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