载入中...
搜索中...
未找到
RenderSystem.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <string>
7#include <vector>
8#include "common/ECS.h"
9#include "common/Result.h"
10#include "graphics/DrawItem2D.h"
11
12namespace eve::graphics {
13
14class Canvas;
15class Quad;
16class Shader;
17class Texture;
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;
36 float pixelsPerUnit = 1.f;
38 int pixelRefWidth = 0;
40 int pixelRefHeight = 0;
42 int pixelScale = 1;
44 bool pixelPerfect = false;
46 bool pixelSnap = true;
47 bool active = false; // true only after createCamera() / explicit enable
48 Canvas *canvas = nullptr;
49 Camera2D *entity = nullptr; // self; set by createCamera()
50 };
51
52 COMPONENT(Data, data)
53
54
62 static Camera2D *createCamera(ecs::Table &table = *ecs::current());
63
64 void setAmbient(float r, float g, float b);
65
67 void setPosition(float x, float y);
68 float getX();
69 float getY();
70 void setZoom(float zoom);
71 float getZoom();
72
80 [[nodiscard]] Result<void> setPixelConfig(float pixelsPerUnit, int refWidth = 0, int refHeight = 0);
82 void clearPixelConfig();
84 void setPixelPerfect(bool enabled);
86 bool getPixelPerfect();
88 void setPixelSnap(bool enabled);
90 bool getPixelSnap();
98 [[nodiscard]] Result<void> applyPixelPerfect(int viewWidth, int viewHeight);
100 float getPixelsPerUnit();
102 int getPixelRefWidth();
104 int getPixelRefHeight();
106 int getPixelScale();
107
112 float screenToWorldX(float screenX, float screenY, float viewW, float viewH);
113 float screenToWorldY(float screenX, float screenY, float viewW, float viewH);
114 float worldToScreenX(float worldX, float worldY, float viewW, float viewH);
115 float worldToScreenY(float worldX, float worldY, float viewW, float viewH);
116};
117
119class EVENGINE_API_BACKENDS Renderable2D : public ecs::Entity {
120public:
122 ENTITY(Renderable2D, ecs::Entity)
123
124
125 void release() override;
126
128 struct Transform2D {
129 float x = 0;
130 float y = 0;
131 float rot = 0;
132 float sx = 1;
133 float sy = 1;
134 };
135
136 struct Sprite {
137 float width = 32;
138 float height = 32;
139 float r = 1, g = 1, b = 1, a = 1;
140 int layer = 0;
141 bool visible = true;
142 Texture *texture = nullptr;
143 Texture *normalTexture = nullptr; // non-null → GPU lit2d path
144 Quad *quad = nullptr; // nullptr → full UV 0..1
145 Shader *shader = nullptr; // nullptr → default textured / solid pipeline
146 Canvas *canvas = nullptr; // nullptr → screen
147 Camera2D *camera = nullptr; // nullptr → default active camera for canvas
148 bool receiveLight = true; // false → force unlit (ignore lights)
149 bool castOcclusion = true; // volumetric occlusion map (shadow analogue)
150 BlendMode blend = BlendMode::Alpha;
151 float anchorX = 0.5f, anchorY = 0.5f;
152 bool flipX = false, flipY = false;
153 int trimW = 0, trimH = 0, offsetX = 0, offsetY = 0;
154 };
155
156 COMPONENT(Transform2D, transform)
157 COMPONENT(Sprite, sprite)
158
159
160 void setPosition(float x, float y);
162 float getX();
164 float getY();
166 void setRotation(float degrees);
168 float getRotation();
170 void setScale(float sx, float sy);
172 float getScaleX();
174 float getScaleY();
176 void setSize(float width, float height);
178 float getWidth();
180 float getHeight();
182 void setTexture(Texture *texture);
184 Texture *getTexture();
194 void setNormalTexture(Texture *texture);
200 Texture *getNormalTexture();
202 void setQuad(Quad *quad);
204 Quad *getQuad();
206 void setColor(float r, float g, float b, float a = 1.f);
208 void setLayer(int layer);
210 int getLayer();
212 void setVisible(bool visible);
214 bool getVisible();
216 void setReceiveLight(bool receive);
218 bool getReceiveLight();
220 void setBlend(const std::string &blend);
222 std::string getBlend();
224 void setAnchor(float x, float y);
226 float getAnchorX();
228 float getAnchorY();
230 void setFlip(bool horizontal, bool vertical);
232 bool getFlipX();
234 bool getFlipY();
236 void setFrameLayout(int sourceW, int sourceH, int trimW, int trimH, int offsetX, int offsetY);
238 void setCastOcclusion(bool cast);
240 bool getCastOcclusion();
241};
242
243class Graphics;
244
247public:
249 static void render(Graphics &gfx);
250
252 static void collectSprites(std::vector<DrawItem2D> &out);
253
258 static void drawItems(Graphics &gfx, std::vector<DrawItem2D> &items, bool present);
259};
260
261} // namespace eve::graphics
double y
double x
bool & active
float degrees
Definition CardTypes.cpp:38
#define EVENGINE_API_BACKENDS
Definition Export.h:108
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
double r
float blend
std::uint32_t height
std::uint32_t width
bool present
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
Texture * texture
TileLayer * layer
const EntityFact * entity
Shader * shader
float zoom
float ambientG
float ambientR
float ambientB
Move-only, checked operation results for the common layer.
ScriptStructure out
float offsetX
float offsetY
bool visible
Move-only operation result carrying either a value or Status.
Definition Result.h:176
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:41
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11
bool enabled