]>
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 **************************************************************************/
12 #include <cstdlib> // atexit, getenv
16 #include <unistd.h> // access
18 #include <Moof/Log.hh>
19 #include <Moof/ModalDialog.hh>
20 #include <Moof/OpenGL.hh>
21 #include <Moof/Resource.hh>
22 #include <Moof/Settings.hh>
23 #include <Moof/Video.hh>
25 #include "ErrorHandler.hh"
26 #include "GameLayer.hh"
28 #include "TitleLayer.hh"
36 Main::Main(Mf::Settings
& settings
, Mf::Video
& video
) :
37 Mf::View(settings
, video
)
39 Mf::Dispatch
& dispatch
= Mf::Dispatch::global();
40 mNewContextDispatch
= dispatch
.addTarget("video.newcontext",
41 boost::bind(&Main::setupGL
));
46 void Main::update(Mf::Scalar t
, Mf::Scalar dt
)
48 if (children().size() == 0)
50 //Mf::logWarning("main view has no children");
53 addChild(TitleLayer::alloc());
56 Mf::View::update(t
, dt
);
59 void Main::draw(Mf::Scalar alpha
) const
61 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
63 glMatrixMode(GL_PROJECTION
);
66 glMatrixMode(GL_MODELVIEW
);
69 Mf::View::draw(alpha
);
72 bool Main::handleEvent(const Mf::Event
& event
)
74 if (Mf::View::handleEvent(event
)) return true;
79 if (event
.key
.keysym
.sym
== SDLK_f
)
83 else if (event
.key
.keysym
.sym
== SDLK_l
)
85 video().toggleCursorGrab();
86 video().toggleCursorVisible();
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)
111 char* dataDir
= getenv("YOINK_DATADIR");
117 path
+= YOINK_DATADIR
;
122 std::string
Main::getConfigPath()
124 // Build the list of config files to search for, in this order:
125 // 1. YOINK_DATADIR/yoinkrc
126 // 2. /etc/yoinkrc (not for Windows)
128 // 4. YOINKRC (environment)
130 std::string
path("yoinkrc");
131 Mf::Resource::getPath(path
);
134 path
+= ":/etc/yoinkrc";
136 path
+= ":$HOME/.yoinkrc";
138 char* configFile
= getenv("YOINKRC");
151 glEnable(GL_TEXTURE_2D
);
152 glEnable(GL_DEPTH_TEST
);
154 glEnable(GL_LINE_SMOOTH
);
155 glEnable(GL_POLYGON_SMOOTH
);
156 glShadeModel(GL_SMOOTH
);
158 //glEnable(GL_BLEND);
159 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
160 glEnable(GL_ALPHA_TEST
);
161 glAlphaFunc(GL_GREATER
, 0.0);
163 glClearColor(0.0, 0.0, 0.0, 1.0);
165 //glMatrixMode(GL_PROJECTION);
167 //Mf::Scalar ratio = Mf::core.getVideo()->getWidth() /
168 //Mf::core.getVideo()->getHeight();
169 //gluPerspective(60.0, ratio, 1.0, 250.0);
171 //glMatrixMode(GL_MODELVIEW);
175 void Main::printUsage()
177 std::cout
<< "Usage: "
178 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
180 << "The alien-smashing action game." << std::endl
182 << "Options:" << std::endl
183 << " -h, --help" << std::endl
184 << " show this help and exit" << std::endl
185 << " -i, --info" << std::endl
186 << " show version and build information" << std::endl
187 << " detail=1|2|3" << std::endl
188 << " the level of detail of game scenes" << std::endl
189 << " fullscreen=true|false" << std::endl
190 << " if true, uses the entire display" << std::endl
191 << " framerate=num" << std::endl
192 << " number of frames to draw per second" << std::endl
194 << "See documentation for more options." << std::endl
;
197 void Main::printInfo(int argc
, char* argv
[])
203 assets
.assign(YOINK_DATADIR
);
204 int accessible
= access(assets
.c_str(), R_OK
);
205 if (accessible
!= 0) assets
+= " (no access)";
207 char* temp
= getenv("YOINK_DATADIR");
211 accessible
= access(temp
, R_OK
);
212 if (accessible
!= 0) datadir
+= " (no access)";
215 temp
= getenv("YOINKRC");
219 accessible
= access(temp
, R_OK
);
220 if (accessible
!= 0) config
+= " (no access)";
223 std::cout
<< " Executable: " << argv
[0] << 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 PROFILING_ENABLED
256 << "threads" << std::endl
257 << " YOINKRC: " << config
<< std::endl
258 << "YOINK_DATADIR: " << datadir
<< std::endl
;
264 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
265 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
266 << "Send patches and bug reports to <"
267 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
272 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
276 int main(int argc
, char* argv
[])
280 std::string
arg(argv
[1]);
281 if (arg
== "-h" || arg
== "--help")
286 else if (arg
== "-i" || arg
== "--info")
288 Main::printInfo(argc
, argv
);
296 Mf::Resource::addSearchPaths(Main::getSearchPath());
298 Mf::Settings
settings(argc
, argv
, Main::getConfigPath());
300 Mf::Log::Level logLevel
= Mf::Log::INFO
;
301 settings
.get("loglevel", logLevel
);
302 Mf::Log::setLevel(logLevel
);
306 Mf::Video::Attributes
attributes(settings
);
307 attributes
.caption
= PACKAGE_STRING
;
308 attributes
.icon
= Mf::Resource::getPath(PACKAGE
".png");
310 Mf::Video
video(attributes
);
311 Main
mainView(settings
, video
);
316 catch (const Mf::Error
& error
)
318 Mf::ModalDialog
dialog(Mf::ModalDialog::CRITICAL
,
319 PACKAGE_STRING
, "Unhandled Exception",
320 getErrorString(error
));
This page took 0.045499 seconds and 4 git commands to generate.