* 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)
285 lines
9.1 KiB
C++
285 lines
9.1 KiB
C++
#include "zeroerr/assert.h"
|
|
#include "zeroerr/unittest.h"
|
|
|
|
#include "graphics/AmbientOcclusion.h"
|
|
#include "graphics/AntiAliasing.h"
|
|
#include "graphics/Canvas.h"
|
|
#include "graphics/DrawItem2D.h"
|
|
#include "graphics/Font.h"
|
|
#include "graphics/GBuffer.h"
|
|
#include "graphics/GlobalIllumination.h"
|
|
#include "graphics/Graphics.h"
|
|
#include "graphics/Grass.h"
|
|
#include "graphics/Light.h"
|
|
#include "graphics/Material.h"
|
|
#include "graphics/Mesh.h"
|
|
#include "graphics/Outline.h"
|
|
#include "graphics/Quad.h"
|
|
#include "graphics/RenderControl.h"
|
|
#include "graphics/RenderSystem.h"
|
|
#include "graphics/RenderSystem3D.h"
|
|
#include "graphics/ScreenSpaceReflection.h"
|
|
#include "graphics/Shader.h"
|
|
#include "graphics/Texture.h"
|
|
#include "graphics/Volumetric.h"
|
|
#include "graphics/Water.h"
|
|
#include "graphics/Waterfall.h"
|
|
#include "ui/UI.h"
|
|
#include "ui/UISystem.h"
|
|
#include "ui/Widget.h"
|
|
#include "window/Window.h"
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <cmath>
|
|
#include <string>
|
|
// Color lives in eve::graphics (see graphics/Canvas.h); keep the unqualified form.
|
|
using eve::graphics::Color;
|
|
|
|
using namespace eve::graphics;
|
|
using namespace eve::ui;
|
|
|
|
/**
|
|
* Real window + Vulkan: world sprites (RenderSystem) and ImGui UI overlay in one present.
|
|
* Frame order: UI NewFrame/widgets → RenderSystem (draws + present with overlay) → dispatch.
|
|
*/
|
|
TEST_CASE("UI.smoke.RenderSystemSameFrameVulkanOverlay") {
|
|
auto *win = eve::window::Window::create();
|
|
auto *gfx = Graphics::create();
|
|
auto *ui = UI::create();
|
|
REQUIRE(win != nullptr);
|
|
REQUIRE(gfx != nullptr);
|
|
REQUIRE(ui != nullptr);
|
|
|
|
eve::window::WindowSettings s;
|
|
s.width = 640;
|
|
s.height = 480;
|
|
s.centered = true;
|
|
REQUIRE(win->setWindowSettings(s));
|
|
REQUIRE_GT(gfx->getWidth(), 0);
|
|
REQUIRE_GT(gfx->getPixelWidth(), 0);
|
|
|
|
REQUIRE(ui->initBackend());
|
|
CHECK(ui->isBackendReady());
|
|
const bool overlayHooked = gfx->getPresentOverlay() != nullptr && gfx->getPresentOverlayUser() != nullptr;
|
|
CHECK(overlayHooked);
|
|
|
|
gfx->setBackgroundColor(Color(0.10f, 0.12f, 0.18f, 1.0f));
|
|
gfx->setScreenReadbackEnabled(true);
|
|
|
|
auto *cam = Camera2D::createCamera();
|
|
cam->data()->r = 0.10f;
|
|
cam->data()->g = 0.12f;
|
|
cam->data()->b = 0.18f;
|
|
|
|
auto *solid = Renderable2D::create();
|
|
solid->transform()->x = 80;
|
|
solid->transform()->y = 100;
|
|
solid->sprite()->width = 160;
|
|
solid->sprite()->height = 100;
|
|
solid->sprite()->r = 0.2f;
|
|
solid->sprite()->g = 0.85f;
|
|
solid->sprite()->b = 0.35f;
|
|
solid->sprite()->visible = true;
|
|
|
|
ui->mountAs("smoke",
|
|
window("Overlay",
|
|
{
|
|
text("UI+RenderSystem", "label"),
|
|
button("Ping", "ping"),
|
|
},
|
|
"root"));
|
|
|
|
int framesOk = 0;
|
|
for (int frame = 0; frame < 30; ++frame) {
|
|
solid->transform()->x = 80.0f + float(frame) * 2.0f;
|
|
|
|
// ImGui frame must be built before present (RenderSystem ends with present).
|
|
ui->beginFrameAndRender();
|
|
RenderSystem::render(*gfx);
|
|
ui->dispatchEvents();
|
|
|
|
SDL_Event e;
|
|
while (SDL_PollEvent(&e)) {
|
|
ui->processEvent(&e);
|
|
if (e.type == SDL_QUIT) break;
|
|
}
|
|
|
|
// After present+readback, swapchain content should be readable.
|
|
Color p = gfx->getPixel(gfx->getWidth() / 2, gfx->getHeight() / 2);
|
|
CHECK(std::isfinite(p.r));
|
|
CHECK(std::isfinite(p.g));
|
|
CHECK(std::isfinite(p.b));
|
|
++framesOk;
|
|
|
|
SDL_Delay(8);
|
|
}
|
|
|
|
CHECK_EQ(framesOk, 30);
|
|
CHECK(UISystem::findHost("smoke") != nullptr);
|
|
CHECK(ui->current()->findById("label") != nullptr);
|
|
|
|
gfx->setScreenReadbackEnabled(false);
|
|
win->close();
|
|
}
|
|
|
|
TEST_CASE("UI.smoke.panelGalleryPreview") {
|
|
auto *win = eve::window::Window::create();
|
|
auto *gfx = Graphics::create();
|
|
auto *ui = UI::create();
|
|
REQUIRE(win != nullptr);
|
|
REQUIRE(gfx != nullptr);
|
|
REQUIRE(ui != nullptr);
|
|
|
|
eve::window::WindowSettings s;
|
|
s.width = 720;
|
|
s.height = 480;
|
|
s.centered = true;
|
|
REQUIRE(win->setWindowSettings(s));
|
|
REQUIRE(ui->initBackend());
|
|
|
|
gfx->setBackgroundColor(Color(0.09f, 0.10f, 0.14f, 1.0f));
|
|
|
|
auto *cam = Camera2D::createCamera();
|
|
cam->data()->r = 0.09f;
|
|
cam->data()->g = 0.10f;
|
|
cam->data()->b = 0.14f;
|
|
|
|
// Soft backdrop sprites so the world + overlay composition is obvious.
|
|
auto *bgA = Renderable2D::create();
|
|
bgA->transform()->x = 40;
|
|
bgA->transform()->y = 60;
|
|
bgA->sprite()->width = 220;
|
|
bgA->sprite()->height = 140;
|
|
bgA->sprite()->r = 0.25f;
|
|
bgA->sprite()->g = 0.45f;
|
|
bgA->sprite()->b = 0.75f;
|
|
bgA->sprite()->visible = true;
|
|
|
|
auto *bgB = Renderable2D::create();
|
|
bgB->transform()->x = 420;
|
|
bgB->transform()->y = 220;
|
|
bgB->sprite()->width = 180;
|
|
bgB->sprite()->height = 160;
|
|
bgB->sprite()->r = 0.75f;
|
|
bgB->sprite()->g = 0.35f;
|
|
bgB->sprite()->b = 0.45f;
|
|
bgB->sprite()->visible = true;
|
|
|
|
float volume = 0.55f;
|
|
bool muted = false;
|
|
int clicks = 0;
|
|
|
|
ui->mountAs("gallery",
|
|
window("EVEngine Preview",
|
|
{
|
|
text("UI overlay + world sprites", "title"),
|
|
separator("sep0"),
|
|
checkbox("Mute", muted, "mute", [&](bool v) { muted = v; }),
|
|
slider("Volume", volume, 0.f, 1.f, "vol", [&](float v) { volume = v; }),
|
|
progress(volume, "prog", "level"),
|
|
button("Ping", "ping", [&]() { ++clicks; }),
|
|
text("clicks: 0", "clicks"),
|
|
},
|
|
"root"));
|
|
|
|
for (int frame = 0; frame < 90; ++frame) {
|
|
bgA->transform()->x = 40.f + float(frame) * 1.2f;
|
|
bgB->transform()->y = 220.f + std::sin(float(frame) * 0.08f) * 24.f;
|
|
volume = 0.35f + 0.3f * (0.5f + 0.5f * std::sin(float(frame) * 0.06f));
|
|
|
|
ui->remountAs("gallery",
|
|
window("EVEngine Preview",
|
|
{
|
|
text("UI overlay + world sprites", "title"),
|
|
separator("sep0"),
|
|
checkbox("Mute", muted, "mute", [&](bool v) { muted = v; }),
|
|
slider("Volume", volume, 0.f, 1.f, "vol",
|
|
[&](float v) { volume = v; }),
|
|
progress(volume, "prog", muted ? "muted" : "level"),
|
|
button("Ping", "ping", [&]() { ++clicks; }),
|
|
text("clicks: " + std::to_string(clicks) +
|
|
" vol: " + std::to_string(int(volume * 100.f)),
|
|
"clicks"),
|
|
},
|
|
"root"));
|
|
|
|
ui->beginFrameAndRender();
|
|
RenderSystem::render(*gfx);
|
|
ui->dispatchEvents();
|
|
|
|
SDL_Event e;
|
|
while (SDL_PollEvent(&e)) {
|
|
ui->processEvent(&e);
|
|
if (e.type == SDL_QUIT) break;
|
|
}
|
|
SDL_Delay(16);
|
|
}
|
|
|
|
CHECK(UISystem::findHost("gallery") != nullptr);
|
|
bgA->sprite()->visible = false;
|
|
bgB->sprite()->visible = false;
|
|
win->close();
|
|
}
|
|
|
|
TEST_CASE("UI.smoke.viewportEmbeddedRenderTarget") {
|
|
auto *win = eve::window::Window::create();
|
|
auto *gfx = Graphics::create();
|
|
auto *ui = UI::create();
|
|
REQUIRE(win != nullptr);
|
|
REQUIRE(gfx != nullptr);
|
|
REQUIRE(ui != nullptr);
|
|
|
|
eve::window::WindowSettings s;
|
|
s.width = 800;
|
|
s.height = 600;
|
|
s.centered = true;
|
|
REQUIRE(win->setWindowSettings(s));
|
|
REQUIRE(ui->initBackend());
|
|
|
|
ui->mountAs("vpsmoke", window("Viewport", {viewport("vp", 420.f, 260.f)}, "root"));
|
|
|
|
for (int frame = 0; frame < 4; ++frame) {
|
|
// UI pass first: ensures the offscreen canvas exists at the widget rect.
|
|
ui->beginFrameAndRender();
|
|
Canvas *canvas = ui->viewportCanvas("vp");
|
|
REQUIRE(canvas != nullptr);
|
|
REQUIRE(canvas->getWidth() > 0);
|
|
|
|
// 2D: draw into the viewport canvas with the immediate-mode path.
|
|
gfx->setCanvas(canvas);
|
|
gfx->clearScreen();
|
|
gfx->drawSolidRectRGBA(10.f, 10.f, 120.f, 80.f, 0.2f, 0.6f, 0.9f, 1.f);
|
|
gfx->setCanvas(nullptr);
|
|
|
|
RenderSystem::render(*gfx); // present + UI overlay
|
|
ui->dispatchEvents();
|
|
|
|
SDL_Event e;
|
|
while (SDL_PollEvent(&e)) {
|
|
ui->processEvent(&e);
|
|
if (e.type == SDL_QUIT) break;
|
|
}
|
|
}
|
|
|
|
auto *vs = UISystem::viewportState("vpsmoke", "vp");
|
|
REQUIRE(vs != nullptr);
|
|
CHECK(vs->canvas != nullptr);
|
|
CHECK(vs->textureId != 0);
|
|
CHECK(vs->width == 420);
|
|
CHECK(vs->height == 260);
|
|
|
|
// 3D: render a cube scene into the same canvas (preview-quality pass).
|
|
auto *cam = Camera3D::createCamera();
|
|
cam->setEye(3.f, 2.f, 4.f);
|
|
cam->setTarget(0.f, 0.f, 0.f);
|
|
auto *cube = Renderable3D::create();
|
|
cube->setMesh(gfx->newMeshCube(1.f));
|
|
cube->setVisible(true);
|
|
gfx->setDirectionalLight(-0.4f, 0.9f, 0.3f, 1.8f, 1.6f, 1.3f);
|
|
gfx->renderScene3DToCanvas(vs->canvas, cam);
|
|
CHECK(vs->canvas->getTexture() != nullptr);
|
|
|
|
win->close();
|
|
}
|