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