From ee22aadcc739897bd4dfe9e9fc0af8382e204f3d Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 18 Jun 2025 15:03:53 -0500 Subject: [PATCH] made player position be fixed248_t --- src/dusk/entity/player.c | 4 ++-- tools/mapcompile/mapcompile.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/dusk/entity/player.c b/src/dusk/entity/player.c index 1086081..569fe61 100644 --- a/src/dusk/entity/player.c +++ b/src/dusk/entity/player.c @@ -17,8 +17,8 @@ void playerInit() { entityInit(ent, ENTITY_TYPE_PLAYER); ent->id = PLAYER_ENTITY_ID; - ent->x = fx248Fromui32(WORLD_PLAYER_SPAWN_X); - ent->y = fx248Fromui32(WORLD_PLAYER_SPAWN_Y); + ent->x = WORLD_PLAYER_SPAWN_X; + ent->y = WORLD_PLAYER_SPAWN_Y; } void playerNPCInit(entity_t *entity) { diff --git a/tools/mapcompile/mapcompile.py b/tools/mapcompile/mapcompile.py index 7b09840..3a16d4c 100644 --- a/tools/mapcompile/mapcompile.py +++ b/tools/mapcompile/mapcompile.py @@ -16,6 +16,13 @@ ENTITY_TYPE_MAP = { "npc": "ENTITY_TYPE_NPC", } +# Helper functions +def floatToFixed248(value): + # Converts a float to the fixed248_t used internally. + high24 = int(value) & 0xFFFFFF + low8 = int((value * 256.0 - high24) * 256.0) & 0xFF + return (high24 << 8) | low8 + # Check if the script is run with the correct arguments parser = argparse.ArgumentParser(description="Generate chunk header files") parser.add_argument('--output', required=True, help='Dir to output headers') @@ -392,8 +399,8 @@ for ob in objectLayer['objects']: if 'x' not in ob or 'y' not in ob: print(f"Error: Player spawn object does not contain 'x' or 'y' key.") sys.exit(1) - playerSpawnX = round(ob['x']) - playerSpawnY = round(ob['y']) + playerSpawnX = ob['x'] + playerSpawnY = ob['y'] break # Output header file. @@ -421,7 +428,7 @@ with open(headerPath, 'w') as f: f.write("NULL, ") f.write("\n") f.write("};\n\n") - f.write(f"#define WORLD_PLAYER_SPAWN_X {playerSpawnX}\n") - f.write(f"#define WORLD_PLAYER_SPAWN_Y {playerSpawnY}\n") + f.write(f"#define WORLD_PLAYER_SPAWN_X (fixed248_t){floatToFixed248(playerSpawnX)}\n") + f.write(f"#define WORLD_PLAYER_SPAWN_Y (fixed248_t){floatToFixed248(playerSpawnY)}\n") print(f"chunks.h generated at: {headerPath}") \ No newline at end of file