载入中...
搜索中...
未找到
RenderSystem.h
浏览该文件的文档.
1#pragma once
2
3#include "common/ECS.h"
5#include "graphics/Quad.h"
6#include "graphics/Shader.h"
7#include "graphics/Texture.h"
8#include "zeroerr/assert.h"
9#include <cstdint>
10#include <vector>
11
12namespace eve::graphics {
13
14class Canvas;
15
17class Camera2D : public ecs::Entity {
18public:
19 ENTITY(Camera2D, ecs::Entity)
20
21 void release() override {}
22
23 struct Data {
24 float x = 0.f;
25 float y = 0.f;
26 float zoom = 1.f;
27 float r = 0.1f, g = 0.1f, b = 0.12f, a = 1.f;
28 float ambientR = 0.15f, ambientG = 0.15f, ambientB = 0.18f;
29 bool active = false; // true only after createCamera() / explicit enable
30 Canvas *canvas = nullptr;
31 Camera2D *entity = nullptr; // self; set by createCamera()
32 };
33
34 COMPONENT(Data, data)
35
37 Camera2D *c = Camera2D::create();
38 ASSERT(c != nullptr);
39 c->data()->entity = c;
40 c->data()->active = true;
41 ASSERT(c->data()->entity == c);
42 return c;
43 }
44
45 void setAmbient(float r, float g, float b);
46
48 void setPosition(float x, float y);
49 float getX();
50 float getY();
51 void setZoom(float zoom);
52 float getZoom();
53
58 float screenToWorldX(float screenX, float screenY, float viewW, float viewH);
59 float screenToWorldY(float screenX, float screenY, float viewW, float viewH);
60 float worldToScreenX(float worldX, float worldY, float viewW, float viewH);
61 float worldToScreenY(float worldX, float worldY, float viewW, float viewH);
62};
63
65class Renderable2D : public ecs::Entity {
66public:
67 ENTITY(Renderable2D, ecs::Entity)
68
69 void release() override {}
70
71 struct Transform2D {
72 float x = 0;
73 float y = 0;
74 float rot = 0;
75 float sx = 1;
76 float sy = 1;
77 };
78
79 struct Sprite {
80 float width = 32;
81 float height = 32;
82 float r = 1, g = 1, b = 1, a = 1;
83 int layer = 0;
84 bool visible = true;
85 Texture *texture = nullptr;
86 Texture *normalTexture = nullptr; // non-null → GPU lit2d path
87 Quad *quad = nullptr; // nullptr → full UV 0..1
88 Shader *shader = nullptr; // nullptr → default textured / solid pipeline
89 Canvas *canvas = nullptr; // nullptr → screen
90 Camera2D *camera = nullptr; // nullptr → default active camera for canvas
91 bool receiveLight = true; // false → force unlit (ignore lights)
92 bool castOcclusion = true; // volumetric occlusion map (shadow analogue)
93 };
94
95 COMPONENT(Transform2D, transform)
96 COMPONENT(Sprite, sprite)
97
98 void setCastOcclusion(bool cast);
99 bool getCastOcclusion();
100};
101
102class Graphics;
103
106public:
108 static void render(Graphics &gfx);
109
111 static void collectSprites(std::vector<DrawItem2D> &out);
112
117 static void drawItems(Graphics &gfx, std::vector<DrawItem2D> &items, bool present);
118};
119
120} // namespace eve::graphics
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t b
uint32_t c
float zoom
Declarative 2D camera (viewport center + zoom).
float screenToWorldY(float screenX, float screenY, float viewW, float viewH)
float worldToScreenY(float worldX, float worldY, float viewW, float viewH)
float worldToScreenX(float worldX, float worldY, float viewW, float viewH)
float screenToWorldX(float screenX, float screenY, float viewW, float viewH)
Convert screen pixel (origin top-left of viewport) to world coordinates. viewW/viewH are the current ...
void setZoom(float zoom)
void setAmbient(float r, float g, float b)
void setPosition(float x, float y)
World-space look-at center and zoom (1 = identity).
static Camera2D * createCamera()
void release() override
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:9
Walks ECS Renderable2D views and draws via Graphics batch path.
static void render(Graphics &gfx)
Full sprite pass + present (existing tests / sprite-only scenes).
static void collectSprites(std::vector< DrawItem2D > &out)
Append visible Renderable2D sprites into a shared queue.
static void drawItems(Graphics &gfx, std::vector< DrawItem2D > &items, bool present)
Sort and draw items. If present=true, calls gfx.present() at the end. Map::render uses present=false ...
Default renderable entity for declarative 2D sprites / solid quads.
void setCastOcclusion(bool cast)
Custom GPU program.
Definition Shader.h:30
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6