Updated the meta parser, and ifdef'd out a bunch of old node related code.

This commit is contained in:
Peter Slattery 2019-12-31 13:15:28 -08:00
parent 7545e3bbd0
commit 744a1c6c92
8 changed files with 139 additions and 1409 deletions

View File

@ -16,10 +16,7 @@ set CommonLinkerFlags= -opt:ref
pushd build pushd build
del *.pdb > NUL 2> NUL cl %CommonCompilerFlags% -IC:\programs-dev\gs_libs\src ..\meta\foldhaus_meta.cpp /link %CommonLinkerFlags%
REM cl %CommonCompilerFlags% ..\meta\main_meta.cpp /link %CommonLinkerFlags% user32.lib winmm.lib gdi32.lib -incremental:no
cl %CommonCompilerFlags% ..\meta\foldhaus_meta.cpp /link %CommonLinkerFlags%
C:\programs\ctime\ctime.exe -end C:\projects\foldhaus\build\win32_gs_meta_build_time.ctm %LastError% C:\programs\ctime\ctime.exe -end C:\projects\foldhaus\build\win32_gs_meta_build_time.ctm %LastError%
C:\programs\ctime\ctime.exe -stats C:\projects\foldhaus\build\win32_gs_meta_build_time.ctm C:\programs\ctime\ctime.exe -stats C:\projects\foldhaus\build\win32_gs_meta_build_time.ctm

View File

@ -1,21 +1,19 @@
#include "..\src\gs_language.h" #include <windows.h>
#include "..\src\foldhaus_memory.h" #include <stdio.h>
#include <gs_language.h>
#include "..\src\gs_platform.h"
#include <gs_memory_arena.h>
#include "..\src\gs_string.h" #include "..\src\gs_string.h"
#include "gs_meta_error.h" #include "gs_meta_error.h"
#include "gs_meta_lexer.h" #include "gs_meta_lexer.h"
#include <windows.h>
#include <stdio.h>
error_list GlobalErrorList = {}; error_list GlobalErrorList = {};
PLATFORM_ALLOC(StdAlloc) PLATFORM_ALLOC(StdAlloc)
{ {
platform_memory_result Result = {}; u8* Result = (u8*)malloc(Size);
Result.Base = (u8*)malloc(Size);
Result.Size = Size;
Result.Error = 0;
return Result; return Result;
} }
@ -26,12 +24,80 @@ struct source_code_file
string Contents; string Contents;
}; };
struct code_block_builder #define STRING_BUILDER_BUFFER_CAPACITY 4096
struct string_builder_buffer
{ {
memory_arena Data; u8* BufferMemory;
string String; string String;
string_builder_buffer* Next;
}; };
struct string_builder
{
string_builder_buffer* Buffers;
string_builder_buffer* Head;
};
internal void
GrowStringBuilder(string_builder* StringBuilder)
{
u8* BufferAndHeader = (u8*)malloc(sizeof(string_builder_buffer) + STRING_BUILDER_BUFFER_CAPACITY);
string_builder_buffer* NewBuffer = (string_builder_buffer*)BufferAndHeader;
*NewBuffer = {0};
NewBuffer->BufferMemory = (u8*)(NewBuffer + 1);
NewBuffer->String = MakeString((char*)NewBuffer->BufferMemory, 0, STRING_BUILDER_BUFFER_CAPACITY);
if (!StringBuilder->Buffers)
{
StringBuilder->Buffers = NewBuffer;
StringBuilder->Head = NewBuffer;
}
else
{
StringBuilder->Head->Next = NewBuffer;
StringBuilder->Head = NewBuffer;
}
}
internal void
Write(string Text, string_builder* StringBuilder)
{
string TextLeft = Text;
if (StringBuilder->Buffers == 0)
{
GrowStringBuilder(StringBuilder);
}
while (TextLeft.Length > 0)
{
// Copy what there is room for
s32 SpaceAvailable = StringBuilder->Head->String.Max - StringBuilder->Head->String.Length;
ConcatString(TextLeft, GSMin(SpaceAvailable, TextLeft.Length), &StringBuilder->Head->String);
TextLeft.Memory += SpaceAvailable;
TextLeft.Length -= SpaceAvailable;
if (TextLeft.Length > 0)
{
GrowStringBuilder(StringBuilder);
}
}
}
internal void
WriteStringBuilderToFile(string_builder StringBuilder, FILE* WriteFile)
{
string_builder_buffer* BufferAt = StringBuilder.Buffers;
while (BufferAt)
{
string String = BufferAt->String;
fwrite(String.Memory, 1, String.Length, WriteFile);
BufferAt = BufferAt->Next;
}
}
#define TYPE_TABLE_IDENTIFIER_MAX_LENGTH 128 #define TYPE_TABLE_IDENTIFIER_MAX_LENGTH 128
#define TYPE_TABLE_BUFFER_MAX 64 #define TYPE_TABLE_BUFFER_MAX 64
struct type_table_buffer struct type_table_buffer
@ -56,9 +122,7 @@ AddTypeToTable (string Identifier, s32 Size, type_table* Table)
{ {
if (!Table->Head || Table->TotalUsed >= Table->TotalMax) if (!Table->Head || Table->TotalUsed >= Table->TotalMax)
{ {
s32 NewHeadSize = sizeof(type_table_buffer) + ((sizeof(string) + TYPE_TABLE_IDENTIFIER_MAX_LENGTH + sizeof(s32)) * TYPE_TABLE_BUFFER_MAX); memory_arena Memory = {};
u8* NewHeadBuffer = (u8*)malloc(NewHeadSize);
static_memory_arena Memory = CreateMemoryArena(NewHeadBuffer, NewHeadSize);
type_table_buffer* NewHead = PushStruct(&Memory, type_table_buffer); type_table_buffer* NewHead = PushStruct(&Memory, type_table_buffer);
NewHead->IdentifiersBackbuffer = PushArray(&Memory, u8, TYPE_TABLE_IDENTIFIER_MAX_LENGTH * TYPE_TABLE_BUFFER_MAX); NewHead->IdentifiersBackbuffer = PushArray(&Memory, u8, TYPE_TABLE_IDENTIFIER_MAX_LENGTH * TYPE_TABLE_BUFFER_MAX);
@ -119,44 +183,6 @@ GetSizeOfType (string Identifier, type_table* TypeTable)
return Result; return Result;
} }
internal code_block_builder
InitCodeBlockBuilder()
{
code_block_builder Result = {};
InitMemoryArena(&Result.Data, 0, 0, StdAlloc);
return Result;
}
internal void
CodeBlockPrint (code_block_builder* Block, string Source)
{
char* NewCode = PushArray(&Block->Data, char, Source.Length);
GSMemCopy(Source.Memory, NewCode, Source.Length);
if (Block->String.Memory == 0)
{
Block->String.Memory = NewCode;
}
Block->String.Max += Source.Length;
Block->String.Length += Source.Length;
}
internal void
WriteMemoryRegionToFile (memory_region* Region, FILE* WriteFile)
{
if (Region->PreviousRegion)
{
WriteMemoryRegionToFile(Region->PreviousRegion, WriteFile);
}
fwrite(Region->Base, 1, Region->Used, WriteFile);
}
internal void
WriteCodeBlockToFile(code_block_builder CodeBlock, FILE* WriteFile)
{
memory_region* Region = CodeBlock.Data.CurrentRegion;
WriteMemoryRegionToFile (Region, WriteFile);
}
internal s32 internal s32
GetFileSize (char* FileName) GetFileSize (char* FileName)
{ {
@ -240,7 +266,7 @@ FindSeenStructInList (seen_node_struct* SeenStructList, string Name)
} }
internal void internal void
ParseNodeStruct (token* NodeStruct, code_block_builder* NodeMembersBlock, seen_node_struct* SeenStruct, type_table* TypeTable) ParseNodeStruct (token* NodeStruct, string_builder* NodeMembersBlock, seen_node_struct* SeenStruct, type_table* TypeTable)
{ {
token* OpenParen = NodeStruct->Next; token* OpenParen = NodeStruct->Next;
token* StructName = OpenParen->Next; token* StructName = OpenParen->Next;
@ -251,7 +277,7 @@ ParseNodeStruct (token* NodeStruct, code_block_builder* NodeMembersBlock, seen_n
PrintF(&Buffer, "node_struct_member MemberList_%.*s[] = {\n", PrintF(&Buffer, "node_struct_member MemberList_%.*s[] = {\n",
StructName->Text.Length, StructName->Text.Memory); StructName->Text.Length, StructName->Text.Memory);
CodeBlockPrint(NodeMembersBlock, Buffer); Write(Buffer, NodeMembersBlock);
token* Token = StructName->Next; token* Token = StructName->Next;
while (Token->Type != Token_RightCurlyBracket) while (Token->Type != Token_RightCurlyBracket)
@ -343,14 +369,14 @@ ParseNodeStruct (token* NodeStruct, code_block_builder* NodeMembersBlock, seen_n
(IsInput ? "IsInputMember" : ""), (IsInput ? "IsInputMember" : ""),
(IsInput && IsOutput ? "|" : ""), (IsInput && IsOutput ? "|" : ""),
(IsOutput ? "IsOutputMember" : "")); (IsOutput ? "IsOutputMember" : ""));
CodeBlockPrint(NodeMembersBlock, Buffer); Write(Buffer, NodeMembersBlock);
SeenStruct->MembersCount++; SeenStruct->MembersCount++;
Token = GetNextTokenOfType(Token, Token_Semicolon)->Next; Token = GetNextTokenOfType(Token, Token_Semicolon)->Next;
} }
} }
CodeBlockPrint(NodeMembersBlock, MakeStringLiteral("};\n\n")); Write(MakeStringLiteral("};\n\n"), NodeMembersBlock);
} }
internal s32 internal s32
@ -460,9 +486,9 @@ ParseTypedefs (token* Tokens, type_table* TypeTable)
internal void internal void
ParseNodeProc (token* NodeProc, ParseNodeProc (token* NodeProc,
code_block_builder* NodeTypeBlock, string_builder* NodeTypeBlock,
code_block_builder* NodeSpecificationsBlock, string_builder* NodeSpecificationsBlock,
code_block_builder* CallNodeProcBlock, string_builder* CallNodeProcBlock,
seen_node_struct* SeenStructs, seen_node_struct* SeenStructs,
b32 IsPatternProc) b32 IsPatternProc)
{ {
@ -473,7 +499,7 @@ ParseNodeProc (token* NodeProc,
// Types Enum // Types Enum
PrintF(&Buffer, "NodeType_%.*s,\n", ProcName->Text.Length, ProcName->Text.Memory); PrintF(&Buffer, "NodeType_%.*s,\n", ProcName->Text.Length, ProcName->Text.Memory);
CodeBlockPrint(NodeTypeBlock, Buffer); Write(Buffer, NodeTypeBlock);
// Node Specification // Node Specification
string ArgName = ProcArg->Text; string ArgName = ProcArg->Text;
@ -487,7 +513,7 @@ ParseNodeProc (token* NodeProc,
ArgStruct->MembersSize, ArgStruct->MembersSize,
ArgStruct->MembersCount, ArgStruct->MembersCount,
(IsPatternProc ? 4 : 5), (IsPatternProc ? "true" : "false")); (IsPatternProc ? 4 : 5), (IsPatternProc ? "true" : "false"));
CodeBlockPrint(NodeSpecificationsBlock, Buffer); Write(Buffer, NodeSpecificationsBlock);
// Call Node Proc // Call Node Proc
if (IsPatternProc) if (IsPatternProc)
@ -500,17 +526,17 @@ ParseNodeProc (token* NodeProc,
ProcName->Text.Length, ProcName->Text.Memory, ProcName->Text.Length, ProcName->Text.Memory,
ProcName->Text.Length, ProcName->Text.Memory, ProcName->Text.Length, ProcName->Text.Memory,
ProcArg->Text.Length, ProcArg->Text.Memory); ProcArg->Text.Length, ProcArg->Text.Memory);
CodeBlockPrint(CallNodeProcBlock, Buffer); Write(Buffer, CallNodeProcBlock);
} }
} }
internal s32 internal s32
PreprocessStructsAndProcs (string StructSearchString, string ProcSearchString, b32 FindingPatterns, PreprocessStructsAndProcs (string StructSearchString, string ProcSearchString, b32 FindingPatterns,
token* Tokens, token* Tokens,
code_block_builder* NodeMembersBlock, string_builder* NodeMembersBlock,
code_block_builder* NodeTypeBlock, string_builder* NodeTypeBlock,
code_block_builder* NodeSpecificationsBlock, string_builder* NodeSpecificationsBlock,
code_block_builder* CallNodeProcBlock, string_builder* CallNodeProcBlock,
type_table* TypeTable) type_table* TypeTable)
{ {
// Node Structs // Node Structs
@ -568,21 +594,19 @@ int main(int ArgCount, char** ArgV)
type_table TypeTable = {}; type_table TypeTable = {};
memory_arena SourceFileArena = {}; memory_arena SourceFileArena = {};
InitMemoryArena(&SourceFileArena, 0, 0, StdAlloc);
code_block_builder NodeTypeBlock = InitCodeBlockBuilder(); string_builder NodeTypeBlock = {};
CodeBlockPrint(&NodeTypeBlock, MakeStringLiteral("enum node_type\n{\n")); Write(MakeStringLiteral("enum node_type\n{\n"), &NodeTypeBlock);
code_block_builder NodeMembersBlock = InitCodeBlockBuilder(); string_builder NodeMembersBlock = {};
code_block_builder NodeSpecificationsBlock = InitCodeBlockBuilder(); string_builder NodeSpecificationsBlock = {};
CodeBlockPrint(&NodeSpecificationsBlock, MakeStringLiteral("node_specification NodeSpecifications[] = {\n")); Write(MakeStringLiteral("node_specification NodeSpecifications[] = {\n"), &NodeSpecificationsBlock);
code_block_builder CallNodeProcBlock = InitCodeBlockBuilder(); string_builder CallNodeProcBlock = {};
CodeBlockPrint(&CallNodeProcBlock, MakeStringLiteral("internal void CallNodeProc(node_header* Node, u8* Data, led* LEDs, s32 LEDsCount, r32 DeltaTime)\n{\n")); Write(MakeStringLiteral("internal void CallNodeProc(u32 SpecificationIndex, u8* Data, led* LEDs, s32 LEDsCount, r32 DeltaTime)\n{\n"), &CallNodeProcBlock);
CodeBlockPrint(&CallNodeProcBlock, Write(MakeStringLiteral("node_specification Spec = NodeSpecifications[SpecificationIndex];\n"), &CallNodeProcBlock);
MakeStringLiteral("node_specification Spec = NodeSpecifications[Node->Type];\n")); Write(MakeStringLiteral("switch (Spec.Type)\n{\n"), &CallNodeProcBlock);
CodeBlockPrint(&CallNodeProcBlock, MakeStringLiteral("switch (Spec.Type)\n{\n"));
// Build Search Paths Array // Build Search Paths Array
@ -649,7 +673,8 @@ int main(int ArgCount, char** ArgV)
{ {
source_code_file* File = SourceFiles + SourceFilesUsed++; source_code_file* File = SourceFiles + SourceFilesUsed++;
PushString(&File->Path, &SourceFileArena, SearchPathString->Length + CharArrayLength(FindFileData.cFileName)); u32 PathLength = SearchPathString->Length + CharArrayLength(FindFileData.cFileName);
File->Path = MakeString(PushArray(&SourceFileArena, char, PathLength), 0, PathLength);
CopyStringTo(Substring(*SearchPathString, 0, SearchPathString->Length - 2), &File->Path); CopyStringTo(Substring(*SearchPathString, 0, SearchPathString->Length - 2), &File->Path);
ConcatCharArrayToString(FindFileData.cFileName, &File->Path); ConcatCharArrayToString(FindFileData.cFileName, &File->Path);
NullTerminate(&File->Path); NullTerminate(&File->Path);
@ -657,7 +682,8 @@ int main(int ArgCount, char** ArgV)
File->FileSize = FindFileData.nFileSizeLow; File->FileSize = FindFileData.nFileSizeLow;
ErrorAssert(FindFileData.nFileSizeHigh == 0, &GlobalErrorList, "File Too Big. Peter needs to handle this. File: %.*s", FileName.Length, FileName.Memory); ErrorAssert(FindFileData.nFileSizeHigh == 0, &GlobalErrorList, "File Too Big. Peter needs to handle this. File: %.*s", FileName.Length, FileName.Memory);
PushString(&File->Contents, &SourceFileArena, File->FileSize + 1); u32 FileSize = File->FileSize + 1;
File->Contents = MakeString(PushArray(&SourceFileArena, char, FileSize), FileSize);
File->Contents.Length = ReadEntireFileAndNullTerminate(File->Path.Memory, File->Contents.Memory, File->Contents.Max); File->Contents.Length = ReadEntireFileAndNullTerminate(File->Path.Memory, File->Contents.Memory, File->Contents.Max);
} }
@ -727,23 +753,23 @@ int main(int ArgCount, char** ArgV)
MakeStringBuffer(Buffer, 256); MakeStringBuffer(Buffer, 256);
// Close Types Block - overwrite the last comma and '\' newline character with newlines. // Close Types Block - overwrite the last comma and '\' newline character with newlines.
CodeBlockPrint(&NodeTypeBlock, MakeStringLiteral("NodeType_Count,\n};\n\n")); Write(MakeStringLiteral("NodeType_Count,\n};\n\n"), &NodeTypeBlock);
// Close Specifications Block // Close Specifications Block
CodeBlockPrint(&NodeSpecificationsBlock, MakeStringLiteral("};\n")); Write(MakeStringLiteral("};\n"), &NodeSpecificationsBlock);
PrintF(&Buffer, "s32 NodeSpecificationsCount = %d;\n\n", NodeProcCount); PrintF(&Buffer, "s32 NodeSpecificationsCount = %d;\n\n", NodeProcCount);
CodeBlockPrint(&NodeSpecificationsBlock, Buffer); Write(Buffer, &NodeSpecificationsBlock);
// Close Call Node Proc Block // Close Call Node Proc Block
CodeBlockPrint(&CallNodeProcBlock, MakeStringLiteral("}\n}\n")); Write(MakeStringLiteral("}\n}\n"), &CallNodeProcBlock);
FILE* NodeGeneratedCPP = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.cpp", "w"); FILE* NodeGeneratedCPP = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.cpp", "w");
if (NodeGeneratedCPP) if (NodeGeneratedCPP)
{ {
WriteCodeBlockToFile(NodeTypeBlock, NodeGeneratedCPP); WriteStringBuilderToFile(NodeTypeBlock, NodeGeneratedCPP);
WriteCodeBlockToFile(NodeMembersBlock, NodeGeneratedCPP); WriteStringBuilderToFile(NodeMembersBlock, NodeGeneratedCPP);
WriteCodeBlockToFile(NodeSpecificationsBlock, NodeGeneratedCPP); WriteStringBuilderToFile(NodeSpecificationsBlock, NodeGeneratedCPP);
WriteCodeBlockToFile(CallNodeProcBlock, NodeGeneratedCPP); WriteStringBuilderToFile(CallNodeProcBlock, NodeGeneratedCPP);
fclose(NodeGeneratedCPP); fclose(NodeGeneratedCPP);
} }

View File

@ -33,9 +33,3 @@ struct animation_system
r32 AnimationStart; r32 AnimationStart;
r32 AnimationEnd; r32 AnimationEnd;
}; };
internal void
InitializeAnimationSystem(animation_system* System)
{
*System = {0};
}

View File

@ -181,7 +181,7 @@ INITIALIZE_APPLICATION(InitializeApplication)
State->Modes.Arena.FindAddressRule = FindAddress_InLastBufferOnly; State->Modes.Arena.FindAddressRule = FindAddress_InLastBufferOnly;
{ // Animation PLAYGROUND { // Animation PLAYGROUND
InitializeAnimationSystem(&State->AnimationSystem); State->AnimationSystem = {};
State->AnimationSystem.SecondsPerFrame = 1.f / 24.f; State->AnimationSystem.SecondsPerFrame = 1.f / 24.f;
State->AnimationSystem.AnimationStart = 0; State->AnimationSystem.AnimationStart = 0;
State->AnimationSystem.AnimationEnd = 15; State->AnimationSystem.AnimationEnd = 15;

File diff suppressed because it is too large Load Diff

View File

@ -19,21 +19,6 @@ s32 name##LEDCount;
#define NODE_COLOR_BUFFER_IN(name) NAMED_NODE_COLOR_BUFFER(name) #define NODE_COLOR_BUFFER_IN(name) NAMED_NODE_COLOR_BUFFER(name)
#define NODE_COLOR_BUFFER_OUT(name) NAMED_NODE_COLOR_BUFFER(name) #define NODE_COLOR_BUFFER_OUT(name) NAMED_NODE_COLOR_BUFFER(name)
enum mouse_node_interaction
{
NodeInteraction_None,
NodeInteraction_MouseDragNode,
NodeInteraction_MouseDragInput,
NodeInteraction_KeyboardEnterPortValue,
MouseNodeInteraction_Count,
};
enum node_port_direction
{
NodePort_Input,
NodePort_Output,
};
// TODO(Peter): Generate this // TODO(Peter): Generate this
enum struct_member_type enum struct_member_type
{ {
@ -45,114 +30,6 @@ enum struct_member_type
MemberTypeCount, MemberTypeCount,
}; };
struct node_led_color_connection
{
NODE_COLOR_BUFFER;
};
struct node_connection
{
s32 NodeHandle;
struct_member_type Type;
// TODO(Peter): probably can unify these pairs into a struct
s32 UpstreamNodeHandle;
s32 UpstreamNodePortIndex;
s32 DownstreamNodeHandle;
s32 DownstreamNodePortIndex;
b32 DirectionMask;
union
{
u8* Ptr;
s32* S32ValuePtr;
r32* R32ValuePtr;
v4* V4ValuePtr;
node_led_color_connection* LEDsValuePtr;
};
};
// TODO(Peter): cant decide if this needs to be dynamic or just a really big number
// reevaluate once you have some examples
#define NODE_CONNECTIONS_MAX 8
struct node_header
{
s32 Handle; // NOTE(Peter): stores a non-zero handle. must come first to match node_free_list_member
node_type Type;
v2 Min, Dim;
s32 ConnectionsCount;
node_connection* Connections;
b32 UpdatedThisFrame;
u8* PersistentData;
};
struct node_list_buffer
{
node_header* Headers;
s32 Max;
s32 Used;
node_list_buffer* Next;
};
#define NODE_LIST_CONNECTIONS_MAX 256
struct node_list
{
node_list_buffer* First;
node_list_buffer* Head;
s32 TotalMax;
s32 TotalUsed;
s32 HandleAccumulator;
// TODO(Peter): Replace this with some sort of stretchy bufferf
// :ConnectionsToStretchyBuffer
s32 ConnectionsUsed;
node_connection Connections[NODE_LIST_CONNECTIONS_MAX];
};
struct node_list_iterator
{
node_list List;
node_list_buffer* CurrentBuffer;
node_header* At;
s32 BufferIndexAt;
s32 TotalIndexAt;
};
enum node_interaction_flag
{
NodeInteraction_AllUpstream = 0x1,
NodeInteraction_AllDownstream = 0x2,
};
struct node_interaction
{
s32 NodeHandle;
v2 MouseOffset;
b32 Flags;
// TODO(Peter): Inputs and outputs are all stored in the same array. Should this just be flags,
// and we store the Port and Value?
s32 InputPort;
s32 InputValue;
s32 OutputPort;
s32 OutputValue;
};
struct node_render_settings
{
v4 PortColors[MemberTypeCount];
bitmap_font* Font;
b32 Display;
};
// ^^ OLD ^^
struct node_struct_member struct node_struct_member
{ {
struct_member_type Type; struct_member_type Type;
@ -201,21 +78,6 @@ struct pattern_node_workspace
}; };
// vv OLD vv
v4 DragButtonColors[] = {
v4{.7f, .7f, .7f, 1},
BlackV4,
v4{.7f, .7f, .7f, 1},
};
#define NODE_HEADER_HEIGHT 20
#define NODE_PORT_X 20
#define NODE_PORT_Y 15
#define NODE_PORT_DIM v2{NODE_PORT_X, NODE_PORT_Y}
#define NODE_PORT_STEP NODE_PORT_Y + 20
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Pre Processor Macros // Pre Processor Macros
/////////////////////////////////////////////// ///////////////////////////////////////////////

View File

@ -47,6 +47,7 @@ node_struct_member MemberList_sin_wave_data[] = {
node_struct_member MemberList_multiply_patterns_data[] = { node_struct_member MemberList_multiply_patterns_data[] = {
{ MemberType_NODE_COLOR_BUFFER, "ALEDs", (u64)&((multiply_patterns_data*)0)->ALEDs, IsInputMember }, { MemberType_NODE_COLOR_BUFFER, "ALEDs", (u64)&((multiply_patterns_data*)0)->ALEDs, IsInputMember },
{ MemberType_NODE_COLOR_BUFFER, "BLEDs", (u64)&((multiply_patterns_data*)0)->BLEDs, IsInputMember },
{ MemberType_NODE_COLOR_BUFFER, "ResultLEDs", (u64)&((multiply_patterns_data*)0)->ResultLEDs, IsOutputMember}, { MemberType_NODE_COLOR_BUFFER, "ResultLEDs", (u64)&((multiply_patterns_data*)0)->ResultLEDs, IsOutputMember},
}; };
@ -82,8 +83,8 @@ node_specification NodeSpecifications[] = {
{ NodeType_VectorValue, "VectorValue", 11, MemberList_vector_data, 32, 5, false}, { NodeType_VectorValue, "VectorValue", 11, MemberList_vector_data, 32, 5, false},
{ NodeType_MultiplyNodeProc, "MultiplyNodeProc", 16, MemberList_multiply_data, 12, 3, false}, { NodeType_MultiplyNodeProc, "MultiplyNodeProc", 16, MemberList_multiply_data, 12, 3, false},
{ NodeType_AddNodeProc, "AddNodeProc", 11, MemberList_add_data, 48, 3, false}, { NodeType_AddNodeProc, "AddNodeProc", 11, MemberList_add_data, 48, 3, false},
{ NodeType_SinWave, "SinWave", 7, MemberList_sin_wave_data, 16, 4, false}, { NodeType_SinWave, "SinWave", 7, MemberList_sin_wave_data, 20, 4, false},
{ NodeType_MultiplyPatterns, "MultiplyPatterns", 16, MemberList_multiply_patterns_data, 40, 2, false}, { NodeType_MultiplyPatterns, "MultiplyPatterns", 16, MemberList_multiply_patterns_data, 60, 3, false},
{ NodeType_OutputNode, "OutputNode", 10, MemberList_output_node_data, 20, 1, false}, { NodeType_OutputNode, "OutputNode", 10, MemberList_output_node_data, 20, 1, false},
{ NodeType_SolidColorProc, "SolidColorProc", 14, MemberList_solid_color_data, 36, 2, false}, { NodeType_SolidColorProc, "SolidColorProc", 14, MemberList_solid_color_data, 36, 2, false},
{ NodeType_VerticalColorFadeProc, "VerticalColorFadeProc", 21, MemberList_vertical_color_fade_data, 44, 4, false}, { NodeType_VerticalColorFadeProc, "VerticalColorFadeProc", 21, MemberList_vertical_color_fade_data, 44, 4, false},
@ -91,12 +92,12 @@ node_specification NodeSpecifications[] = {
}; };
s32 NodeSpecificationsCount = 10; s32 NodeSpecificationsCount = 10;
internal void CallNodeProc(node_header* Node, u8* Data, led* LEDs, s32 LEDsCount, r32 DeltaTime) internal void CallNodeProc(u32 SpecificationIndex, u8* Data, led* LEDs, s32 LEDsCount, r32 DeltaTime)
{ {
node_specification Spec = NodeSpecifications[Node->Type]; node_specification Spec = NodeSpecifications[SpecificationIndex];
switch (Spec.Type) switch (Spec.Type)
{ {
case NodeType_FloatValue: { FloatValue((float_value_data*)Data, DeltaTime); } break; case NodeType_FloatValue: { FloatValue((float_value_data*)Data, DeltaTime); } break;
case NodeType_VectorValue: { VectorValue((vector_data*)Data, DeltaTime); } break; case NodeType_VectorValue: { VectorValue((vector_data*)Data, DeltaTime); } break;
case NodeType_MultiplyNodeProc: { MultiplyNodeProc((multiply_data*)Data, DeltaTime); } break; case NodeType_MultiplyNodeProc: { MultiplyNodeProc((multiply_data*)Data, DeltaTime); } break;
case NodeType_AddNodeProc: { AddNodeProc((add_data*)Data, DeltaTime); } break; case NodeType_AddNodeProc: { AddNodeProc((add_data*)Data, DeltaTime); } break;

View File

@ -6,7 +6,7 @@ struct visual_node
struct visual_port struct visual_port
{ {
u32 SparseNodeIndex; gs_list_handle SparseNodeHandle;
u32 PortIndex; u32 PortIndex;
rect PortBounds; rect PortBounds;
}; };
@ -113,15 +113,18 @@ FOLDHAUS_INPUT_COMMAND_PROC(EndConnectNodesOperation)
rect ViewAdjustedBounds = RectOffsetByVector(VisualPort.PortBounds, GraphState->ViewOffset); rect ViewAdjustedBounds = RectOffsetByVector(VisualPort.PortBounds, GraphState->ViewOffset);
if (PointIsInRect(Mouse.Pos, ViewAdjustedBounds)) if (PointIsInRect(Mouse.Pos, ViewAdjustedBounds))
{ {
pattern_node_connection Connection = {};
visual_port UpstreamPort = (OpState->IsInput & IsInputMember) ? VisualPort : OpState->VisualPort; visual_port UpstreamPort = (OpState->IsInput & IsInputMember) ? VisualPort : OpState->VisualPort;
visual_port DownstreamPort = (OpState->IsInput & IsInputMember) ? OpState->VisualPort : VisualPort; visual_port DownstreamPort = (OpState->IsInput & IsInputMember) ? OpState->VisualPort : VisualPort;
// Make Connection // Make Connection
// TODO(Peter): START HERE pattern_node_connection Connection = {};
//start here; Connection.UpstreamNodeHandle = UpstreamPort.SparseNodeHandle;
// You were working on connection UpstreamPort and DownstreamPort Connection.DownstreamNodeHandle = DownstreamPort.SparseNodeHandle;
// You need to get each node's handle and add a new connection to the connection bucket Connection.UpstreamPortIndex = UpstreamPort.PortIndex;
Connection.DownstreamPortIndex = DownstreamPort.PortIndex;
State->NodeWorkspace.Connections.PushElementOnBucket(Connection);
GraphState->LayoutIsDirty = true;
} }
} }
@ -330,8 +333,10 @@ ArrangeNodes(pattern_node_workspace Workspace, r32 NodeWidth, r32 LayerDistance,
for (u32 n = 0; n < Result.SparseToContiguousNodeMapCount; n++) for (u32 n = 0; n < Result.SparseToContiguousNodeMapCount; n++)
{ {
u32 NodeIndex = Result.SparseToContiguousNodeMap[n]; u32 NodeIndex = Result.SparseToContiguousNodeMap[n];
pattern_node* Node = Workspace.Nodes.GetElementAtIndex(NodeIndex); gs_list_entry<pattern_node>* NodeEntry = Workspace.Nodes.GetEntryAtIndex(NodeIndex);
u32 SpecIndex = Node->SpecificationIndex; pattern_node Node = NodeEntry->Value;
u32 SpecIndex = Node.SpecificationIndex;
node_specification Spec = NodeSpecifications[SpecIndex]; node_specification Spec = NodeSpecifications[SpecIndex];
u32 NodeLayer = Result.VisualNodeLayers[n]; u32 NodeLayer = Result.VisualNodeLayers[n];
@ -363,7 +368,7 @@ ArrangeNodes(pattern_node_workspace Workspace, r32 NodeWidth, r32 LayerDistance,
PortBounds.Max = PortBounds.Min + v2{8, 8}; PortBounds.Max = PortBounds.Min + v2{8, 8};
visual_port* VisualPort = Result.VisualPorts + VisualPortsUsed++; visual_port* VisualPort = Result.VisualPorts + VisualPortsUsed++;
VisualPort->SparseNodeIndex = n; VisualPort->SparseNodeHandle = NodeEntry->Handle;
VisualPort->PortIndex = p; VisualPort->PortIndex = p;
VisualPort->PortBounds = PortBounds; VisualPort->PortBounds = PortBounds;
} }