]> git.tdb.fi Git - libs/demoscene.git/blob - source/launcher.h
Allow stages to define actions
[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                 Msp::Graphics::GLOptions gl_opts;
30                 int start_fullscreen;
31                 std::string frame_dump_fn;
32                 float framerate;
33                 Msp::Time::TimeDelta seek;
34                 bool no_music;
35                 bool no_vsync;
36
37                 Options(Msp::Graphics::Display &, int, char **);
38
39                 static void parse_size(const std::string &, Msp::Graphics::WindowOptions &);
40         };
41
42         Msp::Graphics::Display display;
43         Options options;
44         Msp::Graphics::Window window;
45         Msp::Graphics::GLContext gl_context;
46         Msp::Input::Keyboard keyboard;
47         Msp::AL::Device *al_device;
48         Msp::AL::Context *al_context;
49
50         LaunchScreen *launch_screen;
51         Msp::Time::TimeStamp timeout;
52
53         Demo *demo;
54         Msp::Time::TimeStamp next_frame;
55         Msp::IO::Base *frame_dump;
56         unsigned frame_size;
57         char *frame_dump_buffer;
58
59 public:
60         LauncherBase(int, char **);
61         ~LauncherBase();
62
63 protected:
64         virtual Resources &get_resources() = 0;
65         virtual Demo *create_demo() = 0;
66         virtual void start();
67         virtual void tick();
68         void tick_launch_screen();
69         virtual void tick_demo();
70
71         void start_demo(bool);
72         void key_press(unsigned);
73
74         virtual void exit(int) = 0;
75 };
76
77 template<typename T>
78 class Launcher: public Msp::RegisteredApplication<T>, public LauncherBase
79 {
80 protected:
81         Launcher(int argc, char **argv): LauncherBase(argc, argv) { }
82
83         virtual int main() { start(); return Msp::Application::main(); }
84         virtual void tick() { LauncherBase::tick(); }
85         virtual void exit(int c) { Msp::Application::exit(c); }
86 };
87
88 } // namespace DemoScene
89 } // namespace Msp
90
91 #endif