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