@@ -56,12 +56,17 @@ void Engine::Run() {
5656}
5757
5858bool Engine::Start (std::string title) {
59- SDL_Log (" Initializing Window" );
60- window = new Window (title);
61- if (window != nullptr )
62- SDL_Log (" Window Initialized" );
63- else
64- exit (0 );
59+ if (!settings.headless ) {
60+ SDL_Log (" Initializing Window" );
61+ window = new Window (title);
62+ if (window != nullptr )
63+ SDL_Log (" Window Initialized" );
64+ else
65+ exit (0 );
66+ } else {
67+ SDL_Log (" Starting in headless mode - no window created" );
68+ window = nullptr ;
69+ }
6570
6671 lastFrameTime = std::chrono::high_resolution_clock::now ();
6772 SDL_Delay (1000 / targetFPS);
@@ -71,15 +76,18 @@ bool Engine::Start(std::string title) {
7176}
7277
7378void Engine::Tick () {
74- // Start the Dear ImGui frame
75- ImGui_ImplSDLRenderer2_NewFrame ();
76- ImGui_ImplSDL2_NewFrame ();
77- ImGui::NewFrame ();
78- window->Update ();
79-
80- SDL_SetRenderDrawColor (window->sdlRenderer , (Uint8)(clear_color.x * 255 ), (Uint8)(clear_color.y * 255 ), (Uint8)(clear_color.z * 255 ),
81- (Uint8)(clear_color.w * 255 ));
82- SDL_RenderClear (window->sdlRenderer );
79+ // Only initialize ImGui and rendering if not in headless mode
80+ if (!settings.headless ) {
81+ // Start the Dear ImGui frame
82+ ImGui_ImplSDLRenderer2_NewFrame ();
83+ ImGui_ImplSDL2_NewFrame ();
84+ ImGui::NewFrame ();
85+ window->Update ();
86+
87+ SDL_SetRenderDrawColor (window->sdlRenderer , (Uint8)(clear_color.x * 255 ), (Uint8)(clear_color.y * 255 ), (Uint8)(clear_color.z * 255 ),
88+ (Uint8)(clear_color.w * 255 ));
89+ SDL_RenderClear (window->sdlRenderer );
90+ }
8391
8492 // inputs processing
8593 processInput ();
@@ -94,17 +102,23 @@ void Engine::Tick() {
94102 // update
95103 for (auto go : gameObjects) go->Update (deltaTime);
96104
97- // iterate over all game objects ui
98- auto gos = gameObjects; // clone to prevent out of bounds access
99- for (auto go : gameObjects) go->OnGui (window->imGuiContext ); // todo: find a better way to pass imgui context
105+ // Only process GUI and rendering if not in headless mode
106+ if (!settings.headless ) {
107+ // iterate over all game objects ui
108+ auto gos = gameObjects; // clone to prevent out of bounds access
109+ for (auto go : gameObjects) go->OnGui (window->imGuiContext ); // todo: find a better way to pass imgui context
100110
101- for (auto go : scriptableObjects) go->OnGui (window->imGuiContext );
111+ for (auto go : scriptableObjects) go->OnGui (window->imGuiContext );
102112
103- // Rendering
104- ImGui::Render ();
113+ // Rendering
114+ ImGui::Render ();
105115
106- // Draw
107- for (auto go : gameObjects) go->OnDraw (window->sdlRenderer );
116+ // Draw
117+ for (auto go : gameObjects) go->OnDraw (window->sdlRenderer );
118+
119+ ImGui_ImplSDLRenderer2_RenderDrawData (ImGui::GetDrawData (), window->sdlRenderer );
120+ SDL_RenderPresent (window->sdlRenderer );
121+ }
108122
109123 // destroy objects marked to death
110124 if (!toDestroy.empty ()) {
@@ -114,9 +128,6 @@ void Engine::Tick() {
114128 }
115129 toDestroy.clear ();
116130 }
117-
118- ImGui_ImplSDLRenderer2_RenderDrawData (ImGui::GetDrawData (), window->sdlRenderer );
119- SDL_RenderPresent (window->sdlRenderer );
120131}
121132
122133void Engine::Exit () {
@@ -137,6 +148,11 @@ void Engine::processInput() {
137148 // clean the state
138149 arrowInput = Vector2f ();
139150
151+ // Skip input processing in headless mode
152+ if (settings.headless ) {
153+ return ;
154+ }
155+
140156 // process events
141157 SDL_Event event;
142158 while (SDL_PollEvent (&event)) {
0 commit comments