author | unc0rr |
Sat, 01 Aug 2009 14:03:25 +0000 | |
changeset 2293 | f8d488636828 |
parent 2264 | b8fff48235de |
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 |
||
355 | 19 |
{$IFNDEF FPC} |
20 |
WriteLn('Only Freepascal supported'); |
|
21 |
{$ENDIF} |
|
22 |
||
51 | 23 |
program hwengine; |
24 |
uses |
|
1947 | 25 |
SDLh in 'SDLh.pas', |
2152 | 26 |
{$IFDEF GLES11} |
1906 | 27 |
gles11, |
28 |
{$ELSE} |
|
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
29 |
GL, |
1906 | 30 |
{$ENDIF} |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
uStats in 'uStats.pas', |
1807 | 58 |
uChat in 'uChat.pas', |
2008 | 59 |
uLandTexture in 'uLandTexture.pas'; |
51 | 60 |
|
61 |
{$INCLUDE options.inc} |
|
62 |
||
63 |
// also: GSHandlers.inc |
|
64 |
// CCHandlers.inc |
|
65 |
// HHHandlers.inc |
|
357 | 66 |
// SinTable.inc |
271 | 67 |
// proto.inc |
51 | 68 |
|
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
69 |
var recordFileName : shortstring = ''; |
51 | 70 |
|
71 |
procedure OnDestroy; forward; |
|
72 |
||
73 |
//////////////////////////////// |
|
371 | 74 |
procedure DoTimer(Lag: LongInt); |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
75 |
{$IFNDEF IPHONEOS} |
1080 | 76 |
var s: string; |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
77 |
{$ENDIF} |
51 | 78 |
begin |
564 | 79 |
inc(RealTicks, Lag); |
80 |
||
51 | 81 |
case GameState of |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
82 |
gsLandGen: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
83 |
GenMap; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
84 |
GameState:= gsStart; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
85 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
86 |
gsStart: begin |
1784 | 87 |
if HasBorder then DisableSomeWeapons; |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
88 |
AddClouds; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
89 |
AssignHHCoords; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
90 |
AddMiscGears; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
91 |
StoreLoad; |
1825 | 92 |
InitWorld; |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
93 |
ResetKbd; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
94 |
SoundLoad; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
95 |
if GameType = gmtSave then |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
96 |
begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
97 |
isSEBackup:= isSoundEnabled; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
98 |
isSoundEnabled:= false |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
99 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
100 |
FinishProgress; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
101 |
PlayMusic; |
2162 | 102 |
SetScale(zoom); |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
103 |
GameState:= gsGame |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
104 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
105 |
gsConfirm, |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
106 |
gsGame: begin |
1645 | 107 |
DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
108 |
ProcessKbd; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
109 |
DoGameTick(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
110 |
ProcessVisualGears(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
111 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
112 |
gsChat: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
113 |
DrawWorld(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
114 |
DoGameTick(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
115 |
ProcessVisualGears(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
116 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
117 |
gsExit: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
118 |
OnDestroy; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
119 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
120 |
end; |
564 | 121 |
|
753 | 122 |
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
|
123 |
{$IFNDEF IPHONEOS} |
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2162
diff
changeset
|
124 |
//not going to make captures on the iPhone |
51 | 125 |
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
|
126 |
begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
127 |
flagMakeCapture:= false; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
128 |
s:= 'hw_' + cSeed + '_' + inttostr(GameTicks) + '.tga'; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
129 |
WriteLnToConsole('Saving ' + s); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
130 |
MakeScreenshot(s); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
131 |
// SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
132 |
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
|
133 |
{$ENDIF} |
51 | 134 |
end; |
135 |
||
136 |
//////////////////// |
|
79 | 137 |
procedure OnDestroy; |
51 | 138 |
begin |
139 |
{$IFDEF DEBUGFILE}AddFileLog('Freeing resources...');{$ENDIF} |
|
140 |
if isSoundEnabled then ReleaseSound; |
|
619 | 141 |
StoreRelease; |
1807 | 142 |
FreeLand; |
619 | 143 |
SendKB; |
51 | 144 |
CloseIPC; |
145 |
TTF_Quit; |
|
146 |
SDL_Quit; |
|
147 |
halt |
|
148 |
end; |
|
149 |
||
1120 | 150 |
//////////////////////////////// |
151 |
procedure Resize(w, h: LongInt); |
|
152 |
begin |
|
153 |
cScreenWidth:= w; |
|
154 |
cScreenHeight:= h; |
|
155 |
if cFullScreen then |
|
156 |
ParseCommand('/fullscr 1', true) |
|
157 |
else |
|
158 |
ParseCommand('/fullscr 0', true); |
|
159 |
end; |
|
160 |
||
51 | 161 |
/////////////////// |
162 |
procedure MainLoop; |
|
163 |
var PrevTime, |
|
188 | 164 |
CurrTime: Longword; |
51 | 165 |
event: TSDL_Event; |
166 |
begin |
|
167 |
PrevTime:= SDL_GetTicks; |
|
168 |
repeat |
|
169 |
while SDL_PollEvent(@event) <> 0 do |
|
1120 | 170 |
case event.type_ of |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
171 |
{$IFDEF IPHONEOS} |
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
172 |
SDL_MOUSEMOTION: WriteLnToConsole('mouse number ' + inttostr(SDL_SelectMouse(event.motion.which)) + ' over ' + inttostr(SDL_GetNumMice())); |
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
173 |
{$ELSE} |
1120 | 174 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
2243
b4764993f833
additional touch support and nemo's reduced land array size
koda
parents:
2191
diff
changeset
|
175 |
{$ENDIF} |
1120 | 176 |
SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
177 |
cHasFocus:= event.active.gain = 1; |
|
1127 | 178 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
1120 | 179 |
SDL_QUITEV: isTerminated:= true |
180 |
end; |
|
51 | 181 |
CurrTime:= SDL_GetTicks; |
182 |
if PrevTime + cTimerInterval <= CurrTime then |
|
183 |
begin |
|
184 |
DoTimer(CurrTime - PrevTime); |
|
185 |
PrevTime:= CurrTime |
|
434 | 186 |
end else SDL_Delay(1); |
51 | 187 |
IPCCheckSock |
188 |
until isTerminated |
|
189 |
end; |
|
190 |
||
2008 | 191 |
///////////////////// |
192 |
procedure DisplayUsage; |
|
193 |
begin |
|
194 |
WriteLn('Wrong argument format: correct configurations is'); |
|
195 |
WriteLn(); |
|
196 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
197 |
WriteLn(); |
|
198 |
WriteLn('where [option] must be specified either as'); |
|
2264 | 199 |
WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
2008 | 200 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
201 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
202 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
203 |
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]'); |
|
204 |
WriteLn(); |
|
2015 | 205 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
206 |
halt(1); |
|
2008 | 207 |
end; |
208 |
||
51 | 209 |
//////////////////// |
210 |
procedure GetParams; |
|
889 | 211 |
var |
267 | 212 |
{$IFDEF DEBUGFILE} |
371 | 213 |
i: LongInt; |
267 | 214 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
215 |
p: TPathType; |
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
216 |
begin |
51 | 217 |
{$IFDEF DEBUGFILE} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
218 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
51 | 219 |
for i:= 0 to ParamCount do |
220 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
221 |
{$ENDIF} |
|
267 | 222 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
223 |
case ParamCount of |
1892 | 224 |
16: begin |
498 | 225 |
val(ParamStr(2), cScreenWidth); |
226 |
val(ParamStr(3), cScreenHeight); |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
227 |
cInitWidth:= cScreenWidth; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
228 |
cInitHeight:= cScreenHeight; |
497 | 229 |
cBitsStr:= ParamStr(4); |
498 | 230 |
val(cBitsStr, cBits); |
231 |
val(ParamStr(5), ipcPort); |
|
497 | 232 |
cFullScreen:= ParamStr(6) = '1'; |
233 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
234 |
cLocaleFName:= ParamStr(8); |
|
498 | 235 |
val(ParamStr(9), cInitVolume); |
236 |
val(ParamStr(10), cTimerInterval); |
|
497 | 237 |
PathPrefix:= ParamStr(11); |
238 |
cShowFPS:= ParamStr(12) = '1'; |
|
529 | 239 |
cAltDamage:= ParamStr(13) = '1'; |
949 | 240 |
UserNick:= DecodeBase64(ParamStr(14)); |
1128 | 241 |
isMusicEnabled:= ParamStr(15) = '1'; |
1812 | 242 |
cReducedQuality:= ParamStr(16) = '1'; |
267 | 243 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
949 | 244 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
245 |
end; |
2252 | 246 |
{$IFDEF IPHONEOS} |
247 |
0: begin |
|
248 |
PathPrefix:= 'hedgewars/Data'; |
|
249 |
recordFileName:= 'hedgewars/save.hws'; |
|
250 |
val('320', cScreenWidth); |
|
251 |
val('480', cScreenHeight); |
|
252 |
cInitWidth:= cScreenWidth; |
|
253 |
cInitHeight:= cScreenHeight; |
|
254 |
cBitsStr:= '32'; |
|
255 |
val(cBitsStr, cBits); |
|
256 |
val('100', cInitVolume); |
|
257 |
isMusicEnabled:= false; |
|
258 |
isSoundEnabled:= false; |
|
259 |
cLocaleFName:= 'en.txt'; |
|
260 |
cFullScreen:= false; |
|
261 |
cAltDamage:= false; |
|
262 |
cShowFPS:= false; |
|
263 |
val('8', cTimerInterval); |
|
264 |
cReducedQuality:= false; |
|
265 |
||
266 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
267 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
268 |
end; |
|
269 |
{$ENDIF} |
|
497 | 270 |
3: begin |
498 | 271 |
val(ParamStr(2), ipcPort); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
272 |
GameType:= gmtLandPreview; |
497 | 273 |
if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true); |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
274 |
end; |
2008 | 275 |
2: begin |
276 |
PathPrefix:= ParamStr(1); |
|
277 |
recordFileName:= ParamStr(2); |
|
278 |
||
279 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
280 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
281 |
end; |
|
282 |
6: begin |
|
283 |
PathPrefix:= ParamStr(1); |
|
284 |
recordFileName:= ParamStr(2); |
|
285 |
||
286 |
if ParamStr(3) = '--set-video' then |
|
287 |
begin |
|
288 |
val(ParamStr(4), cScreenWidth); |
|
289 |
val(ParamStr(5), cScreenHeight); |
|
290 |
cInitWidth:= cScreenWidth; |
|
291 |
cInitHeight:= cScreenHeight; |
|
292 |
cBitsStr:= ParamStr(6); |
|
293 |
val(cBitsStr, cBits); |
|
294 |
end |
|
295 |
else |
|
296 |
begin |
|
297 |
if ParamStr(3) = '--set-audio' then |
|
298 |
begin |
|
299 |
val(ParamStr(4), cInitVolume); |
|
300 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
301 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
302 |
end |
|
303 |
else |
|
304 |
begin |
|
305 |
if ParamStr(3) = '--set-other' then |
|
306 |
begin |
|
307 |
cLocaleFName:= ParamStr(4); |
|
308 |
cFullScreen:= ParamStr(5) = '1'; |
|
309 |
cShowFPS:= ParamStr(6) = '1'; |
|
310 |
end |
|
311 |
else DisplayUsage; |
|
312 |
end |
|
313 |
end; |
|
314 |
||
315 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
316 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
317 |
end; |
|
318 |
11: begin |
|
319 |
PathPrefix:= ParamStr(1); |
|
320 |
recordFileName:= ParamStr(2); |
|
321 |
||
322 |
if ParamStr(3) = '--set-multimedia' then |
|
323 |
begin |
|
324 |
val(ParamStr(4), cScreenWidth); |
|
325 |
val(ParamStr(5), cScreenHeight); |
|
326 |
cInitWidth:= cScreenWidth; |
|
327 |
cInitHeight:= cScreenHeight; |
|
328 |
cBitsStr:= ParamStr(6); |
|
329 |
val(cBitsStr, cBits); |
|
330 |
val(ParamStr(7), cInitVolume); |
|
331 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
332 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
333 |
cLocaleFName:= ParamStr(10); |
|
334 |
cFullScreen:= ParamStr(11) = '1'; |
|
335 |
end |
|
336 |
else DisplayUsage; |
|
337 |
||
338 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
339 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
340 |
end; |
|
341 |
15: begin |
|
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
342 |
PathPrefix:= ParamStr(1); |
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
343 |
recordFileName:= ParamStr(2); |
2008 | 344 |
if ParamStr(3) = '--set-everything' then |
345 |
begin |
|
346 |
val(ParamStr(4), cScreenWidth); |
|
347 |
val(ParamStr(5), cScreenHeight); |
|
348 |
cInitWidth:= cScreenWidth; |
|
349 |
cInitHeight:= cScreenHeight; |
|
350 |
cBitsStr:= ParamStr(6); |
|
351 |
val(cBitsStr, cBits); |
|
352 |
val(ParamStr(7), cInitVolume); |
|
353 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
354 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
355 |
cLocaleFName:= ParamStr(10); |
|
356 |
cFullScreen:= ParamStr(11) = '1'; |
|
357 |
cAltDamage:= ParamStr(12) = '1'; |
|
358 |
cShowFPS:= ParamStr(13) = '1'; |
|
359 |
val(ParamStr(14), cTimerInterval); |
|
360 |
cReducedQuality:= ParamStr(15) = '1'; |
|
361 |
end |
|
362 |
else DisplayUsage; |
|
363 |
||
364 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
365 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
366 |
end; |
|
367 |
else DisplayUsage; |
|
368 |
end; |
|
51 | 369 |
end; |
370 |
||
2016 | 371 |
///////////////////////// |
51 | 372 |
procedure ShowMainWindow; |
373 |
begin |
|
351 | 374 |
if cFullScreen then ParseCommand('fullscr 1', true) |
375 |
else ParseCommand('fullscr 0', true); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
271
diff
changeset
|
376 |
SDL_ShowCursor(0) |
51 | 377 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
378 |
|
160 | 379 |
/////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
380 |
procedure Game; |
205 | 381 |
var s: shortstring; |
51 | 382 |
begin |
383 |
WriteToConsole('Init SDL... '); |
|
384 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
385 |
WriteLnToConsole(msgOK); |
|
753 | 386 |
|
377 | 387 |
SDL_EnableUNICODE(1); |
51 | 388 |
|
389 |
WriteToConsole('Init SDL_ttf... '); |
|
200 | 390 |
SDLTry(TTF_Init <> -1, true); |
51 | 391 |
WriteLnToConsole(msgOK); |
392 |
||
393 |
ShowMainWindow; |
|
394 |
||
395 |
InitKbdKeyTable; |
|
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
396 |
|
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
397 |
if recordFileName = '' then InitIPC; |
51 | 398 |
WriteLnToConsole(msgGettingConfig); |
80 | 399 |
|
2039 | 400 |
if cLocaleFName <> 'en.txt' then |
401 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
80 | 402 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
403 |
||
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
404 |
if recordFileName = '' then |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
405 |
SendIPCAndWaitReply('C') // ask for game config |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
406 |
else |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
407 |
begin |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
408 |
LoadRecordFromFile(recordFileName); |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
409 |
end; |
205 | 410 |
|
411 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
412 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
413 |
||
51 | 414 |
InitTeams; |
288 | 415 |
AssignStores; |
51 | 416 |
|
417 |
if isSoundEnabled then InitSound; |
|
418 |
||
419 |
StoreInit; |
|
420 |
||
421 |
isDeveloperMode:= false; |
|
422 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
423 |
TryDo(InitStepsFlags = cifAllInited, |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
424 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
425 |
true); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
426 |
|
51 | 427 |
MainLoop |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
428 |
end; |
51 | 429 |
|
160 | 430 |
///////////////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
431 |
procedure GenLandPreview; |
566 | 432 |
var Preview: TPreview; |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
433 |
h: byte; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
434 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
435 |
InitIPC; |
159 | 436 |
IPCWaitPongEvent; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
437 |
TryDo(InitStepsFlags = cifRandomize, |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
438 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
439 |
true); |
160 | 440 |
|
566 | 441 |
Preview:= GenPreview; |
159 | 442 |
WriteLnToConsole('Sending preview...'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
443 |
SendIPCRaw(@Preview, sizeof(Preview)); |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
444 |
h:= MaxHedgehogs; |
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
445 |
SendIPCRaw(@h, sizeof(h)); |
159 | 446 |
WriteLnToConsole('Preview sent, disconnect'); |
158 | 447 |
CloseIPC |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
448 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
449 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
450 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
451 |
/////////////////////////////// m a i n //////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
452 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
453 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
454 |
begin |
2006 | 455 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
456 |
GetParams; |
2145 | 457 |
// FIXME - hack in font with support for CJK |
2105 | 458 |
if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then |
459 |
Fontz:= FontzCJK; |
|
460 |
||
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
461 |
Randomize; |
2008 | 462 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
463 |
if GameType = gmtLandPreview then GenLandPreview |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
464 |
else Game |
51 | 465 |
end. |
2008 | 466 |