Browse Source

Merge pull request #500 from Hoikas/player-array

Convert NetCommPlayer to std::vector
Michael Hansen 10 years ago
parent
commit
7abf1b2035
  1. 11
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp
  2. 58
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  3. 7
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h

11
Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp

@ -61,22 +61,21 @@ bool cyAccountManagement::IsSubscriptionActive()
PyObject* cyAccountManagement::GetPlayerList() PyObject* cyAccountManagement::GetPlayerList()
{ {
const ARRAY(NetCommPlayer)& playerList = NetCommGetPlayerList(); const std::vector<NetCommPlayer>& playerList = NetCommGetPlayerList();
int numPlayers = NetCommGetPlayerCount();
PyObject* pList = PyList_New(0); PyObject* pList = PyList_New(0);
PyObject* visitor = nil; PyObject* visitor = nil;
for (int i = 0; i < numPlayers; ++i) for (Py_ssize_t i = 0; i < playerList.size(); ++i)
{ {
PyObject* playerTuple = PyTuple_New(3); PyObject* playerTuple = PyTuple_New(3);
PyObject* playerName = PyUnicode_FromStringEx(playerList[i].playerName); PyObject* playerName = PyUnicode_FromStringEx(playerList[i].playerName);
PyObject* playerId = PyInt_FromLong(playerList[i].playerInt); PyObject* playerId = PyInt_FromLong(playerList[i].playerInt);
PyObject* avatarShape = PyString_FromPlString(playerList[i].avatarDatasetName); PyObject* avatarShape = PyString_FromPlString(playerList[i].avatarDatasetName);
PyTuple_SetItem(playerTuple, 0, playerName); PyTuple_SET_ITEM(playerTuple, 0, playerName);
PyTuple_SetItem(playerTuple, 1, playerId); PyTuple_SET_ITEM(playerTuple, 1, playerId);
PyTuple_SetItem(playerTuple, 2, avatarShape); PyTuple_SET_ITEM(playerTuple, 2, avatarShape);
if (visitor || playerList[i].explorer) if (visitor || playerList[i].explorer)
PyList_Append(pList, playerTuple); PyList_Append(pList, playerTuple);

58
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -106,7 +106,7 @@ struct NetCommParam {
static bool s_shutdown; static bool s_shutdown;
static NetCommAccount s_account; static NetCommAccount s_account;
static ARRAY(NetCommPlayer) s_players; static std::vector<NetCommPlayer> s_players;
static NetCommPlayer * s_player; static NetCommPlayer * s_player;
static NetCommAge s_age; static NetCommAge s_age;
static NetCommAge s_startupAge; static NetCommAge s_startupAge;
@ -391,7 +391,7 @@ static void INetCliAuthLoginRequestCallback (
s_authResult = result; s_authResult = result;
s_player = nil; s_player = nil;
s_players.Clear(); s_players.clear();
bool wantsStartUpAge = (s_startupAge.ageDatasetName.IsEmpty() || bool wantsStartUpAge = (s_startupAge.ageDatasetName.IsEmpty() ||
s_startupAge.ageDatasetName.CompareI("StartUp") == 0); s_startupAge.ageDatasetName.CompareI("StartUp") == 0);
@ -402,7 +402,7 @@ static void INetCliAuthLoginRequestCallback (
s_account.accountUuid = accountUuid; s_account.accountUuid = accountUuid;
s_account.accountFlags = accountFlags; s_account.accountFlags = accountFlags;
s_account.billingType = billingType; s_account.billingType = billingType;
s_players.GrowToCount(playerCount, true); s_players.resize(playerCount);
for (unsigned i = 0; i < playerCount; ++i) { for (unsigned i = 0; i < playerCount; ++i) {
LogMsg(kLogDebug, L"Player %u: %S explorer: %u", playerInfoArr[i].playerInt, playerInfoArr[i].playerName.c_str(), playerInfoArr[i].explorer); LogMsg(kLogDebug, L"Player %u: %S explorer: %u", playerInfoArr[i].playerInt, playerInfoArr[i].playerName.c_str(), playerInfoArr[i].explorer);
s_players[i].playerInt = playerInfoArr[i].playerInt; s_players[i].playerInt = playerInfoArr[i].playerInt;
@ -448,19 +448,15 @@ static void INetCliAuthCreatePlayerRequestCallback (
LogMsg(kLogDebug, L"Created player %S: %u", playerInfo.playerName.c_str(), playerInfo.playerInt); LogMsg(kLogDebug, L"Created player %S: %u", playerInfo.playerName.c_str(), playerInfo.playerInt);
unsigned currPlayer = s_player ? s_player->playerInt : 0; unsigned currPlayer = s_player ? s_player->playerInt : 0;
NetCommPlayer * newPlayer = s_players.New(); s_players.emplace_back(playerInfo.playerInt, playerInfo.playerName,
playerInfo.avatarShape, playerInfo.explorer);
newPlayer->playerInt = playerInfo.playerInt; for (NetCommPlayer& player : s_players) {
newPlayer->explorer = playerInfo.explorer; if (player.playerInt == currPlayer) {
newPlayer->playerName = playerInfo.playerName; s_player = &player;
newPlayer->avatarDatasetName = playerInfo.avatarShape;
{ for (unsigned i = 0; i < s_players.Count(); ++i) {
if (s_players[i].playerInt == currPlayer) {
s_player = &s_players[i];
break; break;
} }
}} }
} }
plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kCreatePlayer); plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kCreatePlayer);
@ -483,21 +479,21 @@ static void INetCliAuthDeletePlayerCallback (
else { else {
LogMsg(kLogDebug, L"Player deleted: %d", playerInt); LogMsg(kLogDebug, L"Player deleted: %d", playerInt);
uint32_t currPlayer = s_player ? s_player->playerInt : 0; uint32_t currPlayer = s_player ? s_player->playerInt : 0;
{for (uint32_t i = 0; i < s_players.Count(); ++i) { for (auto it = s_players.begin(); it != s_players.end(); ++it) {
if (s_players[i].playerInt == playerInt) { if (it->playerInt == playerInt) {
s_players.DeleteUnordered(i); s_players.erase(it);
break; break;
} }
}} }
{for (uint32_t i = 0; i < s_players.Count(); ++i) { for (NetCommPlayer& player : s_players) {
if (s_players[i].playerInt == currPlayer) { if (player.playerInt == currPlayer) {
s_player = &s_players[i]; s_player = &player;
break; break;
} }
}} }
} }
plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kDeletePlayer); plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kDeletePlayer);
@ -623,12 +619,12 @@ static void INetCliAuthUpgradeVisitorRequestCallback (
else { else {
LogMsg(kLogDebug, L"Upgrade visitor succeeded: %d", playerInt); LogMsg(kLogDebug, L"Upgrade visitor succeeded: %d", playerInt);
{for (uint32_t i = 0; i < s_players.Count(); ++i) { for (NetCommPlayer& player : s_players) {
if (s_players[i].playerInt == playerInt) { if (player.playerInt == playerInt) {
s_players[i].explorer = true; player.explorer = true;
break; break;
} }
}} }
} }
plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kUpgradePlayer); plAccountUpdateMsg* updateMsg = new plAccountUpdateMsg(plAccountUpdateMsg::kUpgradePlayer);
@ -682,13 +678,13 @@ const NetCommPlayer * NetCommGetPlayer () {
} }
//============================================================================ //============================================================================
const ARRAY(NetCommPlayer)& NetCommGetPlayerList () { const std::vector<NetCommPlayer>& NetCommGetPlayerList () {
return s_players; return s_players;
} }
//============================================================================ //============================================================================
unsigned NetCommGetPlayerCount () { unsigned NetCommGetPlayerCount () {
return s_players.Count(); return s_players.size();
} }
//============================================================================ //============================================================================
@ -1101,10 +1097,10 @@ void NetCommSetActivePlayer (//--> plNetCommActivePlayerMsg
if (desiredPlayerInt == 0) if (desiredPlayerInt == 0)
s_player = nil; s_player = nil;
else { else {
for (unsigned i = 0; i < s_players.Count(); ++i) { for (NetCommPlayer& player : s_players) {
if (s_players[i].playerInt == desiredPlayerInt) { if (player.playerInt == desiredPlayerInt) {
playerInt = desiredPlayerInt; playerInt = desiredPlayerInt;
s_player = &s_players[i]; s_player = &player;
break; break;
} }
} }

7
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h

@ -76,6 +76,11 @@ struct NetCommPlayer {
plString playerName; plString playerName;
plString avatarDatasetName; plString avatarDatasetName;
unsigned explorer; unsigned explorer;
NetCommPlayer() { }
NetCommPlayer(unsigned id, const plString& name, const plString& shape, unsigned ex)
: playerInt(id), playerName(name), avatarDatasetName(shape), explorer(ex)
{ }
}; };
struct NetCommAccount { struct NetCommAccount {
@ -102,7 +107,7 @@ const NetCommAge * NetCommGetAge ();
const NetCommAge * NetCommGetStartupAge (); const NetCommAge * NetCommGetStartupAge ();
const NetCommAccount * NetCommGetAccount (); const NetCommAccount * NetCommGetAccount ();
const NetCommPlayer * NetCommGetPlayer (); const NetCommPlayer * NetCommGetPlayer ();
const ARRAY(NetCommPlayer) & NetCommGetPlayerList (); const std::vector<NetCommPlayer> & NetCommGetPlayerList ();
unsigned NetCommGetPlayerCount (); unsigned NetCommGetPlayerCount ();
bool NetCommIsLoginComplete (); bool NetCommIsLoginComplete ();
void NetCommSetIniPlayerId(unsigned playerId); void NetCommSetIniPlayerId(unsigned playerId);

Loading…
Cancel
Save