]>
Dogcows Code - chaz/yoink/blob - src/Main.cc
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
);
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 //glEnable(GL_LIGHTING);
166 float light
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
167 glLightfv(GL_LIGHT0
, GL_AMBIENT_AND_DIFFUSE
, light
);
170 //glMatrixMode(GL_PROJECTION);
172 //moof::scalar ratio = moof::core.getVideo()->width() /
173 //moof::core.getVideo()->height();
174 //gluPerspective(60.0, ratio, 1.0, 250.0);
176 //glMatrixMode(GL_MODELVIEW);
180 void Main::printUsage()
182 std::cout
<< "Usage: "
183 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
185 << "The alien-smashing action game." << std::endl
187 << "Options:" << std::endl
188 << " -h, --help" << std::endl
189 << " show this help and exit" << std::endl
190 << " -i, --info" << std::endl
191 << " show version and build information" << std::endl
192 << " detail=1|2|3" << std::endl
193 << " the level of detail of game scenes" << std::endl
194 << " fullscreen=true|false" << std::endl
195 << " if true, uses the entire display" << std::endl
196 << " framerate=num" << std::endl
197 << " number of frames to draw per second" << std::endl
199 << "See documentation for more options." << std::endl
;
202 void Main::printInfo(int argc
, char* argv
[])
204 stlplus::env_vector environment
;
207 assets
.assign(YOINK_DATADIR
);
208 if (!stlplus::file_readable(assets
)) assets
+= " (no access)";
210 std::string datadir
= environment
["YOINK_DATADIR"];
211 if (!datadir
.empty())
213 if (!stlplus::folder_readable(datadir
)) datadir
+= " (no access)";
216 std::string rc_file
= environment
["YOINKRC"];
217 if (!rc_file
.empty())
219 if (!stlplus::file_readable(rc_file
)) rc_file
+= " (no access)";
222 std::cout
<< " Executable: " << argv
[0] << std::endl
224 << " Commit: "YOINK_GITHEAD
<< std::endl
226 << " Version: " << PACKAGE_VERSION
<< std::endl
227 << " Built: " << COMPILE_TIME
<< std::endl
228 << " Compiler: " << COMPILER_STRING
<< std::endl
229 << " Assets: " << assets
<< std::endl
231 #if !USE_CLOCK_GETTIME
239 #if !USE_DOUBLE_PRECISION
242 << "double-precision "
251 #if !PROFILING_ENABLED
262 << "threads" << std::endl
263 << " YOINKRC: " << rc_file
<< std::endl
264 << "YOINK_DATADIR: " << datadir
<< std::endl
;
270 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
271 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
272 << "Send patches and bug reports to <"
273 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
278 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
282 int main(int argc
, char* argv
[])
284 moof::backend backend
;
286 // FIXME: This is temporary.
287 moof::timer
reloadTimer(boost::bind(&moof::resource::reload_as_needed
),
289 moof::timer::repeat
);
293 std::string
arg(argv
[1]);
294 if (arg
== "-h" || arg
== "--help")
299 else if (arg
== "-i" || arg
== "--info")
301 Main::printInfo(argc
, argv
);
309 moof::resource::add_search_paths(Main::getSearchPath());
311 moof::settings
settings(argc
, argv
, Main::getConfigPath());
313 enum moof::log::level logLevel
= moof::log::info
;
314 settings
.get("loglevel", logLevel
);
315 moof::log::level(logLevel
);
319 //std::string iconPath(PACKAGE".png");
320 //iconPath = moof::resource::find_file(iconPath);
321 //moof::image icon(iconPath);
322 //icon.set_as_icon();
323 moof::image_handle
icon(PACKAGE
, "png");
324 if (icon
) icon
->set_as_icon();
325 else moof::log_error("no icon loaded");
328 class moof::video::attributes
attributes(settings
);
329 moof::video
video(PACKAGE_STRING
, attributes
);
330 Main
mainView(settings
, video
);
335 catch (const std::exception
& e
)
337 moof::modal_dialog
dialog(moof::modal_dialog::error
,
338 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.057042 seconds and 4 git commands to generate.