From ae94b4b9fc5b4443f6d9eb6bb450de1def108cdb Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 24 Aug 2022 20:40:39 -0400 Subject: fixes for gl core; create/delete developing --- undo.cpp | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 2 deletions(-) (limited to 'undo.cpp') diff --git a/undo.cpp b/undo.cpp index 6ebdfca..2306db9 100644 --- a/undo.cpp +++ b/undo.cpp @@ -114,6 +114,12 @@ void History_Action_Change_SwapBool(memory *Memory, bool32 *Bool) History_Action_Change(Memory, Bool, Bool, &OppositeBool, action_type_change_i32); } +void History_Action_Change_V2(memory *Memory, v2 *DataAddress, v2 *OriginalData, v2 *NewData) +{ + History_Action_Change(Memory, (void *)&DataAddress->x, (void *)&OriginalData->x, (void *)&NewData->x, action_type_change_r32); + History_Action_Change(Memory, (void *)&DataAddress->y, (void *)&OriginalData->y, (void *)&NewData->y, action_type_change_r32); +} + void History_Action_Change_Increment(memory *Memory, void *Data, action_type ActionChange) { switch (ActionChange) @@ -155,6 +161,93 @@ void History_Action_Change_Increment(memory *Memory, void *Data, action_type Act } } +void History_Action_Change_Decrement(memory *Memory, void *Data, action_type ActionChange) +{ + switch (ActionChange) + { + case action_type_change_u16: + { + uint16 DataPlusOne = (*(uint16 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + case action_type_change_i16: + { + int16 DataPlusOne = (*(int16 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + case action_type_change_u32: + { + uint32 DataPlusOne = (*(uint32 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + case action_type_change_i32: + { + int32 DataPlusOne = (*(int32 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + case action_type_change_r32: + { + real32 DataPlusOne = (*(real32 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + case action_type_change_u64: + { + uint64 DataPlusOne = (*(uint64 *)Data) - 1; + History_Action_Change(Memory, Data, Data, &DataPlusOne, ActionChange); + } break; + default: + { + Assert(0); + } + } +} + +static void +Arbitrary_ShiftData(action_shift_data ShiftData) { + int16 StopAt = ShiftData.Index; + if (ShiftData.Direction > 0) { + int16 i = ShiftData.NumberOf - 1; + while (i >= StopAt) { + uint8 *CurrentData = (uint8 *)ShiftData.StartingAddress + (ShiftData.Size * i); + uint8 *NextData = (uint8 *)ShiftData.StartingAddress + (ShiftData.Size * (i + ShiftData.Direction)); + uint32 Bytes = 0; + while (Bytes < ShiftData.Size) { + *NextData++ = *CurrentData++; + Bytes++; + } + i--; + } + } else { + int16 i = StopAt; + while (i <= ShiftData.NumberOf - 1) { + uint8 *CurrentData = (uint8 *)ShiftData.StartingAddress + (ShiftData.Size * i); + uint8 *NextData = (uint8 *)ShiftData.StartingAddress + (ShiftData.Size * (i - ShiftData.Direction)); + uint32 Bytes = 0; + while (Bytes < ShiftData.Size) { + *CurrentData++ = *NextData++; + Bytes++; + } + i++; + } + } +} + +void History_Action_Shift_2(memory *Memory, void *StartingAddress, uint32 Size, uint16 NumberOf, int16 Direction, int16 Index) +{ + Memory->Action.Entry[Memory->Action.Index].NumberOfActions++; + void *Data = Memory_Advance(Memory, sizeof(action_type), P_UndoBuffer); + *(action_type *)Data = action_type_shift; + action_shift_data *ShiftData = (action_shift_data *)Memory_Advance(Memory, sizeof(action_shift_data), P_UndoBuffer); + ShiftData->StartingAddress = StartingAddress; + ShiftData->Size = Size; + ShiftData->NumberOf = NumberOf; + ShiftData->Index = Index; + ShiftData->Direction = Direction; + Data = Memory_Advance(Memory, sizeof(action_type), P_UndoBuffer); + *(action_type *)Data = action_type_shift; + Arbitrary_ShiftData(*ShiftData); +} + void History_Action_Shift(memory *Memory, action_type ActionChange, void *DataAddress, int16 Direction, int16 Index) { Memory->Action.Entry[Memory->Action.Index].NumberOfActions++; @@ -171,6 +264,15 @@ void History_Action_Shift(memory *Memory, action_type ActionChange, void *DataAd void *DataIndex = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); *(ptrsize *)DataIndex = (ptrsize)Index; } break; + case action_type_shift_bezier: + { + void *DataPropertyAddress = Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + *(ptrsize *)DataPropertyAddress = (ptrsize)DataAddress; + void *DataDirection = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); + *(ptrsize *)DataDirection = (ptrsize)Direction; + void *DataIndex = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); + *(ptrsize *)DataIndex = (ptrsize)Index; + } break; default: { Assert(0); @@ -180,6 +282,30 @@ void History_Action_Shift(memory *Memory, action_type ActionChange, void *DataAd *(action_type *)Data = ActionChange; } +// Overwrite area with arbitrary-sized memory. Only use for creation/deletion, +// not for value changes of things that already exist. +void History_Action_StoreData(memory *Memory, void *DataAddress, uint64 ByteSize) +{ + Memory->Action.Entry[Memory->Action.Index].NumberOfActions++; + void *Data = Memory_Advance(Memory, sizeof(action_type), P_UndoBuffer); + *(action_type *)Data = action_type_storedata; + Data = Memory_Advance(Memory, sizeof(uint64), P_UndoBuffer); + *(uint64 *)Data = ByteSize; + Data = Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + *(ptrsize *)Data = (ptrsize)DataAddress; + uint64 i = 0; + while (i < ByteSize) { + void *DataIndex = Memory_Advance(Memory, 1, P_UndoBuffer); + *(uint8 *)DataIndex = *((uint8 *)DataAddress + i++); + } + Data = Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + *(ptrsize *)Data = (ptrsize)DataAddress; + Data = Memory_Advance(Memory, sizeof(uint64), P_UndoBuffer); + *(uint64 *)Data = ByteSize; + Data = Memory_Advance(Memory, sizeof(action_type), P_UndoBuffer); + *(action_type *)Data = action_type_storedata; +} + // This is only called when we're certain the action is going to be taken. void History_Entry_Commit(memory *Memory, action_entry_type Type, char *Name) { @@ -264,7 +390,33 @@ void History_Action_Undo(memory *Memory) { void *DataIndex = Memory_Rewind(Memory, sizeof(int16), P_UndoBuffer); void *DataDirection = Memory_Rewind(Memory, sizeof(int16), P_UndoBuffer); void **DataPropertyAddress = (void **)Memory_Rewind(Memory, sizeof(void *), P_UndoBuffer); - ShiftKeyframes((property_channel *)*DataPropertyAddress, *(int16 *)DataDirection * -1, *(int16 *)DataIndex); + Keyframe_ShiftPointers((property_channel *)*DataPropertyAddress, *(int16 *)DataDirection * -1, *(int16 *)DataIndex); + } break; + case action_type_shift_bezier: + { + void *DataIndex = Memory_Rewind(Memory, sizeof(int16), P_UndoBuffer); + void *DataDirection = Memory_Rewind(Memory, sizeof(int16), P_UndoBuffer); + void **DataPropertyAddress = (void **)Memory_Rewind(Memory, sizeof(void *), P_UndoBuffer); + Mask_ShiftPointers((mask *)*DataPropertyAddress, *(int16 *)DataDirection * -1, *(int16 *)DataIndex); + } break; + case action_type_shift: + { + action_shift_data ShiftData = *(action_shift_data *)Memory_Rewind(Memory, sizeof(action_shift_data), P_UndoBuffer); + ShiftData.Direction *= -1; + Arbitrary_ShiftData(ShiftData); + } break; + case action_type_storedata: + { + uint64 *ByteSize = (uint64 *)Memory_Rewind(Memory, sizeof(uint64), P_UndoBuffer); + void *DataAddress = *(void **)Memory_Rewind(Memory, sizeof(void *), P_UndoBuffer); + void *DataStart = Memory_Rewind(Memory, *ByteSize, P_UndoBuffer); + uint64 i = 0; + while (i < *ByteSize) { + void *DataIndex = Memory_GetAddressAt(Memory, i, P_UndoBuffer); + *((uint8 *)DataAddress + i++) = *(uint8 *)DataIndex; + } + DataStart = Memory_Rewind(Memory, sizeof(void *), P_UndoBuffer); + DataStart = Memory_Rewind(Memory, sizeof(uint64), P_UndoBuffer); } break; default: { @@ -332,7 +484,28 @@ void History_Action_Redo(memory *Memory) { void **DataPropertyAddress = (void **)Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); void *DataDirection = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); void *DataIndex = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); - ShiftKeyframes((property_channel *)*DataPropertyAddress, *(int16 *)DataDirection, *(int16 *)DataIndex); + Keyframe_ShiftPointers((property_channel *)*DataPropertyAddress, *(int16 *)DataDirection, *(int16 *)DataIndex); + } break; + case action_type_shift_bezier: + { + void **DataPropertyAddress = (void **)Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + void *DataDirection = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); + void *DataIndex = Memory_Advance(Memory, sizeof(int16), P_UndoBuffer); + Mask_ShiftPointers((mask *)*DataPropertyAddress, *(int16 *)DataDirection, *(int16 *)DataIndex); + } break; + case action_type_shift: + { + action_shift_data ShiftData = *(action_shift_data *)Memory_Advance(Memory, sizeof(action_shift_data), P_UndoBuffer); + Arbitrary_ShiftData(ShiftData); + } break; + case action_type_storedata: + { + // NOTE(fox): Right now I'm only using this to overwrite data, so all we need to do is advance. + uint64 *ByteSize = (uint64 *)Memory_Advance(Memory, sizeof(uint64), P_UndoBuffer); + void *DataAddress = *(void **)Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + void *DataEnd = Memory_Advance(Memory, *ByteSize, P_UndoBuffer); + DataEnd = Memory_Advance(Memory, sizeof(void *), P_UndoBuffer); + DataEnd = Memory_Advance(Memory, sizeof(uint64), P_UndoBuffer); } break; default: { -- cgit v1.2.3