Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Generals/Code/GameEngine/Include/Common/PlayerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class PlayerList : public SubsystemInterface,
*/
Player *findPlayerWithNameKey(NameKeyType key);

void setSlotIndex(Int playerIndex, Byte slotIndex);
Byte getSlotIndex(Int playerIndex) const;
void resolveSlotIndices();

/**
Return the "local" player (ie, the human playing the game).
This will never return null.
Expand Down Expand Up @@ -162,6 +166,7 @@ class PlayerList : public SubsystemInterface,
Player *m_local;
Int m_playerCount;
Player *m_players[MAX_PLAYER_COUNT];
Byte m_slotIndices[MAX_PLAYER_COUNT];

};

Expand Down
47 changes: 46 additions & 1 deletion Generals/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#endif
#include "GameLogic/SidesList.h"
#include "GameNetwork/NetworkDefs.h"

#include "GameNetwork/GameInfo.h"

//-----------------------------------------------------------------------------
/*extern*/ PlayerList *ThePlayerList = nullptr;
Expand Down Expand Up @@ -110,6 +110,49 @@ Player *PlayerList::findPlayerWithNameKey(NameKeyType key)
return nullptr;
}

//-----------------------------------------------------------------------------
void PlayerList::setSlotIndex(Int playerIndex, Byte slotIndex)
{
if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices))
{
m_slotIndices[playerIndex] = slotIndex;
}
}

Comment thread
fbraz3 marked this conversation as resolved.
Byte PlayerList::getSlotIndex(Int playerIndex) const
{
if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices))
{
return m_slotIndices[playerIndex];
}

return -1;
}

void PlayerList::resolveSlotIndices()
{
if (!TheGameInfo)
return;

AsciiString playerName;

for (Int i = 0; i < MAX_SLOTS; ++i)
{
const GameSlot* slot = TheGameInfo->getSlot(i);
if (!slot || !slot->isOccupied())
continue;

playerName.format("player%d", i);

Player* player = findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
if (player)
{
setSlotIndex(player->getPlayerIndex(), i);
}
}
}


Comment thread
fbraz3 marked this conversation as resolved.
//-----------------------------------------------------------------------------
void PlayerList::reset()
{
Expand Down Expand Up @@ -226,13 +269,15 @@ void PlayerList::newGame()
p->setDefaultTeam();
}

resolveSlotIndices();
}

//-----------------------------------------------------------------------------
void PlayerList::init()
{
m_playerCount = 1;
m_players[0]->init(nullptr);
memset(m_slotIndices, -1, sizeof(m_slotIndices));
Comment thread
fbraz3 marked this conversation as resolved.

for (int i = 1; i < MAX_PLAYER_COUNT; i++)
m_players[i]->init(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2345,9 +2345,11 @@ void GameLogic::processCommandList( CommandList *list )
{
// TheSuperHackers @bugfix Caball009 14/06/2026 Check if player is still connected,
// to avoid spurious mismatches at low CRC intervals, e.g. every frame.
if (!TheNetwork->isPlayerConnected(it->first))
const Int slotIndex = ThePlayerList->getSlotIndex(it->first);
if (slotIndex >= 0 && !TheNetwork->isPlayerConnected(slotIndex))
continue;


const UnsignedInt crc = it->second;

if (!hasReferenceCRC)
Expand Down
5 changes: 5 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class PlayerList : public SubsystemInterface,
*/
Player *findPlayerWithNameKey(NameKeyType key);

void setSlotIndex(Int playerIndex, Byte slotIndex);
Comment thread
fbraz3 marked this conversation as resolved.
Byte getSlotIndex(Int playerIndex) const;
void resolveSlotIndices();
Comment thread
fbraz3 marked this conversation as resolved.

/**
Return the "local" player (ie, the human playing the game).
This will never return null.
Expand Down Expand Up @@ -162,6 +166,7 @@ class PlayerList : public SubsystemInterface,
Player *m_local;
Int m_playerCount;
Player *m_players[MAX_PLAYER_COUNT];
Byte m_slotIndices[MAX_PLAYER_COUNT];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why the PlayerList class owns the slot indices as opposed to the GameInfo class owning the player indices?

I am not sure right now which one is better, but my first instinct would have been to tie it to GameInfo class, because that is closer to the slots. Do we have any opinions on this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PlayerList is preferable because there are a couple of places where it's not clear to me if we could easily access GameInfo.

You can search the code base for player%d to find them; one example:

AsciiString name;
name.format("player%d", getPlayerID());
retval->friend_setPlayerIndex( ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(name))->getPlayerIndex());


};

Expand Down
47 changes: 46 additions & 1 deletion GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#endif
#include "GameLogic/SidesList.h"
#include "GameNetwork/NetworkDefs.h"

#include "GameNetwork/GameInfo.h"

//-----------------------------------------------------------------------------
/*extern*/ PlayerList *ThePlayerList = nullptr;
Expand Down Expand Up @@ -110,6 +110,49 @@ Player *PlayerList::findPlayerWithNameKey(NameKeyType key)
return nullptr;
}

//-----------------------------------------------------------------------------
void PlayerList::setSlotIndex(Int playerIndex, Byte slotIndex)
{
if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices))
{
m_slotIndices[playerIndex] = slotIndex;
}
}

Byte PlayerList::getSlotIndex(Int playerIndex) const
{
if (playerIndex >= 0 && playerIndex < ARRAY_SIZE(m_slotIndices))
{
return m_slotIndices[playerIndex];
}

return -1;
}

void PlayerList::resolveSlotIndices()
{
if (!TheGameInfo)
return;

AsciiString playerName;

for (Int i = 0; i < MAX_SLOTS; ++i)
{
const GameSlot* slot = TheGameInfo->getSlot(i);
if (!slot || !slot->isOccupied())
continue;

playerName.format("player%d", i);

Player* player = findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
if (player)
{
setSlotIndex(player->getPlayerIndex(), i);
}
}
}


//-----------------------------------------------------------------------------
void PlayerList::reset()
{
Expand Down Expand Up @@ -226,13 +269,15 @@ void PlayerList::newGame()
p->setDefaultTeam();
}

resolveSlotIndices();
}

//-----------------------------------------------------------------------------
void PlayerList::init()
{
m_playerCount = 1;
m_players[0]->init(nullptr);
memset(m_slotIndices, -1, sizeof(m_slotIndices));

for (int i = 1; i < MAX_PLAYER_COUNT; i++)
m_players[i]->init(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2671,9 +2671,11 @@ void GameLogic::processCommandList( CommandList *list )
{
// TheSuperHackers @bugfix Caball009 14/06/2026 Check if player is still connected,
// to avoid spurious mismatches at low CRC intervals, e.g. every frame.
if (!TheNetwork->isPlayerConnected(it->first))
const Int slotIndex = ThePlayerList->getSlotIndex(it->first);
if (slotIndex >= 0 && !TheNetwork->isPlayerConnected(slotIndex))
continue;


Comment thread
fbraz3 marked this conversation as resolved.
const UnsignedInt crc = it->second;

if (!hasReferenceCRC)
Expand Down
Loading