载入中...
搜索中...
未找到
RenderSystem.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/ECS.h"
7#include "graphics/Quad.h"
8#include "graphics/Shader.h"
9#include "graphics/Texture.h"
10#include "zeroerr/assert.h"
11#include <cstdint>
12#include <string>
13#include <vector>
14
15namespace eve::graphics {
16
17class Canvas;
18
20class EVENGINE_API_BACKENDS Camera2D : public ecs::Entity {
21public:
23 ENTITY(Camera2D, ecs::Entity)
24
25
26 void release() override {}
27
29 struct Data {
30 float x = 0.f;
31 float y = 0.f;
32 float zoom = 1.f;
33 float r = 0.1f, g = 0.1f, b = 0.12f, a = 1.f;
34 float ambientR = 0.15f, ambientG = 0.15f, ambientB = 0.18f;
35 bool active = false; // true only after createCamera() / explicit enable
36 Canvas *canvas = nullptr;
37 Camera2D *entity = nullptr; // self; set by createCamera()
38 };
39
40 COMPONENT(Data, data)
41
42 static Camera2D *createCamera() {
43 Camera2D *c = Camera2D::create();
44 ASSERT(c != nullptr);
45 c->data()->entity = c;
46 c->data()->active = true;
47 ASSERT(c->data()->entity == c);
48 return c;
49 }
50
51 void setAmbient(float r, float g, float b);
52
54 void setPosition(float x, float y);
55 float getX();
56 float getY();
57 void setZoom(float zoom);
58 float getZoom();
59
64 float screenToWorldX(float screenX, float screenY, float viewW, float viewH);
65 float screenToWorldY(float screenX, float screenY, float viewW, float viewH);
66 float worldToScreenX(float worldX, float worldY, float viewW, float viewH);
67 float worldToScreenY(float worldX, float worldY, float viewW, float viewH);
68};
69
71class EVENGINE_API_BACKENDS Renderable2D : public ecs::Entity {
72public:
74 ENTITY(Renderable2D, ecs::Entity)
75
76
77 void release() override;
78
80 struct Transform2D {
81 float x = 0;
82 float y = 0;
83 float rot = 0;
84 float sx = 1;
85 float sy = 1;
86 };
87
88 struct Sprite {
89 float width = 32;
90 float height = 32;
91 float r = 1, g = 1, b = 1, a = 1;
92 int layer = 0;
93 bool visible = true;
94 Texture *texture = nullptr;
95 Texture *normalTexture = nullptr; // non-null → GPU lit2d path
96 Quad *quad = nullptr; // nullptr → full UV 0..1
97 Shader *shader = nullptr; // nullptr → default textured / solid pipeline
98 Canvas *canvas = nullptr; // nullptr → screen
99 Camera2D *camera = nullptr; // nullptr → default active camera for canvas
100 bool receiveLight = true; // false → force unlit (ignore lights)
101 bool castOcclusion = true; // volumetric occlusion map (shadow analogue)
102 BlendMode blend = BlendMode::Alpha;
103 float anchorX = 0.5f, anchorY = 0.5f;
104 bool flipX = false, flipY = false;
105 int trimW = 0, trimH = 0, offsetX = 0, offsetY = 0;
106 };
107
108 COMPONENT(Transform2D, transform)
109 COMPONENT(Sprite, sprite)
110
111
112 void setPosition(float x, float y);
114 float getX();
116 float getY();
118 void setRotation(float degrees);
120 float getRotation();
122 void setScale(float sx, float sy);
124 float getScaleX();
126 float getScaleY();
128 void setSize(float width, float height);
130 float getWidth();
132 float getHeight();
134 void setTexture(Texture *texture);
136 Texture *getTexture();
146 void setNormalTexture(Texture *texture);
152 Texture *getNormalTexture();
154 void setQuad(Quad *quad);
156 Quad *getQuad();
158 void setColor(float r, float g, float b, float a = 1.f);
160 void setLayer(int layer);
162 int getLayer();
164 void setVisible(bool visible);
166 bool getVisible();
168 void setReceiveLight(bool receive);
170 bool getReceiveLight();
172 void setBlend(const std::string &blend);
174 std::string getBlend();
176 void setAnchor(float x, float y);
178 float getAnchorX();
180 float getAnchorY();
182 void setFlip(bool horizontal, bool vertical);
184 bool getFlipX();
186 bool getFlipY();
188 void setFrameLayout(int sourceW, int sourceH, int trimW, int trimH, int offsetX, int offsetY);
190 void setCastOcclusion(bool cast);
192 bool getCastOcclusion();
193};
194
195class Graphics;
196
199public:
201 static void render(Graphics &gfx);
202
204 static void collectSprites(std::vector<DrawItem2D> &out);
205
210 static void drawItems(Graphics &gfx, std::vector<DrawItem2D> &items, bool present);
211};
212
213} // namespace eve::graphics
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float degrees
Definition CardTypes.cpp:35
#define EVENGINE_API_BACKENDS
Definition Export.h:108
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
double r
std::int32_t c
float blend
std::uint32_t height
std::uint32_t width
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
TileLayer * layer
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
Shader * shader
float zoom
float ambientG
float ambientR
float ambientB
float offsetX
float offsetY
bool visible
Declarative 2D camera (viewport center + zoom).
Canvas public API.
Definition Canvas.h:17
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:11
Walks ECS Renderable2D views and draws via Graphics batch path.
Default renderable entity for declarative 2D sprites / solid quads.
Custom GPU program.
Definition Shader.h:39
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11