author | koda |
Mon, 18 Jan 2010 05:36:08 +0000 | |
changeset 2699 | 249adefa9c1c |
parent 2698 | 90585aba87ad |
child 2702 | 48fc46a922fd |
permissions | -rw-r--r-- |
498 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
393 | 3 |
* Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com> |
51 | 4 |
* |
183 | 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 |
|
51 | 8 |
* |
183 | 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. |
|
51 | 13 |
* |
183 | 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 |
|
51 | 17 |
*) |
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 |
|
2698 | 21 |
{$IFDEF IPHONEOS} |
22 |
unit hwengine; |
|
23 |
interface |
|
24 |
{$ELSE} |
|
51 | 25 |
program hwengine; |
2698 | 26 |
{$ENDIF} |
2690 | 27 |
uses SDLh in 'SDLh.pas', |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
28 |
uConsts in 'uConsts.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
29 |
uGame in 'uGame.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
30 |
uMisc in 'uMisc.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
31 |
uStore in 'uStore.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
32 |
uWorld in 'uWorld.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
33 |
uIO in 'uIO.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
34 |
uGears in 'uGears.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
35 |
uVisualGears in 'uVisualGears.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
36 |
uConsole in 'uConsole.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
37 |
uKeys in 'uKeys.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
38 |
uTeams in 'uTeams.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
39 |
uSound in 'uSound.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
40 |
uRandom in 'uRandom.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
41 |
uAI in 'uAI.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
42 |
uAIMisc in 'uAIMisc.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
43 |
uAIAmmoTests in 'uAIAmmoTests.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
44 |
uAIActions in 'uAIActions.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
45 |
uCollisions in 'uCollisions.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
46 |
uLand in 'uLand.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
47 |
uLandTemplates in 'uLandTemplates.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
48 |
uLandObjects in 'uLandObjects.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
49 |
uLandGraphics in 'uLandGraphics.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
50 |
uLocale in 'uLocale.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
51 |
uAmmos in 'uAmmos.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
52 |
uSHA in 'uSHA.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
53 |
uFloat in 'uFloat.pas', |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
54 |
uStats in 'uStats.pas', |
1807 | 55 |
uChat in 'uChat.pas', |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
56 |
uTriggers in 'uTriggers.pas', |
2690 | 57 |
uLandTexture in 'uLandTexture.pas' |
58 |
{$IFDEF IPHONEOS} |
|
59 |
, PascalExports in 'PascalExports.pas' |
|
60 |
{$ENDIF} |
|
61 |
; |
|
51 | 62 |
|
63 |
// also: GSHandlers.inc |
|
64 |
// CCHandlers.inc |
|
65 |
// HHHandlers.inc |
|
357 | 66 |
// SinTable.inc |
271 | 67 |
// proto.inc |
51 | 68 |
|
2698 | 69 |
{$IFDEF IPHONEOS} |
70 |
procedure DoTimer(Lag: LongInt); |
|
71 |
procedure OnDestroy; |
|
72 |
procedure MainLoop; |
|
73 |
procedure ShowMainWindow; |
|
74 |
procedure Game; cdecl; export; |
|
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 |
||
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} |
1080 | 88 |
var s: string; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
89 |
{$ENDIF} |
51 | 90 |
begin |
2698 | 91 |
inc(RealTicks, Lag); |
564 | 92 |
|
2698 | 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 |
GameState:= gsGame; |
|
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
116 |
end; |
2698 | 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 |
|
2698 | 134 |
SDL_GL_SwapBuffers(); |
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
|
135 |
{$IFNDEF IPHONEOS} |
2698 | 136 |
// not going to make captures on the iPhone |
137 |
if flagMakeCapture then |
|
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
138 |
begin |
2698 | 139 |
flagMakeCapture:= false; |
140 |
s:= 'hw_' + cSeed + '_' + inttostr(GameTicks) + '.tga'; |
|
141 |
WriteLnToConsole('Saving ' + s); |
|
142 |
MakeScreenshot(s); |
|
143 |
//SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
|
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
144 |
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
|
145 |
{$ENDIF} |
51 | 146 |
end; |
147 |
||
148 |
//////////////////// |
|
79 | 149 |
procedure OnDestroy; |
51 | 150 |
begin |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
151 |
WriteLnToConsole('Freeing resources...'); |
2688 | 152 |
if isSoundEnabled then ReleaseSound(); |
153 |
StoreRelease(); |
|
154 |
FreeLand(); |
|
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
155 |
ControllerClose(); |
2688 | 156 |
SendKB(); |
157 |
CloseIPC(); |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
158 |
freeEverything(); |
2688 | 159 |
TTF_Quit(); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
160 |
{$IFDEF SDL13}SDL_VideoQuit();{$ENDIF} |
2688 | 161 |
SDL_Quit(); |
2698 | 162 |
exit(); |
51 | 163 |
end; |
164 |
||
165 |
/////////////////// |
|
2698 | 166 |
procedure MainLoop; |
51 | 167 |
var PrevTime, |
188 | 168 |
CurrTime: Longword; |
51 | 169 |
event: TSDL_Event; |
2698 | 170 |
begin |
171 |
||
172 |
PrevTime:= SDL_GetTicks; |
|
173 |
repeat |
|
174 |
{$IFNDEF IPHONEOS} |
|
175 |
// have to remove this cycle because otherwise it segfaults at exit |
|
176 |
while SDL_PollEvent(@event) <> 0 do |
|
177 |
begin |
|
178 |
case event.type_ of |
|
179 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
|
180 |
{$IFDEF SDL13} |
|
181 |
SDL_WINDOWEVENT: |
|
182 |
{$ELSE} |
|
183 |
SDL_ACTIVEEVENT: |
|
2569 | 184 |
{$ENDIF} |
2698 | 185 |
if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
186 |
cHasFocus:= event.active.gain = 1; |
|
187 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
|
188 |
SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
|
189 |
SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
|
190 |
SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
|
191 |
SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
|
192 |
SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
|
193 |
SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
|
194 |
SDL_QUITEV: isTerminated:= true |
|
195 |
end; // end case event.type_ of |
|
196 |
end; // end while SDL_PollEvent(@event) <> 0 do |
|
2390 | 197 |
{$ENDIF} |
2698 | 198 |
CurrTime:= SDL_GetTicks; |
199 |
if PrevTime + cTimerInterval <= CurrTime then |
|
200 |
begin |
|
201 |
DoTimer(CurrTime - PrevTime); |
|
202 |
PrevTime:= CurrTime |
|
203 |
end else SDL_Delay(1); |
|
204 |
if isTerminated = false then IPCCheckSock(); |
|
205 |
until isTerminated; |
|
206 |
||
207 |
exit(); |
|
208 |
end; |
|
209 |
||
210 |
///////////////////////// |
|
211 |
procedure ShowMainWindow; |
|
212 |
begin |
|
213 |
if cFullScreen then ParseCommand('fullscr 1', true) |
|
214 |
else ParseCommand('fullscr 0', true); |
|
215 |
SDL_ShowCursor(0) |
|
216 |
end; |
|
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
217 |
|
2698 | 218 |
/////////////// |
219 |
procedure Game;{$IFDEF IPHONEOS}cdecl; export;{$ENDIF} |
|
220 |
var p: TPathType; |
|
221 |
s: shortstring; |
|
222 |
begin |
|
223 |
{$IFDEF IPHONEOS} |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
224 |
initEverything(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
225 |
Randomize(); |
2591
c6597b65caea
other controls implementation + sdlh revisited (once again)
koda
parents:
2590
diff
changeset
|
226 |
|
2698 | 227 |
val('320', cScreenWidth); |
228 |
val('480', cScreenHeight); |
|
229 |
cInitWidth:= cScreenWidth; |
|
230 |
cInitHeight:= cScreenHeight; |
|
231 |
cBitsStr:= '16'; |
|
232 |
val(cBitsStr, cBits); |
|
233 |
val('51432', ipcPort); |
|
234 |
cFullScreen:= true; |
|
235 |
isSoundEnabled:= false; |
|
236 |
cVSyncInUse:= true; |
|
237 |
cLocaleFName:= 'en.txt'; |
|
238 |
val('100', cInitVolume); |
|
239 |
val('8', cTimerInterval); |
|
240 |
PathPrefix:= 'Data'; |
|
241 |
cShowFPS:= true; |
|
242 |
cAltDamage:= false; |
|
243 |
UserNick:= 'Koda'; //DecodeBase64(ParamStr(15)); |
|
244 |
isMusicEnabled:= false; |
|
245 |
cReducedQuality:= false; |
|
2600 | 246 |
{$ENDIF} |
2698 | 247 |
|
248 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
249 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
|
250 |
||
251 |
WriteToConsole('Init SDL... '); |
|
252 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
253 |
WriteLnToConsole(msgOK); |
|
254 |
||
255 |
SDL_EnableUNICODE(1); |
|
256 |
||
257 |
WriteToConsole('Init SDL_ttf... '); |
|
258 |
SDLTry(TTF_Init <> -1, true); |
|
259 |
WriteLnToConsole(msgOK); |
|
260 |
||
261 |
ShowMainWindow; |
|
262 |
||
263 |
AddProgress; |
|
264 |
||
265 |
ControllerInit; // has to happen before InitKbdKeyTable to map keys |
|
266 |
InitKbdKeyTable; |
|
267 |
||
268 |
if recordFileName = '' then |
|
269 |
InitIPC; |
|
270 |
WriteLnToConsole(msgGettingConfig); |
|
271 |
||
272 |
if cLocaleFName <> 'en.txt' then |
|
273 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
274 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
|
275 |
||
276 |
if recordFileName = '' then |
|
277 |
SendIPCAndWaitReply('C') // ask for game config |
|
278 |
else |
|
279 |
LoadRecordFromFile(recordFileName); |
|
280 |
||
281 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
282 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
283 |
||
284 |
InitTeams; |
|
285 |
AssignStores; |
|
2590 | 286 |
|
2698 | 287 |
if isSoundEnabled then |
288 |
InitSound; |
|
289 |
||
290 |
isDeveloperMode:= false; |
|
291 |
||
292 |
TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
293 |
||
294 |
MainLoop(); |
|
295 |
OnDestroy(); |
|
296 |
exit(); |
|
297 |
end; |
|
2590 | 298 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
299 |
procedure initEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
300 |
begin |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
301 |
init_uConsts(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
302 |
init_uMisc(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
303 |
init_uConsole(); // MUST happen after uMisc |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
304 |
init_uStore(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
305 |
init_uTeams(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
306 |
init_uGears(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
307 |
init_uVisualGears(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
308 |
init_uLand(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
309 |
init_uIO(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
310 |
init_uWorld(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
311 |
init_uRandom; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
312 |
init_uTriggers; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
313 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
314 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
315 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
316 |
procedure freeEverything; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
317 |
begin |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
318 |
//free_uConts(); not necessary |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
319 |
free_uConsole(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
320 |
free_uMisc(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
321 |
free_uTeams(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
322 |
free_uGears(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
323 |
//free_uVisualGears(); not necessary |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
324 |
free_uLand(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
325 |
//free_uWorld(); not necessary |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
326 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
327 |
end; |
2698 | 328 |
{$IFNDEF IPHONEOS} |
329 |
///////////////////////// |
|
330 |
procedure GenLandPreview; |
|
331 |
var Preview: TPreview; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
332 |
h: byte; |
2698 | 333 |
begin |
334 |
InitIPC; |
|
335 |
IPCWaitPongEvent; |
|
336 |
TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
337 |
||
338 |
Preview:= GenPreview; |
|
339 |
WriteLnToConsole('Sending preview...'); |
|
340 |
SendIPCRaw(@Preview, sizeof(Preview)); |
|
341 |
h:= MaxHedgehogs; |
|
342 |
SendIPCRaw(@h, sizeof(h)); |
|
343 |
WriteLnToConsole('Preview sent, disconnect'); |
|
344 |
CloseIPC(); |
|
345 |
end; |
|
346 |
||
347 |
//////////////////////////////// |
|
348 |
procedure Resize(w, h: LongInt); |
|
349 |
begin |
|
350 |
cScreenWidth:= w; |
|
351 |
cScreenHeight:= h; |
|
352 |
if cFullScreen then |
|
353 |
ParseCommand('/fullscr 1', true) |
|
354 |
else |
|
355 |
ParseCommand('/fullscr 0', true); |
|
51 | 356 |
end; |
357 |
||
2008 | 358 |
///////////////////// |
359 |
procedure DisplayUsage; |
|
2691 | 360 |
var i: LongInt; |
2008 | 361 |
begin |
362 |
WriteLn('Wrong argument format: correct configurations is'); |
|
363 |
WriteLn(); |
|
364 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
365 |
WriteLn(); |
|
366 |
WriteLn('where [option] must be specified either as'); |
|
2264 | 367 |
WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
2008 | 368 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
369 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
370 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
371 |
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]'); |
|
372 |
WriteLn(); |
|
2015 | 373 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
2691 | 374 |
Write('parsed command: '); |
2698 | 375 |
for i:=0 to ParamCount do |
376 |
Write(ParamStr(i) + ' '); |
|
2691 | 377 |
WriteLn(); |
2015 | 378 |
halt(1); |
2008 | 379 |
end; |
380 |
||
51 | 381 |
//////////////////// |
382 |
procedure GetParams; |
|
267 | 383 |
{$IFDEF DEBUGFILE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
384 |
var i: LongInt; |
267 | 385 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
386 |
begin |
267 | 387 |
|
2698 | 388 |
case ParamCount of |
389 |
17: begin |
|
390 |
val(ParamStr(2), cScreenWidth); |
|
391 |
val(ParamStr(3), cScreenHeight); |
|
2008 | 392 |
cInitWidth:= cScreenWidth; |
393 |
cInitHeight:= cScreenHeight; |
|
2698 | 394 |
cBitsStr:= ParamStr(4); |
2008 | 395 |
val(cBitsStr, cBits); |
2698 | 396 |
val(ParamStr(5), ipcPort); |
397 |
cFullScreen:= ParamStr(6) = '1'; |
|
398 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
399 |
cVSyncInUse:= ParamStr(8) = '1'; |
|
400 |
cLocaleFName:= ParamStr(9); |
|
401 |
val(ParamStr(10), cInitVolume); |
|
402 |
val(ParamStr(11), cTimerInterval); |
|
403 |
PathPrefix:= ParamStr(12); |
|
404 |
cShowFPS:= ParamStr(13) = '1'; |
|
405 |
cAltDamage:= ParamStr(14) = '1'; |
|
406 |
UserNick:= DecodeBase64(ParamStr(15)); |
|
407 |
isMusicEnabled:= ParamStr(16) = '1'; |
|
408 |
cReducedQuality:= ParamStr(17) = '1'; |
|
409 |
end; |
|
410 |
3: begin |
|
411 |
val(ParamStr(2), ipcPort); |
|
412 |
GameType:= gmtLandPreview; |
|
413 |
if ParamStr(3) <> 'landpreview' then |
|
414 |
OutError(errmsgShouldntRun, true); |
|
415 |
end; |
|
416 |
2: begin |
|
417 |
PathPrefix:= ParamStr(1); |
|
418 |
recordFileName:= ParamStr(2); |
|
419 |
end; |
|
420 |
6: begin |
|
421 |
PathPrefix:= ParamStr(1); |
|
422 |
recordFileName:= ParamStr(2); |
|
423 |
||
424 |
if ParamStr(3) = '--set-video' then |
|
2008 | 425 |
begin |
2698 | 426 |
val(ParamStr(4), cScreenWidth); |
427 |
val(ParamStr(5), cScreenHeight); |
|
428 |
cInitWidth:= cScreenWidth; |
|
429 |
cInitHeight:= cScreenHeight; |
|
430 |
cBitsStr:= ParamStr(6); |
|
431 |
val(cBitsStr, cBits); |
|
2008 | 432 |
end |
433 |
else |
|
434 |
begin |
|
2698 | 435 |
if ParamStr(3) = '--set-audio' then |
436 |
begin |
|
437 |
val(ParamStr(4), cInitVolume); |
|
438 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
439 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
440 |
end |
|
441 |
else |
|
2008 | 442 |
begin |
2698 | 443 |
if ParamStr(3) = '--set-other' then |
444 |
begin |
|
445 |
cLocaleFName:= ParamStr(4); |
|
446 |
cFullScreen:= ParamStr(5) = '1'; |
|
447 |
cShowFPS:= ParamStr(6) = '1'; |
|
448 |
end |
|
449 |
else DisplayUsage; |
|
2008 | 450 |
end |
2698 | 451 |
end; |
2008 | 452 |
end; |
2698 | 453 |
11: begin |
454 |
PathPrefix:= ParamStr(1); |
|
455 |
recordFileName:= ParamStr(2); |
|
2376 | 456 |
|
2698 | 457 |
if ParamStr(3) = '--set-multimedia' then |
458 |
begin |
|
459 |
val(ParamStr(4), cScreenWidth); |
|
460 |
val(ParamStr(5), cScreenHeight); |
|
461 |
cInitWidth:= cScreenWidth; |
|
462 |
cInitHeight:= cScreenHeight; |
|
463 |
cBitsStr:= ParamStr(6); |
|
464 |
val(cBitsStr, cBits); |
|
465 |
val(ParamStr(7), cInitVolume); |
|
466 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
467 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
468 |
cLocaleFName:= ParamStr(10); |
|
469 |
cFullScreen:= ParamStr(11) = '1'; |
|
470 |
end |
|
471 |
else DisplayUsage; |
|
472 |
end; |
|
473 |
15: begin |
|
474 |
PathPrefix:= ParamStr(1); |
|
475 |
recordFileName:= ParamStr(2); |
|
476 |
if ParamStr(3) = '--set-everything' then |
|
477 |
begin |
|
478 |
val(ParamStr(4), cScreenWidth); |
|
479 |
val(ParamStr(5), cScreenHeight); |
|
480 |
cInitWidth:= cScreenWidth; |
|
481 |
cInitHeight:= cScreenHeight; |
|
482 |
cBitsStr:= ParamStr(6); |
|
483 |
val(cBitsStr, cBits); |
|
484 |
val(ParamStr(7), cInitVolume); |
|
485 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
486 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
487 |
cLocaleFName:= ParamStr(10); |
|
488 |
cFullScreen:= ParamStr(11) = '1'; |
|
489 |
cAltDamage:= ParamStr(12) = '1'; |
|
490 |
cShowFPS:= ParamStr(13) = '1'; |
|
491 |
val(ParamStr(14), cTimerInterval); |
|
492 |
cReducedQuality:= ParamStr(15) = '1'; |
|
493 |
end |
|
494 |
else DisplayUsage; |
|
495 |
end; |
|
2008 | 496 |
else DisplayUsage; |
497 |
end; |
|
2630 | 498 |
|
499 |
{$IFDEF DEBUGFILE} |
|
2698 | 500 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
501 |
for i:= 0 to ParamCount do |
|
502 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
2630 | 503 |
{$IFDEF IPHONEOS} |
2690 | 504 |
WriteLnToConsole('Saving debug file at: ' + IPH_getDocumentsPath()); |
2630 | 505 |
{$ENDIF} |
506 |
{$ENDIF} |
|
51 | 507 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
508 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
509 |
/////////////////////////////// m a i n //////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
510 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
511 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
512 |
begin |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
513 |
initEverything(); |
2692
ce9992075118
better network support + initial work for returning to frontend
koda
parents:
2691
diff
changeset
|
514 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
515 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
516 |
GetParams(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
517 |
Randomize(); |
2008 | 518 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
519 |
if GameType = gmtLandPreview then GenLandPreview() |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
520 |
else Game(); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
521 |
ExitCode := 0; |
2698 | 522 |
{$ENDIF} |
51 | 523 |
end. |