Added a great scene generator
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
<scene name="SceneBase">
|
||||
<item ref="eth" prefab="preafbs/characters/EthPrefab" />
|
||||
|
||||
<item ref="camNew">
|
||||
<Camera fov="0.436332" />
|
||||
<CameraTexture />
|
||||
<scene name="TestScene">
|
||||
<item position="0, 0, -10" >
|
||||
<Camera fov="0.436332" ref="camNew" />
|
||||
<!-- <CameraTexture /> -->
|
||||
</item>
|
||||
|
||||
<item ref="canvasItem">
|
||||
<item ref="eth" prefab="prefabs/EthPrefab" />
|
||||
|
||||
<!-- <item ref="canvasItem">
|
||||
<UICanvas ref="canvas" />
|
||||
<item ref="textbox" prefab="prefabs/VNTextbox" />
|
||||
|
||||
@ -14,10 +14,10 @@
|
||||
<UIImage
|
||||
alignment="0, 0, 50, 0"
|
||||
alignX="UI_COMPONENT_ALIGN_START"
|
||||
alignUnitRight="UI_COMPONENT_ALIGN_UNIT_PERCENTAGE"
|
||||
alignUnitRight="UI_COMPONENT_ALIGN_UNIT_PERCENT"
|
||||
alignY="UI_COMPONENT_ALIGN_STRETCH"
|
||||
ref="image"
|
||||
/>
|
||||
</item>
|
||||
</item>
|
||||
</item> -->
|
||||
</scene>
|
@ -19,7 +19,7 @@ add_subdirectory(save)
|
||||
# Assets
|
||||
set(LIMINAL_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/liminal)
|
||||
tool_scene(${LIMINAL_ASSETS_DIR}/scenes/scene-base.xml)
|
||||
tool_vnscene(${LIMINAL_ASSETS_DIR}/test.xml)
|
||||
# tool_vnscene(${LIMINAL_ASSETS_DIR}/test.xml)
|
||||
|
||||
tool_prefab(${LIMINAL_ASSETS_DIR}/VNTextbox.xml)
|
||||
tool_truetype(font_main ${DAWN_ASSETS_DIR}/ark-pixel.ttf)
|
||||
|
@ -5,11 +5,11 @@
|
||||
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "scenes/HelloWorldScene.hpp"
|
||||
#include "vnscenes/TestScene.hpp"
|
||||
#include "scenes/TestScene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
|
||||
return new HelloWorldScene(game);
|
||||
// return new TestScene(game);
|
||||
// return new HelloWorldScene(game);
|
||||
return new TestScene(game);
|
||||
}
|
@ -48,6 +48,7 @@ void PrefabGen::generate(
|
||||
&methodInit.body,
|
||||
&methodAssets.body,
|
||||
"",
|
||||
"scene",
|
||||
&info->root,
|
||||
""
|
||||
);
|
||||
|
@ -16,6 +16,7 @@ target_sources(scenetool
|
||||
${DAWN_TOOL_SOURCES}
|
||||
SceneTool.cpp
|
||||
SceneParser.cpp
|
||||
SceneGen.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
69
src/dawntools/scenetool/SceneGen.cpp
Normal file
69
src/dawntools/scenetool/SceneGen.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneGen.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SceneGen::generate(
|
||||
std::vector<std::string> *out,
|
||||
struct Scene *scene,
|
||||
std::string tabs
|
||||
) {
|
||||
struct ClassGenInfo classInfo;
|
||||
classInfo.clazz = scene->name;
|
||||
classInfo.extend = "Scene";
|
||||
classInfo.constructorArgs = "DawnGame *game";
|
||||
classInfo.extendArgs = "game";
|
||||
|
||||
struct MethodGenInfo methodAssets;
|
||||
methodAssets.name = "getRequiredAssets";
|
||||
methodAssets.isOverride = true;
|
||||
methodAssets.type = "std::vector<Asset*>";
|
||||
line(&methodAssets.body, "auto assMan = &this->game->assetManager;", "");
|
||||
line(&methodAssets.body, "std::vector<Asset*> assets;", "");
|
||||
|
||||
struct MethodGenInfo methodInit;
|
||||
methodInit.name = "stage";
|
||||
methodInit.isOverride = true;
|
||||
|
||||
classInfo.includes.push_back("scene/Scene.hpp");
|
||||
|
||||
|
||||
// Generate
|
||||
int32_t assetNumber = 0;
|
||||
int32_t childNumber = 0;
|
||||
int32_t componentNumber = 0;
|
||||
std::map<std::string, std::string> assetMap;
|
||||
|
||||
auto sceneItems = scene->items.begin();
|
||||
while(sceneItems != scene->items.end()) {
|
||||
SceneItemGenerator::generate(
|
||||
assetNumber,
|
||||
componentNumber,
|
||||
childNumber,
|
||||
assetMap,
|
||||
classInfo.includes,
|
||||
&classInfo.publicProperties,
|
||||
&methodInit.body,
|
||||
&methodAssets.body,
|
||||
"",
|
||||
"this",
|
||||
&(*sceneItems),
|
||||
""
|
||||
);
|
||||
++sceneItems;
|
||||
}
|
||||
|
||||
// Seal methods
|
||||
line(&methodAssets.body, "return assets;", "");
|
||||
|
||||
// Add in methods
|
||||
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
|
||||
line(&classInfo.publicCode, "", "");
|
||||
CodeGen::methodGen(&classInfo.publicCode, methodInit);
|
||||
|
||||
CodeGen::classGen(out, classInfo);
|
||||
}
|
19
src/dawntools/scenetool/SceneGen.hpp
Normal file
19
src/dawntools/scenetool/SceneGen.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneParser.hpp"
|
||||
#include "util/generator/SceneItemGenerator.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneGen : public CodeGen {
|
||||
public:
|
||||
static void generate(
|
||||
std::vector<std::string> *out,
|
||||
struct Scene *scene,
|
||||
std::string tabs
|
||||
);
|
||||
};
|
||||
}
|
@ -42,10 +42,9 @@ int32_t SceneTool::start() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Generate output
|
||||
std::vector<std::string> outputData;
|
||||
// VNSceneGen::generate(&outputData, &scene, "");
|
||||
SceneGen::generate(&outputData, &scene, "");
|
||||
|
||||
// Load output file from name and type
|
||||
File outputFile = File(flags["output"] + "/scenes/TestScene.hpp");
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "util/File.hpp"
|
||||
#include "util/Xml.hpp"
|
||||
#include "SceneParser.hpp"
|
||||
#include "SceneGen.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneTool : public DawnTool {
|
||||
|
@ -17,23 +17,42 @@ void SceneItemGenerator::generate(
|
||||
std::vector<std::string> *initBody,
|
||||
std::vector<std::string> *assetBody,
|
||||
std::string parentRef,
|
||||
std::string sceneRef,
|
||||
struct SceneItem *item,
|
||||
std::string tabs
|
||||
) {
|
||||
auto name = "itm" + std::to_string(childNumber++);
|
||||
// Determine interface
|
||||
std::string name = "itm" + std::to_string(childNumber++);
|
||||
std::string itemType = "SceneItem";
|
||||
|
||||
if(item->ref == "this") {
|
||||
name = item->ref;
|
||||
} else {
|
||||
bool_t init = true;
|
||||
if(item->ref.size() > 0) {
|
||||
init = false;
|
||||
name = item->ref;
|
||||
if(item->ref != "this") {
|
||||
line(publicProperties, "SceneItemComponent *" + name + " = nullptr;", "");
|
||||
// Determine name
|
||||
if(!item->ref.empty()) name = item->ref;
|
||||
|
||||
// Initialize, either prefab or created.
|
||||
if(!item->prefab.empty()) {
|
||||
// Determine prefab name, type and include
|
||||
std::string prefabName = item->prefab;
|
||||
if(prefabName.find("/") != std::string::npos) {
|
||||
prefabName = prefabName.substr(prefabName.find_last_of("/") + 1);
|
||||
}
|
||||
itemType = prefabName;
|
||||
|
||||
// Create prefab
|
||||
includes.push_back(item->prefab + ".hpp");
|
||||
line(initBody, (item->ref.empty() ? "auto " : "") + name + " = " + prefabName + "::create(" + sceneRef + ");", "");
|
||||
line(assetBody, "vectorAppend(&assets, " + prefabName + "::getRequiredAssets(assMan));", "");
|
||||
} else {
|
||||
// Not a prefab, init empty child.
|
||||
line(initBody, (item->ref.empty() ? "auto " : "") + name + " = " + sceneRef + "->createSceneItem();", "");
|
||||
}
|
||||
|
||||
// Property/Ref defintion
|
||||
if(!item->ref.empty() && item->ref != "this") {
|
||||
line(publicProperties, itemType + " *" + name + " = nullptr;", "");
|
||||
}
|
||||
line(initBody, (init ? "auto " : "") + name + " = scene->createSceneItem();", "");
|
||||
}
|
||||
|
||||
// Process extra properties
|
||||
@ -88,6 +107,7 @@ void SceneItemGenerator::generate(
|
||||
initBody,
|
||||
assetBody,
|
||||
name,
|
||||
sceneRef,
|
||||
&(*itChildren),
|
||||
""
|
||||
);
|
||||
|
@ -21,6 +21,7 @@ namespace Dawn {
|
||||
std::vector<std::string> *initBody,
|
||||
std::vector<std::string> *assetBody,
|
||||
std::string parentRef,
|
||||
std::string sceneRef,
|
||||
struct SceneItem *item,
|
||||
std::string tabs
|
||||
);
|
||||
|
@ -15,7 +15,8 @@ std::map<std::string, std::string> SceneItemParser::getOptionalAttributes() {
|
||||
return {
|
||||
{ "ref", "" },
|
||||
{ "position", "" },
|
||||
{ "scale", "" }
|
||||
{ "scale", "" },
|
||||
{ "prefab", "" }
|
||||
};
|
||||
}
|
||||
|
||||
@ -37,6 +38,8 @@ int32_t SceneItemParser::onParse(
|
||||
if(error->size() > 0) return 1;
|
||||
}
|
||||
|
||||
out->prefab = values["prefab"];
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
// Parse child nodes, they may be components or not
|
||||
|
@ -13,6 +13,7 @@ namespace Dawn {
|
||||
std::string ref;
|
||||
std::string position;
|
||||
std::string scale;
|
||||
std::string prefab;
|
||||
std::vector<struct SceneItemComponent> components;
|
||||
std::vector<struct SceneItem> children;
|
||||
std::vector<struct SceneAsset> assets;
|
||||
|
Reference in New Issue
Block a user