/
skydrawable.h
137 lines (115 loc) · 3.42 KB
/
skydrawable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** @file skydrawable.h Drawable specialized for the sky.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef DENG_CLIENT_RENDER_SKYDRAWABLE_H
#define DENG_CLIENT_RENDER_SKYDRAWABLE_H
#include <de/libcore.h>
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include <doomsday/defs/ded.h>
#include <doomsday/defs/sky.h>
#include "MaterialVariantSpec"
class Sky;
#define MAX_SKY_MODELS ( 32 )
/**
* Sky drawable.
*
* This version supports only two sky layers. (More would be a waste of resources?)
*
* @ingroup render
*/
class SkyDrawable
{
public:
/// Required model is missing. @ingroup errors
DENG2_ERROR(MissingModelError);
struct ModelData
{
de::Record const *def; // Sky model def
ModelDef *model;
int frame;
int timer;
int maxTimer;
float yaw;
};
/**
* Sky sphere and model animator.
*
* Animates a sky according to the configured definition.
*/
class Animator
{
public:
Animator();
Animator(SkyDrawable &sky);
virtual ~Animator();
void setSky(SkyDrawable *sky);
SkyDrawable &sky() const;
/**
* Advances the animation state.
*
* @param elapsed Duration of elapsed time.
*/
void advanceTime(timespan_t elapsed);
public:
DENG2_PRIVATE(d)
};
public:
SkyDrawable();
/**
* Models are set up according to the given @a skyDef.
*/
void setupModels(defn::Sky const &skyDef);
/**
* Cache all assets needed for visualizing the sky.
*/
void cacheDrawableAssets(Sky const *sky = 0);
/**
* Render the sky.
*/
void draw(Sky const *sky = 0) const;
/**
* Determines whether the specified sky model @a index is valid.
*
* @see model(), modelPtr()
*/
bool hasModel(int index) const;
/**
* Lookup a sky model by it's unique @a index.
*
* @see hasModel()
*/
ModelData &model(int index);
/// @copydoc model()
ModelData const &model(int index) const;
/**
* Returns a pointer to the referenced sky model; otherwise @c 0.
*
* @see hasModel(), model()
*/
inline ModelData *modelPtr(int index) { return hasModel(index)? &model(index) : 0; }
public:
static de::MaterialVariantSpec const &layerMaterialSpec(bool masked);
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();
private:
DENG2_PRIVATE(d)
};
#endif // DENG_CLIENT_RENDER_SKYDRAWABLE_H