Added delta time as a parameter to NODE_PROC functions. Created a vector node and a sin wave node.
This commit is contained in:
parent
40d9e0b83e
commit
16401f9259
|
@ -21,7 +21,7 @@ del *.pdb > NUL 2> NUL
|
||||||
REM Compile and Run the Preprocessor
|
REM Compile and Run the Preprocessor
|
||||||
REM cl %CommonCompilerFlags% ..\meta\foldhaus_meta.cpp /link %CommonLinkerFlags%
|
REM cl %CommonCompilerFlags% ..\meta\foldhaus_meta.cpp /link %CommonLinkerFlags%
|
||||||
pushd ..\src\
|
pushd ..\src\
|
||||||
REM ..\build\foldhaus_meta.exe C:\projects\foldhaus\src\
|
..\build\foldhaus_meta.exe C:\projects\foldhaus\src\
|
||||||
popd
|
popd
|
||||||
|
|
||||||
REM cl %CommonCompilerFlags% F:\src\foldhaus_util_radialumia_file_converter.cpp /link %CommonLinkerFlags%
|
REM cl %CommonCompilerFlags% F:\src\foldhaus_util_radialumia_file_converter.cpp /link %CommonLinkerFlags%
|
||||||
|
|
|
@ -304,7 +304,7 @@ LoadAssembly (app_state* State, context Context, char* Path)
|
||||||
Context.PlatformFree(TestAssemblyFile.Base, TestAssemblyFile.Size);
|
Context.PlatformFree(TestAssemblyFile.Base, TestAssemblyFile.Size);
|
||||||
|
|
||||||
string PathString = MakeStringLiteral(Path);
|
string PathString = MakeStringLiteral(Path);
|
||||||
s32 IndexOfLastSlash = FastLastIndexOfChar(PathString.Memory, PathString.Length, '\\');
|
s32 IndexOfLastSlash = FastLastIndexOfCharInCharArray(PathString.Memory, PathString.Length, '\\');
|
||||||
string FileName = Substring(PathString, IndexOfLastSlash + 1);
|
string FileName = Substring(PathString, IndexOfLastSlash + 1);
|
||||||
|
|
||||||
r32 Scale = 100;
|
r32 Scale = 100;
|
||||||
|
@ -548,10 +548,12 @@ UPDATE_AND_RENDER(UpdateAndRender)
|
||||||
|
|
||||||
ExecuteAllRegisteredCommands(&State->InputCommandRegistry, Input, State);
|
ExecuteAllRegisteredCommands(&State->InputCommandRegistry, Input, State);
|
||||||
|
|
||||||
UpdateOutputNodeCalculations(State->OutputNode, State->NodeList, State->Transient,
|
UpdateOutputNodeCalculations(State->OutputNode, State->NodeList,
|
||||||
|
State->Permanent, State->Transient,
|
||||||
State->LEDBufferList->LEDs,
|
State->LEDBufferList->LEDs,
|
||||||
State->LEDBufferList->Colors,
|
State->LEDBufferList->Colors,
|
||||||
State->LEDBufferList->Count);
|
State->LEDBufferList->Count,
|
||||||
|
Context.DeltaTime);
|
||||||
|
|
||||||
ClearTransientNodeColorBuffers(State->NodeList);
|
ClearTransientNodeColorBuffers(State->NodeList);
|
||||||
|
|
||||||
|
|
|
@ -767,12 +767,14 @@ UpdateDraggingNodeValue (v2 MousePos, v2 LastFrameMousePos, node_interaction Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal void UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena* Transient,
|
internal void UpdateNodeCalculation (interface_node* Node, node_list* NodeList,
|
||||||
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount);
|
memory_arena* Permanent, memory_arena* Transient,
|
||||||
|
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount, r32 DeltaTime);
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
UpdateNodesConnectedUpstream (interface_node* Node, node_list* NodeList, memory_arena* Transient,
|
UpdateNodesConnectedUpstream (interface_node* Node, node_list* NodeList,
|
||||||
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount)
|
memory_arena* Permanent, memory_arena* Transient,
|
||||||
|
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount, r32 DeltaTime)
|
||||||
{
|
{
|
||||||
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
||||||
{
|
{
|
||||||
|
@ -786,7 +788,7 @@ UpdateNodesConnectedUpstream (interface_node* Node, node_list* NodeList, memory_
|
||||||
interface_node* UpstreamNode = GetNodeAtOffset(NodeList, Connection->UpstreamNodeOffset);
|
interface_node* UpstreamNode = GetNodeAtOffset(NodeList, Connection->UpstreamNodeOffset);
|
||||||
if (!UpstreamNode->UpdatedThisFrame)
|
if (!UpstreamNode->UpdatedThisFrame)
|
||||||
{
|
{
|
||||||
UpdateNodeCalculation(UpstreamNode, NodeList, Transient, LEDs, ColorsInit, LEDCount);
|
UpdateNodeCalculation(UpstreamNode, NodeList, Permanent, Transient, LEDs, ColorsInit, LEDCount, DeltaTime);
|
||||||
}
|
}
|
||||||
switch (Connection->Type)
|
switch (Connection->Type)
|
||||||
{
|
{
|
||||||
|
@ -818,8 +820,9 @@ UpdateNodesConnectedUpstream (interface_node* Node, node_list* NodeList, memory_
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena* Transient,
|
UpdateNodeCalculation (interface_node* Node, node_list* NodeList,
|
||||||
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount)
|
memory_arena* Permanent, memory_arena* Transient,
|
||||||
|
led* LEDs, sacn_pixel* ColorsInit, s32 LEDCount, r32 DeltaTime)
|
||||||
{
|
{
|
||||||
DEBUG_TRACK_FUNCTION;
|
DEBUG_TRACK_FUNCTION;
|
||||||
|
|
||||||
|
@ -835,9 +838,14 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
Node->UpdatedThisFrame = true;
|
Node->UpdatedThisFrame = true;
|
||||||
|
|
||||||
sacn_pixel* Colors = ColorsInit;
|
sacn_pixel* Colors = ColorsInit;
|
||||||
u8* NodeData = PushArray(Transient, u8, Spec.DataStructSize);
|
|
||||||
|
|
||||||
UpdateNodesConnectedUpstream(Node, NodeList, Transient, LEDs, Colors, LEDCount);
|
// TODO(Peter): Should do this at node creation time
|
||||||
|
if (Node->PersistentData == 0)
|
||||||
|
{
|
||||||
|
Node->PersistentData = PushArray(Permanent, u8, Spec.DataStructSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateNodesConnectedUpstream(Node, NodeList, Permanent, Transient, LEDs, Colors, LEDCount, DeltaTime);
|
||||||
|
|
||||||
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
||||||
{
|
{
|
||||||
|
@ -848,7 +856,7 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
// needs the leds to request that as its own member/parameter.
|
// needs the leds to request that as its own member/parameter.
|
||||||
if (Connection.Type == MemberType_NODE_COLOR_BUFFER)
|
if (Connection.Type == MemberType_NODE_COLOR_BUFFER)
|
||||||
{
|
{
|
||||||
node_led_color_connection* ColorConnection = (node_led_color_connection*)(NodeData + MemberList[ConnectionIdx].Offset);
|
node_led_color_connection* ColorConnection = (node_led_color_connection*)(Node->PersistentData + MemberList[ConnectionIdx].Offset);
|
||||||
|
|
||||||
ColorConnection->LEDs = LEDs;
|
ColorConnection->LEDs = LEDs;
|
||||||
ColorConnection->LEDCount = LEDCount;
|
ColorConnection->LEDCount = LEDCount;
|
||||||
|
@ -868,17 +876,17 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
{
|
{
|
||||||
case MemberType_s32:
|
case MemberType_s32:
|
||||||
{
|
{
|
||||||
GSMemCopy(&Connection.S32Value, (NodeData + MemberList[ConnectionIdx].Offset), sizeof(s32));
|
GSMemCopy(&Connection.S32Value, (Node->PersistentData + MemberList[ConnectionIdx].Offset), sizeof(s32));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case MemberType_r32:
|
case MemberType_r32:
|
||||||
{
|
{
|
||||||
GSMemCopy(&Connection.R32Value, (NodeData + MemberList[ConnectionIdx].Offset), sizeof(r32));
|
GSMemCopy(&Connection.R32Value, (Node->PersistentData + MemberList[ConnectionIdx].Offset), sizeof(r32));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case MemberType_v4:
|
case MemberType_v4:
|
||||||
{
|
{
|
||||||
GSMemCopy(&Connection.V4Value, (NodeData + MemberList[ConnectionIdx].Offset), sizeof(v4));
|
GSMemCopy(&Connection.V4Value, (Node->PersistentData + MemberList[ConnectionIdx].Offset), sizeof(v4));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
InvalidDefaultCase;
|
InvalidDefaultCase;
|
||||||
|
@ -886,7 +894,7 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CallNodeProc(Node, NodeData, LEDs, Colors, LEDCount);
|
CallNodeProc(Node, Node->PersistentData, LEDs, LEDCount, DeltaTime);
|
||||||
|
|
||||||
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
for (s32 ConnectionIdx = 0; ConnectionIdx < Node->ConnectionsCount; ConnectionIdx++)
|
||||||
{
|
{
|
||||||
|
@ -904,22 +912,22 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
{
|
{
|
||||||
case MemberType_s32:
|
case MemberType_s32:
|
||||||
{
|
{
|
||||||
GSMemCopy((NodeData + MemberList[ConnectionIdx].Offset), &Connection->S32Value, sizeof(s32));
|
GSMemCopy((Node->PersistentData + MemberList[ConnectionIdx].Offset), &Connection->S32Value, sizeof(s32));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case MemberType_r32:
|
case MemberType_r32:
|
||||||
{
|
{
|
||||||
GSMemCopy((NodeData + MemberList[ConnectionIdx].Offset), &Connection->R32Value, sizeof(r32));
|
GSMemCopy((Node->PersistentData + MemberList[ConnectionIdx].Offset), &Connection->R32Value, sizeof(r32));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case MemberType_v4:
|
case MemberType_v4:
|
||||||
{
|
{
|
||||||
GSMemCopy((NodeData + MemberList[ConnectionIdx].Offset), &Connection->V4Value, sizeof(v4));
|
GSMemCopy((Node->PersistentData + MemberList[ConnectionIdx].Offset), &Connection->V4Value, sizeof(v4));
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case MemberType_NODE_COLOR_BUFFER:
|
case MemberType_NODE_COLOR_BUFFER:
|
||||||
{
|
{
|
||||||
node_led_color_connection* Value = (node_led_color_connection*)(NodeData + MemberList[ConnectionIdx].Offset);
|
node_led_color_connection* Value = (node_led_color_connection*)(Node->PersistentData + MemberList[ConnectionIdx].Offset);
|
||||||
Connection->LEDsValue.Colors = Value->Colors;
|
Connection->LEDsValue.Colors = Value->Colors;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
|
@ -929,10 +937,12 @@ UpdateNodeCalculation (interface_node* Node, node_list* NodeList, memory_arena*
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
UpdateOutputNodeCalculations (interface_node* OutputNode, node_list* NodeList, memory_arena* Transient, led* LEDs, sacn_pixel* Colors, s32 LEDCount)
|
UpdateOutputNodeCalculations (interface_node* OutputNode, node_list* NodeList,
|
||||||
|
memory_arena* Permanent, memory_arena* Transient,
|
||||||
|
led* LEDs, sacn_pixel* Colors, s32 LEDCount, r32 DeltaTime)
|
||||||
{
|
{
|
||||||
Assert(OutputNode->Type == NodeType_OutputNode);
|
Assert(OutputNode->Type == NodeType_OutputNode);
|
||||||
UpdateNodesConnectedUpstream(OutputNode, NodeList, Transient, LEDs, Colors, LEDCount);
|
UpdateNodesConnectedUpstream(OutputNode, NodeList, Permanent, Transient, LEDs, Colors, LEDCount, DeltaTime);
|
||||||
|
|
||||||
node_connection ColorsConnection = OutputNode->Connections[0];
|
node_connection ColorsConnection = OutputNode->Connections[0];
|
||||||
if (ColorsConnection.LEDsValue.Colors)
|
if (ColorsConnection.LEDsValue.Colors)
|
||||||
|
@ -947,7 +957,7 @@ UpdateOutputNodeCalculations (interface_node* OutputNode, node_list* NodeList, m
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
UpdateAllNodeCalculations (node_list* NodeList, memory_arena* Transient, led* LEDs, sacn_pixel* Colors, s32 LEDCount)
|
UpdateAllNodeCalculations (node_list* NodeList, memory_arena* Permanent, memory_arena* Transient, led* LEDs, sacn_pixel* Colors, s32 LEDCount, r32 DeltaTime)
|
||||||
{
|
{
|
||||||
node_list_iterator NodeIter = GetNodeListIterator(*NodeList);
|
node_list_iterator NodeIter = GetNodeListIterator(*NodeList);
|
||||||
while (NodeIteratorIsValid(NodeIter))
|
while (NodeIteratorIsValid(NodeIter))
|
||||||
|
@ -955,7 +965,7 @@ UpdateAllNodeCalculations (node_list* NodeList, memory_arena* Transient, led* LE
|
||||||
interface_node* Node = NodeIter.At;
|
interface_node* Node = NodeIter.At;
|
||||||
if (!Node->UpdatedThisFrame)
|
if (!Node->UpdatedThisFrame)
|
||||||
{
|
{
|
||||||
UpdateNodeCalculation(Node, NodeList, Transient, LEDs, Colors, LEDCount);
|
UpdateNodeCalculation(Node, NodeList, Permanent, Transient, LEDs, Colors, LEDCount, DeltaTime);
|
||||||
}
|
}
|
||||||
Next(&NodeIter);
|
Next(&NodeIter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,8 @@ struct interface_node
|
||||||
|
|
||||||
node_type Type;
|
node_type Type;
|
||||||
b32 UpdatedThisFrame;
|
b32 UpdatedThisFrame;
|
||||||
|
|
||||||
|
u8* PersistentData;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct node_list
|
struct node_list
|
||||||
|
@ -174,10 +176,7 @@ struct data_name
|
||||||
struct data_name
|
struct data_name
|
||||||
|
|
||||||
#define NODE_PROC(proc_name, input_type) \
|
#define NODE_PROC(proc_name, input_type) \
|
||||||
void proc_name(input_type* Data)
|
void proc_name(input_type* Data, r32 DeltaTime)
|
||||||
|
|
||||||
#define NODE_PATTERN_PROC(proc_name, input_type) \
|
|
||||||
void proc_name(input_type* Data, led* LEDs, sacn_pixel* Colors, s32 LEDCount)
|
|
||||||
|
|
||||||
#define NODE_IN(type, name) type name
|
#define NODE_IN(type, name) type name
|
||||||
#define NODE_OUT(type, name) type name
|
#define NODE_OUT(type, name) type name
|
||||||
|
|
|
@ -5,6 +5,8 @@ NodeType_MultiplyNodeProc,
|
||||||
NodeType_AddNodeProc,
|
NodeType_AddNodeProc,
|
||||||
NodeType_FloatValueProc,
|
NodeType_FloatValueProc,
|
||||||
NodeType_SolidColorProc,
|
NodeType_SolidColorProc,
|
||||||
|
NodeType_SinWaveProc,
|
||||||
|
NodeType_VectorProc,
|
||||||
NodeType_MultiplyPatterns,
|
NodeType_MultiplyPatterns,
|
||||||
NodeType_VerticalColorFadeProc,
|
NodeType_VerticalColorFadeProc,
|
||||||
NodeType_Count,
|
NodeType_Count,
|
||||||
|
@ -32,6 +34,21 @@ node_struct_member MemberList_solid_color_data[] = {
|
||||||
{ MemberType_NODE_COLOR_BUFFER, "LEDs", (u64)&((solid_color_data*)0)->LEDs, IsInputMember | IsOutputMember},
|
{ MemberType_NODE_COLOR_BUFFER, "LEDs", (u64)&((solid_color_data*)0)->LEDs, IsInputMember | IsOutputMember},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
node_struct_member MemberList_sin_wave_data[] = {
|
||||||
|
{ MemberType_r32, "Period", (u64)&((sin_wave_data*)0)->Period, IsInputMember },
|
||||||
|
{ MemberType_r32, "Min", (u64)&((sin_wave_data*)0)->Min, IsInputMember },
|
||||||
|
{ MemberType_r32, "Max", (u64)&((sin_wave_data*)0)->Max, IsInputMember },
|
||||||
|
{ MemberType_r32, "Result", (u64)&((sin_wave_data*)0)->Result, IsOutputMember},
|
||||||
|
};
|
||||||
|
|
||||||
|
node_struct_member MemberList_vector_data[] = {
|
||||||
|
{ MemberType_r32, "X", (u64)&((vector_data*)0)->X, IsInputMember },
|
||||||
|
{ MemberType_r32, "Y", (u64)&((vector_data*)0)->Y, IsInputMember },
|
||||||
|
{ MemberType_r32, "Z", (u64)&((vector_data*)0)->Z, IsInputMember },
|
||||||
|
{ MemberType_r32, "W", (u64)&((vector_data*)0)->W, IsInputMember },
|
||||||
|
{ MemberType_v4, "Result", (u64)&((vector_data*)0)->Result, IsOutputMember},
|
||||||
|
};
|
||||||
|
|
||||||
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, "BLEDs", (u64)&((multiply_patterns_data*)0)->BLEDs, IsInputMember },
|
||||||
|
@ -42,6 +59,7 @@ node_struct_member MemberList_vertical_color_fade_data[] = {
|
||||||
{ MemberType_v4, "Color", (u64)&((vertical_color_fade_data*)0)->Color, IsInputMember },
|
{ MemberType_v4, "Color", (u64)&((vertical_color_fade_data*)0)->Color, IsInputMember },
|
||||||
{ MemberType_r32, "Min", (u64)&((vertical_color_fade_data*)0)->Min, IsInputMember },
|
{ MemberType_r32, "Min", (u64)&((vertical_color_fade_data*)0)->Min, IsInputMember },
|
||||||
{ MemberType_r32, "Max", (u64)&((vertical_color_fade_data*)0)->Max, IsInputMember },
|
{ MemberType_r32, "Max", (u64)&((vertical_color_fade_data*)0)->Max, IsInputMember },
|
||||||
|
{ MemberType_NODE_COLOR_BUFFER, "ResultLEDs", (u64)&((vertical_color_fade_data*)0)->ResultLEDs, IsOutputMember},
|
||||||
};
|
};
|
||||||
|
|
||||||
node_specification NodeSpecifications[] = {
|
node_specification NodeSpecifications[] = {
|
||||||
|
@ -49,20 +67,24 @@ node_specification NodeSpecifications[] = {
|
||||||
{ NodeType_AddNodeProc, "AddNodeProc", 11, MemberList_add_data, 48, 3, false},
|
{ NodeType_AddNodeProc, "AddNodeProc", 11, MemberList_add_data, 48, 3, false},
|
||||||
{ NodeType_FloatValueProc, "FloatValueProc", 14, MemberList_float_value_data, 8, 2, false},
|
{ NodeType_FloatValueProc, "FloatValueProc", 14, MemberList_float_value_data, 8, 2, false},
|
||||||
{ NodeType_SolidColorProc, "SolidColorProc", 14, MemberList_solid_color_data, 36, 2, false},
|
{ NodeType_SolidColorProc, "SolidColorProc", 14, MemberList_solid_color_data, 36, 2, false},
|
||||||
|
{ NodeType_SinWaveProc, "SinWaveProc", 11, MemberList_sin_wave_data, 16, 4, false},
|
||||||
|
{ NodeType_VectorProc, "VectorProc", 10, MemberList_vector_data, 32, 5, false},
|
||||||
{ NodeType_MultiplyPatterns, "MultiplyPatterns", 16, MemberList_multiply_patterns_data, 60, 3, false},
|
{ NodeType_MultiplyPatterns, "MultiplyPatterns", 16, MemberList_multiply_patterns_data, 60, 3, false},
|
||||||
{ NodeType_VerticalColorFadeProc, "VerticalColorFadeProc", 21, MemberList_vertical_color_fade_data, 24, 3, true},
|
{ NodeType_VerticalColorFadeProc, "VerticalColorFadeProc", 21, MemberList_vertical_color_fade_data, 44, 4, false},
|
||||||
};
|
};
|
||||||
s32 NodeSpecificationsCount = 6;
|
s32 NodeSpecificationsCount = 8;
|
||||||
|
|
||||||
internal void CallNodeProc(interface_node* Node, u8* Data, led* LEDs, sacn_pixel* Colors, s32 LEDCount)
|
internal void CallNodeProc(interface_node* Node, u8* Data, led* LEDs, s32 LEDsCount, r32 DeltaTime)
|
||||||
{
|
{
|
||||||
switch (Node->Type)
|
switch (Node->Type)
|
||||||
{
|
{
|
||||||
case NodeType_MultiplyNodeProc: { MultiplyNodeProc((multiply_data*)Data); } break;
|
case NodeType_MultiplyNodeProc: { MultiplyNodeProc((multiply_data*)Data, DeltaTime); } break;
|
||||||
case NodeType_AddNodeProc: { AddNodeProc((add_data*)Data); } break;
|
case NodeType_AddNodeProc: { AddNodeProc((add_data*)Data, DeltaTime); } break;
|
||||||
case NodeType_FloatValueProc: { FloatValueProc((float_value_data*)Data); } break;
|
case NodeType_FloatValueProc: { FloatValueProc((float_value_data*)Data, DeltaTime); } break;
|
||||||
case NodeType_SolidColorProc: { SolidColorProc((solid_color_data*)Data); } break;
|
case NodeType_SolidColorProc: { SolidColorProc((solid_color_data*)Data, DeltaTime); } break;
|
||||||
case NodeType_MultiplyPatterns: { MultiplyPatterns((multiply_patterns_data*)Data); } break;
|
case NodeType_SinWaveProc: { SinWaveProc((sin_wave_data*)Data, DeltaTime); } break;
|
||||||
case NodeType_VerticalColorFadeProc: { VerticalColorFadeProc((vertical_color_fade_data*)Data, LEDs, Colors, LEDCount); } break;
|
case NodeType_VectorProc: { VectorProc((vector_data*)Data, DeltaTime); } break;
|
||||||
|
case NodeType_MultiplyPatterns: { MultiplyPatterns((multiply_patterns_data*)Data, DeltaTime); } break;
|
||||||
|
case NodeType_VerticalColorFadeProc: { VerticalColorFadeProc((vertical_color_fade_data*)Data, DeltaTime); } break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,6 +278,24 @@ GSIntDivideRoundUpDef(s32);
|
||||||
GSIntDivideRoundUpDef(s64);
|
GSIntDivideRoundUpDef(s64);
|
||||||
#undef GSIntDivideRoundUpDef
|
#undef GSIntDivideRoundUpDef
|
||||||
|
|
||||||
|
#define GSRemapDef(type) \
|
||||||
|
static type GSRemap(type Value, type OldMin, type OldMax, type NewMin, type NewMax) { \
|
||||||
|
type Result = (Value - OldMin) / (OldMax - OldMin); \
|
||||||
|
Result = (Result * (NewMax - NewMin)) + NewMin; \
|
||||||
|
return Result; \
|
||||||
|
}
|
||||||
|
GSRemapDef(u8);
|
||||||
|
GSRemapDef(u16);
|
||||||
|
GSRemapDef(u32);
|
||||||
|
GSRemapDef(u64);
|
||||||
|
GSRemapDef(s8);
|
||||||
|
GSRemapDef(s16);
|
||||||
|
GSRemapDef(s32);
|
||||||
|
GSRemapDef(s64);
|
||||||
|
GSRemapDef(r32);
|
||||||
|
GSRemapDef(r64);
|
||||||
|
#undef GSRemapDef
|
||||||
|
|
||||||
#define GSTrigFunctionDef(name, type, func) static type name(type V) { return func(V); }
|
#define GSTrigFunctionDef(name, type, func) static type name(type V) { return func(V); }
|
||||||
GSTrigFunctionDef(GSSin, r32, sinf);
|
GSTrigFunctionDef(GSSin, r32, sinf);
|
||||||
GSTrigFunctionDef(GSSin, r64, sin);
|
GSTrigFunctionDef(GSSin, r64, sin);
|
||||||
|
|
71
gs_string.h
71
gs_string.h
|
@ -169,6 +169,7 @@ static bool IsAlphaNumeric (char C);
|
||||||
static bool IsOperator (char C);
|
static bool IsOperator (char C);
|
||||||
|
|
||||||
// Tokenizing
|
// Tokenizing
|
||||||
|
static b32 AtValidPosition(tokenizer Tokenizer);
|
||||||
static b32 AtValidToken(tokenizer Tokenizer);
|
static b32 AtValidToken(tokenizer Tokenizer);
|
||||||
static char* EatToNewLine(char* C);
|
static char* EatToNewLine(char* C);
|
||||||
static void EatToNewLine(tokenizer* T);
|
static void EatToNewLine(tokenizer* T);
|
||||||
|
@ -189,16 +190,21 @@ static s32 CharArrayLength (char* CharArray);
|
||||||
static bool CharArraysEqual (char* A, s32 ALength, char* B, s32 BLength);
|
static bool CharArraysEqual (char* A, s32 ALength, char* B, s32 BLength);
|
||||||
static bool CharArraysEqualUnsafe (char* A, char* B);
|
static bool CharArraysEqualUnsafe (char* A, char* B);
|
||||||
static void ReverseCharArray (char* Array, s32 Length);
|
static void ReverseCharArray (char* Array, s32 Length);
|
||||||
#define FirstIndexOfChar(array, find) IndexOfChar(array, 0, find)
|
#define FirstIndexOfCharInCharArray(array, find) IndexOfChar(array, 0, find)
|
||||||
static s32 IndexOfChar (char* Array, s32 Start, char Find);
|
static s32 IndexOfChar (char* Array, s32 Start, char Find);
|
||||||
#define FastLastIndexOfChar(array, len, find) FastReverseIndexOfChar(array, len, 0, find)
|
#define FastLastIndexOfCharInCharArray(array, len, find) FastReverseIndexOfChar(array, len, 0, find)
|
||||||
static s32 FastReverseIndexOfChar (char* Array, s32 Length, s32 OffsetFromEnd, char Find);
|
static s32 FastReverseIndexOfChar (char* Array, s32 Length, s32 OffsetFromEnd, char Find);
|
||||||
#define LastIndexOfChar(array, find) ReverseIndexOfChar(array, 0, find)
|
#define LastIndexOfCharInCharArray(array, find) ReverseIndexOfChar(array, 0, find)
|
||||||
static s32 ReverseIndexOfChar (char* Array, s32 OffsetFromEnd, char Find);
|
static s32 ReverseIndexOfChar (char* Array, s32 OffsetFromEnd, char Find);
|
||||||
static b32 CharArrayContains(char* Array, char* CheckFor);
|
static b32 CharArrayContains(char* Array, char* CheckFor);
|
||||||
static b32 CharArrayContainsSafe(char* Array, s32 ArrayLength, char* CheckFor, s32 CheckForLength);
|
static b32 CharArrayContainsSafe(char* Array, s32 ArrayLength, char* CheckFor, s32 CheckForLength);
|
||||||
|
|
||||||
// String
|
// String
|
||||||
|
|
||||||
|
#define MakeStringBuffer(name, size) \
|
||||||
|
char name##Backbuffer[(size)]; \
|
||||||
|
string name = MakeString(name##Backbuffer, size);
|
||||||
|
|
||||||
static string MakeString (char* Array, s32 Length, s32 Max);
|
static string MakeString (char* Array, s32 Length, s32 Max);
|
||||||
static string MakeString (char* Array, s32 Length);
|
static string MakeString (char* Array, s32 Length);
|
||||||
static string MakeString (char* Array);
|
static string MakeString (char* Array);
|
||||||
|
@ -212,11 +218,11 @@ static s32 FindFirstChar (string String, char C);
|
||||||
static void SetStringToChar (string* Dest, char C, s32 Count);
|
static void SetStringToChar (string* Dest, char C, s32 Count);
|
||||||
static void SetStringToCharArray (string* Dest, char* Source);
|
static void SetStringToCharArray (string* Dest, char* Source);
|
||||||
|
|
||||||
static void ConcatString (string* Dest, string Source);
|
static void ConcatString (string Source, string* Dest);
|
||||||
static void ConcatString (string* Dest, string Source, s32 Length);
|
static void ConcatString (string Source, s32 Length, string* Dest);
|
||||||
static void ConcatCharToString(string* Dest, char C);
|
static void ConcatCharToString(string* Dest, char C);
|
||||||
static void ConcatCharArrayToString (string* Dest, char* Source);
|
static void ConcatCharArrayToString (char* Source, string* Dest);
|
||||||
static void ConcatCharArrayToString (string* Dest, char* Source, s32 SourceLength);
|
static void ConcatCharArrayToString (char* Source, s32 SourceLength, string* Dest);
|
||||||
|
|
||||||
static void CopyStringTo (string Source, string* Dest);
|
static void CopyStringTo (string Source, string* Dest);
|
||||||
static s32 CopyStringToCharArray (string Source, char* Dest, s32 DestLength);
|
static s32 CopyStringToCharArray (string Source, char* Dest, s32 DestLength);
|
||||||
|
@ -229,6 +235,8 @@ static void InsertChar (string* String, char Char, s32 Index);
|
||||||
static void InsertStringAt (string* Dest, string Source, s32 At);
|
static void InsertStringAt (string* Dest, string Source, s32 At);
|
||||||
static void RemoveCharAt (string* String, s32 Index);
|
static void RemoveCharAt (string* String, s32 Index);
|
||||||
|
|
||||||
|
static s32 IndexOfChar(string String, char C);
|
||||||
|
static s32 LastIndexOfChar(string String, char C);
|
||||||
static string Substring (string* String, s32 Start, s32 End);
|
static string Substring (string* String, s32 Start, s32 End);
|
||||||
static string Substring (string* String, s32 Start);
|
static string Substring (string* String, s32 Start);
|
||||||
|
|
||||||
|
@ -403,6 +411,13 @@ static bool IsOperator (char C)
|
||||||
// Tokenizing
|
// Tokenizing
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static b32
|
||||||
|
AtValidPosition (tokenizer Tokenizer)
|
||||||
|
{
|
||||||
|
b32 Result = (Tokenizer.At - Tokenizer.Memory) <= Tokenizer.MemoryLength;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
static b32
|
static b32
|
||||||
AtValidToken(tokenizer Tokenizer)
|
AtValidToken(tokenizer Tokenizer)
|
||||||
{
|
{
|
||||||
|
@ -878,7 +893,7 @@ SetStringToCharArray (string* Dest, char* Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ConcatString (string* Dest, string Source)
|
ConcatString (string Source, string* Dest)
|
||||||
{
|
{
|
||||||
Assert((Dest->Length + Source.Length) <= Dest->Max);
|
Assert((Dest->Length + Source.Length) <= Dest->Max);
|
||||||
|
|
||||||
|
@ -892,7 +907,7 @@ ConcatString (string* Dest, string Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ConcatString (string* Dest, string Source, s32 Length)
|
ConcatString (string Source, s32 Length, string* Dest)
|
||||||
{
|
{
|
||||||
Assert(Length < Source.Length);
|
Assert(Length < Source.Length);
|
||||||
Assert((Dest->Length + Length) <= Dest->Max);
|
Assert((Dest->Length + Length) <= Dest->Max);
|
||||||
|
@ -917,7 +932,7 @@ ConcatCharToString (string* Dest, char C)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ConcatCharArrayToString (string* Dest, char* Source)
|
ConcatCharArrayToString (char* Source, string* Dest)
|
||||||
{
|
{
|
||||||
Assert(CharArrayLength(Source) + Dest->Length <= Dest->Max);
|
Assert(CharArrayLength(Source) + Dest->Length <= Dest->Max);
|
||||||
|
|
||||||
|
@ -932,7 +947,7 @@ ConcatCharArrayToString (string* Dest, char* Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ConcatCharArrayToString (string* Dest, char* Source, s32 SourceLength)
|
ConcatCharArrayToString (char* Source, s32 SourceLength, string* Dest)
|
||||||
{
|
{
|
||||||
Assert(SourceLength + Dest->Length <= Dest->Max);
|
Assert(SourceLength + Dest->Length <= Dest->Max);
|
||||||
|
|
||||||
|
@ -1061,6 +1076,40 @@ RemoveCharAt (string* String, s32 Index)
|
||||||
String->Length--;
|
String->Length--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static s32
|
||||||
|
IndexOfChar(string String, char C)
|
||||||
|
{
|
||||||
|
s32 Result = -1;
|
||||||
|
char* At = String.Memory;
|
||||||
|
for (s32 i = 0; i < String.Length; i++)
|
||||||
|
{
|
||||||
|
if (*At == C)
|
||||||
|
{
|
||||||
|
Result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
At++;
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static s32
|
||||||
|
LastIndexOfChar(string String, char C)
|
||||||
|
{
|
||||||
|
s32 Result = -1;
|
||||||
|
char* At = String.Memory + String.Length - 1;
|
||||||
|
for (s32 i = 0; i < String.Length; i++)
|
||||||
|
{
|
||||||
|
if (*At == C)
|
||||||
|
{
|
||||||
|
Result = String.Length - i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
At--;
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
static string
|
static string
|
||||||
Substring (string String, s32 Start, s32 End)
|
Substring (string String, s32 Start, s32 End)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,9 +17,9 @@ NODE_STRUCT(solid_color_data)
|
||||||
|
|
||||||
NODE_PROC(SolidColorProc, solid_color_data)
|
NODE_PROC(SolidColorProc, solid_color_data)
|
||||||
{
|
{
|
||||||
u8 R = (u8)(Data->Color.r * 255);
|
u8 R = (u8)GSClamp(0.f, (Data->Color.r * 255), 255.f);
|
||||||
u8 G = (u8)(Data->Color.g * 255);
|
u8 G = (u8)GSClamp(0.f, (Data->Color.g * 255), 255.f);
|
||||||
u8 B = (u8)(Data->Color.b * 255);
|
u8 B = (u8)GSClamp(0.f, (Data->Color.b * 255), 255.f);
|
||||||
|
|
||||||
led* LED = Data->LEDs;
|
led* LED = Data->LEDs;
|
||||||
for (s32 l = 0; l < Data->LEDCount; l++)
|
for (s32 l = 0; l < Data->LEDCount; l++)
|
||||||
|
@ -33,6 +33,51 @@ NODE_PROC(SolidColorProc, solid_color_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODE_STRUCT(sin_wave_data)
|
||||||
|
{
|
||||||
|
NODE_IN(r32, Period);
|
||||||
|
NODE_IN(r32, Min);
|
||||||
|
NODE_IN(r32, Max);
|
||||||
|
NODE_OUT(r32, Result);
|
||||||
|
|
||||||
|
r32 Accumulator;
|
||||||
|
};
|
||||||
|
|
||||||
|
NODE_PROC(SinWaveProc, sin_wave_data)
|
||||||
|
{
|
||||||
|
Data->Accumulator += DeltaTime;
|
||||||
|
if (Data->Period > 0)
|
||||||
|
{
|
||||||
|
while (Data->Accumulator > Data->Period)
|
||||||
|
{
|
||||||
|
Data->Accumulator -= Data->Period;
|
||||||
|
}
|
||||||
|
|
||||||
|
r32 ActualMin = GSMin(Data->Min, Data->Max);
|
||||||
|
r32 ActualMax = GSMax(Data->Min, Data->Max);
|
||||||
|
r32 SinResult = GSSin((Data->Accumulator / Data->Period) * PI * 2);
|
||||||
|
Data->Result = GSRemap(SinResult, -1.f, 1.f, ActualMin, ActualMax);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Data->Result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE_STRUCT(vector_data)
|
||||||
|
{
|
||||||
|
NODE_IN(r32, X);
|
||||||
|
NODE_IN(r32, Y);
|
||||||
|
NODE_IN(r32, Z);
|
||||||
|
NODE_IN(r32, W);
|
||||||
|
NODE_OUT(v4, Result);
|
||||||
|
};
|
||||||
|
|
||||||
|
NODE_PROC(VectorProc, vector_data)
|
||||||
|
{
|
||||||
|
Data->Result = v4{Data->X, Data->Y, Data->Z, Data->W};
|
||||||
|
}
|
||||||
|
|
||||||
NODE_STRUCT(multiply_patterns_data)
|
NODE_STRUCT(multiply_patterns_data)
|
||||||
{
|
{
|
||||||
NODE_COLOR_BUFFER_IN(A);
|
NODE_COLOR_BUFFER_IN(A);
|
||||||
|
@ -47,35 +92,35 @@ NODE_PROC(MultiplyPatterns, multiply_patterns_data)
|
||||||
{
|
{
|
||||||
Assert(LED->Index >= 0 && LED->Index < Data->ResultLEDCount);
|
Assert(LED->Index >= 0 && LED->Index < Data->ResultLEDCount);
|
||||||
|
|
||||||
r32 AR = (r32)Data->AColors[LED->Index].R / 255.f;
|
s32 AR = Data->AColors[LED->Index].R;
|
||||||
r32 AG = (r32)Data->AColors[LED->Index].G / 255.f;
|
s32 AG = Data->AColors[LED->Index].G;
|
||||||
r32 AB = (r32)Data->AColors[LED->Index].B / 255.f;
|
s32 AB = Data->AColors[LED->Index].B;
|
||||||
|
|
||||||
r32 BR = (r32)Data->BColors[LED->Index].R / 255.f;
|
s32 BR = Data->BColors[LED->Index].R;
|
||||||
r32 BG = (r32)Data->BColors[LED->Index].G / 255.f;
|
s32 BG = Data->BColors[LED->Index].G;
|
||||||
r32 BB = (r32)Data->BColors[LED->Index].B / 255.f;
|
s32 BB = Data->BColors[LED->Index].B;
|
||||||
|
|
||||||
r32 RCombined = AR * BR;
|
s32 RCombined = (AR * BR) / 255;
|
||||||
r32 GCombined = AG * BG;
|
s32 GCombined = (AG * BG) / 255;
|
||||||
r32 BCombined = AB * BB;
|
s32 BCombined = (AB * BB) / 255;
|
||||||
|
|
||||||
Data->ResultColors[LED->Index].R = (u8)(GSClamp01(RCombined) * 255);
|
Data->ResultColors[LED->Index].R = (u8)RCombined;
|
||||||
Data->ResultColors[LED->Index].G = (u8)(GSClamp01(GCombined) * 255);
|
Data->ResultColors[LED->Index].G = (u8)GCombined;
|
||||||
Data->ResultColors[LED->Index].B = (u8)(GSClamp01(BCombined) * 255);
|
Data->ResultColors[LED->Index].B = (u8)BCombined;
|
||||||
|
|
||||||
LED++;
|
LED++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NODE_STRUCT(vertical_color_fade_data)
|
||||||
NODE_PATTERN_STRUCT(vertical_color_fade_data)
|
|
||||||
{
|
{
|
||||||
NODE_IN(v4, Color);
|
NODE_IN(v4, Color);
|
||||||
NODE_IN(r32, Min);
|
NODE_IN(r32, Min);
|
||||||
NODE_IN(r32, Max);
|
NODE_IN(r32, Max);
|
||||||
|
NODE_COLOR_BUFFER_OUT(Result);
|
||||||
};
|
};
|
||||||
|
|
||||||
NODE_PATTERN_PROC(VerticalColorFadeProc, vertical_color_fade_data)
|
NODE_PROC(VerticalColorFadeProc, vertical_color_fade_data)
|
||||||
{
|
{
|
||||||
r32 R = (Data->Color.r * 255);
|
r32 R = (Data->Color.r * 255);
|
||||||
r32 G = (Data->Color.g * 255);
|
r32 G = (Data->Color.g * 255);
|
||||||
|
@ -83,15 +128,17 @@ NODE_PATTERN_PROC(VerticalColorFadeProc, vertical_color_fade_data)
|
||||||
|
|
||||||
r32 Range = Data->Max - Data->Min;
|
r32 Range = Data->Max - Data->Min;
|
||||||
|
|
||||||
led* LED = LEDs;
|
led* LED = Data->ResultLEDs;
|
||||||
for (s32 l = 0; l < LEDCount; l++)
|
for (s32 l = 0; l < Data->ResultLEDCount; l++)
|
||||||
{
|
{
|
||||||
|
Assert(LED->Index >= 0 && LED->Index < Data->ResultLEDCount);
|
||||||
|
|
||||||
r32 Amount = (LED->Position.y - Data->Min) / Range;
|
r32 Amount = (LED->Position.y - Data->Min) / Range;
|
||||||
Amount = GSClamp01(1.0f - Amount);
|
Amount = GSClamp01(1.0f - Amount);
|
||||||
|
|
||||||
Colors[LED->Index].R = (u8)(R * Amount);
|
Data->ResultColors[LED->Index].R = (u8)(R * Amount);
|
||||||
Colors[LED->Index].G = (u8)(G * Amount);
|
Data->ResultColors[LED->Index].G = (u8)(G * Amount);
|
||||||
Colors[LED->Index].B = (u8)(B * Amount);
|
Data->ResultColors[LED->Index].B = (u8)(B * Amount);
|
||||||
LED++;
|
LED++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue