]>
Dogcows Code - chaz/yoink/blob - src/client.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #include <cstdlib> // atexit
17 #include <stlplus/portability/file_system.hpp>
18 #include <stlplus/portability/subprocesses.hpp>
20 #include <moof/compression.hh>
21 #include <moof/image.hh>
22 #include <moof/log.hh>
23 #include <moof/modal_dialog.hh>
24 #include <moof/opengl.hh>
25 #include <moof/resource.hh>
26 #include <moof/settings.hh>
27 #include <moof/string.hh>
28 #include <moof/video.hh>
40 inline int isatty(int dummy
) { return 0; }
44 Main::Main(moof::settings
& settings
) :
45 moof::application(settings
)
47 moof::dispatcher
& dispatcher
= moof::dispatcher::global();
48 video_reloaded_
= dispatcher
.add_target("video.newcontext",
49 boost::bind(&Main::setup_opengl
));
53 hotload_timer_
.init(boost::bind(&moof::resource::reload_as_needed
),
54 SCALAR(0.25), moof::timer::repeat
);
58 void Main::setup_opengl()
60 glEnable(GL_TEXTURE_2D
);
61 glEnable(GL_DEPTH_TEST
);
62 //glEnable(GL_CULL_FACE);
64 //glEnable(GL_POINT_SMOOTH);
65 //glEnable(GL_LINE_SMOOTH);
66 //glEnable(GL_POLYGON_SMOOTH);
67 //glShadeModel(GL_SMOOTH);
70 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
71 glEnable(GL_ALPHA_TEST
);
72 glAlphaFunc(GL_GREATER
, 0.0);
74 glEnable(GL_MULTISAMPLE
);
76 glClearColor(1.0, 0.0, 0.0, 1.0);
78 //glEnable(GL_LIGHTING);
79 //glEnable(GL_LIGHT0);
81 //glEnable(GL_COLOR_MATERIAL);
82 //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
84 float amb
[] = {0.1f
, 0.1f
, 0.1f
, 1.0f
};
85 float dif
[] = {0.6f
, 0.6f
, 0.6f
, 1.0f
};
86 //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light);
87 glLightfv(GL_LIGHT0
, GL_AMBIENT
, amb
);
88 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, dif
);
90 float spec
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
91 glLightfv(GL_LIGHT0
, GL_SPECULAR
, spec
);
94 void Main::update(moof::scalar t
, moof::scalar dt
)
99 void Main::draw(moof::scalar alpha
) const
101 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
103 glMatrixMode(GL_PROJECTION
);
106 glMatrixMode(GL_MODELVIEW
);
112 void Main::handle_event(const moof::event
& event
)
114 if (yoink
.handle_event(event
)) return;
119 if (event
.key
.keysym
.sym
== SDLK_f
)
121 moof::video::current().toggle_fullscreen();
123 else if (event
.key
.keysym
.sym
== SDLK_l
)
125 moof::video::current().toggle_cursor_captured();
126 moof::video::current().toggle_cursor_visible();
128 else if (event
.key
.keysym
.sym
== SDLK_ESCAPE
)
134 case SDL_VIDEORESIZE
:
135 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
144 static std::string
search_paths()
146 // Add search paths; they should be searched in this order:
147 // 1. YOINK_DATADIR (environment)
148 // 2. YOINK_DATADIR (configure)
151 std::string datadir
= stlplus::env_vector()["YOINK_DATADIR"];
152 if (!datadir
.empty())
157 path
+= YOINK_DATADIR
;
164 static std::string
config_paths()
166 // Build the list of config files to search for, in this order:
167 // 1. YOINK_DATADIR/yoinkrc
168 // 2. /etc/yoinkrc (not for Windows)
170 // 4. YOINKRC (environment)
172 std::string path
= moof::resource::find_file("yoinkrc");
175 path
+= ":/etc/yoinkrc";
177 path
+= ":$HOME/.yoinkrc";
179 std::string rc_file
= stlplus::env_vector()["YOINKRC"];
180 if (!rc_file
.empty())
189 static void print_usage()
191 std::cout
<< "Usage: "
192 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
194 << "The alien-smashing action game." << std::endl
196 << "Options:" << std::endl
197 << " -h, --help" << std::endl
198 << " show this help and exit" << std::endl
199 << " -i, --info" << std::endl
200 << " show version and build information" << std::endl
201 << " detail=1|2|3" << std::endl
202 << " the level of detail of game scenes" << std::endl
203 << " fullscreen=true|false" << std::endl
204 << " if true, uses the entire display" << std::endl
205 << " framerate=num" << std::endl
206 << " number of frames to draw per second" << std::endl
208 << "See documentation for more options." << std::endl
;
211 static void print_info(int argc
, char* argv
[])
213 #if INCLUDE_CONFIG_FILE
214 extern size_t data_config_gz_size
;
215 extern char data_config_gz
[];
216 moof::inflate(data_config_gz
, data_config_gz_size
, std::cout
);
218 std::cout
<< std::endl
<< "No configuration available. :-("
226 if (isatty(1) == 1) std::cout
<< "\033[94m";
227 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
228 << "Compiled " << __TIME__
" "__DATE__
<< std::endl
229 << "Send patches and bug reports to <"PACKAGE_BUGREPORT
">."
230 << std::endl
<< moof::log::endl
;
233 static void goodbye()
235 if (isatty(1) == 1) std::cout
<< "\033[94m";
236 std::cout
<< std::endl
<< "Goodbye." << std::endl
<< moof::log::endl
;
240 int main(int argc
, char* argv
[])
244 std::string
arg(argv
[1]);
245 if (arg
== "-h" || arg
== "--help")
250 else if (arg
== "-i" || arg
== "--info")
252 print_info(argc
, argv
);
260 moof::backend backend
;
262 moof::resource::set_search_paths(search_paths());
264 moof::settings
settings(argc
, argv
, config_paths());
266 enum moof::log::level logLevel
= moof::log::info
;
267 settings
.get("loglevel", logLevel
);
268 moof::log::level(logLevel
);
270 std::cout
.precision(10);
274 moof::image_handle
icon("yoink", "png");
275 if (icon
) icon
->set_as_icon();
276 else moof::log_error("no icon loaded");
279 class moof::video::attributes
attributes(settings
);
280 moof::video
video(PACKAGE_STRING
, attributes
);
282 bool showfps
= false;
283 settings
.get("showfps", showfps
);
284 video
.show_fps(showfps
);
289 catch (const std::exception
& e
)
291 moof::modal_dialog
dialog(moof::modal_dialog::error
,
292 PACKAGE_STRING
, "unhandled exception",
296 catch (const char* e
)
298 moof::modal_dialog
dialog(moof::modal_dialog::error
,
299 PACKAGE_STRING
, "unhandled exception", e
);
This page took 0.045194 seconds and 4 git commands to generate.