author | smxx |
Sat, 27 Mar 2010 17:22:33 +0000 | |
changeset 3115 | 831bd0f7050d |
parent 3078 | 07d4ca3afce3 |
child 3153 | adfe8a91658f |
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 |
sysutils; |
|
51 | 63 |
|
64 |
// also: GSHandlers.inc |
|
65 |
// CCHandlers.inc |
|
66 |
// HHHandlers.inc |
|
357 | 67 |
// SinTable.inc |
271 | 68 |
// proto.inc |
51 | 69 |
|
3064 | 70 |
var isTerminated: boolean = false; |
71 |
alsoShutdownFrontend: boolean = false; |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
72 |
{$IFDEF HWLIBRARY} |
3021 | 73 |
type arrayofpchar = array[0..7] of PChar; |
74 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
75 |
procedure initEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
76 |
procedure freeEverything; |
51 | 77 |
|
2698 | 78 |
implementation |
79 |
{$ELSE} |
|
51 | 80 |
procedure OnDestroy; forward; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
81 |
procedure freeEverything; forward; |
2698 | 82 |
{$ENDIF} |
51 | 83 |
|
84 |
//////////////////////////////// |
|
371 | 85 |
procedure DoTimer(Lag: LongInt); |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
86 |
{$IFNDEF IPHONEOS} |
2905 | 87 |
var s: shortstring; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
88 |
{$ENDIF} |
51 | 89 |
begin |
2947 | 90 |
inc(RealTicks, Lag); |
564 | 91 |
|
2947 | 92 |
case GameState of |
93 |
gsLandGen: begin |
|
94 |
GenMap; |
|
95 |
GameState:= gsStart; |
|
96 |
end; |
|
97 |
gsStart: begin |
|
98 |
if HasBorder then DisableSomeWeapons; |
|
99 |
AddClouds; |
|
100 |
AssignHHCoords; |
|
101 |
AddMiscGears; |
|
102 |
StoreLoad; |
|
103 |
InitWorld; |
|
104 |
ResetKbd; |
|
105 |
SoundLoad; |
|
106 |
if GameType = gmtSave then |
|
107 |
begin |
|
108 |
isSEBackup:= isSoundEnabled; |
|
109 |
isSoundEnabled:= false |
|
110 |
end; |
|
111 |
FinishProgress; |
|
112 |
PlayMusic; |
|
113 |
SetScale(zoom); |
|
114 |
ScriptCall('onGameStart'); |
|
115 |
GameState:= gsGame; |
|
116 |
end; |
|
117 |
gsConfirm, |
|
118 |
gsGame: begin |
|
119 |
DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
|
120 |
ProcessKbd; |
|
121 |
DoGameTick(Lag); |
|
122 |
ProcessVisualGears(Lag); |
|
123 |
end; |
|
124 |
gsChat: begin |
|
125 |
DrawWorld(Lag); |
|
126 |
DoGameTick(Lag); |
|
127 |
ProcessVisualGears(Lag); |
|
128 |
end; |
|
129 |
gsExit: begin |
|
130 |
isTerminated:= true; |
|
131 |
end; |
|
132 |
end; |
|
564 | 133 |
|
2947 | 134 |
SDL_GL_SwapBuffers(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
135 |
{$IFDEF SDL13} |
2947 | 136 |
SDL_RenderPresent(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
137 |
{$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
|
138 |
{$IFNDEF IPHONEOS} |
2947 | 139 |
// not going to make captures on the iPhone |
140 |
if flagMakeCapture then |
|
141 |
begin |
|
142 |
flagMakeCapture:= false; |
|
143 |
s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
|
144 |
WriteLnToConsole('Saving ' + s + '...'); |
|
145 |
MakeScreenshot(s); |
|
146 |
//SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
|
147 |
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
|
148 |
{$ENDIF} |
51 | 149 |
end; |
150 |
||
151 |
//////////////////// |
|
79 | 152 |
procedure OnDestroy; |
51 | 153 |
begin |
2947 | 154 |
WriteLnToConsole('Freeing resources...'); |
155 |
if isSoundEnabled then ReleaseSound(); |
|
156 |
StoreRelease(); |
|
3045 | 157 |
FreeGearsList(); |
3053 | 158 |
FreeVisualGears(); |
2947 | 159 |
FreeLand(); |
160 |
ControllerClose(); |
|
161 |
SendKB(); |
|
162 |
CloseIPC(); |
|
163 |
TTF_Quit(); |
|
164 |
SDL_Quit(); |
|
3063 | 165 |
isTerminated:= false; |
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; |
3063 | 174 |
while isTerminated = false do |
175 |
begin |
|
2698 | 176 |
{$IFNDEF IPHONEOS} |
177 |
// have to remove this cycle because otherwise it segfaults at exit |
|
2947 | 178 |
while SDL_PollEvent(@event) <> 0 do |
179 |
begin |
|
180 |
case event.type_ of |
|
181 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
|
2698 | 182 |
{$IFDEF SDL13} |
2947 | 183 |
SDL_WINDOWEVENT: |
2698 | 184 |
{$ELSE} |
2947 | 185 |
SDL_ACTIVEEVENT: |
2569 | 186 |
{$ENDIF} |
2947 | 187 |
if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
188 |
cHasFocus:= event.active.gain = 1; |
|
189 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
|
190 |
SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
|
191 |
SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
|
192 |
SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
|
193 |
SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
|
194 |
SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
|
195 |
SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
|
196 |
SDL_QUITEV: isTerminated:= true |
|
197 |
end; // end case event.type_ of |
|
198 |
end; // end while SDL_PollEvent(@event) <> 0 do |
|
2390 | 199 |
{$ENDIF} |
3063 | 200 |
if isTerminated = false then |
2947 | 201 |
begin |
3063 | 202 |
CurrTime:= SDL_GetTicks; |
203 |
if PrevTime + cTimerInterval <= CurrTime then |
|
204 |
begin |
|
205 |
DoTimer(CurrTime - PrevTime); |
|
206 |
PrevTime:= CurrTime |
|
207 |
end |
|
208 |
else SDL_Delay(1); |
|
209 |
IPCCheckSock(); |
|
210 |
end; |
|
211 |
end; |
|
2698 | 212 |
end; |
213 |
||
214 |
///////////////////////// |
|
215 |
procedure ShowMainWindow; |
|
216 |
begin |
|
2947 | 217 |
if cFullScreen then ParseCommand('fullscr 1', true) |
218 |
else ParseCommand('fullscr 0', true); |
|
219 |
SDL_ShowCursor(0) |
|
2698 | 220 |
end; |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
221 |
|
2698 | 222 |
/////////////// |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
223 |
{$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
|
224 |
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
|
225 |
{$ELSE} |
3064 | 226 |
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
|
227 |
{$ENDIF} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
228 |
var p: TPathType; |
2947 | 229 |
s: shortstring; |
2698 | 230 |
begin |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2800
diff
changeset
|
231 |
{$IFDEF HWLIBRARY} |
3049 | 232 |
initEverything(); |
2947 | 233 |
Randomize(); |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
234 |
|
2947 | 235 |
cBits:= 32; |
236 |
cFullScreen:= false; |
|
237 |
cVSyncInUse:= true; |
|
238 |
cTimerInterval:= 8; |
|
239 |
PathPrefix:= 'Data'; |
|
240 |
cReducedQuality:= false; |
|
241 |
cShowFPS:= true; |
|
242 |
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
|
243 |
|
2947 | 244 |
UserNick:= gameArgs[0]; |
245 |
val(gameArgs[1], ipcPort); |
|
3025 | 246 |
isSoundEnabled:= false;//gameArgs[2] = '1'; |
247 |
isMusicEnabled:= false;//gameArgs[3] = '1'; |
|
2947 | 248 |
cLocaleFName:= gameArgs[4]; |
249 |
cAltDamage:= gameArgs[5] = '1'; |
|
3021 | 250 |
val(gameArgs[6], cScreenHeight); |
251 |
val(gameArgs[7], cScreenWidth); |
|
252 |
cInitHeight:= cScreenHeight; |
|
253 |
cInitWidth:= cScreenWidth; |
|
2600 | 254 |
{$ENDIF} |
2698 | 255 |
|
2947 | 256 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
257 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
|
258 |
||
259 |
WriteToConsole('Init SDL... '); |
|
260 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
261 |
WriteLnToConsole(msgOK); |
|
2698 | 262 |
|
2947 | 263 |
SDL_EnableUNICODE(1); |
2698 | 264 |
|
2947 | 265 |
WriteToConsole('Init SDL_ttf... '); |
266 |
SDLTry(TTF_Init() <> -1, true); |
|
267 |
WriteLnToConsole(msgOK); |
|
2698 | 268 |
|
2947 | 269 |
ShowMainWindow(); |
2698 | 270 |
|
2947 | 271 |
AddProgress(); |
2698 | 272 |
|
2947 | 273 |
ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
274 |
InitKbdKeyTable(); |
|
2698 | 275 |
|
2947 | 276 |
if recordFileName = '' then |
277 |
InitIPC; |
|
278 |
WriteLnToConsole(msgGettingConfig); |
|
2698 | 279 |
|
2947 | 280 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english |
281 |
if cLocaleFName <> 'en.txt' then |
|
2719 | 282 |
begin |
283 |
// Try two letter locale first before trying specific locale overrides |
|
2722 | 284 |
if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then |
285 |
LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt'); |
|
2947 | 286 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
2719 | 287 |
end; |
2698 | 288 |
|
2947 | 289 |
if recordFileName = '' then |
290 |
SendIPCAndWaitReply('C') // ask for game config |
|
291 |
else |
|
292 |
LoadRecordFromFile(recordFileName); |
|
2698 | 293 |
|
2947 | 294 |
ScriptOnGameInit; |
2786 | 295 |
|
2947 | 296 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
297 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
298 |
||
299 |
InitTeams(); |
|
300 |
AssignStores(); |
|
2698 | 301 |
|
2947 | 302 |
if isSoundEnabled then |
303 |
InitSound(); |
|
2590 | 304 |
|
2947 | 305 |
isDeveloperMode:= false; |
2698 | 306 |
|
2947 | 307 |
TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
2698 | 308 |
|
2947 | 309 |
ParseCommand('rotmask', true); |
2698 | 310 |
|
2947 | 311 |
MainLoop(); |
312 |
OnDestroy(); |
|
3063 | 313 |
if alsoShutdownFrontend then |
314 |
begin |
|
315 |
alsoShutdownFrontend:= false; |
|
316 |
halt; |
|
317 |
end; |
|
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 |
3038 | 322 |
uConsts.initModule; |
323 |
uMisc.initModule; |
|
324 |
uConsole.initModule; // MUST happen after uMisc |
|
2947 | 325 |
|
3038 | 326 |
uAI.initModule; |
2947 | 327 |
//uAIActions does not need initialization |
328 |
//uAIAmmoTests does not need initialization |
|
3038 | 329 |
uAIMisc.initModule; |
330 |
uAmmos.initModule; |
|
331 |
uChat.initModule; |
|
332 |
uCollisions.initModule; |
|
2947 | 333 |
//uFloat does not need initialization |
334 |
//uGame does not need initialization |
|
3038 | 335 |
uGears.initModule; |
336 |
uIO.initModule; |
|
337 |
uKeys.initModule; |
|
338 |
uLand.initModule; |
|
2947 | 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 |
|
3038 | 344 |
uRandom.initModule; |
2947 | 345 |
//uSHA does not need initialization |
3038 | 346 |
uSound.initModule; |
347 |
uStats.initModule; |
|
348 |
uStore.initModule; |
|
349 |
uTeams.initModule; |
|
350 |
uVisualGears.initModule; |
|
351 |
uWorld.initModule; |
|
352 |
uScript.initModule; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
353 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
354 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
355 |
procedure freeEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
356 |
begin |
3038 | 357 |
uWorld.freeModule; |
358 |
uVisualGears.freeModule; //stub |
|
359 |
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
|
360 |
uStore.freeModule; //stub |
3038 | 361 |
uStats.freeModule; //stub |
362 |
uSound.freeModule; //stub |
|
2947 | 363 |
//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
|
364 |
uRandom.freeModule; //stub |
2947 | 365 |
//uLocale does not need to be freed |
366 |
//uLandTemplates does not need to be freed |
|
367 |
//uLandTexture does not need to be freed |
|
368 |
//uLandObjects does not need to be freed |
|
369 |
//uLandGraphics does not need to be freed |
|
3038 | 370 |
uLand.freeModule; |
371 |
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
|
372 |
uIO.freeModule; //stub |
3038 | 373 |
uGears.freeModule; |
2947 | 374 |
//uGame does not need to be freed |
375 |
//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
|
376 |
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
|
377 |
uChat.freeModule; //stub |
3038 | 378 |
uAmmos.freeModule; |
379 |
uAIMisc.freeModule; //stub |
|
2947 | 380 |
//uAIAmmoTests does not need to be freed |
381 |
//uAIActions does not need to be freed |
|
3038 | 382 |
uAI.freeModule; //stub |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
383 |
|
3038 | 384 |
uConsole.freeModule; |
385 |
uConsts.freeModule; //stub |
|
386 |
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
|
387 |
// 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
|
388 |
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
|
389 |
|
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 |
|
2698 | 392 |
///////////////////////// |
393 |
procedure GenLandPreview; |
|
394 |
var Preview: TPreview; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
395 |
h: byte; |
2698 | 396 |
begin |
2947 | 397 |
InitIPC; |
398 |
IPCWaitPongEvent; |
|
399 |
TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
2698 | 400 |
|
2947 | 401 |
Preview:= GenPreview; |
402 |
WriteLnToConsole('Sending preview...'); |
|
403 |
SendIPCRaw(@Preview, sizeof(Preview)); |
|
404 |
h:= MaxHedgehogs; |
|
405 |
SendIPCRaw(@h, sizeof(h)); |
|
406 |
WriteLnToConsole('Preview sent, disconnect'); |
|
407 |
CloseIPC(); |
|
2698 | 408 |
end; |
409 |
||
3021 | 410 |
{$IFNDEF HWLIBRARY} |
2698 | 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 |
{$ENDIF} |
51 | 568 |
end; |
3021 | 569 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
570 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
571 |
/////////////////////////////// m a i n //////////////////////////////////////// |
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 |
|
3078 | 580 |
if GameType = gmtLandPreview then GenLandPreview() |
2947 | 581 |
else if GameType = gmtSyntax then DisplayUsage() |
582 |
else Game(); |
|
583 |
||
3078 | 584 |
freeEverything(); |
2947 | 585 |
if GameType = gmtSyntax then |
586 |
ExitCode:= 1 |
|
587 |
else |
|
588 |
ExitCode:= 0; |
|
2698 | 589 |
{$ENDIF} |
51 | 590 |
end. |