#include "Asset/AssetImporter.h" #include "Asset/AssetRegistry.h" #include "Asset/EnvironmentLoader.h" #include "Asset/FontLoader.h" #include "Asset/MaterialLoader.h" #include "Asset/MeshLoader.h" #include "Graphics/Vulkan/Graphics.h" #include "Asset/TextureLoader.h" #include "Graphics/Initializer.h" #include "Material/Material.h" #include "Graphics/Vulkan/Graphics.h" #include "Graphics/StaticMeshVertexData.h" #include "System/SystemGraph.h" #include "Window/PlayView.h" #include "System/CameraUpdater.h" #include "System/FluidUpdater.h" #include "System/LightGather.h" #include "System/MeshUpdater.h" #include "Window/WindowManager.h" #include "Window/InspectorView.h" #include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene #include "Component/Transform.h" #include "Actor/Entity.h" #include "ComponentRegistry.h" #include #include using namespace Seele; using namespace Seele::Editor; // make it global so it gets deleted last and automatically static Gfx::OGraphics graphics; // Headless path: build a real Vulkan device with no WSI (no display available), // populate a Scene with a few entities + components, dump the registry to stdout // via the same handle-space query the editor's inspector uses, then tear down. // Used for CI / smoke verification on display-less machines: the driver is // present, only the display is not, so surface extensions are intentionally // omitted while everything else (instance, device, queues, GPU buffers) works. static int runHeadlessDump() { std::cout << "[headless] constructing Vulkan::Graphics (no WSI / no swapchain)...\n"; Gfx::OGraphics headlessGfx = new Vulkan::Graphics(); GraphicsInitializer initializer; initializer.headless = true; // skip GLFW init, WSI instance exts, and the swapchain device ext headlessGfx->init(initializer); std::cout << "[headless] Vulkan device constructed successfully.\n"; // A real (non-null) graphics handle, so Scene builds its GPU sub-systems for real. OScene scene = new Scene(headlessGfx); std::cout << "[headless] Scene constructed (LightEnvironment + FluidScene on real device).\n"; // A few entities with real transforms so the dump is meaningful. The display label is // auto-derived from the entt id (Entity::getLabel -> "#"), so no setLabel needed. Entity* a = new Entity(scene); a->attachComponent().transform.setPosition(glm::vec3(0.0f, 0.0f, 0.0f)); Entity* b = new Entity(scene); b->attachComponent().transform.setPosition(glm::vec3(1.0f, 2.0f, -3.0f)); Entity* c = new Entity(scene); // c intentionally has no components - exercises the "no components" roster row. initComponentRegistry(); auto entities = enumerateEntities(scene); std::cout << "\n[headless] entity roster: " << entities.size() << " entity(ies)\n"; for (const auto& e : entities) { std::cout << "\n=== " << e.label << " ===\n"; std::cout << " components: " << e.componentSummary << "\n"; auto components = describeEntityComponents(scene, e.entity); for (const auto& c : components) { std::cout << " [ " << c.name << " ]\n"; // Indent the field text by 4 spaces for readability. for (const auto& line : std::vector{ [&] { std::vector out; std::string cur; for (char ch : c.fieldText) { if (ch == '\n') { out.push_back(" " + cur); cur.clear(); } else { cur += ch; } } if (!cur.empty()) { out.push_back(" " + cur); } return out; }()}) { std::cout << " " << line << "\n"; } } } std::cout << "\n[headless] tearing down (waitDeviceIdle + dispose)...\n"; headlessGfx->waitDeviceIdle(); delete a; delete b; delete c; // scene (OScene) and headlessGfx (OGraphics) are OwningPtr (RAII): their destructors // free the Scene / Graphics when the locals go out of scope at the end of this function. // No manual delete - that would be a double-free. Order matters (entities before scene), // which is already satisfied by the explicit deletes above. std::cout << "[headless] OK - headless Vulkan path validated.\n"; return 0; } int main(int argc, char** argv) { // --headless: build a real headless Vulkan device and exit (no window). // --dump-entities: (implies --headless) also dump the entity roster to stdout. bool wantHeadless = false, wantDump = false; for (int i = 1; i < argc; ++i) { std::string a = argv[i]; if (a == "--headless" || a == "--dump-entities") wantHeadless = true; if (a == "--dump-entities") wantDump = true; } if (wantHeadless) { if (wantDump) { return runHeadlessDump(); } // Headless device smoke test only (no dump). Gfx::OGraphics h = new Vulkan::Graphics(); GraphicsInitializer init; init.headless = true; h->init(init); std::cout << "[headless] device OK (no WSI). Tearing down.\n"; h->waitDeviceIdle(); // h is an OwningPtr (RAII) - the destructor frees the Graphics at end of scope. // No manual delete (would be a double-free). return 0; } std::string gameName = "MeshShadingDemo"; std::filesystem::path outputPath = fmt::format("/home/dynamitos/{0}Game/", gameName); std::filesystem::path sourcePath = fmt::format("/home/dynamitos/{0}/", gameName); #ifdef WIN32 std::string libraryEnding = "dll"; #elif __APPLE__ std::string libraryEnding = "dylib"; #else std::string libraryEnding = "so"; #endif std::filesystem::path binaryPath = sourcePath / "bin" / fmt::format("{}.{}", gameName, libraryEnding); std::filesystem::path cmakePath = outputPath / "cmake"; if (true) { graphics = new Vulkan::Graphics(); GraphicsInitializer initializer; graphics->init(initializer); StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); vd->init(graphics); GameInterface gameInterface(binaryPath); OScene scene = new Scene(graphics); gameInterface.reload(); OSystemGraph systemGraph = new SystemGraph(); gameInterface.getGame()->setupScene(scene, systemGraph); systemGraph->addSystem(new System::KeyboardInput(scene)); systemGraph->addSystem(new System::FluidUpdater(scene)); systemGraph->addSystem(new System::LightGather(scene)); systemGraph->addSystem(new System::MeshUpdater(scene)); systemGraph->addSystem(new System::CameraUpdater(scene)); OWindowManager windowManager = new WindowManager(systemGraph); AssetRegistry::init(sourcePath / "Assets", graphics); AssetImporter::init(graphics); AssetImporter::importFont(FontImportArgs{ .filePath = "./fonts/arial.ttf", }); AssetImporter::importEnvironmentMap(EnvironmentImportArgs{ .filePath = sourcePath / "import" / "textures" / "newport_loft.hdr", }); // AssetImporter::importTexture(TextureImportArgs{ // .filePath = sourcePath / "import" / "textures" / "grass_block_side.png", // .importPath = "", // }); //AssetImporter::importMesh(MeshImportArgs{ // .filePath = sourcePath / "import" / "models" / "main1_sponza" / "sponza.gltf", // .importPath = "sponza", //}); AssetImporter::importMesh(MeshImportArgs{ .filePath = sourcePath / "import" / "models" / "rttest.gltf", .importPath = "rttest", }); AssetImporter::importMesh(MeshImportArgs{ .filePath = sourcePath / "import" / "models" / "cube.fbx", .importPath = "", }); getThreadPool().waitIdle(); vd->commitMeshes(); WindowCreateInfo mainWindowInfo = { .width = 1920, .height = 1080, .title = "SeeleEngine", .preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB, }; auto window = windowManager->addWindow(graphics, mainWindowInfo); ViewportCreateInfo sceneViewInfo = { .dimensions = { .size = {1920, 1080}, .offset = {0, 0}, }, }; OGameView sceneView = new Editor::PlayView(graphics, window, scene, sceneViewInfo); sceneView->setFocused(); OInspectorView inspectorView = new Editor::InspectorView(graphics, window, ViewportCreateInfo{ .dimensions = { .size = {1920, 1080}, .offset = {0, 0}, }, }, /* scene = */ scene); inspectorView->setFocused(); window->show(); while (windowManager->isActive() && getGlobals().running) { windowManager->render(); } graphics->waitDeviceIdle(); Material::destroy(); vd->destroy(); // export game } else { std::filesystem::create_directories(outputPath); std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=Release -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" " "-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()) .c_str()); std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), outputPath.generic_string()).c_str()); std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str()); std::filesystem::copy(binaryPath, outputPath, std::filesystem::copy_options::recursive); std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive); std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive); std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive); #ifdef WIN32 std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll"); std::filesystem::copy_file("slang.dll", outputPath / "slang.dll"); std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll"); #endif } return 0; }