]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
entity optimizations
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Dec 2015 17:47:19 +0000 (12:47 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Dec 2015 17:47:19 +0000 (12:47 -0500)
src/entities.cpp
src/gameplay.cpp

index f81291999b44584686ee2548eb2aa812f5f59d26..26eb09ae31a30f65486c873a6cbb8b13303f1af9 100644 (file)
@@ -183,17 +183,17 @@ Object::~Object(){
 
 void Entity::draw(void){               //draws the entities
        glPushMatrix();
+       glColor3ub(255,255,255);
        if(type==NPCT){
                if(NPCp(this)->aiFunc.size()){
                        glColor3ub(255,255,0);
                        glRectf(loc.x+width/3,loc.y+height,loc.x+width*2/3,loc.y+height+width/3);
-               }if(gender == MALE){
+               }
+               if(gender == MALE){
                        glColor3ub(255,255,255);
                }else if(gender == FEMALE){
                        glColor3ub(255,105,180);
                }
-       }else{
-               glColor3ub(255,255,255);
        }
        if(left){
                glScalef(-1.0f,1.0f,1.0f);
@@ -202,58 +202,44 @@ void Entity::draw(void){          //draws the entities
        glMatrixMode(GL_TEXTURE);
        glLoadIdentity();
        glEnable(GL_TEXTURE_2D);
-       if(type == PLAYERT){
+       switch(type){
+       case PLAYERT:
                static int texState = 0;
                static bool up = true;
-               if(loops % (int)((float)2 / (float)speed) == 0){
+               if(loops % (int)((float)3 / (float)speed) == 0){
                        if(up){
-                               texState+=1;
-                               if(texState==2)up=false;
+                               if(++texState==2)up=false;
                                tex->bindNext();
-                       }else if(!up){
-                               texState-=1;
-                               if(texState==0)up=true;
+                       }else{
+                               if(!--texState)up=true;
                                tex->bindPrev();
                        }
                }
-               if(ground == 0){
+               if(!ground){
                        tex->bind(0);
-               }else if(vel.x != 0){
-                       switch(texState){
-                               case 0:
-                                       tex->bind(0);
-                               break;
-                               case 1:
-                                       tex->bind(1);
-                               break;
-                               case 2:
-                                       tex->bind(2);
-                               break;
-                       }
+               }else if(vel.x){
+                       tex->bind(texState);
                }else{
                        tex->bind(1);
                }
-       }else if(type == MOBT){
+               break;
+       case MOBT:
                switch(subtype){
                        case MS_RABBIT:
-                               if(ground == 0){
-                                       tex->bind(1);
-                               }else if(ground == 1){
-                                       tex->bind(0);
-                               }
-                               break;
-                       case MS_BIRD:
-                               tex->bind(0);
+                               tex->bind(!ground);
                                break;
                        case MS_TRIGGER:
                                goto NOPE;
                                break;
+                       case MS_BIRD:
                        default:
                                tex->bind(0);
                                break;
                }
-       }else{
+               break;
+       default:
                tex->bind(0);
+               break;
        }
        glColor3ub(255,255,255);
        glBegin(GL_QUADS);
@@ -266,9 +252,7 @@ NOPE:
        glDisable(GL_TEXTURE_2D);
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
-       if(near){
-               ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
-       }
+       if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
 }
 
 void Player::interact(){ //the function that will cause the player to search for things to interact with
index eb5ce7971635c9bb55a6a2fbb44959cafbbb9922..8e7d961326c2459b6f499c917bdfaa5a097eafae 100644 (file)
@@ -51,7 +51,7 @@ void CUTSCENEEE(Mob *callee){
 void CUTSCENEEE2(Mob *callee){
        player->vel.x = 0;
        ui::dialogBox(player->name,":Yeah.",
-       "What the fuck is this dead end supposed to mean, and why does this place smell like soap?");
+       "What the fuck is this dead end supposed to mean, and why this place smell like soap.");
        ui::waitForDialog();
        callee->alive = false;
 }