diff --git a/datasrc/network.py b/datasrc/network.py index d09c5b333..1a83a80fe 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -176,8 +176,6 @@ Objects = [ NetIntRange("cid", 0, 'MAX_CLIENTS-1'), ]), - NetEvent("AirJump:Common", []), - NetEvent("SoundGlobal:Common", [ NetIntRange("soundid", 0, 'NUM_SOUNDS-1'), ]), diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index 5e2e25e37..6b3d90ed9 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -38,6 +38,8 @@ void EFFECTS::air_jump(vec2 pos) p.pos = pos + vec2(6.0f, 16.0f); gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); + + gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos); } void EFFECTS::damage_indicator(vec2 pos, vec2 dir) diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index c0488d190..0b3a70534 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -93,6 +93,7 @@ void PLAYERS::render_player( // check for teamplay modes bool is_teamplay = false; + bool new_tick = gameclient.new_tick; if(gameclient.snap.gameobj) is_teamplay = gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS != 0; @@ -165,6 +166,7 @@ void PLAYERS::render_player( gameclient.predicted_char.write(&player); gameclient.predicted_prev_char.write(&prev); intratick = client_predintratick(); + new_tick = gameclient.new_predicted_tick; } } @@ -175,6 +177,15 @@ void PLAYERS::render_player( gameclient.flow->add(position, vel*100.0f, 10.0f); render_info.got_airjump = player.jumped&2?0:1; + + + // detect events + if(new_tick) + { + // detect air jump + if(!render_info.got_airjump && !(prev.jumped&2)) + gameclient.effects->air_jump(position); + } if(prev.health < 0) // Don't flicker from previous position position = vec2(player.x, player.y); diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index 024d07d42..dfa7e31b9 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -21,6 +21,16 @@ void SOUNDS::on_render() snd_set_listener_pos(gameclient.camera->center.x, gameclient.camera->center.y); } +void SOUNDS::play_and_record(int chn, int setid, float vol, vec2 pos) +{ + NETMSG_SV_SOUNDGLOBAL msg; + msg.soundid = setid; + msg.pack(MSGFLAG_NOSEND|MSGFLAG_RECORD); + client_send_msg(); + + play(chn, setid, vol, pos); +} + void SOUNDS::play(int chn, int setid, float vol, vec2 pos) { SOUNDSET *set = &data->sounds[setid]; diff --git a/src/game/client/components/sounds.hpp b/src/game/client/components/sounds.hpp index 5e3dfd6e8..95ddb1ecc 100644 --- a/src/game/client/components/sounds.hpp +++ b/src/game/client/components/sounds.hpp @@ -16,6 +16,7 @@ public: virtual void on_render(); void play(int chn, int setid, float vol, vec2 pos); + void play_and_record(int chn, int setid, float vol, vec2 pos); }; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 9af337e05..69045cce6 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -360,6 +360,10 @@ void GAMECLIENT::on_render() // render all systems for(int i = 0; i < all.num; i++) all.components[i]->on_render(); + + // clear new tick flags + new_tick = false; + new_predicted_tick = false; } void GAMECLIENT::on_message(int msgtype) @@ -433,6 +437,9 @@ void GAMECLIENT::on_message(int msgtype) } else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL) { + if(suppress_events) + return; + NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg; gameclient.sounds->play(SOUNDS::CHN_GLOBAL, msg->soundid, 1.0f, vec2(0,0)); } @@ -470,11 +477,6 @@ void GAMECLIENT::process_events() NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)data; gameclient.effects->damage_indicator(vec2(ev->x, ev->y), get_direction(ev->angle)); } - else if(item.type == NETEVENTTYPE_AIRJUMP) - { - NETEVENT_COMMON *ev = (NETEVENT_COMMON *)data; - gameclient.effects->air_jump(vec2(ev->x, ev->y)); - } else if(item.type == NETEVENTTYPE_EXPLOSION) { NETEVENT_EXPLOSION *ev = (NETEVENT_EXPLOSION *)data; @@ -505,6 +507,8 @@ void GAMECLIENT::process_events() void GAMECLIENT::on_snapshot() { + new_tick = true; + // clear out the invalid pointers mem_zero(&gameclient.snap, sizeof(gameclient.snap)); snap.local_cid = -1; @@ -621,7 +625,7 @@ void GAMECLIENT::on_snapshot() snap.characters[item.id].active = true; snap.characters[item.id].prev = *((const NETOBJ_CHARACTER *)old); snap.characters[item.id].cur = *((const NETOBJ_CHARACTER *)data); - + if(snap.characters[item.id].prev.tick) evolve(&snap.characters[item.id].prev, client_prevtick()); if(snap.characters[item.id].cur.tick) @@ -744,21 +748,24 @@ void GAMECLIENT::on_predict() if(tick > last_new_predicted_tick) { last_new_predicted_tick = tick; + new_predicted_tick = true; if(snap.local_cid != -1 && world.characters[snap.local_cid]) { vec2 pos = world.characters[snap.local_cid]->pos; int events = world.characters[snap.local_cid]->triggered_events; - if(events&COREEVENT_GROUND_JUMP) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); - if(events&COREEVENT_AIR_JUMP) + if(events&COREEVENT_GROUND_JUMP) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); + + /*if(events&COREEVENT_AIR_JUMP) { gameclient.effects->air_jump(pos); - gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, 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) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); - if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, pos); + if(events&COREEVENT_HOOK_ATTACH_GROUND) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); + if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, pos); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); } } diff --git a/src/game/client/gameclient.hpp b/src/game/client/gameclient.hpp index dfd642e6d..beb87b8e2 100644 --- a/src/game/client/gameclient.hpp +++ b/src/game/client/gameclient.hpp @@ -36,6 +36,8 @@ class GAMECLIENT public: bool suppress_events; + bool new_tick; + bool new_predicted_tick; // TODO: move this TUNING_PARAMS tuning; diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 3714bf08f..479b1243c 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -602,16 +602,6 @@ void CHARACTER::tick_defered() int mask = cmask_all_except_one(player->client_id); if(events&COREEVENT_GROUND_JUMP) game.create_sound(pos, SOUND_PLAYER_JUMP, mask); - if(events&COREEVENT_AIR_JUMP) - { - game.create_sound(pos, SOUND_PLAYER_AIRJUMP, mask); - NETEVENT_COMMON *c = (NETEVENT_COMMON *)game.events.create(NETEVENTTYPE_AIRJUMP, sizeof(NETEVENT_COMMON), mask); - if(c) - { - c->x = (int)pos.x; - c->y = (int)pos.y; - } - } //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all());