]>
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
15 #include <unistd.h> // access
17 #include <Moof/Log.hh>
18 #include <Moof/ModalDialog.hh>
19 #include <Moof/OpenGL.hh>
20 #include <Moof/Resource.hh>
21 #include <Moof/Settings.hh>
22 #include <Moof/Transition.hh>
23 #include <Moof/Video.hh>
25 #include "ErrorHandler.hh"
26 #include "GameLayer.hh"
28 #include "TitleLayer.hh"
38 mDispatchHandler
= Mf::core
.addHandler("video.newcontext",
39 boost::bind(&Main::contextCreated
));
43 void Main::addedToCore()
45 //Mf::Scalar coeff[] = {0.0, 1.0};
46 //Mf::Lerp interp(coeff, 0.25);
48 //Mf::LayerP gameLayer = GameLayer::alloc();
49 //Mf::Transition<Mf::Lerp>::Ptr transition =
50 //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
51 //core.push(transition);
52 //core.push(GameLayer::alloc());
53 Mf::core
.push(TitleLayer::alloc());
57 void Main::update(Mf::Scalar t
, Mf::Scalar dt
)
59 if (Mf::core
.getSize() == 1)
61 // this is the only layer left on the stack
62 //Mf::core.push(TitleLayer::alloc());
67 void Main::draw(Mf::Scalar alpha
) const
69 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
71 glMatrixMode(GL_PROJECTION
);
74 glMatrixMode(GL_MODELVIEW
);
78 bool Main::handleEvent(const Mf::Event
& event
)
83 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
)
87 else if (event
.key
.keysym
.sym
== SDLK_f
)
89 Mf::video
->toggleFull();
91 else if (event
.key
.keysym
.sym
== SDLK_l
)
93 Mf::video
->toggleCursorGrab();
94 Mf::video
->toggleCursorVisible();
99 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
111 std::string
Main::getSearchPath()
113 // Add search paths; they should be searched in this order:
114 // 1. YOINK_DATADIR (environment)
115 // 2. YOINK_DATADIR (configure)
119 char* dataDir
= getenv("YOINK_DATADIR");
125 path
+= YOINK_DATADIR
;
130 std::string
Main::getConfigPath()
132 // Build the list of config files to search for, in this order:
133 // 1. YOINK_DATADIR/yoinkrc
134 // 2. /etc/yoinkrc (not for Windows)
136 // 4. YOINKRC (environment)
138 std::string path
= Mf::Resource::getPath("yoinkrc");
140 #if !defined(_WIN32) && !defined(__WIN32__)
141 path
+= ":/etc/yoinkrc";
143 path
+= ":$HOME/.yoinkrc";
145 char* configFile
= getenv("YOINKRC");
158 glEnable(GL_TEXTURE_2D
);
159 glEnable(GL_DEPTH_TEST
);
161 glEnable(GL_LINE_SMOOTH
);
162 glEnable(GL_POLYGON_SMOOTH
);
163 glShadeModel(GL_SMOOTH
);
165 //glEnable(GL_BLEND);
166 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
167 glEnable(GL_ALPHA_TEST
);
168 glAlphaFunc(GL_GREATER
, 0.0);
170 glClearColor(0.0, 0.0, 0.0, 1.0);
172 //glMatrixMode(GL_PROJECTION);
174 //Mf::Scalar ratio = Mf::core.getVideo()->getWidth() /
175 //Mf::core.getVideo()->getHeight();
176 //gluPerspective(60.0, ratio, 1.0, 250.0);
178 //glMatrixMode(GL_MODELVIEW);
181 void Main::contextCreated()
183 // whenever the context is destroyed and a new one created, it probably
184 // won't contain our state so we need to set that up again
190 void Main::printUsage()
192 std::cout
<< "Usage: "
193 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
195 << "The alien-smashing action game." << std::endl
197 << "Options:" << std::endl
198 << " -h, --help" << std::endl
199 << " show this help and exit" << std::endl
200 << " -i, --info" << std::endl
201 << " show version and build information" << std::endl
202 << " detail=1|2|3" << std::endl
203 << " the level of detail of game scenes" << std::endl
204 << " fullscreen=true|false" << std::endl
205 << " if true, uses the entire display" << std::endl
206 << " framerate=num" << std::endl
207 << " number of frames to draw per second" << std::endl
209 << "See documentation for more options." << std::endl
;
212 void Main::printInfo(int argc
, char* argv
[])
218 assets
.assign(YOINK_DATADIR
);
219 int accessible
= access(assets
.c_str(), R_OK
);
220 if (accessible
!= 0) assets
+= " (no access)";
222 char* temp
= getenv("YOINK_DATADIR");
226 accessible
= access(temp
, R_OK
);
227 if (accessible
!= 0) datadir
+= " (no access)";
230 temp
= getenv("YOINKRC");
234 accessible
= access(temp
, R_OK
);
235 if (accessible
!= 0) config
+= " (no access)";
238 std::cout
<< " Executable: " << argv
[0] << std::endl
239 << " Version: "VERSION
<< std::endl
240 << " Built: " << COMPILE_TIME
<< std::endl
241 << " Compiler: "COMPILER_STRING
<< std::endl
242 << " Assets: " << assets
<< std::endl
248 #ifndef USE_DOUBLE_PRECISION
251 << "double-precision "
256 #ifndef PROFILING_ENABLED
267 << "threads" << std::endl
268 << " YOINKRC: " << config
<< std::endl
269 << "YOINK_DATADIR: " << datadir
<< std::endl
;
275 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
276 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
277 << "Send patches and bug reports to <"
278 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
283 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
286 int main(int argc
, char* argv
[])
290 std::string
arg(argv
[1]);
291 if (arg
== "-h" || arg
== "--help")
296 else if (arg
== "-i" || arg
== "--info")
298 Main::printInfo(argc
, argv
);
306 Mf::Resource::addSearchPaths(Main::getSearchPath());
308 Mf::settings
.loadFromFiles(Main::getConfigPath());
309 Mf::settings
.parseArgs(argc
, argv
);
311 Mf::Log::Level logLevel
= Mf::Log::INFO
;
312 Mf::settings
.get("loglevel", logLevel
);
313 Mf::Log::setLevel(logLevel
);
317 Mf::Video
video(PACKAGE_STRING
,
318 Mf::Resource::getPath(PACKAGE
".png"));
319 MainP app
= Main::alloc();
323 catch (const Mf::Error
& error
)
325 Mf::ModalDialog dialog
;
326 dialog
.title
= PACKAGE_STRING
;
327 dialog
.text1
= "Unhandled Exception";
328 dialog
.text2
= getErrorString(error
);
329 dialog
.type
= Mf::ModalDialog::CRITICAL
;
This page took 0.05012 seconds and 4 git commands to generate.