author | smxx |
Thu, 29 Apr 2010 19:39:58 +0000 | |
changeset 3379 | f73e0e8e55c2 |
parent 3369 | c7289e42f0ee |
child 3387 | 733f4001b8b9 |
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); |
|
3312 | 247 |
isSoundEnabled:= gameArgs[2] = '1'; |
248 |
isMusicEnabled:= 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 |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
327 |
Randomize(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
328 |
|
3038 | 329 |
uConsts.initModule; |
330 |
uMisc.initModule; |
|
331 |
uConsole.initModule; // MUST happen after uMisc |
|
2947 | 332 |
|
3038 | 333 |
uAI.initModule; |
2947 | 334 |
//uAIActions does not need initialization |
335 |
//uAIAmmoTests does not need initialization |
|
3038 | 336 |
uAIMisc.initModule; |
337 |
uAmmos.initModule; |
|
338 |
uChat.initModule; |
|
339 |
uCollisions.initModule; |
|
2947 | 340 |
//uFloat does not need initialization |
341 |
//uGame does not need initialization |
|
3038 | 342 |
uGears.initModule; |
343 |
uIO.initModule; |
|
344 |
uKeys.initModule; |
|
345 |
uLand.initModule; |
|
2947 | 346 |
//uLandGraphics does not need initialization |
347 |
//uLandObjects does not need initialization |
|
348 |
//uLandTemplates does not need initialization |
|
349 |
//uLandTexture does not need initialization |
|
350 |
//uLocale does not need initialization |
|
3038 | 351 |
uRandom.initModule; |
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
352 |
//uSHA is initialized internally |
3038 | 353 |
uSound.initModule; |
354 |
uStats.initModule; |
|
355 |
uStore.initModule; |
|
356 |
uTeams.initModule; |
|
357 |
uVisualGears.initModule; |
|
358 |
uWorld.initModule; |
|
359 |
uScript.initModule; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
360 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
361 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
362 |
procedure freeEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
363 |
begin |
3038 | 364 |
uWorld.freeModule; |
365 |
uVisualGears.freeModule; //stub |
|
366 |
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
|
367 |
uStore.freeModule; //stub |
3038 | 368 |
uStats.freeModule; //stub |
369 |
uSound.freeModule; //stub |
|
2947 | 370 |
//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
|
371 |
uRandom.freeModule; //stub |
2947 | 372 |
//uLocale does not need to be freed |
373 |
//uLandTemplates does not need to be freed |
|
374 |
//uLandTexture does not need to be freed |
|
375 |
//uLandObjects does not need to be freed |
|
376 |
//uLandGraphics does not need to be freed |
|
3038 | 377 |
uLand.freeModule; |
378 |
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
|
379 |
uIO.freeModule; //stub |
3038 | 380 |
uGears.freeModule; |
2947 | 381 |
//uGame does not need to be freed |
382 |
//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
|
383 |
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
|
384 |
uChat.freeModule; //stub |
3038 | 385 |
uAmmos.freeModule; |
386 |
uAIMisc.freeModule; //stub |
|
2947 | 387 |
//uAIAmmoTests does not need to be freed |
388 |
//uAIActions does not need to be freed |
|
3038 | 389 |
uAI.freeModule; //stub |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
390 |
|
3038 | 391 |
uConsole.freeModule; |
392 |
uConsts.freeModule; //stub |
|
393 |
uScript.freeModule; |
|
3369
c7289e42f0ee
add other controls for map preview, also fix a bug in digest
koda
parents:
3365
diff
changeset
|
394 |
// uMisc closes the debug log. |
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
|
395 |
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
|
396 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
397 |
end; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
398 |
|
2698 | 399 |
///////////////////////// |
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
400 |
procedure GenLandPreview{$IFDEF IPHONEOS}(port: LongInt){$ENDIF}; {$IFDEF HWLIBRARY}cdecl; export;{$ENDIF} |
2698 | 401 |
var Preview: TPreview; |
402 |
begin |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
403 |
{$IFDEF IPHONEOS} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
404 |
initEverything(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
405 |
WriteLnToConsole('Preview connecting on port ' + inttostr(port)); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
406 |
ipcPort:= port; |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
407 |
{$ENDIF} |
2947 | 408 |
InitIPC; |
409 |
IPCWaitPongEvent; |
|
410 |
TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
2698 | 411 |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
412 |
Preview:= GenPreview(); |
2947 | 413 |
WriteLnToConsole('Sending preview...'); |
414 |
SendIPCRaw(@Preview, sizeof(Preview)); |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
415 |
SendIPCRaw(@MaxHedgehogs, sizeof(byte)); |
2947 | 416 |
WriteLnToConsole('Preview sent, disconnect'); |
417 |
CloseIPC(); |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
418 |
{$IFDEF IPHONEOS} |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
419 |
freeEverything(); |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3312
diff
changeset
|
420 |
{$ENDIF} |
2698 | 421 |
end; |
422 |
||
3021 | 423 |
{$IFNDEF HWLIBRARY} |
2698 | 424 |
//////////////////////////////// |
425 |
procedure Resize(w, h: LongInt); |
|
426 |
begin |
|
2947 | 427 |
cScreenWidth:= w; |
428 |
cScreenHeight:= h; |
|
429 |
if cFullScreen then |
|
430 |
ParseCommand('/fullscr 1', true) |
|
431 |
else |
|
432 |
ParseCommand('/fullscr 0', true); |
|
51 | 433 |
end; |
434 |
||
2008 | 435 |
///////////////////// |
436 |
procedure DisplayUsage; |
|
2691 | 437 |
var i: LongInt; |
2008 | 438 |
begin |
2947 | 439 |
WriteLn('Wrong argument format: correct configurations is'); |
440 |
WriteLn(); |
|
441 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
442 |
WriteLn(); |
|
443 |
WriteLn('where [option] must be specified either as'); |
|
444 |
WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
|
445 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
|
446 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
447 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
448 |
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]'); |
|
449 |
WriteLn(); |
|
450 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
|
451 |
Write('parsed command: '); |
|
452 |
for i:=0 to ParamCount do |
|
453 |
Write(ParamStr(i) + ' '); |
|
454 |
WriteLn(); |
|
2008 | 455 |
end; |
456 |
||
51 | 457 |
//////////////////// |
458 |
procedure GetParams; |
|
267 | 459 |
{$IFDEF DEBUGFILE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
460 |
var i: LongInt; |
267 | 461 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
462 |
begin |
267 | 463 |
|
2947 | 464 |
case ParamCount of |
465 |
18: begin |
|
466 |
val(ParamStr(2), cScreenWidth); |
|
467 |
val(ParamStr(3), cScreenHeight); |
|
468 |
cInitWidth:= cScreenWidth; |
|
469 |
cInitHeight:= cScreenHeight; |
|
470 |
cBitsStr:= ParamStr(4); |
|
471 |
val(cBitsStr, cBits); |
|
472 |
val(ParamStr(5), ipcPort); |
|
473 |
cFullScreen:= ParamStr(6) = '1'; |
|
474 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
475 |
cVSyncInUse:= ParamStr(8) = '1'; |
|
476 |
cWeaponTooltips:= ParamStr(9) = '1'; |
|
477 |
cLocaleFName:= ParamStr(10); |
|
478 |
val(ParamStr(11), cInitVolume); |
|
479 |
val(ParamStr(12), cTimerInterval); |
|
480 |
PathPrefix:= ParamStr(13); |
|
481 |
cShowFPS:= ParamStr(14) = '1'; |
|
482 |
cAltDamage:= ParamStr(15) = '1'; |
|
483 |
UserNick:= DecodeBase64(ParamStr(16)); |
|
484 |
isMusicEnabled:= ParamStr(17) = '1'; |
|
485 |
cReducedQuality:= ParamStr(18) = '1'; |
|
486 |
end; |
|
487 |
3: begin |
|
488 |
val(ParamStr(2), ipcPort); |
|
489 |
GameType:= gmtLandPreview; |
|
490 |
if ParamStr(3) <> 'landpreview' then |
|
491 |
OutError(errmsgShouldntRun, true); |
|
492 |
end; |
|
493 |
2: begin |
|
494 |
PathPrefix:= ParamStr(1); |
|
495 |
recordFileName:= ParamStr(2); |
|
496 |
end; |
|
497 |
6: begin |
|
498 |
PathPrefix:= ParamStr(1); |
|
499 |
recordFileName:= ParamStr(2); |
|
2698 | 500 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
501 |
if ParamStr(3) = '--set-video' then |
2947 | 502 |
begin |
503 |
val(ParamStr(4), cScreenWidth); |
|
504 |
val(ParamStr(5), cScreenHeight); |
|
505 |
cInitWidth:= cScreenWidth; |
|
506 |
cInitHeight:= cScreenHeight; |
|
507 |
cBitsStr:= ParamStr(6); |
|
508 |
val(cBitsStr, cBits); |
|
509 |
end |
|
510 |
else |
|
511 |
begin |
|
512 |
if ParamStr(3) = '--set-audio' then |
|
513 |
begin |
|
514 |
val(ParamStr(4), cInitVolume); |
|
515 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
516 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
517 |
end |
|
518 |
else |
|
519 |
begin |
|
520 |
if ParamStr(3) = '--set-other' then |
|
521 |
begin |
|
522 |
cLocaleFName:= ParamStr(4); |
|
523 |
cFullScreen:= ParamStr(5) = '1'; |
|
524 |
cShowFPS:= ParamStr(6) = '1'; |
|
525 |
end |
|
526 |
else GameType:= gmtSyntax; |
|
527 |
end |
|
528 |
end; |
|
529 |
end; |
|
530 |
11: begin |
|
531 |
PathPrefix:= ParamStr(1); |
|
532 |
recordFileName:= ParamStr(2); |
|
2376 | 533 |
|
2947 | 534 |
if ParamStr(3) = '--set-multimedia' then |
535 |
begin |
|
536 |
val(ParamStr(4), cScreenWidth); |
|
537 |
val(ParamStr(5), cScreenHeight); |
|
538 |
cInitWidth:= cScreenWidth; |
|
539 |
cInitHeight:= cScreenHeight; |
|
540 |
cBitsStr:= ParamStr(6); |
|
541 |
val(cBitsStr, cBits); |
|
542 |
val(ParamStr(7), cInitVolume); |
|
543 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
544 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
545 |
cLocaleFName:= ParamStr(10); |
|
546 |
cFullScreen:= ParamStr(11) = '1'; |
|
547 |
end |
|
548 |
else GameType:= gmtSyntax; |
|
549 |
end; |
|
550 |
15: begin |
|
551 |
PathPrefix:= ParamStr(1); |
|
552 |
recordFileName:= ParamStr(2); |
|
553 |
if ParamStr(3) = '--set-everything' then |
|
554 |
begin |
|
555 |
val(ParamStr(4), cScreenWidth); |
|
556 |
val(ParamStr(5), cScreenHeight); |
|
557 |
cInitWidth:= cScreenWidth; |
|
558 |
cInitHeight:= cScreenHeight; |
|
559 |
cBitsStr:= ParamStr(6); |
|
560 |
val(cBitsStr, cBits); |
|
561 |
val(ParamStr(7), cInitVolume); |
|
562 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
563 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
564 |
cLocaleFName:= ParamStr(10); |
|
565 |
cFullScreen:= ParamStr(11) = '1'; |
|
566 |
cAltDamage:= ParamStr(12) = '1'; |
|
567 |
cShowFPS:= ParamStr(13) = '1'; |
|
568 |
val(ParamStr(14), cTimerInterval); |
|
569 |
cReducedQuality:= ParamStr(15) = '1'; |
|
570 |
end |
|
571 |
else GameType:= gmtSyntax; |
|
572 |
end; |
|
573 |
else GameType:= gmtSyntax; |
|
574 |
end; |
|
2630 | 575 |
|
576 |
{$IFDEF DEBUGFILE} |
|
2947 | 577 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
578 |
for i:= 0 to ParamCount do |
|
579 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
2630 | 580 |
{$ENDIF} |
51 | 581 |
end; |
3021 | 582 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
583 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
584 |
/////////////////////////////// m a i n //////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
585 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
586 |
begin |
2947 | 587 |
initEverything(); |
588 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
|
589 |
||
590 |
GetParams(); |
|
2008 | 591 |
|
3078 | 592 |
if GameType = gmtLandPreview then GenLandPreview() |
2947 | 593 |
else if GameType = gmtSyntax then DisplayUsage() |
594 |
else Game(); |
|
595 |
||
3078 | 596 |
freeEverything(); |
2947 | 597 |
if GameType = gmtSyntax then |
598 |
ExitCode:= 1 |
|
599 |
else |
|
600 |
ExitCode:= 0; |
|
2698 | 601 |
{$ENDIF} |
51 | 602 |
end. |