1
0

finish chicken nugget anime loader

This commit is contained in:
2026-01-09 16:49:06 +08:00
parent 06bfe69c0e
commit ff34754274
3 changed files with 26 additions and 26 deletions

View File

@@ -3,6 +3,7 @@
#include <basalt/math.hpp> #include <basalt/math.hpp>
namespace anime_loader = ::basalt::shared::anime_loader; namespace anime_loader = ::basalt::shared::anime_loader;
using anime_loader::AnimeLoaderConfig;
using anime_loader::IAnimeLoader; using anime_loader::IAnimeLoader;
using anime_loader::KeyFrame; using anime_loader::KeyFrame;
@@ -14,8 +15,10 @@ public:
ChickenNuggetAnimeLoader() {} ChickenNuggetAnimeLoader() {}
virtual ~ChickenNuggetAnimeLoader() {} virtual ~ChickenNuggetAnimeLoader() {}
protected: public:
virtual void internal_load() override { virtual void load(AnimeLoaderConfig&& config) override {
IAnimeLoader::load(std::move(config));
this->frames.emplace(60 * 0, KeyFrame{.position = {F(0), F(-10), F(10)}, .rotation = {F(0.382683), F(0), F(0), F(0.92388)}}); this->frames.emplace(60 * 0, KeyFrame{.position = {F(0), F(-10), F(10)}, .rotation = {F(0.382683), F(0), F(0), F(0.92388)}});
this->frames.emplace(60 * 1, this->frames.emplace(60 * 1,
KeyFrame{.position = {F(-10), F(0), F(10)}, KeyFrame{.position = {F(-10), F(0), F(10)},

View File

@@ -6,33 +6,26 @@ namespace basalt::shared::anime_loader {
#pragma region Anime Loader #pragma region Anime Loader
IAnimeLoader::IAnimeLoader() : status(AnimeLoaderStatus::Ready), time(0), last_index(0) {} IAnimeLoader::IAnimeLoader() : status(AnimeLoaderStatus::Ready), time(0) {}
IAnimeLoader::~IAnimeLoader() {} IAnimeLoader::~IAnimeLoader() {}
void IAnimeLoader::load() { void IAnimeLoader::load(AnimeLoaderConfig&& config) {
if (this->status != AnimeLoaderStatus::Ready) throw std::runtime_error("unexpected anime loader status"); if (this->status != AnimeLoaderStatus::Ready) throw std::runtime_error("unexpected anime loader status");
this->config = std::move(config);
// load by user
internal_load();
// check empty
if (this->frames.empty()) throw std::runtime_error("no anime key frames.");
// Get last frame index
auto last_pair = this->frames.end();
--last_pair;
this->last_index = last_pair->first;
// change status
this->status = AnimeLoaderStatus::Loaded; this->status = AnimeLoaderStatus::Loaded;
} }
KeyFrameSpan IAnimeLoader::tick() { KeyFrameSpan IAnimeLoader::tick() {
if (this->status != AnimeLoaderStatus::Loaded) throw std::runtime_error("unexpected anime loader status"); if (this->status != AnimeLoaderStatus::Loaded) throw std::runtime_error("unexpected anime loader status");
// Get last frame index
auto last_pair = this->frames.end();
--last_pair;
auto last_index = last_pair->first;
// Accumulate time // Accumulate time
++this->time; ++this->time;
if (this->time > this->last_index) { if (this->time > last_index) {
this->time = 0; this->time = 0;
} }
@@ -61,10 +54,6 @@ namespace basalt::shared::anime_loader {
}; };
} }
void IAnimeLoader::internal_load() {
throw std::logic_error("unimplemented function");
}
#pragma endregion #pragma endregion
} // namespace basalt::shared::anime_loader } // namespace basalt::shared::anime_loader

View File

@@ -28,6 +28,10 @@ namespace basalt::shared::anime_loader {
math::Quaternion next_rotation; ///< 后一帧的摄像机旋转。 math::Quaternion next_rotation; ///< 后一帧的摄像机旋转。
}; };
struct AnimeLoaderConfig {
};
enum class AnimeLoaderStatus { enum class AnimeLoaderStatus {
Ready, Ready,
Loaded, Loaded,
@@ -45,15 +49,19 @@ namespace basalt::shared::anime_loader {
virtual ~IAnimeLoader(); virtual ~IAnimeLoader();
public: public:
void load(); /**
* @brief
* @remarks
* \li 重写时只允许往frames里插入数据。
* \li 重写时务必保证frames里插入的数据大于2个且初始节点的Key总是0。动画帧个数必须大于4。
*/
virtual void load(AnimeLoaderConfig&& config);
KeyFrameSpan tick(); KeyFrameSpan tick();
protected:
virtual void internal_load();
protected: protected:
AnimeLoaderStatus status; AnimeLoaderStatus status;
math::Index time, last_index; AnimeLoaderConfig config;
math::Index time;
std::map<math::Index, KeyFrame> frames; std::map<math::Index, KeyFrame> frames;
}; };