From 8deb365040ebf0037c841dfe8435c9e4a6ae4224 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 31 Oct 2011 08:19:05 +0000 Subject: [PATCH] core: write a generic application class. --- src/Makefile.am | 1 + src/application/application.cpp | 72 +++++++++++++++++++++++++++++++++ src/application/application.h | 39 ++++++++++++++++++ src/core.h | 1 + src/platform/ps3/ps3app.cpp | 3 ++ src/platform/sdl/sdlapp.cpp | 4 ++ test/debug/quad.cpp | 22 +--------- 7 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 src/application/application.cpp create mode 100644 src/application/application.h diff --git a/src/Makefile.am b/src/Makefile.am index b31901b3..4435cacd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ liblol_a_SOURCES = \ \ lol/unit.h \ \ + application/application.cpp application/application.h \ eglapp.cpp eglapp.h \ \ $(ps3_sources) \ diff --git a/src/application/application.cpp b/src/application/application.cpp new file mode 100644 index 00000000..68d14bab --- /dev/null +++ b/src/application/application.cpp @@ -0,0 +1,72 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "lolgl.h" + +#if defined __CELLOS_LV2__ +# include "platform/ps3/ps3app.h" +#elif defined HAVE_GLES_2X +# include "eglapp.h" +#else +# include "platform/sdl/sdlapp.h" +# include "platform/sdl/sdlinput.h" +#endif + +using namespace std; + +namespace lol +{ + +class ApplicationData +{ + friend class Application; + + ApplicationData(char const *name, ivec2 resolution, float framerate) + : app(name, resolution, framerate) + { } + +#if defined __CELLOS_LV2__ + Ps3App app; +#elif defined HAVE_GLES_2X + /* FIXME: this macro is only deactivated if we include "lolgl.h" */ + EglApp app; +#elif defined HAVE_SDL_H + SdlApp app; +#else +# error No application class available on this platform +#endif +}; + +/* + * Public Application class + */ + +Application::Application(char const *name, ivec2 resolution, float framerate) +{ + data = new ApplicationData(name, resolution, framerate); +} + +void Application::Run() +{ + data->app.Run(); +} + +Application::~Application() +{ + delete data; +} + +} /* namespace lol */ + diff --git a/src/application/application.h b/src/application/application.h new file mode 100644 index 00000000..69b08b6e --- /dev/null +++ b/src/application/application.h @@ -0,0 +1,39 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The Application class +// --------------------- +// + +#if !defined __LOL_APPLICATION_H__ +#define __LOL_APPLICATION_H__ + +namespace lol +{ + +class ApplicationData; + +class Application +{ +public: + Application(char const *name, ivec2 resolution, float framerate); + ~Application(); + + void Run(); + +private: + ApplicationData *data; +}; + +} /* namespace lol */ + +#endif // __LOL_APPLICATION_H__ + diff --git a/src/core.h b/src/core.h index feefb6fc..b95d5db3 100644 --- a/src/core.h +++ b/src/core.h @@ -98,6 +98,7 @@ static inline int isnan(float f) #include "layer.h" #include "shader/shader.h" #include "image/image.h" +#include "application/application.h" // Managers #include "ticker.h" diff --git a/src/platform/ps3/ps3app.cpp b/src/platform/ps3/ps3app.cpp index 992fbec1..06e7172d 100644 --- a/src/platform/ps3/ps3app.cpp +++ b/src/platform/ps3/ps3app.cpp @@ -102,6 +102,9 @@ Ps3App::Ps3App(char const *title, ivec2 res, float fps) : Ticker::Setup(fps); Video::Setup(res); Audio::Setup(2); + + /* Autoreleased objects */ + new Ps3Input(); #endif } diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index d3859c49..8c8afc09 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -19,6 +19,7 @@ #include "core.h" #include "lolgl.h" #include "platform/sdl/sdlapp.h" +#include "platform/sdl/sdlinput.h" namespace lol { @@ -67,6 +68,9 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : Ticker::Setup(fps); Video::Setup(ivec2(video->w, video->h)); Audio::Setup(2); + + /* Autoreleased objects */ + new SdlInput(); #endif } diff --git a/test/debug/quad.cpp b/test/debug/quad.cpp index 9e2c6b05..7792120f 100644 --- a/test/debug/quad.cpp +++ b/test/debug/quad.cpp @@ -19,15 +19,6 @@ using namespace std; using namespace lol; -#if defined __CELLOS_LV2__ -# include "platform/ps3/ps3app.h" -#elif defined HAVE_GLES_2X -# include "eglapp.h" -#else -# include "platform/sdl/sdlapp.h" -# include "platform/sdl/sdlinput.h" -#endif - #if USE_SDL && defined __APPLE__ # include #endif @@ -38,18 +29,9 @@ using namespace lol; int main(int argc, char **argv) { -#if defined __CELLOS_LV2__ - Ps3App app("Quad", ivec2(640, 480), 60.0f); -#elif defined HAVE_GLES_2X - EglApp app("Quad", ivec2(640, 480), 60.0f); -#else - SdlApp app("Quad", ivec2(640, 480), 60.0f); -#endif + Application app("Quad", ivec2(640, 480), 60.0f); - /* Register an input driver and some debug stuff */ -#if !defined HAVE_GLES_2X - new SdlInput(); -#endif + /* Register some debug stuff */ new DebugFps(5, 5); new DebugQuad();