author | nemo |
Thu, 25 Jun 2009 10:49:05 +0000 | |
changeset 2194 | 1597710c6118 |
parent 2191 | 20c62f787a4d |
child 2243 | b4764993f833 |
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); |
1080 | 75 |
var s: string; |
51 | 76 |
begin |
564 | 77 |
inc(RealTicks, Lag); |
78 |
||
51 | 79 |
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
|
80 |
gsLandGen: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
81 |
GenMap; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
82 |
GameState:= gsStart; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
83 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
84 |
gsStart: begin |
1784 | 85 |
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
|
86 |
AddClouds; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
87 |
AssignHHCoords; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
88 |
AddMiscGears; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
89 |
StoreLoad; |
1825 | 90 |
InitWorld; |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
91 |
ResetKbd; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
92 |
SoundLoad; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
93 |
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
|
94 |
begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
95 |
isSEBackup:= isSoundEnabled; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
96 |
isSoundEnabled:= false |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
97 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
98 |
FinishProgress; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
99 |
PlayMusic; |
2162 | 100 |
SetScale(zoom); |
1524
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
101 |
GameState:= gsGame |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
102 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
103 |
gsConfirm, |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
104 |
gsGame: begin |
1645 | 105 |
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
|
106 |
ProcessKbd; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
107 |
DoGameTick(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
108 |
ProcessVisualGears(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
109 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
110 |
gsChat: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
111 |
DrawWorld(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
112 |
DoGameTick(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
113 |
ProcessVisualGears(Lag); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
114 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
115 |
gsExit: begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
116 |
OnDestroy; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
117 |
end; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
118 |
end; |
564 | 119 |
|
753 | 120 |
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
|
121 |
{$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
|
122 |
//not going to make captures on the iPhone |
51 | 123 |
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
|
124 |
begin |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
125 |
flagMakeCapture:= false; |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
126 |
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
|
127 |
WriteLnToConsole('Saving ' + s); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
128 |
MakeScreenshot(s); |
5a652a465559
Draw world before processing gears, as this should improve performance by introducing cpu-gpu parallelizm
unc0rr
parents:
1128
diff
changeset
|
129 |
// 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
|
130 |
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
|
131 |
{$ENDIF} |
51 | 132 |
end; |
133 |
||
134 |
//////////////////// |
|
79 | 135 |
procedure OnDestroy; |
51 | 136 |
begin |
137 |
{$IFDEF DEBUGFILE}AddFileLog('Freeing resources...');{$ENDIF} |
|
138 |
if isSoundEnabled then ReleaseSound; |
|
619 | 139 |
StoreRelease; |
1807 | 140 |
FreeLand; |
619 | 141 |
SendKB; |
51 | 142 |
CloseIPC; |
143 |
TTF_Quit; |
|
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
|
144 |
{$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
|
145 |
//i know it is not clean but it is better than a crash |
51 | 146 |
SDL_Quit; |
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
|
147 |
{$ENDIF} |
51 | 148 |
halt |
149 |
end; |
|
150 |
||
1120 | 151 |
//////////////////////////////// |
152 |
procedure Resize(w, h: LongInt); |
|
153 |
begin |
|
154 |
cScreenWidth:= w; |
|
155 |
cScreenHeight:= h; |
|
156 |
if cFullScreen then |
|
157 |
ParseCommand('/fullscr 1', true) |
|
158 |
else |
|
159 |
ParseCommand('/fullscr 0', true); |
|
160 |
end; |
|
161 |
||
51 | 162 |
/////////////////// |
163 |
procedure MainLoop; |
|
164 |
var PrevTime, |
|
188 | 165 |
CurrTime: Longword; |
51 | 166 |
event: TSDL_Event; |
167 |
begin |
|
168 |
PrevTime:= SDL_GetTicks; |
|
169 |
repeat |
|
170 |
while SDL_PollEvent(@event) <> 0 do |
|
1120 | 171 |
case event.type_ of |
2191 | 172 |
{thinker here for adding touch events} |
1120 | 173 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
174 |
SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
|
175 |
cHasFocus:= event.active.gain = 1; |
|
1127 | 176 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
1120 | 177 |
SDL_QUITEV: isTerminated:= true |
178 |
end; |
|
51 | 179 |
CurrTime:= SDL_GetTicks; |
180 |
if PrevTime + cTimerInterval <= CurrTime then |
|
181 |
begin |
|
182 |
DoTimer(CurrTime - PrevTime); |
|
183 |
PrevTime:= CurrTime |
|
434 | 184 |
end else SDL_Delay(1); |
51 | 185 |
IPCCheckSock |
186 |
until isTerminated |
|
187 |
end; |
|
188 |
||
2008 | 189 |
///////////////////// |
190 |
procedure DisplayUsage; |
|
191 |
begin |
|
192 |
WriteLn('Wrong argument format: correct configurations is'); |
|
193 |
WriteLn(); |
|
194 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
195 |
WriteLn(); |
|
196 |
WriteLn('where [option] must be specified either as'); |
|
197 |
WriteLn(' --set-video [screen height] [screen width] [color dept]'); |
|
198 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
|
199 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
200 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
201 |
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]'); |
|
202 |
WriteLn(); |
|
2015 | 203 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
204 |
halt(1); |
|
2008 | 205 |
end; |
206 |
||
51 | 207 |
//////////////////// |
208 |
procedure GetParams; |
|
889 | 209 |
var |
267 | 210 |
{$IFDEF DEBUGFILE} |
371 | 211 |
i: LongInt; |
267 | 212 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
213 |
p: TPathType; |
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
214 |
begin |
51 | 215 |
{$IFDEF DEBUGFILE} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
216 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
51 | 217 |
for i:= 0 to ParamCount do |
218 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
219 |
{$ENDIF} |
|
267 | 220 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
221 |
case ParamCount of |
1892 | 222 |
16: begin |
498 | 223 |
val(ParamStr(2), cScreenWidth); |
224 |
val(ParamStr(3), cScreenHeight); |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
225 |
cInitWidth:= cScreenWidth; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
226 |
cInitHeight:= cScreenHeight; |
497 | 227 |
cBitsStr:= ParamStr(4); |
498 | 228 |
val(cBitsStr, cBits); |
229 |
val(ParamStr(5), ipcPort); |
|
497 | 230 |
cFullScreen:= ParamStr(6) = '1'; |
231 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
232 |
cLocaleFName:= ParamStr(8); |
|
498 | 233 |
val(ParamStr(9), cInitVolume); |
234 |
val(ParamStr(10), cTimerInterval); |
|
497 | 235 |
PathPrefix:= ParamStr(11); |
236 |
cShowFPS:= ParamStr(12) = '1'; |
|
529 | 237 |
cAltDamage:= ParamStr(13) = '1'; |
949 | 238 |
UserNick:= DecodeBase64(ParamStr(14)); |
1128 | 239 |
isMusicEnabled:= ParamStr(15) = '1'; |
1812 | 240 |
cReducedQuality:= ParamStr(16) = '1'; |
267 | 241 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
949 | 242 |
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
|
243 |
end; |
497 | 244 |
3: begin |
498 | 245 |
val(ParamStr(2), ipcPort); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
246 |
GameType:= gmtLandPreview; |
497 | 247 |
if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true); |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
248 |
end; |
2008 | 249 |
2: begin |
250 |
PathPrefix:= ParamStr(1); |
|
251 |
recordFileName:= ParamStr(2); |
|
252 |
||
253 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
254 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
255 |
end; |
|
256 |
6: begin |
|
257 |
PathPrefix:= ParamStr(1); |
|
258 |
recordFileName:= ParamStr(2); |
|
259 |
||
260 |
if ParamStr(3) = '--set-video' then |
|
261 |
begin |
|
262 |
val(ParamStr(4), cScreenWidth); |
|
263 |
val(ParamStr(5), cScreenHeight); |
|
264 |
cInitWidth:= cScreenWidth; |
|
265 |
cInitHeight:= cScreenHeight; |
|
266 |
cBitsStr:= ParamStr(6); |
|
267 |
val(cBitsStr, cBits); |
|
268 |
end |
|
269 |
else |
|
270 |
begin |
|
271 |
if ParamStr(3) = '--set-audio' then |
|
272 |
begin |
|
273 |
val(ParamStr(4), cInitVolume); |
|
274 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
275 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
276 |
end |
|
277 |
else |
|
278 |
begin |
|
279 |
if ParamStr(3) = '--set-other' then |
|
280 |
begin |
|
281 |
cLocaleFName:= ParamStr(4); |
|
282 |
cFullScreen:= ParamStr(5) = '1'; |
|
283 |
cShowFPS:= ParamStr(6) = '1'; |
|
284 |
end |
|
285 |
else DisplayUsage; |
|
286 |
end |
|
287 |
end; |
|
288 |
||
289 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
290 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
291 |
end; |
|
292 |
11: begin |
|
293 |
PathPrefix:= ParamStr(1); |
|
294 |
recordFileName:= ParamStr(2); |
|
295 |
||
296 |
if ParamStr(3) = '--set-multimedia' then |
|
297 |
begin |
|
298 |
val(ParamStr(4), cScreenWidth); |
|
299 |
val(ParamStr(5), cScreenHeight); |
|
300 |
cInitWidth:= cScreenWidth; |
|
301 |
cInitHeight:= cScreenHeight; |
|
302 |
cBitsStr:= ParamStr(6); |
|
303 |
val(cBitsStr, cBits); |
|
304 |
val(ParamStr(7), cInitVolume); |
|
305 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
306 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
307 |
cLocaleFName:= ParamStr(10); |
|
308 |
cFullScreen:= ParamStr(11) = '1'; |
|
309 |
end |
|
310 |
else DisplayUsage; |
|
311 |
||
312 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
313 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
314 |
end; |
|
315 |
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
|
316 |
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
|
317 |
recordFileName:= ParamStr(2); |
2008 | 318 |
if ParamStr(3) = '--set-everything' then |
319 |
begin |
|
320 |
val(ParamStr(4), cScreenWidth); |
|
321 |
val(ParamStr(5), cScreenHeight); |
|
322 |
cInitWidth:= cScreenWidth; |
|
323 |
cInitHeight:= cScreenHeight; |
|
324 |
cBitsStr:= ParamStr(6); |
|
325 |
val(cBitsStr, cBits); |
|
326 |
val(ParamStr(7), cInitVolume); |
|
327 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
328 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
329 |
cLocaleFName:= ParamStr(10); |
|
330 |
cFullScreen:= ParamStr(11) = '1'; |
|
331 |
cAltDamage:= ParamStr(12) = '1'; |
|
332 |
cShowFPS:= ParamStr(13) = '1'; |
|
333 |
val(ParamStr(14), cTimerInterval); |
|
334 |
cReducedQuality:= ParamStr(15) = '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 |
else DisplayUsage; |
|
342 |
end; |
|
51 | 343 |
end; |
344 |
||
2016 | 345 |
///////////////////////// |
51 | 346 |
procedure ShowMainWindow; |
347 |
begin |
|
351 | 348 |
if cFullScreen then ParseCommand('fullscr 1', true) |
349 |
else ParseCommand('fullscr 0', true); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
271
diff
changeset
|
350 |
SDL_ShowCursor(0) |
51 | 351 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
352 |
|
160 | 353 |
/////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
354 |
procedure Game; |
205 | 355 |
var s: shortstring; |
51 | 356 |
begin |
357 |
WriteToConsole('Init SDL... '); |
|
358 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
359 |
WriteLnToConsole(msgOK); |
|
753 | 360 |
|
377 | 361 |
SDL_EnableUNICODE(1); |
51 | 362 |
|
363 |
WriteToConsole('Init SDL_ttf... '); |
|
200 | 364 |
SDLTry(TTF_Init <> -1, true); |
51 | 365 |
WriteLnToConsole(msgOK); |
366 |
||
367 |
ShowMainWindow; |
|
368 |
||
369 |
InitKbdKeyTable; |
|
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
370 |
|
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
371 |
if recordFileName = '' then InitIPC; |
51 | 372 |
WriteLnToConsole(msgGettingConfig); |
80 | 373 |
|
2039 | 374 |
if cLocaleFName <> 'en.txt' then |
375 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
80 | 376 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
377 |
||
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
378 |
if recordFileName = '' then |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
379 |
SendIPCAndWaitReply('C') // ask for game config |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
380 |
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
|
381 |
begin |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
382 |
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
|
383 |
end; |
205 | 384 |
|
385 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
386 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
387 |
||
51 | 388 |
InitTeams; |
288 | 389 |
AssignStores; |
51 | 390 |
|
391 |
if isSoundEnabled then InitSound; |
|
392 |
||
393 |
StoreInit; |
|
394 |
||
395 |
isDeveloperMode:= false; |
|
396 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
397 |
TryDo(InitStepsFlags = cifAllInited, |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
398 |
'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
|
399 |
true); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
400 |
|
51 | 401 |
MainLoop |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
402 |
end; |
51 | 403 |
|
160 | 404 |
///////////////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
405 |
procedure GenLandPreview; |
566 | 406 |
var Preview: TPreview; |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
407 |
h: byte; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
408 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
409 |
InitIPC; |
159 | 410 |
IPCWaitPongEvent; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
411 |
TryDo(InitStepsFlags = cifRandomize, |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
412 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
413 |
true); |
160 | 414 |
|
566 | 415 |
Preview:= GenPreview; |
159 | 416 |
WriteLnToConsole('Sending preview...'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
417 |
SendIPCRaw(@Preview, sizeof(Preview)); |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
418 |
h:= MaxHedgehogs; |
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
419 |
SendIPCRaw(@h, sizeof(h)); |
159 | 420 |
WriteLnToConsole('Preview sent, disconnect'); |
158 | 421 |
CloseIPC |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
422 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
423 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
424 |
//////////////////////////////////////////////////////////////////////////////// |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
425 |
/////////////////////////////// m a i n //////////////////////////////////////// |
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 |
|
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
428 |
begin |
2006 | 429 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
430 |
GetParams; |
2145 | 431 |
// FIXME - hack in font with support for CJK |
2105 | 432 |
if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then |
433 |
Fontz:= FontzCJK; |
|
434 |
||
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
435 |
Randomize; |
2008 | 436 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
437 |
if GameType = gmtLandPreview then GenLandPreview |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
438 |
else Game |
51 | 439 |
end. |
2008 | 440 |