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
826 {$IFNDEF HEADLESS}
828 begin
836 {$ENDIF}
842 begin
844 end
845 else
846 begin
847 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
855 var
857 begin
861 begin
865 //e_PollJoysticks();
870 var
872 begin
881 begin
891 begin
894 begin
899 end
900 else
901 begin
912 begin
918 begin
920 exit;
923 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
925 begin
928 begin
932 end
933 else
934 begin
943 begin
949 {$IF not DEFINED(HEADLESS)}
950 var
952 {$ENDIF}
953 begin
954 {$IF not DEFINED(HEADLESS)}
957 begin
959 end
960 else
961 begin
962 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
964 {$ENDIF}
969 begin
970 {$IF not DEFINED(HEADLESS)}
971 {$IFDEF USE_GLES1}
975 {$ELSE}
983 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
984 {$ENDIF}
985 {$ENDIF}
990 var
995 begin
1002 begin
1004 begin
1008 begin
1010 end
1011 else
1012 begin
1020 begin
1024 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
1032 var
1034 {$IF not DEFINED(HEADLESS)}
1036 {$ENDIF}
1039 {$IFDEF ENABLE_HOLMES}
1042 {$ENDIF}
1043 begin
1044 {$IFDEF HEADLESS}
1046 {$ELSE}
1047 {$IFDEF ENABLE_HOLMES}
1049 begin
1053 {$ENDIF}
1054 {$ENDIF}
1058 begin
1062 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
1080 {.$IF DEFINED(D2F_DEBUG)}
1082 {.$ENDIF}
1084 {$IFDEF ENABLE_HOLMES}
1088 begin
1090 begin
1097 begin
1099 begin
1102 {$IFNDEF HEADLESS}
1104 begin
1111 {$ELSE}
1112 // fuck off, fpc!
1115 {$ENDIF}
1119 {$ENDIF}
1122 begin
1124 begin
1131 begin
1144 begin
1147 exit;
1150 {EnumDisplayModes();}
1152 {$IFDEF HEADLESS}
1153 //gwin_k8_enable_light_experiments := false;
1157 {$ELSE}
1164 begin
1167 end
1168 else
1169 begin
1174 {$ENDIF}
1179 // Êîìàíäíàÿ ñòðîêà
1182 {$IFNDEF HEADLESS}
1183 // Çàïðîñ ÿçûêà
1185 {$ENDIF}
1189 // main loop
1199 initialization