The-NodeBox-Generator/src/main.cpp

192 lines
4.8 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-07-06 08:34:00 -07:00
#include "util/filesys.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-06 11:04:44 -07:00
#ifndef _WIN32
#include <stdlib.h>
#include <unistd.h>
2015-06-28 05:55:55 -07:00
void findWorkingDirectory(bool &editor_is_installed)
{
std::cerr << "Looking for the working directory..." << std::endl;
if (FileExists("media/sky.jpg"))
return;
chdir("../");
if (FileExists("media/sky.jpg"))
return;
chdir("share/nodeboxeditor");
if (FileExists("media/sky.jpg")) {
std::cerr << "Is installed!";
editor_is_installed = true;
return;
}
chdir("/usr/share/nodeboxeditor");
if (FileExists("media/sky.jpg")) {
2015-06-28 05:55:55 -07:00
std::cerr << "Is installed!";
editor_is_installed = true;
return;
}
chdir("/usr/local/share/nodeboxeditor");
if (FileExists("media/sky.jpg")) {
std::cerr << "Is installed!";
editor_is_installed = true;
return;
}
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len != -1) {
buff[len] = '\0';
std::string path(buff);
path = pathWithoutFilename(path);
std::cerr << path << std::endl;
chdir(path.c_str());
if (FileExists("media/sky.jpg"))
return;
chdir("../");
if (FileExists("media/sky.jpg"))
return;
}
std::cerr << "Can't find the working directory!" << std::endl;
}
#endif // ifndef _WIN32
2014-07-06 11:04:44 -07:00
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;
2014-07-23 08:23:39 -07:00
2015-05-10 09:15:24 -07:00
#ifdef _DEBUG
std::cerr << "Debug mode enabled!" << std::endl;
#endif
2014-07-23 08:23:39 -07:00
2014-07-01 12:27:07 -07:00
// Find the working directory
2014-07-01 12:59:15 -07:00
bool editor_is_installed = false;
2014-07-06 10:09:54 -07:00
#ifndef _WIN32
2015-06-28 05:55:55 -07:00
findWorkingDirectory(editor_is_installed);
2014-07-06 10:09:54 -07:00
#endif
2014-07-01 12:27:07 -07:00
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;
}
conf->set("snapping", "true");
2015-07-26 06:51:23 -07:00
conf->set("default_snap_res", "16");
2014-04-25 11:46:35 -07:00
conf->set("limiting", "true");
conf->set("fractional_positions", "false");
2014-04-25 11:46:35 -07:00
conf->set("driver", "opengl");
conf->set("hide_sidebar", "false");
2014-07-01 12:27:07 -07:00
conf->set("save_directory", "");
2015-02-02 11:52:15 -08:00
conf->set("minetest_root", "");
2014-04-25 11:46:35 -07:00
conf->set("always_show_position_handle", "false");
2014-07-06 10:09:54 -07:00
#ifdef _WIN32
conf->set("vsync", "false");
conf->set("use_sleep", "true");
#else
2014-04-25 11:46:35 -07:00
conf->set("vsync", "true");
conf->set("use_sleep", "false");
2014-07-06 10:09:54 -07:00
#endif
2014-07-09 06:08:39 -07:00
conf->set("viewport_top_left", "pers");
conf->set("viewport_top_right", "top");
conf->set("viewport_bottom_left", "front");
conf->set("viewport_bottom_right", "right");
2014-07-10 11:55:40 -07:00
conf->set("lighting", "2");
2014-07-25 12:16:28 -07:00
conf->set("hide_other_nodes", "true");
conf->set("no_negative_node_y", "true");
2014-04-25 11:46:35 -07:00
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
2015-02-02 10:40:35 -08:00
if (!conf->load(std::string(getSaveLoadDirectory("", true)) + ".config/nodeboxeditor.conf"))
conf->load("editor.conf");
2013-12-15 09:40:57 -08:00
2014-07-01 12:59:15 -07:00
// Set up irrlicht device
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"));
2015-03-08 04:44:09 -07:00
#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
2014-04-25 11:46:35 -07:00
if (confDriver == "directx8") {
driv = EDT_DIRECT3D8;
2015-03-08 04:44:09 -07:00
} else
#endif
#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
if (confDriver == "directx9") {
2013-12-15 09:40:57 -08:00
driv = EDT_DIRECT3D9;
2015-03-08 04:44:09 -07:00
} else
#endif
if (confDriver == "software") {
2014-04-25 11:46:35 -07:00
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");
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.
}
2015-02-02 10:40:35 -08:00
2014-07-25 10:16:41 -07:00
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
std::cerr << "Warning! Your Irrlicht version is outdated, so some NBE features will not be available." << std::endl;
2014-07-25 10:16:41 -07:00
#endif
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();
editor->run(device, conf, editor_is_installed);
2013-12-15 09:40:57 -08:00
2014-07-01 12:59:15 -07:00
if (!editor_is_installed)
conf->save("editor.conf");
2014-07-01 12:27:07 -07:00
else
2015-02-02 10:40:35 -08:00
if (!conf->save(std::string(getSaveLoadDirectory("", true)) + ".config/nodeboxeditor.conf"))
conf->save("editor.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-07-06 10:09:54 -07:00
#ifndef _WIN32
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();
};
2014-07-06 10:09:54 -07:00
#endif