sim cmd testing
This commit is contained in:
parent
994c84ae5c
commit
18c54c4507
@ -482,7 +482,9 @@ typedef u32 b32;
|
||||
|
||||
//- Gpu scalar types
|
||||
typedef int i32;
|
||||
typedef int2 i64;
|
||||
typedef uint u32;
|
||||
typedef uint2 u64;
|
||||
typedef float f32;
|
||||
typedef uint b32;
|
||||
|
||||
@ -671,6 +673,15 @@ Struct(StringList)
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ U128 types
|
||||
|
||||
Struct(U128)
|
||||
{
|
||||
u64 hi;
|
||||
u64 lo;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource types
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ String StringFromButton(Button button)
|
||||
[Button_F22] = CompLit("F22"),
|
||||
[Button_F23] = CompLit("F23"),
|
||||
[Button_F24] = CompLit("F24"),
|
||||
[Button_GraveAccent] = CompLit("Tilde"),
|
||||
[Button_GraveAccent] = CompLit("~"),
|
||||
[Button_0] = CompLit("0"),
|
||||
[Button_1] = CompLit("1"),
|
||||
[Button_2] = CompLit("2"),
|
||||
|
||||
@ -5,7 +5,7 @@ Readonly PP_Ent PP_nil_ent = ZI;
|
||||
|
||||
b32 PP_IsKeyNil(PP_EntKey key)
|
||||
{
|
||||
return key.v == 0;
|
||||
return key.v.hi == 0 && key.v.lo == 0;
|
||||
}
|
||||
|
||||
b32 PP_IsEntNil(PP_Ent *ent)
|
||||
|
||||
@ -4,26 +4,79 @@
|
||||
#define PP_NilKey ((PP_Key) { 0 })
|
||||
|
||||
Struct(PP_EntKey)
|
||||
{
|
||||
U128 v;
|
||||
};
|
||||
|
||||
Struct(PP_EntNum)
|
||||
{
|
||||
u64 v;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Property types
|
||||
//~ Ent types
|
||||
|
||||
//////////////////////////////
|
||||
//- Ent roperties
|
||||
|
||||
Enum(PP_EntProp)
|
||||
{
|
||||
PP_EntProp_None,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Ent types
|
||||
//////////////////////////////
|
||||
//- Ent
|
||||
|
||||
Struct(PP_Ent)
|
||||
{
|
||||
i32 _;
|
||||
PP_EntKey parent;
|
||||
PP_EntKey first;
|
||||
PP_EntKey last;
|
||||
PP_EntKey next;
|
||||
PP_EntKey prev;
|
||||
|
||||
PP_EntKey key;
|
||||
} extern Readonly PP_nil_ent;
|
||||
|
||||
//////////////////////////////
|
||||
//- Ent list
|
||||
|
||||
Struct(PP_EntListNode)
|
||||
{
|
||||
PP_EntListNode *next;
|
||||
PP_Ent ent;
|
||||
};
|
||||
|
||||
Struct(PP_EntList)
|
||||
{
|
||||
PP_EntListNode *first;
|
||||
PP_EntListNode *last;
|
||||
u64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Ent lookup types
|
||||
|
||||
Struct(PP_EntLookupBin)
|
||||
{
|
||||
PP_EntNum first;
|
||||
PP_EntNum last;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ World types
|
||||
|
||||
Struct(PP_World)
|
||||
{
|
||||
i64 tick;
|
||||
|
||||
PP_Ent *ents;
|
||||
i64 ents_count;
|
||||
|
||||
PP_EntLookupBin *bins;
|
||||
i64 bins_count;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Nil helpers
|
||||
|
||||
|
||||
@ -54,28 +54,39 @@ JobDef(PP_SimWorker, sig, job_id)
|
||||
i64 frame_begin_ns = TimeNs();
|
||||
|
||||
//////////////////////////////
|
||||
//- Swap & pop v2s
|
||||
//- Pop sim commands
|
||||
|
||||
PP_VisToSimState *v2s = 0;
|
||||
LockTicketMutex(&shared->v2s_back_tm);
|
||||
{
|
||||
i32 v2s_front_idx = Atomic32Fetch(&shared->v2s_front_idx);
|
||||
v2s = &shared->v2s[v2s_front_idx];
|
||||
i32 new_v2s_front_idx = v2s_front_idx + 1;
|
||||
if (new_v2s_front_idx >= countof(shared->v2s))
|
||||
v2s = &shared->v2s[shared->v2s_back_idx];
|
||||
++shared->v2s_back_idx;
|
||||
if (shared->v2s_back_idx >= countof(shared->v2s))
|
||||
{
|
||||
new_v2s_front_idx = 0;
|
||||
shared->v2s_back_idx = 0;
|
||||
}
|
||||
LockTicketMutex(&v2s->tm);
|
||||
{
|
||||
Atomic32Set(&shared->v2s_front_idx, new_v2s_front_idx);
|
||||
}
|
||||
UnlockTicketMutex(&v2s->tm);
|
||||
UnlockTicketMutex(&shared->v2s_back_tm);
|
||||
|
||||
//////////////////////////////
|
||||
//- Process sim commands
|
||||
|
||||
for (PP_SimCmdNode *cmd_node = v2s->first_cmd_node; cmd_node; cmd_node = cmd_node->next)
|
||||
{
|
||||
PP_SimCmd cmd = cmd_node->cmd;
|
||||
switch (cmd.kind)
|
||||
{
|
||||
case PP_SimCmdKind_Ent:
|
||||
{
|
||||
LogInfoF("Ent cmd");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- End sim frame
|
||||
|
||||
/* Reset v2s */
|
||||
/* Reset front v2s */
|
||||
{
|
||||
Arena *arena = v2s->arena;
|
||||
ResetArena(arena);
|
||||
@ -288,7 +299,9 @@ JobDef(PP_VisWorker, sig, job_id)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- Process vis cmds
|
||||
//- Process vis commands
|
||||
|
||||
PP_EntList spawn_ents = ZI;
|
||||
|
||||
for (PP_VisCmdNode *cmd_node = first_cmd_node; cmd_node; cmd_node = cmd_node->next)
|
||||
{
|
||||
@ -347,7 +360,9 @@ JobDef(PP_VisWorker, sig, job_id)
|
||||
|
||||
case PP_VisCmdKind_spawn:
|
||||
{
|
||||
LogErrorF("RAAAAH");
|
||||
PP_EntListNode *n = PushStruct(frame_arena, PP_EntListNode);
|
||||
++spawn_ents.count;
|
||||
QueuePush(spawn_ents.first, spawn_ents.last, n);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@ -355,6 +370,19 @@ JobDef(PP_VisWorker, sig, job_id)
|
||||
//////////////////////////////
|
||||
//- Submit sim commands
|
||||
|
||||
LockTicketMutex(&shared->v2s_back_tm);
|
||||
{
|
||||
PP_VisToSimState *v2s = &shared->v2s[shared->v2s_back_idx];
|
||||
for (PP_EntListNode *ent_node = spawn_ents.first; ent_node; ent_node = ent_node->next)
|
||||
{
|
||||
PP_SimCmdNode *cmd_node = PushStruct(v2s->arena, PP_SimCmdNode);
|
||||
cmd_node->cmd.kind = PP_SimCmdKind_Ent;
|
||||
cmd_node->cmd.ent = ent_node->ent;
|
||||
QueuePush(v2s->first_cmd_node, v2s->last_cmd_node, cmd_node);
|
||||
++v2s->cmds_count;
|
||||
}
|
||||
}
|
||||
UnlockTicketMutex(&shared->v2s_back_tm);
|
||||
|
||||
//////////////////////////////
|
||||
//- End vis frame
|
||||
|
||||
@ -1,18 +1,3 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Sim cmd types
|
||||
|
||||
Enum(PP_SimCmdKind)
|
||||
{
|
||||
PP_SimCmdKind_None,
|
||||
|
||||
PP_SimCmdKind_Count,
|
||||
};
|
||||
|
||||
Struct(PP_SimCmd)
|
||||
{
|
||||
PP_SimCmd *next;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Vis command table
|
||||
|
||||
@ -24,12 +9,42 @@ Struct(PP_SimCmd)
|
||||
X(toggle_console, Toggle Developer Console, PP_VisCmdDescFlag_None, PP_HOTKEY( Button_GraveAccent ), ) \
|
||||
X(toggle_fullscreen, Toggle Fullscreen Mode, PP_VisCmdDescFlag_None, PP_HOTKEY( Button_Enter, .alt = 1 ), PP_HOTKEY( Button_F11 ) ) \
|
||||
X(toggle_window_topmost, Toggle Window Topmost, PP_VisCmdDescFlag_None, PP_HOTKEY( Button_F4 ), ) \
|
||||
X(spawn, Ctrl, PP_VisCmdDescFlag_None, PP_HOTKEY( Button_S, .ctrl = 1 ), ) \
|
||||
X(spawn, Spawn, PP_VisCmdDescFlag_None, PP_HOTKEY( Button_S, .ctrl = 1 ), ) \
|
||||
/* -------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Sim command types
|
||||
|
||||
Enum(PP_SimCmdKind)
|
||||
{
|
||||
PP_SimCmdKind_Nop,
|
||||
PP_SimCmdKind_Ent,
|
||||
};
|
||||
|
||||
Struct(PP_SimCmd)
|
||||
{
|
||||
PP_SimCmdKind kind;
|
||||
PP_Ent ent;
|
||||
};
|
||||
|
||||
Struct(PP_SimCmdNode)
|
||||
{
|
||||
PP_SimCmdNode *next;
|
||||
PP_SimCmd cmd;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Vis command types
|
||||
|
||||
Enum(PP_VisCmdKind)
|
||||
{
|
||||
#define X(name, ...) PP_VisCmdKind_##name,
|
||||
PP_VisCmdsTableXMacro(X)
|
||||
#undef X
|
||||
|
||||
PP_VisCmdKind_Count,
|
||||
};
|
||||
|
||||
Struct(PP_Shortcut)
|
||||
{
|
||||
PP_Shortcut *next_in_bin;
|
||||
@ -70,15 +85,6 @@ Struct(PP_VisCmdNode)
|
||||
PP_VisCmd cmd;
|
||||
};
|
||||
|
||||
Enum(PP_VisCmdKind)
|
||||
{
|
||||
#define X(name, ...) PP_VisCmdKind_##name,
|
||||
PP_VisCmdsTableXMacro(X)
|
||||
#undef X
|
||||
|
||||
PP_VisCmdKind_Count,
|
||||
};
|
||||
|
||||
Global Readonly PP_VisCmdDesc PP_vis_cmd_descs[PP_VisCmdKind_Count] = {
|
||||
#define X(_name, _display_name, _flags, ...) { .name = CompLit(#_name), .display_name = CompLit(#_display_name), .flags = _flags, .default_hotkeys = { __VA_ARGS__ } },
|
||||
PP_VisCmdsTableXMacro(X)
|
||||
@ -92,10 +98,10 @@ Global Readonly PP_VisCmdDesc PP_vis_cmd_descs[PP_VisCmdKind_Count] = {
|
||||
|
||||
Struct(PP_VisToSimState)
|
||||
{
|
||||
TicketMutex tm;
|
||||
Arena *arena;
|
||||
PP_SimCmd *first_cmd;
|
||||
PP_SimCmd *last_cmd;
|
||||
PP_SimCmdNode *first_cmd_node;
|
||||
PP_SimCmdNode *last_cmd_node;
|
||||
u64 cmds_count;
|
||||
};
|
||||
|
||||
Struct(PP_SharedState)
|
||||
@ -105,7 +111,8 @@ Struct(PP_SharedState)
|
||||
i64 workers_count;
|
||||
|
||||
//- Vis -> Sim
|
||||
Atomic32 v2s_front_idx;
|
||||
TicketMutex v2s_back_tm;
|
||||
i32 v2s_back_idx;
|
||||
PP_VisToSimState v2s[PP_VisToSimStatesCount];
|
||||
|
||||
} extern PP_shared_state;
|
||||
|
||||
@ -4,15 +4,17 @@
|
||||
PP_WidgetTheme PP_GetWidgetTheme(void)
|
||||
{
|
||||
PP_WidgetTheme theme = ZI;
|
||||
|
||||
theme.font = ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf"));
|
||||
theme.font_size = 16;
|
||||
|
||||
theme.window_background_color = Rgb32(0xff1a1d1e);
|
||||
theme.window_border_color = Rgb32(0xff343a3b);
|
||||
theme.window_border = 1;
|
||||
theme.window_width = 600;
|
||||
theme.window_width = 500;
|
||||
theme.window_padding = theme.window_border - 1;
|
||||
theme.divider_color = theme.window_border_color;
|
||||
|
||||
theme.font_size = 16;
|
||||
theme.window_title_font_size = 16;
|
||||
theme.text_padding_x = 3;
|
||||
theme.text_padding_y = 3;
|
||||
|
||||
@ -56,20 +56,20 @@ UI_Key UI_TransKey(void)
|
||||
UI_Box *UI_BoxFromKey(UI_Key key)
|
||||
{
|
||||
UI_State *g = &UI_state;
|
||||
UI_Box *front_box = 0;
|
||||
UI_Box *box = 0;
|
||||
if (key.hash != 0)
|
||||
{
|
||||
UI_BoxBin *front_bin = &g->box_bins[key.hash % UI_NumBoxLookupBins];
|
||||
for (UI_Box *tmp = front_bin->first; tmp; tmp = tmp->next_in_bin)
|
||||
UI_BoxBin *bin = &g->box_bins[key.hash % UI_NumBoxLookupBins];
|
||||
for (UI_Box *tmp = bin->first; tmp; tmp = tmp->next_in_bin)
|
||||
{
|
||||
if (tmp->key.hash == key.hash)
|
||||
{
|
||||
front_box = tmp;
|
||||
box = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return front_box;
|
||||
return box;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
Reference in New Issue
Block a user