From 245f554990c04e0dc3483ae211e6e1006f6ff1c8 Mon Sep 17 00:00:00 2001 From: xtreme8000 Date: Sat, 9 Dec 2023 19:46:53 +0100 Subject: [PATCH] Fix a few compiler warnings --- CMakeLists.txt | 1 + source/graphics/texture_atlas.c | 5 ++- source/network/inventory_logic.c | 73 ++++++++++++++++++++++++++++++++ source/network/inventory_logic.h | 57 ++----------------------- 4 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 source/network/inventory_logic.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fd26ed..69e200a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ add_executable(cavex source/network/server_interface.c source/network/server_local.c source/network/server_world.c + source/network/inventory_logic.c source/network/inventory_player.c source/network/inventory_crafting.c source/network/inventory_furnace.c diff --git a/source/graphics/texture_atlas.c b/source/graphics/texture_atlas.c index a6e5019..780cfbf 100644 --- a/source/graphics/texture_atlas.c +++ b/source/graphics/texture_atlas.c @@ -104,8 +104,9 @@ void* tex_atlas_compute(dict_atlas_src_t atlas, uint8_t* atlas_dst, size_t current_y = (current / 14) * (tile_size + 2 * border_scale) + 3 * border_scale; - for(int y = -border_scale; y < tile_size + border_scale; y++) { - for(int x = -border_scale; x < tile_size + border_scale; x++) { + // int64_t to prevent unreasonable gcc warning + for(int64_t y = -border_scale; y < tile_size + border_scale; y++) { + for(int64_t x = -border_scale; x < tile_size + border_scale; x++) { uint8_t* src_col = image + ((clamp_n(x, tile_size) + e->x * tile_size) + (clamp_n(y, tile_size) + e->y * tile_size) * width) diff --git a/source/network/inventory_logic.c b/source/network/inventory_logic.c new file mode 100644 index 0000000..399a402 --- /dev/null +++ b/source/network/inventory_logic.c @@ -0,0 +1,73 @@ +/* + Copyright (c) 2023 ByteBit/xtreme8000 + + This file is part of CavEX. + + CavEX is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + CavEX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with CavEX. If not, see . +*/ + +#include "inventory_logic.h" + +#define min(a, b) ((a) < (b) ? (a) : (b)) + +bool inventory_collect(struct inventory* inv, struct item_data* item, + uint8_t* slot_priority, size_t slot_length, + set_inv_slot_t changes) { + assert(inv && item && item->id != 0 && changes); + + struct item* it = item_get(item); + + if(!it) + return false; + + while(item->count > 0) { + bool has_canidate_equal = false; + size_t candidate_equal = 0; + bool has_canidate_empty = false; + size_t candidate_empty = 0; + + for(size_t k = 0; k < slot_length; k++) { + uint8_t slot = slot_priority[k]; + + if(inv->items[slot].id == item->id + && inv->items[slot].durability == item->durability + && inv->items[slot].count < it->max_stack) { + has_canidate_equal = true; + candidate_equal = slot; + break; + } + + if(!has_canidate_empty && inv->items[slot].id == 0) { + has_canidate_empty = true; + candidate_empty = slot; + } + } + + if(has_canidate_equal || has_canidate_empty) { + size_t candidate + = has_canidate_equal ? candidate_equal : candidate_empty; + size_t additional + = min(it->max_stack - inv->items[candidate].count, item->count); + inv->items[candidate].id = item->id; + inv->items[candidate].durability = item->durability; + inv->items[candidate].count += additional; + item->count -= additional; + set_inv_slot_push(changes, candidate); + } else { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/source/network/inventory_logic.h b/source/network/inventory_logic.h index e91a695..a88d8aa 100644 --- a/source/network/inventory_logic.h +++ b/source/network/inventory_logic.h @@ -19,60 +19,9 @@ #include "../item/inventory.h" -#define min(a, b) ((a) < (b) ? (a) : (b)) - -static bool inventory_collect(struct inventory* inv, struct item_data* item, - uint8_t* slot_priority, size_t slot_length, - set_inv_slot_t changes) { - assert(inv && item && item->id != 0 && changes); - - struct item* it = item_get(item); - - if(!it) - return false; - - while(item->count > 0) { - bool has_canidate_equal = false; - size_t candidate_equal = 0; - bool has_canidate_empty = false; - size_t candidate_empty = 0; - - for(size_t k = 0; k < slot_length; k++) { - uint8_t slot = slot_priority[k]; - - if(inv->items[slot].id == item->id - && inv->items[slot].durability == item->durability - && inv->items[slot].count < it->max_stack) { - has_canidate_equal = true; - candidate_equal = slot; - break; - } - - if(!has_canidate_empty && inv->items[slot].id == 0) { - has_canidate_empty = true; - candidate_empty = slot; - } - } - - if(has_canidate_equal || has_canidate_empty) { - size_t candidate - = has_canidate_equal ? candidate_equal : candidate_empty; - size_t additional - = min(it->max_stack - inv->items[candidate].count, item->count); - inv->items[candidate].id = item->id; - inv->items[candidate].durability = item->durability; - inv->items[candidate].count += additional; - item->count -= additional; - set_inv_slot_push(changes, candidate); - } else { - return false; - } - } - - return true; -} - -#undef min +bool inventory_collect(struct inventory* inv, struct item_data* item, + uint8_t* slot_priority, size_t slot_length, + set_inv_slot_t changes); extern struct inventory_logic inventory_logic_player; extern struct inventory_logic inventory_logic_crafting;