From a6bacb6e8cb7cd89b9a179cfaacf30685b5db015 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Sun, 24 Aug 2025 12:54:23 +0200 Subject: [PATCH] Compiling for 32 bit arch because of compatibility with SH4 arch --- Makefile | 6 +-- assets/maps/example.json | 2 +- assets/maps/map_converter.py | 20 ++++++--- src/game_data/ecs/ecs.hpp | 3 +- src/game_data/game_data.hpp | 4 +- src/game_data/maps.cpp | 84 +++++++++++++++++++++++++----------- src/game_data/maps.hpp | 2 +- src/game_data/textures.cpp | 12 +++++- src/game_data/textures.hpp | 2 +- 9 files changed, 94 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 45540e3..f029ba4 100644 --- a/Makefile +++ b/Makefile @@ -25,12 +25,12 @@ OUTPUT := 2D_Engine_Casio_Tool # Compiler and flags CXX = ccache g++ -CXXFLAGS = -Wall -Wextra -std=c++17 -O2 -no-pie +CXXFLAGS = -m32 -Wall -Wextra -std=c++17 -g -no-pie INCLUDE_DIRS = 3rd_party -LDFLAGS = -no-pie +LDFLAGS = -m32 -no-pie # Converter flags -FXCONV_FLAGS = --cg --toolchain= --arch=x86-64 --outputtarget=elf64-x86-64 +FXCONV_FLAGS = --cg --toolchain= --arch=i386 --outputtarget=elf32-x86-64 FXCONV_CONVERTERS = assets/maps/map_converter.py # Change output location diff --git a/assets/maps/example.json b/assets/maps/example.json index 106a192..808da26 100644 --- a/assets/maps/example.json +++ b/assets/maps/example.json @@ -1,5 +1,5 @@ { - "MapWidth": 3, + "MapWidth": 2, "MapHeight": 2, "BackgroundLayer1": [ diff --git a/assets/maps/map_converter.py b/assets/maps/map_converter.py index 5919e46..94035a9 100644 --- a/assets/maps/map_converter.py +++ b/assets/maps/map_converter.py @@ -1,5 +1,5 @@ import fxconv -from fxconv import u16, u32, ref, string +from fxconv import u16, u32, ref, chars, string import json def convert(input, output, params, target): @@ -17,6 +17,11 @@ def convert_map(input, output, params, target): SPRITE_COMPONENT = 1 ANIMATION_SYSTEM = 2 + background_layer1 = b''.join(u16(tile) for tile in map["BackgroundLayer1"]) + background_layer2 = b''.join(u16(tile) for tile in map["BackgroundLayer2"]) + background_layer3 = b''.join(u16(tile) for tile in map["BackgroundLayer3"]) + foreground = b''.join(u16(tile) for tile in map["Foreground"]) + entities = fxconv.Structure() for entity in map["Entities"]: @@ -24,6 +29,8 @@ def convert_map(input, output, params, target): e += u16(entity["ID"]) e += u32(len(entity["Components"])) + components = fxconv.Structure() + for component in entity["Components"]: c = fxconv.Structure() c_data = fxconv.Structure() @@ -54,17 +61,18 @@ def convert_map(input, output, params, target): raise fxconv.FxconvError(f"unknown component type {component['Type']}") c += ref(c_data) - e += ref(c) + components += c + e += ref(components) entities += e o = fxconv.ObjectData() o += string(params["name"]) o += u32(map["MapWidth"]) + u32(map["MapHeight"]) - o += bytes(map["BackgroundLayer1"]) - o += bytes(map["BackgroundLayer2"]) - o += bytes(map["BackgroundLayer3"]) - o += bytes(map["Foreground"]) + o += ref(background_layer1) + o += ref(background_layer2) + o += ref(background_layer3) + o += ref(foreground) o += u32(len(map["Entities"])) o += ref(entities) diff --git a/src/game_data/ecs/ecs.hpp b/src/game_data/ecs/ecs.hpp index f765089..d210bc0 100644 --- a/src/game_data/ecs/ecs.hpp +++ b/src/game_data/ecs/ecs.hpp @@ -23,8 +23,7 @@ typedef struct component_t { typedef struct entity_t { uint16_t id; - - unsigned long nb_component; + uint32_t nb_component; component_t *components; } entity_t; diff --git a/src/game_data/game_data.hpp b/src/game_data/game_data.hpp index 6775f2c..9a10ef9 100644 --- a/src/game_data/game_data.hpp +++ b/src/game_data/game_data.hpp @@ -8,10 +8,10 @@ typedef struct game_data_t { const uint32_t nb_textures = NB_TEXTURES; - const texture_t *textures = textures; + const texture_t *textures = TEXTURES; const uint32_t nb_maps = NB_MAPS; - const map_t **maps = maps; + const map_t **maps = MAPS; } game_data_t; void write_game_data_as_bin_into_file(void); diff --git a/src/game_data/maps.cpp b/src/game_data/maps.cpp index 6c736e7..a03ee0f 100644 --- a/src/game_data/maps.cpp +++ b/src/game_data/maps.cpp @@ -2,46 +2,82 @@ #include "maps.hpp" -static inline void verify_layers_integrity(void) -{ - for(uint32_t map_index = 0; map_index < NB_MAPS; map_index++) - { - std::cout << "Map " << map_index + 1 << std::endl; - } -} - -static inline void verify_entities_integrity(void) -{ - -} - void verify_maps_integrity(void) { std::cout << "Nb Maps : " << NB_MAPS << std::endl; for(uint32_t map_index = 0; map_index < NB_MAPS; map_index++) { - const uint32_t NB_ENTITIES = maps[map_index]->nb_entities; - const entity_t *ENTITIES = maps[map_index]->entities; + const uint32_t NB_ENTITIES = MAPS[map_index]->nb_entities; + const entity_t *ENTITIES = MAPS[map_index]->entities; std::cout << "Map " << map_index + 1 << std::endl; - std::cout << " - MapName : " << maps[map_index]->map_name << std::endl; - std::cout << " - MapWidth : " << maps[map_index]->map_width << std::endl; - std::cout << " - MapHeight : " << maps[map_index]->map_width << std::endl; - std::cout << " - Nb Entities : " << NB_ENTITIES << std::endl; + std::cout << " - MapName : " << MAPS[map_index]->map_name << std::endl; + std::cout << " - MapWidth : " << MAPS[map_index]->map_width << std::endl; + std::cout << " - MapHeight : " << MAPS[map_index]->map_height << std::endl; + std::cout << " BackgroundLayer1 :"; + + for(uint32_t tile_index_x = 0; tile_index_x < MAPS[map_index]->map_width; tile_index_x++) + { + std::cout << "\n "; + + for(uint32_t tile_index_y = 0; tile_index_y < MAPS[map_index]->map_height; tile_index_y++) + { + std::cout << MAPS[map_index]->map_background_layer1[tile_index_x * MAPS[map_index]->map_width + tile_index_y] << ","; + } + } + + std::cout << "\n BackgroundLayer2 :"; + + for(uint32_t tile_index_x = 0; tile_index_x < MAPS[map_index]->map_width; tile_index_x++) + { + std::cout << "\n "; + + for(uint32_t tile_index_y = 0; tile_index_y < MAPS[map_index]->map_height; tile_index_y++) + { + std::cout << MAPS[map_index]->map_background_layer2[tile_index_x * MAPS[map_index]->map_width + tile_index_y] << ","; + } + } + + std::cout << "\n BackgroundLayer3 :"; + + for(uint32_t tile_index_x = 0; tile_index_x < MAPS[map_index]->map_width; tile_index_x++) + { + std::cout << "\n "; + + for(uint32_t tile_index_y = 0; tile_index_y < MAPS[map_index]->map_height; tile_index_y++) + { + std::cout << MAPS[map_index]->map_background_layer3[tile_index_x * MAPS[map_index]->map_width + tile_index_y] << ","; + } + } + + std::cout << "\n Foreground :"; + + for(uint32_t tile_index_x = 0; tile_index_x < MAPS[map_index]->map_width; tile_index_x++) + { + std::cout << "\n "; + + for(uint32_t tile_index_y = 0; tile_index_y < MAPS[map_index]->map_height; tile_index_y++) + { + std::cout << MAPS[map_index]->map_foreground[tile_index_x * MAPS[map_index]->map_width + tile_index_y] << ","; + } + } + + std::cout << "\n - Nb Entities : " << NB_ENTITIES << std::endl; for(uint32_t entity_index = 0; entity_index < NB_ENTITIES; entity_index++) { - const uint32_t NB_COMPONENTS = ENTITIES->nb_component; - const component_t *COMPONENTS = ENTITIES->components; - - std::cout << " - Nb Components : " << NB_COMPONENTS << std::endl; + const uint32_t NB_COMPONENTS = ENTITIES[entity_index].nb_component; + const component_t *COMPONENTS = ENTITIES[entity_index].components; + std::cout << " Entity " << entity_index + 1 << std::endl; + std::cout << " - ID : " << ENTITIES[entity_index].id << std::endl; + std::cout << " - Nb Components : " << NB_COMPONENTS << std::endl; for(uint32_t component_index = 0; component_index < NB_COMPONENTS; component_index++) { const component_t *COMPONENT = &COMPONENTS[component_index]; - std::cout << " Component " << component_index << std::endl; + std::cout << " Component " << component_index + 1 << std::endl; switch(COMPONENT->component_type) { diff --git a/src/game_data/maps.hpp b/src/game_data/maps.hpp index cb85fa6..98f0492 100644 --- a/src/game_data/maps.hpp +++ b/src/game_data/maps.hpp @@ -20,7 +20,7 @@ typedef struct map_t { extern map_t map_example; -static map_t *maps[] = { +static const map_t *MAPS[] = { &map_example }; diff --git a/src/game_data/textures.cpp b/src/game_data/textures.cpp index 428866f..95f1694 100644 --- a/src/game_data/textures.cpp +++ b/src/game_data/textures.cpp @@ -1,6 +1,16 @@ +#include + #include "textures.hpp" void verify_textures_integrity(void) { - return; + std::cout << "NbTexture : " << NB_TEXTURES << std::endl; + for(uint32_t texture_index = 0; texture_index < NB_TEXTURES; texture_index++) + { + const texture_t *TEXTURE = &TEXTURES[texture_index]; + + std::cout << "Texture \"" << TEXTURE->name << "\" :" << std::endl; + std::cout << " - Width : " << TEXTURE->image->width << std::endl; + std::cout << " - Height : " << TEXTURE->image->height << std::endl; + } } \ No newline at end of file diff --git a/src/game_data/textures.hpp b/src/game_data/textures.hpp index 195ad06..fb1bfb9 100644 --- a/src/game_data/textures.hpp +++ b/src/game_data/textures.hpp @@ -17,7 +17,7 @@ extern bopti_image_t img_lever_sheet; extern bopti_image_t img_small_chest_sheet; extern bopti_image_t img_big_chest_sheet; -static texture_t textures[] = { +static const texture_t TEXTURES[] = { {"tileset", &img_tileset}, {"player_idle_sheet", &img_player_idle_sheet}, {"player_walk_sheet", &img_player_walk_sheet},