66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
#pragma once
|
|
#include "Asset/AssetManager.h"
|
|
#include "EngineFrame/Component/Canvas.h"
|
|
class GameMap;
|
|
class Tile : public Actor
|
|
{
|
|
struct ImgKey
|
|
{
|
|
std::string img;
|
|
int index;
|
|
|
|
bool operator<(const ImgKey &other) const
|
|
{
|
|
if (img != other.img)
|
|
{
|
|
return img < other.img; // 字符串按字典序比较
|
|
}
|
|
return index < other.index; // 字符串相同则比较index
|
|
}
|
|
};
|
|
struct DrawInfo
|
|
{
|
|
ImgKey texture;
|
|
SDL_FRect rect = {0, 0, 0, 0};
|
|
};
|
|
|
|
public:
|
|
using TileInfoBody = std::variant<int,std::string>;
|
|
using TileInfo = std::unordered_map<std::string, TileInfoBody>;
|
|
|
|
private:
|
|
/**纹理 */
|
|
RefPtr<Texture> m_texture = nullptr;
|
|
/**FBO */
|
|
GLuint m_fbo = 0;
|
|
/**地图父对象 */
|
|
GameMap* m_parentMap;
|
|
|
|
/**绘制纹理集 */
|
|
std::map<ImgKey, RefPtr<Texture>> m_imgMap;
|
|
/**绘制队列 */
|
|
std::vector<DrawInfo> m_drawQueue;
|
|
|
|
/**渲染大小 */
|
|
SDL_Rect m_srcRect;
|
|
SDL_FRect m_rect;
|
|
|
|
/**大纹理构造完成Flag */
|
|
bool m_isBuild = false;
|
|
|
|
/**Tile横轴个数 */
|
|
int m_tileX = 0;
|
|
|
|
public:
|
|
Tile(GameMap *parentMap, std::vector<std::string> normal,std::vector<std::string> ex);
|
|
~Tile();
|
|
|
|
void InitTile(std::string Path,int Index);
|
|
void InitExTile(std::string Path, int Index);
|
|
void InitInfo(std::string Path, TileInfo &m_data);
|
|
|
|
void PreRender() override;
|
|
void Render() override;
|
|
// void SetPos(Vec2 pos) override;
|
|
};
|