MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / sdlInit

Function sdlInit

TheForceEngine/main.cpp:212–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212bool sdlInit()
213{
214 const int code = SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO);
215 if (code != 0) { return false; }
216
217 TFE_Settings_Window* windowSettings = TFE_Settings::getWindowSettings();
218 bool fullscreen = windowSettings->fullscreen || TFE_Settings::getTempSettings()->forceFullscreen;
219 s_displayWidth = windowSettings->width;
220 s_displayHeight = windowSettings->height;
221 s_baseWindowWidth = windowSettings->baseWidth;
222 s_baseWindowHeight = windowSettings->baseHeight;
223
224 // Get the displays and their bounds.
225 s_displayIndex = TFE_RenderBackend::getDisplayIndex(windowSettings->x, windowSettings->y);
226 // Reset the display if the window is out of bounds.
227 if (s_displayIndex < 0)
228 {
229 MonitorInfo mInfo;
230 s_displayIndex = 0;
231 TFE_RenderBackend::getDisplayMonitorInfo(0, &mInfo);
232
233 windowSettings->x = mInfo.x;
234 windowSettings->y = mInfo.y + 32;
235 windowSettings->width = min((s32)windowSettings->width, mInfo.w);
236 windowSettings->height = min((s32)windowSettings->height, mInfo.h);
237 windowSettings->baseWidth = windowSettings->width;
238 windowSettings->baseHeight = windowSettings->height;
239 TFE_Settings::writeToDisk();
240
241 s_displayWidth = windowSettings->width;
242 s_displayHeight = windowSettings->height;
243 s_baseWindowWidth = windowSettings->baseWidth;
244 s_baseWindowHeight = windowSettings->baseHeight;
245 }
246
247 // Determine the display mode settings based on the desktop.
248 SDL_DisplayMode mode = {};
249 SDL_GetDesktopDisplayMode(s_displayIndex, &mode);
250 s_refreshRate = (f32)mode.refresh_rate;
251
252 if (fullscreen)
253 {
254 s_displayWidth = mode.w;
255 s_displayHeight = mode.h;
256 }
257 else
258 {
259 s_displayWidth = std::min(s_displayWidth, (u32)mode.w);
260 s_displayHeight = std::min(s_displayHeight, (u32)mode.h);
261 }
262
263 s_monitorWidth = mode.w;
264 s_monitorHeight = mode.h;
265
266#ifdef SDL_HINT_APP_NAME // SDL 2.0.18+
267 SDL_SetHint(SDL_HINT_APP_NAME, "The Force Engine");
268#endif
269

Callers 1

mainFunction · 0.85

Calls 6

getWindowSettingsFunction · 0.85
getTempSettingsFunction · 0.85
getDisplayIndexFunction · 0.85
getDisplayMonitorInfoFunction · 0.85
minFunction · 0.85
writeToDiskFunction · 0.85

Tested by

no test coverage detected