Skip to content

Commit

Permalink
0.0.036: Loading/Saving (Release)
Browse files Browse the repository at this point in the history
Add skeleton code for Loading global maps from World Generator.
Resize local maps to 64*64 for development.
  • Loading branch information
RyanBabij committed Aug 29, 2018
1 parent 45256af commit 47a1800
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CompileCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/
#include <string>

const std::string COMPILE_COUNT = "5286";
const std::string COMPILE_COUNT = "5308";
#endif
13 changes: 8 additions & 5 deletions Driver_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int lastline = 0;

bool FAST_COUT = false;

const std::string VERSION = "0.0.028 Win32 dev";
const std::string VERSION = "0.0.036 Win32 dev";
const std::string G_WINDOW_TITLE = "WorldSim";

const std::string SAVE_FOLDER_PATH = "savedata";
Expand All @@ -54,10 +54,13 @@ int DEFAULT_NUMBER_CIVS = 0;

bool FOG_OF_WAR = true;

/* Size of each city in tiles. Size is CITY_SIZE * CITY_SIZE.
Realistically it should be 3000, however I might need to reduce it
depending on scaling and performance considerations. */
const int LOCAL_MAP_SIZE = 513;
/* Size of each local map in tiles. Size is LOCAL_MAP_SIZE * LOCAL_MAP_SIZE.
Should be (n^2+1).
Realistically it should be 2049, however I might need to reduce it
depending on scaling and performance considerations.
It will likely be set to low values during development.
*/
const int LOCAL_MAP_SIZE = 65;

int TIME_SCALE = 60; /* How many seconds of gametime pass per logic tick. */

Expand Down
60 changes: 27 additions & 33 deletions Menu_WorldGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,9 @@ class Menu_WorldGenerator: public GUI_Interface
if ( buttonLoadWorld.clicked==true)
{
buttonLoadWorld.unclick();
std::cout<<"Load world data.\n";
world.loadWorld("test");
//std::cout<<"Load world data.\n";
eventLoad();

}

}
Expand Down Expand Up @@ -807,15 +808,12 @@ class Menu_WorldGenerator: public GUI_Interface
}
else
{
//world.name=textEntryWorldName.input;
int worldSizeV = DataTools::toInt(worldSize.getCurrentOption());

if (worldSizeV<0 || worldSizeV>100000)
{
std::cout<<"Warning. Strange worldsize. Attempting to continue.\n";
}
//textEntryFullSeed.input;

// If a seed string has been entered, either use the actual number,
// or hash it to a number if it contains non-numeric characters.
// This allows for a word seed to have a numeric equivalent.
Expand Down Expand Up @@ -859,40 +857,36 @@ class Menu_WorldGenerator: public GUI_Interface

double landPercent = (double) nLandPercent.currentValue / 100;


//string s = "heyho";

//size_t hash = hasher(s);

//std::cout<<"The raw seed is: "<<textEntryFullSeed.input<<".\n";
//std::cout<<"The hashed seed is: "<<seed<<".\n";
world.generateWorld(textEntryWorldName.input,worldSizeV,worldSizeV,seed,fragmentation,islandMode,wrapX,wrapY,landPercent);

// std::cout<<"no crash\n";
// exit(0);

worldViewer.active=true;

//world.generateCivs(nCiv.currentValue);

// Just to start, we'll put all three races down immediately.
//world.addRace(1,"Dwarves");
//world.addRace(1,"Elves");
//world.addRace(1,"Humans");



//std::cout<<"Generating "<<nTribe.currentValue<<" tribes.\n";
world.generateTribes(nTribe.currentValue,nTribeDwarven.currentValue,nTribeElven.currentValue);

// Get name of regions.
//std::cout<<"Naming regions.\n";
world.nameRegions();


//std::cout<<"end generate.\n";
worldViewer.active=true;

}
}


// Load the specified world into the generator.
void eventLoad()
{
std::cout<<"Not yet implemented.\n";
return;

// First check to ensure the world has a name. Important because it's also the name of the savefile.
if ( textEntryWorldName.input == "" )
{
std::cout<<"Error: World needs a name.\n";
}
else if (DataTools::isAlphaNumeric(textEntryWorldName.input) == false)
{
std::cout<<"Error: World name must be alphanumeric.\n";
textEntryWorldName.input="";
}
else
{
world.loadWorld(textEntryWorldName.input);
}

}

Expand Down
61 changes: 55 additions & 6 deletions World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,29 @@ void World::idleTick()
handleTickBacklog();
}

bool World::loadWorld(std::string filePath)
bool World::loadWorld(std::string _name)
{
strSavePath = "savedata/"+_name;

std::cout<<"Attempting to load data from: "<<strSavePath<<".\n";
// For now, we will just delete any worlds with the same name.
//std::string systemCommmand = "exec rm -r "+strSavePath;
//system(systemCommmand.c_str());
//FileManager::DeleteDirectory(strSavePath,true);


std::cout<<"Loading world png.\n";

//FileManager::createDirectory(strSavePath);

if ( FileManager::directoryExists(strSavePath) == false )
{
std::cout<<"Error: This world doesn't appear to exist.\n";
return false ;
}

return false;
std::cout<<"Loading data from: "<<strSavePath<<".\n";

return true;

// int fileSize;
// unsigned char* data = FileManager::getFile(filePath,&fileSize);
Expand Down Expand Up @@ -1050,8 +1067,7 @@ void World::generateWorld(const std::string _worldName, const int x=127, const i
std::cout<<"world generated in: "<<worldGenTimer.fullSeconds<<" seconds.\n";
}

// This will likely need to be moved into a local map class.
// It's too unwieldy trying to manage it here.

void World::generateLocal(const int _localX, const int _localY)
{
if ( isSafe(_localX,_localY) == false )
Expand All @@ -1062,7 +1078,7 @@ void World::generateLocal(const int _localX, const int _localY)
{
if ( vWorldLocal(i)->globalX == _localX && vWorldLocal(i)->globalY == _localY )
{
std::cout<<"ALREADY GENERATED\n";
//std::cout<<"ALREADY GENERATED\n";
return;
}
}
Expand All @@ -1073,10 +1089,43 @@ void World::generateLocal(const int _localX, const int _localY)

vWorldLocal.push(worldLocal);

if ( vWorldLocal.size() > 3 )
{
// UNLOAD LOCAL MAP HERE
delete vWorldLocal(0);
vWorldLocal.eraseSlot(0);
}

return;

}

void World::unloadLocal(const int _localX, const int _localY)
{
if ( isSafe(_localX,_localY) == false )
{ return; }

// Only unload the local map if it is loaded.
for ( int i=0;i<vWorldLocal.size();++i)
{
if ( vWorldLocal(i)->globalX == _localX && vWorldLocal(i)->globalY == _localY )
{
//std::cout<<"ALREADY GENERATED\n";
return;
}
}

// auto worldLocal = new World_Local;
// worldLocal->init(_localX,_localY);
// worldLocal->generate();

// vWorldLocal.push(worldLocal);

return;

}


Vector <Tribe*>* World::getTribesOn(const int _x, const int _y)
{
Vector <Tribe*>* vTribeOn = new Vector <Tribe*>;
Expand Down
6 changes: 5 additions & 1 deletion World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,17 @@ class World: public LogicTickInterface, public IdleTickInterface
void logicTick();

/* FILE IO */
bool loadWorld(std::string /* filepath */);
bool loadWorld(std::string /* world name */);

/* WORLD GENERATION */

void generateWorld (const std::string /* _name */, const int /* x */, const int /* y */, int /* seed */, int /* fragmentation */, const bool /* islandMode */, const bool /* wrapX */, const bool /* wrapY */, const double /* landPercent */);
// Generate a local map so it can be viewed and interacted with.
void generateLocal(const int /* worldX */, const int /* worldY */);
//Unload a local map from RAM and into a save file.
void unloadLocal(const int /* worldX */, const int /* worldY */);


void buildArrays();
// Find all unique areas and give them names.
void nameRegions();
Expand Down
3 changes: 3 additions & 0 deletions World_Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ bool World_Local::generate()

}

return false;

std::cout<<"Checking map data in path: "<<world.strSavePath<<"\n";

// strSavePath = "savedata/"+name;
Expand All @@ -167,6 +169,7 @@ bool World_Local::generate()
// FileManager::DeleteDirectory(strSavePath,true);



std::string localMapPath = world.strSavePath + "/" + DataTools::toString(globalX) + "-" + DataTools::toString(globalY) + ".dat";

std::cout<<"Savefile for this map is: "<<localMapPath<<"\n";
Expand Down
1 change: 1 addition & 0 deletions World_Local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class World_Local: public LogicTickInterface, public IdleTickInterface
int globalX, globalY; /* The local world's position in the world. */

World_Local();
virtual ~World_Local() {}


// Local RNG
Expand Down

0 comments on commit 47a1800

Please sign in to comment.