mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[ion/simulator] Factorize the main function
This commit is contained in:
@@ -21,6 +21,7 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
keyboard_dummy.cpp:+headless \
|
||||
keyboard_sdl.cpp:-headless \
|
||||
layout.cpp:-headless \
|
||||
main.cpp \
|
||||
power.cpp \
|
||||
random.cpp \
|
||||
timing.cpp \
|
||||
|
||||
30
ion/src/simulator/shared/main.cpp
Normal file
30
ion/src/simulator/shared/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "haptics.h"
|
||||
#include "platform.h"
|
||||
#include "telemetry.h"
|
||||
#include "window.h"
|
||||
#include <vector>
|
||||
#include <ion.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
std::vector<const char *> arguments(argv, argv + argc);
|
||||
|
||||
char * language = IonSimulatorGetLanguageCode();
|
||||
if (language != nullptr) {
|
||||
arguments.push_back("--language");
|
||||
arguments.push_back(language);
|
||||
}
|
||||
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::init();
|
||||
#endif
|
||||
Ion::Simulator::Window::init();
|
||||
Ion::Simulator::Haptics::init();
|
||||
ion_main(arguments.size(), &arguments[0]);
|
||||
Ion::Simulator::Haptics::shutdown();
|
||||
Ion::Simulator::Window::quit();
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::shutdown();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,18 +1,14 @@
|
||||
#include "window.h"
|
||||
#include "display.h"
|
||||
#include "platform.h"
|
||||
#include "framebuffer.h"
|
||||
#include "events.h"
|
||||
|
||||
#include <ion.h>
|
||||
#include <ion/events.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef __WIN32__
|
||||
#include <signal.h>
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
constexpr int kHeapSize = 131072;
|
||||
#ifdef NDEBUG
|
||||
/* TODO : Reduce stack memory cost in prime factorization to allow running
|
||||
* tests with the actual stack size */
|
||||
@@ -21,22 +17,21 @@ constexpr int kStackSize = 32768*10;
|
||||
constexpr int kStackSize = 32768*10; // In DEBUG mode, we increase the stack to be able to pass the tests
|
||||
#endif
|
||||
|
||||
char heap[kHeapSize];
|
||||
extern "C" {
|
||||
char * _heap_start = (char *)heap;
|
||||
char * _heap_end = _heap_start+kHeapSize;
|
||||
}
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Window {
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
void init() {
|
||||
Ion::Simulator::Framebuffer::setActive(false);
|
||||
// Parse command-line arguments
|
||||
// This feature is lost for now
|
||||
/* Parse command-line arguments
|
||||
for (int i=1; i<argc; i++) {
|
||||
if (strcmp(argv[i], "--logAfter") == 0 && argc > i+1) {
|
||||
Ion::Simulator::Framebuffer::setActive(true);
|
||||
Ion::Simulator::Events::logAfter(atoi(argv[i+1]));
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
#ifndef __WIN32__
|
||||
// Handle signals
|
||||
signal(SIGABRT, Ion::Simulator::Events::dumpEventCount);
|
||||
@@ -45,16 +40,9 @@ int main(int argc, char * argv[]) {
|
||||
struct rlimit stackLimits = {kStackSize, kStackSize};
|
||||
setrlimit(RLIMIT_STACK, &stackLimits);
|
||||
#endif
|
||||
|
||||
ion_main(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Window {
|
||||
|
||||
void init() {
|
||||
void quit() {
|
||||
}
|
||||
|
||||
void setNeedsRefresh() {
|
||||
|
||||
@@ -1,44 +1,12 @@
|
||||
#include "window.h"
|
||||
#include "display.h"
|
||||
#include "haptics.h"
|
||||
#include "layout.h"
|
||||
#include "platform.h"
|
||||
#include "telemetry.h"
|
||||
#include "random.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ion.h>
|
||||
#include <ion/events.h>
|
||||
#include <SDL.h>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
std::vector<const char *> arguments(argv, argv + argc);
|
||||
|
||||
char * language = IonSimulatorGetLanguageCode();
|
||||
if (language != nullptr) {
|
||||
arguments.push_back("--language");
|
||||
arguments.push_back(language);
|
||||
}
|
||||
|
||||
// Init
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::init();
|
||||
#endif
|
||||
Ion::Simulator::Window::init();
|
||||
Ion::Simulator::Haptics::init();
|
||||
|
||||
ion_main(arguments.size(), &arguments[0]);
|
||||
|
||||
// Shutdown
|
||||
Ion::Simulator::Haptics::shutdown();
|
||||
Ion::Simulator::Window::quit();
|
||||
#if EPSILON_TELEMETRY
|
||||
Ion::Simulator::Telemetry::shutdown();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
|
||||
Reference in New Issue
Block a user