]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
save/load positions
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 21 Jan 2016 13:20:27 +0000 (08:20 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 21 Jan 2016 13:20:27 +0000 (08:20 -0500)
include/entities.h
main.cpp
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp

index fa9828577c8d8837109036ee2345ad78fa77fb2a..1fcb89652faecdd9d1a3a18720b24629e6eb523b 100644 (file)
@@ -190,6 +190,7 @@ public:
        ~NPC();
        
        void addAIFunc(int (*func)(NPC *),bool preload);
+       void clearAIFunc(void);
        void interact();
        void wander(int);
 };
index cb5a20a59c7b08d340eda0fb4862477e82e81b33..1df2c003e58d2c4f4193215ec1ff7a53c9a49853 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -110,7 +110,7 @@ extern bool worldInside;
  *     referenced somewhere.
 */
 
-unsigned int tickCount = 0;
+unsigned int tickCount = DAY_CYCLE;
 unsigned int deltaTime = 0;
 
 /*
@@ -340,7 +340,7 @@ int main(/*int argc, char *argv[]*/){
 
        const GLchar *shaderSource = readFile("test.frag");
 
-       GLint bufferln = 0;
+       GLint bufferln = GL_FALSE;
        int logLength;
 
 
index 334671e05ea13056f521e6a8e0eaddce04a37360..faa7012bbf0832b3ade9ae90adb16a096bae09eb 100644 (file)
@@ -104,9 +104,10 @@ const char *readFile(const char *path){
        }
        
        in.seekg(0,in.end);
-       buf = new GLchar[(size = in.tellg())];
+       buf = new GLchar[(size = in.tellg()) + 1];
        in.seekg(0,in.beg);
        in.read(buf,size);
+       buf[size] = '\0';
        
        in.close();
        return buf;
index 65085ae1f75ad310894ff8d8b99d42f94d716c73..0507376c6eaac611bed296887bc2929ae1076b24 100644 (file)
@@ -393,6 +393,10 @@ void NPC::addAIFunc(int (*func)(NPC *),bool preload){
        else aiFunc.push_back(func);
 }
 
+void NPC::clearAIFunc(void){
+       aiFunc.clear();
+}
+
 const char *randomDialog[] = {
        "What a beautiful day it is.",
        "Have you ever went fast? I have.",
index b8e51dc01cd132f7d3d514fef489ad872f1f9b88..7730cf693302c8d76dbff0c875380f124427baae 100644 (file)
@@ -145,14 +145,17 @@ int commonAIFunc(NPC *speaker){
                                        speaker->dialogIndex = idx;
                                        
                                        if(exml->QueryBoolAttribute("stop",&stop) == XML_NO_ERROR && stop){
-                                               speaker->dialogIndex = -1;
+                                               speaker->dialogIndex = 9999;
                                                return 0;
                                        }else if(exml->QueryBoolAttribute("pause",&stop) == XML_NO_ERROR && stop){
-                                               speaker->dialogIndex = -1;
+                                               speaker->dialogIndex = 9999;
                                                return 1;
                                        }else return commonAIFunc(speaker);
+                               }else{
+                                       speaker->dialogIndex = 9999;
+                                       return 0;
                                }
-                               return 0;
+                               return 1;
                        }
                }
                
index 76e27774e9e9e10cae768cc6e40e843eee60d694..49acd4ff2c730f098e14365878e92c2ffc2612c8 100644 (file)
@@ -730,7 +730,10 @@ DONE:
                                                                toggleBlackFast();
                                                        }
                                                }else{*/
-                                                       currentWorld=currentWorld->goInsideStructure(player);
+                                                       if((tmp = currentWorld->goInsideStructure(player)) != currentWorld){
+                                                               delete currentWorld;
+                                                               currentWorld = tmp;
+                                                       }
                                                //}*/
                                                break;
                                        case SDLK_i:
index ed1b522a62b85acd6b09c374819446509b6a0d35..af960d576338adc3528d0d74c2bc290c1468e45f 100644 (file)
@@ -1154,17 +1154,29 @@ int World::getTheWidth(void){
 }
 
 void World::save(void){
-       static std::string data;
+       std::string data;
        
        std::string save = (std::string)currentXML + ".dat";
        std::ofstream out (save,std::ios::out | std::ios::binary);
        
        std::cout<<"Saving to "<<save<<" ..."<<std::endl;
-       
-       //data.append(std::to_string(npc.size()) + "\n");
-       for(auto &n : npc)
+
+       for(auto &n : npc){
                data.append(std::to_string(n->dialogIndex) + "\n");
-               
+               data.append(std::to_string((int)n->loc.x) + "\n");
+               data.append(std::to_string((int)n->loc.y) + "\n");
+       }
+       
+       for(auto &b : build){
+               data.append(std::to_string((int)b->loc.x) + "\n");
+               data.append(std::to_string((int)b->loc.y) + "\n");
+       }
+       
+       for(auto &m : mob){
+               data.append(std::to_string((int)m->loc.x) + "\n");
+               data.append(std::to_string((int)m->loc.y) + "\n");
+       }
+       
        data.append("dOnE\0");
        out.write(data.c_str(),data.size());
        
@@ -1184,15 +1196,35 @@ void World::load(void){
        
        for(auto &n : npc){
                std::getline(iss,line);
-               if((n->dialogIndex = std::stoi(line)) != -1)
+               if((n->dialogIndex = std::stoi(line)) != 9999)
                        n->addAIFunc(commonAIFunc,false);
+               else n->clearAIFunc();
+               
+               std::getline(iss,line);
+               n->loc.x = std::stoi(line);
+               std::getline(iss,line);
+               n->loc.y = std::stoi(line);
+       }
+       
+       for(auto &b : build){
+               std::getline(iss,line);
+               b->loc.x = std::stoi(line);
+               std::getline(iss,line);
+               b->loc.y = std::stoi(line);
+       }
+       
+       for(auto &m : mob){
+               std::getline(iss,line);
+               m->loc.x = std::stoi(line);
+               std::getline(iss,line);
+               m->loc.y = std::stoi(line);
        }
        
        while(std::getline(iss,line)){
                if(line == "dOnE")
                        break;
                
-               std::cout<<line<<std::endl;
+               //std::cout<<line<<std::endl;
        }
        
        //abort();
@@ -1202,6 +1234,7 @@ IndoorWorld::IndoorWorld(void){
 }
 
 IndoorWorld::~IndoorWorld(void){
+       std::cout<<"A\n";
        delete bgTex;
        delete[] star;
        delete[] line;
@@ -1438,7 +1471,7 @@ World *loadWorldFromXML(const char *path){
                        dialog = false;
                        if(wxml->QueryBoolAttribute("hasDialog",&dialog) == XML_NO_ERROR && dialog)
                                tmp->npc.back()->addAIFunc(commonAIFunc,false);
-                       else tmp->npc.back()->dialogIndex = -1;
+                       else tmp->npc.back()->dialogIndex = 9999;
                        
                }else if(!strcmp(name,"structure")){
                        ptr = wxml->Attribute("inside");
@@ -1455,6 +1488,6 @@ World *loadWorldFromXML(const char *path){
                dat.close();
                tmp->load();
        }
-       
+
        return tmp;
 }