]> git.tdb.fi Git - libs/demoscene.git/blob - source/launcher.h
54e6eda17361bf65a491bfeb695585842b1d338a
[libs/demoscene.git] / source / launcher.h
1 #ifndef MSP_DEMOSCENE_LAUNCHER_H_
2 #define MSP_DEMOSCENE_LAUNCHER_H_
3
4 #include <msp/al/context.h>
5 #include <msp/al/device.h>
6 #include <msp/core/application.h>
7 #include <msp/graphics/display.h>
8 #include <msp/graphics/glcontext.h>
9 #include <msp/graphics/window.h>
10 #include <msp/input/keyboard.h>
11 #include <msp/io/base.h>
12 #include <msp/time/timedelta.h>
13 #include <msp/time/timestamp.h>
14 #include "resources.h"
15
16 namespace Msp {
17 namespace DemoScene {
18
19 class Demo;
20 class LaunchScreen;
21
22 class LauncherBase
23 {
24 protected:
25         struct Options
26         {
27                 Msp::Graphics::WindowOptions win_opts;
28                 Msp::Graphics::WindowOptions fullscreen_opts;
29                 int start_fullscreen;
30                 std::string frame_dump_fn;
31                 float framerate;
32                 Msp::Time::TimeDelta seek;
33                 bool no_music;
34                 bool no_vsync;
35
36                 Options(Msp::Graphics::Display &, int, char **);
37
38                 static void parse_size(const std::string &, Msp::Graphics::WindowOptions &);
39         };
40
41         Msp::Graphics::Display display;
42         Options options;
43         Msp::Graphics::Window window;
44         Msp::Graphics::GLContext gl_context;
45         Msp::Input::Keyboard keyboard;
46         Msp::AL::Device *al_device;
47         Msp::AL::Context *al_context;
48
49         LaunchScreen *launch_screen;
50         Msp::Time::TimeStamp timeout;
51
52         Demo *demo;
53         Msp::Time::TimeStamp next_frame;
54         Msp::IO::Base *frame_dump;
55         unsigned frame_size;
56         char *frame_dump_buffer;
57
58 public:
59         LauncherBase(int, char **);
60         ~LauncherBase();
61
62 protected:
63         virtual Resources &get_resources() = 0;
64         virtual Demo *create_demo() = 0;
65         virtual void start();
66         virtual void tick();
67         void tick_launch_screen();
68         virtual void tick_demo();
69
70         void start_demo(bool);
71         void key_press(unsigned);
72
73         virtual void exit(int) = 0;
74 };
75
76 template<typename T>
77 class Launcher: public Msp::RegisteredApplication<T>, public LauncherBase
78 {
79 protected:
80         Launcher(int argc, char **argv): LauncherBase(argc, argv) { }
81
82         virtual int main() { start(); return Msp::Application::main(); }
83         virtual void tick() { LauncherBase::tick(); }
84         virtual void exit(int c) { Msp::Application::exit(c); }
85 };
86
87 } // namespace DemoScene
88 } // namespace Msp
89
90 #endif