From 58abfb3ace3c3a127df83fab615d2f1987b25367 Mon Sep 17 00:00:00 2001 From: aerkefiende Date: Sat, 19 Jan 2013 21:44:40 +0000 Subject: [PATCH] Sound bug fix by Felix-The-Ghost git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7117 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clients2c.cpp | 11 +++++++++++ source/src/sound.h | 3 ++- source/src/world.cpp | 41 ++++++++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index b6835d06..2ee6936b 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -968,6 +968,17 @@ void parsemessages(int cn, playerent *d, ucharbuf &p, bool demo = false) uint i = getint(p); while((uint)ents.length()<=i) ents.add().type = NOTUSED; int to = ents[i].type; + if(ents[i].type==SOUND) + { + entity &e = ents[i]; + + entityreference entref(&e); + location *loc = audiomgr.locations.find(e.attr1, &entref, mapsounds); + + if(loc) + loc->drop(); + } + ents[i].type = getint(p); ents[i].x = getint(p); ents[i].y = getint(p); diff --git a/source/src/sound.h b/source/src/sound.h index 347ddfd9..c277bca2 100644 --- a/source/src/sound.h +++ b/source/src/sound.h @@ -379,11 +379,12 @@ class audiomanager ALCcontext *context; bufferhashtable bufferpool; - locvector locations; oggstream *gamemusic; public: + locvector locations; + audiomanager(); // init & setup diff --git a/source/src/world.cpp b/source/src/world.cpp index 2aa33879..3b7eaafc 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -184,7 +184,12 @@ void entproperty(int prop, int amount) switch(e.type) { case LIGHT: calclight(); break; - case SOUND: audiomgr.preloadmapsound(e); + case SOUND: + audiomgr.preloadmapsound(e); + entityreference entref(&e); + location *loc = audiomgr.locations.find(e.attr1-amount, &entref, mapsounds); + if(loc) + loc->drop(); } if(changedents.find(n) == -1) changedents.add(n); // apply ent changes later (reduces network traffic) } @@ -218,13 +223,26 @@ COMMAND(getentattr, "i"); void delent() { - int e = closestent(); - if(e<0) { conoutf("no more entities"); return; } + int n = closestent(); + if(n<0) { conoutf("no more entities"); return; } syncentchanges(true); - int t = ents[e].type; + int t = ents[n].type; conoutf("%s entity deleted", entnames[t]); - ents[e].type = NOTUSED; - addmsg(SV_EDITENT, "ri9", e, NOTUSED, 0, 0, 0, 0, 0, 0, 0); + + entity &e = ents[n]; + + if (t == SOUND) //stop playing sound + { + entityreference entref(&e); + location *loc = audiomgr.locations.find(e.attr1, &entref, mapsounds); + + if(loc) + loc->drop(); + } + + ents[n].type = NOTUSED; + addmsg(SV_EDITENT, "ri9", n, NOTUSED, 0, 0, 0, 0, 0, 0, 0); + switch(t) { case LIGHT: calclight(); break; @@ -243,6 +261,17 @@ entity *newentity(int index, int x, int y, int z, char *what, int v1, int v2, in int type = findtype(what); if(type==NOTUSED) return NULL; + if (type == SOUND && index >= 0) + { + entity &o = ents[index]; + + entityreference entref(&o); + location *loc = audiomgr.locations.find(o.attr1, &entref, mapsounds); + + if(loc) + loc->drop(); + } + entity e(x, y, z, type, v1, v2, v3, v4); switch(type)