Browse Source

Revert "Reducing mutex locks, reducing unnecessary calls by timers increased/utilized for certain processes"

This reverts commit cb352a66329ddd9ca46e1db9b44094850f39a2d0.
Image 4 years ago
parent
commit
423163d30c

+ 4 - 4
EQ2/source/WorldServer/NPC_AI.cpp

@@ -54,6 +54,10 @@ Brain::~Brain() {
 
 void Brain::Think() {
 
+	// Get the entity this NPC hates the most,
+	// GetMostHated() will handle dead spawns so no need to check the health in this function
+	Entity* target = GetMostHated();
+
 	// If mezzed, stunned or feared we can't do anything so skip
 	if (!m_body->IsMezzedOrStunned()) {
 		// Not mezzed or stunned
@@ -61,10 +65,6 @@ void Brain::Think() {
 		// Get the distance to the runback location
 		float run_back_distance = m_body->GetRunbackDistance();
 
-		// Get the entity this NPC hates the most,
-		// GetMostHated() will handle dead spawns so no need to check the health in this function
-		Entity* target = GetMostHated();
-
 		if (target) {
 			LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "%s has %s targeted.", m_body->GetName(), target->GetName());
 			// NPC has an entity that it hates

+ 11 - 6
EQ2/source/WorldServer/Player.cpp

@@ -4090,12 +4090,17 @@ void Player::ClearRemovedSpawn(Spawn* spawn){
 }
 
 bool Player::ShouldSendSpawn(Spawn* spawn){
-
-	bool wasSentSpawn = WasSentSpawn(spawn->GetID());
-	if((!wasSentSpawn || (wasSentSpawn && WasSpawnRemoved(spawn)))
-		&& (!spawn->IsPrivateSpawn() || spawn->AllowedAccess(this)))
-		return true;
-
+	// Added a try catch to attempt to prevent a zone crash when an invalid spawn is passed to this function.
+	// Think invalid spawns are coming from the mutex list, if spawn is invalid return false.
+	try
+	{
+		if((WasSentSpawn(spawn->GetID()) == false || NeedsSpawnResent(spawn)) && (!spawn->IsPrivateSpawn() || spawn->AllowedAccess(this)))
+			return true;
+	}
+	catch (...)
+	{
+		LogWrite(SPAWN__ERROR, 0, "Spawn", "Invalid spawn passes to player->ShouldSendSpawn()");
+	}
 	return false;
 }
 

+ 1 - 2
EQ2/source/WorldServer/net.cpp

@@ -440,7 +440,6 @@ int main(int argc, char** argv) {
 					connecting_clients[eqs] = Timer::GetCurrentTime2();
 				}
 			}
-
 			if(connecting_clients.size() > 0){
 				for(cc_itr = connecting_clients.begin(); cc_itr!=connecting_clients.end(); cc_itr++){
 					if(cc_itr->first && cc_itr->first->CheckActive() && client_list.ContainsStream(cc_itr->first) == false){
@@ -489,7 +488,7 @@ int main(int argc, char** argv) {
 			Sleep(10);
 			continue;
 		}
-		Sleep(10);
+		Sleep(1);
 	}
 	LogWrite(WORLD__DEBUG, 0, "World", "The world is ending!");
 

+ 11 - 15
EQ2/source/WorldServer/zoneserver.cpp

@@ -237,7 +237,7 @@ void ZoneServer::Init()
 
 	/* Static Timers */
 	// JA - haven't decided yet if these should remain hard-coded. Changing them could break EQ2Emu functionality
-	spawn_check_add.Start(1000);
+	spawn_check_add.Start(100);
 	spawn_check_remove.Start(30000);
 	spawn_expire_timer.Start(10000);
 	respawn_timer.Start(10000);
@@ -1056,7 +1056,7 @@ void ZoneServer::CheckSendSpawnToClient(Client* client, bool initial_login) {
 		if(initial_login || client->IsConnected()) {
 			MutexMap<int32, float >::iterator spawn_iter = spawn_range_map.Get(client)->begin();
 			while(spawn_iter.Next()) {
-				spawn = GetSpawnByID(spawn_iter->first, !initial_login);
+				spawn = GetSpawnByID(spawn_iter->first);
 				if(spawn && spawn->GetPrivateQuestSpawn()) {
 					if(!spawn->IsPrivateSpawn())
 						spawn->AddAllowAccessSpawn(spawn);
@@ -1242,10 +1242,6 @@ bool ZoneServer::Process()
 	{
 #endif
 		if (LoadingData) {
-			while (zoneID == 0) { //this is loaded by world
-				Sleep(10);
-			}
-
 			if (lua_interface) {
 				string tmpScript("ZoneScripts/");
 				tmpScript.append(GetZoneName());
@@ -1256,6 +1252,10 @@ bool ZoneServer::Process()
 					lua_interface->RunZoneScript(tmpScript.c_str(), "preinit_zone_script", this);
 			}
 
+			while (zoneID == 0) { //this is loaded by world
+				Sleep(10);
+			}
+
 			if (reloading) {
 				LogWrite(COMMAND__DEBUG, 0, "Command", "-Loading Entity Commands...");
 				database.LoadEntityCommands(this);
@@ -1530,18 +1530,14 @@ bool ZoneServer::SpawnProcess(){
 					spawn->ProcessMovement(true);
 					// update last_movement_update for all spawns (used for time_step)
 					spawn->last_movement_update = Timer::GetCurrentTime2();
-
-					// Process combat for the spawn
-					if (!aggroCheck)
-						CombatProcess(spawn);
 				}
 
 				// Makes NPC's KOS to other NPC's or players
 				if (aggroCheck)
-				{
 					ProcessAggroChecks(spawn);
-					CombatProcess(spawn);
-				}
+
+				// Process combat for the spawn
+				CombatProcess(spawn);
 			}
 			else {
 				// unable to get a valid spawn, lets add the id to another list to remove from the spawn list after this loop is finished
@@ -1865,7 +1861,7 @@ void ZoneServer::SendSpawnChanges(){
 	MutexList<int32>::iterator spawn_iter = changed_spawns.begin();
 	int count = 0;
 	while(spawn_iter.Next()){		
-		spawn = GetSpawnByID(spawn_iter->value, true);
+		spawn = GetSpawnByID(spawn_iter->value);
 		if(spawn){
 			spawns_to_send.insert(spawn);
 		}
@@ -6310,7 +6306,7 @@ ThreadReturnType ZoneLoop(void* tmp) {
 		if(zs->GetClientCount() == 0)
 			Sleep(1000);
 		else
-			Sleep(20);
+			Sleep(10);
 	}
 	zs->Process(); //run loop once more to clean up some functions
 	safe_delete(zs);

+ 1 - 3
EQ2/source/common/EQStreamFactory.cpp

@@ -340,9 +340,7 @@ void EQStreamFactory::CombinePacketLoop(){
 		}
 		MStreams.unlock();
 		if(!packets_waiting)
-			Sleep(20);
-
-		Sleep(10);
+			Sleep(25);
 	}
 }