]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
killed threads
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 2 Dec 2015 13:09:02 +0000 (08:09 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 2 Dec 2015 13:09:02 +0000 (08:09 -0500)
include/entities.h
include/inventory.h
main.cpp
src/entities.cpp
src/inventory.cpp
src/ui.cpp

index c593710bab958733014cd726c25239a1e78108c2..4413d4116d75bbfa5fc310395273c0a80ff714b2 100644 (file)
@@ -145,9 +145,6 @@ public:
        ~Object();
        
        void interact(void);
-       std::thread runInteract() {
-          return std::thread([=] { interact(); });
-    }
 };
 #endif // ENTITIES_H
 
index ec71e94a589ff3c6e67df03095c69c5bfc3e5dea..b62e491f362133548c246226380b99229b4460fd 100644 (file)
@@ -81,9 +81,6 @@ public:
        int takeItem(ITEM_ID id,unsigned char count);   // Take 'count' items with an id of 'id' from the inventory
        int useItem(void);
        
-       bool tossd;
-       int itemToss(void);
-       
        void setSelection(unsigned int s);
        
        void draw(void);        // Draws a text list of items in this inventory (should only be called for the player for now)
index ffd9ead3b4899bca35491ed8ac12afb25c3d429e..6230e72c7ebf77b0caf3fa671dc5ee99eaf80208 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -413,7 +413,7 @@ int main(int argc, char *argv[]){
         *      src/gameplay.cpp
         * 
        */
-       fadeIntensity = 254;
+       fadeIntensity = 250;
        initEverything();
        
        /*
@@ -809,6 +809,8 @@ void render(){
        SDL_GL_SwapWindow(window);
 }
 
+static volatile bool objectInteracting = false;
+
 void logic(){
        /*
         *      NPCSelected is used to insure that only one NPC is made interactable with the mouse
@@ -930,28 +932,31 @@ void logic(){
                        }
                }
        }
-       for(auto &o : currentWorld->object){
-               if(o->alive){
-                       if(ui::mouse.x >= o->loc.x                              &&
-                          ui::mouse.x <= o->loc.x + o->width   &&
-                          ui::mouse.y >= o->loc.y                              &&
-                          ui::mouse.y <= o->loc.y + o->width   ){
-                               if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
-
-                                       /*
-                                        *      Check for a right click, and allow the Object to interact with the
-                                        *      player if one was made.
-                                       */
-
-                                       if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
-                                               std::thread thr(o->runInteract());
-                                               thr.detach();
+       if(!objectInteracting){
+               for(auto &o : currentWorld->object){
+                       if(o->alive){
+                               if(ui::mouse.x >= o->loc.x                              &&
+                                  ui::mouse.x <= o->loc.x + o->width   &&
+                                  ui::mouse.y >= o->loc.y                              &&
+                                  ui::mouse.y <= o->loc.y + o->width   ){
+                                       if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
+
+                                               /*
+                                                *      Check for a right click, and allow the Object to interact with the
+                                                *      player if one was made.
+                                               */
+
+                                               if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
+                                                       objectInteracting=true;
+                                                       o->interact();
+                                                       objectInteracting=false;
+                                               }
                                        }
                                }
                        }
                }
        }
-
+       
        /*
         *      Switch between day and night (SUNNY and DARK) if necessary.
        */
@@ -973,11 +978,11 @@ void logic(){
         *      Transition to and from black if necessary.
        */
        if(fadeEnable){
-                        if(fadeIntensity < 160)fadeIntensity+=5;
-               else if(fadeIntensity < 255)fadeIntensity+=1;
+                        if(fadeIntensity < 160)fadeIntensity+=10;
+               else if(fadeIntensity < 255)fadeIntensity+=5;
        }else{
-                        if(fadeIntensity > 150)fadeIntensity-=1;
-               else if(fadeIntensity)          fadeIntensity-=5;
+                        if(fadeIntensity > 150)fadeIntensity-=5;
+               else if(fadeIntensity > 0)      fadeIntensity-=10;
        }
 
        /*
index 1e6fad5bb9d5ba30d36d155421286167ae7e328c..32867841bcae6f45cbbb7d658a7ac8297c9efb2e 100644 (file)
@@ -339,18 +339,14 @@ void NPC::interact(){ //have the npc's interact back to the player
        }
 }
 
-extern void waitForDialog(void);
-void Object::interact(void){
+void Object::interact(void){   
        if(questObject && alive){
-               
                ui::dialogBox("You",":Yes:No",pickupDialog);            
-               while(ui::dialogBoxExists);
-
-               if(ui::dialogOptChosen == 1 && alive){
+               ui::waitForDialog();
+               if(ui::dialogOptChosen == 1){
                        player->inv->addItem((ITEM_ID)(identifier), (char)1);
                        alive = false;
-                       return;
-               }       
+               }
        }else{
                alive = false;
                player->inv->addItem((ITEM_ID)(identifier), (char)1);
index e67f031443c5fae312e8be9a723a9b838357555c..a365204e714c0d7b5baf95dcab4b88fb7a819228 100644 (file)
@@ -41,7 +41,6 @@ Inventory::Inventory(unsigned int s){
        size=s;
        inv = new struct item_t[size];
        memset(inv,0,size*sizeof(struct item_t));
-       tossd=false;
        for(int i = 0;i<ITEM_COUNT;i++){
                itemtex[i]=Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
        }
@@ -162,29 +161,16 @@ void Inventory::draw(void){
        lop++;
 }
 
-static vec2 item_coord = {0,0};
-static vec2 item_velcd = {0,0};
-static bool item_tossd = false;
-static bool yes=false;
-
 void itemDraw(Player *p,ITEM_ID id){
-       static vec2 p1,p2;
        if(!id)return;
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,itemtex[id]);
-       if(!yes){
-               p1 = {p->loc.x+p->width/2,
-                         p->loc.y+p->width/2+HLINE*3};
-               p2 = {(float)(p1.x+p->width*(p->left?-.5:.5)),
-                         p->loc.y+HLINE*3};
-       }
-       if(p->inv->tossd) yes=true;
        glColor4ub(255,255,255,255);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2f(item_coord.x+p->loc.x,                                             item_coord.y+p->loc.y);
-               glTexCoord2i(1,1);glVertex2f(item_coord.x+item[id].width+p->loc.x,              item_coord.y+p->loc.y);
-               glTexCoord2i(1,0);glVertex2f(item_coord.x+item[id].width+p->loc.x,              item_coord.y+item[id].height+p->loc.y);
-               glTexCoord2i(0,0);glVertex2f(item_coord.x+p->loc.x,                                             item_coord.y+item[id].height+p->loc.y);
+               glTexCoord2i(0,1);glVertex2f(p->loc.x,                           p->loc.y);
+               glTexCoord2i(1,1);glVertex2f(p->loc.x+item[id].width,p->loc.y);
+               glTexCoord2i(1,0);glVertex2f(p->loc.x+item[id].width,p->loc.y+item[id].height);
+               glTexCoord2i(0,0);glVertex2f(p->loc.x,                           p->loc.y+item[id].height);
        glEnd();
        glDisable(GL_TEXTURE_2D);
 }
@@ -202,31 +188,3 @@ int Inventory::useItem(void){
        return 0;
 }
 
-int Inventory::itemToss(void){
-       if(!item_tossd && item[sel].count && item[sel].id){
-               item_tossd = true;
-               item_coord.x = HLINE;
-               item_velcd.x = 0;
-               item_velcd.y = 3;
-               tossd = true;
-               return 1;
-       }else if(item_tossd){
-               if(item_coord.y<0){
-                       memset(&item_coord,0,sizeof(vec2));
-                       memset(&item_velcd,0,sizeof(vec2));
-                       item_tossd = false;
-                       
-                       takeItem(item[sel].id,1);
-                       
-                       tossd = yes = false;
-                       
-                       return 0;
-               }else{
-                       item_coord.x += item_velcd.x;
-                       item_coord.y += item_velcd.y;
-                       //item_velcd.x -= .005;
-                       item_velcd.y -= .1;
-                       return 1;
-               }
-       }
-}
index a37a97c9fe346d670ea10361e03859061c45a368..e10ed466ca16e63c0012a98c898432536fc2d9e7 100644 (file)
@@ -514,12 +514,14 @@ namespace ui {
                }
        }
        void handleEvents(void){
-               unsigned char i;
                static bool left=false,right=false;
                static vec2 premouse={0,0};
+               unsigned char i;
                SDL_Event e;
+               
                mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
                mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
+               
                while(SDL_PollEvent(&e)){
                        switch(e.type){
                        case SDL_QUIT:
@@ -602,9 +604,7 @@ DONE:
                                                player->ground=false;
                                        }
                                }
-                               if(SDL_KEY==SDLK_q){
-                                       player->inv->itemToss();
-                               }
+
                                if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3;                                                      // Sprint
                                if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
                        }
@@ -632,8 +632,6 @@ DONE:
                        }
                }
                
-               if(player->inv->tossd)player->inv->itemToss();
-               
                if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
                        for(i=0;i<AIpreaddr.size();i++){
                                AIpreaddr.front()->addAIFunc(AIpreload.front(),false);