]>
Dogcows Code - chaz/yoink/blob - src/MainLayer.cc
4975e17f1b28db30e9df1d95a73469a9f6a85456
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
29 #include <cstdlib> // atexit, getenv
33 #include <Moof/Dispatcher.hh>
34 #include <Moof/Exception.hh>
35 #include <Moof/Log.hh>
36 #include <Moof/OpenGL.hh>
37 #include <Moof/Resource.hh>
38 #include <Moof/Transition.hh>
39 #include <Moof/Video.hh>
41 #include "GameLayer.hh"
42 #include "MainLayer.hh"
43 #include "TitleLayer.hh"
51 MainLayer::MainLayer()
53 Mf::dispatcher::addHandler("video.context_recreated",
54 boost::bind(&MainLayer::contextRecreated
, this, _1
), this);
58 MainLayer::~MainLayer()
60 Mf::dispatcher::removeHandler(this);
64 void MainLayer::pushed(Mf::Engine
& e
)
68 //Mf::Scalar coeff[] = {0.0, 1.0};
69 //Mf::Lerp interp(coeff, 0.25);
71 //Mf::LayerP gameLayer = GameLayer::alloc();
72 //Mf::Transition<Mf::Lerp>::Ptr transition =
73 //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
74 //engine->push(transition);
75 //engine->push(GameLayer::alloc());
76 engine
->push(TitleLayer::alloc());
80 void MainLayer::draw(Mf::Scalar alpha
) const
82 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
84 glMatrixMode(GL_PROJECTION
);
87 glMatrixMode(GL_MODELVIEW
);
91 bool MainLayer::handleEvent(const Mf::Event
& event
)
96 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
)
100 else if (event
.key
.keysym
.sym
== SDLK_f
)
102 engine
->getVideo().toggleFull();
104 else if (event
.key
.keysym
.sym
== SDLK_l
)
106 Mf::Video
& video
= engine
->getVideo();
107 video
.toggleCursorGrab();
108 video
.toggleCursorVisible();
110 else if (event
.key
.keysym
.sym
== SDLK_y
)
112 engine
->push(GameLayer::alloc());
116 case SDL_VIDEORESIZE
:
117 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
128 void MainLayer::quit()
131 // we don't really need to unwind the stack and shut everything down because
132 // the operating system will take care of cleaning up
140 void MainLayer::setupGL()
142 glEnable(GL_TEXTURE_2D
);
143 glEnable(GL_DEPTH_TEST
);
145 glEnable(GL_LINE_SMOOTH
);
146 glEnable(GL_POLYGON_SMOOTH
);
147 glShadeModel(GL_SMOOTH
);
149 //glEnable(GL_BLEND);
150 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
151 glEnable(GL_ALPHA_TEST
);
152 glAlphaFunc(GL_GREATER
, 0.0);
154 glClearColor(0.0, 0.0, 0.0, 1.0);
156 glMatrixMode(GL_PROJECTION
);
158 gluPerspective(60.0, 1.33333, 1.0, 2500.0);
160 glMatrixMode(GL_MODELVIEW
);
163 void MainLayer::contextRecreated(const Mf::Notification
* note
)
165 // whenever the context is destroyed and a new one created, it probably
166 // won't contain our state so we need to set that up again
174 std::cout
<< "Usage: "PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..." << std::endl
175 << "The alien-smashing action game." << std::endl
177 << "Options:" << std::endl
178 << " -h, --help" << std::endl
179 << " show this help and exit" << std::endl
180 << " -i, --info" << std::endl
181 << " show version and build information" << std::endl
182 << " detail=1|2|3" << std::endl
183 << " the level of detail of game scenes" << std::endl
184 << " fullscreen=true|false" << std::endl
185 << " if true, uses the entire display" << std::endl
186 << " maxfps=num" << std::endl
187 << " the maximum number of frames per second" << std::endl
189 << "See documentation for more options." << std::endl
;
194 std::cout
<< PACKAGE_STRING
<< std::endl
196 << "When compiled: "__DATE__
" "__TIME__
<< std::endl
198 << "Compiler: "COMPILER_STRING
<< std::endl
199 << "Asset directory: "YOINK_DATADIR
<< std::endl
205 #ifndef USE_DOUBLE_PRECISION
209 #ifndef PROFILING_ENABLED
214 #if !defined (_WIN32) && !defined(__WIN32__)
221 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
226 int main(int argc
, char* argv
[])
230 std::string
arg(argv
[1]);
231 if (arg
== "-h" || arg
== "--help")
236 else if (arg
== "-i" || arg
== "--info")
243 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
244 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
245 << "Send patches and bug reports to <"
246 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
251 #if YOINK_LOGLEVEL >= 4
252 Mf::setLogLevel(Mf::LOG_DEBUG
);
253 #elif YOINK_LOGLEVEL >= 3
254 Mf::setLogLevel(Mf::LOG_INFO
);
255 #elif YOINK_LOGLEVEL >= 2
256 Mf::setLogLevel(Mf::LOG_SCRIPT
);
257 #elif YOINK_LOGLEVEL >= 1
258 Mf::setLogLevel(Mf::LOG_ERROR
);
260 Mf::setLogLevel(Mf::LOG_NONE
);
264 // Add search paths; they should be searched in this order:
265 // 1. YOINK_DATADIR (environment)
266 // 2. YOINK_DATADIR (configure)
268 char* dataDir
= getenv("YOINK_DATADIR");
271 Mf::Resource::addSearchPath(dataDir
);
274 Mf::Resource::addSearchPath(YOINK_DATADIR
);
276 std::string iconFile
= Mf::Resource::getPath("yoink.png");
279 // Build the list of config files to search for, in this order:
280 // 1. YOINK_DATADIR/yoinkrc
283 // 4. YOINKRC (environment)
285 std::string configFiles
;
287 configFiles
+= Mf::Resource::getPath("yoinkrc");
288 configFiles
+= ":/etc/yoinkrc:$HOME/.yoinkrc";
290 char* configFile
= getenv("YOINKRC");
294 configFiles
+= configFile
;
300 Mf::Engine
app(argc
, argv
, PACKAGE_STRING
, iconFile
, configFiles
);
301 app
.push(MainLayer::alloc());
305 catch (Mf::Exception e
)
307 Mf::logError("unhandled exception: <<%s>>", e
.what());
308 Mf::logInfo("it's time to crash now :-(");
316 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.046761 seconds and 4 git commands to generate.