mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 13:11:19 +01:00
* make file ref counted * migrate File to refcnt * add bindable artboard class to keep file reference * feat(unity): support rcp file and BindableArtboard class (#10228) * refactor(apple): use updated file bindable artboard apis (#10229) * update command queue to support bindable artboards * use bindable artboards on command queue * self manage view model instances in js runtime * change remaining viewModelInstanceRuntimes to rcp * refactor(apple): update view model instances to use rcp (#10298) * refactor(unity): support rcp ViewModelInstanceRuntime (#10309) * rebase fix * deprecate getArtboard in favor of getBindableArtboard * fix merge * remove unused lambda capture * fix rive binding * feat(Android): RCP File, VMI, and add bindable artboards (#10456) * refactor: C++ refactors - Import from long (incorrect) -> jlong - Header clang-tidy fix - Use reinterpret_cast instead of C-style cast - Break out some variables instead of long one liners - Use auto - Remove unused env and thisObj # Conflicts: # packages/runtime_android/kotlin/src/main/cpp/src/helpers/general.cpp * docs: Improve documentation on the File class * feat: Support bindable artboard type and RCP VMIs # Conflicts: # packages/runtime_android/kotlin/src/androidTest/java/app/rive/runtime/kotlin/core/RiveDataBindingTest.kt * feat: Support RCP files * refactor: Change from +1/-1 ref to just release * fix: Moved to the more appropriate null pointer for GetStringUTFChars * replace unref with release Co-authored-by: Adam <67035612+damzobridge@users.noreply.github.com> Co-authored-by: David Skuza <david@rive.app> Co-authored-by: Erik <erik@rive.app> Co-authored-by: hernan <hernan@rive.app>
159 lines
3.5 KiB
C++
159 lines
3.5 KiB
C++
#include "rive/animation/state_machine.hpp"
|
|
#include "rive/artboard.hpp"
|
|
#include "rive/importers/artboard_importer.hpp"
|
|
#include "rive/animation/state_machine_layer.hpp"
|
|
#include "rive/animation/state_machine_input.hpp"
|
|
#include "rive/animation/state_machine_listener.hpp"
|
|
#include "rive/data_bind/data_bind.hpp"
|
|
|
|
using namespace rive;
|
|
|
|
StateMachine::StateMachine() {}
|
|
|
|
StateMachine::~StateMachine() {}
|
|
|
|
StatusCode StateMachine::onAddedDirty(CoreContext* context)
|
|
{
|
|
StatusCode code;
|
|
for (auto& object : m_Inputs)
|
|
{
|
|
if ((code = object->onAddedDirty(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
for (auto& object : m_Layers)
|
|
{
|
|
if ((code = object->onAddedDirty(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
for (auto& object : m_Listeners)
|
|
{
|
|
if ((code = object->onAddedDirty(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
return StatusCode::Ok;
|
|
}
|
|
|
|
StatusCode StateMachine::onAddedClean(CoreContext* context)
|
|
{
|
|
StatusCode code;
|
|
for (auto& object : m_Inputs)
|
|
{
|
|
if ((code = object->onAddedClean(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
for (auto& object : m_Layers)
|
|
{
|
|
if ((code = object->onAddedClean(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
for (auto& object : m_Listeners)
|
|
{
|
|
if ((code = object->onAddedClean(context)) != StatusCode::Ok)
|
|
{
|
|
return code;
|
|
}
|
|
}
|
|
return StatusCode::Ok;
|
|
}
|
|
|
|
StatusCode StateMachine::import(ImportStack& importStack)
|
|
{
|
|
auto artboardImporter =
|
|
importStack.latest<ArtboardImporter>(ArtboardBase::typeKey);
|
|
if (artboardImporter == nullptr)
|
|
{
|
|
return StatusCode::MissingObject;
|
|
}
|
|
artboardImporter->addStateMachine(this);
|
|
return Super::import(importStack);
|
|
}
|
|
|
|
void StateMachine::addLayer(std::unique_ptr<StateMachineLayer> layer)
|
|
{
|
|
m_Layers.push_back(std::move(layer));
|
|
}
|
|
|
|
void StateMachine::addInput(std::unique_ptr<StateMachineInput> input)
|
|
{
|
|
m_Inputs.push_back(std::move(input));
|
|
}
|
|
|
|
void StateMachine::addListener(std::unique_ptr<StateMachineListener> listener)
|
|
{
|
|
m_Listeners.push_back(std::move(listener));
|
|
}
|
|
|
|
void StateMachine::addDataBind(std::unique_ptr<DataBind> dataBind)
|
|
{
|
|
m_dataBinds.push_back(std::move(dataBind));
|
|
}
|
|
|
|
const StateMachineInput* StateMachine::input(std::string name) const
|
|
{
|
|
for (auto& input : m_Inputs)
|
|
{
|
|
if (input->name() == name)
|
|
{
|
|
return input.get();
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const StateMachineInput* StateMachine::input(size_t index) const
|
|
{
|
|
if (index < m_Inputs.size())
|
|
{
|
|
return m_Inputs[index].get();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const StateMachineLayer* StateMachine::layer(std::string name) const
|
|
{
|
|
for (auto& layer : m_Layers)
|
|
{
|
|
if (layer->name() == name)
|
|
{
|
|
return layer.get();
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const StateMachineLayer* StateMachine::layer(size_t index) const
|
|
{
|
|
if (index < m_Layers.size())
|
|
{
|
|
return m_Layers[index].get();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const StateMachineListener* StateMachine::listener(size_t index) const
|
|
{
|
|
if (index < m_Listeners.size())
|
|
{
|
|
return m_Listeners[index].get();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const DataBind* StateMachine::dataBind(size_t index) const
|
|
{
|
|
if (index < m_dataBinds.size())
|
|
{
|
|
return m_dataBinds[index].get();
|
|
}
|
|
return nullptr;
|
|
} |