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