]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world rewrite -- fixed all world stuffs
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 29 Feb 2016 13:31:49 +0000 (08:31 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 29 Feb 2016 13:31:49 +0000 (08:31 -0500)
include/world.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index f60c181a28dedd0311767d15779f154fe345ccab..05b2a10b21b6860a325077b0106221feffc86780 100644 (file)
@@ -63,7 +63,7 @@ typedef struct {
 
 typedef struct {
     bool          grassUnpressed;
-    int           grassHeight[2];
+    float         grassHeight[2];
     float         groundHeight;
     unsigned char groundColor;
 } WorldData;
@@ -481,7 +481,7 @@ public:
 };
 
 extern int worldShade;
-extern char *currentXML;
+extern std::string currentXML;
 
 World *loadWorldFromXML(const char *path);
 World *loadWorldFromXMLNoSave(const char *path);
index abea57823766a9a96e185dde234fff104f6d2f1d..885c6103baf5723f7bff8709c5f23de4f75b4d46 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -486,13 +486,14 @@ void mainLoop(void){
         * Update debug variables if necessary
         */
        
-       if(++debugDiv==20)
+       if ( ++debugDiv == 20 ) {
                debugDiv=0;
                
-       if(deltaTime)
-               fps=1000/deltaTime;
-       else if(!(debugDiv%10))
-               debugY = player->loc.y;
+               if ( deltaTime )
+                       fps = 1000 / deltaTime;
+               else if(!(debugDiv%10))
+                       debugY = player->loc.y;
+       }
 MENU:
        render();
 }
index 6c2da81d8a38688afe0904daf666632ab886e2ea..98bba8b60b983c461a040bd959500a9a1b76288a 100644 (file)
@@ -564,7 +564,7 @@ void Player::save(void){
        for(auto &i : inv->items)
                data.append(std::to_string((int)i.count) + "\n" + std::to_string((int)i.id) + "\n");
        
-       data.append((std::string)(currentXML+4) + "\n");
+       data.append((std::string)(currentXML.c_str() + 4) + "\n");
        
        data.append("dOnE\0");
        out.write(data.c_str(),data.size());
index d983804d86870aabfa60d20115df2ae9dc3e7c4b..95b95d6b532c41e5d931194dbafbd382d17cfc7a 100644 (file)
@@ -43,7 +43,7 @@ int commonAIFunc(NPC *speaker){
         * Load the current world's XML file into memory for reading.
         */
        
-       xml.LoadFile(currentXML);
+       xml.LoadFile(currentXML.c_str());
        exml = xml.FirstChildElement("Dialog");
        
        /*
@@ -222,7 +222,7 @@ void commonTriggerFunc(Mob *callee){
        if(!lock){
                lock = true;
        
-               xml.LoadFile(currentXML);
+               xml.LoadFile(currentXML.c_str());
                exml = xml.FirstChildElement("Trigger");
                
                while(strcmp(exml->Attribute("id"),callee->heyid.c_str()))
@@ -321,7 +321,7 @@ extern std::vector<NPC *> AIpreaddr;
 void destroyEverything(void){
        currentWorld->save();
        delete currentWorld;
-       delete[] currentXML;
+       //delete[] currentXML;
        
        while(!AIpreload.empty())
                AIpreload.pop_back();
index 57b5ff587ee709899812113d491510d89d515fd4..76dccb8e335f1b89bb278908effa75c63468f3e5 100644 (file)
@@ -246,7 +246,7 @@ generate( unsigned int width )
     
     // give every GROUND_HILLINESSth entry a groundHeight value
     for(unsigned int i = GROUND_HILLINESS; i < worldData.size(); i += GROUND_HILLINESS, wditer += GROUND_HILLINESS)
-        worldData[i].groundHeight = (*wditer).groundHeight + (randGet() % 12 - 6);
+        worldData[i].groundHeight = (*wditer).groundHeight + (randGet() % 8 - 4);
 
     // create slopes from the points that were just defined, populate the rest of the WorldData structure
     
@@ -261,9 +261,14 @@ generate( unsigned int width )
         (*wditer).grassHeight[0] = (randGet() % 16) / 3 + 2;
         (*wditer).grassHeight[1] = (randGet() % 16) / 3 + 2;
         
-        // dirty fix for bug -- please fix the bug
-        if( (*wditer).groundHeight <= 0 )
-            (*wditer).groundHeight = (*(wditer - 1)).groundHeight;
+        // bound checks
+        if ( (*wditer).groundHeight < GROUND_HEIGHT_MINIMUM )
+            (*wditer).groundHeight = GROUND_HEIGHT_MINIMUM;
+        else if ( (*wditer).groundHeight > GROUND_HEIGHT_MAXIMUM )
+                       (*wditer).groundHeight = GROUND_HEIGHT_MAXIMUM;
+               
+               if( (*wditer).groundHeight <= 0 )
+                       (*wditer).groundHeight = GROUND_HEIGHT_MINIMUM;
     }
     
     // define x-coordinate of world's leftmost 'line'
@@ -303,26 +308,26 @@ update( Player *p, unsigned int delta )
        }
 
     // iterate through particles
-    for ( std::vector<Particles *>::iterator pi = particles.begin(); pi != particles.end(); pi++ ) {
-        if ( (*pi)->kill(delta) ) {
-            //delete[] (*pi);
-            particles.erase(pi);
-        } else if ( (*pi)->canMove ) {
-            (*pi)->loc.x += (*pi)->velx * delta;
-            (*pi)->loc.y += (*pi)->vely * delta;
-            
-            for ( auto &b : build ) {
-                if ( b->subtype == FOUNTAIN ) {
-                    if ( (*pi)->loc.x >= b->loc.x && (*pi)->loc.x <= b->loc.x + b->width ) {
-                        if ( (*pi)->loc.y <= b->loc.y + b->height * 0.25f ) {
-                            //delete[] (*pi);
-                            particles.erase(pi);
-                        }
-                    }
-                }
-            }
-        }
-    }
+    for(unsigned int i=0;i<particles.size();i++){
+               if(particles[i]->kill(deltaTime)){
+                       delete particles[i];
+                       particles.erase(particles.begin()+i);
+               }else if(particles[i]->canMove){
+                       particles[i]->loc.y += particles[i]->vely * deltaTime;
+                       particles[i]->loc.x += particles[i]->velx * deltaTime;
+
+                       for(auto &b : build){
+                               if(b->bsubtype==FOUNTAIN){
+                                       if(particles[i]->loc.x >= b->loc.x && particles[i]->loc.x <= b->loc.x + b->width){
+                                               if(particles[i]->loc.y <= b->loc.y + b->height * .25){
+                                                       delete particles[i];
+                                                       particles.erase(particles.begin()+i);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
        
     // handle music fades
        if ( ui::dialogImportant )
@@ -394,7 +399,7 @@ draw( Player *p )
     int i, iStart, iEnd;
     
     // shade value for draws -- may be unnecessary
-       int shadeBackground = worldShade;
+       int shadeBackground = 0;
     
     // player's offset in worldData[]
        int pOffset;
@@ -532,8 +537,8 @@ draw( Player *p )
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
        
        glUseProgram( shaderProgram );
-       glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0);
-       glUniform1f( glGetUniformLocation( shaderProgram, "amb"    ), 0.5f );
+       glUniform1i( glGetUniformLocation( shaderProgram, "sampler"), 0 );
+       glUniform1f( glGetUniformLocation( shaderProgram, "amb"    ), 1 );
        
        if ( p->light ) {
                pointArray[light.size() + 1][0] = (float)( p->loc.x + SCREEN_WIDTH / 2 );
@@ -561,8 +566,8 @@ draw( Player *p )
         glTexCoord2i(0 ,1);glVertex2i(pOffset - (SCREEN_WIDTH / 1.5),GROUND_HEIGHT_MINIMUM);*/
 
         for ( i = iStart; i < iEnd; i++ ) {
-            if ( !worldData[i].groundHeight ) {
-                worldData[i].groundHeight = GROUND_HEIGHT_MINIMUM;
+            if ( worldData[i].groundHeight <= 0 ) {
+                worldData[i].groundHeight = GROUND_HEIGHT_MINIMUM - 1;
                 glColor4ub( 0, 0, 0, 255 );
             } else
                 safeSetColorA( 150, 150, 150, 255 );
@@ -573,7 +578,7 @@ draw( Player *p )
             glTexCoord2i( 1, (int)(worldData[i].groundHeight / 64) + worldData[i].groundColor ); glVertex2i(worldStart + i * HLINE + HLINE, 0 );
             glTexCoord2i( 0, (int)(worldData[i].groundHeight / 64) + worldData[i].groundColor ); glVertex2i(worldStart + i * HLINE           , 0 );
             
-            if ( worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM )
+            if ( worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1 )
                 worldData[i].groundHeight = 0;
         }
        
@@ -1004,16 +1009,17 @@ World *World::goWorldRight(Player *p){
        return this;
 }
 
-std::vector<char *>inside;
-World *World::goInsideStructure(Player *p){
+std::vector<std::string> inside;
+World *World::
+goInsideStructure( Player *p )
+{
        World *tmp;
        char *current;
        if(inside.empty()){
                for(auto &b : build){
                        if(p->loc.x            > b->loc.x            &&
                           p->loc.x + p->width < b->loc.x + b->width ){
-                               inside.push_back(new char[1 + strlen(currentXML)]);
-                               strcpy(inside.back(),(char *)(currentXML+4));
+                               inside.push_back((std::string)(currentXML.c_str() + 4));
                                
                                tmp = loadWorldFromXML(b->inside);
                                
@@ -1025,12 +1031,11 @@ World *World::goInsideStructure(Player *p){
                        }
                }
        }else{
-               strcpy((current = new char[strlen((char *)(currentXML + 4)) + 1]),(char *)(currentXML + 4));
-               tmp = loadWorldFromXML(inside.back());
+               strcpy((current = new char[strlen((const char *)(currentXML.c_str() + 4)) + 1]),(const char *)(currentXML.c_str() + 4));
+               tmp = loadWorldFromXML(inside.back().c_str());
                for(auto &b : tmp->build){
                        if(!strcmp(current,b->inside)){
                                p->loc.x = b->loc.x + (b->width / 2);
-                               delete[] inside.back();
                                inside.pop_back();
 
                                ui::toggleBlackFast();
@@ -1301,16 +1306,14 @@ World *Arena::exitArena(Player *p){
 #include <tinyxml2.h>
 using namespace tinyxml2;
 
-char *currentXML = NULL;
+std::string currentXML = "\0";
 
 extern World *currentWorld;
 
 World *loadWorldFromXML(const char *path){
-       if(currentXML){
+       if ( currentXML != "\0" )
                currentWorld->save();
-               delete[] currentXML;
-       }
-       
+
        return loadWorldFromXMLNoSave(path);
 }
 
@@ -1324,25 +1327,20 @@ World *loadWorldFromXMLNoSave(const char *path){
        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");
-       vil = xml.FirstChildElement("World")->FirstChildElement("village");
-
+       
        if(wxml){
                wxml = wxml->FirstChildElement();
+               vil = xml.FirstChildElement("World")->FirstChildElement("village");
                Indoor = false;
                tmp = new World();
        }else if((wxml = xml.FirstChildElement("IndoorWorld"))){
                wxml = wxml->FirstChildElement();
+               vil = NULL;
                Indoor = true;
                tmp = new IndoorWorld();
        }
index 269b393ffe0c6969ab399ae57a5c015e9ea238ca..ee2c46a8a7682c17373649f13f6e51b0d5ad90a3 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <World>
        <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/" />
-       <generation type="Random" width="1600" />
+       <generation type="Random" width="500" />
        <link left="playerSpawnHill2.xml" />
        
        <mob type="1" aggressive="false" />