From b103ede28c8210186ede6965971319aac467a4ca Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Sat, 29 Feb 2020 14:43:07 -0800 Subject: [PATCH] Made the meta system put generated files relative to the root file rather than at an absolute path --- meta/foldhaus_meta.cpp | 41 ++++++++++++++++++++-- src/generated/gs_meta_genreated_typeinfo.h | 32 +++++++++++++++++ todo.txt | 3 +- 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/generated/gs_meta_genreated_typeinfo.h diff --git a/meta/foldhaus_meta.cpp b/meta/foldhaus_meta.cpp index f7cacba..1d8f85b 100644 --- a/meta/foldhaus_meta.cpp +++ b/meta/foldhaus_meta.cpp @@ -254,6 +254,19 @@ GeneratePanelMetaInfo(gs_meta_preprocessor Meta, string_builder* PanelCodeGen) WriteF(PanelCodeGen, "};\n"); } +internal string +AllocAndConcatStrings(string First, string Second) +{ + string Result = {0}; + Result.Max = First.Length + Second.Length + 1; + Result.Memory = (char*)malloc(sizeof(char) * Result.Max); + ConcatString(First, &Result); + ConcatString(Second, &Result); + NullTerminate(&Result); + Result.Length -= 1; + return Result; +} + int main(int ArgCount, char* Args[]) { if (ArgCount <= 1) @@ -262,6 +275,13 @@ int main(int ArgCount, char* Args[]) return 0; } + string RootFile = MakeString(Args[1]); + s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/"); + string WorkingDirectory = Substring(RootFile, 0, IndexOfLastSlash + 1); + string GeneratedDirectoryName = MakeStringLiteral("generated\\"); + string GeneratedFilesDirectory = AllocAndConcatStrings(WorkingDirectory, GeneratedDirectoryName); + printf("Putting Generated Files In %s\n", GeneratedFilesDirectory.Memory); + gs_meta_preprocessor Meta = PreprocessProgram(Args[1]); typeinfo_generator TypeGenerator = InitTypeInfoGenerator(Meta.TypeTable); @@ -278,7 +298,8 @@ int main(int ArgCount, char* Args[]) string_builder PanelCodeGen = {0}; GeneratePanelMetaInfo(Meta, &PanelCodeGen); - FILE* TypeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\gs_meta_generated_typeinfo.h", "w"); + string TypeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("gs_meta_genreated_typeinfo.h")); + FILE* TypeInfoH = fopen(TypeInfoHFilePath.Memory, "w"); if (TypeInfoH) { WriteStringBuilderToFile(TypeGenerator.MetaTagEnum, TypeInfoH); @@ -288,8 +309,13 @@ int main(int ArgCount, char* Args[]) WriteStringBuilderToFile(TypeGenerator.TypeDefinitions, TypeInfoH); fclose(TypeInfoH); } + else + { + printf("Error: Unable to open file at %.*s\n", StringExpand(TypeInfoHFilePath)); + } - FILE* NodeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.h", "w"); + string NodeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_nodes_generated.h")); + FILE* NodeInfoH = fopen(TypeInfoHFilePath.Memory, "w"); if (NodeInfoH) { WriteStringBuilderToFile(*NodeTypeGen.Builder, NodeInfoH); @@ -297,13 +323,22 @@ int main(int ArgCount, char* Args[]) WriteStringBuilderToFile(CallNodeProcGen, NodeInfoH); fclose(NodeInfoH); } + else + { + printf("Error: Unable to open file at %.*s\n", StringExpand(NodeInfoHFilePath)); + } - FILE* PanelInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_panels_generated.h", "w"); + string PanelInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_panels_generated.h")); + FILE* PanelInfoH = fopen(PanelInfoHFilePath.Memory, "w"); if (PanelInfoH) { WriteStringBuilderToFile(PanelCodeGen, PanelInfoH); fclose(PanelInfoH); } + else + { + printf("Error: Unable to open file at %.*s\n", StringExpand(PanelInfoHFilePath)); + } FinishMetaprogram(&Meta); diff --git a/src/generated/gs_meta_genreated_typeinfo.h b/src/generated/gs_meta_genreated_typeinfo.h new file mode 100644 index 0000000..f72b4bb --- /dev/null +++ b/src/generated/gs_meta_genreated_typeinfo.h @@ -0,0 +1,32 @@ +enum node_type +{ + NodeType_RevolvingDiscs, + NodeType_SolidColorProc, + NodeType_VerticalColorFadeProc, + NodeType_Count, +}; + +static node_specification_ NodeSpecifications[] = { +{ NodeType_RevolvingDiscs, {"RevolvingDiscs", 14}, gsm_StructType_revolving_discs_data }, +{ NodeType_SolidColorProc, {"SolidColorProc", 14}, gsm_StructType_solid_color_data }, +{ NodeType_VerticalColorFadeProc, {"VerticalColorFadeProc", 21}, gsm_StructType_vertical_color_fade_data }, +}; + +void CallNodeProc(node_type Type, u8* NodeData) +{ + switch(Type) { + case NodeType_RevolvingDiscs: + { + RevolvingDiscs((revolving_discs_data*)NodeData); + } break; + case NodeType_SolidColorProc: + { + SolidColorProc((solid_color_data*)NodeData); + } break; + case NodeType_VerticalColorFadeProc: + { + VerticalColorFadeProc((vertical_color_fade_data*)NodeData); + } break; + } +} + diff --git a/todo.txt b/todo.txt index 080fbf7..c6a27ca 100644 --- a/todo.txt +++ b/todo.txt @@ -2,8 +2,9 @@ TODO FOLDHAUS Ground Up Reengineering - Metaprogramming - - panels metaprogramming + x panels metaprogramming - fix memory layout (remeber to profile before and after) + x get the meta program to generate code in the codebase's directory, no matter where it is - Make the DLL truly platform agnostic - math.h: present for trig functions