rename temp_arena -> arena_temp
This commit is contained in:
parent
df4eb24fe3
commit
05668865a7
2
.natvis
2
.natvis
@ -23,7 +23,7 @@
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name = "temp_arena">
|
||||
<Type Name = "arena_temp">
|
||||
<DisplayString>start: {start_pos}, arena: {{{*arena}}}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="Data">(arena->base + start_pos), [arena->pos - start_pos] s</Item>
|
||||
|
||||
10
src/app.c
10
src/app.c
@ -49,7 +49,7 @@ GLOBAL struct {
|
||||
|
||||
INTERNAL struct string initialize_write_directory(struct arena *arena, struct string write_dir)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
/* Create write path */
|
||||
struct string base_write_dir = sys_get_write_path(scratch.arena);
|
||||
@ -208,7 +208,7 @@ INTERNAL struct app_arg_list parse_args(struct arena *arena, struct string args_
|
||||
|
||||
void app_entry_point(struct string args_str)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct app_arg_list args = parse_args(scratch.arena, args_str);
|
||||
struct string logfile_name = LIT("log.log");
|
||||
@ -266,7 +266,7 @@ void app_entry_point(struct string args_str)
|
||||
|
||||
/* Startup logging */
|
||||
{
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct string logfile_dir = string_cat(temp.arena, G.write_path, LIT("logs/"));
|
||||
struct string logfile_path = string_cat(temp.arena, logfile_dir, logfile_name);
|
||||
@ -286,7 +286,7 @@ void app_entry_point(struct string args_str)
|
||||
|
||||
/* Read window settings from file */
|
||||
{
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct sys_window_settings window_settings = ZI;
|
||||
struct string settings_path = app_write_path_cat(temp.arena, settings_file_name);
|
||||
@ -381,7 +381,7 @@ void app_entry_point(struct string args_str)
|
||||
/* Write window settings to file */
|
||||
{
|
||||
__profscope(app_write_to_settings_file);
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct string window_settings_path = app_write_path_cat(temp.arena, settings_file_name);
|
||||
|
||||
|
||||
15
src/arena.h
15
src/arena.h
@ -13,10 +13,10 @@
|
||||
#define arena_pop_array(a, type, n, dest) arena_pop_struct((a), sizeof(type) * (n), dest)
|
||||
|
||||
/* Returns a pointer to where the next allocation would be (at alignment of type).
|
||||
* Equivalent to arena_push but without actually allocating anything. */
|
||||
#define arena_dry_push(a, type) (type *)(_arena_dry_push((a), alignof(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 temp_arena {
|
||||
struct arena_temp {
|
||||
struct arena *arena;
|
||||
u64 start_pos;
|
||||
|
||||
@ -65,7 +65,6 @@ INLINE void arena_pop_struct(struct arena *arena, u64 size, void *copy_dest)
|
||||
INLINE void *arena_align(struct arena *arena, u64 align)
|
||||
{
|
||||
ASSERT(!arena->readonly);
|
||||
|
||||
if (align > 0) {
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
@ -82,15 +81,15 @@ INLINE void *arena_align(struct arena *arena, u64 align)
|
||||
}
|
||||
}
|
||||
|
||||
INLINE struct temp_arena arena_temp_begin(struct arena *arena)
|
||||
INLINE struct arena_temp arena_temp_begin(struct arena *arena)
|
||||
{
|
||||
struct temp_arena t = ZI;
|
||||
struct arena_temp t = ZI;
|
||||
t.arena = arena;
|
||||
t.start_pos = arena->pos;
|
||||
return t;
|
||||
}
|
||||
|
||||
INLINE void arena_temp_end(struct temp_arena temp)
|
||||
INLINE void arena_temp_end(struct arena_temp temp)
|
||||
{
|
||||
arena_pop_to(temp.arena, temp.start_pos);
|
||||
}
|
||||
@ -108,7 +107,7 @@ INLINE struct string arena_to_string(struct arena *arena)
|
||||
return b;
|
||||
}
|
||||
|
||||
INLINE void *_arena_dry_push(struct arena *arena, u64 align)
|
||||
INLINE void *_arena_push_dry(struct arena *arena, u64 align)
|
||||
{
|
||||
u64 aligned_start_pos = (arena->pos + (align - 1));
|
||||
aligned_start_pos -= aligned_start_pos % align;
|
||||
|
||||
@ -242,7 +242,7 @@ INTERNAL u16 huffman_decode(struct huffman *huffman, struct huff_bb *bb)
|
||||
|
||||
INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
__prof;
|
||||
struct huff_bb bb = { .data = encoded };
|
||||
@ -275,7 +275,7 @@ INTERNAL void inflate(u8 *dst, u8 *encoded)
|
||||
|
||||
case BLOCK_TYPE_COMPRESSED_FIXED:
|
||||
case BLOCK_TYPE_COMPRESSED_DYNAMIC: {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
u32 lit_len_dist_table[512] = ZI;
|
||||
u32 hlit;
|
||||
u32 hdist;
|
||||
@ -553,7 +553,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct stri
|
||||
{
|
||||
__prof;
|
||||
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
struct ase_decode_image_result res = ZI;
|
||||
|
||||
struct bitbuff bb = bitbuff_from_string(encoded);
|
||||
|
||||
@ -687,7 +687,7 @@ void br_read_dbg_marker(struct bitbuff_reader *br, struct string name)
|
||||
|
||||
void bitbuff_test(void)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
u8 kind_ubits = 0;
|
||||
u8 kind_ibits = 1;
|
||||
|
||||
@ -325,7 +325,7 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(struct collider_shape *shape0
|
||||
INTERNAL struct epa_result epa_get_normal_from_gjk(struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1, struct gjk_result gjk_res, f32 min_unique_pt_dist_sq, u32 max_iterations)
|
||||
#endif
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct collider_menkowski_feature closest_feature = ZI;
|
||||
struct v2 normal = ZI;
|
||||
@ -334,7 +334,7 @@ INTERNAL struct epa_result epa_get_normal_from_gjk(struct collider_shape *shape0
|
||||
u32 proto_count = 0;
|
||||
if (gjk_res.overlapping) {
|
||||
struct collider_menkowski_simplex s = gjk_res.simplex;
|
||||
proto = arena_dry_push(scratch.arena, struct collider_menkowski_point);
|
||||
proto = arena_push_dry(scratch.arena, struct collider_menkowski_point);
|
||||
{
|
||||
ASSERT(s.len == 3);
|
||||
struct collider_menkowski_point *tmp = arena_push_array_no_zero(scratch.arena, struct collider_menkowski_point, 3);
|
||||
@ -946,7 +946,7 @@ f32 collider_time_of_impact(struct collider_shape *c0, struct collider_shape *c1
|
||||
/* TODO: Remove this (debugging) */
|
||||
struct v2_array menkowski(struct arena *arena, struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1, u32 detail)
|
||||
{
|
||||
struct v2_array res = { .points = arena_dry_push(arena, struct v2) };
|
||||
struct v2_array res = { .points = arena_push_dry(arena, struct v2) };
|
||||
for (u64 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / detail) * (2 * PI);
|
||||
struct v2 dir = v2_from_angle(angle);
|
||||
@ -963,7 +963,7 @@ struct v2_array menkowski(struct arena *arena, struct collider_shape *shape0, st
|
||||
struct v2_array cloud(struct arena *arena, struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1)
|
||||
{
|
||||
/* FIXME: Account for radius */
|
||||
struct v2_array res = { .points = arena_dry_push(arena, struct v2) };
|
||||
struct v2_array res = { .points = arena_push_dry(arena, struct v2) };
|
||||
struct v2 *points0 = shape0->points;
|
||||
struct v2 *points1 = shape1->points;
|
||||
u32 count0 = shape0->count;
|
||||
|
||||
12
src/draw.c
12
src/draw.c
@ -71,7 +71,7 @@ void draw_poly_ex(struct gpu_handle cmd_list, struct v2_array vertices, struct g
|
||||
void draw_poly(struct gpu_handle cmd_list, struct v2_array vertices, u32 color)
|
||||
{
|
||||
if (vertices.count >= 3) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
u32 num_tris = vertices.count - 2;
|
||||
u32 num_indices = num_tris * 3;
|
||||
@ -96,7 +96,7 @@ void draw_poly(struct gpu_handle cmd_list, struct v2_array vertices, u32 color)
|
||||
|
||||
void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct v2 *points = arena_push_array_no_zero(scratch.arena, struct v2, detail);
|
||||
for(u32 i = 0; i < detail; ++i) {
|
||||
@ -176,7 +176,7 @@ void draw_poly_line(struct gpu_handle cmd_list, struct v2_array points, b32 loop
|
||||
|
||||
void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct v2 *points = arena_push_array_no_zero(scratch.arena, struct v2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
@ -241,7 +241,7 @@ void draw_arrow_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f3
|
||||
|
||||
void draw_collider_line(struct gpu_handle cmd_list, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct v2 *points = arena_push_array_no_zero(scratch.arena, struct v2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
@ -285,7 +285,7 @@ void draw_grid(struct gpu_handle cmd_list, struct xform xf, u32 bg0_color, u32 b
|
||||
/* Returns the rect of the text area */
|
||||
struct rect draw_text(struct gpu_handle cmd_list, struct draw_text_params params)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
f32 inv_font_image_width = 1.0 / (f32)params.font->image_width;
|
||||
f32 inv_font_image_height = 1.0 / (f32)params.font->image_height;
|
||||
@ -327,7 +327,7 @@ struct rect draw_text(struct gpu_handle cmd_list, struct draw_text_params params
|
||||
f32 top_offset = 0;
|
||||
f32 bottom_offset = 0;
|
||||
u64 num_line_glyphs = 0;
|
||||
struct drawable_glyph *line_glyphs = arena_dry_push(scratch.arena, struct drawable_glyph);
|
||||
struct drawable_glyph *line_glyphs = arena_push_dry(scratch.arena, struct drawable_glyph);
|
||||
|
||||
b32 line_done = false;
|
||||
while (!line_done) {
|
||||
|
||||
@ -94,7 +94,7 @@ INTERNAL void font_task_params_release(struct font_task_params *p)
|
||||
INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct font_task_params *params = (struct font_task_params *)vparams;
|
||||
struct string path = STRING(params->path_len, (u8 *)params->path_cstr);
|
||||
@ -166,7 +166,7 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
||||
struct asset *font_load_asset(struct string path, f32 point_size, b32 help)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* Concatenate point_size to path for key */
|
||||
struct string key = string_format(scratch.arena,
|
||||
|
||||
@ -827,7 +827,7 @@ INTERNAL void dx11_include_handler_release(struct dx11_include_handler *handler)
|
||||
INTERNAL struct string shader_alloc(struct arena *arena, struct dx11_shader *shader, struct dx11_shader_desc *shader_desc, struct resource *src_res)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
struct string error_str = ZI;
|
||||
i64 start_ns = sys_time_ns();
|
||||
|
||||
@ -952,7 +952,7 @@ INTERNAL void shader_release(struct dx11_shader *shader)
|
||||
INTERNAL void reload_shader(struct dx11_shader *old_shader, struct dx11_shader_desc *desc)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
{
|
||||
struct string name = string_from_cstr_no_limit(desc->name_cstr);
|
||||
struct string error_msg = ZI;
|
||||
@ -1180,7 +1180,7 @@ INTERNAL struct dx11_buffer *dx11_buffer_alloc(struct D3D11_BUFFER_DESC desc, D3
|
||||
buffer->cpu_buffer_arena = cpu_buffer_arena;
|
||||
}
|
||||
buffer->desc = desc;
|
||||
buffer->cpu_buffer = arena_dry_push(&buffer->cpu_buffer_arena, u8);
|
||||
buffer->cpu_buffer = arena_push_dry(&buffer->cpu_buffer_arena, u8);
|
||||
|
||||
if (desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
|
||||
ASSERT(desc.StructureByteStride != 0); /* Must provide stride for shader resource buffers */
|
||||
@ -2138,7 +2138,7 @@ INTERNAL void gpu_capture_image_for_profiler(void)
|
||||
f32 width_frequency = (f32)read_cap->size.x / (f32)final_width;
|
||||
f32 height_frequency = (f32)read_cap->size.y / (f32)final_height;
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
u32 *source = res.pData;
|
||||
u32 *dest = arena_push_array_no_zero(scratch.arena, u32, final_width * final_height);
|
||||
|
||||
@ -253,7 +253,7 @@ void gpu_release(struct gpu_handle handle)
|
||||
|
||||
INTERNAL void dx12_init_error(struct string error)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string msg = string_format(scratch.arena, LIT("Failed to initialize DirectX 12.\n\n%F"), FMT_STR(error));
|
||||
sys_panic(msg);
|
||||
scratch_end(scratch);
|
||||
@ -262,7 +262,7 @@ INTERNAL void dx12_init_error(struct string error)
|
||||
INTERNAL void dx12_init_base(struct sys_window *window)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
HRESULT hr = 0;
|
||||
|
||||
/* Enable debug layer */
|
||||
@ -523,7 +523,7 @@ INTERNAL void dx12_shader_release(struct dx12_shader *shader);
|
||||
INTERNAL void dx12_init_shaders(void)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct dx12_shader_desc shader_descs[] = {
|
||||
/* Texture shader */
|
||||
{
|
||||
@ -660,7 +660,7 @@ INTERNAL WORK_TASK_FUNC_DEF(shader_compile_task, comp_arg_raw)
|
||||
enum shader_compile_task_kind kind = comp_arg->kind;
|
||||
struct resource *src_res = comp_arg->src_res;
|
||||
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
{
|
||||
b32 success = false;
|
||||
ID3DBlob *blob = NULL;
|
||||
@ -757,7 +757,7 @@ INTERNAL WORK_TASK_FUNC_DEF(shader_load_task, load_arg_raw)
|
||||
struct dx12_shader_desc desc = shader->desc;
|
||||
struct dx12_shader_result *result = load_arg->result;
|
||||
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
{
|
||||
struct string shader_name = string_from_cstr_no_limit(desc.name);
|
||||
logf_info("Loading shader '%F'", FMT_STR(shader_name));
|
||||
|
||||
@ -189,7 +189,7 @@ struct host *host_alloc(u16 listen_port)
|
||||
host->rcv_buffer_write->arena = arena_alloc(GIGABYTE(64));
|
||||
host->buddy = buddy_ctx_alloc(GIGABYTE(64));
|
||||
|
||||
host->channels = arena_dry_push(&host->channel_arena, struct host_channel);
|
||||
host->channels = arena_push_dry(&host->channel_arena, struct host_channel);
|
||||
|
||||
host->num_channel_lookup_bins = NUM_CHANNEL_LOOKUP_BINS;
|
||||
host->channel_lookup_bins = arena_push_array(&host->arena, struct host_channel_lookup_bin, host->num_channel_lookup_bins);
|
||||
@ -647,7 +647,7 @@ INTERNAL struct host_event *push_event(struct arena *arena, struct host_event_li
|
||||
/* Read incoming packets, update channels, and return events */
|
||||
struct host_event_list host_update_begin(struct arena *arena, struct host *host)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct host_event_list events = ZI;
|
||||
i64 now_ns = sys_time_ns();
|
||||
@ -898,7 +898,7 @@ struct host_event_list host_update_begin(struct arena *arena, struct host *host)
|
||||
void host_update_end(struct host *host)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* Process cmds into sendable packets */
|
||||
/* TODO: Unreliable packets don't need to be allocated into unreliable packet queue, should just send them and forget */
|
||||
|
||||
@ -25,7 +25,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)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct rc_search_params *params = (struct rc_search_params *)udata;
|
||||
struct string entry_name_lower = string_lower(scratch.arena, string_from_wstr_no_limit(scratch.arena, (LPWSTR)wstr_entry_name));
|
||||
params->found = false;
|
||||
@ -49,7 +49,7 @@ struct string _incbin_get(struct _incbin_rc_resource *inc)
|
||||
{
|
||||
enum inc_state state = atomic_i32_eval(&inc->state);
|
||||
if (state != INCBIN_STATE_SEARCHED) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
if (state == INCBIN_STATE_UNSEARCHED) {
|
||||
enum inc_state v = atomic_i32_eval_compare_exchange(&inc->state, state, INCBIN_STATE_SEARCHING);
|
||||
|
||||
@ -532,7 +532,7 @@ INTERNAL struct string interpret_string(struct arena *arena, struct string src,
|
||||
{
|
||||
struct string res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u8)
|
||||
.text = arena_push_dry(arena, u8)
|
||||
};
|
||||
|
||||
if (src.len < 2) {
|
||||
@ -667,7 +667,7 @@ INTERNAL void push_error(struct arena *arena, struct parser *p, struct token *t,
|
||||
|
||||
INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct json *root = arena_push(arena, struct json);
|
||||
struct token *at = p->at;
|
||||
@ -833,7 +833,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p)
|
||||
|
||||
struct json_parse_result json_from_string(struct arena *arena, struct string src)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct token_list tl = lex(scratch.arena, src);
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ INTERNAL void append_to_logfile(struct string msg)
|
||||
if (!atomic_i32_eval(&G.initialized)) { return; }
|
||||
|
||||
if (G.file_valid) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string msg_line = string_cat(scratch.arena, msg, LIT("\n"));
|
||||
sys_file_write(G.file, msg_line);
|
||||
scratch_end(scratch);
|
||||
@ -142,7 +142,7 @@ void _log(i32 level, struct string msg)
|
||||
sys_panic(LIT("Invalid log level"));
|
||||
}
|
||||
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct sys_datetime datetime = sys_local_time();
|
||||
i64 time_ns = sys_time_ns();
|
||||
@ -232,7 +232,7 @@ void _logfv(i32 level, struct string fmt, va_list args)
|
||||
#endif
|
||||
{
|
||||
if (!atomic_i32_eval(&G.initialized)) { return; }
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string msg = string_formatv(scratch.arena, fmt, args);
|
||||
#if LOG_INCLUDE_SOURCE_LOCATION
|
||||
_log(level, file, line, msg);
|
||||
|
||||
@ -269,7 +269,7 @@ struct mixed_pcm_f32 mixer_update(struct arena *arena, u64 frame_count)
|
||||
{
|
||||
__prof;
|
||||
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct mixed_pcm_f32 res = ZI;
|
||||
res.count = frame_count * 2;
|
||||
|
||||
@ -92,7 +92,7 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct string encoded,
|
||||
* Read
|
||||
* ========================== */
|
||||
|
||||
res.pcm.samples = arena_dry_push(arena, i16);
|
||||
res.pcm.samples = arena_push_dry(arena, i16);
|
||||
u64 sample_bytes_read = 0;
|
||||
while (true) {
|
||||
IMFSample *sample;
|
||||
|
||||
@ -1256,7 +1256,7 @@ void phys_step(struct phys_step_ctx *ctx, f32 timestep)
|
||||
while (remaining_dt > 0) {
|
||||
__profscope(step_part);
|
||||
++phys_iteration;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* TOI */
|
||||
f32 step_dt = remaining_dt;
|
||||
|
||||
@ -235,14 +235,14 @@ INTERNAL void wasapi_update_end(struct wasapi_buffer *wspbuf, struct mixed_pcm_f
|
||||
|
||||
INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(playback_thread_entry_point, arg)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
(UNUSED)arg;
|
||||
|
||||
|
||||
/* FIXME: If playback fails at any point and mixer stops advancing, we
|
||||
* need to halt mixer to prevent memory leak when sounds are played. */
|
||||
while (!atomic_i32_eval(&G.playback_thread_shutdown)) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
struct wasapi_buffer wspbuf = wasapi_update_begin();
|
||||
struct mixed_pcm_f32 pcm = mixer_update(temp.arena, wspbuf.frames_count);
|
||||
wasapi_update_end(&wspbuf, pcm);
|
||||
|
||||
@ -185,10 +185,10 @@ void resource_register_watch_callback(resource_watch_callback *callback)
|
||||
INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(resource_watch_monitor_thread_entry_point, _)
|
||||
{
|
||||
(UNUSED)_;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
while (!atomic_i32_eval(&G.watch_shutdown)) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
struct sys_watch_info_list res = sys_watch_wait(temp.arena, &G.watch);
|
||||
if (res.first && !atomic_i32_eval(&G.watch_shutdown)) {
|
||||
struct sys_lock lock = sys_mutex_lock_e(&G.watch_dispatcher_mutex);
|
||||
@ -222,7 +222,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(resource_watch_monitor_thread_entry_poi
|
||||
INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(resource_watch_dispatcher_thread_entry_point, _)
|
||||
{
|
||||
(UNUSED)_;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct sys_lock watch_dispatcher_lock = sys_mutex_lock_e(&G.watch_dispatcher_mutex);
|
||||
while (!atomic_i32_eval(&G.watch_shutdown)) {
|
||||
@ -235,7 +235,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(resource_watch_dispatcher_thread_entry_
|
||||
watch_dispatcher_lock = sys_mutex_lock_e(&G.watch_dispatcher_mutex);
|
||||
}
|
||||
if (!atomic_i32_eval(&G.watch_shutdown)) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
/* Pull watch info from queue */
|
||||
struct sys_watch_info_list watch_info_list = sys_watch_info_copy(temp.arena, G.watch_dispatcher_info_list);
|
||||
|
||||
@ -16,7 +16,7 @@ INTERNAL THREAD_LOCAL_VAR_RELEASE_FUNC_DEF(scratch_context_release, vctx)
|
||||
|
||||
#if RTC
|
||||
/* If stack count is not 0, then a `scratch_end` is missing on a top-level
|
||||
* scratch arena (The temp_arena with
|
||||
* scratch arena (The arena_temp with
|
||||
* `scratch_id` = ctx->scratch_id_stack[ctx->scratch_id_stack_count - 1]) */
|
||||
ASSERT(ctx->scratch_id_stack_count == 0);
|
||||
#endif
|
||||
|
||||
@ -28,7 +28,7 @@ THREAD_LOCAL_VAR_DECL_EXTERN(tl_scratch_ctx, struct scratch_ctx);
|
||||
* Scratch begin
|
||||
* ========================== */
|
||||
|
||||
INLINE void scratch_dbg_push(struct scratch_ctx *ctx, struct temp_arena *temp)
|
||||
INLINE void scratch_dbg_push(struct scratch_ctx *ctx, struct arena_temp *temp)
|
||||
{
|
||||
#if RTC
|
||||
if (ctx->scratch_id_stack_count >= ARRAY_COUNT(ctx->scratch_id_stack)) {
|
||||
@ -42,7 +42,7 @@ INLINE void scratch_dbg_push(struct scratch_ctx *ctx, struct temp_arena *temp)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Any arena parameters in the calling function's scope should be passed into this
|
||||
/* Any parameterized arenas in the caller's scope should be passed into this
|
||||
* function as a potential "conflict". This is to prevent friction in case the
|
||||
* passed arena is itself a scratch arena from another scope (since
|
||||
* parameterized arenas are often used to allocate persistent results for the
|
||||
@ -52,7 +52,7 @@ INLINE void scratch_dbg_push(struct scratch_ctx *ctx, struct temp_arena *temp)
|
||||
* scope that could potentially be a scratch arena from another scope. */
|
||||
#define scratch_begin(potential_conflict) _scratch_begin(potential_conflict)
|
||||
|
||||
INLINE struct temp_arena _scratch_begin(struct arena *potential_conflict)
|
||||
INLINE struct arena_temp _scratch_begin(struct arena *potential_conflict)
|
||||
{
|
||||
/* This function is currently hard-coded to support 2 scratch arenas */
|
||||
CT_ASSERT(SCRATCH_ARENAS_PER_THREAD == 2);
|
||||
@ -65,7 +65,7 @@ INLINE struct temp_arena _scratch_begin(struct arena *potential_conflict)
|
||||
if (potential_conflict && scratch_arena->base == potential_conflict->base) {
|
||||
scratch_arena = &ctx->arenas[1];
|
||||
}
|
||||
struct temp_arena temp = arena_temp_begin(scratch_arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch_arena);
|
||||
scratch_dbg_push(ctx, &temp);
|
||||
return temp;
|
||||
}
|
||||
@ -82,11 +82,11 @@ INLINE struct temp_arena _scratch_begin(struct arena *potential_conflict)
|
||||
(UNUSED)arena; \
|
||||
} while (0)
|
||||
|
||||
INLINE struct temp_arena _scratch_begin_no_conflict(void)
|
||||
INLINE struct arena_temp _scratch_begin_no_conflict(void)
|
||||
{
|
||||
struct scratch_ctx *ctx = (struct scratch_ctx *)thread_local_var_eval(&tl_scratch_ctx);
|
||||
struct arena *scratch_arena = &ctx->arenas[0];
|
||||
struct temp_arena temp = arena_temp_begin(scratch_arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch_arena);
|
||||
scratch_dbg_push(ctx, &temp);
|
||||
return temp;
|
||||
}
|
||||
@ -95,7 +95,7 @@ INLINE struct temp_arena _scratch_begin_no_conflict(void)
|
||||
* Scratch end
|
||||
* ========================== */
|
||||
|
||||
INLINE void scratch_end(struct temp_arena scratch_temp)
|
||||
INLINE void scratch_end(struct arena_temp scratch_temp)
|
||||
{
|
||||
#if RTC
|
||||
struct scratch_ctx *ctx = (struct scratch_ctx *)thread_local_var_eval(&tl_scratch_ctx);
|
||||
|
||||
@ -47,7 +47,7 @@ struct string settings_serialize(struct arena *arena, const struct sys_window_se
|
||||
struct sys_window_settings *settings_deserialize(struct arena *arena, struct string src, struct string *error_out)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct string error = ZI;
|
||||
struct json_error json_error = ZI;
|
||||
|
||||
@ -114,7 +114,7 @@ struct sim_client_store *sim_client_store_alloc(void)
|
||||
store->num_client_lookup_bins = CLIENT_LOOKUP_BINS;
|
||||
store->client_lookup_bins = arena_push_array(&store->arena, struct sim_client_lookup_bin, store->num_client_lookup_bins);
|
||||
store->clients_arena = arena_alloc(GIGABYTE(64));
|
||||
store->clients = arena_dry_push(&store->clients_arena, struct sim_client);
|
||||
store->clients = arena_push_dry(&store->clients_arena, struct sim_client);
|
||||
return store;
|
||||
}
|
||||
|
||||
@ -946,7 +946,7 @@ struct sim_ent_decode_queue {
|
||||
void sim_snapshot_decode(struct bitbuff_reader *br, struct sim_snapshot *ss)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
ss->sim_dt_ns = br_read_iv(br);
|
||||
ss->sim_time_ns = br_read_iv(br);
|
||||
|
||||
@ -135,9 +135,9 @@ void sim_ent_release(struct sim_ent *ent)
|
||||
|
||||
void sim_ent_release_all_with_prop(struct sim_snapshot *ss, enum sim_ent_prop prop)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct sim_ent **ents_to_release = arena_dry_push(scratch.arena, struct sim_ent *);
|
||||
struct sim_ent **ents_to_release = arena_push_dry(scratch.arena, struct sim_ent *);
|
||||
u64 ents_to_release_count = 0;
|
||||
for (u64 ent_index = 0; ent_index < ss->num_ents_reserved; ++ent_index) {
|
||||
struct sim_ent *ent = &ss->ents[ent_index];
|
||||
|
||||
@ -423,7 +423,7 @@ INTERNAL SORT_COMPARE_FUNC_DEF(tile_chunk_sort_y, arg_a, arg_b, udata)
|
||||
INTERNAL void test_generate_walls(struct sim_snapshot *world)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
|
||||
|
||||
/* Release existing walls and gather tile chunks.
|
||||
@ -433,7 +433,7 @@ INTERNAL void test_generate_walls(struct sim_snapshot *world)
|
||||
struct sim_ent **y_sorted_tile_chunks = NULL;
|
||||
u64 sorted_tile_chunks_count = 0;
|
||||
{
|
||||
x_sorted_tile_chunks = arena_dry_push(scratch.arena, struct sim_ent *);
|
||||
x_sorted_tile_chunks = arena_push_dry(scratch.arena, struct sim_ent *);
|
||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||
struct sim_ent *ent = &world->ents[ent_index];
|
||||
if (!ent->valid) continue;
|
||||
@ -828,7 +828,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
|
||||
void sim_step(struct sim_step_ctx *ctx)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
b32 is_master = ctx->is_master;
|
||||
struct sim_snapshot *world = ctx->world;
|
||||
@ -1870,7 +1870,7 @@ void sim_step(struct sim_step_ctx *ctx)
|
||||
* ========================== */
|
||||
|
||||
{
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct sim_ent **stack = arena_push_no_zero(temp.arena, struct sim_ent *);
|
||||
u64 stack_count = 1;
|
||||
|
||||
@ -85,7 +85,7 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
||||
{
|
||||
__prof;
|
||||
struct sound_task_params *params = (struct sound_task_params *)vparams;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string path = STRING(params->path_len, (u8 *)params->path_cstr);
|
||||
struct asset *asset = params->asset;
|
||||
u32 flags = params->flags;
|
||||
@ -159,7 +159,7 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
||||
struct asset *sound_load_asset(struct string path, u32 flags, b32 help)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* Generate and append sound flags to path key */
|
||||
struct string key = string_format(scratch.arena,
|
||||
|
||||
@ -30,7 +30,7 @@ struct space *space_alloc(f32 cell_size, u32 num_bins_sqrt)
|
||||
}
|
||||
|
||||
space->valid = true;
|
||||
space->entries = arena_dry_push(&space->entry_arena, struct space_entry);
|
||||
space->entries = arena_push_dry(&space->entry_arena, struct space_entry);
|
||||
|
||||
space->cell_arena = arena_alloc(GIGABYTE(64));
|
||||
space->cell_size = cell_size;
|
||||
|
||||
12
src/sprite.c
12
src/sprite.c
@ -225,7 +225,7 @@ struct sprite_startup_receipt sprite_startup(struct gpu_startup_receipt *gpu_sr,
|
||||
G.nil_texture = arena_push(&G.perm_arena, struct sprite_texture);
|
||||
G.nil_texture->loaded = true;
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct image_rgba purple_black_image = generate_purple_black_image(scratch.arena, 64, 64);
|
||||
G.nil_texture->texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(purple_black_image.width, purple_black_image.height), purple_black_image.pixels);
|
||||
scratch_end(scratch);
|
||||
@ -344,7 +344,7 @@ INTERNAL void push_load_task(struct cache_ref ref, struct sprite_tag tag)
|
||||
INTERNAL void cache_entry_load_texture(struct cache_ref ref, struct sprite_tag tag)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct cache_entry *e = ref.e;
|
||||
|
||||
atomic_i32_eval_exchange(&e->state, CACHE_ENTRY_STATE_WORKING);
|
||||
@ -471,7 +471,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
|
||||
/* Init slices */
|
||||
if (ase.num_slice_keys > 0) {
|
||||
__profscope(init_slices);
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
struct temp_ase_slice_key_node {
|
||||
struct ase_slice_key *key;
|
||||
@ -667,7 +667,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
|
||||
INTERNAL void cache_entry_load_sheet(struct cache_ref ref, struct sprite_tag tag)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct cache_entry *e = ref.e;
|
||||
|
||||
atomic_i32_eval_exchange(&e->state, CACHE_ENTRY_STATE_WORKING);
|
||||
@ -1235,10 +1235,10 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(sprite_evictor_thread_entry_point, arg)
|
||||
|
||||
struct sys_lock evictor_lock = sys_mutex_lock_e(&G.evictor_mutex);
|
||||
while (!G.evictor_shutdown) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
u64 evict_array_count = 0;
|
||||
struct evict_node *evict_array = arena_dry_push(scratch.arena, struct evict_node);
|
||||
struct evict_node *evict_array = arena_push_dry(scratch.arena, struct evict_node);
|
||||
|
||||
if (!G.evictor_shutdown) {
|
||||
i32 cur_cycle = atomic_i32_eval(&G.evictor_cycle);
|
||||
|
||||
36
src/string.c
36
src/string.c
@ -16,8 +16,8 @@
|
||||
* NOTE: It is valid for a string to have len 0 but a non-NULL text pointer.
|
||||
* Always check string.len rather than string.text for string presence.
|
||||
* (If we want to change this behavior then we need to check for length = 0 in
|
||||
* our functions that return a pointer from arena_dry_push, or guarantee that
|
||||
* all functions returning an arena_dry_push do allocate.)
|
||||
* our functions that return a pointer from arena_push_dry, or guarantee that
|
||||
* all functions returning an arena_push_dry do allocate.)
|
||||
*/
|
||||
|
||||
/* ========================== *
|
||||
@ -41,11 +41,11 @@ struct string string_from_uint(struct arena *arena, u64 n, u64 base, u64 zfill)
|
||||
/* Base too large */
|
||||
ASSERT(base <= (ARRAY_COUNT(INT_CHARS) - 1));
|
||||
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
/* Build backwards text starting from least significant digit */
|
||||
u64 len = 0;
|
||||
u8 *backwards_text = arena_dry_push(scratch.arena, u8);
|
||||
u8 *backwards_text = arena_push_dry(scratch.arena, u8);
|
||||
do {
|
||||
string_from_char(scratch.arena, INT_CHARS[n % base]);
|
||||
++len;
|
||||
@ -73,7 +73,7 @@ struct string string_from_uint(struct arena *arena, u64 n, u64 base, u64 zfill)
|
||||
|
||||
struct string string_from_int(struct arena *arena, i64 n, u64 base, u64 zfill)
|
||||
{
|
||||
u8 *final_text = arena_dry_push(arena, u8);
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
u8 len = 0;
|
||||
if (n < 0) {
|
||||
/* Push sign */
|
||||
@ -101,8 +101,8 @@ struct string string_from_ptr(struct arena *arena, void *ptr)
|
||||
|
||||
struct string string_from_float(struct arena *arena, f64 f, u32 precision)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
u8 *final_text = arena_dry_push(arena, u8);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
u64 final_len = 0;
|
||||
|
||||
if (F32_IS_NAN(f)) {
|
||||
@ -127,7 +127,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
|
||||
/* Print whole part */
|
||||
{
|
||||
/* Build backwards text starting from least significant digit */
|
||||
u8 *backwards_text = arena_dry_push(scratch.arena, u8);
|
||||
u8 *backwards_text = arena_push_dry(scratch.arena, u8);
|
||||
u64 backwards_text_len = 0;
|
||||
do {
|
||||
u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0));
|
||||
@ -167,7 +167,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision)
|
||||
struct string string_from_handle(struct arena *arena, u64 v0, u64 v1)
|
||||
{
|
||||
struct string res = ZI;
|
||||
res.text = arena_dry_push(arena, u8);
|
||||
res.text = arena_push_dry(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;
|
||||
@ -178,7 +178,7 @@ struct string string_from_handle(struct arena *arena, u64 v0, u64 v1)
|
||||
struct string string_from_uid(struct arena *arena, struct uid uid)
|
||||
{
|
||||
struct string res = ZI;
|
||||
res.text = arena_dry_push(arena, u8);
|
||||
res.text = arena_push_dry(arena, u8);
|
||||
res.len += string_from_uint(arena, (uid.hi >> 32), 16, 8).len;
|
||||
return res;
|
||||
}
|
||||
@ -235,7 +235,7 @@ struct string_array string_split(struct arena *arena, struct string str, struct
|
||||
{
|
||||
struct string_array pieces = {
|
||||
.count = 0,
|
||||
.strings = arena_dry_push(arena, struct string)
|
||||
.strings = arena_push_dry(arena, struct string)
|
||||
};
|
||||
|
||||
struct string piece = {
|
||||
@ -273,10 +273,10 @@ struct string_array string_split(struct arena *arena, struct string str, struct
|
||||
/* NOTE: Really slow */
|
||||
struct string string_indent(struct arena *arena, struct string str, u32 indent)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
|
||||
u64 final_len = 0;
|
||||
u8 *final_text = arena_dry_push(arena, u8);
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
|
||||
struct string_array split = string_split(scratch.arena, str, LIT("\n"));
|
||||
for (u64 i = 0; i < split.count; ++i) {
|
||||
@ -443,7 +443,7 @@ struct string string_formatv(struct arena *arena, struct string fmt, va_list arg
|
||||
__prof;
|
||||
|
||||
u64 final_len = 0;
|
||||
u8 *final_text = arena_dry_push(arena, u8);
|
||||
u8 *final_text = arena_push_dry(arena, u8);
|
||||
|
||||
u8 *end = fmt.text + fmt.len;
|
||||
b32 no_more_args = false;
|
||||
@ -584,7 +584,7 @@ struct string string_from_string16(struct arena *arena, struct string16 str16)
|
||||
{
|
||||
struct string res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u8)
|
||||
.text = arena_push_dry(arena, u8)
|
||||
};
|
||||
|
||||
u64 pos16 = 0;
|
||||
@ -608,7 +608,7 @@ struct string string_from_string32(struct arena *arena, struct string32 str32)
|
||||
{
|
||||
struct string res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u8)
|
||||
.text = arena_push_dry(arena, u8)
|
||||
};
|
||||
|
||||
u64 pos32 = 0;
|
||||
@ -632,7 +632,7 @@ struct string16 string16_from_string(struct arena *arena, struct string str8)
|
||||
{
|
||||
struct string16 res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u16)
|
||||
.text = arena_push_dry(arena, u16)
|
||||
};
|
||||
|
||||
u64 pos8 = 0;
|
||||
@ -656,7 +656,7 @@ struct string32 string32_from_string(struct arena *arena, struct string str8)
|
||||
{
|
||||
struct string32 res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u32)
|
||||
.text = arena_push_dry(arena, u32)
|
||||
};
|
||||
|
||||
u64 pos8 = 0;
|
||||
|
||||
@ -268,7 +268,7 @@ INTERNAL struct string string_from_win32_path(struct arena *arena, wchar_t *src)
|
||||
{
|
||||
struct string res = {
|
||||
.len = 0,
|
||||
.text = arena_dry_push(arena, u8)
|
||||
.text = arena_push_dry(arena, u8)
|
||||
};
|
||||
|
||||
while (*src) {
|
||||
@ -311,7 +311,7 @@ struct string sys_get_write_path(struct arena *arena)
|
||||
b32 sys_is_file(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
DWORD attributes = GetFileAttributesW(path_wstr);
|
||||
scratch_end(scratch);
|
||||
@ -320,7 +320,7 @@ b32 sys_is_file(struct string path)
|
||||
|
||||
b32 sys_is_dir(struct string path)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
DWORD attributes = GetFileAttributesW(path_wstr);
|
||||
scratch_end(scratch);
|
||||
@ -330,7 +330,7 @@ b32 sys_is_dir(struct string path)
|
||||
void sys_mkdir(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
int err_code = SHCreateDirectory(NULL, path_wstr);
|
||||
struct string err = ZI;
|
||||
@ -366,7 +366,7 @@ void sys_mkdir(struct string path)
|
||||
struct sys_file sys_file_open_read(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sys_file file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -389,7 +389,7 @@ struct sys_file sys_file_open_read(struct string path)
|
||||
struct sys_file sys_file_open_read_wait(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sys_file file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -416,7 +416,7 @@ struct sys_file sys_file_open_read_wait(struct string path)
|
||||
struct sys_file sys_file_open_write(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sys_file file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -439,7 +439,7 @@ struct sys_file sys_file_open_write(struct string path)
|
||||
struct sys_file sys_file_open_append(struct string path)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sys_file file = ZI;
|
||||
|
||||
wchar_t *path_wstr = wstr_from_string(scratch.arena, path);
|
||||
@ -501,7 +501,7 @@ void sys_file_write(struct sys_file file, struct string data)
|
||||
/* TODO: Check what the real data limit is and chunk sequentially based on
|
||||
* that (rather than failing) */
|
||||
if (data.len >= 0x7FFF) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
sys_panic(string_format(scratch.arena,
|
||||
LIT("Tried to write too many bytes to disk (%F)"),
|
||||
FMT_UINT(data.len)));
|
||||
@ -688,7 +688,7 @@ struct win32_watch {
|
||||
|
||||
struct sys_watch sys_watch_alloc(struct string dir_path)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct win32_watch *w32_watch = NULL;
|
||||
{
|
||||
@ -1178,7 +1178,7 @@ INTERNAL void win32_update_window_from_settings(struct win32_window *window, str
|
||||
SetWindowPlacement(hwnd, &wp);
|
||||
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
wchar_t *title_wstr = wstr_from_string(scratch.arena, string_from_cstr_no_limit(settings->title));
|
||||
SetWindowTextW(hwnd, title_wstr);
|
||||
scratch_end(scratch);
|
||||
@ -1369,7 +1369,7 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
|
||||
|
||||
/* Raw mouse move */
|
||||
case WM_INPUT: {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* Read raw input buffer */
|
||||
UINT buff_size;
|
||||
@ -1918,7 +1918,7 @@ INTERNAL DWORD WINAPI win32_thread_proc(LPVOID vt)
|
||||
struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, void *thread_data, struct string thread_name)
|
||||
{
|
||||
__prof;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
ASSERT(entry_point != NULL);
|
||||
logf_info("Creating thread \"%F\"", FMT_STR(thread_name));
|
||||
|
||||
@ -2027,7 +2027,7 @@ void sys_thread_assert(u32 tid)
|
||||
|
||||
void sys_message_box(enum sys_message_box_kind kind, struct string message)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
wchar_t *message_wstr = wstr_from_string(scratch.arena, message);
|
||||
const wchar_t *title = L"";
|
||||
@ -2067,7 +2067,7 @@ void sys_message_box(enum sys_message_box_kind kind, struct string message)
|
||||
void sys_set_clipboard_text(struct string str)
|
||||
{
|
||||
if (OpenClipboard(0)) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string16 str16 = string16_from_string(scratch.arena, str);
|
||||
u64 str16_size_bytes = str16.len * 2;
|
||||
EmptyClipboard();
|
||||
@ -2284,7 +2284,7 @@ void sys_sleep(f64 seconds)
|
||||
INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(win32_app_thread_entry_point, arg)
|
||||
{
|
||||
(UNUSED)arg;
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string cmdline_args = string_from_wstr(scratch.arena, G.cmdline_args_wstr, ARRAY_COUNT(G.cmdline_args_wstr));
|
||||
app_entry_point(cmdline_args);
|
||||
scratch_end(scratch);
|
||||
@ -2439,10 +2439,10 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
if (!atomic_i32_eval(&G.panicking)) {
|
||||
struct sys_lock lock = sys_mutex_lock_s(&G.threads_mutex);
|
||||
if (G.threads_first) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
u64 num_dangling_threads = 0;
|
||||
struct string threads_msg = ZI;
|
||||
threads_msg.text = arena_dry_push(scratch.arena, u8);
|
||||
threads_msg.text = arena_push_dry(scratch.arena, u8);
|
||||
for (struct win32_thread *t = G.threads_first; t; t = t->next) {
|
||||
struct string name = string_from_cstr(t->thread_name_cstr, ARRAY_COUNT(t->thread_name_cstr));
|
||||
threads_msg.len += string_format(scratch.arena, LIT(" \"%F\"\n"), FMT_STR(name)).len;
|
||||
|
||||
22
src/user.c
22
src/user.c
@ -378,13 +378,13 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
||||
|
||||
INTERNAL struct string get_ent_debug_text(struct arena *arena, struct sim_ent *ent)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin(arena);
|
||||
struct arena_temp scratch = scratch_begin(arena);
|
||||
struct sim_snapshot *ss = ent->ss;
|
||||
|
||||
const u8 hex[] = "0123456789abcdef";
|
||||
|
||||
struct string res = ZI;
|
||||
res.text = arena_dry_push(arena, u8);
|
||||
res.text = arena_push_dry(arena, u8);
|
||||
|
||||
res.len += string_format(arena, LIT("[%F]"), FMT_UID(ent->id.uid)).len;
|
||||
{
|
||||
@ -495,7 +495,7 @@ INTERNAL LOG_EVENT_CALLBACK_FUNC_DEF(debug_console_log_callback, log)
|
||||
|
||||
INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct v2 desired_start_pos = V2(10, minimized ? 100 : 600);
|
||||
i64 fade_time_ns = NS_FROM_SECONDS(10);
|
||||
@ -631,7 +631,7 @@ INTERNAL SORT_COMPARE_FUNC_DEF(ent_draw_order_cmp, arg_a, arg_b, udata)
|
||||
|
||||
INTERNAL void user_update(void)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
/* ========================== *
|
||||
* Begin frame
|
||||
@ -1181,7 +1181,7 @@ INTERNAL void user_update(void)
|
||||
* Sort drawable entities
|
||||
* ========================== */
|
||||
|
||||
struct sim_ent **sorted = arena_dry_push(scratch.arena, struct sim_ent *);
|
||||
struct sim_ent **sorted = arena_push_dry(scratch.arena, struct sim_ent *);
|
||||
u64 sorted_count = 0;
|
||||
{
|
||||
/* Copy valid entities */
|
||||
@ -1312,7 +1312,7 @@ INTERNAL void user_update(void)
|
||||
|
||||
/* Debug draw entity info */
|
||||
if (G.debug_draw && !skip_debug_draw) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
||||
debug_draw_movement(ent);
|
||||
@ -1939,10 +1939,10 @@ INTERNAL void user_update(void)
|
||||
struct v2 pos = v2_add(G.user_cursor, V2(15, 15));
|
||||
struct font *font = font_load_async(LIT("fonts/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
struct string dbg_text = ZI;
|
||||
dbg_text.text = arena_dry_push(temp.arena, u8);
|
||||
dbg_text.text = arena_push_dry(temp.arena, u8);
|
||||
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
|
||||
draw_text(G.user_gpu_cmd_list, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
|
||||
@ -1957,9 +1957,9 @@ INTERNAL void user_update(void)
|
||||
if (G.debug_draw) {
|
||||
struct font *font = font_load_async(LIT("fonts/fixedsys.ttf"), 12.0f);
|
||||
if (font) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
struct arena_temp temp = arena_temp_begin(scratch.arena);
|
||||
struct string text = ZI;
|
||||
text.text = arena_dry_push(temp.arena, u8);
|
||||
text.text = arena_push_dry(temp.arena, u8);
|
||||
|
||||
#if BITBUFF_DEBUG
|
||||
text.len += string_format(temp.arena, LIT("(bitbuff debug enabled)")).len;
|
||||
@ -2319,7 +2319,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg)
|
||||
f64 compute_timescale = 1.0;
|
||||
while (!atomic_i32_eval(&G.local_sim_thread_shutdown)) {
|
||||
__profscope(local_sim_loop);
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
{
|
||||
__profscope(local_sim_sleep);
|
||||
sleep_frame(real_time_ns, step_dt_ns * compute_timescale);
|
||||
|
||||
@ -80,7 +80,7 @@ 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) {
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
u64 left_count = item_count / 2;
|
||||
u64 right_count = item_count - left_count;
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(worker_thread_entry_point, thread_data)
|
||||
|
||||
struct work_startup_receipt work_startup(u32 num_worker_threads)
|
||||
{
|
||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
if (num_worker_threads <= 0) {
|
||||
sys_panic(LIT("Tried to start up worker pool with 0 threads"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user