]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
save/load tests
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 4 Jan 2016 13:48:27 +0000 (08:48 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 4 Jan 2016 13:48:27 +0000 (08:48 -0500)
Changelog
Goals.txt
include/ui.h
include/world.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp

index c0d2b9e55ac2f8f9bb1d21fcc75a31932aa23d85..e3ed5e0f401825edd9f1cd0047fdfc8fb75b2043 100644 (file)
--- a/Changelog
+++ b/Changelog
        - added World::getAvailableNPC() for easy quest assigner assigning
        - added the Condition class, so that events and actions can be remembered by NPCs
        - added functionality for multiple lights (GLSL)
+
+12/22/2015:
+===========
+
+       - 3 month Changelog anniversary!
+       - fixed dialog quitting bug
+       - worked on village spawning
+       - worked on wrapping text for dialog boxes
+       - did more work on GLSL shaders
+
+1/3/2015:
+=========
+
+       - finished wrapping text for dialog boxes
+       - began working on world saving/loading again
+       - got some mad GLSL shaders running
index 140cdd37f190a01e733ccfb225345812583df848..4848bac476f9ad4d6f4ce443c17477e6ebefe03a 100644 (file)
--- a/Goals.txt
+++ b/Goals.txt
@@ -35,7 +35,7 @@ End of December:
        - create first 'chapters' of story
        - create very first areas in the game (code it) to get an
          idea of what's gonna go down
-         
+
 January - March:
 ===============
 
@@ -45,7 +45,7 @@ January - March:
 February - End of March:
 ========================
 
-       - design sound effects / background music?
+       - design or focus on sound effects / background music?
        
 March-ish:
 ======
index 6a81dab5627e21f7ce0b8c3118d3cbf37c7d1717..b769bbff4943feea86d4c9f1273f526642f993e3 100644 (file)
@@ -33,6 +33,8 @@ namespace ui {
        extern unsigned char dialogOptChosen;
        extern bool dialogImportant;
 
+       extern unsigned int textWrapLimit;
+
        /*
         *      Initializes the FreeType system.
        */
index 98ca54a562aac38932f7e3c14cdf6459891fab84..cdcea3c6f869893e0d4439fd60077966b812d256 100644 (file)
@@ -8,6 +8,9 @@
 #ifndef WORLD_H
 #define WORLD_H
 
+#include <ostream>
+#include <istream>
+
 #include <common.h>
 #include <entities.h>
 
@@ -128,6 +131,7 @@ protected:
         */
        
        Texturec *bgTex;
+       WORLD_BG_TYPE bgType;
        
        /**
         * The Mix_Music object that holds the background soundtrack for the world.
@@ -167,7 +171,7 @@ public:
        std::vector<Particles   *>      particles;
        
        void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside);
-       void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside);
+       void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside);
        void addMob(int t,float x,float y);
        void addMob(int t,float x,float y,void (*hey)(Mob *));
        void addNPC(float x,float y);
@@ -262,8 +266,8 @@ public:
        
        int getTheWidth(void);
        
-       void save(FILE *);
-       void load(FILE *);
+       void save(std::ofstream *);
+       void load(std::ifstream *);
 };
 
 /*
index e6ff2eb240a5a83e221203ef5ae2b0386f0443c9..2c088cb24e0b5426f8ab36c075fcef7e089d0b16 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -480,6 +480,7 @@ void mainLoop(void){
        
        if(prev != currentWorld){
                currentWorld->bgmPlay(prev);
+               ui::dialogBoxExists = false;
        }
        
        if(prevPrevTime + MSEC_PER_TICK <= currentTime){
index 38490406f661afc7877679e007c30a6974369f5a..d424aba40151807321d5d5dcbaff37ae1119e107 100644 (file)
@@ -101,7 +101,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
        tex = new Texturec(1,"assets/NPC.png");
        inv = new Inventory(NPC_INV_SIZE);
        
-       randDialog = rand() % 12 - 1;
+       randDialog = 6;//rand() % 12 - 1;
 }
 NPC::~NPC(){
        while(!aiFunc.empty()){
@@ -341,7 +341,7 @@ const char *randomDialog[] = {
        "How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
        "I don\'t think anyone has ever been able to climb up that hill.",
        "If you ever see a hole in the ground, watch out; it could mean the end for you.",
-       "Did you know this game has over 4000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
+       "Did you know this game has over 5000 lines of code? I didn\'t. I didn't even know I was in a game until now...",
        "HELP MY CAPS LOCK IS STUCK",
        "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.",
        "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.",
index 7dbe98ebc9e08c4820be3d645261f7a2633e8911..ff77728283e1027f91acd5b9d71a9ee8b8fae7e4 100644 (file)
@@ -115,15 +115,21 @@ static World *worldSpawnHill3;
 
 static IndoorWorld *worldSpawnHill2_Building1;
 
+static World *worldFirstVillage;
 /*
  *     initEverything() start
  */
 
 void destroyEverything(void);
 void initEverything(void){
-
+       //static std::ifstream i ("world.dat",std::ifstream::in | std::ifstream::binary);
+       
        worldSpawnHill1 = new World();
-       worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
+       /*if(!i.fail()){
+               worldSpawnHill1->load(&i);
+               i.close();
+       }else*/
+               worldSpawnHill1->generateFunc(400,gen_worldSpawnHill1);
        worldSpawnHill1->setBackground(BG_FOREST);
        worldSpawnHill1->setBGM("assets/music/embark.wav");
        worldSpawnHill1->addMob(MS_TRIGGER,0,0,worldSpawnHill1_hillBlock);
@@ -138,12 +144,18 @@ void initEverything(void){
        worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
        worldSpawnHill3->setBackground(BG_FOREST);
        worldSpawnHill3->setBGM("assets/music/ozone.wav");
-       worldSpawnHill3->addHole(800,1000);
+       
+       worldFirstVillage = new World();
+       worldFirstVillage->generate(1000);
+       worldFirstVillage->setBackground(BG_FOREST);
+       worldFirstVillage->setBGM("assets/music/embark.wav");
        
        worldSpawnHill1->toRight = worldSpawnHill2;
        worldSpawnHill2->toLeft = worldSpawnHill1;
        worldSpawnHill2->toRight = worldSpawnHill3;
        worldSpawnHill3->toLeft = worldSpawnHill2;
+       worldSpawnHill3->toRight = worldFirstVillage;
+       worldFirstVillage->toLeft = worldSpawnHill3;
 
        /*
         *      Spawn some entities.
@@ -166,6 +178,8 @@ void initEverything(void){
        worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
        worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
        
+       worldFirstVillage->addVillage(5,0,0,STRUCTURET,worldSpawnHill2_Building1);
+       
        player = new Player();
        player->spawn(200,100);
 
@@ -178,6 +192,11 @@ extern std::vector<int (*)(NPC *)> AIpreload;
 extern std::vector<NPC *> AIpreaddr;
 
 void destroyEverything(void){
+       static std::ofstream o;
+       o.open("world.dat",std::ifstream::binary);
+       worldSpawnHill1->save(&o);
+       o.close();
+       
        while(!AIpreload.empty())
                AIpreload.pop_back();
        while(!AIpreaddr.empty())
index f73f48abfbb0641944160949928fcc2ec47bbc4a..b827b431a021ea7ef784e7760d63d214ff88c587 100644 (file)
@@ -95,6 +95,8 @@ namespace ui {
        bool dialogImportant = false;
        unsigned char dialogOptChosen = 0;
        
+       unsigned int textWrapLimit = 110;
+       
        /*
         *      Current font size. Changing this WILL NOT change the font size, see setFontSize() for
         *      actual font size changing.
@@ -266,7 +268,13 @@ namespace ui {
                */
                
                do{
-                       if(s[i]=='\n'){                 //      Handle newlines
+                       if(i && ((i / 110.0) == (i / 110))){
+                               yo-=fontSize*1.05;
+                               xo=x;
+                               if(s[i] == ' ')
+                                       i++;
+                       }
+                       if(s[i] == '\n'){
                                yo-=fontSize*1.05;
                                xo=x;
                        }else if(s[i]==' '){    //      Handle spaces
@@ -308,12 +316,13 @@ namespace ui {
         *      Draw a string in a typewriter-esque fashion. Each letter is rendered as calls are made
         *      to this function. Passing a different string to the function will reset the counters.
        */
-       
+
+       static char *ret = NULL;
        char *typeOut(char *str){
                static unsigned int sinc,       //      Acts as a delayer for the space between each character.
                                                        linc=0, //      Contains the number of letters that should be drawn.
                                                        size=0; //      Contains the full size of the current string.
-               static char *ret = NULL;
+               //static char *ret = NULL;
                
                /*
                 *      Create a well-sized buffer if we haven't yet.
@@ -453,6 +462,8 @@ namespace ui {
                dialogBoxExists = true;
                dialogImportant = false;
                
+               if(ret)
+                       ret[0] = '\0';
        }
        void waitForDialog(void){
                do{
@@ -667,7 +678,6 @@ DONE:
                                                                memcpy(&player->loc,&tmppos,sizeof(vec2));
                                                                currentWorld = tmp;
                                                                toggleBlackFast();
-                                                               dialogBoxExists = false;
                                                        }
                                                }
                                                break;
@@ -689,7 +699,6 @@ DONE:
                                                                memcpy(&player->loc,&tmppos,sizeof(vec2));
                                                                currentWorld = tmp;
                                                                toggleBlackFast();
-                                                               dialogBoxExists = false;
                                                        }
                                                }
                                                break;
index 5663086d868d64f500e8b77d2243f422570c0292..2afbdf5dbc8e5c7888e3b545727dcc3061b5330a 100644 (file)
@@ -50,6 +50,7 @@ float worldGetYBase(World *w){
 }
 
 void World::setBackground(WORLD_BG_TYPE bgt){
+       bgType = bgt;
        switch(bgt){
        case BG_FOREST:
                bgTex = new Texturec(7,bgPaths[0]);
@@ -60,12 +61,28 @@ void World::setBackground(WORLD_BG_TYPE bgt){
        }
 }
 
-void World::save(FILE *s){
-       fclose(s);
+void World::save(std::ofstream *o){
+       o->write((char *)&lineCount,            sizeof(unsigned int));
+       o->write((char *)&line     ,lineCount * sizeof(struct line_t));
+       o->write("GG"              ,2         * sizeof(char));
+       o->write((char *)&star     ,100       * sizeof(vec2));
 }
 
-void World::load(FILE *s){
-       fclose(s);
+void World::load(std::ifstream *i){
+       static char end[2];
+       
+       i->read((char *)&lineCount,sizeof(unsigned int));
+       line = new struct line_t[lineCount];
+       
+       i->read((char *)&line,lineCount * sizeof(struct line_t));
+       i->read(end          ,2         * sizeof(char));
+       if(strncmp(end,"GG",2)){
+               std::cout<<"world.dat corrupt"<<std::endl;
+               exit(EXIT_FAILURE);
+       }
+       i->read((char *)&star,100 * sizeof(vec2));
+       
+       x_start = 0 - getWidth(this) / 2;
 }
 
 World::World(void){
@@ -913,16 +930,20 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){
        entity.push_back(build.back());
 }
        
-void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside){
+void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){
        std::cout << npcMin << ", " << npcMax << std::endl;
-       int xwasd;
+       //int xwasd;
        for(int i = 0; i < bCount; i++){
-               xwasd = (rand()%(int)x+1000*HLINE);
+               addStructure(t,HOUSE,x_start + (i * 300),100,inside);
+               /*std::cout<<"1\n";
                HERE:
+               xwasd = (rand()%(int)x+1000*HLINE);
                for(auto &bu : build){
                        if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE;
                }
-               addStructure(t,HOUSE,xwasd,y,outside);
+               std::cout<<"2\n";
+               addStructure(t,HOUSE,xwasd,y,inside);
+               std::cout<<"3\n";*/
        }
 }
 void World::addMob(int t,float x,float y){