summaryrefslogtreecommitdiff
path: root/src/bezier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bezier.cpp')
-rw-r--r--src/bezier.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bezier.cpp b/src/bezier.cpp
index ac89ed3..420cae1 100644
--- a/src/bezier.cpp
+++ b/src/bezier.cpp
@@ -35,6 +35,19 @@ Bezier_SolveYForX(v2 Point_P0, v2 Point_P1, v2 Point_P2, v2 Point_P3, real32 Tar
}
static bezier_point *
+Bezier_LookupAddress(memory *Memory, uint16 *Block_Bezier_Index, uint16 Index, bool32 AssertExists)
+{
+ Assert(Index < (MAX_KEYFRAMES_PER_BLOCK * MAX_KEYFRAME_BLOCKS));
+ int SeekBlock = Index / MAX_KEYFRAMES_PER_BLOCK;
+ int SeekIndex = Index - (SeekBlock * MAX_KEYFRAMES_PER_BLOCK);
+ block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Block_Bezier_Index[SeekBlock], 0);
+ Assert(Bezier->Occupied);
+ if (AssertExists)
+ Assert(Bezier->Point[SeekIndex].Occupied);
+ return &Bezier->Point[SeekIndex];
+}
+
+static bezier_point *
Bezier_LookupAddress(memory *Memory, property_channel *Property, uint16 Index, bool32 AssertExists)
{
Assert(Index < MAX_KEYFRAMES_PER_BLOCK); // TODO(fox): Test multiple keyframe blocks!
@@ -65,6 +78,32 @@ Bezier_Interact_Evaluate(project_state *State, bezier_point *PointAddress, v2 *P
}
static void
+Bezier_Add(memory *Memory, memory_table_list TableName, uint16 *Block_Bezier_Index, uint16 *Block_Bezier_Count,
+ uint16 *PointCount, bezier_point PointData)
+{
+ int k = 0;
+ for (;;) {
+ int SeekBlock = k / MAX_KEYFRAMES_PER_BLOCK;
+ if ((SeekBlock + 1) > *Block_Bezier_Count) {
+ Block_Bezier_Index[SeekBlock] = Memory_Block_AllocateNew(Memory, F_Bezier);
+ block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Block_Bezier_Index[SeekBlock], 0);
+ Bezier->Occupied = true;
+ History_Action_Swap(Memory, TableName, sizeof(*Block_Bezier_Count), Block_Bezier_Count);
+ *Block_Bezier_Count += 1;
+ }
+ bezier_point *Point = Bezier_LookupAddress(Memory, Block_Bezier_Index, k, 0);
+ if (!Point->Occupied) {
+ History_Action_Swap(Memory, F_Bezier, sizeof(*Point), Point);
+ *Point = PointData;
+ History_Action_Swap(Memory, TableName, sizeof(*PointCount), PointCount);
+ *PointCount += 1;
+ return;
+ }
+ k++;
+ }
+}
+
+static void
Bezier_Add(memory *Memory, memory_table_list TableName, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation)
{
if (!Property->Block_Bezier_Count) {