[go: up one dir, main page]

Menu

[f338fb]: / vamos / Options.cc  Maximize  Restore  History

Download this file

221 lines (202 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Options.h - runtime option handling.
//
// Copyright (C) 2014 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib>
#include <getopt.h>
#include <iostream>
#include <boost/filesystem.hpp>
#include "Options.h"
#include "../geometry/Parameter.h"
Options::Options (int argc, char* argv [])
: data_dir ("../data/"),
car_file ("GT"),
track_file ("Peanut"),
world_file ("earth"),
controls_file ("stick"),
number_of_cars (1),
laps (5),
performance (0.0),
volume (1.0),
map_mode (false),
full_screen (false),
interact (true),
demo (false),
qualifying (false),
show_line (false),
m_exit_status (EXIT_SUCCESS),
m_exit (false)
{
int option_index = 0;
while (true)
{
static struct option long_options [] =
{
{ "car", required_argument, 0, 'c' },
{ "track", required_argument, 0, 't' },
{ "world", required_argument, 0, 'w' },
{ "controls", required_argument, 0, 'a' },
{ "opponents", required_argument, 0, 'o' },
{ "laps", required_argument, 0, 'p' },
{ "performance", required_argument, 0, 'z' },
{ "volume", required_argument, 0, 's' },
{ "show-line", optional_argument, 0, 'l' },
{ "map", no_argument, 0, 'm' },
{ "demo", no_argument, 0, 'd' },
{ "qualifying", no_argument, 0, 'q' },
{ "full-screen", no_argument, 0, 'f' },
{ "no-interaction", no_argument, 0, 'n' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
int c = getopt_long (argc, argv, "c:t:w:a:o:p:z:s:l::mdqfnv",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
break;
case 'c':
car_file = optarg;
break;
case 't':
track_file = optarg;
break;
case 'w':
world_file = optarg;
break;
case 'a':
controls_file = optarg;
break;
case 'o':
number_of_cars = atoi (optarg) + 1;
break;
case 'p':
laps = atoi (optarg);
break;
case 'z':
performance = atoi (optarg) / 100.0 - 1.0;
break;
case 's':
volume = atoi (optarg) / 100.0;
break;
case 'l':
show_line = (optarg == NULL) ? true : (strcmp (optarg, "yes") == 0);
break;
case 'm':
map_mode = true;
break;
case 'd':
demo = true;
break;
case 'q':
qualifying = true;
break;
case 'f':
full_screen = true;
break;
case 'n':
interact = false;
break;
case 'v':
std::cout << PACKAGE_STRING << std::endl;
m_exit = true;
break;
default:
show_usage ();
m_exit_status = EXIT_FAILURE;
m_exit = true;
break;
}
}
// Assume the rest of the arguments are values of adjustable
// parameters.
if (optind < argc)
input_file = argv [optind++];
while (optind < argc)
parameter.push_back (atof (argv [optind++]));
// Subtract a car for demo mode.
if (demo && (number_of_cars > 1))
--number_of_cars;
find_data_directory ();
Vamos_Geometry::Parameter::set (parameter);
}
void Options::find_data_directory ()
{
namespace fs = boost::filesystem;
if (!fs::exists (data_dir))
{
data_dir = DATADIR "/";
if (!fs::exists (data_dir))
{
std::cerr << "Couldn't find the data direcory, ../data or "
<< data_dir
<< std::endl;
data_dir.clear ();
m_exit_status = EXIT_FAILURE;
m_exit = true;
}
}
}
void Options::show_usage () const
{
std::cerr << "Usage: vamos "
<< "[-m|--map] "
<< "[[-t|--track=] TRACK_FILE] "
<< "[[-c|--car=] CAR_FILE] "
<< "[[-w|--world=] WORLD_FILE] "
<< "[[-a|--controls=] CONTROLS_FILE] "
<< "[[-o|--opponents=] NUMBER_OF_OPPONENTS] "
<< "[[-p|--laps=] NUMBER_OF_LAPS] "
<< "[[-z|--performance=] FACTOR] "
<< "[[-s|--volume=] VOLUME_PERCENT] "
<< "[-f|--full-screen] "
<< "[-n|--no-interaction] "
<< "[-d|--demo] "
<< "[-q|--qualifying] "
<< "[-l|--show-line[=ARG] draw the racing line on the track [ARG=yes]]"
<< std::endl;
}
std::ostream& operator << (std::ostream& os, const Options& opt)
{
os << "data_dir\t" << opt.data_dir << '\n'
<< "car_file\t" << opt.car_file << '\n'
<< "track_file\t" << opt.track_file << '\n'
<< "world_file\t" << opt.world_file << '\n'
<< "controls_file\t" << opt.controls_file << '\n'
<< "number_of_cars\t" << opt.number_of_cars << '\n'
<< "laps\t" << opt.laps << '\n'
<< "performance\t" << opt.performance << '\n'
<< "volume\t" << opt.volume << '\n'
<< "map_mode\t" << opt.map_mode << '\n'
<< "full_screen\t" << opt.full_screen << '\n'
<< "interact\t" << opt.interact << '\n'
<< "demo\t" << opt.demo << '\n'
<< "qualifying\t" << opt.qualifying << '\n'
<< "show_line\t" << opt.show_line << '\n'
<< "input_file\t" << opt.input_file << '\n'
<< "parameters\t[ ";
for (std::vector <double>::const_iterator it = opt.parameter.begin ();
it != opt.parameter.end ();
++it)
{
os << *it << ' ';
}
os << "]\n";
return os;
}