Skip to content

Commit

Permalink
Refactor|Renderer|Sky: Introduced an animator abstraction for the sky
Browse files Browse the repository at this point in the history
Began splitting up the renderer's Sky class into subcomponents. The
first of which will be an animator for separation of these duties from
the GL drawable/rendering logic.
  • Loading branch information
danij-deng committed Aug 29, 2014
1 parent 219950d commit 4dcec2f
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 205 deletions.
87 changes: 79 additions & 8 deletions doomsday/client/include/render/sky.h
Expand Up @@ -22,13 +22,14 @@
#define DENG_CLIENT_RENDER_SKY_H

#include "Material"
#include <QFlags>
#include <de/libcore.h>
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include <doomsday/defs/ded.h>
#include <doomsday/defs/sky.h>
#include <QFlags>
#include "ModelDef"

#define MAX_SKY_LAYERS ( 2 )
#define MAX_SKY_MODELS ( 32 )
Expand All @@ -46,9 +47,15 @@
class Sky
{
public:
/// No animator is presently configured. @ingroup errors
DENG2_ERROR(MissingAnimatorError);

/// Required layer is missing. @ingroup errors
DENG2_ERROR(MissingLayerError);

/// Required model is missing. @ingroup errors
DENG2_ERROR(MissingModelError);

/**
* Multiple layers can be used for parallax effects.
*/
Expand Down Expand Up @@ -156,6 +163,48 @@ class Sky
float _fadeoutLimit;
};

struct ModelInfo
{
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(Sky &sky);
virtual ~Animator();

void setSky(Sky &sky);
Sky &sky() const;

/**
* Reconfigure according to the specified @a definition if not @c NULL,
* otherwise, reconfigure using the default values.
*/
void configure(defn::Sky *definition);

/**
* Advances the animation state.
*
* @param elapsed Duration of elapsed time.
*/
void advanceTime(timespan_t elapsed);

public:
DENG2_PRIVATE(d)
};

public:
Sky();

Expand All @@ -164,16 +213,14 @@ class Sky
*/
void configureDefault();

/**
* Reconfigure the sky according the specified @a definition if not @c NULL,
* otherwise, setup using suitable defaults.
*/
void configure(defn::Sky *sky);
bool hasAnimator() const;
void setAnimator(Animator *newAnimator);
Animator &animator();

/**
* Animate the sky.
* Models are set up according to the given @a skyDef.
*/
void runTick();
void setupModels(defn::Sky const &skyDef);

#ifdef __CLIENT__

Expand Down Expand Up @@ -220,6 +267,30 @@ class Sky
*/
int firstActiveLayer() 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()
*/
ModelInfo &model(int index);

/// @copydoc model()
ModelInfo const &model(int index) const;

/**
* Returns a pointer to the referenced sky model; otherwise @c 0.
*
* @see hasModel(), model()
*/
inline ModelInfo *modelPtr(int index) { return hasModel(index)? &model(index) : 0; }

/**
* Returns the horizon offset for the sky.
*
Expand Down

0 comments on commit 4dcec2f

Please sign in to comment.