Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
system_utils.cpp
Go to the documentation of this file.
1/*
2Olympus Game Engine V2 2025
3Nicolas Chereau
4nchereau@gmail.com
5
6purpose:
7
8Notes:
9
10*/
11
12#include "system_utils.h"
13#include "..\gameengine.h"
14#include "..\PanelManager.h"
15
16#include <windows.h>
17
18void LoadOlympeConfig(const char* filename)
19{
22
23 std::ifstream ifs(filename);
24 if (!ifs) {
25 SYSTEM_LOG << "Config file '" << filename << "' not found \xe2\x80\x93 using defaults " << GameEngine::screenWidth << "x" << GameEngine::screenHeight << "\n";
26 return;
27 }
28
29 std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
30
31 // Extract screen width and height
34
35 if (extract_json_int(content, "screen_width", w) || extract_json_int(content, "screenWidth", w) || extract_json_int(content, "width", w)) {}
36 if (extract_json_int(content, "screen_height", h) || extract_json_int(content, "screenHeight", h) || extract_json_int(content, "screen_heigth", h) || extract_json_int(content, "height", h)) {}
37
38 if (w > 0) GameEngine::screenWidth = w;
39 if (h > 0) GameEngine::screenHeight = h;
40
41 // Phase 26 — Simplified logging: output to stdout, file, and panel always
42 // (no configurable output channels)
43
44 SYSTEM_LOG << "Config loaded from '" << filename << "': " << GameEngine::screenWidth << "x" << GameEngine::screenHeight << "\n";
45
46 // Extract Log Panel data
47 if (extract_json_int(content, "log_panel_width", PanelManager::LogPanelWidth)) {}
48 if (extract_json_int(content, "log_panel_height", PanelManager::LogPanelHeight)) {}
49 if (extract_json_int(content, "log_panel_posx", PanelManager::LogPanelPosX)) {}
50 if (extract_json_int(content, "log_panel_posy", PanelManager::LogPanelPosY)) {}
51
52 // Extract Object Inspector Panel data
53 if (extract_json_int(content, "inspector_panel_width", PanelManager::InspectorPanelWidth)) {}
54 if (extract_json_int(content, "inspector_panel_height", PanelManager::InspectorPanelHeight)) {}
55 if (extract_json_int(content, "inspector_panel_posx", PanelManager::InspectorPanelPosX)) {}
56 if (extract_json_int(content, "inspector_panel_posy", PanelManager::InspectorPanelPosY)) {}
57
58 // Extract Tree View Panel data
59 if (extract_json_int(content, "treeview_panel_width", PanelManager::TreeViewPanelWidth)) {}
60 if (extract_json_int(content, "treeview_panel_height", PanelManager::TreeViewPanelHeight)) {}
61 if (extract_json_int(content, "treeview_panel_posx", PanelManager::TreeViewPanelPosX)) {}
62 if (extract_json_int(content, "treeview_panel_posy", PanelManager::TreeViewPanelPosY)) {}
63
64 /* "object_panel_width" : 200,
65 "object_panel_height" : 400,
66 "object_panel_posx" : 700,
67 "object_panel_posy" : 0,
68
69 "treeview_panel_width" : 300,
70 "treeview_panel_height" : 600,
71 "treeview_panel_posx" : 700,
72 "treeview_panel_posy" : 400,/**/
73}
74
75//-------------------------------------------------------------
76// Path resolution for resource files (Phase 24 - Condition Presets)
77// Resolves relative paths to absolute paths based on executable location.
78// This works in both IDE debug mode (working dir = solution subdir) and
79// built executable mode (working dir = parent dir).
80//-------------------------------------------------------------
81std::string ResolveResourcePath(const std::string& relativePath)
82{
83 // Normalize the relative path: convert forward slashes to backslashes
84 std::string normPath = relativePath;
85 for (size_t i = 0; i < normPath.size(); ++i)
86 {
87 if (normPath[i] == '/') normPath[i] = '\\';
88 }
89
90 // Get the executable path (OlympeBlueprintEditor.exe)
91 char exePath[MAX_PATH] = { 0 };
92 if (GetModuleFileNameA(nullptr, exePath, MAX_PATH) == 0)
93 {
94 // Fallback: return the normalized relative path as-is if we can't get the executable path
95 return normPath;
96 }
97
98 // Get the directory containing the executable
99 std::string exeDir(exePath);
100 size_t lastSlash = exeDir.find_last_of("\\/");
101 if (lastSlash != std::string::npos)
102 {
103 exeDir = exeDir.substr(0, lastSlash);
104 }
105 else
106 {
107 // Fallback: return the normalized relative path as-is
108 return normPath;
109 }
110
111 // Construct the absolute path by combining executable directory with relative path
112 // Try multiple locations to handle both IDE debug and built executable scenarios:
113 // 1. exeDir + relative (built executable, or when running from bin/ directly)
114 // 2. parent of exeDir + relative (IDE debug, executable is in OlympeBlueprintEditor/bin/)
115 // 3. grandparent of exeDir + relative (IDE debug, executable is deeper)
116
117 // Try the direct path first (built executable case)
118 std::string absolutePath = exeDir + "\\" + normPath;
120 {
121 return absolutePath;
122 }
123
124 // If not found, try going up one directory level (IDE debug case)
125 size_t parentSlash = exeDir.find_last_of("\\/");
126 if (parentSlash != std::string::npos)
127 {
128 std::string parentDir = exeDir.substr(0, parentSlash);
129 std::string pathAtParent = parentDir + "\\" + normPath;
131 {
132 return pathAtParent;
133 }
134
135 // Try another level up (grandparent)
136 size_t grandparentSlash = parentDir.find_last_of("\\/");
137 if (grandparentSlash != std::string::npos)
138 {
139 std::string grandparentDir = parentDir.substr(0, grandparentSlash);
140 std::string pathAtGrandparent = grandparentDir + "\\" + normPath;
142 {
143 return pathAtGrandparent;
144 }
145 }
146 }
147
148 // If file not found anywhere, return the executable directory + relative path
149 // This will cause a load failure later with a meaningful path for debugging
150 SYSTEM_LOG << "[ResolveResourcePath] Warning: Could not find resource '" << normPath
151 << "' relative to executable. Returning path relative to exe dir.\n";
152 return exeDir + "\\" + normPath;
153}
154
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static int screenWidth
Screen width in pixels.
Definition GameEngine.h:123
static int screenHeight
Screen height in pixels.
Definition GameEngine.h:126
static int LogPanelHeight
static int TreeViewPanelPosX
static int LogPanelPosX
static int InspectorPanelHeight
static int InspectorPanelWidth
static int InspectorPanelPosY
static int LogPanelWidth
static int TreeViewPanelPosY
static int LogPanelPosY
static int InspectorPanelPosX
static int TreeViewPanelHeight
static int TreeViewPanelWidth
static const int DEFAULT_WINDOW_HEIGHT
static const int DEFAULT_WINDOW_WIDTH
void LoadOlympeConfig(const char *filename)
std::string ResolveResourcePath(const std::string &relativePath)
#define SYSTEM_LOG
static bool extract_json_int(const std::string &json, const std::string &key, int &out)