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