3958d24d12df79b518b6dc351942a53d487acc52
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
470 begin
474 SDL_WINDOWEVENT:
477 SDL_QUITEV:
478 begin
480 begin
482 begin
485 end
486 else
487 begin
495 begin
500 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
502 begin
503 // event eaten, but...
505 exit;
507 {$ENDIF}
512 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
515 {$ENDIF}
517 SDL_TEXTINPUT:
518 begin
528 // other key presses and joysticks are handled in e_input
534 begin
535 {$IF not DEFINED(HEADLESS)}
537 {$ENDIF}
542 begin
548 {$IF not DEFINED(HEADLESS)}
550 {$ENDIF}
554 begin
557 exit;
560 {$IF not DEFINED(HEADLESS)}
563 {$IFDEF ENABLE_HOLMES}
566 {$ENDIF}
568 {$IFDEF USE_NANOGL}
570 begin
573 exit;
575 {$ENDIF}
576 {$IFDEF USE_NOGL}
577 nogl_Init;
578 {$ENDIF}
579 {$IFDEF ENABLE_HOLMES}
581 {$ENDIF}
583 {$ENDIF}
592 {$IFDEF WINDOWS}
593 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
595 var
597 begin
602 {$ELSE}
604 var
607 begin
610 begin
613 end
614 else
615 begin
617 begin
618 // overflow, increment overflow ;-)
627 {$ENDIF}
631 begin
637 var
639 begin
645 var
649 var
653 begin
658 begin
665 begin
667 exit;
671 begin
673 begin
675 end
676 else
677 begin
680 begin
687 begin
689 begin
692 end
693 else
694 begin
706 begin
708 end
709 else
710 begin
711 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
719 var
721 begin
725 begin
734 var
736 begin
745 begin
755 begin
758 begin
763 end
764 else
765 begin
774 begin
780 begin
782 exit;
785 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
787 begin
790 begin
794 end
795 else
796 begin
805 begin
811 {$IF not DEFINED(HEADLESS)}
812 var
814 {$ENDIF}
815 begin
816 {$IF not DEFINED(HEADLESS)}
819 begin
821 end
822 else
823 begin
824 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
826 {$ENDIF}
831 begin
832 {$IF not DEFINED(HEADLESS)}
833 {$IFDEF USE_GLES1}
837 {$ELSE}
845 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
846 {$ENDIF}
847 {$ENDIF}
852 var
857 begin
864 begin
866 begin
870 begin
872 end
873 else
874 begin
882 begin
886 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
894 var
896 {$IF not DEFINED(HEADLESS)}
898 {$ENDIF}
901 {$IFDEF ENABLE_HOLMES}
904 {$ENDIF}
905 begin
906 {$IFDEF HEADLESS}
908 {$ELSE}
909 {$IFDEF ENABLE_HOLMES}
911 begin
915 {$ENDIF}
916 {$ENDIF}
920 begin
924 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
940 {.$IF DEFINED(D2F_DEBUG)}
942 {.$ENDIF}
944 {$IFDEF ENABLE_HOLMES}
948 begin
950 begin
957 begin
959 begin
962 {$IFNDEF HEADLESS}
964 begin
971 {$ELSE}
972 // fuck off, fpc!
975 {$ENDIF}
979 {$ENDIF}
982 begin
984 begin
991 begin
1004 begin
1007 exit;
1010 {EnumDisplayModes();}
1012 {$IFDEF HEADLESS}
1013 //gwin_k8_enable_light_experiments := false;
1017 {$ELSE}
1024 begin
1027 end
1028 else
1029 begin
1034 {$ENDIF}
1039 // Êîìàíäíàÿ ñòðîêà
1042 // Çàïðîñ ÿçûêà
1047 // main loop