fixed so predicted sounds and air jump effect works with demo playback

This commit is contained in:
Magnus Auvinen 2009-01-11 15:51:43 +00:00
parent fec578e084
commit 46125d5ed7
8 changed files with 45 additions and 24 deletions

View file

@ -176,8 +176,6 @@ Objects = [
NetIntRange("cid", 0, 'MAX_CLIENTS-1'), NetIntRange("cid", 0, 'MAX_CLIENTS-1'),
]), ]),
NetEvent("AirJump:Common", []),
NetEvent("SoundGlobal:Common", [ NetEvent("SoundGlobal:Common", [
NetIntRange("soundid", 0, 'NUM_SOUNDS-1'), NetIntRange("soundid", 0, 'NUM_SOUNDS-1'),
]), ]),

View file

@ -38,6 +38,8 @@ void EFFECTS::air_jump(vec2 pos)
p.pos = pos + vec2(6.0f, 16.0f); p.pos = pos + vec2(6.0f, 16.0f);
gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); 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) void EFFECTS::damage_indicator(vec2 pos, vec2 dir)

View file

@ -93,6 +93,7 @@ void PLAYERS::render_player(
// check for teamplay modes // check for teamplay modes
bool is_teamplay = false; bool is_teamplay = false;
bool new_tick = gameclient.new_tick;
if(gameclient.snap.gameobj) if(gameclient.snap.gameobj)
is_teamplay = gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS != 0; is_teamplay = gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS != 0;
@ -165,6 +166,7 @@ void PLAYERS::render_player(
gameclient.predicted_char.write(&player); gameclient.predicted_char.write(&player);
gameclient.predicted_prev_char.write(&prev); gameclient.predicted_prev_char.write(&prev);
intratick = client_predintratick(); intratick = client_predintratick();
new_tick = gameclient.new_predicted_tick;
} }
} }
@ -176,6 +178,15 @@ void PLAYERS::render_player(
render_info.got_airjump = player.jumped&2?0:1; 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 if(prev.health < 0) // Don't flicker from previous position
position = vec2(player.x, player.y); position = vec2(player.x, player.y);

View file

@ -21,6 +21,16 @@ void SOUNDS::on_render()
snd_set_listener_pos(gameclient.camera->center.x, gameclient.camera->center.y); 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) void SOUNDS::play(int chn, int setid, float vol, vec2 pos)
{ {
SOUNDSET *set = &data->sounds[setid]; SOUNDSET *set = &data->sounds[setid];

View file

@ -16,6 +16,7 @@ public:
virtual void on_render(); virtual void on_render();
void play(int chn, int setid, float vol, vec2 pos); void play(int chn, int setid, float vol, vec2 pos);
void play_and_record(int chn, int setid, float vol, vec2 pos);
}; };

View file

@ -360,6 +360,10 @@ void GAMECLIENT::on_render()
// render all systems // render all systems
for(int i = 0; i < all.num; i++) for(int i = 0; i < all.num; i++)
all.components[i]->on_render(); all.components[i]->on_render();
// clear new tick flags
new_tick = false;
new_predicted_tick = false;
} }
void GAMECLIENT::on_message(int msgtype) void GAMECLIENT::on_message(int msgtype)
@ -433,6 +437,9 @@ void GAMECLIENT::on_message(int msgtype)
} }
else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL) else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL)
{ {
if(suppress_events)
return;
NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg; NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg;
gameclient.sounds->play(SOUNDS::CHN_GLOBAL, msg->soundid, 1.0f, vec2(0,0)); 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; NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)data;
gameclient.effects->damage_indicator(vec2(ev->x, ev->y), get_direction(ev->angle)); 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) else if(item.type == NETEVENTTYPE_EXPLOSION)
{ {
NETEVENT_EXPLOSION *ev = (NETEVENT_EXPLOSION *)data; NETEVENT_EXPLOSION *ev = (NETEVENT_EXPLOSION *)data;
@ -505,6 +507,8 @@ void GAMECLIENT::process_events()
void GAMECLIENT::on_snapshot() void GAMECLIENT::on_snapshot()
{ {
new_tick = true;
// clear out the invalid pointers // clear out the invalid pointers
mem_zero(&gameclient.snap, sizeof(gameclient.snap)); mem_zero(&gameclient.snap, sizeof(gameclient.snap));
snap.local_cid = -1; snap.local_cid = -1;
@ -744,21 +748,24 @@ void GAMECLIENT::on_predict()
if(tick > last_new_predicted_tick) if(tick > last_new_predicted_tick)
{ {
last_new_predicted_tick = tick; last_new_predicted_tick = tick;
new_predicted_tick = true;
if(snap.local_cid != -1 && world.characters[snap.local_cid]) if(snap.local_cid != -1 && world.characters[snap.local_cid])
{ {
vec2 pos = world.characters[snap.local_cid]->pos; vec2 pos = world.characters[snap.local_cid]->pos;
int events = world.characters[snap.local_cid]->triggered_events; 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_GROUND_JUMP) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
if(events&COREEVENT_AIR_JUMP)
/*if(events&COREEVENT_AIR_JUMP)
{ {
gameclient.effects->air_jump(pos); 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_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_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_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(SOUNDS::CHN_WORLD, SOUND_HOOK_NOATTACH, 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); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
} }
} }

View file

@ -36,6 +36,8 @@ class GAMECLIENT
public: public:
bool suppress_events; bool suppress_events;
bool new_tick;
bool new_predicted_tick;
// TODO: move this // TODO: move this
TUNING_PARAMS tuning; TUNING_PARAMS tuning;

View file

@ -602,16 +602,6 @@ void CHARACTER::tick_defered()
int mask = cmask_all_except_one(player->client_id); 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_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_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()); if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all());