]>
Dogcows Code - chaz/yoink/blob - src/Main.cc
8361b39d3dffe7a5e24eda753650e2722aad6092
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 **************************************************************************/
12 #include "../config.h"
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 stlplus::env_vector environment
;
112 std::string datadir
= environment
["YOINK_DATADIR"];
113 if (!datadir
.empty())
118 path
+= YOINK_DATADIR
;
123 std::string
Main::getConfigPath()
125 // Build the list of config files to search for, in this order:
126 // 1. YOINK_DATADIR/yoinkrc
127 // 2. /etc/yoinkrc (not for Windows)
129 // 4. YOINKRC (environment)
131 std::string
path("yoinkrc");
132 moof::resource::find(path
);
134 stlplus::env_vector environment
;
137 path
+= ":/etc/yoinkrc";
139 path
+= ":$HOME/.yoinkrc";
141 std::string rc_file
= environment
["YOINKRC"];
142 if (!rc_file
.empty())
154 glEnable(GL_TEXTURE_2D
);
155 glEnable(GL_DEPTH_TEST
);
157 glEnable(GL_LINE_SMOOTH
);
158 glEnable(GL_POLYGON_SMOOTH
);
159 glShadeModel(GL_SMOOTH
);
161 //glEnable(GL_BLEND);
162 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
163 glEnable(GL_ALPHA_TEST
);
164 glAlphaFunc(GL_GREATER
, 0.0);
166 glClearColor(0.0, 0.0, 0.0, 1.0);
168 //glMatrixMode(GL_PROJECTION);
170 //moof::scalar ratio = moof::core.getVideo()->width() /
171 //moof::core.getVideo()->height();
172 //gluPerspective(60.0, ratio, 1.0, 250.0);
174 //glMatrixMode(GL_MODELVIEW);
178 void Main::printUsage()
180 std::cout
<< "Usage: "
181 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
183 << "The alien-smashing action game." << std::endl
185 << "Options:" << std::endl
186 << " -h, --help" << std::endl
187 << " show this help and exit" << std::endl
188 << " -i, --info" << std::endl
189 << " show version and build information" << std::endl
190 << " detail=1|2|3" << std::endl
191 << " the level of detail of game scenes" << std::endl
192 << " fullscreen=true|false" << std::endl
193 << " if true, uses the entire display" << std::endl
194 << " framerate=num" << std::endl
195 << " number of frames to draw per second" << std::endl
197 << "See documentation for more options." << std::endl
;
200 void Main::printInfo(int argc
, char* argv
[])
202 stlplus::env_vector environment
;
205 assets
.assign(YOINK_DATADIR
);
206 if (!stlplus::file_readable(assets
)) assets
+= " (no access)";
208 std::string datadir
= environment
["YOINK_DATADIR"];
209 if (!datadir
.empty())
211 if (!stlplus::folder_readable(datadir
)) datadir
+= " (no access)";
214 std::string rc_file
= environment
["YOINKRC"];
215 if (!rc_file
.empty())
217 if (!stlplus::file_readable(rc_file
)) rc_file
+= " (no access)";
220 std::cout
<< " Executable: " << argv
[0] << std::endl
222 << " Commit: "YOINK_GITHEAD
<< std::endl
224 << " Version: "VERSION
<< std::endl
225 << " Built: " << COMPILE_TIME
<< std::endl
226 << " Compiler: "COMPILER_STRING
<< std::endl
227 << " Assets: " << assets
<< std::endl
229 #ifndef HAVE_CLOCK_GETTIME
237 #ifndef USE_DOUBLE_PRECISION
240 << "double-precision "
245 #ifndef USE_HOTLOADING
249 #ifndef PROFILING_ENABLED
260 << "threads" << std::endl
261 << " YOINKRC: " << rc_file
<< std::endl
262 << "YOINK_DATADIR: " << datadir
<< std::endl
;
268 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
269 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
270 << "Send patches and bug reports to <"
271 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
276 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
280 #include <moof/socket.hh>
287 MyAsset(const std::string
& path
)
289 moof::log_info("MyAsset loading:", path
);
293 std::ifstream
stream(path
.c_str());
294 stream
.getline(buffer
, sizeof(buffer
));
303 moof::log_info("MyAsset COOL:", str
);
308 moof::log_info("MyAsset GROOVY!!!!", str
);
314 typedef moof::resource_handle
<MyAsset
> MyAsset_handle
;
319 AnotherAsset(const std::string
& path
, double d
= 5.0)
321 moof::log_info("AnotherAsset loading:", path
);
328 moof::log_info("AnotherAsset cool", dude
);
333 moof::log_info("AnotherAsset GROOVY!!!!", dude
);
340 int main(int argc
, char* argv
[])
342 moof::resource::register_type
<MyAsset
>("mine");
344 //moof::resource::add_type<AnotherAsset>("k");
347 //moof::resource_ptr myAsset = moof::resource::load(assetName,
350 //MyAsset_handle aCopy = myAsset;
352 //MyAsset_handle copy2 = moof::resource::load(assetName, "asdfas", "mine");
354 ////if (myAsset->check<MyAsset>()) myAsset->get<AnotherAsset>()->cool();
355 //myAsset->get<MyAsset>()->cool();
356 ////myAsset->get<AnotherAsset>()->groovy();
358 //aCopy.get()->cool();
359 //copy2.get()->cool();
361 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "mine"));
363 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "k"));
364 //moof::resource::load(assetName, "", "mine")->get<MyAsset>()->cool();
366 ////if (myAsset) myAsset.get()->cool();
367 ////else moof::log_error("asset not obtained...");
369 MyAsset_handle myAsset
= moof::resource::load("/home/chaz/meh.mine");
370 MyAsset
* asset
= myAsset
.get();
371 if (asset
) asset
->cool();
372 else moof::log_warning("no asset obtained!!");
374 //moof::timer reloadTimer(
375 //boost::bind(&moof::resource::reload_as_needed),
377 //moof::timer::repeat);
381 if (myAsset
) myAsset
.get()->cool();
382 moof::resource::reload_as_needed();
389 std::string
arg(argv
[1]);
390 if (arg
== "-h" || arg
== "--help")
395 else if (arg
== "-i" || arg
== "--info")
397 Main::printInfo(argc
, argv
);
405 moof::resource::add_search_paths(Main::getSearchPath());
407 moof::settings
settings(argc
, argv
, Main::getConfigPath());
409 enum moof::log::level logLevel
= moof::log::info
;
410 settings
.get("loglevel", logLevel
);
411 moof::log::level(logLevel
);
415 std::string
iconPath(PACKAGE
".png");
416 moof::resource::find(iconPath
);
417 moof::image
icon(iconPath
);
420 class moof::video::attributes
attributes(settings
);
421 moof::video
video(PACKAGE_STRING
, attributes
);
422 Main
mainView(settings
, video
);
427 catch (const std::exception
& e
)
429 moof::modal_dialog
dialog(moof::modal_dialog::error
,
430 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.050821 seconds and 3 git commands to generate.