author | koda |
Thu, 09 Jul 2009 00:56:26 +0000 | |
changeset 2244 | 853a1db1cff6 |
parent 2243 | b4764993f833 |
child 2252 | 03fd99dff989 |
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'); |
|
199 |
WriteLn(' --set-video [screen height] [screen width] [color dept]'); |
|
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; |
497 | 246 |
3: begin |
498 | 247 |
val(ParamStr(2), ipcPort); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
248 |
GameType:= gmtLandPreview; |
497 | 249 |
if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true); |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
250 |
end; |
2008 | 251 |
2: begin |
252 |
PathPrefix:= ParamStr(1); |
|
253 |
recordFileName:= ParamStr(2); |
|
254 |
||
255 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
256 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
257 |
end; |
|
258 |
6: begin |
|
259 |
PathPrefix:= ParamStr(1); |
|
260 |
recordFileName:= ParamStr(2); |
|
261 |
||
262 |
if ParamStr(3) = '--set-video' then |
|
263 |
begin |
|
264 |
val(ParamStr(4), cScreenWidth); |
|
265 |
val(ParamStr(5), cScreenHeight); |
|
266 |
cInitWidth:= cScreenWidth; |
|
267 |
cInitHeight:= cScreenHeight; |
|
268 |
cBitsStr:= ParamStr(6); |
|
269 |
val(cBitsStr, cBits); |
|
270 |
end |
|
271 |
else |
|
272 |
begin |
|
273 |
if ParamStr(3) = '--set-audio' then |
|
274 |
begin |
|
275 |
val(ParamStr(4), cInitVolume); |
|
276 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
277 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
278 |
end |
|
279 |
else |
|
280 |
begin |
|
281 |
if ParamStr(3) = '--set-other' then |
|
282 |
begin |
|
283 |
cLocaleFName:= ParamStr(4); |
|
284 |
cFullScreen:= ParamStr(5) = '1'; |
|
285 |
cShowFPS:= ParamStr(6) = '1'; |
|
286 |
end |
|
287 |
else DisplayUsage; |
|
288 |
end |
|
289 |
end; |
|
290 |
||
291 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
292 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
293 |
end; |
|
294 |
11: begin |
|
295 |
PathPrefix:= ParamStr(1); |
|
296 |
recordFileName:= ParamStr(2); |
|
297 |
||
298 |
if ParamStr(3) = '--set-multimedia' then |
|
299 |
begin |
|
300 |
val(ParamStr(4), cScreenWidth); |
|
301 |
val(ParamStr(5), cScreenHeight); |
|
302 |
cInitWidth:= cScreenWidth; |
|
303 |
cInitHeight:= cScreenHeight; |
|
304 |
cBitsStr:= ParamStr(6); |
|
305 |
val(cBitsStr, cBits); |
|
306 |
val(ParamStr(7), cInitVolume); |
|
307 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
308 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
309 |
cLocaleFName:= ParamStr(10); |
|
310 |
cFullScreen:= ParamStr(11) = '1'; |
|
311 |
end |
|
312 |
else DisplayUsage; |
|
313 |
||
314 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
315 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
316 |
end; |
|
317 |
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
|
318 |
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
|
319 |
recordFileName:= ParamStr(2); |
2008 | 320 |
if ParamStr(3) = '--set-everything' then |
321 |
begin |
|
322 |
val(ParamStr(4), cScreenWidth); |
|
323 |
val(ParamStr(5), cScreenHeight); |
|
324 |
cInitWidth:= cScreenWidth; |
|
325 |
cInitHeight:= cScreenHeight; |
|
326 |
cBitsStr:= ParamStr(6); |
|
327 |
val(cBitsStr, cBits); |
|
328 |
val(ParamStr(7), cInitVolume); |
|
329 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
330 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
331 |
cLocaleFName:= ParamStr(10); |
|
332 |
cFullScreen:= ParamStr(11) = '1'; |
|
333 |
cAltDamage:= ParamStr(12) = '1'; |
|
334 |
cShowFPS:= ParamStr(13) = '1'; |
|
335 |
val(ParamStr(14), cTimerInterval); |
|
336 |
cReducedQuality:= ParamStr(15) = '1'; |
|
337 |
end |
|
338 |
else DisplayUsage; |
|
339 |
||
340 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
341 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
342 |
end; |
|
343 |
else DisplayUsage; |
|
344 |
end; |
|
51 | 345 |
end; |
346 |
||
2016 | 347 |
///////////////////////// |
51 | 348 |
procedure ShowMainWindow; |
349 |
begin |
|
351 | 350 |
if cFullScreen then ParseCommand('fullscr 1', true) |
351 |
else ParseCommand('fullscr 0', true); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
271
diff
changeset
|
352 |
SDL_ShowCursor(0) |
51 | 353 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
354 |
|
160 | 355 |
/////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
356 |
procedure Game; |
205 | 357 |
var s: shortstring; |
51 | 358 |
begin |
359 |
WriteToConsole('Init SDL... '); |
|
360 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
361 |
WriteLnToConsole(msgOK); |
|
753 | 362 |
|
377 | 363 |
SDL_EnableUNICODE(1); |
51 | 364 |
|
365 |
WriteToConsole('Init SDL_ttf... '); |
|
200 | 366 |
SDLTry(TTF_Init <> -1, true); |
51 | 367 |
WriteLnToConsole(msgOK); |
368 |
||
369 |
ShowMainWindow; |
|
370 |
||
371 |
InitKbdKeyTable; |
|
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
372 |
|
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
373 |
if recordFileName = '' then InitIPC; |
51 | 374 |
WriteLnToConsole(msgGettingConfig); |
80 | 375 |
|
2039 | 376 |
if cLocaleFName <> 'en.txt' then |
377 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
80 | 378 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
379 |
||
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
380 |
if recordFileName = '' then |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
381 |
SendIPCAndWaitReply('C') // ask for game config |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
382 |
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
|
383 |
begin |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
384 |
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
|
385 |
end; |
205 | 386 |
|
387 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
388 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
389 |
||
51 | 390 |
InitTeams; |
288 | 391 |
AssignStores; |
51 | 392 |
|
393 |
if isSoundEnabled then InitSound; |
|
394 |
||
395 |
StoreInit; |
|
396 |
||
397 |
isDeveloperMode:= false; |
|
398 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
399 |
TryDo(InitStepsFlags = cifAllInited, |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
400 |
'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
|
401 |
true); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
402 |
|
51 | 403 |
MainLoop |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
404 |
end; |
51 | 405 |
|
160 | 406 |
///////////////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
407 |
procedure GenLandPreview; |
566 | 408 |
var Preview: TPreview; |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
409 |
h: byte; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
410 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
411 |
InitIPC; |
159 | 412 |
IPCWaitPongEvent; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
413 |
TryDo(InitStepsFlags = cifRandomize, |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
414 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
415 |
true); |
160 | 416 |
|
566 | 417 |
Preview:= GenPreview; |
159 | 418 |
WriteLnToConsole('Sending preview...'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
419 |
SendIPCRaw(@Preview, sizeof(Preview)); |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
420 |
h:= MaxHedgehogs; |
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
421 |
SendIPCRaw(@h, sizeof(h)); |
159 | 422 |
WriteLnToConsole('Preview sent, disconnect'); |
158 | 423 |
CloseIPC |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
424 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
425 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
426 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
427 |
/////////////////////////////// m a i n //////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
428 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
429 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
430 |
begin |
2006 | 431 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
432 |
GetParams; |
2145 | 433 |
// FIXME - hack in font with support for CJK |
2105 | 434 |
if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then |
435 |
Fontz:= FontzCJK; |
|
436 |
||
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
437 |
Randomize; |
2008 | 438 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
439 |
if GameType = gmtLandPreview then GenLandPreview |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
440 |
else Game |
51 | 441 |
end. |
2008 | 442 |