]>
Dogcows Code - chaz/yoink/blob - src/MainLayer.cc
51881a770d0e03d8f6d2846c96542c4a2e265d34
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> // 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/Video.hh>
41 #include "GameLayer.hh"
42 #include "MainLayer.hh"
49 MainLayer::MainLayer()
51 Mf::dispatcher::addHandler("video.context_recreated",
52 boost::bind(&MainLayer::contextRecreated
, this, _1
), this);
56 MainLayer::~MainLayer()
58 Mf::dispatcher::removeHandler(this);
62 void MainLayer::pushed(Mf::Engine
& e
)
65 engine
->pushLayer(GameLayer::alloc());
69 void MainLayer::draw(Mf::Scalar alpha
) const
71 glClear(GL_DEPTH_BUFFER_BIT
);
74 bool MainLayer::handleEvent(const Mf::Event
& event
)
79 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
)
81 engine
->clearLayers();
83 else if (event
.key
.keysym
.sym
== SDLK_f
)
85 engine
->getVideo().toggleFull();
87 else if (event
.key
.keysym
.sym
== SDLK_l
)
89 Mf::Video
& video
= engine
->getVideo();
90 video
.toggleCursorGrab();
91 video
.toggleCursorVisible();
93 else if (event
.key
.keysym
.sym
== SDLK_y
)
95 engine
->pushLayer(GameLayer::alloc());
100 engine
->clearLayers();
108 void MainLayer::setupGL()
110 glEnable(GL_TEXTURE_2D
);
112 //glEnable(GL_CULL_FACE);
113 glEnable(GL_DEPTH_TEST
);
115 glShadeModel(GL_SMOOTH
);
116 //glEnable(GL_POLYGON_SMOOTH);
119 //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
120 //std::cout << "texture size: " << texSize << std::endl;
122 //glEnable(GL_BLEND);
123 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
124 glEnable(GL_ALPHA_TEST
);
125 glAlphaFunc(GL_GREATER
, 0.0);
127 glClearColor(1.0, 0.0, 0.0, 1.0);
129 //glMatrixMode(GL_PROJECTION);
131 //gluPerspective(60.0, 1.33333, 1.0, 2500.0);
133 //glMatrixMode(GL_MODELVIEW);
135 //glLineWidth(10.0f);
138 void MainLayer::contextRecreated(const Mf::Notification
* note
)
140 // whenever the context is destroyed and a new one created, it probably
141 // won't contain our state so we need to set that up again
149 std::cout
<< "Usage: "PACKAGE
" [-h|--help] [OPTION=VALUE]..." << std::endl
150 << "The alien-smashing action game." << std::endl
152 << "Options:" << std::endl
153 << " -h, --help" << std::endl
154 << " show this help and exit" << std::endl
155 << " detail=1|2|3" << std::endl
156 << " the level of detail of game scenes" << std::endl
157 << " fullscreen=true|false" << std::endl
158 << " if true, uses the entire display" << std::endl
159 << " maxfps=num" << std::endl
160 << " the maximum number of frames per second" << std::endl
162 << "See documentation for more options." << std::endl
;
165 int main(int argc
, char* argv
[])
168 (strcmp(argv
[1], "-h") == 0 || strcmp(argv
[1], "--help") == 0))
174 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
175 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
176 << "Send patches and bug reports to <"
177 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
180 #if YOINK_LOGLEVEL >= 4
181 Mf::setLogLevel(Mf::LOG_DEBUG
);
182 #elif YOINK_LOGLEVEL >= 3
183 Mf::setLogLevel(Mf::LOG_INFO
);
184 #elif YOINK_LOGLEVEL >= 2
185 Mf::setLogLevel(Mf::LOG_SCRIPT
);
186 #elif YOINK_LOGLEVEL >= 1
187 Mf::setLogLevel(Mf::LOG_ERROR
);
189 Mf::setLogLevel(Mf::LOG_NONE
);
193 // Add search paths; they should be searched in this order:
194 // 1. YOINK_DATADIR (environment)
195 // 2. YOINK_DATADIR (configure)
197 char* dataDir
= getenv("YOINK_DATADIR");
200 Mf::Resource::addSearchPath(dataDir
);
203 Mf::Resource::addSearchPath(YOINK_DATADIR
);
205 std::string iconFile
= Mf::Resource::getPath("yoink.png");
208 // Build the list of config files to search for, in this order:
209 // 1. YOINK_DATADIR/yoinkrc
212 // 4. YOINKRC (environment)
214 std::string configFiles
;
216 configFiles
+= Mf::Resource::getPath("yoinkrc");
217 configFiles
+= ":/etc/yoinkrc:$HOME/.yoinkrc";
219 char* configFile
= getenv("YOINKRC");
223 configFiles
+= configFile
;
229 Mf::Engine
app(argc
, argv
, PACKAGE_STRING
, iconFile
, configFiles
);
230 app
.pushLayer(MainLayer::alloc());
234 catch (Mf::Exception e
)
236 Mf::logError("unhandled exception: <<%s>>", e
.what());
237 Mf::logInfo("it's time to crash now :-(");
241 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
246 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.037869 seconds and 3 git commands to generate.