mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Simplify switch state using NetArray
This commit is contained in:
parent
264c6f969d
commit
940205b3cc
|
@ -359,3 +359,38 @@ class NetBool(NetIntRange):
|
|||
class NetTick(NetIntAny):
|
||||
def __init__(self, name):
|
||||
NetIntAny.__init__(self,name)
|
||||
|
||||
class NetArray(NetVariable):
|
||||
def __init__(self, var, size):
|
||||
NetVariable.__init__(self,var.name)
|
||||
self.base_name = var.name
|
||||
self.var = var
|
||||
self.size = size
|
||||
self.name = self.base_name + "[%d]"%self.size
|
||||
def emit_declaration(self):
|
||||
self.var.name = self.name
|
||||
return self.var.emit_declaration()
|
||||
def emit_validate(self):
|
||||
lines = []
|
||||
for i in range(self.size):
|
||||
self.var.name = self.base_name + "[%d]"%i
|
||||
lines += self.var.emit_validate()
|
||||
return lines
|
||||
def emit_unpack(self):
|
||||
lines = []
|
||||
for i in range(self.size):
|
||||
self.var.name = self.base_name + "[%d]"%i
|
||||
lines += self.var.emit_unpack()
|
||||
return lines
|
||||
def emit_pack(self):
|
||||
lines = []
|
||||
for i in range(self.size):
|
||||
self.var.name = self.base_name + "[%d]"%i
|
||||
lines += self.var.emit_pack()
|
||||
return lines
|
||||
def emit_unpack_check(self):
|
||||
lines = []
|
||||
for i in range(self.size):
|
||||
self.var.name = self.base_name + "[%d]"%i
|
||||
lines += self.var.emit_unpack_check()
|
||||
return lines
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# pylint: skip-file
|
||||
# See https://github.com/ddnet/ddnet/issues/3507
|
||||
|
||||
from datatypes import Enum, Flags, NetBool, NetEvent, NetIntAny, NetIntRange, NetMessage, NetMessageEx, NetObject, NetObjectEx, NetString, NetStringHalfStrict, NetStringStrict, NetTick
|
||||
from datatypes import Enum, Flags, NetArray, NetBool, NetEvent, NetIntAny, NetIntRange, NetMessage, NetMessageEx, NetObject, NetObjectEx, NetString, NetStringHalfStrict, NetStringStrict, NetTick
|
||||
|
||||
Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"]
|
||||
PlayerFlags = ["PLAYING", "IN_MENU", "CHATTING", "SCOREBOARD", "AIM"]
|
||||
|
@ -314,14 +314,7 @@ Objects = [
|
|||
NetObjectEx("SwitchState", "switch-state@netobj.ddnet.tw", [
|
||||
NetIntRange("m_NumSwitchers", 0, 256),
|
||||
# 256 switches / 32 bits = 8 int32
|
||||
NetIntAny("m_Status1"),
|
||||
NetIntAny("m_Status2"),
|
||||
NetIntAny("m_Status3"),
|
||||
NetIntAny("m_Status4"),
|
||||
NetIntAny("m_Status5"),
|
||||
NetIntAny("m_Status6"),
|
||||
NetIntAny("m_Status7"),
|
||||
NetIntAny("m_Status8"),
|
||||
NetArray(NetIntAny("m_Status"), 8),
|
||||
]),
|
||||
|
||||
# Switch info for map items
|
||||
|
|
|
@ -1447,22 +1447,7 @@ void CGameClient::OnNewSnapshot()
|
|||
|
||||
for(int j = 0; j < NumSwitchers + 1; j++)
|
||||
{
|
||||
if(j < 32)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status1 & (1 << j);
|
||||
else if(j < 64)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status2 & (1 << (j - 32));
|
||||
else if(j < 96)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status3 & (1 << (j - 64));
|
||||
else if(j < 128)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status4 & (1 << (j - 96));
|
||||
else if(j < 160)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status5 & (1 << (j - 128));
|
||||
else if(j < 192)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status6 & (1 << (j - 160));
|
||||
else if(j < 224)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status7 & (1 << (j - 192));
|
||||
else if(j < 256)
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = pSwitchStateData->m_Status8 & (1 << (j - 224));
|
||||
Collision()->m_pSwitchers[j].m_Status[Team] = (pSwitchStateData->m_Status[j / 32] >> (j % 32)) & 1;
|
||||
|
||||
// update
|
||||
if(Collision()->m_pSwitchers[j].m_Status[Team])
|
||||
|
|
|
@ -647,35 +647,12 @@ void IGameController::Snap(int SnappingClient)
|
|||
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;
|
||||
mem_zero(pSwitchState->m_Status, sizeof(pSwitchState->m_Status));
|
||||
|
||||
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);
|
||||
pSwitchState->m_Status[i / 32] |= (Status << (i % 32));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue