Skip to content

Commit

Permalink
Bump rive
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed May 10, 2024
1 parent 0530eb0 commit 0ee8ca4
Show file tree
Hide file tree
Showing 170 changed files with 10,869 additions and 9,436 deletions.
24 changes: 24 additions & 0 deletions thirdparty/rive/include/rive/animation/layer_state_flags.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _RIVE_LAYER_STATE_FLAGS_HPP_
#define _RIVE_LAYER_STATE_FLAGS_HPP_

#include <type_traits>

namespace rive
{
enum class LayerStateFlags : unsigned char
{
None = 0,

/// Whether the transition is disabled.
Random = 1 << 0,

};

inline constexpr LayerStateFlags operator&(LayerStateFlags lhs, LayerStateFlags rhs)
{
return static_cast<LayerStateFlags>(
static_cast<std::underlying_type<LayerStateFlags>::type>(lhs) &
static_cast<std::underlying_type<LayerStateFlags>::type>(rhs));
}
} // namespace rive
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class LinearAnimationInstance : public Scene
(directedSpeed() < 0 && m_time > m_animation->startSeconds());
}

bool keepGoing(float speedMultiplier) const
{
return this->loopValue() != static_cast<int>(rive::Loop::oneShot) ||
(directedSpeed() * speedMultiplier > 0 && m_time < m_animation->endSeconds()) ||
(directedSpeed() * speedMultiplier < 0 && m_time > m_animation->startSeconds());
}

float totalTime() const { return m_totalTime; }
float lastTotalTime() const { return m_lastTotalTime; }
float spilledTime() const { return m_spilledTime; }
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/rive/include/rive/animation/listener_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ListenerAction : public ListenerActionBase
{
public:
StatusCode import(ImportStack& importStack) override;
virtual void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const = 0;
virtual void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const = 0;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace rive
class ListenerAlignTarget : public ListenerAlignTargetBase
{
public:
void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const override;
void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ListenerBoolChange : public ListenerBoolChangeBase
public:
bool validateInputType(const StateMachineInput* input) const override;
bool validateNestedInputType(const NestedInput* input) const override;
void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const override;
void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace rive
class ListenerFireEvent : public ListenerFireEventBase
{
public:
void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const override;
void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ListenerNumberChange : public ListenerNumberChangeBase
public:
bool validateInputType(const StateMachineInput* input) const override;
bool validateNestedInputType(const NestedInput* input) const override;
void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const override;
void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ListenerTriggerChange : public ListenerTriggerChangeBase
public:
bool validateInputType(const StateMachineInput* input) const override;
bool validateNestedInputType(const NestedInput* input) const override;
void perform(StateMachineInstance* stateMachineInstance, Vec2D position) const override;
void perform(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NestedRemapAnimation : public NestedRemapAnimationBase
{
public:
void timeChanged() override;
void advance(float elapsedSeconds) override;
bool advance(float elapsedSeconds) override;
void initializeAnimation(ArtboardInstance*) override;
};
} // namespace rive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace rive
class NestedSimpleAnimation : public NestedSimpleAnimationBase
{
public:
void advance(float elapsedSeconds) override;
bool advance(float elapsedSeconds) override;
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NestedStateMachine : public NestedStateMachineBase
public:
NestedStateMachine();
~NestedStateMachine() override;
void advance(float elapsedSeconds) override;
bool advance(float elapsedSeconds) override;
void initializeAnimation(ArtboardInstance*) override;
StateMachineInstance* stateMachineInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <stddef.h>
#include <vector>
#include "rive/animation/linear_animation_instance.hpp"
#include "rive/animation/state_instance.hpp"
#include "rive/animation/state_transition.hpp"
#include "rive/core/field_types/core_callback_type.hpp"
#include "rive/hit_result.hpp"
#include "rive/listener_type.hpp"
Expand Down Expand Up @@ -43,6 +45,7 @@ class StateMachineInstance : public Scene
friend class SMIInput;
friend class KeyedProperty;
friend class HitComponent;
friend class StateMachineLayerInstance;

private:
/// Provide a hitListener if you want to process a down or an up for the pointer position
Expand All @@ -51,8 +54,11 @@ class StateMachineInstance : public Scene

template <typename SMType, typename InstType>
InstType* getNamedInput(const std::string& name) const;
void notifyEventListeners(std::vector<EventReport> events, NestedArtboard* source);
void notifyEventListeners(const std::vector<EventReport>& events, NestedArtboard* source);
void sortHitComponents();
double randomValue();
StateTransition* findRandomTransition(StateInstance* stateFromInstance, bool ignoreTriggers);
StateTransition* findAllowedTransition(StateInstance* stateFromInstance, bool ignoreTriggers);

public:
StateMachineInstance(const StateMachine* machine, ArtboardInstance* instance);
Expand Down Expand Up @@ -120,6 +126,7 @@ class StateMachineInstance : public Scene

/// Gets a reported event at an index < reportedEventCount().
const EventReport reportedEventAt(std::size_t index) const;
bool playsAudio() override { return true; }

private:
std::vector<EventReport> m_reportedEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class StateMachineListener : public StateMachineListenerBase
StatusCode onAddedClean(CoreContext* context) override;

const std::vector<uint32_t>& hitShapeIds() const { return m_HitShapesIds; }
void performChanges(StateMachineInstance* stateMachineInstance, Vec2D position) const;
void performChanges(StateMachineInstance* stateMachineInstance,
Vec2D position,
Vec2D previousPosition) const;
};
} // namespace rive

Expand Down
4 changes: 4 additions & 0 deletions thirdparty/rive/include/rive/animation/state_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class StateTransition : public StateTransitionBase
return static_cast<StateTransitionFlags>(flags());
}
LayerState* m_StateTo = nullptr;
uint32_t m_EvaluatedRandomWeight = 1;
CubicInterpolator* m_Interpolator = nullptr;

std::vector<TransitionCondition*> m_Conditions;
Expand All @@ -45,6 +46,9 @@ class StateTransition : public StateTransitionBase
const LayerState* stateTo() const { return m_StateTo; }
inline CubicInterpolator* interpolator() const { return m_Interpolator; }

inline uint32_t evaluatedRandomWeight() const { return m_EvaluatedRandomWeight; }
void evaluatedRandomWeight(uint32_t value) { m_EvaluatedRandomWeight = value; }

StatusCode onAddedDirty(CoreContext* context) override;
StatusCode onAddedClean(CoreContext* context) override;

Expand Down
10 changes: 8 additions & 2 deletions thirdparty/rive/include/rive/artboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class Artboard : public ArtboardBase, public CoreContext, public ShapePaintConta
void onDirty(ComponentDirt dirt) override;

bool advance(double elapsedSeconds);
bool hasChangedDrawOrderInLastUpdate() { return m_HasChangedDrawOrderInLastUpdate; };
Drawable* firstDrawable() { return m_FirstDrawable; };
bool hasChangedDrawOrderInLastUpdate() { return m_HasChangedDrawOrderInLastUpdate; }
Drawable* firstDrawable() { return m_FirstDrawable; }

enum class DrawOption
{
Expand All @@ -127,6 +127,7 @@ class Artboard : public ArtboardBase, public CoreContext, public ShapePaintConta
bool isTranslucent() const;
bool isTranslucent(const LinearAnimation*) const;
bool isTranslucent(const LinearAnimationInstance*) const;
bool hasAudio() const;

template <typename T = Component> T* find(const std::string& name)
{
Expand Down Expand Up @@ -260,10 +261,15 @@ class Artboard : public ArtboardBase, public CoreContext, public ShapePaintConta

StatusCode import(ImportStack& importStack) override;

float volume() const;
void volume(float value);

#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
rcp<AudioEngine> audioEngine() const;
void audioEngine(rcp<AudioEngine> audioEngine);
#endif
private:
float m_volume = 1.0f;
};

class ArtboardInstance : public Artboard
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/rive/include/rive/assets/audio_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _RIVE_AUDIO_ASSET_HPP_
#include "rive/generated/assets/audio_asset_base.hpp"
#include "rive/audio/audio_source.hpp"
#include "rive/audio/audio_engine.hpp"

namespace rive
{
Expand All @@ -13,17 +14,16 @@ class AudioAsset : public AudioAssetBase
bool decode(SimpleArray<uint8_t>&, Factory*) override;
std::string fileExtension() const override;

#ifdef WITH_RIVE_AUDIO
#ifdef TESTING
bool hasAudioSource() { return m_audioSource != nullptr; }
#endif

rcp<AudioSource> audioSource() { return m_audioSource; }
void audioSource(rcp<AudioSource> source) { m_audioSource = source; }
void stop(rcp<AudioEngine> engine);

private:
rcp<AudioSource> m_audioSource;
#endif
};
} // namespace rive

Expand Down
13 changes: 13 additions & 0 deletions thirdparty/rive/include/rive/assets/export_audio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _RIVE_EXPORT_AUDIO_HPP_
#define _RIVE_EXPORT_AUDIO_HPP_
#include "rive/generated/assets/export_audio_base.hpp"
#include <stdio.h>
namespace rive
{
class ExportAudio : public ExportAudioBase
{
public:
};
} // namespace rive

#endif
1 change: 1 addition & 0 deletions thirdparty/rive/include/rive/assets/file_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FileAsset : public FileAssetBase
}
}

std::string uniqueName() const;
std::string uniqueFilename() const;
};
} // namespace rive
Expand Down
37 changes: 31 additions & 6 deletions thirdparty/rive/include/rive/audio/audio_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
#include <vector>
#include <stdio.h>
#include <cstdint>
#include <mutex>

typedef struct ma_engine ma_engine;
typedef struct ma_sound ma_sound;
typedef struct ma_device ma_device;
typedef struct ma_node_base ma_node_base;

namespace rive
{
class AudioSound;
class AudioSource;

class LevelsNode;
class Artboard;
class AudioEngine : public RefCnt<AudioEngine>
{
friend class AudioSound;
friend class AudioSource;
friend class LevelsNode;

public:
static const uint32_t defaultNumChannels = 2;
Expand All @@ -39,26 +43,47 @@ class AudioEngine : public RefCnt<AudioEngine>
rcp<AudioSound> play(rcp<AudioSource> source,
uint64_t startTime,
uint64_t endTime,
uint64_t soundStartTime);
uint64_t soundStartTime,
Artboard* artboard = nullptr);

static rcp<AudioEngine> RuntimeEngine();
static rcp<AudioEngine> RuntimeEngine(bool makeWhenNecessary = true);

#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
bool readAudioFrames(float* frames, uint64_t numFrames, uint64_t* framesRead = nullptr);
bool sumAudioFrames(float* frames, uint64_t numFrames);
#endif

#ifdef WITH_RIVE_AUDIO_TOOLS
void initLevelMonitor();
void levels(Span<float> levels);
float level(uint32_t channel);
#endif

void start();
void stop();
void stop(Artboard* artboard);

#ifdef TESTING
size_t playingSoundCount();
#endif
private:
AudioEngine(ma_engine* engine);
ma_device* m_device;
ma_engine* m_engine;
std::mutex m_mutex;

std::vector<rcp<AudioSound>> m_completedSounds;
void soundCompleted(rcp<AudioSound> sound);
void unlinkSound(rcp<AudioSound> sound);

void completeSound(rcp<AudioSound> sound);
void purgeCompletedSounds();
std::vector<rcp<AudioSound>> m_completedSounds;
rcp<AudioSound> m_playingSoundsHead;
static void SoundCompleted(void* pUserData, ma_sound* pSound);

#ifdef WITH_RIVE_AUDIO_TOOLS
void measureLevels(const float* frames, uint32_t frameCount);
std::vector<float> m_levels;
LevelsNode* m_levelMonitor = nullptr;
#endif
#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
std::vector<float> m_readFrames;
#endif
Expand Down
2 changes: 0 additions & 2 deletions thirdparty/rive/include/rive/audio/audio_format.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef WITH_RIVE_AUDIO
#ifndef _RIVE_AUDIO_FORMAT_HPP_
#define _RIVE_AUDIO_FORMAT_HPP_
namespace rive
Expand All @@ -13,5 +12,4 @@ enum class AudioFormat : unsigned int
buffered
};
}
#endif
#endif
Loading

0 comments on commit 0ee8ca4

Please sign in to comment.