mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion/simulator] Add a runtime "--headless" option
We probably can ditch the static headless version
This commit is contained in:
@@ -39,6 +39,11 @@ namespace Ion {
|
||||
namespace Keyboard {
|
||||
|
||||
State scan() {
|
||||
State state = sKeyboardState;
|
||||
|
||||
if (Simulator::Window::isHeadless()) {
|
||||
return state;
|
||||
}
|
||||
// We need to tell SDL to get new state from the host OS
|
||||
SDL_PumpEvents();
|
||||
|
||||
@@ -48,7 +53,6 @@ State scan() {
|
||||
// Grab this opportunity to refresh the display if needed
|
||||
Simulator::Window::refresh();
|
||||
|
||||
State state = sKeyboardState;
|
||||
#if !EPSILON_SDL_SCREEN_ONLY
|
||||
// Register a key for the mouse, if any
|
||||
Key k = Simulator::Layout::getHighlightedKey();
|
||||
@@ -65,6 +69,7 @@ State scan() {
|
||||
state.setKey(pair.key());
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "haptics.h"
|
||||
#include "journal.h"
|
||||
#include "platform.h"
|
||||
#include "random.h"
|
||||
#include "telemetry.h"
|
||||
#include "window.h"
|
||||
#include <vector>
|
||||
@@ -85,19 +86,26 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
#endif
|
||||
|
||||
bool headless = args.popFlag("--headless");
|
||||
|
||||
using namespace Ion::Simulator;
|
||||
Journal::init();
|
||||
Random::init();
|
||||
if (!headless) {
|
||||
Journal::init();
|
||||
#if EPSILON_TELEMETRY
|
||||
Telemetry::init();
|
||||
Telemetry::init();
|
||||
#endif
|
||||
Window::init();
|
||||
Haptics::init();
|
||||
Window::init();
|
||||
Haptics::init();
|
||||
}
|
||||
ion_main(args.argc(), args.argv());
|
||||
Haptics::shutdown();
|
||||
Window::quit();
|
||||
if (!headless) {
|
||||
Haptics::shutdown();
|
||||
Window::quit();
|
||||
#if EPSILON_TELEMETRY
|
||||
Telemetry::shutdown();
|
||||
Telemetry::shutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "display.h"
|
||||
#include "layout.h"
|
||||
#include "platform.h"
|
||||
#include "random.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ion.h>
|
||||
@@ -19,14 +18,16 @@ static bool sNeedsRefresh = false;
|
||||
static SDL_Rect sScreenRect;
|
||||
#endif
|
||||
|
||||
bool isHeadless() {
|
||||
return sWindow == nullptr;
|
||||
}
|
||||
|
||||
void init() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_Log("Could not init video");
|
||||
return;
|
||||
}
|
||||
|
||||
Random::init();
|
||||
|
||||
sWindow = SDL_CreateWindow(
|
||||
"Epsilon",
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
@@ -67,6 +68,9 @@ void init() {
|
||||
}
|
||||
|
||||
void relayout() {
|
||||
if (isHeadless()) {
|
||||
return;
|
||||
}
|
||||
int windowWidth = 0;
|
||||
int windowHeight = 0;
|
||||
SDL_GetWindowSize(sWindow, &windowWidth, &windowHeight);
|
||||
@@ -89,7 +93,7 @@ void setNeedsRefresh() {
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
if (!sNeedsRefresh) {
|
||||
if (!sNeedsRefresh || isHeadless()) {
|
||||
return;
|
||||
}
|
||||
sNeedsRefresh = false;
|
||||
@@ -112,11 +116,15 @@ void refresh() {
|
||||
}
|
||||
|
||||
void quit() {
|
||||
if (isHeadless()) {
|
||||
return;
|
||||
}
|
||||
#if !EPSILON_SDL_SCREEN_ONLY
|
||||
Layout::quit();
|
||||
#endif
|
||||
Display::quit();
|
||||
SDL_DestroyWindow(sWindow);
|
||||
sWindow = nullptr;
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Window {
|
||||
void init();
|
||||
void quit();
|
||||
|
||||
bool isHeadless();
|
||||
|
||||
void setNeedsRefresh();
|
||||
void refresh();
|
||||
void relayout();
|
||||
|
||||
Reference in New Issue
Block a user