Skip to content

Commit

Permalink
Re-instantiate artboard when playing state machine (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg authored Nov 13, 2024
1 parent 7e422a3 commit a0b50c2
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion defold-rive/include/common/atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <rive/assets/file_asset.hpp>
#include <rive/file_asset_loader.hpp>

#include "renderer.h"
#include "defold/renderer.h"

namespace dmGameSystemDDF {
struct TextureSet;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion defold-rive/pluginsrc/rive_renderer_null.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <rive/refcnt.hpp>

#include <renderer.h>
#include <defold/renderer.h>

namespace dmRive
{
Expand Down
49 changes: 28 additions & 21 deletions defold-rive/src/comp_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
#include <common/tess_renderer.h>

// Defold Rive Renderer
#include "renderer.h"

#include <private/defold_graphics.h>
#include <defold/renderer.h>
#include <defold/defold_graphics.h>

// DMSDK
#include <dmsdk/script.h>
Expand Down Expand Up @@ -235,6 +234,26 @@ namespace dmRive
return GetComponentFromIndex(world, index);
}

static void InstantiateArtboard(RiveComponent* component)
{
dmRive::RiveSceneData* data = (dmRive::RiveSceneData*) component->m_Resource->m_Scene->m_Scene;

if (component->m_Resource->m_DDF->m_Artboard)
{
component->m_ArtboardInstance = data->m_File->artboardNamed(component->m_Resource->m_DDF->m_Artboard);

if (!component->m_ArtboardInstance)
{
dmLogWarning("Could not find artboard with name '%s'", component->m_Resource->m_DDF->m_Artboard);
}
}

if (!component->m_ArtboardInstance)
{
component->m_ArtboardInstance = data->m_File->artboardDefault();
}
}

dmGameObject::CreateResult CompRiveCreate(const dmGameObject::ComponentCreateParams& params)
{
RiveWorld* world = (RiveWorld*)params.m_World;
Expand Down Expand Up @@ -263,22 +282,8 @@ namespace dmRive
component->m_DoRender = 0;
component->m_RenderConstants = 0;

dmRive::RiveSceneData* data = (dmRive::RiveSceneData*) component->m_Resource->m_Scene->m_Scene;

if (component->m_Resource->m_DDF->m_Artboard)
{
component->m_ArtboardInstance = data->m_File->artboardNamed(component->m_Resource->m_DDF->m_Artboard);
InstantiateArtboard(component);

if (!component->m_ArtboardInstance)
{
dmLogWarning("Could not find artboard with name '%s'", component->m_Resource->m_DDF->m_Artboard);
}
}

if (!component->m_ArtboardInstance)
{
component->m_ArtboardInstance = data->m_File->artboardDefault();
}
component->m_ArtboardInstance->advance(0.0f);

if (component->m_Resource->m_CreateGoBones)
Expand Down Expand Up @@ -578,7 +583,7 @@ namespace dmRive
return dmGameObject::CREATE_RESULT_OK;
}

static bool GetSender(RiveComponent* component, dmMessage::URL* out_sender)
static bool GetSender(RiveComponent* component, dmMessage::URL* out_sender)
{
dmMessage::URL sender;
sender.m_Socket = dmGameObject::GetMessageSocket(dmGameObject::GetCollection(component->m_Instance));
Expand All @@ -603,7 +608,6 @@ namespace dmRive

component->m_AnimationInstance.reset();
component->m_StateMachineInstance.reset();

component->m_StateMachineInputs.SetSize(0);
}

Expand Down Expand Up @@ -1030,11 +1034,14 @@ namespace dmRive
CompRiveAnimationReset(component);
CompRiveClearCallback(component);

// For now, we need to create a new state machine instance when playing a state machine, because of nested artboards+state machine events
InstantiateArtboard(component);

component->m_Callback = callback_info;
component->m_CallbackId++;
component->m_AnimationInstance = nullptr;
component->m_StateMachineInstance = component->m_ArtboardInstance->stateMachineAt(state_machine_index);
component->m_AnimationPlaybackRate = playback_rate;
component->m_StateMachineInstance = component->m_ArtboardInstance->stateMachineAt(state_machine_index);

// update the list of current state machine inputs
uint32_t count = component->m_StateMachineInstance->inputCount();
Expand Down
2 changes: 2 additions & 0 deletions defold-rive/src/comp_rive.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace dmRive
std::unique_ptr<rive::LinearAnimationInstance> m_AnimationInstance;
std::unique_ptr<rive::StateMachineInstance> m_StateMachineInstance;

dmArray<std::unique_ptr<rive::StateMachineInstance>> m_AllSMSInstances;

dmGameObject::Playback m_AnimationPlayback;
float m_AnimationPlaybackRate;

Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/private/renderer_context_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <dmsdk/graphics/graphics_vulkan.h>

#include <private/defold_graphics.h>
#include <defold/defold_graphics.h>

#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/private/renderer_context_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <rive/renderer/gl/render_context_gl_impl.hpp>
#include <rive/renderer/gl/render_target_gl.hpp>

#include <private/defold_graphics.h>
#include <defold/defold_graphics.h>

#ifdef RIVE_DESKTOP_GL
#define GLFW_INCLUDE_NONE
Expand Down
10 changes: 5 additions & 5 deletions defold-rive/src/private/renderer_private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include <rive/renderer/rive_render_image.hpp>

#include <private/defold_graphics.h>
#include <private/defold_render.h>
#include <private/shaders/rivemodel_blit.vpc.gen.h>
#include <private/shaders/rivemodel_blit.fpc.gen.h>
#include <defold/defold_graphics.h>
#include <defold/defold_render.h>
#include <defold/shaders/rivemodel_blit.vpc.gen.h>
#include <defold/shaders/rivemodel_blit.fpc.gen.h>

#include <common/vertices.h>
#include <renderer.h>
#include <defold/renderer.h>

#include <assert.h>

Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/private/renderer_wbgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <dmsdk/graphics/graphics_vulkan.h>

#include <private/defold_graphics.h>
#include <defold/defold_graphics.h>

namespace dmRive
{
Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/res_rive_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdint.h>
#include <dmsdk/dlib/array.h>
#include <dmsdk/dlib/hash.h>
#include "renderer.h"
#include "defold/renderer.h"

namespace rive
{
Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/res_rive_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <dmsdk/dlib/log.h>
#include <dmsdk/resource/resource.h>

#include "renderer.h"
#include "defold/renderer.h"

namespace dmRive
{
Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/res_rive_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <dmsdk/gamesys/resources/res_textureset.h>

#include "renderer.h"
#include "defold/renderer.h"

#include "rive_ddf.h" // generated from the rive_ddf.proto

Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/script_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "comp_rive.h"
#include "rive_ddf.h"

#include <private/defold_graphics.h>
#include <defold/defold_graphics.h>

namespace dmRive
{
Expand Down

0 comments on commit a0b50c2

Please sign in to comment.