author | unc0rr |
Fri, 19 Jun 2009 17:56:52 +0000 | |
changeset 2173 | 98cde8645e21 |
parent 2171 | 8208946331ba |
child 2191 | 20c62f787a4d |
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 |
172 |
SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
|
173 |
SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
|
174 |
cHasFocus:= event.active.gain = 1; |
|
1127 | 175 |
//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
1120 | 176 |
SDL_QUITEV: isTerminated:= true |
177 |
end; |
|
51 | 178 |
CurrTime:= SDL_GetTicks; |
179 |
if PrevTime + cTimerInterval <= CurrTime then |
|
180 |
begin |
|
181 |
DoTimer(CurrTime - PrevTime); |
|
182 |
PrevTime:= CurrTime |
|
434 | 183 |
end else SDL_Delay(1); |
51 | 184 |
IPCCheckSock |
185 |
until isTerminated |
|
186 |
end; |
|
187 |
||
2008 | 188 |
///////////////////// |
189 |
procedure DisplayUsage; |
|
190 |
begin |
|
191 |
WriteLn('Wrong argument format: correct configurations is'); |
|
192 |
WriteLn(); |
|
193 |
WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
|
194 |
WriteLn(); |
|
195 |
WriteLn('where [option] must be specified either as'); |
|
196 |
WriteLn(' --set-video [screen height] [screen width] [color dept]'); |
|
197 |
WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
|
198 |
WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
|
199 |
WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
200 |
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]'); |
|
201 |
WriteLn(); |
|
2015 | 202 |
WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
203 |
halt(1); |
|
2008 | 204 |
end; |
205 |
||
51 | 206 |
//////////////////// |
207 |
procedure GetParams; |
|
889 | 208 |
var |
267 | 209 |
{$IFDEF DEBUGFILE} |
371 | 210 |
i: LongInt; |
267 | 211 |
{$ENDIF} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
212 |
p: TPathType; |
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
213 |
begin |
51 | 214 |
{$IFDEF DEBUGFILE} |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
81
diff
changeset
|
215 |
AddFileLog('Prefix: "' + PathPrefix +'"'); |
51 | 216 |
for i:= 0 to ParamCount do |
217 |
AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
|
218 |
{$ENDIF} |
|
267 | 219 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
220 |
case ParamCount of |
1892 | 221 |
16: begin |
498 | 222 |
val(ParamStr(2), cScreenWidth); |
223 |
val(ParamStr(3), cScreenHeight); |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
224 |
cInitWidth:= cScreenWidth; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1120
diff
changeset
|
225 |
cInitHeight:= cScreenHeight; |
497 | 226 |
cBitsStr:= ParamStr(4); |
498 | 227 |
val(cBitsStr, cBits); |
228 |
val(ParamStr(5), ipcPort); |
|
497 | 229 |
cFullScreen:= ParamStr(6) = '1'; |
230 |
isSoundEnabled:= ParamStr(7) = '1'; |
|
231 |
cLocaleFName:= ParamStr(8); |
|
498 | 232 |
val(ParamStr(9), cInitVolume); |
233 |
val(ParamStr(10), cTimerInterval); |
|
497 | 234 |
PathPrefix:= ParamStr(11); |
235 |
cShowFPS:= ParamStr(12) = '1'; |
|
529 | 236 |
cAltDamage:= ParamStr(13) = '1'; |
949 | 237 |
UserNick:= DecodeBase64(ParamStr(14)); |
1128 | 238 |
isMusicEnabled:= ParamStr(15) = '1'; |
1812 | 239 |
cReducedQuality:= ParamStr(16) = '1'; |
267 | 240 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
949 | 241 |
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
|
242 |
end; |
497 | 243 |
3: begin |
498 | 244 |
val(ParamStr(2), ipcPort); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
245 |
GameType:= gmtLandPreview; |
497 | 246 |
if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true); |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
247 |
end; |
2008 | 248 |
2: begin |
249 |
PathPrefix:= ParamStr(1); |
|
250 |
recordFileName:= ParamStr(2); |
|
251 |
||
252 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
253 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
254 |
end; |
|
255 |
6: begin |
|
256 |
PathPrefix:= ParamStr(1); |
|
257 |
recordFileName:= ParamStr(2); |
|
258 |
||
259 |
if ParamStr(3) = '--set-video' then |
|
260 |
begin |
|
261 |
val(ParamStr(4), cScreenWidth); |
|
262 |
val(ParamStr(5), cScreenHeight); |
|
263 |
cInitWidth:= cScreenWidth; |
|
264 |
cInitHeight:= cScreenHeight; |
|
265 |
cBitsStr:= ParamStr(6); |
|
266 |
val(cBitsStr, cBits); |
|
267 |
end |
|
268 |
else |
|
269 |
begin |
|
270 |
if ParamStr(3) = '--set-audio' then |
|
271 |
begin |
|
272 |
val(ParamStr(4), cInitVolume); |
|
273 |
isMusicEnabled:= ParamStr(5) = '1'; |
|
274 |
isSoundEnabled:= ParamStr(6) = '1'; |
|
275 |
end |
|
276 |
else |
|
277 |
begin |
|
278 |
if ParamStr(3) = '--set-other' then |
|
279 |
begin |
|
280 |
cLocaleFName:= ParamStr(4); |
|
281 |
cFullScreen:= ParamStr(5) = '1'; |
|
282 |
cShowFPS:= ParamStr(6) = '1'; |
|
283 |
end |
|
284 |
else DisplayUsage; |
|
285 |
end |
|
286 |
end; |
|
287 |
||
288 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
289 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
290 |
end; |
|
291 |
11: begin |
|
292 |
PathPrefix:= ParamStr(1); |
|
293 |
recordFileName:= ParamStr(2); |
|
294 |
||
295 |
if ParamStr(3) = '--set-multimedia' then |
|
296 |
begin |
|
297 |
val(ParamStr(4), cScreenWidth); |
|
298 |
val(ParamStr(5), cScreenHeight); |
|
299 |
cInitWidth:= cScreenWidth; |
|
300 |
cInitHeight:= cScreenHeight; |
|
301 |
cBitsStr:= ParamStr(6); |
|
302 |
val(cBitsStr, cBits); |
|
303 |
val(ParamStr(7), cInitVolume); |
|
304 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
305 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
306 |
cLocaleFName:= ParamStr(10); |
|
307 |
cFullScreen:= ParamStr(11) = '1'; |
|
308 |
end |
|
309 |
else DisplayUsage; |
|
310 |
||
311 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
312 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
313 |
end; |
|
314 |
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
|
315 |
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
|
316 |
recordFileName:= ParamStr(2); |
2008 | 317 |
if ParamStr(3) = '--set-everything' then |
318 |
begin |
|
319 |
val(ParamStr(4), cScreenWidth); |
|
320 |
val(ParamStr(5), cScreenHeight); |
|
321 |
cInitWidth:= cScreenWidth; |
|
322 |
cInitHeight:= cScreenHeight; |
|
323 |
cBitsStr:= ParamStr(6); |
|
324 |
val(cBitsStr, cBits); |
|
325 |
val(ParamStr(7), cInitVolume); |
|
326 |
isMusicEnabled:= ParamStr(8) = '1'; |
|
327 |
isSoundEnabled:= ParamStr(9) = '1'; |
|
328 |
cLocaleFName:= ParamStr(10); |
|
329 |
cFullScreen:= ParamStr(11) = '1'; |
|
330 |
cAltDamage:= ParamStr(12) = '1'; |
|
331 |
cShowFPS:= ParamStr(13) = '1'; |
|
332 |
val(ParamStr(14), cTimerInterval); |
|
333 |
cReducedQuality:= ParamStr(15) = '1'; |
|
334 |
end |
|
335 |
else DisplayUsage; |
|
336 |
||
337 |
for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
338 |
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
339 |
end; |
|
340 |
else DisplayUsage; |
|
341 |
end; |
|
51 | 342 |
end; |
343 |
||
2016 | 344 |
///////////////////////// |
51 | 345 |
procedure ShowMainWindow; |
346 |
begin |
|
351 | 347 |
if cFullScreen then ParseCommand('fullscr 1', true) |
348 |
else ParseCommand('fullscr 0', true); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
271
diff
changeset
|
349 |
SDL_ShowCursor(0) |
51 | 350 |
end; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
351 |
|
160 | 352 |
/////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
353 |
procedure Game; |
205 | 354 |
var s: shortstring; |
51 | 355 |
begin |
356 |
WriteToConsole('Init SDL... '); |
|
357 |
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
358 |
WriteLnToConsole(msgOK); |
|
753 | 359 |
|
377 | 360 |
SDL_EnableUNICODE(1); |
51 | 361 |
|
362 |
WriteToConsole('Init SDL_ttf... '); |
|
200 | 363 |
SDLTry(TTF_Init <> -1, true); |
51 | 364 |
WriteLnToConsole(msgOK); |
365 |
||
366 |
ShowMainWindow; |
|
367 |
||
368 |
InitKbdKeyTable; |
|
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
369 |
|
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
370 |
if recordFileName = '' then InitIPC; |
51 | 371 |
WriteLnToConsole(msgGettingConfig); |
80 | 372 |
|
2039 | 373 |
if cLocaleFName <> 'en.txt' then |
374 |
LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
80 | 375 |
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
376 |
||
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
377 |
if recordFileName = '' then |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
378 |
SendIPCAndWaitReply('C') // ask for game config |
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
379 |
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
|
380 |
begin |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1825
diff
changeset
|
381 |
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
|
382 |
end; |
205 | 383 |
|
384 |
s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
385 |
SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
386 |
||
51 | 387 |
InitTeams; |
288 | 388 |
AssignStores; |
51 | 389 |
|
390 |
if isSoundEnabled then InitSound; |
|
391 |
||
392 |
StoreInit; |
|
393 |
||
394 |
isDeveloperMode:= false; |
|
395 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
396 |
TryDo(InitStepsFlags = cifAllInited, |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
397 |
'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
|
398 |
true); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
54
diff
changeset
|
399 |
|
51 | 400 |
MainLoop |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
401 |
end; |
51 | 402 |
|
160 | 403 |
///////////////////////// |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
404 |
procedure GenLandPreview; |
566 | 405 |
var Preview: TPreview; |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
406 |
h: byte; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
407 |
begin |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
408 |
InitIPC; |
159 | 409 |
IPCWaitPongEvent; |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
410 |
TryDo(InitStepsFlags = cifRandomize, |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
411 |
'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
412 |
true); |
160 | 413 |
|
566 | 414 |
Preview:= GenPreview; |
159 | 415 |
WriteLnToConsole('Sending preview...'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
416 |
SendIPCRaw(@Preview, sizeof(Preview)); |
1791
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
417 |
h:= MaxHedgehogs; |
7c9d645d2591
Fix passing hedgehogs number from engine to frontend
unc0rr
parents:
1784
diff
changeset
|
418 |
SendIPCRaw(@h, sizeof(h)); |
159 | 419 |
WriteLnToConsole('Preview sent, disconnect'); |
158 | 420 |
CloseIPC |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
421 |
end; |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
422 |
|
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 |
/////////////////////////////// m a i n //////////////////////////////////////// |
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 |
begin |
2006 | 428 |
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine'); |
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
429 |
GetParams; |
2145 | 430 |
// FIXME - hack in font with support for CJK |
2105 | 431 |
if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then |
432 |
Fontz:= FontzCJK; |
|
433 |
||
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
434 |
Randomize; |
2008 | 435 |
|
155
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
436 |
if GameType = gmtLandPreview then GenLandPreview |
401f4ea24715
Engine can generate land preview and send it via IPC
unc0rr
parents:
109
diff
changeset
|
437 |
else Game |
51 | 438 |
end. |
2008 | 439 |