106 lines
3.4 KiB
C++
106 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include "RuntimeApi.h"
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace dts {
|
|
|
|
struct RuntimePluginMetadata {
|
|
std::uint32_t apiVersion = 0;
|
|
std::string spineVersionLine;
|
|
std::string adapterBuild;
|
|
std::uint32_t capabilities = 0;
|
|
};
|
|
|
|
struct AnimationMetadata {
|
|
std::string name;
|
|
float duration = 0;
|
|
};
|
|
|
|
struct SkeletonMetadata {
|
|
std::uint32_t boneCount = 0;
|
|
std::uint32_t slotCount = 0;
|
|
std::uint32_t eventCount = 0;
|
|
std::uint32_t constraintCount = 0;
|
|
std::vector<std::string> skins;
|
|
std::vector<AnimationMetadata> animations;
|
|
};
|
|
|
|
struct PreviewVertex {
|
|
float x = 0;
|
|
float y = 0;
|
|
float u = 0;
|
|
float v = 0;
|
|
std::uint32_t color = 0xffffffff;
|
|
};
|
|
|
|
struct PreviewDrawCommand {
|
|
std::vector<PreviewVertex> vertices;
|
|
std::vector<std::uint16_t> indices;
|
|
std::filesystem::path texturePath;
|
|
std::uint32_t blendMode = 0;
|
|
};
|
|
|
|
class RuntimePlugin {
|
|
public:
|
|
RuntimePlugin() = default;
|
|
~RuntimePlugin();
|
|
|
|
RuntimePlugin(const RuntimePlugin&) = delete;
|
|
RuntimePlugin& operator=(const RuntimePlugin&) = delete;
|
|
RuntimePlugin(RuntimePlugin&& other) noexcept;
|
|
RuntimePlugin& operator=(RuntimePlugin&& other) noexcept;
|
|
|
|
[[nodiscard]] bool load(const std::filesystem::path& path, std::string& error);
|
|
void unload();
|
|
[[nodiscard]] bool isLoaded() const;
|
|
[[nodiscard]] std::optional<RuntimePluginMetadata> metadata(std::string& error) const;
|
|
[[nodiscard]] std::optional<SkeletonMetadata> loadSkeleton(
|
|
const std::filesystem::path& skeletonPath,
|
|
const std::filesystem::path& atlasPath,
|
|
float scale,
|
|
std::string& error);
|
|
[[nodiscard]] bool setAnimation(const std::string& name, bool loop, std::string& error);
|
|
[[nodiscard]] std::optional<std::vector<PreviewDrawCommand>> updatePreview(
|
|
float deltaSeconds, std::string& error);
|
|
|
|
private:
|
|
using GetApiVersion = std::uint32_t (*)();
|
|
using GetInfo = std::int32_t (*)(DtsRuntimeInfo*);
|
|
using Create = DtsRuntimeHandle (*)();
|
|
using Destroy = void (*)(DtsRuntimeHandle);
|
|
using Load = std::int32_t (*)(DtsRuntimeHandle, const DtsLoadRequest*);
|
|
using GetSkeletonInfo = std::int32_t (*)(DtsRuntimeHandle, DtsSkeletonInfo*);
|
|
using GetName = const char* (*)(DtsRuntimeHandle, std::uint32_t);
|
|
using GetDuration = float (*)(DtsRuntimeHandle, std::uint32_t);
|
|
using GetLastError = const char* (*)(DtsRuntimeHandle);
|
|
using SetAnimation = std::int32_t (*)(DtsRuntimeHandle, const char*, std::int32_t);
|
|
using Update = std::int32_t (*)(DtsRuntimeHandle, float);
|
|
using GetDrawCommandCount = std::uint32_t (*)(DtsRuntimeHandle);
|
|
using GetDrawCommand = std::int32_t (*)(DtsRuntimeHandle, std::uint32_t, DtsDrawCommand*);
|
|
|
|
void* handle_ = nullptr;
|
|
GetApiVersion getApiVersion_ = nullptr;
|
|
GetInfo getInfo_ = nullptr;
|
|
Create create_ = nullptr;
|
|
Destroy destroy_ = nullptr;
|
|
Load load_ = nullptr;
|
|
GetSkeletonInfo getSkeletonInfo_ = nullptr;
|
|
GetName getAnimationName_ = nullptr;
|
|
GetDuration getAnimationDuration_ = nullptr;
|
|
GetName getSkinName_ = nullptr;
|
|
GetLastError getLastError_ = nullptr;
|
|
SetAnimation setAnimation_ = nullptr;
|
|
Update update_ = nullptr;
|
|
GetDrawCommandCount getDrawCommandCount_ = nullptr;
|
|
GetDrawCommand getDrawCommand_ = nullptr;
|
|
DtsRuntimeHandle context_ = nullptr;
|
|
};
|
|
|
|
} // namespace dts
|