Added SceneItemComponent registry (unfinished)
This commit is contained in:
@ -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)
|
||||
|
@ -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}
|
||||
)
|
@ -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;
|
||||
}
|
@ -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;
|
||||
};
|
||||
}
|
@ -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, "", " ");
|
||||
|
Reference in New Issue
Block a user