author | koda |
Thu, 06 Dec 2012 00:44:27 +0100 | |
changeset 8252 | db3bccd784c9 |
parent 8221 | 5e2dc5813408 |
child 8278 | 9cdfcb5b7ddd |
child 8302 | a7934cd12469 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
18 |
|
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
19 |
|
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
20 |
procedure internalStartGameWithParameters(); |
4004
b1c2c2f6fc5e
update branch with latest head, most likely breaking water color in stereo mode
koda
parents:
3858
diff
changeset
|
21 |
var tmp: LongInt; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
22 |
begin |
5239 | 23 |
UserPathPrefix:= ParamStr(1); |
7151 | 24 |
cScreenWidth:= StrToInt(ParamStr(2)); |
25 |
cScreenHeight:= StrToInt(ParamStr(3)); |
|
26 |
cBits:= StrToInt(ParamStr(4)); |
|
27 |
ipcPort:= StrToInt(ParamStr(5)); |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
28 |
cFullScreen:= ParamStr(6) = '1'; |
7021
0c75512a8920
adjust the scope of a few uSound variables and functions
koda
parents:
6982
diff
changeset
|
29 |
SetSound(ParamStr(7) = '1'); |
0c75512a8920
adjust the scope of a few uSound variables and functions
koda
parents:
6982
diff
changeset
|
30 |
SetMusic(ParamStr(8) = '1'); |
7151 | 31 |
SetVolume(StrToInt(ParamStr(9))); |
32 |
cTimerInterval:= StrToInt(ParamStr(10)); |
|
3709 | 33 |
PathPrefix:= ParamStr(11); |
34 |
cShowFPS:= ParamStr(12) = '1'; |
|
35 |
cAltDamage:= ParamStr(13) = '1'; |
|
36 |
UserNick:= DecodeBase64(ParamStr(14)); |
|
7151 | 37 |
cReducedQuality:= StrToInt(ParamStr(15)); |
38 |
tmp:= StrToInt(ParamStr(16)); |
|
6982 | 39 |
GrayScale:= false; |
8221 | 40 |
{$IFDEF USE_S3D_RENDERING} |
41 |
if (tmp > 9) and (tmp < 16) then |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5239
diff
changeset
|
42 |
begin |
8221 | 43 |
// set the gray anaglyph rendering |
6982 | 44 |
GrayScale:= true; |
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5239
diff
changeset
|
45 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9))) |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
5239
diff
changeset
|
46 |
end |
8221 | 47 |
else if tmp <= 9 then |
48 |
// set the fullcolor anaglyph |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6426
diff
changeset
|
49 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp))) |
8221 | 50 |
else |
51 |
// any other mode |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6426
diff
changeset
|
52 |
cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6))); |
8221 | 53 |
{$ELSE} |
54 |
cStereoMode:= smNone; |
|
55 |
{$ENDIF} |
|
4004
b1c2c2f6fc5e
update branch with latest head, most likely breaking water color in stereo mode
koda
parents:
3858
diff
changeset
|
56 |
cLocaleFName:= ParamStr(17); |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
57 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
58 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
59 |
{$IFDEF USE_VIDEO_RECORDING} |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
60 |
procedure internalStartVideoRecordingWithParameters(); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
61 |
begin |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
62 |
internalStartGameWithParameters(); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
63 |
GameType:= gmtRecord; |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
64 |
cVideoFramerateNum:= StrToInt(ParamStr(18)); |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
65 |
cVideoFramerateDen:= StrToInt(ParamStr(19)); |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
66 |
RecPrefix:= ParamStr(20); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
67 |
cAVFormat:= ParamStr(21); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
68 |
cVideoCodec:= ParamStr(22); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
69 |
cVideoQuality:= StrToInt(ParamStr(23)); |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
70 |
cAudioCodec:= ParamStr(24); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
71 |
end; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
72 |
{$ENDIF} |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
73 |
|
8150 | 74 |
procedure DisplayUsage; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
75 |
begin |
8150 | 76 |
WriteLn(stdout, 'Usage:'); |
77 |
WriteLn(stdout, ''); |
|
8167
96635d815141
Make user folder default to global folder in hwengine
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
8150
diff
changeset
|
78 |
WriteLn(stdout, ' hwengine [path to user hedgewars folder] <path to global data folder> <path to replay file> [options]'); |
8150 | 79 |
WriteLn(stdout, ''); |
80 |
WriteLn(stdout, 'where [options] are any of the following:'); |
|
81 |
WriteLn(stdout, ' --locale [path to language file]'); |
|
82 |
WriteLn(stdout, ' --width [screen width in pixels]'); |
|
83 |
WriteLn(stdout, ' --height [screen height in pixels]'); |
|
84 |
WriteLn(stdout, ' --depth [color depth]'); |
|
85 |
WriteLn(stdout, ' --volume [sound level]'); |
|
86 |
WriteLn(stdout, ' --time [number of seconds]'); |
|
87 |
WriteLn(stdout, ' --nomusic'); |
|
88 |
WriteLn(stdout, ' --nosound'); |
|
89 |
WriteLn(stdout, ' --fullscreen'); |
|
90 |
WriteLn(stdout, ' --showfps'); |
|
91 |
WriteLn(stdout, ' --altdmg'); |
|
92 |
WriteLn(stdout, ' --lowquality'); |
|
93 |
WriteLn(stdout, ' --stats-only'); |
|
94 |
WriteLn(stdout, ' --help'); |
|
95 |
WriteLn(stdout, ''); |
|
96 |
WriteLn(stdout, 'Deprecated options:'); |
|
97 |
WriteLn(stdout, ' --set-video [screen width] [screen height] [color dept]'); |
|
98 |
WriteLn(stdout, ' --set-audio [volume] [enable music] [enable sounds]'); |
|
99 |
WriteLn(stdout, ' --set-other [language file] [full screen] [show FPS]'); |
|
100 |
WriteLn(stdout, ' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
|
101 |
WriteLn(stdout, ' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); |
|
102 |
WriteLn(stdout, ''); |
|
103 |
WriteLn(stdout, 'For a more detailed help and examples go to:'); |
|
104 |
WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions'); |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
105 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
106 |
|
8150 | 107 |
function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt; |
108 |
var tmpInt, c: LongInt; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
109 |
begin |
8150 | 110 |
paramIndex:= paramIndex + 1; |
111 |
val(str, tmpInt, c); |
|
112 |
wrongParameter:= c <> 0; |
|
113 |
if wrongParameter then |
|
114 |
WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"'); |
|
115 |
getLongIntParameter:= tmpInt; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
116 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
117 |
|
8150 | 118 |
function getStringParameter(str:String; var paramIndex:LongInt): String; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
119 |
begin |
8150 | 120 |
paramIndex:= paramIndex + 1; |
121 |
getStringParameter:= str; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
122 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
123 |
|
8150 | 124 |
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward; |
125 |
||
126 |
function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean; |
|
127 |
const videoArray: Array [1..3] of String = ('--width','--height','--depth'); |
|
128 |
const audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound'); |
|
129 |
const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps'); |
|
130 |
const mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen'); |
|
131 |
const allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--time','--lowquality'); |
|
8197 | 132 |
const reallyAll: array[0..19] of shortstring = ( |
133 |
'--locale', '--width', '--height', '--depth', '--time' |
|
134 |
, '--volume', '--nomusic', '--nosound', '--fullscreen', '--showfps' |
|
135 |
, '--altdmg', '--lowquality', '--set-video', '--set-audio', '--set-other' |
|
136 |
, '--set-multimedia', '--set-everything', '--stats-only', '--gci', '--help'); |
|
137 |
var cmdIndex: byte; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
138 |
begin |
8150 | 139 |
parseParameter:= false; |
8197 | 140 |
cmdIndex:= 0; |
141 |
while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex); |
|
142 |
case cmdIndex of |
|
143 |
{--locale} 0 : cLocaleFName := getStringParameter (arg, paramIndex); |
|
144 |
{--width} 1 : cScreenWidth := getLongIntParameter(arg, paramIndex, parseParameter); |
|
145 |
{--height} 2 : cScreenHeight := getLongIntParameter(arg, paramIndex, parseParameter); |
|
146 |
{--depth} 3 : cBits := getLongIntParameter(arg, paramIndex, parseParameter); |
|
147 |
{--time} 4 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter); |
|
148 |
{--volume} 5 : SetVolume ( getLongIntParameter(arg, paramIndex, parseParameter) ); |
|
149 |
{--nomusic} 6 : SetMusic ( false ); |
|
150 |
{--nosound} 7 : SetSound ( false ); |
|
151 |
{--fullscreen} 8 : cFullScreen := true; |
|
152 |
{--showfps} 9 : cShowFPS := true; |
|
153 |
{--altdmg} 10 : cAltDamage := true; |
|
154 |
{--lowquality} 11 : cReducedQuality:= ($FFFFFFFF * getLongIntParameter(arg, paramIndex, parseParameter)) xor rqLowRes; //HACK! |
|
155 |
{--set-video} 12 : parseClassicParameter(videoArray,3,paramIndex); |
|
156 |
{--set-audio} 13 : parseClassicParameter(audioArray,3,paramIndex); |
|
157 |
{--set-other} 14 : parseClassicParameter(otherArray,3,paramIndex); |
|
158 |
{--set-multimedia} 15 : parseClassicParameter(mediaArray,8,paramIndex); |
|
159 |
{--set-everything} 16 : parseClassicParameter(allArray,12,paramIndex); |
|
160 |
{--stats-only} 17 : begin |
|
161 |
cOnlyStats:= true; |
|
162 |
SetSound(false); |
|
163 |
SetMusic(false); |
|
164 |
cReducedQuality:= $FFFFFFFF xor rqLowRes; |
|
165 |
end; |
|
166 |
{--gci} 18 : begin // We had to make up all this saved space some how... \\ |
|
167 |
WriteLn(stdout, ' '); |
|
168 |
WriteLn(stdout, ' /\\\\\\\\\\\\ /\\\\\\\\\ /\\\\\\\\\\\ '); |
|
169 |
WriteLn(stdout, ' /\\\////////// /\\\//////// \/////\\\/// '); |
|
170 |
WriteLn(stdout, ' /\\\ /\\\/ \/\\\ '); |
|
171 |
WriteLn(stdout, ' \/\\\ /\\\\\\\ /\\\ \/\\\ '); |
|
172 |
WriteLn(stdout, ' \/\\\ \/////\\\ \/\\\ \/\\\ '); |
|
173 |
WriteLn(stdout, ' \/\\\ \/\\\ \//\\\ \/\\\ '); |
|
174 |
WriteLn(stdout, ' \/\\\ \/\\\ \///\\\ \/\\\ '); |
|
175 |
WriteLn(stdout, ' \//\\\\\\\\\\\\/ \////\\\\\\\\\ /\\\\\\\\\\\ '); |
|
176 |
WriteLn(stdout, ' \//////////// \///////// \/////////// '); |
|
177 |
WriteLn(stdout, ' '); |
|
178 |
WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student '); |
|
179 |
WriteLn(stdout, ' ASCII Art easter egg idea by @sheepluva '); |
|
180 |
WriteLn(stdout, ' '); |
|
181 |
end; |
|
182 |
{--help} 19 : begin |
|
183 |
DisplayUsage(); |
|
184 |
GameType:= gmtSyntax; |
|
185 |
end; |
|
8150 | 186 |
else |
187 |
begin |
|
188 |
WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument'); |
|
189 |
parseParameter:= true; |
|
190 |
end |
|
191 |
end; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
192 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
193 |
|
8150 | 194 |
procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); |
195 |
var index, tmpInt: LongInt; |
|
196 |
isBool: Boolean; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
197 |
begin |
8150 | 198 |
index:= 0; |
199 |
tmpInt:= 1; |
|
200 |
while (index < size) do |
|
201 |
begin |
|
202 |
paramIndex:= paramIndex+1; |
|
8197 | 203 |
// check if the parameter is a boolean one |
204 |
isBool:= (cmdArray[index] = '--nomusic') |
|
205 |
or (cmdArray[index] = '--nosound') |
|
206 |
or (cmdArray[index] = '--fullscreen') |
|
207 |
or (cmdArray[index] = '--showfps') |
|
208 |
or (cmdArray[index] = '--altdmg') |
|
209 |
or (cmdArray[index] = '--lowquality'); |
|
8150 | 210 |
if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then |
211 |
parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt); |
|
212 |
index:= index+1; |
|
213 |
end; |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
214 |
end; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
215 |
|
8167
96635d815141
Make user folder default to global folder in hwengine
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
8150
diff
changeset
|
216 |
procedure playReplayFileWithParameters(paramIndex: LongInt); |
8207
5f08609613fe
Made user data path default to '.'.
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents:
8204
diff
changeset
|
217 |
var tmpInt: LongInt; |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
218 |
wrongParameter: boolean; |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
219 |
begin |
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
220 |
wrongParameter:= false; |
8150 | 221 |
while (paramIndex <= ParamCount) do |
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
222 |
begin |
8150 | 223 |
if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then |
224 |
wrongParameter:= true; |
|
225 |
paramIndex:= paramIndex+1; |
|
226 |
end; |
|
227 |
if wrongParameter = true then |
|
228 |
begin |
|
229 |
WriteLn(stderr, 'Please use --help to see possible arguments and their usage'); |
|
230 |
GameType:= gmtSyntax; |
|
231 |
end |
|
3678
00428183300f
patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff
changeset
|
232 |
end; |