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); entityInit(ent, ENTITY_TYPE_PLAYER);
ent->id = PLAYER_ENTITY_ID; ent->id = PLAYER_ENTITY_ID;
ent->x = fx248Fromui32(WORLD_PLAYER_SPAWN_X); ent->x = WORLD_PLAYER_SPAWN_X;
ent->y = fx248Fromui32(WORLD_PLAYER_SPAWN_Y); ent->y = WORLD_PLAYER_SPAWN_Y;
} }
void playerNPCInit(entity_t *entity) { void playerNPCInit(entity_t *entity) {

View File

@ -16,6 +16,13 @@ ENTITY_TYPE_MAP = {
"npc": "ENTITY_TYPE_NPC", "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 # Check if the script is run with the correct arguments
parser = argparse.ArgumentParser(description="Generate chunk header files") parser = argparse.ArgumentParser(description="Generate chunk header files")
parser.add_argument('--output', required=True, help='Dir to output headers') 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: if 'x' not in ob or 'y' not in ob:
print(f"Error: Player spawn object does not contain 'x' or 'y' key.") print(f"Error: Player spawn object does not contain 'x' or 'y' key.")
sys.exit(1) sys.exit(1)
playerSpawnX = round(ob['x']) playerSpawnX = ob['x']
playerSpawnY = round(ob['y']) playerSpawnY = ob['y']
break break
# Output header file. # Output header file.
@ -421,7 +428,7 @@ with open(headerPath, 'w') as f:
f.write("NULL, ") f.write("NULL, ")
f.write("\n") f.write("\n")
f.write("};\n\n") f.write("};\n\n")
f.write(f"#define WORLD_PLAYER_SPAWN_X {playerSpawnX}\n") f.write(f"#define WORLD_PLAYER_SPAWN_X (fixed248_t){floatToFixed248(playerSpawnX)}\n")
f.write(f"#define WORLD_PLAYER_SPAWN_Y {playerSpawnY}\n") f.write(f"#define WORLD_PLAYER_SPAWN_Y (fixed248_t){floatToFixed248(playerSpawnY)}\n")
print(f"chunks.h generated at: {headerPath}") print(f"chunks.h generated at: {headerPath}")