Bläddra i källkod

Speed/CPU improvements

Reverted movement manager to Entity, limited to just entity (NPC/Player)
spawn add timer moved to 1000 ms (or trigger on new spawn)
CombatProcess migrated to either movement check (100ms) or aggro check (every 2s) -- in other words not every 10ms.
Set a 1 ms sleep in the CombinePacketLoop
Image 4 år sedan
förälder
incheckning
56f4d39864

+ 28 - 48
EQ2/source/WorldServer/Zone/mob_movement_manager.cpp

@@ -23,7 +23,7 @@ class IMovementCommand {
 public:
 	IMovementCommand() = default;
 	virtual ~IMovementCommand() = default;
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob) = 0;
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob) = 0;
 	virtual bool Started() const = 0;
 };
 
@@ -42,7 +42,7 @@ public:
 
 	}
 
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		auto rotate_to_speed = m_rotate_to_mode == MovementRunning ? 200.0 : 16.0; //todo: get this from mob
 
@@ -129,7 +129,7 @@ public:
 	 * @param mob
 	 * @return
 	 */
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		//Send a movement packet when you start moving		
 		double current_time = static_cast<double>(Timer::GetCurrentTime2()) / 1000.0;
@@ -261,22 +261,22 @@ public:
 
 	}
 
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		//Send a movement packet when you start moving
 		double current_time = static_cast<double>(Timer::GetCurrentTime2()) / 1000.0;
 		int    current_speed = 0;
 
-		if (m_move_to_mode == MovementRunning && mob->IsEntity()) {
-			if (((Entity*)mob)->IsFeared()) {
-				current_speed = ((Entity*)mob)->GetBaseSpeed();
+		if (m_move_to_mode == MovementRunning) {
+			if (mob->IsFeared()) {
+				current_speed = mob->GetBaseSpeed();
 			}
 			else {
 				//runback overrides
-				if (((Entity*)mob)->GetSpeed() > ((Entity*)mob)->GetMaxSpeed())
-					current_speed = ((Entity*)mob)->GetSpeed();
+				if (mob->GetSpeed() > mob->GetMaxSpeed())
+					current_speed = mob->GetSpeed();
 				else
-					current_speed = ((Entity*)mob)->GetMaxSpeed();
+					current_speed = mob->GetMaxSpeed();
 			}
 		}
 		else {
@@ -362,7 +362,7 @@ public:
 
 	}
 
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		mob->SetX(m_teleport_to_x);
 		mob->SetZ(m_teleport_to_z);
@@ -397,7 +397,7 @@ public:
 
 	}
 
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		mob->ClearRunningLocations();
 		return true;
@@ -420,7 +420,7 @@ public:
 
 	}
 
-	virtual bool Process(MobMovementManager* mob_movement_manager, Spawn* mob)
+	virtual bool Process(MobMovementManager* mob_movement_manager, Entity* mob)
 	{
 		if (mob->IsRunning()) {
 			mob->StopMoving();
@@ -474,7 +474,7 @@ struct MobMovementEntry {
 	NavigateTo                                    NavTo;
 };
 
-void AdjustRoute(std::list<IPathfinder::IPathNode> &nodes, Spawn *who)
+void AdjustRoute(std::list<IPathfinder::IPathNode> &nodes, Entity *who)
 {
 	if (who->GetZone() == nullptr || !who->GetZone()->zonemap /*|| !zone->HasWaterMap()*/) {
 		return;
@@ -493,7 +493,7 @@ void AdjustRoute(std::list<IPathfinder::IPathNode> &nodes, Spawn *who)
 }
 
 struct MobMovementManager::Implementation {
-	std::map<Spawn *, MobMovementEntry> Entries;
+	std::map<Entity *, MobMovementEntry> Entries;
 	std::vector<Client *>             Clients;
 	MovementStats                     Stats;
 };
@@ -515,7 +515,6 @@ void MobMovementManager::Process()
 		auto &ent      = iter.second;
 		auto &commands = ent.Commands;
 
-		iter.first->MCommandMutex.writelock();
 		while (true != commands.empty()) {
 			auto &cmd = commands.front();
 			auto r    = cmd->Process(this, iter.first);
@@ -526,7 +525,6 @@ void MobMovementManager::Process()
 
 			commands.pop_front();
 		}
-		iter.first->MCommandMutex.releasewritelock();
 	}
 	MobListMutex.releasereadlock();
 }
@@ -534,24 +532,20 @@ void MobMovementManager::Process()
 /**
  * @param mob
  */
-void MobMovementManager::AddMob(Spawn *mob)
+void MobMovementManager::AddMob(Entity *mob)
 {
 	MobListMutex.writelock();
-	mob->MCommandMutex.writelock();
 	_impl->Entries.insert(std::make_pair(mob, MobMovementEntry()));
-	mob->MCommandMutex.releasewritelock();
 	MobListMutex.releasewritelock();
 }
 
 /**
  * @param mob
  */
-void MobMovementManager::RemoveMob(Spawn *mob)
+void MobMovementManager::RemoveMob(Entity *mob)
 {
 	MobListMutex.writelock();
-	mob->MCommandMutex.writelock();
 	_impl->Entries.erase(mob);
-	mob->MCommandMutex.releasewritelock();
 	MobListMutex.releasewritelock();
 }
 
@@ -584,7 +578,7 @@ void MobMovementManager::RemoveClient(Client *client)
  * @param to
  * @param mob_movement_mode
  */
-void MobMovementManager::RotateTo(Spawn *who, float to, MobMovementMode mob_movement_mode)
+void MobMovementManager::RotateTo(Entity *who, float to, MobMovementMode mob_movement_mode)
 {
 	MobListMutex.readlock();
 	auto iter = _impl->Entries.find(who);
@@ -605,7 +599,7 @@ void MobMovementManager::RotateTo(Spawn *who, float to, MobMovementMode mob_move
  * @param z
  * @param heading
  */
-void MobMovementManager::Teleport(Spawn *who, float x, float y, float z, float heading)
+void MobMovementManager::Teleport(Entity *who, float x, float y, float z, float heading)
 {
 	MobListMutex.readlock();
 	auto iter = _impl->Entries.find(who);
@@ -624,11 +618,8 @@ void MobMovementManager::Teleport(Spawn *who, float x, float y, float z, float h
  * @param z
  * @param mode
  */
-void MobMovementManager::NavigateTo(Spawn *who, float x, float y, float z, MobMovementMode mode, bool overrideDistance)
+void MobMovementManager::NavigateTo(Entity *who, float x, float y, float z, MobMovementMode mode, bool overrideDistance)
 {
-	if (who->IsRunning())
-		return;
-
 	glm::vec3 targPos(x, z, y);
 	glm::vec3 origPos(who->GetX(), who->GetZ(), who->GetY());
 
@@ -651,19 +642,15 @@ void MobMovementManager::NavigateTo(Spawn *who, float x, float y, float z, MobMo
 			6.0f
 		);
 
-		who->MCommandMutex.writelock();
-
 		if (within && ent.second.Commands.size() > 0 && nav.last_set_time != 0)
 		{
 			//who->ClearRunningLocations();
 			//StopNavigation((Entity*)who);
-			who->MCommandMutex.releasewritelock();
 			MobListMutex.releasereadlock();
 			return;
 		}
 		else if (!within && ent.second.Commands.size() > 0 && nav.last_set_time != 0)
 		{
-			who->MCommandMutex.releasewritelock();
 			MobListMutex.releasereadlock();
 			return;
 		}
@@ -683,7 +670,6 @@ void MobMovementManager::NavigateTo(Spawn *who, float x, float y, float z, MobMo
 			nav.navigate_to_z       = z;
 			nav.navigate_to_heading = 0.0;
 			nav.last_set_time       = current_time;
-			who->MCommandMutex.releasewritelock();
 		//}
 	}
 	MobListMutex.releasereadlock();
@@ -692,7 +678,7 @@ void MobMovementManager::NavigateTo(Spawn *who, float x, float y, float z, MobMo
 /**
  * @param who
  */
-void MobMovementManager::StopNavigation(Spawn *who)
+void MobMovementManager::StopNavigation(Entity *who)
 {
 	MobListMutex.readlock();
 	auto iter = _impl->Entries.find(who);
@@ -705,28 +691,24 @@ void MobMovementManager::StopNavigation(Spawn *who)
 	nav.navigate_to_heading = 0.0;
 	nav.last_set_time = 0.0;
 
-	who->MCommandMutex.writelock();
 	if (true == ent.second.Commands.empty()) {
 		PushStopMoving(ent.second);
-		who->MCommandMutex.releasewritelock();
 		MobListMutex.releasereadlock();
 		return;
 	}
 
 	if (!who->IsRunning()) {
 		ent.second.Commands.clear();
-		who->MCommandMutex.releasewritelock();
 		MobListMutex.releasereadlock();
 		return;
 	}
 
 	ent.second.Commands.clear();
 	PushStopMoving(ent.second);
-	who->MCommandMutex.releasewritelock();
 	MobListMutex.releasereadlock();
 }
 
-void MobMovementManager::DisruptNavigation(Spawn* who)
+void MobMovementManager::DisruptNavigation(Entity* who)
 {
 	MobListMutex.readlock();
 	auto iter = _impl->Entries.find(who);
@@ -740,9 +722,7 @@ void MobMovementManager::DisruptNavigation(Spawn* who)
 	nav.last_set_time = 0.0;
 
 	if (!who->IsRunning()) {
-		who->MCommandMutex.writelock();
 		ent.second.Commands.clear();
-		who->MCommandMutex.releasewritelock();
 		MobListMutex.releasereadlock();
 		return;
 	}
@@ -783,7 +763,7 @@ void MobMovementManager::ClearStats()
  * @param z
  * @param mob_movement_mode
  */
-void MobMovementManager::UpdatePath(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode)
+void MobMovementManager::UpdatePath(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode)
 {
 	if (!who->GetZone()->zonemap /*|| !zone->HasWaterMap()*/) {
 		MobListMutex.readlock();
@@ -814,7 +794,7 @@ void MobMovementManager::UpdatePath(Spawn *who, float x, float y, float z, MobMo
  * @param z
  * @param mode
  */
-void MobMovementManager::UpdatePathGround(Spawn *who, float x, float y, float z, MobMovementMode mode)
+void MobMovementManager::UpdatePathGround(Entity *who, float x, float y, float z, MobMovementMode mode)
 {
 	PathfinderOptions opts;
 	opts.smooth_path = true;
@@ -958,7 +938,7 @@ void MobMovementManager::UpdatePathGround(Spawn *who, float x, float y, float z,
  * @param z
  * @param movement_mode
  */
-void MobMovementManager::UpdatePathUnderwater(Spawn *who, float x, float y, float z, MobMovementMode movement_mode)
+void MobMovementManager::UpdatePathUnderwater(Entity *who, float x, float y, float z, MobMovementMode movement_mode)
 {
 	MobListMutex.readlock();
 	auto eiter = _impl->Entries.find(who);
@@ -1079,7 +1059,7 @@ void MobMovementManager::UpdatePathUnderwater(Spawn *who, float x, float y, floa
  * @param z
  * @param mode
  */
-void MobMovementManager::UpdatePathBoat(Spawn *who, float x, float y, float z, MobMovementMode mode)
+void MobMovementManager::UpdatePathBoat(Entity *who, float x, float y, float z, MobMovementMode mode)
 {
 	MobListMutex.readlock();
 	auto eiter = _impl->Entries.find(who);
@@ -1132,7 +1112,7 @@ void MobMovementManager::PushSwimTo(MobMovementEntry &ent, float x, float y, flo
  * @param to
  * @param mob_movement_mode
  */
-void MobMovementManager::PushRotateTo(MobMovementEntry &ent, Spawn *who, float to, MobMovementMode mob_movement_mode)
+void MobMovementManager::PushRotateTo(MobMovementEntry &ent, Entity *who, float to, MobMovementMode mob_movement_mode)
 {
 	auto from = FixHeading(who->GetHeading());
 	to = FixHeading(to);
@@ -1177,7 +1157,7 @@ void MobMovementManager::PushEvadeCombat(MobMovementEntry &mob_movement_entry)
  * @param z
  * @param mob_movement_mode
  */
-void MobMovementManager::HandleStuckBehavior(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode)
+void MobMovementManager::HandleStuckBehavior(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode)
 {
 	//LogDebug("Handle stuck behavior for {0} at ({1}, {2}, {3}) with movement_mode {4}", who->GetName(), x, y, z, mob_movement_mode);
 

+ 13 - 13
EQ2/source/WorldServer/Zone/mob_movement_manager.h

@@ -42,16 +42,16 @@ class MobMovementManager
 public:
 	~MobMovementManager();
 	void Process();
-	void AddMob(Spawn *mob);
-	void RemoveMob(Spawn*mob);
+	void AddMob(Entity *mob);
+	void RemoveMob(Entity *mob);
 	void AddClient(Client *client);
 	void RemoveClient(Client *client);
 
-	void RotateTo(Spawn *who, float to, MobMovementMode mob_movement_mode = MovementRunning);
-	void Teleport(Spawn *who, float x, float y, float z, float heading);
-	void NavigateTo(Spawn *who, float x, float y, float z, MobMovementMode mode = MovementRunning, bool overrideDistance=false);
-	void StopNavigation(Spawn *who);
-	void DisruptNavigation(Spawn *who);
+	void RotateTo(Entity *who, float to, MobMovementMode mob_movement_mode = MovementRunning);
+	void Teleport(Entity *who, float x, float y, float z, float heading);
+	void NavigateTo(Entity *who, float x, float y, float z, MobMovementMode mode = MovementRunning, bool overrideDistance=false);
+	void StopNavigation(Entity *who);
+	void DisruptNavigation(Entity* who);
 	/*
 	void SendCommandToClients(
 		Entity *mob,
@@ -91,17 +91,17 @@ private:
 	MobMovementManager(const MobMovementManager&);
 	MobMovementManager& operator=(const MobMovementManager&);
 
-	void UpdatePath(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode);
-	void UpdatePathGround(Spawn *who, float x, float y, float z, MobMovementMode mode);
-	void UpdatePathUnderwater(Spawn *who, float x, float y, float z, MobMovementMode movement_mode);
-	void UpdatePathBoat(Spawn *who, float x, float y, float z, MobMovementMode mode);
+	void UpdatePath(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode);
+	void UpdatePathGround(Entity *who, float x, float y, float z, MobMovementMode mode);
+	void UpdatePathUnderwater(Entity *who, float x, float y, float z, MobMovementMode movement_mode);
+	void UpdatePathBoat(Entity *who, float x, float y, float z, MobMovementMode mode);
 	void PushTeleportTo(MobMovementEntry &ent, float x, float y, float z, float heading);
 	void PushMoveTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
 	void PushSwimTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mob_movement_mode);
-	void PushRotateTo(MobMovementEntry &ent, Spawn *who, float to, MobMovementMode mob_movement_mode);
+	void PushRotateTo(MobMovementEntry &ent, Entity *who, float to, MobMovementMode mob_movement_mode);
 	void PushStopMoving(MobMovementEntry &mob_movement_entry);
 	void PushEvadeCombat(MobMovementEntry &mob_movement_entry);
-	void HandleStuckBehavior(Spawn *who, float x, float y, float z, MobMovementMode mob_movement_mode);
+	void HandleStuckBehavior(Entity *who, float x, float y, float z, MobMovementMode mob_movement_mode);
 
 	struct Implementation;
 	std::unique_ptr<Implementation> _impl;

+ 8 - 6
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(100);
+	spawn_check_add.Start(1000);
 	spawn_check_remove.Start(30000);
 	spawn_expire_timer.Start(10000);
 	respawn_timer.Start(10000);
@@ -1530,14 +1530,16 @@ bool ZoneServer::SpawnProcess(){
 					spawn->ProcessMovement(true);
 					// update last_movement_update for all spawns (used for time_step)
 					spawn->last_movement_update = Timer::GetCurrentTime2();
+					if (!aggroCheck)
+						CombatProcess(spawn);
 				}
 
 				// Makes NPC's KOS to other NPC's or players
 				if (aggroCheck)
+				{
 					ProcessAggroChecks(spawn);
-
-				// Process combat for the spawn
-				CombatProcess(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
@@ -2884,7 +2886,7 @@ void ZoneServer::AddSpawn(Spawn* spawn) {
 	if (Grid != nullptr) {
 		Grid->AddSpawn(spawn);
 	}
-	if (movementMgr != nullptr) {
+	if (movementMgr != nullptr && spawn->IsEntity()) {
 		movementMgr->AddMob((Entity*)spawn);
 	}
 
@@ -3770,7 +3772,7 @@ void ZoneServer::RemoveSpawn(bool spawnListLocked, Spawn* spawn, bool delete_spa
 	if (Grid != nullptr) {
 		Grid->RemoveSpawnFromCell(spawn);
 	}
-	if (movementMgr != nullptr) {
+	if (movementMgr != nullptr && spawn->IsEntity()) {
 		movementMgr->RemoveMob((Entity*)spawn);
 	}
 

+ 2 - 0
EQ2/source/common/EQStreamFactory.cpp

@@ -341,6 +341,8 @@ void EQStreamFactory::CombinePacketLoop(){
 		MStreams.unlock();
 		if(!packets_waiting)
 			Sleep(25);
+
+		Sleep(1);
 	}
 }