]>
Dogcows Code - chaz/yoink/blob - Main.cc
adda533e40fcc595e8cf5784d3be4de6361a9bad
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
14 #include <cstdlib> // atexit
20 #include <stlplus/portability/file_system.hpp>
21 #include <stlplus/portability/subprocesses.hpp>
23 #include <moof/log.hh>
24 #include <moof/modal_dialog.hh>
25 #include <moof/opengl.hh>
26 #include <moof/resource.hh>
27 #include <moof/settings.hh>
28 #include <moof/video.hh>
30 #include "GameLayer.hh"
32 #include "TitleLayer.hh"
36 Main::Main(moof::settings
& settings
, moof::video
& video
) :
37 moof::view(settings
, video
)
39 moof::dispatcher
& dispatcher
= moof::dispatcher::global();
40 mNewContextDispatch
= dispatcher
.add_target("video.newcontext",
41 boost::bind(&Main::setupGL
));
46 void Main::update(moof::scalar t
, moof::scalar dt
)
48 if (children().size() == 0)
50 //moof::log_warning("main view has no children");
53 add_child(TitleLayer::alloc());
56 moof::view::update(t
, dt
);
59 void Main::draw(moof::scalar alpha
) const
61 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
63 glMatrixMode(GL_PROJECTION
);
66 glMatrixMode(GL_MODELVIEW
);
69 moof::view::draw(alpha
);
72 bool Main::handle_event(const moof::event
& event
)
74 if (moof::view::handle_event(event
)) return true;
79 if (event
.key
.keysym
.sym
== SDLK_f
)
81 video().toggle_fullscreen();
83 else if (event
.key
.keysym
.sym
== SDLK_l
)
85 video().toggle_cursor_captured();
86 video().toggle_cursor_visible();
91 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
103 std::string
Main::getSearchPath()
105 // Add search paths; they should be searched in this order:
106 // 1. YOINK_DATADIR (environment)
107 // 2. YOINK_DATADIR (configure)
110 std::string datadir
= stlplus::env_vector()["YOINK_DATADIR"];
111 if (!datadir
.empty())
116 path
+= YOINK_DATADIR
;
121 std::string
Main::getConfigPath()
123 // Build the list of config files to search for, in this order:
124 // 1. YOINK_DATADIR/yoinkrc
125 // 2. /etc/yoinkrc (not for Windows)
127 // 4. YOINKRC (environment)
129 std::string path
= moof::resource::find_file("yoinkrc");
132 path
+= ":/etc/yoinkrc";
134 path
+= ":$HOME/.yoinkrc";
136 std::string rc_file
= stlplus::env_vector()["YOINKRC"];
137 if (!rc_file
.empty())
149 glEnable(GL_TEXTURE_2D
);
150 glEnable(GL_DEPTH_TEST
);
152 glEnable(GL_LINE_SMOOTH
);
153 glEnable(GL_POLYGON_SMOOTH
);
154 glShadeModel(GL_SMOOTH
);
156 //glEnable(GL_BLEND);
157 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
158 glEnable(GL_ALPHA_TEST
);
159 glAlphaFunc(GL_GREATER
, 0.0);
161 glClearColor(0.0, 0.0, 0.0, 1.0);
163 //glMatrixMode(GL_PROJECTION);
165 //moof::scalar ratio = moof::core.getVideo()->width() /
166 //moof::core.getVideo()->height();
167 //gluPerspective(60.0, ratio, 1.0, 250.0);
169 //glMatrixMode(GL_MODELVIEW);
173 void Main::printUsage()
175 std::cout
<< "Usage: "
176 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
178 << "The alien-smashing action game." << std::endl
180 << "Options:" << std::endl
181 << " -h, --help" << std::endl
182 << " show this help and exit" << std::endl
183 << " -i, --info" << std::endl
184 << " show version and build information" << std::endl
185 << " detail=1|2|3" << std::endl
186 << " the level of detail of game scenes" << std::endl
187 << " fullscreen=true|false" << std::endl
188 << " if true, uses the entire display" << std::endl
189 << " framerate=num" << std::endl
190 << " number of frames to draw per second" << std::endl
192 << "See documentation for more options." << std::endl
;
195 void Main::printInfo(int argc
, char* argv
[])
197 stlplus::env_vector environment
;
200 assets
.assign(YOINK_DATADIR
);
201 if (!stlplus::file_readable(assets
)) assets
+= " (no access)";
203 std::string datadir
= environment
["YOINK_DATADIR"];
204 if (!datadir
.empty())
206 if (!stlplus::folder_readable(datadir
)) datadir
+= " (no access)";
209 std::string rc_file
= environment
["YOINKRC"];
210 if (!rc_file
.empty())
212 if (!stlplus::file_readable(rc_file
)) rc_file
+= " (no access)";
215 std::cout
<< " Executable: " << argv
[0] << std::endl
217 << " Commit: "YOINK_GITHEAD
<< std::endl
219 << " Version: "PACKAGE_VERSION
<< std::endl
220 << " Built: " << COMPILE_TIME
<< std::endl
221 << " Compiler: "COMPILER_STRING
<< std::endl
222 << " Assets: " << assets
<< std::endl
224 #ifndef HAVE_CLOCK_GETTIME
232 #ifndef USE_DOUBLE_PRECISION
235 << "double-precision "
240 #ifndef USE_HOTLOADING
244 #ifndef PROFILING_ENABLED
255 << "threads" << std::endl
256 << " YOINKRC: " << rc_file
<< std::endl
257 << "YOINK_DATADIR: " << datadir
<< std::endl
;
263 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
264 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
265 << "Send patches and bug reports to <"
266 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
271 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
275 int main(int argc
, char* argv
[])
277 // FIXME: This is temporary.
278 moof::timer
reloadTimer(boost::bind(&moof::resource::reload_as_needed
),
280 moof::timer::repeat
);
284 std::string
arg(argv
[1]);
285 if (arg
== "-h" || arg
== "--help")
290 else if (arg
== "-i" || arg
== "--info")
292 Main::printInfo(argc
, argv
);
300 moof::resource::add_search_paths(Main::getSearchPath());
302 moof::settings
settings(argc
, argv
, Main::getConfigPath());
304 enum moof::log::level logLevel
= moof::log::info
;
305 settings
.get("loglevel", logLevel
);
306 moof::log::level(logLevel
);
310 std::string
iconPath(PACKAGE
".png");
311 iconPath
= moof::resource::find_file(iconPath
);
312 moof::image
icon(iconPath
);
315 class moof::video::attributes
attributes(settings
);
316 moof::video
video(PACKAGE_STRING
, attributes
);
317 Main
mainView(settings
, video
);
322 catch (const std::exception
& e
)
324 moof::modal_dialog
dialog(moof::modal_dialog::error
,
325 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.048174 seconds and 3 git commands to generate.