245efa3a1ee2d425efcd2e100f10db90cab708bd
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
50 implementation
52 uses
54 {$INCLUDE ../nogl/noGLuses.inc}
55 {$IFDEF ENABLE_HOLMES}
57 {$ENDIF}
63 g_touch;
66 const
69 var
74 {$IF not DEFINED(HEADLESS)}
77 {$ENDIF}
83 {$IFNDEF WINDOWS}
86 {$ENDIF}
90 begin
91 {$IFDEF ENABLE_HOLMES}
92 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
93 {$ENDIF}
96 begin
98 {$IFDEF USE_NANOGL}
99 nanoGL_Destroy;
100 {$ENDIF}
102 {$IFDEF USE_NOGL}
103 nogl_Quit;
104 {$ENDIF}
114 {$IF not DEFINED(HEADLESS)}
115 var
119 {$ENDIF}
120 begin
121 {$IF not DEFINED(HEADLESS)}
127 if gFullscreen then wFlags := wFlags {or SDL_WINDOW_FULLSCREEN} else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
128 if (not gFullscreen) and (not preserveGL) and gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED else gWinMaximized := false;
131 begin
138 begin
142 end
143 else
144 begin
145 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight)+': '+IntToStr(cmode.w)+'x'+IntToStr(cmode.h), TMsgType.Notify);
152 begin
153 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
154 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
159 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
160 //SDL_SetWindowFullscreen(h_Wnd, 0);
161 end
162 else
163 begin
165 h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
176 begin
181 begin
182 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw)+'x'+IntToStr(nh)+': '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight), TMsgType.Notify);
185 end
186 else
187 begin
188 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
192 {$IFDEF ENABLE_HOLMES}
195 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
196 {$ENDIF}
197 {$ENDIF}
204 var
207 begin
214 begin
232 begin
238 begin
239 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
242 {$IF not DEFINED(HEADLESS)}
243 {$IFDEF ENABLE_HOLMES}
246 {$ENDIF}
249 {$IF DEFINED(ANDROID)}
250 (* This will fix menu reset on keyboard showing *)
252 g_Menu_Reset;
253 {$ELSE}
254 g_Menu_Reset;
255 {$ENDIF}
257 {$ENDIF}
262 {$IF not DEFINED(HEADLESS)}
263 var
265 {$ENDIF}
266 begin
268 {$IF not DEFINED(HEADLESS)}
272 begin
280 begin
288 begin
292 {$ENDIF}
297 var
299 begin
305 SDL_WINDOWEVENT_MOVED:
306 begin
308 begin
314 SDL_WINDOWEVENT_MINIMIZED:
315 begin
318 begin
322 begin
330 SDL_WINDOWEVENT_RESIZED:
331 begin
332 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth, gScreenHeight, Integer(ev.data1), Integer(ev.data2)]);
333 {if (gFullscreen) then
334 begin
335 e_LogWriteln(' fullscreen fix applied.');
336 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
337 begin
338 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
339 end;
340 end
341 else}
342 begin
349 begin
351 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2), TMsgType.Notify);
355 SDL_WINDOWEVENT_EXPOSED:
358 SDL_WINDOWEVENT_MAXIMIZED:
359 begin
362 begin
368 begin
371 begin
378 SDL_WINDOWEVENT_RESTORED:
379 begin
382 begin
389 begin
395 SDL_WINDOWEVENT_FOCUS_GAINED:
396 begin
398 //e_WriteLog('window gained focus!', MSG_NOTIFY);
401 SDL_WINDOWEVENT_FOCUS_LOST:
402 begin
405 //e_WriteLog('window lost focus!', MSG_NOTIFY);
410 begin
412 begin
418 begin
419 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
424 begin
431 {$IFDEF ENABLE_HOLMES}
433 {$ENDIF}
435 end
437 begin
439 begin
440 //e_WriteLog('activating window', MSG_NOTIFY);
444 begin
445 //e_WriteLog('activating sounds', MSG_NOTIFY);
450 begin
457 {$IFDEF ENABLE_HOLMES}
459 {$ENDIF}
466 var
472 begin
476 SDL_WINDOWEVENT:
479 SDL_QUITEV:
480 begin
482 begin
484 begin
487 end
488 else
489 begin
497 begin
502 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
504 begin
505 // event eaten, but...
507 exit;
509 {$ENDIF}
511 begin
520 begin
528 SDL_JOYAXISMOTION:
530 begin
534 if ev.jaxis.value < Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then
535 begin
537 begin
544 end
545 else if ev.jaxis.value > Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then
546 begin
548 begin
555 end
556 else
557 begin
559 begin
564 begin
571 SDL_JOYHATMOTION:
573 begin
579 begin
581 begin
587 end
592 (*
593 SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED:
594 begin
595 // TODO update menu here
596 end
597 *)
599 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
602 {$ENDIF}
604 SDL_TEXTINPUT:
605 begin
615 // other key presses and joysticks are handled in e_input
621 begin
622 {$IF not DEFINED(HEADLESS)}
624 {$ENDIF}
629 begin
635 {$IF not DEFINED(HEADLESS)}
637 {$ENDIF}
641 begin
644 exit;
647 {$IF not DEFINED(HEADLESS)}
650 {$IFDEF ENABLE_HOLMES}
653 {$ENDIF}
655 {$IFDEF USE_NANOGL}
657 begin
660 exit;
662 {$ENDIF}
663 {$IFDEF USE_NOGL}
664 nogl_Init;
665 {$ENDIF}
666 {$IFDEF ENABLE_HOLMES}
668 {$ENDIF}
670 {$ENDIF}
679 {$IFDEF WINDOWS}
680 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
682 var
684 begin
689 {$ELSE}
691 var
694 begin
697 begin
700 end
701 else
702 begin
704 begin
705 // overflow, increment overflow ;-)
714 {$ENDIF}
718 begin
724 var
726 begin
732 var
736 var
740 begin
745 begin
749 //e_PollJoysticks();
752 begin
754 exit;
758 begin
760 begin
762 end
763 else
764 begin
767 begin
774 begin
776 begin
779 end
780 else
781 begin
793 begin
795 end
796 else
797 begin
798 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
806 var
808 begin
812 begin
816 //e_PollJoysticks();
821 var
823 begin
832 begin
842 begin
845 begin
850 end
851 else
852 begin
861 begin
867 begin
869 exit;
872 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
874 begin
877 begin
881 end
882 else
883 begin
892 begin
898 {$IF not DEFINED(HEADLESS)}
899 var
901 {$ENDIF}
902 begin
903 {$IF not DEFINED(HEADLESS)}
906 begin
908 end
909 else
910 begin
911 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
913 {$ENDIF}
918 begin
919 {$IF not DEFINED(HEADLESS)}
920 {$IFDEF USE_GLES1}
924 {$ELSE}
932 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
933 {$ENDIF}
934 {$ENDIF}
939 var
944 begin
951 begin
953 begin
957 begin
959 end
960 else
961 begin
969 begin
973 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
981 var
983 {$IF not DEFINED(HEADLESS)}
985 {$ENDIF}
988 {$IFDEF ENABLE_HOLMES}
991 {$ENDIF}
992 begin
993 {$IFDEF HEADLESS}
995 {$ELSE}
996 {$IFDEF ENABLE_HOLMES}
998 begin
1002 {$ENDIF}
1003 {$ENDIF}
1007 begin
1011 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
1027 {.$IF DEFINED(D2F_DEBUG)}
1029 {.$ENDIF}
1031 {$IFDEF ENABLE_HOLMES}
1035 begin
1037 begin
1044 begin
1046 begin
1049 {$IFNDEF HEADLESS}
1051 begin
1058 {$ELSE}
1059 // fuck off, fpc!
1062 {$ENDIF}
1066 {$ENDIF}
1069 begin
1071 begin
1078 begin
1091 begin
1094 exit;
1097 {EnumDisplayModes();}
1099 {$IFDEF HEADLESS}
1100 //gwin_k8_enable_light_experiments := false;
1104 {$ELSE}
1111 begin
1114 end
1115 else
1116 begin
1121 {$ENDIF}
1126 // Êîìàíäíàÿ ñòðîêà
1129 // Çàïðîñ ÿçûêà
1134 // main loop