X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=a47edc9d765065e911bae8ee0b04ca6262d07d65;hb=75f57e08723a98ddbd4383be19c228f031c18b53;hp=05e9fd8312e6bdc328573f96b149c11f934f4740;hpb=bef7cd3a2b0217e63ef0b3b6832b22abbfe05bd1;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 05e9fd8..a47edc9 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif +#include #include #include "Game.h" #include "openal_wrapper.h" @@ -49,7 +50,6 @@ extern XYZ viewer; extern int environment; extern float texscale; extern Terrain terrain; -extern int channels[100]; extern int kTextureSize; extern float screenwidth,screenheight; extern float gravity; @@ -64,7 +64,6 @@ extern Light light; extern float texdetail; extern GLubyte bloodText[512*512*3]; extern GLubyte wolfbloodText[512*512*3]; -extern float terraindetail; extern float camerashake; extern float woozy; extern float blackout; @@ -84,7 +83,6 @@ extern bool autoslomo; extern bool keyboardfrozen; extern int netdatanew; extern bool loadingstuff; -extern char mapname[256]; extern XYZ windvector; extern bool debugmode; static int music1; @@ -109,7 +107,6 @@ extern bool texttoggle; extern bool alwaysblur; extern float gamespeed; extern bool decals; -extern bool vblsync; extern bool immediate; extern bool velocityblur; extern float tintr,tintg,tintb; @@ -158,28 +155,6 @@ extern int hostile; extern bool stillloading; extern bool winfreeze; -extern int numdialogues; -extern int numdialogueboxes[max_dialogues]; -extern int dialoguetype[max_dialogues]; -extern int dialogueboxlocation[max_dialogues][max_dialoguelength]; -extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3]; -extern int dialogueboxsound[max_dialogues][max_dialoguelength]; -extern char dialoguetext[max_dialogues][max_dialoguelength][128]; -extern char dialoguename[max_dialogues][max_dialoguelength][64]; -extern XYZ dialoguecamera[max_dialogues][max_dialoguelength]; -extern XYZ participantlocation[max_dialogues][10]; -extern int participantfocus[max_dialogues][max_dialoguelength]; -extern int participantaction[max_dialogues][max_dialoguelength]; -extern float participantrotation[max_dialogues][10]; -extern XYZ participantfacing[max_dialogues][max_dialoguelength][10]; -extern float dialoguecamerarotation[max_dialogues][max_dialoguelength]; -extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength]; -extern int indialogue; -extern int whichdialogue; -extern int directing; -extern float dialoguetime; -extern int dialoguegonethrough[20]; - extern bool campaign; extern float oldgamespeed; @@ -214,10 +189,6 @@ static bool stripfx(const char *str, const char *pfx) return !strncasecmp(str, pfx, strlen(pfx)); } -extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); -extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); - - static const char *cmd_names[] = { #define DECLARE_COMMAND(cmd) #cmd " ", #include "ConsoleCmds.h" @@ -243,9 +214,7 @@ static void ch_quit(Game *game, const char *args) static void ch_map(Game *game, const char *args) { - char buf[64]; - snprintf(buf, 63, ":Data:Maps:%s", args); - game->Loadlevel(buf); + game->Loadlevel(args); game->whichlevel = -2; campaign = 0; } @@ -463,7 +432,7 @@ static void ch_size(Game *game, const char *args) static int find_closest() { int closest = 0; - float closestdist = 1.0/0.0; + float closestdist = std::numeric_limits::max(); for (int i = 1; i < numplayers; i++) { float distance; @@ -610,7 +579,7 @@ static void set_clothes(int pnum, Game *game, const char *args) if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize)) return; - player[pnum].DoMipmaps(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize); + player[pnum].DoMipmaps(); strcpy(player[pnum].clothes[player[pnum].numclothes],buf); player[pnum].clothestintr[player[pnum].numclothes]=tintr; player[pnum].clothestintg[player[pnum].numclothes]=tintg; @@ -988,20 +957,12 @@ static void ch_play(Game *game, const char *args) directing=0; indialogue=0; - float gLoc[3]; - float vel[3]; XYZ temppos; temppos=player[participantfocus[whichdialogue][indialogue]].coords; temppos=temppos-viewer; Normalise(&temppos); temppos+=viewer; - gLoc[0]=temppos.x; - gLoc[1]=temppos.y; - gLoc[2]=temppos.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; int whichsoundplay; whichsoundplay=rabbitchitter; if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2; @@ -1023,10 +984,7 @@ static void ch_play(Game *game, const char *args) if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound; if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound; if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound; - PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel); - OPENAL_SetVolume(channels[whichsoundplay], 256); - OPENAL_SetPaused(channels[whichsoundplay], false); + emit_sound_at(whichsoundplay, temppos); } static void ch_mapkilleveryone(Game *game, const char *args) @@ -1115,18 +1073,7 @@ static void cmd_dispatch(Game *game, const char *cmd) cmd_handlers[i](game, cmd + strlen(cmd_names[i])); break; } - if (i < n_cmds) - { - PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); - } - else - { - PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true); - OPENAL_SetVolume(channels[consolefailsound], 256); - OPENAL_SetPaused(channels[consolefailsound], false); - } + emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound); } /********************> Tick() <*****/ @@ -1341,29 +1288,19 @@ void Game::Setenvironment(int which) float temptexdetail; environment=which; -/* - OPENAL_SetPaused(channels[music1snow], true); - OPENAL_SetPaused(channels[music1grass], true); - OPENAL_SetPaused(channels[music1desert], true); - OPENAL_SetPaused(channels[wind], true); - OPENAL_SetPaused(channels[desertambient], true); -*/ - OPENAL_SetPaused(channels[stream_music1snow], true); - OPENAL_SetPaused(channels[stream_music1grass], true); - OPENAL_SetPaused(channels[stream_music1desert], true); - OPENAL_SetPaused(channels[stream_wind], true); - OPENAL_SetPaused(channels[stream_desertambient], true); + + pause_sound(stream_music1snow); + pause_sound(stream_music1grass); + pause_sound(stream_music1desert); + pause_sound(stream_wind); + pause_sound(stream_desertambient); if(environment==snowyenvironment){ windvector=0; windvector.z=3; - if(ambientsound){ - //PlaySoundEx( wind, samp[wind], NULL, true); - PlayStreamEx(stream_wind, samp[stream_wind], 0, true); - OPENAL_SetPaused(channels[stream_wind], false); - OPENAL_SetVolume(channels[stream_wind], 256); - } + if(ambientsound) + emit_stream_np(stream_wind); LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1); LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1); @@ -1391,9 +1328,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(snow):Back.jpg", ":Data:Textures:Skybox(snow):Right.jpg", ":Data:Textures:Skybox(snow):Up.jpg", - ":Data:Textures:Skybox(snow):Down.jpg", - ":Data:Textures:Skybox(snow):Cloud.jpg", - ":Data:Textures:Skybox(snow):Reflect.jpg"); + ":Data:Textures:Skybox(snow):Down.jpg"); @@ -1409,12 +1344,8 @@ void Game::Setenvironment(int which) LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0); - if(ambientsound){ - //PlaySoundEx( desertambient, samp[desertambient], NULL, true); - PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true); - OPENAL_SetPaused(channels[stream_desertambient], false); - OPENAL_SetVolume(channels[stream_desertambient], 256); - } + if(ambientsound) + emit_stream_np(stream_desertambient); footstepsound = footstepsn1; footstepsound2 = footstepsn2; @@ -1436,9 +1367,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(sand):Back.jpg", ":Data:Textures:Skybox(sand):Right.jpg", ":Data:Textures:Skybox(sand):Up.jpg", - ":Data:Textures:Skybox(sand):Down.jpg", - ":Data:Textures:Skybox(sand):Cloud.jpg", - ":Data:Textures:Skybox(sand):Reflect.jpg"); + ":Data:Textures:Skybox(sand):Down.jpg"); @@ -1453,11 +1382,8 @@ void Game::Setenvironment(int which) LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0); LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0); - if(ambientsound){ - PlayStreamEx( stream_wind, samp[stream_wind], NULL, true); - OPENAL_SetPaused(channels[stream_wind], false); - OPENAL_SetVolume(channels[stream_wind], 100); - } + if(ambientsound) + emit_stream_np(stream_wind, 100.); footstepsound = footstepgr1; footstepsound2 = footstepgr2; @@ -1479,9 +1405,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(grass):Back.jpg", ":Data:Textures:Skybox(grass):Right.jpg", ":Data:Textures:Skybox(grass):Up.jpg", - ":Data:Textures:Skybox(grass):Down.jpg", - ":Data:Textures:Skybox(grass):Cloud.jpg", - ":Data:Textures:Skybox(grass):Reflect.jpg"); + ":Data:Textures:Skybox(grass):Down.jpg"); @@ -1497,35 +1421,31 @@ void Game::Setenvironment(int which) void Game::Loadlevel(int which){ stealthloading=0; - - if(which==0)Loadlevel((char *)":Data:Maps:map1"); - else if(which==1)Loadlevel((char *)":Data:Maps:map2"); - else if(which==2)Loadlevel((char *)":Data:Maps:map3"); - else if(which==3)Loadlevel((char *)":Data:Maps:map4"); - else if(which==4)Loadlevel((char *)":Data:Maps:map5"); - else if(which==5)Loadlevel((char *)":Data:Maps:map6"); - else if(which==6)Loadlevel((char *)":Data:Maps:map7"); - else if(which==7)Loadlevel((char *)":Data:Maps:map8"); - else if(which==8)Loadlevel((char *)":Data:Maps:map9"); - else if(which==9)Loadlevel((char *)":Data:Maps:map10"); - else if(which==10)Loadlevel((char *)":Data:Maps:map11"); - else if(which==11)Loadlevel((char *)":Data:Maps:map12"); - else if(which==12)Loadlevel((char *)":Data:Maps:map13"); - else if(which==13)Loadlevel((char *)":Data:Maps:map14"); - else if(which==14)Loadlevel((char *)":Data:Maps:map15"); - else if(which==15)Loadlevel((char *)":Data:Maps:map16"); - else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");} - else Loadlevel((char *)":Data:Maps:mapsave"); - whichlevel=which; + + if (which == -1) + { + tutoriallevel = -1; + Loadlevel("tutorial"); + } + else if (which >= 0 && which <= 15) + { + char buf[32]; + snprintf(buf, 32, "map%d", which + 1); + Loadlevel(buf); + } + else + Loadlevel("mapsave"); } -void Game::Loadlevel(char *name){ +void Game::Loadlevel(const char *name){ int i,j,k,l,m; static int oldlevel; int templength; float lamefloat; int lameint; + static const char *pfx = ":Data:Maps:"; + char *buf; float headprop,legprop,armprop,bodyprop; @@ -1554,18 +1474,20 @@ void Game::Loadlevel(char *name){ if(!firstload){ oldlevel=50; } - OPENAL_SetPaused(channels[whooshsound], true); - OPENAL_SetPaused(channels[stream_firesound], true); + pause_sound(whooshsound); + pause_sound(stream_firesound); // Change the map filename into something that is os specific - char *FixedFN = ConvertFileName(name); + buf = (char*) alloca(strlen(pfx) + strlen(name) + 1); + sprintf(buf, "%s%s", pfx, name); + const char *FixedFN = ConvertFileName(buf); int mapvers; FILE *tfile; tfile=fopen( FixedFN, "rb" ); if(tfile) { - OPENAL_SetPaused(channels[stream_firesound], true); + pause_sound(stream_firesound); scoreadded=0; @@ -1636,9 +1558,7 @@ void Game::Loadlevel(char *name){ changedelay=0; if(console) { - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); + emit_sound_np(consolesuccesssound); freeze=0; console=0; } @@ -1732,21 +1652,6 @@ void Game::Loadlevel(char *name){ player[0].creature=rabbittype; } - for(i=0;i64||templength<=0)templength=64; @@ -1792,6 +1698,7 @@ void Game::Loadlevel(char *name){ break; } } + dialoguename[k][l][m] = 0; funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z); funpackf(tfile, "Bi", &participantfocus[k][l]); funpackf(tfile, "Bi", &participantaction[k][l]); @@ -2071,7 +1978,7 @@ void Game::Loadlevel(char *name){ tintb=player[i].clothestintb[j]; AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize); } - player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize); + player[i].DoMipmaps(); } player[i].currentanimation=bounceidleanim; @@ -2242,33 +2149,17 @@ void Game::Loadlevel(char *name){ if(environment==snowyenvironment) { if(ambientsound) - { - PlayStreamEx(stream_wind, samp[stream_wind], NULL, true); - OPENAL_SetPaused(channels[stream_wind], false); - OPENAL_SetVolume(channels[stream_wind], 256); - } + emit_stream_np(stream_wind); } else if(environment==desertenvironment) { if(ambientsound) - { - //PlaySoundEx(desertambient, - // samp[desertambient], NULL, true); - PlayStreamEx(stream_desertambient, - samp[stream_desertambient], NULL, true); - OPENAL_SetPaused(channels[stream_desertambient], false); - OPENAL_SetVolume(channels[stream_desertambient], 256); - } + emit_stream_np(stream_desertambient); } else if(environment==grassyenvironment) { if(ambientsound) - { - //PlaySoundEx(wind, samp[wind], NULL, true); - PlayStreamEx(stream_wind, samp[stream_wind], NULL, true); - OPENAL_SetPaused(channels[stream_wind], false); - OPENAL_SetVolume(channels[stream_wind], 100); - } + emit_stream_np(stream_wind, 100.); } oldmusicvolume[0]=0; oldmusicvolume[1]=0; @@ -2363,15 +2254,13 @@ void Game::Tick() if(mainmenu&&musictoggle){ if(mainmenu==1||mainmenu==2||mainmenu==100){ OPENAL_SetFrequency(OPENAL_ALL, 0.001); - PlayStreamEx( stream_music3, samp[stream_music3], NULL, true); - OPENAL_SetPaused(channels[stream_music3], false); - OPENAL_SetVolume(channels[stream_music3], 256); - OPENAL_SetPaused(channels[music1], true); + emit_stream_np(stream_music3); + pause_sound(music1); } } if(!mainmenu){ - OPENAL_SetPaused(channels[stream_music3], true); - OPENAL_SetPaused(channels[music1], false); + pause_sound(stream_music3); + resume_stream(music1); } } if(mainmenu==3){ @@ -2416,9 +2305,7 @@ void Game::Tick() if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){ if(tutorialstage!=51) tutorialstagetime=tutorialmaxtime; - PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true); - OPENAL_SetVolume(channels[consolefailsound], 128); - OPENAL_SetPaused(channels[consolefailsound], false); + emit_sound_np(consolefailsound, 128.); minimaptogglekeydown=1; } if(!Input::isKeyDown(SDLK_TAB)){ @@ -2446,8 +2333,8 @@ void Game::Tick() { //resume mainmenu=0; - OPENAL_SetPaused(channels[stream_music3], true); - OPENAL_SetPaused(channels[music1], false); + pause_sound(stream_music3); + resume_stream(music1); } } @@ -2476,7 +2363,7 @@ void Game::Tick() if(!gameon){ //quit tryquit=1; - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); } else{ //end game @@ -2485,7 +2372,7 @@ void Game::Tick() } } } - if(mainmenu==3){ + else if(mainmenu==3){ if(Input::Button()&&!oldbutton&&selected!=-1){ fireSound(); } @@ -2559,9 +2446,9 @@ void Game::Tick() musictoggle=1-musictoggle; if(!musictoggle){ - OPENAL_SetPaused(channels[music1], true); - OPENAL_SetPaused(channels[stream_music2], true); - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(music1); + pause_sound(stream_music2); + pause_sound(stream_music3); for(i=0;i<4;i++){ oldmusicvolume[i]=0; @@ -2569,11 +2456,8 @@ void Game::Tick() } } - if(musictoggle){ - PlayStreamEx( stream_music3, samp[stream_music3], NULL, true); - OPENAL_SetPaused(channels[stream_music3], false); - OPENAL_SetVolume(channels[stream_music3], 256); - } + if(musictoggle) + emit_stream_np(stream_music3); } if(Input::Button()&&!oldbutton&&selected==9){ invertmouse=1-invertmouse; @@ -2624,7 +2508,7 @@ void Game::Tick() if(mainmenu==3&&!gameon)mainmenu=1; } } - if(mainmenu==4){ + else if(mainmenu==4){ if(Input::Button()&&!oldbutton&&selected!=-1&&!waiting){ fireSound(); if(selected<9&&keyselect==-1) @@ -2646,7 +2530,7 @@ void Game::Tick() } } - if(mainmenu==5){ + else if(mainmenu==5){ if(endgame==2){ accountactive->endGame(); @@ -2671,7 +2555,7 @@ void Game::Tick() mainmenu=0; gameon=1; - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); } if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){ fireSound(); @@ -2685,30 +2569,15 @@ void Game::Tick() targetlevel=7; if(firstload) TickOnceAfter(); else LoadStuff(); - for(i=0;i<255;i++){ - mapname[i]='\0'; - } - mapname[0]=':'; - mapname[1]='D'; - mapname[2]='a'; - mapname[3]='t'; - mapname[4]='a'; - mapname[5]=':'; - mapname[6]='M'; - mapname[7]='a'; - mapname[8]='p'; - mapname[9]='s'; - mapname[10]=':'; - strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]); whichchoice=selected-7-accountactive->getCampaignChoicesMade(); visibleloading=1; stillloading=1; - Loadlevel(mapname); + Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]); //Loadlevel(campaignmapname[levelorder[selected-7]]); campaign=1; mainmenu=0; gameon=1; - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); } if(Input::Button()&&!oldbutton&&selected==4){ fireSound(); @@ -2760,7 +2629,7 @@ void Game::Tick() mainmenu=0; gameon=1; - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); } if(Input::Button()&&!oldbutton&&selected==numchallengelevels){ fireSound(); @@ -2770,7 +2639,7 @@ void Game::Tick() mainmenu=5; } } - if(mainmenu==10){ + else if(mainmenu==10){ endgame=2; if(Input::Button()&&!oldbutton&&selected==3){ fireSound(); @@ -2781,7 +2650,7 @@ void Game::Tick() } } - if(mainmenu==6){ + else if(mainmenu==6){ if(Input::Button()&&!oldbutton) { if(selected>-1){ fireSound(); @@ -2796,7 +2665,7 @@ void Game::Tick() } } } - if(mainmenu==7){ + else if(mainmenu==7){ if(Input::Button()&&!oldbutton) { if(selected!=-1){ fireSound(); @@ -2821,7 +2690,7 @@ void Game::Tick() } } } - if(mainmenu==8){ + else if(mainmenu==8){ if(Input::Button()&&!oldbutton&&selected>-1){ fireSound(); @@ -2834,7 +2703,7 @@ void Game::Tick() } } - if (mainmenu==18) { + else if (mainmenu==18) { if(Input::Button()&&!oldbutton&&selected==0) { newstereomode = (StereoMode)(newstereomode + 1); while(!CanInitStereo(newstereomode)) { @@ -3040,9 +2909,7 @@ void Game::Tick() static int oldwinfreeze; if(winfreeze&&!oldwinfreeze){ OPENAL_SetFrequency(OPENAL_ALL, 0.001); - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); + emit_sound_np(consolesuccesssound); } if(winfreeze==0)oldwinfreeze=winfreeze; else oldwinfreeze++; @@ -3114,19 +2981,12 @@ void Game::Tick() dialoguetime=0; dialoguegonethrough[i]++; if(dialogueboxsound[whichdialogue][indialogue]!=0){ - static float gLoc[3]; - static float vel[3]; XYZ temppos; temppos=player[participantfocus[whichdialogue][indialogue]].coords; temppos=temppos-viewer; Normalise(&temppos); temppos+=viewer; - gLoc[0]=temppos.x; - gLoc[1]=temppos.y; - gLoc[2]=temppos.z;vel[0]=0; - vel[1]=0; - vel[2]=0; int whichsoundplay; if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter; if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2; @@ -3148,10 +3008,7 @@ void Game::Tick() if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound; if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound; if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound; - PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel); - OPENAL_SetVolume(channels[whichsoundplay], 256); - OPENAL_SetPaused(channels[whichsoundplay], false); + emit_sound_at(whichsoundplay, temppos); } if(Input::isKeyDown(attackkey))oldbuttondialogue=1; } @@ -3238,18 +3095,7 @@ void Game::Tick() player[1].coords=(temp+temp2)/2; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[1].coords.x; - gLoc[1]=player[1].coords.y; - gLoc[2]=player[1].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); + emit_sound_at(fireendsound, player[1].coords); for(i=0;i=1){ @@ -3665,16 +3498,12 @@ void Game::Tick() if(tutoriallevel!=1){ if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){ - PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true); - OPENAL_SetVolume(channels[consolesuccesssound], 256); - OPENAL_SetPaused(channels[consolesuccesssound], false); + emit_sound_np(consolesuccesssound); } } else if(bonustime==0){ - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); + emit_sound_np(fireendsound); } if(bonustime==0){ if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++; @@ -3780,19 +3609,8 @@ void Game::Tick() player[k].target=0; player[k].targetanimation=walljumpleftanim; player[k].targetframe=0; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel); - OPENAL_SetVolume(channels[movewhooshsound], 256); - OPENAL_SetPaused(channels[movewhooshsound], false); - if(k==0)OPENAL_SetPaused(channels[whooshsound], true); + emit_sound_at(movewhooshsound, player[k].coords); + if(k==0)pause_sound(whooshsound); lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0); player[k].rotation=-asin(0-lowpointtarget.x); @@ -3811,19 +3629,8 @@ void Game::Tick() player[k].target=0; player[k].targetanimation=walljumprightanim; player[k].targetframe=0; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel); - OPENAL_SetVolume(channels[movewhooshsound], 256); - OPENAL_SetPaused(channels[movewhooshsound], false); - if(k==0)OPENAL_SetPaused(channels[whooshsound], true); + emit_sound_at(movewhooshsound, player[k].coords); + if(k==0)pause_sound(whooshsound); lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0); player[k].rotation=-asin(0-lowpointtarget.x); @@ -3842,19 +3649,8 @@ void Game::Tick() player[k].target=0; player[k].targetanimation=walljumpbackanim; player[k].targetframe=0; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel); - OPENAL_SetVolume(channels[movewhooshsound], 256); - OPENAL_SetPaused(channels[movewhooshsound], false); - if(k==0)OPENAL_SetPaused(channels[whooshsound], true); + emit_sound_at(movewhooshsound, player[k].coords); + if(k==0)pause_sound(whooshsound); lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0); player[k].rotation=-asin(0-lowpointtarget.x); @@ -3873,19 +3669,8 @@ void Game::Tick() player[k].target=0; player[k].targetanimation=walljumpfrontanim; player[k].targetframe=0; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel); - OPENAL_SetVolume(channels[movewhooshsound], 256); - OPENAL_SetPaused(channels[movewhooshsound], false); - if(k==0)OPENAL_SetPaused(channels[whooshsound], true); + emit_sound_at(movewhooshsound, player[k].coords); + if(k==0)pause_sound(whooshsound); lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0); player[k].rotation=-asin(0-lowpointtarget.x); @@ -3920,25 +3705,14 @@ void Game::Tick() player[k].onterrain=1; if(player[k].id==0){ - OPENAL_SetPaused(channels[whooshsound], true); + pause_sound(whooshsound); OPENAL_SetVolume(channels[whooshsound], 0); } if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){ if(player[k].isFlip())player[k].jumppower=-4; player[k].targetanimation=player[k].getLanding(); - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=player[k].velocity.x; - vel[1]=player[k].velocity.y; - vel[2]=player[k].velocity.z; - PlaySoundEx( landsound, samp[landsound], NULL, true); - OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel); - OPENAL_SetVolume(channels[landsound], 128); - OPENAL_SetPaused(channels[landsound], false); + emit_sound_at(landsound, player[k].coords, 128.); if(k==0){ envsound[numenvsounds]=player[k].coords; envsoundvol[numenvsounds]=16; @@ -4036,20 +3810,9 @@ void Game::Tick() if(j>10||!player[k].isRun()){ if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){ - if(k==0)OPENAL_SetPaused(channels[whooshsound], true); + if(k==0)pause_sound(whooshsound); } - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=player[k].velocity.x; - vel[1]=player[k].velocity.y; - vel[2]=player[k].velocity.z; - PlaySoundEx( jumpsound, samp[jumpsound], NULL, true); - OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel); - OPENAL_SetVolume(channels[jumpsound], 128); - OPENAL_SetPaused(channels[jumpsound], false); + emit_sound_at(jumpsound, player[k].coords, 128.); lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0); player[k].rotation=-asin(0-lowpointtarget.x); @@ -4099,20 +3862,8 @@ void Game::Tick() player[k].targetframe=0; player[k].target=0; - float gLoc[3]; - float vel[3]; - gLoc[0]=player[k].coords.x; - gLoc[1]=player[k].coords.y; - gLoc[2]=player[k].coords.z; - vel[0]=player[k].velocity.x; - vel[1]=player[k].velocity.y; - vel[2]=player[k].velocity.z; - if(k==0){ - PlaySoundEx( whooshsound, samp[whooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel); - OPENAL_SetVolume(channels[whooshsound], 128); - OPENAL_SetPaused(channels[whooshsound], false); - } + if(!k) + emit_sound_at(whooshsound, player[k].coords, 128.); } player[k].velocity.y+=gravity; } @@ -4204,19 +3955,12 @@ void Game::Tick() indialogue++; if(indialogue150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){ //If hit by body if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){ - static float gLoc[3]; - static float vel[3]; - gLoc[0]=player[i].coords.x; - gLoc[1]=player[i].coords.y; - gLoc[2]=player[i].coords.z; - vel[0]=player[i].velocity.x; - vel[1]=player[i].velocity.y; - vel[2]=player[i].velocity.z; if(tutoriallevel!=1){ - PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true); - OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel); - OPENAL_SetVolume(channels[heavyimpactsound], 256); - OPENAL_SetPaused(channels[heavyimpactsound], false); + emit_sound_at(heavyimpactsound, player[i].coords); } //player[i].velocity=player[k].velocity; //player[k].velocity=player[i].velocity; @@ -6935,20 +6590,8 @@ void Game::Tick() if((((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1)||(player[i].victim&&weapons.owner[j]==player[i].victim->id)) if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){ if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){ - float gLoc[3]; - float vel[3]; - gLoc[0]=player[i].coords.x; - gLoc[1]=player[i].coords.y; - gLoc[2]=player[i].coords.z; - vel[0]=player[i].velocity.x; - vel[1]=player[i].velocity.y; - vel[2]=player[i].velocity.z; - if(weapons.type[j]!=staff){ - PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true); - OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel); - OPENAL_SetVolume(channels[knifedrawsound], 128); - OPENAL_SetPaused(channels[knifedrawsound], false); - } + if(weapons.type[j]!=staff) + emit_sound_at(knifedrawsound, player[i].coords, 128.); player[i].weaponactive=0; weapons.owner[j]=player[i].id; @@ -6982,20 +6625,8 @@ void Game::Tick() if(player[i].weaponactive==-1) if((((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[k]==-1)||(player[i].victim&&weapons.owner[k]==player[i].victim->id)) if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){ - float gLoc[3]; - float vel[3]; - gLoc[0]=player[i].coords.x; - gLoc[1]=player[i].coords.y; - gLoc[2]=player[i].coords.z; - vel[0]=player[i].velocity.x; - vel[1]=player[i].velocity.y; - vel[2]=player[i].velocity.z; - if(weapons.type[k]!=staff){ - PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true); - OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel); - OPENAL_SetVolume(channels[knifedrawsound], 128); - OPENAL_SetPaused(channels[knifedrawsound], false); - } + if(weapons.type[k]!=staff) + emit_sound_at(knifedrawsound, player[i].coords, 128.); player[i].weaponactive=0; weapons.owner[k]=player[i].id; @@ -7035,14 +6666,6 @@ void Game::Tick() player[i].hasvictim=1; int k = player[j].weaponids[0]; if(player[i].hasvictim){ - float gLoc[3]; - float vel[3]; - gLoc[0]=player[i].coords.x; - gLoc[1]=player[i].coords.y; - gLoc[2]=player[i].coords.z; - vel[0]=player[i].velocity.x; - vel[1]=player[i].velocity.y; - vel[2]=player[i].velocity.z; bool fleshstuck; fleshstuck=0; if(player[i].victim->weaponstuck!=-1){ @@ -7051,19 +6674,11 @@ void Game::Tick() } } if(!fleshstuck){ - if(weapons.type[k]!=staff){ - PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true); - OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel); - OPENAL_SetVolume(channels[knifedrawsound], 128); - OPENAL_SetPaused(channels[knifedrawsound], false); - } - } - if(fleshstuck){ - PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true); - OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel); - OPENAL_SetVolume(channels[fleshstabremovesound], 128); - OPENAL_SetPaused(channels[fleshstabremovesound], false); + if(weapons.type[k]!=staff) + emit_sound_at(knifedrawsound, player[i].coords, 128.); } + if(fleshstuck) + emit_sound_at(fleshstabremovesound, player[i].coords, 128.); player[i].weaponactive=0; if(weapons.owner[k]!=-1){ @@ -7477,26 +7092,10 @@ void Game::Tick() player[i].coords.y+=.2; player[i].jumppower-=1; - static float gLoc[3]; - static float vel[3]; - gLoc[0]=player[i].coords.x; - gLoc[1]=player[i].coords.y; - gLoc[2]=player[i].coords.z; - vel[0]=player[i].velocity.x; - vel[1]=player[i].velocity.y; - vel[2]=player[i].velocity.z; - - if(i==0){ - PlaySoundEx( whooshsound, samp[whooshsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel); - OPENAL_SetVolume(channels[whooshsound], 128); - OPENAL_SetPaused(channels[whooshsound], false); - } + if (!i) + emit_sound_at(whooshsound, player[i].coords, 128.); - PlaySoundEx( jumpsound, samp[jumpsound], NULL, true); - OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel); - OPENAL_SetVolume(channels[jumpsound], 128); - OPENAL_SetPaused(channels[jumpsound], false); + emit_sound_at(jumpsound, player[i].coords, 128.); } if((player[i].isIdle())&&player[i].jumppower>1){ player[i].targetanimation=player[i].getLanding(); @@ -7588,8 +7187,8 @@ void Game::Tick() for(k=0;k=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){ - float gLoc[3]; - float vel[3]; - gLoc[0]=player[0].coords.x; - gLoc[1]=player[0].coords.y; - gLoc[2]=player[0].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); + emit_sound_at(fireendsound, player[0].coords); player[0].coords=(oldtemp+oldtemp2)/2; @@ -7659,18 +7245,7 @@ void Game::Tick() } if(tutorialstage>=14&&tutorialstage<50) if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){ - float gLoc[3]; - float vel[3]; - gLoc[0]=player[1].coords.x; - gLoc[1]=player[1].coords.y; - gLoc[2]=player[1].coords.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); + emit_sound_at(fireendsound, player[1].coords); for(int i=0;i128&&!loading&&!mainmenu)musicvolume[2]=128; if(musictoggle){ - if(musicvolume[0]>0&&oldmusicvolume[0]<=0){ - PlayStreamEx( music1, samp[music1], NULL, true); - OPENAL_SetPaused(channels[music1], false); - } - if(musicvolume[1]>0&&oldmusicvolume[1]<=0){ - PlayStreamEx( stream_music2, samp[stream_music2], NULL, true); - OPENAL_SetPaused(channels[stream_music2], false); - } - if(musicvolume[2]>0&&oldmusicvolume[2]<=0){ - PlayStreamEx( stream_music3, samp[stream_music3], NULL, true); - OPENAL_SetPaused(channels[stream_music3], false); - } + if(musicvolume[0]>0&&oldmusicvolume[0]<=0) + emit_stream_np(music1, musicvolume[0]); + if(musicvolume[1]>0&&oldmusicvolume[1]<=0) + emit_stream_np(stream_music2, musicvolume[1]); + if(musicvolume[2]>0&&oldmusicvolume[2]<=0) + emit_stream_np(stream_music3, musicvolume[2]); if(musicvolume[0]<=0&&oldmusicvolume[0]>0){ - OPENAL_SetPaused(channels[music1], true); + pause_sound(music1); } if(musicvolume[1]<=0&&oldmusicvolume[1]>0){ - OPENAL_SetPaused(channels[stream_music2], true); + pause_sound(stream_music2); } if(musicvolume[2]<=0&&oldmusicvolume[2]>0){ - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); } if(musicvolume[0]!=oldmusicvolume[0]){ @@ -7876,9 +7435,9 @@ void Game::TickOnceAfter(){ oldmusicvolume[i]=musicvolume[i]; } } else { - OPENAL_SetPaused(channels[music1], true); - OPENAL_SetPaused(channels[stream_music2], true); - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(music1); + pause_sound(stream_music2); + pause_sound(stream_music3); for(i=0;i<4;i++){ oldmusicvolume[i]=0; @@ -7990,22 +7549,7 @@ void Game::TickOnceAfter(){ fireSound(firestartsound); - for(i=0;i<255;i++){ - mapname[i]='\0'; - } - mapname[0]=':'; - mapname[1]='D'; - mapname[2]='a'; - mapname[3]='t'; - mapname[4]='a'; - mapname[5]=':'; - mapname[6]='M'; - mapname[7]='a'; - mapname[8]='p'; - mapname[9]='s'; - mapname[10]=':'; - strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]); - Loadlevel(mapname); + Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]); fireSound(); @@ -8109,33 +7653,15 @@ void Game::TickOnceAfter(){ loading=2; loadtime=0; targetlevel=7; - //if(firstload)TickOnceAfter(); if(!firstload)LoadStuff(); - //else { - for(i=0;i<255;i++){ - mapname[i]='\0'; - } - mapname[0]=':'; - mapname[1]='D'; - mapname[2]='a'; - mapname[3]='t'; - mapname[4]='a'; - mapname[5]=':'; - mapname[6]='M'; - mapname[7]='a'; - mapname[8]='p'; - mapname[9]='s'; - mapname[10]=':'; - - strcat(mapname,campaignmapname[campaignchoicewhich[0]]); whichchoice=0; visibleloading=1; stillloading=1; - Loadlevel(mapname); + Loadlevel(campaignmapname[campaignchoicewhich[0]]); campaign=1; mainmenu=0; gameon=1; - OPENAL_SetPaused(channels[stream_music3], true); + pause_sound(stream_music3); stealthloading=0; }