Initial engine repository
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <frostbite2D/2d/sprite.h>
|
||||
#include <frostbite2D/animation/animation_data.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class Sprite;
|
||||
|
||||
class Animation : public Actor {
|
||||
public:
|
||||
struct ReplaceData {
|
||||
int param1 = 0;
|
||||
int param2 = 0;
|
||||
ReplaceData() = default;
|
||||
ReplaceData(int p1, int p2) : param1(p1), param2(p2) {}
|
||||
};
|
||||
|
||||
public:
|
||||
Animation();
|
||||
explicit Animation(const std::string& aniPath);
|
||||
Animation(const std::string& aniPath,
|
||||
std::function<std::string(std::string, ReplaceData)> additionalOptions,
|
||||
ReplaceData data);
|
||||
~Animation();
|
||||
|
||||
void Init(const std::string& aniPath);
|
||||
|
||||
void OnUpdate(float deltaTime) override;
|
||||
void OnAdded(Actor* parent) override;
|
||||
void SetVisible(bool visible);
|
||||
|
||||
public:
|
||||
void FlushFrame(int index);
|
||||
void Reset();
|
||||
animation::AniFrame GetCurrentFrameInfo() const;
|
||||
void SetFrameIndex(int index);
|
||||
void SetDirection(int direction);
|
||||
void InterpolationLogic();
|
||||
|
||||
Vec2 GetMaxSize() const;
|
||||
bool GetStaticLocalBounds(Rect& outBounds) const;
|
||||
bool GetStaticLocalBounds(int direction, Rect& outBounds) const;
|
||||
uint64 GetRenderSignature() const;
|
||||
|
||||
bool IsUsable() const { return usable_; }
|
||||
void SetUsable(bool usable) { usable_ = usable; }
|
||||
|
||||
int GetCurrentFrameIndex() const { return currentFrameIndex_; }
|
||||
int GetTotalFrameCount() const { return totalFrameCount_; }
|
||||
|
||||
public:
|
||||
bool usable_ = true;
|
||||
int currentFrameIndex_ = 0;
|
||||
int totalFrameCount_ = 0;
|
||||
float currentFrameTime_ = 0.0f;
|
||||
Ptr<Sprite> currentFrame_ = nullptr;
|
||||
float nextFrameDelay_ = 9999999.0f;
|
||||
|
||||
bool isLooping_ = true;
|
||||
|
||||
std::function<void(int)> changeFrameCallback_;
|
||||
std::function<void()> endCallback_;
|
||||
|
||||
std::vector<animation::AniFrame> frames_;
|
||||
std::vector<Ptr<Sprite>> spriteFrames_;
|
||||
std::vector<Vec2> spriteFrameOffsets_;
|
||||
|
||||
std::unordered_map<std::string, animation::AniFlag> animationFlag_;
|
||||
|
||||
std::string type_ = "normal";
|
||||
std::string aniPath_;
|
||||
|
||||
std::function<std::string(std::string, ReplaceData)> additionalOptions_;
|
||||
ReplaceData additionalOptionsData_;
|
||||
|
||||
Vec2 maxSize_ = Vec2::Zero();
|
||||
int direction_ = 1;
|
||||
|
||||
std::vector<animation::AniFrame> interpolationData_;
|
||||
|
||||
private:
|
||||
void ApplyFramePresentation(const Vec2& framePos,
|
||||
const Vec2& imageRate,
|
||||
float rotation,
|
||||
BlendMode blendMode);
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
@@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/types/type_alias.h>
|
||||
#include <frostbite2D/types/type_math.h>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <optional>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class BinaryReader;
|
||||
|
||||
namespace animation {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 类型定义
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
using AniFlag = std::variant<
|
||||
int,
|
||||
float,
|
||||
Vec2,
|
||||
std::string,
|
||||
std::vector<int>,
|
||||
std::vector<float>>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 数据结构
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct AniFrame {
|
||||
std::string imgPath; // 图片路径
|
||||
int imgIndex = 0; // 图片索引
|
||||
Vec2 imgPos; // 图片位置
|
||||
std::vector<std::vector<int>> attackBox; // 攻击框 [x, y, w, h, type, param]
|
||||
std::vector<std::vector<int>> damageBox; // 受击框 [x, y, w, h, type, param]
|
||||
std::unordered_map<std::string, AniFlag> flag; // 帧特效数据
|
||||
int delay = 0; // 延迟(毫秒)
|
||||
};
|
||||
|
||||
struct AniInfo {
|
||||
std::vector<std::string> imgList; // 图片列表
|
||||
std::vector<AniFrame> frames; // 帧列表
|
||||
std::unordered_map<std::string, AniFlag> flag; // 动画特效数据
|
||||
};
|
||||
|
||||
struct AlsAniInfo {
|
||||
std::string path; // 路径
|
||||
std::vector<int> layer; // 图层 [zOrder, subLayer]
|
||||
};
|
||||
|
||||
struct AlsInfo {
|
||||
std::unordered_map<std::string, AlsAniInfo> aniList; // ALS 动画列表
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 工具函数
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
std::string getAniFlag(int type);
|
||||
std::string getAniEffectType(int type);
|
||||
std::string getAniFlipType(int type);
|
||||
std::string getAniDamageType(int type);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 解析函数
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief 解析 .ani 二进制数据
|
||||
* @param data 二进制数据
|
||||
* @param size 数据大小
|
||||
* @return 解析后的动画信息
|
||||
*/
|
||||
AniInfo parseAniInfo(const char* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief 从 PVF 路径解析 .ani 文件
|
||||
* @param path PVF 中的文件路径(如 "character/player/attack.ani")
|
||||
* @return 解析后的动画信息,解析失败返回 std::nullopt
|
||||
*/
|
||||
std::optional<AniInfo> parseAniFromPvf(const std::string& path);
|
||||
|
||||
/**
|
||||
* @brief 解析 .als 文本数据
|
||||
* @param data 文本数据
|
||||
* @return 解析后的 ALS 信息
|
||||
*/
|
||||
AlsInfo parseAlsInfo(const std::string& data);
|
||||
|
||||
/**
|
||||
* @brief 从 PVF 路径解析 .als 文件
|
||||
* @param path PVF 中的文件路径
|
||||
* @return 解析后的 ALS 信息,解析失败返回 std::nullopt
|
||||
*/
|
||||
std::optional<AlsInfo> parseAlsFromPvf(const std::string& path);
|
||||
|
||||
} // namespace animation
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user