Skip to content

Commit

Permalink
Refactor|Client: Renamed MobjAnimator to StateAnimator
Browse files Browse the repository at this point in the history
This animator is not exclusive to mobjs, but it is oriented around
state triggers.
  • Loading branch information
skyjake committed Oct 14, 2015
1 parent 36d337b commit 888c1bb
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
4 changes: 2 additions & 2 deletions doomsday/apps/client/include/render/playerweaponanimator.h
Expand Up @@ -20,7 +20,7 @@
#define CLIENT_RENDER_PLAYERWEAPONANIMATOR_H

#include <de/ModelDrawable>
#include "mobjanimator.h"
#include "stateanimator.h"

class ClientPlayer;
struct state_s;
Expand All @@ -46,7 +46,7 @@ class PlayerWeaponAnimator

de::ModelDrawable const *model() const;

MobjAnimator &animator();
StateAnimator &animator();

void setupVisPSprite(vispsprite_t &spr) const;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/include/render/rend_model.h
Expand Up @@ -29,7 +29,7 @@
#include <de/ModelDrawable>

class TextureVariantSpec;
class MobjAnimator;
class StateAnimator;
struct vissprite_t;

/// Absolute maximum number of vertices per submodel supported by this module.
Expand Down Expand Up @@ -66,7 +66,7 @@ struct drawmodel2params_t
struct mobj_s const *object;
de::ModelDrawable const *model;
ModelRenderer::AuxiliaryData const *auxData;
MobjAnimator const *animator;
StateAnimator const *animator;
};

DENG_EXTERN_C de::dbyte useModels;
Expand Down
@@ -1,4 +1,4 @@
/** @file mobjanimator.h
/** @file stateanimator.h
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,26 +16,26 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_RENDER_MOBJANIMATOR_H
#define DENG_CLIENT_RENDER_MOBJANIMATOR_H
#ifndef DENG_CLIENT_RENDER_STATEANIMATOR_H
#define DENG_CLIENT_RENDER_STATEANIMATOR_H

#include "render/modelrenderer.h"
#include <de/ModelDrawable>
#include <de/GLProgram>

/**
* Mobj-specific model animator.
* State-based object animator for `ModelDrawable`s.
*
* The state and movement of the mobj determine which animation sequences are started.
* Also used for psprites, since they are pretty much light-weight mobjs.
* Used for both mobjs and psprites. The state and movement of the object
* determine which animation sequences are started.
*/
class MobjAnimator : public de::ModelDrawable::Animator
class StateAnimator : public de::ModelDrawable::Animator
{
public:
DENG2_ERROR(DefinitionError);

public:
MobjAnimator(de::DotPath const &id, de::ModelDrawable const &model);
StateAnimator(de::DotPath const &id, de::ModelDrawable const &model);

/**
* Sets the namespace of the animator's owner. Available as "self" in animation
Expand Down Expand Up @@ -76,4 +76,4 @@ class MobjAnimator : public de::ModelDrawable::Animator
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_RENDER_MOBJANIMATOR_H
#endif // DENG_CLIENT_RENDER_STATEANIMATOR_H
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/render/vissprite.h
Expand Up @@ -194,7 +194,7 @@ struct vispsprite_t
struct vispsprite_model2_s {
de::ModelDrawable const *model;
ModelAuxiliaryData const *auxData;
MobjAnimator const *animator;
StateAnimator const *animator;
} model2;
} data;
};
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/include/world/clientmobjthinkerdata.h
Expand Up @@ -52,7 +52,7 @@
//#define CLM_MAGIC1 0xdecafed1
//#define CLM_MAGIC2 0xcafedeb8

class MobjAnimator;
class StateAnimator;

/**
* Private client-side data for mobjs. This includes any per-object state for rendering
Expand Down Expand Up @@ -104,9 +104,9 @@ class ClientMobjThinkerData : public MobjThinkerData
*
* @return Animation state, or @c NULL if not drawn as a model.
*/
MobjAnimator *animator();
StateAnimator *animator();

MobjAnimator const *animator() const;
StateAnimator const *animator() const;

de::Matrix4f const &modelTransformation() const;

Expand Down
11 changes: 6 additions & 5 deletions doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -17,7 +17,7 @@
*/

#include "render/modelrenderer.h"
#include "render/mobjanimator.h"
#include "render/stateanimator.h"
#include "render/rend_main.h"
#include "render/vissprite.h"
#include "gl/gl_main.h"
Expand All @@ -29,6 +29,7 @@
#include <de/App>
#include <de/ModelBank>
#include <de/ScriptedInfo>
#include <de/NativeValue>

#include <QHash>

Expand Down Expand Up @@ -569,17 +570,17 @@ DENG2_PIMPL(ModelRenderer)
[&p] (GLProgram &program, ModelDrawable::ProgramBinding binding)
{
p.animator->bindUniforms(program,
binding == ModelDrawable::AboutToBind? MobjAnimator::Bind :
MobjAnimator::Unbind);
binding == ModelDrawable::AboutToBind? StateAnimator::Bind :
StateAnimator::Unbind);
},

// Callback for each rendering pass:
[&p] (ModelDrawable::Pass const &pass, ModelDrawable::PassState state)
{
p.animator->bindPassUniforms(*p.model->currentProgram(),
pass.name,
state == ModelDrawable::PassBegun? MobjAnimator::Bind :
MobjAnimator::Unbind);
state == ModelDrawable::PassBegun? StateAnimator::Bind :
StateAnimator::Unbind);
}
);
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/src/render/playerweaponanimator.cpp
Expand Up @@ -17,7 +17,7 @@
*/

#include "render/playerweaponanimator.h"
#include "render/mobjanimator.h"
#include "render/stateanimator.h"
#include "render/vissprite.h"
#include "clientplayer.h"
#include "clientapp.h"
Expand All @@ -31,7 +31,7 @@ DENG2_PIMPL_NOREF(PlayerWeaponAnimator)
, DENG2_OBSERVES(Asset, Deletion)
{
ClientPlayer *player;
std::unique_ptr<MobjAnimator> animator;
std::unique_ptr<StateAnimator> animator;
ModelRenderer::AuxiliaryData const *modelAuxData = nullptr;

Instance(ClientPlayer *plr)
Expand All @@ -52,7 +52,7 @@ DENG2_PIMPL_NOREF(PlayerWeaponAnimator)
auto loaded = modelBank().modelAndData<ModelRenderer::AuxiliaryData>(identifier);
ModelDrawable &model = *loaded.first;
model.audienceForDeletion() += this;
animator.reset(new MobjAnimator(identifier, model));
animator.reset(new StateAnimator(identifier, model));
animator->setOwnerNamespace(player->info());

// The basic transformation of the model.
Expand Down Expand Up @@ -94,7 +94,7 @@ void PlayerWeaponAnimator::stateChanged(state_s const *state)
}
}

MobjAnimator &PlayerWeaponAnimator::animator()
StateAnimator &PlayerWeaponAnimator::animator()
{
DENG2_ASSERT(hasModel());
return *d->animator;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/render/r_things.cpp
Expand Up @@ -41,7 +41,7 @@

#include "render/r_main.h"
#include "render/angleclipper.h"
#include "render/mobjanimator.h"
#include "render/stateanimator.h"
#include "render/rend_halo.h"
#include "render/vissprite.h"

Expand Down Expand Up @@ -191,7 +191,7 @@ void R_ProjectSprite(mobj_t &mob)
ModelDef *mf = nullptr, *nextmf = nullptr;
dfloat interp = 0;

MobjAnimator const *animator = nullptr; // GL2 model present?
StateAnimator const *animator = nullptr; // GL2 model present?

if(useModels)
{
Expand Down
@@ -1,4 +1,4 @@
/** @file mobjanimator.cpp
/** @file stateanimator.cpp
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,7 +16,7 @@
* http://www.gnu.org/licenses</small>
*/

#include "render/mobjanimator.h"
#include "render/stateanimator.h"
#include "render/rendersystem.h"
#include "clientapp.h"
#include "dd_loop.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ static String const PASS_GLOBAL("");

static int const ANIM_DEFAULT_PRIORITY = 1;

DENG2_PIMPL(MobjAnimator)
DENG2_PIMPL(StateAnimator)
{
/**
* Specialized animation sequence state for a running animation.
Expand Down Expand Up @@ -251,7 +251,7 @@ DENG2_PIMPL(MobjAnimator)
switch(array->size())
{
default:
throw DefinitionError("MobjAnimator::initVariables",
throw DefinitionError("StateAnimator::initVariables",
QString("%1: Invalid initial value size (%2) for render.variable")
.arg(valueDef.gets(ScriptedInfo::VAR_SOURCE))
.arg(array->size()));
Expand Down Expand Up @@ -349,17 +349,17 @@ DENG2_PIMPL(MobjAnimator)
}
};

MobjAnimator::MobjAnimator(DotPath const &id, ModelDrawable const &model)
StateAnimator::StateAnimator(DotPath const &id, ModelDrawable const &model)
: ModelDrawable::Animator(model, Instance::Sequence::make)
, d(new Instance(this, id))
{}

void MobjAnimator::setOwnerNamespace(Record &names)
void StateAnimator::setOwnerNamespace(Record &names)
{
d->names.add(VAR_SELF).set(new RecordValue(names));
}

void MobjAnimator::triggerByState(String const &stateName)
void StateAnimator::triggerByState(String const &stateName)
{
using Sequence = Instance::Sequence;

Expand All @@ -370,7 +370,7 @@ void MobjAnimator::triggerByState(String const &stateName)
auto found = stateAnims->constFind(stateName);
if(found == stateAnims->constEnd()) return;

LOG_AS("MobjAnimator");
LOG_AS("StateAnimator");
LOGDEV_GL_XVERBOSE("triggerByState: ") << stateName;

d->currentStateName = stateName;
Expand Down Expand Up @@ -442,7 +442,7 @@ void MobjAnimator::triggerByState(String const &stateName)
}
}

void MobjAnimator::advanceTime(TimeDelta const &elapsed)
void StateAnimator::advanceTime(TimeDelta const &elapsed)
{
ModelDrawable::Animator::advanceTime(elapsed);

Expand Down Expand Up @@ -516,19 +516,19 @@ void MobjAnimator::advanceTime(TimeDelta const &elapsed)
}
}

ddouble MobjAnimator::currentTime(int index) const
ddouble StateAnimator::currentTime(int index) const
{
// Mobjs think on sharp ticks only, however we need to ensure time advances on
// every frame for smooth animation.
return ModelDrawable::Animator::currentTime(index); // + frameTimePos;
}

void MobjAnimator::bindUniforms(GLProgram &program, BindOperation operation) const
void StateAnimator::bindUniforms(GLProgram &program, BindOperation operation) const
{
bindPassUniforms(program, PASS_GLOBAL, operation);
}

void MobjAnimator::bindPassUniforms(GLProgram &program, String const &passName,
void StateAnimator::bindPassUniforms(GLProgram &program, String const &passName,
BindOperation operation) const
{
auto const vars = d->passVars.constFind(passName);
Expand Down
10 changes: 5 additions & 5 deletions doomsday/apps/client/src/world/clientmobjthinkerdata.cpp
Expand Up @@ -24,7 +24,7 @@
#include "clientapp.h"
#include "dd_loop.h"
#include "render/modelrenderer.h"
#include "render/mobjanimator.h"
#include "render/stateanimator.h"
#include "world/generator.h"

using namespace de;
Expand All @@ -47,7 +47,7 @@ DENG2_PIMPL(ClientMobjThinkerData)
{
Flags flags;
std::unique_ptr<RemoteSync> sync;
std::unique_ptr<MobjAnimator> animator;
std::unique_ptr<StateAnimator> animator;
ModelRenderer::AuxiliaryData const *modelAuxData = nullptr;
Matrix4f modelMatrix;

Expand Down Expand Up @@ -110,7 +110,7 @@ DENG2_PIMPL(ClientMobjThinkerData)
auto loaded = modelBank().modelAndData<ModelRenderer::AuxiliaryData>(modelId());
ModelDrawable &model = *loaded.first;
model.audienceForDeletion() += this;
animator.reset(new MobjAnimator(modelId(), model));
animator.reset(new StateAnimator(modelId(), model));
animator->setOwnerNamespace(self.info());

modelAuxData = loaded.second;
Expand Down Expand Up @@ -227,12 +227,12 @@ ClientMobjThinkerData::RemoteSync &ClientMobjThinkerData::remoteSync()
return *d->sync;
}

MobjAnimator *ClientMobjThinkerData::animator()
StateAnimator *ClientMobjThinkerData::animator()
{
return d->animator.get();
}

MobjAnimator const *ClientMobjThinkerData::animator() const
StateAnimator const *ClientMobjThinkerData::animator() const
{
return d->animator.get();
}
Expand Down

0 comments on commit 888c1bb

Please sign in to comment.