-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPADrendMain.cpp
187 lines (157 loc) · 5.25 KB
/
PADrendMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* This file is part of the open source part of the
* Platform for Algorithm Development and Rendering (PADrend).
* Web page: http://www.padrend.de/
* Copyright (C) 2008-2013 Benjamin Eikel <[email protected]>
* Copyright (C) 2007-2015 Claudius Jähn <[email protected]>
* Copyright (C) 2009-2011 Ralf Petring <[email protected]>
*
* PADrend consists of an open source part and a proprietary part.
* The open source part of PADrend is subject to the terms of the Mozilla
* Public License, v. 2.0. You should have received a copy of the MPL along
* with this library; see the file LICENSE. If not, you can obtain one at
* http://mozilla.org/MPL/2.0/.
*/
#define OBJECTDEBUG
#include <E_Geometry/ELibGeometry.h>
#include <E_MinSG/ELibMinSG.h>
#include <E_GUI/ELibGUI.h>
#include <E_Util/ELibUtil.h>
#include <E_Rendering/ELibRendering.h>
#include <EScript/EScript.h>
// [Serial Port support]
// Win32 only
#ifdef LIB_E_SERIAL_PORT
#include <E_SerialPort/E_SerialPort.h>
#endif
// [ARToolkit]
#ifdef LIB_ARTOOLKIT
#include <E_ARToolKit/ELibARToolkit.h>
#endif // LIB_ARTOOLKIT
// [Sound]
#ifdef PADREND_HAVE_LIB_E_SOUND
#include <E_Sound/ELibSound.h>
#endif /* PADREND_HAVE_LIB_E_SOUND */
// [VideoLib]
// Based on ffmpeg
#ifdef LIB_VIDEOLIB
#include <E_VideoLib/E_VideoLib.h>
#endif // LIB_ARTOOLKIT
// ---
#if defined(__APPLE__)
#include <SDL.h>
#endif
#include <Util/Util.h>
#include <Util/LibRegistry.h>
#include <Util/IO/FileLocator.h>
#include <Util/IO/FileName.h>
#include <cstdlib>
#include <iostream>
#include <string>
#if defined(__linux__)
#include <signal.h>
static void signalHandler(int signalNumber) {
if(signalNumber == SIGUSR1) {
std::cout << "Received signal SIGUSR1. Shutting down." << std::endl;
exit(EXIT_SUCCESS);
}
}
#endif
using namespace EScript;
/**
* The main function initializes the needed libraries and starts interpreting the script
* <tt>./plugins/main.escript</tt>.
*
* @return Always @c EXIT_SUCCESS.
*/
int main(int argc, char *argv[]) {
#if defined(__linux__)
struct sigaction action;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
action.sa_handler = &signalHandler;
/*
* SIGINT is caught by SDL already.
* Use SIGUSR1 to gracefully shut down this application when the event loop
* is blocked by a running function and does not react to other signals.
*/
sigaction(SIGUSR1, &action, nullptr);
#endif
// -----------------------------------------------------------
// init Util
Util::init();
// -----------------------------------------------------------
// init EScript
Util::LibRegistry::registerLibVersionString("EScript",ES_VERSION_STRING);
EScript::init();
// init Libraries
EScript::initLibrary(E_Util::init);
EScript::initLibrary(E_Geometry::init);
EScript::initLibrary(E_Rendering::init);
EScript::initLibrary(E_MinSG::init);
EScript::initLibrary(E_GUI::init);
#ifdef LIB_E_SERIAL_PORT
EScript::initLibrary(E_SerialPort::init);
#endif // LIB_E_SERIAL_PORT
#ifdef PADREND_HAVE_LIB_E_SOUND
EScript::initLibrary(E_Sound::init);
#endif // /* PADREND_HAVE_LIB_E_SOUND */
#ifdef LIB_ARTOOLKIT
EScript::initLibrary(E_ARToolKit::init);
#endif // LIB_ARTOOLKIT
#ifdef LIB_VIDEOLIB
EScript::initLibrary(E_VideoLib::init);
#endif // LIB_VIDEOLIB
// Debug::clearObjects();
// -----------------------------------------------------------
ERef<Runtime> rt(new Runtime);
declareConstant(rt->getGlobals(), "args", Array::create(static_cast<std::size_t>(argc), argv));
std::string mainScript("./plugins/main.escript");
for(int i = 0; i < argc; ++i) {
const std::string arg(argv[i]);
if(arg.compare(0, 9, "--script=") == 0)
mainScript = arg.substr(9);
}
// pass some values to the script
declareConstant(rt->getGlobals(),"SIZE_OF_PTR", Number::create(sizeof(void*)));
#ifdef NDEBUG
declareConstant(rt->getGlobals(),"BUILD_TYPE", String::create("release"));
#else
declareConstant(rt->getGlobals(),"BUILD_TYPE", String::create("debug"));
#endif
Util::FileLocator locator;
locator.addSearchPath("./");
locator.addSearchPath("./../"); // PADrend is in ./build
locator.addSearchPath("./share/PADrend/");
#if defined(__linux__)
locator.addSearchPath("/usr/local/share/PADrend/");
locator.addSearchPath("/usr/share/PADrend/");
#elif defined(_WIN32)
locator.addSearchPath("./../../"); // PADrend is in, e.g., ./build/Release
locator.addSearchPath("C:/Program Files/PADrendComplete/share/PADrend/");
locator.addSearchPath("C:/Program Files (x86)/PADrendComplete/share/PADrend/");
locator.addSearchPath("C:/Program Files/PADrend/share/PADrend/");
locator.addSearchPath("C:/Program Files (x86)/PADrend/share/PADrend/");
#elif defined(__APPLE__)
// Where does apple store applications by default?
#endif
auto file = locator.locateFile(Util::FileName(mainScript));
if(!file.first) {
std::cout <<"ERROR: Could not locate 'main.escript'" << std::endl;
return EXIT_FAILURE;
}
// --- Load and execute script
std::pair<bool,ObjRef> result = EScript::loadAndExecute(*rt.get(), file.second.getPath());
// --- output result
if(result.second)
std::cout << "\n\n --- "<<"\nResult: " << result.second.toString()<< std::endl;
rt=nullptr;
// Debug::showObjects();
if(result.first){
std::cout <<" \nBYE."<< std::endl;
return EXIT_SUCCESS;
}else{
std::cout <<" \nFAILURE."<< std::endl;
return EXIT_FAILURE;
}
}