* chore(ci): add clang-format gate, CODEOWNERS and agent collaboration rules * refactor(modules): clear remaining back-edges and split the largest TUs Three known dependency back-edges are gone (module_depgraph.py KNOWN_BACK_EDGES is now empty; --check passes with 0 violations, 0 cycles): - window -> graphics: window queries the new IWindowSurfaceHost capability (common/WindowSurfaceHost.h) instead of holding a Graphics pointer; Window::setGraphics was removed and all call sites updated. - window -> image: Window::setIcon was replaced by setIconRGBA(const uint8_t*, w, h); the window no longer decodes ImageData. - scene -> graphics: pickScreenAt / collectFrustumIdsAt implementations moved to graphics/ScenePicking.cpp (graphics -> scene is a legal downward edge); scene now depends only on spatial. TU splits (pure moves, verified identical method sets and brace balance): - vulkan/Graphics.cpp (5118 lines) -> Graphics.cpp (lifecycle), GraphicsPipeline, Graphics2D, Graphics3D, GraphicsMesh + shared GraphicsInternal.h. - scene/Scene.cpp -> Scene.cpp (script layer / host lifecycle / serialization) + SceneNodes.cpp + shared SceneInternal.h. Verified with a real build (MSVC 19.51, prebuilt third-party): full build green; window.* and Scene.* suites pass, including scene picking/culling and GPU cases. * refactor(graphics): narrow Graphics interfaces and clear public-header leaks Step 4 — interface segregation: - New lean interfaces: IGraphics2D, IGraphics3D, IResourceFactory, IPostFX (pure virtuals, forward-declared types only; graphics/Color.h extracted from Canvas.h so modules that only need the color type stop pulling Canvas.h). - Graphics now implements all four facets; consumers can depend on the narrow interface they use instead of the 129-method god class. - Migrated voxel (VoxelWorld::drawVisible -> IGraphics3D*) and model3d (ModelRenderer::buildRenderable(s) -> IResourceFactory&). - Graphics.h slims from 24 sub-header includes to a handful of small type headers + forward declarations; the destructor moved out-of-line so unique_ptr effect members are destroyed where types are complete. Step 5 — header leaks (module_depgraph.py '*' marks: 14 -> 7): - map/TileLayer.h, particles/ParticleEmitter.h, avatar/AvatarInstance.h, animation/SpineAnim.h, map/TileSystem.h, model3d/ModelData.h, model3d/ModelRenderer.h, audio/Audio.h + Source.h, image/ImageData.h + Image.h, dialogue/Dialogue.h, procgen Palette/OutputSpec/TextureRecipe/ PbrMaterial -> forward declarations, includes moved to .cpp. - voxel/VoxelWorld.h: terrain sampler Pimpl'd (unique_ptr + out-of-line destructor), removing the procgen header dependency. - gpgpu/vulkan backend headers stop pulling graphics/vulkan/Graphics.h. - Remaining '*' marks are deliberate: tiny POD/enum headers (GridConfig, MapObject, BlendMode, Color), an internal backend header (GraphicsInternal.h -> filesystem), and lean interface references. Verified with a full clean build (MSVC) and tests: window/Scene/voxel/ RenderSystem/Quad/shader/TextureSampler/resourceLifetime pass; broad suite only shows the pre-existing PHYSFS-init filesystem-environment failures. * feat(resources): revive ResourceManager as unified IAssetReloader-backed cache * fix(resources): leak ResourceManager singleton to avoid exit-time teardown crashes Cached CPU resources may own third-party handles (FreeType faces, Assimp scenes, image decode handlers) whose libraries are torn down at process exit in an unspecified TU order; destroying cached entries from the singleton destructor can segfault at exit (seen on CI Windows in model3d.materialApi.objMtl). Keep the singleton alive until OS reclaim; explicit unload()/clear() still release entries during the run. * refactor(devtools): consume business modules through capability interfaces DevTools / cmdline no longer include business-module headers, so trimming scene / physics / procgen / particles / audio / ui / graphics no longer requires disabling devtools, and devtools can be switched off with -DEVENGINE_MODULE_DEVTOOLS=OFF. New capability interfaces in common/: - ISceneQuery (scene) - host/node inspection + mutation + transform sync - IRenderCapture (graphics) - render status, PNG capture, camera control, visible-entity snapshot, entity-ID mask, G-buffer PNGs - IPhysicsQuery (physics) - 2D world lifecycle + ray casts - IProcgenQuery (procgen) - recipe listing, map/mesh generation - IParticlesQuery (particles) - emitter status + one-shot emit - IAudioQuery (audio) - volume / stop-all - IEditorHost (ui) - declarative editor host (used by cmdline too) Providers register in their module constructors. DevTools rewires McpServer (render/scene/procgen/physics/particles/audio/host tools), SceneInspect (now delegates to ISceneQuery + IRenderCapture) and RenderVision (uses IRenderCapture::capturePngDataUrl); cmdline/Mcp.cpp uses IEditorHost. manifest: devtools DEPS graphics scene physics procgen particles audio ui image event filesystem -> event; cmdline DEPS filesystem ui -> filesystem. Verified: full build green; devtools.mcp.* tests pass; broad suite shows only the pre-existing PHYSFS-init filesystem-environment failures. * style: apply clang-format to changed lines after dev merge * fix(webgpu): include RenderControl/TextureSampler explicitly after Graphics.h slimming * fix(webgpu): provide newFont/print stubs to satisfy IGraphics2D/IResourceFactory vtables * fix(common): make ProcgenQuery.h self-sufficient (cstdint/utility for GCC)
164 lines
4.8 KiB
C++
164 lines
4.8 KiB
C++
#pragma once
|
|
|
|
#include "common/ECS.h"
|
|
#include "graphics/Color.h"
|
|
#include "map/TileOrientation.h"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace eve::graphics {
|
|
class Graphics;
|
|
class Camera2D;
|
|
class Canvas;
|
|
class Texture;
|
|
} // namespace eve::graphics
|
|
|
|
namespace eve::map {
|
|
|
|
// Color lives in eve::graphics (see graphics/Canvas.h); re-expose it here so
|
|
// tile code keeps the unqualified form.
|
|
using eve::graphics::Color;
|
|
|
|
/**
|
|
* @brief ECS tile layer entity. Script mutates tile GIDs / tileset / draw; TileRenderSystem
|
|
* batch-draws atlas quads (or solid debug colors when no texture).
|
|
*
|
|
* GID 0 = empty. Tiled flip flags (high bits) are masked on read/draw.
|
|
*/
|
|
class TileLayer : public ecs::Entity {
|
|
public:
|
|
ENTITY(TileLayer, ecs::Entity)
|
|
|
|
void release() override {}
|
|
|
|
struct Config {
|
|
int mapW = 0;
|
|
int mapH = 0;
|
|
float tileW = 32.f;
|
|
float tileH = 32.f;
|
|
float originX = 0.f;
|
|
float originY = 0.f;
|
|
MapOrientation orientation = MapOrientation::Orthogonal;
|
|
StaggerAxis staggerAxis = StaggerAxis::Y;
|
|
StaggerIndex staggerIndex = StaggerIndex::Odd;
|
|
float hexSideLength = 0.f;
|
|
TileLayer *entity = nullptr;
|
|
};
|
|
|
|
struct Tiles {
|
|
std::vector<uint32_t> gids;
|
|
};
|
|
|
|
struct Tileset {
|
|
graphics::Texture *texture = nullptr;
|
|
int firstGid = 1;
|
|
int columns = 1;
|
|
int tileW = 32;
|
|
int tileH = 32;
|
|
int margin = 0;
|
|
int spacing = 0;
|
|
};
|
|
|
|
struct Draw {
|
|
graphics::Canvas *canvas = nullptr;
|
|
graphics::Camera2D *camera = nullptr;
|
|
int layer = 0;
|
|
bool visible = true;
|
|
Color tint{1.f, 1.f, 1.f, 1.f};
|
|
};
|
|
|
|
struct Resource {
|
|
std::string path;
|
|
std::string texturePath;
|
|
int64_t modtime = -1;
|
|
bool autoReload = true;
|
|
};
|
|
|
|
COMPONENT(Config, config)
|
|
COMPONENT(Tiles, tiles)
|
|
COMPONENT(Tileset, tileset)
|
|
COMPONENT(Draw, draw)
|
|
COMPONENT(Resource, resource)
|
|
|
|
static TileLayer *createLayer(int mapW, int mapH, float tileW = 32.f, float tileH = 32.f);
|
|
|
|
/** @brief World origin of the layer (pixels). */
|
|
void setOrigin(float x, float y);
|
|
float getX();
|
|
float getY();
|
|
|
|
/** @brief Map dimensions in tiles. */
|
|
int getMapWidth();
|
|
int getMapHeight();
|
|
/** @brief Tile size in pixels. */
|
|
float getTileWidth();
|
|
float getTileHeight();
|
|
void setTileSize(float tileW, float tileH);
|
|
|
|
/** @brief Resizes the tile grid (existing GIDs preserved where possible). */
|
|
void resize(int mapW, int mapH);
|
|
|
|
/** @brief Tile GID access; 0 = empty. */
|
|
void setTile(int tx, int ty, int gid);
|
|
int getTile(int tx, int ty);
|
|
/** @brief Fills the whole layer with one GID. */
|
|
void fill(int gid);
|
|
/** @brief Clears the layer to empty. */
|
|
void clear();
|
|
|
|
/** @brief Binds the atlas texture and tile table. */
|
|
void setTileset(graphics::Texture *texture, int firstGid, int columns, int margin = 0,
|
|
int spacing = 0);
|
|
/** @brief Tile size in pixels of the bound tileset. */
|
|
void setTilesetTileSize(int tileW, int tileH);
|
|
/** @brief Bound tileset accessors. */
|
|
graphics::Texture *getTilesetTexture();
|
|
int getTilesetFirstGid();
|
|
int getTilesetColumns();
|
|
|
|
/** @brief Draw target canvas / camera. */
|
|
void setCanvas(graphics::Canvas *canvas);
|
|
void setCamera(graphics::Camera2D *camera);
|
|
|
|
/** @brief Draw order layer / visibility / tint. */
|
|
void setLayer(int layer);
|
|
int getLayer();
|
|
|
|
void setVisible(bool visible);
|
|
bool isVisible();
|
|
|
|
void setTint(float r, float g, float b, float a = 1.f);
|
|
|
|
/** @brief Applies a map JSON config (Config + Tiles + Tileset + Draw). */
|
|
bool applyConfig(const std::string &json);
|
|
/** @brief Loads a config file and binds it for hot reload. */
|
|
bool loadConfig(const std::string &path);
|
|
/** @brief Re-reads the bound config file (hot reload). */
|
|
bool reloadConfig();
|
|
/** @brief Enables/disables automatic config hot reload. */
|
|
void setAutoReload(bool enable);
|
|
bool getAutoReload();
|
|
/** @brief Path of the bound config file. */
|
|
std::string getConfigPath();
|
|
|
|
/** @brief Tile-index ↔ world-pixel conversions (per layer orientation). */
|
|
void tileToWorld(int tx, int ty, float &wx, float &wy);
|
|
/** @brief Painter's-algorithm depth for 2.5D draw ordering. */
|
|
float depthY(int tx, int ty);
|
|
void worldToTile(float wx, float wy, int &tx, int &ty);
|
|
|
|
/** @brief Scalar conversion helpers. */
|
|
float tileToWorldX(int tx, int ty);
|
|
float tileToWorldY(int tx, int ty);
|
|
float depthYAt(int tx, int ty);
|
|
int worldToTileX(float wx, float wy);
|
|
int worldToTileY(float wx, float wy);
|
|
};
|
|
|
|
/** @brief Strip Tiled flip / rotate flags; keep low 28 bits. */
|
|
inline uint32_t tileGid(uint32_t raw) { return raw & 0x0FFFFFFFu; }
|
|
|
|
} // namespace eve::map
|