Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * Olympe Tilemap Editor - Entry Point
3 *
4 * SDL3-based standalone tilemap editor for Olympe Engine.
5 */
6
7#define SDL_MAIN_USE_CALLBACKS
8#include <SDL3/SDL.h>
9#include <SDL3/SDL_main.h>
10#include "../../third_party/imgui/imgui.h"
11#include "../../third_party/imgui/backends/imgui_impl_sdl3.h"
12#include "../../third_party/imgui/backends/imgui_impl_sdlrenderer3.h"
13#include "../include/TilemapEditorApp.h"
14#include <iostream>
15
16// This provides the platform-specific entry point implementation for SDL3
17#include <SDL3/SDL_main_impl.h>
18
19static SDL_Window* g_Window = nullptr;
20static SDL_Renderer* g_Renderer = nullptr;
23
25{
26 std::cout << "=============================================" << std::endl;
27 std::cout << " Olympe Tilemap Editor" << std::endl;
28 std::cout << "=============================================" << std::endl;
29 std::cout << "Version: 1.0.0 (Phase 1 - Foundation)" << std::endl;
30 std::cout << "Mode: Standalone Tilemap/Level Editor" << std::endl;
31 std::cout << "=============================================" << std::endl;
32
33 // Initialize SDL3
35 {
36 std::cerr << "[TilemapEditor] SDL3 Init failed: " << SDL_GetError() << std::endl;
37 return SDL_APP_FAILURE;
38 }
39
40 // Create window
42 "Olympe Tilemap Editor - Phase 1",
43 1920,
44 1080,
46 );
47
48 if (!g_Window)
49 {
50 std::cerr << "[TilemapEditor] Window creation failed: " << SDL_GetError() << std::endl;
51 SDL_Quit();
52 return SDL_APP_FAILURE;
53 }
54
55 // Create renderer
57 if (!g_Renderer)
58 {
59 std::cerr << "[TilemapEditor] Renderer creation failed: " << SDL_GetError() << std::endl;
61 SDL_Quit();
62 return SDL_APP_FAILURE;
63 }
64
65 // Initialize ImGui
67 ImGui::CreateContext();
68 ImGuiIO& io = ImGui::GetIO();
70 // Note: Docking not available in current ImGui version
71
72 // Setup ImGui style
73 ImGui::StyleColorsDark();
74
75 ImGuiStyle& style = ImGui::GetStyle();
76 style.Colors[ImGuiCol_WindowBg] = ImVec4(0.12f, 0.12f, 0.14f, 1.00f);
77 style.Colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.18f, 1.00f);
78 style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.20f, 0.40f, 0.60f, 1.00f);
79 style.Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.40f, 0.60f, 0.80f);
80 style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.45f, 0.65f, 1.00f);
81 style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.30f, 0.50f, 0.70f, 1.00f);
82 style.Colors[ImGuiCol_Button] = ImVec4(0.20f, 0.40f, 0.60f, 0.80f);
83 style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.25f, 0.45f, 0.65f, 1.00f);
84 style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.30f, 0.50f, 0.70f, 1.00f);
85
86 // Initialize ImGui backends
89
90 // Create and initialize editor application
92 if (!g_EditorApp->Initialize())
93 {
94 std::cerr << "[TilemapEditor] Editor app initialization failed" << std::endl;
95 delete g_EditorApp;
96 g_EditorApp = nullptr;
99 ImGui::DestroyContext();
102 SDL_Quit();
103 return SDL_APP_FAILURE;
104 }
105
106 // Initialize frame timing
108
109 std::cout << "[TilemapEditor] Initialization complete" << std::endl;
110 std::cout << "[TilemapEditor] Press Ctrl+Q to quit" << std::endl;
111
112 return SDL_APP_CONTINUE;
113}
114
116{
117 if (!event)
118 return SDL_APP_CONTINUE;
119
121
122 ImGuiIO& io = ImGui::GetIO();
123
124 // Handle quit events
126 {
128 {
129 std::cout << "[TilemapEditor] Warning: Unsaved changes detected" << std::endl;
130 // TODO: Show confirmation dialog
131 }
132 return SDL_APP_SUCCESS;
133 }
134
135 // Handle keyboard shortcuts
136 if (event->type == SDL_EVENT_KEY_DOWN && !io.WantCaptureKeyboard)
137 {
138 // Ctrl+Q: Quit
139 if ((event->key.mod & SDL_KMOD_CTRL) && event->key.key == SDLK_Q)
140 {
141 std::cout << "[TilemapEditor] User requested quit (Ctrl+Q)" << std::endl;
143 {
144 std::cout << "[TilemapEditor] Warning: Unsaved changes detected" << std::endl;
145 }
146 return SDL_APP_SUCCESS;
147 }
148
149 // Ctrl+N: New Level
150 if ((event->key.mod & SDL_KMOD_CTRL) && event->key.key == SDLK_N)
151 {
152 if (g_EditorApp)
154 }
155
156 // Ctrl+O: Open Level
157 if ((event->key.mod & SDL_KMOD_CTRL) && event->key.key == SDLK_O)
158 {
159 if (g_EditorApp)
161 }
162
163 // Ctrl+S: Save Level
164 if ((event->key.mod & SDL_KMOD_CTRL) && event->key.key == SDLK_S)
165 {
166 if (g_EditorApp)
167 {
168 if (event->key.mod & SDL_KMOD_SHIFT)
170 else
172 }
173 }
174
175 // ESC: Deselect / Cancel
176 if (event->key.key == SDLK_ESCAPE)
177 {
178 // TODO: Clear selection
179 }
180 }
181
182 return SDL_APP_CONTINUE;
183}
184
186{
187 // Calculate delta time
189 float deltaTime = (currentTime - g_LastFrameTime) / 1000.0f;
191
192 // Clamp delta time to prevent large jumps (e.g., when debugging)
193 if (deltaTime > 0.1f)
194 {
195 deltaTime = 0.016f; // Fall back to ~60 FPS if delta is too large
196 }
197
198 // Start ImGui frame
201 ImGui::NewFrame();
202
203 // Render editor UI
204 if (g_EditorApp)
205 {
207 }
208
209 // Render ImGui
210 ImGui::Render();
211
212 // Clear and render
213 SDL_SetRenderDrawColor(g_Renderer, 30, 30, 34, 255);
215
217
219
220 return SDL_APP_CONTINUE;
221}
222
224{
225 std::cout << "[TilemapEditor] Shutting down..." << std::endl;
226
227 // Cleanup editor app
228 if (g_EditorApp)
229 {
231 delete g_EditorApp;
232 g_EditorApp = nullptr;
233 }
234
235 // Cleanup ImGui
238 ImGui::DestroyContext();
239
240 // Cleanup SDL
241 if (g_Renderer)
242 {
244 g_Renderer = nullptr;
245 }
246
247 if (g_Window)
248 {
250 g_Window = nullptr;
251 }
252
253 SDL_Quit();
254
255 std::cout << "[TilemapEditor] Shutdown complete" << std::endl;
256}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void SDL_AppQuit(void *appstate, SDL_AppResult result)
Definition main.cpp:223
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
Definition main.cpp:24
SDL_AppResult SDL_AppIterate(void *appstate)
Definition main.cpp:185
static Uint64 g_LastFrameTime
Definition main.cpp:22
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
Definition main.cpp:115
static Olympe::Editor::TilemapEditorApp * g_EditorApp
Definition main.cpp:21
static SDL_Renderer * g_Renderer
Definition main.cpp:20
static SDL_Window * g_Window
Definition main.cpp:19