code: rewrite assertions

isolation_bkp/dynres
Dominik Madarász 2021-08-11 15:49:44 +02:00
parent 5d7b275c87
commit c5849da051
4 changed files with 22 additions and 20 deletions

View File

@ -36,7 +36,7 @@ static char replay_filename[1024] = {0};
static char replaybuf[sizeof(replay_record)*UINT16_MAX + 32];
void debug_replay_store(void) {
assert(replay_filename[0]);
ZPL_ASSERT(replay_filename[0]);
if (!records) return;
cw_pack_context pc = {0};
@ -56,10 +56,12 @@ void debug_replay_store(void) {
}
void debug_replay_load(void) {
assert(replay_filename[0]);
ZPL_ASSERT(replay_filename[0]);
zpl_file f = {0};
assert(zpl_file_open(&f, replay_filename) == ZPL_FILE_ERROR_NONE);
zpl_file_error err = zpl_file_open(&f, replay_filename);
ZPL_ASSERT(err == ZPL_FILE_ERROR_NONE);
size_t file_size = zpl_file_size(&f);
zpl_file_read(&f, replaybuf, file_size);
zpl_file_close(&f);
@ -68,20 +70,20 @@ void debug_replay_load(void) {
cw_unpack_context_init(&uc, replaybuf, file_size, 0);
cw_unpack_next(&uc);
assert(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_MAGIC);
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_MAGIC);
cw_unpack_next(&uc);
assert(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_VERSION);
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_VERSION);
cw_unpack_next(&uc);
assert(uc.item.type == CWP_ITEM_ARRAY);
ZPL_ASSERT(uc.item.type == CWP_ITEM_ARRAY);
size_t items = uc.item.as.array.size;
zpl_array_init_reserve(records, zpl_heap(), sizeof(replay_record)*items);
for (size_t i = 0; i < items; i++) {
cw_unpack_next(&uc);
assert(uc.item.type == CWP_ITEM_BIN);
ZPL_ASSERT(uc.item.type == CWP_ITEM_BIN);
replay_record rec = {0};
zpl_memcopy(&rec, uc.item.as.bin.start, sizeof(replay_record));
@ -204,7 +206,7 @@ void debug_replay_record_keystate(pkt_send_keystate state) {
}
void debug_replay_special_action(replay_kind kind) {
assert(kind != RPKIND_KEY);
ZPL_ASSERT(kind != RPKIND_KEY);
if (!is_recording || is_playing) return;
float record_time = zpl_time_rel_ms();

View File

@ -198,7 +198,7 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
ypos += DBG_GAP_HEIGHT;
}break;
case DITEM_COND: {
assert(it->on_success);
ZPL_ASSERT(it->on_success);
if (!it->on_success()) {
it += it->skip ? it->skip : 1;
@ -227,14 +227,14 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
}
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, RAYWHITE);
assert(it->proc);
ZPL_ASSERT(it->proc);
debug_draw_result res = it->proc(it, xpos + it->name_width, ypos);
ypos = res.y;
}break;
case DITEM_RAW: {
assert(it->proc);
ZPL_ASSERT(it->proc);
debug_draw_result res = it->proc(it, xpos, ypos);
ypos = res.y;
@ -259,7 +259,7 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
}break;
case DITEM_SLIDER: {
assert(it->slider.min != it->slider.max);
ZPL_ASSERT(it->slider.min != it->slider.max);
char const *text = TextFormat("%s: ", it->name);
if (it->name_width == 0) {
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
@ -344,7 +344,7 @@ debug_area_status check_mouse_area(float xpos, float ypos, float w, float h) {
}
bool is_btn_pressed(float xpos, float ypos, float w, float h, Color *color) {
assert(color);
ZPL_ASSERT(color);
*color = RAYWHITE;
debug_area_status area = check_mouse_area(xpos, ypos, w, h);
if (area == DAREA_PRESS) {

View File

@ -14,7 +14,7 @@ DrawFloat(float xpos, float ypos, float val) {
static inline debug_draw_result
DrawColoredText(float xpos, float ypos, char const *text, Color color) {
assert(text);
ZPL_ASSERT(text);
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, color);
return (debug_draw_result){.x = xpos + UIMeasureText(text, DBG_FONT_SIZE), .y = ypos + DBG_FONT_SPACING};
}
@ -58,7 +58,7 @@ DrawZoom(debug_item *it, float xpos, float ypos) {
static inline debug_draw_result
DrawLiteral(debug_item *it, float xpos, float ypos) {
assert(it->text);
ZPL_ASSERT(it->text);
return DrawFormattedText(xpos, ypos, it->text);
}

View File

@ -23,7 +23,7 @@ entity_view world_build_entity_view(int64_t e) {
entity_view view = {0};
const Classify *classify = ecs_get(world_ecs(), e, Classify);
assert(classify);
ZPL_ASSERT(classify);
view.kind = classify->id;
@ -305,7 +305,7 @@ uint16_t world_dim(void) {
}
ecs_entity_t world_chunk_mapping(librg_chunk id) {
assert(id >= 0 && id < zpl_square(world.chunk_amount));
ZPL_ASSERT(id >= 0 && id < zpl_square(world.chunk_amount));
return world.chunk_mapping[id];
}
@ -366,7 +366,7 @@ int64_t world_chunk_from_entity(ecs_entity_t id) {
}
void world_chunk_replace_block(ecs_world_t *ecs, int64_t id, uint16_t block_idx, uint8_t block_id) {
assert(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size));
world.block_mapping[id][block_idx] = block_id;
world_chunk_mark_dirty(ecs, world.chunk_mapping[id]);
}
@ -378,14 +378,14 @@ uint8_t *world_chunk_get_blocks(int64_t id) {
void world_chunk_mark_dirty(ecs_world_t *ecs, ecs_entity_t e) {
bool was_added=false;
Chunk *chunk = ecs_get_mut(ecs, e, Chunk, &was_added);
assert(!was_added);
ZPL_ASSERT(!was_added);
if (chunk) chunk->is_dirty = true;
}
uint8_t world_chunk_is_dirty(ecs_world_t *ecs, ecs_entity_t e) {
bool was_added=false;
Chunk *chunk = ecs_get_mut(ecs, e, Chunk, &was_added);
assert(!was_added);
ZPL_ASSERT(!was_added);
if (chunk) return chunk->is_dirty;
return false;
}