]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world linking xml'd
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 12 Jan 2016 12:38:57 +0000 (07:38 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 12 Jan 2016 12:38:57 +0000 (07:38 -0500)
Changelog
include/common.h
include/world.h
main.cpp
src/common.cpp
src/gameplay.cpp
src/world.cpp
test.frag
xml/playerSpawnHill1.xml
xml/playerSpawnHill2.xml [new file with mode: 0644]

index 02dd4366d8d4c52b4f713ad9a4c0c039aeb9d406..30c1a50947e2b05bd3b6da505417e57d8692b096 100644 (file)
--- a/Changelog
+++ b/Changelog
        - xml'd npc dialogs
        - drafted page xml
        
+1/11/2015:
+==========
+
+       - improved npc dialog xmling
+       - WIP xml'd world linking
+       - textures?
+       - music?
index 855272085f9c4761ab136606d01ae4be343db851..22ecb22f227eadb3cc97c26ea4b6c899c844de88 100644 (file)
@@ -201,5 +201,6 @@ unsigned int millis(void);
 #endif // __WIN32__
 
 int getdir(const char *dir, std::vector<std::string> &files);
+void strVectorSortAlpha(std::vector<std::string> *v);
 
 #endif // COMMON_H
index 0e8546290af6fdf113eaa67dbb9a3272e1d6d049..28d7a0968b4b94f3773679763e2c58779a20f221 100644 (file)
@@ -157,8 +157,8 @@ public:
         * ui.cpp for world jumping.
         */
 
-       World *toLeft,
-                 *toRight,
+       World **toLeft,
+                 **toRight,
                  *behind,
                  *infront;
        
index 3ae9787f5dd85f630e4b72be28dc5b1f80473691..79c7250dab313f1b594452846281b9b80d6062dd 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -376,6 +376,7 @@ int main(/*int argc, char *argv[]*/){
            std::vector<char> programError( (logLength > 1) ? logLength : 1 );
            glGetProgramInfoLog(shaderProgram, logLength, NULL, &programError[0]);
            std::cout << &programError[0] << std::endl;
+                       
        #endif //SHADERS
        
        //glEnable(GL_DEPTH_TEST); //THIS DOESN'T WORK ON LINUX
index 8defd613f56e87b1de21837fb2b3ec8cc9ccc83e..63077908dbef255cb81eb4bec7c77de88b09d089 100644 (file)
@@ -77,3 +77,17 @@ int getdir(const char *dir, std::vector<std::string> &files){
     closedir(dp);
     return 0;
 }
+
+void strVectorSortAlpha(std::vector<std::string> *v){
+       static bool change;
+       do{
+               change = false;
+               for(unsigned int i=0;i<v->size()-1;i++){
+                       if(v[0][i] > v[0][i+1]){
+                               std::cout<<"swap "<<v[0][i]<<" <-> "<<v[0][i+1]<<std::endl;
+                               std::swap(v[0][i],v[0][i+1]);
+                               change = true;
+                       }
+               }
+       }while(change);
+}
index a257ad33aa62250a0eebf80413c296365ec2ca2e..55161f9dfbcc15a73fdf20d82e79a1ad2e656eda 100644 (file)
@@ -32,16 +32,21 @@ typedef struct {
        char *file;
 } WorldXML;
 
+typedef struct {
+       char *name;
+       World *ptr;
+} WorldLink;
 
 typedef struct {
        NPC *npc;
        unsigned int index;
 } NPCDialog;
 
-std::vector<NPCDialog>         npcd;
-std::vector<WorldXML>          earthxml;
-std::vector<World *>           earth;
-std::vector<XMLElement *>      dopt;
+std::vector<NPCDialog>                 npcd;
+std::vector<WorldXML>                  earthxml;
+static std::vector<WorldLink>  earthlnk;
+std::vector<World *>                   earth;
+std::vector<XMLElement *>              dopt;
 
 int commonAIFunc(NPC *speaker){
        XMLDocument xml;
@@ -68,7 +73,7 @@ int commonAIFunc(NPC *speaker){
                        
                        do{
                                if(!strcmp(exml->Name(),"text")){
-                                       if(/*!strcmp(exml->Attribute("name"),speaker->name) &&*/ exml->UnsignedAttribute("id") == idx){
+                                       if(exml->UnsignedAttribute("id") == idx){
                                                
                                                if((oxml = exml->FirstChildElement("option"))){
                                                        const char *op;
@@ -158,22 +163,53 @@ void initEverything(void){
                abort();
        }
        
-       for(auto x : xmlFiles){
-               if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
-                       file = new char[5 + x.size()];
-                       memset(file,0,5 + x.size());
+       strVectorSortAlpha(&xmlFiles);
+       
+       for(unsigned int i=0;i<xmlFiles.size();i++){
+               if(strncmp(xmlFiles[i].c_str(),".",1) && strncmp(xmlFiles[i].c_str(),"..",2)){
+                       earthlnk.push_back((WorldLink){new char[strlen(xmlFiles[i].c_str() + 1)],NULL});
+                       strcpy(earthlnk.back().name,xmlFiles[i].c_str());
+               }
+       }
+       
+       for(unsigned int i=0;i<xmlFiles.size();i++){
+               if(strncmp(xmlFiles[i].c_str(),".",1) && strncmp(xmlFiles[i].c_str(),"..",2)){
+                       file = new char[5 + xmlFiles[i].size()];
+                       memset(file,0,5 + xmlFiles[i].size());
                        strncpy(file,"xml/",4);
-                       strcpy(file+4,x.c_str());
+                       strcpy(file+4,xmlFiles[i].c_str());
+                       std::cout<<std::endl<<"Loading "<<file<<" ..."<<std::endl<<std::endl;
                        xml.LoadFile(file);
 
                        wxml = xml.FirstChildElement("World")->FirstChildElement();
 
                        earth.push_back(new World());
                        
-                       do{
+                       for(auto &l : earthlnk){
+                               if(!strcmp(file+4,l.name)){
+                                       l.ptr = earth.back();
+                                       break;
+                               }
+                       }
+                       
+                       while(wxml){
                                name = wxml->Name();
-                               
-                               if(!strcmp(name,"style")){
+
+                               if(!strcmp(name,"link") && wxml->Attribute("left")){
+                                       for(auto &l : earthlnk){
+                                               if(!strcmp(l.name,wxml->Attribute("left"))){
+                                                       earth.back()->toLeft = &l.ptr;
+                                                       break;
+                                               }
+                                       }
+                               }else if(!strcmp(name,"link") && wxml->Attribute("right")){
+                                       for(auto &l : earthlnk){
+                                               if(!strcmp(l.name,wxml->Attribute("right"))){
+                                                       earth.back()->toRight = &l.ptr;
+                                                       break;
+                                               }
+                                       }
+                               }else if(!strcmp(name,"style")){
                                        earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
                                        earth.back()->setBGM(wxml->Attribute("bgm"));
                                }else if(!strcmp(name,"generation")){
@@ -208,10 +244,15 @@ SKIP:
                                                earth.back()->npc.back()->addAIFunc(commonAIFunc,false);
                                                npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
                                        }
+                               }else if(!strcmp(name,"structure")){
+                                       /*if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
+                                               earth.back()->addStructure((getRand() % earth.back()->getTheWidth() / 2.0f,100);
+                                       else
+                                               earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));*/
                                }
                                
                                wxml = wxml->NextSiblingElement();
-                       }while(wxml);
+                       }
                        
                        delete[] file;
                }
index e66fb0d64c37bae4d2da6ace5cc9dd33d4abb16c..e2c6aa9aec04b2052c52b63ac184600729a2379a 100644 (file)
@@ -185,6 +185,8 @@ void World::load(std::ifstream *i){
        }
 }
 
+void *NULLPTR = NULL;
+
 World::World(void){
        
        bgm = NULL;
@@ -195,9 +197,9 @@ World::World(void){
        */
        
        behind  =
-       infront =
+       infront = NULL;
        toLeft  =
-       toRight = NULL;
+       toRight = (World **)&NULLPTR;
        
        /*
         *      Allocate and clear an array for star coordinates.
@@ -1151,19 +1153,19 @@ NPC *World::getAvailableNPC(void){
 }
 
 World *World::goWorldLeft(Player *p){
-       if(toLeft&&p->loc.x<x_start+HLINE*15){
-               p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;
-               p->loc.y=toLeft->line[toLeft->lineCount-GEN_INC-1].y;
-               return toLeft;
+       if(toLeft[0]&&p->loc.x<x_start+HLINE*15){
+               p->loc.x=toLeft[0]->x_start+getWidth(toLeft[0])-HLINE*10;
+               p->loc.y=toLeft[0]->line[toLeft[0]->lineCount-GEN_INC-1].y;
+               return toLeft[0];
        }
        return this;
 }
 
 World *World::goWorldRight(Player *p){
-       if(toRight&&p->loc.x+p->width>x_start+getWidth(this)-HLINE*10){
-               p->loc.x=toRight->x_start+HLINE*10;
-               p->loc.y=toRight->line[0].y;
-               return toRight;
+       if(toRight[0]&&p->loc.x+p->width>x_start+getWidth(this)-HLINE*10){
+               p->loc.x=toRight[0]->x_start+HLINE*10;
+               p->loc.y=toRight[0]->line[0].y;
+               return toRight[0];
        }
        return this;
 }
index 1c1e77b2dec34e316d50e7c4369b9998266ed25a..c6ff3c9c6c381b793be61ef9a2bba7655363c38e 100644 (file)
--- a/test.frag
+++ b/test.frag
@@ -1,4 +1,4 @@
-#version 130\r
+#version 120\r
 uniform sampler2D sampler;\r
 \r
 uniform int numLight;\r
@@ -24,4 +24,4 @@ void main(){
 \r
        color += vec4(amb,amb,amb,1.0f+amb);\r
        gl_FragColor = tex * vec4(color)*tex.a;\r
-}
\ No newline at end of file
+}\r
index 5a0e51f690d38621d1405581864b5710fc0913aa..fbf5d8d03c185f9ac7c8ffb789431809963f5f37 100644 (file)
@@ -1,7 +1,9 @@
 <?xml version="1.0"?>
 <World>
        <style background="0" bgm="assets/music/embark.wav" />
-       <generation type="Random" width="2000" />
+       <generation type="Random" width="800" />
+       
+       <link right="playerSpawnHill2.xml" />
        
        <mob type="1" />
        
diff --git a/xml/playerSpawnHill2.xml b/xml/playerSpawnHill2.xml
new file mode 100644 (file)
index 0000000..d6a966f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<World>
+       <style background="0" bgm="assets/music/embark.wav" />
+       <generation type="Random" width="500" />
+       
+       <link left="playerSpawnHill1.xml" />
+
+</World>
+