Browse Source

Merge pull request #500 from Hoikas/player-array

Convert NetCommPlayer to std::vector
Michael Hansen 9 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()
{
const ARRAY(NetCommPlayer)& playerList = NetCommGetPlayerList();
int numPlayers = NetCommGetPlayerCount();
const std::vector<NetCommPlayer>& playerList = NetCommGetPlayerList();
PyObject* pList = PyList_New(0);
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* playerName = PyUnicode_FromStringEx(playerList[i].playerName);
PyObject* playerId = PyInt_FromLong(playerList[i].playerInt);
PyObject* avatarShape = PyString_FromPlString(playerList[i].avatarDatasetName);
PyTuple_SetItem(playerTuple, 0, playerName);
PyTuple_SetItem(playerTuple, 1, playerId);
PyTuple_SetItem(playerTuple, 2, avatarShape);
PyTuple_SET_ITEM(playerTuple, 0, playerName);
PyTuple_SET_ITEM(playerTuple, 1, playerId);
PyTuple_SET_ITEM(playerTuple, 2, avatarShape);
if (visitor || playerList[i].explorer)
PyList_Append(pList, playerTuple);

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

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

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

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

Loading…
Cancel
Save