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