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