From a6c1801d546c83055d0c23b6ffca5efc71fba28d Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 11 Nov 2007 10:18:10 +0000 Subject: [PATCH] footstep sound bug, nosway git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1415 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 2 +- source/src/hudgun.cpp | 22 ++++++++------- source/src/server.cpp | 2 +- source/src/sound.cpp | 56 +++++++++++++-------------------------- source/src/weapon.cpp | 8 +++--- 5 files changed, 38 insertions(+), 52 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 0749c7bf..c9a2c6e6 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -375,7 +375,7 @@ void showteamkill() { player1->lastteamkill = lastmillis; } void dodamage(int damage, playerent *pl, playerent *actor, bool gib, bool local) { - if(pl->state!=CS_ALIVE || intermission) return; + if(pl->state != CS_ALIVE || pl->state == CS_EDITING || intermission) return; pl->lastpain = lastmillis; if(local) damage = pl->dodamage(damage); diff --git a/source/src/hudgun.cpp b/source/src/hudgun.cpp index c7562509..e9ce7585 100644 --- a/source/src/hudgun.cpp +++ b/source/src/hudgun.cpp @@ -23,15 +23,19 @@ struct weaponmove pos = player1->o; anim = ANIM_GUN_IDLE; - float k = pow(0.7f, (lastmillis-lastsway)/10.0f); - swaydir.mul(k); - vec dv(player1->vel); - dv.mul((1-k)/max(player1->vel.magnitude(), player1->maxspeed)); - dv.x *= 1.5f; - dv.y *= 1.5f; - dv.z *= 0.4f; - swaydir.add(dv); - pos.add(swaydir); + if(!nosway) + { + float k = pow(0.7f, (lastmillis-lastsway)/10.0f); + swaydir.mul(k); + vec dv(player1->vel); + dv.mul((1-k)/max(player1->vel.magnitude(), player1->maxspeed)); + dv.x *= 1.5f; + dv.y *= 1.5f; + dv.z *= 0.4f; + swaydir.add(dv); + pos.add(swaydir); + } + if(player1->onfloor || player1->onladder || player1->inwater) swaymillis += lastmillis-lastsway; lastsway = lastmillis; diff --git a/source/src/server.cpp b/source/src/server.cpp index 81cc56cb..3c6975e1 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2114,7 +2114,7 @@ void serverslice(uint timeout) // main server update, called from cube main lo int nonlocalclients = numnonlocalclients(); if((smode>1 || (gamemode==0 && nonlocalclients)) && gamemillis-diff>0 && gamemillis/60000!=(gamemillis-diff)/60000) - checkintermission(); + checkintermission(); if(interm && gamemillis>interm) { if(demorecord) enddemorecord(); diff --git a/source/src/sound.cpp b/source/src/sound.cpp index 4570bb06..2df280f5 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -40,6 +40,7 @@ struct soundslot sample *s; int vol; int uses, maxuses; + bool loop; }; struct soundloc @@ -198,7 +199,7 @@ int findsound(char *name, int vol, vector &sounds) return -1; } -int addsound(char *name, int vol, int maxuses, vector &sounds) +int addsound(char *name, int vol, int maxuses, bool loop, vector &sounds) { sample *s = samples.access(name); if(!s) @@ -213,14 +214,15 @@ int addsound(char *name, int vol, int maxuses, vector &sounds) slot.vol = vol ? vol : 100; slot.uses = 0; slot.maxuses = maxuses; + slot.loop = loop; return sounds.length()-1; } -void registersound(char *name, char *vol) { addsound(name, atoi(vol), 0, gamesounds); } -COMMAND(registersound, ARG_2STR); +void registersound(char *name, char *vol, char *loop) { addsound(name, atoi(vol), 0, atoi(loop) != 0, gamesounds); } +COMMAND(registersound, ARG_3STR); -void mapsound(char *name, char *vol, char *maxuses) { addsound(name, atoi(vol), atoi(maxuses) < 0 ? 0 : max(1, *maxuses), mapsounds); } -COMMAND(mapsound, ARG_3STR); +void mapsound(char *name, char *vol, char *maxuses, char *loop) { addsound(name, atoi(vol), atoi(maxuses) < 0 ? 0 : max(1, *maxuses), atoi(loop) != 0, mapsounds); } +COMMAND(mapsound, ARG_4STR); void cleansound() { @@ -262,7 +264,6 @@ void checkmapsounds() } VAR(footsteps, 0, 1, 1); -VAR(footstepalign, 5, 15, 4000); int findsoundloc(int sound, physent *p) { @@ -272,33 +273,15 @@ int findsoundloc(int sound, physent *p) void checkplayerloopsounds() { - loopv(players) + if(footsteps) { - playerent *p = players[i]; - if(!p) continue; - - if(footsteps && camera1->o.dist(p->o) < 16) - { - int idx = findsoundloc(S_FOOTSTEPS, p); - if(idx == -1 || !soundlocs[idx].inuse) - { - // sync to model animation - int basetime = -((int)(size_t)p&0xFFF); - int time = lastmillis-basetime; - int speed = int(1860/p->maxspeed); - // TODO: share with model code - - if(time%speed < footstepalign) playsound(S_FOOTSTEPS, p); - } + if(findsoundloc(S_FOOTSTEPS, player1) == -1) playsound(S_FOOTSTEPS, player1); + loopv(players) + { + playerent *p = players[i]; + if(!p) continue; + if(findsoundloc(S_FOOTSTEPS, p) == -1) playsound(S_FOOTSTEPS, p); } - - // add other sounds here - } - - if(footsteps && (player1->move || player1->strafe)) - { - int idx = findsoundloc(S_FOOTSTEPS, player1); - if(idx == -1 || !soundlocs[idx].inuse) playsound(S_FOOTSTEPS, player1); } } @@ -336,8 +319,8 @@ void updatechanvol(int chan, int svol, soundloc *sl) { playerent *p = (playerent *)sl->pse; ASSERT(p); - bool nofootsteps = p->state != CS_ALIVE || lastmillis-p->lastpain < 300 || (!p->onfloor && p->timeinair>50) || (!p->move && !p->strafe); - if(nofootsteps) vol = 0; // TODO: fade out? + bool nofootsteps = !footsteps || p->state != CS_ALIVE || lastmillis-p->lastpain < 300 || (!p->onfloor && p->timeinair>50) || (!p->move && !p->strafe); + if(nofootsteps) vol = 0; // fade out instead? } } } @@ -374,7 +357,6 @@ soundloc *newsoundloc(int sound, int chan, soundslot *slot, physent *p = NULL, e if(!p && !ent && !loc) return NULL; while(chan >= soundlocs.length()) soundlocs.add().inuse = false; soundloc *sl = &soundlocs[chan]; - sl->inuse = true; sl->slot = slot; sl->pse = p; sl->ent = ent && !p ? ent : NULL; @@ -439,7 +421,7 @@ void playsound(int n, physent *p, entity *ent, const vec *loc) #ifdef USE_MIXER slot.s->sound = Mix_LoadWAV(file); #else - slot.s->sound = FSOUND_Sample_Load(ent ? n+gamesounds.length() : n, file, FSOUND_LOOP_OFF, 0, 0); + slot.s->sound = FSOUND_Sample_Load(ent ? n+gamesounds.length() : n, file, slot.loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF, 0, 0); #endif if(slot.s->sound) break; } @@ -448,7 +430,7 @@ void playsound(int n, physent *p, entity *ent, const vec *loc) } #ifdef USE_MIXER - int chan = Mix_PlayChannel(-1, slot.s->sound, 0); + int chan = Mix_PlayChannel(-1, slot.s->sound, slot.loop ? -1 : 0); #else int chan = FSOUND_PlaySoundEx(FSOUND_FREE, slot.s->sound, NULL, true); #endif @@ -465,7 +447,7 @@ void playsoundname(char *s, const vec *loc, int vol) { if(!vol) vol = 100; int id = findsound(s, vol, gamesounds); - if(id < 0) id = addsound(s, vol, 0, gamesounds); + if(id < 0) id = addsound(s, vol, 0, false, gamesounds); playsound(id, NULL, NULL, loc); } diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index ed95bf9a..ab7399ed 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -389,7 +389,7 @@ void moveprojectiles(float time) { if(p.local) addmsg(SV_EXPLODE, "ri3iv", lastmillis, p.gun, p.id, - hits.length(), hits.length()*sizeof(hitmsg)/sizeof(int), hits.getbuf()); + hits.length(), hits.length()*sizeof(hitmsg)/sizeof(int), hits.getbuf()); projs.remove(i--); } else p.o = v; @@ -535,7 +535,7 @@ void thrownade(playerent *d, bounceent *p) thrownade(d, vel, p); } -bounceent *new_nade(playerent *d, int millis = 0) +bounceent *newnade(playerent *d, int millis = 0) { bounceent *p = newbounceent(); p->owner = d; @@ -592,7 +592,7 @@ void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademilli { if(d!=player1) { - bounceent *p = new_nade(d, nademillis); + bounceent *p = newnade(d, nademillis); thrownade(d, to, p); } break; @@ -746,7 +746,7 @@ void shoot(playerent *d, vec &targ) { if(!hasammo(d)) return; d->mag[d->gunselect]--; - new_nade(d); + newnade(d); updatelastaction(d); d->gunwait[d->gunselect] = attackdelay(d->gunselect); d->lastattackgun = d->gunselect;