Skip to content

Commit

Permalink
Scripting|Model Renderer: Added bindings for StateAnimator
Browse files Browse the repository at this point in the history
Currently only has a method for listing currently playing sequences.
  • Loading branch information
skyjake committed Oct 30, 2015
1 parent 1885e89 commit da2c7c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
36 changes: 33 additions & 3 deletions doomsday/apps/client/src/render/modelrenderer.cpp
Expand Up @@ -616,7 +616,7 @@ DENG2_PIMPL(ModelRenderer)
void draw(Params const &p)
{
uTex = static_cast<AtlasTexture const *>(p.model->textures->atlas());

p.model->draw(&p.animator->appearance(), p.animator);
}
};
Expand Down Expand Up @@ -739,8 +739,38 @@ int ModelRenderer::identifierFromText(String const &text,
return id;
}

//---------------------------------------------------------------------------------------

static render::StateAnimator &animatorInstance(Context &ctx)
{
if(auto *self = ctx.selfInstance().get(Record::VAR_NATIVE_SELF).maybeAs<NativeValue>())
{
if(auto *obj = self->nativeObject<render::StateAnimator>())
{
return *obj;
}
}
throw Value::IllegalError("ModelRenderer::animatorInstance",
"No StateAnimator instance available");
}

static Value *Function_StateAnimator_PlayingSequences(Context &ctx, Function::ArgumentValues const &)
{
render::StateAnimator &anim = animatorInstance(ctx);
std::unique_ptr<ArrayValue> playing(new ArrayValue);
for(int i = 0; i < anim.count(); ++i)
{
playing->add(new NumberValue(anim.at(i).animId));
}
return playing.release();
}

void ModelRenderer::initBindings(Binder &binder, Record &module) // static
{
DENG2_UNUSED(binder);
DENG2_UNUSED(module);
// StateAnimator
{
Record &anim = module.addSubrecord("StateAnimator");
binder.init(anim)
<< DENG2_FUNC_NOARG(StateAnimator_PlayingSequences, "playingSequences");
}
}
3 changes: 3 additions & 0 deletions doomsday/apps/client/src/render/stateanimator.cpp
Expand Up @@ -210,6 +210,9 @@ DENG2_PIMPL(StateAnimator)

Instance(Public *i, DotPath const &id) : Base(i)
{
names.add(Record::VAR_NATIVE_SELF).set(new NativeValue(&self)).setReadOnly();
names.addSuperRecord(ScriptSystem::builtInClass(QStringLiteral("Render"),
QStringLiteral("StateAnimator")));
names.addText(VAR_ID, id).setReadOnly();
names.add(VAR_ASSET).set(new RecordValue(App::asset(id).accessedRecord())).setReadOnly();

Expand Down
3 changes: 2 additions & 1 deletion doomsday/sdk/libgui/include/de/graphics/modeldrawable.h
Expand Up @@ -20,6 +20,7 @@
#define LIBGUI_MODELDRAWABLE_H

#include <de/Asset>
#include <de/Deletable>
#include <de/File>
#include <de/GLProgram>
#include <de/GLState>
Expand Down Expand Up @@ -108,7 +109,7 @@ class LIBGUI_PUBLIC ModelDrawable : public AssetGroup
*
* @ingroup gl
*/
class LIBGUI_PUBLIC Animator
class LIBGUI_PUBLIC Animator : public Deletable
{
public:
/**
Expand Down

0 comments on commit da2c7c0

Please sign in to comment.