-
Notifications
You must be signed in to change notification settings - Fork 5
/
i_main.pas
177 lines (156 loc) · 4.54 KB
/
i_main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//
// DESCRIPTION:
// Main program, simply calls D_DoomMain high level loop.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
{$WARN SYMBOL_DEPRECATED OFF}
unit i_main;
interface
uses
Windows;
var
hMainWnd: HWND = 0;
windowxpos: integer = 0;
windowypos: integer = 0;
const
WINDOW_STYLE_FS = (WS_OVERLAPPED);
WINDOW_STYLE_W = (WS_POPUPWINDOW or WS_TABSTOP or WS_VISIBLE or WS_SYSMENU or WS_CAPTION);
//==============================================================================
//
// DoomMain
//
//==============================================================================
procedure DoomMain;
implementation
uses
d_fpc,
Messages,
doomdef,
i_input,
i_system,
d_main;
//==============================================================================
//
// WindowProc
//
//==============================================================================
function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
begin
if not I_GameFinished then
begin
case Msg of
WM_SETCURSOR:
begin
SetCursor(0);
end;
WM_SYSCOMMAND:
begin
if (wParam = SC_SCREENSAVE) or (wParam = SC_MINIMIZE) then
begin
result := 0;
exit;
end;
if fullscreen and (wParam = SC_TASKLIST) then
begin
result := 0;
exit;
end;
end;
WM_SIZE:
begin
result := 0;
exit;
end;
WM_ACTIVATE:
begin
InBackground := (LOWORD(wparam) = WA_INACTIVE) or (HIWORD(wparam) <> 0);
I_SynchronizeInput(not InBackground);
end;
WM_CLOSE:
begin
result := 0; // Preserve closing window by pressing Alt + F4
exit;
end;
WM_DESTROY:
begin
result := 0;
ShowWindow(hWnd, SW_HIDE);
I_Destroy(0);
exit;
end;
end;
end;
result := DefWindowProc(hWnd, Msg, WParam, LParam);
end;
//==============================================================================
//
// DoomMain
//
//==============================================================================
procedure DoomMain;
var
WindowClass: TWndClass;
exStyle: integer;
caption: string;
begin
I_SetDPIAwareness;
ZeroMemory(@WindowClass, SizeOf(WindowClass));
WindowClass.lpfnWndProc := @WindowProc;
WindowClass.hbrBackground := GetStockObject(DKGRAY_BRUSH);
WindowClass.lpszClassName := 'FPCDOOM';
if HPrevInst = 0 then
begin
WindowClass.hInstance := HInstance;
WindowClass.hIcon := LoadIcon(HInstance, 'MAINICON');
WindowClass.hCursor := 0;
WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
if RegisterClass(WindowClass) = 0 then
halt(1);
end;
if fullscreen then
exStyle := WS_EX_TOPMOST
else
exStyle := 0;
caption := D_Version + ' - ' + D_VersionBuilt;
hMainWnd := CreateWindowEx(
exStyle,
WindowClass.lpszClassName,
PAnsiChar(caption),
WINDOW_STYLE_FS,
windowxpos, windowypos, 0, 0,
0,
0,
HInstance,
nil);
SetWindowLong(hMainWnd, GWL_STYLE, 0);
SetCursor(0);
D_DoomMain;
end;
end.