forked from dracc/NevolutionX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
153 lines (134 loc) · 3.91 KB
/
main.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
#include <vector>
#include "config.hpp"
#include "menu.hpp"
#include "langMenu.hpp"
#include "timeMenu.hpp"
#include "findXBE.h"
#include "font.h"
#include "outputLine.h"
#include "renderer.h"
#include "subsystems.h"
#include "ftpServer.h"
#include <memory>
#include <type_traits>
#include <thread>
#include <SDL.h>
#ifdef NXDK
#include <hal/xbox.h>
#include <hal/video.h>
#include <windows.h>
#endif
#ifdef NXDK
#define SEPARATOR "\\"
#define HOME "A:" SEPARATOR
#else
#define SEPARATOR "/"
#define HOME "." SEPARATOR
#endif
int main(void) {
#ifdef NXDK
mountHomeDir('A');
#endif
Config config;
std::map<int, SDL_GameController*> controllers;
int init = init_systems();
ftpServer *s = nullptr;
std::thread thrF;
if (init <= 1) {
bool running = true;
// Open our GameController
for (int i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
controllers[i] = SDL_GameControllerOpen(i);
if (!controllers[i]) {
outputLine("Could not open gamecontroller %i: %s\n", i, SDL_GetError());
SDL_Delay(2000);
}
}
}
// Set a hint that we want to use our gamecontroller always
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
if (init == 0 && config.settings.ftp.getEnabled()) {
s = new ftpServer(&config.settings.ftp);
s->init();
thrF = std::thread(thread_runner, s);
}
// Create render system
Renderer r;
r.init(HOME);
// Load font
// FIXME: Font path should be read from theme
Font f(r, HOME "vegur.ttf");
Menu menu(config, r);
std::shared_ptr<MenuNode> lang = nullptr;
std::shared_ptr<MenuNode> timeZone = nullptr;
r.drawBackground();
r.flip();
SDL_Event event;
#ifdef NXDK
ULONG ValueIndex = 0;
ULONG Type = 0;
uint32_t Value = 0;
char Value2[5] = {0};
ULONG ValueLength = 4;
ULONG ResultLength = 0;
ValueIndex = 0x1;
ExQueryNonVolatileSetting(ValueIndex, &Type, &Value2,
ValueLength, &ResultLength);
if (ValueLength == ResultLength && Value2[0] == 0) {
#endif
timeZone = std::make_shared<TimeMenu>(menu.getCurrentMenu(), "Timezone select");
menu.setCurrentMenu(timeZone.get());
#ifdef NXDK
}
ValueIndex = 0x7;
ExQueryNonVolatileSetting(ValueIndex, &Type, &Value,
ValueLength, &ResultLength);
if (ValueLength == ResultLength && Value == 0) {
#endif
lang = std::make_shared<LangMenu>(menu.getCurrentMenu(), "Language select");
menu.setCurrentMenu(lang.get());
#ifdef NXDK
}
#endif
while (running) {
r.setDrawColor(0, 89, 0);
r.clear();
r.drawBackground();
menu.render(f);
r.flip();
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
break;
} else if (event.type == SDL_CONTROLLERDEVICEADDED) {
controllers[event.cdevice.which] = SDL_GameControllerOpen(event.cdevice.which);
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
SDL_GameControllerClose(controllers[event.cdevice.which]);
controllers.erase(event.cdevice.which);
} else if (event.type == SDL_CONTROLLERBUTTONDOWN) {
if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP) {
menu.up();
} else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) {
menu.down();
} else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
menu.execute();
} else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_B ||
event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) {
menu.back();
}
}
}
#ifdef NXDK
// Let's not hog CPU for nothing.
SwitchToThread();
#endif
}
}
for (auto c: controllers) {
SDL_GameControllerClose(c.second);
}
delete s;
shutdown_systems(init);
return init;
}