bitbuff refactor
This commit is contained in:
parent
8e1cbdd192
commit
deaa397709
@ -9,7 +9,7 @@ GLOBAL struct {
|
||||
|
||||
INTERNAL String initialize_write_directory(Arena *arena, String write_dir)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
/* Create write path */
|
||||
String base_write_dir = P_GetWritePath(scratch.arena);
|
||||
@ -27,7 +27,7 @@ INTERNAL String initialize_write_directory(Arena *arena, String write_dir)
|
||||
/* TODO: handle failure */
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return write_path;
|
||||
}
|
||||
@ -120,7 +120,7 @@ INTERNAL struct app_arg_list parse_args(Arena *arena, String args_str)
|
||||
if (key_start >= 0 && key_end > key_start && key_end <= (i64)args_str.len && value_start >= 0 && value_end > value_start && value_end <= (i64)args_str.len) {
|
||||
String key = string_copy(arena, STRING(key_end - key_start, args_str.text + key_start));
|
||||
String value = string_copy(arena, STRING(value_end - value_start, args_str.text + value_start));
|
||||
struct app_arg *arg = arena_push(arena, struct app_arg);
|
||||
struct app_arg *arg = PushStruct(arena, struct app_arg);
|
||||
arg->key = key;
|
||||
arg->value = value;
|
||||
if (res.last) {
|
||||
@ -149,7 +149,7 @@ INTERNAL struct app_arg_list parse_args(Arena *arena, String args_str)
|
||||
void P_AppStartup(String args_str)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
struct app_arg_list args = parse_args(scratch.arena, args_str);
|
||||
String logfile_name = LIT("log.log");
|
||||
@ -180,21 +180,21 @@ void P_AppStartup(String args_str)
|
||||
|
||||
#if !RTC
|
||||
/* Verify test modes aren't left on by accident in release mode */
|
||||
STATIC_ASSERT(BITBUFF_DEBUG == 0);
|
||||
STATIC_ASSERT(BB_DebugIsEnabled == 0);
|
||||
STATIC_ASSERT(BITBUFF_TEST == 0);
|
||||
#endif
|
||||
|
||||
#if BITBUFF_TEST
|
||||
bitbuff_test();
|
||||
BB_Test();
|
||||
#endif
|
||||
|
||||
G.arena = arena_alloc(GIBI(64));
|
||||
G.arena = AllocArena(GIBI(64));
|
||||
|
||||
G.write_path = initialize_write_directory(G.arena, LIT(WRITE_DIR));
|
||||
|
||||
/* Startup logging */
|
||||
{
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
String logfile_dir = string_cat(temp.arena, G.write_path, LIT("logs/"));
|
||||
String logfile_path = string_cat(temp.arena, logfile_dir, logfile_name);
|
||||
@ -202,7 +202,7 @@ void P_AppStartup(String args_str)
|
||||
|
||||
P_LogStartup(logfile_path);
|
||||
P_LogInfoF("Start of logs");
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
P_LogInfoF("App started with args \"%F\" (%F parsed)", FMT_STR(args_str), FMT_UINT(args.count));
|
||||
for (struct app_arg *arg = args.first; arg; arg = arg->next) {
|
||||
@ -212,7 +212,7 @@ void P_AppStartup(String args_str)
|
||||
#if 0
|
||||
/* Read window settings from file */
|
||||
{
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
P_WindowSettings window_settings = ZI;
|
||||
String settings_path = app_write_path_cat(temp.arena, settings_file_name);
|
||||
@ -248,7 +248,7 @@ void P_AppStartup(String args_str)
|
||||
string_copy_to_string(STRING_FROM_ARRAY(window_settings.title), LIT(WINDOW_TITLE));
|
||||
P_UpdateWindowSettings(window, &window_settings);
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -279,7 +279,7 @@ void P_AppStartup(String args_str)
|
||||
/* Write window settings to file */
|
||||
{
|
||||
__profn("Write settings file");
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
String window_settings_path = app_write_path_cat(temp.arena, settings_file_name);
|
||||
|
||||
@ -293,7 +293,7 @@ void P_AppStartup(String args_str)
|
||||
P_CloseFIle(settings_file);
|
||||
P_LogInfoF("Finished writing settings file");
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -302,5 +302,5 @@ void P_AppStartup(String args_str)
|
||||
#endif
|
||||
|
||||
//P_LogInfoF("Program exited normally");
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define ASE_H
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "../bitbuff/bitbuff.h"
|
||||
|
||||
#include "ase_core.h"
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ INTERNAL struct huffman huffman_init(Arena *arena, u32 max_code_bits, u32 *bl_co
|
||||
struct huffman res = ZI;
|
||||
res.max_code_bits = max_code_bits;
|
||||
res.entries_count = (1 << max_code_bits);
|
||||
res.entries = arena_push_array_no_zero(arena, struct huffman_entry, res.entries_count);
|
||||
res.entries = PushArrayNoZero(arena, struct huffman_entry, res.entries_count);
|
||||
|
||||
u32 code_length_hist[HUFFMAN_BIT_COUNT] = ZI;
|
||||
for (u32 i = 0; i < bl_counts_count; ++i) {
|
||||
@ -231,7 +231,7 @@ INTERNAL u16 huffman_decode(struct huffman *huffman, struct huff_bb *bb)
|
||||
|
||||
INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
__prof;
|
||||
struct huff_bb bb = { .data = encoded };
|
||||
@ -271,7 +271,7 @@ INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
|
||||
case BLOCK_TYPE_COMPRESSED_FIXED:
|
||||
case BLOCK_TYPE_COMPRESSED_DYNAMIC: {
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
u32 lit_len_dist_table[512] = ZI;
|
||||
u32 hlit;
|
||||
u32 hdist;
|
||||
@ -367,7 +367,7 @@ INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
}
|
||||
}
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
} break;
|
||||
|
||||
case BLOCK_TYPE_RESERVED: {
|
||||
@ -377,7 +377,7 @@ INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -442,7 +442,7 @@ PACK(struct frame_header {
|
||||
|
||||
INTERNAL void push_error_copy_msg(Arena *arena, Ase_ErrorList *list, String msg_src)
|
||||
{
|
||||
Ase_Error *e = arena_push(arena, Ase_Error);
|
||||
Ase_Error *e = PushStruct(arena, Ase_Error);
|
||||
e->msg = string_copy(arena, msg_src);
|
||||
if (!list->first) {
|
||||
list->first = e;
|
||||
@ -548,13 +548,13 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
{
|
||||
__prof;
|
||||
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
Ase_DecodedImage res = ZI;
|
||||
|
||||
Bitbuff bb = bitbuff_from_string(encoded);
|
||||
BitbuffReader br = br_from_bitbuff_no_debug(&bb);
|
||||
BB_Buff bb = BitbuffFromString(encoded);
|
||||
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
|
||||
struct ase_header ase_header;
|
||||
br_read_bytes(&br, STRING_FROM_STRUCT(&ase_header));
|
||||
BB_ReadBytes(&br, STRING_FROM_STRUCT(&ase_header));
|
||||
|
||||
if (ase_header.magic != 0xA5E0) {
|
||||
push_error_copy_msg(arena, &res.errors, LIT("Not a valid aseprite file"));
|
||||
@ -581,7 +581,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
res.image.width = image_width;
|
||||
res.image.height = image_height;
|
||||
/* TODO: Optimize this. Naive memset(0) is bloating the decode time for large images. */
|
||||
res.image.pixels = arena_push_array(arena, u32, image_width * image_height);
|
||||
res.image.pixels = PushArray(arena, u32, image_width * image_height);
|
||||
|
||||
u32 num_layers = 0;
|
||||
struct layer *layer_head = 0;
|
||||
@ -593,7 +593,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
u32 num_frames = 0;
|
||||
for (u16 i = 0; i < ase_header.frames; ++i) {
|
||||
struct frame_header frame_header;
|
||||
br_read_bytes(&br, STRING_FROM_STRUCT(&frame_header));
|
||||
BB_ReadBytes(&br, STRING_FROM_STRUCT(&frame_header));
|
||||
|
||||
u32 num_chunks = frame_header.chunks_new;
|
||||
if (num_chunks == 0) {
|
||||
@ -603,29 +603,29 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
|
||||
/* Iterate chunks in frame */
|
||||
for (u32 j = 0; j < num_chunks; ++j) {
|
||||
u32 chunk_size = br_read_ubits(&br, 32);
|
||||
enum chunk_type chunk_type = br_read_ubits(&br, 16);
|
||||
u32 chunk_size = BB_ReadUBits(&br, 32);
|
||||
enum chunk_type chunk_type = BB_ReadUBits(&br, 16);
|
||||
|
||||
/* Chunk size includes size & type */
|
||||
ASSERT(chunk_size >= 6);
|
||||
chunk_size -= 6;
|
||||
|
||||
u64 chunk_end_pos = br_cur_byte(&br) + chunk_size;
|
||||
u64 chunk_end_pos = BB_GetCurrentReaderByte(&br) + chunk_size;
|
||||
|
||||
switch (chunk_type) {
|
||||
case CHUNK_TYPE_LAYER: {
|
||||
struct layer *layer = arena_push(scratch.arena, struct layer);
|
||||
struct layer *layer = PushStruct(scratch.arena, struct layer);
|
||||
layer->next = layer_head;
|
||||
layer_head = layer;
|
||||
|
||||
layer->flags = br_read_ubits(&br, 16);
|
||||
layer->type = br_read_ubits(&br, 16);
|
||||
layer->child_level = br_read_ubits(&br, 16);
|
||||
layer->flags = BB_ReadUBits(&br, 16);
|
||||
layer->type = BB_ReadUBits(&br, 16);
|
||||
layer->child_level = BB_ReadUBits(&br, 16);
|
||||
|
||||
/* Ignoring layer default width & height */
|
||||
br_seek_bytes(&br, sizeof(u16) * 2);
|
||||
BB_SeekBytes(&br, sizeof(u16) * 2);
|
||||
|
||||
layer->blend_mode = br_read_ubits(&br, 16);
|
||||
layer->blend_mode = BB_ReadUBits(&br, 16);
|
||||
if (layer->blend_mode != 0) {
|
||||
push_error_copy_msg(arena,
|
||||
&res.errors,
|
||||
@ -633,26 +633,26 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
goto abort;
|
||||
}
|
||||
|
||||
layer->opacity = br_read_ubits(&br, 8);
|
||||
layer->opacity = BB_ReadUBits(&br, 8);
|
||||
if (!(ase_header.flags & 1)) {
|
||||
layer->opacity = 255;
|
||||
}
|
||||
|
||||
br_seek_bytes(&br, sizeof(u8) * 3);
|
||||
BB_SeekBytes(&br, sizeof(u8) * 3);
|
||||
|
||||
u16 str_len = br_read_ubits(&br, 16);
|
||||
layer->name = (String) { str_len, arena_push_array_no_zero(scratch.arena, u8, str_len) };
|
||||
br_read_bytes(&br, layer->name);
|
||||
u16 str_len = BB_ReadUBits(&br, 16);
|
||||
layer->name = (String) { str_len, PushArrayNoZero(scratch.arena, u8, str_len) };
|
||||
BB_ReadBytes(&br, layer->name);
|
||||
|
||||
if (layer->type == 2) {
|
||||
layer->tileset_index = br_read_ubits(&br, 32);
|
||||
layer->tileset_index = BB_ReadUBits(&br, 32);
|
||||
}
|
||||
|
||||
layer->index = num_layers++;
|
||||
} break;
|
||||
|
||||
case CHUNK_TYPE_CEL: {
|
||||
struct cel *cel = arena_push(scratch.arena, struct cel);
|
||||
struct cel *cel = PushStruct(scratch.arena, struct cel);
|
||||
if (cel_tail) {
|
||||
cel_tail->next = cel;
|
||||
} else {
|
||||
@ -660,33 +660,33 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
}
|
||||
cel_tail = cel;
|
||||
|
||||
cel->layer_index = br_read_ubits(&br, 16);
|
||||
cel->x_pos = br_read_ibits(&br, 16);
|
||||
cel->y_pos = br_read_ibits(&br, 16);
|
||||
cel->opacity = br_read_ubits(&br, 8);
|
||||
cel->type = br_read_ubits(&br, 16);
|
||||
cel->z_index = br_read_ibits(&br, 16);
|
||||
br_seek_bytes(&br, sizeof(u8) * 5);
|
||||
cel->layer_index = BB_ReadUBits(&br, 16);
|
||||
cel->x_pos = BB_ReadIBits(&br, 16);
|
||||
cel->y_pos = BB_ReadIBits(&br, 16);
|
||||
cel->opacity = BB_ReadUBits(&br, 8);
|
||||
cel->type = BB_ReadUBits(&br, 16);
|
||||
cel->z_index = BB_ReadIBits(&br, 16);
|
||||
BB_SeekBytes(&br, sizeof(u8) * 5);
|
||||
|
||||
cel->frame_index = num_frames;
|
||||
|
||||
switch (cel->type) {
|
||||
case CEL_TYPE_RAW_IMAGE: {
|
||||
/* Unsupported */
|
||||
br_seek_to_byte(&br, chunk_end_pos);
|
||||
BB_SeekToByte(&br, chunk_end_pos);
|
||||
} break;
|
||||
|
||||
case CEL_TYPE_LINKED: {
|
||||
cel->frame_pos = br_read_ubits(&br, 16);
|
||||
cel->frame_pos = BB_ReadUBits(&br, 16);
|
||||
/* Actual linking happens later after iteration */
|
||||
} break;
|
||||
|
||||
case CEL_TYPE_COMPRESSED_IMAGE: {
|
||||
cel->width = br_read_ubits(&br, 16);
|
||||
cel->height = br_read_ubits(&br, 16);
|
||||
cel->width = BB_ReadUBits(&br, 16);
|
||||
cel->height = BB_ReadUBits(&br, 16);
|
||||
|
||||
cel->pixels = arena_push_array_no_zero(scratch.arena, u32, cel->width * cel->height);
|
||||
u8 *huffman_encoded = br_read_bytes_raw(&br, chunk_end_pos - br_cur_byte(&br));
|
||||
cel->pixels = PushArrayNoZero(scratch.arena, u32, cel->width * cel->height);
|
||||
u8 *huffman_encoded = BB_ReadBytesRaw(&br, chunk_end_pos - BB_GetCurrentReaderByte(&br));
|
||||
if (huffman_encoded) {
|
||||
inflate((u8 *)cel->pixels, huffman_encoded);
|
||||
}
|
||||
@ -701,7 +701,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
} break;
|
||||
|
||||
default: {
|
||||
br_seek_to_byte(&br, chunk_end_pos);
|
||||
BB_SeekToByte(&br, chunk_end_pos);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@ -709,13 +709,13 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
}
|
||||
|
||||
/* Create ordered layers array */
|
||||
struct layer **layers_ordered = arena_push_array_no_zero(scratch.arena, struct layer *, num_layers);
|
||||
struct layer **layers_ordered = PushArrayNoZero(scratch.arena, struct layer *, num_layers);
|
||||
for (struct layer *layer = layer_head; layer; layer = layer->next) {
|
||||
layers_ordered[layer->index] = layer;
|
||||
}
|
||||
|
||||
/* Link cels */
|
||||
struct cel **cels_ordered = arena_push_array_no_zero(scratch.arena, struct cel *, num_frames * num_layers);
|
||||
struct cel **cels_ordered = PushArrayNoZero(scratch.arena, struct cel *, num_frames * num_layers);
|
||||
for (struct cel *cel = cel_head; cel; cel = cel->next) {
|
||||
cels_ordered[(cel->frame_index * num_layers) + cel->layer_index] = cel;
|
||||
if (cel->type == CEL_TYPE_LINKED) {
|
||||
@ -790,7 +790,7 @@ Ase_DecodedImage ase_decode_image(Arena *arena, String encoded)
|
||||
}
|
||||
|
||||
/* ASSERT all data was read */
|
||||
ASSERT(br_num_bytes_left(&br) == 0);
|
||||
ASSERT(BB_NumBytesRemaining(&br) == 0);
|
||||
|
||||
abort:
|
||||
|
||||
@ -798,7 +798,7 @@ abort:
|
||||
res.success = 1;
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -812,10 +812,10 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
|
||||
Ase_DecodedSheet res = ZI;
|
||||
|
||||
Bitbuff bb = bitbuff_from_string(encoded);
|
||||
BitbuffReader br = br_from_bitbuff_no_debug(&bb);
|
||||
BB_Buff bb = BitbuffFromString(encoded);
|
||||
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
|
||||
struct ase_header ase_header;
|
||||
br_read_bytes(&br, STRING_FROM_STRUCT(&ase_header));
|
||||
BB_ReadBytes(&br, STRING_FROM_STRUCT(&ase_header));
|
||||
|
||||
u64 frame_width = ase_header.width;
|
||||
u64 frame_height = ase_header.height;
|
||||
@ -838,7 +838,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
/* Iterate frames */
|
||||
for (u16 i = 0; i < ase_header.frames; ++i) {
|
||||
struct frame_header frame_header;
|
||||
br_read_bytes(&br, STRING_FROM_STRUCT(&frame_header));
|
||||
BB_ReadBytes(&br, STRING_FROM_STRUCT(&frame_header));
|
||||
|
||||
u32 num_chunks = frame_header.chunks_new;
|
||||
if (num_chunks == 0) {
|
||||
@ -846,7 +846,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
num_chunks = frame_header.chunks_old;
|
||||
}
|
||||
|
||||
Ase_Frame *frame = arena_push(arena, Ase_Frame);
|
||||
Ase_Frame *frame = PushStruct(arena, Ase_Frame);
|
||||
frame->next = frame_head;
|
||||
frame_head = frame;
|
||||
|
||||
@ -870,32 +870,32 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
|
||||
/* Iterate chunks in frame */
|
||||
for (u32 j = 0; j < num_chunks; ++j) {
|
||||
u32 chunk_size = br_read_ubits(&br, 32);
|
||||
enum chunk_type chunk_type = br_read_ubits(&br, 16);
|
||||
u32 chunk_size = BB_ReadUBits(&br, 32);
|
||||
enum chunk_type chunk_type = BB_ReadUBits(&br, 16);
|
||||
|
||||
/* Chunk size includes size & type */
|
||||
ASSERT(chunk_size >= 6);
|
||||
chunk_size -= 6;
|
||||
|
||||
u64 chunk_end_pos = br_cur_byte(&br) + chunk_size;
|
||||
u64 chunk_end_pos = BB_GetCurrentReaderByte(&br) + chunk_size;
|
||||
|
||||
switch (chunk_type) {
|
||||
case CHUNK_TYPE_TAGS: {
|
||||
u16 frame_span_count = br_read_ubits(&br, 16);
|
||||
br_seek_bytes(&br, 8);
|
||||
u16 frame_span_count = BB_ReadUBits(&br, 16);
|
||||
BB_SeekBytes(&br, 8);
|
||||
|
||||
for (u16 k = 0; k < frame_span_count; ++k) {
|
||||
Ase_Span *span = arena_push(arena, Ase_Span);
|
||||
Ase_Span *span = PushStruct(arena, Ase_Span);
|
||||
span->next = span_head;
|
||||
span_head = span;
|
||||
|
||||
span->start = br_read_ubits(&br, 16);
|
||||
span->end = br_read_ubits(&br, 16);
|
||||
br_seek_bytes(&br, 13);
|
||||
span->start = BB_ReadUBits(&br, 16);
|
||||
span->end = BB_ReadUBits(&br, 16);
|
||||
BB_SeekBytes(&br, 13);
|
||||
|
||||
u16 str_len = br_read_ubits(&br, 16);
|
||||
span->name = (String) { str_len, arena_push_array_no_zero(arena, u8, str_len) };
|
||||
br_read_bytes(&br, span->name);
|
||||
u16 str_len = BB_ReadUBits(&br, 16);
|
||||
span->name = (String) { str_len, PushArrayNoZero(arena, u8, str_len) };
|
||||
BB_ReadBytes(&br, span->name);
|
||||
|
||||
++num_spans;
|
||||
}
|
||||
@ -903,37 +903,37 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
} break;
|
||||
|
||||
case CHUNK_TYPE_SLICE: {
|
||||
Ase_SliceKey *slice_key = arena_push(arena, Ase_SliceKey);
|
||||
Ase_SliceKey *slice_key = PushStruct(arena, Ase_SliceKey);
|
||||
slice_key->next = slice_key_head;
|
||||
slice_key_head = slice_key;
|
||||
|
||||
u32 num_slices = br_read_ubits(&br, 32);
|
||||
u32 num_slices = BB_ReadUBits(&br, 32);
|
||||
slice_key->num_slices = num_slices;
|
||||
|
||||
u32 flags = br_read_ubits(&br, 32);
|
||||
br_seek_bytes(&br, 4);
|
||||
u32 flags = BB_ReadUBits(&br, 32);
|
||||
BB_SeekBytes(&br, 4);
|
||||
|
||||
u16 str_len = br_read_ubits(&br, 16);
|
||||
slice_key->name = (String) { str_len, arena_push_array_no_zero(arena, u8, str_len) };
|
||||
br_read_bytes(&br, slice_key->name);
|
||||
u16 str_len = BB_ReadUBits(&br, 16);
|
||||
slice_key->name = (String) { str_len, PushArrayNoZero(arena, u8, str_len) };
|
||||
BB_ReadBytes(&br, slice_key->name);
|
||||
|
||||
for (u32 k = 0; k < num_slices; ++k) {
|
||||
Ase_Slice *slice = arena_push(arena, Ase_Slice);
|
||||
Ase_Slice *slice = PushStruct(arena, Ase_Slice);
|
||||
slice->next = slice_key->slice_head;
|
||||
slice_key->slice_head = slice;
|
||||
|
||||
u32 start = br_read_ubits(&br, 32);
|
||||
i32 x = br_read_ibits(&br, 32);
|
||||
i32 y = br_read_ibits(&br, 32);
|
||||
u32 width = br_read_ubits(&br, 32);
|
||||
u32 height = br_read_ubits(&br, 32);
|
||||
u32 start = BB_ReadUBits(&br, 32);
|
||||
i32 x = BB_ReadIBits(&br, 32);
|
||||
i32 y = BB_ReadIBits(&br, 32);
|
||||
u32 width = BB_ReadUBits(&br, 32);
|
||||
u32 height = BB_ReadUBits(&br, 32);
|
||||
if (flags & 0x01) {
|
||||
/* Skip 9-patches info */
|
||||
br_seek_bytes(&br, 128);
|
||||
BB_SeekBytes(&br, 128);
|
||||
}
|
||||
if (flags & 0x02) {
|
||||
/* Skip pivot info */
|
||||
br_seek_bytes(&br, 64);
|
||||
BB_SeekBytes(&br, 64);
|
||||
}
|
||||
|
||||
slice->start = start;
|
||||
@ -950,7 +950,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
//case CHUNK_TYPE_USER_DATA
|
||||
|
||||
default: {
|
||||
br_seek_to_byte(&br, chunk_end_pos);
|
||||
BB_SeekToByte(&br, chunk_end_pos);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@ -958,7 +958,7 @@ Ase_DecodedSheet ase_decode_sheet(Arena *arena, String encoded)
|
||||
}
|
||||
|
||||
/* ASSERT all data was read */
|
||||
ASSERT(br_num_bytes_left(&br) == 0);
|
||||
ASSERT(BB_NumBytesRemaining(&br) == 0);
|
||||
|
||||
res.image_size = V2FromXY(image_width, image_height);
|
||||
res.frame_size = V2FromXY(frame_width, frame_height);
|
||||
|
||||
@ -29,7 +29,7 @@ AC_StartupReceipt asset_cache_startup(void)
|
||||
{
|
||||
__prof;
|
||||
/* Init store */
|
||||
G.store_arena = arena_alloc(GIBI(64));
|
||||
G.store_arena = AllocArena(GIBI(64));
|
||||
return (AC_StartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include "base_buddy.c"
|
||||
#include "base_rand.c"
|
||||
#include "base_string.c"
|
||||
#include "base_bitbuff.c"
|
||||
#include "base_uid.c"
|
||||
#include "base_uni.c"
|
||||
#include "base_incbin.c"
|
||||
|
||||
@ -36,7 +36,6 @@
|
||||
#include "base_buddy.h"
|
||||
#include "base_math.h"
|
||||
#include "base_rand.h"
|
||||
#include "base_bitbuff.h"
|
||||
#include "base_util.h"
|
||||
#include "base_incbin.h"
|
||||
|
||||
|
||||
@ -1,19 +1,21 @@
|
||||
SharedScratchCtx g_scratch_shared = ZI;
|
||||
SharedScratchCtx shared_scratch_ctx = ZI;
|
||||
|
||||
/* NOTE: Application will exit if arena fails to reserve or commit initial memory. */
|
||||
Arena *arena_alloc(u64 reserve)
|
||||
Arena *AllocArena(u64 reserve)
|
||||
{
|
||||
__prof;
|
||||
reserve += ARENA_HEADER_SIZE;
|
||||
reserve += ArenaHeaderSize;
|
||||
|
||||
/* Round up to nearest block size */
|
||||
u64 block_remainder = reserve % ARENA_BLOCK_SIZE;
|
||||
if (block_remainder > 0) {
|
||||
reserve += ARENA_BLOCK_SIZE - block_remainder;
|
||||
u64 block_remainder = reserve % ArenaBlockSize;
|
||||
if (block_remainder > 0)
|
||||
{
|
||||
reserve += ArenaBlockSize - block_remainder;
|
||||
}
|
||||
|
||||
u8 *base = memory_reserve(reserve);
|
||||
if (!base) {
|
||||
if (!base)
|
||||
{
|
||||
/* Hard fail on memory reserve failure for now */
|
||||
/* FIXME: Enable this */
|
||||
//P_Panic(LIT("Failed to reserve memory"));
|
||||
@ -23,8 +25,9 @@ Arena *arena_alloc(u64 reserve)
|
||||
gstat_add(GSTAT_MEMORY_RESERVED, reserve);
|
||||
|
||||
/* Commit initial block */
|
||||
base = memory_commit(base, ARENA_BLOCK_SIZE);
|
||||
if (!base) {
|
||||
base = memory_commit(base, ArenaBlockSize);
|
||||
if (!base)
|
||||
{
|
||||
/* Hard fail on commit failure */
|
||||
/* FIXME: Enable this */
|
||||
//P_Panic(LIT("Failed to commit initial memory block: System may be out of memory"));
|
||||
@ -32,62 +35,66 @@ Arena *arena_alloc(u64 reserve)
|
||||
}
|
||||
|
||||
ASSERT(((u64)base & 0xFFF) == 0); /* Base should be 4k aligned */
|
||||
STATIC_ASSERT(ARENA_HEADER_SIZE <= ARENA_BLOCK_SIZE); /* Header must fit in first block */
|
||||
STATIC_ASSERT(sizeof(Arena) <= ARENA_HEADER_SIZE); /* Arena struct must fit in header */
|
||||
STATIC_ASSERT(ArenaHeaderSize <= ArenaBlockSize); /* Header must fit in first block */
|
||||
STATIC_ASSERT(sizeof(Arena) <= ArenaHeaderSize); /* Arena struct must fit in header */
|
||||
|
||||
__profalloc(base, ARENA_BLOCK_SIZE);
|
||||
ASAN_POISON(base + sizeof(Arena), ARENA_BLOCK_SIZE - sizeof(Arena));
|
||||
gstat_add(GSTAT_MEMORY_COMMITTED, ARENA_BLOCK_SIZE);
|
||||
__profalloc(base, ArenaBlockSize);
|
||||
ASAN_POISON(base + sizeof(Arena), ArenaBlockSize - sizeof(Arena));
|
||||
gstat_add(GSTAT_MEMORY_COMMITTED, ArenaBlockSize);
|
||||
gstat_add(GSTAT_NUM_ARENAS, 1);
|
||||
|
||||
/* Create & return arena header at beginning of block */
|
||||
Arena *arena = (Arena *)base;
|
||||
MEMZERO_STRUCT(arena);
|
||||
arena->committed = ARENA_BLOCK_SIZE - ARENA_HEADER_SIZE;
|
||||
arena->committed = ArenaBlockSize - ArenaHeaderSize;
|
||||
arena->reserved = reserved;
|
||||
return arena;
|
||||
}
|
||||
|
||||
void arena_release(Arena *arena)
|
||||
void ReleaseArena(Arena *arena)
|
||||
{
|
||||
ASAN_UNPOISON(arena, arena->committed + ARENA_HEADER_SIZE);
|
||||
ASAN_UNPOISON(arena, arena->committed + ArenaHeaderSize);
|
||||
__prof;
|
||||
__proffree(arena);
|
||||
gstat_add(GSTAT_MEMORY_COMMITTED, -(i64)(arena->committed - ARENA_HEADER_SIZE));
|
||||
gstat_add(GSTAT_MEMORY_COMMITTED, -(i64)(arena->committed - ArenaHeaderSize));
|
||||
gstat_add(GSTAT_MEMORY_RESERVED, -(i64)(arena->reserved));
|
||||
gstat_add(GSTAT_NUM_ARENAS, -1);
|
||||
memory_release(arena);
|
||||
}
|
||||
|
||||
/* NOTE: Application will exit if arena fails to commit memory */
|
||||
void *arena_push_bytes_no_zero(Arena *arena, u64 size, u64 align)
|
||||
void *PushBytesNoZero(Arena *arena, u64 size, u64 align)
|
||||
{
|
||||
ASSERT(align > 0);
|
||||
ASSERT(!arena->readonly);
|
||||
|
||||
void *ptr = 0;
|
||||
u8 *base = arena_base(arena);
|
||||
u8 *base = ArenaBase(arena);
|
||||
|
||||
/* Check to avoid aligning when size = 0 */
|
||||
if (size > 0) {
|
||||
if (size > 0)
|
||||
{
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
|
||||
u64 new_pos = aligned_start_pos + size;
|
||||
if (new_pos > arena->committed) {
|
||||
if (new_pos > arena->committed)
|
||||
{
|
||||
__profn("Arena commit");
|
||||
/* Commit new block(s) */
|
||||
u64 blocks_needed = (new_pos - arena->committed + ARENA_BLOCK_SIZE - 1) / ARENA_BLOCK_SIZE;
|
||||
u64 commit_bytes = blocks_needed * ARENA_BLOCK_SIZE;
|
||||
u64 blocks_needed = (new_pos - arena->committed + ArenaBlockSize - 1) / ArenaBlockSize;
|
||||
u64 commit_bytes = blocks_needed * ArenaBlockSize;
|
||||
u64 new_capacity = arena->committed + commit_bytes;
|
||||
if (new_capacity > arena->reserved) {
|
||||
if (new_capacity > arena->reserved)
|
||||
{
|
||||
/* Hard fail if we overflow reserved memory for now */
|
||||
/* FIXME: Enable this */
|
||||
//P_Panic(LIT("Failed to commit new memory block: Overflow of reserved memory"));
|
||||
(*(volatile int *)0) = 0;
|
||||
}
|
||||
void *commit_address = base + arena->committed;
|
||||
if (!memory_commit(commit_address, commit_bytes)) {
|
||||
if (!memory_commit(commit_address, commit_bytes))
|
||||
{
|
||||
/* Hard fail on memory allocation failure for now */
|
||||
/* FIXME: Enable this */
|
||||
//P_Panic(LIT("Failed to commit new memory block: System may be out of memory"));
|
||||
@ -96,14 +103,16 @@ void *arena_push_bytes_no_zero(Arena *arena, u64 size, u64 align)
|
||||
arena->committed += commit_bytes;
|
||||
gstat_add(GSTAT_MEMORY_COMMITTED, commit_bytes);
|
||||
__proffree(arena);
|
||||
__profalloc(arena, arena->committed + ARENA_HEADER_SIZE);
|
||||
__profalloc(arena, arena->committed + ArenaHeaderSize);
|
||||
ASAN_POISON(commit_address, commit_bytes);
|
||||
}
|
||||
|
||||
ptr = base + aligned_start_pos;
|
||||
ASAN_UNPOISON(ptr, new_pos - aligned_start_pos);
|
||||
arena->pos = new_pos;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = base + arena->pos;
|
||||
}
|
||||
|
||||
@ -112,33 +121,33 @@ void *arena_push_bytes_no_zero(Arena *arena, u64 size, u64 align)
|
||||
|
||||
/* Copies the memory from the source arena into the destination arena,
|
||||
* replacing old contents. Destination arena will be expanded if necessary. */
|
||||
void arena_copy_replace(Arena *dst, Arena *src)
|
||||
void CopyArena(Arena *dst, Arena *src)
|
||||
{
|
||||
arena_reset(dst);
|
||||
ResetArena(dst);
|
||||
u64 data_size = src->pos;
|
||||
u8 *data_src = arena_base(src);
|
||||
u8 *data_dst = arena_push_bytes_no_zero(dst, data_size, 1);
|
||||
u8 *data_src = ArenaBase(src);
|
||||
u8 *data_dst = PushBytesNoZero(dst, data_size, 1);
|
||||
MEMCPY(data_dst, data_src, data_size);
|
||||
}
|
||||
|
||||
void arena_decommit_unused_blocks(Arena *arena)
|
||||
void ShrinkArena(Arena *arena)
|
||||
{
|
||||
/* Not implemented */
|
||||
ASSERT(0);
|
||||
(UNUSED)arena;
|
||||
}
|
||||
|
||||
void arena_set_readonly(Arena *arena)
|
||||
void SetArenaReadonly(Arena *arena)
|
||||
{
|
||||
#if RTC
|
||||
arena->readonly = 1;
|
||||
#endif
|
||||
memory_set_committed_readonly(arena, arena->committed + ARENA_HEADER_SIZE);
|
||||
memory_set_committed_readonly(arena, arena->committed + ArenaHeaderSize);
|
||||
}
|
||||
|
||||
void arena_set_readwrite(Arena *arena)
|
||||
void SetArenaReadWrite(Arena *arena)
|
||||
{
|
||||
memory_set_committed_readwrite(arena, arena->committed + ARENA_HEADER_SIZE);
|
||||
memory_set_committed_readwrite(arena, arena->committed + ArenaHeaderSize);
|
||||
#if RTC
|
||||
arena->readonly = 0;
|
||||
#endif
|
||||
|
||||
@ -1,24 +1,11 @@
|
||||
/* ========================== *
|
||||
* Arena
|
||||
* ========================== */
|
||||
////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
#define ARENA_HEADER_SIZE 256
|
||||
#define ARENA_BLOCK_SIZE 16384
|
||||
#define ArenaHeaderSize 256
|
||||
#define ArenaBlockSize 16384
|
||||
|
||||
#define arena_push(a, type) ((type *)arena_push_bytes((a), sizeof(type), alignof(type)))
|
||||
#define arena_push_no_zero(a, type) ((type *)arena_push_bytes_no_zero((a), sizeof(type), alignof(type)))
|
||||
|
||||
#define arena_push_array(a, type, n) ((type *)arena_push_bytes((a), (sizeof(type) * (n)), alignof(type)))
|
||||
#define arena_push_array_no_zero(a, type, n) ((type *)arena_push_bytes_no_zero((a), (sizeof(type) * (n)), alignof(type)))
|
||||
|
||||
#define arena_pop(a, type, dst) arena_pop_struct((a), sizeof(type), dst)
|
||||
#define arena_pop_array(a, type, n, dst) arena_pop_struct((a), sizeof(type) * (n), dst)
|
||||
|
||||
/* Returns a pointer to where the next allocation would be (at alignment of type).
|
||||
* Equivalent to arena_push but without actually allocating anything or modifying the arena. */
|
||||
#define arena_push_dry(a, type) (type *)(_arena_push_dry((a), alignof(type)))
|
||||
|
||||
Struct(Arena) {
|
||||
Struct(Arena)
|
||||
{
|
||||
u64 pos;
|
||||
u64 committed;
|
||||
u64 reserved;
|
||||
@ -36,49 +23,98 @@ Struct(TempArena) {
|
||||
#endif
|
||||
};
|
||||
|
||||
Arena *arena_alloc(u64 reserve);
|
||||
void arena_release(Arena *arena);
|
||||
void *arena_push_bytes_no_zero(Arena *arena, u64 size, u64 align);
|
||||
void arena_copy_replace(Arena *dst, Arena *src);
|
||||
void arena_decommit_unused_blocks(Arena *arena);
|
||||
void arena_set_readonly(Arena *arena);
|
||||
void arena_set_readwrite(Arena *arena);
|
||||
////////////////////////////////
|
||||
//~ Scratch types
|
||||
|
||||
INLINE u8 *arena_base(Arena *arena)
|
||||
{
|
||||
return (u8 *)arena + ARENA_HEADER_SIZE;
|
||||
}
|
||||
#define ScratchArenasPerCtx 2
|
||||
|
||||
INLINE void *arena_push_bytes(Arena *arena, u64 size, u64 align)
|
||||
Struct(ScratchCtx)
|
||||
{
|
||||
void *p = arena_push_bytes_no_zero(arena, size, align);
|
||||
Arena *arenas[ScratchArenasPerCtx];
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Shared state
|
||||
|
||||
Struct(SharedScratchCtx)
|
||||
{
|
||||
ScratchCtx scratch_contexts[MAX_FIBERS];
|
||||
};
|
||||
|
||||
extern SharedScratchCtx shared_scratch_ctx;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Arena push/pop
|
||||
|
||||
#define PushStruct(a, type) ((type *)PushBytes((a), sizeof(type), alignof(type)))
|
||||
#define PushStructNoZero(a, type) ((type *)PushBytesNoZero((a), sizeof(type), alignof(type)))
|
||||
|
||||
#define PushArray(a, type, n) ((type *)PushBytes((a), (sizeof(type) * (n)), alignof(type)))
|
||||
#define PushArrayNoZero(a, type, n) ((type *)PushBytesNoZero((a), (sizeof(type) * (n)), alignof(type)))
|
||||
|
||||
#define PopStruct(a, type, dst) PopBytes((a), sizeof(type), dst)
|
||||
#define PopArray(a, type, n, dst) PopBytes((a), sizeof(type) * (n), dst)
|
||||
|
||||
/* Returns a pointer to where the next allocation would be (at alignment of type).
|
||||
* Equivalent to PushStruct but without actually allocating anything or modifying the arena. */
|
||||
#define PushDry(a, type) (type *)(_PushDry((a), alignof(type)))
|
||||
|
||||
void *PushBytesNoZero(Arena *arena, u64 size, u64 align);
|
||||
|
||||
INLINE void *PushBytes(Arena *arena, u64 size, u64 align)
|
||||
{
|
||||
void *p = PushBytesNoZero(arena, size, align);
|
||||
MEMZERO(p, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
INLINE void arena_pop_to(Arena *arena, u64 pos)
|
||||
INLINE u8 *ArenaBase(Arena *arena)
|
||||
{
|
||||
return (u8 *)arena + ArenaHeaderSize;
|
||||
}
|
||||
|
||||
INLINE void PopTo(Arena *arena, u64 pos)
|
||||
{
|
||||
ASSERT(arena->pos >= pos);
|
||||
ASSERT(!arena->readonly);
|
||||
|
||||
ASAN_POISON(arena_base(arena) + pos, arena->pos - pos);
|
||||
ASAN_POISON(ArenaBase(arena) + pos, arena->pos - pos);
|
||||
arena->pos = pos;
|
||||
}
|
||||
|
||||
INLINE void arena_pop_struct(Arena *arena, u64 size, void *copy_dst)
|
||||
INLINE void PopBytes(Arena *arena, u64 size, void *copy_dst)
|
||||
{
|
||||
ASSERT(arena->pos >= size);
|
||||
ASSERT(!arena->readonly);
|
||||
|
||||
u64 new_pos = arena->pos - size;
|
||||
void *src = (void *)(arena_base(arena) + new_pos);
|
||||
void *src = (void *)(ArenaBase(arena) + new_pos);
|
||||
MEMCPY(copy_dst, src, size);
|
||||
|
||||
ASAN_POISON(arena_base(arena) + new_pos, arena->pos - new_pos);
|
||||
ASAN_POISON(ArenaBase(arena) + new_pos, arena->pos - new_pos);
|
||||
arena->pos = new_pos;
|
||||
}
|
||||
|
||||
INLINE void *arena_align(Arena *arena, u64 align)
|
||||
INLINE void *_PushDry(Arena *arena, u64 align)
|
||||
{
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
void *ptr = ArenaBase(arena) + aligned_start_pos;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ Arena management
|
||||
|
||||
Arena *AllocArena(u64 reserve);
|
||||
void ReleaseArena(Arena *arena);
|
||||
|
||||
void CopyArena(Arena *dst, Arena *src);
|
||||
void ShrinkArena(Arena *arena);
|
||||
void SetArenaReadonly(Arena *arena);
|
||||
void SetArenaReadWrite(Arena *arena);
|
||||
|
||||
INLINE void *AlignArena(Arena *arena, u64 align)
|
||||
{
|
||||
ASSERT(!arena->readonly);
|
||||
if (align > 0) {
|
||||
@ -86,18 +122,26 @@ INLINE void *arena_align(Arena *arena, u64 align)
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
u64 align_bytes = aligned_start_pos - (u64)arena->pos;
|
||||
if (align_bytes > 0) {
|
||||
return (void *)arena_push_array_no_zero(arena, u8, align_bytes);
|
||||
return (void *)PushArrayNoZero(arena, u8, align_bytes);
|
||||
} else {
|
||||
return (void *)(arena_base(arena) + arena->pos);
|
||||
return (void *)(ArenaBase(arena) + arena->pos);
|
||||
}
|
||||
} else {
|
||||
/* 0 alignment */
|
||||
ASSERT(0);
|
||||
return (void *)(arena_base(arena) + arena->pos);
|
||||
return (void *)(ArenaBase(arena) + arena->pos);
|
||||
}
|
||||
}
|
||||
|
||||
INLINE TempArena arena_temp_begin(Arena *arena)
|
||||
INLINE void ResetArena(Arena *arena)
|
||||
{
|
||||
PopTo(arena, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ Temp arena
|
||||
|
||||
INLINE TempArena BeginTempArena(Arena *arena)
|
||||
{
|
||||
TempArena t = ZI;
|
||||
t.arena = arena;
|
||||
@ -105,47 +149,21 @@ INLINE TempArena arena_temp_begin(Arena *arena)
|
||||
return t;
|
||||
}
|
||||
|
||||
INLINE void arena_temp_end(TempArena temp)
|
||||
INLINE void EndTempArena(TempArena temp)
|
||||
{
|
||||
arena_pop_to(temp.arena, temp.start_pos);
|
||||
PopTo(temp.arena, temp.start_pos);
|
||||
}
|
||||
|
||||
INLINE void arena_reset(Arena *arena)
|
||||
////////////////////////////////
|
||||
//~ Scratch
|
||||
|
||||
INLINE ScratchCtx *ScratchCtxFromFiberId(i16 fiber_id)
|
||||
{
|
||||
arena_pop_to(arena, 0);
|
||||
}
|
||||
|
||||
INLINE void *_arena_push_dry(Arena *arena, u64 align)
|
||||
{
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
void *ptr = arena_base(arena) + aligned_start_pos;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Scratch
|
||||
* ========================== */
|
||||
|
||||
#define SCRATCH_ARENAS_PER_CTX 2
|
||||
|
||||
Struct(ScratchCtx) {
|
||||
Arena *arenas[SCRATCH_ARENAS_PER_CTX];
|
||||
};
|
||||
|
||||
Struct(SharedScratchCtx) {
|
||||
ScratchCtx scratch_contexts[MAX_FIBERS];
|
||||
};
|
||||
|
||||
extern SharedScratchCtx g_scratch_shared;
|
||||
|
||||
INLINE ScratchCtx *scratch_ctx_from_fiber_id(i16 fiber_id)
|
||||
{
|
||||
SharedScratchCtx *shared = &g_scratch_shared;
|
||||
SharedScratchCtx *shared = &shared_scratch_ctx;
|
||||
ScratchCtx *ctx = &shared->scratch_contexts[fiber_id];
|
||||
if (!ctx->arenas[0]) {
|
||||
for (i32 i = 0; i < (i32)countof(ctx->arenas); ++i) {
|
||||
ctx->arenas[i] = arena_alloc(GIBI(64));
|
||||
ctx->arenas[i] = AllocArena(GIBI(64));
|
||||
}
|
||||
}
|
||||
return ctx;
|
||||
@ -157,48 +175,48 @@ INLINE ScratchCtx *scratch_ctx_from_fiber_id(i16 fiber_id)
|
||||
* parameterized arenas are often used to allocate persistent results for the
|
||||
* caller).
|
||||
*
|
||||
* Use `scratch_begin_no_conflict` instead if there is no arena in the current
|
||||
* Use `BeginScratchNoConflict` instead if there is no arena in the current
|
||||
* scope that could potentially be a scratch arena from another scope. */
|
||||
#define scratch_begin(potential_conflict) _scratch_begin(potential_conflict)
|
||||
#define BeginScratch(potential_conflict) _BeginScratch(potential_conflict)
|
||||
|
||||
INLINE TempArena _scratch_begin(Arena *potential_conflict)
|
||||
INLINE TempArena _BeginScratch(Arena *potential_conflict)
|
||||
{
|
||||
/* This function is currently hard-coded to support 2 scratch arenas */
|
||||
STATIC_ASSERT(SCRATCH_ARENAS_PER_CTX == 2);
|
||||
STATIC_ASSERT(ScratchArenasPerCtx == 2);
|
||||
|
||||
/* Use `scratch_begin_no_conflict` if no conflicts are present */
|
||||
/* Use `BeginScratchNoConflict` if no conflicts are present */
|
||||
ASSERT(potential_conflict != 0);
|
||||
|
||||
ScratchCtx *ctx = scratch_ctx_from_fiber_id(FiberId());
|
||||
ScratchCtx *ctx = ScratchCtxFromFiberId(FiberId());
|
||||
Arena *scratch_arena = ctx->arenas[0];
|
||||
if (potential_conflict && scratch_arena == potential_conflict) {
|
||||
scratch_arena = ctx->arenas[1];
|
||||
}
|
||||
TempArena temp = arena_temp_begin(scratch_arena);
|
||||
TempArena temp = BeginTempArena(scratch_arena);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* This macro declares an unused "arena" variable that will error if an existing "arena"
|
||||
* variable is present (due to shadowing). This is for catching obvious cases of
|
||||
* `scratch_begin_no_conflict` getting called when an `arena` variable already
|
||||
* exists in the caller's scope (`scratch_begin(arena)` should be called
|
||||
* `BeginScratchNoConflict` getting called when an `arena` variable already
|
||||
* exists in the caller's scope (`BeginScratch(arena)` should be called
|
||||
* instead). */
|
||||
#define scratch_begin_no_conflict() \
|
||||
_scratch_begin_no_conflict(); \
|
||||
#define BeginScratchNoConflict() \
|
||||
_BeginScratchNoConflict(); \
|
||||
do { \
|
||||
u8 arena = 0; \
|
||||
(UNUSED)arena; \
|
||||
} while (0)
|
||||
|
||||
INLINE TempArena _scratch_begin_no_conflict(void)
|
||||
INLINE TempArena _BeginScratchNoConflict(void)
|
||||
{
|
||||
ScratchCtx *ctx = scratch_ctx_from_fiber_id(FiberId());
|
||||
ScratchCtx *ctx = ScratchCtxFromFiberId(FiberId());
|
||||
Arena *scratch_arena = ctx->arenas[0];
|
||||
TempArena temp = arena_temp_begin(scratch_arena);
|
||||
TempArena temp = BeginTempArena(scratch_arena);
|
||||
return temp;
|
||||
}
|
||||
|
||||
INLINE void scratch_end(TempArena scratch_temp)
|
||||
INLINE void EndScratch(TempArena scratch_temp)
|
||||
{
|
||||
arena_temp_end(scratch_temp);
|
||||
EndTempArena(scratch_temp);
|
||||
}
|
||||
|
||||
@ -1,56 +1,61 @@
|
||||
/* ========================== *
|
||||
* Atomic types
|
||||
* ========================== */
|
||||
////////////////////////////////
|
||||
//~ Atomic types
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
Struct(Atomic8) {
|
||||
Struct(Atomic8)
|
||||
{
|
||||
volatile i8 _v;
|
||||
};
|
||||
|
||||
/* NOTE: Must be aligned to 32 bit boundary by user */
|
||||
Struct(Atomic16) {
|
||||
Struct(Atomic16)
|
||||
{
|
||||
volatile i16 _v;
|
||||
};
|
||||
|
||||
Struct(Atomic32) {
|
||||
Struct(Atomic32)
|
||||
{
|
||||
volatile i32 _v;
|
||||
};
|
||||
|
||||
Struct(Atomic64) {
|
||||
Struct(Atomic64)
|
||||
{
|
||||
volatile i64 _v;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Cache-line isolated atomic types
|
||||
* ========================== */
|
||||
////////////////////////////////
|
||||
//~ Cache-line isolated atomic types
|
||||
|
||||
AlignedStruct(Atomic8Padded, 64) {
|
||||
AlignedStruct(Atomic8Padded, 64)
|
||||
{
|
||||
Atomic8 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(Atomic8Padded) == 64 && alignof(Atomic8Padded) == 64);
|
||||
|
||||
AlignedStruct(Atomic16Padded, 64) {
|
||||
AlignedStruct(Atomic16Padded, 64)
|
||||
{
|
||||
Atomic16 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(Atomic16Padded) == 64 && alignof(Atomic16Padded) == 64);
|
||||
|
||||
AlignedStruct(Atomic32Padded, 64) {
|
||||
AlignedStruct(Atomic32Padded, 64)
|
||||
{
|
||||
Atomic32 v;
|
||||
u8 _pad[60];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(Atomic32Padded) == 64 && alignof(Atomic32Padded) == 64);
|
||||
|
||||
AlignedStruct(Atomic64Padded, 64) {
|
||||
AlignedStruct(Atomic64Padded, 64)
|
||||
{
|
||||
Atomic64 v;
|
||||
u8 _pad[56];
|
||||
};
|
||||
STATIC_ASSERT(sizeof(Atomic64Padded) == 64 && alignof(Atomic64Padded) == 64);
|
||||
|
||||
/* ========================== *
|
||||
* Atomics impl
|
||||
* ========================== */
|
||||
////////////////////////////////
|
||||
//~ Atomic impl
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
|
||||
|
||||
@ -1,122 +0,0 @@
|
||||
/* ========================== *
|
||||
* Bitbuff
|
||||
* ========================== */
|
||||
|
||||
Struct(Bitbuff) {
|
||||
b32 is_backed_by_arena;
|
||||
|
||||
/* If `is_arena_bitbuff` is 1, this dynamically-sized arena will be used for reading & writing (meaning writing cannot overflow) */
|
||||
Arena *arena;
|
||||
|
||||
/* If `is_arena_bitbuff` is 0, this fixed-sized buffer willl be used for reading & writing */
|
||||
String fixed_buffer;
|
||||
};
|
||||
|
||||
Bitbuff bitbuff_alloc(u64 arena_reserve);
|
||||
void bitbuff_release(Bitbuff *bitbuff);
|
||||
|
||||
Bitbuff bitbuff_from_string(String s);
|
||||
|
||||
/* ========================== *
|
||||
* Writer
|
||||
* ========================== */
|
||||
|
||||
/* NOTE: base_len is not stored in writer (as it is in the reader) since a dynamic arena-backed bitbuff could grow meaning len needs to be re-checked */
|
||||
Struct(BitbuffWriter) {
|
||||
b32 overflowed;
|
||||
Bitbuff *bb;
|
||||
u8 *base;
|
||||
u64 cur_bit;
|
||||
#if BITBUFF_DEBUG
|
||||
b32 debug_enabled;
|
||||
#endif
|
||||
};
|
||||
|
||||
BitbuffWriter bw_from_bitbuff(Bitbuff *bb);
|
||||
BitbuffWriter bw_from_bitbuff_no_debug(Bitbuff *bb);
|
||||
|
||||
u64 bw_num_bits_written(BitbuffWriter *bw);
|
||||
u64 bw_num_bytes_written(BitbuffWriter *bw);
|
||||
|
||||
String bw_get_written(Arena *arena, BitbuffWriter *bw);
|
||||
u8 *bw_get_written_raw(BitbuffWriter *bw);
|
||||
|
||||
b32 bw_check_overflow_bits(BitbuffWriter *bw, u64 num_bits);
|
||||
|
||||
void bw_align(BitbuffWriter *bw);
|
||||
|
||||
void bw_write_ubits(BitbuffWriter *bw, u64 value, u8 num_bits);
|
||||
void bw_write_ibits(BitbuffWriter *bw, i64 value, u8 num_bits);
|
||||
b32 bw_write_bit(BitbuffWriter *bw, u8 value);
|
||||
|
||||
void bw_write_uv(BitbuffWriter *bw, u64 value);
|
||||
void bw_write_iv(BitbuffWriter *bw, i64 value);
|
||||
|
||||
void bw_write_f32(BitbuffWriter *bw, f32 value);
|
||||
void bw_write_f64(BitbuffWriter *bw, f64 value);
|
||||
void bw_write_uid(BitbuffWriter *bw, UID value);
|
||||
|
||||
void bw_write_string(BitbuffWriter *bw, String s);
|
||||
|
||||
void bw_write_bytes(BitbuffWriter *bw, String bytes);
|
||||
|
||||
#if BITBUFF_DEBUG
|
||||
void bw_write_dbg_marker(BitbuffWriter *bw, String name);
|
||||
#else
|
||||
#define bw_write_dbg_marker(bw, name)
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Reader
|
||||
* ========================== */
|
||||
|
||||
Struct(BitbuffReader) {
|
||||
b32 overflowed;
|
||||
u64 base_len;
|
||||
u8 *base;
|
||||
u64 cur_bit;
|
||||
#if BITBUFF_DEBUG
|
||||
b32 debug_enabled;
|
||||
#endif
|
||||
};
|
||||
|
||||
BitbuffReader br_from_bitbuff(Bitbuff *bb);
|
||||
BitbuffReader br_from_bitbuff_no_debug(Bitbuff *bb);
|
||||
|
||||
u64 br_cur_bit(BitbuffReader *br);
|
||||
u64 br_cur_byte(BitbuffReader *br);
|
||||
|
||||
u64 br_num_bits_left(BitbuffReader *br);
|
||||
u64 br_num_bytes_left(BitbuffReader *br);
|
||||
|
||||
b32 br_check_overflow_bits(BitbuffReader *br, u64 num_bits);
|
||||
|
||||
void br_align(BitbuffReader *br);
|
||||
|
||||
u64 br_read_ubits(BitbuffReader *br, u8 num_bits);
|
||||
i64 br_read_ibits(BitbuffReader *br, u8 num_bits);
|
||||
u8 br_read_bit(BitbuffReader *br);
|
||||
|
||||
u64 br_read_uv(BitbuffReader *br);
|
||||
i64 br_read_iv(BitbuffReader *br);
|
||||
|
||||
f32 br_read_f32(BitbuffReader *br);
|
||||
f64 br_read_f64(BitbuffReader *br);
|
||||
UID br_read_uid(BitbuffReader *br);
|
||||
|
||||
String br_read_string(Arena *arena, BitbuffReader *br);
|
||||
|
||||
void br_read_bytes(BitbuffReader *br, String dst);
|
||||
u8 *br_read_bytes_raw(BitbuffReader *br, u64 num_bytes);
|
||||
void br_seek_bytes(BitbuffReader *br, u64 num_bytes);
|
||||
void br_seek_to_byte(BitbuffReader *br, u64 pos);
|
||||
|
||||
#if BITBUFF_DEBUG
|
||||
void br_read_dbg_marker(BitbuffReader *br, String name);
|
||||
#else
|
||||
#define br_read_dbg_marker(br, name)
|
||||
#endif
|
||||
|
||||
#if BITBUFF_TEST
|
||||
void bitbuff_test(void);
|
||||
#endif
|
||||
@ -7,13 +7,13 @@
|
||||
BuddyCtx *buddy_ctx_alloc(u64 reserve)
|
||||
{
|
||||
/* TODO: Determine meta reserve dynamically */
|
||||
Arena *meta_arena = arena_alloc(GIBI(64));
|
||||
BuddyCtx *ctx = arena_push(meta_arena, BuddyCtx);
|
||||
Arena *meta_arena = AllocArena(GIBI(64));
|
||||
BuddyCtx *ctx = PushStruct(meta_arena, BuddyCtx);
|
||||
ctx->meta_arena = meta_arena;
|
||||
ctx->data_arena = arena_alloc(reserve);
|
||||
ctx->data_arena = AllocArena(reserve);
|
||||
|
||||
/* TODO: Minimum block size */
|
||||
ctx->levels = arena_push_array(ctx->meta_arena, BuddyLevel, 64);
|
||||
ctx->levels = PushArray(ctx->meta_arena, BuddyLevel, 64);
|
||||
for (u64 i = 0; i < 64; ++i) {
|
||||
BuddyLevel *level = &ctx->levels[i];
|
||||
level->ctx = ctx;
|
||||
@ -26,8 +26,8 @@ BuddyCtx *buddy_ctx_alloc(u64 reserve)
|
||||
|
||||
void buddy_ctx_release(BuddyCtx *ctx)
|
||||
{
|
||||
arena_release(ctx->data_arena);
|
||||
arena_release(ctx->meta_arena);
|
||||
ReleaseArena(ctx->data_arena);
|
||||
ReleaseArena(ctx->meta_arena);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -41,7 +41,7 @@ INTERNAL BuddyBlock *buddy_block_alloc_internal(BuddyCtx *ctx)
|
||||
block = ctx->first_free_block;
|
||||
ctx->first_free_block = block->next;
|
||||
} else {
|
||||
block = arena_push_no_zero(ctx->meta_arena, BuddyBlock);
|
||||
block = PushStructNoZero(ctx->meta_arena, BuddyBlock);
|
||||
}
|
||||
MEMZERO_STRUCT(block);
|
||||
return block;
|
||||
@ -113,7 +113,7 @@ INTERNAL BuddyBlock *buddy_block_get_unused(BuddyCtx *ctx, BuddyLevel *level)
|
||||
/* Grow arena */
|
||||
i64 level_commit_diff = (level->size * 2) - arena->pos;
|
||||
if (level_commit_diff > 0) {
|
||||
arena_push_array_no_zero(arena, u8, level_commit_diff);
|
||||
PushArrayNoZero(arena, u8, level_commit_diff);
|
||||
ASSERT(arena->pos == (level->size * 2));
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ INTERNAL BuddyBlock *buddy_block_get_unused(BuddyCtx *ctx, BuddyLevel *level)
|
||||
BuddyBlock *left = buddy_block_alloc_internal(ctx);
|
||||
left->is_used = 1;
|
||||
left->level = level;
|
||||
left->memory = arena_base(arena);
|
||||
left->memory = ArenaBase(arena);
|
||||
|
||||
/* Create right (unused) block from new arena memory */
|
||||
BuddyBlock *right = buddy_block_alloc_internal(ctx);
|
||||
|
||||
@ -19,7 +19,7 @@ struct rc_search_params {
|
||||
/* Find first resource with `type` and return the data in `udata`. */
|
||||
INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entry_name, LONG_PTR udata)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct rc_search_params *params = (struct rc_search_params *)udata;
|
||||
String entry_name_lower = string_lower(scratch.arena, string_from_wstr_no_limit(scratch.arena, (LPWSTR)wstr_entry_name));
|
||||
params->found = 0;
|
||||
@ -35,7 +35,7 @@ INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entr
|
||||
}
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return !params->found;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ String _incbin_get(_IncbinRcResource *inc)
|
||||
{
|
||||
enum _incbin_state state = atomic32_fetch(&inc->state);
|
||||
if (state != INCBIN_STATE_SEARCHED) {
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
if (state == INCBIN_STATE_UNSEARCHED) {
|
||||
enum _incbin_state v = atomic32_fetch_test_set(&inc->state, state, INCBIN_STATE_SEARCHING);
|
||||
@ -73,7 +73,7 @@ String _incbin_get(_IncbinRcResource *inc)
|
||||
state = atomic32_fetch(&inc->state);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
return inc->data;
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
String string_from_char(Arena *arena, char c)
|
||||
{
|
||||
u8 *dst = arena_push_no_zero(arena, u8);
|
||||
u8 *dst = PushStructNoZero(arena, u8);
|
||||
*dst = c;
|
||||
return (String) {
|
||||
.len = 1,
|
||||
@ -31,11 +31,11 @@ String string_from_uint(Arena *arena, u64 n, u64 base, u64 zfill)
|
||||
/* Base too large */
|
||||
ASSERT(base <= (countof(INT_CHARS) - 1));
|
||||
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
/* Build backwards text starting from least significant digit */
|
||||
u64 len = 0;
|
||||
u8 *backwards_text = arena_push_dry(scratch.arena, u8);
|
||||
u8 *backwards_text = PushDry(scratch.arena, u8);
|
||||
do {
|
||||
string_from_char(scratch.arena, INT_CHARS[n % base]);
|
||||
++len;
|
||||
@ -48,12 +48,12 @@ String string_from_uint(Arena *arena, u64 n, u64 base, u64 zfill)
|
||||
}
|
||||
|
||||
/* Reverse text into final string */
|
||||
u8 *final_text = arena_push_array_no_zero(arena, u8, len);
|
||||
u8 *final_text = PushArrayNoZero(arena, u8, len);
|
||||
for (u64 i = 0; i < len; ++i) {
|
||||
final_text[i] = backwards_text[len - i - 1];
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return (String) {
|
||||
.len = len,
|
||||
@ -63,15 +63,15 @@ String string_from_uint(Arena *arena, u64 n, u64 base, u64 zfill)
|
||||
|
||||
String string_from_int(Arena *arena, i64 n, u64 base, u64 zfill)
|
||||
{
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
u8 len = 0;
|
||||
if (n < 0) {
|
||||
/* Push sign */
|
||||
/* PushStruct sign */
|
||||
string_from_char(arena, '-');
|
||||
len = 1;
|
||||
n = -n;
|
||||
}
|
||||
/* Push unsigned number */
|
||||
/* PushStruct unsigned number */
|
||||
String uint_str = string_from_uint(arena, n, base, zfill);
|
||||
return (String) {
|
||||
.len = len + uint_str.len,
|
||||
@ -91,8 +91,8 @@ String string_from_ptr(Arena *arena, void *ptr)
|
||||
|
||||
String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
u64 final_len = 0;
|
||||
|
||||
if (F32_IS_NAN(f)) {
|
||||
@ -117,7 +117,7 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
/* Print whole part */
|
||||
{
|
||||
/* Build backwards text starting from least significant digit */
|
||||
u8 *backwards_text = arena_push_dry(scratch.arena, u8);
|
||||
u8 *backwards_text = PushDry(scratch.arena, u8);
|
||||
u64 backwards_text_len = 0;
|
||||
do {
|
||||
u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0));
|
||||
@ -127,7 +127,7 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
} while (part_whole > 0);
|
||||
|
||||
/* Reverse text into final string */
|
||||
arena_push_array_no_zero(arena, u8, backwards_text_len);
|
||||
PushArrayNoZero(arena, u8, backwards_text_len);
|
||||
for (u64 i = backwards_text_len; i-- > 0;) {
|
||||
final_text[final_len++] = backwards_text[i];
|
||||
}
|
||||
@ -146,7 +146,7 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return (String) {
|
||||
.len = final_len,
|
||||
@ -157,7 +157,7 @@ String string_from_float(Arena *arena, f64 f, u32 precision)
|
||||
String string_from_handle(Arena *arena, u64 v0, u64 v1)
|
||||
{
|
||||
String res = ZI;
|
||||
res.text = arena_push_dry(arena, u8);
|
||||
res.text = PushDry(arena, u8);
|
||||
res.len += string_copy(arena, LIT("h")).len;
|
||||
res.len += string_from_uint(arena, v0, 16, 0).len;
|
||||
res.len += string_copy(arena, LIT("x")).len;
|
||||
@ -168,7 +168,7 @@ String string_from_handle(Arena *arena, u64 v0, u64 v1)
|
||||
String string_from_uid(Arena *arena, UID uid)
|
||||
{
|
||||
String res = ZI;
|
||||
res.text = arena_push_dry(arena, u8);
|
||||
res.text = PushDry(arena, u8);
|
||||
res.len += string_from_uint(arena, (uid.hi >> 32), 16, 8).len;
|
||||
return res;
|
||||
}
|
||||
@ -181,7 +181,7 @@ String string_copy(Arena *arena, String src)
|
||||
{
|
||||
String str = {
|
||||
.len = src.len,
|
||||
.text = arena_push_array_no_zero(arena, u8, src.len)
|
||||
.text = PushArrayNoZero(arena, u8, src.len)
|
||||
};
|
||||
MEMCPY(str.text, src.text, src.len);
|
||||
return str;
|
||||
@ -199,7 +199,7 @@ String string_copy_to_string(String dst, String src)
|
||||
String string_repeat(Arena *arena, String src, u64 count)
|
||||
{
|
||||
u64 final_len = src.len * count;
|
||||
u8 *final_text = arena_push_array_no_zero(arena, u8, final_len);
|
||||
u8 *final_text = PushArrayNoZero(arena, u8, final_len);
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
MEMCPY(final_text + (src.len * i), src.text, src.len);
|
||||
}
|
||||
@ -213,7 +213,7 @@ String string_cat(Arena *arena, String str1, String str2)
|
||||
{
|
||||
String new_str = ZI;
|
||||
new_str.len = str1.len + str2.len;
|
||||
new_str.text = arena_push_array_no_zero(arena, u8, new_str.len);
|
||||
new_str.text = PushArrayNoZero(arena, u8, new_str.len);
|
||||
MEMCPY(new_str.text, str1.text, str1.len);
|
||||
MEMCPY(new_str.text + str1.len, str2.text, str2.len);
|
||||
return new_str;
|
||||
@ -224,7 +224,7 @@ String string_cat(Arena *arena, String str1, String str2)
|
||||
StringArray string_split(Arena *arena, String str, String delim)
|
||||
{
|
||||
StringArray pieces = ZI;
|
||||
pieces.strings = arena_push_dry(arena, String);
|
||||
pieces.strings = PushDry(arena, String);
|
||||
i64 piece_start = 0;
|
||||
for (i64 i = 0; i < (i64)str.len - (i64)delim.len; ++i) {
|
||||
String cmp = ZI;
|
||||
@ -239,7 +239,7 @@ StringArray string_split(Arena *arena, String str, String delim)
|
||||
i += delim.len;
|
||||
piece_start = i;
|
||||
if (piece.len > 0) {
|
||||
*arena_push_no_zero(arena, String) = piece;
|
||||
*PushStructNoZero(arena, String) = piece;
|
||||
++pieces.count;
|
||||
}
|
||||
}
|
||||
@ -248,7 +248,7 @@ StringArray string_split(Arena *arena, String str, String delim)
|
||||
String piece = ZI;
|
||||
piece.text = &str.text[piece_start];
|
||||
piece.len = str.len - piece_start;
|
||||
*arena_push_no_zero(arena, String) = piece;
|
||||
*PushStructNoZero(arena, String) = piece;
|
||||
++pieces.count;
|
||||
}
|
||||
return pieces;
|
||||
@ -257,10 +257,10 @@ StringArray string_split(Arena *arena, String str, String delim)
|
||||
/* NOTE: Really slow */
|
||||
String string_indent(Arena *arena, String str, u32 indent)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
u64 final_len = 0;
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
|
||||
StringArray split = string_split(scratch.arena, str, LIT("\n"));
|
||||
for (u64 i = 0; i < split.count; ++i) {
|
||||
@ -277,7 +277,7 @@ String string_indent(Arena *arena, String str, u32 indent)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return (String) {
|
||||
.len = final_len,
|
||||
@ -288,7 +288,7 @@ String string_indent(Arena *arena, String str, u32 indent)
|
||||
String string_lower(Arena *arena, String str)
|
||||
{
|
||||
String res = ZI;
|
||||
res.text = arena_push_array_no_zero(arena, u8, str.len);
|
||||
res.text = PushArrayNoZero(arena, u8, str.len);
|
||||
res.len = str.len;
|
||||
|
||||
for (u64 i = 0; i < str.len; ++i) {
|
||||
@ -426,7 +426,7 @@ String string_formatv(Arena *arena, String fmt, va_list args)
|
||||
__prof;
|
||||
|
||||
u64 final_len = 0;
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
|
||||
u8 *end = fmt.text + fmt.len;
|
||||
b32 no_more_args = 0;
|
||||
@ -567,7 +567,7 @@ String string_from_string16(Arena *arena, String16 str16)
|
||||
{
|
||||
String res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u8)
|
||||
.text = PushDry(arena, u8)
|
||||
};
|
||||
|
||||
u64 pos16 = 0;
|
||||
@ -576,7 +576,7 @@ String string_from_string16(Arena *arena, String16 str16)
|
||||
Utf16DecodeResult decoded = uni_decode_utf16(str16_remaining);
|
||||
Utf8EncodeResult encoded = uni_encode_utf8(decoded.codepoint);
|
||||
|
||||
u8 *dst = arena_push_array_no_zero(arena, u8, encoded.count8);
|
||||
u8 *dst = PushArrayNoZero(arena, u8, encoded.count8);
|
||||
MEMCPY(dst, encoded.chars8, encoded.count8);
|
||||
|
||||
pos16 += decoded.advance16;
|
||||
@ -591,7 +591,7 @@ String string_from_string32(Arena *arena, String32 str32)
|
||||
{
|
||||
String res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u8)
|
||||
.text = PushDry(arena, u8)
|
||||
};
|
||||
|
||||
u64 pos32 = 0;
|
||||
@ -600,7 +600,7 @@ String string_from_string32(Arena *arena, String32 str32)
|
||||
Utf32DecodeResult decoded = uni_decode_utf32(str32_remaining);
|
||||
Utf8EncodeResult encoded = uni_encode_utf8(decoded.codepoint);
|
||||
|
||||
u8 *dst = arena_push_array_no_zero(arena, u8, encoded.count8);
|
||||
u8 *dst = PushArrayNoZero(arena, u8, encoded.count8);
|
||||
MEMCPY(dst, &encoded.chars8, encoded.count8);
|
||||
|
||||
pos32 += 1;
|
||||
@ -615,7 +615,7 @@ String16 string16_from_string(Arena *arena, String str8)
|
||||
{
|
||||
String16 res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u16)
|
||||
.text = PushDry(arena, u16)
|
||||
};
|
||||
|
||||
u64 pos8 = 0;
|
||||
@ -624,7 +624,7 @@ String16 string16_from_string(Arena *arena, String str8)
|
||||
Utf8DecodeResult decoded = uni_decode_utf8(str8_remaining);
|
||||
Utf16EncodeResult encoded = uni_encode_utf16(decoded.codepoint);
|
||||
|
||||
u16 *dst = arena_push_array_no_zero(arena, u16, encoded.count16);
|
||||
u16 *dst = PushArrayNoZero(arena, u16, encoded.count16);
|
||||
MEMCPY(dst, encoded.chars16, (encoded.count16 << 1));
|
||||
|
||||
pos8 += decoded.advance8;
|
||||
@ -639,7 +639,7 @@ String32 string32_from_string(Arena *arena, String str8)
|
||||
{
|
||||
String32 res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u32)
|
||||
.text = PushDry(arena, u32)
|
||||
};
|
||||
|
||||
u64 pos8 = 0;
|
||||
@ -648,7 +648,7 @@ String32 string32_from_string(Arena *arena, String str8)
|
||||
Utf8DecodeResult decoded = uni_decode_utf8(str8_remaining);
|
||||
Utf32EncodeResult encoded = uni_encode_utf32(decoded.codepoint);
|
||||
|
||||
u32 *dst = arena_push_no_zero(arena, u32);
|
||||
u32 *dst = PushStructNoZero(arena, u32);
|
||||
*dst = encoded.chars32;
|
||||
|
||||
pos8 += decoded.advance8;
|
||||
@ -690,7 +690,7 @@ u64 cstr_len(char *cstr, u64 limit)
|
||||
|
||||
char *cstr_from_string(Arena *arena, String src)
|
||||
{
|
||||
u8 *text = arena_push_array_no_zero(arena, u8, src.len + 1);
|
||||
u8 *text = PushArrayNoZero(arena, u8, src.len + 1);
|
||||
MEMCPY(text, src.text, src.len);
|
||||
text[src.len] = 0;
|
||||
return (char *)text;
|
||||
@ -757,13 +757,13 @@ u64 wstr_len(wchar_t *wstr, u64 limit)
|
||||
wchar_t *wstr_from_string(Arena *arena, String src)
|
||||
{
|
||||
String16 str16 = string16_from_string(arena, src);
|
||||
*arena_push_no_zero(arena, u16) = 0;
|
||||
*PushStructNoZero(arena, u16) = 0;
|
||||
return (wchar_t *)str16.text;
|
||||
}
|
||||
|
||||
wchar_t *wstr_from_string16(Arena *arena, String16 src)
|
||||
{
|
||||
u16 *text = arena_push_array_no_zero(arena, u16, src.len + 1);
|
||||
u16 *text = PushArrayNoZero(arena, u16, src.len + 1);
|
||||
text[src.len] = 0;
|
||||
return (wchar_t *)text;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ Struct(StringArray) {
|
||||
|
||||
#define STRING_FROM_STRUCT(ptr) (CPPCOMPAT_INITLIST_TYPE(String) { sizeof(*(ptr)), (u8 *)(ptr) })
|
||||
|
||||
#define STRING_FROM_ARENA(arena) (STRING((arena)->pos, arena_base(arena)))
|
||||
#define STRING_FROM_ARENA(arena) (STRING((arena)->pos, ArenaBase(arena)))
|
||||
|
||||
/* String from static array */
|
||||
#define STRING_FROM_ARRAY(a) \
|
||||
|
||||
@ -69,22 +69,22 @@ INLINE void merge_sort_internal(u8 *left, u8 *right, u8 *items, u64 left_count,
|
||||
INLINE void merge_sort(void *items, u64 item_count, u64 item_size, sort_compare_func *callback, void *udata)
|
||||
{
|
||||
if (item_count > 1) {
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
u64 left_count = item_count / 2;
|
||||
u64 right_count = item_count - left_count;
|
||||
|
||||
u64 left_size = left_count * item_size;
|
||||
u64 right_size = right_count * item_size;
|
||||
|
||||
u8 *left = arena_push_array_no_zero(scratch.arena, u8, left_size);
|
||||
u8 *right = arena_push_array_no_zero(scratch.arena, u8, right_size);
|
||||
u8 *left = PushArrayNoZero(scratch.arena, u8, left_size);
|
||||
u8 *right = PushArrayNoZero(scratch.arena, u8, right_size);
|
||||
MEMCPY(left, items, left_size);
|
||||
MEMCPY(right, (u8 *)items + left_size, right_size);
|
||||
|
||||
merge_sort(left, left_count, item_size, callback, udata);
|
||||
merge_sort(right, right_count, item_size, callback, udata);
|
||||
merge_sort_internal(left, right, (u8 *)items, left_count, right_count, item_size, callback, udata);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,9 +119,9 @@ Struct(Dict) {
|
||||
INLINE Dict *dict_init(Arena *arena, u64 bins_count)
|
||||
{
|
||||
__prof;
|
||||
Dict *dict = arena_push(arena, Dict);
|
||||
Dict *dict = PushStruct(arena, Dict);
|
||||
dict->bins_count = max_u64(bins_count, 1); /* Ensure at least 1 bin */
|
||||
dict->bins = arena_push_array(arena, DictBin, dict->bins_count);
|
||||
dict->bins = PushArray(arena, DictBin, dict->bins_count);
|
||||
return dict;
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ INLINE DictEntry *dict_ensure_entry(Arena *arena, Dict *dict, u64 hash)
|
||||
entry = dict->first_free;
|
||||
dict->first_free = entry->next;
|
||||
} else {
|
||||
entry = arena_push_no_zero(arena, DictEntry);
|
||||
entry = PushStructNoZero(arena, DictEntry);
|
||||
}
|
||||
MEMZERO_STRUCT(entry);
|
||||
entry->hash = hash;
|
||||
|
||||
3
src/bitbuff/bitbuff.c
Normal file
3
src/bitbuff/bitbuff.c
Normal file
@ -0,0 +1,3 @@
|
||||
#include "bitbuff.h"
|
||||
|
||||
#include "bitbuff_core.c"
|
||||
8
src/bitbuff/bitbuff.h
Normal file
8
src/bitbuff/bitbuff.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef BITBUFF_H
|
||||
#define BITBUFF_H
|
||||
|
||||
#include "../base/base.h"
|
||||
|
||||
#include "bitbuff_core.h"
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
191
src/bitbuff/bitbuff_core.h
Normal file
191
src/bitbuff/bitbuff_core.h
Normal file
@ -0,0 +1,191 @@
|
||||
////////////////////////////////
|
||||
//~ Bitbuff types
|
||||
|
||||
#define BB_DebugIsEnabled DebugBitbuff
|
||||
|
||||
//- Buff
|
||||
Struct(BB_Buff)
|
||||
{
|
||||
b32 is_backed_by_arena;
|
||||
|
||||
/* If `is_arena_bitbuff` is 1, this dynamically-sized arena will be used for reading & writing (meaning writing cannot overflow) */
|
||||
Arena *arena;
|
||||
|
||||
/* If `is_arena_bitbuff` is 0, this fixed-sized buffer willl be used for reading & writing */
|
||||
String fixed_buffer;
|
||||
};
|
||||
|
||||
//- Writer
|
||||
/* NOTE: base_len is not stored with the writer (as it is with the reader) since a dynamic arena-backed bitbuff could grow, meaning len needs to be re-checked */
|
||||
#define BB_WriterOverflowArenaPushSize 4096
|
||||
Struct(BB_Writer)
|
||||
{
|
||||
b32 overflowed;
|
||||
BB_Buff *bb;
|
||||
u8 *base;
|
||||
u64 cur_bit;
|
||||
#if BB_DebugIsEnabled
|
||||
b32 debug_enabled;
|
||||
#endif
|
||||
};
|
||||
|
||||
//- Reader
|
||||
Struct(BB_Reader)
|
||||
{
|
||||
b32 overflowed;
|
||||
u64 base_len;
|
||||
u8 *base;
|
||||
u64 cur_bit;
|
||||
#if BB_DebugIsEnabled
|
||||
b32 debug_enabled;
|
||||
#endif
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Debug types
|
||||
|
||||
#if BB_DebugIsEnabled
|
||||
|
||||
/* Magic numbers inserted to verify read/write type & length */
|
||||
typedef u32 BB_DebugMagicKind; enum
|
||||
{
|
||||
BB_DebugMagicKind_Align = 0x20A4,
|
||||
BB_DebugMagicKind_UBits = 0xCB4A,
|
||||
BB_DebugMagicKind_IBits = 0xB30D,
|
||||
BB_DebugMagicKind_UV = 0xE179,
|
||||
BB_DebugMagicKind_IV = 0x981f,
|
||||
BB_DebugMagicKind_F32 = 0x56F9,
|
||||
BB_DebugMagicKind_F64 = 0x7053,
|
||||
BB_DebugMagicKind_UID = 0xA24E,
|
||||
BB_DebugMagicKind_String = 0x7866
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ Buff management
|
||||
|
||||
BB_Buff AllocBitbuff(u64 arena_reserve);
|
||||
void ReleaseBitbuff(BB_Buff *bitbuff);
|
||||
|
||||
BB_Buff BitbuffFromString(String s);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Writer management
|
||||
|
||||
BB_Writer BB_WriterFromBuff(BB_Buff *bb);
|
||||
BB_Writer BB_WriterFromBuffNoDebug(BB_Buff *bb);
|
||||
|
||||
u64 BB_GetNumBitsWritten(BB_Writer *bw);
|
||||
u64 BB_GetNumBytesWritten(BB_Writer *bw);
|
||||
|
||||
String BB_GetWritten(Arena *arena, BB_Writer *bw);
|
||||
u8 *BB_GetWrittenRaw(BB_Writer *bw);
|
||||
|
||||
b32 BB_CheckWriterOverflowBits(BB_Writer *bw, u64 num_bits);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Writer ops
|
||||
|
||||
//- Align
|
||||
void BB_AlignWriter(BB_Writer *bw);
|
||||
|
||||
//- Bits
|
||||
void BB_WriteUBitsNoMagic(BB_Writer *bw, u64 value, u8 num_bits);
|
||||
void BB_WriteUBits(BB_Writer *bw, u64 value, u8 num_bits);
|
||||
void BB_WriteIBits(BB_Writer *bw, i64 value, u8 num_bits);
|
||||
b32 BB_WriteBit(BB_Writer *bw, u8 value);
|
||||
|
||||
//- Variable length integers
|
||||
void BB_WriteUV(BB_Writer *bw, u64 value);
|
||||
void BB_WriteIV(BB_Writer *bw, i64 value);
|
||||
|
||||
//- Floating point
|
||||
void BB_WriteF32(BB_Writer *bw, f32 value);
|
||||
void BB_WriteF64(BB_Writer *bw, f64 value);
|
||||
|
||||
//- UID
|
||||
void BB_WriteUID(BB_Writer *bw, UID value);
|
||||
|
||||
//- Raw data
|
||||
void BB_WriteString(BB_Writer *bw, String s);
|
||||
void BB_WriteBytes(BB_Writer *bw, String bytes);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Writer debug
|
||||
|
||||
#if BB_DebugIsEnabled
|
||||
void BB_WriteDebugMagic(BB_Writer *bw, BB_DebugMagicKind magic, u8 num_bits);
|
||||
void BB_WriteDebugMarker(BB_Writer *bw, String name);
|
||||
#else
|
||||
#define BB_WriteDebugMagic(bw, magic, num_bits)
|
||||
#define BB_WriteDebugMarker(bw, name)
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ Reader management
|
||||
|
||||
BB_Reader BB_ReaderFromBuff(BB_Buff *bb);
|
||||
BB_Reader BB_ReaderFromBuffNoDebug(BB_Buff *bb);
|
||||
|
||||
u64 BB_GetCurrentReaderBit(BB_Reader *br);
|
||||
u64 BB_GetCurrentReaderByte(BB_Reader *br);
|
||||
|
||||
u64 BB_NumBitsRemaining(BB_Reader *br);
|
||||
u64 BB_NumBytesRemaining(BB_Reader *br);
|
||||
|
||||
b32 BB_CheckReaderOverflowBits(BB_Reader *br, u64 num_bits);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Reader ops
|
||||
|
||||
//- Align
|
||||
void BB_AlignReader(BB_Reader *br);
|
||||
|
||||
//- Bits
|
||||
u64 BB_ReadUBitsNoMagic(BB_Reader *br, u8 num_bits);
|
||||
u64 BB_ReadUBits(BB_Reader *br, u8 num_bits);
|
||||
i64 BB_ReadIBits(BB_Reader *br, u8 num_bits);
|
||||
u8 BB_ReadBit(BB_Reader *br);
|
||||
|
||||
//- Variable length integers
|
||||
u64 BB_ReadUV(BB_Reader *br);
|
||||
i64 BB_ReadIV(BB_Reader *br);
|
||||
|
||||
//- Floating point
|
||||
f32 BB_ReadF32(BB_Reader *br);
|
||||
f64 BB_ReadF64(BB_Reader *br);
|
||||
|
||||
//- UID
|
||||
UID BB_ReadUID(BB_Reader *br);
|
||||
|
||||
//- Raw data
|
||||
String BB_ReadString(Arena *arena, BB_Reader *br);
|
||||
void BB_ReadBytes(BB_Reader *br, String dst);
|
||||
u8 *BB_ReadBytesRaw(BB_Reader *br, u64 num_bytes);
|
||||
void BB_SeekBytes(BB_Reader *br, u64 num_bytes);
|
||||
void BB_SeekToByte(BB_Reader *br, u64 pos);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Reader debug
|
||||
|
||||
#if BB_DebugIsEnabled
|
||||
void BB_ReadDebugMagic(BB_Reader *br, BB_DebugMagicKind expected_magic, u8 expected_num_bits);
|
||||
void BB_ReadDebugMarker(BB_Reader *br, String name);
|
||||
#else
|
||||
#define BB_ReadDebugMagic(br, expected_magic, expected_num_bits)
|
||||
#define BB_ReadDebugMarker(br, name)
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ Utils
|
||||
|
||||
u64 BB_TwosComplimentFromUint(u64 value, u8 num_bits);
|
||||
i64 BB_IntFromTwosCompliment(u64 tc, u8 num_bits);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Test
|
||||
|
||||
#if BITBUFF_TEST
|
||||
void BB_Test(void);
|
||||
#endif
|
||||
@ -328,7 +328,7 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
INTERNAL struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, struct gjk_result gjk_res, f32 min_unique_pt_dist_sq, u32 max_iterations)
|
||||
#endif
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
CLD_MenkowskiFeature closest_feature = ZI;
|
||||
V2 normal = ZI;
|
||||
@ -337,10 +337,10 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
u32 proto_count = 0;
|
||||
if (gjk_res.overlapping) {
|
||||
CLD_MenkowskiSimplex s = gjk_res.simplex;
|
||||
proto = arena_push_dry(scratch.arena, CLD_MenkowskiPoint);
|
||||
proto = PushDry(scratch.arena, CLD_MenkowskiPoint);
|
||||
{
|
||||
ASSERT(s.len == 3);
|
||||
CLD_MenkowskiPoint *tmp = arena_push_array_no_zero(scratch.arena, CLD_MenkowskiPoint, 3);
|
||||
CLD_MenkowskiPoint *tmp = PushArrayNoZero(scratch.arena, CLD_MenkowskiPoint, 3);
|
||||
tmp[0] = s.a;
|
||||
tmp[1] = s.b;
|
||||
tmp[2] = s.c;
|
||||
@ -430,7 +430,7 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
}
|
||||
|
||||
/* Expand prototype */
|
||||
arena_push_no_zero(scratch.arena, CLD_MenkowskiPoint);
|
||||
PushStructNoZero(scratch.arena, CLD_MenkowskiPoint);
|
||||
++proto_count;
|
||||
|
||||
/* Shift points in prototype to make room */
|
||||
@ -468,7 +468,7 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(CLD_Shape *shape0, CLD_Shape
|
||||
res.prototype.len = len;
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -949,13 +949,13 @@ f32 collider_time_of_impact(CLD_Shape *c0, CLD_Shape *c1,
|
||||
/* TODO: Remove this (debugging) */
|
||||
V2Array menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1, u32 detail)
|
||||
{
|
||||
V2Array res = { .points = arena_push_dry(arena, V2) };
|
||||
V2Array res = { .points = PushDry(arena, V2) };
|
||||
for (u64 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / detail) * (2 * PI);
|
||||
V2 dir = v2_from_angle(angle);
|
||||
CLD_MenkowskiPoint m = get_menkowski_point(shape0, shape1, xf0, xf1, dir);
|
||||
if (res.count == 0 || !v2_eq(m.p, res.points[res.count - 1])) {
|
||||
*arena_push_no_zero(arena, V2) = m.p;
|
||||
*PushStructNoZero(arena, V2) = m.p;
|
||||
++res.count;
|
||||
}
|
||||
}
|
||||
@ -966,7 +966,7 @@ V2Array menkowski(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0,
|
||||
V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xform xf1)
|
||||
{
|
||||
/* FIXME: Account for radius */
|
||||
V2Array res = { .points = arena_push_dry(arena, V2) };
|
||||
V2Array res = { .points = PushDry(arena, V2) };
|
||||
V2 *points0 = shape0->points;
|
||||
V2 *points1 = shape1->points;
|
||||
u32 count0 = shape0->count;
|
||||
@ -975,7 +975,7 @@ V2Array cloud(Arena *arena, CLD_Shape *shape0, CLD_Shape *shape1, Xform xf0, Xfo
|
||||
V2 p0 = xform_mul_v2(xf0, points0[i]);
|
||||
for (u64 j = 0; j < count1; ++j) {
|
||||
V2 p1 = xform_mul_v2(xf1, points1[j]);
|
||||
*arena_push_no_zero(arena, V2) = v2_sub(p0, p1);
|
||||
*PushStructNoZero(arena, V2) = v2_sub(p0, p1);
|
||||
++res.count;
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@
|
||||
#define FLOOD_DEBUG 0
|
||||
|
||||
/* If enabled, bitbuffs will insert/verify magic numbers & length for each read & write */
|
||||
#define BITBUFF_DEBUG 0
|
||||
#define DebugBitbuff 0
|
||||
#define BITBUFF_TEST RTC
|
||||
|
||||
/* If enabled, things like network writes & memory allocations will be tracked in a global statistics struct */
|
||||
|
||||
@ -50,7 +50,7 @@ void draw_poly_ex(G_RenderSig *sig, V2Array vertices, G_Indices indices, u32 col
|
||||
void draw_poly(G_RenderSig *sig, V2Array vertices, u32 color)
|
||||
{
|
||||
if (vertices.count >= 3) {
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
u32 num_tris = vertices.count - 2;
|
||||
u32 num_indices = num_tris * 3;
|
||||
@ -58,7 +58,7 @@ void draw_poly(G_RenderSig *sig, V2Array vertices, u32 color)
|
||||
/* Generate indices in a fan pattern */
|
||||
G_Indices indices = {
|
||||
.count = num_indices,
|
||||
.indices = arena_push_array_no_zero(scratch.arena, u32, num_indices)
|
||||
.indices = PushArrayNoZero(scratch.arena, u32, num_indices)
|
||||
};
|
||||
for (u32 i = 0; i < num_tris; ++i) {
|
||||
u32 tri_offset = i * 3;
|
||||
@ -69,15 +69,15 @@ void draw_poly(G_RenderSig *sig, V2Array vertices, u32 color)
|
||||
|
||||
draw_poly_ex(sig, vertices, indices, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle(G_RenderSig *sig, V2 pos, f32 radius, u32 color, u32 detail)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
V2 *points = arena_push_array_no_zero(scratch.arena, V2, detail);
|
||||
V2 *points = PushArrayNoZero(scratch.arena, V2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * TAU;
|
||||
V2 p = V2FromXY(
|
||||
@ -93,7 +93,7 @@ void draw_circle(G_RenderSig *sig, V2 pos, f32 radius, u32 color, u32 detail)
|
||||
};
|
||||
draw_poly(sig, vertices, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void draw_quad(G_RenderSig *sig, Quad quad, u32 color)
|
||||
@ -156,9 +156,9 @@ void draw_poly_line(G_RenderSig *sig, V2Array points, b32 loop, f32 thickness, u
|
||||
|
||||
void draw_circle_line(G_RenderSig *sig, V2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
V2 *points = arena_push_array_no_zero(scratch.arena, V2, detail);
|
||||
V2 *points = PushArrayNoZero(scratch.arena, V2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * TAU;
|
||||
V2 p = V2FromXY(
|
||||
@ -174,7 +174,7 @@ void draw_circle_line(G_RenderSig *sig, V2 pos, f32 radius, f32 thickness, u32 c
|
||||
};
|
||||
draw_poly_line(sig, a, 1, thickness, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void draw_quad_line(G_RenderSig *sig, Quad quad, f32 thickness, u32 color)
|
||||
@ -222,18 +222,18 @@ void draw_arrow_ray(G_RenderSig *sig, V2 pos, V2 rel, f32 thickness, f32 arrowhe
|
||||
|
||||
void draw_collider_line(G_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
V2Array poly = ZI;
|
||||
if (shape.radius == 0) {
|
||||
poly.count = shape.count;
|
||||
poly.points = arena_push_array_no_zero(scratch.arena, V2, shape.count);
|
||||
poly.points = PushArrayNoZero(scratch.arena, V2, shape.count);
|
||||
for (u32 i = 0; i < shape.count; ++i) {
|
||||
V2 p = xform_mul_v2(shape_xf, shape.points[i]);
|
||||
poly.points[i] = p;
|
||||
}
|
||||
} else {
|
||||
poly.count = detail;
|
||||
poly.points = arena_push_array_no_zero(scratch.arena, V2, detail);
|
||||
poly.points = PushArrayNoZero(scratch.arena, V2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * TAU;
|
||||
V2 dir = V2FromXY(math_cos(angle), math_sin(angle));
|
||||
@ -242,7 +242,7 @@ void draw_collider_line(G_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 t
|
||||
}
|
||||
}
|
||||
draw_poly_line(sig, poly, 1, thickness, color);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -296,7 +296,7 @@ void draw_ui_rect(G_RenderSig *sig, D_UiRectParams params)
|
||||
/* Returns the rect of the text area */
|
||||
Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
f32 inv_font_image_width = 1.0 / (f32)params.font->image_width;
|
||||
f32 inv_font_image_height = 1.0 / (f32)params.font->image_height;
|
||||
@ -338,7 +338,7 @@ Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
f32 top_offset = 0;
|
||||
f32 bottom_offset = 0;
|
||||
u64 num_line_glyphs = 0;
|
||||
struct drawable_glyph *line_glyphs = arena_push_dry(scratch.arena, struct drawable_glyph);
|
||||
struct drawable_glyph *line_glyphs = PushDry(scratch.arena, struct drawable_glyph);
|
||||
|
||||
b32 line_done = 0;
|
||||
while (!line_done) {
|
||||
@ -350,7 +350,7 @@ Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
if (codepoint == '\n') {
|
||||
line_done = 1;
|
||||
} else {
|
||||
struct drawable_glyph *tg = arena_push(scratch.arena, struct drawable_glyph);
|
||||
struct drawable_glyph *tg = PushStruct(scratch.arena, struct drawable_glyph);
|
||||
++num_line_glyphs;
|
||||
F_Glyph *glyph = font_get_glyph(params.font, codepoint);
|
||||
tg->off_x = glyph->off_x * params.scale;
|
||||
@ -378,7 +378,7 @@ Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
|
||||
/* Line ended */
|
||||
/* TODO: Only create nodes for non-empty lines. Embed line number in the node. */
|
||||
struct drawable_line *node = arena_push(scratch.arena, struct drawable_line);
|
||||
struct drawable_line *node = PushStruct(scratch.arena, struct drawable_line);
|
||||
node->line_width = line_width;
|
||||
node->num_glyphs = num_line_glyphs;
|
||||
node->glyphs = line_glyphs;
|
||||
@ -469,6 +469,6 @@ Rect draw_text(G_RenderSig *sig, D_TextParams params)
|
||||
++line_number;
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@ -34,10 +34,10 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
|
||||
DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String *args)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
DXC_Result res = ZI;
|
||||
|
||||
wchar_t **wstr_args = arena_push_array(scratch.arena, wchar_t *, num_args);
|
||||
wchar_t **wstr_args = PushArray(scratch.arena, wchar_t *, num_args);
|
||||
for (i32 i = 0; i < num_args; ++i) {
|
||||
wstr_args[i] = wstr_from_string(scratch.arena, args[i]);
|
||||
}
|
||||
@ -86,7 +86,7 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "ase/ase.h"
|
||||
#include "asset_cache/asset_cache.h"
|
||||
#include "base/base.h"
|
||||
#include "bitbuff/bitbuff.h"
|
||||
#include "collider/collider.h"
|
||||
#include "draw/draw.h"
|
||||
#include "dxc/dxc.h"
|
||||
|
||||
@ -36,7 +36,7 @@ F_StartupReceipt font_startup(AC_StartupReceipt *asset_cache_sr,
|
||||
__prof;
|
||||
(UNUSED)asset_cache_sr;
|
||||
(UNUSED)ttf_sr;
|
||||
G.params.arena = arena_alloc(GIBI(64));
|
||||
G.params.arena = AllocArena(GIBI(64));
|
||||
return (F_StartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ INTERNAL struct font_task_params *font_task_params_alloc(void)
|
||||
p = G.params.head_free;
|
||||
G.params.head_free = p->next_free;
|
||||
} else {
|
||||
p = arena_push(G.params.arena, struct font_task_params);
|
||||
p = PushStruct(G.params.arena, struct font_task_params);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -75,7 +75,7 @@ INTERNAL void font_task_params_release(struct font_task_params *p)
|
||||
INTERNAL P_JobDef(font_load_asset_job, job)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
struct font_task_params *params = job.sig;
|
||||
String path = STRING(params->path_len, (u8 *)params->path_cstr);
|
||||
@ -106,9 +106,9 @@ INTERNAL P_JobDef(font_load_asset_job, job)
|
||||
F_Font *font = 0;
|
||||
{
|
||||
AC_Store store = asset_cache_store_open();
|
||||
font = arena_push(store.arena, F_Font);
|
||||
font->glyphs = arena_push_array_no_zero(store.arena, F_Glyph, result.glyphs_count);
|
||||
font->lookup = arena_push_array(store.arena, u16, LOOKUP_TABLE_SIZE);
|
||||
font = PushStruct(store.arena, F_Font);
|
||||
font->glyphs = PushArrayNoZero(store.arena, F_Glyph, result.glyphs_count);
|
||||
font->lookup = PushArray(store.arena, u16, LOOKUP_TABLE_SIZE);
|
||||
asset_cache_store_close(&store);
|
||||
}
|
||||
|
||||
@ -141,14 +141,14 @@ INTERNAL P_JobDef(font_load_asset_job, job)
|
||||
P_LogSuccessF("Loaded font \"%F\" (point size %F) in %F seconds", FMT_STR(path), FMT_FLOAT((f64)point_size), FMT_FLOAT(SECONDS_FROM_NS(P_TimeNs() - start_ns)));
|
||||
asset_cache_mark_ready(asset, font);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* Returns the asset from the asset cache */
|
||||
AC_Asset *font_load_asset(String path, f32 point_size, b32 wait)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* Concatenate point_size to path for key */
|
||||
String key = string_format(scratch.arena,
|
||||
@ -172,7 +172,7 @@ AC_Asset *font_load_asset(String path, f32 point_size, b32 wait)
|
||||
params->asset = asset;
|
||||
params->point_size = point_size;
|
||||
|
||||
/* Push task */
|
||||
/* PushStruct task */
|
||||
asset_cache_mark_loading(asset);
|
||||
P_Run(1, font_load_asset_job, params, P_Pool_Background, P_Priority_Low, 0);
|
||||
if (wait) {
|
||||
@ -180,7 +180,7 @@ AC_Asset *font_load_asset(String path, f32 point_size, b32 wait)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return asset;
|
||||
}
|
||||
|
||||
|
||||
@ -387,26 +387,26 @@ void gp_startup(void)
|
||||
}
|
||||
|
||||
/* Initialize command descriptor heaps pool */
|
||||
G.command_descriptor_heaps_arena = arena_alloc(GIBI(64));
|
||||
G.command_descriptor_heaps_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Initialize command buffers pool */
|
||||
G.command_buffers_arena = arena_alloc(GIBI(64));
|
||||
G.command_buffers_arena = AllocArena(GIBI(64));
|
||||
G.command_buffers_dict = dict_init(G.command_buffers_arena, 4096);
|
||||
|
||||
/* Initialize resources pool */
|
||||
G.resources_arena = arena_alloc(GIBI(64));
|
||||
G.resources_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Initialize swapchains pool */
|
||||
G.swapchains_arena = arena_alloc(GIBI(64));
|
||||
G.swapchains_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Initialize pipeline cache */
|
||||
G.pipelines_arena = arena_alloc(GIBI(64));
|
||||
G.pipelines_arena = AllocArena(GIBI(64));
|
||||
G.pipeline_descs = dict_init(G.pipelines_arena, 1024);
|
||||
G.top_pipelines = dict_init(G.pipelines_arena, 1024);
|
||||
G.top_successful_pipelines = dict_init(G.pipelines_arena, 1024);
|
||||
|
||||
/* Initialize fenced releases queue */
|
||||
G.fenced_releases_arena = arena_alloc(GIBI(64));
|
||||
G.fenced_releases_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Initialize embedded shader archive */
|
||||
String embedded_data = inc_dxc_tar();
|
||||
@ -462,16 +462,16 @@ INTERNAL P_ExitFuncDef(gp_shutdown)
|
||||
|
||||
INTERNAL void dx12_init_error(String error)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String msg = string_format(scratch.arena, LIT("Failed to initialize DirectX 12.\n\n%F"), FMT_STR(error));
|
||||
P_Panic(msg);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
INTERNAL void dx12_init_device(void)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
HRESULT hr = 0;
|
||||
|
||||
/* Enable debug layer */
|
||||
@ -620,7 +620,7 @@ INTERNAL void dx12_init_device(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -686,13 +686,13 @@ INTERNAL void pipeline_register(u64 num_pipelines, struct pipeline **pipelines);
|
||||
INTERNAL void dx12_init_pipelines(void)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* Register pipeline descs */
|
||||
{
|
||||
/* Material pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_material");
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
@ -702,19 +702,19 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
}
|
||||
/* Flood pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_flood");
|
||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||
}
|
||||
/* Shade pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_shade");
|
||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||
}
|
||||
/* Shape pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_shape");
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
@ -722,7 +722,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
}
|
||||
/* UI pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_ui");
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
@ -730,7 +730,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
}
|
||||
/* Blit pipeilne */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
struct pipeline_desc *desc = PushStruct(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("kernel_blit");
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
@ -740,13 +740,13 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
|
||||
/* Compile pipelines */
|
||||
u32 num_pipelines = 0;
|
||||
struct pipeline_desc *descs = arena_push_dry(scratch.arena, struct pipeline_desc);
|
||||
struct pipeline_desc *descs = PushDry(scratch.arena, struct pipeline_desc);
|
||||
for (DictEntry *entry = G.pipeline_descs->first; entry; entry = entry->next) {
|
||||
struct pipeline_desc *desc = (struct pipeline_desc *)entry->value;
|
||||
*arena_push(scratch.arena, struct pipeline_desc) = *desc;
|
||||
*PushStruct(scratch.arena, struct pipeline_desc) = *desc;
|
||||
++num_pipelines;
|
||||
}
|
||||
struct pipeline **pipelines = arena_push_array(scratch.arena, struct pipeline *, num_pipelines);
|
||||
struct pipeline **pipelines = PushArray(scratch.arena, struct pipeline *, num_pipelines);
|
||||
{
|
||||
__profn("Allocate pipelines");
|
||||
struct pipeline_alloc_job_sig sig = ZI;
|
||||
@ -773,7 +773,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
}
|
||||
pipeline_register(num_pipelines, pipelines);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -782,7 +782,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
|
||||
INTERNAL void dx12_init_noise(void)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
{
|
||||
String noise_res_name = LIT("noise_128x128x64_16.dat");
|
||||
@ -838,7 +838,7 @@ INTERNAL void dx12_init_noise(void)
|
||||
resource_close(&noise_res);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -875,7 +875,7 @@ INTERNAL P_JobDef(shader_compile_job, job)
|
||||
struct shader_compile_desc *desc = &sig->descs[job.id];
|
||||
struct shader_compile_result *result = &sig->results[job.id];
|
||||
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
{
|
||||
i64 start_ns = P_TimeNs();
|
||||
DXC_Result dxc_result = ZI;
|
||||
@ -892,7 +892,7 @@ INTERNAL P_JobDef(shader_compile_job, job)
|
||||
LIT("-T"), desc->target,
|
||||
};
|
||||
u32 num_args = countof(shader_args) + dxc_args_array.count;
|
||||
String *args = arena_push_array(scratch.arena, String, num_args);
|
||||
String *args = PushArray(scratch.arena, String, num_args);
|
||||
for (u32 i = 0; i < countof(shader_args); ++i) {
|
||||
args[i] = shader_args[i];
|
||||
}
|
||||
@ -907,7 +907,7 @@ INTERNAL P_JobDef(shader_compile_job, job)
|
||||
result->elapsed_ns = P_TimeNs() - start_ns;
|
||||
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -930,7 +930,7 @@ INTERNAL P_JobDef(pipeline_alloc_job, job)
|
||||
pipeline = G.first_free_pipeline;
|
||||
G.first_free_pipeline = pipeline->next;
|
||||
} else {
|
||||
pipeline = arena_push_no_zero(G.pipelines_arena, struct pipeline);
|
||||
pipeline = PushStructNoZero(G.pipelines_arena, struct pipeline);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -940,7 +940,7 @@ INTERNAL P_JobDef(pipeline_alloc_job, job)
|
||||
pipeline->name = desc->name;
|
||||
pipeline->hash = hash_fnv64(HASH_FNV64_BASIS, pipeline->name);
|
||||
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
{
|
||||
i64 start_ns = P_TimeNs();
|
||||
String pipeline_name = pipeline->name;
|
||||
@ -1183,7 +1183,7 @@ INTERNAL P_JobDef(pipeline_alloc_job, job)
|
||||
ID3D10Blob_Release(cs_blob);
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
INTERNAL void pipeline_release_now(struct pipeline *pipeline)
|
||||
@ -1220,10 +1220,10 @@ INTERNAL struct pipeline_scope *pipeline_scope_begin(void)
|
||||
if (scope) {
|
||||
arena = scope->arena;
|
||||
} else {
|
||||
arena = arena_alloc(MEBI(64));
|
||||
arena = AllocArena(MEBI(64));
|
||||
}
|
||||
arena_reset(arena);
|
||||
scope = arena_push(arena, struct pipeline_scope);
|
||||
ResetArena(arena);
|
||||
scope = PushStruct(arena, struct pipeline_scope);
|
||||
scope->arena = arena;
|
||||
scope->refs = dict_init(scope->arena, 64);
|
||||
return scope;
|
||||
@ -1309,7 +1309,7 @@ INTERNAL void pipeline_register(u64 num_pipelines, struct pipeline **pipelines)
|
||||
INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
String rst_extension = LIT(".rst");
|
||||
String knl_extension = LIT(".knl");
|
||||
@ -1347,8 +1347,8 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
sig.arena = scratch.arena;
|
||||
if (is_rs) {
|
||||
num_shaders = 2;
|
||||
shader_descs = arena_push_array(scratch.arena, struct shader_compile_desc, num_shaders);
|
||||
shader_results = arena_push_array(scratch.arena, struct shader_compile_result, num_shaders);
|
||||
shader_descs = PushArray(scratch.arena, struct shader_compile_desc, num_shaders);
|
||||
shader_results = PushArray(scratch.arena, struct shader_compile_result, num_shaders);
|
||||
sig.descs = shader_descs;
|
||||
sig.results = shader_results;
|
||||
sig.descs[0].src = data;
|
||||
@ -1361,8 +1361,8 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
sig.descs[1].target = LIT("ps_6_6");
|
||||
} else if (is_cs) {
|
||||
num_shaders = 1;
|
||||
shader_descs = arena_push_array(scratch.arena, struct shader_compile_desc, num_shaders);
|
||||
shader_results = arena_push_array(scratch.arena, struct shader_compile_result, num_shaders);
|
||||
shader_descs = PushArray(scratch.arena, struct shader_compile_desc, num_shaders);
|
||||
shader_results = PushArray(scratch.arena, struct shader_compile_result, num_shaders);
|
||||
sig.descs = shader_descs;
|
||||
sig.results = shader_results;
|
||||
sig.descs[0].src = data;
|
||||
@ -1399,7 +1399,7 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
if (success) {
|
||||
/* Create pipeline descs */
|
||||
u32 num_pipelines = 0;
|
||||
struct pipeline_desc *pipeline_descs = arena_push_dry(scratch.arena, struct pipeline_desc);
|
||||
struct pipeline_desc *pipeline_descs = PushDry(scratch.arena, struct pipeline_desc);
|
||||
for (DictEntry *entry = G.pipeline_descs->first; entry; entry = entry->next) {
|
||||
struct pipeline_desc *pipeline_desc = (struct pipeline_desc *)entry->value;
|
||||
struct pipeline_desc new_pipeline_desc = *pipeline_desc;
|
||||
@ -1410,7 +1410,7 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
} else if (is_cs) {
|
||||
new_pipeline_desc.cs_dxc = shader_results[0].dxc;
|
||||
}
|
||||
*arena_push_no_zero(scratch.arena, struct pipeline_desc) = new_pipeline_desc;
|
||||
*PushStructNoZero(scratch.arena, struct pipeline_desc) = new_pipeline_desc;
|
||||
++num_pipelines;
|
||||
}
|
||||
}
|
||||
@ -1418,7 +1418,7 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
/* Recompile dirty pipelines */
|
||||
if (num_pipelines > 0) {
|
||||
__profn("Compile dirty pipelines");
|
||||
struct pipeline **pipelines = arena_push_array(scratch.arena, struct pipeline *, num_pipelines);
|
||||
struct pipeline **pipelines = PushArray(scratch.arena, struct pipeline *, num_pipelines);
|
||||
{
|
||||
struct pipeline_alloc_job_sig sig = ZI;
|
||||
sig.descs_in = pipeline_descs;
|
||||
@ -1459,7 +1459,7 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1484,7 +1484,7 @@ INTERNAL struct descriptor *descriptor_alloc(struct cpu_descriptor_heap *dh)
|
||||
if (dh->num_descriptors_reserved >= dh->num_descriptors_capacity) {
|
||||
P_Panic(LIT("Max descriptors reached in heap"));
|
||||
}
|
||||
d = arena_push_no_zero(dh->arena, struct descriptor);
|
||||
d = PushStructNoZero(dh->arena, struct descriptor);
|
||||
index = dh->num_descriptors_reserved++;
|
||||
handle.ptr = dh->handle.ptr + (index * dh->descriptor_size);
|
||||
}
|
||||
@ -1517,8 +1517,8 @@ INTERNAL struct cpu_descriptor_heap *cpu_descriptor_heap_alloc(enum D3D12_DESCRI
|
||||
__prof;
|
||||
struct cpu_descriptor_heap *dh = 0;
|
||||
{
|
||||
Arena *arena = arena_alloc(MEBI(64));
|
||||
dh = arena_push(arena, struct cpu_descriptor_heap);
|
||||
Arena *arena = AllocArena(MEBI(64));
|
||||
dh = PushStruct(arena, struct cpu_descriptor_heap);
|
||||
dh->arena = arena;
|
||||
}
|
||||
|
||||
@ -1576,11 +1576,11 @@ INTERNAL void fenced_release(void *data, enum fenced_release_kind kind)
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
|
||||
/* Push data to release queue */
|
||||
/* PushStruct data to release queue */
|
||||
{
|
||||
P_Lock lock = P_LockE(&G.fenced_releases_mutex);
|
||||
{
|
||||
*arena_push(G.fenced_releases_arena, struct fenced_release_data) = fr;
|
||||
*PushStruct(G.fenced_releases_arena, struct fenced_release_data) = fr;
|
||||
MEMCPY(G.fenced_release_targets, fr_targets, sizeof(fr_targets));
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
@ -1611,7 +1611,7 @@ INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_pr
|
||||
r = G.first_free_resource;
|
||||
G.first_free_resource = r->next_free;
|
||||
} else {
|
||||
r = arena_push_no_zero(G.resources_arena, struct dx12_resource);
|
||||
r = PushStructNoZero(G.resources_arena, struct dx12_resource);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -1682,10 +1682,10 @@ struct dx12_resource_barrier_desc {
|
||||
INTERNAL void dx12_resource_barriers(ID3D12GraphicsCommandList *cl, i32 num_descs, struct dx12_resource_barrier_desc *descs)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
i32 num_rbs = 0;
|
||||
struct D3D12_RESOURCE_BARRIER *rbs = arena_push_array_no_zero(scratch.arena, struct D3D12_RESOURCE_BARRIER, num_descs);
|
||||
struct D3D12_RESOURCE_BARRIER *rbs = PushArrayNoZero(scratch.arena, struct D3D12_RESOURCE_BARRIER, num_descs);
|
||||
for (i32 i = 0; i < num_descs; ++i) {
|
||||
struct dx12_resource_barrier_desc *desc = &descs[i];
|
||||
struct dx12_resource *resource = desc->resource;
|
||||
@ -1720,7 +1720,7 @@ INTERNAL void dx12_resource_barriers(ID3D12GraphicsCommandList *cl, i32 num_desc
|
||||
ID3D12GraphicsCommandList_ResourceBarrier(cl, num_rbs, rbs);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -1737,8 +1737,8 @@ INTERNAL P_JobDef(command_queue_alloc_job, job)
|
||||
{
|
||||
struct command_queue *cq = 0;
|
||||
{
|
||||
Arena *arena = arena_alloc(GIBI(64));
|
||||
cq = arena_push(arena, struct command_queue);
|
||||
Arena *arena = AllocArena(GIBI(64));
|
||||
cq = PushStruct(arena, struct command_queue);
|
||||
cq->arena = arena;
|
||||
}
|
||||
cq->desc = *desc;
|
||||
@ -1779,8 +1779,8 @@ INTERNAL struct command_list_pool *command_list_pool_alloc(struct command_queue
|
||||
{
|
||||
struct command_list_pool *pool = 0;
|
||||
{
|
||||
Arena *arena = arena_alloc(GIBI(64));
|
||||
pool = arena_push(arena, struct command_list_pool);
|
||||
Arena *arena = AllocArena(GIBI(64));
|
||||
pool = PushStruct(arena, struct command_list_pool);
|
||||
pool->arena = arena;
|
||||
}
|
||||
pool->cq = cq;
|
||||
@ -1822,7 +1822,7 @@ INTERNAL struct command_list *command_list_open(struct command_list_pool *pool)
|
||||
pool->last_submitted_command_list = prev;
|
||||
}
|
||||
} else {
|
||||
cl = arena_push_no_zero(pool->arena, struct command_list);
|
||||
cl = PushStructNoZero(pool->arena, struct command_list);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -1992,7 +1992,7 @@ INTERNAL struct command_descriptor_heap *command_list_push_descriptor_heap(struc
|
||||
}
|
||||
} else {
|
||||
/* No available heap available for reuse, allocate new */
|
||||
cdh = arena_push_no_zero(G.command_descriptor_heaps_arena, struct command_descriptor_heap);
|
||||
cdh = PushStructNoZero(G.command_descriptor_heaps_arena, struct command_descriptor_heap);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -2079,7 +2079,7 @@ INTERNAL struct command_buffer *_command_list_push_buffer(struct command_list *c
|
||||
cb_group = (struct command_buffer_group *)cb_group_entry->value;
|
||||
if (!cb_group) {
|
||||
/* Create group */
|
||||
cb_group = arena_push(G.command_buffers_arena, struct command_buffer_group);
|
||||
cb_group = PushStruct(G.command_buffers_arena, struct command_buffer_group);
|
||||
cb_group_entry->value = (u64)cb_group;
|
||||
}
|
||||
}
|
||||
@ -2109,7 +2109,7 @@ INTERNAL struct command_buffer *_command_list_push_buffer(struct command_list *c
|
||||
}
|
||||
} else {
|
||||
/* Allocate new */
|
||||
cb = arena_push_no_zero(G.command_buffers_arena, struct command_buffer);
|
||||
cb = PushStructNoZero(G.command_buffers_arena, struct command_buffer);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -2575,16 +2575,16 @@ INTERNAL struct render_sig *render_sig_alloc(void)
|
||||
__prof;
|
||||
struct render_sig *sig = 0;
|
||||
{
|
||||
Arena *arena = arena_alloc(MEBI(64));
|
||||
sig = arena_push(arena, struct render_sig);
|
||||
Arena *arena = AllocArena(MEBI(64));
|
||||
sig = PushStruct(arena, struct render_sig);
|
||||
sig->arena = arena;
|
||||
}
|
||||
|
||||
sig->material_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->material_grid_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_rect_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_verts_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_indices_arena = arena_alloc(GIBI(1));
|
||||
sig->material_instance_descs_arena = AllocArena(GIBI(1));
|
||||
sig->material_grid_descs_arena = AllocArena(GIBI(1));
|
||||
sig->ui_rect_instance_descs_arena = AllocArena(GIBI(1));
|
||||
sig->ui_shape_verts_arena = AllocArena(GIBI(1));
|
||||
sig->ui_shape_indices_arena = AllocArena(GIBI(1));
|
||||
|
||||
return sig;
|
||||
}
|
||||
@ -2595,19 +2595,19 @@ INTERNAL void render_sig_reset(struct render_sig *sig)
|
||||
|
||||
/* Reset material instances */
|
||||
sig->num_material_instance_descs = 0;
|
||||
arena_reset(sig->material_instance_descs_arena);
|
||||
ResetArena(sig->material_instance_descs_arena);
|
||||
|
||||
/* Reset UI rect instances */
|
||||
sig->num_ui_rect_instance_descs = 0;
|
||||
arena_reset(sig->ui_rect_instance_descs_arena);
|
||||
ResetArena(sig->ui_rect_instance_descs_arena);
|
||||
|
||||
/* Reset shapes */
|
||||
arena_reset(sig->ui_shape_verts_arena);
|
||||
arena_reset(sig->ui_shape_indices_arena);
|
||||
ResetArena(sig->ui_shape_verts_arena);
|
||||
ResetArena(sig->ui_shape_indices_arena);
|
||||
|
||||
/* Reset grids */
|
||||
sig->num_material_grid_descs = 0;
|
||||
arena_reset(sig->material_grid_descs_arena);
|
||||
ResetArena(sig->material_grid_descs_arena);
|
||||
}
|
||||
|
||||
G_RenderSig *gp_render_sig_alloc(void)
|
||||
@ -2628,7 +2628,7 @@ u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *cmd_desc)
|
||||
case GP_RENDER_CMD_KIND_DRAW_MATERIAL:
|
||||
{
|
||||
struct dx12_resource *texture = (struct dx12_resource *)cmd_desc->material.texture;
|
||||
struct material_instance_desc *instance_desc = arena_push(sig->material_instance_descs_arena, struct material_instance_desc);
|
||||
struct material_instance_desc *instance_desc = PushStruct(sig->material_instance_descs_arena, struct material_instance_desc);
|
||||
instance_desc->xf = cmd_desc->material.xf;
|
||||
instance_desc->texture_id = texture ? texture->srv_descriptor->index : 0xFFFFFFFF;
|
||||
instance_desc->clip = cmd_desc->material.clip;
|
||||
@ -2642,7 +2642,7 @@ u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *cmd_desc)
|
||||
case GP_RENDER_CMD_KIND_DRAW_UI_RECT:
|
||||
{
|
||||
struct dx12_resource *texture = (struct dx12_resource *)cmd_desc->ui_rect.texture;
|
||||
struct ui_rect_instance_desc *instance_desc = arena_push(sig->ui_rect_instance_descs_arena, struct ui_rect_instance_desc);
|
||||
struct ui_rect_instance_desc *instance_desc = PushStruct(sig->ui_rect_instance_descs_arena, struct ui_rect_instance_desc);
|
||||
instance_desc->xf = cmd_desc->ui_rect.xf;
|
||||
instance_desc->texture_id = texture ? texture->srv_descriptor->index : 0xFFFFFFFF;
|
||||
instance_desc->clip = cmd_desc->ui_rect.clip;
|
||||
@ -2653,14 +2653,14 @@ u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *cmd_desc)
|
||||
case GP_RENDER_CMD_KIND_DRAW_UI_SHAPE:
|
||||
{
|
||||
u32 color = cmd_desc->ui_shape.color;
|
||||
struct k_shape_vert *verts = arena_push_array_no_zero(sig->ui_shape_verts_arena, struct k_shape_vert, cmd_desc->ui_shape.vertices.count);
|
||||
u32 *indices = arena_push_array_no_zero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
||||
struct k_shape_vert *verts = PushArrayNoZero(sig->ui_shape_verts_arena, struct k_shape_vert, cmd_desc->ui_shape.vertices.count);
|
||||
u32 *indices = PushArrayNoZero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
||||
for (u32 i = 0; i < cmd_desc->ui_shape.vertices.count; ++i) {
|
||||
struct k_shape_vert *v = &verts[i];
|
||||
v->pos = K_Float2FromV2(cmd_desc->ui_shape.vertices.points[i]);
|
||||
v->color_srgb = K_UintFromU32(color);
|
||||
}
|
||||
u32 vert_offset = verts - (struct k_shape_vert *)arena_base(sig->ui_shape_verts_arena);
|
||||
u32 vert_offset = verts - (struct k_shape_vert *)ArenaBase(sig->ui_shape_verts_arena);
|
||||
for (u32 i = 0; i < cmd_desc->ui_shape.indices.count; ++i) {
|
||||
indices[i] = cmd_desc->ui_shape.indices.indices[i] + vert_offset;
|
||||
}
|
||||
@ -2668,7 +2668,7 @@ u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *cmd_desc)
|
||||
|
||||
case GP_RENDER_CMD_KIND_PUSH_GRID:
|
||||
{
|
||||
struct material_grid_desc *grid_desc = arena_push(sig->material_grid_descs_arena, struct material_grid_desc);
|
||||
struct material_grid_desc *grid_desc = PushStruct(sig->material_grid_descs_arena, struct material_grid_desc);
|
||||
grid_desc->line_thickness = cmd_desc->grid.line_thickness;
|
||||
grid_desc->line_spacing = cmd_desc->grid.line_spacing;
|
||||
grid_desc->offset = cmd_desc->grid.offset;
|
||||
@ -2691,7 +2691,7 @@ u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *cmd_desc)
|
||||
G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct render_sig *rsig = (struct render_sig *)gp_render_sig;
|
||||
++rsig->frame_index;
|
||||
|
||||
@ -2764,9 +2764,9 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, countof(quad_indices), quad_indices);
|
||||
|
||||
/* Process sig data into uploadable data */
|
||||
struct k_material_instance *material_instances = arena_push_array_no_zero(scratch.arena, struct k_material_instance, rsig->num_material_instance_descs);
|
||||
struct k_ui_instance *ui_rect_instances = arena_push_array_no_zero(scratch.arena, struct k_ui_instance, rsig->num_ui_rect_instance_descs);
|
||||
struct k_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct k_material_grid, rsig->num_material_grid_descs);
|
||||
struct k_material_instance *material_instances = PushArrayNoZero(scratch.arena, struct k_material_instance, rsig->num_material_instance_descs);
|
||||
struct k_ui_instance *ui_rect_instances = PushArrayNoZero(scratch.arena, struct k_ui_instance, rsig->num_ui_rect_instance_descs);
|
||||
struct k_material_grid *grids = PushArrayNoZero(scratch.arena, struct k_material_grid, rsig->num_material_grid_descs);
|
||||
{
|
||||
__profn("Process sig data");
|
||||
|
||||
@ -2774,7 +2774,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
{
|
||||
__profn("Process material instances");
|
||||
for (u32 i = 0; i < rsig->num_material_instance_descs; ++i) {
|
||||
struct material_instance_desc *desc = &((struct material_instance_desc *)arena_base(rsig->material_instance_descs_arena))[i];
|
||||
struct material_instance_desc *desc = &((struct material_instance_desc *)ArenaBase(rsig->material_instance_descs_arena))[i];
|
||||
struct k_material_instance *instance = &material_instances[i];
|
||||
instance->tex_nurid = K_UintFromU32(desc->texture_id);
|
||||
instance->grid_id = K_UintFromU32(desc->grid_id);
|
||||
@ -2791,7 +2791,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
{
|
||||
__profn("Process ui rect instances");
|
||||
for (u32 i = 0; i < rsig->num_ui_rect_instance_descs; ++i) {
|
||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(rsig->ui_rect_instance_descs_arena))[i];
|
||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)ArenaBase(rsig->ui_rect_instance_descs_arena))[i];
|
||||
struct k_ui_instance *instance = &ui_rect_instances[i];
|
||||
instance->tex_nurid = K_UintFromU32(desc->texture_id);
|
||||
instance->xf = K_Float2x3FromXform(desc->xf);
|
||||
@ -2805,7 +2805,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
{
|
||||
__profn("Process grids");
|
||||
for (u32 i = 0; i < rsig->num_material_grid_descs; ++i) {
|
||||
struct material_grid_desc *desc = &((struct material_grid_desc *)arena_base(rsig->material_grid_descs_arena))[i];
|
||||
struct material_grid_desc *desc = &((struct material_grid_desc *)ArenaBase(rsig->material_grid_descs_arena))[i];
|
||||
struct k_material_grid *grid = &grids[i];
|
||||
grid->line_thickness = K_FloatFromF32(desc->line_thickness);
|
||||
grid->line_spacing = K_FloatFromF32(desc->line_spacing);
|
||||
@ -2824,8 +2824,8 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u32);
|
||||
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, rsig->num_material_instance_descs, material_instances);
|
||||
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, rsig->num_ui_rect_instance_descs, ui_rect_instances);
|
||||
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (struct k_shape_vert *)arena_base(rsig->ui_shape_verts_arena));
|
||||
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)arena_base(rsig->ui_shape_indices_arena));
|
||||
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (struct k_shape_vert *)ArenaBase(rsig->ui_shape_verts_arena));
|
||||
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)ArenaBase(rsig->ui_shape_indices_arena));
|
||||
struct command_buffer *grid_buffer = command_list_push_buffer(cl, rsig->num_material_grid_descs, grids);
|
||||
|
||||
/* Upload descriptor heap */
|
||||
@ -3142,7 +3142,7 @@ G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams params)
|
||||
pipeline_scope_end(pipeline_scope);
|
||||
|
||||
render_sig_reset(rsig);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return (G_Resource *)rsig->ui_target;
|
||||
}
|
||||
@ -3214,7 +3214,7 @@ G_Swapchain *gp_swapchain_alloc(P_Window *window, V2i32 resolution)
|
||||
swapchain = G.first_free_swapchain;
|
||||
G.first_free_swapchain = swapchain->next_free;
|
||||
} else {
|
||||
swapchain = arena_push(G.swapchains_arena, struct swapchain);
|
||||
swapchain = PushStruct(G.swapchains_arena, struct swapchain);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -3497,7 +3497,7 @@ INTERNAL P_JobDef(dx12_evictor_job, _)
|
||||
while (!shutdown) {
|
||||
{
|
||||
__profn("Dx12 evictor run");
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
u64 targets[countof(completed_targets)] = ZI;
|
||||
|
||||
/* Copy queued data */
|
||||
@ -3507,9 +3507,9 @@ INTERNAL P_JobDef(dx12_evictor_job, _)
|
||||
__profn("Copy queued releases");
|
||||
P_Lock lock = P_LockE(&G.fenced_releases_mutex);
|
||||
num_fenced_releases = G.fenced_releases_arena->pos / sizeof(struct fenced_release_data);
|
||||
fenced_releases = arena_push_array_no_zero(scratch.arena, struct fenced_release_data, num_fenced_releases);
|
||||
MEMCPY(fenced_releases, arena_base(G.fenced_releases_arena), G.fenced_releases_arena->pos);
|
||||
arena_reset(G.fenced_releases_arena);
|
||||
fenced_releases = PushArrayNoZero(scratch.arena, struct fenced_release_data, num_fenced_releases);
|
||||
MEMCPY(fenced_releases, ArenaBase(G.fenced_releases_arena), G.fenced_releases_arena->pos);
|
||||
ResetArena(G.fenced_releases_arena);
|
||||
MEMCPY(targets, G.fenced_release_targets, sizeof(targets));
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -3561,7 +3561,7 @@ INTERNAL P_JobDef(dx12_evictor_job, _)
|
||||
} break;
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
P_Lock lock = P_LockE(&G.evictor_wake_mutex);
|
||||
{
|
||||
|
||||
@ -77,7 +77,7 @@ GLOBAL READONLY enum token_type g_keyword_types[] = {
|
||||
|
||||
INTERNAL struct token *push_token(Arena *arena, struct token_list *list)
|
||||
{
|
||||
struct token *t = arena_push(arena, struct token);
|
||||
struct token *t = PushStruct(arena, struct token);
|
||||
if (!list->token_first) {
|
||||
list->token_first = t;
|
||||
} else {
|
||||
@ -356,7 +356,7 @@ INTERNAL struct token_list lex(Arena *arena, String src)
|
||||
|
||||
INTERNAL void append_char(Arena *arena, String *str, u8 c)
|
||||
{
|
||||
*arena_push_no_zero(arena, u8) = c;
|
||||
*PushStructNoZero(arena, u8) = c;
|
||||
++str->len;
|
||||
}
|
||||
|
||||
@ -526,7 +526,7 @@ INTERNAL String interpret_string(Arena *arena, String src, String *error)
|
||||
{
|
||||
String res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u8)
|
||||
.text = PushDry(arena, u8)
|
||||
};
|
||||
|
||||
if (src.len < 2) {
|
||||
@ -644,7 +644,7 @@ struct parser {
|
||||
|
||||
INTERNAL void push_error(Arena *arena, struct parser *p, struct token *t, String msg)
|
||||
{
|
||||
JSON_Error *error = arena_push(arena, JSON_Error);
|
||||
JSON_Error *error = PushStruct(arena, JSON_Error);
|
||||
error->msg = msg;
|
||||
error->start = t->start;
|
||||
error->end = t->end;
|
||||
@ -661,9 +661,9 @@ INTERNAL void push_error(Arena *arena, struct parser *p, struct token *t, String
|
||||
|
||||
INTERNAL void parse(Arena *arena, struct parser *p)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
JSON_Blob *root = arena_push(arena, JSON_Blob);
|
||||
JSON_Blob *root = PushStruct(arena, JSON_Blob);
|
||||
struct token *at = p->at;
|
||||
String src = p->src;
|
||||
|
||||
@ -672,12 +672,12 @@ INTERNAL void parse(Arena *arena, struct parser *p)
|
||||
}
|
||||
|
||||
/* Depth first stack */
|
||||
*arena_push_no_zero(scratch.arena, JSON_Blob *) = root;
|
||||
*PushStructNoZero(scratch.arena, JSON_Blob *) = root;
|
||||
u64 stack_count = 1;
|
||||
|
||||
while (stack_count > 0) {
|
||||
JSON_Blob *json = 0;
|
||||
arena_pop(scratch.arena, JSON_Blob *, &json);
|
||||
PopStruct(scratch.arena, JSON_Blob *, &json);
|
||||
--stack_count;
|
||||
|
||||
JSON_Blob *parent_json = json->parent;
|
||||
@ -791,22 +791,22 @@ INTERNAL void parse(Arena *arena, struct parser *p)
|
||||
}
|
||||
|
||||
if (is_new_parent) {
|
||||
/* Push self back to stack to re-check for closing brace later */
|
||||
*arena_push_no_zero(scratch.arena, JSON_Blob *) = json;
|
||||
/* PushStruct self back to stack to re-check for closing brace later */
|
||||
*PushStructNoZero(scratch.arena, JSON_Blob *) = json;
|
||||
++stack_count;
|
||||
|
||||
/* Create child & push to stack */
|
||||
JSON_Blob *child = arena_push(arena, JSON_Blob);
|
||||
JSON_Blob *child = PushStruct(arena, JSON_Blob);
|
||||
child->parent = json;
|
||||
*arena_push_no_zero(scratch.arena, JSON_Blob *) = child;
|
||||
*PushStructNoZero(scratch.arena, JSON_Blob *) = child;
|
||||
++stack_count;
|
||||
} else if (parent_json) {
|
||||
/* Check for comma */
|
||||
if (at->type == TOKEN_TYPE_COMMA) {
|
||||
/* Create sibling & push to stack */
|
||||
JSON_Blob *sibling = arena_push(arena, JSON_Blob);
|
||||
JSON_Blob *sibling = PushStruct(arena, JSON_Blob);
|
||||
sibling->parent = parent_json;
|
||||
*arena_push_no_zero(scratch.arena, JSON_Blob *) = sibling;
|
||||
*PushStructNoZero(scratch.arena, JSON_Blob *) = sibling;
|
||||
++stack_count;
|
||||
at = at->next;
|
||||
}
|
||||
@ -818,7 +818,7 @@ INTERNAL void parse(Arena *arena, struct parser *p)
|
||||
p->at = at;
|
||||
p->root = root;
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -827,7 +827,7 @@ INTERNAL void parse(Arena *arena, struct parser *p)
|
||||
|
||||
JSON_Result json_from_string(Arena *arena, String src)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
struct token_list tl = lex(scratch.arena, src);
|
||||
|
||||
@ -843,7 +843,7 @@ JSON_Result json_from_string(Arena *arena, String src)
|
||||
push_error(arena, &p, p.at, LIT("Expected end of file."));
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return (JSON_Result) {
|
||||
.root = p.root,
|
||||
|
||||
@ -66,7 +66,7 @@ GLOBAL struct {
|
||||
M_StartupReceipt mixer_startup(void)
|
||||
{
|
||||
__prof;
|
||||
G.track_arena = arena_alloc(GIBI(64));
|
||||
G.track_arena = AllocArena(GIBI(64));
|
||||
G.listener_pos = V2FromXY(0, 0);
|
||||
G.listener_dir = V2FromXY(0, -1);
|
||||
return (M_StartupReceipt) { 0 };
|
||||
@ -111,7 +111,7 @@ INTERNAL struct track *track_alloc_locked(P_Lock *lock, SND_Sound *sound)
|
||||
*track = (struct track) { .gen = track->gen + 1 };
|
||||
} else {
|
||||
/* Allocate new */
|
||||
track = arena_push(G.track_arena, struct track);
|
||||
track = PushStruct(G.track_arena, struct track);
|
||||
track->gen = 1;
|
||||
}
|
||||
|
||||
@ -261,11 +261,11 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
{
|
||||
__prof;
|
||||
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
M_PcmF32 res = ZI;
|
||||
res.count = frame_count * 2;
|
||||
res.samples = arena_push_array(arena, f32, res.count);
|
||||
res.samples = PushArray(arena, f32, res.count);
|
||||
|
||||
V2 listener_pos = V2FromXY(0, 0);
|
||||
V2 listener_dir = V2FromXY(0, 0);
|
||||
@ -281,7 +281,7 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
listener_dir = G.listener_dir;
|
||||
|
||||
/* Update & read mixes */
|
||||
mixes = arena_push_array_no_zero(scratch.arena, struct mix *, G.track_playing_count);
|
||||
mixes = PushArrayNoZero(scratch.arena, struct mix *, G.track_playing_count);
|
||||
for (struct track *track = G.track_first_playing; track; track = track->next) {
|
||||
__profn("Prepare track");
|
||||
struct mix *mix = &track->mix;
|
||||
@ -337,7 +337,7 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
|
||||
M_PcmF32 mix_pcm = {
|
||||
.count = res.count,
|
||||
.samples = arena_push_array(scratch.arena, f32, res.count)
|
||||
.samples = PushArray(scratch.arena, f32, res.count)
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
@ -476,6 +476,6 @@ M_PcmF32 mixer_update(Arena *arena, u64 frame_count)
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
* Read
|
||||
* ========================== */
|
||||
|
||||
res.pcm.samples = arena_push_dry(arena, i16);
|
||||
res.pcm.samples = PushDry(arena, i16);
|
||||
u64 sample_bytes_read = 0;
|
||||
for (;;) {
|
||||
IMFSample *sample;
|
||||
@ -109,7 +109,7 @@ MP3_Result mp3_decode(Arena *arena, String encoded, u32 sample_rate, u32 flags)
|
||||
DWORD size_bytes;
|
||||
IMFMediaBuffer_Lock(buffer, &src, 0, &size_bytes);
|
||||
{
|
||||
i16 *dst = arena_push_array_no_zero(arena, i16, (size_bytes + 1) >> 1);
|
||||
i16 *dst = PushArrayNoZero(arena, i16, (size_bytes + 1) >> 1);
|
||||
MEMCPY(dst, src, size_bytes);
|
||||
sample_bytes_read += size_bytes;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "../platform/platform.h"
|
||||
#include "../bitbuff/bitbuff.h"
|
||||
|
||||
#include "net_core.h"
|
||||
|
||||
|
||||
@ -139,25 +139,25 @@ N_StartupReceipt host_startup(void)
|
||||
|
||||
N_Host *host_alloc(u16 listen_port)
|
||||
{
|
||||
Arena *arena = arena_alloc(GIBI(64));
|
||||
N_Host *host = arena_push(arena, N_Host);
|
||||
Arena *arena = AllocArena(GIBI(64));
|
||||
N_Host *host = PushStruct(arena, N_Host);
|
||||
|
||||
host->arena = arena;
|
||||
host->cmd_arena = arena_alloc(GIBI(64));
|
||||
host->channel_arena = arena_alloc(GIBI(64));
|
||||
host->rcv_buffer_read = arena_push(host->arena, N_RcvBuffer);
|
||||
host->rcv_buffer_write = arena_push(host->arena, N_RcvBuffer);
|
||||
host->rcv_buffer_read->arena = arena_alloc(GIBI(64));
|
||||
host->rcv_buffer_write->arena = arena_alloc(GIBI(64));
|
||||
host->cmd_arena = AllocArena(GIBI(64));
|
||||
host->channel_arena = AllocArena(GIBI(64));
|
||||
host->rcv_buffer_read = PushStruct(host->arena, N_RcvBuffer);
|
||||
host->rcv_buffer_write = PushStruct(host->arena, N_RcvBuffer);
|
||||
host->rcv_buffer_read->arena = AllocArena(GIBI(64));
|
||||
host->rcv_buffer_write->arena = AllocArena(GIBI(64));
|
||||
host->buddy = buddy_ctx_alloc(GIBI(64));
|
||||
|
||||
host->channels = arena_push_dry(host->channel_arena, struct host_channel);
|
||||
host->channels = PushDry(host->channel_arena, struct host_channel);
|
||||
|
||||
host->num_channel_lookup_bins = N_NumChannelLookupBins;
|
||||
host->channel_lookup_bins = arena_push_array(host->arena, N_ChannelLookupBin, host->num_channel_lookup_bins);
|
||||
host->channel_lookup_bins = PushArray(host->arena, N_ChannelLookupBin, host->num_channel_lookup_bins);
|
||||
|
||||
host->num_msg_assembler_lookup_bins = N_NumMsgAssemblerLookupBins;
|
||||
host->msg_assembler_lookup_bins = arena_push_array(host->arena, struct host_msg_assembler_lookup_bin, host->num_msg_assembler_lookup_bins);
|
||||
host->msg_assembler_lookup_bins = PushArray(host->arena, struct host_msg_assembler_lookup_bin, host->num_msg_assembler_lookup_bins);
|
||||
|
||||
host->sock = P_AllocSock(listen_port, MEBI(2), MEBI(2));
|
||||
|
||||
@ -169,11 +169,11 @@ void host_release(N_Host *host)
|
||||
P_ReleaseSock(host->sock);
|
||||
|
||||
buddy_ctx_release(host->buddy);
|
||||
arena_release(host->rcv_buffer_write->arena);
|
||||
arena_release(host->rcv_buffer_read->arena);
|
||||
arena_release(host->channel_arena);
|
||||
arena_release(host->cmd_arena);
|
||||
arena_release(host->arena);
|
||||
ReleaseArena(host->rcv_buffer_write->arena);
|
||||
ReleaseArena(host->rcv_buffer_read->arena);
|
||||
ReleaseArena(host->channel_arena);
|
||||
ReleaseArena(host->cmd_arena);
|
||||
ReleaseArena(host->arena);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -216,7 +216,7 @@ INTERNAL struct host_channel_list host_channels_from_id(Arena *arena, N_Host *ho
|
||||
for (u64 i = 0; i < host->num_channels_reserved; ++i) {
|
||||
struct host_channel *channel = &host->channels[i];
|
||||
if (channel->valid) {
|
||||
struct host_channel_node *n = arena_push(arena, struct host_channel_node);
|
||||
struct host_channel_node *n = PushStruct(arena, struct host_channel_node);
|
||||
n->channel = channel;
|
||||
if (res.last) {
|
||||
res.last->next = n;
|
||||
@ -229,7 +229,7 @@ INTERNAL struct host_channel_list host_channels_from_id(Arena *arena, N_Host *ho
|
||||
} else {
|
||||
struct host_channel *channel = host_single_channel_from_id(host, channel_id);
|
||||
if (channel->valid) {
|
||||
struct host_channel_node *n = arena_push(arena, struct host_channel_node);
|
||||
struct host_channel_node *n = PushStruct(arena, struct host_channel_node);
|
||||
n->channel = channel;
|
||||
res.first = n;
|
||||
res.last = n;
|
||||
@ -248,7 +248,7 @@ INTERNAL struct host_channel *host_channel_alloc(N_Host *host, P_Address address
|
||||
id = channel->id;
|
||||
++id.gen;
|
||||
} else {
|
||||
channel = arena_push_no_zero(host->channel_arena, struct host_channel);
|
||||
channel = PushStructNoZero(host->channel_arena, struct host_channel);
|
||||
id.gen = 1;
|
||||
id.idx = host->num_channels_reserved;
|
||||
++host->num_channels_reserved;
|
||||
@ -350,7 +350,7 @@ INTERNAL struct host_msg_assembler *host_msg_assembler_alloc(struct host_channel
|
||||
ma = host->first_free_msg_assembler;
|
||||
host->first_free_msg_assembler = ma->next_free;
|
||||
} else {
|
||||
ma = arena_push_no_zero(host->arena, struct host_msg_assembler);
|
||||
ma = PushStructNoZero(host->arena, struct host_msg_assembler);
|
||||
}
|
||||
MEMZERO_STRUCT(ma);
|
||||
ma->channel = channel;
|
||||
@ -505,7 +505,7 @@ INTERNAL N_SndPacket *host_channel_snd_packet_alloc(struct host_channel *channel
|
||||
packet = host->first_free_packet;
|
||||
host->first_free_packet = packet->next;
|
||||
} else {
|
||||
packet = arena_push_no_zero(host->arena, N_SndPacket);
|
||||
packet = PushStructNoZero(host->arena, N_SndPacket);
|
||||
}
|
||||
MEMZERO_STRUCT(packet);
|
||||
|
||||
@ -536,7 +536,7 @@ INTERNAL N_SndPacket *host_channel_snd_packet_alloc(struct host_channel *channel
|
||||
|
||||
INTERNAL N_Cmd *host_cmd_alloc_and_append(N_Host *host)
|
||||
{
|
||||
N_Cmd *cmd = arena_push(host->cmd_arena, N_Cmd);
|
||||
N_Cmd *cmd = PushStruct(host->cmd_arena, N_Cmd);
|
||||
if (host->last_cmd) {
|
||||
host->last_cmd->next = cmd;
|
||||
} else {
|
||||
@ -586,7 +586,7 @@ i64 host_get_channel_last_rtt_ns(N_Host *host, N_ChannelId channel_id)
|
||||
|
||||
INTERNAL N_Event *push_event(Arena *arena, N_EventList *list)
|
||||
{
|
||||
N_Event *event = arena_push(arena, N_Event);
|
||||
N_Event *event = PushStruct(arena, N_Event);
|
||||
if (list->last) {
|
||||
list->last->next = event;
|
||||
} else {
|
||||
@ -599,7 +599,7 @@ INTERNAL N_Event *push_event(Arena *arena, N_EventList *list)
|
||||
/* Read incoming packets, update channels, and return events */
|
||||
N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
N_EventList events = ZI;
|
||||
i64 now_ns = P_TimeNs();
|
||||
@ -617,7 +617,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
P_Address address = res.address;
|
||||
String data = res.data;
|
||||
if (data.len > 0) {
|
||||
struct host_rcv_packet *packet = arena_push(scratch.arena, struct host_rcv_packet);
|
||||
struct host_rcv_packet *packet = PushStruct(scratch.arena, struct host_rcv_packet);
|
||||
packet->address = address;
|
||||
packet->data = string_copy(scratch.arena, data);
|
||||
if (last_packet) {
|
||||
@ -636,16 +636,16 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
for (struct host_rcv_packet *packet = first_packet; packet; packet = packet->next) {
|
||||
//struct sock *sock = packet->sock;
|
||||
P_Address address = packet->address;
|
||||
Bitbuff bb = bitbuff_from_string(packet->data);
|
||||
BitbuffReader br = br_from_bitbuff(&bb);
|
||||
u32 magic = br_read_ubits(&br, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_Buff bb = BitbuffFromString(packet->data);
|
||||
BB_Reader br = BB_ReaderFromBuff(&bb);
|
||||
u32 magic = BB_ReadUBits(&br, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
if (magic == N_PacketMagic) {
|
||||
/* TODO: Combine kind byte with flags byte */
|
||||
struct host_channel *channel = host_channel_from_address(host, address);
|
||||
enum host_packet_kind host_packet_kind = br_read_ibits(&br, 8);
|
||||
u8 packet_flags = br_read_ubits(&br, 8);
|
||||
enum host_packet_kind host_packet_kind = BB_ReadIBits(&br, 8);
|
||||
u8 packet_flags = BB_ReadUBits(&br, 8);
|
||||
|
||||
u64 their_acked_seq = br_read_uv(&br);
|
||||
u64 their_acked_seq = BB_ReadUV(&br);
|
||||
if (channel->valid) {
|
||||
channel->last_packet_received_ns = now_ns;
|
||||
if (their_acked_seq > channel->their_acked_seq) {
|
||||
@ -657,7 +657,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
b32 is_reliable = packet_flags & HOST_PACKET_FLAG_RELIABLE;
|
||||
if (channel->valid) {
|
||||
if (is_reliable) {
|
||||
u64 packet_seq = br_read_uv(&br);
|
||||
u64 packet_seq = BB_ReadUV(&br);
|
||||
if (packet_seq == channel->our_acked_seq + 1) {
|
||||
channel->our_acked_seq = packet_seq;
|
||||
} else {
|
||||
@ -709,8 +709,8 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
case HOST_PACKET_KIND_HEARTBEAT:
|
||||
{
|
||||
if (channel->valid) {
|
||||
u16 heartbeat_id = br_read_ubits(&br, 16);
|
||||
u16 acked_heartbeat_id = br_read_ubits(&br, 16);
|
||||
u16 heartbeat_id = BB_ReadUBits(&br, 16);
|
||||
u16 acked_heartbeat_id = BB_ReadUBits(&br, 16);
|
||||
if (heartbeat_id > channel->last_heartbeat_received_id) {
|
||||
channel->last_heartbeat_received_id = heartbeat_id;
|
||||
}
|
||||
@ -728,11 +728,11 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
{
|
||||
if (channel->valid && channel->connected) {
|
||||
/* Packet is chunk <chunk_id> out of <chunk_count> belonging to message <msg_id> */
|
||||
u64 msg_id = br_read_uv(&br);
|
||||
u64 chunk_id = br_read_uv(&br);
|
||||
u64 chunk_count = br_read_uv(&br);
|
||||
u64 msg_id = BB_ReadUV(&br);
|
||||
u64 chunk_id = BB_ReadUV(&br);
|
||||
u64 chunk_count = BB_ReadUV(&br);
|
||||
b32 is_last_chunk = (chunk_id + 1) == chunk_count;
|
||||
u64 chunk_len = is_last_chunk ? br_read_uv(&br) : N_MaxPacketChunkLen;
|
||||
u64 chunk_len = is_last_chunk ? BB_ReadUV(&br) : N_MaxPacketChunkLen;
|
||||
|
||||
struct host_msg_assembler *ma = host_get_msg_assembler(host, channel->id, msg_id);
|
||||
if (!ma) {
|
||||
@ -741,7 +741,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
|
||||
if (chunk_count == ma->num_chunks_total && chunk_id < chunk_count) {
|
||||
if (!host_msg_assembler_is_chunk_filled(ma, chunk_id)) {
|
||||
u8 *src = br_read_bytes_raw(&br, chunk_len);
|
||||
u8 *src = BB_ReadBytesRaw(&br, chunk_len);
|
||||
if (src) {
|
||||
u8 *dst = &ma->chunk_data[chunk_id * N_MaxPacketChunkLen];
|
||||
MEMCPY(dst, src, chunk_len);
|
||||
@ -757,7 +757,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
N_Event *event = push_event(arena, &events);
|
||||
String data = ZI;
|
||||
data.len = ((chunk_count - 1) * N_MaxPacketChunkLen) + ma->last_chunk_len;
|
||||
data.text = arena_push_array_no_zero(arena, u8, data.len);
|
||||
data.text = PushArrayNoZero(arena, u8, data.len);
|
||||
MEMCPY(data.text, ma->chunk_data, data.len);
|
||||
event->kind = HOST_EVENT_KIND_MSG;
|
||||
event->msg = data;
|
||||
@ -851,7 +851,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return events;
|
||||
}
|
||||
|
||||
@ -859,7 +859,7 @@ N_EventList host_update_begin(Arena *arena, N_Host *host)
|
||||
void host_update_end(N_Host *host)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* Process cmds into sendable packets */
|
||||
/* TODO: Unreliable packets don't need to be allocated into unreliable packet queue, should just send them and forget */
|
||||
@ -876,54 +876,54 @@ void host_update_end(N_Host *host)
|
||||
{
|
||||
u8 packet_flags = 0;
|
||||
N_SndPacket *packet = host_channel_snd_packet_alloc(channel, 0);
|
||||
Bitbuff bb = bitbuff_from_string(STRING_FROM_ARRAY(packet->data));
|
||||
BitbuffWriter bw = bw_from_bitbuff(&bb);
|
||||
bw_write_ubits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
bw_write_ibits(&bw, HOST_PACKET_KIND_TRY_CONNECT, 8);
|
||||
bw_write_ubits(&bw, packet_flags, 8);
|
||||
bw_write_uv(&bw, channel->our_acked_seq);
|
||||
packet->data_len = bw_num_bytes_written(&bw);
|
||||
BB_Buff bb = BitbuffFromString(STRING_FROM_ARRAY(packet->data));
|
||||
BB_Writer bw = BB_WriterFromBuff(&bb);
|
||||
BB_WriteUBits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_WriteIBits(&bw, HOST_PACKET_KIND_TRY_CONNECT, 8);
|
||||
BB_WriteUBits(&bw, packet_flags, 8);
|
||||
BB_WriteUV(&bw, channel->our_acked_seq);
|
||||
packet->data_len = BB_GetNumBytesWritten(&bw);
|
||||
} break;
|
||||
|
||||
case HOST_CMD_KIND_CONNECT_SUCCESS:
|
||||
{
|
||||
u8 packet_flags = 0;
|
||||
N_SndPacket *packet = host_channel_snd_packet_alloc(channel, 0);
|
||||
Bitbuff bb = bitbuff_from_string(STRING_FROM_ARRAY(packet->data));
|
||||
BitbuffWriter bw = bw_from_bitbuff(&bb);
|
||||
bw_write_ubits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
bw_write_ibits(&bw, HOST_PACKET_KIND_CONNECT_SUCCESS, 8);
|
||||
bw_write_ubits(&bw, packet_flags, 8);
|
||||
bw_write_uv(&bw, channel->our_acked_seq);
|
||||
packet->data_len = bw_num_bytes_written(&bw);
|
||||
BB_Buff bb = BitbuffFromString(STRING_FROM_ARRAY(packet->data));
|
||||
BB_Writer bw = BB_WriterFromBuff(&bb);
|
||||
BB_WriteUBits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_WriteIBits(&bw, HOST_PACKET_KIND_CONNECT_SUCCESS, 8);
|
||||
BB_WriteUBits(&bw, packet_flags, 8);
|
||||
BB_WriteUV(&bw, channel->our_acked_seq);
|
||||
packet->data_len = BB_GetNumBytesWritten(&bw);
|
||||
} break;
|
||||
|
||||
case HOST_CMD_KIND_DISCONNECT:
|
||||
{
|
||||
u8 packet_flags = 0;
|
||||
N_SndPacket *packet = host_channel_snd_packet_alloc(channel, 0);
|
||||
Bitbuff bb = bitbuff_from_string(STRING_FROM_ARRAY(packet->data));
|
||||
BitbuffWriter bw = bw_from_bitbuff(&bb);
|
||||
bw_write_ubits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
bw_write_ibits(&bw, HOST_PACKET_KIND_DISCONNECT, 8);
|
||||
bw_write_ubits(&bw, packet_flags, 8);
|
||||
bw_write_uv(&bw, channel->our_acked_seq);
|
||||
packet->data_len = bw_num_bytes_written(&bw);
|
||||
BB_Buff bb = BitbuffFromString(STRING_FROM_ARRAY(packet->data));
|
||||
BB_Writer bw = BB_WriterFromBuff(&bb);
|
||||
BB_WriteUBits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_WriteIBits(&bw, HOST_PACKET_KIND_DISCONNECT, 8);
|
||||
BB_WriteUBits(&bw, packet_flags, 8);
|
||||
BB_WriteUV(&bw, channel->our_acked_seq);
|
||||
packet->data_len = BB_GetNumBytesWritten(&bw);
|
||||
} break;
|
||||
|
||||
case HOST_CMD_KIND_HEARTBEAT:
|
||||
{
|
||||
u8 packet_flags = 0;
|
||||
N_SndPacket *packet = host_channel_snd_packet_alloc(channel, 0);
|
||||
Bitbuff bb = bitbuff_from_string(STRING_FROM_ARRAY(packet->data));
|
||||
BitbuffWriter bw = bw_from_bitbuff(&bb);
|
||||
bw_write_ubits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
bw_write_ibits(&bw, HOST_PACKET_KIND_HEARTBEAT, 8);
|
||||
bw_write_ubits(&bw, packet_flags, 8);
|
||||
bw_write_uv(&bw, channel->our_acked_seq);
|
||||
bw_write_ubits(&bw, cmd->heartbeat_id, 16);
|
||||
bw_write_ubits(&bw, cmd->heartbeat_ack_id, 16);
|
||||
packet->data_len = bw_num_bytes_written(&bw);
|
||||
BB_Buff bb = BitbuffFromString(STRING_FROM_ARRAY(packet->data));
|
||||
BB_Writer bw = BB_WriterFromBuff(&bb);
|
||||
BB_WriteUBits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_WriteIBits(&bw, HOST_PACKET_KIND_HEARTBEAT, 8);
|
||||
BB_WriteUBits(&bw, packet_flags, 8);
|
||||
BB_WriteUV(&bw, channel->our_acked_seq);
|
||||
BB_WriteUBits(&bw, cmd->heartbeat_id, 16);
|
||||
BB_WriteUBits(&bw, cmd->heartbeat_ack_id, 16);
|
||||
packet->data_len = BB_GetNumBytesWritten(&bw);
|
||||
} break;
|
||||
|
||||
case HOST_CMD_KIND_WRITE:
|
||||
@ -949,24 +949,24 @@ void host_update_end(N_Host *host)
|
||||
}
|
||||
}
|
||||
N_SndPacket *packet = host_channel_snd_packet_alloc(channel, is_reliable);
|
||||
Bitbuff bb = bitbuff_from_string(STRING_FROM_ARRAY(packet->data));
|
||||
BitbuffWriter bw = bw_from_bitbuff(&bb);
|
||||
bw_write_ubits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
bw_write_ibits(&bw, HOST_PACKET_KIND_MSG_CHUNK, 8);
|
||||
bw_write_ubits(&bw, packet_flags, 8);
|
||||
bw_write_uv(&bw, channel->our_acked_seq);
|
||||
BB_Buff bb = BitbuffFromString(STRING_FROM_ARRAY(packet->data));
|
||||
BB_Writer bw = BB_WriterFromBuff(&bb);
|
||||
BB_WriteUBits(&bw, N_PacketMagic, 32); /* TODO: implicitly encode magic into crc32 */
|
||||
BB_WriteIBits(&bw, HOST_PACKET_KIND_MSG_CHUNK, 8);
|
||||
BB_WriteUBits(&bw, packet_flags, 8);
|
||||
BB_WriteUV(&bw, channel->our_acked_seq);
|
||||
if (is_reliable) {
|
||||
bw_write_uv(&bw, packet->seq);
|
||||
BB_WriteUV(&bw, packet->seq);
|
||||
}
|
||||
bw_write_uv(&bw, msg_id);
|
||||
bw_write_uv(&bw, i);
|
||||
bw_write_uv(&bw, chunk_count);
|
||||
BB_WriteUV(&bw, msg_id);
|
||||
BB_WriteUV(&bw, i);
|
||||
BB_WriteUV(&bw, chunk_count);
|
||||
if (is_last_chunk) {
|
||||
bw_write_uv(&bw, chunk_len);
|
||||
BB_WriteUV(&bw, chunk_len);
|
||||
}
|
||||
u8 *chunk_data = msg.text + (i * N_MaxPacketChunkLen);
|
||||
bw_write_bytes(&bw, STRING(chunk_len, chunk_data));
|
||||
packet->data_len = bw_num_bytes_written(&bw);
|
||||
BB_WriteBytes(&bw, STRING(chunk_len, chunk_data));
|
||||
packet->data_len = BB_GetNumBytesWritten(&bw);
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -1013,7 +1013,7 @@ void host_update_end(N_Host *host)
|
||||
/* Reset cmds */
|
||||
host->first_cmd = 0;
|
||||
host->last_cmd = 0;
|
||||
arena_reset(host->cmd_arena);
|
||||
ResetArena(host->cmd_arena);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ void P_LogStartup(String logfile_path)
|
||||
{
|
||||
__prof;
|
||||
P_SharedLogCtx *ctx = &P_shared_log_ctx;
|
||||
ctx->callbacks_arena = arena_alloc(MEBI(8));
|
||||
ctx->callbacks_arena = AllocArena(MEBI(8));
|
||||
if (logfile_path.len > 0)
|
||||
{
|
||||
/* Create / wipe log file */
|
||||
@ -66,7 +66,7 @@ void P_RegisterLogCallback(P_LogEventCallbackFunc *func, i32 level)
|
||||
if (!atomic32_fetch(&ctx->initialized)) { return; }
|
||||
P_Lock lock = P_LockE(&ctx->callbacks_mutex);
|
||||
{
|
||||
LogEventCallback *callback = arena_push(ctx->callbacks_arena, LogEventCallback);
|
||||
LogEventCallback *callback = PushStruct(ctx->callbacks_arena, LogEventCallback);
|
||||
callback->func = func;
|
||||
callback->level = level;
|
||||
if (ctx->last_callback)
|
||||
@ -93,10 +93,10 @@ void P__LogAppend(String msg)
|
||||
|
||||
if (ctx->file_valid)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String msg_line = string_cat(scratch.arena, msg, LIT("\n"));
|
||||
P_WriteFile(ctx->file, msg_line);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,14 +129,14 @@ void P__LogFV(i32 level, String fmt, va_list args)
|
||||
{
|
||||
P_SharedLogCtx *ctx = &P_shared_log_ctx;
|
||||
if (!atomic32_fetch(&ctx->initialized)) { return; }
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String msg = string_formatv(scratch.arena, fmt, args);
|
||||
#if P_IncludeLogSourceLocation
|
||||
P__log(level, file, line, msg);
|
||||
#else
|
||||
P__log(level, msg);
|
||||
#endif
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@ -172,7 +172,7 @@ void P__log(i32 level, String msg)
|
||||
__prof;
|
||||
P_SharedLogCtx *ctx = &P_shared_log_ctx;
|
||||
if (!atomic32_fetch(&ctx->initialized)) { return; }
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
P_LogLevelSettings settings = P_log_settings[level];
|
||||
if (level < 0 || level >= P_LogLevel_Count)
|
||||
@ -261,5 +261,5 @@ void P__log(i32 level, String msg)
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ DWORD WINAPI P_W32_Win32ThreadProc(LPVOID vt)
|
||||
P_W32_Thread *P_W32_AllocThread(P_W32_ThreadFunc *entry_point, void *thread_data, String thread_name, i32 profiler_group)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
||||
ASSERT(entry_point != 0);
|
||||
P_LogInfoF("Creating thread \"%F\"", FMT_STR(thread_name));
|
||||
@ -81,7 +81,7 @@ P_W32_Thread *P_W32_AllocThread(P_W32_ThreadFunc *entry_point, void *thread_data
|
||||
}
|
||||
else
|
||||
{
|
||||
t = arena_push_no_zero(g->threads_arena, P_W32_Thread);
|
||||
t = PushStructNoZero(g->threads_arena, P_W32_Thread);
|
||||
}
|
||||
MEMZERO_STRUCT(t);
|
||||
if (g->last_thread)
|
||||
@ -129,7 +129,7 @@ P_W32_Thread *P_W32_AllocThread(P_W32_ThreadFunc *entry_point, void *thread_data
|
||||
P_Panic(LIT("Failed to create thread"));
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return (P_W32_Thread *)t;
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ void P_W32_WakeLockedFibers(i32 num_fibers, P_W32_Fiber **fibers)
|
||||
}
|
||||
else
|
||||
{
|
||||
info = arena_push_no_zero(queue->arena, P_W32_JobInfo);
|
||||
info = PushStructNoZero(queue->arena, P_W32_JobInfo);
|
||||
}
|
||||
MEMZERO_STRUCT(info);
|
||||
info->count = 1;
|
||||
@ -422,7 +422,7 @@ void P_W32_WakeLockedFibers(i32 num_fibers, P_W32_Fiber **fibers)
|
||||
|
||||
void P_W32_WakeByAddress(void *addr, i32 count)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
||||
|
||||
u64 wait_addr_bin_index = (u64)addr % P_W32_NumWaitAddrBins;
|
||||
@ -447,7 +447,7 @@ void P_W32_WakeByAddress(void *addr, i32 count)
|
||||
/* Lock fibers & build array */
|
||||
if (wait_addr_list)
|
||||
{
|
||||
fibers = arena_push_array_no_zero(scratch.arena, P_W32_Fiber *, wait_addr_list->num_waiters);
|
||||
fibers = PushArrayNoZero(scratch.arena, P_W32_Fiber *, wait_addr_list->num_waiters);
|
||||
for (P_W32_Fiber *fiber = P_W32_FiberFromId(wait_addr_list->first_waiter); fiber && num_fibers < count; fiber = P_W32_FiberFromId(fiber->next_addr_waiter))
|
||||
{
|
||||
if (atomic32_fetch_test_set(&fiber->wake_lock, 0, 1) == 0)
|
||||
@ -479,12 +479,12 @@ void P_W32_WakeByAddress(void *addr, i32 count)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void P_W32_WakeByTime(u64 time)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
||||
|
||||
u64 wait_time_bin_index = (u64)time % P_W32_NumWaitTimeBins;
|
||||
@ -509,7 +509,7 @@ void P_W32_WakeByTime(u64 time)
|
||||
if (wait_time_list)
|
||||
{
|
||||
/* Set waiter wake status & build fibers list */
|
||||
fibers = arena_push_array_no_zero(scratch.arena, P_W32_Fiber *, wait_time_list->num_waiters);
|
||||
fibers = PushArrayNoZero(scratch.arena, P_W32_Fiber *, wait_time_list->num_waiters);
|
||||
for (P_W32_Fiber *fiber = P_W32_FiberFromId(wait_time_list->first_waiter); fiber; fiber = P_W32_FiberFromId(fiber->next_time_waiter))
|
||||
{
|
||||
if (atomic32_fetch_test_set(&fiber->wake_lock, 0, 1) == 0)
|
||||
@ -526,7 +526,7 @@ void P_W32_WakeByTime(u64 time)
|
||||
|
||||
P_W32_WakeLockedFibers(num_fibers, fibers);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@ -562,7 +562,7 @@ P_W32_Fiber *P_W32_AllocFiber(P_W32_JobPool *pool)
|
||||
P_Panic(LIT("Max fibers reached"));
|
||||
}
|
||||
fiber = &g->fibers[fiber_id];
|
||||
new_name_cstr = arena_push_array(g->fiber_names_arena, char, P_W32_FiberNameMaxSize);
|
||||
new_name_cstr = PushArray(g->fiber_names_arena, char, P_W32_FiberNameMaxSize);
|
||||
}
|
||||
}
|
||||
P_W32_UnlockTicketMutex(&g->fibers_lock);
|
||||
@ -890,9 +890,9 @@ P_W32_ThreadDef(P_W32_JobWorkerEntryFunc, worker_ctx_arg)
|
||||
default:
|
||||
{
|
||||
/* Invalid yield kind */
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_Panic(string_format(scratch.arena, LIT("Invalid fiber yield kind \"%F\""), FMT_SINT(yield.kind)));
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
} break;
|
||||
|
||||
case P_W32_YieldKind_Wait:
|
||||
@ -960,7 +960,7 @@ P_W32_ThreadDef(P_W32_JobWorkerEntryFunc, worker_ctx_arg)
|
||||
{
|
||||
P_W32_LockTicketMutex(&g->wait_lists_arena_lock);
|
||||
{
|
||||
wait_addr_list = arena_push_no_zero(g->wait_lists_arena, P_W32_WaitList);
|
||||
wait_addr_list = PushStructNoZero(g->wait_lists_arena, P_W32_WaitList);
|
||||
}
|
||||
P_W32_UnlockTicketMutex(&g->wait_lists_arena_lock);
|
||||
}
|
||||
@ -1014,7 +1014,7 @@ P_W32_ThreadDef(P_W32_JobWorkerEntryFunc, worker_ctx_arg)
|
||||
{
|
||||
P_W32_LockTicketMutex(&g->wait_lists_arena_lock);
|
||||
{
|
||||
wait_time_list = arena_push_no_zero(g->wait_lists_arena, P_W32_WaitList);
|
||||
wait_time_list = PushStructNoZero(g->wait_lists_arena, P_W32_WaitList);
|
||||
}
|
||||
P_W32_UnlockTicketMutex(&g->wait_lists_arena_lock);
|
||||
}
|
||||
@ -1046,7 +1046,7 @@ P_W32_ThreadDef(P_W32_JobWorkerEntryFunc, worker_ctx_arg)
|
||||
++wait_time_list->num_waiters;
|
||||
}
|
||||
|
||||
/* Pop worker's job fiber */
|
||||
/* PopStruct worker's job fiber */
|
||||
job_fiber = 0;
|
||||
done = 1;
|
||||
}
|
||||
@ -1197,7 +1197,7 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
|
||||
{
|
||||
String res = {
|
||||
.len = 0,
|
||||
.text = arena_push_dry(arena, u8)
|
||||
.text = PushDry(arena, u8)
|
||||
};
|
||||
|
||||
while (*src)
|
||||
@ -1205,7 +1205,7 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
|
||||
String16 decode_str = { .len = *(src + 1) ? 2 : 1, .text = src };
|
||||
Utf16DecodeResult decoded = uni_decode_utf16(decode_str);
|
||||
Utf8EncodeResult encoded = uni_encode_utf8(decoded.codepoint);
|
||||
u8 *dest = arena_push_array_no_zero(arena, u8, encoded.count8);
|
||||
u8 *dest = PushArrayNoZero(arena, u8, encoded.count8);
|
||||
for (u32 i = 0; i < encoded.count8; ++i)
|
||||
{
|
||||
u8 byte = encoded.chars8[i];
|
||||
@ -1238,14 +1238,14 @@ P_W32_Window *P_W32_AllocWindow(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
window = arena_push_no_zero(g->windows_arena, P_W32_Window);
|
||||
window = PushStructNoZero(g->windows_arena, P_W32_Window);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
MEMZERO_STRUCT(window);
|
||||
|
||||
window->event_arenas[0] = arena_alloc(GIBI(64));
|
||||
window->event_arenas[1] = arena_alloc(GIBI(64));
|
||||
window->event_arenas[0] = AllocArena(GIBI(64));
|
||||
window->event_arenas[1] = AllocArena(GIBI(64));
|
||||
|
||||
/* Start window event thread */
|
||||
/* NOTE: This thread must finish building for the window to actually be
|
||||
@ -1450,10 +1450,10 @@ void P_W32_UpdateWindowFromSettings(P_W32_Window *window, P_WindowSettings *sett
|
||||
SetWindowPlacement(hwnd, &wp);
|
||||
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *title_wstr = wstr_from_string(scratch.arena, string_from_cstr_no_limit(settings->title));
|
||||
SetWindowTextW(hwnd, title_wstr);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1495,7 +1495,7 @@ void P_W32_ProcessWindowEvent(P_W32_Window *window, P_WindowEvent event)
|
||||
__prof;
|
||||
P_Lock lock = P_LockE(&window->event_arena_swp_mutex);
|
||||
{
|
||||
*arena_push(window->event_arenas[window->current_event_arena_index], P_WindowEvent) = event;
|
||||
*PushStruct(window->event_arenas[window->current_event_arena_index], P_WindowEvent) = event;
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -1797,12 +1797,12 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
||||
/* Raw mouse move */
|
||||
case WM_INPUT:
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* Read raw input buffer */
|
||||
UINT buff_size;
|
||||
GetRawInputData((HRAWINPUT)lparam, RID_INPUT, 0, &buff_size, sizeof(RAWINPUTHEADER));
|
||||
u8 *buff = arena_push_array(scratch.arena, u8, buff_size);
|
||||
u8 *buff = PushArray(scratch.arena, u8, buff_size);
|
||||
if (GetRawInputData((HRAWINPUT)lparam, RID_INPUT, buff, &buff_size, sizeof(RAWINPUTHEADER)) != buff_size)
|
||||
{
|
||||
P_LogErrorF("GetRawInputData did not return correct size");
|
||||
@ -1826,7 +1826,7 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
||||
);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
} break;
|
||||
|
||||
/* Minmax info */
|
||||
@ -2012,7 +2012,7 @@ void P_Run(i32 count, P_JobFunc *func, void *sig, P_Pool pool_kind, P_Priority p
|
||||
}
|
||||
else
|
||||
{
|
||||
info = arena_push_no_zero(queue->arena, P_W32_JobInfo);
|
||||
info = PushStructNoZero(queue->arena, P_W32_JobInfo);
|
||||
}
|
||||
MEMZERO_STRUCT(info);
|
||||
info->count = count;
|
||||
@ -2097,26 +2097,26 @@ String P_GetWritePath(Arena *arena)
|
||||
b32 P_IsFile(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
DWORD attributes = GetFileAttributesW(path_wstr);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return attributes != INVALID_FILE_ATTRIBUTES && !(attributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
b32 P_IsDir(String path)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
DWORD attributes = GetFileAttributesW(path_wstr);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
void P_MkDir(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
int err_code = SHCreateDirectory(0, path_wstr);
|
||||
String err = ZI;
|
||||
@ -2152,13 +2152,13 @@ void P_MkDir(String path)
|
||||
FMT_STR(err));
|
||||
P_Panic(msg);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
P_File P_OpenFileRead(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_File file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -2174,14 +2174,14 @@ P_File P_OpenFileRead(String path)
|
||||
file.handle = (u64)handle;
|
||||
file.valid = handle != INVALID_HANDLE_VALUE;
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return file;
|
||||
}
|
||||
|
||||
P_File P_OpenFileReadWait(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_File file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -2206,14 +2206,14 @@ P_File P_OpenFileReadWait(String path)
|
||||
file.handle = (u64)handle;
|
||||
file.valid = handle != INVALID_HANDLE_VALUE;
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return file;
|
||||
}
|
||||
|
||||
P_File P_OpenFileWrite(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_File file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -2229,14 +2229,14 @@ P_File P_OpenFileWrite(String path)
|
||||
file.handle = (u64)handle;
|
||||
file.valid = handle != INVALID_HANDLE_VALUE;
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return file;
|
||||
}
|
||||
|
||||
P_File P_OpenFileAppend(String path)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_File file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -2252,7 +2252,7 @@ P_File P_OpenFileAppend(String path)
|
||||
file.handle = (u64)handle;
|
||||
file.valid = handle != INVALID_HANDLE_VALUE;
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return file;
|
||||
}
|
||||
|
||||
@ -2280,8 +2280,8 @@ String P_ReadFile(Arena *arena, P_File file)
|
||||
{
|
||||
/* ReadFile returns non-zero on success */
|
||||
/* TODO: error checking */
|
||||
arena_align(arena, 16);
|
||||
s.text = arena_push_array_no_zero(arena, u8, size);
|
||||
AlignArena(arena, 16);
|
||||
s.text = PushArrayNoZero(arena, u8, size);
|
||||
(UNUSED)ReadFile(
|
||||
(HANDLE)file.handle,
|
||||
s.text,
|
||||
@ -2301,11 +2301,11 @@ void P_WriteFile(P_File file, String data)
|
||||
* that (rather than failing) */
|
||||
if (data.len >= 0x7FFF)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
P_Panic(string_format(scratch.arena,
|
||||
LIT("Tried to write too many bytes to disk (%F)"),
|
||||
FMT_UINT(data.len)));
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* WriteFile returns TRUE on success */
|
||||
@ -2435,7 +2435,7 @@ String P_GetFileMapData(P_FileMap map)
|
||||
|
||||
P_Watch *P_AllocWatch(String dir_path)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
||||
|
||||
P_W32_Watch *w32_watch = 0;
|
||||
@ -2449,7 +2449,7 @@ P_Watch *P_AllocWatch(String dir_path)
|
||||
}
|
||||
else
|
||||
{
|
||||
w32_watch = arena_push_no_zero(g->watches_arena, P_W32_Watch);
|
||||
w32_watch = PushStructNoZero(g->watches_arena, P_W32_Watch);
|
||||
}
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
@ -2469,7 +2469,7 @@ P_Watch *P_AllocWatch(String dir_path)
|
||||
|
||||
w32_watch->wake_handle = CreateEventW(0, 0, 0, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return (P_Watch *)w32_watch;
|
||||
}
|
||||
|
||||
@ -2530,7 +2530,7 @@ P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw)
|
||||
{
|
||||
FILE_NOTIFY_INFORMATION *res = (FILE_NOTIFY_INFORMATION *)(w32_watch->results_buff + offset);
|
||||
|
||||
P_WatchInfo *info = arena_push(arena, P_WatchInfo);
|
||||
P_WatchInfo *info = PushStruct(arena, P_WatchInfo);
|
||||
if (list.last)
|
||||
{
|
||||
list.last->next = info;
|
||||
@ -2651,9 +2651,9 @@ P_WindowEventArray P_PopWindowEvents(Arena *arena, P_Window *p_window)
|
||||
Arena *events_arena = window->event_arenas[event_arena_index];
|
||||
P_WindowEventArray events = ZI;
|
||||
events.count = events_arena->pos / sizeof(P_WindowEvent);
|
||||
events.events = arena_push_array_no_zero(arena, P_WindowEvent, events.count);
|
||||
MEMCPY(events.events, arena_base(events_arena), events_arena->pos);
|
||||
arena_reset(events_arena);
|
||||
events.events = PushArrayNoZero(arena, P_WindowEvent, events.count);
|
||||
MEMCPY(events.events, ArenaBase(events_arena), events_arena->pos);
|
||||
ResetArena(events_arena);
|
||||
return events;
|
||||
}
|
||||
|
||||
@ -2981,7 +2981,7 @@ P_Sock *P_AllocSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size)
|
||||
}
|
||||
else
|
||||
{
|
||||
ws = arena_push_no_zero(g->socks_arena, P_W32_Sock);
|
||||
ws = PushStructNoZero(g->socks_arena, P_W32_Sock);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -3023,7 +3023,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
|
||||
u64 read_buff_size = KIBI(64);
|
||||
String read_buff = ZI;
|
||||
read_buff.len = read_buff_size;
|
||||
read_buff.text = arena_push_array_no_zero(arena, u8, read_buff_size);
|
||||
read_buff.text = PushArrayNoZero(arena, u8, read_buff_size);
|
||||
|
||||
P_SockReadResult res = ZI;
|
||||
|
||||
@ -3041,8 +3041,8 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
|
||||
res.data.len = size;
|
||||
res.valid = 1;
|
||||
|
||||
/* Pop arena back to end of msg */
|
||||
arena_pop_to(arena, arena->pos - read_buff_size + size);
|
||||
/* PopStruct arena back to end of msg */
|
||||
PopTo(arena, arena->pos - read_buff_size + size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3082,7 +3082,7 @@ void P_WriteSock(P_Sock *sock, P_Address address, String data)
|
||||
|
||||
void P_MessageBox(P_MessageBoxKind kind, String message)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
wchar_t *message_wstr = wstr_from_string(scratch.arena, message);
|
||||
const wchar_t *title = L"";
|
||||
@ -3117,14 +3117,14 @@ void P_MessageBox(P_MessageBoxKind kind, String message)
|
||||
P_LogDebugF("Showing message box kind %F with text \"%F\"", FMT_SINT(kind), FMT_STR(message));
|
||||
MessageBoxExW(0, message_wstr, title, mbox_type, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void P_SetClipboardText(String str)
|
||||
{
|
||||
if (OpenClipboard(0))
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String16 str16 = string16_from_string(scratch.arena, str);
|
||||
u64 str16_size_bytes = str16.len * 2;
|
||||
EmptyClipboard();
|
||||
@ -3138,7 +3138,7 @@ void P_SetClipboardText(String str)
|
||||
SetClipboardData(CF_UNICODETEXT, handle);
|
||||
}
|
||||
CloseClipboard();
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3351,13 +3351,13 @@ P_JobDef(P_W32_AppStartupJob, _)
|
||||
{
|
||||
(UNUSED)_;
|
||||
P_W32_SharedCtx *g = &P_W32_shared_ctx;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
{
|
||||
String cmdline_args = string_from_wstr(scratch.arena, g->cmdline_args_wstr, countof(g->cmdline_args_wstr));
|
||||
P_AppStartup(cmdline_args);
|
||||
SetEvent(g->startup_end_event);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
P_JobDef(P_W32_AppShutdownJob, _)
|
||||
@ -3478,10 +3478,10 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
|
||||
/* Init fibers */
|
||||
g->num_fibers = 1; /* Fiber at index 0 always nil */
|
||||
g->fiber_names_arena = arena_alloc(GIBI(64));
|
||||
g->fiber_names_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Init wait lists */
|
||||
g->wait_lists_arena = arena_alloc(GIBI(64));
|
||||
g->wait_lists_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Convert main thread to fiber */
|
||||
P_W32_AllocFiber(0);
|
||||
@ -3495,7 +3495,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
for (P_Priority priority = 0; priority < (i32)countof(pool->job_queues); ++priority)
|
||||
{
|
||||
P_W32_JobQueue *queue = &pool->job_queues[priority];
|
||||
queue->arena = arena_alloc(GIBI(64));
|
||||
queue->arena = AllocArena(GIBI(64));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3550,17 +3550,17 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
}
|
||||
|
||||
/* Init threads pool */
|
||||
g->threads_arena = arena_alloc(GIBI(64));
|
||||
g->threads_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Init watches pool */
|
||||
g->watches_arena = arena_alloc(GIBI(64));
|
||||
g->watches_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Init windows pool */
|
||||
g->windows_arena = arena_alloc(GIBI(64));
|
||||
g->windows_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Init winsock */
|
||||
WSAStartup(MAKEWORD(2, 2), &g->wsa_data);
|
||||
g->socks_arena = arena_alloc(GIBI(64));
|
||||
g->socks_arena = AllocArena(GIBI(64));
|
||||
|
||||
/* Start job scheduler */
|
||||
atomic64_fetch_set(&g->current_scheduler_cycle_period_ns.v, P_W32_DefaultSchedulerPeriodNs);
|
||||
@ -3618,9 +3618,9 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
pool->thread_affinity_mask = 0x0000000000000FFFull;
|
||||
} break;
|
||||
}
|
||||
pool->worker_threads_arena = arena_alloc(GIBI(64));
|
||||
pool->worker_threads = arena_push_array(pool->worker_threads_arena, P_W32_Thread *, pool->num_worker_threads);
|
||||
pool->worker_contexts = arena_push_array(pool->worker_threads_arena, P_W32_WorkerCtx, pool->num_worker_threads);
|
||||
pool->worker_threads_arena = AllocArena(GIBI(64));
|
||||
pool->worker_threads = PushArray(pool->worker_threads_arena, P_W32_Thread *, pool->num_worker_threads);
|
||||
pool->worker_contexts = PushArray(pool->worker_threads_arena, P_W32_WorkerCtx, pool->num_worker_threads);
|
||||
for (i32 i = 0; i < pool->num_worker_threads; ++i)
|
||||
{
|
||||
P_W32_WorkerCtx *ctx = &pool->worker_contexts[i];
|
||||
@ -3721,10 +3721,10 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
P_Lock lock = P_LockS(&g->threads_mutex);
|
||||
if (g->first_thread)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
u64 num_dangling_threads = 0;
|
||||
String threads_msg = ZI;
|
||||
threads_msg.text = arena_push_dry(scratch.arena, u8);
|
||||
threads_msg.text = PushDry(scratch.arena, u8);
|
||||
for (P_W32_Thread *t = g->first_thread; t; t = t->next)
|
||||
{
|
||||
String name = string_from_cstr(t->thread_name_cstr, countof(t->thread_name_cstr));
|
||||
@ -3733,7 +3733,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
}
|
||||
threads_msg = string_format(scratch.arena, LIT("%F dangling thread(s):\n%F"), FMT_UINT(num_dangling_threads), FMT_STR(threads_msg));
|
||||
P_Panic(threads_msg);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ INTERNAL P_JobDef(playback_job, _)
|
||||
* need to halt mixer to prevent memory leak when sounds are played. */
|
||||
/* TODO: Signal counter that running job wiats on, rather than scheduling job manually */
|
||||
while (!atomic32_fetch(&G.shutdown)) {
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
{
|
||||
__profn("Wasapi wait");
|
||||
WaitForSingleObject(G.event, INFINITE);
|
||||
@ -235,6 +235,6 @@ INTERNAL P_JobDef(playback_job, _)
|
||||
M_PcmF32 pcm = mixer_update(scratch.arena, wspbuf.frames_count);
|
||||
wasapi_update_end(&wspbuf, pcm);
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ GLOBAL struct {
|
||||
R_StartupReceipt resource_startup(void)
|
||||
{
|
||||
__prof;
|
||||
G.arena = arena_alloc(GIBI(64));
|
||||
G.arena = AllocArena(GIBI(64));
|
||||
|
||||
#if RESOURCES_EMBEDDED
|
||||
String embedded_data = inc_res_tar();
|
||||
|
||||
@ -40,12 +40,12 @@ String settings_serialize(Arena *arena, const P_WindowSettings *settings)
|
||||
P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_out)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
String error = ZI;
|
||||
JSON_Error json_error = ZI;
|
||||
|
||||
P_WindowSettings *settings = arena_push(arena, P_WindowSettings);
|
||||
P_WindowSettings *settings = PushStruct(arena, P_WindowSettings);
|
||||
JSON_Result parse_res = json_from_string(scratch.arena, src);
|
||||
|
||||
if (parse_res.errors.count > 0) {
|
||||
@ -144,7 +144,7 @@ P_WindowSettings *settings_deserialize(Arena *arena, String src, String *error_o
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "../collider/collider.h"
|
||||
#include "../net/net.h"
|
||||
#include "../mixer/mixer.h"
|
||||
#include "../bitbuff/bitbuff.h"
|
||||
|
||||
#include "sim_core.h"
|
||||
#include "sim_phys.h"
|
||||
|
||||
@ -55,24 +55,24 @@ READONLY Ent **_g_sim_ent_nil = &G.nil_ent;
|
||||
SimStartupReceipt sim_startup(void)
|
||||
{
|
||||
__prof;
|
||||
G.nil_arena = arena_alloc(GIBI(1));
|
||||
G.nil_arena = AllocArena(GIBI(1));
|
||||
|
||||
/* Nil client store */
|
||||
G.nil_client_store = arena_push(G.nil_arena, ClientStore);
|
||||
G.nil_client_store = PushStruct(G.nil_arena, ClientStore);
|
||||
G.nil_client_store->valid = 0;
|
||||
|
||||
/* Nil client */
|
||||
G.nil_client = arena_push(G.nil_arena, Client);
|
||||
G.nil_client = PushStruct(G.nil_arena, Client);
|
||||
G.nil_client->valid = 0;
|
||||
G.nil_client->store = sim_client_store_nil();
|
||||
|
||||
/* Nil snapshot */
|
||||
G.nil_snapshot = arena_push(G.nil_arena, Snapshot);
|
||||
G.nil_snapshot = PushStruct(G.nil_arena, Snapshot);
|
||||
G.nil_snapshot->valid = 0;
|
||||
G.nil_snapshot->client = sim_client_nil();
|
||||
|
||||
/* Nil ent */
|
||||
G.nil_ent = arena_push(G.nil_arena, Ent);
|
||||
G.nil_ent = PushStruct(G.nil_arena, Ent);
|
||||
G.nil_ent->ss = sim_snapshot_nil();
|
||||
G.nil_ent->valid = 0;
|
||||
G.nil_ent->id = SIM_ENT_NIL_ID;
|
||||
@ -86,7 +86,7 @@ SimStartupReceipt sim_startup(void)
|
||||
G.nil_ent->sprite_tint = COLOR_WHITE;
|
||||
|
||||
/* Lock nil arena */
|
||||
arena_set_readonly(G.nil_arena);
|
||||
SetArenaReadonly(G.nil_arena);
|
||||
return (SimStartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
@ -99,15 +99,15 @@ ClientStore *sim_client_store_alloc(void)
|
||||
__prof;
|
||||
ClientStore *store;
|
||||
{
|
||||
Arena *arena = arena_alloc(GIBI(64));
|
||||
store = arena_push(arena, ClientStore);
|
||||
Arena *arena = AllocArena(GIBI(64));
|
||||
store = PushStruct(arena, ClientStore);
|
||||
store->arena = arena;
|
||||
}
|
||||
store->valid = 1;
|
||||
store->num_client_lookup_bins = CLIENT_LOOKUP_BINS;
|
||||
store->client_lookup_bins = arena_push_array(store->arena, ClientLookupBin, store->num_client_lookup_bins);
|
||||
store->clients_arena = arena_alloc(GIBI(64));
|
||||
store->clients = arena_push_dry(store->clients_arena, Client);
|
||||
store->client_lookup_bins = PushArray(store->arena, ClientLookupBin, store->num_client_lookup_bins);
|
||||
store->clients_arena = AllocArena(GIBI(64));
|
||||
store->clients = PushDry(store->clients_arena, Client);
|
||||
return store;
|
||||
}
|
||||
|
||||
@ -120,8 +120,8 @@ void sim_client_store_release(ClientStore *store)
|
||||
sim_client_release(client);
|
||||
}
|
||||
}
|
||||
arena_release(store->clients_arena);
|
||||
arena_release(store->arena);
|
||||
ReleaseArena(store->clients_arena);
|
||||
ReleaseArena(store->arena);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -138,7 +138,7 @@ Client *sim_client_alloc(ClientStore *store)
|
||||
handle = client->handle;
|
||||
++handle.gen;
|
||||
} else {
|
||||
client = arena_push_no_zero(store->clients_arena, Client);
|
||||
client = PushStructNoZero(store->clients_arena, Client);
|
||||
handle.gen = 1;
|
||||
handle.idx = store->num_clients_reserved;
|
||||
++store->num_clients_reserved;
|
||||
@ -149,9 +149,9 @@ Client *sim_client_alloc(ClientStore *store)
|
||||
client->valid = 1;
|
||||
client->handle = handle;
|
||||
|
||||
client->snapshots_arena = arena_alloc(GIBI(8));
|
||||
client->snapshots_arena = AllocArena(GIBI(8));
|
||||
client->num_snapshot_lookup_bins = TICK_LOOKUP_BINS;
|
||||
client->snapshot_lookup_bins = arena_push_array(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins);
|
||||
client->snapshot_lookup_bins = PushArray(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins);
|
||||
|
||||
return client;
|
||||
}
|
||||
@ -164,8 +164,8 @@ void sim_client_release(Client *client)
|
||||
Snapshot *ss = bin->first;
|
||||
while (ss) {
|
||||
Snapshot *next = ss->next_in_bin;
|
||||
arena_release(ss->ents_arena);
|
||||
arena_release(ss->arena);
|
||||
ReleaseArena(ss->ents_arena);
|
||||
ReleaseArena(ss->arena);
|
||||
ss = next;
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,7 @@ void sim_client_release(Client *client)
|
||||
store->first_free_client = client->handle;
|
||||
--store->num_clients_allocated;
|
||||
++client->handle.gen;
|
||||
arena_release(client->snapshots_arena);
|
||||
ReleaseArena(client->snapshots_arena);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -286,16 +286,16 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
|
||||
arena = ss->arena;
|
||||
} else {
|
||||
/* Arenas allocated here will be released with client */
|
||||
arena = arena_alloc(GIBI(1));
|
||||
ents_arena = arena_alloc(GIBI(1));
|
||||
arena = AllocArena(GIBI(1));
|
||||
ents_arena = AllocArena(GIBI(1));
|
||||
}
|
||||
}
|
||||
arena_reset(arena);
|
||||
ss = arena_push(arena, Snapshot);
|
||||
ResetArena(arena);
|
||||
ss = PushStruct(arena, Snapshot);
|
||||
ss->arena = arena;
|
||||
|
||||
ss->ents_arena = ents_arena;
|
||||
arena_reset(ss->ents_arena);
|
||||
ResetArena(ss->ents_arena);
|
||||
}
|
||||
|
||||
ss->tick = tick;
|
||||
@ -312,7 +312,7 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
|
||||
|
||||
/* Copy id lookup bins */
|
||||
ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : ID_LOOKUP_BINS;
|
||||
ss->id_bins = arena_push_array_no_zero(ss->arena, EntBin, ss->num_id_bins);
|
||||
ss->id_bins = PushArrayNoZero(ss->arena, EntBin, ss->num_id_bins);
|
||||
if (src->num_id_bins > 0) {
|
||||
for (u64 i = 0; i < src->num_id_bins; ++i) {
|
||||
ss->id_bins[i] = src->id_bins[i];
|
||||
@ -325,20 +325,20 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
|
||||
ss->first_free_ent = src->first_free_ent;
|
||||
ss->num_ents_allocated = src->num_ents_allocated;
|
||||
ss->num_ents_reserved = src->num_ents_reserved;
|
||||
ss->ents = arena_push_array_no_zero(ss->ents_arena, Ent, ss->num_ents_reserved);
|
||||
ss->ents = PushArrayNoZero(ss->ents_arena, Ent, ss->num_ents_reserved);
|
||||
if (ss->num_ents_reserved == 0) {
|
||||
/* Copying from nil snapshot, need to create blank & root entity */
|
||||
|
||||
/* Push blank ent at index 0 (because index 0 is never valid anyway since it maps to sim_ent_nil()) */
|
||||
/* PushStruct blank ent at index 0 (because index 0 is never valid anyway since it maps to sim_ent_nil()) */
|
||||
{
|
||||
arena_push(ss->ents_arena, Ent);
|
||||
PushStruct(ss->ents_arena, Ent);
|
||||
++ss->num_ents_allocated;
|
||||
++ss->num_ents_reserved;
|
||||
}
|
||||
|
||||
/* Push root ent with constant id */
|
||||
/* PushStruct root ent with constant id */
|
||||
{
|
||||
Ent *root = arena_push_no_zero(ss->ents_arena, Ent);
|
||||
Ent *root = PushStructNoZero(ss->ents_arena, Ent);
|
||||
*root = *sim_ent_nil();
|
||||
root->ss = ss;
|
||||
root->valid = 1;
|
||||
@ -720,23 +720,23 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntId remot
|
||||
* Snapshot encode
|
||||
* ========================== */
|
||||
|
||||
void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1)
|
||||
void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1)
|
||||
{
|
||||
__prof;
|
||||
|
||||
bw_write_dbg_marker(bw, LIT("SNAPSHOT START"));
|
||||
BB_WriteDebugMarker(bw, LIT("SNAPSHOT START"));
|
||||
|
||||
bw_write_iv(bw, ss1->sim_dt_ns);
|
||||
bw_write_iv(bw, ss1->sim_time_ns);
|
||||
BB_WriteIV(bw, ss1->sim_dt_ns);
|
||||
BB_WriteIV(bw, ss1->sim_time_ns);
|
||||
|
||||
bw_write_uv(bw, ss1->continuity_gen);
|
||||
bw_write_uv(bw, ss1->phys_iteration);
|
||||
BB_WriteUV(bw, ss1->continuity_gen);
|
||||
BB_WriteUV(bw, ss1->phys_iteration);
|
||||
|
||||
bw_write_uid(bw, receiver->player_id.uid);
|
||||
BB_WriteUID(bw, receiver->player_id.uid);
|
||||
|
||||
/* Id bins */
|
||||
/* TODO: Don't encode these */
|
||||
bw_write_dbg_marker(bw, LIT("SNAPSHOT BINS"));
|
||||
BB_WriteDebugMarker(bw, LIT("SNAPSHOT BINS"));
|
||||
for (u64 i = 0; i < ss1->num_id_bins; ++i) {
|
||||
u32 old_first = 0;
|
||||
u32 old_last = 0;
|
||||
@ -749,29 +749,29 @@ void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Sna
|
||||
b32 first_diff = bin->first != old_first;
|
||||
b32 last_diff = bin->last != old_last;
|
||||
if (first_diff || last_diff) {
|
||||
bw_write_bit(bw, 1);
|
||||
bw_write_uv(bw, i);
|
||||
if (bw_write_bit(bw, first_diff)) {
|
||||
bw_write_uv(bw, bin->first);
|
||||
BB_WriteBit(bw, 1);
|
||||
BB_WriteUV(bw, i);
|
||||
if (BB_WriteBit(bw, first_diff)) {
|
||||
BB_WriteUV(bw, bin->first);
|
||||
}
|
||||
if (bw_write_bit(bw, last_diff)) {
|
||||
bw_write_uv(bw, bin->last);
|
||||
if (BB_WriteBit(bw, last_diff)) {
|
||||
BB_WriteUV(bw, bin->last);
|
||||
}
|
||||
}
|
||||
}
|
||||
bw_write_bit(bw, 0);
|
||||
BB_WriteBit(bw, 0);
|
||||
|
||||
/* Ents */
|
||||
bw_write_dbg_marker(bw, LIT("SNAPSHOT NUM ENTS"));
|
||||
if (bw_write_bit(bw, ss1->num_ents_allocated != ss0->num_ents_allocated)) {
|
||||
bw_write_uv(bw, ss1->num_ents_allocated);
|
||||
BB_WriteDebugMarker(bw, LIT("SNAPSHOT NUM ENTS"));
|
||||
if (BB_WriteBit(bw, ss1->num_ents_allocated != ss0->num_ents_allocated)) {
|
||||
BB_WriteUV(bw, ss1->num_ents_allocated);
|
||||
}
|
||||
if (bw_write_bit(bw, ss1->num_ents_reserved != ss0->num_ents_reserved)) {
|
||||
bw_write_uv(bw, ss1->num_ents_reserved);
|
||||
if (BB_WriteBit(bw, ss1->num_ents_reserved != ss0->num_ents_reserved)) {
|
||||
BB_WriteUV(bw, ss1->num_ents_reserved);
|
||||
}
|
||||
|
||||
bw_write_dbg_marker(bw, LIT("SNAPSHOT ENTS"));
|
||||
bw_write_dbg_marker(bw, STRING_FROM_STRUCT(&ss1->num_ents_reserved));
|
||||
BB_WriteDebugMarker(bw, LIT("SNAPSHOT ENTS"));
|
||||
BB_WriteDebugMarker(bw, STRING_FROM_STRUCT(&ss1->num_ents_reserved));
|
||||
|
||||
for (u64 i = 1; i < ss1->num_ents_reserved; ++i) {
|
||||
Ent *e0 = sim_ent_nil();
|
||||
@ -782,63 +782,63 @@ void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Sna
|
||||
sim_ent_encode(bw, e0, e1);
|
||||
}
|
||||
|
||||
bw_write_dbg_marker(bw, LIT("SNAPSHOT END"));
|
||||
BB_WriteDebugMarker(bw, LIT("SNAPSHOT END"));
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Snapshot decode
|
||||
* ========================== */
|
||||
|
||||
void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
|
||||
{
|
||||
__prof;
|
||||
|
||||
br_read_dbg_marker(br, LIT("SNAPSHOT START"));
|
||||
BB_ReadDebugMarker(br, LIT("SNAPSHOT START"));
|
||||
|
||||
ss->sim_dt_ns = br_read_iv(br);
|
||||
ss->sim_time_ns = br_read_iv(br);
|
||||
ss->sim_dt_ns = BB_ReadIV(br);
|
||||
ss->sim_time_ns = BB_ReadIV(br);
|
||||
|
||||
ss->continuity_gen = br_read_uv(br);
|
||||
ss->phys_iteration = br_read_uv(br);
|
||||
ss->continuity_gen = BB_ReadUV(br);
|
||||
ss->phys_iteration = BB_ReadUV(br);
|
||||
|
||||
ss->local_player = (EntId) { .uid = br_read_uid(br) };
|
||||
ss->local_player = (EntId) { .uid = BB_ReadUID(br) };
|
||||
|
||||
/* Id bins */
|
||||
/* TODO: Don't decode these, determine them implicitly from decoded ents */
|
||||
br_read_dbg_marker(br, LIT("SNAPSHOT BINS"));
|
||||
BB_ReadDebugMarker(br, LIT("SNAPSHOT BINS"));
|
||||
{
|
||||
b32 bin_changed = br_read_bit(br);
|
||||
b32 bin_changed = BB_ReadBit(br);
|
||||
while (bin_changed) {
|
||||
u32 bin_index = br_read_uv(br);
|
||||
u32 bin_index = BB_ReadUV(br);
|
||||
if (bin_index < ss->num_id_bins) {
|
||||
EntBin *bin = &ss->id_bins[bin_index];
|
||||
if (br_read_bit(br)) {
|
||||
bin->first = br_read_uv(br);
|
||||
if (BB_ReadBit(br)) {
|
||||
bin->first = BB_ReadUV(br);
|
||||
}
|
||||
if (br_read_bit(br)) {
|
||||
bin->last = br_read_uv(br);
|
||||
if (BB_ReadBit(br)) {
|
||||
bin->last = BB_ReadUV(br);
|
||||
}
|
||||
} else {
|
||||
/* Invalid bin index */
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
bin_changed = br_read_bit(br);
|
||||
bin_changed = BB_ReadBit(br);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ents */
|
||||
br_read_dbg_marker(br, LIT("SNAPSHOT NUM ENTS"));
|
||||
if (br_read_bit(br)) {
|
||||
ss->num_ents_allocated = br_read_uv(br);
|
||||
BB_ReadDebugMarker(br, LIT("SNAPSHOT NUM ENTS"));
|
||||
if (BB_ReadBit(br)) {
|
||||
ss->num_ents_allocated = BB_ReadUV(br);
|
||||
}
|
||||
b32 num_ents_reserved_changed = br_read_bit(br);
|
||||
b32 num_ents_reserved_changed = BB_ReadBit(br);
|
||||
if (num_ents_reserved_changed) {
|
||||
u64 old_num_ents_reserved = ss->num_ents_reserved;
|
||||
ss->num_ents_reserved = br_read_uv(br);
|
||||
ss->num_ents_reserved = BB_ReadUV(br);
|
||||
i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved;
|
||||
if (reserve_diff > 0) {
|
||||
arena_push_array_no_zero(ss->ents_arena, Ent, reserve_diff);
|
||||
PushArrayNoZero(ss->ents_arena, Ent, reserve_diff);
|
||||
for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) {
|
||||
Ent *e = &ss->ents[i];
|
||||
*e = *sim_ent_nil();
|
||||
@ -851,15 +851,15 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
}
|
||||
}
|
||||
|
||||
br_read_dbg_marker(br, LIT("SNAPSHOT ENTS"));
|
||||
br_read_dbg_marker(br, STRING_FROM_STRUCT(&ss->num_ents_reserved));
|
||||
BB_ReadDebugMarker(br, LIT("SNAPSHOT ENTS"));
|
||||
BB_ReadDebugMarker(br, STRING_FROM_STRUCT(&ss->num_ents_reserved));
|
||||
for (u64 i = 1; i < ss->num_ents_reserved; ++i) {
|
||||
Ent *e = &ss->ents[i];
|
||||
e->ss = ss;
|
||||
sim_ent_decode(br, e);
|
||||
}
|
||||
|
||||
br_read_dbg_marker(br, LIT("SNAPSHOT END"));
|
||||
BB_ReadDebugMarker(br, LIT("SNAPSHOT END"));
|
||||
}
|
||||
|
||||
|
||||
@ -869,37 +869,37 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
* Snapshot encode
|
||||
* ========================== */
|
||||
|
||||
void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1)
|
||||
void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1)
|
||||
{
|
||||
__prof;
|
||||
|
||||
bw_write_iv(bw, ss1->sim_dt_ns);
|
||||
bw_write_iv(bw, ss1->sim_time_ns);
|
||||
BB_WriteIV(bw, ss1->sim_dt_ns);
|
||||
BB_WriteIV(bw, ss1->sim_time_ns);
|
||||
|
||||
bw_write_uv(bw, ss1->continuity_gen);
|
||||
bw_write_uv(bw, ss1->phys_iteration);
|
||||
BB_WriteUV(bw, ss1->continuity_gen);
|
||||
BB_WriteUV(bw, ss1->phys_iteration);
|
||||
|
||||
bw_write_uid(bw, receiver->player_id.uid);
|
||||
BB_WriteUID(bw, receiver->player_id.uid);
|
||||
|
||||
/* Ents */
|
||||
|
||||
|
||||
|
||||
if (ss1->num_ents_allocated == ss0->num_ents_allocated) {
|
||||
bw_write_bit(bw, 0);
|
||||
BB_WriteBit(bw, 0);
|
||||
} else {
|
||||
bw_write_bit(bw, 1);
|
||||
bw_write_uv(bw, ss1->num_ents_allocated);
|
||||
BB_WriteBit(bw, 1);
|
||||
BB_WriteUV(bw, ss1->num_ents_allocated);
|
||||
}
|
||||
if (ss1->num_ents_reserved == ss0->num_ents_reserved) {
|
||||
bw_write_bit(bw, 0);
|
||||
BB_WriteBit(bw, 0);
|
||||
} else {
|
||||
bw_write_bit(bw, 1);
|
||||
bw_write_uv(bw, ss1->num_ents_reserved);
|
||||
BB_WriteBit(bw, 1);
|
||||
BB_WriteUV(bw, ss1->num_ents_reserved);
|
||||
}
|
||||
|
||||
|
||||
bw_align(bw);
|
||||
BB_AlignWriter(bw);
|
||||
for (u64 i = 0; i < ss1->num_ents_reserved; ++i) {
|
||||
Ent *e0 = sim_ent_nil();
|
||||
if (i < ss0->num_ents_reserved) {
|
||||
@ -907,13 +907,13 @@ void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Sna
|
||||
}
|
||||
|
||||
if (e0->valid != e1->valid) {
|
||||
bw_write_bit(1);
|
||||
bw_write_bit(e1->valid);
|
||||
BB_WriteBit(1);
|
||||
BB_WriteBit(e1->valid);
|
||||
if (e1->valid) {
|
||||
bw_write_uid(bw, e1->id.uid);
|
||||
BB_WriteUID(bw, e1->id.uid);
|
||||
}
|
||||
} else {
|
||||
bw_write_bit(0);
|
||||
BB_WriteBit(0);
|
||||
}
|
||||
|
||||
if (e1->valid) {
|
||||
@ -936,30 +936,30 @@ struct sim_ent_decode_queue {
|
||||
struct sim_ent_decode_node *last;
|
||||
};
|
||||
|
||||
void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
ss->sim_dt_ns = br_read_iv(br);
|
||||
ss->sim_time_ns = br_read_iv(br);
|
||||
ss->sim_dt_ns = BB_ReadIV(br);
|
||||
ss->sim_time_ns = BB_ReadIV(br);
|
||||
|
||||
ss->continuity_gen = br_read_uv(br);
|
||||
ss->phys_iteration = br_read_uv(br);
|
||||
ss->continuity_gen = BB_ReadUV(br);
|
||||
ss->phys_iteration = BB_ReadUV(br);
|
||||
|
||||
ss->local_player = (EntId) { .uid = br_read_uid(br) };
|
||||
ss->local_player = (EntId) { .uid = BB_ReadUID(br) };
|
||||
|
||||
#if 1
|
||||
|
||||
if (br_read_bit(br)) {
|
||||
ss->num_ents_allocated = br_read_uv(br);
|
||||
if (BB_ReadBit(br)) {
|
||||
ss->num_ents_allocated = BB_ReadUV(br);
|
||||
}
|
||||
if (br_read_bit(br)) {
|
||||
if (BB_ReadBit(br)) {
|
||||
u64 old_num_ents_reserved = ss->num_ents_reserved;
|
||||
ss->num_ents_reserved = br_read_uv(br);
|
||||
ss->num_ents_reserved = BB_ReadUV(br);
|
||||
i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved;
|
||||
if (reserve_diff > 0) {
|
||||
arena_push_array_no_zero(ss->ents_arena, Ent, reserve_diff);
|
||||
PushArrayNoZero(ss->ents_arena, Ent, reserve_diff);
|
||||
for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) {
|
||||
Ent *e = &ss->ents[i];
|
||||
*e = *sim_ent_nil();
|
||||
@ -970,17 +970,17 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
|
||||
/* Build decode queue */
|
||||
struct sim_ent_decode_queue queue;
|
||||
b32 should_read_ent = br_read_bit(br);
|
||||
b32 should_read_ent = BB_ReadBit(br);
|
||||
while (should_read_ent) {
|
||||
/* TODO: Delta decode index based on last read index */
|
||||
u32 index = br_read_uv(br);
|
||||
b32 allocation_changed = br_read_bit(br);
|
||||
u32 index = BB_ReadUV(br);
|
||||
b32 allocation_changed = BB_ReadBit(br);
|
||||
b32 released = 0;
|
||||
|
||||
u32 alloc_parent_index = ZI;
|
||||
EntId alloc_ent_id = ZI;
|
||||
if (allocation_changed) {
|
||||
released = br_read_bit(br);
|
||||
released = BB_ReadBit(br);
|
||||
if (released) {
|
||||
Ent *e = sim_ent_from_index(ss, e);
|
||||
ASSERT(e->valid); /* An entity that we don't have allocated should never have been marked for release */
|
||||
@ -988,16 +988,16 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
sim_ent_enable_prop(e, SEPROP_RELEASE);
|
||||
}
|
||||
} else {
|
||||
alloc_parent_index = br_read_uv();
|
||||
alloc_ent_id = sim_ent_id_from_uid(br_read_uid(br));
|
||||
alloc_parent_index = BB_ReadUV();
|
||||
alloc_ent_id = sim_ent_id_from_uid(BB_ReadUID(br));
|
||||
}
|
||||
}
|
||||
|
||||
if (!released) {
|
||||
u64 num_ent_bits = br_read_uv(br);
|
||||
BitbuffReader ent_br = br_from_seek_bits(br, num_ent_bits);
|
||||
if (br_num_bits_left(&ent_br) > 0) {
|
||||
struct sim_ent_decode_node *n = arena_push(scratch.arena, struct sim_ent_decode_node);
|
||||
u64 num_ent_bits = BB_ReadUV(br);
|
||||
BB_Reader ent_br = br_from_seek_bits(br, num_ent_bits);
|
||||
if (BB_NumBitsRemaining(&ent_br) > 0) {
|
||||
struct sim_ent_decode_node *n = PushStruct(scratch.arena, struct sim_ent_decode_node);
|
||||
n->is_new = allocation_changed && !released;
|
||||
n->index = index;
|
||||
n->alloc_parent_ndex = alloc_parent_index;
|
||||
@ -1012,7 +1012,7 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
}
|
||||
}
|
||||
|
||||
should_read_ent = br_read_bit(br);
|
||||
should_read_ent = BB_ReadBit(br);
|
||||
}
|
||||
|
||||
/* Allocate new ents from decode queue */
|
||||
@ -1036,7 +1036,7 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
|
||||
/* Decode ent data from decode queue */
|
||||
for (struct sim_ent_decode_node *n = queue.first; n; n = n->next) {
|
||||
BitbuffReader ent_br = n->br;
|
||||
BB_Reader ent_br = n->br;
|
||||
u32 index = n->index;
|
||||
Ent *e = sim_ent_from_index(ss, index);
|
||||
if (e->valid) {
|
||||
@ -1048,15 +1048,15 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
}
|
||||
#else
|
||||
/* Ents */
|
||||
if (br_read_bit(br)) {
|
||||
ss->num_ents_allocated = br_read_uv(br);
|
||||
if (BB_ReadBit(br)) {
|
||||
ss->num_ents_allocated = BB_ReadUV(br);
|
||||
}
|
||||
if (br_read_bit(br)) {
|
||||
if (BB_ReadBit(br)) {
|
||||
u64 old_num_ents_reserved = ss->num_ents_reserved;
|
||||
ss->num_ents_reserved = br_read_uv(br);
|
||||
ss->num_ents_reserved = BB_ReadUV(br);
|
||||
i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved;
|
||||
if (reserve_diff > 0) {
|
||||
arena_push_array_no_zero(ss->ents_arena, Ent, reserve_diff);
|
||||
PushArrayNoZero(ss->ents_arena, Ent, reserve_diff);
|
||||
for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) {
|
||||
Ent *e = &ss->ents[i];
|
||||
*e = *sim_ent_nil();
|
||||
@ -1066,10 +1066,10 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < ss->num_ents_reserved; ++i) {
|
||||
b32 allocation_changed = br_read_bit(br);
|
||||
b32 allocation_changed = BB_ReadBit(br);
|
||||
if (allocation_changed) {
|
||||
if (br_read_bit(br)) {
|
||||
struct sim_ent_decode_node *n = arena_push(scratch.arena, struct sim_ent_decode_node)
|
||||
if (BB_ReadBit(br)) {
|
||||
struct sim_ent_decode_node *n = PushStruct(scratch.arena, struct sim_ent_decode_node)
|
||||
} else {
|
||||
sim_ent_enable_prop(e, SEPROP_RELEASE);
|
||||
}
|
||||
@ -1080,10 +1080,10 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
Ent *e = &ss->ents[i];
|
||||
e->ss = ss;
|
||||
|
||||
b32 valid_changed = br_read_bit(br);
|
||||
b32 valid_changed = BB_ReadBit(br);
|
||||
b32 allocated = 1;
|
||||
if (valid_changed) {
|
||||
allocated = br_read_bit(br);
|
||||
allocated = BB_ReadBit(br);
|
||||
}
|
||||
|
||||
if (!allocated) {
|
||||
@ -1099,6 +1099,6 @@ void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss)
|
||||
sim_ent_release_all_with_prop(ss, SEPROP_RELEASE);
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -247,5 +247,5 @@ Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *
|
||||
void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntId remote_player, u32 sync_flags);
|
||||
|
||||
/* Encode / decode */
|
||||
void sim_snapshot_encode(BitbuffWriter *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1);
|
||||
void sim_snapshot_decode(BitbuffReader *br, Snapshot *ss);
|
||||
void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1);
|
||||
void sim_snapshot_decode(BB_Reader *br, Snapshot *ss);
|
||||
|
||||
@ -33,7 +33,7 @@ Ent *sim_ent_alloc_raw(Snapshot *ss, Ent *parent, EntId id)
|
||||
ss->first_free_ent = ent->next_free;
|
||||
} else {
|
||||
/* Make new */
|
||||
ent = arena_push_no_zero(ss->ents_arena, Ent);
|
||||
ent = PushStructNoZero(ss->ents_arena, Ent);
|
||||
++ss->num_ents_reserved;
|
||||
}
|
||||
*ent = *sim_ent_nil();
|
||||
@ -128,14 +128,14 @@ void sim_ent_release(Ent *ent)
|
||||
|
||||
void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop)
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
Ent **ents_to_release = arena_push_dry(scratch.arena, Ent *);
|
||||
Ent **ents_to_release = PushDry(scratch.arena, Ent *);
|
||||
u64 ents_to_release_count = 0;
|
||||
for (u64 ent_index = 0; ent_index < ss->num_ents_reserved; ++ent_index) {
|
||||
Ent *ent = &ss->ents[ent_index];
|
||||
if (ent->valid && sim_ent_has_prop(ent, prop)) {
|
||||
*arena_push_no_zero(scratch.arena, Ent *) = ent;
|
||||
*PushStructNoZero(scratch.arena, Ent *) = ent;
|
||||
++ents_to_release_count;
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -687,7 +687,7 @@ void sim_ent_sync(Ent *local, Ent *remote)
|
||||
* Ent encode
|
||||
* ========================== */
|
||||
|
||||
void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
void sim_ent_encode(BB_Writer *bw, Ent *e0, Ent *e1)
|
||||
{
|
||||
Snapshot *ss = e1->ss;
|
||||
/* FIXME: Things like xforms need to be retreived manually rather than memcopied. */
|
||||
@ -700,10 +700,10 @@ void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
u64 chunk_size = min_u64(pos + 8, sizeof(*e1)) - pos;
|
||||
u8 *chunk0 = (u8 *)e0 + pos;
|
||||
u8 *chunk1 = (u8 *)e1 + pos;
|
||||
if (bw_write_bit(bw, !MEMEQ(chunk0, chunk1, chunk_size))) {
|
||||
if (BB_WriteBit(bw, !MEMEQ(chunk0, chunk1, chunk_size))) {
|
||||
u64 bits = 0;
|
||||
MEMCPY(&bits, chunk1, chunk_size);
|
||||
bw_write_ubits(bw, bits, 64);
|
||||
BB_WriteUBits(bw, bits, 64);
|
||||
}
|
||||
pos += 8;
|
||||
}
|
||||
@ -714,16 +714,16 @@ void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
* Ent decode
|
||||
* ========================== */
|
||||
|
||||
void sim_ent_decode(BitbuffReader *br, Ent *e)
|
||||
void sim_ent_decode(BB_Reader *br, Ent *e)
|
||||
{
|
||||
Snapshot *old_ss = e->ss;
|
||||
{
|
||||
u64 pos = 0;
|
||||
while (pos < sizeof(*e)) {
|
||||
u8 *chunk = (u8 *)e + pos;
|
||||
if (br_read_bit(br)) {
|
||||
if (BB_ReadBit(br)) {
|
||||
u64 chunk_size = min_u64(pos + 8, sizeof(*e)) - pos;
|
||||
u64 bits = br_read_ubits(br, 64);
|
||||
u64 bits = BB_ReadUBits(br, 64);
|
||||
MEMCPY(chunk, &bits, chunk_size);
|
||||
}
|
||||
pos += 8;
|
||||
@ -739,7 +739,7 @@ void sim_ent_decode(BitbuffReader *br, Ent *e)
|
||||
* Ent encode
|
||||
* ========================== */
|
||||
|
||||
void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
void sim_ent_encode(BB_Writer *bw, Ent *e0, Ent *e1)
|
||||
{
|
||||
Snapshot *ss = e1->ss;
|
||||
|
||||
@ -756,12 +756,12 @@ void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
u8 *chunk0 = (u8 *)e0 + pos;
|
||||
u8 *chunk1 = (u8 *)e1 + pos;
|
||||
if (MEMEQ(chunk0, chunk1, chunk_size)) {
|
||||
bw_write_bit(bw, 0);
|
||||
BB_WriteBit(bw, 0);
|
||||
} else {
|
||||
bw_write_bit(bw, 1);
|
||||
BB_WriteBit(bw, 1);
|
||||
u64 bits = 0;
|
||||
MEMCPY(&bits, chunk1, chunk_size);
|
||||
bw_write_ubits(bw, bits, 64);
|
||||
BB_WriteUBits(bw, bits, 64);
|
||||
}
|
||||
pos += 8;
|
||||
}
|
||||
@ -772,16 +772,16 @@ void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1)
|
||||
* Ent decode
|
||||
* ========================== */
|
||||
|
||||
void sim_ent_decode(BitbuffReader *br, Ent *e)
|
||||
void sim_ent_decode(BB_Reader *br, Ent *e)
|
||||
{
|
||||
Ent decoded = *e;
|
||||
{
|
||||
u64 pos = 0;
|
||||
while (pos < sizeof(decoded)) {
|
||||
u8 *chunk = (u8 *)&decoded + pos;
|
||||
if (br_read_bit(br)) {
|
||||
if (BB_ReadBit(br)) {
|
||||
u64 chunk_size = min_u64(pos + 8, sizeof(decoded)) - pos;
|
||||
u64 bits = br_read_ubits(br, 64);
|
||||
u64 bits = BB_ReadUBits(br, 64);
|
||||
MEMCPY(chunk, &bits, chunk_size);
|
||||
}
|
||||
pos += 8;
|
||||
|
||||
@ -546,5 +546,5 @@ void sim_ent_sync_alloc_tree(Ent *local_parent, Ent *remote, EntId remote_player
|
||||
void sim_ent_sync(Ent *local, Ent *remote);
|
||||
|
||||
/* Encode / decode */
|
||||
void sim_ent_encode(BitbuffWriter *bw, Ent *e0, Ent *e1);
|
||||
void sim_ent_decode(BitbuffReader *br, Ent *e);
|
||||
void sim_ent_encode(BB_Writer *bw, Ent *e0, Ent *e1);
|
||||
void sim_ent_decode(BB_Reader *br, Ent *e);
|
||||
|
||||
@ -1248,7 +1248,7 @@ void phys_step(PhysStepCtx *ctx, f32 timestep)
|
||||
while (remaining_dt > 0) {
|
||||
__profn("Step part");
|
||||
++phys_iteration;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* TOI */
|
||||
f32 step_dt = remaining_dt;
|
||||
@ -1302,7 +1302,7 @@ void phys_step(PhysStepCtx *ctx, f32 timestep)
|
||||
}
|
||||
|
||||
phys_update_aabbs(ctx);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
ss->phys_iteration = phys_iteration;
|
||||
|
||||
@ -19,34 +19,34 @@ Space *space_alloc(f32 cell_size, u32 num_bins_sqrt)
|
||||
{
|
||||
Space *space;
|
||||
{
|
||||
Arena *arena = arena_alloc(GIBI(64));
|
||||
space = arena_push(arena, Space);
|
||||
Arena *arena = AllocArena(GIBI(64));
|
||||
space = PushStruct(arena, Space);
|
||||
space->entry_arena = arena;
|
||||
}
|
||||
|
||||
space->valid = 1;
|
||||
space->entries = arena_push_dry(space->entry_arena, SpaceEntry);
|
||||
space->entries = PushDry(space->entry_arena, SpaceEntry);
|
||||
|
||||
space->cell_arena = arena_alloc(GIBI(64));
|
||||
space->cell_arena = AllocArena(GIBI(64));
|
||||
space->cell_size = cell_size;
|
||||
space->num_bins = num_bins_sqrt * num_bins_sqrt;
|
||||
space->num_bins_sqrt = num_bins_sqrt;
|
||||
space->bins = arena_push_array(space->cell_arena, SpaceCellBin, space->num_bins);
|
||||
space->bins = PushArray(space->cell_arena, SpaceCellBin, space->num_bins);
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
void space_release(Space *space)
|
||||
{
|
||||
arena_release(space->cell_arena);
|
||||
arena_release(space->entry_arena);
|
||||
ReleaseArena(space->cell_arena);
|
||||
ReleaseArena(space->entry_arena);
|
||||
}
|
||||
|
||||
void space_reset(Space *space)
|
||||
{
|
||||
arena_pop_to(space->entry_arena, (u64)space->entries - (u64)arena_base(space->entry_arena));
|
||||
arena_reset(space->cell_arena);
|
||||
space->bins = arena_push_array(space->cell_arena, SpaceCellBin, space->num_bins);
|
||||
PopTo(space->entry_arena, (u64)space->entries - (u64)ArenaBase(space->entry_arena));
|
||||
ResetArena(space->cell_arena);
|
||||
space->bins = PushArray(space->cell_arena, SpaceCellBin, space->num_bins);
|
||||
space->num_entries_reserved = 0;
|
||||
space->first_free_cell = 0;
|
||||
space->first_free_cell_node = 0;
|
||||
@ -135,7 +135,7 @@ INTERNAL void space_cell_node_alloc(V2i32 cell_pos, SpaceEntry *entry)
|
||||
cell = space->first_free_cell;
|
||||
space->first_free_cell = cell->next_free;
|
||||
} else {
|
||||
cell = arena_push_no_zero(space->cell_arena, SpaceCell);
|
||||
cell = PushStructNoZero(space->cell_arena, SpaceCell);
|
||||
}
|
||||
MEMZERO_STRUCT(cell);
|
||||
if (bin->last_cell) {
|
||||
@ -157,7 +157,7 @@ INTERNAL void space_cell_node_alloc(V2i32 cell_pos, SpaceEntry *entry)
|
||||
node = space->first_free_cell_node;
|
||||
space->first_free_cell_node = node->next_free;
|
||||
} else {
|
||||
node = arena_push_no_zero(space->cell_arena, SpaceCellNode);
|
||||
node = PushStructNoZero(space->cell_arena, SpaceCellNode);
|
||||
}
|
||||
MEMZERO_STRUCT(node);
|
||||
}
|
||||
@ -276,7 +276,7 @@ SpaceEntry *space_entry_alloc(Space *space, EntId ent)
|
||||
space->first_free_entry = entry->next_free;
|
||||
handle = entry->handle;
|
||||
} else {
|
||||
entry = arena_push_no_zero(space->entry_arena, SpaceEntry);
|
||||
entry = PushStructNoZero(space->entry_arena, SpaceEntry);
|
||||
handle.idx = space->num_entries_reserved;
|
||||
handle.gen = 1;
|
||||
++space->num_entries_reserved;
|
||||
|
||||
@ -434,7 +434,7 @@ INTERNAL SORT_COMPARE_FUNC_DEF(tile_chunk_sort_y, arg_a, arg_b, udata)
|
||||
INTERNAL void test_generate_walls(Snapshot *world)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
Ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
|
||||
|
||||
/* Release existing walls and gather tile chunks.
|
||||
@ -444,20 +444,20 @@ INTERNAL void test_generate_walls(Snapshot *world)
|
||||
Ent **y_sorted_tile_chunks = 0;
|
||||
u64 sorted_tile_chunks_count = 0;
|
||||
{
|
||||
x_sorted_tile_chunks = arena_push_dry(scratch.arena, Ent *);
|
||||
x_sorted_tile_chunks = PushDry(scratch.arena, Ent *);
|
||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||
Ent *ent = &world->ents[ent_index];
|
||||
if (!ent->valid) continue;
|
||||
if (sim_ent_has_prop(ent, SEPROP_TILE_CHUNK)) {
|
||||
/* Append chunk to array */
|
||||
*arena_push_no_zero(scratch.arena, Ent *) = ent;
|
||||
*PushStructNoZero(scratch.arena, Ent *) = ent;
|
||||
++sorted_tile_chunks_count;
|
||||
} else if (sim_ent_has_prop(ent, SEPROP_WALL)) {
|
||||
/* Release existing wall */
|
||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
||||
}
|
||||
}
|
||||
y_sorted_tile_chunks = arena_push_array_no_zero(scratch.arena, Ent *, sorted_tile_chunks_count);
|
||||
y_sorted_tile_chunks = PushArrayNoZero(scratch.arena, Ent *, sorted_tile_chunks_count);
|
||||
MEMCPY(y_sorted_tile_chunks, x_sorted_tile_chunks, sizeof(*x_sorted_tile_chunks) * sorted_tile_chunks_count);
|
||||
|
||||
/* NOTE: We sort x & y separately because it's possible that a wall
|
||||
@ -538,7 +538,7 @@ INTERNAL void test_generate_walls(Snapshot *world)
|
||||
}
|
||||
}
|
||||
if (!node) {
|
||||
node = arena_push(scratch.arena, struct wall_node);
|
||||
node = PushStruct(scratch.arena, struct wall_node);
|
||||
node->start = start;
|
||||
node->next = first_wall;
|
||||
node->wall_dir = wall_dir;
|
||||
@ -628,7 +628,7 @@ INTERNAL void test_generate_walls(Snapshot *world)
|
||||
}
|
||||
}
|
||||
if (!node) {
|
||||
node = arena_push(scratch.arena, struct wall_node);
|
||||
node = PushStruct(scratch.arena, struct wall_node);
|
||||
node->start = start;
|
||||
node->next = first_wall;
|
||||
node->wall_dir = wall_dir;
|
||||
@ -681,7 +681,7 @@ INTERNAL void test_generate_walls(Snapshot *world)
|
||||
sim_ent_activate(wall_ent, world->tick);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
|
||||
@ -839,7 +839,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
void sim_step(SimStepCtx *ctx)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
b32 is_master = ctx->is_master;
|
||||
Snapshot *world = ctx->world;
|
||||
@ -1881,28 +1881,28 @@ void sim_step(SimStepCtx *ctx)
|
||||
* ========================== */
|
||||
|
||||
{
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
Ent **stack = arena_push_no_zero(temp.arena, Ent *);
|
||||
Ent **stack = PushStructNoZero(temp.arena, Ent *);
|
||||
u64 stack_count = 1;
|
||||
*stack = root;
|
||||
|
||||
while (stack_count > 0) {
|
||||
Ent *parent;
|
||||
arena_pop(temp.arena, Ent *, &parent);
|
||||
PopStruct(temp.arena, Ent *, &parent);
|
||||
--stack_count;
|
||||
|
||||
i32 parent_layer = parent->final_layer;
|
||||
for (Ent *child = sim_ent_from_id(world, parent->first); child->valid; child = sim_ent_from_id(world, child->next)) {
|
||||
if (sim_ent_should_simulate(child)) {
|
||||
child->final_layer = parent_layer + child->layer;
|
||||
*arena_push_no_zero(temp.arena, Ent *) = child;
|
||||
*PushStructNoZero(temp.arena, Ent *) = child;
|
||||
++stack_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -1944,5 +1944,5 @@ void sim_step(SimStepCtx *ctx)
|
||||
|
||||
sprite_scope_end(sprite_frame_scope);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ SND_StartupReceipt sound_startup(AC_StartupReceipt *asset_cache_sr)
|
||||
{
|
||||
__prof;
|
||||
(UNUSED)asset_cache_sr;
|
||||
G.params.arena = arena_alloc(GIBI(64));
|
||||
G.params.arena = AllocArena(GIBI(64));
|
||||
return (SND_StartupReceipt) { 0 };
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ INTERNAL struct sound_task_params *sound_task_params_alloc(void)
|
||||
p = G.params.head_free;
|
||||
G.params.head_free = p->next_free;
|
||||
} else {
|
||||
p = arena_push(G.params.arena, struct sound_task_params);
|
||||
p = PushStruct(G.params.arena, struct sound_task_params);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -71,7 +71,7 @@ INTERNAL P_JobDef(sound_load_asset_job, job)
|
||||
{
|
||||
__prof;
|
||||
struct sound_task_params *params = job.sig;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String path = STRING(params->path_len, (u8 *)params->path_cstr);
|
||||
AC_Asset *asset = params->asset;
|
||||
u32 flags = params->flags;
|
||||
@ -108,8 +108,8 @@ INTERNAL P_JobDef(sound_load_asset_job, job)
|
||||
i16 *samples = 0;
|
||||
{
|
||||
AC_Store store = asset_cache_store_open();
|
||||
sound = arena_push_no_zero(store.arena, SND_Sound);
|
||||
samples = arena_push_array_no_zero(store.arena, i16, decoded.pcm.count);
|
||||
sound = PushStructNoZero(store.arena, SND_Sound);
|
||||
samples = PushArrayNoZero(store.arena, i16, decoded.pcm.count);
|
||||
asset_cache_store_close(&store);
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ INTERNAL P_JobDef(sound_load_asset_job, job)
|
||||
SND_Sound *sound = 0;
|
||||
{
|
||||
AC_Store store = asset_cache_store_open();
|
||||
sound = arena_push_no_zero(store.arena, SND_Sound);
|
||||
sound = PushStructNoZero(store.arena, SND_Sound);
|
||||
asset_cache_store_close(&store);
|
||||
}
|
||||
*sound = (SND_Sound) { 0 };
|
||||
@ -138,13 +138,13 @@ INTERNAL P_JobDef(sound_load_asset_job, job)
|
||||
|
||||
sound_task_params_release(params);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
AC_Asset *sound_load_asset(String path, u32 flags, b32 wait)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* Generate and append sound flags to path key */
|
||||
String key = string_format(scratch.arena,
|
||||
@ -168,7 +168,7 @@ AC_Asset *sound_load_asset(String path, u32 flags, b32 wait)
|
||||
params->asset = asset;
|
||||
params->flags = flags;
|
||||
|
||||
/* Push task */
|
||||
/* PushStruct task */
|
||||
asset_cache_mark_loading(asset);
|
||||
P_Run(1, sound_load_asset_job, params, P_Pool_Background, P_Priority_Low, &asset->counter);
|
||||
if (wait) {
|
||||
@ -176,7 +176,7 @@ AC_Asset *sound_load_asset(String path, u32 flags, b32 wait)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return asset;
|
||||
}
|
||||
|
||||
|
||||
@ -150,7 +150,7 @@ GLOBAL struct {
|
||||
|
||||
INTERNAL ImageDataRgba generate_purple_black_image(Arena *arena, u32 width, u32 height)
|
||||
{
|
||||
u32 *pixels = arena_push_array_no_zero(arena, u32, width * height);
|
||||
u32 *pixels = PushArrayNoZero(arena, u32, width * height);
|
||||
|
||||
/* Create texture containing alternating blocks of purple and black */
|
||||
u32 color_size = 4;
|
||||
@ -197,40 +197,40 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(sprite_watch_callback, info);
|
||||
S_StartupReceipt sprite_startup(void)
|
||||
{
|
||||
__prof;
|
||||
G.perm_arena = arena_alloc(MEBI(1));
|
||||
G.perm_arena = AllocArena(MEBI(1));
|
||||
{
|
||||
/* Init loading texture */
|
||||
G.loading_texture = arena_push(G.perm_arena, S_Texture);
|
||||
G.loading_texture = PushStruct(G.perm_arena, S_Texture);
|
||||
|
||||
/* Init nil texture */
|
||||
G.nil_texture = arena_push(G.perm_arena, S_Texture);
|
||||
G.nil_texture = PushStruct(G.perm_arena, S_Texture);
|
||||
G.nil_texture->loaded = 1;
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
ImageDataRgba purple_black_image = generate_purple_black_image(scratch.arena, 64, 64);
|
||||
G.nil_texture->gp_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2i32FromXY(purple_black_image.width, purple_black_image.height), purple_black_image.pixels);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* Init loading sheet */
|
||||
G.loading_sheet = arena_push(G.perm_arena, S_Sheet);
|
||||
G.loading_sheet = PushStruct(G.perm_arena, S_Sheet);
|
||||
G.loading_sheet->image_size = V2FromXY(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.loading_sheet->frame_size = V2FromXY(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
|
||||
/* Init nil sheet */
|
||||
G.nil_sheet = arena_push(G.perm_arena, S_Sheet);
|
||||
G.nil_sheet = PushStruct(G.perm_arena, S_Sheet);
|
||||
G.nil_sheet->image_size = V2FromXY(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->frame_size = V2FromXY(PIXELS_PER_UNIT, PIXELS_PER_UNIT);
|
||||
G.nil_sheet->loaded = 1;
|
||||
}
|
||||
arena_set_readonly(G.perm_arena);
|
||||
SetArenaReadonly(G.perm_arena);
|
||||
|
||||
G.cache.arena = arena_alloc(GIBI(64));
|
||||
G.cache.bins = arena_push_array(G.cache.arena, struct cache_bin, CACHE_BINS_COUNT);
|
||||
G.cache.arena = AllocArena(GIBI(64));
|
||||
G.cache.bins = PushArray(G.cache.arena, struct cache_bin, CACHE_BINS_COUNT);
|
||||
|
||||
G.load_cmds_arena = arena_alloc(GIBI(64));
|
||||
G.load_cmds_arena = AllocArena(GIBI(64));
|
||||
|
||||
G.scopes_arena = arena_alloc(GIBI(64));
|
||||
G.scopes_arena = AllocArena(GIBI(64));
|
||||
|
||||
P_Run(1, sprite_evictor_job, 0, P_Pool_Background, P_Priority_Low, &G.shutdown_counter);
|
||||
|
||||
@ -295,7 +295,7 @@ INTERNAL void push_load_job(struct cache_ref ref, S_Tag tag)
|
||||
cmd = G.first_free_load_cmd;
|
||||
G.first_free_load_cmd = cmd->next_free;
|
||||
} else {
|
||||
cmd = arena_push_no_zero(G.load_cmds_arena, struct load_cmd);
|
||||
cmd = PushStructNoZero(G.load_cmds_arena, struct load_cmd);
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
@ -311,14 +311,14 @@ INTERNAL void push_load_job(struct cache_ref ref, S_Tag tag)
|
||||
MEMCPY(cmd->tag.path.text, tag.path.text, copy_len);
|
||||
}
|
||||
|
||||
/* Push work */
|
||||
/* PushStruct work */
|
||||
P_Run(1, sprite_load_job, cmd, P_Pool_Background, P_Priority_Inherit, 0);
|
||||
}
|
||||
|
||||
INTERNAL void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct cache_entry *e = ref.e;
|
||||
|
||||
atomic32_fetch_set(&e->state, CACHE_ENTRY_STATE_WORKING);
|
||||
@ -333,7 +333,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
|
||||
/* TODO: Replace arena allocs w/ buddy allocator */
|
||||
/* TODO: Arena probably overkill. Just using it to store texture struct. */
|
||||
e->arena = arena_alloc(TEXTURE_ARENA_RESERVE);
|
||||
e->arena = AllocArena(TEXTURE_ARENA_RESERVE);
|
||||
u64 memory_size = 0;
|
||||
{
|
||||
/* Decode */
|
||||
@ -350,7 +350,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
|
||||
if (decoded.success) {
|
||||
/* Initialize */
|
||||
e->texture = arena_push(e->arena, S_Texture);
|
||||
e->texture = PushStruct(e->arena, S_Texture);
|
||||
e->texture->width = decoded.image.width;
|
||||
e->texture->height = decoded.image.height;
|
||||
e->texture->valid = 1;
|
||||
@ -361,7 +361,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
success = 1;
|
||||
}
|
||||
}
|
||||
arena_set_readonly(e->arena);
|
||||
SetArenaReadonly(e->arena);
|
||||
e->memory_usage = e->arena->committed + memory_size;
|
||||
atomic64_fetch_add(&G.cache.memory_usage.v, e->memory_usage);
|
||||
|
||||
@ -389,7 +389,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, S_Tag tag)
|
||||
P_Unlock(&bin_lock);
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
@ -407,7 +407,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
__profn("Init frames");
|
||||
sheet.image_size = ase.image_size;
|
||||
sheet.frame_size = ase.frame_size;
|
||||
sheet.frames = arena_push_array(arena, S_SheetFrame, ase.num_frames);
|
||||
sheet.frames = PushArray(arena, S_SheetFrame, ase.num_frames);
|
||||
sheet.frames_count = ase.num_frames;
|
||||
for (Ase_Frame *ase_frame = ase.frame_head; ase_frame; ase_frame = ase_frame->next) {
|
||||
u32 index = ase_frame->index;
|
||||
@ -427,7 +427,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
sheet.spans_count = ase.num_spans;
|
||||
if (ase.num_spans > 0) {
|
||||
__profn("Init spans");
|
||||
sheet.spans = arena_push_array(arena, S_SheetSpan, sheet.spans_count);
|
||||
sheet.spans = PushArray(arena, S_SheetSpan, sheet.spans_count);
|
||||
sheet.spans_dict = dict_init(arena, (u64)(ase.num_spans * SHEET_SPAN_LOOKUP_TABLE_BIN_RATIO));
|
||||
u64 index = 0;
|
||||
for (Ase_Span *ase_span = ase.span_head; ase_span; ase_span = ase_span->next) {
|
||||
@ -445,7 +445,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
/* Init slices */
|
||||
if (ase.num_slice_keys > 0) {
|
||||
__profn("Init slices");
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
|
||||
struct temp_ase_slice_key_node {
|
||||
Ase_SliceKey *key;
|
||||
@ -474,7 +474,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
|
||||
struct temp_slice_group_node *temp_slice_group_node = (struct temp_slice_group_node *)dict_get(temp_slice_dict, hash);
|
||||
if (!temp_slice_group_node) {
|
||||
temp_slice_group_node = arena_push(scratch.arena, struct temp_slice_group_node);
|
||||
temp_slice_group_node = PushStruct(scratch.arena, struct temp_slice_group_node);
|
||||
temp_slice_group_node->name = name;
|
||||
dict_set(scratch.arena, temp_slice_dict, hash, (u64)temp_slice_group_node);
|
||||
|
||||
@ -483,7 +483,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
temp_slice_group_head = temp_slice_group_node;
|
||||
}
|
||||
|
||||
struct temp_ase_slice_key_node *node = arena_push(scratch.arena, struct temp_ase_slice_key_node);
|
||||
struct temp_ase_slice_key_node *node = PushStruct(scratch.arena, struct temp_ase_slice_key_node);
|
||||
node->key = ase_slice_key;
|
||||
node->next = temp_slice_group_node->temp_ase_slice_key_head;
|
||||
node->earliest_frame = U32_MAX; /* To be overwritten later after iterating */
|
||||
@ -496,7 +496,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
|
||||
/* Allocate slice groups & fill originals in 2d array */
|
||||
sheet.slice_groups_count = num_temp_slice_group_nodes;
|
||||
sheet.slice_groups = arena_push_array(arena, S_SheetSliceGroup, sheet.slice_groups_count);
|
||||
sheet.slice_groups = PushArray(arena, S_SheetSliceGroup, sheet.slice_groups_count);
|
||||
sheet.slice_groups_dict = dict_init(arena, (u64)(num_temp_slice_group_nodes * SHEET_SLICE_LOOKUP_TABLE_BIN_RATIO));
|
||||
|
||||
u64 index = 0;
|
||||
@ -505,7 +505,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
slice_group->name = string_copy(arena, temp_slice_group_node->name);
|
||||
slice_group->per_frame_count = temp_slice_group_node->per_frame_count;
|
||||
|
||||
slice_group->frame_slices = arena_push_array(arena, S_SheetSlice, ase.num_frames * slice_group->per_frame_count);
|
||||
slice_group->frame_slices = PushArray(arena, S_SheetSlice, ase.num_frames * slice_group->per_frame_count);
|
||||
|
||||
u64 index_in_frame = 0;
|
||||
for (struct temp_ase_slice_key_node *node = temp_slice_group_node->temp_ase_slice_key_head; node; node = node->next) {
|
||||
@ -632,7 +632,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
return sheet;
|
||||
@ -641,7 +641,7 @@ INTERNAL S_Sheet init_sheet_from_ase_result(Arena *arena, Ase_DecodedSheet ase)
|
||||
INTERNAL void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct cache_entry *e = ref.e;
|
||||
|
||||
atomic32_fetch_set(&e->state, CACHE_ENTRY_STATE_WORKING);
|
||||
@ -654,7 +654,7 @@ INTERNAL void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
ASSERT(e->kind == CACHE_ENTRY_KIND_SHEET);
|
||||
|
||||
/* TODO: Replace arena allocs w/ buddy allocator */
|
||||
e->arena = arena_alloc(SHEET_ARENA_RESERVE);
|
||||
e->arena = AllocArena(SHEET_ARENA_RESERVE);
|
||||
{
|
||||
/* Decode */
|
||||
Ase_DecodedSheet decoded = ZI;
|
||||
@ -674,7 +674,7 @@ INTERNAL void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
resource_close(&sheet_rs);
|
||||
|
||||
/* Initialize */
|
||||
e->sheet = arena_push_no_zero(e->arena, S_Sheet);
|
||||
e->sheet = PushStructNoZero(e->arena, S_Sheet);
|
||||
*e->sheet = init_sheet_from_ase_result(e->arena, decoded);
|
||||
e->sheet->loaded = 1;
|
||||
e->sheet->valid = 1;
|
||||
@ -682,7 +682,7 @@ INTERNAL void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
success = 1;
|
||||
}
|
||||
}
|
||||
arena_set_readonly(e->arena);
|
||||
SetArenaReadonly(e->arena);
|
||||
e->memory_usage = e->arena->committed;
|
||||
atomic64_fetch_add(&G.cache.memory_usage.v, e->memory_usage);
|
||||
|
||||
@ -710,7 +710,7 @@ INTERNAL void cache_entry_load_sheet(struct cache_ref ref, S_Tag tag)
|
||||
P_Unlock(&bin_lock);
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -796,9 +796,9 @@ S_Scope *sprite_scope_begin(void)
|
||||
bins = res->ref_node_bins;
|
||||
pool = res->ref_node_pool;
|
||||
} else {
|
||||
res = arena_push_no_zero(G.scopes_arena, S_Scope);
|
||||
bins = arena_push_array_no_zero(G.scopes_arena, struct sprite_scope_cache_ref *, CACHE_BINS_COUNT);
|
||||
pool = arena_push_array_no_zero(G.scopes_arena, struct sprite_scope_cache_ref, MAX_SCOPE_REFERENCES);
|
||||
res = PushStructNoZero(G.scopes_arena, S_Scope);
|
||||
bins = PushArrayNoZero(G.scopes_arena, struct sprite_scope_cache_ref *, CACHE_BINS_COUNT);
|
||||
pool = PushArrayNoZero(G.scopes_arena, struct sprite_scope_cache_ref, MAX_SCOPE_REFERENCES);
|
||||
}
|
||||
}
|
||||
P_Unlock(&lock);
|
||||
@ -917,7 +917,7 @@ INTERNAL struct sprite_scope_cache_ref *cache_entry_from_tag(S_Scope *scope, S_T
|
||||
entry = G.cache.entry_pool_first_free;
|
||||
G.cache.entry_pool_first_free = entry->next_free;
|
||||
} else {
|
||||
entry = arena_push_no_zero(G.cache.arena, struct cache_entry);
|
||||
entry = PushStructNoZero(G.cache.arena, struct cache_entry);
|
||||
}
|
||||
P_Unlock(&pool_lock);
|
||||
}
|
||||
@ -1217,9 +1217,9 @@ INTERNAL P_JobDef(sprite_evictor_job, _)
|
||||
while (!shutdown) {
|
||||
{
|
||||
__profn("Sprite evictor cycle");
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
u64 evict_array_count = 0;
|
||||
struct evict_node *evict_array = arena_push_dry(scratch.arena, struct evict_node);
|
||||
struct evict_node *evict_array = PushDry(scratch.arena, struct evict_node);
|
||||
{
|
||||
i32 cur_cycle = atomic32_fetch(&G.evictor_cycle.v);
|
||||
|
||||
@ -1244,7 +1244,7 @@ INTERNAL P_JobDef(sprite_evictor_job, _)
|
||||
#endif
|
||||
b32 is_old = cache_over_budget_threshold && ((cur_cycle - refcount.last_ref_cycle) > EVICTOR_GRACE_PERIOD_CYCLES);
|
||||
if (is_old || is_out_of_date) {
|
||||
struct evict_node *en = arena_push(scratch.arena, struct evict_node);
|
||||
struct evict_node *en = PushStruct(scratch.arena, struct evict_node);
|
||||
en->cache_entry = n;
|
||||
en->cache_bin = bin;
|
||||
en->last_ref_cycle = refcount.last_ref_cycle;
|
||||
@ -1263,7 +1263,7 @@ INTERNAL P_JobDef(sprite_evictor_job, _)
|
||||
}
|
||||
|
||||
/* Scratch arena should only contain evict array at this point */
|
||||
ASSERT(((arena_base(scratch.arena) + scratch.arena->pos) - (sizeof(*evict_array) * evict_array_count)) == (u8 *)evict_array);
|
||||
ASSERT(((ArenaBase(scratch.arena) + scratch.arena->pos) - (sizeof(*evict_array) * evict_array_count)) == (u8 *)evict_array);
|
||||
|
||||
/* Sort evict nodes */
|
||||
{
|
||||
@ -1326,7 +1326,7 @@ INTERNAL P_JobDef(sprite_evictor_job, _)
|
||||
if (n->kind == CACHE_ENTRY_KIND_TEXTURE && n->texture->valid) {
|
||||
gp_resource_release(n->texture->gp_texture);
|
||||
}
|
||||
arena_release(n->arena);
|
||||
ReleaseArena(n->arena);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1344,7 +1344,7 @@ INTERNAL P_JobDef(sprite_evictor_job, _)
|
||||
}
|
||||
}
|
||||
atomic32_fetch_add(&G.evictor_cycle.v, 1);
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* Evictor sleep */
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "../platform/platform.h"
|
||||
#include "../bitbuff/bitbuff.h"
|
||||
|
||||
#include "tar_core.h"
|
||||
|
||||
|
||||
@ -64,14 +64,14 @@ struct tar_archive tar_parse(Arena *arena, String data, String prefix)
|
||||
__prof;
|
||||
|
||||
struct tar_archive archive = ZI;
|
||||
Bitbuff bb = bitbuff_from_string(data);
|
||||
BitbuffReader br = br_from_bitbuff_no_debug(&bb);
|
||||
BB_Buff bb = BitbuffFromString(data);
|
||||
BB_Reader br = BB_ReaderFromBuffNoDebug(&bb);
|
||||
|
||||
u64 num_files = 0;
|
||||
while (br_num_bytes_left(&br) > 1024) {
|
||||
while (BB_NumBytesRemaining(&br) > 1024) {
|
||||
|
||||
struct tar_header header = ZI;
|
||||
br_read_bytes(&br, STRING_FROM_STRUCT(&header));
|
||||
BB_ReadBytes(&br, STRING_FROM_STRUCT(&header));
|
||||
|
||||
if (!string_eq(STRING_FROM_ARRAY(header.ustar_indicator), LIT("ustar\0"))) {
|
||||
/* Invalid header */
|
||||
@ -88,7 +88,7 @@ struct tar_archive tar_parse(Arena *arena, String data, String prefix)
|
||||
String file_size_oct_str = { .len = 11, .text = header.file_size };
|
||||
|
||||
u64 file_size = str_oct_to_u64(file_size_oct_str);
|
||||
u8 *file_data_ptr = br_read_bytes_raw(&br, file_size);
|
||||
u8 *file_data_ptr = BB_ReadBytesRaw(&br, file_size);
|
||||
if (!file_data_ptr) {
|
||||
file_size = 0;
|
||||
}
|
||||
@ -96,7 +96,7 @@ struct tar_archive tar_parse(Arena *arena, String data, String prefix)
|
||||
|
||||
/* Skip sector padding */
|
||||
u64 remaining = (512 - (file_size % 512)) % 512;
|
||||
br_seek_bytes(&br, remaining);
|
||||
BB_SeekBytes(&br, remaining);
|
||||
|
||||
b32 is_dir = header.file_type == TAR_TYPE_DIRECTORY;
|
||||
if (!is_dir && header.file_type != TAR_TYPE_FILE) {
|
||||
@ -114,7 +114,7 @@ struct tar_archive tar_parse(Arena *arena, String data, String prefix)
|
||||
}
|
||||
String file_name = string_cat(arena, prefix, file_name_cstr);
|
||||
|
||||
struct tar_entry *entry = arena_push(arena, struct tar_entry);
|
||||
struct tar_entry *entry = PushStruct(arena, struct tar_entry);
|
||||
entry->valid = 1;
|
||||
entry->is_dir = is_dir;
|
||||
entry->file_name = file_name;
|
||||
|
||||
@ -152,7 +152,7 @@ TTF_Result ttf_decode(Arena *arena, String encoded, f32 point_size, u32 *cache_c
|
||||
}
|
||||
|
||||
/* Allocate font memory */
|
||||
TTF_Glyph *glyphs = (TTF_Glyph *)arena_push_array(arena, TTF_Glyph, glyph_count);
|
||||
TTF_Glyph *glyphs = (TTF_Glyph *)PushArray(arena, TTF_Glyph, glyph_count);
|
||||
|
||||
/* Allocate (starting) atlas memory
|
||||
* NOTE: This is unecessary since atlas memory will grow anyway. Could
|
||||
@ -160,7 +160,7 @@ TTF_Result ttf_decode(Arena *arena, String encoded, f32 point_size, u32 *cache_c
|
||||
*/
|
||||
u64 atlas_w = 1024;
|
||||
u64 atlas_h = 1;
|
||||
u32 *atlas_memory = arena_push_array(arena, u32, atlas_w * atlas_h);
|
||||
u32 *atlas_memory = PushArray(arena, u32, atlas_w * atlas_h);
|
||||
|
||||
/* Fill CPU side atlas & metric data */
|
||||
u32 out_offset_x = 0;
|
||||
@ -229,7 +229,7 @@ TTF_Result ttf_decode(Arena *arena, String encoded, f32 point_size, u32 *cache_c
|
||||
u64 diff = (out_offset_y + tex_h) - atlas_h;
|
||||
/* NOTE: This allocation must be contiguous with the initial atlas
|
||||
* allocation (IE: No non-atlas arena PUSHes) */
|
||||
arena_push_array(arena, u32, diff * atlas_w);
|
||||
PushArray(arena, u32, diff * atlas_w);
|
||||
atlas_h += diff;
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ TTF_Result ttf_decode(Arena *arena, String encoded, f32 point_size, u32 *cache_c
|
||||
/* Construct indices array */
|
||||
u16 *cache_indices = 0;
|
||||
if (cache_codes_count > 0) {
|
||||
cache_indices = arena_push_array(arena, u16, cache_codes_count);
|
||||
cache_indices = PushArray(arena, u16, cache_codes_count);
|
||||
font_face->GetGlyphIndices(cache_codes, cache_codes_count, cache_indices);
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
|
||||
|
||||
gstat_set(GSTAT_DEBUG_STEPS, U64_MAX);
|
||||
|
||||
G.arena = arena_alloc(GIBI(64));
|
||||
G.arena = AllocArena(GIBI(64));
|
||||
G.real_time_ns = P_TimeNs();
|
||||
|
||||
/* TODO: Remove this */
|
||||
@ -224,7 +224,7 @@ struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
|
||||
G.world_to_render_xf = XFORM_IDENT;
|
||||
G.render_sig = gp_render_sig_alloc();
|
||||
|
||||
G.console_logs_arena = arena_alloc(GIBI(64));
|
||||
G.console_logs_arena = AllocArena(GIBI(64));
|
||||
//P_RegisterLogCallback(debug_console_log_callback, P_LogLevel_Success);
|
||||
P_RegisterLogCallback(debug_console_log_callback, P_LogLevel_Debug);
|
||||
|
||||
@ -295,13 +295,13 @@ INTERNAL void debug_draw_movement(Ent *ent)
|
||||
|
||||
INTERNAL String get_ent_debug_text(Arena *arena, Ent *ent)
|
||||
{
|
||||
TempArena scratch = scratch_begin(arena);
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
Snapshot *ss = ent->ss;
|
||||
|
||||
const u8 hex[] = "0123456789abcdef";
|
||||
|
||||
String res = ZI;
|
||||
res.text = arena_push_dry(arena, u8);
|
||||
res.text = PushDry(arena, u8);
|
||||
|
||||
res.len += string_format(arena, LIT("[%F]"), FMT_UID(ent->id.uid)).len;
|
||||
{
|
||||
@ -377,7 +377,7 @@ INTERNAL String get_ent_debug_text(Arena *arena, Ent *ent)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ INTERNAL P_LogEventCallbackFuncDef(debug_console_log_callback, log)
|
||||
__prof;
|
||||
P_Lock lock = P_LockE(&G.console_logs_mutex);
|
||||
{
|
||||
struct console_log *clog = arena_push(G.console_logs_arena, struct console_log);
|
||||
struct console_log *clog = PushStruct(G.console_logs_arena, struct console_log);
|
||||
clog->level = log.level;
|
||||
clog->msg = string_copy(G.console_logs_arena, log.msg);
|
||||
clog->datetime = log.datetime;
|
||||
@ -414,7 +414,7 @@ INTERNAL P_LogEventCallbackFuncDef(debug_console_log_callback, log)
|
||||
INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
V2 desired_start_pos = V2FromXY(10, minimized ? 100 : 600);
|
||||
i64 fade_time_ns = NS_FROM_SECONDS(10);
|
||||
@ -501,7 +501,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
||||
if (bounds_top < F32_INFINITY && bounds_bottom > -F32_INFINITY) {
|
||||
G.console_logs_height = bounds_bottom - bounds_top;
|
||||
}
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -552,7 +552,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
{
|
||||
__prof;
|
||||
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
/* ========================== *
|
||||
* Begin frame
|
||||
@ -1134,7 +1134,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
* Sort drawable entities
|
||||
* ========================== */
|
||||
|
||||
Ent **sorted = arena_push_dry(scratch.arena, Ent *);
|
||||
Ent **sorted = PushDry(scratch.arena, Ent *);
|
||||
u64 sorted_count = 0;
|
||||
{
|
||||
/* Copy valid entities */
|
||||
@ -1143,7 +1143,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) {
|
||||
Ent *ent = &G.ss_blended->ents[ent_index];
|
||||
if (sim_ent_is_valid_and_active(ent)) {
|
||||
*arena_push_no_zero(scratch.arena, Ent *) = ent;
|
||||
*PushStructNoZero(scratch.arena, Ent *) = ent;
|
||||
++sorted_count;
|
||||
}
|
||||
}
|
||||
@ -1264,7 +1264,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
|
||||
/* Debug draw entity info */
|
||||
if (G.debug_draw && !skip_debug_draw) {
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
debug_draw_movement(ent);
|
||||
@ -1684,7 +1684,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
draw_quad_line(G.render_sig, quad, thickness, color);
|
||||
}
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1904,14 +1904,14 @@ INTERNAL void user_update(P_Window *window)
|
||||
V2 pos = v2_add(G.ui_cursor, V2FromXY(15, 15));
|
||||
F_Font *font = font_load_async(LIT("font/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
|
||||
String dbg_text = ZI;
|
||||
dbg_text.text = arena_push_dry(temp.arena, u8);
|
||||
dbg_text.text = PushDry(temp.arena, u8);
|
||||
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
|
||||
draw_text(G.render_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1929,12 +1929,12 @@ INTERNAL void user_update(P_Window *window)
|
||||
__profn("Draw debug info");
|
||||
F_Font *font = font_load_async(LIT("font/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
String text = ZI;
|
||||
text.text = arena_push_dry(temp.arena, u8);
|
||||
text.text = PushDry(temp.arena, u8);
|
||||
|
||||
#if BITBUFF_DEBUG
|
||||
text.len += string_format(temp.arena, LIT("(bitbuff debug enabled)")).len;
|
||||
#if BB_DebugIsEnabled
|
||||
text.len += string_copy(temp.arena, LIT("(bitbuff debug enabled)")).len;
|
||||
text.len += string_copy(temp.arena, LIT("\n")).len;
|
||||
#endif
|
||||
|
||||
@ -2030,7 +2030,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
V2 pos = V2FromXY(10, G.ui_size.y);
|
||||
D_TextOffsetY offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
||||
draw_text(G.render_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2078,7 +2078,7 @@ INTERNAL void user_update(P_Window *window)
|
||||
|
||||
sprite_scope_end(sprite_frame_scope);
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
INTERNAL P_JobDef(user_update_job, _)
|
||||
@ -2203,8 +2203,8 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
is_master = 1;
|
||||
}
|
||||
|
||||
Bitbuff msg_writer_bb = bitbuff_alloc(GIBI(64));
|
||||
Bitbuff snapshot_writer_bb = bitbuff_alloc(GIBI(64));
|
||||
BB_Buff msg_writer_bb = AllocBitbuff(GIBI(64));
|
||||
BB_Buff snapshot_writer_bb = AllocBitbuff(GIBI(64));
|
||||
SimAccel accel = sim_accel_alloc();
|
||||
|
||||
ClientStore *store = sim_client_store_alloc();
|
||||
@ -2257,7 +2257,7 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
i64 step_dt_ns = NS_FROM_SECONDS(1) / SIM_TICKS_PER_SECOND;
|
||||
f64 compute_timescale = 1.0;
|
||||
while (!atomic32_fetch(&G.shutdown)) {
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
{
|
||||
__profn("Sim sleep");
|
||||
P_SleepFrame(real_time_ns, step_dt_ns * compute_timescale);
|
||||
@ -2302,11 +2302,11 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
case HOST_EVENT_KIND_MSG:
|
||||
{
|
||||
if (client->valid) {
|
||||
Bitbuff msg_bb = bitbuff_from_string(event->msg);
|
||||
BitbuffReader msg_br = br_from_bitbuff(&msg_bb);
|
||||
BB_Buff msg_bb = BitbuffFromString(event->msg);
|
||||
BB_Reader msg_br = BB_ReaderFromBuff(&msg_bb);
|
||||
|
||||
u64 ack = br_read_uv(&msg_br);
|
||||
u64 double_ack = br_read_uv(&msg_br);
|
||||
u64 ack = BB_ReadUV(&msg_br);
|
||||
u64 double_ack = BB_ReadUV(&msg_br);
|
||||
if (ack > client->ack) {
|
||||
client->ack = ack;
|
||||
}
|
||||
@ -2315,19 +2315,19 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
}
|
||||
|
||||
/* Read & queue incoming snapshots for decoding */
|
||||
u64 tmp_encoded_len = br_read_uv(&msg_br);
|
||||
u64 tmp_encoded_len = BB_ReadUV(&msg_br);
|
||||
while (tmp_encoded_len > 0) {
|
||||
u8 *tmp_encoded_bytes = br_read_bytes_raw(&msg_br, tmp_encoded_len);
|
||||
u8 *tmp_encoded_bytes = BB_ReadBytesRaw(&msg_br, tmp_encoded_len);
|
||||
if (!tmp_encoded_bytes) break;
|
||||
|
||||
Bitbuff decoder_bb = bitbuff_from_string(STRING(tmp_encoded_len, tmp_encoded_bytes));
|
||||
BitbuffReader decoder_br = br_from_bitbuff(&decoder_bb);
|
||||
u64 base_tick = br_read_uv(&decoder_br);
|
||||
u64 tick = br_read_uv(&decoder_br);
|
||||
BB_Buff decoder_bb = BitbuffFromString(STRING(tmp_encoded_len, tmp_encoded_bytes));
|
||||
BB_Reader decoder_br = BB_ReaderFromBuff(&decoder_bb);
|
||||
u64 base_tick = BB_ReadUV(&decoder_br);
|
||||
u64 tick = BB_ReadUV(&decoder_br);
|
||||
|
||||
String tmp_encoded = ZI;
|
||||
tmp_encoded.len = br_num_bytes_left(&decoder_br);
|
||||
tmp_encoded.text = br_read_bytes_raw(&decoder_br, tmp_encoded.len);
|
||||
tmp_encoded.len = BB_NumBytesRemaining(&decoder_br);
|
||||
tmp_encoded.text = BB_ReadBytesRaw(&decoder_br, tmp_encoded.len);
|
||||
if (!tmp_encoded.text) tmp_encoded.len = 0;
|
||||
|
||||
Snapshot *base_ss = sim_snapshot_from_tick(client, base_tick);
|
||||
@ -2337,7 +2337,7 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
//b32 should_decode = tick == client->highest_received_tick + 1 || client->highest_received_tick == 0;
|
||||
b32 should_decode = tick > client->highest_received_tick;
|
||||
if (should_decode) {
|
||||
struct sim_ss_decode_node *node = arena_push(scratch.arena, struct sim_ss_decode_node);
|
||||
struct sim_ss_decode_node *node = PushStruct(scratch.arena, struct sim_ss_decode_node);
|
||||
node->client = client;
|
||||
node->tick = tick;
|
||||
node->base_tick = base_tick;
|
||||
@ -2356,7 +2356,7 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
/* Decode incoming master client snapshots for decoding (only the newest one) */
|
||||
b32 should_decode = client == master_client && tick > client->highest_received_tick;
|
||||
if (should_decode) {
|
||||
struct sim_ss_decode_node *node = queue.first ? queue.first : arena_push(scratch.arena, struct sim_ss_decode_node);
|
||||
struct sim_ss_decode_node *node = queue.first ? queue.first : PushStruct(scratch.arena, struct sim_ss_decode_node);
|
||||
node->client = client;
|
||||
node->tick = tick;
|
||||
node->base_tick = base_tick;
|
||||
@ -2380,7 +2380,7 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tmp_encoded_len = br_read_uv(&msg_br);
|
||||
tmp_encoded_len = BB_ReadUV(&msg_br);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
@ -2397,8 +2397,8 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
u64 tick = n->tick;
|
||||
Snapshot *base_ss = sim_snapshot_from_tick(client, base_tick);
|
||||
if (base_ss->tick == base_tick) {
|
||||
Bitbuff bb = bitbuff_from_string(n->tmp_encoded);
|
||||
BitbuffReader br = br_from_bitbuff(&bb);
|
||||
BB_Buff bb = BitbuffFromString(n->tmp_encoded);
|
||||
BB_Reader br = BB_ReaderFromBuff(&bb);
|
||||
|
||||
/* Alloc & decode snapshot */
|
||||
Snapshot *ss = sim_snapshot_alloc(client, base_ss, tick);
|
||||
@ -2707,10 +2707,10 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
for (u64 i = 0; i < store->num_clients_reserved; ++i) {
|
||||
Client *client = &store->clients[i];
|
||||
if (client->valid && client != user_input_client && client != local_client && client != publish_client) {
|
||||
BitbuffWriter msg_bw = bw_from_bitbuff(&msg_writer_bb);
|
||||
BB_Writer msg_bw = BB_WriterFromBuff(&msg_writer_bb);
|
||||
|
||||
bw_write_uv(&msg_bw, client->highest_received_tick); /* ack */
|
||||
bw_write_uv(&msg_bw, client->ack); /* double ack */
|
||||
BB_WriteUV(&msg_bw, client->highest_received_tick); /* ack */
|
||||
BB_WriteUV(&msg_bw, client->ack); /* double ack */
|
||||
|
||||
Snapshot *base_ss = sim_snapshot_from_tick(publish_client, client->ack);
|
||||
Snapshot *publish_ss;
|
||||
@ -2723,24 +2723,24 @@ INTERNAL P_JobDef(local_sim_job, _)
|
||||
}
|
||||
|
||||
while (publish_ss->valid) {
|
||||
BitbuffWriter snapshot_bw = bw_from_bitbuff(&snapshot_writer_bb);
|
||||
BB_Writer snapshot_bw = BB_WriterFromBuff(&snapshot_writer_bb);
|
||||
String tmp_snapshot_encoded = ZI;
|
||||
{
|
||||
bw_write_uv(&snapshot_bw, base_ss->tick);
|
||||
bw_write_uv(&snapshot_bw, publish_ss->tick);
|
||||
BB_WriteUV(&snapshot_bw, base_ss->tick);
|
||||
BB_WriteUV(&snapshot_bw, publish_ss->tick);
|
||||
sim_snapshot_encode(&snapshot_bw, client, base_ss, publish_ss);
|
||||
tmp_snapshot_encoded.len = bw_num_bytes_written(&snapshot_bw);
|
||||
tmp_snapshot_encoded.text = bw_get_written_raw(&snapshot_bw);
|
||||
tmp_snapshot_encoded.len = BB_GetNumBytesWritten(&snapshot_bw);
|
||||
tmp_snapshot_encoded.text = BB_GetWrittenRaw(&snapshot_bw);
|
||||
}
|
||||
bw_write_uv(&msg_bw, tmp_snapshot_encoded.len);
|
||||
bw_write_bytes(&msg_bw, tmp_snapshot_encoded);
|
||||
BB_WriteUV(&msg_bw, tmp_snapshot_encoded.len);
|
||||
BB_WriteBytes(&msg_bw, tmp_snapshot_encoded);
|
||||
publish_ss = sim_snapshot_from_tick(publish_client, publish_ss->tick + 1);
|
||||
}
|
||||
bw_write_uv(&msg_bw, 0);
|
||||
BB_WriteUV(&msg_bw, 0);
|
||||
|
||||
String encoded = ZI;
|
||||
encoded.len = bw_num_bytes_written(&msg_bw);
|
||||
encoded.text = bw_get_written_raw(&msg_bw);
|
||||
encoded.len = BB_GetNumBytesWritten(&msg_bw);
|
||||
encoded.text = BB_GetWrittenRaw(&msg_bw);
|
||||
host_queue_write(host, client->channel_id, encoded, 0);
|
||||
}
|
||||
}
|
||||
@ -2770,13 +2770,13 @@ skip_step:
|
||||
host_update_end(host);
|
||||
__profframe("Local sim");
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
sim_client_store_release(store);
|
||||
sim_accel_release(&accel);
|
||||
bitbuff_release(&snapshot_writer_bb);
|
||||
bitbuff_release(&msg_writer_bb);
|
||||
ReleaseBitbuff(&snapshot_writer_bb);
|
||||
ReleaseBitbuff(&msg_writer_bb);
|
||||
host_release(host);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ void watch_startup(void)
|
||||
{
|
||||
G.watch = P_AllocWatch(LIT("./"));
|
||||
|
||||
G.watch_events_arena = arena_alloc(GIBI(64));
|
||||
G.watch_events_arena = AllocArena(GIBI(64));
|
||||
|
||||
P_Run(1, watch_monitor_job, 0, P_Pool_Floating, P_Priority_Low, &G.watch_jobs_counter);
|
||||
P_Run(1, watch_dispatcher_job, 0, P_Pool_Background, P_Priority_Low, &G.watch_jobs_counter);
|
||||
@ -74,7 +74,7 @@ void watch_register_callback(watch_callback *callback)
|
||||
INTERNAL P_JobDef(watch_monitor_job, _)
|
||||
{
|
||||
(UNUSED)_;
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
|
||||
String ignored[] = {
|
||||
LIT(".vs"),
|
||||
@ -82,7 +82,7 @@ INTERNAL P_JobDef(watch_monitor_job, _)
|
||||
};
|
||||
|
||||
while (!atomic32_fetch(&G.watch_shutdown)) {
|
||||
TempArena temp = arena_temp_begin(scratch.arena);
|
||||
TempArena temp = BeginTempArena(scratch.arena);
|
||||
P_WatchInfoList info_list = P_ReadWatchWait(temp.arena, G.watch);
|
||||
if (info_list.first && !atomic32_fetch(&G.watch_shutdown)) {
|
||||
P_Lock lock = P_LockE(&G.watch_dispatcher_mutex);
|
||||
@ -97,7 +97,7 @@ INTERNAL P_JobDef(watch_monitor_job, _)
|
||||
}
|
||||
}
|
||||
if (!ignore) {
|
||||
struct watch_event *e = arena_push(G.watch_events_arena, struct watch_event);
|
||||
struct watch_event *e = PushStruct(G.watch_events_arena, struct watch_event);
|
||||
e->name = string_copy(G.watch_events_arena, name_src);
|
||||
if (G.last_watch_event) {
|
||||
G.last_watch_event->next = e;
|
||||
@ -111,10 +111,10 @@ INTERNAL P_JobDef(watch_monitor_job, _)
|
||||
P_SignalCv(&G.watch_dispatcher_cv, I32_MAX);
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
arena_temp_end(temp);
|
||||
EndTempArena(temp);
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* NOTE: We separate the responsibilities of monitoring directory changes
|
||||
@ -145,7 +145,7 @@ INTERNAL P_JobDef(watch_dispatcher_job, _)
|
||||
b32 shutdown = 0;
|
||||
while (!shutdown) {
|
||||
{
|
||||
TempArena scratch = scratch_begin_no_conflict();
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
struct watch_event *first_watch_event = 0;
|
||||
struct watch_event *last_watch_event = 0;
|
||||
|
||||
@ -159,7 +159,7 @@ INTERNAL P_JobDef(watch_dispatcher_job, _)
|
||||
{
|
||||
P_Lock lock = P_LockE(&G.watch_dispatcher_mutex);
|
||||
for (struct watch_event *src_event = G.first_watch_event; src_event; src_event = src_event->next) {
|
||||
struct watch_event *e = arena_push(scratch.arena, struct watch_event);
|
||||
struct watch_event *e = PushStruct(scratch.arena, struct watch_event);
|
||||
e->name = string_copy(scratch.arena, src_event->name);
|
||||
if (last_watch_event) {
|
||||
last_watch_event->next = e;
|
||||
@ -170,7 +170,7 @@ INTERNAL P_JobDef(watch_dispatcher_job, _)
|
||||
}
|
||||
G.first_watch_event = 0;
|
||||
G.last_watch_event = 0;
|
||||
arena_reset(G.watch_events_arena);
|
||||
ResetArena(G.watch_events_arena);
|
||||
P_Unlock(&lock);
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ INTERNAL P_JobDef(watch_dispatcher_job, _)
|
||||
P_Lock callbacks_lock = P_LockS(&G.watch_callbacks_mutex);
|
||||
{
|
||||
num_callbacks = G.num_watch_callbacks;
|
||||
callbacks = arena_push_array_no_zero(scratch.arena, watch_callback *, num_callbacks);
|
||||
callbacks = PushArrayNoZero(scratch.arena, watch_callback *, num_callbacks);
|
||||
for (u64 i = 0; i < num_callbacks; ++i) {
|
||||
callbacks[i] = G.watch_callbacks[i];
|
||||
}
|
||||
@ -211,7 +211,7 @@ INTERNAL P_JobDef(watch_dispatcher_job, _)
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
/* Wait for event */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user