config file now uses the SparrowSerializer
This commit is contained in:
parent
d71250fab0
commit
7400ace40c
@ -14,6 +14,7 @@ file(GLOB EXEC_SRC_LIST src/test/*.cpp)
|
|||||||
#set compilation option
|
#set compilation option
|
||||||
set(IS_LIBRARY True)
|
set(IS_LIBRARY True)
|
||||||
set(USE_RENDERER True)
|
set(USE_RENDERER True)
|
||||||
|
set(USE_SERIALIZER True)
|
||||||
set(USE_INPUT True)
|
set(USE_INPUT True)
|
||||||
set(USE_BULLET True)
|
set(USE_BULLET True)
|
||||||
set(USE_SOL2 True)
|
set(USE_SOL2 True)
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# this is the demo's config file
|
|
||||||
width=800
|
|
||||||
height=600
|
|
||||||
mode=windowed
|
|
||||||
scene=none
|
|
||||||
vsync=false
|
|
@ -7,7 +7,7 @@
|
|||||||
ScriptNode::ScriptNode()
|
ScriptNode::ScriptNode()
|
||||||
{
|
{
|
||||||
LUASETFUN(print);
|
LUASETFUN(print);
|
||||||
printf("c is love\n");
|
// printf("c is love\n"); // nope
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptNode::update(){
|
void ScriptNode::update(){
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
#include "potator.h"
|
#include "potator.h"
|
||||||
|
#include "serializationmanager.h"
|
||||||
|
#include "serializable.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
class TestGen : public TerrainGenerator
|
class TestGen : public TerrainGenerator
|
||||||
{
|
{
|
||||||
@ -124,43 +127,55 @@ void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Config
|
struct Config : public Serializable
|
||||||
{
|
{
|
||||||
std::string mode; // fullscreen / windowed / borderless
|
STRING(mode) // fullscreen / windowed / borderless
|
||||||
std::string scene; // terrain / sponza / none
|
STRING(scene) // terrain / sponza / none
|
||||||
bool vsync;
|
BOOL(vsync)
|
||||||
int width;
|
INT(width)
|
||||||
int height;
|
INT(height)
|
||||||
|
SERIALIZABLE(Config, CAST(mode), CAST(scene), CAST(vsync), CAST(width), CAST(height))
|
||||||
|
|
||||||
Config() :
|
Config()
|
||||||
mode("windowed"),
|
|
||||||
scene("none"),
|
|
||||||
vsync(false),
|
|
||||||
width(800),
|
|
||||||
height(600)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void loadFromMap(std::unordered_map<std::string, std::string>* configMap)
|
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, std::string>& conf = *configMap;
|
mode = "windowed";
|
||||||
if(conf.count("width"))
|
scene = "none";
|
||||||
width = std::stoi(conf["width"]);
|
vsync = false;
|
||||||
if(conf.count("height"))
|
width = 800;
|
||||||
height = std::stoi(conf["height"]);
|
height = 600;
|
||||||
if(conf.count("vsync"))
|
|
||||||
vsync = (conf["vsync"] == "true");
|
|
||||||
if(conf.count("mode"))
|
|
||||||
mode = conf["mode"];
|
|
||||||
if(conf.count("scene"))
|
|
||||||
scene = conf["scene"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Config* load()
|
||||||
|
{
|
||||||
|
std::fstream configFile;
|
||||||
|
configFile.open("../config.ini", std::ios_base::in);
|
||||||
|
Config *conf;
|
||||||
|
if(configFile.is_open())
|
||||||
|
{
|
||||||
|
ObjectLoader loader;
|
||||||
|
loader.loadAscii(configFile);
|
||||||
|
configFile.close();
|
||||||
|
const std::vector<Config*>& confVec = loader.getObjects<Config>();
|
||||||
|
if(confVec.size() != 0)
|
||||||
|
conf = confVec[0];
|
||||||
|
else
|
||||||
|
conf = new Config();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
conf = new Config();
|
||||||
|
ObjectSaver saver;
|
||||||
|
saver.addObject(conf);
|
||||||
|
configFile.open("../config.ini", std::ios_base::out);
|
||||||
|
saver.saveAscii(configFile);
|
||||||
|
configFile.close();
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(){
|
INIT_SERIALIZABLE(Config)
|
||||||
Config config;
|
|
||||||
config.loadFromMap(Loader::loadConfigFile("../config.ini"));
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Config* config = Config::load();
|
||||||
Engine engine;
|
Engine engine;
|
||||||
|
|
||||||
Loader::setObjDirectory("../data/");
|
Loader::setObjDirectory("../data/");
|
||||||
@ -169,8 +184,8 @@ int main(){
|
|||||||
|
|
||||||
// this creates the opengl context
|
// this creates the opengl context
|
||||||
// the opengl context must exist before any opengl class is used (texture, pipeline, etc..)
|
// the opengl context must exist before any opengl class is used (texture, pipeline, etc..)
|
||||||
engine.createWindow("Sparrow Engine Demo", config.width, config.height, config.mode);
|
engine.createWindow("Sparrow Engine Demo", config->width, config->height, config->mode);
|
||||||
engine.getWindow()->setVerticalSyncEnabled(config.vsync);
|
engine.getWindow()->setVerticalSyncEnabled(config->vsync);
|
||||||
|
|
||||||
engine.toggleMouseVisibility();
|
engine.toggleMouseVisibility();
|
||||||
|
|
||||||
@ -226,7 +241,7 @@ int main(){
|
|||||||
scene->getRootObject()->addChild(sunLight);
|
scene->getRootObject()->addChild(sunLight);
|
||||||
|
|
||||||
// scene
|
// scene
|
||||||
if(config.scene == "sponza")
|
if(config->scene == "sponza")
|
||||||
{
|
{
|
||||||
sun->initShadowMap(4096);
|
sun->initShadowMap(4096);
|
||||||
generateSponza(scene, engine.getPhysics());
|
generateSponza(scene, engine.getPhysics());
|
||||||
@ -235,7 +250,7 @@ int main(){
|
|||||||
player->setPosition(0.f, 2.f, 0.f);
|
player->setPosition(0.f, 2.f, 0.f);
|
||||||
sun->setShadowView(glm::vec3(30, 30, 50));
|
sun->setShadowView(glm::vec3(30, 30, 50));
|
||||||
}
|
}
|
||||||
else if(config.scene == "terrain")
|
else if(config->scene == "terrain")
|
||||||
{
|
{
|
||||||
sun->initShadowMap(4096);
|
sun->initShadowMap(4096);
|
||||||
generateTerrain(scene, engine.getPhysics());
|
generateTerrain(scene, engine.getPhysics());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user