Got map rendering back working

This commit is contained in:
mibi88 2024-07-30 20:15:39 +02:00
parent 537e4d5e96
commit efde68f9c7
8 changed files with 77 additions and 31 deletions

View file

@ -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
# ...
)

View file

@ -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}")

View file

@ -107,7 +107,7 @@
</properties>
<point/>
</object>
<object id="3" name="Chemin Gardien" x="303.818" y="117.455">
<object id="3" name="Chemin Gardien" type="TRJ" x="303.818" y="117.455">
<properties>
<property name="dialogID" type="int" value="0"/>
<property name="needAction" type="int" value="1"/>

View file

@ -117,7 +117,7 @@
</properties>
<point/>
</object>
<object id="8" name="CHEMIN_FERMIER" x="147.952" y="63.0743">
<object id="8" name="CHEMIN_FERMIER" type="TRJ" x="147.952" y="63.0743">
<polyline points="0,0 13.6272,31.1478 50.6152,79.4269 13.6272,74.7547 -7.3976,102.009 -15.5739,71.6399 -17.91,116.804 47.8897,112.132 71.6399,87.2138 131.21,112.132 176.374,91.1073 218.424,89.9393 131.599,59.1808 74.3654,64.2423 50.2258,44.775 29.9798,42.4389 3.50413,3.50413"/>
</object>
</objectgroup>

View file

@ -2,7 +2,7 @@
#define CONFIG_H
#define USB_FEATURE 0
#define DEBUGMODE 1
#define DEBUGMODE 0
#include <gint/display.h>

View file

@ -4,6 +4,7 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <fxlibc/printf.h>
#if USB_FEATURE
#include <gint/usb-ff-bulk.h>
@ -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));

View file

@ -6,7 +6,20 @@
#include <gint/display.h>
#include <gint/keyboard.h>
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;
}

View file

@ -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) {