Procházet zdrojové kódy

core: write a generic application class.

legacy
Sam Hocevar sam před 13 roky
rodič
revize
8deb365040
7 změnil soubory, kde provedl 122 přidání a 20 odebrání
  1. +1
    -0
      src/Makefile.am
  2. +72
    -0
      src/application/application.cpp
  3. +39
    -0
      src/application/application.h
  4. +1
    -0
      src/core.h
  5. +3
    -0
      src/platform/ps3/ps3app.cpp
  6. +4
    -0
      src/platform/sdl/sdlapp.cpp
  7. +2
    -20
      test/debug/quad.cpp

+ 1
- 0
src/Makefile.am Zobrazit soubor

@@ -15,6 +15,7 @@ liblol_a_SOURCES = \
\
lol/unit.h \
\
application/application.cpp application/application.h \
eglapp.cpp eglapp.h \
\
$(ps3_sources) \


+ 72
- 0
src/application/application.cpp Zobrazit soubor

@@ -0,0 +1,72 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 */


+ 39
- 0
src/application/application.h Zobrazit soubor

@@ -0,0 +1,39 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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__


+ 1
- 0
src/core.h Zobrazit soubor

@@ -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"


+ 3
- 0
src/platform/ps3/ps3app.cpp Zobrazit soubor

@@ -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
}



+ 4
- 0
src/platform/sdl/sdlapp.cpp Zobrazit soubor

@@ -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
}



+ 2
- 20
test/debug/quad.cpp Zobrazit soubor

@@ -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 <SDL_main.h>
#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();



Načítá se…
Zrušit
Uložit