Fixed a lot of bad math causing issues in negative chunks

This commit is contained in:
2025-03-02 13:33:43 -06:00
parent cc339b9389
commit bd2130dfa0
5 changed files with 110 additions and 82 deletions

View File

@@ -25,7 +25,7 @@ main :: proc() {
rl.SetTargetFPS(60)
player = {
position = {CELL_SIZE * 10000, CELL_SIZE * 10000},
position = {CELL_SIZE * 10, CELL_SIZE * 10},
camera = {
zoom = 4,
target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)},
@@ -37,7 +37,7 @@ main :: proc() {
load_tilemap()
defer unload_tilemap()
world = create_world("test_world", 23456725245)
world = create_world("test_world", 10172020)
save_world(&world)
game_loop()
@@ -45,8 +45,6 @@ main :: proc() {
game_loop :: proc() {
pos_string : string
pos_cstring : cstring
for !rl.WindowShouldClose() {
@@ -66,13 +64,21 @@ game_loop :: proc() {
player_grid_pos_tile := get_world_tile(&world, vec2_to_vec2i(player_grid_pos))
current_chunk := get_chunk_from_world_pos(&world, player_grid_pos)
status_string := rl.TextFormat("POS: [%i,%i] : %v | Chunk: [%i,%i] : %v | MODE: %v", int(player_grid_pos.x), int(player_grid_pos.y), player_grid_pos_tile.type, current_chunk.position.x, current_chunk.position.y, get_biome_from_id(current_chunk.biome_id).name, player.mode)
pos_string := rl.TextFormat("Actual pos: %v", player.position)
rl.DrawText(status_string, 5, 25, 20, rl.RED)
// Debug: Draw collision check position
target_pos := player_grid_pos
chunk_pos := world_pos_to_chunk_pos(player_grid_pos)
local_pos := get_local_chunk_pos(vec2_to_vec2i(player_grid_pos))
format_string := rl.TextFormat("Grid: (%.0f,%.0f) Chunk: (%d,%d) Local: (%d,%d)",
player_grid_pos.x, player_grid_pos.y,
chunk_pos.x, chunk_pos.y,
local_pos.x, local_pos.y)
rl.DrawText(format_string, 10, 45, 20, rl.YELLOW)
rl.EndDrawing()
}
delete(pos_string)
delete(pos_cstring)
}
update :: proc() {