almost there (open window)
This commit is contained in:
1 parent
cf86dd10a7
commit
bf13f269fe
6 files changed
+84
-29
No files matched your search
+1
-1
@@ -27,4 +27,4 @@ internal int32 safe_cast_int32(int64 val)
|
|||||||
|
|
||||||
#define STB_SPRINTF_IMPLEMENTATION
|
#define STB_SPRINTF_IMPLEMENTATION
|
||||||
#define STB_SPRINTF_STATIC
|
#define STB_SPRINTF_STATIC
|
||||||
#include "external/stb/stb_sprintf.h"
|
#include "external/stb_sprintf/stb_sprintf.h"
|
||||||
+15
-12
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#define STB_SPRINTF_DECORATE(name) juliet_##name
|
#define STB_SPRINTF_DECORATE(name) juliet_##name
|
||||||
#define STB_SPRINTF_STATIC
|
#define STB_SPRINTF_STATIC
|
||||||
#include "external/stb/stb_sprintf.h"
|
#include "external/stb_sprintf/stb_sprintf.h"
|
||||||
|
|
||||||
#define internal static
|
#define internal static
|
||||||
#define global static
|
#define global static
|
||||||
@@ -119,30 +119,33 @@
|
|||||||
#define CheckNil(nil, ptr) ((ptr) == 0 || (ptr) == nil)
|
#define CheckNil(nil, ptr) ((ptr) == 0 || (ptr) == nil)
|
||||||
#define SetNil(nil, ptr) ((ptr) = nil)
|
#define SetNil(nil, ptr) ((ptr) = nil)
|
||||||
|
|
||||||
|
// Doubly-linked-lists
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define DLL_insert_NPZ(nil, first, last, ptr, node, next, previous) \
|
#define DLL_insert_next_prev_zero(nil, first, last, ptr, node, next, previous) \
|
||||||
(CheckNil(nil, first) ? ((first) = (last) = (node), SetNil(nil, (node)->next), SetNil(nil, (node)->previous)) \
|
(CheckNil(nil, first) ? ((first) = (last) = (node), SetNil(nil, (node)->next), SetNil(nil, (node)->previous)) \
|
||||||
: CheckNil(nil, ptr) ? ((node)->next = (first), (first)->previous = (node), (first) = (node), SetNil(nil, (node)->previous)) \
|
: CheckNil(nil, ptr) ? ((node)->next = (first), (first)->previous = (node), (first) = (node), SetNil(nil, (node)->previous)) \
|
||||||
: ((ptr) == (last)) ? ((last)->next = (node), (node )->previous = (last), (last ) = (node), SetNil(nil, (node)->next)) \
|
: ((ptr) == (last)) ? ((last)->next = (node), (node )->previous = (last), (last ) = (node), SetNil(nil, (node)->next)) \
|
||||||
: (((CheckNil(nil, ptr) && CheckNil(nil, (ptr)->next)) ? (0) : ((ptr)->next->previous = (node))), \
|
: (((CheckNil(nil, ptr) && CheckNil(nil, (ptr)->next)) ? (0) : ((ptr)->next->previous = (node))), \
|
||||||
((node)->next = (ptr)->next), ((ptr)->next = (node)), ((node)->previous = (ptr))))
|
((node)->next = (ptr)->next), ((ptr)->next = (node)), ((node)->previous = (ptr))))
|
||||||
// clang-format on
|
#define DLL_push_back_next_prev_zero(nil, first, last, node, next, previous) \
|
||||||
#define DLL_push_back_NPZ(nil, first, last, node, next, previous) \
|
DLL_insert_next_prev_zero(nil, first, last, last, node, next, previous)
|
||||||
DLL_insert_NPZ(nil, first, last, last, node, next, previous)
|
#define DLL_remove_next_prev_zero(nil, first, last, node, next, previous) \
|
||||||
#define DLL_remove_NPZ(nil, first, last, node, next, previous) \
|
|
||||||
(((node) == (first) ? (first) = (node)->next : (0)), ((node) == (last) ? (last) = (last)->previous : (0)), \
|
(((node) == (first) ? (first) = (node)->next : (0)), ((node) == (last) ? (last) = (last)->previous : (0)), \
|
||||||
(CheckNil(nil, (node)->previous) ? (0) : ((node)->previous->next = (node)->next)), \
|
(CheckNil(nil, (node)->previous) ? (0) : ((node)->previous->next = (node)->next)), \
|
||||||
(CheckNil(nil, (node)->next) ? (0) : ((node)->next->previous = (node)->previous)))
|
(CheckNil(nil, (node)->next) ? (0) : ((node)->next->previous = (node)->previous)))
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
// Single (link & head) lists (= stacks)
|
// Single (link & head) lists (= stacks)
|
||||||
#define SLL_stack_push_node(first, node, next) ((node)->next = (first), (first) = (node))
|
#define SLL_stack_push_next(first, node, next) ((node)->next = (first), (first) = (node))
|
||||||
#define SLL_stack_pop_node(first, next) ((first) = (first)->next);
|
#define SLL_stack_pop_next(first, next) ((first) = (first)->next);
|
||||||
#define SLL_stack_push(first, node) SLL_stack_push_node(first, node, next)
|
#define SLL_stack_push(first, node) SLL_stack_push_next(first, node, next)
|
||||||
#define SLL_stack_pop(first) SLL_stack_pop_node(first, next)
|
#define SLL_stack_pop(first) SLL_stack_pop_next(first, next)
|
||||||
|
|
||||||
// Double linked list helpers
|
// Double linked list helpers
|
||||||
#define DLL_push_back(first, last, node) DLL_push_back_NPZ(0, first, last, node, next, previous)
|
#define DLL_push_back_next_prev(first, last, node, next, previous) \
|
||||||
#define DLL_remove(first, last, node) DLL_remove_NPZ(0, first, last, node, next, previous)
|
DLL_push_back_next_prev_zero(0, first, last, node, next, previous)
|
||||||
|
#define DLL_push_back(first, last, node) DLL_push_back_next_prev_zero(0, first, last, node, next, previous)
|
||||||
|
#define DLL_remove(first, last, node) DLL_remove_next_prev_zero(0, first, last, node, next, previous)
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ internal void* arena_push(Arena* arena, uint64 size, uint64 align, bool32 zero)
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_block->base_position = current->base_position + current->reserved;
|
new_block->base_position = current->base_position + current->reserved;
|
||||||
SLL_stack_push_node(arena->current, new_block, previous);
|
SLL_stack_push_next(arena->current, new_block, previous);
|
||||||
|
|
||||||
current = new_block;
|
current = new_block;
|
||||||
pos_pre = AlignPow2(current->position, align);
|
pos_pre = AlignPow2(current->position, align);
|
||||||
|
|||||||
@@ -21,5 +21,6 @@ internal uint64 uint64_hash_from_string(String8 string)
|
|||||||
|
|
||||||
internal uint64 uint64_hash_from_seed_string(uint64 seed, String8 string)
|
internal uint64 uint64_hash_from_seed_string(uint64 seed, String8 string)
|
||||||
{
|
{
|
||||||
return 0;
|
uint64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,12 @@ internal void ja_init()
|
|||||||
ja_state->arena = arena;
|
ja_state->arena = arena;
|
||||||
|
|
||||||
// Window cache
|
// Window cache
|
||||||
ja_state->window_state_gen_id = 1;
|
{
|
||||||
ja_state->first_window_state = ja_state->last_window_state = &ja_nil_window_state;
|
ja_state->window_state_gen_id = 1;
|
||||||
|
ja_state->window_state_slots_count = 64;
|
||||||
|
ja_state->window_state_slots = push_array(arena, JA_WindowStateSlot, ja_state->window_state_slots_count);
|
||||||
|
ja_state->first_window_state = ja_state->last_window_state = &ja_nil_window_state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ja_frame()
|
internal void ja_frame()
|
||||||
@@ -46,11 +50,10 @@ internal void ja_frame()
|
|||||||
|
|
||||||
// Window management (open/render)
|
// Window management (open/render)
|
||||||
{
|
{
|
||||||
for
|
for (uint64 id = 1; id < ja_state->window_state_gen_id + 1; ++id)
|
||||||
EachIndex(slot_idx, ja_state->window_state_gen_id)
|
{
|
||||||
{
|
JA_WindowState* ws = ja_window_state_from_id(id);
|
||||||
JA_WindowState* ws = ja_window_state_from_id(slot_idx);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
@@ -75,10 +78,44 @@ internal JA_WindowState* ja_window_state_from_id(JA_ID id)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint64 hash = uint64_hash_from_string(str8_struct(&id));
|
uint64 hash = uint64_hash_from_string(str8_struct(&id));
|
||||||
|
uint64 slot_idx = hash % ja_state->window_state_slots_count;
|
||||||
|
JA_WindowStateSlot* slot = &ja_state->window_state_slots[slot_idx];
|
||||||
|
for (JA_WindowState* w = slot->first; w != 0; w = w->hash_next)
|
||||||
|
{
|
||||||
|
if (w->id == id)
|
||||||
|
{
|
||||||
|
ws = w;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate / open window if none found for this id
|
// allocate / open window if none found for this id
|
||||||
|
if (ws == &ja_nil_window_state)
|
||||||
|
{
|
||||||
|
ws = ja_state->free_window_state;
|
||||||
|
if (ws != 0)
|
||||||
|
{
|
||||||
|
SLL_stack_pop_next(ja_state->free_window_state, order_next);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ws = push_array_no_zero(ja_state->arena, JA_WindowState, 1);
|
||||||
|
}
|
||||||
|
MemoryZeroStruct(ws);
|
||||||
|
|
||||||
|
ws->id = id;
|
||||||
|
ws->arena = arena_alloc();
|
||||||
|
|
||||||
|
// hook up the window
|
||||||
|
uint64 hash = uint64_hash_from_string(str8_struct(&id));
|
||||||
|
uint64 slot_idx = hash % ja_state->window_state_slots_count;
|
||||||
|
JA_WindowStateSlot* slot = &ja_state->window_state_slots[slot_idx];
|
||||||
|
DLL_push_back_next_prev_zero(&ja_nil_window_state, ja_state->first_window_state, ja_state->last_window_state,
|
||||||
|
ws, order_next, order_previous);
|
||||||
|
DLL_push_back_next_prev(slot->first, slot->last, ws, hash_next, hash_previous);
|
||||||
|
}
|
||||||
|
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,23 @@ typedef uint64 JA_ID;
|
|||||||
typedef struct JA_WindowState JA_WindowState;
|
typedef struct JA_WindowState JA_WindowState;
|
||||||
struct JA_WindowState
|
struct JA_WindowState
|
||||||
{
|
{
|
||||||
|
// links and metadata
|
||||||
JA_WindowState* order_next;
|
JA_WindowState* order_next;
|
||||||
JA_WindowState* order_previous;
|
JA_WindowState* order_previous;
|
||||||
JA_WindowState* hash_next;
|
JA_WindowState* hash_next;
|
||||||
JA_WindowState* hash_previous;
|
JA_WindowState* hash_previous;
|
||||||
JA_ID id;
|
JA_ID id;
|
||||||
WM_Window plat_handle;
|
|
||||||
|
// Info and handle
|
||||||
|
Arena* arena;
|
||||||
|
WM_Window plat_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct JA_WindowStateSlot JA_WindowStateSlot;
|
||||||
|
struct JA_WindowStateSlot
|
||||||
|
{
|
||||||
|
JA_WindowState* first;
|
||||||
|
JA_WindowState* last;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct JA_State JA_State;
|
typedef struct JA_State JA_State;
|
||||||
@@ -26,11 +37,14 @@ struct JA_State
|
|||||||
bool32 quit;
|
bool32 quit;
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
JA_WindowState* first_window_state;
|
JA_WindowState* free_window_state;
|
||||||
JA_WindowState* last_window_state;
|
uint64 window_state_slots_count;
|
||||||
JA_WindowState* window_state_last_accessed;
|
JA_WindowStateSlot* window_state_slots;
|
||||||
JA_ID window_state_last_accessed_id;
|
JA_WindowState* first_window_state;
|
||||||
JA_ID window_state_gen_id;
|
JA_WindowState* last_window_state;
|
||||||
|
JA_ID window_state_last_accessed_id;
|
||||||
|
JA_ID window_state_gen_id;
|
||||||
|
JA_WindowState* window_state_last_accessed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|||||||
Reference in new issue
Block a user