]> Dogcows Code - chaz/yoink/blobdiff - src/MainLayer.cc
beginning CD implementation
[chaz/yoink] / src / MainLayer.cc
index 51881a770d0e03d8f6d2846c96542c4a2e265d34..4975e17f1b28db30e9df1d95a73469a9f6a85456 100644 (file)
@@ -26,8 +26,7 @@
 
 *******************************************************************************/
 
-#include <cstdlib>             // getenv
-#include <cstring>
+#include <cstdlib>             // atexit, getenv
 #include <iostream>
 #include <string>
 
 #include <Moof/Log.hh>
 #include <Moof/OpenGL.hh>
 #include <Moof/Resource.hh>
+#include <Moof/Transition.hh>
 #include <Moof/Video.hh>
 
 #include "GameLayer.hh"
 #include "MainLayer.hh"
+#include "TitleLayer.hh"
 
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "version.h"
 
 
 MainLayer::MainLayer()
@@ -62,13 +64,28 @@ MainLayer::~MainLayer()
 void MainLayer::pushed(Mf::Engine& e)
 {
        engine = &e;
-       engine->pushLayer(GameLayer::alloc());
+
+       //Mf::Scalar coeff[] = {0.0, 1.0};
+       //Mf::Lerp interp(coeff, 0.25);
+
+       //Mf::LayerP gameLayer = GameLayer::alloc();
+       //Mf::Transition<Mf::Lerp>::Ptr transition =
+               //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
+       //engine->push(transition);
+       //engine->push(GameLayer::alloc());
+       engine->push(TitleLayer::alloc());
 }
 
 
 void MainLayer::draw(Mf::Scalar alpha) const
 {
-       glClear(GL_DEPTH_BUFFER_BIT);
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+
+       glMatrixMode(GL_MODELVIEW);
+       glLoadIdentity();
 }
 
 bool MainLayer::handleEvent(const Mf::Event& event)
@@ -78,7 +95,7 @@ bool MainLayer::handleEvent(const Mf::Event& event)
                case SDL_KEYDOWN:
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               engine->clearLayers();
+                               quit();
                        }
                        else if (event.key.keysym.sym == SDLK_f)
                        {
@@ -92,47 +109,55 @@ bool MainLayer::handleEvent(const Mf::Event& event)
                        }
                        else if (event.key.keysym.sym == SDLK_y)
                        {
-                               engine->pushLayer(GameLayer::alloc());
+                               engine->push(GameLayer::alloc());
                        }
                        break;
 
+               case SDL_VIDEORESIZE:
+                       glViewport(0, 0, event.resize.w, event.resize.h);
+                       break;
+
                case SDL_QUIT:
-                       engine->clearLayers();
+                       quit();
                        break;
        }
 
        return false;
 }
 
+void MainLayer::quit()
+{
+#if NDEBUG
+       // we don't really need to unwind the stack and shut everything down because
+       // the operating system will take care of cleaning up
+       exit(0);
+#else
+       engine->clear();
+#endif
+}
+
 
 void MainLayer::setupGL()
 {
        glEnable(GL_TEXTURE_2D);
-
-       //glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
 
+       glEnable(GL_LINE_SMOOTH);
+       glEnable(GL_POLYGON_SMOOTH);
        glShadeModel(GL_SMOOTH);
-       //glEnable(GL_POLYGON_SMOOTH);
 
-       //int texSize;
-       //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
-       //std::cout << "texture size: " << texSize << std::endl;
-       
        //glEnable(GL_BLEND);
        //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(GL_GREATER, 0.0);
 
-       glClearColor(1.0, 0.0, 0.0, 1.0);
+       glClearColor(0.0, 0.0, 0.0, 1.0);
 
-       //glMatrixMode(GL_PROJECTION);
-       //glLoadIdentity();
-       //gluPerspective(60.0, 1.33333, 1.0, 2500.0);
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+       gluPerspective(60.0, 1.33333, 1.0, 2500.0);
 
-       //glMatrixMode(GL_MODELVIEW);
-       
-       //glLineWidth(10.0f);
+       glMatrixMode(GL_MODELVIEW);
 }
 
 void MainLayer::contextRecreated(const Mf::Notification* note)
@@ -146,12 +171,14 @@ void MainLayer::contextRecreated(const Mf::Notification* note)
 
 void printUsage()
 {
-       std::cout << "Usage: "PACKAGE" [-h|--help] [OPTION=VALUE]..." << std::endl
+       std::cout << "Usage: "PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." << std::endl
                          << "The alien-smashing action game." << std::endl
                          << std::endl
                          << "Options:" << std::endl
                          << "  -h, --help" << std::endl
                          << "      show this help and exit" << std::endl
+                         << "  -i, --info" << std::endl
+                         << "      show version and build information" << std::endl
                          << "  detail=1|2|3" << std::endl
                          << "      the level of detail of game scenes" << std::endl
                          << "  fullscreen=true|false" << std::endl
@@ -162,13 +189,55 @@ void printUsage()
                          << "See documentation for more options." << std::endl;
 }
 
+void printInfo()
+{
+       std::cout << PACKAGE_STRING << std::endl
+#ifdef __DATE__
+                         << "When compiled: "__DATE__" "__TIME__ << std::endl
+#endif
+                         << "Compiler: "COMPILER_STRING << std::endl
+                         << "Asset directory: "YOINK_DATADIR << std::endl
+                         << "Build options: "
+#ifdef NDEBUG
+                         << "-"
+#endif
+                         << "debug "
+#ifndef USE_DOUBLE_PRECISION
+                         << "-"
+#endif
+                         << "double "
+#ifndef PROFILING_ENABLED
+                         << "-"
+#endif
+                         << "profile "
+                         << std::endl;
+#if !defined (_WIN32) && !defined(__WIN32__)
+       system("uname -a");
+#endif
+}
+
+void goodbye()
+{
+       std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
+}
+
+
+
 int main(int argc, char* argv[])
 {
-       if (argc > 1 &&
-                       (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))
+       if (argc > 1)
        {
-               printUsage();
-               return 0;
+               std::string arg(argv[1]);
+               if (arg == "-h" || arg == "--help")
+               {
+                       printUsage();
+                       return 0;
+               }
+               else if (arg == "-i" || arg == "--info")
+               {
+                       printInfo();
+                       return 0;
+               }
        }
 
        std::cout << std::endl << PACKAGE_STRING << std::endl
@@ -176,6 +245,8 @@ int main(int argc, char* argv[])
                          << "Send patches and bug reports to <"
                          PACKAGE_BUGREPORT << ">." << std::endl << std::endl;
 
+       atexit(goodbye);
+
 
 #if            YOINK_LOGLEVEL >= 4
        Mf::setLogLevel(Mf::LOG_DEBUG);
@@ -227,7 +298,7 @@ int main(int argc, char* argv[])
        try
        {
                Mf::Engine app(argc, argv, PACKAGE_STRING, iconFile, configFiles);
-               app.pushLayer(MainLayer::alloc());
+               app.push(MainLayer::alloc());
 
                app.run();
        }
@@ -238,7 +309,6 @@ int main(int argc, char* argv[])
                throw e;
        }
 
-       std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
        return 0;
 }
 
This page took 0.023632 seconds and 4 git commands to generate.