~gimaker/peekabot/coord-sys-default

« back to all changes in this revision

Viewing changes to src/renderer/api/ObjectEntityProxy.cc

  • Committer: Staffan Gimåker
  • Date: 2009-06-29 10:09:26 UTC
  • mfrom: (665.1.39 renderer-redux)
  • Revision ID: staffan@gimaker.se-20090629100926-ju5kx8jwzy422rwu
Merged the renderer-redux branch.

This represents a major overhaul to the rendering engine, with a less contrived
design and better performance. Both memory and CPU utilization should be 
better in general.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright Staffan Gimåker 2008-2009.
 
3
 *
 
4
 * ---
 
5
 *
 
6
 * This file is part of peekabot.
 
7
 *
 
8
 * peekabot is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * peekabot is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#include "ObjectEntityProxy.hh"
 
23
#include "Renderer.hh"
 
24
#include "../SceneAction.hh"
 
25
#include "../Scene.hh"
 
26
#include "../ObjectEntity.hh"
 
27
 
 
28
 
 
29
using namespace peekabot;
 
30
using namespace peekabot::renderer;
 
31
using namespace peekabot::renderer::api;
 
32
 
 
33
 
 
34
ObjectEntityProxy::ObjectEntityProxy(Renderer &renderer)
 
35
    : EntityProxy(renderer)
 
36
{
 
37
}
 
38
 
 
39
 
 
40
void ObjectEntityProxy::set_transformation(const Matrix4f &mtow)
 
41
{
 
42
    class SetTransformation : public SceneAction
 
43
    {
 
44
    public:
 
45
        SetTransformation(EntityID id, const Matrix4f &mtow)
 
46
            : m_id(id), m_mtow(mtow) {}
 
47
 
 
48
        virtual void execute(SceneAction::Context &context)
 
49
        {
 
50
            context.scene().get_entity<ObjectEntity>(
 
51
                m_id)->set_transformation(m_mtow);
 
52
        }
 
53
 
 
54
    private:
 
55
        const EntityID m_id;
 
56
        const Matrix4f m_mtow;
 
57
    };
 
58
 
 
59
    dispatch(new SetTransformation(entity_id(), mtow));
 
60
}
 
61
 
 
62
 
 
63
void ObjectEntityProxy::set_color(const RGBColor &color)
 
64
{
 
65
    class SetColor : public SceneAction
 
66
    {
 
67
    public:
 
68
        SetColor(EntityID id, const RGBColor &color)
 
69
            : m_id(id), m_color(color) {}
 
70
 
 
71
        virtual void execute(SceneAction::Context &context)
 
72
        {
 
73
            context.scene().get_entity<ObjectEntity>(
 
74
                m_id)->set_color(m_color);
 
75
        }
 
76
 
 
77
    private:
 
78
        const EntityID m_id;
 
79
        const RGBColor m_color;
 
80
    };
 
81
 
 
82
    dispatch(new SetColor(entity_id(), color));
 
83
}
 
84
 
 
85
 
 
86
void ObjectEntityProxy::set_opacity(float alpha)
 
87
{
 
88
    class SetOpacity : public SceneAction
 
89
    {
 
90
    public:
 
91
        SetOpacity(EntityID id, float alpha) : m_id(id), m_alpha(alpha) {}
 
92
 
 
93
        virtual void execute(SceneAction::Context &context)
 
94
        {
 
95
            context.scene().get_entity<ObjectEntity>(
 
96
                m_id)->set_opacity(m_alpha);
 
97
        }
 
98
 
 
99
    private:
 
100
        const EntityID m_id;
 
101
        const float m_alpha;
 
102
    };
 
103
 
 
104
    dispatch(new SetOpacity(entity_id(), alpha));
 
105
}
 
106
 
 
107
 
 
108
void ObjectEntityProxy::set_layer(uint32_t layer)
 
109
{
 
110
    class SetLayer : public SceneAction
 
111
    {
 
112
    public:
 
113
        SetLayer(EntityID id, uint32_t layer) : m_id(id), m_layer(layer) {}
 
114
 
 
115
        virtual void execute(SceneAction::Context &context)
 
116
        {
 
117
            context.scene().get_entity<ObjectEntity>(m_id)->set_layer(m_layer);
 
118
        }
 
119
 
 
120
    private:
 
121
        const EntityID m_id;
 
122
        const uint32_t m_layer;
 
123
    };
 
124
 
 
125
    dispatch(new SetLayer(entity_id(), layer));
 
126
}
 
127
 
 
128
 
 
129
void ObjectEntityProxy::set_name(uint32_t name)
 
130
{
 
131
    class SetName : public SceneAction
 
132
    {
 
133
    public:
 
134
        SetName(EntityID id, uint32_t name) : m_id(id), m_name(name) {}
 
135
 
 
136
        virtual void execute(SceneAction::Context &context)
 
137
        {
 
138
            context.scene().get_entity<ObjectEntity>(m_id)->set_name(m_name);
 
139
        }
 
140
 
 
141
    private:
 
142
        const EntityID m_id;
 
143
        const uint32_t m_name;
 
144
    };
 
145
 
 
146
    dispatch(new SetName(entity_id(), name));
 
147
}
 
148
 
 
149
 
 
150
void ObjectEntityProxy::set_visibility(bool visible)
 
151
{
 
152
    class SetVisibility : public SceneAction
 
153
    {
 
154
    public:
 
155
        SetVisibility(EntityID id, bool visible) :
 
156
            m_id(id), m_visible(visible) {}
 
157
 
 
158
        virtual void execute(SceneAction::Context &context)
 
159
        {
 
160
            context.scene().get_entity<ObjectEntity>(
 
161
                m_id)->set_visibility(m_visible);
 
162
        }
 
163
 
 
164
    private:
 
165
        const EntityID m_id;
 
166
        const bool m_visible;
 
167
    };
 
168
 
 
169
    dispatch(new SetVisibility(entity_id(), visible));
 
170
}
 
171
 
 
172
 
 
173
void ObjectEntityProxy::set_selected(bool is_selected)
 
174
{
 
175
    class SetSelected : public SceneAction
 
176
    {
 
177
    public:
 
178
        SetSelected(EntityID id, bool is_selected)
 
179
            : m_id(id), m_is_selected(is_selected) {}
 
180
 
 
181
        virtual void execute(SceneAction::Context &context)
 
182
        {
 
183
            context.scene().get_entity<ObjectEntity>(
 
184
                m_id)->set_selected(m_is_selected);
 
185
        }
 
186
 
 
187
    private:
 
188
        const EntityID m_id;
 
189
        const bool m_is_selected;
 
190
    };
 
191
 
 
192
    dispatch(new SetSelected(entity_id(), is_selected));
 
193
}
 
194
 
 
195
 
 
196
void ObjectEntityProxy::set_has_selected_ancestor(bool has_selected_ancestor)
 
197
{
 
198
    class SetHasSelectedAncestor : public SceneAction
 
199
    {
 
200
    public:
 
201
        SetHasSelectedAncestor(EntityID id, bool has_selected_ancestor)
 
202
            : m_id(id), m_has_selected_ancestor(has_selected_ancestor) {}
 
203
 
 
204
        virtual void execute(SceneAction::Context &context)
 
205
        {
 
206
            context.scene().get_entity<ObjectEntity>(
 
207
                m_id)->set_has_selected_ancestor(m_has_selected_ancestor);
 
208
        }
 
209
 
 
210
    private:
 
211
        const EntityID m_id;
 
212
        const bool m_has_selected_ancestor;
 
213
    };
 
214
 
 
215
    dispatch(new SetHasSelectedAncestor(entity_id(), has_selected_ancestor));
 
216
}
 
217
 
 
218
 
 
219
void ObjectEntityProxy::set_parent(EntityID parent_id)
 
220
{
 
221
    class SetParent : public SceneAction
 
222
    {
 
223
    public:
 
224
        SetParent(EntityID id, EntityID parent_id)
 
225
            : m_id(id), m_parent_id(parent_id) {}
 
226
 
 
227
        virtual void execute(SceneAction::Context &context)
 
228
        {
 
229
            context.scene().get_entity<ObjectEntity>(m_id)->set_parent(
 
230
                context.scene().get_entity<ObjectEntity>(m_parent_id));
 
231
        }
 
232
 
 
233
    private:
 
234
        const EntityID m_id, m_parent_id;
 
235
    };
 
236
 
 
237
    dispatch(new SetParent(entity_id(), parent_id));
 
238
}
 
239
 
 
240
 
 
241
void ObjectEntityProxy::set_parent(const ObjectEntityProxy &e)
 
242
{
 
243
    set_parent(e.entity_id());
 
244
}