mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
feature: making rive::File rcp (#10439) 213f07ec13
* feature: making rive::File rcp * fixes * fix: recorder Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
c681049169c307c8c5538c2cdcb7fe1e4ff43bba
|
||||
213f07ec13feddad7b9467d6da4d278a8adcc8cb
|
||||
|
||||
@@ -183,7 +183,7 @@ private:
|
||||
m_artboardDependencies;
|
||||
|
||||
// Handle Maps
|
||||
std::unordered_map<FileHandle, std::unique_ptr<File>> m_files;
|
||||
std::unordered_map<FileHandle, rcp<File>> m_files;
|
||||
std::unordered_map<FontHandle, rcp<Font>> m_fonts;
|
||||
std::unordered_map<RenderImageHandle, rcp<RenderImage>> m_images;
|
||||
std::unordered_map<AudioSourceHandle, rcp<AudioSource>> m_audioSources;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "rive/viewmodel/viewmodel_instance_viewmodel.hpp"
|
||||
#include "rive/viewmodel/viewmodel_instance_list_item.hpp"
|
||||
#include "rive/animation/keyframe_interpolator.hpp"
|
||||
#include "rive/refcnt.hpp"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
@@ -43,7 +44,7 @@ enum class ImportResult
|
||||
///
|
||||
/// A Rive file.
|
||||
///
|
||||
class File
|
||||
class File : public RefCnt<File>
|
||||
{
|
||||
public:
|
||||
/// Major version number supported by the runtime.
|
||||
@@ -63,18 +64,18 @@ public:
|
||||
/// @param assetLoader is an optional helper to load assets which
|
||||
/// cannot be found in-band.
|
||||
/// @returns a pointer to the file, or null on failure.
|
||||
static std::unique_ptr<File> import(Span<const uint8_t> data,
|
||||
Factory* factory,
|
||||
ImportResult* result = nullptr,
|
||||
FileAssetLoader* assetLoader = nullptr)
|
||||
static rcp<File> import(Span<const uint8_t> data,
|
||||
Factory* factory,
|
||||
ImportResult* result = nullptr,
|
||||
FileAssetLoader* assetLoader = nullptr)
|
||||
{
|
||||
return import(data, factory, result, ref_rcp(assetLoader));
|
||||
}
|
||||
|
||||
static std::unique_ptr<File> import(Span<const uint8_t> data,
|
||||
Factory*,
|
||||
ImportResult* result,
|
||||
rcp<FileAssetLoader> assetLoader);
|
||||
static rcp<File> import(Span<const uint8_t> data,
|
||||
Factory*,
|
||||
ImportResult* result,
|
||||
rcp<FileAssetLoader> assetLoader);
|
||||
|
||||
/// @returns the file's backboard. All files have exactly one backboard.
|
||||
Backboard* backboard() const { return m_backboard; }
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
#include "rive/importers/import_stack.hpp"
|
||||
#include "rive/animation/keyframe_interpolator.hpp"
|
||||
#include "rive/refcnt.hpp"
|
||||
#include "rive/file.hpp"
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace rive
|
||||
{
|
||||
class Artboard;
|
||||
class File;
|
||||
class NestedArtboard;
|
||||
class Backboard;
|
||||
class FileAsset;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include "rive/advancing_component.hpp"
|
||||
#include "rive/resetting_component.hpp"
|
||||
#include "rive/viewmodel/viewmodel_instance_artboard.hpp"
|
||||
#include <stdio.h>
|
||||
#include "rive/refcnt.hpp"
|
||||
#include "rive/file.hpp"
|
||||
|
||||
namespace rive
|
||||
{
|
||||
@@ -20,7 +21,6 @@ class NestedAnimation;
|
||||
class NestedInput;
|
||||
class NestedStateMachine;
|
||||
class StateMachineInstance;
|
||||
class File;
|
||||
class NestedArtboard : public NestedArtboardBase,
|
||||
public AdvancingComponent,
|
||||
public ResettingComponent,
|
||||
|
||||
@@ -85,7 +85,7 @@ static int horzRepeat = 0;
|
||||
static int upRepeat = 0;
|
||||
static int downRepeat = 0;
|
||||
|
||||
std::unique_ptr<File> rivFile;
|
||||
rcp<File> rivFile;
|
||||
std::vector<std::unique_ptr<Artboard>> artboards;
|
||||
std::vector<std::unique_ptr<Scene>> scenes;
|
||||
std::vector<rive::rcp<rive::ViewModelInstance>> viewModelInstances;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "rive/artboard.hpp"
|
||||
#include "rive/file.hpp"
|
||||
#include "rive/refcnt.hpp"
|
||||
#include "rive/layout.hpp"
|
||||
#include "rive/animation/state_machine_instance.hpp"
|
||||
|
||||
@@ -41,7 +42,7 @@ static WGPUSurface surface;
|
||||
static WGPUTextureFormat format = WGPUTextureFormat_Undefined;
|
||||
static wgpu::Queue queue;
|
||||
|
||||
static std::unique_ptr<File> rivFile;
|
||||
static rcp<File> rivFile;
|
||||
static std::unique_ptr<ArtboardInstance> artboard;
|
||||
static std::unique_ptr<Scene> scene;
|
||||
|
||||
@@ -318,8 +319,7 @@ int main(int argc, const char** argv)
|
||||
std::ifstream rivStream(filename, std::ios::binary);
|
||||
std::vector<uint8_t> rivBytes(std::istreambuf_iterator<char>(rivStream),
|
||||
{});
|
||||
std::unique_ptr<File> rivFile =
|
||||
File::import(rivBytes, fiddleContextDawn->factory());
|
||||
rcp<File> rivFile = File::import(rivBytes, fiddleContextDawn->factory());
|
||||
std::unique_ptr<ArtboardInstance> artboard = rivFile->artboardDefault();
|
||||
std::unique_ptr<Scene> scene = artboard->defaultScene();
|
||||
scene->advanceAndApply(0);
|
||||
|
||||
@@ -138,7 +138,7 @@ static void dump(JSoner& js, rive::File* file)
|
||||
js.pop();
|
||||
}
|
||||
|
||||
static std::unique_ptr<rive::File> open_file(const char name[])
|
||||
static rcp<rive::File> open_file(const char name[])
|
||||
{
|
||||
FILE* f = fopen(name, "rb");
|
||||
if (!f)
|
||||
|
||||
@@ -512,11 +512,10 @@ bool CommandServer::processCommands()
|
||||
commandStream >> requestId;
|
||||
m_commandQueue->m_byteVectors >> rivBytes;
|
||||
lock.unlock();
|
||||
std::unique_ptr<rive::File> file =
|
||||
rive::File::import(rivBytes,
|
||||
m_factory,
|
||||
nullptr,
|
||||
m_fileAssetLoader);
|
||||
rcp<rive::File> file = rive::File::import(rivBytes,
|
||||
m_factory,
|
||||
nullptr,
|
||||
m_fileAssetLoader);
|
||||
if (file != nullptr)
|
||||
{
|
||||
m_fileDependencies[handle] = {};
|
||||
|
||||
10
src/file.cpp
10
src/file.cpp
@@ -203,10 +203,10 @@ File::~File()
|
||||
delete m_backboard;
|
||||
}
|
||||
|
||||
std::unique_ptr<File> File::import(Span<const uint8_t> bytes,
|
||||
Factory* factory,
|
||||
ImportResult* result,
|
||||
rcp<FileAssetLoader> assetLoader)
|
||||
rcp<File> File::import(Span<const uint8_t> bytes,
|
||||
Factory* factory,
|
||||
ImportResult* result,
|
||||
rcp<FileAssetLoader> assetLoader)
|
||||
{
|
||||
BinaryReader reader(bytes);
|
||||
RuntimeHeader header;
|
||||
@@ -233,7 +233,7 @@ std::unique_ptr<File> File::import(Span<const uint8_t> bytes,
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
auto file = rivestd::make_unique<File>(factory, std::move(assetLoader));
|
||||
auto file = make_rcp<File>(factory, std::move(assetLoader));
|
||||
|
||||
auto readResult = file->read(reader, header);
|
||||
if (result)
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
{
|
||||
// Sniff paths out of a .riv file.
|
||||
SniffPathsRenderer sniffer(&m_pathPaints, allStrokes, allRoundJoin);
|
||||
std::unique_ptr<File> rivFile =
|
||||
rcp<File> rivFile =
|
||||
File::import(assets::paper_riv(), m_nullContext.get());
|
||||
std::unique_ptr<ArtboardInstance> artboard = rivFile->artboardDefault();
|
||||
std::unique_ptr<Scene> scene = artboard->defaultScene();
|
||||
@@ -262,7 +262,7 @@ public:
|
||||
/*allStrokes=*/false,
|
||||
/*allRoundJoin=*/false,
|
||||
/*forcedFeather=*/100);
|
||||
std::unique_ptr<File> rivFile = File::import(riv, m_nullContext.get());
|
||||
rcp<File> rivFile = File::import(riv, m_nullContext.get());
|
||||
std::unique_ptr<ArtboardInstance> artboard = rivFile->artboardDefault();
|
||||
std::unique_ptr<Scene> scene = artboard->defaultScene();
|
||||
scene->advanceAndApply(0);
|
||||
|
||||
@@ -76,8 +76,8 @@ static void log(const char msg[], const char arg[] = nullptr)
|
||||
fprintf(stderr, "%s\n", err.c_str());
|
||||
}
|
||||
|
||||
std::unique_ptr<rive::File> RiveMgr::loadFile(const char filename[],
|
||||
rive::Factory* factory)
|
||||
rive::rcp<rive::File> RiveMgr::loadFile(const char filename[],
|
||||
rive::Factory* factory)
|
||||
{
|
||||
AutoClose afc(fopen(filename, "rb"));
|
||||
FILE* fp = afc.m_File;
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
#define _RIVE_MGR_HPP_
|
||||
|
||||
#include "rive/scene.hpp"
|
||||
#include "rive/file.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace rive
|
||||
{
|
||||
class Factory;
|
||||
class File;
|
||||
class ArtboardInstance;
|
||||
} // namespace rive
|
||||
|
||||
class RiveMgr
|
||||
{
|
||||
rive::Factory* m_Factory;
|
||||
std::unique_ptr<rive::File> m_File;
|
||||
rive::rcp<rive::File> m_File;
|
||||
std::unique_ptr<rive::ArtboardInstance> m_Artboard;
|
||||
std::unique_ptr<rive::Scene> m_Scene;
|
||||
|
||||
@@ -33,8 +33,8 @@ public:
|
||||
|
||||
rive::Scene* scene() const { return m_Scene.get(); }
|
||||
|
||||
static std::unique_ptr<rive::File> loadFile(const char filename[],
|
||||
rive::Factory*);
|
||||
static rive::rcp<rive::File> loadFile(const char filename[],
|
||||
rive::Factory*);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
rive::Scene* stateMachine() const { return m_scene.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<rive::File> m_file;
|
||||
rive::rcp<rive::File> m_file;
|
||||
std::unique_ptr<rive::ArtboardInstance> m_artboard;
|
||||
std::unique_ptr<rive::Scene> m_scene;
|
||||
rive::rcp<rive::ViewModelInstance> m_viewModelInstance;
|
||||
|
||||
@@ -23,7 +23,7 @@ static inline std::vector<uint8_t> ReadFile(const char path[])
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static inline std::unique_ptr<rive::File> ReadRiveFile(
|
||||
static inline rive::rcp<rive::File> ReadRiveFile(
|
||||
const char path[],
|
||||
rive::Factory* factory = nullptr,
|
||||
rive::FileAssetLoader* loader = nullptr,
|
||||
|
||||
@@ -230,7 +230,7 @@ int main(int argc, const char* argv[])
|
||||
fprintf(stderr, "no .riv file specified");
|
||||
abort();
|
||||
}
|
||||
std::unique_ptr<rive::File> file =
|
||||
rive::rcp<rive::File> file =
|
||||
rive::File::import(rivBytes, TestingWindow::Get()->factory());
|
||||
assert(file);
|
||||
std::unique_ptr<rive::ArtboardInstance> artboard = file->artboardDefault();
|
||||
|
||||
@@ -4457,21 +4457,6 @@ TEST_CASE("dependency lifetime management", "[CommandQueue]")
|
||||
CHECK(server->getStateMachineInstance(stateMachine3_2) != nullptr);
|
||||
});
|
||||
|
||||
commandQueue->deleteFile(fileHandle);
|
||||
|
||||
commandQueue->runOnce([&](CommandServer* server) {
|
||||
CHECK(server->getFile(fileHandle) == nullptr);
|
||||
CHECK(server->getArtboardInstance(artboardHandle) == nullptr);
|
||||
CHECK(server->getArtboardInstance(artboardHandle2) == nullptr);
|
||||
CHECK(server->getArtboardInstance(artboardHandle3) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine_2) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine2) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine2_2) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine3) == nullptr);
|
||||
CHECK(server->getStateMachineInstance(stateMachine3_2) == nullptr);
|
||||
});
|
||||
|
||||
commandQueue->disconnect();
|
||||
serverThread.join();
|
||||
}
|
||||
Reference in New Issue
Block a user