This commit is contained in:
Lendemor 2017-01-19 15:47:04 +01:00
commit 1be61d665e
3 changed files with 52 additions and 37 deletions

View File

@ -16,6 +16,7 @@ set(RESOURCES_FILES ${LIB_HEAD_LIST})
#set compilation option
set(IS_LIBRARY True)
set(USE_RENDERER True)
set(USE_SERIALIZER True)
set(USE_INPUT True)
set(USE_BULLET True)
set(USE_SOL2 True)

View File

@ -7,7 +7,7 @@
ScriptNode::ScriptNode()
{
LUASETFUN(print);
printf("c is love\n");
// printf("c is love\n"); // nope
}
void ScriptNode::update(){

View File

@ -34,6 +34,9 @@
#include "scene/gui/backgroundnode.h"
#include "potator.h"
#include "serializationmanager.h"
#include "serializable.h"
#include <fstream>
#include "scene/gui/callback.h"
@ -131,37 +134,49 @@ void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
}
}
struct Config
struct Config : public Serializable
{
std::string mode; // fullscreen / windowed / borderless
std::string scene; // terrain / sponza / menu / none
bool vsync;
int width;
int height;
STRING(mode) // fullscreen / windowed / borderless
STRING(scene) // terrain / sponza / none
BOOL(vsync)
INT(width)
INT(height)
SERIALIZABLE(Config, CAST(mode), CAST(scene), CAST(vsync), CAST(width), CAST(height))
Config() :
mode("windowed"),
scene("none"),
vsync(false),
width(800),
height(600)
{}
void loadFromMap(std::unordered_map<std::string, std::string>* configMap)
Config()
{
std::unordered_map<std::string, std::string>& conf = *configMap;
if(conf.count("width"))
width = std::stoi(conf["width"]);
if(conf.count("height"))
height = std::stoi(conf["height"]);
if(conf.count("vsync"))
vsync = (conf["vsync"] == "true");
if(conf.count("mode"))
mode = conf["mode"];
if(conf.count("scene"))
scene = conf["scene"];
mode = "windowed";
scene = "none";
vsync = false;
width = 800;
height = 600;
}
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;
}
};
class Demo {
@ -256,11 +271,10 @@ public:
SceneTree* getScene(){return m_menu_scene;}
};
INIT_SERIALIZABLE(Config)
int main(){
Config config;
config.loadFromMap(Loader::loadConfigFile("../config.ini"));
Config* config = Config::load();
Engine engine;
Loader::setObjDirectory("../data/");
@ -269,8 +283,8 @@ int main(){
// this creates the opengl context
// 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.getWindow()->setVerticalSyncEnabled(config.vsync);
engine.createWindow("Sparrow Engine Demo", config->width, config->height, config->mode);
engine.getWindow()->setVerticalSyncEnabled(config->vsync);
// engine.toggleMouseVisibility();
@ -299,8 +313,8 @@ int main(){
input->updateKeyBindings();
//setup menu
Menu* menu = new Menu(&engine,&config);
Demo* demo = new Demo(&engine,&config);
Menu* menu = new Menu(&engine,config);
Demo* demo = new Demo(&engine,config);
menu->setLeftClickAction(DefaultKeysMap::LEFT_CLICK);
input->addContext(Context("menu",DefaultKeysMap::getMenuContext()));
input->setCurrentContext("menu");
@ -339,7 +353,8 @@ int main(){
scene->getRootObject()->addChild(sunLight);
*/
// scene
/* if(config.scene == "sponza")
/* if(config.scene == "sponza")
{
sun->initShadowMap(4096);
generateSponza(scene, engine.getPhysics());
@ -348,7 +363,7 @@ int main(){
player->setPosition(0.f, 2.f, 0.f);
sun->setShadowView(glm::vec3(30, 30, 50));
}
else if(config.scene == "terrain")
else if(config->scene == "terrain")
{
sun->initShadowMap(4096);
generateTerrain(scene, engine.getPhysics());
@ -362,7 +377,6 @@ int main(){
// preparing shaders and launching the engine
engine.getScene()->updateShaders();
// scene->updateShaders();
engine.start();
// pathfinding tests