mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 23:26:43 +00:00 
			
		
		
		
	Simplify the type of map that player objects are stored in
This commit is contained in:
		
							parent
							
								
									65363b0dd1
								
							
						
					
					
						commit
						c91e240664
					
				
					 5 changed files with 38 additions and 35 deletions
				
			
		|  | @ -673,7 +673,7 @@ void Networking::NewPlayer(RakNet::RakNetGUID guid) | |||
|     for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player
 | ||||
|     { | ||||
|         // If we are iterating over the new player, don't send the packets below
 | ||||
|         if (pl->first == guid) continue; | ||||
|         if (pl->first == guid.g) continue; | ||||
| 
 | ||||
|         playerController->GetPacket(ID_GAME_BASE_INFO)->Send(pl->second, guid); | ||||
|         playerController->GetPacket(ID_GAME_DYNAMICSTATS)->Send(pl->second, guid); | ||||
|  |  | |||
|  | @ -13,17 +13,20 @@ void Players::DeletePlayer(RakNet::RakNetGUID guid) | |||
|     LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", | ||||
|         guid.g); | ||||
| 
 | ||||
|     if (players[guid] != 0) | ||||
|     LOG_APPEND(Log::LOG_INFO, "- %i players remaining before", | ||||
|         players.size()); | ||||
|      | ||||
|     if (players[guid.g] != 0) | ||||
|     { | ||||
|         LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i", | ||||
|             players[guid]->GetID()); | ||||
|             players[guid.g]->GetID()); | ||||
| 
 | ||||
|         slots[players[guid]->GetID()] = 0; | ||||
|         delete players[guid]; | ||||
|         players.erase(guid); | ||||
|         slots[players[guid.g]->GetID()] = 0; | ||||
|         delete players[guid.g]; | ||||
|         players.erase(guid.g); | ||||
|     } | ||||
| 
 | ||||
|     LOG_APPEND(Log::LOG_INFO, "- %i remaining", | ||||
|     LOG_APPEND(Log::LOG_INFO, "- %i players remaining after", | ||||
|         players.size()); | ||||
| } | ||||
| 
 | ||||
|  | @ -32,12 +35,12 @@ void Players::NewPlayer(RakNet::RakNetGUID guid) | |||
|     LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu", | ||||
|         guid.g); | ||||
| 
 | ||||
|     players[guid] = new Player(guid); | ||||
|     players[guid]->GetCell()->blank(); | ||||
|     players[guid]->Npc()->blank(); | ||||
|     players[guid]->NpcStats()->blank(); | ||||
|     players[guid]->CreatureStats()->blank(); | ||||
|     players[guid]->charClass.blank(); | ||||
|     players[guid.g] = new Player(guid); | ||||
|     players[guid.g]->GetCell()->blank(); | ||||
|     players[guid.g]->Npc()->blank(); | ||||
|     players[guid.g]->NpcStats()->blank(); | ||||
|     players[guid.g]->CreatureStats()->blank(); | ||||
|     players[guid.g]->charClass.blank(); | ||||
| 
 | ||||
|     for (int i = 0; i < mwmp::Networking::Get().MaxConnections(); i++) | ||||
|     { | ||||
|  | @ -46,7 +49,7 @@ void Players::NewPlayer(RakNet::RakNetGUID guid) | |||
|             LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i", | ||||
|                 i); | ||||
| 
 | ||||
|             slots[i] = players[guid]; | ||||
|             slots[i] = players[guid.g]; | ||||
|             slots[i]->SetID(i); | ||||
|             break; | ||||
|         } | ||||
|  | @ -55,10 +58,10 @@ void Players::NewPlayer(RakNet::RakNetGUID guid) | |||
| 
 | ||||
| Player *Players::GetPlayer(RakNet::RakNetGUID guid) | ||||
| { | ||||
|     return players[guid]; | ||||
|     return players[guid.g]; | ||||
| } | ||||
| 
 | ||||
| std::map<RakNet::RakNetGUID, Player*> *Players::GetPlayers() | ||||
| std::map<uint64_t, Player*> *Players::GetPlayers() | ||||
| { | ||||
|     return &players; | ||||
| } | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ | |||
| #include <components/openmw-mp/Base/BasePlayer.hpp> | ||||
| 
 | ||||
| struct Player; | ||||
| typedef std::map<RakNet::RakNetGUID, Player*> TPlayers; | ||||
| typedef std::map<uint64_t, Player*> TPlayers; | ||||
| typedef std::map<unsigned short, Player*> TSlots; | ||||
| 
 | ||||
| class Players | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ | |||
| using namespace mwmp; | ||||
| using namespace std; | ||||
| 
 | ||||
| std::map<RakNet::RakNetGUID, DedicatedPlayer *> Players::players; | ||||
| std::map<uint64_t, DedicatedPlayer *> Players::players; | ||||
| 
 | ||||
| DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid) | ||||
| { | ||||
|  | @ -50,7 +50,7 @@ void Players::CreatePlayer(RakNet::RakNetGUID guid) | |||
|     MWWorld::Ptr player = world->getPlayerPtr(); | ||||
| 
 | ||||
|     ESM::NPC npc = *player.get<ESM::NPC>()->mBase; | ||||
|     DedicatedPlayer *dedicPlayer = players[guid]; | ||||
|     DedicatedPlayer *dedicPlayer = players[guid.g]; | ||||
| 
 | ||||
|     npc.mRace = dedicPlayer->Npc()->mRace; | ||||
|     npc.mHead = dedicPlayer->Npc()->mHead; | ||||
|  | @ -94,7 +94,7 @@ void Players::CreatePlayer(RakNet::RakNetGUID guid) | |||
|         dedicPlayer->ptr.getBase()->canChangeCell = true; | ||||
|         dedicPlayer->UpdatePtr(world->moveObject(dedicPlayer->ptr, cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2])); | ||||
| 
 | ||||
|         npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId; | ||||
|         npc.mId = players[guid.g]->ptr.get<ESM::NPC>()->mBase->mId; | ||||
| 
 | ||||
|         MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore()); | ||||
|         MWWorld::Store<ESM::NPC> *esm_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::NPC>()); | ||||
|  | @ -111,41 +111,41 @@ void Players::CreatePlayer(RakNet::RakNetGUID guid) | |||
|     dedicPlayer->guid = guid; | ||||
|     dedicPlayer->state = 2; | ||||
| 
 | ||||
|     world->enable(players[guid]->ptr); | ||||
|     world->enable(players[guid.g]->ptr); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void Players::CleanUp() | ||||
| { | ||||
|     for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++) | ||||
|     for (std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++) | ||||
|         delete it->second; | ||||
| } | ||||
| 
 | ||||
| void Players::DisconnectPlayer(RakNet::RakNetGUID guid) | ||||
| { | ||||
|     if (players[guid]->state > 1) | ||||
|     if (players[guid.g]->state > 1) | ||||
|     { | ||||
|         players[guid]->state = 1; | ||||
|         players[guid.g]->state = 1; | ||||
| 
 | ||||
|         // Remove player's marker
 | ||||
|         players[guid]->setMarkerState(false); | ||||
|         players[guid.g]->setMarkerState(false); | ||||
| 
 | ||||
|         MWBase::World *world = MWBase::Environment::get().getWorld(); | ||||
|         world->disable(players[guid]->getPtr()); | ||||
|         world->disable(players[guid.g]->getPtr()); | ||||
| 
 | ||||
|         // Move player to ToddTest
 | ||||
|         ESM::Position newPos; | ||||
|         world->findInteriorPosition("ToddTest", newPos); | ||||
|         MWWorld::CellStore *store = world->getInterior("ToddTest"); | ||||
| 
 | ||||
|         players[guid]->getPtr().getBase()->canChangeCell = true; | ||||
|         world->moveObject(players[guid]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]); | ||||
|         players[guid.g]->getPtr().getBase()->canChangeCell = true; | ||||
|         world->moveObject(players[guid.g]->getPtr(), store, newPos.pos[0], newPos.pos[1], newPos.pos[2]); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| DedicatedPlayer *Players::GetPlayer(RakNet::RakNetGUID guid) | ||||
| { | ||||
|     return players[guid]; | ||||
|     return players[guid.g]; | ||||
| } | ||||
| 
 | ||||
| MWWorld::Ptr DedicatedPlayer::getLiveCellPtr() | ||||
|  | @ -222,7 +222,7 @@ void Players::Update(float dt) | |||
| { | ||||
|     static float timer = 0; | ||||
|     timer += dt; | ||||
|     for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++) | ||||
|     for (std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++) | ||||
|     { | ||||
|         DedicatedPlayer *pl = it->second; | ||||
|         if (pl == 0) continue; | ||||
|  | @ -287,9 +287,9 @@ DedicatedPlayer *Players::NewPlayer(RakNet::RakNetGUID guid) | |||
|     LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu", | ||||
|         guid.g); | ||||
| 
 | ||||
|     players[guid] = new DedicatedPlayer(guid); | ||||
|     players[guid]->state = 0; | ||||
|     return players[guid]; | ||||
|     players[guid.g] = new DedicatedPlayer(guid); | ||||
|     players[guid.g]->state = 0; | ||||
|     return players[guid.g]; | ||||
| } | ||||
| 
 | ||||
| void DedicatedPlayer::UpdateInventory() | ||||
|  | @ -402,7 +402,7 @@ const std::string DedicatedPlayer::GetAnim() | |||
| 
 | ||||
| DedicatedPlayer *Players::GetPlayer(const MWWorld::Ptr &ptr) | ||||
| { | ||||
|     std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); | ||||
|     std::map <uint64_t, DedicatedPlayer *>::iterator it = players.begin(); | ||||
| 
 | ||||
|     for (; it != players.end(); it++) | ||||
|     { | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ namespace mwmp | |||
|         static DedicatedPlayer *GetPlayer(const MWWorld::Ptr &ptr); | ||||
|         static void Update(float dt); | ||||
|     private: | ||||
|         static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players; | ||||
|         static std::map<uint64_t, DedicatedPlayer *> players; | ||||
|     }; | ||||
| 
 | ||||
|     class DedicatedPlayer : public BasePlayer | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue