]>
Dogcows Code - chaz/yoink/blob - src/MainLayer.cc
2266326402f89b475df8c1a57b3f4abd3dba9d37
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
34 #include <Moof/Dispatcher.hh>
35 #include <Moof/Exception.hh>
36 #include <Moof/Log.hh>
37 #include <Moof/OpenGL.hh>
38 #include <Moof/Resource.hh>
39 #include <Moof/Transition.hh>
40 #include <Moof/Video.hh>
42 #include "GameLayer.hh"
43 #include "MainLayer.hh"
44 #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] [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 << " detail=1|2|3" << std::endl
181 << " the level of detail of game scenes" << std::endl
182 << " fullscreen=true|false" << std::endl
183 << " if true, uses the entire display" << std::endl
184 << " maxfps=num" << std::endl
185 << " the maximum number of frames per second" << std::endl
187 << "See documentation for more options." << std::endl
;
192 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
195 int main(int argc
, char* argv
[])
198 (strcmp(argv
[1], "-h") == 0 || strcmp(argv
[1], "--help") == 0))
204 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
205 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
206 << "Send patches and bug reports to <"
207 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
212 #if YOINK_LOGLEVEL >= 4
213 Mf::setLogLevel(Mf::LOG_DEBUG
);
214 #elif YOINK_LOGLEVEL >= 3
215 Mf::setLogLevel(Mf::LOG_INFO
);
216 #elif YOINK_LOGLEVEL >= 2
217 Mf::setLogLevel(Mf::LOG_SCRIPT
);
218 #elif YOINK_LOGLEVEL >= 1
219 Mf::setLogLevel(Mf::LOG_ERROR
);
221 Mf::setLogLevel(Mf::LOG_NONE
);
225 // Add search paths; they should be searched in this order:
226 // 1. YOINK_DATADIR (environment)
227 // 2. YOINK_DATADIR (configure)
229 char* dataDir
= getenv("YOINK_DATADIR");
232 Mf::Resource::addSearchPath(dataDir
);
235 Mf::Resource::addSearchPath(YOINK_DATADIR
);
237 std::string iconFile
= Mf::Resource::getPath("yoink.png");
240 // Build the list of config files to search for, in this order:
241 // 1. YOINK_DATADIR/yoinkrc
244 // 4. YOINKRC (environment)
246 std::string configFiles
;
248 configFiles
+= Mf::Resource::getPath("yoinkrc");
249 configFiles
+= ":/etc/yoinkrc:$HOME/.yoinkrc";
251 char* configFile
= getenv("YOINKRC");
255 configFiles
+= configFile
;
261 Mf::Engine
app(argc
, argv
, PACKAGE_STRING
, iconFile
, configFiles
);
262 app
.push(MainLayer::alloc());
266 catch (Mf::Exception e
)
268 Mf::logError("unhandled exception: <<%s>>", e
.what());
269 Mf::logInfo("it's time to crash now :-(");
277 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.047241 seconds and 4 git commands to generate.