]> git.tdb.fi Git - libs/demoscene.git/blob - source/stage.cpp
Make it possible for Stages to add things to the Demo
[libs/demoscene.git] / source / stage.cpp
1 #include <msp/gl/view.h>
2 #include "demo.h"
3 #include "stage.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 Stage::Stage():
9         pipeline(0)
10 { }
11
12 Stage::~Stage()
13 {
14         delete pipeline;
15 }
16
17 void Stage::add_things(Demo::ThingMap &things, const string &prefix)
18 {
19         things[prefix+"camera"] = static_cast<GL::Placeable *>(&camera);
20 }
21
22 void Stage::add_postprocessor(GL::PostProcessor &pp)
23 {
24         pipeline->add_postprocessor(pp);
25 }
26
27 void Stage::set_camera(const GL::Camera &c)
28 {
29         camera.set_object_matrix(c.get_object_matrix());
30         camera.set_up_direction(c.get_up_direction());
31         camera.set_field_of_view(c.get_field_of_view());
32         camera.set_depth_clip(c.get_near_clip(), c.get_far_clip());
33 }
34
35
36 Stage::UseInView::UseInView():
37         view(0),
38         stage(0)
39 { }
40
41 Stage::UseInView::UseInView(GL::View &v, Stage &s):
42         view(&v),
43         stage(&s)
44 { }
45
46 void Stage::UseInView::validate() const
47 {
48         if(!view)
49                 throw logic_error("null view");
50         if(!stage)
51                 throw logic_error("null stage");
52 }
53
54 void Stage::UseInView::start(float, float)
55 {
56         view->set_camera(&stage->camera);
57         view->set_content(stage->pipeline);
58 }
59
60
61 Stage::SetCamera::SetCamera():
62         stage(0),
63         camera(0)
64 { }
65
66 Stage::SetCamera::SetCamera(Stage &s, const GL::Camera &c):
67         stage(&s),
68         camera(&c)
69 { }
70
71 void Stage::SetCamera::validate() const
72 {
73         if(!stage)
74                 throw logic_error("null stage");
75         if(!camera)
76                 throw logic_error("null camera");
77 }
78
79 void Stage::SetCamera::start(float, float)
80 {
81         stage->set_camera(*camera);
82 }
83
84
85 Stage::UseInView::Loader::Loader(UseInView &u, Demo &d):
86         DataFile::DerivedObjectLoader<UseInView, Action::Loader>(u, d)
87 {
88         add("stage", &Loader::stage);
89         add("view", &Loader::view);
90 }
91
92 void Stage::UseInView::Loader::stage(const string &n)
93 {
94         obj.stage = &demo.get_thing<Stage>(n);
95 }
96
97 void Stage::UseInView::Loader::view(const string &n)
98 {
99         obj.view = &demo.get_thing<GL::View>(n);
100 }
101
102
103 Stage::SetCamera::Loader::Loader(SetCamera &s, Demo &d):
104         DataFile::DerivedObjectLoader<SetCamera, Action::Loader>(s, d)
105 {
106         add("camera", &Loader::camera);
107         add("stage", &Loader::stage);
108 }
109
110 void Stage::SetCamera::Loader::stage(const string &n)
111 {
112         obj.stage = &demo.get_thing<Stage>(n);
113 }
114
115 void Stage::SetCamera::Loader::camera(const string &n)
116 {
117         obj.camera = &demo.get_resources().get<GL::Camera>(n);
118 }