Added SceneItemComponent registry (unfinished)

This commit is contained in:
2023-02-23 23:43:13 -08:00
parent 5dcf20a282
commit bc972cbb57
16 changed files with 289 additions and 8 deletions

View File

@ -20,6 +20,7 @@ project(Dawn
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}")
set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools")
set(DAWN_SOURCES_DIR "${DAWN_ROOT_DIR}/src")
set(DAWN_ASSETS_SOURCE_DIR "${DAWN_ROOT_DIR}/assets")
set(DAWN_ASSETS_BUILD_DIR "${DAWN_BUILD_DIR}/assets")
set(DAWN_GENERATED_DIR "${DAWN_BUILD_DIR}/generated")

View File

@ -14,6 +14,7 @@
#include "locale/LocaleManager.hpp"
#include "save/SaveManager.hpp"
#include "audio/AudioManager.hpp"
#include "scene/SceneItemComponentListItems.hpp"
#define DAWN_GAME_INIT_RESULT_SUCCESS 0
#define DAWN_GAME_UPDATE_RESULT_SUCCESS 0
@ -23,6 +24,9 @@ namespace Dawn {
class DawnHost;
class IDawnGame {
protected:
SceneItemComponentListItems componentListItems;
public:
Scene *scene = nullptr;

View File

@ -9,6 +9,7 @@ target_sources(${DAWN_TARGET_NAME}
Scene.cpp
SceneItem.cpp
SceneItemComponent.cpp
SceneItemComponentList.cpp
)
# Subdirs

View File

@ -0,0 +1,8 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SceneItemComponentList.hpp"
using namespace Dawn;

View File

@ -0,0 +1,25 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct SceneItemComponentRegister {
int32_t i;
};
class SceneItemComponentList {
private:
std::vector<struct SceneItemComponentRegister> components;
protected:
template<class T>
void append() {
struct SceneItemComponentRegister r;
this->components.push_back(r);
}
};
}

View File

@ -14,4 +14,13 @@ target_sources(${DAWN_TARGET_NAME}
PixelPerfectCamera.cpp
TiledSprite.cpp
SimpleRenderTargetQuad.cpp
)
)
tool_scenecomponent(AnimationController scene/components/display/AnimationController.hpp)
tool_scenecomponent(Camera scene/components/display/Camera.hpp)
tool_scenecomponent(Material scene/components/display/Material.hpp)
tool_scenecomponent(MeshHost scene/components/display/MeshHost.hpp)
tool_scenecomponent(MeshRenderer scene/components/display/MeshRenderer.hpp)
tool_scenecomponent(PixelPerfectCamera scene/components/display/PixelPerfectCamera.hpp)
tool_scenecomponent(TiledSprite scene/components/display/TiledSprite.hpp)
tool_scenecomponent(SimpleRenderTargetQuad scene/components/display/SimpleRenderTargetQuad.hpp)

View File

@ -7,4 +7,6 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
ExampleSpin.cpp
)
)
tool_scenecomponent(ExampleSpin scene/components/example/ExampleSpin.hpp)

View File

@ -8,4 +8,7 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
Collider3D.cpp
CubeCollider.cpp
)
)
tool_scenecomponent(Collider3D scene/components/physics/3d/collider/Collider3D.hpp)
tool_scenecomponent(CubeCollider scene/components/physics/3d/collider/CubeCollider.hpp)

View File

@ -8,4 +8,7 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
SubSceneCameraAlign.cpp
SubSceneController.cpp
)
)
tool_scenecomponent(SubSceneCameraAlign scene/components/scene/SubSceneCameraAlign.hpp)
tool_scenecomponent(SubSceneController scene/components/scene/SubSceneController.hpp)

View File

@ -7,4 +7,6 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
UICanvas.cpp
)
)
tool_scenecomponent(UICanvas scene/components/ui/UICanvas.hpp)

View File

@ -8,4 +8,7 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
SimpleVisualNovelBackground.cpp
VisualNovelCharacter.cpp
)
)
tool_scenecomponent(SimpleVisualNovelBackground visualnovel/components/SimpleVisualNovelBackground.hpp)
tool_scenecomponent(VisualNovelCharacter visualnovel/components/VisualNovelCharacter.hpp)

View File

@ -10,9 +10,11 @@ add_subdirectory(uigen)
add_subdirectory(languagegen)
add_subdirectory(audiogen)
add_subdirectory(generatedlanguages)
add_subdirectory(sceneitemcomponentregister)
# Settings
set(DAWN_TOOL_GENERATED_LANG_DIR "${DAWN_TEMP_DIR}/languages" CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_SCENE_ITEM_COMPONENT_LIST "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Texture Tool
function(tool_texture target in)
@ -66,7 +68,6 @@ function(tool_generatedlanguages in)
COMMENT "Generating all languages"
DEPENDS generatedlanguagestool
)
if(NOT generatedlanguages IN_LIST DAWN_TARGET_DEPENDENCIES_LAST)
set(
DAWN_TARGET_DEPENDENCIES_LAST
@ -97,6 +98,40 @@ function(tool_audio target in)
add_dependencies(${DAWN_TARGET_NAME} ${target})
endfunction()
# Scene Item Component Tool
function(tool_scenecomponent clazz hfile)
add_custom_target(${clazz}_scenecomponent
COMMENT "Registering component ${hfile}::${clazz}"
DEPENDS ${ARGN}
)
set(
DAWN_SCENE_ITEM_COMPONENT_LIST
${DAWN_SCENE_ITEM_COMPONENT_LIST}
${clazz}
${hfile}
CACHE INTERNAL ${DAWN_CACHE_TARGET}
)
file(CONFIGURE OUTPUT
"${DAWN_TEMP_DIR}/SceneItemComponents.txt"
CONTENT "${DAWN_SCENE_ITEM_COMPONENT_LIST}"
)
if(NOT TARGET sceneitemcomponentgen_cmd)
add_custom_target(sceneitemcomponentgen_cmd
COMMAND sceneitemcomponentgen --input="${DAWN_TEMP_DIR}/SceneItemComponents.txt" --output="${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.hpp"
COMMENT "Generating scene item component ${hfile}::${clazz}"
DEPENDS sceneitemcomponentgen
)
endif()
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${DAWN_GENERATED_DIR}
)
add_dependencies(sceneitemcomponentgen ${clazz}_scenecomponent)
add_dependencies(${DAWN_TARGET_NAME} sceneitemcomponentgen_cmd)
endfunction()
if(DAWN_VISUAL_NOVEL)
add_subdirectory(vnscenegen)

View File

@ -0,0 +1,36 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
project(sceneitemcomponentgen VERSION 1.0)
add_executable(sceneitemcomponentgen)
# Sources
target_sources(sceneitemcomponentgen
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
SceneItemComponentRegister.cpp
)
# Includes
target_include_directories(sceneitemcomponentgen
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(sceneitemcomponentgen
PUBLIC
DAWN_TOOL_INSTANCE=SceneItemComponentRegister
DAWN_TOOL_HEADER="SceneItemComponentRegister.hpp"
)
# Libraries
target_link_libraries(sceneitemcomponentgen
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)

View File

@ -0,0 +1,113 @@
/**
* Copyright (c) 2023 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "SceneItemComponentRegister.hpp"
using namespace Dawn;
void SceneItemComponentRootGen::generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs = ""
) {
struct ClassGenInfo clazz;
clazz.clazz = "SceneItemComponentListItems";
clazz.extend = "SceneItemComponentList";
clazz.includes.push_back("#include \"scene/SceneItemComponentList.hpp\"");
auto it = info->begin();
while(it != info->end()) {
auto c = *it;
clazz.includes.push_back("#include \"" + c.header + "\"");
line(&clazz.constructorCode, "this->append<" + c.clazz + ">();", "");
++it;
}
classGen(out, clazz);
}
std::vector<std::string> SceneItemComponentRegister::getRequiredFlags() {
return std::vector<std::string>{ "input", "output" };
}
int32_t SceneItemComponentRegister::start() {
File fileIn(flags["input"]);
if(!fileIn.exists()) {
std::cout << "Input scene item component file does not exist." << std::endl;
return 1;
}
std::string buffer;
if(!fileIn.readString(&buffer)) {
std::cout << "Failed to read input scene item component file" << std::endl;
return 1;
}
std::vector<struct SceneItemComponent> components;
struct SceneItemComponent sci;
size_t i = 0;
std::string t;
uint8_t state = 0x00;
while(i < buffer.size()) {
char c = buffer[i++];
if(c != ';') {
t.push_back(c);
continue;
}
switch(state) {
case 0x00:
sci.clazz = t;
t.clear();
state = 0x01;
break;
case 0x01:
sci.header = t;
t.clear();
state = 0x00;
components.push_back(sci);
break;
default:
assertUnreachable();
}
}
if(state == 0x01) {
sci.header = t;
components.push_back(sci);
} else {
assertUnreachable();
}
std::vector<std::string> lines;
SceneItemComponentRootGen::generate(&lines, &components, "");
// Generate buffer
std::string bufferOut;
auto itLine = lines.begin();
while(itLine != lines.end()) {
bufferOut += *itLine + "\n";
++itLine;
}
File fileOut(flags["output"]);
if(!fileOut.mkdirp()) {
std::cout << "Failed to create Scene Item Component List Dir" << std::endl;
return 1;
}
if(!fileOut.writeString(bufferOut)) {
std::cout << "Failed to write SceneItemComponentList file" << std::endl;
return 1;
}
return 0;
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/DawnTool.hpp"
#include "util/File.hpp"
#include "util/CodeGen.hpp"
namespace Dawn {
struct SceneItemComponent {
std::string clazz;
std::string header;
};
class SceneItemComponentRootGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
std::vector<struct SceneItemComponent> *info,
std::string tabs
);
};
class SceneItemComponentRegister : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
public:
int32_t start() override;
};
}

View File

@ -14,6 +14,8 @@ namespace Dawn {
std::string constructorArgs = "";
std::string extendArgs = "";
std::vector<std::string> constructorCode;
std::vector<std::string> protectedCode;
std::vector<std::string> protectedProperties;
@ -73,11 +75,12 @@ namespace Dawn {
lines(out, info.protectedCode, " ");
}
if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0) {
if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) {
line(out, "public:", " ");
lines(out, info.publicProperties, " ");
line(out, "", " ");
line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " ");
lines(out, info.constructorCode, " ");
line(out, "}", " ");
if(info.publicCode.size() > 0) {
line(out, "", " ");