diff --git a/build.c b/build.c index ee44b95d..b7d21f54 100644 --- a/build.c +++ b/build.c @@ -363,7 +363,7 @@ void OnBuild(StringList cli_args) "-Wno-declaration-after-statement -Wno-extra-semi -Wno-extra-semi-stmt " "-Wno-bad-function-cast -Wno-class-varargs -Wno-unreachable-code-break " "-Wno-cast-align -Wno-float-equal -Wno-zero-as-null-pointer-constant " - "-Wno-cast-qual -Wno-missing-noreturn -Wno-missing-field-initializers " + "-Wno-cast-qual -Wno-missing-noreturn " "-Wno-missing-braces -Wno-initializer-overrides " "-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat " "-Wno-switch-enum -Wno-switch-default " diff --git a/src/app.c b/src/app.c index be4ed93b..bcb3d8d3 100644 --- a/src/app.c +++ b/src/app.c @@ -36,7 +36,7 @@ GLOBAL struct { struct sys_mutex exit_callbacks_mutex; struct arena exit_callbacks_arena; struct exit_callback *exit_callbacks_head; -} G = { 0 }, DEBUG_ALIAS(G, G_app); +} G = ZI, DEBUG_ALIAS(G, G_app); /* ========================== * * Write directory @@ -165,7 +165,7 @@ void app_entry_point(void) { struct temp_arena temp = arena_temp_begin(scratch.arena); - struct sys_window_settings window_settings = { 0 }; + struct sys_window_settings window_settings = ZI; struct string settings_path = app_write_path_cat(temp.arena, STR(SETTINGS_FILENAME)); logf_info("Looking for settings file \"%F\"", FMT_STR(settings_path)); if (sys_is_file(settings_path)) { @@ -174,7 +174,7 @@ void app_entry_point(void) struct buffer file_data = sys_file_read_all(temp.arena, settings_file); sys_file_close(settings_file); logf_info("Deserializing settings file data: %F", FMT_STR(STRING_FROM_BUFFER(file_data))); - struct string error = { 0 }; + struct string error = ZI; struct sys_window_settings *res = settings_deserialize(temp.arena, file_data, &error); if (error.len > 0) { logf_info("Failed to load settings file with error - %F", FMT_STR(error)); diff --git a/src/arena.c b/src/arena.c index b90b6ab9..de30864b 100644 --- a/src/arena.c +++ b/src/arena.c @@ -11,7 +11,7 @@ struct arena arena_alloc(u64 reserve) { __prof; - struct arena arena = { 0 }; + struct arena arena = ZI; /* Round up to nearest block size */ u64 block_remainder = reserve % ARENA_BLOCK_SIZE; diff --git a/src/arena.h b/src/arena.h index fd8f49e6..25132c2d 100644 --- a/src/arena.h +++ b/src/arena.h @@ -86,7 +86,7 @@ INLINE void *_arena_align(struct arena *arena, u64 align) INLINE struct temp_arena arena_temp_begin(struct arena *arena) { - struct temp_arena t = { 0 }; + struct temp_arena t = ZI; t.arena = arena; t.start_pos = arena->pos; return t; diff --git a/src/ase.c b/src/ase.c index 07dee20b..8c4d3298 100644 --- a/src/ase.c +++ b/src/ase.c @@ -187,19 +187,19 @@ INTERNAL struct huffman huffman_init(struct arena *arena, u32 max_code_bits, u32 { __prof; - struct huffman res = { 0 }; + struct huffman res = ZI; res.max_code_bits = max_code_bits; res.entries_count = (1 << max_code_bits); res.entries = arena_push_array(arena, struct huffman_entry, res.entries_count); - u32 code_length_hist[HUFFMAN_BIT_COUNT] = { 0 }; + u32 code_length_hist[HUFFMAN_BIT_COUNT] = ZI; for (u32 i = 0; i < bl_counts_count; ++i) { u32 count = bl_counts[i]; ASSERT(count <= ARRAY_COUNT(code_length_hist)); ++code_length_hist[count]; } - u32 next_code[HUFFMAN_BIT_COUNT] = { 0 }; + u32 next_code[HUFFMAN_BIT_COUNT] = ZI; next_code[0] = 0; code_length_hist[0] = 0; for (u32 i = 1; i < ARRAY_COUNT(next_code); ++i) { @@ -276,7 +276,7 @@ INTERNAL void inflate(u8 *dest, u8 *encoded) case BLOCK_TYPE_COMPRESSED_FIXED: case BLOCK_TYPE_COMPRESSED_DYNAMIC: { struct temp_arena temp = arena_temp_begin(scratch.arena); - u32 lit_len_dist_table[512] = { 0 }; + u32 lit_len_dist_table[512] = ZI; u32 hlit; u32 hdist; @@ -289,7 +289,7 @@ INTERNAL void inflate(u8 *dest, u8 *encoded) u32 hclen = consume_bits(&bb, 4) + 4; /* Init dict huffman (hclen) */ - u32 hclen_bl_counts[19] = { 0 }; + u32 hclen_bl_counts[19] = ZI; for (u32 i = 0; i < hclen; ++i) { u32 code = g_hclen_order[i]; hclen_bl_counts[code] = consume_bits(&bb, 3); @@ -556,7 +556,7 @@ struct ase_decode_image_result ase_decode_image(struct arena *arena, struct buff __prof; struct temp_arena scratch = scratch_begin(arena); - struct ase_decode_image_result res = { 0 }; + struct ase_decode_image_result res = ZI; struct byte_reader br = br_create_from_buffer(encoded); struct ase_header ase_header; @@ -815,7 +815,7 @@ struct ase_decode_sheet_result ase_decode_sheet(struct arena *arena, struct buff { __prof; - struct ase_decode_sheet_result res = { 0 }; + struct ase_decode_sheet_result res = ZI; struct byte_reader br = br_create_from_buffer(encoded); struct ase_header ase_header; diff --git a/src/asset_cache.c b/src/asset_cache.c index 940359ab..82456032 100644 --- a/src/asset_cache.c +++ b/src/asset_cache.c @@ -29,7 +29,7 @@ GLOBAL struct { u64 dbg_table_count; struct sys_mutex dbg_table_mutex; #endif -} G = { 0 }, DEBUG_ALIAS(G, G_asset_cache); +} G = ZI, DEBUG_ALIAS(G, G_asset_cache); /* ========================== * * Startup @@ -139,7 +139,7 @@ struct asset *asset_cache_touch(struct string key, u64 hash, b32 *is_first_touch if (G.num_assets >= MAX_ASSETS) { sys_panic(STR("Max assets reached")); } - struct string key_stored = { 0 }; + struct string key_stored = ZI; { /* Copy key to store */ struct asset_cache_store store = asset_cache_store_open(); diff --git a/src/common.h b/src/common.h index 3b929e2f..c408a77a 100644 --- a/src/common.h +++ b/src/common.h @@ -166,9 +166,16 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); * ========================== */ #if COMPILER_MSVC && LANGUAGE_CPP -# define CPPFRIENDLY_INITLIST_TYPE(type) type -# else -# define CPPFRIENDLY_INITLIST_TYPE(type) (type) +# define CPPFRIENDLY_INITLIST_TYPE(type) type +#else +# define CPPFRIENDLY_INITLIST_TYPE(type) (type) +#endif + +/* Zero initialization macro */ +#if LANGUAGE_C +# define ZI { 0 } +#else +# define ZI { } #endif #if 1 diff --git a/src/draw.c b/src/draw.c index a5ad84f1..4cbef17b 100644 --- a/src/draw.c +++ b/src/draw.c @@ -7,7 +7,7 @@ GLOBAL struct { struct renderer_handle solid_white; -} G = { 0 }, DEBUG_ALIAS(G, G_draw); +} G = ZI, DEBUG_ALIAS(G, G_draw); /* ========================== * * Startup diff --git a/src/entity.c b/src/entity.c index 3c71eb36..cbc9d88a 100644 --- a/src/entity.c +++ b/src/entity.c @@ -91,7 +91,7 @@ void entity_store_reset(struct entity_store *store) INTERNAL struct entity *entity_alloc_internal(struct entity_store *store) { struct entity *entity = NULL; - struct entity_handle handle = { 0 }; + struct entity_handle handle = ZI; if (store->first_free.gen) { /* Reuse from free list */; entity = entity_from_handle(store, store->first_free); diff --git a/src/font.c b/src/font.c index fb46a650..96de37f3 100644 --- a/src/font.c +++ b/src/font.c @@ -35,7 +35,7 @@ struct font_task_params_store { GLOBAL struct { struct font_task_params_store params; -} G = { 0 }, DEBUG_ALIAS(G, L_font); +} G = ZI, DEBUG_ALIAS(G, L_font); /* ========================== * * Startup @@ -193,7 +193,7 @@ struct asset *font_load_asset(struct string path, f32 point_size, b32 help) /* Push task */ asset_cache_mark_loading(asset); - struct work_handle wh = { 0 }; + struct work_handle wh = ZI; if (help) { wh = work_push_task_and_help(&font_load_asset_task, params, WORK_PRIORITY_NORMAL); } else { diff --git a/src/game.c b/src/game.c index a449a892..238c741c 100644 --- a/src/game.c +++ b/src/game.c @@ -29,7 +29,7 @@ GLOBAL struct { struct atomic_u64 prev_tick_id; struct world prev_tick; struct world tick; -} G = { 0 }, DEBUG_ALIAS(G, G_game); +} G = ZI, DEBUG_ALIAS(G, G_game); /* ========================== * * Startup @@ -85,7 +85,7 @@ INTERNAL void push_cmds(struct game_cmd_array cmd_array) INTERNAL struct game_cmd_array pop_cmds(struct arena *arena) { - struct game_cmd_array array = { 0 }; + struct game_cmd_array array = ZI; if (G.game_cmds_arena.pos > 0) { struct sys_lock lock = sys_mutex_lock_e(&G.game_cmds_mutex); struct buffer game_cmds_buff = arena_to_buffer(&G.game_cmds_arena); @@ -292,8 +292,8 @@ INTERNAL void create_contact_manifolds(void) /* TODO: Remove this */ - static struct arena dict_arena = { 0 }; - static struct fixed_dict dict = { 0 }; + static struct arena dict_arena = ZI; + static struct fixed_dict dict = ZI; if (dict.buckets_count == 0) { dict_arena = arena_alloc(GIGABYTE(64)); dict = fixed_dict_init(&dict_arena, 4096); diff --git a/src/gjk.c b/src/gjk.c index f4b9a3cd..12afd5f5 100644 --- a/src/gjk.c +++ b/src/gjk.c @@ -32,7 +32,7 @@ INTERNAL struct v2 menkowski_point(struct v2_array poly0, struct v2_array shape1 b32 gjk_boolean(struct v2_array shape0, struct v2_array shape1) { - struct { struct v2 a, b, c; } s = { 0 }; + struct { struct v2 a, b, c; } s = ZI; /* First point is support point in shape's general directions to eachother */ s.a = menkowski_point(shape0, shape1, v2_sub(shape1.points[0], shape0.points[0])); @@ -160,23 +160,23 @@ struct v2_array cloud(struct arena *arena, struct v2_array poly0, struct v2_arra struct gjk_contact_points_result gjk_contact_points(struct v2_array shape0, struct v2_array shape1) { struct temp_arena scratch = scratch_begin_no_conflict(); /* TODO: Only begin scratch for EPA */ - struct gjk_contact_points_result res = { 0 }; + struct gjk_contact_points_result res = ZI; /* TODO: Verify epsilon */ /* FIXME: Infinite loop when epsilon too low and shapes is too far from 0 (precision issue) */ const f32 epsilon = 0.0000100f; - struct gjk_simplex s = { 0 }; + struct gjk_simplex s = ZI; b32 colliding = false; struct gjk_menkowski_point *proto = NULL; u32 proto_count = 0; - struct gjk_contact_pair pair0 = { 0 }; - struct gjk_contact_pair pair1 = { 0 }; + struct gjk_contact_pair pair0 = ZI; + struct gjk_contact_pair pair1 = ZI; u32 num_pairs = 0; /* Used by GJK & EPA */ - struct v2 dir = { 0 }; - struct gjk_menkowski_point m = { 0 }; + struct v2 dir = ZI; + struct gjk_menkowski_point m = ZI; #if GJK_DEBUG u32 dbg_step = 0; @@ -430,18 +430,18 @@ abort: struct gjk_contact_points_result gjk_contact_points(struct v2_array shape0, struct v2_array shape1) { struct temp_arena scratch = scratch_begin_no_conflict(); - struct gjk_contact_points_result res = { 0 }; + struct gjk_contact_points_result res = ZI; /* TODO: Verify epsilon */ /* FIXME: Infinite loop when epsilon too low and shapes is too far from 0 (precision issue) */ const f32 epsilon = 0.0000100; - struct gjk_simplex s = { 0 }; + struct gjk_simplex s = ZI; b32 colliding = false; struct gjk_menkowski_point *proto = NULL; u32 proto_count = 0; - struct gjk_contact_pair pair0 = { 0 }; - struct gjk_contact_pair pair1 = { 0 }; + struct gjk_contact_pair pair0 = ZI; + struct gjk_contact_pair pair1 = ZI; u32 num_pairs = 0; #if GJK_DEBUG @@ -453,8 +453,8 @@ struct gjk_contact_points_result gjk_contact_points(struct v2_array shape0, stru * Construct encapsulating simplex OR closest feature if not colliding * ========================== */ - struct v2 dir = { 0 }; - struct gjk_menkowski_point m = { 0 }; + struct v2 dir = ZI; + struct gjk_menkowski_point m = ZI; /* Determine encapsulating simplex if colliding, or closest edge / point to origin on simplex */ { /* First point is support point in shape's general directions to eachother */ @@ -730,14 +730,14 @@ abort: struct gjk_extended_result gjk_extended(struct v2_array shape0, struct v2_array shape1) { struct temp_arena scratch = scratch_begin_no_conflict(); - struct gjk_extended_result res = { 0 }; + struct gjk_extended_result res = ZI; /* TODO: Verify epsilon */ const f32 epsilon = 0.0000100; - struct gjk_simplex s = { 0 }; + struct gjk_simplex s = ZI; b32 colliding = false; - struct v2 shape0_p = { 0 }; - struct v2 shape1_p = { 0 }; + struct v2 shape0_p = ZI; + struct v2 shape1_p = ZI; struct gjk_menkowski_point *proto = NULL; u32 proto_count = 0; @@ -750,8 +750,8 @@ struct gjk_extended_result gjk_extended(struct v2_array shape0, struct v2_array * Construct encapsulating simplex OR closest feature if not colliding * ========================== */ - struct v2 dir = { 0 }; - struct gjk_menkowski_point m = { 0 }; + struct v2 dir = ZI; + struct gjk_menkowski_point m = ZI; /* Determine encapsulating simplex if colliding, or closest edge / point to origin on simplex */ { /* First point is support point in shape's general directions to eachother */ @@ -1057,7 +1057,7 @@ INTERNAL struct poly_support_swept_result poly_support_swept(struct v2_array a, } } - struct poly_support_swept_result res = { 0 }; + struct poly_support_swept_result res = ZI; res.p = furthest; res.original = furthest_original; return res; @@ -1077,7 +1077,7 @@ INTERNAL struct gjk_menkowski_point menkowski_point_extended_swept(struct v2_arr struct gjk_extended_result gjk_extended(struct v2_array shape0, struct v2_array shape1, struct v2 linear_velocity) { struct temp_arena scratch = scratch_begin_no_conflict(); - struct gjk_extended_result res = { 0 }; + struct gjk_extended_result res = ZI; /* FIXME: Divs by 0 */ @@ -1090,8 +1090,8 @@ struct gjk_extended_result gjk_extended(struct v2_array shape0, struct v2_array .c = V2(F32_NAN, F32_NAN) }; b32 colliding = false; - struct v2 shape0_p = { 0 }; - struct v2 shape1_p = { 0 }; + struct v2 shape0_p = ZI; + struct v2 shape1_p = ZI; b32 velocity_intersects = false; f32 velocity_intersection = 0; @@ -1108,8 +1108,8 @@ struct gjk_extended_result gjk_extended(struct v2_array shape0, struct v2_array * Construct encapsulating simplex OR closest feature if not colliding * ========================== */ - struct v2 dir = { 0 }; - struct gjk_menkowski_point m = { 0 }; + struct v2 dir = ZI; + struct gjk_menkowski_point m = ZI; /* Determine encapsulating simplex if colliding, or closest edge / point to origin on simplex */ { /* First point is support point in shape's general directions to eachother */ diff --git a/src/json.c b/src/json.c index 758f8e4a..34ea3365 100644 --- a/src/json.c +++ b/src/json.c @@ -95,7 +95,7 @@ INTERNAL struct token *push_token(struct arena *arena, struct token_list *list) INTERNAL struct token_list lex(struct arena *arena, struct string src) { - struct token_list res = { 0 }; + struct token_list res = ZI; struct token *bof = push_token(arena, &res); bof->type = TOKEN_TYPE_BOF; @@ -705,7 +705,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p) /* Parse key */ if (at->type == TOKEN_TYPE_STRING) { struct string t_text = (struct string) { .len = at->end - at->start, .text = &src.text[at->start] }; - struct string error = { 0 }; + struct string error = ZI; struct string key = interpret_string(arena, t_text, &error); if (error.len > 0) { push_error(arena, p, at, error); @@ -748,7 +748,7 @@ INTERNAL void parse(struct arena *arena, struct parser *p) case TOKEN_TYPE_STRING: { struct string t_text = (struct string) { .len = at->end - at->start, .text = &src.text[at->start] }; - struct string error = { 0 }; + struct string error = ZI; struct string value = interpret_string(arena, t_text, &error); if (error.len > 0) { push_error(arena, p, at, error); diff --git a/src/log.c b/src/log.c index fe9bb737..0f855f46 100644 --- a/src/log.c +++ b/src/log.c @@ -20,7 +20,7 @@ GLOBAL struct { log_event_callback_func *callbacks_head; struct sys_file file; b32 file_valid; -} G = { 0 }, DEBUG_ALIAS(G, G_log); +} G = ZI, DEBUG_ALIAS(G, G_log); GLOBAL READONLY struct log_level_settings g_log_level_settings[LOG_LEVEL_COUNT] = { [LOG_LEVEL_CRITICAL] = { diff --git a/src/mixer.c b/src/mixer.c index 75a65082..1285273a 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -64,7 +64,7 @@ GLOBAL struct { struct track *track_last_playing; u64 track_playing_count; struct track *track_first_free; -} G = { 0 }, DEBUG_ALIAS(G, G_mixer); +} G = ZI, DEBUG_ALIAS(G, G_mixer); /* ========================== * * Startup @@ -202,7 +202,7 @@ struct mixer_track_handle mixer_play_ex(struct sound *sound, struct mixer_desc d /* NOTE: This is quite inefficient. */ struct mixer_desc mixer_track_get(struct mixer_track_handle handle) { - struct mixer_desc res = { 0 }; + struct mixer_desc res = ZI; struct track *track = track_from_handle(handle); if (track) { @@ -271,7 +271,7 @@ struct mixed_pcm_f32 mixer_update(struct arena *arena, u64 frame_count) struct temp_arena scratch = scratch_begin(arena); - struct mixed_pcm_f32 res = { 0 }; + struct mixed_pcm_f32 res = ZI; res.count = frame_count * 2; res.samples = arena_push_array_zero(arena, f32, res.count); diff --git a/src/mp3_mmf.c b/src/mp3_mmf.c index 3b8e10a3..f8d61e1a 100644 --- a/src/mp3_mmf.c +++ b/src/mp3_mmf.c @@ -26,7 +26,7 @@ struct mp3_decode_result mp3_decode(struct arena *arena, struct buffer encoded, u32 flags) { - struct mp3_decode_result res = { 0 }; + struct mp3_decode_result res = ZI; u64 sample_rate = PLAYBACK_SAMPLE_RATE; u64 bytes_per_sample = 2; diff --git a/src/playback_wasapi.c b/src/playback_wasapi.c index 8b460190..d95171fd 100644 --- a/src/playback_wasapi.c +++ b/src/playback_wasapi.c @@ -45,7 +45,7 @@ GLOBAL struct { WAVEFORMATEX *buffer_format; u32 buffer_frames; HANDLE mmtc_handle; -} G = { 0 }, DEBUG_ALIAS(G, G_playback_wasapi); +} G = ZI, DEBUG_ALIAS(G, G_playback_wasapi); /* ========================== * * Startup @@ -177,7 +177,7 @@ INTERNAL void wasapi_initialize(void) INTERNAL struct wasapi_buffer wasapi_update_begin(void) { __prof; - struct wasapi_buffer wspbuf = { 0 }; + struct wasapi_buffer wspbuf = ZI; /* Wait */ { diff --git a/src/renderer_d3d11.c b/src/renderer_d3d11.c index f6997387..bc1d6a7d 100644 --- a/src/renderer_d3d11.c +++ b/src/renderer_d3d11.c @@ -147,7 +147,7 @@ GLOBAL struct { struct dx11_shader_desc shader_info[NUM_SHADERS]; -} G = { 0 }, DEBUG_ALIAS(G, G_renderer_d3d11); +} G = ZI, DEBUG_ALIAS(G, G_renderer_d3d11); /* ========================== * * Util @@ -542,7 +542,7 @@ struct renderer_startup_receipt renderer_startup(struct sys_window *window) { __profscope(create_depth_stencil_state); /* TODO: Actually go over these (copied from elsewhere) */ - D3D11_DEPTH_STENCIL_DESC desc = { 0 }; + D3D11_DEPTH_STENCIL_DESC desc = ZI; desc.DepthEnable = false; desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; desc.DepthFunc = D3D11_COMPARISON_ALWAYS; @@ -874,7 +874,7 @@ void renderer_canvas_present(struct renderer_canvas **canvases, u32 canvases_cou ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &G.vs_constant_buffer); struct dx11_shader *last_shader = NULL; - struct renderer_handle last_texture_handle = { 0 }; + struct renderer_handle last_texture_handle = ZI; for (struct renderer_cmd *cmd = canvas->gpu_cmd_store.cmd_first; cmd; cmd = cmd->next) { struct dx11_shader *shader = cmd->shader; struct dx11_buffer *buffer = &canvas->buffers[shader->kind]; @@ -1021,7 +1021,7 @@ INTERNAL void renderer_capture_image_for_profiler(f32 width, f32 height) * At the time of writing this code, 5 textures seems to be the sweet spot * for performance. */ - static struct prof_cap staging_caps[5] = { 0 }; + static struct prof_cap staging_caps[5] = ZI; static u32 cap_index = 0; static b32 ready_to_read = false; diff --git a/src/resource.c b/src/resource.c index aeb2f5e7..b9304e64 100644 --- a/src/resource.c +++ b/src/resource.c @@ -12,7 +12,7 @@ GLOBAL struct { struct arena arena; struct tar_archive archive; -} G = { 0 }, DEBUG_ALIAS(G, G_resource); +} G = ZI, DEBUG_ALIAS(G, G_resource); #endif struct resource_startup_receipt resource_startup(void) diff --git a/src/settings.c b/src/settings.c index 5903eca8..9033bef3 100644 --- a/src/settings.c +++ b/src/settings.c @@ -49,8 +49,8 @@ struct sys_window_settings *settings_deserialize(struct arena *arena, struct buf __prof; struct temp_arena scratch = scratch_begin(arena); - struct string error = { 0 }; - struct json_error json_error = { 0 }; + struct string error = ZI; + struct json_error json_error = ZI; struct sys_window_settings *settings = arena_push_zero(arena, struct sys_window_settings); struct json_parse_result parse_res = json_from_string(scratch.arena, STRING_FROM_BUFFER(src)); diff --git a/src/sound.c b/src/sound.c index 18dc8e5c..1a08b194 100644 --- a/src/sound.c +++ b/src/sound.c @@ -29,7 +29,7 @@ struct sound_task_params_store { GLOBAL struct { struct sound_task_params_store params; -} G = { 0 }, DEBUG_ALIAS(G, G_sound); +} G = ZI, DEBUG_ALIAS(G, G_sound); /* ========================== * * Startup @@ -194,7 +194,7 @@ struct asset *sound_load_asset(struct string path, u32 flags, b32 help) /* Push task */ asset_cache_mark_loading(asset); - struct work_handle wh = { 0 }; + struct work_handle wh = ZI; if (help) { wh = work_push_task_and_help(&sound_load_asset_task, params, WORK_PRIORITY_NORMAL); } else { diff --git a/src/sprite.c b/src/sprite.c index 4d3da01a..5a9f4836 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -141,7 +141,7 @@ GLOBAL struct { struct sys_condition_variable evictor_cv; struct sys_thread evictor_thread; -} G = { 0 }, DEBUG_ALIAS(G, G_sprite); +} G = ZI, DEBUG_ALIAS(G, G_sprite); /* ========================== * * Thread local state @@ -285,7 +285,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(sprite_shutdown) struct sprite_tag sprite_tag_from_path(struct string path) { - struct sprite_tag res = { 0 }; + struct sprite_tag res = ZI; res.hash = HASH_FNV128_BASIS; res.hash = hash_fnv128(res.hash, BUFFER_FROM_STRING(path)); res.path = path; @@ -352,7 +352,7 @@ INTERNAL void cache_node_load_texture(struct cache_node *n, struct sprite_tag ta u64 memory_size = 0; { /* Decode */ - struct ase_decode_image_result decoded = { 0 }; + struct ase_decode_image_result decoded = ZI; if (resource_exists(path)) { struct resource texture_rs = resource_open(path); decoded = ase_decode_image(scratch.arena, texture_rs.bytes); @@ -396,7 +396,7 @@ INTERNAL void cache_node_load_texture(struct cache_node *n, struct sprite_tag ta INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, struct ase_decode_sheet_result ase) { __prof; - struct sprite_sheet sheet = { 0 }; + struct sprite_sheet sheet = ZI; ASSERT(ase.num_frames >= 1); @@ -655,7 +655,7 @@ INTERNAL void cache_node_load_sheet(struct cache_node *n, struct sprite_tag tag) n->arena = arena_alloc(SHEET_ARENA_RESERVE); { /* Decode */ - struct ase_decode_sheet_result decoded = { 0 }; + struct ase_decode_sheet_result decoded = ZI; if (resource_exists(path)) { struct resource sheet_rs = resource_open(path); decoded = ase_decode_sheet(scratch.arena, sheet_rs.bytes); @@ -942,7 +942,7 @@ struct sprite_sheet_frame sprite_sheet_get_frame(struct sprite_sheet *sheet, u32 if (index < sheet->frames_count ) { return sheet->frames[index]; } - struct sprite_sheet_frame res = { 0 }; + struct sprite_sheet_frame res = ZI; res.index = 0; res.duration = 0.1; res.clip = CLIP_ALL; @@ -952,7 +952,7 @@ struct sprite_sheet_frame sprite_sheet_get_frame(struct sprite_sheet *sheet, u32 struct sprite_sheet_span sprite_sheet_get_span(struct sprite_sheet *sheet, struct string name) { __prof; - struct sprite_sheet_span res = { 0 }; + struct sprite_sheet_span res = ZI; if (sheet->spans_count > 0) { struct sprite_sheet_span *entry = fixed_dict_get(&sheet->spans_dict, name); if (entry) { @@ -972,7 +972,7 @@ struct sprite_sheet_slice sprite_sheet_get_slice(struct sprite_sheet *sheet, str } /* Return 'pivot' by default */ - struct sprite_sheet_slice res = { 0 }; + struct sprite_sheet_slice res = ZI; if (string_eq(name, STR("pivot"))) { /* 'pivot' slice does not exist, return center */ res.center = V2(0, 0); @@ -988,7 +988,7 @@ struct sprite_sheet_slice sprite_sheet_get_slice(struct sprite_sheet *sheet, str struct sprite_sheet_slice_array sprite_sheet_get_slices(struct sprite_sheet *sheet, struct string name, u32 frame_index) { - struct sprite_sheet_slice_array res = { 0 }; + struct sprite_sheet_slice_array res = ZI; if (sheet->slice_groups_count > 0) { struct sprite_sheet_slice_group *group = fixed_dict_get(&sheet->slice_groups_dict, name); if (group) { diff --git a/src/string.c b/src/string.c index 94a73242..1e4f6be6 100644 --- a/src/string.c +++ b/src/string.c @@ -199,7 +199,7 @@ struct string string_repeat(struct arena *arena, struct string src, u64 count) struct string string_cat(struct arena *arena, struct string str1, struct string str2) { - struct string new_str = { 0 }; + struct string new_str = ZI; new_str.len = str1.len + str2.len; new_str.text = arena_push_array(arena, u8, new_str.len); MEMCPY(new_str.text, str1.text, str1.len); @@ -281,7 +281,7 @@ struct string string_indent(struct arena *arena, struct string str, u32 indent) struct string string_lower(struct arena *arena, struct string str) { - struct string res = { 0 }; + struct string res = ZI; res.text = arena_push_array(arena, u8, str.len); res.len = str.len; @@ -416,7 +416,7 @@ struct string string_formatv(struct arena *arena, struct string fmt, va_list arg } if (!no_more_args && !escape && *c == '%' && *next == 'F') { - struct string parsed_str = { 0 }; + struct string parsed_str = ZI; /* Detect arg type and parse to string */ struct fmt_arg arg = va_arg(args, struct fmt_arg); switch (arg.type) { diff --git a/src/sys_win32.c b/src/sys_win32.c index d2856eba..2e038799 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -130,7 +130,7 @@ GLOBAL struct { struct sys_mutex windows_mutex; struct arena windows_arena; struct win32_window *first_free_window; -} G = { 0 }, DEBUG_ALIAS(G, G_sys_win32); +} G = ZI, DEBUG_ALIAS(G, G_sys_win32); /* ========================== * * Events @@ -304,7 +304,7 @@ struct string sys_get_write_path(struct arena *arena) NULL, &p ); - struct string path = { 0 }; + struct string path = ZI; if (res == S_OK) { path = string_from_win32_path(arena, p); } @@ -337,7 +337,7 @@ void sys_mkdir(struct string path) struct temp_arena 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 = { 0 }; + struct string err = ZI; switch (err_code) { case ERROR_BAD_PATHNAME: { err = STR("Bad path name"); @@ -629,7 +629,7 @@ struct win32_file_filter { struct sys_file_filter sys_file_filter_begin(struct arena *arena, struct string pattern) { - struct sys_file_filter filter = { 0 }; + struct sys_file_filter filter = ZI; struct win32_file_filter *filter_internal = arena_push_zero(arena, struct win32_file_filter); filter_internal->filter_wstr = wstr_from_string(arena, pattern); filter.handle = (u64)filter_internal; @@ -640,7 +640,7 @@ b32 sys_file_filter_next(struct arena *arena, struct sys_file_filter *filter) { struct win32_file_filter *filter_internal = (struct win32_file_filter *)filter->handle; - WIN32_FIND_DATAW find_file_data = { 0 }; + WIN32_FIND_DATAW find_file_data = ZI; b32 found = false; if (filter_internal->find_handle) { @@ -933,7 +933,7 @@ INTERNAL void win32_update_window_from_settings(struct win32_window *window, str } } - RECT rect = { 0 }; + RECT rect = ZI; b32 old_fullscreen = old_settings.flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN; b32 fullscreen = settings->flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN; @@ -1373,7 +1373,7 @@ struct sys_lock sys_mutex_lock_e(struct sys_mutex *mutex) mutex->owner_tid = (u64)GetCurrentThreadId(); atomic_i64_inc_eval(&mutex->count); #endif - struct sys_lock lock = { 0 }; + struct sys_lock lock = ZI; lock.exclusive = true; lock.mutex = mutex; return lock; @@ -1386,7 +1386,7 @@ struct sys_lock sys_mutex_lock_s(struct sys_mutex *mutex) #if RTC atomic_i64_inc_eval(&mutex->count); #endif - struct sys_lock lock = { 0 }; + struct sys_lock lock = ZI; lock.mutex = mutex; return lock; } @@ -1563,7 +1563,7 @@ INTERNAL struct win32_tls *win32_thread_get_tls(void) INTERNAL struct win32_tls win32_tls_alloc(void) { - struct win32_tls tls = { 0 }; + struct win32_tls tls = ZI; tls.sleep_timer = CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS); tls.store = thread_local_store_alloc(); return tls; @@ -1706,7 +1706,7 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi ASSERT(entry_point != NULL); logf_info("Creating thread \"%F\"", FMT_STR(thread_name)); - struct sys_thread res = { 0 }; + struct sys_thread res = ZI; struct sys_lock lock = sys_mutex_lock_e(&G.threads_mutex); { /* Allocate thread object */ @@ -1838,7 +1838,7 @@ void sys_set_clipboard_text(struct string str) struct string sys_get_clipboard_text(struct arena *arena) { - struct string res = { 0 }; + struct string res = ZI; if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0)) { HANDLE handle = GetClipboardData(CF_UNICODETEXT); if (handle) { @@ -2103,7 +2103,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance, wc->hInstance = instance; /* Use first icon resource as window icon (same as explorer) */ - wchar_t path[4096] = { 0 }; + wchar_t path[4096] = ZI; GetModuleFileNameW(instance, path, ARRAY_COUNT(path)); ExtractIconExW(path, 0, &wc->hIcon, &wc->hIconSm, 1); diff --git a/src/tar.c b/src/tar.c index 0ce0387f..90bc462c 100644 --- a/src/tar.c +++ b/src/tar.c @@ -69,13 +69,13 @@ struct tar_archive tar_parse(struct arena *arena, struct buffer data, struct str { __prof; - struct tar_archive archive = { 0 }; + struct tar_archive archive = ZI; struct byte_reader br = br_create_from_buffer(data); u64 num_files = 0; while (br_bytes_left(&br) > 1024) { - struct tar_header header = { 0 }; + struct tar_header header = ZI; br_read_to_struct(&br, &header); if (!string_eq(STRING_FROM_ARRAY(header.ustar_indicator), STR("ustar\0"))) { diff --git a/src/thread_local.c b/src/thread_local.c index 93bb623c..ab4656e5 100644 --- a/src/thread_local.c +++ b/src/thread_local.c @@ -13,7 +13,7 @@ GLOBAL struct { struct atomic_i32 metas_lock_flag; u64 metas_count; struct thread_local_var_meta metas[MAX_THREAD_LOCAL_VARS]; -} G = { 0 }, DEBUG_ALIAS(G, G_thread_local); +} G = ZI, DEBUG_ALIAS(G, G_thread_local); INTERNAL void metas_lock(void) { @@ -31,7 +31,7 @@ INTERNAL void metas_unlock(void) struct thread_local_store thread_local_store_alloc(void) { __prof; - struct thread_local_store t = { 0 }; + struct thread_local_store t = ZI; t.arena = arena_alloc(THREAD_LOCAL_STORE_RESERVE); t.lookup = arena_push_array_zero(&t.arena, void *, MAX_THREAD_LOCAL_VARS); t.allocation_order = arena_push_array_zero(&t.arena, u64, MAX_THREAD_LOCAL_VARS); diff --git a/src/ttf_dwrite.cpp b/src/ttf_dwrite.cpp index 1fe3ce6f..f4119394 100644 --- a/src/ttf_dwrite.cpp +++ b/src/ttf_dwrite.cpp @@ -32,7 +32,7 @@ extern "C" GLOBAL struct { /* FIXME: Do we need to wrap this in a mutex? */ IDWriteFactory5 *factory; -} G = { 0 }, DEBUG_ALIAS(G, L_ttf_dwrite); +} G = ZI, DEBUG_ALIAS(G, L_ttf_dwrite); /* ========================== * * Decode font @@ -122,7 +122,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, error = factory->GetGdiInterop(&dwrite_gdi_interop); /* Get Metrics */ - DWRITE_FONT_METRICS metrics = { 0 }; + DWRITE_FONT_METRICS metrics = ZI; font_face->GetMetrics(&metrics); f32 pixel_per_em = point_size * (DPI / 72.0f); @@ -175,13 +175,13 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, u32 row_height = 0; for (u16 i = 0; i < glyph_count; ++i) { /* Render glyph to target */ - DWRITE_GLYPH_RUN glyph_run = { 0 }; + DWRITE_GLYPH_RUN glyph_run = ZI; glyph_run.fontFace = font_face; glyph_run.fontEmSize = pixel_per_em; glyph_run.glyphCount = 1; glyph_run.glyphIndices = &i; - RECT bounding_box = { 0 }; + RECT bounding_box = ZI; error = render_target->DrawGlyphRun( raster_target_x, raster_target_y, @@ -201,7 +201,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, } /* Compute glyph metrics */ - DWRITE_GLYPH_METRICS glyph_metrics = { 0 }; + DWRITE_GLYPH_METRICS glyph_metrics = ZI; error = font_face->GetDesignGlyphMetrics(&i, 1, &glyph_metrics, false); @@ -221,7 +221,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, /* Get the bitmap */ HBITMAP bitmap = (HBITMAP)GetCurrentObject(dc, OBJ_BITMAP); - DIBSECTION dib = { 0 }; + DIBSECTION dib = ZI; GetObject(bitmap, sizeof(dib), &dib); /* Start new row if necessary */ @@ -241,7 +241,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, } /* Set bounding box metrics (now that we know atlas x & y) */ - glyph->atlas_rect = { 0 }; + glyph->atlas_rect = ZI; glyph->atlas_rect.x = (f32)out_offset_x; glyph->atlas_rect.y = (f32)out_offset_y; glyph->atlas_rect.width = (f32)tex_w; @@ -298,7 +298,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded, factory->Release(); /* Return */ - struct ttf_decode_result result = { 0 }; + struct ttf_decode_result result = ZI; result.glyphs = glyphs; result.glyphs_count = glyph_count; result.cache_indices = cache_indices; diff --git a/src/uni.c b/src/uni.c index 43070359..84ceb50d 100644 --- a/src/uni.c +++ b/src/uni.c @@ -76,7 +76,7 @@ struct uni_decode_utf8_result uni_decode_utf8(struct string str) struct uni_encode_utf8_result uni_encode_utf8(u32 codepoint) { - struct uni_encode_utf8_result res = { 0 }; + struct uni_encode_utf8_result res = ZI; if (codepoint <= 0x7F) { res.count8 = 1; @@ -136,7 +136,7 @@ struct uni_decode_utf16_result uni_decode_utf16(struct string16 str) struct uni_encode_utf16_result uni_encode_utf16(u32 codepoint) { - struct uni_encode_utf16_result res = { 0 }; + struct uni_encode_utf16_result res = ZI; if (codepoint <= 0xFFFF) { res.count16 = 1; @@ -189,7 +189,7 @@ struct uni_decode_utf32_result uni_decode_utf32(struct string32 str) struct uni_encode_utf32_result uni_encode_utf32(u32 codepoint) { - struct uni_encode_utf32_result res = { 0 }; + struct uni_encode_utf32_result res = ZI; if (codepoint <= 0x10FFFF) { res.chars32 = codepoint; diff --git a/src/user.c b/src/user.c index c54862a9..f83ff272 100644 --- a/src/user.c +++ b/src/user.c @@ -69,7 +69,7 @@ GLOBAL struct { struct v2 viewport_center; struct v2 viewport_cursor; struct v2 world_cursor; -} G = { 0 }, DEBUG_ALIAS(G, G_user); +} G = ZI, DEBUG_ALIAS(G, G_user); /* ========================== * * Bind state @@ -165,7 +165,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(user_shutdown) INTERNAL struct sys_event_array pop_sys_events(struct arena *arena) { - struct sys_event_array array = { 0 }; + struct sys_event_array array = ZI; struct sys_lock lock = sys_mutex_lock_e(&G.sys_events_mutex); { struct buffer events_buff = arena_to_buffer(&G.sys_events_arena); @@ -435,7 +435,7 @@ INTERNAL void user_update(void) struct entity_store *store = G.world.entity_store; struct sprite_scope *sprite_frame_scope = sprite_scope_begin(); - struct game_cmd_list cmd_list = { 0 }; + struct game_cmd_list cmd_list = ZI; /* ========================== * * Produce interpolated tick @@ -1223,7 +1223,7 @@ INTERNAL void user_update(void) move_speed *= walk_ratio; } - struct v2 input_move_dir = { 0 }; + struct v2 input_move_dir = ZI; { for (enum user_bind_kind bind = 0; bind < (i32)ARRAY_COUNT(G.bind_states); ++bind) { struct bind_state state = G.bind_states[bind]; diff --git a/src/util.h b/src/util.h index ddfdd47f..6369e47b 100644 --- a/src/util.h +++ b/src/util.h @@ -66,7 +66,7 @@ struct fixed_dict { INLINE struct fixed_dict fixed_dict_init(struct arena *arena, u64 buckets_count) { __prof; - struct fixed_dict dict = { 0 }; + struct fixed_dict dict = ZI; buckets_count = max_u64(buckets_count, 1); /* Ensure at least 1 bucket */ dict.buckets_count = buckets_count; dict.buckets = arena_push_array_zero(arena, struct fixed_dict_bucket, buckets_count); @@ -133,7 +133,7 @@ struct sync_flag { INLINE struct sync_flag sync_flag_alloc(void) { - struct sync_flag sf = { 0 }; + struct sync_flag sf = ZI; sf.mutex = sys_mutex_alloc(); sf.cv = sys_condition_variable_alloc(); return sf; diff --git a/src/work.c b/src/work.c index cd405465..532a9b1f 100644 --- a/src/work.c +++ b/src/work.c @@ -82,7 +82,7 @@ GLOBAL struct { /* Pointers to the last piece of work of each priority in the scheduled * work list (used for O(1) insertion) */ struct work *scheduled_work_priority_tails[NUM_WORK_PRIORITIES]; -} G = { 0 }, DEBUG_ALIAS(G, G_work); +} G = ZI, DEBUG_ALIAS(G, G_work); /* ========================== * * Thread local state @@ -502,7 +502,7 @@ struct work_handle work_push_task_and_help(work_task_func *func, void *data, enu struct work_slate work_slate_begin(void) { __prof; - struct work_slate ws = { 0 }; + struct work_slate ws = ZI; return ws; }