fix: Флип тайлов перенесен в рендер

This commit is contained in:
2026-08-28 20:17:36 +05:00
parent 35a64fe432
commit cdadd72635
2 changed files with 27 additions and 18 deletions
+11 -8
View File
@@ -76,7 +76,7 @@ draw_scene :: proc(scene: ^Scene) {
0, 0,
0, 0,
cast(f32)scene.map_tex.texture.width, cast(f32)scene.map_tex.texture.width,
-cast(f32)scene.map_tex.texture.height, // FIX: flip Y axis cast(f32)scene.map_tex.texture.height,
}, },
rl.Rectangle { rl.Rectangle {
0, 0,
@@ -112,10 +112,16 @@ draw_scene :: proc(scene: ^Scene) {
} }
render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D { render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D {
tex := rl.LoadRenderTexture(map_data.width * 16, map_data.height * 16) tex := rl.LoadRenderTexture(
map_data.width * i32(atlas.tile_size.x),
map_data.height * i32(atlas.tile_size.y),
)
// RT хранится в GL-координатах (Y вверх), поэтому ряды тайлов пишем
// снизу вверх — тогда текстуру можно выводить без переворота
rl.BeginTextureMode(tex) rl.BeginTextureMode(tex)
for layer in map_data.layers { for layer in map_data.layers {
for row_data, row in layer.data { for row_data, row in layer.data {
dest_y := f32(i32(map_data.height) - 1 - i32(row)) * atlas.tile_size.y
for tile_id, col in row_data { for tile_id, col in row_data {
offset, empty := get_offset(atlas, tile_id) offset, empty := get_offset(atlas, tile_id)
if empty do continue if empty do continue
@@ -125,11 +131,11 @@ render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D {
offset.x, offset.x,
offset.y, offset.y,
atlas.tile_size.x, atlas.tile_size.x,
atlas.tile_size.y, -atlas.tile_size.y, // флип: RT хранит квадры перевёрнутыми
}, },
rl.Rectangle { rl.Rectangle {
f32(col) * atlas.tile_size.x, f32(col) * atlas.tile_size.x,
f32(row) * atlas.tile_size.y, dest_y,
atlas.tile_size.x, atlas.tile_size.x,
atlas.tile_size.y, atlas.tile_size.y,
}, },
@@ -175,10 +181,7 @@ main :: proc() {
arena_alloc := runtime.arena_allocator(&arena) arena_alloc := runtime.arena_allocator(&arena)
map_data, err := load_map( map_data, err := load_map("./Tiled/map_file.json", arena_alloc)
"./Tiled/map_file.json",
arena_alloc,
)
if err.type != .None { if err.type != .None {
fmt.println(err.msg) fmt.println(err.msg)
+8 -2
View File
@@ -83,8 +83,14 @@ load_tileset :: proc(
return {}, Map_Load_Error{type = .Err_Unmarshal, msg = fmt.aprintf("Error unmarshalling tileset: %v (%v)", path, unm_err)} return {}, Map_Load_Error{type = .Err_Unmarshal, msg = fmt.aprintf("Error unmarshalling tileset: %v (%v)", path, unm_err)}
} }
assert(ts.margin == 0 && ts.spacing == 0, "Tilesets with margin/spacing are not supported") assert(
assert(ts.tile_width == 16 && ts.tile_height == 16, "Only 16x16 tiles are supported") ts.margin == 0 && ts.spacing == 0,
"Tilesets with margin/spacing are not supported",
)
assert(
ts.tile_width == 16 && ts.tile_height == 16,
"Only 16x16 tiles are supported",
)
// image path in tiles.json is relative to the tileset file itself // image path in tiles.json is relative to the tileset file itself
elem := [2]string{filepath.dir(path), ts.image} elem := [2]string{filepath.dir(path), ts.image}