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 @@ -150,6 +150,8 @@ class PlayerList : public SubsystemInterface,
*/
PlayerMaskType getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships );

Int getSlotIndex(Int playerIndex) const;

protected:

// snapshot methods
Expand All @@ -158,10 +160,13 @@ class PlayerList : public SubsystemInterface,
virtual void loadPostProcess() override;

private:
void resolveSlotIndices();
void setSlotIndex(Int playerIndex, Int slotIndex);

Player *m_local;
Int m_playerCount;
Player *m_players[MAX_PLAYER_COUNT];
Int m_slotIndices[MAX_PLAYER_COUNT];

};

Expand Down
49 changes: 47 additions & 2 deletions Generals/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
#include "GameLogic/Object.h"
#endif
#include "GameLogic/SidesList.h"
#include "GameNetwork/GameInfo.h"
Comment thread
fbraz3 marked this conversation as resolved.
#include "GameNetwork/NetworkDefs.h"


//-----------------------------------------------------------------------------
/*extern*/ PlayerList *ThePlayerList = nullptr;

Expand Down Expand Up @@ -226,6 +226,7 @@ void PlayerList::newGame()
p->setDefaultTeam();
}

resolveSlotIndices();
}

//-----------------------------------------------------------------------------
Expand All @@ -237,6 +238,8 @@ void PlayerList::init()
for (int i = 1; i < MAX_PLAYER_COUNT; i++)
m_players[i]->init(nullptr);

std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1);

// call setLocalPlayer so that becomingLocalPlayer() gets called appropriately
setLocalPlayer(m_players[0]);

Expand Down Expand Up @@ -383,7 +386,6 @@ Player *PlayerList::getEachPlayerFromMask( PlayerMaskType& maskToAdjust )
return nullptr; // mask not found
}


//-------------------------------------------------------------------------------------------------
PlayerMaskType PlayerList::getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships )
{
Expand Down Expand Up @@ -479,6 +481,49 @@ void PlayerList::xfer( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
void PlayerList::loadPostProcess()
{
std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1);

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 can confirm that this is called after newGame, overwriting its assignments.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it necessary to do anything in loadPostProcess?

}

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

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

return -1;
}

//-----------------------------------------------------------------------------
void PlayerList::resolveSlotIndices()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe call it assignSlotIndices ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe make GameInfo an argument

assignSlotIndices(const GameInfo& gameInfo)

It makes the intent of the function even clearer from the outside.

if (TheGameInfo)
  assignSlotIndices(TheGameInfo)

{
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,8 @@ 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;
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 @@ -150,6 +150,8 @@ class PlayerList : public SubsystemInterface,
*/
PlayerMaskType getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships );

Int getSlotIndex(Int playerIndex) const;

protected:

// snapshot methods
Expand All @@ -158,10 +160,13 @@ class PlayerList : public SubsystemInterface,
virtual void loadPostProcess() override;

private:
void resolveSlotIndices();
void setSlotIndex(Int playerIndex, Int slotIndex);

Player *m_local;
Int m_playerCount;
Player *m_players[MAX_PLAYER_COUNT];
Int m_slotIndices[MAX_PLAYER_COUNT];

};

Expand Down
49 changes: 47 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
#include "GameLogic/Object.h"
#endif
#include "GameLogic/SidesList.h"
#include "GameNetwork/GameInfo.h"
#include "GameNetwork/NetworkDefs.h"


//-----------------------------------------------------------------------------
/*extern*/ PlayerList *ThePlayerList = nullptr;

Expand Down Expand Up @@ -226,6 +226,7 @@ void PlayerList::newGame()
p->setDefaultTeam();
}

resolveSlotIndices();
}

//-----------------------------------------------------------------------------
Expand All @@ -237,6 +238,8 @@ void PlayerList::init()
for (int i = 1; i < MAX_PLAYER_COUNT; i++)
m_players[i]->init(nullptr);

std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1);

// call setLocalPlayer so that becomingLocalPlayer() gets called appropriately
setLocalPlayer(m_players[0]);

Expand Down Expand Up @@ -383,7 +386,6 @@ Player *PlayerList::getEachPlayerFromMask( PlayerMaskType& maskToAdjust )
return nullptr; // mask not found
}


Comment thread
Caball009 marked this conversation as resolved.
//-------------------------------------------------------------------------------------------------
PlayerMaskType PlayerList::getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships )
{
Expand Down Expand Up @@ -479,6 +481,49 @@ void PlayerList::xfer( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
void PlayerList::loadPostProcess()
{
std::fill(m_slotIndices, m_slotIndices + ARRAY_SIZE(m_slotIndices), -1);
}

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

//-----------------------------------------------------------------------------
Int 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,8 @@ 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;
Expand Down
Loading