The-NodeBox-Generator/src/main.cpp

132 lines
3.1 KiB
C++
Raw Normal View History

2014-04-25 11:46:35 -07:00
#include <stdlib.h>
#include <iostream>
2012-09-02 14:36:01 -07:00
#include <irrlicht.h>
2014-04-25 11:46:35 -07:00
#include "util/string.hpp"
2014-05-20 15:15:40 -07:00
#include "common.hpp"
#include "Editor.hpp"
2012-09-02 14:36:01 -07:00
2013-07-23 08:19:47 -07:00
#ifdef _MSC_VER
2012-09-02 14:36:01 -07:00
#pragma comment(lib, "Irrlicht.lib")
2013-07-23 09:06:33 -07:00
#ifndef _DEBUG
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
2013-05-06 06:38:59 -07:00
#endif
2013-05-06 06:33:35 -07:00
2014-07-01 12:27:07 -07:00
#ifdef _WIN32
#include <windows.h>
bool PathExists(const char* path)
{
return (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
}
#else
#include <sys/stat.h>
bool PathExists(const char* path)
{
struct stat st;
return (stat(path, &st) == 0);
}
#endif
2014-04-25 11:46:35 -07:00
int main(int argc, char *argv[]) {
std::cerr <<
2013-12-15 09:40:57 -08:00
" _ _ _ ____ _____ _ _ _ \n"
"| \\ | | ___ __| | ___ | __ ) _____ __ | ____|__| (_) |_ ___ _ __ \n"
"| \\| |/ _ \\ / _` |/ _ \\ | _ \\ / _ \\ \\/ / | _| / _` | | __/ _ \\| '__|\n"
"| |\\ | (_) | (_| | __/ | |_) | (_) > < | |__| (_| | | || (_) | | \n"
2014-04-25 11:46:35 -07:00
"|_| \\_|\\___/ \\__,_|\\___| |____/ \\___/_/\\_\\ |_____\\__,_|_|\\__\\___/|_| \n\n"
<< std::endl;
2012-09-02 14:36:01 -07:00
2014-07-01 12:27:07 -07:00
// Find the working directory
std::cerr << "Looking for the working directory..." << std::endl;
if (!PathExists("media/sky.jpg")) {
chdir("../");
if (!PathExists("media/sky.jpg")) {
chdir("share/nodeboxeditor");
if (!PathExists("media/sky.jpg")) {
std::cerr << "Can't find the working directory!" << std::endl;
} else {
std::cerr << "Setting" << std::endl;
editor_is_installed = true;
}
}
}
2013-12-15 09:40:57 -08:00
// Settings
Configuration* conf = new Configuration();
2014-04-25 11:46:35 -07:00
if (conf == NULL) {
return EXIT_FAILURE;
}
2013-12-15 09:40:57 -08:00
// Init Settings
2014-04-25 11:46:35 -07:00
conf->set("snapping", "true");
conf->set("limiting", "true");
conf->set("driver", "opengl");
conf->set("hide_sidebar", "false");
2014-07-01 12:27:07 -07:00
conf->set("save_directory", "");
2014-04-25 11:46:35 -07:00
conf->set("always_show_position_handle", "false");
conf->set("vsync", "true");
conf->set("use_sleep", "false");
conf->set("fullscreen", "false");
conf->set("width", "896");
conf->set("height", "520");
2014-07-01 12:29:22 -07:00
if (!editor_is_installed)
2014-07-01 12:27:07 -07:00
conf->load("editor.conf");
else
conf->load("~/.config/nodeboxeditor.conf");
2013-12-15 09:40:57 -08:00
E_DRIVER_TYPE driv = irr::video::EDT_OPENGL;
2014-04-25 11:46:35 -07:00
const std::string confDriver = str_to_lower(conf->get("driver"));
if (confDriver == "directx8") {
driv = EDT_DIRECT3D8;
} else if (confDriver == "directx9") {
2013-12-15 09:40:57 -08:00
driv = EDT_DIRECT3D9;
2014-04-25 11:46:35 -07:00
} else if (confDriver == "software") {
driv = EDT_SOFTWARE;
2013-12-15 09:40:57 -08:00
}
2014-04-25 11:46:35 -07:00
// Start Irrlicht
int w = conf->getInt("width");
int h = conf->getInt("height");
2013-12-15 09:40:57 -08:00
2014-04-25 11:46:35 -07:00
if (w < 1) w = 896;
if (h < 1) h = 520;
2013-12-15 09:40:57 -08:00
2014-04-29 13:48:27 -07:00
if (!conf->getBool("vsync")) {
2014-04-25 11:46:35 -07:00
std::cerr << "[WARNING] You have disabled vsync. Expect major CPU usage!" << std::endl;
}
irr::IrrlichtDevice* device = irr::createDevice(
2013-12-15 09:40:57 -08:00
driv,
irr::core::dimension2d<irr::u32>(w,h),
16U,
2014-04-25 11:46:35 -07:00
conf->getBool("fullscreen"),
2013-12-15 09:40:57 -08:00
false,
2014-04-25 11:46:35 -07:00
conf->getBool("vsync")
2013-12-15 09:40:57 -08:00
);
2014-04-25 11:46:35 -07:00
if (device == NULL) {
return EXIT_FAILURE; // could not create selected driver.
}
2012-09-02 14:36:01 -07:00
2013-12-15 09:40:57 -08:00
// Editor
2013-07-23 08:19:47 -07:00
Editor* editor = new Editor();
2014-04-25 11:46:35 -07:00
editor->run(device, conf);
2013-12-15 09:40:57 -08:00
2014-07-01 12:27:07 -07:00
if (editor_is_installed)
conf->load("editor.conf");
else
conf->load("~/.config/nodeboxeditor.conf");
2012-09-23 10:05:49 -07:00
2014-04-25 11:46:35 -07:00
return 1;
2013-12-15 09:40:57 -08:00
}
2014-02-14 12:21:55 -08:00
2014-06-30 04:09:53 -07:00
// Fix for Inconsistency detected by ld.so
#include <pthread.h>
void junk() {
int i;
i = pthread_getconcurrency();
};