Moved C++ tools out

This commit is contained in:
2023-10-31 21:15:03 -05:00
parent f8a715ec78
commit 343f75433e
98 changed files with 5 additions and 16 deletions

View File

@ -0,0 +1,61 @@
# Copyright (c) 2023 Dominic Msters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Texture Build Tool
project(scenetool VERSION 1.0)
add_executable(scenetool)
# Subdirs
# Sources
target_sources(scenetool
PRIVATE
${DAWN_SHARED_SOURCES}
${DAWN_TOOL_SOURCES}
SceneTool.cpp
SceneGen.cpp
)
# Includes
target_include_directories(scenetool
PUBLIC
${DAWN_SHARED_INCLUDES}
${DAWN_TOOL_INCLUDES}
${CMAKE_CURRENT_LIST_DIR}
)
# Definitions
target_compile_definitions(scenetool
PUBLIC
${DAWN_SHARED_DEFINITIONS}
DAWN_TOOL_INSTANCE=SceneTool
DAWN_TOOL_HEADER="SceneTool.hpp"
)
# Libraries
target_link_libraries(scenetool
PUBLIC
${DAWN_BUILD_HOST_LIBS}
)
# Tool Function
function(tool_scene in)
set(DEPS "")
if(DAWN_BUILD_TOOLS)
set(DEPS scenetool)
endif()
STRING(REGEX REPLACE "[\.|\\|\/|\:]" "-" scene_name ${in})
add_custom_target(scene_${scene_name}
COMMAND scenetool --input="${in}" --output="${DAWN_GENERATED_DIR}/generatedscenes" --sources="${DAWN_SOURCES_DIR}"
COMMENT "Generating scene from ${in}"
DEPENDS ${DEPS}
)
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${DAWN_GENERATED_DIR}/generatedscenes
)
add_dependencies(${DAWN_TARGET_NAME} scene_${scene_name})
endfunction()

View File

@ -0,0 +1,32 @@
// 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;
struct MethodGenInfo methodAssets;
struct MethodGenInfo methodInit;
SceneGenerator::generate(
scene,
classInfo,
methodAssets,
methodInit
);
// Add in methods
CodeGen::methodGen(&classInfo.publicCode, methodAssets);
line(&classInfo.publicCode, "", "");
CodeGen::methodGen(&classInfo.publicCode, methodInit);
CodeGen::classGen(out, classInfo);
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "util/generator/SceneGenerator.hpp"
namespace Dawn {
class SceneGen : public CodeGen {
public:
static void generate(
std::vector<std::string> *out,
struct Scene *scene,
std::string tabs
);
};
}

View File

@ -0,0 +1,69 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SceneTool.hpp"
using namespace Dawn;
std::vector<std::string> SceneTool::getRequiredFlags() {
return { "input", "output", "sources" };
}
std::map<std::string, std::string> SceneTool::getOptionalFlags() {
return std::map<std::string, std::string>();
}
int32_t SceneTool::start() {
File input = File(flags["input"]);
if(!input.exists()) {
std::cout << "Input file " + input.filename + " does not exist!" << std::endl;
return 1;
}
std::string data;
if(!input.readString(&data)) {
std::cout << "Failed to read input file!" << std::endl;
return 1;
}
auto xml = Xml::load(data);
std::string error;
struct Scene scene;
struct SceneItemComponentRegistry registry;
registry.sources = File::normalizeSlashes(flags["sources"]);
scene.registry = &registry;
auto result = ((SceneParser()).parse(&xml, &scene, &error));
if(result != 0) {
std::cout << "Failed to parse scene " << input.filename << "::" << error << std::endl;
return result;
}
// Generate output
std::vector<std::string> outputData;
SceneGen::generate(&outputData, &scene, "");
// Load output file from name and type
File outputFile = File(flags["output"] + "/scenes/" + scene.name + ".hpp");
if(!outputFile.mkdirp()) {
std::cout << "Failed to create output directory!" << std::endl;
return 1;
}
// Combine vector into single string
std::string outputDataStr = "";
auto it = outputData.begin();
while(it != outputData.end()) {
outputDataStr += *it + "\n";
++it;
}
if(!outputFile.writeString(outputDataStr)) {
std::cout << "Failed to write output file! " << input.filename << std::endl;
return 1;
}
return 0;
}

View File

@ -0,0 +1,22 @@
// 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/Xml.hpp"
#include "util/parser/SceneParser.hpp"
#include "SceneGen.hpp"
namespace Dawn {
class SceneTool : public DawnTool {
protected:
std::vector<std::string> getRequiredFlags() override;
std::map<std::string, std::string> getOptionalFlags() override;
public:
int32_t start();
};
}