From cdadd7263525594dd059363c709fa8df31412550 Mon Sep 17 00:00:00 2001 From: Alexey Bagno Date: Fri, 28 Aug 2026 20:17:36 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=A4=D0=BB=D0=B8=D0=BF=20=D1=82=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=B5=D0=BD=20=D0=B2=20=D1=80=D0=B5=D0=BD=D0=B4=D0=B5?= =?UTF-8?q?=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.odin | 19 +++++++++++-------- tiled_parser.odin | 26 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/main.odin b/main.odin index 80e6881..8481c27 100644 --- a/main.odin +++ b/main.odin @@ -76,7 +76,7 @@ draw_scene :: proc(scene: ^Scene) { 0, 0, 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 { 0, @@ -112,10 +112,16 @@ draw_scene :: proc(scene: ^Scene) { } 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) for layer in map_data.layers { 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 { offset, empty := get_offset(atlas, tile_id) if empty do continue @@ -125,11 +131,11 @@ render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D { offset.x, offset.y, atlas.tile_size.x, - atlas.tile_size.y, + -atlas.tile_size.y, // флип: RT хранит квадры перевёрнутыми }, rl.Rectangle { f32(col) * atlas.tile_size.x, - f32(row) * atlas.tile_size.y, + dest_y, atlas.tile_size.x, atlas.tile_size.y, }, @@ -175,10 +181,7 @@ main :: proc() { arena_alloc := runtime.arena_allocator(&arena) - map_data, err := load_map( - "./Tiled/map_file.json", - arena_alloc, - ) + map_data, err := load_map("./Tiled/map_file.json", arena_alloc) if err.type != .None { fmt.println(err.msg) diff --git a/tiled_parser.odin b/tiled_parser.odin index b0834da..71fc479 100644 --- a/tiled_parser.odin +++ b/tiled_parser.odin @@ -43,16 +43,16 @@ Tileset :: struct { } Tileset_File :: struct { - columns: int `json:"columns"`, + columns: int `json:"columns"`, image: string `json:"image"`, - image_height: int `json:"imageheight"`, - image_width: int `json:"imagewidth"`, - margin: int `json:"margin"`, + image_height: int `json:"imageheight"`, + image_width: int `json:"imagewidth"`, + margin: int `json:"margin"`, name: string `json:"name"`, - spacing: int `json:"spacing"`, - tile_count: int `json:"tilecount"`, - tile_height: int `json:"tileheight"`, - tile_width: int `json:"tilewidth"`, + spacing: int `json:"spacing"`, + tile_count: int `json:"tilecount"`, + tile_height: int `json:"tileheight"`, + tile_width: int `json:"tilewidth"`, } Tileset_Info :: struct { @@ -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)} } - assert(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") + assert( + 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 elem := [2]string{filepath.dir(path), ts.image}