d790c4f852c9f468bd51c39ba4a9fd1b221faa20
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
19 interface
21 uses
22 utils;
39 // returns `true` if quit event was received
43 var
51 implementation
53 uses
55 {$INCLUDE ../nogl/noGLuses.inc}
56 {$IFDEF ENABLE_HOLMES}
58 {$ENDIF}
67 const
70 var
75 {$IF not DEFINED(HEADLESS)}
78 {$ENDIF}
84 {$IFNDEF WINDOWS}
87 {$ENDIF}
93 begin
94 {$IFDEF ENABLE_HOLMES}
95 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
96 {$ENDIF}
99 begin
101 {$IFDEF USE_NANOGL}
102 nanoGL_Destroy;
103 {$ENDIF}
105 {$IFDEF USE_NOGL}
106 nogl_Quit;
107 {$ENDIF}
117 {$IF not DEFINED(HEADLESS)}
118 var
122 {$ENDIF}
123 begin
124 {$IF not DEFINED(HEADLESS)}
130 if gFullscreen then wFlags := wFlags {or SDL_WINDOW_FULLSCREEN} else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
131 if (not gFullscreen) and (not preserveGL) and gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED else gWinMaximized := false;
134 begin
141 begin
145 end
146 else
147 begin
148 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight)+': '+IntToStr(cmode.w)+'x'+IntToStr(cmode.h), TMsgType.Notify);
155 begin
156 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
157 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
162 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
163 //SDL_SetWindowFullscreen(h_Wnd, 0);
164 end
165 else
166 begin
168 h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
179 begin
184 begin
185 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw)+'x'+IntToStr(nh)+': '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight), TMsgType.Notify);
188 end
189 else
190 begin
191 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
195 {$IFDEF ENABLE_HOLMES}
198 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
199 {$ENDIF}
200 {$ENDIF}
207 var
210 begin
217 begin
235 begin
241 begin
242 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
245 {$IF not DEFINED(HEADLESS)}
246 {$IFDEF ENABLE_HOLMES}
249 {$ENDIF}
252 {$IF DEFINED(ANDROID)}
253 (* This will fix menu reset on keyboard showing *)
255 g_Menu_Reset;
256 {$ELSE}
257 g_Menu_Reset;
258 {$ENDIF}
260 {$ENDIF}
265 {$IF not DEFINED(HEADLESS)}
266 var
268 {$ENDIF}
269 begin
271 {$IF not DEFINED(HEADLESS)}
275 begin
283 begin
291 begin
295 {$ENDIF}
300 var
302 begin
308 SDL_WINDOWEVENT_MOVED:
309 begin
311 begin
317 SDL_WINDOWEVENT_MINIMIZED:
318 begin
321 begin
325 begin
333 SDL_WINDOWEVENT_RESIZED:
334 begin
335 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth, gScreenHeight, Integer(ev.data1), Integer(ev.data2)]);
336 {if (gFullscreen) then
337 begin
338 e_LogWriteln(' fullscreen fix applied.');
339 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
340 begin
341 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
342 end;
343 end
344 else}
345 begin
352 begin
354 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2), TMsgType.Notify);
358 SDL_WINDOWEVENT_EXPOSED:
361 SDL_WINDOWEVENT_MAXIMIZED:
362 begin
365 begin
371 begin
374 begin
381 SDL_WINDOWEVENT_RESTORED:
382 begin
385 begin
392 begin
398 SDL_WINDOWEVENT_FOCUS_GAINED:
399 begin
401 //e_WriteLog('window gained focus!', MSG_NOTIFY);
404 SDL_WINDOWEVENT_FOCUS_LOST:
405 begin
408 //e_WriteLog('window lost focus!', MSG_NOTIFY);
413 begin
415 begin
417 e_UnpressAllKeys;
420 begin
421 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
426 begin
433 {$IFDEF ENABLE_HOLMES}
435 {$ENDIF}
437 end
439 begin
441 begin
442 //e_WriteLog('activating window', MSG_NOTIFY);
445 begin
446 //e_WriteLog('activating sounds', MSG_NOTIFY);
451 begin
458 {$IFDEF ENABLE_HOLMES}
460 {$ENDIF}
467 var
473 begin
477 SDL_WINDOWEVENT:
480 SDL_QUITEV:
481 begin
483 begin
485 begin
488 end
489 else
490 begin
498 begin
503 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
505 begin
506 // event eaten, but...
508 exit;
510 {$ENDIF}
512 begin
517 end
519 begin
520 // key repeat in menus and shit
527 begin
531 e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, key, down]);
534 end
535 else
536 begin
538 begin
540 e_LogWritefln('Input Debug: NOT IN RANGE! jbutton, joy=%s, button=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, down])
541 end
544 SDL_JOYAXISMOTION:
546 begin
551 e_LogWritefln('Input Debug: jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]]);
553 if ev.jaxis.value < JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then
554 begin
556 begin
562 end
563 else if ev.jaxis.value > JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then
564 begin
566 begin
572 end
573 else
574 begin
576 begin
581 begin
586 end
587 else
588 begin
590 e_LogWritefln('Input Debug: NOT IN RANGE! jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]])
593 SDL_JOYHATMOTION:
595 begin
597 e_LogWritefln('Input Debug: jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value]);
603 begin
605 begin
610 end
613 end
614 else
615 begin
617 e_LogWritefln('Input Debug: NOT IN RANGE! jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value])
620 SDL_JOYDEVICEADDED:
622 begin
625 begin
629 JoystickZeroAxes[ev.jdevice.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.jdevice.which], i)
630 end
631 else
633 end
634 else
635 begin
636 e_LogWritefln('Warning! Added Joystick %s, but we support only <= %s', [ev.jdevice.which, e_MaxJoys])
639 SDL_JOYDEVICEREMOVED:
640 begin
643 begin
648 end
651 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
654 {$ENDIF}
656 SDL_TEXTINPUT:
657 begin
669 // other key presses and joysticks are handled in e_input
675 begin
676 {$IF not DEFINED(HEADLESS)}
678 {$ENDIF}
683 begin
689 {$IF not DEFINED(HEADLESS)}
691 {$ENDIF}
695 begin
698 exit;
701 {$IF not DEFINED(HEADLESS)}
704 {$IFDEF ENABLE_HOLMES}
707 {$ENDIF}
709 {$IFDEF USE_NANOGL}
711 begin
714 exit;
716 {$ENDIF}
717 {$IFDEF USE_NOGL}
718 nogl_Init;
719 {$ENDIF}
720 {$IFDEF ENABLE_HOLMES}
722 {$ENDIF}
724 {$ENDIF}
733 {$IFDEF WINDOWS}
734 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
736 var
738 begin
743 {$ELSE}
745 var
748 begin
751 begin
754 end
755 else
756 begin
758 begin
759 // overflow, increment overflow ;-)
768 {$ENDIF}
772 begin
778 var
780 begin
786 var
790 var
793 begin
798 begin
802 //e_PollJoysticks();
805 begin
807 exit;
811 begin
813 begin
815 end
816 else
817 begin
820 begin
827 begin
839 begin
841 end
842 else
843 begin
844 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
852 var
854 begin
858 begin
862 //e_PollJoysticks();
867 var
869 begin
878 begin
888 begin
891 begin
896 end
897 else
898 begin
907 begin
913 begin
915 exit;
918 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
920 begin
923 begin
927 end
928 else
929 begin
938 begin
944 {$IF not DEFINED(HEADLESS)}
945 var
947 {$ENDIF}
948 begin
949 {$IF not DEFINED(HEADLESS)}
952 begin
954 end
955 else
956 begin
957 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
959 {$ENDIF}
964 begin
965 {$IF not DEFINED(HEADLESS)}
966 {$IFDEF USE_GLES1}
970 {$ELSE}
978 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
979 {$ENDIF}
980 {$ENDIF}
985 var
990 begin
997 begin
999 begin
1003 begin
1005 end
1006 else
1007 begin
1015 begin
1019 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
1027 var
1029 {$IF not DEFINED(HEADLESS)}
1031 {$ENDIF}
1034 {$IFDEF ENABLE_HOLMES}
1037 {$ENDIF}
1038 begin
1039 {$IFDEF HEADLESS}
1041 {$ELSE}
1042 {$IFDEF ENABLE_HOLMES}
1044 begin
1048 {$ENDIF}
1049 {$ENDIF}
1053 begin
1057 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
1075 {.$IF DEFINED(D2F_DEBUG)}
1077 {.$ENDIF}
1079 {$IFDEF ENABLE_HOLMES}
1083 begin
1085 begin
1092 begin
1094 begin
1097 {$IFNDEF HEADLESS}
1099 begin
1106 {$ELSE}
1107 // fuck off, fpc!
1110 {$ENDIF}
1114 {$ENDIF}
1117 begin
1119 begin
1126 begin
1139 begin
1142 exit;
1145 {EnumDisplayModes();}
1147 {$IFDEF HEADLESS}
1148 //gwin_k8_enable_light_experiments := false;
1152 {$ELSE}
1159 begin
1162 end
1163 else
1164 begin
1169 {$ENDIF}
1174 // Êîìàíäíàÿ ñòðîêà
1177 // Çàïðîñ ÿçûêà
1182 // main loop
1192 initialization