bunch of code quality fixes

efd/v1
Dominik Madarász 2023-02-10 06:42:30 +01:00
parent eccaa14bda
commit e302d1c865
10 changed files with 21 additions and 22 deletions

3
.gitignore vendored
View File

@ -1,6 +1,5 @@
build build
build_rel build_*
build_web
emsdk emsdk
deploy_web deploy_web
run_web run_web

View File

@ -100,7 +100,7 @@ void game_world_view_cycle_active(int8_t dir) {
game_world_view_set_active_by_idx(zpl_max(0, (idx+dir)%zpl_buffer_count(world_viewers))); game_world_view_set_active_by_idx(zpl_max(0, (idx+dir)%zpl_buffer_count(world_viewers)));
} }
void game_world_view_set_active_by_idx(uint16_t idx) { void game_world_view_set_active_by_idx(uint16_t idx) {
ZPL_ASSERT(idx >= 0 && idx < zpl_buffer_count(world_viewers)); ZPL_ASSERT(idx < zpl_buffer_count(world_viewers));
game_world_view_set_active(&world_viewers[idx]); game_world_view_set_active(&world_viewers[idx]);
} }

View File

@ -66,8 +66,8 @@ ActSpawnMobs(void) {
for (uint32_t cy=y; cy<y+h; cy+=WORLD_BLOCK_SIZE) { for (uint32_t cy=y; cy<y+h; cy+=WORLD_BLOCK_SIZE) {
for (uint32_t cx=x; cx<x+w; cx+=WORLD_BLOCK_SIZE) { for (uint32_t cx=x; cx<x+w; cx+=WORLD_BLOCK_SIZE) {
if (cx < 0 || cx >= world_dim()) continue; if (cx >= world_dim()) continue;
if (cy < 0 || cy >= world_dim()) continue; if (cy >= world_dim()) continue;
if ((cy == y || cy == (y + h-WORLD_BLOCK_SIZE)) || if ((cy == y || cy == (y + h-WORLD_BLOCK_SIZE)) ||
(cx == x || cx == (x + w-WORLD_BLOCK_SIZE))) { (cx == x || cx == (x + w-WORLD_BLOCK_SIZE))) {

View File

@ -45,7 +45,7 @@ uint16_t craft_get_recipe_id_from_product(asset_id id) {
} }
recipe craft_get_recipe_data(uint16_t i) { recipe craft_get_recipe_data(uint16_t i) {
ZPL_ASSERT(i >= 0 && i < MAX_RECIPES); ZPL_ASSERT(i < MAX_RECIPES);
return recipes[i]; return recipes[i];
} }

View File

@ -12,7 +12,7 @@
#define ITEMS_COUNT (sizeof(items)/sizeof(item_desc)) #define ITEMS_COUNT (sizeof(items)/sizeof(item_desc))
static inline item_id item_resolve_proxy(item_id id) { static inline item_id item_resolve_proxy(item_id id) {
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); ZPL_ASSERT(id < ITEMS_COUNT);
item_usage usage = items[id].usage; item_usage usage = items[id].usage;
if (usage == UKIND_PROXY) { if (usage == UKIND_PROXY) {
return item_find(items[id].proxy.id); return item_find(items[id].proxy.id);
@ -164,21 +164,21 @@ void item_despawn(uint64_t id) {
} }
uint32_t item_max_quantity(item_id id) { uint32_t item_max_quantity(item_id id) {
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); ZPL_ASSERT(id < ITEMS_COUNT);
return items[id].max_quantity; return items[id].max_quantity;
} }
item_usage item_get_usage(item_id id) { item_usage item_get_usage(item_id id) {
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); ZPL_ASSERT(id < ITEMS_COUNT);
return items[id].usage; return items[id].usage;
} }
bool item_get_place_directional(item_id id) { bool item_get_place_directional(item_id id) {
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); ZPL_ASSERT(id < ITEMS_COUNT);
return items[id].place.directional; return items[id].place.directional;
} }
item_desc item_get_desc(item_id id) { item_desc item_get_desc(item_id id) {
ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); ZPL_ASSERT(id < ITEMS_COUNT);
return items[id]; return items[id];
} }

View File

@ -1,7 +1,7 @@
#include "input.h" #include "input.h"
#include "raylib.h" #include "raylib.h"
const static input_map maps[] = { static const input_map maps[] = {
{ {
"left", "left",
IN_LEFT, IN_LEFT,

View File

@ -28,7 +28,7 @@ void PickItem(ecs_iter_t *it) {
uint16_t item_id = item ? item_find(item->kind) : 0; uint16_t item_id = item ? item_find(item->kind) : 0;
if (!item || (item_id != ASSET_INVALID && (item->kind == drop->kind && item->durability == drop->durability) && item->quantity < item_max_quantity(drop_id))) { if (!item || (item_id != ASSET_INVALID && (item->kind == drop->kind && item->durability == drop->durability) && item->quantity < item_max_quantity(drop_id))) {
if (item) { if (item) {
uint32_t picked_count = zpl_max(0, drop->quantity); uint32_t picked_count = zpl_max(0, (int32_t)drop->quantity);
picked_count = zpl_clamp(picked_count, 0, item_max_quantity(drop_id) - item->quantity); picked_count = zpl_clamp(picked_count, 0, item_max_quantity(drop_id) - item->quantity);
item->quantity += picked_count; item->quantity += picked_count;
drop->quantity -= picked_count; drop->quantity -= picked_count;
@ -378,7 +378,7 @@ void HarvestIntoContainers(ecs_iter_t *it) {
uint16_t item_id = item ? item_find(item->kind) : 0; uint16_t item_id = item ? item_find(item->kind) : 0;
if (!item || (item_id != ASSET_INVALID && (item->kind == drop->kind && item->durability == drop->durability) && item->quantity < item_max_quantity(drop_id))) { if (!item || (item_id != ASSET_INVALID && (item->kind == drop->kind && item->durability == drop->durability) && item->quantity < item_max_quantity(drop_id))) {
if (item) { if (item) {
uint32_t picked_count = zpl_max(0, drop->quantity); uint32_t picked_count = zpl_max(0, (int32_t)drop->quantity);
picked_count = zpl_clamp(picked_count, 0, item_max_quantity(drop_id) - item->quantity); picked_count = zpl_clamp(picked_count, 0, item_max_quantity(drop_id) - item->quantity);
item->quantity += picked_count; item->quantity += picked_count;
drop->quantity -= picked_count; drop->quantity -= picked_count;

View File

@ -658,14 +658,14 @@ int64_t world_chunk_from_entity(ecs_entity_t id) {
} }
void world_chunk_replace_worldgen_block(int64_t id, uint16_t block_idx, block_id bid) { void world_chunk_replace_worldgen_block(int64_t id, uint16_t block_idx, block_id bid) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); ZPL_ASSERT(block_idx < zpl_square(world.chunk_size));
ZPL_ASSERT(!(blocks_get_flags(bid) & BLOCK_FLAG_ENTITY)); ZPL_ASSERT(!(blocks_get_flags(bid) & BLOCK_FLAG_ENTITY));
world.block_mapping[id][block_idx] = bid; world.block_mapping[id][block_idx] = bid;
world_chunk_mark_dirty(world.chunk_mapping[id]); world_chunk_mark_dirty(world.chunk_mapping[id]);
} }
void world_chunk_replace_block(int64_t id, uint16_t block_idx, block_id bid) { void world_chunk_replace_block(int64_t id, uint16_t block_idx, block_id bid) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); ZPL_ASSERT(block_idx < zpl_square(world.chunk_size));
if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) { if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) {
ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid)); ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid));
world_block_lookup l = world_block_from_index(id, block_idx); world_block_lookup l = world_block_from_index(id, block_idx);
@ -678,7 +678,7 @@ void world_chunk_replace_block(int64_t id, uint16_t block_idx, block_id bid) {
} }
bool world_chunk_place_block(int64_t id, uint16_t block_idx, block_id bid) { bool world_chunk_place_block(int64_t id, uint16_t block_idx, block_id bid) {
ZPL_ASSERT(block_idx >= 0 && block_idx < zpl_square(world.chunk_size)); ZPL_ASSERT(block_idx < zpl_square(world.chunk_size));
if (world.outer_block_mapping[id][block_idx] != 0 && bid != 0) return false; if (world.outer_block_mapping[id][block_idx] != 0 && bid != 0) return false;
if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) { if (blocks_get_flags(bid) & BLOCK_FLAG_ENTITY) {
ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid)); ecs_entity_t e = entity_spawn_id(blocks_get_asset(bid));

View File

@ -25,8 +25,8 @@ int worldgen_in_circle(int x, int y, int radius) {
static void world_fill_rect(block_id *data, block_id id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { static void world_fill_rect(block_id *data, block_id id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) {
for (uint32_t cy=y; cy<y+h; cy++) { for (uint32_t cy=y; cy<y+h; cy++) {
for (uint32_t cx=x; cx<x+w; cx++) { for (uint32_t cx=x; cx<x+w; cx++) {
if (cx < 0 || cx >= world->dim) continue; if (cx >= world->dim) continue;
if (cy < 0 || cy >= world->dim) continue; if (cy >= world->dim) continue;
uint32_t i = (cy*world->dim) + cx; uint32_t i = (cy*world->dim) + cx;
if (proc) { if (proc) {

View File

@ -1094,8 +1094,8 @@ c2TOIResult c2TOI(const void* A, C2_TYPE typeA, const c2x* ax_ptr, c2v vA, const
if (!bx_ptr) bx = c2xIdentity(); if (!bx_ptr) bx = c2xIdentity();
else bx = *bx_ptr; else bx = *bx_ptr;
c2Proxy pA; c2Proxy pA = { 0 };
c2Proxy pB; c2Proxy pB = { 0 };
c2MakeProxy(A, typeA, &pA); c2MakeProxy(A, typeA, &pA);
c2MakeProxy(B, typeB, &pB); c2MakeProxy(B, typeB, &pB);
@ -1933,7 +1933,7 @@ void c2AABBtoPolyManifold(c2AABB A, const c2Poly* B, const c2x* bx, c2Manifold*
// clip a segment to a plane // clip a segment to a plane
static int c2Clip(c2v* seg, c2h h) static int c2Clip(c2v* seg, c2h h)
{ {
c2v out[2]; c2v out[2] = { 0 };
int sp = 0; int sp = 0;
float d0, d1; float d0, d1;
if ((d0 = c2Dist(h, seg[0])) < 0) out[sp++] = seg[0]; if ((d0 = c2Dist(h, seg[0])) < 0) out[sp++] = seg[0];