From: Côme BERNIGAUD Date: Sat, 5 Jun 2010 20:51:18 +0000 (+0400) Subject: Minor code simplifications X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=250e2a61f24154d8eebff5b2b403f926ca24a543;p=lugaru.git Minor code simplifications --- Source/GameDraw.cpp | 12 +- Source/GameTick.cpp | 411 +++++++++++++++++++-------------------------- Source/OpenGL_Windows.cpp | 19 +-- 3 files changed, 178 insertions(+), 264 deletions(-) --- diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 349492e..083af9d 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -2910,7 +2910,8 @@ int Game::DrawGLScene(StereoSide side) movex[0]=0; movey[0]=0; - if(entername)startx[0]+=10; + if(entername) + startx[0]+=10; num=1; @@ -3583,12 +3584,9 @@ int Game::DrawGLScene(StereoSide side) sprintf (string, "_"); text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480); } - k=0; - for(l=0;l1&&numplayers0&&player[j].num_weapons<5) - for(k=0;knumpathpoints); - if(game->numpathpoints) - for(j=0;jnumpathpoints;j++){ - fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); - for(k=0;knumpathpointconnect[j];k++){ - fpackf(tfile, "Bi", game->pathpointconnect[j][k]); - } - } + for(j=0;jnumpathpoints;j++){ + fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); + for(k=0;knumpathpointconnect[j];k++){ + fpackf(tfile, "Bi", game->pathpointconnect[j][k]); + } + } fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius); @@ -555,9 +544,7 @@ static void set_proportion(int pnum, const char *args) player[pnum].proportionbody=1.1*bodyprop; player[pnum].proportionarms=1.1*armprop; player[pnum].proportionlegs=1.1*legprop; - } - - if(player[pnum].creature==rabbittype){ + } else if(player[pnum].creature==rabbittype){ player[pnum].proportionhead=1.2*headprop; player[pnum].proportionbody=1.05*bodyprop; player[pnum].proportionarms=1.00*armprop; @@ -1012,9 +999,7 @@ static void ch_default(Game *game, const char *args) player[0].proportionbody=1.1; player[0].proportionarms=1.1; player[0].proportionlegs=1.1; - } - - if(player[0].creature==rabbittype){ + } else if(player[0].creature==rabbittype){ player[0].proportionhead=1.2; player[0].proportionbody=1.05; player[0].proportionarms=1.00; @@ -2997,9 +2982,8 @@ void Game::Tick() loading=2; loadtime=0; targetlevel=7; - if(firstload)TickOnceAfter(); - if(!firstload)LoadStuff(); - //else { + if(firstload) TickOnceAfter(); + else LoadStuff(); for(i=0;i<255;i++){ mapname[i]='\0'; } @@ -3177,11 +3161,11 @@ void Game::Tick() loading=2; loadtime=0; targetlevel=selected; - if(firstload)TickOnceAfter(); - if(!firstload)LoadStuff(); - else { + if(firstload) { + TickOnceAfter(); Loadlevel(selected); - } + } else + LoadStuff(); campaign=0; mainmenu=0; @@ -3973,44 +3957,31 @@ void Game::Tick() } if(tutorialstage==1){ tutorialmaxtime=5; - } - if(tutorialstage==2){ + } else if(tutorialstage==2){ tutorialmaxtime=2; - } - if(tutorialstage==3){ + } else if(tutorialstage==3){ tutorialmaxtime=600; - } - if(tutorialstage==4){ + } else if(tutorialstage==4){ tutorialmaxtime=1000; - } - if(tutorialstage==5){ + } else if(tutorialstage==5){ tutorialmaxtime=600; - } - if(tutorialstage==6){ + } else if(tutorialstage==6){ tutorialmaxtime=600; - } - if(tutorialstage==7){ + } else if(tutorialstage==7){ tutorialmaxtime=600; - } - if(tutorialstage==8){ + } else if(tutorialstage==8){ tutorialmaxtime=600; - } - if(tutorialstage==9){ + } else if(tutorialstage==9){ tutorialmaxtime=600; - } - if(tutorialstage==10){ + } else if(tutorialstage==10){ tutorialmaxtime=2; - } - if(tutorialstage==11){ + } else if(tutorialstage==11){ tutorialmaxtime=1000; - } - if(tutorialstage==12){ + } else if(tutorialstage==12){ tutorialmaxtime=1000; - } - if(tutorialstage==13){ + } else if(tutorialstage==13){ tutorialmaxtime=2; - } - if(tutorialstage==14){ + } else if(tutorialstage==14){ tutorialmaxtime=3; XYZ temp,temp2; @@ -4047,107 +4018,82 @@ void Game::Tick() } } - } - if(tutorialstage==15){ + } else if(tutorialstage==15){ tutorialmaxtime=500; - } - if(tutorialstage==16){ + } else if(tutorialstage==16){ tutorialmaxtime=500; - } - if(tutorialstage==17){ + } else if(tutorialstage==17){ tutorialmaxtime=500; - } - if(tutorialstage==18){ + } else if(tutorialstage==18){ tutorialmaxtime=500; - } - if(tutorialstage==19){ + } else if(tutorialstage==19){ tutorialstage=20; //tutorialmaxtime=500; - } - if(tutorialstage==20){ + } else if(tutorialstage==20){ tutorialmaxtime=500; - } - if(tutorialstage==21){ + } else if(tutorialstage==21){ tutorialmaxtime=500; if(bonus==cannon){ bonus=Slicebonus; againbonus=1; } else againbonus=0; - } - if(tutorialstage==22){ + } else if(tutorialstage==22){ tutorialmaxtime=500; - } - if(tutorialstage==23){ + } else if(tutorialstage==23){ tutorialmaxtime=500; - } - if(tutorialstage==24){ + } else if(tutorialstage==24){ tutorialmaxtime=500; - } - if(tutorialstage==25){ + } else if(tutorialstage==25){ tutorialmaxtime=500; - } - if(tutorialstage==26){ + } else if(tutorialstage==26){ tutorialmaxtime=2; - } - if(tutorialstage==27){ + } else if(tutorialstage==27){ tutorialmaxtime=4; reversaltrain=1; cananger=1; player[1].aitype=attacktypecutoff; - } - if(tutorialstage==28){ + } else if(tutorialstage==28){ tutorialmaxtime=400; - } - if(tutorialstage==29){ + } else if(tutorialstage==29){ tutorialmaxtime=400; player[0].escapednum=0; - } - if(tutorialstage==30){ + } else if(tutorialstage==30){ tutorialmaxtime=4; reversaltrain=0; cananger=0; player[1].aitype=passivetype; - } - if(tutorialstage==31){ + } else if(tutorialstage==31){ tutorialmaxtime=13; - } - if(tutorialstage==32){ + } else if(tutorialstage==32){ tutorialmaxtime=8; - } - if(tutorialstage==33){ + } else if(tutorialstage==33){ tutorialmaxtime=400; cananger=1; canattack=1; player[1].aitype=attacktypecutoff; - } - if(tutorialstage==34){ + } else if(tutorialstage==34){ tutorialmaxtime=400; - } - if(tutorialstage==35){ + } else if(tutorialstage==35){ tutorialmaxtime=400; - } - if(tutorialstage==36){ + } else if(tutorialstage==36){ tutorialmaxtime=2; reversaltrain=0; cananger=0; player[1].aitype=passivetype; - } - if(tutorialstage==37){ + } else if(tutorialstage==37){ damagedealt=0; damagetaken=0; tutorialmaxtime=50; cananger=1; canattack=1; player[1].aitype=attacktypecutoff; - } - if(tutorialstage==38){ + } else if(tutorialstage==38){ tutorialmaxtime=4; canattack=0; cananger=0; player[1].aitype=passivetype; - } - if(tutorialstage==39){ + } else if(tutorialstage==39){ XYZ temp,temp2; temp.x=1011; @@ -4176,20 +4122,15 @@ void Game::Tick() weapons.physics[weapons.numweapons]=1; weapons.numweapons++; - } - if(tutorialstage==40){ + } else if(tutorialstage==40){ tutorialmaxtime=300; - } - if(tutorialstage==41){ + } else if(tutorialstage==41){ tutorialmaxtime=300; - } - if(tutorialstage==42){ + } else if(tutorialstage==42){ tutorialmaxtime=8; - } - if(tutorialstage==43){ + } else if(tutorialstage==43){ tutorialmaxtime=300; - } - if(tutorialstage==44){ + } else if(tutorialstage==44){ weapons.owner[0]=1; player[0].weaponactive=-1; player[0].num_weapons=0; @@ -4202,8 +4143,7 @@ void Game::Tick() player[1].aitype=attacktypecutoff; tutorialmaxtime=300; - } - if(tutorialstage==45){ + } else if(tutorialstage==45){ weapons.owner[0]=1; player[0].weaponactive=-1; player[0].num_weapons=0; @@ -4212,8 +4152,7 @@ void Game::Tick() player[1].weaponids[0]=0; tutorialmaxtime=300; - } - if(tutorialstage==46){ + } else if(tutorialstage==46){ weapons.owner[0]=1; player[0].weaponactive=-1; player[0].num_weapons=0; @@ -4224,9 +4163,7 @@ void Game::Tick() weapons.type[0]=sword; tutorialmaxtime=300; - } - - if(tutorialstage==47){ + } else if(tutorialstage==47){ tutorialmaxtime=10; XYZ temp,temp2; @@ -4265,8 +4202,7 @@ void Game::Tick() player[1].weaponids[0]=0; weapons.numweapons++; - } - if(tutorialstage==48){ + } else if(tutorialstage==48){ canattack=0; cananger=0; player[1].aitype=passivetype; @@ -4286,8 +4222,7 @@ void Game::Tick() else weapons.type[0]=staff; weapons.numweapons++; - } - if(tutorialstage==49){ + } else if(tutorialstage==49){ canattack=0; cananger=0; player[1].aitype=passivetype; @@ -4308,8 +4243,7 @@ void Game::Tick() weapons.type[0]=knife; weapons.numweapons++; - } - if(tutorialstage==50){ + } else if(tutorialstage==50){ tutorialmaxtime=8; XYZ temp,temp2; @@ -4350,8 +4284,7 @@ void Game::Tick() weapons.freetime[0]=0; weapons.firstfree[0]=1; weapons.physics[0]=1; - } - if(tutorialstage==51){ + } else if(tutorialstage==51){ tutorialmaxtime=80000; } if(tutorialstage<=51)tutorialstagetime=0; @@ -5983,7 +5916,8 @@ void Game::Tick() } if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){ pathpointselected--; - if(pathpointselected<=-2)pathpointselected=numpathpoints-1; + if(pathpointselected<=-2) + pathpointselected=numpathpoints-1; drawmodetogglekeydown=1; } if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){ @@ -6014,19 +5948,14 @@ void Game::Tick() editorenabled=1-editorenabled; if(editorenabled){ player[0].damagetolerance=100000; - player[0].damage=0; - player[0].superpermanentdamage=0; - player[0].bloodloss=0; - player[0].deathbleeding=0; - } - if(!editorenabled){ + } else { player[0].damagetolerance=200; - player[0].damage=0; - player[0].permanentdamage=0; - player[0].superpermanentdamage=0; - player[0].bloodloss=0; - player[0].deathbleeding=0; } + player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if + player[0].permanentdamage=0; + player[0].superpermanentdamage=0; + player[0].bloodloss=0; + player[0].deathbleeding=0; drawmodetogglekeydown=1; } diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 84e9812..82364c1 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -196,10 +196,7 @@ static void GLAPIENTRY glDeleteTextures_doNothing(GLsizei n, const GLuint *textu void sdlGetCursorPos(POINT *pt) { - int x, y; - SDL_GetMouseState(&x, &y); - pt->x = x; - pt->y = y; + SDL_GetMouseState(&(pt->x), &(pt->y)); } #define GetCursorPos(x) sdlGetCursorPos(x) #define SetCursorPos(x, y) SDL_WarpMouse(x, y) @@ -1241,25 +1238,15 @@ int main(int argc, char **argv) bool LoadImage(const char * fname, TGAImageRec & tex) { - bool res = true; - if ( tex.data == NULL ) - { return false; - } - - - res = load_image(fname, tex); - - - return res; + else + return load_image(fname, tex); } void ScreenShot(const char * fname) { - save_image(fname); - }