Files
Seele/src/Editor/main.cpp
T

233 lines
11 KiB
C++
Raw Normal View History

2023-02-24 22:09:07 +01:00
#include "Asset/AssetImporter.h"
2024-04-18 13:33:35 +02:00
#include "Asset/AssetRegistry.h"
2025-04-10 23:43:01 +02:00
#include "Asset/EnvironmentLoader.h"
2024-04-18 13:33:35 +02:00
#include "Asset/FontLoader.h"
#include "Asset/MaterialLoader.h"
2023-02-24 22:09:07 +01:00
#include "Asset/MeshLoader.h"
2026-03-16 16:52:43 +01:00
#include "Graphics/Vulkan/Graphics.h"
2023-02-24 22:09:07 +01:00
#include "Asset/TextureLoader.h"
2024-04-18 13:33:35 +02:00
#include "Graphics/Initializer.h"
2026-03-14 13:53:04 +01:00
#include "Material/Material.h"
2026-03-16 16:54:14 +01:00
#include "Graphics/Vulkan/Graphics.h"
2023-11-05 11:47:22 +01:00
#include "Graphics/StaticMeshVertexData.h"
2026-11-08 23:00:57 +01:00
#include "System/SystemGraph.h"
2024-04-18 13:33:35 +02:00
#include "Window/PlayView.h"
2026-11-08 23:00:57 +01:00
#include "System/CameraUpdater.h"
#include "System/FluidUpdater.h"
#include "System/LightGather.h"
#include "System/MeshUpdater.h"
#include "Window/Application.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"
2024-01-16 19:24:49 +01:00
#include <fmt/core.h>
#include <iostream>
2021-03-31 12:18:16 +02:00
2020-03-05 11:43:38 +01:00
using namespace Seele;
2022-11-17 16:47:42 +01:00
using namespace Seele::Editor;
2021-03-31 12:18:16 +02:00
2023-12-12 11:37:00 +01:00
// 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 -> "#<id>"), so no setLabel needed.
Entity* a = new Entity(scene);
a->attachComponent<Component::Transform>().transform.setPosition(glm::vec3(0.0f, 0.0f, 0.0f));
Entity* b = new Entity(scene);
b->attachComponent<Component::Transform>().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::string>{
[&] {
std::vector<std::string> 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;
}
2026-10-13 21:49:28 +02:00
std::string gameName = "MeshShadingDemo";
2026-04-12 20:49:02 +02:00
std::filesystem::path outputPath = fmt::format("/home/dynamitos/{0}Game/", gameName);
std::filesystem::path sourcePath = fmt::format("/home/dynamitos/{0}/", gameName);
2025-04-12 17:40:14 +02:00
#ifdef WIN32
std::string libraryEnding = "dll";
#elif __APPLE__
std::string libraryEnding = "dylib";
#else
std::string libraryEnding = "so";
#endif
2026-10-13 21:49:28 +02:00
std::filesystem::path binaryPath = sourcePath / "bin" / fmt::format("{}.{}", gameName, libraryEnding);
2024-06-09 12:20:04 +02:00
std::filesystem::path cmakePath = outputPath / "cmake";
2024-07-05 12:02:46 +02:00
if (true) {
graphics = new Vulkan::Graphics();
GraphicsInitializer initializer;
graphics->init(initializer);
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
vd->init(graphics);
2024-04-26 19:32:38 +02:00
2024-07-05 12:02:46 +02:00
AssetRegistry::init(sourcePath / "Assets", graphics);
AssetImporter::init(graphics);
2025-01-08 19:15:12 +01:00
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/arial.ttf",
});
2026-04-12 20:49:02 +02:00
AssetImporter::importEnvironmentMap(EnvironmentImportArgs{
2026-10-13 21:49:28 +02:00
.filePath = sourcePath / "import" / "textures" / "newport_loft.hdr",
2026-04-12 20:49:02 +02:00
});
2025-05-09 14:59:58 +02:00
// 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",
2025-05-04 21:30:01 +02:00
//});
2026-02-15 21:17:09 +01:00
AssetImporter::importMesh(MeshImportArgs{
2026-10-13 21:49:28 +02:00
.filePath = sourcePath / "import" / "models" / "rttest.gltf",
2025-05-09 14:59:58 +02:00
.importPath = "rttest",
2025-04-10 23:43:01 +02:00
});
2026-10-13 21:49:28 +02:00
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import" / "models" / "cube.fbx",
.importPath = "",
});
2024-08-30 09:29:41 +02:00
getThreadPool().waitIdle();
2026-11-09 20:06:47 +01:00
// The world (Scene + SystemGraph) and the game binary are owned by the
// Application from here on. `loadGame` dlopen's the .so, lets the game
// populate the scene+graph, and appends the editor's own systems. Views
// below only render the non-owning application->scene() handle.
OApplication application = new Application();
application->loadGame(graphics, sourcePath, gameName);
2024-07-05 12:02:46 +02:00
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
.height = 1080,
.title = "SeeleEngine",
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
};
auto window = application->addWindow(graphics, mainWindowInfo);
2026-11-08 23:00:57 +01:00
ViewportCreateInfo sceneViewInfo = {
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
};
OGameView sceneView = new Editor::PlayView(graphics, window, application->scene(), sceneViewInfo);
2026-11-08 23:00:57 +01:00
sceneView->setFocused();
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
ViewportCreateInfo{
.dimensions =
{
.size = {1920, 1080},
.offset = {0, 0},
},
},
/* scene = */ application->scene());
inspectorView->setFocused();
2025-02-28 16:56:51 +09:00
window->show();
while (application->isActive() && getGlobals().running) {
application->render();
2024-07-05 12:02:46 +02:00
}
2024-07-18 11:45:56 +02:00
graphics->waitDeviceIdle();
Material::destroy();
2024-07-05 12:02:46 +02:00
vd->destroy();
// export game
} else {
2024-06-09 12:20:04 +02:00
std::filesystem::create_directories(outputPath);
2024-07-05 12:02:46 +02:00
std::system(fmt::format("cmake -DCMAKE_BUILD_TYPE=Release -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" "
2024-06-09 12:20:04 +02:00
"-DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake",
gameName, outputPath.generic_string(), binaryPath.generic_string())
.c_str());
2024-07-05 12:02:46 +02:00
std::system(fmt::format("cmake -S {} -B {}", cmakePath.generic_string(), outputPath.generic_string()).c_str());
2024-06-09 12:20:04 +02:00
std::system(fmt::format("cmake --build {}", cmakePath.generic_string()).c_str());
2024-07-05 12:02:46 +02:00
std::filesystem::copy(binaryPath, outputPath, std::filesystem::copy_options::recursive);
2024-06-09 12:20:04 +02:00
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);
2023-11-06 14:47:21 +01:00
#ifdef WIN32
2024-06-09 12:20:04 +02:00
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");
2023-11-06 14:47:21 +01:00
#endif
2024-06-09 12:20:04 +02:00
}
return 0;
2024-04-19 18:23:36 +02:00
}