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
320 begin
324 begin
332 SDL_WINDOWEVENT_RESIZED:
333 begin
334 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth, gScreenHeight, Integer(ev.data1), Integer(ev.data2)]);
335 {if (gFullscreen) then
336 begin
337 e_LogWriteln(' fullscreen fix applied.');
338 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
339 begin
340 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
341 end;
342 end
343 else}
344 begin
351 begin
353 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2), TMsgType.Notify);
357 SDL_WINDOWEVENT_EXPOSED:
360 SDL_WINDOWEVENT_MAXIMIZED:
361 begin
364 begin
370 begin
373 begin
380 SDL_WINDOWEVENT_RESTORED:
381 begin
384 begin
391 begin
397 SDL_WINDOWEVENT_FOCUS_GAINED:
398 begin
400 //e_WriteLog('window gained focus!', MSG_NOTIFY);
403 SDL_WINDOWEVENT_FOCUS_LOST:
404 begin
409 //e_WriteLog('window lost focus!', MSG_NOTIFY);
414 begin
416 begin
422 begin
423 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
428 begin
435 {$IFDEF ENABLE_HOLMES}
437 {$ENDIF}
439 end
441 begin
443 begin
444 //e_WriteLog('activating window', MSG_NOTIFY);
448 begin
449 //e_WriteLog('activating sounds', MSG_NOTIFY);
454 begin
461 {$IFDEF ENABLE_HOLMES}
463 {$ENDIF}
470 var
474 begin
478 SDL_WINDOWEVENT:
481 SDL_QUITEV:
482 begin
484 begin
486 begin
489 end
490 else
491 begin
499 begin
504 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
506 begin
507 // event eaten, but...
509 exit;
511 {$ENDIF}
516 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
519 {$ENDIF}
521 SDL_TEXTINPUT:
522 begin
532 // other key presses and joysticks are handled in e_input
538 begin
539 {$IF not DEFINED(HEADLESS)}
541 {$ENDIF}
546 begin
552 {$IF not DEFINED(HEADLESS)}
554 {$ENDIF}
558 begin
561 exit;
564 {$IF not DEFINED(HEADLESS)}
567 {$IFDEF ENABLE_HOLMES}
570 {$ENDIF}
572 {$IFDEF USE_NANOGL}
574 begin
577 exit;
579 {$ENDIF}
580 {$IFDEF USE_NOGL}
581 nogl_Init;
582 {$ENDIF}
583 {$IFDEF ENABLE_HOLMES}
585 {$ENDIF}
587 {$ENDIF}
596 {$IFDEF WINDOWS}
597 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
599 var
601 begin
606 {$ELSE}
608 var
611 begin
614 begin
617 end
618 else
619 begin
621 begin
622 // overflow, increment overflow ;-)
631 {$ENDIF}
635 begin
641 var
643 begin
649 var
653 var
657 begin
662 begin
669 begin
671 exit;
675 begin
677 begin
679 end
680 else
681 begin
684 begin
691 begin
693 begin
696 end
697 else
698 begin
710 begin
712 end
713 else
714 begin
715 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
723 var
725 begin
729 begin
738 var
740 begin
749 begin
759 begin
762 begin
767 end
768 else
769 begin
778 begin
784 begin
786 exit;
789 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
791 begin
794 begin
798 end
799 else
800 begin
809 begin
815 {$IF not DEFINED(HEADLESS)}
816 var
818 {$ENDIF}
819 begin
820 {$IF not DEFINED(HEADLESS)}
823 begin
825 end
826 else
827 begin
828 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
830 {$ENDIF}
835 begin
836 {$IF not DEFINED(HEADLESS)}
837 {$IFDEF USE_GLES1}
841 {$ELSE}
849 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
850 {$ENDIF}
851 {$ENDIF}
856 var
861 begin
868 begin
870 begin
874 begin
876 end
877 else
878 begin
886 begin
890 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
898 var
900 {$IF not DEFINED(HEADLESS)}
902 {$ENDIF}
905 {$IFDEF ENABLE_HOLMES}
908 {$ENDIF}
909 begin
910 {$IFDEF HEADLESS}
912 {$ELSE}
913 {$IFDEF ENABLE_HOLMES}
915 begin
919 {$ENDIF}
920 {$ENDIF}
924 begin
928 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
944 {.$IF DEFINED(D2F_DEBUG)}
946 {.$ENDIF}
948 {$IFDEF ENABLE_HOLMES}
952 begin
954 begin
961 begin
963 begin
966 {$IFNDEF HEADLESS}
968 begin
975 {$ELSE}
976 // fuck off, fpc!
979 {$ENDIF}
983 {$ENDIF}
986 begin
988 begin
995 begin
1008 begin
1011 exit;
1014 {EnumDisplayModes();}
1016 {$IFDEF HEADLESS}
1017 //gwin_k8_enable_light_experiments := false;
1021 {$ELSE}
1028 begin
1031 end
1032 else
1033 begin
1038 {$ENDIF}
1043 // Êîìàíäíàÿ ñòðîêà
1046 // Çàïðîñ ÿçûêà
1051 // main loop