Revert "yet another checkpoint"

This reverts commit 5ad8d523ba.
This commit is contained in:
Ryan Fleury
2024-09-07 14:48:29 -07:00
parent 30766f93ae
commit 6180da1b0f
11 changed files with 396 additions and 797 deletions
+2 -84
View File
@@ -430,8 +430,6 @@ ui_state_alloc(void)
ui->string_hover_arena = arena_alloc();
ui->box_table_size = 4096;
ui->box_table = push_array(arena, UI_BoxHashSlot, ui->box_table_size);
ui->anim_slots_count = 4096;
ui->anim_slots = push_array(arena, UI_AnimSlot, ui->anim_slots_count);
UI_InitStackNils(ui);
return ui;
}
@@ -799,25 +797,6 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, U
ui_state->build_box_count = 0;
ui_state->tooltip_open = 0;
ui_state->ctx_menu_changed = 0;
ui_state->default_animation_rate = 1 - pow_f32(2, (-50.f * ui_state->animation_dt));
}
//- rjf: prune unused animation nodes
ProfScope("ui prune unused animation nodes")
{
for(UI_AnimNode *n = ui_state->lru_anim_node, *next = &ui_nil_anim_node; n != &ui_nil_anim_node; n = next)
{
next = n->lru_next;
if(n->last_touched_build_index+1 < ui_state->build_index)
{
DLLRemove_NPZ(&ui_nil_anim_node, ui_state->lru_anim_node, ui_state->mru_anim_node, n, lru_next, lru_prev);
SLLStackPush_N(ui_state->free_anim_node, n, slot_next);
}
else
{
break;
}
}
}
//- rjf: detect mouse-moves
@@ -1276,18 +1255,8 @@ ui_end_build(void)
}
//- rjf: animate
ProfScope("animate")
{
for(U64 slot_idx = 0; slot_idx < ui_state->anim_slots_count; slot_idx += 1)
{
for(UI_AnimNode *n = ui_state->anim_slots[slot_idx].first;
n != &ui_nil_anim_node && n != 0;
n = n->slot_next)
{
n->current += (n->params.target - n->current) * n->params.rate;
ui_state->is_animating = (ui_state->is_animating || abs_f32(n->params.target - n->current) > n->params.epsilon);
}
}
ProfBegin("ui animate");
F32 vast_rate = 1 - pow_f32(2, (-60.f * ui_state->animation_dt));
F32 fast_rate = 1 - pow_f32(2, (-50.f * ui_state->animation_dt));
F32 fish_rate = 1 - pow_f32(2, (-40.f * ui_state->animation_dt));
@@ -1403,6 +1372,7 @@ ui_end_build(void)
}
}
}
ProfEnd();
}
//- rjf: animate context menu
@@ -2947,58 +2917,6 @@ ui_signal_from_box(UI_Box *box)
return sig;
}
////////////////////////////////
//~ rjf: Animation Cache Interaction API
internal F32
ui_anim_(UI_Key key, UI_AnimParams *params)
{
// rjf: get animation cache node
UI_AnimNode *node = &ui_nil_anim_node;
{
U64 slot_idx = key.u64[0]%ui_state->anim_slots_count;
UI_AnimSlot *slot = &ui_state->anim_slots[slot_idx];
for(UI_AnimNode *n = slot->first; n != &ui_nil_anim_node; n = n->slot_next)
{
if(ui_key_match(n->key, key))
{
node = n;
break;
}
}
if(node == &ui_nil_anim_node)
{
node = ui_state->free_anim_node;
if(node != 0)
{
SLLStackPop_N(ui_state->free_anim_node, slot_next);
}
else
{
node = push_array(ui_state->arena, UI_AnimNode, 1);
}
node->first_touched_build_index = ui_state->build_index;
node->key = key;
MemoryCopyStruct(&node->params, params);
DLLPushBack_NPZ(&ui_nil_anim_node, slot->first, slot->last, node, slot_next, slot_prev);
}
else
{
DLLRemove_NPZ(&ui_nil_anim_node, ui_state->lru_anim_node, ui_state->mru_anim_node, node, lru_next, lru_prev);
}
}
// rjf: touch node & update parameters - grab current
node->last_touched_build_index = ui_state->build_index;
DLLPushBack_NPZ(&ui_nil_anim_node, ui_state->lru_anim_node, ui_state->mru_anim_node, node, lru_next, lru_prev);
MemoryCopyStruct(&node->params, params);
if(node->params.epsilon == 0)
{
node->params.epsilon = (node->params.target - node->params.initial) / 10000.f;
}
return node->current;;
}
////////////////////////////////
//~ rjf: Stacks
-53
View File
@@ -571,39 +571,6 @@ struct UI_Nav
Vec2S64 new_p;
};
////////////////////////////////
//~ rjf: Animation State Types
typedef struct UI_AnimParams UI_AnimParams;
struct UI_AnimParams
{
F32 initial;
F32 target;
F32 rate;
F32 epsilon;
};
typedef struct UI_AnimNode UI_AnimNode;
struct UI_AnimNode
{
UI_AnimNode *slot_next;
UI_AnimNode *slot_prev;
UI_AnimNode *lru_next;
UI_AnimNode *lru_prev;
U64 first_touched_build_index;
U64 last_touched_build_index;
UI_Key key;
UI_AnimParams params;
F32 current;
};
typedef struct UI_AnimSlot UI_AnimSlot;
struct UI_AnimSlot
{
UI_AnimNode *first;
UI_AnimNode *last;
};
////////////////////////////////
//~ rjf: Generated Code
@@ -634,13 +601,6 @@ struct UI_State
U64 box_table_size;
UI_BoxHashSlot *box_table;
//- rjf: anim cache
UI_AnimNode *free_anim_node;
UI_AnimNode *lru_anim_node;
UI_AnimNode *mru_anim_node;
U64 anim_slots_count;
UI_AnimSlot *anim_slots;
//- rjf: build state machine state
B32 is_in_open_ctx_menu;
@@ -662,7 +622,6 @@ struct UI_State
UI_EventList *events;
Vec2F32 mouse;
F32 animation_dt;
F32 default_animation_rate;
//- rjf: user interaction state
UI_Key hot_box_key;
@@ -893,18 +852,6 @@ internal U64 ui_box_char_pos_from_xy(UI_Box *box, Vec2F32 xy);
internal UI_Signal ui_signal_from_box(UI_Box *box);
////////////////////////////////
//~ rjf: Animation Cache Interaction API
read_only global UI_AnimNode ui_nil_anim_node =
{
&ui_nil_anim_node,
&ui_nil_anim_node,
};
internal F32 ui_anim_(UI_Key key, UI_AnimParams *params);
#define ui_anim(key, target_val, ...) ui_anim_((key), &(UI_AnimParams){.target = (target_val), __VA_ARGS__, .rate = (ui_state->default_animation_rate)})
////////////////////////////////
//~ rjf: Stacks