author | unc0rr |
Sat, 03 Apr 2010 14:49:45 +0000 | |
changeset 3293 | 3e3a819d5b48 |
parent 3236 | 4ab3917d7d44 |
child 3312 | 6d8f1c76756d |
permissions | -rw-r--r-- |
2947 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3236
4ab3917d7d44
Update (c) lines to 2010 as unc0rr requested - they all had varying values so I just took the first year mentioned, then tacked on -2010
nemo
parents:
3165
diff
changeset
|
3 |
* Copyright (c) 2004-2010 Andrey Korotaev <unC0Rr@gmail.com> |
2947 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
51 | 18 |
|
2599 | 19 |
{$INCLUDE "options.inc"} |
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2586
diff
changeset
|
20 |
|
2800 | 21 |
{$IFDEF WIN32} |
22 |
{$R hwengine.rc} |
|
23 |
{$ENDIF} |
|
24 |
||
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
25 |
{$IFDEF HWLIBRARY} |
2698 | 26 |
unit hwengine; |
27 |
interface |
|
28 |
{$ELSE} |
|
51 | 29 |
program hwengine; |
2698 | 30 |
{$ENDIF} |
3153 | 31 |
uses |
32 |
SDLh in 'SDLh.pas', |
|
2947 | 33 |
uConsts in 'uConsts.pas', |
34 |
uGame in 'uGame.pas', |
|
35 |
uMisc in 'uMisc.pas', |
|
36 |
uStore in 'uStore.pas', |
|
37 |
uWorld in 'uWorld.pas', |
|
38 |
uIO in 'uIO.pas', |
|
39 |
uGears in 'uGears.pas', |
|
40 |
uVisualGears in 'uVisualGears.pas', |
|
41 |
uConsole in 'uConsole.pas', |
|
42 |
uKeys in 'uKeys.pas', |
|
43 |
uTeams in 'uTeams.pas', |
|
44 |
uSound in 'uSound.pas', |
|
45 |
uRandom in 'uRandom.pas', |
|
46 |
uAI in 'uAI.pas', |
|
47 |
uAIMisc in 'uAIMisc.pas', |
|
48 |
uAIAmmoTests in 'uAIAmmoTests.pas', |
|
49 |
uAIActions in 'uAIActions.pas', |
|
50 |
uCollisions in 'uCollisions.pas', |
|
51 |
uLand in 'uLand.pas', |
|
52 |
uLandTemplates in 'uLandTemplates.pas', |
|
53 |
uLandObjects in 'uLandObjects.pas', |
|
54 |
uLandGraphics in 'uLandGraphics.pas', |
|
55 |
uLocale in 'uLocale.pas', |
|
56 |
uAmmos in 'uAmmos.pas', |
|
57 |
uSHA in 'uSHA.pas', |
|
58 |
uFloat in 'uFloat.pas', |
|
59 |
uStats in 'uStats.pas', |
|
60 |
uChat in 'uChat.pas', |
|
61 |
uLandTexture in 'uLandTexture.pas', |
|
62 |
uScript in 'uScript.pas', |
|
63 |
sysutils; |
|
51 | 64 |
|
65 |
// also: GSHandlers.inc |
|
66 |
// CCHandlers.inc |
|
67 |
// HHHandlers.inc |
|
357 | 68 |
// SinTable.inc |
271 | 69 |
// proto.inc |
51 | 70 |
|
3064 | 71 |
var isTerminated: boolean = false; |
72 |
alsoShutdownFrontend: boolean = false; |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
73 |
{$IFDEF HWLIBRARY} |
3021 | 74 |
type arrayofpchar = array[0..7] of PChar; |
75 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
76 |
procedure initEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
77 |
procedure freeEverything; |
51 | 78 |
|
2698 | 79 |
implementation |
80 |
{$ELSE} |
|
51 | 81 |
procedure OnDestroy; forward; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
82 |
procedure freeEverything; forward; |
2698 | 83 |
{$ENDIF} |
51 | 84 |
|
85 |
//////////////////////////////// |
|
371 | 86 |
procedure DoTimer(Lag: LongInt); |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
87 |
{$IFNDEF IPHONEOS} |
2905 | 88 |
var s: shortstring; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
89 |
{$ENDIF} |
51 | 90 |
begin |
2947 | 91 |
inc(RealTicks, Lag); |
564 | 92 |
|
2947 | 93 |
case GameState of |
94 |
gsLandGen: begin |
|
95 |
GenMap; |
|
96 |
GameState:= gsStart; |
|
97 |
end; |
|
98 |
gsStart: begin |
|
99 |
if HasBorder then DisableSomeWeapons; |
|
100 |
AddClouds; |
|
101 |
AssignHHCoords; |
|
102 |
AddMiscGears; |
|
103 |
StoreLoad; |
|
104 |
InitWorld; |
|
105 |
ResetKbd; |
|
106 |
SoundLoad; |
|
107 |
if GameType = gmtSave then |
|
108 |
begin |
|
109 |
isSEBackup:= isSoundEnabled; |
|
110 |
isSoundEnabled:= false |
|
111 |
end; |
|
112 |
FinishProgress; |
|
113 |
PlayMusic; |
|
114 |
SetScale(zoom); |
|
115 |
ScriptCall('onGameStart'); |
|
116 |
GameState:= gsGame; |
|
117 |
end; |
|
118 |
gsConfirm, |
|
119 |
gsGame: begin |
|
120 |
DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
|
121 |
ProcessKbd; |
|
122 |
DoGameTick(Lag); |
|
123 |
ProcessVisualGears(Lag); |
|
124 |
end; |
|
125 |
gsChat: begin |
|
126 |
DrawWorld(Lag); |
|
127 |
DoGameTick(Lag); |
|
128 |
ProcessVisualGears(Lag); |
|
129 |
end; |
|
130 |
gsExit: begin |
|
131 |
isTerminated:= true; |
|
132 |
end; |
|
133 |
end; |
|
564 | 134 |
|
2947 | 135 |
SDL_GL_SwapBuffers(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
136 |
{$IFDEF SDL13} |
2947 | 137 |
SDL_RenderPresent(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
138 |
{$ENDIF} |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2162
diff
changeset
|
139 |
{$IFNDEF IPHONEOS} |
2947 | 140 |
// not going to make captures on the iPhone |
141 |
if flagMakeCapture then |
|
142 |
begin |
|
143 |
flagMakeCapture:= false; |
|
144 |
s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
|
145 |
WriteLnToConsole('Saving ' + s + '...'); |
|
146 |
MakeScreenshot(s); |
|
147 |
//SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
|
148 |
end; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2162
diff
changeset
|
149 |
{$ENDIF} |
51 | 150 |
end; |
151 |
||
152 |
//////////////////// |
|
79 | 153 |
procedure OnDestroy; |
51 | 154 |
begin |
2947 | 155 |
WriteLnToConsole('Freeing resources...'); |
156 |
if isSoundEnabled then ReleaseSound(); |
|
157 |
StoreRelease(); |
|
3045 | 158 |
FreeGearsList(); |
3053 | 159 |
FreeVisualGears(); |
2947 | 160 |
FreeLand(); |
161 |
ControllerClose(); |
|
162 |
SendKB(); |
|
163 |
CloseIPC(); |
|
164 |
TTF_Quit(); |
|
165 |
SDL_Quit(); |
|
3063 | 166 |
isTerminated:= false; |
51 | 167 |
end; |
168 |
||
169 |
/////////////////// |
|
2698 | 170 |
procedure MainLoop; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
171 |
var PrevTime, CurrTime: Longword; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
172 |
{$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF} |
2698 | 173 |
begin |
2947 | 174 |
PrevTime:= SDL_GetTicks; |
3063 | 175 |
while isTerminated = false do |
176 |
begin |
|
2698 | 177 |
{$IFNDEF IPHONEOS} |
178 |
// have to remove this cycle because otherwise it segfaults at exit |
|
2947 | 179 |
while SDL_PollEvent(@event) <> 0 do |
180 |
begin |
|
181 |
case event.type_ of |
|
182 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
|
2698 | 183 |
{$IFDEF SDL13} |
2947 | 184 |
SDL_WINDOWEVENT: |
2698 | 185 |
{$ELSE} |
2947 | 186 |
SDL_ACTIVEEVENT: |
2569 | 187 |
{$ENDIF} |
2947 | 188 |
if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
189 |
cHasFocus:= event.active.gain = 1; |
|
190 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
|
191 |
SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
|
192 |
SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
|
193 |
SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
|
194 |
SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
|
195 |
SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
|
196 |
SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
|
197 |
SDL_QUITEV: isTerminated:= true |
|
198 |
end; // end case event.type_ of |
|
199 |
end; // end while SDL_PollEvent(@event) <> 0 do |
|
2390 | 200 |
{$ENDIF} |
3063 | 201 |
if isTerminated = false then |
2947 | 202 |
begin |
3063 | 203 |
CurrTime:= SDL_GetTicks; |
204 |
if PrevTime + cTimerInterval <= CurrTime then |
|
205 |
begin |
|
206 |
DoTimer(CurrTime - PrevTime); |
|
207 |
PrevTime:= CurrTime |
|
208 |
end |
|
209 |
else SDL_Delay(1); |
|
210 |
IPCCheckSock(); |
|
211 |
end; |
|
212 |
end; |
|
2698 | 213 |
end; |
214 |
||
215 |
///////////////////////// |
|
216 |
procedure ShowMainWindow; |
|
217 |
begin |
|
2947 | 218 |
if cFullScreen then ParseCommand('fullscr 1', true) |
219 |
else ParseCommand('fullscr 0', true); |
|
220 |
SDL_ShowCursor(0) |
|
2698 | 221 |
end; |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
222 |
|
2698 | 223 |
/////////////// |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
224 |
{$IFDEF HWLIBRARY} |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
225 |
procedure Game(gameArgs: arrayofpchar); cdecl; export; |
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
226 |
{$ELSE} |
3064 | 227 |
procedure Game; |
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
228 |
{$ENDIF} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
229 |
var p: TPathType; |
2947 | 230 |
s: shortstring; |
2698 | 231 |
begin |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
232 |
{$IFDEF HWLIBRARY} |
3049 | 233 |
initEverything(); |
2947 | 234 |
Randomize(); |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
235 |
|
2947 | 236 |
cBits:= 32; |
237 |
cFullScreen:= false; |
|
238 |
cVSyncInUse:= true; |
|
239 |
cTimerInterval:= 8; |
|
240 |
PathPrefix:= 'Data'; |
|
241 |
cReducedQuality:= false; |
|
242 |
cShowFPS:= true; |
|
243 |
cInitVolume:= 100; |
|
2702
48fc46a922fd
rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents:
2699
diff
changeset
|
244 |
|
2947 | 245 |
UserNick:= gameArgs[0]; |
246 |
val(gameArgs[1], ipcPort); |
|
3025 | 247 |
isSoundEnabled:= false;//gameArgs[2] = '1'; |
248 |
isMusicEnabled:= false;//gameArgs[3] = '1'; |
|
2947 | 249 |
cLocaleFName:= gameArgs[4]; |
250 |
cAltDamage:= gameArgs[5] = '1'; |
|
3021 | 251 |
val(gameArgs[6], cScreenHeight); |
252 |
val(gameArgs[7], cScreenWidth); |
|
253 |
cInitHeight:= cScreenHeight; |
|
254 |
cInitWidth:= cScreenWidth; |
|
2600 | 255 |
{$ENDIF} |
2698 | 256 |
|
2947 | 257 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
258 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
|
259 |
||
260 |
WriteToConsole('Init SDL... '); |
|
261 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
262 |
WriteLnToConsole(msgOK); |
|
2698 | 263 |
|
2947 | 264 |
SDL_EnableUNICODE(1); |
2698 | 265 |
|
2947 | 266 |
WriteToConsole('Init SDL_ttf... '); |
267 |
SDLTry(TTF_Init() <> -1, true); |
|
268 |
WriteLnToConsole(msgOK); |
|
2698 | 269 |
|
3162 | 270 |
{$IFDEF WIN32} |
271 |
s:= SDL_getenv('SDL_VIDEO_CENTERED'); |
|
3153 | 272 |
SDL_putenv('SDL_VIDEO_CENTERED=1'); |
2947 | 273 |
ShowMainWindow(); |
3162 | 274 |
SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s)); |
275 |
{$ELSE} |
|
3154 | 276 |
ShowMainWindow(); |
3162 | 277 |
{$ENDIF} |
2698 | 278 |
|
2947 | 279 |
AddProgress(); |
2698 | 280 |
|
2947 | 281 |
ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
282 |
InitKbdKeyTable(); |
|
2698 | 283 |
|
2947 | 284 |
if recordFileName = '' then |
285 |
InitIPC; |
|
286 |
WriteLnToConsole(msgGettingConfig); |
|
2698 | 287 |
|
2947 | 288 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english |
289 |
if cLocaleFName <> 'en.txt' then |
|
2719 | 290 |
begin |
291 |
// Try two letter locale first before trying specific locale overrides |
|
2722 | 292 |
if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then |
293 |
LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt'); |
|
2947 | 294 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
2719 | 295 |
end; |
2698 | 296 |
|
2947 | 297 |
if recordFileName = '' then |
298 |
SendIPCAndWaitReply('C') // ask for game config |
|
299 |
else |
|
300 |
LoadRecordFromFile(recordFileName); |
|
2698 | 301 |
|
2947 | 302 |
ScriptOnGameInit; |
2786 | 303 |
|
2947 | 304 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
305 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
306 |
||
307 |
InitTeams(); |
|
308 |
AssignStores(); |
|
2698 | 309 |
|
2947 | 310 |
if isSoundEnabled then |
311 |
InitSound(); |
|
2590 | 312 |
|
2947 | 313 |
isDeveloperMode:= false; |
2698 | 314 |
|
2947 | 315 |
TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
2698 | 316 |
|
2947 | 317 |
ParseCommand('rotmask', true); |
2698 | 318 |
|
2947 | 319 |
MainLoop(); |
320 |
OnDestroy(); |
|
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3162
diff
changeset
|
321 |
{$IFDEF HWLIBRARY}freeEverything();{$ENDIF} |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3162
diff
changeset
|
322 |
if alsoShutdownFrontend then halt; |
2698 | 323 |
end; |
2590 | 324 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
325 |
procedure initEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
326 |
begin |
3038 | 327 |
uConsts.initModule; |
328 |
uMisc.initModule; |
|
329 |
uConsole.initModule; // MUST happen after uMisc |
|
2947 | 330 |
|
3038 | 331 |
uAI.initModule; |
2947 | 332 |
//uAIActions does not need initialization |
333 |
//uAIAmmoTests does not need initialization |
|
3038 | 334 |
uAIMisc.initModule; |
335 |
uAmmos.initModule; |
|
336 |
uChat.initModule; |
|
337 |
uCollisions.initModule; |
|
2947 | 338 |
//uFloat does not need initialization |
339 |
//uGame does not need initialization |
|
3038 | 340 |
uGears.initModule; |
341 |
uIO.initModule; |
|
342 |
uKeys.initModule; |
|
343 |
uLand.initModule; |
|
2947 | 344 |
//uLandGraphics does not need initialization |
345 |
//uLandObjects does not need initialization |
|
346 |
//uLandTemplates does not need initialization |
|
347 |
//uLandTexture does not need initialization |
|
348 |
//uLocale does not need initialization |
|
3038 | 349 |
uRandom.initModule; |
2947 | 350 |
//uSHA does not need initialization |
3038 | 351 |
uSound.initModule; |
352 |
uStats.initModule; |
|
353 |
uStore.initModule; |
|
354 |
uTeams.initModule; |
|
355 |
uVisualGears.initModule; |
|
356 |
uWorld.initModule; |
|
357 |
uScript.initModule; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
358 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
359 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
360 |
procedure freeEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
361 |
begin |
3038 | 362 |
uWorld.freeModule; |
363 |
uVisualGears.freeModule; //stub |
|
364 |
uTeams.freeModule; |
|
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
365 |
uStore.freeModule; //stub |
3038 | 366 |
uStats.freeModule; //stub |
367 |
uSound.freeModule; //stub |
|
2947 | 368 |
//uSHA does not need to be freed |
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
369 |
uRandom.freeModule; //stub |
2947 | 370 |
//uLocale does not need to be freed |
371 |
//uLandTemplates does not need to be freed |
|
372 |
//uLandTexture does not need to be freed |
|
373 |
//uLandObjects does not need to be freed |
|
374 |
//uLandGraphics does not need to be freed |
|
3038 | 375 |
uLand.freeModule; |
376 |
uKeys.freeModule; //stub |
|
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
377 |
uIO.freeModule; //stub |
3038 | 378 |
uGears.freeModule; |
2947 | 379 |
//uGame does not need to be freed |
380 |
//uFloat does not need to be freed |
|
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
381 |
uCollisions.freeModule; //stub |
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
382 |
uChat.freeModule; //stub |
3038 | 383 |
uAmmos.freeModule; |
384 |
uAIMisc.freeModule; //stub |
|
2947 | 385 |
//uAIAmmoTests does not need to be freed |
386 |
//uAIActions does not need to be freed |
|
3038 | 387 |
uAI.freeModule; //stub |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
388 |
|
3038 | 389 |
uConsole.freeModule; |
390 |
uConsts.freeModule; //stub |
|
391 |
uScript.freeModule; |
|
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
392 |
// uMisc closes the debug log. |
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
393 |
uMisc.freeModule; |
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset
|
394 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
395 |
end; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
396 |
|
2698 | 397 |
///////////////////////// |
398 |
procedure GenLandPreview; |
|
399 |
var Preview: TPreview; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
400 |
h: byte; |
2698 | 401 |
begin |
2947 | 402 |
InitIPC; |
403 |
IPCWaitPongEvent; |
|
404 |
TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
2698 | 405 |
|
2947 | 406 |
Preview:= GenPreview; |
407 |
WriteLnToConsole('Sending preview...'); |
|
408 |
SendIPCRaw(@Preview, sizeof(Preview)); |
|
409 |
h:= MaxHedgehogs; |
|
410 |
SendIPCRaw(@h, sizeof(h)); |
|
411 |
WriteLnToConsole('Preview sent, disconnect'); |
|
412 |
CloseIPC(); |
|
2698 | 413 |
end; |
414 |
||
3021 | 415 |
{$IFNDEF HWLIBRARY} |
2698 | 416 |
//////////////////////////////// |
417 |
procedure Resize(w, h: LongInt); |
|
418 |
begin |
|
2947 | 419 |
cScreenWidth:= w; |
420 |
cScreenHeight:= h; |
|
421 |
if cFullScreen then |
|
422 |
ParseCommand('/fullscr 1', true) |
|
423 |
else |
|
424 |
ParseCommand('/fullscr 0', true); |
|
51 | 425 |
end; |
426 |
||
2008 | 427 |
///////////////////// |
428 |
procedure DisplayUsage; |
|
2691 | 429 |
var i: LongInt; |
2008 | 430 |
begin |
2947 | 431 |
WriteLn('Wrong argument format: correct configurations is'); |
432 |
WriteLn(); |
|
433 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
434 |
WriteLn(); |
|
435 |
WriteLn('where [option] must be specified either as'); |
|
436 |
WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
|
437 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
|
438 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
439 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
440 |
WriteLn(' --set-everything [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); |
|
441 |
WriteLn(); |
|
442 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
|
443 |
Write('parsed command: '); |
|
444 |
for i:=0 to ParamCount do |
|
445 |
Write(ParamStr(i) + ' '); |
|
446 |
WriteLn(); |
|
2008 | 447 |
end; |
448 |
||
51 | 449 |
//////////////////// |
450 |
procedure GetParams; |
|
267 | 451 |
{$IFDEF DEBUGFILE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
452 |
var i: LongInt; |
267 | 453 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
454 |
begin |
267 | 455 |
|
2947 | 456 |
case ParamCount of |
457 |
18: begin |
|
458 |
val(ParamStr(2), cScreenWidth); |
|
459 |
val(ParamStr(3), cScreenHeight); |
|
460 |
cInitWidth:= cScreenWidth; |
|
461 |
cInitHeight:= cScreenHeight; |
|
462 |
cBitsStr:= ParamStr(4); |
|
463 |
val(cBitsStr, cBits); |
|
464 |
val(ParamStr(5), ipcPort); |
|
465 |
cFullScreen:= ParamStr(6) = '1'; |
|
466 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
467 |
cVSyncInUse:= ParamStr(8) = '1'; |
|
468 |
cWeaponTooltips:= ParamStr(9) = '1'; |
|
469 |
cLocaleFName:= ParamStr(10); |
|
470 |
val(ParamStr(11), cInitVolume); |
|
471 |
val(ParamStr(12), cTimerInterval); |
|
472 |
PathPrefix:= ParamStr(13); |
|
473 |
cShowFPS:= ParamStr(14) = '1'; |
|
474 |
cAltDamage:= ParamStr(15) = '1'; |
|
475 |
UserNick:= DecodeBase64(ParamStr(16)); |
|
476 |
isMusicEnabled:= ParamStr(17) = '1'; |
|
477 |
cReducedQuality:= ParamStr(18) = '1'; |
|
478 |
end; |
|
479 |
3: begin |
|
480 |
val(ParamStr(2), ipcPort); |
|
481 |
GameType:= gmtLandPreview; |
|
482 |
if ParamStr(3) <> 'landpreview' then |
|
483 |
OutError(errmsgShouldntRun, true); |
|
484 |
end; |
|
485 |
2: begin |
|
486 |
PathPrefix:= ParamStr(1); |
|
487 |
recordFileName:= ParamStr(2); |
|
488 |
end; |
|
489 |
6: begin |
|
490 |
PathPrefix:= ParamStr(1); |
|
491 |
recordFileName:= ParamStr(2); |
|
2698 | 492 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
493 |
if ParamStr(3) = '--set-video' then |
2947 | 494 |
begin |
495 |
val(ParamStr(4), cScreenWidth); |
|
496 |
val(ParamStr(5), cScreenHeight); |
|
497 |
cInitWidth:= cScreenWidth; |
|
498 |
cInitHeight:= cScreenHeight; |
|
499 |
cBitsStr:= ParamStr(6); |
|
500 |
val(cBitsStr, cBits); |
|
501 |
end |
|
502 |
else |
|
503 |
begin |
|
504 |
if ParamStr(3) = '--set-audio' then |
|
505 |
begin |
|
506 |
val(ParamStr(4), cInitVolume); |
|
507 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
508 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
509 |
end |
|
510 |
else |
|
511 |
begin |
|
512 |
if ParamStr(3) = '--set-other' then |
|
513 |
begin |
|
514 |
cLocaleFName:= ParamStr(4); |
|
515 |
cFullScreen:= ParamStr(5) = '1'; |
|
516 |
cShowFPS:= ParamStr(6) = '1'; |
|
517 |
end |
|
518 |
else GameType:= gmtSyntax; |
|
519 |
end |
|
520 |
end; |
|
521 |
end; |
|
522 |
11: begin |
|
523 |
PathPrefix:= ParamStr(1); |
|
524 |
recordFileName:= ParamStr(2); |
|
2376 | 525 |
|
2947 | 526 |
if ParamStr(3) = '--set-multimedia' then |
527 |
begin |
|
528 |
val(ParamStr(4), cScreenWidth); |
|
529 |
val(ParamStr(5), cScreenHeight); |
|
530 |
cInitWidth:= cScreenWidth; |
|
531 |
cInitHeight:= cScreenHeight; |
|
532 |
cBitsStr:= ParamStr(6); |
|
533 |
val(cBitsStr, cBits); |
|
534 |
val(ParamStr(7), cInitVolume); |
|
535 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
536 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
537 |
cLocaleFName:= ParamStr(10); |
|
538 |
cFullScreen:= ParamStr(11) = '1'; |
|
539 |
end |
|
540 |
else GameType:= gmtSyntax; |
|
541 |
end; |
|
542 |
15: begin |
|
543 |
PathPrefix:= ParamStr(1); |
|
544 |
recordFileName:= ParamStr(2); |
|
545 |
if ParamStr(3) = '--set-everything' then |
|
546 |
begin |
|
547 |
val(ParamStr(4), cScreenWidth); |
|
548 |
val(ParamStr(5), cScreenHeight); |
|
549 |
cInitWidth:= cScreenWidth; |
|
550 |
cInitHeight:= cScreenHeight; |
|
551 |
cBitsStr:= ParamStr(6); |
|
552 |
val(cBitsStr, cBits); |
|
553 |
val(ParamStr(7), cInitVolume); |
|
554 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
555 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
556 |
cLocaleFName:= ParamStr(10); |
|
557 |
cFullScreen:= ParamStr(11) = '1'; |
|
558 |
cAltDamage:= ParamStr(12) = '1'; |
|
559 |
cShowFPS:= ParamStr(13) = '1'; |
|
560 |
val(ParamStr(14), cTimerInterval); |
|
561 |
cReducedQuality:= ParamStr(15) = '1'; |
|
562 |
end |
|
563 |
else GameType:= gmtSyntax; |
|
564 |
end; |
|
565 |
else GameType:= gmtSyntax; |
|
566 |
end; |
|
2630 | 567 |
|
568 |
{$IFDEF DEBUGFILE} |
|
2947 | 569 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
570 |
for i:= 0 to ParamCount do |
|
571 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
2630 | 572 |
{$ENDIF} |
51 | 573 |
end; |
3021 | 574 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
575 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
576 |
/////////////////////////////// m a i n //////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
577 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
578 |
begin |
2947 | 579 |
initEverything(); |
580 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
|
581 |
||
582 |
GetParams(); |
|
583 |
Randomize(); |
|
2008 | 584 |
|
3078 | 585 |
if GameType = gmtLandPreview then GenLandPreview() |
2947 | 586 |
else if GameType = gmtSyntax then DisplayUsage() |
587 |
else Game(); |
|
588 |
||
3078 | 589 |
freeEverything(); |
2947 | 590 |
if GameType = gmtSyntax then |
591 |
ExitCode:= 1 |
|
592 |
else |
|
593 |
ExitCode:= 0; |
|
2698 | 594 |
{$ENDIF} |
51 | 595 |
end. |