]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
merge with remake
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 1 Mar 2016 13:43:56 +0000 (08:43 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 1 Mar 2016 13:43:56 +0000 (08:43 -0500)
1  2 
Changelog
include/common.h
include/world.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

diff --cc Changelog
index 9a9b9277487d758b9430509d528773b4e12c5331,b85c19577d8fa119b06f2d6178c7752832f86a8e..0384181d8b0aac5e9949e6a3e85a25e216898c87
+++ b/Changelog
        - C++-ified loaded texture handlers
        - documented more stuff
        - made merchant menu
 +
 +2/29/2016:
 +==========
 +
 +      - renewed branch 'remake': re-wrote world.cpp and pushed
 +      - fixed world linkage errors
 +      - considered more formal coding? (as in documentation and indentation)
 +      - fixed dialog boxes and options
 +      - broke screenshots
++
++3/1/2016:
++=========
++
++      - merged 'remake' with 'master', fixed font issues and world stuffs
++      - continued work on merchant dialog
Simple merge
diff --cc include/world.h
Simple merge
diff --cc main.cpp
index fd02cc1d7c232e84fd91f67bfb97f4c31258b63f,fa833fb78d720fcece5c8a5c1b6de7a314ef9559..abc4f3cc23ba3745f9842d64cb690dd80b8256c9
+++ b/main.cpp
@@@ -457,14 -496,16 +483,17 @@@ void mainLoop(void)
         */
  
        prev = currentWorld;
 -      pool.Enqueue(ui::handleEvents);
 -      //ui::handleEvents();
++
++      //pool.Enqueue(ui::handleEvents);
 +      ui::handleEvents();
-     
        if(prev != currentWorld){
                currentWorld->bgmPlay(prev);
                ui::dialogBoxExists = false;
        }
 -      
 +    
        if(prevPrevTime + MSEC_PER_TICK <= currentTime){
+               //pool.Enqueue(logic);
                logic();
                prevPrevTime = currentTime;
        }
        /*
         * Update player and entity coordinates.
         */
-      
+       
+       /*pool.Enqueue([](){
+               currentWorld->update(player,deltaTime);
+       });*/
 -      currentWorld->update(player,deltaTime);
+       
 +      currentWorld->update(player,deltaTime);
 +    
        /*
         * Update debug variables if necessary
         */
Simple merge
Simple merge
diff --cc src/ui.cpp
index 47110cc54a70d28e9c490057c7b07b1d48cfcb5d,89e4805a7f7eb4d10ec4e7d9aa28eb7745b3b058..7029cd38ebd5a6c62caf3cc24edd2699957b9380
@@@ -46,17 -45,25 +46,22 @@@ static unsigned char fontColor[3] = {25
  
  /*
   *    Variables for dialog boxes / options.
 - */
 +*/
  
- static char dialogBoxText[512];
- static char *dialogOptText[4];
- static float dialogOptLoc[4][3];
+ static char                    dialogBoxText[512];
+ static char                   *dialogOptText[4];
+ static float         merchAOptLoc[2][3];
+ static float           dialogOptLoc[4][3];
  static unsigned char dialogOptCount = 0;
- static bool typeOutDone = true;
+ static bool                    typeOutDone = true;
+ /*
+  * Menu-related objects
+  */
  
 -extern Menu *currentMenu;
 +extern MenucurrentMenu;
  extern Menu pauseMenu;
  
 -/**
 - * The sound made when displaying characters with dialogBox or importantText.
 - */
  
  static Mix_Chunk *dialogClick;
  
@@@ -86,51 -108,74 +91,53 @@@ void Menu::gotoParent()
  }
  
  void Menu::gotoChild(){
 -      if(!child)
 +      if(child == NULL){
                currentMenu = NULL;
 -      else
 +      }else{
                currentMenu = child;
 +      }
  }
  
 -static vec2 premouse={0,0};
 -
  namespace ui {
        
 -      /**
 -       * The current position of the mouse.
 -       */
 +      /*
 +       *      Mouse coordinates.
 +      */
        
        vec2 mouse;
 +      static vec2 premouse={0,0};             
  
 -      /**
 -       * If true, debug information will be drawn to the screen.
 -       */
 -      
 -      bool debug = false;
 -      
 -      /**
 -       * If true, lines should be drawn to the player when the debug menu is open.
 -       */
 +      /*
 +       *      Variety of keydown bools
 +      */
 +      bool edown;
 +
 +      /*
 +       *      Debugging flags.
 +      */
        
 +      bool debug=false;
        bool posFlag=false;
 -      
 -      /**
 -       * If true, the player will be able to move when the current dialog box is
 -       * displayed.
 -       */
 -      
        bool dialogPassive = false;
+       bool dialogMerchant = false;
+       std::vector<BuySell> *minv;
        int dialogPassiveTime = 0;
  
 -      /**
 -       * When set to true the dialog box will attempt to display.
 -       */
 -      
 -      bool dialogBoxExists = false;
        
 -      /**
 -       * When set to true the text will display as 'important' text.
 -       */
 +      /*
 +       *      Dialog stuff that needs to be 'public'.
 +      */
        
 +      bool dialogBoxExists = false;
        bool dialogImportant = false;
 -      
 -      /**
 -       * Contains the last chosen dialog option.
 -       */
 -      
        unsigned char dialogOptChosen = 0;
        
 -      /**
 -       * Determines how many characters can be displayed in a dialog box before
 -       * a new line is required.
 -       */
 -      
        unsigned int textWrapLimit = 110;
        
 -      /**
 -       * The current font size.
 -       * 
 -       * DO NOT change this directly, use setFontSize() instead.
 -       */
 +      /*
 +       *      Current font size. Changing this WILL NOT change the font size, see setFontSize() for
 +       *      actual font size changing.
 +      */
        
        unsigned int fontSize;
  
        
        float putText(const float x,const float y,const char *str,...){
                va_list args;
 -              std::unique_ptr<char[]> buf (new char[512]);
 +              char *buf;
 +              float width;
                
 -              // create the formatted string
 -              va_start(args, str);
 -              vsnprintf(buf.get(), 512, str, args);
 +              /*
 +               *      Create a wimpy buffer.
 +              */
 +              
 +              buf = new char[512];    //(char *)calloc(128,sizeof(char));
 +              memset(buf,0,512*sizeof(char));
 +              
 +              /*
 +               *      Handle the formatted string, printing it to the buffer.
 +              */
 +              
 +              va_start(args,str);
 +              vsnprintf(buf,512,str,args);
                va_end(args);
                
 -              return putString(x, y, buf.get());
 +              /*
 +               *      Draw the string, free resources, return the width of the string.
 +              */
 +              
 +              width=putString(x,y,buf);
 +              delete[] buf;   //free(buf);
 +              
 +              return width;
        }
 -      
 -      /**
 -       * Prints a character dialog box.
 -       * 
 -       * This function sets up the variables necessary to draw a dialog box. If
 -       * `opt` contains a valid string, options will be printed with the dialog
 -       * box. If the box is passive, the player will be allowed to move while it
 -       * is being displayed.
 -       */
 -      
        void dialogBox(const char *name,const char *opt,bool passive,const char *text,...){
+               textWrapLimit = 110;
                va_list dialogArgs;
 -              size_t len;
 +              unsigned int len;
 +              char *sopt,*soptbuf;
                
                dialogPassive = passive;
                
                dialogBoxExists = true;
                dialogImportant = false;
                
 -              // kill the string created by typeOut if it contains something
 -              if(typeOutStr)
 -                      *typeOutStr = '\0';
 +              if(ret)
 +                      ret[0] = '\0';
        }
 -              if(typeOutStr)
 -                      *typeOutStr = '\0';
+       void merchantBox(const char *name,std::vector<BuySell> *bsinv,const char *opt,bool passive,const char *text,...){
+               std::cout << "Buying and selling on the bi-weekly!" << std::endl;
+               va_list dialogArgs;
+               size_t len;
+               
+               minv = bsinv;
+               dialogPassive = passive;
+               
+               // clear the buffer
+               memset(dialogBoxText, '\0', 512);
+               
+               // create the string
+               strcpy(dialogBoxText, name);
+               strcat(dialogBoxText, ": ");
+               
+               len=strlen(dialogBoxText);
+               va_start(dialogArgs,text);
+               vsnprintf(dialogBoxText + len, 512 - len, text, dialogArgs);
+               va_end(dialogArgs);
+                               
+               // free old option text
+               while(dialogOptCount){
+                       if(dialogOptText[dialogOptCount]){
+                               delete[] dialogOptText[dialogOptCount];
+                               dialogOptText[dialogOptCount] = NULL;
+                       }
+                       
+                       dialogOptCount--;
+               };
+               dialogOptChosen = 0;
+               memset(&dialogOptLoc, 0, sizeof(float) * 12);
+               
+               // handle options if desired
+               if(opt){
+                       //std::unique_ptr<char[]> soptbuf (new char[strlen(opt) + 1]);
+                       char soptbuf[255];
+                       strcpy(soptbuf, opt);
+                       char *sopt = strtok(soptbuf, ":");
+                       // cycle through options
+                       while(sopt){
+                               strcpy( (dialogOptText[dialogOptCount++] = new char[strlen(sopt) + 1]), sopt);
+                               sopt = strtok(NULL,":");
+                       }
+               }
+               
+               // allow box to be displayed
+               dialogBoxExists = true;
+               dialogImportant = false;
+               dialogMerchant = true;
+               textWrapLimit = 50;
+               
+               // kill the string created by typeOut if it contains something
++              if(ret)
++                      *ret = '\0';
+       }
+       
+       void merchantBox(){
+               textWrapLimit = 50;
+               dialogMerchant = true;
+       }
+       
+       /**
+        * Wait for a dialog box to be dismissed.
+        */
+       
        void waitForDialog(void){
                do{
                        mainLoop();
                float x,y,tmp;
                char *rtext;
                
 -              // handle dialog box / important text
                if(dialogBoxExists){
                        
 -                      rtext = typeOut(dialogBoxText);
 +                      rtext=typeOut(dialogBoxText);
                        
                        if(dialogImportant){
 -                              setFontColor(255, 255, 255);
 -                              
 -                              // handle timeout
 -                              if(dialogPassive && (dialogPassiveTime -= deltaTime) <= 0){
 -                                      dialogPassive = false;
 -                                      dialogImportant = false;
 -                                      dialogBoxExists = false;
 +                              setFontColor(255,255,255);
 +                              if(dialogPassive){
 +                                      dialogPassiveTime -= deltaTime;
 +                                      if(dialogPassiveTime < 0){
 +                                              dialogPassive = false;
 +                                              dialogImportant = false;
 +                                              dialogBoxExists = false;
 +                                      }
                                }
 -                              
 -                              // draw text
                                if(fadeIntensity == 255 || dialogPassive){
                                        setFontSize(24);
 -                                      putStringCentered(offset.x, offset.y, rtext);
 +                                      putStringCentered(offset.x,offset.y,rtext);
                                        setFontSize(16);
                                }
-                       }else{
-                       
-                               x=offset.x-SCREEN_WIDTH/2+HLINE*8;
+                       }else if(dialogMerchant){
+                               x=offset.x-SCREEN_WIDTH/6;
                                y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
                        
                        
                                glColor3ub(255,255,255);
+                               glBegin(GL_LINE_STRIP);
+                                       glVertex2f(x-1                                    ,y+1);
+                                       glVertex2f(x+1+(SCREEN_WIDTH/3),y+1);
+                                       glVertex2f(x+1+(SCREEN_WIDTH/3),y-1-SCREEN_HEIGHT*.6);
+                                       glVertex2f(x-1,y-1-SCREEN_HEIGHT*.6);
+                                       glVertex2f(x,y+1);
+                               glEnd();
+                       
+                               glColor3ub(0,0,0);
+                               glRectf(x,y,x+SCREEN_WIDTH/3,y-SCREEN_HEIGHT*.6);
+                               
+                               // draw typeOut'd text
+                               putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
+                               merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 6.5) - 16;
+                               merchAOptLoc[0][1] = offset.x + (SCREEN_WIDTH / 6.5);
+                               merchAOptLoc[1][0] = offset.y + (SCREEN_HEIGHT *.25);
+                               merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25);
+                               merchAOptLoc[2][0] = offset.x - (SCREEN_WIDTH / 6.5);
+                               merchAOptLoc[2][1] = offset.x + (SCREEN_WIDTH / 6.5) + 16;
+                               for(i = 0; i < 2; i++){
+                                       if(mouse.x > merchAOptLoc[0][i] && mouse.x < merchAOptLoc[2][i] &&
+                                          mouse.y > merchAOptLoc[1][i] - 8 && mouse.y < merchAOptLoc[1][i] + 8){
+                                               glColor3ub(255, 255, 0);
+                                       }else{
+                                               glColor3ub(255,255,255);
+                                       }
+                               }
+                               glBegin(GL_TRIANGLES);
+                                       glVertex2f(merchAOptLoc[0][0],merchAOptLoc[1][0]);
+                                       glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]-8);
+                                       glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]+8);
+                                       glVertex2f(merchAOptLoc[2][1],merchAOptLoc[1][1]);
+                                       glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]-8);
+                                       glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]+8);
+                               glEnd();
+                       
+                               // draw / handle dialog options if they exist
+                               for(i = 0; i < dialogOptCount; i++){
+                                       setFontColor(255, 255, 255);
+                                       
+                                       // draw option
+                                       tmp = putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
+                                       
+                                       // get coordinate information on option
+                                       dialogOptLoc[i][2] = offset.x + tmp;
+                                       dialogOptLoc[i][0] = offset.x - tmp;
+                                       dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1);
+                                       
+                                       // make text yellow if the mouse hovers over the text
+                                       if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] &&
+                                          mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){
+                                                 setFontColor(255, 255, 0);
+                                                 putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
+                                       }
+                               }
+                               
+                               setFontColor(255, 255, 255);
+                       }else{ //normal dialog box
+                       
+                               x=offset.x-SCREEN_WIDTH/2+HLINE*8;
+                               y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+                                               
+                               // draw white border
+                               glColor3ub(255, 255, 255);
++
                                glBegin(GL_LINE_STRIP);
 -                                      glVertex2f(x - 1                                                        , y + 1                                         );
 -                                      glVertex2f(x + 1 + SCREEN_WIDTH - HLINE * 16, y + 1                                             );
 -                                      glVertex2f(x + 1 + SCREEN_WIDTH - HLINE * 16, y - 1 - SCREEN_HEIGHT / 4 );
 -                                      glVertex2f(x - 1                                                        , y - 1 - SCREEN_HEIGHT / 4 );
 -                                      glVertex2f(x                                                            , y + 1                                         );
 +                                      glVertex2f(x-1                                          ,y+1);
 +                                      glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1);
 +                                      glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
 +                                      glVertex2f(x-1                                          ,y-1-SCREEN_HEIGHT/4);
 +                                      glVertex2f(x                                            ,y+1);
                                glEnd();
                        
 -                              // draw black box
 -                              glColor3ub(0, 0, 0);
 -                              glRectf(x, y, x + SCREEN_WIDTH - HLINE * 16, y - SCREEN_HEIGHT / 4);
 +                              glColor3ub(0,0,0);
 +                              glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
                        
 -                              // draw typeOut'd text
 -                              putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
 +                              rtext=typeOut(dialogBoxText);
                        
 -                              // draw / handle dialog options if they exist
 -                              for(i = 0; i < dialogOptCount; i++){
 -                                      setFontColor(255, 255, 255);
 -                                      
 -                                      // draw option
 -                                      tmp = putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
 -                                      
 -                                      // get coordinate information on option
 +                              putString(x+HLINE,y-fontSize-HLINE,rtext);
 +                      
 +                              for(i=0;i<dialogOptCount;i++){
 +                                      setFontColor(255,255,255);
 +                                      tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
                                        dialogOptLoc[i][2] = offset.x + tmp;
                                        dialogOptLoc[i][0] = offset.x - tmp;
                                        dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1);
                        return;
                }
  
 -              // check for selected option
 -              for(i = 0; i < dialogOptCount; i++){
 -                      if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] &&
 -                         mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){
 +              for(i=0;i<dialogOptCount;i++){
 +                      if(mouse.x > dialogOptLoc[i][0] &&
 +                         mouse.x < dialogOptLoc[i][2] &&
 +                         mouse.y > dialogOptLoc[i][1] &&
 +                         mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
                                dialogOptChosen = i + 1;
 -                              break;
 +                              goto DONE;
                        }
                }
 -              if(dialogMerchant){
 -                      for(i = 0; i < 2; i++){
 -                      }
 -              }
 +DONE:
+               
+               // handle important text
                if(dialogImportant){
                        dialogImportant = false;
                        setFontSize(16);
diff --cc src/world.cpp
index 4fa71d8585b6328daf88546d6fa4464ec2083069,9e891fb26c92a431d67a96e7750af3edac630628..80ddc5a27a0ae8484173ab8aa2036cc45b685cc7
@@@ -148,9 -118,10 +148,11 @@@ deleteEntities( void 
                delete mob.back();
                mob.pop_back();
        }
-     
-     // free npcs
-       while ( !npc.empty() ) {
++
+       while(!merchant.empty()){
+               merchant.pop_back();
+       }
+       while(!npc.empty()){
                delete npc.back();
                npc.pop_back();
        }
                delete village.back();
                village.pop_back();
        }
-       
  }
  
 -World::~World(void){
 -      /*if(behind != NULL)
 -              delete behind;*/
 -      
 +/**
 + * The world destructor.
 + * 
 + * This will free objects used by the world itself, then free the vectors of
 + * entity-related objects.
 + */
 +
 +World::
 +~World( void )
 +{
 +    // sdl2_mixer's object
        if(bgmObj)
                Mix_FreeMusic(bgmObj);
 +    
 +    // bgm path
        if(bgm)
                delete[] bgm;
 +
        delete bgTex;
 -      delete[] star;
 -      delete[] line;
        
        delete[] toLeft;
        delete[] toRight;
@@@ -810,22 -945,28 +811,21 @@@ singleDetect( Entity *e 
        }
  }
  
 -void World::detect(Player *p){
 -      
 -      /*
 -       *      Handle the player. 
 -      */
 -      
 -      //auto pl = std::async(&World::singleDetect,this,p);
 -      //std::thread(&World::singleDetect,this, p).detach();
 -       singleDetect(p);
 +void World::
 +detect( Player *p )
 +{
-       
 +      // handle the player
 +      std::thread( &World::singleDetect, this, p).detach();
                
 -      /*
 -       *      Handle all remaining entities in this world. 
 -      */
 -      
 -//LOOOOP:
 -      for(auto &e : entity)
 -              //std::thread(&World::singleDetect,this,e).detach();
 -              singleDetect(e);
 -      for(auto &part : particles){
 +    // handle other entities
 +      for ( auto &e : entity )
 +              std::thread(&World::singleDetect,this,e).detach();
 +        
 +    // handle particles
 +      for ( auto &part : particles ) {
                int l;
                unsigned int i;
 -              l=(part->loc.x + part->width / 2 - x_start) / HLINE;
 +              l=(part->loc.x + part->width / 2 - worldStart) / HLINE;
                if(l < 0) l=0;
                i = l;
                if(i > lineCount-1) i=lineCount-1;
@@@ -1337,12 -1537,18 +1345,12 @@@ World *loadWorldFromXMLNoSave(const cha
        bool dialog,Indoor;
        
        const char *ptr,*name;
 -      
 -      unsigned int size = 5 + strlen(path);
 +              
 +      currentXML = (std::string)"xml/" + path;
  
 -      if(currentXML)
 -              delete[] currentXML;
 -      memset((currentXML = new char[size]),0,size);
 -      strcpy(currentXML,"xml/");
 -      strcat(currentXML,path);
 -      
 -      xml.LoadFile(currentXML);
 +      xml.LoadFile(currentXML.c_str());
        wxml = xml.FirstChildElement("World");
-       
        if(wxml){
                wxml = wxml->FirstChildElement();
                vil = xml.FirstChildElement("World")->FirstChildElement("village");
Simple merge