vn/code/vn_animation_curve.h

67 lines
1.7 KiB
C

/* date = May 7th 2023 0:37 pm */
#ifndef VN_ANIMATION_CURVE_H
#define VN_ANIMATION_CURVE_H
////////////////////////////////
//~ sixten: Animation Curve Types
struct animation_curve_key
{
u64 Value;
};
struct animation_curve_entry
{
animation_curve_key Key;
u32 LastFrameTouched;
r32 Value;
animation_curve_entry *Next;
animation_curve_entry *Prev;
};
struct animation_curve_bucket
{
animation_curve_entry *First;
animation_curve_entry *Last;
};
struct animation_curve_state
{
memory_arena *Arena;
u32 CurrentFrame;
r32 dtForFrame;
// sixten: Hash map
animation_curve_bucket Buckets[256];
// sixten: Free list
animation_curve_entry *FirstFreeEntry;
animation_curve_entry *LastFreeEntry;
};
////////////////////////////////
//~ sixten: Animation Curve Functions
inline b32 AreEqual(animation_curve_key A, animation_curve_key B)
{
b32 Result = (A.Value == B.Value);
return(Result);
}
static void AC_SetState(animation_curve_state *State);
static animation_curve_key AC_GenerateKeyFromString(string String);
static void AC_Init(animation_curve_state *State);
static animation_curve_entry *AC_GetEntryByKey(animation_curve_key Key, r32 Initial = 0);
static r32 AC_GetValue(string Name, r32 Initial);
static void AC_SetValue(string Name, r32 Value);
static r32 AC_AnimateValueDirect(r32 Target, r32 Duration, r32 *Value);
static r32 AC_AnimateValue(r32 Target, r32 Initial, r32 Duration, string Name);
static r32 AC_AnimateValueF(r32 Target, r32 Initial, r32 Duration, char *Format, ...);
static void AC_NewFrame(animation_curve_state *State, r32 dtForFrame);
#endif //VN_ANIMATION_CURVE_H