]> Dogcows Code - chaz/yoink/blobdiff - src/Main.cc
further implementing runloop support
[chaz/yoink] / src / Main.cc
index ff2ce61d081fc47ffa5a8c42c35322ea99db614d..070912e7ce1a0c7acb8fb7c3e1f75adf6cb151eb 100644 (file)
@@ -26,6 +26,7 @@ inline int isatty(int dummy) { return 0; }
 #include <stlplus/portability/file_system.hpp>
 #include <stlplus/portability/subprocesses.hpp>
 
+#include <moof/image.hh>
 #include <moof/log.hh>
 #include <moof/modal_dialog.hh>
 #include <moof/opengl.hh>
@@ -34,21 +35,19 @@ inline int isatty(int dummy) { return 0; }
 #include <moof/string.hh>
 #include <moof/video.hh>
 
-#include "GameLayer.hh"
 #include "Main.hh"
-#include "TitleLayer.hh"
 #include "version.h"
 
 
-Main::Main(moof::settings& settings, moof::video& video) :
-       moof::view(settings, video)
+Main::Main(moof::settings& settings) :
+       moof::application(settings)
 {
        moof::dispatcher& dispatcher = moof::dispatcher::global();
        video_reloaded_ = dispatcher.add_target("video.newcontext",
                                                                                        boost::bind(&Main::setup_opengl));
        setup_opengl();
 
-#if USE_HOTLOADING
+#if ENABLE_HOTLOADING
        hotload_timer_.init(boost::bind(&moof::resource::reload_as_needed),
                                                SCALAR(0.25),
                                                moof::timer::repeat);
@@ -58,15 +57,7 @@ Main::Main(moof::settings& settings, moof::video& video) :
 
 void Main::update(moof::scalar t, moof::scalar dt)
 {
-       if (children().size() == 0)
-       {
-               //moof::log_warning("main view has no children");
-               //stop();
-               //return;
-               add_child(TitleLayer::alloc());
-       }
-
-       moof::view::update(t, dt);
+       yoink.update(t, dt);
 }
 
 void Main::draw(moof::scalar alpha) const
@@ -79,37 +70,41 @@ void Main::draw(moof::scalar alpha) const
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 
-       moof::view::draw(alpha);
+       yoink.draw(alpha);
 }
 
-bool Main::handle_event(const moof::event& event)
+void Main::handle_event(const moof::event& event)
 {
-       if (moof::view::handle_event(event)) return true;
+       if (yoink.handle_event(event)) return;
 
        switch (event.type)
        {
                case SDL_KEYUP:
+
                        if (event.key.keysym.sym == SDLK_f)
                        {
-                               video().toggle_fullscreen();
+                               moof::video::current()->toggle_fullscreen();
                        }
                        else if (event.key.keysym.sym == SDLK_l)
                        {
-                               video().toggle_cursor_captured();
-                               video().toggle_cursor_visible();
+                               moof::video::current()->toggle_cursor_captured();
+                               moof::video::current()->toggle_cursor_visible();
+                       }
+                       else if (event.key.keysym.sym == SDLK_ESCAPE)
+                       {
+                               stop();
                        }
                        break;
 
                case SDL_VIDEORESIZE:
+
                        glViewport(0, 0, event.resize.w, event.resize.h);
                        break;
 
                case SDL_QUIT:
+
                        stop();
-                       return true;
        }
-
-       return false;
 }
 
 
@@ -173,7 +168,7 @@ void Main::setup_opengl()
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(GL_GREATER, 0.0);
 
-       glClearColor(0.0, 0.0, 0.0, 1.0);
+       glClearColor(1.0, 0.0, 0.0, 1.0);
 
        //glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
@@ -259,7 +254,7 @@ void Main::print_info(int argc, char* argv[])
                          << "       Assets: " << assets << std::endl
                          << "Build options: ";
 
-#if USE_CLOCK_GETTIME
+#if ENABLE_CLOCK_GETTIME
        print_option("clock_gettime", true);
 #else
        print_option("clock_gettime", false);
@@ -269,27 +264,32 @@ void Main::print_info(int argc, char* argv[])
 #else
        print_option("debug", false);
 #endif
-#if USE_GTK
+#if ENABLE_DOUBLE_PRECISION
+       print_option("double", true);
+#else
+       print_option("double", false);
+#endif
+#if WITH_GTK
        print_option("gtk", true);
 #else
        print_option("gtk", false);
 #endif
-#if USE_HOTLOADING
+#if ENABLE_HOTLOADING
        print_option("hotload", true);
 #else
        print_option("hotload", false);
 #endif
-#if PROFILING_ENABLED
+#if ENABLE_PROFILING
        print_option("profile", true);
 #else
        print_option("profile", false);
 #endif
-#if USE_QT4
+#if WITH_QT4
        print_option("qt4", true);
 #else
        print_option("qt4", false);
 #endif
-#if USE_THREADS
+#if ENABLE_THREADS
        print_option("threads", true);
 #else
        print_option("threads", false);
@@ -331,7 +331,7 @@ void goodbye()
 
 int main(int argc, char* argv[])
 {
-       //moof::backend backend;
+       moof::backend backend;
 
        if (argc > 1)
        {
@@ -361,10 +361,6 @@ int main(int argc, char* argv[])
 
        try
        {
-               //std::string iconPath(PACKAGE".png");
-               //iconPath = moof::resource::find_file(iconPath);
-               //moof::image icon(iconPath);
-               //icon.set_as_icon();
                moof::image_handle icon(PACKAGE, "png");
                if (icon) icon->set_as_icon();
                else moof::log_error("no icon loaded");
@@ -372,10 +368,10 @@ int main(int argc, char* argv[])
 
                class moof::video::attributes attributes(settings);
                moof::video video(PACKAGE_STRING, attributes);
-               Main            mainView(settings, video);
+               video.show_fps(true);
 
-               mainView.run();
-               return 0;
+               Main app(settings);
+               return app.run();
        }
        catch (const std::exception& e)
        {
This page took 0.026159 seconds and 4 git commands to generate.