102 case ARG_GRAPHICS: |
103 case ARG_GRAPHICS: |
103 graphics_enabled = true; |
104 graphics_enabled = true; |
104 break; |
105 break; |
105 |
106 |
106 case ARG_FULLSCREEN: |
107 case ARG_FULLSCREEN: |
107 graphics.fullscreen = true; |
108 display.fullscreen = true; |
108 |
109 |
109 // choose best resolution unless explicitly set |
110 // choose best resolution unless explicitly set |
110 if (resolution_default) { |
111 if (resolution_default) { |
111 const CL_DisplayMode best_mode = Graphics::getBestMode(); |
112 const CL_DisplayMode best_mode = graphics::Display::getBestMode(); |
112 const CL_Size best_resolution = best_mode.get_resolution(); |
113 const CL_Size best_resolution = best_mode.get_resolution(); |
113 |
114 |
114 graphics.resolution = PixelCoordinate(best_resolution.width, best_resolution.height); |
115 display.resolution = PixelDimensions(best_resolution.width, best_resolution.height); |
115 } |
116 } |
116 |
117 |
117 break; |
118 break; |
118 |
119 |
119 case ARG_RESOLUTION: |
120 case ARG_RESOLUTION: |
120 graphics.resolution = parse_arg_dimensions(args.get_argument(), "--resolution"); |
121 display.resolution = parse_arg_dimensions(args.get_argument(), "--resolution"); |
121 resolution_default = false; |
122 resolution_default = false; |
122 break; |
123 break; |
123 |
124 |
124 case ARG_LIST_MODES: |
125 case ARG_LIST_MODES: |
125 dump_display_modes(); |
126 dump_display_modes(); |
168 throw ArgumentError(std::string() + "invalid integer arugment for " + arg_name + ": " + arg_val); |
169 throw ArgumentError(std::string() + "invalid integer arugment for " + arg_name + ": " + arg_val); |
169 |
170 |
170 return int_val; |
171 return int_val; |
171 } |
172 } |
172 |
173 |
173 PixelCoordinate Main::parse_arg_dimensions (const std::string &arg_val, const char *arg_name) { |
174 PixelDimensions Main::parse_arg_dimensions (const std::string &arg_val, const char *arg_name) { |
174 unsigned int w, h; |
175 unsigned int w, h; |
175 |
176 |
176 // sccanf as unsigned |
177 // sccanf as unsigned |
177 if (sscanf(arg_val.c_str(), "%ux%u", &w, &h) != 2) |
178 if (sscanf(arg_val.c_str(), "%ux%u", &w, &h) != 2) |
178 throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val); |
179 throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val); |
179 |
180 |
180 return PixelCoordinate(w, h); |
181 return PixelDimensions(w, h); |
181 } |
182 } |
182 |
183 |
183 void Main::dump_display_modes (void) { |
184 void Main::dump_display_modes (void) { |
184 const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes(); |
185 const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes(); |
185 |
186 |
186 std::cout << "Available display modes:" << std::endl; |
187 std::cout << "Available display modes:" << std::endl; |
187 |
188 |
188 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
189 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
189 std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; |
190 std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; |
215 if (net_connect.empty()) |
216 if (net_connect.empty()) |
216 engine.setupGame(terrain); |
217 engine.setupGame(terrain); |
217 |
218 |
218 // setup graphics |
219 // setup graphics |
219 if (graphics_enabled) |
220 if (graphics_enabled) |
220 engine.setupGraphics(graphics); |
221 engine.setupGraphics(display); |
221 |
222 |
222 // setup either network server, client or singleplayer |
223 // setup either network server, client or singleplayer |
223 if (net_server) { |
224 if (net_server) { |
224 engine.setupNetworkServer(net_port); |
225 engine.setupNetworkServer(net_port); |
225 |
226 |