Skip to content

Commit 907988d

Browse files
committed
Created AGENTS.md file
1 parent f9645cc commit 907988d

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

editor/Exporter.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ fs::path editor::Exporter::getExportProjectRoot() const {
104104
return config.targetDir / "project";
105105
}
106106

107+
bool editor::Exporter::shouldSkipExportSupportFile(const fs::path& relativePath) {
108+
return relativePath == "CMakeLists.txt" || relativePath.filename() == "AGENTS.md";
109+
}
110+
107111
bool editor::Exporter::checkTargetDir() {
108112
setProgress("Checking target directory...", 0.0f);
109113

@@ -295,12 +299,21 @@ bool editor::Exporter::copyGenerated() {
295299
// Also copy scene_scripts.cpp
296300
fs::path sceneScriptsSrc = project->getProjectInternalPath() / "scene_scripts.cpp";
297301
if (fs::exists(sceneScriptsSrc, ec)) {
298-
fs::copy_file(sceneScriptsSrc, generatedDst / "scene_scripts.cpp",
299-
fs::copy_options::overwrite_existing, ec);
300-
if (ec) {
301-
setError("Failed to copy scene_scripts.cpp: " + ec.message());
302+
std::ifstream ifs(sceneScriptsSrc, std::ios::in | std::ios::binary);
303+
if (!ifs) {
304+
setError("Failed to read generated scene_scripts.cpp");
302305
return false;
303306
}
307+
308+
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
309+
const std::string editorOnlyComment = "// Doriax API headers for this project are provided by .doriax/engine-api; see generated CMakeLists.txt for local and upstream source references.\n";
310+
const std::string exportComment = "// This file binds scene script metadata to compiled C++ and Lua scripts for the current build configuration.\n";
311+
size_t commentPos = content.find(editorOnlyComment);
312+
if (commentPos != std::string::npos) {
313+
content.replace(commentPos, editorOnlyComment.size(), exportComment);
314+
}
315+
316+
FileUtils::writeIfChanged(generatedDst / "scene_scripts.cpp", content);
304317
}
305318

306319
return true;
@@ -355,8 +368,8 @@ bool editor::Exporter::copyAssets() {
355368
std::string firstComponent = relPath.begin()->string();
356369
if (!firstComponent.empty() && firstComponent[0] == '.') continue;
357370

358-
// Skip CMakeLists.txt at root level
359-
if (relPath == "CMakeLists.txt") continue;
371+
// Skip project support files that should not ship as assets
372+
if (shouldSkipExportSupportFile(relPath)) continue;
360373

361374
// Skip C++ script files (handled by copyCppScripts)
362375
if (entry.is_regular_file() && scriptPaths.count(fs::weakly_canonical(entry.path(), ec))) continue;
@@ -450,8 +463,8 @@ bool editor::Exporter::copyLua() {
450463
std::string firstComponent = relPath.begin()->string();
451464
if (!firstComponent.empty() && firstComponent[0] == '.') { it.disable_recursion_pending(); continue; }
452465

453-
// Skip CMakeLists.txt at root level
454-
if (relPath == "CMakeLists.txt") continue;
466+
// Skip project support files that should not ship in the Lua directory
467+
if (shouldSkipExportSupportFile(relPath)) continue;
455468

456469
// Skip terrain_maps directory (handled by copyAssets)
457470
if (entry.is_directory()) {

editor/Exporter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace doriax::editor {
5454
bool isCancelled() const;
5555

5656
fs::path getExportProjectRoot() const;
57+
static bool shouldSkipExportSupportFile(const fs::path& relativePath);
5758

5859
bool checkTargetDir();
5960
bool clearGenerated();

editor/Generator.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ void editor::Generator::writeSourceFiles(const fs::path& projectPath, const fs::
739739
cmakeContent += "project(" + libName + ")\n\n";
740740
cmakeContent += "set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})\n";
741741
cmakeContent += "set(INTERNAL_DIR ${PROJECT_ROOT}/.doriax)\n\n";
742+
cmakeContent += "# Doriax runtime API headers for this project come from ${INTERNAL_DIR}/engine-api.\n";
743+
cmakeContent += "# Local engine API source used by this editor build: " + (exePath / "engine").generic_string() + "\n";
744+
cmakeContent += "# Full engine + editor source (including YAML serialization for *.scene/*.bundle/project.yaml): https://github.com/doriaxengine/doriax\n\n";
742745

743746
cmakeContent += "# Specify C++ standard\n";
744747
cmakeContent += "set(CMAKE_CXX_STANDARD 17)\n";
@@ -808,7 +811,7 @@ void editor::Generator::writeSourceFiles(const fs::path& projectPath, const fs::
808811
cmakeContent += " " + engineApiPathStr + "/core/util\n";
809812
cmakeContent += ")\n\n";
810813

811-
cmakeContent += "# Default DORIAX_LIB_DIR if not provided\n";
814+
cmakeContent += "# libdoriax is searched in DORIAX_LIB_DIR; by default it points to the Doriax editor executable directory.\n";
812815
cmakeContent += "if(NOT DEFINED DORIAX_LIB_DIR OR DORIAX_LIB_DIR STREQUAL \"\")\n";
813816
cmakeContent += " set(DORIAX_LIB_DIR \"" + exePath.generic_string() + "\")\n";
814817
cmakeContent += " # Must be the same as the editor's library to not ODR violation / ABI mismatch\n";
@@ -845,6 +848,7 @@ void editor::Generator::writeSourceFiles(const fs::path& projectPath, const fs::
845848
// Build C++ source content
846849
std::string sourceContent;
847850
sourceContent += "// This file is auto-generated by Doriax Editor. Do not edit manually.\n\n";
851+
sourceContent += "// This file binds scene script metadata to compiled C++ and Lua scripts for the current build configuration.\n\n";
848852
sourceContent += "#include <vector>\n";
849853
sourceContent += "#include <string>\n";
850854
sourceContent += "#include <stdio.h>\n";
@@ -884,6 +888,38 @@ void editor::Generator::writeSourceFiles(const fs::path& projectPath, const fs::
884888
settingsContent += "}\n";
885889
FileUtils::writeIfChanged(settingsFile, settingsContent);
886890
}
891+
892+
fs::path agentsFile = projectPath / "AGENTS.md";
893+
std::string agentsContent;
894+
agentsContent += "<!-- This file is auto-generated by Doriax Editor. -->\n\n";
895+
agentsContent += "# Doriax Project Context\n\n";
896+
agentsContent += "This project was generated by Doriax Editor.\n\n";
897+
agentsContent += "## Source references\n\n";
898+
agentsContent += "- Runtime API headers used by this project (snapshot): `" + engineApiRelativePath.generic_string() + "`\n";
899+
agentsContent += "- Local engine API source used by this editor build: `" + (exePath / "engine").generic_string() + "`\n";
900+
agentsContent += "- Full engine **and editor** source (upstream): https://github.com/doriaxengine/doriax\n\n";
901+
agentsContent += "The two local paths above contain only the runtime engine API (what user code links against).\n";
902+
agentsContent += "They do **not** include the editor itself. To understand the YAML schema of `*.scene`, `*.bundle`, and `project.yaml`, or how the generator/factory produces C++, consult the upstream repository — specifically the `editor/` directory.\n\n";
903+
agentsContent += "## Generated files\n\n";
904+
agentsContent += "These files are produced by the editor when a scene is played/run and are intended for **in-editor testing only**. Project export/distribution uses a separate pipeline and does not reuse these files. Do not edit them manually — they will be overwritten on the next generation:\n\n";
905+
agentsContent += "- `CMakeLists.txt` (project root)\n";
906+
agentsContent += "- `" + relativeInternalPath.generic_string() + "/scene_scripts.cpp`\n";
907+
agentsContent += "- `" + relativeInternalPath.generic_string() + "/generated/` (scene factories, bundle factories, `main.cpp`, `PlatformEditor.h`, `PlatformEditor.cpp`)\n";
908+
agentsContent += "- `" + engineApiRelativePath.generic_string() + "/` (engine API snapshot copied from the editor)\n\n";
909+
agentsContent += "## Regenerating C++ code\n\n";
910+
agentsContent += "The generated C++ sources (scene factories, script bindings) are derived from `*.scene`, `*.bundle`, and `project.yaml` files.\n";
911+
agentsContent += "If you modify any `*.scene`, `*.bundle`, or `project.yaml` file, **you must return to Doriax Editor and play/run the scene** so the editor regenerates all C++ code under `" + relativeInternalPath.generic_string() + "/generated`.\n\n";
912+
agentsContent += "## C++ Scripts\n\n";
913+
agentsContent += "User C++ script files (`.h`/`.cpp`) can be placed anywhere in the project outside of `" + relativeInternalPath.generic_string() + "/`.\n";
914+
agentsContent += "Each script class must inherit from `doriax::Script`. "
915+
"The editor discovers and registers scripts automatically; "
916+
"they are added to `SCRIPT_SOURCES` in the generated `CMakeLists.txt` and compiled into the project.\n";
917+
agentsContent += "Lua scripts (`.lua`) are separate — they are loaded at runtime and are not compiled into the binary.\n\n";
918+
agentsContent += "## Build modes\n\n";
919+
agentsContent += "- **Editor mode** (`DORIAX_EDITOR_PLUGIN=ON`): builds as a shared library; `main.cpp` and Factory-generated scene sources are excluded. Used by the editor to hot-reload the project.\n";
920+
agentsContent += "- **Standalone mode** (`DORIAX_EDITOR_PLUGIN=OFF`, default): builds as an executable; includes `main.cpp` and all Factory sources. This standalone build is for local testing only — production distribution uses the editor's separate export pipeline.\n";
921+
922+
FileUtils::writeIfChanged(agentsFile, agentsContent);
887923
}
888924

889925
void editor::Generator::terminateCurrentProcess() {

0 commit comments

Comments
 (0)