made player position be fixed248_t

This commit is contained in:
2025-06-18 15:03:53 -05:00
parent 9a306df7e5
commit ee22aadcc7
2 changed files with 13 additions and 6 deletions

View File

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

View File

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