395f44e415144e1a9aefedc2fee5355f3383389a
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 {$IFDEF USE_NANOGL}
55 nanoGL,
56 {$ELSE}
58 {$ENDIF}
67 const
70 var
75 {$IF not DEFINED(HEADLESS)}
78 {$ENDIF}
84 {$IFNDEF WINDOWS}
87 {$ENDIF}
91 begin
92 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
95 begin
96 {$IFDEF USE_NANOGL}
97 nanoGL_Destroy;
98 {$ENDIF USE_NANOGL}
107 {$IF not DEFINED(HEADLESS)}
108 var
112 {$ENDIF}
113 begin
114 {$IF not DEFINED(HEADLESS)}
120 if gFullscreen then wFlags := wFlags {or SDL_WINDOW_FULLSCREEN} else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
121 if (not gFullscreen) and (not preserveGL) and gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED else gWinMaximized := false;
124 begin
131 begin
135 end
136 else
137 begin
138 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight)+': '+IntToStr(cmode.w)+'x'+IntToStr(cmode.h), TMsgType.Notify);
145 begin
146 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
147 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
152 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
153 //SDL_SetWindowFullscreen(h_Wnd, 0);
154 end
155 else
156 begin
158 h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
169 begin
174 begin
175 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw)+'x'+IntToStr(nh)+': '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight), TMsgType.Notify);
178 end
179 else
180 begin
181 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
186 if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
187 {$ENDIF}
194 var
197 begin
204 begin
222 begin
228 begin
229 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
232 {$IF not DEFINED(HEADLESS)}
239 {$ENDIF}
244 {$IF not DEFINED(HEADLESS)}
245 var
247 {$ENDIF}
248 begin
250 {$IF not DEFINED(HEADLESS)}
254 begin
262 begin
270 begin
274 {$ENDIF}
279 var
281 begin
287 SDL_WINDOWEVENT_MOVED:
288 begin
290 begin
296 SDL_WINDOWEVENT_MINIMIZED:
297 begin
300 begin
304 begin
312 SDL_WINDOWEVENT_RESIZED:
313 begin
314 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth, gScreenHeight, Integer(ev.data1), Integer(ev.data2)]);
315 {if (gFullscreen) then
316 begin
317 e_LogWriteln(' fullscreen fix applied.');
318 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
319 begin
320 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
321 end;
322 end
323 else}
324 begin
331 begin
333 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev.data1) + 'x' + IntToStr(ev.data2), TMsgType.Notify);
337 SDL_WINDOWEVENT_EXPOSED:
340 SDL_WINDOWEVENT_MAXIMIZED:
341 begin
344 begin
350 begin
353 begin
360 SDL_WINDOWEVENT_RESTORED:
361 begin
364 begin
371 begin
377 SDL_WINDOWEVENT_FOCUS_GAINED:
378 begin
380 //e_WriteLog('window gained focus!', MSG_NOTIFY);
383 SDL_WINDOWEVENT_FOCUS_LOST:
384 begin
387 //e_WriteLog('window lost focus!', MSG_NOTIFY);
392 begin
394 begin
400 begin
401 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
406 begin
415 end
417 begin
419 begin
420 //e_WriteLog('activating window', MSG_NOTIFY);
424 begin
425 //e_WriteLog('activating sounds', MSG_NOTIFY);
430 begin
443 var
447 begin
451 SDL_WINDOWEVENT:
454 SDL_QUITEV:
455 begin
457 begin
459 begin
462 end
463 else
464 begin
472 begin
475 {$IF not DEFINED(HEADLESS)}
477 begin
478 // event eaten, but...
480 exit;
482 {$ENDIF}
487 {$IF not DEFINED(HEADLESS)}
490 {$ENDIF}
492 SDL_TEXTINPUT:
493 begin
500 // other key presses and joysticks are handled in e_input
506 begin
507 {$IF not DEFINED(HEADLESS)}
509 {$ENDIF}
514 begin
520 {$IF not DEFINED(HEADLESS)}
522 {$ENDIF}
526 begin
529 exit;
532 {$IF not DEFINED(HEADLESS)}
538 {$IFDEF USE_NANOGL}
540 begin
543 exit;
545 {$ENDIF}
548 {$ENDIF}
557 {$IFDEF WINDOWS}
558 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
560 var
562 begin
567 {$ELSE}
569 var
572 begin
575 begin
578 end
579 else
580 begin
582 begin
583 // overflow, increment overflow ;-)
592 {$ENDIF}
596 begin
602 var
604 begin
610 var
614 var
618 begin
623 begin
630 begin
632 exit;
636 begin
638 begin
640 end
641 else
642 begin
645 begin
652 begin
654 begin
657 end
658 else
659 begin
671 begin
673 end
674 else
675 begin
676 if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then g_Net_Client_UpdateWhileLoading();
684 var
686 begin
690 begin
699 var
701 begin
710 begin
720 begin
723 begin
728 end
729 else
730 begin
739 begin
745 begin
747 exit;
750 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
752 begin
755 begin
759 end
760 else
761 begin
770 begin
776 {$IF not DEFINED(HEADLESS)}
777 var
779 {$ENDIF}
780 begin
781 {$IF not DEFINED(HEADLESS)}
784 begin
786 end
787 else
788 begin
789 if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
791 {$ENDIF}
796 begin
797 {$IF not DEFINED(HEADLESS)}
798 {$IFDEF USE_NANOGL}
802 {$ELSE}
810 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
811 {$ENDIF}
812 {$ENDIF}
817 var
822 begin
829 begin
831 begin
835 begin
837 end
838 else
839 begin
847 begin
851 if found and ((exts[Length(name)] = #0) or (exts[Length(name)] = ' ')) then begin result := true; exit; end;
859 var
861 {$IF not DEFINED(HEADLESS)}
863 {$ENDIF}
868 begin
869 {$IFDEF HEADLESS}
871 {$ELSE}
873 begin
877 {$ENDIF}
881 begin
885 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
901 {.$IF DEFINED(D2F_DEBUG)}
903 {.$ENDIF}
908 begin
910 begin
917 begin
919 begin
922 {$IFNDEF HEADLESS}
924 begin
931 {$ELSE}
932 // fuck off, fpc!
935 {$ENDIF}
941 begin
943 begin
950 begin
963 begin
966 exit;
969 {EnumDisplayModes();}
971 {$IFDEF HEADLESS}
972 //gwin_k8_enable_light_experiments := false;
976 {$ELSE}
982 begin
985 end
986 else
987 begin
992 {$ENDIF}
997 // Êîìàíäíàÿ ñòðîêà
1000 // Çàïðîñ ÿçûêà
1005 // main loop