-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move static Player functions and internal linkage to manager c…
…lass (#1412) * Moving and organizing Player code - Move code to CharacterComponent - Remove extraneous interfaces - Simplify some code greatly - Change some types to return and take in const ref (only structs larger than 8 bytes benefit from this change.) - Update code to use CharacterComponent for sending to zone instead of Player*. * Moving and organizing Player code - Move code to CharacterComponent - Remove extraneous interfaces - Simplify some code greatly - Change some types to return and take in const ref (only structs larger than 8 bytes benefit from this change.) - Update code to use CharacterComponent for sending to zone instead of Player*. - Remove static storage container (static containers can be destroyed before exit/terminate handler executes) * remove player cast * Remove extra includes * Add a player manager Used for the static Player functions. Further removes stuff from the Player class/file.
- Loading branch information
Showing
12 changed files
with
129 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "PlayerManager.h" | ||
|
||
#include "Character.h" | ||
#include "Player.h" | ||
#include "User.h" | ||
#include "UserManager.h" | ||
#include "eReplicaComponentType.h" | ||
|
||
namespace { | ||
std::vector<Player*> m_Players; | ||
}; | ||
|
||
const std::vector<Player*>& PlayerManager::GetAllPlayers() { | ||
return m_Players; | ||
} | ||
|
||
void PlayerManager::AddPlayer(Player* player) { | ||
const auto& iter = std::find(m_Players.begin(), m_Players.end(), player); | ||
|
||
if (iter == m_Players.end()) { | ||
m_Players.push_back(player); | ||
} | ||
} | ||
|
||
void PlayerManager::RemovePlayer(Player* player) { | ||
const auto iter = std::find(m_Players.begin(), m_Players.end(), player); | ||
|
||
if (iter != m_Players.end()) { | ||
m_Players.erase(iter); | ||
} | ||
} | ||
|
||
Player* PlayerManager::GetPlayer(const SystemAddress& sysAddr) { | ||
auto* entity = UserManager::Instance()->GetUser(sysAddr)->GetLastUsedChar()->GetEntity(); | ||
|
||
return static_cast<Player*>(entity); | ||
} | ||
|
||
Player* PlayerManager::GetPlayer(const std::string& name) { | ||
const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); | ||
|
||
Player* player = nullptr; | ||
for (auto* character : characters) { | ||
if (!character->IsPlayer()) continue; | ||
|
||
if (GeneralUtils::CaseInsensitiveStringCompare(name, character->GetCharacter()->GetName())) { | ||
player = dynamic_cast<Player*>(character); | ||
break; | ||
} | ||
} | ||
|
||
return player; | ||
} | ||
|
||
Player* PlayerManager::GetPlayer(LWOOBJID playerID) { | ||
Player* playerToReturn = nullptr; | ||
for (auto* player : m_Players) { | ||
if (player->GetObjectID() == playerID) { | ||
playerToReturn = player; | ||
break; | ||
} | ||
} | ||
|
||
return playerToReturn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef __PLAYERMANAGER__H__ | ||
#define __PLAYERMANAGER__H__ | ||
|
||
#include "dCommonVars.h" | ||
|
||
#include <string> | ||
|
||
class Player; | ||
struct SystemAddress; | ||
|
||
namespace PlayerManager { | ||
void AddPlayer(Player* player); | ||
|
||
void RemovePlayer(Player* player); | ||
|
||
Player* GetPlayer(const SystemAddress& sysAddr); | ||
|
||
Player* GetPlayer(const std::string& name); | ||
|
||
Player* GetPlayer(LWOOBJID playerID); | ||
|
||
const std::vector<Player*>& GetAllPlayers(); | ||
}; | ||
|
||
#endif //!__PLAYERMANAGER__H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.