Changes
This commit is contained in:
+23
-4
@@ -6,28 +6,47 @@
|
||||
|
||||
#include "def.h"
|
||||
|
||||
class Game;
|
||||
/**
|
||||
* 用于标记相对位置。
|
||||
*/
|
||||
enum class Location { LEFT_TOP, LEFT, LEFT_BOTTOM, TOP, CENTER, BOTTOM, RIGHT_TOP, RIGHT, RIGHT_BOTTOM };
|
||||
enum class Location : char { LEFT_TOP, LEFT, LEFT_BOTTOM, TOP, CENTER, BOTTOM, RIGHT_TOP, RIGHT, RIGHT_BOTTOM };
|
||||
|
||||
interface IRenderable {
|
||||
virtual ~IRenderable() = default;
|
||||
virtual void render() const noexcept = 0;
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
interface ITickable {
|
||||
virtual ~ITickable() = default;
|
||||
virtual void tick() noexcept = 0;
|
||||
};
|
||||
|
||||
class Renderer : public ITickable {
|
||||
/**
|
||||
* 后续可能用不到,可能可删
|
||||
*/
|
||||
Game* pGame = nullptr;
|
||||
inline static HDC MainDC;
|
||||
int windowWidth = 0, windowHeight = 0;
|
||||
int resizeTime = 0;
|
||||
|
||||
public:
|
||||
static void initialize() noexcept;
|
||||
explicit Renderer() = default;
|
||||
|
||||
void resize(int width, int height) noexcept(false);
|
||||
|
||||
void setGame(Game& game) noexcept { pGame = &game; }
|
||||
[[nodiscard]] int getWidth() const noexcept { return windowWidth; }
|
||||
[[nodiscard]] int getHeight() const noexcept { return windowHeight; }
|
||||
|
||||
void tick() noexcept override {
|
||||
// 联合处理resize防抖
|
||||
if (resizeTime > 0) --resizeTime;
|
||||
else if (resizeTime == 0) {
|
||||
resize(windowWidth, windowHeight);
|
||||
resizeTime = -1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline static Renderer renderer = Renderer();
|
||||
|
||||
Reference in New Issue
Block a user