aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-04 08:48:27 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-04 08:48:27 -0500
commit65addfa212a2aef2f2d6de3cb49edc99a8f02f59 (patch)
treee47017d9f57b8447ce138fe059bdd7f5e559dacd /src/world.cpp
parent272a152b54a198a84f122ab8bedb1019708b7008 (diff)
save/load tests
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 5663086..2afbdf5 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -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){