mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-15 01:07:58 -05:00
render zoneload header
This commit is contained in:
@ -1,7 +1,176 @@
|
||||
#include "ZoneLoadTemplate.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
static std::string LoaderClassName(StructureInformation* asset)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Loader_" << asset->m_definition->m_name;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
static std::string VariableDecl(const DataDefinition* def)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << def->GetFullName() << "* var" << SafeTypeName(def) << ";";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
static std::string PointerVariableDecl(const DataDefinition* def)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << def->GetFullName() << "** var" << SafeTypeName(def) << "Ptr;";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void PrintHeaderPtrArrayLoadMethodDeclaration(const DataDefinition* def) const
|
||||
{
|
||||
LINE("void LoadPtrArray_"<<SafeTypeName(def)<<"(bool atStreamStart, size_t count);")
|
||||
}
|
||||
|
||||
void PrintHeaderArrayLoadMethodDeclaration(const DataDefinition* def) const
|
||||
{
|
||||
LINE("void LoadArray_"<<SafeTypeName(def)<<"(bool atStreamStart, size_t count);")
|
||||
}
|
||||
|
||||
void PrintHeaderLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void Load_"<<SafeTypeName(info->m_definition)<<"(bool atStreamStart);")
|
||||
}
|
||||
|
||||
void PrintHeaderTempPtrLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void LoadPtr_"<<SafeTypeName(info->m_definition)<<"(bool atStreamStart);")
|
||||
}
|
||||
|
||||
void PrintHeaderAssetLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void LoadAsset_"<<SafeTypeName(info->m_definition)<<"("<<info->m_definition->GetFullName()<<"** pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderGetNameMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("static std::string GetAssetName("<<info->m_definition->GetFullName()<<"* pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderMainLoadMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("XAssetInfo<"<<info->m_definition->GetFullName()<<">* Load("<<info->m_definition->GetFullName()<<"** pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINE(LoaderClassName(m_env.m_asset)<<"(Zone* zone, IZoneInputStream* stream);")
|
||||
}
|
||||
|
||||
public:
|
||||
Internal(std::ostream& stream, RenderingContext* context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
|
||||
void Header()
|
||||
{
|
||||
LINE("// ====================================================================")
|
||||
LINE("// This file has been generated by ZoneCodeGenerator.")
|
||||
LINE("// Do not modify. ")
|
||||
LINE("// Any changes will be discarded when regenerating.")
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINE("#pragma once")
|
||||
LINE("")
|
||||
LINE("#include \"Loading/AssetLoader.h\"")
|
||||
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"")
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINE("#include \"Game/" << m_env.m_game << "/XAssets/" << Lower(m_env.m_asset->m_definition->m_name) << "/" << Lower(m_env.m_asset->m_definition->m_name) << "_actions.h\"")
|
||||
}
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
LINE("namespace " << m_env.m_game)
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
LINE("class " << LoaderClassName(m_env.m_asset) << " final : public AssetLoader")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("XAssetInfo<"<<m_env.m_asset->m_definition->GetFullName()<<">* m_asset_info;")
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINE("Actions_"<<m_env.m_asset->m_definition->m_name<<" m_actions;")
|
||||
}
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type));
|
||||
}
|
||||
}
|
||||
for (auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type));
|
||||
}
|
||||
}
|
||||
|
||||
LINE("")
|
||||
|
||||
// Method Declarations
|
||||
for (auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists)
|
||||
{
|
||||
PrintHeaderPtrArrayLoadMethodDeclaration(type->m_type);
|
||||
}
|
||||
}
|
||||
for (auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_array_reference_exists && type->m_info && !type->m_info->m_is_leaf && type->m_non_runtime_reference_exists)
|
||||
{
|
||||
PrintHeaderArrayLoadMethodDeclaration(type->m_type);
|
||||
}
|
||||
}
|
||||
for (auto* type : m_env.m_used_structures)
|
||||
{
|
||||
if (type->m_non_runtime_reference_exists && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
PrintHeaderLoadMethodDeclaration(type->m_info);
|
||||
}
|
||||
}
|
||||
PrintHeaderLoadMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderTempPtrLoadMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderAssetLoadMethodDeclaration(m_env.m_asset);
|
||||
LINE("")
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainLoadMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderGetNameMethodDeclaration(m_env.m_asset);
|
||||
|
||||
m_intendation--;
|
||||
LINE("};")
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void Source()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(RenderingContext* context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
@ -27,13 +196,18 @@ std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(RenderingContex
|
||||
|
||||
void ZoneLoadTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
{
|
||||
Internal internal(stream, context);
|
||||
|
||||
if (fileTag == TAG_HEADER)
|
||||
{
|
||||
internal.Header();
|
||||
}
|
||||
else if (fileTag == TAG_SOURCE)
|
||||
{
|
||||
internal.Source();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown tag for ZoneLoadTemplate: " << fileTag << "\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user