From efde68f9c708d9763463e97d25c25625f823a887 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:15:39 +0200 Subject: [PATCH] Got map rendering back working --- CMakeLists.txt | 5 ++++- assets/converters.py | 50 ++++++++++++++++++++++++++++++++++++++++++-- assets/level1.tmx | 2 +- assets/level4.tmx | 2 +- src/config.h | 2 +- src/main.c | 8 +++---- src/map.c | 35 +++++++++++++------------------ src/player.c | 4 +++- 8 files changed, 77 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31954ba..8e33e0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,11 @@ set(SOURCES ) # Shared assets, fx-9860G-only assets and fx-CG-50-only assets set(ASSETS - #assets/WorldRPG.world assets/level0.tmx + assets/level1.tmx + assets/level2.tmx + assets/level3.tmx + assets/level4.tmx # ... ) diff --git a/assets/converters.py b/assets/converters.py index 5373dd4..db9f90a 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -2,6 +2,7 @@ import xml.etree.ElementTree as ET import json import os import sys +import fxconv VERBOSE = 1 SIGN_TYPES = ["INFO", "SGN"] @@ -24,6 +25,9 @@ class Tileset: tilecount_str = self.root.get("tilecount") if tilecount_str == None: raise Exception("tilecount not found!") self.tilecount = int(tilecount_str) + columns_str = self.root.get("columns") + if columns_str == None: raise Exception("columns not found!") + self.columns = int(columns_str) def is_raw_in_tileset(self, raw: int) -> bool: if raw >= self.firstgid and raw < self.firstgid+self.tilecount: @@ -84,7 +88,9 @@ class Object: self.name = element.get("name") if self.name == None: raise Exception("Name attribute missing!") self.type = element.get("type") - if self.type == None: raise Exception("Type attribute missing!") + if self.type == None: + self.type = "" + if VERBOSE: print("WARNING: Type attribute missing!") x_str = element.get("x") if x_str == None: raise Exception("X attribute missing!") self.x = int(float(x_str)) @@ -254,6 +260,8 @@ def convert_map(input, output, params, target): npcs = {} signs = {} + map_struct = fxconv.Structure() + # Get the dialog file try: if VERBOSE: print("INFO: Getting the dialog file") @@ -369,7 +377,45 @@ def convert_map(input, output, params, target): + f" Error message: {e}\n") sys.exit(1) # Generate the structs - # + map_struct += fxconv.u32(width) + map_struct += fxconv.u32(height) + map_struct += fxconv.u32(3) + map_struct += fxconv.u32(outdoor_tileset.columns) + map_struct += fxconv.u32(0) + map_struct += fxconv.u32(0) + map_struct += fxconv.u32(0) + map_struct += fxconv.u32(0) + tileset_name = os.path.splitext(os.path.basename(outdoor_tileset.source))[0] + map_struct += fxconv.ref(f"img_{tileset_name}") + + walkable_data = bytes() + for i in walkable_layer: + if i < 0: i = 0 + walkable_data += fxconv.u8(i) + map_struct += fxconv.ptr(walkable_data) + + map_struct += fxconv.u32(0) # TODO: NPC support in-game + map_struct += fxconv.ptr(bytes()) + map_struct += fxconv.u32(0) # TODO: Sign support in-game + map_struct += fxconv.ptr(bytes()) + map_struct += fxconv.u32(0) # TODO: Portal support in-game + map_struct += fxconv.ptr(bytes()) + map_struct += fxconv.u32(0) # TODO: Dialog support + map_struct += fxconv.ptr(bytes()) + + background_data = bytes() + for i in background_layer: + background_data += fxconv.u16(i) + map_struct += fxconv.ptr(background_data) + + foreground_data = bytes() + for i in foreground_layer: + foreground_data += fxconv.u16(i) + map_struct += fxconv.ptr(foreground_data) + + # Create the fxconv object + name = os.path.splitext(os.path.basename(input))[0] + fxconv.elf(map_struct, output, f"_{name}", **target) def convert_dialog(input, output, params, target): if VERBOSE: print(f"INFO: Converting dialog file {input} -> {output}") diff --git a/assets/level1.tmx b/assets/level1.tmx index b635cb5..689f530 100644 --- a/assets/level1.tmx +++ b/assets/level1.tmx @@ -107,7 +107,7 @@ - + diff --git a/assets/level4.tmx b/assets/level4.tmx index 00a477d..69f15a5 100644 --- a/assets/level4.tmx +++ b/assets/level4.tmx @@ -117,7 +117,7 @@ - + diff --git a/src/config.h b/src/config.h index a83dec9..83dbca1 100644 --- a/src/config.h +++ b/src/config.h @@ -2,7 +2,7 @@ #define CONFIG_H #define USB_FEATURE 0 -#define DEBUGMODE 1 +#define DEBUGMODE 0 #include diff --git a/src/main.c b/src/main.c index b705b5f..76446b4 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,7 @@ #include #include #include +#include #if USB_FEATURE #include @@ -33,15 +34,14 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ Game game = {NULL, {12 * PXSIZE, 36 * PXSIZE, 0, 0, 12 * PXSIZE, 36 * PXSIZE, 100, - SPEED, false, 0, false, false, true, true}, + SPEED, false, 0, false, false, true}, {{}, {}, 0}, false, false, false, - 0 + 0, /* debug variables*/ - , false, false, false, @@ -97,7 +97,7 @@ int main(void) { gdb_start_on_exception(); #endif /*DEBUGMODE*/ - //__printf_enable_fp(); + __printf_enable_fp(); int timer; timer = timer_configure(TIMER_TMU, 1000, GINT_CALL(update_time)); diff --git a/src/map.c b/src/map.c index bfa2a18..fb68978 100644 --- a/src/map.c +++ b/src/map.c @@ -6,7 +6,20 @@ #include #include -extern Map *worldRPG[]; +extern Map level0; +extern Map level1; +extern Map level2; +extern Map level3; +extern Map level4; + +Map *worldRPG[] = { + &level0, + &level1, + &level2, + &level3, + &level4 +}; + // extern ExtraData *extraRPG[]; void map_render(Game *game) { @@ -220,23 +233,5 @@ short int map_get_walkable(Game *game, int x, int y) { /* return the pointer to the map containing the given position */ Map *map_get_for_coordinates(Game *game, int x, int y) { - /* check if the current map contains the point */ - if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax && - y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) { - return game->map_level; - } - - /* else we check in worldRPG if there is a mal containing that point */ - int i = 0; - Map *current = worldRPG[i]; - do { - if(x >= (int)current->xmin && x < (int)current->xmax && - y >= (int)current->ymin && y < (int)current->ymax) - return current; - i++; - current = worldRPG[i]; - } while(current != NULL); - - /* else we return NULL cause the point is a not within a map */ - return NULL; + return game->map_level; } diff --git a/src/player.c b/src/player.c index e6aa200..1666c66 100644 --- a/src/player.c +++ b/src/player.c @@ -171,7 +171,8 @@ bool player_collision(Game *game, Direction direction, /* check where the player is expected to go on the next move */ /* if outside the map, we check if there is a map on the other */ /* side of the current map*/ - if(map_get_walkable(game, player_tile_x, player_tile_y) == MAP_OUTSIDE) { + if(0){ + //if(map_get_walkable(game, player_tile_x, player_tile_y) == MAP_OUTSIDE) { // we compute the expected world coordinates accordingly // while taking care of the scaling between fx and cg models (PXSIZE) int worldX = (player->wx + dx) / PXSIZE; @@ -235,6 +236,7 @@ bool player_collision(Game *game, Direction direction, int speed = (on_walkable >= 0 && on_walkable < WALKABLE_TILE_MAX) ? walkable_speed[on_walkable] : 0; + //speed = SPEED; /* if he's on a hard tile */ if(!speed) {