Fix program termination sequence and a lot of memory leaks during it
[d2df-sdl.git] / src / game / sdl2 / g_system.pas
blob6d79d7d27388bbee66ac5b87ee56a95b107cf41d
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_system;
18 interface
20 uses Utils;
22 (* --- Utils --- *)
23 function sys_GetTicks (): Int64;
24 procedure sys_Delay (ms: Integer);
26 (* --- Graphics --- *)
27 function sys_GetDisplayModes (bpp: Integer): SSArray;
28 function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean;
29 procedure sys_EnableVSync (yes: Boolean);
30 procedure sys_Repaint;
32 (* --- Input --- *)
33 function sys_HandleEvents (): Boolean;
34 procedure sys_RequestQuit;
36 (* --- Init --- *)
37 procedure sys_Init;
38 procedure sys_Final;
40 implementation
42 uses
43 SysUtils, SDL2, Math, ctypes,
44 e_log, e_graphics, e_input, e_sound,
45 {$INCLUDE ../nogl/noGLuses.inc}
46 {$IFDEF ENABLE_HOLMES}
47 g_holmes, sdlcarcass, fui_ctls,
48 {$ENDIF}
49 g_touch, g_options, g_window, g_console, g_game, g_menu, g_gui, g_main, g_basic;
51 const
52 GameTitle = 'Doom 2D: Forever (SDL 2, %s)';
54 var
55 window: PSDL_Window;
56 context: TSDL_GLContext;
57 display, wx, wy: Integer;
58 wc: Boolean;
59 JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick;
60 JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean;
61 JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer;
63 (* --------- Utils --------- *)
65 function sys_GetTicks (): Int64;
66 begin
67 result := SDL_GetTicks()
68 end;
70 procedure sys_Delay (ms: Integer);
71 begin
72 SDL_Delay(ms)
73 end;
75 (* --------- Graphics --------- *)
77 function LoadGL: Boolean;
78 var ltmp: Integer;
79 begin
80 result := true;
81 {$IFDEF NOGL_INIT}
82 nogl_Init;
83 if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then
84 begin
85 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
86 glRenderToFBO := false;
87 end;
88 {$ELSE}
89 if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then
90 begin
91 e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering');
92 glRenderToFBO := false;
93 end;
94 {$ENDIF}
95 if SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp) = 0 then
96 begin
97 e_LogWritefln('stencil buffer size: %s', [ltmp]);
98 gwin_has_stencil := (ltmp > 0);
99 end;
100 end;
102 procedure FreeGL;
103 begin
104 {$IFDEF NOGL_INIT}
105 nogl_Quit();
106 {$ENDIF}
107 end;
109 procedure UpdateSize (w, h: Integer);
110 begin
111 gWinSizeX := w;
112 gWinSizeY := h;
113 gRC_Width := w;
114 gRC_Height := h;
115 if glRenderToFBO then
116 begin
117 // store real window size in gWinSize, downscale resolution now
118 w := round(w / r_pixel_scale);
119 h := round(h / r_pixel_scale);
120 if not e_ResizeFramebuffer(w, h) then
121 begin
122 e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo');
123 glRenderToFBO := False;
124 w := gWinSizeX;
125 h := gWinSizeY;
126 end;
127 end;
128 gScreenWidth := w;
129 gScreenHeight := h;
130 {$IFDEF ENABLE_HOLMES}
131 fuiScrWdt := w;
132 fuiScrHgt := h;
133 {$ENDIF}
134 e_ResizeWindow(w, h);
135 e_InitGL;
136 g_Game_SetupScreenSize;
137 {$IFNDEF ANDROID}
138 (* This will fix menu reset on keyboard showing *)
139 g_Menu_Reset;
140 {$ENDIF}
141 g_Game_ClearLoading;
142 {$IFDEF ENABLE_HOLMES}
143 if assigned(oglInitCB) then oglInitCB;
144 {$ENDIF}
145 end;
147 function GetTitle (): AnsiString;
148 var info: AnsiString;
149 begin
150 info := g_GetBuildHash(false);
151 if info = 'custom build' then
152 info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME;
153 result := Format(GameTitle, [info]);
154 end;
156 function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
157 var flags: UInt32; x, y: cint; title: AnsiString;
158 begin
159 // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB;
160 e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]);
161 result := false;
162 if window = nil then
163 begin
164 {$IFDEF USE_GLES1}
165 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
166 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
167 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
168 {$ELSE}
169 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
170 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
171 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
172 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
173 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
174 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
175 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
176 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
177 {$ENDIF}
178 flags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE;
179 if fullScreen then flags := flags or SDL_WINDOW_FULLSCREEN;
180 if maximized then flags := flags or SDL_WINDOW_MAXIMIZED;
181 if wc then
182 begin
183 x := SDL_WINDOWPOS_CENTERED;
184 y := SDL_WINDOWPOS_CENTERED
186 else
187 begin
188 x := wx;
189 y := wy
190 end;
191 title := GetTitle();
192 window := SDL_CreateWindow(PChar(title), x, y, w, h, flags);
193 if window <> nil then
194 begin
195 context := SDL_GL_CreateContext(window);
196 if context <> nil then
197 begin
198 if not LoadGL then
199 begin
200 e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal);
201 SDL_GL_DeleteContext(context); context := nil;
202 exit;
203 end;
204 if (fullscreen = false) and (maximized = false) and (wc = false) then
205 begin
206 SDL_GetWindowPosition(window, @x, @y);
207 wx := x; wy := y
208 end;
209 gFullScreen := fullscreen;
210 gWinMaximized := maximized;
211 gRC_FullScreen := fullscreen;
212 gRC_Maximized := maximized;
213 UpdateSize(w, h);
214 result := true
216 else
217 begin
218 // SDL_DestroyWindow(window);
219 e_LogWritefln('SDL: unable to create OpenGL context: %s', [SDL_GetError])
222 else
223 begin
224 e_LogWritefln('SDL: unable to create window: %s', [SDL_GetError])
227 else
228 begin
229 if fullScreen then flags := SDL_WINDOW_FULLSCREEN else flags := 0;
230 SDL_SetWindowFullscreen(window, flags);
231 SDL_SetWindowSize(window, w, h);
232 if maximized then SDL_MaximizeWindow(window);
233 // always reset to center when changing fullscreen->windowed for safety purposes
234 if wc or (gFullscreen and not fullscreen) or (gWinMaximized and not maximized) then
235 begin
236 x := SDL_WINDOWPOS_CENTERED;
237 y := SDL_WINDOWPOS_CENTERED
239 else
240 begin
241 x := wx;
242 y := wy
243 end;
244 SDL_SetWindowPosition(window, x, y);
245 if (fullscreen = false) and (maximized = false) and (wc = false) then
246 begin
247 SDL_GetWindowPosition(window, @x, @y);
248 wx := x; wy := y
249 end;
250 gFullScreen := fullscreen;
251 gWinMaximized := maximized;
252 gRC_FullScreen := fullscreen;
253 gRC_Maximized := maximized;
254 UpdateSize(w, h);
255 result := true
257 end;
259 procedure sys_Repaint;
260 begin
261 SDL_GL_SwapWindow(window)
262 end;
264 procedure sys_EnableVSync (yes: Boolean);
265 begin
266 SDL_GL_SetSwapInterval(Ord(yes));
267 end;
269 function sys_GetDisplayModes (bpp: Integer): SSArray;
270 var i, count, num, pw, ph: Integer; m: TSDL_DisplayMode;
271 begin
272 result := nil;
273 num := SDL_GetNumDisplayModes(display);
274 if num < 0 then
275 e_LogWritefln('SDL: unable to get number of available display modes: %s', [SDL_GetError]);
276 if num > 0 then
277 begin
278 e_LogWritefln('Video modes for display %s:', [display]);
279 SetLength(result, num);
280 i := 0; count := 0; pw := 0; ph := 0;
281 while i < num do
282 begin
283 SDL_GetDisplayMode(display, i, @m);
284 if ((pw <> m.w) or (ph <> m.h)) then
285 begin
286 e_LogWritefln('* %sx%sx%s@%s', [m.w, m.h, SDL_BITSPERPIXEL(m.format), m.refresh_rate]);
287 pw := m.w; ph := m.h;
288 result[count] := IntToStr(m.w) + 'x' + IntToStr(m.h);
289 Inc(count);
291 else
292 begin
293 e_LogWritefln('- %sx%sx%s@%s', [m.w, m.h, SDL_BITSPERPIXEL(m.format), m.refresh_rate]);
294 end;
295 Inc(i)
296 end;
297 SetLength(result, count)
299 end;
301 function sys_SetDisplayMode (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean;
302 begin
303 result := InitWindow(w, h, bpp, fullScreen, maximized)
304 end;
306 (* --------- Joystick --------- *)
308 procedure HandleJoyButton (var ev: TSDL_JoyButtonEvent);
309 var down: Boolean; key: Integer;
310 begin
311 if (ev.which < e_MaxJoys) and (ev.button < e_MaxJoyBtns) then
312 begin
313 key := e_JoyButtonToKey(ev.which, ev.button);
314 down := ev.type_ = SDL_JOYBUTTONDOWN;
315 if g_dbg_input then
316 e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.which, ev.button, key, down]);
317 e_KeyUpDown(key, down);
318 g_Console_ProcessBind(key, down)
320 else
321 begin
322 if g_dbg_input then
323 begin
324 down := ev.type_ = SDL_JOYBUTTONDOWN;
325 e_LogWritefln('Input Debug: NOT IN RANGE! jbutton, joy=%s, button=%s, press=%s', [ev.which, ev.button, down])
328 end;
330 procedure HandleJoyAxis (var ev: TSDL_JoyAxisEvent);
331 var key, minuskey: Integer;
332 begin
333 if (ev.which < e_MaxJoys) and (ev.axis < e_MaxJoyAxes) then
334 begin
335 key := e_JoyAxisToKey(ev.which, ev.axis, AX_PLUS);
336 minuskey := e_JoyAxisToKey(ev.which, ev.axis, AX_MINUS);
338 if g_dbg_input then
339 e_LogWritefln('Input Debug: jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.which, ev.axis, ev.value, JoystickZeroAxes[ev.which, ev.axis], e_JoystickDeadzones[ev.which]]);
341 if ev.value < JoystickZeroAxes[ev.which, ev.axis] - e_JoystickDeadzones[ev.which] then
342 begin
343 if (e_KeyPressed(key)) then
344 begin
345 e_KeyUpDown(key, False);
346 g_Console_ProcessBind(key, False)
347 end;
348 e_KeyUpDown(minuskey, True);
349 g_Console_ProcessBind(minuskey, True)
351 else if ev.value > JoystickZeroAxes[ev.which, ev.axis] + e_JoystickDeadzones[ev.which] then
352 begin
353 if (e_KeyPressed(minuskey)) then
354 begin
355 e_KeyUpDown(minuskey, False);
356 g_Console_ProcessBind(minuskey, False)
357 end;
358 e_KeyUpDown(key, True);
359 g_Console_ProcessBind(key, True)
361 else
362 begin
363 if (e_KeyPressed(minuskey)) then
364 begin
365 e_KeyUpDown(minuskey, False);
366 g_Console_ProcessBind(minuskey, False)
367 end;
368 if (e_KeyPressed(key)) then
369 begin
370 e_KeyUpDown(key, False);
371 g_Console_ProcessBind(key, False)
375 else
376 begin
377 if g_dbg_input then
378 e_LogWritefln('Input Debug: NOT IN RANGE! jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.which, ev.axis, ev.value, JoystickZeroAxes[ev.which, ev.axis], e_JoystickDeadzones[ev.which]])
380 end;
382 procedure HandleJoyHat (var ev: TSDL_JoyHatEvent);
384 down: Boolean;
385 i, key: Integer;
386 hat: array [HAT_LEFT..HAT_DOWN] of Boolean;
387 begin
388 if (ev.which < e_MaxJoys) and (ev.hat < e_MaxJoyHats) then
389 begin
390 if g_dbg_input then
391 e_LogWritefln('Input Debug: jhat, joy=%s, hat=%s, value=%s', [ev.which, ev.hat, ev.value]);
392 hat[HAT_UP] := LongBool(ev.value and SDL_HAT_UP);
393 hat[HAT_DOWN] := LongBool(ev.value and SDL_HAT_DOWN);
394 hat[HAT_LEFT] := LongBool(ev.value and SDL_HAT_LEFT);
395 hat[HAT_RIGHT] := LongBool(ev.value and SDL_HAT_RIGHT);
396 for i := HAT_LEFT to HAT_DOWN do
397 begin
398 if JoystickHatState[ev.which, ev.hat, i] <> hat[i] then
399 begin
400 down := hat[i];
401 key := e_JoyHatToKey(ev.which, ev.hat, i);
402 e_KeyUpDown(key, down);
403 g_Console_ProcessBind(key, down)
405 end;
406 JoystickHatState[ev.which, ev.hat] := hat
408 else
409 begin
410 if g_dbg_input then
411 e_LogWritefln('Input Debug: NOT IN RANGE! jhat, joy=%s, hat=%s, value=%s', [ev.which, ev.hat, ev.value])
413 end;
415 procedure HandleJoyAdd (var ev: TSDL_JoyDeviceEvent);
416 var i: Integer;
417 begin
418 if (ev.which < e_MaxJoys) then
419 begin
420 JoystickHandle[ev.which] := SDL_JoystickOpen(ev.which);
421 if JoystickHandle[ev.which] <> nil then
422 begin
423 e_LogWritefln('Added Joystick %s', [ev.which]);
424 e_JoystickAvailable[ev.which] := True;
425 for i := 0 to Min(SDL_JoystickNumAxes(JoystickHandle[ev.which]), e_MaxJoyAxes) - 1 do
426 JoystickZeroAxes[ev.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.which], i)
428 else
429 begin
430 e_LogWritefln('Warning! Failed to open Joystick %s', [ev.which])
433 else
434 begin
435 e_LogWritefln('Warning! Added Joystick %s, but we support only <= %s', [ev.which, e_MaxJoys])
437 end;
439 procedure HandleJoyRemove (var ev: TSDL_JoyDeviceEvent);
440 begin
441 e_LogWritefln('Removed Joystick %s', [ev.which]);
442 if (ev.which < e_MaxJoys) then
443 begin
444 e_JoystickAvailable[ev.which] := False;
445 if JoystickHandle[ev.which] <> nil then
446 SDL_JoystickClose(JoystickHandle[ev.which]);
447 JoystickHandle[ev.which] := nil
449 end;
451 (* --------- Input --------- *)
453 function HandleWindow (var ev: TSDL_WindowEvent): Boolean;
454 begin
455 result := false;
456 if g_dbg_input then
457 e_LogWritefln('Window Event: event = %s, data1 = %s, data2 = %s', [ev.event, ev.data1, ev.data2]);
458 case ev.event of
459 SDL_WINDOWEVENT_RESIZED: UpdateSize(ev.data1, ev.data2);
460 SDL_WINDOWEVENT_EXPOSED: sys_Repaint;
461 SDL_WINDOWEVENT_CLOSE: result := true;
462 SDL_WINDOWEVENT_MOVED:
463 begin
464 wx := ev.data1;
465 wy := ev.data2
466 end;
467 SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_MINIMIZED:
468 begin
469 e_UnpressAllKeys;
470 if gMuteWhenInactive then
471 e_MuteChannels(true);
472 {$IFDEF ENABLE_HOLMES}
473 if assigned(winBlurCB) then winBlurCB;
474 {$ENDIF}
475 end;
476 SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_RESTORED:
477 begin
478 if ev.event = SDL_WINDOWEVENT_MAXIMIZED then
479 begin
480 gWinMaximized := true;
481 gRC_Maximized := true
483 else if ev.event = SDL_WINDOWEVENT_RESTORED then
484 begin
485 gWinMaximized := false;
486 gRC_Maximized := false
487 end;
488 e_MuteChannels(false);
489 {$IFDEF ENABLE_HOLMES}
490 if assigned(winFocusCB) then winFocusCB;
491 {$ENDIF}
492 end;
494 end;
496 procedure HandleKeyboard (var ev: TSDL_KeyboardEvent);
497 var down: Boolean; key: Integer;
498 begin
499 key := ev.keysym.scancode;
500 down := (ev.type_ = SDL_KEYDOWN);
501 if key = SDL_SCANCODE_AC_BACK then
502 key := SDL_SCANCODE_ESCAPE;
503 {$IFDEF ENABLE_HOLMES}
504 if fuiOnSDLEvent(PSDL_Event(@ev)^) then
505 begin
506 // event eaten, but...
507 if not down then e_KeyUpDown(key, false);
508 exit;
509 end;
510 {$ENDIF}
511 if ev._repeat = 0 then
512 begin
513 if g_dbg_input then
514 e_LogWritefln('Input Debug: keysym, press=%s, scancode=%s', [down, key]);
515 e_KeyUpDown(key, down);
516 g_Console_ProcessBind(key, down);
518 else
519 begin
520 if g_dbg_input then
521 e_LogWritefln('Input Debug: keyrep, scancode=%s', [key]);
522 g_Console_ProcessBindRepeat(key);
524 end;
526 procedure HandleTextInput (var ev: TSDL_TextInputEvent);
527 var ch: UnicodeChar; sch: AnsiChar;
528 begin
529 Utf8ToUnicode(@ch, PChar(ev.text), 1);
530 sch := AnsiChar(wchar2win(ch));
531 if g_dbg_input then
532 e_LogWritefln('Input Debug: text, text="%s", ch = %s, sch = %s', [ev.text, Ord(ch), Ord(sch)]);
533 if IsValid1251(Word(ch)) and IsPrintable1251(ch) then
534 CharPress(sch);
535 end;
537 function sys_HandleEvents (): Boolean;
538 var ev: TSDL_Event;
539 begin
540 result := false;
541 ZeroMemory(@ev, sizeof(ev));
542 while SDL_PollEvent(@ev) <> 0 do
543 begin
544 case ev.type_ of
545 SDL_QUITEV: result := true;
546 SDL_WINDOWEVENT: result := HandleWindow(ev.window);
547 SDL_KEYUP, SDL_KEYDOWN: HandleKeyboard(ev.key);
548 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: HandleJoyButton(ev.jbutton);
549 SDL_JOYAXISMOTION: HandleJoyAxis(ev.jaxis);
550 SDL_JOYHATMOTION: HandleJoyHat(ev.jhat);
551 SDL_JOYDEVICEADDED: HandleJoyAdd(ev.jdevice);
552 SDL_JOYDEVICEREMOVED: HandleJoyRemove(ev.jdevice);
553 SDL_TEXTINPUT: HandleTextInput(ev.text);
554 SDL_FINGERMOTION, SDL_FINGERDOWN, SDL_FINGERUP: g_Touch_HandleEvent(ev.tfinger);
555 {$IFDEF ENABLE_HOLMES}
556 SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION: fuiOnSDLEvent(ev);
557 {$ENDIF}
560 end;
562 procedure sys_RequestQuit;
563 var ev: TSDL_Event;
564 begin
565 ev.type_ := SDL_QUITEV;
566 SDL_PushEvent(@ev)
567 end;
569 (* --------- Init --------- *)
571 procedure sys_Init;
572 var flags: UInt32;
573 begin
574 e_WriteLog('Init SDL2', TMsgType.Notify);
575 {$IFDEF HEADLESS}
576 {$IFDEF USE_SDLMIXER}
577 flags := SDL_INIT_TIMER or SDL_INIT_AUDIO or $00004000;
578 {$ELSE}
579 flags := SDL_INIT_TIMER or $00004000;
580 {$ENDIF}
581 {$ELSE}
582 flags := SDL_INIT_TIMER or SDL_INIT_VIDEO;
583 {$ENDIF}
584 SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, '0');
585 if SDL_Init(flags) <> 0 then
586 raise Exception.Create('SDL: Init failed: ' + SDL_GetError);
587 {$IFNDEF HEADLESS}
588 if SDL_InitSubSystem(SDL_INIT_JOYSTICK) <> 0 then
589 e_LogWritefln('SDL: Init subsystem failed: %s', [SDL_GetError()]);
590 {$ENDIF}
591 SDL_ShowCursor(SDL_DISABLE);
592 end;
594 procedure sys_Final;
595 begin
596 e_WriteLog('Releasing SDL2', TMsgType.Notify);
597 if context <> nil then
598 begin
599 FreeGL;
600 SDL_GL_DeleteContext(context);
601 context := nil;
602 end;
603 if window <> nil then
604 begin
605 SDL_DestroyWindow(window);
606 window := nil;
607 end;
608 SDL_Quit
609 end;
611 initialization
612 conRegVar('sdl2_display_index', @display, 'use display index as base', '');
613 conRegVar('sdl2_window_x', @wx, 'window position x', '');
614 conRegVar('sdl2_window_y', @wy, 'window position y', '');
615 conRegVar('sdl2_window_center', @wc, 'force window creation at center', '');
616 display := 0;
617 wx := SDL_WINDOWPOS_CENTERED;
618 wy := SDL_WINDOWPOS_CENTERED;
619 wc := false
620 end.