From 8b63ffeb4433cf53d76dd5b8e6173c918cce7fa1 Mon Sep 17 00:00:00 2001 From: driAn Date: Mon, 8 Dec 2008 21:17:11 +0000 Subject: [PATCH] audiomanager refactoring, class-ified world objects, member access cleanups git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3952 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/audiomanager.cpp | 36 ++++++++++++++++++++--------------- source/src/entity.h | 32 +++++++++++++++++++++++-------- source/src/model.h | 2 +- source/src/sound.h | 21 ++++++++++++-------- source/src/soundscheduler.cpp | 11 +++++------ source/src/weapon.cpp | 2 +- source/src/weapon.h | 8 ++++---- 7 files changed, 69 insertions(+), 43 deletions(-) diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index b6f4948c..0415ba93 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -9,13 +9,7 @@ VARF(audio, 0, 1, 1, initwarning("sound configuration", INIT_RESET, CHANGE_SOUND VARP(audiodebug, 0, 0, 1); char *musicdonecmd = NULL; -void setmusicvol() -{ - extern int musicvol; - if(audiomgr.gamemusic) audiomgr.gamemusic->setvolume(musicvol > 0 ? musicvol/255.0f : 0); -} - -VARFP(musicvol, 0, 128, 255, setmusicvol()); +VARFP(musicvol, 0, 128, 255, audiomgr.setmusicvol(musicvol)); // audio manager @@ -76,12 +70,12 @@ void audiomanager::initsound() conoutf("Driver: %s", alGetString(AL_VERSION)); // allocate OpenAL resources - sourcescheduler::instance().init(); + sourcescheduler::instance().init(16); // let the stream get the first source from the scheduler gamemusic = new oggstream(); if(!gamemusic->valid) DELETEP(gamemusic); - setmusicvol(); + setmusicvol(musicvol); nosound = false; } @@ -121,7 +115,7 @@ void audiomanager::music(char *name, char *millis, char *cmd) conoutf("could not play music: %s", name); return; } - setmusicvol(); + setmusicvol(musicvol); } else conoutf("could not open music: %s", name); } @@ -155,6 +149,16 @@ void audiomanager::musicfadeout(int id) if(!strcmp(musics[id], gamemusic->name)) gamemusic->fadeout(lastmillis+1000, 1000); } +void audiomanager::setmusicvol(int musicvol) +{ + if(gamemusic) gamemusic->setvolume(musicvol > 0 ? musicvol/255.0f : 0); +} + +void audiomanager::setlistenervol(int vol) +{ + if(!nosound) alListenerf(AL_GAIN, vol/255.0f); +} + void audiomanager::registermusic(char *name) { if(nosound) return; @@ -214,6 +218,11 @@ void audiomanager::applymapsoundchanges() // during map editing, drop all mapsou } } +void audiomanager::setchannels(int num) +{ + if(!nosound) sourcescheduler::instance().init(num); +}; + // called at game exit @@ -739,12 +748,9 @@ COMMANDF(mapsoundreset, ARG_NONE, () audiomgr.mapsoundreset(); }); -VARF(soundchannels, 4, 32, 1024, { if(!audiomgr.nosound) sourcescheduler::instance().init(); }); +VARF(soundchannels, 4, 32, 1024, audiomgr.setchannels(soundchannels); ); -VARFP(soundvol, 0, 128, 255, -{ - if(!audiomgr.nosound) alListenerf(AL_GAIN, soundvol/255.0f); -}); +VARFP(soundvol, 0, 128, 255, audiomgr.setlistenervol(soundvol); ); COMMANDF(registersound, ARG_4STR, (char *name, char *vol, char *loop, char *audibleradius) { diff --git a/source/src/entity.h b/source/src/entity.h index dc0f312d..764bc086 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -90,8 +90,14 @@ enum { CS_ALIVE = 0, CS_DEAD, CS_SPAWNING, CS_LAGGED, CS_EDITING, CS_SPECTATE }; enum { CR_DEFAULT = 0, CR_ADMIN }; enum { SM_NONE = 0, SM_DEATHCAM, SM_FOLLOW1ST, SM_FOLLOW3RD, SM_FOLLOW3RD_TRANSPARENT, SM_FLY, SM_NUM }; -struct physent +class worldobject { + +}; + +class physent : worldobject +{ +public: vec o, vel; // origin, velocity vec deltapos, newpos; // movement interpolation float yaw, pitch, roll; // used as vec in one place @@ -133,8 +139,9 @@ struct physent virtual void onmoved(const vec &dist) {} }; -struct dynent : physent // animated ent +class dynent : public physent // animated ent { +public: bool k_left, k_right, k_up, k_down; // see input code animstate prev[2], current[2]; // md2's need only [0], md3's need both for the lower&upper model @@ -173,7 +180,7 @@ struct dynent : physent // animated ent #define MAXNAMELEN 15 #define MAXTEAMLEN 4 -struct bounceent; +class bounceent; #define POSHIST_SIZE 7 @@ -215,8 +222,9 @@ struct poshist } }; -struct playerstate +class playerstate { +public: int health, armour; int primary, nextprimary; int gunselect; @@ -329,8 +337,9 @@ struct playerstate #define HEADSIZE 0.4f -struct playerent : dynent, playerstate +class playerent : public dynent, public playerstate { +public: int clientnum, lastupdate, plag, ping; int lifesequence; // sequence id for each respawn, used in damage test int frags, flagscore, deaths; @@ -457,8 +466,9 @@ struct playerent : dynent, playerstate class CBot; -struct botent : playerent +class botent : public playerent { +public: // Added by Rick CBot *pBot; // Only used if this is a bot, points to the bot class if we are the host, // for other clients its NULL @@ -476,6 +486,8 @@ struct botent : playerent int deaths() { return lifesequence; } }; +// flag-mode entities + enum { CTFF_INBASE = 0, CTFF_STOLEN, CTFF_DROPPED, CTFF_IDLE }; struct flaginfo @@ -490,10 +502,13 @@ struct flaginfo flaginfo() : flagent(0), actor(0), state(CTFF_INBASE), ack(false) {} }; +// nades, gibs + enum { BT_NONE, BT_NADE, BT_GIB }; -struct bounceent : physent // nades, gibs +class bounceent : public physent { +public: int millis, timetolive, bouncetype; // see enum above float rotspeed; playerent *owner; @@ -520,8 +535,9 @@ struct hitmsg ivec dir; }; -struct grenadeent : bounceent +class grenadeent : public bounceent { +public: bool local; int nadestate; float distsincebounce; diff --git a/source/src/model.h b/source/src/model.h index 5060e67c..501ac867 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -37,7 +37,7 @@ struct modelattach modelattach(const char *tag, vec *pos) : tag(tag), name(NULL), pos(pos), m(NULL) {} }; -struct dynent; +class dynent; struct model { diff --git a/source/src/sound.h b/source/src/sound.h index 62cc897a..1238e2ea 100644 --- a/source/src/sound.h +++ b/source/src/sound.h @@ -159,6 +159,7 @@ public: class sourcescheduler { + int numsoundchannels; static sourcescheduler *inst; vector sources; @@ -166,7 +167,7 @@ public: sourcescheduler(); static sourcescheduler &instance(); // singleton access - void init(); + void init(int numsoundchannels); void reset(); source *newsource(int priority, const vec &o); void releasesource(source *src); @@ -273,7 +274,7 @@ public: class physentreference : public worldobjreference { public: - struct physent *phys; + class physent *phys; physentreference(physent *ref); worldobjreference *clone() const; @@ -350,8 +351,8 @@ struct locvector : vector // audio interface to the engine -struct audiomanager -{ +class audiomanager +{ bool nosound; float currentpitch; cvector musics; @@ -360,9 +361,10 @@ struct audiomanager bufferhashtable bufferpool; locvector locations; - //sourcescheduler scheduler; oggstream *gamemusic; +public: + audiomanager(); // init @@ -371,13 +373,15 @@ struct audiomanager void preloadmapsound(entity &e); void preloadmapsounds(); void applymapsoundchanges(); + void setchannels(int num); // setup + void setlistenervol(int vol); int addsound(char *name, int vol, int maxuses, bool loop, vector &sounds, bool load, int audibleradius); void registermusic(char *name); // cleanup - void detachsounds(struct playerent *owner); + void detachsounds(class playerent *owner); void clearworldsounds(bool fullclean = true); void mapsoundreset(); void stopsound(); @@ -386,11 +390,12 @@ struct audiomanager void music(char *name, char *millis, char *cmd); void musicsuggest(int id, int millis, bool rndofs); void musicfadeout(int id); + void setmusicvol(int musicvol); // sound handling location *_playsound(int n, const worldobjreference &r, int priority, float offset = 0.0f, bool loop = false); void playsound(int n, int priority = SP_NORMAL); - void playsound(int n, struct physent *p, int priority = SP_NORMAL); + void playsound(int n, class physent *p, int priority = SP_NORMAL); void playsound(int n, struct entity *e, int priority = SP_NORMAL); void playsound(int n, const vec *v, int priority = SP_NORMAL); void playsoundname(char *s, const vec *loc, int vol); @@ -402,7 +407,7 @@ struct audiomanager int soundmuted(int n); // update - void updateplayerfootsteps(struct playerent *p); + void updateplayerfootsteps(class playerent *p); location *updateloopsound(int sound, bool active, float vol = 1.0f); void updateaudio(); diff --git a/source/src/soundscheduler.cpp b/source/src/soundscheduler.cpp index 1d911bbc..6488650c 100644 --- a/source/src/soundscheduler.cpp +++ b/source/src/soundscheduler.cpp @@ -7,8 +7,6 @@ #define DEBUGCOND (audiodebug==1) -extern int soundchannels; - VARP(soundschedpriorityscore, 0, 100, 1000); VARP(soundscheddistancescore, 0, 5, 1000); VARP(soundschedoldbonus, 0, 100, 1000); @@ -26,9 +24,10 @@ sourcescheduler &sourcescheduler::instance() return *inst; } -void sourcescheduler::init() +void sourcescheduler::init(int numsoundchannels) { - int newchannels = soundchannels - sources.length(); + this->numsoundchannels = numsoundchannels; + int newchannels = numsoundchannels - sources.length(); if(newchannels < 0) { loopv(sources) @@ -37,7 +36,7 @@ void sourcescheduler::init() if(src->locked) continue; sources.remove(i--); delete src; - if(sources.length() <= soundchannels) break; + if(sources.length() <= numsoundchannels) break; } } else loopi(newchannels) @@ -151,7 +150,7 @@ void sourcescheduler::releasesource(source *src) if(!src) return; src->unlock(); - if(sources.length() > soundchannels) + if(sources.length() > numsoundchannels) { sources.removeobj(src); delete src; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 1a888b9f..852e593e 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -524,7 +524,7 @@ void raydamage(vec &from, vec &to, playerent *d) // weapon -weapon::weapon(struct playerent *owner, int type) : type(type), owner(owner), info(guns[type]), +weapon::weapon(class playerent *owner, int type) : type(type), owner(owner), info(guns[type]), ammo(owner->ammo[type]), mag(owner->mag[type]), gunwait(owner->gunwait[type]), reloading(0) { } diff --git a/source/src/weapon.h b/source/src/weapon.h index c8af461a..56414ae3 100644 --- a/source/src/weapon.h +++ b/source/src/weapon.h @@ -1,5 +1,5 @@ -struct playerent; +class playerent; struct weapon { @@ -7,7 +7,7 @@ struct weapon const static float weaponbeloweye; static void equipplayer(playerent *pl); - weapon(struct playerent *owner, int type); + weapon(class playerent *owner, int type); virtual ~weapon() {} int type; @@ -48,8 +48,8 @@ struct weapon virtual int flashtime() const; }; -struct grenadeent; -struct bounceent; +class grenadeent; +class bounceent; enum { GST_NONE, GST_INHAND, GST_THROWING };