mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
cleaned up core events
This commit is contained in:
parent
6c530b2926
commit
d2924b5ad6
|
@ -7,6 +7,7 @@ Emoticons = Enum("EMOTICON", ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT",
|
|||
PlayerFlags = Flags("PLAYERFLAG", ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"])
|
||||
GameFlags = Flags("GAMEFLAG", ["TEAMS", "FLAGS", "SURVIVAL"])
|
||||
GameStateFlags = Flags("GAMESTATEFLAG", ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"])
|
||||
CoreEventFlags = Flags("COREEVENTFLAG", ["GROUND_JUMP", "AIR_JUMP", "HOOK_ATTACH_PLAYER", "HOOK_ATTACH_GROUND", "HOOK_HIT_NOHOOK"])
|
||||
|
||||
GameMsgIDs = Enum("GAMEMSG", ["TEAM_SWAP", "VOTE_ABORT", "VOTE_PASS", "VOTE_FAIL", "VOTE_DENY_SPECCALL", "VOTE_DENY_ACTIVE", "VOTE_DENY_KICK", "VOTE_DENY_KICKID",
|
||||
"VOTE_DENY_KICKSELF", "VOTE_DENY_KICKADMIN", "VOTE_DENY_SPEC", "VOTE_DENY_SPECID", "VOTE_DENY_SPECSELF", "SPEC_INVALIDID", "TEAM_SHUFFLE",
|
||||
|
@ -63,7 +64,8 @@ Enums = [
|
|||
Flags = [
|
||||
PlayerFlags,
|
||||
GameFlags,
|
||||
GameStateFlags
|
||||
GameStateFlags,
|
||||
CoreEventFlags,
|
||||
]
|
||||
|
||||
Objects = [
|
||||
|
@ -163,6 +165,7 @@ Objects = [
|
|||
NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'),
|
||||
NetEnum("m_Emote", Emotes),
|
||||
NetTick("m_AttackTick"),
|
||||
NetFlag("m_TriggeredEvents", CoreEventFlags),
|
||||
]),
|
||||
|
||||
NetObject("PlayerInfo", [
|
||||
|
@ -345,10 +348,6 @@ Messages = [
|
|||
NetStringStrict("m_pReason"),
|
||||
]),
|
||||
|
||||
NetMessage("De_SoundGlobal", [
|
||||
NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'),
|
||||
]),
|
||||
|
||||
### Client messages
|
||||
NetMessage("Cl_Say", [
|
||||
NetBool("m_Team"),
|
||||
|
|
|
@ -264,15 +264,6 @@ void CPlayers::RenderPlayer(
|
|||
|
||||
RenderInfo.m_GotAirJump = Player.m_Jumped&2?0:1;
|
||||
|
||||
|
||||
// detect events
|
||||
if(NewTick)
|
||||
{
|
||||
// detect air jump
|
||||
if(!RenderInfo.m_GotAirJump && !(Prev.m_Jumped&2))
|
||||
m_pClient->m_pEffects->AirJump(Position);
|
||||
}
|
||||
|
||||
bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
|
||||
bool InAir = !Collision()->CheckPoint(Player.m_X, Player.m_Y+16);
|
||||
bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
|
||||
|
|
|
@ -150,15 +150,6 @@ void CSounds::Enqueue(int Channel, int SetId)
|
|||
}
|
||||
}
|
||||
|
||||
void CSounds::PlayAndRecord(int Chn, int SetId, float Vol, vec2 Pos)
|
||||
{
|
||||
CNetMsg_De_SoundGlobal Msg;
|
||||
Msg.m_SoundID = SetId;
|
||||
Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD);
|
||||
|
||||
Play(Chn, SetId, Vol);
|
||||
}
|
||||
|
||||
void CSounds::Play(int Chn, int SetId, float Vol)
|
||||
{
|
||||
if(Chn == CHN_MUSIC && !g_Config.m_SndMusic)
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
void Enqueue(int Channel, int SetId);
|
||||
void Play(int Channel, int SetId, float Vol);
|
||||
void PlayAt(int Channel, int SetId, float Vol, vec2 Pos);
|
||||
void PlayAndRecord(int Channel, int SetId, float Vol, vec2 Pos);
|
||||
void Stop(int SetId);
|
||||
};
|
||||
|
||||
|
|
|
@ -803,14 +803,6 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
|
|||
m_aClients[pMsg->m_ClientID].m_Emoticon = pMsg->m_Emoticon;
|
||||
m_aClients[pMsg->m_ClientID].m_EmoticonStart = Client()->GameTick();
|
||||
}
|
||||
else if(MsgId == NETMSGTYPE_DE_SOUNDGLOBAL)
|
||||
{
|
||||
if(m_SuppressEvents)
|
||||
return;
|
||||
|
||||
CNetMsg_De_SoundGlobal *pMsg = (CNetMsg_De_SoundGlobal *)pRawMsg;
|
||||
g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f);
|
||||
}
|
||||
else if(MsgId == NETMSGTYPE_DE_CLIENTENTER && Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
{
|
||||
CNetMsg_De_ClientEnter *pMsg = (CNetMsg_De_ClientEnter *)pRawMsg;
|
||||
|
@ -899,6 +891,27 @@ void CGameClient::ProcessEvents()
|
|||
}
|
||||
}
|
||||
|
||||
void CGameClient::ProcessTriggeredEvents(int Events, vec2 Pos)
|
||||
{
|
||||
if(m_SuppressEvents)
|
||||
return;
|
||||
|
||||
if(Events&COREEVENTFLAG_GROUND_JUMP)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, Pos);
|
||||
if(Events&COREEVENTFLAG_AIR_JUMP)
|
||||
m_pEffects->AirJump(Pos);
|
||||
if(Events&COREEVENTFLAG_HOOK_ATTACH_PLAYER)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, Pos);
|
||||
if(Events&COREEVENTFLAG_HOOK_ATTACH_GROUND)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, Pos);
|
||||
if(Events&COREEVENTFLAG_HOOK_HIT_NOHOOK)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, Pos);
|
||||
/*if(Events&COREEVENTFLAG_HOOK_LAUNCH)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, Pos);
|
||||
if(Events&COREEVENTFLAG_HOOK_RETRACT)
|
||||
m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, Pos);*/
|
||||
}
|
||||
|
||||
void CGameClient::OnNewSnapshot()
|
||||
{
|
||||
m_NewTick = true;
|
||||
|
@ -1050,6 +1063,9 @@ void CGameClient::OnNewSnapshot()
|
|||
if(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Tick)
|
||||
Evolve(&m_Snap.m_aCharacters[Item.m_ID].m_Cur, Client()->GameTick());
|
||||
}
|
||||
|
||||
if(Item.m_ID != m_LocalClientID || Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
ProcessTriggeredEvents(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_TriggeredEvents, vec2(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_X, m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Y));
|
||||
}
|
||||
else if(Item.m_Type == NETOBJTYPE_SPECTATORINFO)
|
||||
{
|
||||
|
@ -1291,23 +1307,7 @@ void CGameClient::OnPredict()
|
|||
m_NewPredictedTick = true;
|
||||
|
||||
if(m_LocalClientID != -1 && World.m_apCharacters[m_LocalClientID])
|
||||
{
|
||||
vec2 Pos = World.m_apCharacters[m_LocalClientID]->m_Pos;
|
||||
int Events = World.m_apCharacters[m_LocalClientID]->m_TriggeredEvents;
|
||||
if(Events&COREEVENT_GROUND_JUMP) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, Pos);
|
||||
|
||||
/*if(events&COREEVENT_AIR_JUMP)
|
||||
{
|
||||
GameClient.effects->air_jump(pos);
|
||||
GameClient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos);
|
||||
}*/
|
||||
|
||||
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
|
||||
//if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos);
|
||||
if(Events&COREEVENT_HOOK_ATTACH_GROUND) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, Pos);
|
||||
if(Events&COREEVENT_HOOK_HIT_NOHOOK) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, Pos);
|
||||
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
|
||||
}
|
||||
ProcessTriggeredEvents(World.m_apCharacters[m_LocalClientID]->m_TriggeredEvents, World.m_apCharacters[m_LocalClientID]->m_Pos);
|
||||
}
|
||||
|
||||
if(Tick == Client()->PredGameTick() && World.m_apCharacters[m_LocalClientID])
|
||||
|
|
|
@ -51,6 +51,7 @@ class CGameClient : public IGameClient
|
|||
|
||||
void DispatchInput();
|
||||
void ProcessEvents();
|
||||
void ProcessTriggeredEvents(int Events, vec2 Pos);
|
||||
void UpdatePositions();
|
||||
|
||||
int m_PredictedTick;
|
||||
|
|
|
@ -118,13 +118,13 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
{
|
||||
if(Grounded)
|
||||
{
|
||||
m_TriggeredEvents |= COREEVENT_GROUND_JUMP;
|
||||
m_TriggeredEvents |= COREEVENTFLAG_GROUND_JUMP;
|
||||
m_Vel.y = -m_pWorld->m_Tuning.m_GroundJumpImpulse;
|
||||
m_Jumped |= 1;
|
||||
}
|
||||
else if(!(m_Jumped&2))
|
||||
{
|
||||
m_TriggeredEvents |= COREEVENT_AIR_JUMP;
|
||||
m_TriggeredEvents |= COREEVENTFLAG_AIR_JUMP;
|
||||
m_Vel.y = -m_pWorld->m_Tuning.m_AirJumpImpulse;
|
||||
m_Jumped |= 3;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
m_HookDir = TargetDirection;
|
||||
m_HookedPlayer = -1;
|
||||
m_HookTick = 0;
|
||||
m_TriggeredEvents |= COREEVENT_HOOK_LAUNCH;
|
||||
//m_TriggeredEvents |= COREEVENTFLAG_HOOK_LAUNCH;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -182,7 +182,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
else if(m_HookState == HOOK_RETRACT_END)
|
||||
{
|
||||
m_HookState = HOOK_RETRACTED;
|
||||
m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
|
||||
//m_TriggeredEvents |= COREEVENTFLAG_HOOK_RETRACT;
|
||||
m_HookState = HOOK_RETRACTED;
|
||||
}
|
||||
else if(m_HookState == HOOK_FLYING)
|
||||
|
@ -221,7 +221,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
{
|
||||
if (m_HookedPlayer == -1 || distance(m_HookPos, pCharCore->m_Pos) < Distance)
|
||||
{
|
||||
m_TriggeredEvents |= COREEVENT_HOOK_ATTACH_PLAYER;
|
||||
m_TriggeredEvents |= COREEVENTFLAG_HOOK_ATTACH_PLAYER;
|
||||
m_HookState = HOOK_GRABBED;
|
||||
m_HookedPlayer = i;
|
||||
Distance = distance(m_HookPos, pCharCore->m_Pos);
|
||||
|
@ -235,12 +235,12 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
// check against ground
|
||||
if(GoingToHitGround)
|
||||
{
|
||||
m_TriggeredEvents |= COREEVENT_HOOK_ATTACH_GROUND;
|
||||
m_TriggeredEvents |= COREEVENTFLAG_HOOK_ATTACH_GROUND;
|
||||
m_HookState = HOOK_GRABBED;
|
||||
}
|
||||
else if(GoingToRetract)
|
||||
{
|
||||
m_TriggeredEvents |= COREEVENT_HOOK_HIT_NOHOOK;
|
||||
m_TriggeredEvents |= COREEVENTFLAG_HOOK_HIT_NOHOOK;
|
||||
m_HookState = HOOK_RETRACT_START;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,14 +150,6 @@ enum
|
|||
HOOK_RETRACT_END=3,
|
||||
HOOK_FLYING,
|
||||
HOOK_GRABBED,
|
||||
|
||||
COREEVENT_GROUND_JUMP=0x01,
|
||||
COREEVENT_AIR_JUMP=0x02,
|
||||
COREEVENT_HOOK_LAUNCH=0x04,
|
||||
COREEVENT_HOOK_ATTACH_PLAYER=0x08,
|
||||
COREEVENT_HOOK_ATTACH_GROUND=0x10,
|
||||
COREEVENT_HOOK_HIT_NOHOOK=0x20,
|
||||
COREEVENT_HOOK_RETRACT=0x40,
|
||||
};
|
||||
|
||||
class CWorldCore
|
||||
|
|
|
@ -47,6 +47,7 @@ CCharacter::CCharacter(CGameWorld *pWorld)
|
|||
m_ProximityRadius = ms_PhysSize;
|
||||
m_Health = 0;
|
||||
m_Armor = 0;
|
||||
m_TriggeredEvents = 0;
|
||||
}
|
||||
|
||||
void CCharacter::Reset()
|
||||
|
@ -614,16 +615,8 @@ void CCharacter::TickDefered()
|
|||
StartVelX.u, StartVelY.u);
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
||||
}
|
||||
|
||||
int Events = m_Core.m_TriggeredEvents;
|
||||
int Mask = CmaskAllExceptOne(m_pPlayer->GetCID());
|
||||
|
||||
if(Events&COREEVENT_GROUND_JUMP) GameServer()->CreateSound(m_Pos, SOUND_PLAYER_JUMP, Mask);
|
||||
|
||||
if(Events&COREEVENT_HOOK_ATTACH_PLAYER) GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_PLAYER, CmaskAll());
|
||||
if(Events&COREEVENT_HOOK_ATTACH_GROUND) GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_GROUND, Mask);
|
||||
if(Events&COREEVENT_HOOK_HIT_NOHOOK) GameServer()->CreateSound(m_Pos, SOUND_HOOK_NOATTACH, Mask);
|
||||
|
||||
|
||||
m_TriggeredEvents |= m_Core.m_TriggeredEvents;
|
||||
|
||||
if(m_pPlayer->GetTeam() == TEAM_SPECTATORS)
|
||||
{
|
||||
|
@ -842,6 +835,7 @@ void CCharacter::Snap(int SnappingClient)
|
|||
pCharacter->m_AmmoCount = 0;
|
||||
pCharacter->m_Health = 0;
|
||||
pCharacter->m_Armor = 0;
|
||||
pCharacter->m_TriggeredEvents = m_TriggeredEvents;
|
||||
|
||||
pCharacter->m_Weapon = m_ActiveWeapon;
|
||||
pCharacter->m_AttackTick = m_AttackTick;
|
||||
|
@ -865,3 +859,8 @@ void CCharacter::Snap(int SnappingClient)
|
|||
pCharacter->m_Emote = EMOTE_BLINK;
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacter::PostSnap()
|
||||
{
|
||||
m_TriggeredEvents = 0;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
virtual void TickDefered();
|
||||
virtual void TickPaused();
|
||||
virtual void Snap(int SnappingClient);
|
||||
virtual void PostSnap();
|
||||
|
||||
bool IsGrounded();
|
||||
|
||||
|
@ -103,6 +104,8 @@ private:
|
|||
int m_Health;
|
||||
int m_Armor;
|
||||
|
||||
int m_TriggeredEvents;
|
||||
|
||||
// ninja
|
||||
struct
|
||||
{
|
||||
|
|
|
@ -83,6 +83,8 @@ public:
|
|||
*/
|
||||
virtual void Snap(int SnappingClient) {}
|
||||
|
||||
virtual void PostSnap() {}
|
||||
|
||||
/*
|
||||
Function: networkclipped(int snapping_client)
|
||||
Performs a series of test to see if a client can see the
|
||||
|
|
|
@ -1594,6 +1594,7 @@ void CGameContext::OnSnap(int ClientID)
|
|||
void CGameContext::OnPreSnap() {}
|
||||
void CGameContext::OnPostSnap()
|
||||
{
|
||||
m_World.PostSnap();
|
||||
m_Events.Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,17 @@ void CGameWorld::Snap(int SnappingClient)
|
|||
}
|
||||
}
|
||||
|
||||
void CGameWorld::PostSnap()
|
||||
{
|
||||
for(int i = 0; i < NUM_ENTTYPES; i++)
|
||||
for(CEntity *pEnt = m_apFirstEntityTypes[i]; pEnt; )
|
||||
{
|
||||
m_pNextTraverseEntity = pEnt->m_pNextTypeEntity;
|
||||
pEnt->PostSnap();
|
||||
pEnt = m_pNextTraverseEntity;
|
||||
}
|
||||
}
|
||||
|
||||
void CGameWorld::Reset()
|
||||
{
|
||||
// reset all entities
|
||||
|
|
|
@ -135,6 +135,8 @@ public:
|
|||
is being created.
|
||||
*/
|
||||
void Snap(int SnappingClient);
|
||||
|
||||
void PostSnap();
|
||||
|
||||
/*
|
||||
Function: tick
|
||||
|
|
Loading…
Reference in a new issue