Send switch states per team and cleanup

This commit is contained in:
fokkonaut 2021-08-23 23:17:44 +02:00
parent b851d74f54
commit 69fe35f288
5 changed files with 75 additions and 93 deletions

View file

@ -1400,31 +1400,42 @@ void CGameClient::OnNewSnapshot()
m_Snap.m_paFlags[Item.m_ID % 2] = (const CNetObj_Flag *)pData;
else if(Item.m_Type == NETOBJTYPE_SWITCHSTATE)
{
m_Snap.m_HasSwitchState = true;
const CNetObj_SwitchState *pSwitchStateData = (const CNetObj_SwitchState *)pData;
CClientData *pClient = &m_aClients[Item.m_ID];
int Team = Item.m_ID;
mem_zero(pClient->m_SwitchStates, sizeof(pClient->m_SwitchStates));
int NumSwitchers = clamp(pSwitchStateData->m_NumSwitchers, 0, 255);
if(!Collision()->m_pSwitchers || NumSwitchers != Collision()->m_NumSwitchers)
{
delete Collision()->m_pSwitchers;
Collision()->m_pSwitchers = new CCollision::SSwitchers[NumSwitchers + 1];
Collision()->m_NumSwitchers = NumSwitchers;
}
for(int i = 0; i < pSwitchStateData->m_NumSwitchers + 1; i++)
for(int i = 0; i < NumSwitchers + 1; i++)
{
if(i < 32)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status1 & (1 << i);
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status1 & (1 << i);
else if(i < 64)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status2 & (1 << (i - 32));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status2 & (1 << (i - 32));
else if(i < 96)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status3 & (1 << (i - 64));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status3 & (1 << (i - 64));
else if(i < 128)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status4 & (1 << (i - 96));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status4 & (1 << (i - 96));
else if(i < 160)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status5 & (1 << (i - 128));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status5 & (1 << (i - 128));
else if(i < 192)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status6 & (1 << (i - 160));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status6 & (1 << (i - 160));
else if(i < 224)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status7 & (1 << (i - 192));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status7 & (1 << (i - 192));
else if(i < 256)
pClient->m_SwitchStates[i] = pSwitchStateData->m_Status8 & (1 << (i - 224));
Collision()->m_pSwitchers[i].m_Status[Team] = pSwitchStateData->m_Status8 & (1 << (i - 224));
// update
if(Collision()->m_pSwitchers[i].m_Status[Team])
Collision()->m_pSwitchers[i].m_Type[Team] = TILE_SWITCHOPEN;
else
Collision()->m_pSwitchers[i].m_Type[Team] = TILE_SWITCHCLOSE;
Collision()->m_pSwitchers[i].m_EndTick[Team] = 0;
}
}
}
@ -2200,32 +2211,6 @@ void CGameClient::UpdatePrediction()
m_GameWorld.m_WorldConfig.m_InfiniteAmmo = false;
m_GameWorld.m_WorldConfig.m_IsSolo = !m_Snap.m_aCharacters[m_Snap.m_LocalClientID].m_HasExtendedData && !m_Tuning[g_Config.m_ClDummy].m_PlayerCollision && !m_Tuning[g_Config.m_ClDummy].m_PlayerHooking;
// update switch state
if(Collision()->m_pSwitchers)
{
const int NumSwitchers = minimum(255, Collision()->m_NumSwitchers);
for(int i = 0; i < MAX_CLIENTS; i++)
{
int Team = m_Teams.Team(i);
if(!m_Snap.m_aCharacters[i].m_Active || !in_range(Team, 0, MAX_CLIENTS - 1))
continue;
for(int Number = 1; Number <= NumSwitchers; Number++)
{
if(m_Snap.m_HasSwitchState && m_aClients[i].m_SwitchStates[Number])
{
Collision()->m_pSwitchers[Number].m_Status[Team] = true;
Collision()->m_pSwitchers[Number].m_Type[Team] = TILE_SWITCHOPEN;
}
else
{
Collision()->m_pSwitchers[Number].m_Status[Team] = false;
Collision()->m_pSwitchers[Number].m_Type[Team] = TILE_SWITCHCLOSE;
}
Collision()->m_pSwitchers[Number].m_EndTick[Team] = 0;
}
}
}
// update the tuning/tunezone at the local character position with the latest tunings received before the new snapshot
vec2 LocalCharPos = vec2(m_Snap.m_pLocalCharacter->m_X, m_Snap.m_pLocalCharacter->m_Y);
m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy];

View file

@ -311,8 +311,6 @@ public:
vec2 m_Position;
};
bool m_HasSwitchState;
CCharacterInfo m_aCharacters[MAX_CLIENTS];
};

View file

@ -116,13 +116,6 @@ public:
class CLayers *Layers() { return m_pLayers; }
int m_NumSwitchers;
private:
class CTeleTile *m_pTele;
class CSpeedupTile *m_pSpeedup;
class CTile *m_pFront;
class CSwitchTile *m_pSwitch;
class CTuneTile *m_pTune;
class CDoorTile *m_pDoor;
struct SSwitchers
{
bool m_Status[MAX_CLIENTS];
@ -130,9 +123,15 @@ private:
int m_EndTick[MAX_CLIENTS];
int m_Type[MAX_CLIENTS];
};
public:
SSwitchers *m_pSwitchers;
private:
class CTeleTile *m_pTele;
class CSpeedupTile *m_pSpeedup;
class CTile *m_pFront;
class CSwitchTile *m_pSwitch;
class CTuneTile *m_pTune;
class CDoorTile *m_pDoor;
};
void ThroughOffset(vec2 Pos0, vec2 Pos1, int *Ox, int *Oy);

View file

@ -1246,49 +1246,6 @@ void CCharacter::Snap(int SnappingClient)
SnapCharacter(SnappingClient, ID);
if(GameServer()->Collision()->m_pSwitchers)
{
CNetObj_SwitchState *pSwitchState = static_cast<CNetObj_SwitchState *>(Server()->SnapNewItem(NETOBJTYPE_SWITCHSTATE, ID, sizeof(CNetObj_SwitchState)));
if(!pSwitchState)
return;
pSwitchState->m_NumSwitchers = GameServer()->Collision()->m_NumSwitchers;
if(pSwitchState->m_NumSwitchers > 256)
pSwitchState->m_NumSwitchers = 256;
pSwitchState->m_Status1 = 0;
pSwitchState->m_Status2 = 0;
pSwitchState->m_Status3 = 0;
pSwitchState->m_Status4 = 0;
pSwitchState->m_Status5 = 0;
pSwitchState->m_Status6 = 0;
pSwitchState->m_Status7 = 0;
pSwitchState->m_Status8 = 0;
for(int i = 0; i < pSwitchState->m_NumSwitchers + 1; i++)
{
int Status = (int)GameServer()->Collision()->m_pSwitchers[i].m_Status[Team()];
if(i < 32)
pSwitchState->m_Status1 |= Status << i;
else if(i < 64)
pSwitchState->m_Status2 |= Status << (i - 32);
else if(i < 96)
pSwitchState->m_Status3 |= Status << (i - 64);
else if(i < 128)
pSwitchState->m_Status4 |= Status << (i - 96);
else if(i < 160)
pSwitchState->m_Status5 |= Status << (i - 128);
else if(i < 192)
pSwitchState->m_Status6 |= Status << (i - 160);
else if(i < 224)
pSwitchState->m_Status7 |= Status << (i - 192);
else if(i < 256)
pSwitchState->m_Status8 |= Status << (i - 224);
}
}
CNetObj_DDNetCharacter *pDDNetCharacter = static_cast<CNetObj_DDNetCharacter *>(Server()->SnapNewItem(NETOBJTYPE_DDNETCHARACTER, ID, sizeof(CNetObj_DDNetCharacter)));
if(!pDDNetCharacter)
return;

View file

@ -628,6 +628,49 @@ void IGameController::Snap(int SnappingClient)
pRaceData->m_Precision = 0;
pRaceData->m_RaceFlags = protocol7::RACEFLAG_HIDE_KILLMSG | protocol7::RACEFLAG_KEEP_WANTED_WEAPON;
}
if(GameServer()->Collision()->m_pSwitchers)
{
// update all teams
for(int i = 0; i < MAX_CLIENTS; i++)
{
CNetObj_SwitchState *pSwitchState = static_cast<CNetObj_SwitchState *>(Server()->SnapNewItem(NETOBJTYPE_SWITCHSTATE, i, sizeof(CNetObj_SwitchState)));
if(!pSwitchState)
return;
pSwitchState->m_NumSwitchers = clamp(GameServer()->Collision()->m_NumSwitchers, 0, 255);
pSwitchState->m_Status1 = 0;
pSwitchState->m_Status2 = 0;
pSwitchState->m_Status3 = 0;
pSwitchState->m_Status4 = 0;
pSwitchState->m_Status5 = 0;
pSwitchState->m_Status6 = 0;
pSwitchState->m_Status7 = 0;
pSwitchState->m_Status8 = 0;
for(int j = 0; j < pSwitchState->m_NumSwitchers + 1; j++)
{
int Status = (int)GameServer()->Collision()->m_pSwitchers[j].m_Status[i];
if(j < 32)
pSwitchState->m_Status1 |= Status << j;
else if(j < 64)
pSwitchState->m_Status2 |= Status << (j - 32);
else if(j < 96)
pSwitchState->m_Status3 |= Status << (j - 64);
else if(j < 128)
pSwitchState->m_Status4 |= Status << (j - 96);
else if(j < 160)
pSwitchState->m_Status5 |= Status << (j - 128);
else if(j < 192)
pSwitchState->m_Status6 |= Status << (j - 160);
else if(j < 224)
pSwitchState->m_Status7 |= Status << (j - 192);
else if(j < 256)
pSwitchState->m_Status8 |= Status << (j - 224);
}
}
}
}
int IGameController::GetAutoTeam(int NotThisID)