/
sky.h
285 lines (237 loc) · 7.33 KB
/
sky.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/** @file sky.h Sky sphere and 3D models.
*
* @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_SKY_H
#define DENG_CLIENT_RENDER_SKY_H
#include "Material"
#include <de/libcore.h>
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include <doomsday/defs/ded.h>
#include <QFlags>
#define MAX_SKY_LAYERS ( 2 )
#define MAX_SKY_MODELS ( 32 )
#define DEFAULT_SKY_HORIZON_OFFSET ( 0 )
#define DEFAULT_SKY_SPHERE_MATERIAL ( "Textures:SKY1" )
/**
* Logical sky.
*
* This version supports only two sky layers. (More would be a waste of resources?)
*
* @ingroup render
*/
class Sky
{
public:
/// Required layer is missing. @ingroup errors
DENG2_ERROR(MissingLayerError);
/**
* Multiple layers can be used for parallax effects.
*/
class Layer
{
public:
/// Notified whenever the layer material changes.
DENG2_DEFINE_AUDIENCE(MaterialChange, void skyLayerMaterialChanged(Layer &layer))
/// Notified whenever the active-state changes.
DENG2_DEFINE_AUDIENCE(ActiveChange, void skyLayerActiveChanged(Layer &layer))
/// Notified whenever the masked-state changes.
DENG2_DEFINE_AUDIENCE(MaskedChange, void skyLayerMaskedChanged(Layer &layer))
/// @todo make private:
enum Flag {
Active = 0x1, ///< Layer is active and will be rendered.
Masked = 0x2, ///< Mask the layer's texture.
DefaultFlags = 0
};
Q_DECLARE_FLAGS(Flags, Flag)
public:
/**
* Construct a new sky layer.
*/
Layer(Material *material = 0);
/**
* Returns @a true of the layer is currently active.
*
* @see setActive()
*/
bool isActive() const;
/**
* Change the 'active' state of the layer. The ActiveChange audience is
* notified whenever the 'active' state changes.
*
* @see isActive()
*/
Layer &setActive(bool yes);
inline void enable() { setActive(true); }
inline void disable() { setActive(false); }
/**
* Returns @c true if the layer's material will be masked.
*
* @see setMasked()
*/
bool isMasked() const;
/**
* Change the 'masked' state of the layer. The MaskedChange audience is
* notified whenever the 'masked' state changes.
*
* @see isMasked()
*/
Layer &setMasked(bool yes);
/**
* Returns the material currently assigned to the layer (if any).
*/
Material *material() const;
/**
* Change the material of the layer. The MaterialChange audience is notified
* whenever the material changes.
*/
Layer &setMaterial(Material *newMaterial);
/**
* Returns the horizontal offset for the layer.
*/
float offset() const;
/**
* Change the horizontal offset for the layer.
*
* @param newOffset New offset to apply.
*/
Layer &setOffset(float newOffset);
/**
* Returns the fadeout limit for the layer.
*/
float fadeoutLimit() const;
/**
* Change the fadeout limit for the layer.
*
* @param newLimit New fadeout limit to apply.
*/
Layer &setFadeoutLimit(float newLimit);
private:
Layer &setFlags(Flags flags, de::FlagOp operation);
Flags _flags;
Material *_material;
float _offset;
float _fadeoutLimit;
};
public:
Sky();
/**
* Reconfigure the sky, returning all values to their defaults.
*/
void configureDefault();
/**
* Reconfigure the sky according the specified @a definition if not @c NULL,
* otherwise, setup using suitable defaults.
*/
void configure(ded_sky_t *sky);
/**
* Animate the sky.
*/
void runTick();
#ifdef __CLIENT__
/**
* Cache all assets needed for visualizing the sky.
*/
void cacheDrawableAssets();
/**
* Render the sky.
*/
void draw();
#endif // __CLIENT__
/**
* Determines whether the specified sky layer @a index is valid.
*
* @see layer(), layerPtr()
*/
bool hasLayer(int index) const;
/**
* Lookup a sky layer by it's unique @a index.
*
* @see hasLayer()
*/
Layer &layer(int index);
/// @copydoc layer()
Layer const &layer(int index) const;
/**
* Returns a pointer to the referenced sky layer; otherwise @c 0.
*
* @see hasLayer(), layer()
*/
inline Layer *layerPtr(int index) { return hasLayer(index)? &layer(index) : 0; }
/**
* Returns the unique identifier of the sky's first active layer.
*
* @see Layer::isActive()
*/
int firstActiveLayer() const;
/**
* Returns the horizon offset for the sky.
*
* @see setHorizonOffset()
*/
float horizonOffset() const;
/**
* Change the horizon offset for the sky.
*
* @param newOffset New horizon offset to apply.
*
* @see horizonOffset()
*/
void setHorizonOffset(float newOffset);
/**
* Returns the height of the sky as a scale factor [0..1] (@c 1 covers the view).
*
* @see setHeight()
*/
float height() const;
/**
* Change the height scale factor for the sky.
*
* @param newHeight New height scale factor to apply (will be normalized).
*
* @see height()
*/
void setHeight(float newHeight);
/**
* Returns the ambient color of the sky. The ambient color is automatically
* calculated by averaging the color information in the configured layer
* material textures. Alternatively, this color can be overridden manually
* by calling @ref setAmbientColor().
*/
de::Vector3f const &ambientColor() const;
/**
* Override the automatically calculated ambient color.
*
* @param newColor New ambient color to apply (will be normalized).
*
* @see ambientColor()
*/
void setAmbientColor(de::Vector3f const &newColor);
public:
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();
private:
DENG2_PRIVATE(d)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Sky::Layer::Flags)
typedef Sky::Layer SkyLayer;
/// The One sky (never @c NULL).
extern Sky *theSky;
#endif // DENG_CLIENT_RENDER_SKY_H