Map parsing

This commit is contained in:
2026-08-21 19:48:16 +05:00
parent 01abef0b05
commit 8a7ca839fa
9 changed files with 426 additions and 53 deletions
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.11.2" name="Map" tilewidth="16" tileheight="16" tilecount="120" columns="8">
<image source="../assets/3rdparty/tileset/Tiles/Tileset.png" width="128" height="240"/>
</tileset>
+34 -2
View File
@@ -1,12 +1,44 @@
{
"activeFile": "",
"Map/SizeTest": {
"height": 4300,
"width": 2
},
"activeFile": "безымянный.tmx",
"expandedProjectPaths": [
],
"file.lastUsedOpenFilter": "Все файлы (*)",
"fileStates": {
"Map.tsx": {
"scaleInDock": 1,
"scaleInEditor": 1
},
"безымянный.tmx": {
"scale": 1.6605208333333332,
"selectedLayer": 2,
"viewCenter": {
"x": 240.2860548271752,
"y": 159.88959287372188
}
}
},
"last.exportedFilePath": "/Users/aleksejbagno/projects/odin/hello/Tiled",
"last.imagePath": "/Users/aleksejbagno/projects/odin/hello/assets/3rdparty/tileset/Tiles",
"map.lastUsedExportFilter": "JSON map-файлы (*.tmj *.json)",
"map.lastUsedFormat": "tmx",
"map.tileHeight": 16,
"map.tileWidth": 16,
"openFiles": [
"безымянный.tmx",
"Map.tsx"
],
"project": "hello.tiled-project",
"recentFiles": [
]
"Map.tsx",
"безымянный.tmx"
],
"tileset.lastUsedFormat": "tsx",
"tileset.tileSize": {
"height": 16,
"width": 16
}
}
+113
View File
@@ -0,0 +1,113 @@
{ "compressionlevel":-1,
"height":20,
"infinite":false,
"layers":[
{
"data":[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 6, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 22, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 14, 22, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 14, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
"height":20,
"id":1,
"name":"\u0421\u043b\u043e\u0439 \u0442\u0430\u0439\u043b\u043e\u0432 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
},
{
"data":[64, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 63,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 29, 29, 29, 29, 30, 0, 0, 60,
62, 0, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 38, 0, 0, 60,
62, 0, 92, 90, 112, 90, 120, 120, 111, 90, 111, 90, 94, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 38, 0, 0, 60,
62, 0, 92, 90, 90, 87, 101, 101, 101, 101, 101, 101, 102, 0, 0, 0, 0, 0, 0, 0, 0, 44, 45, 45, 39, 0, 38, 0, 0, 60,
62, 0, 92, 119, 90, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 45, 46, 0, 0, 60,
62, 0, 92, 90, 90, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 100, 101, 101, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 26, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 34, 34, 34, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 34, 34, 34, 34, 34, 27, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 34, 34, 34, 34, 34, 34, 34, 27, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 34, 34, 34, 34, 34, 34, 35, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 34, 34, 34, 34, 34, 34, 35, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 34, 34, 34, 34, 34, 34, 34, 43, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 34, 34, 34, 34, 43, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 81, 82, 83, 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 34, 34, 34, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 89, 90, 91, 0, 0, 0, 0, 0, 0, 0, 0, 41, 42, 42, 42, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60,
56, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 55],
"height":20,
"id":2,
"name":"\u0421\u043b\u043e\u0439 \u0442\u0430\u0439\u043b\u043e\u0432 2",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":20,
"id":3,
"name":"\u0421\u043b\u043e\u0439 \u0442\u0430\u0439\u043b\u043e\u0432 3",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
}],
"nextlayerid":4,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.2",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"Map.tsx"
}],
"tilewidth":16,
"type":"map",
"version":"1.10",
"width":30
}
+76
View File
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="1">
<tileset firstgid="1" source="Map.tsx"/>
<layer id="1" name="Слой тайлов 1" width="30" height="20">
<data encoding="csv">
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,6,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,14,10,10,14,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,22,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,14,10,10,10,10,14,22,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
</data>
</layer>
<layer id="2" name="Слой тайлов 2" width="30" height="20">
<data encoding="csv">
64,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,63,
62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,29,29,29,29,30,0,0,60,
62,0,84,85,85,85,85,85,85,85,85,85,86,0,0,0,0,0,0,0,0,36,0,0,0,0,38,0,0,60,
62,0,92,90,112,90,120,120,111,90,111,90,94,0,0,0,0,0,0,0,0,36,0,0,0,0,38,0,0,60,
62,0,92,90,90,87,101,101,101,101,101,101,102,0,0,0,0,0,0,0,0,44,45,45,39,0,38,0,0,60,
62,0,92,119,90,94,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44,45,46,0,0,60,
62,0,92,90,90,94,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,
62,0,100,101,101,102,0,0,0,0,0,0,0,0,0,0,25,26,27,0,0,0,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,34,34,34,27,0,0,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,0,25,34,34,34,34,34,27,0,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,25,34,34,34,34,34,34,34,27,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,33,34,34,34,34,34,34,34,35,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,33,34,34,34,34,34,34,34,35,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,41,34,34,34,34,34,34,34,43,0,0,0,0,0,0,0,60,
62,0,0,0,0,0,0,0,0,0,0,0,0,0,33,34,34,34,34,34,43,0,0,0,0,0,0,0,0,60,
62,0,0,81,82,83,0,0,0,0,0,0,0,0,33,34,34,34,34,43,0,0,0,0,0,0,0,0,0,60,
62,0,0,89,90,91,0,0,0,0,0,0,0,0,41,42,42,42,43,0,0,0,0,0,0,0,0,0,0,60,
62,0,0,97,98,99,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>
+27 -30
View File
@@ -1,5 +1,6 @@
package main
import "base:runtime"
import hm "core:container/handle_map"
import "core:fmt"
import rl "vendor:raylib"
@@ -34,6 +35,8 @@ create_scene :: proc() -> Scene {
offset = rl.Vector2{SCREEN_W / 2, SCREEN_H / 2},
},
}
// _ = hm.add(
// &scene.enemies,
// Enemy {
@@ -72,7 +75,7 @@ draw_scene :: proc(scene: ^Scene) {
0,
0,
cast(f32)scene.map_tex.texture.width,
cast(f32)scene.map_tex.texture.height,
-cast(f32)scene.map_tex.texture.height, // FIX: flip Y axis
},
rl.Rectangle {
0,
@@ -107,33 +110,14 @@ draw_scene :: proc(scene: ^Scene) {
rl.EndMode2D()
}
render_map :: proc(atlas: ^Atlas) -> rl.RenderTexture2D {
map_data := [16][16]i32 {
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
{16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18},
}
width := i32(atlas.tile_size.x) * 16
height := i32(atlas.tile_size.y) * 16
tex := rl.LoadRenderTexture(width, height)
render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D {
tex := rl.LoadRenderTexture(map_data.width * 16, map_data.height * 16)
rl.BeginTextureMode(tex)
for row, i in map_data {
for col, j in row {
offset := get_offset(atlas, col)
fmt.printf("offset: %v, frame: %v\n", offset, col)
for layer in map_data.layers {
for row_data, row in layer.data {
for tile_id, col in row_data {
offset, empty := get_offset(atlas, tile_id)
if empty do continue
rl.DrawTexturePro(
atlas^.tex,
rl.Rectangle {
@@ -143,8 +127,8 @@ render_map :: proc(atlas: ^Atlas) -> rl.RenderTexture2D {
atlas.tile_size.y,
},
rl.Rectangle {
f32(j) * atlas.tile_size.x,
f32(i) * atlas.tile_size.y,
f32(col) * atlas.tile_size.x,
f32(row) * atlas.tile_size.y,
atlas.tile_size.x,
atlas.tile_size.y,
},
@@ -154,6 +138,7 @@ render_map :: proc(atlas: ^Atlas) -> rl.RenderTexture2D {
)
}
}
}
rl.EndTextureMode()
return tex
}
@@ -183,9 +168,21 @@ main :: proc() {
defer rl.CloseWindow()
rl.SetTargetFPS(60)
arena: runtime.Arena
defer runtime.arena_destroy(&arena)
arena_alloc := runtime.arena_allocator(&arena)
map_data, err := load_map(
"./Tiled/безымянный.json",
arena_alloc,
)
if err.type != .None do fmt.println(err.msg)
//WARN: Add a destructor to free (handlemap dangling)
scene := create_scene()
scene.map_tex = render_map(&scene.atlas)
scene.map_tex = render_map(&scene.atlas, map_data)
for !rl.WindowShouldClose() {
dt := rl.GetFrameTime()
+17 -5
View File
@@ -51,7 +51,8 @@ load_atlas :: proc() -> Atlas {
draw_tile :: proc(tile: Tile) {
offset := get_offset(tile.atlas, tile.frame)
offset, empty := get_offset(tile.atlas, tile.frame)
if empty do return
rl.DrawTexturePro(
tile.atlas^.tex,
rl.Rectangle {
@@ -73,13 +74,24 @@ draw_tile :: proc(tile: Tile) {
)
}
get_offset :: proc(atlas: ^Atlas, f: i32) -> rl.Vector2 {
get_offset :: proc(
atlas: ^Atlas,
f: i32,
) -> (
offset: rl.Vector2,
empty: bool,
) {
col := f % atlas.cols
row := f / atlas.cols
if f == 0 do return {}, true
return rl.Vector2 {
col := (f - 1) % atlas.cols
row := (f - 1) / atlas.cols
offset = rl.Vector2 {
f32(col) * atlas.tile_size.x,
f32(row) * atlas.tile_size.y,
}
return
}
View File
View File
+139
View File
@@ -0,0 +1,139 @@
package main
import "base:runtime"
import "core:encoding/json"
import "core:fmt"
import "core:os"
Map_File :: struct {
compression_level: int `json:"compressionlevel"`,
height: int `json:"height"`,
infinite: bool `json:"infinite"`,
layers: []Layer `json:"layers"`,
next_layer_id: int `json:"nextlayerid"`,
next_object_id: int `json:"nextobjectid"`,
orientation: string `json:"orientation"`,
render_order: string `json:"renderorder"`,
tiled_version: string `json:"tiledversion"`,
tile_height: int `json:"tileheight"`,
tile_sets: []Tileset `json:"tilesets"`,
tile_width: int `json:"tilewidth"`,
type: string `json:"type"`,
version: string `json:"version"`,
width: int `json:"width"`,
}
Layer :: struct {
data: []int `json:"data"`,
height: int `json:"height"`,
id: int `json:"id"`,
name: string `json:"name"`,
opacity: f32 `json:"opacity"`,
type: string `json:"type"`,
visible: bool `json:"visible"`,
width: int `json:"width"`,
x: int `json:"x"`,
y: int `json:"y"`,
}
Tileset :: struct {
first_gid: int `json:"firstgid"`,
source: string `json:"source"`,
}
Map_Load_Error_Type :: enum {
None,
Err_Loading_File,
Err_Unmarshal,
}
Map_Load_Error :: struct {
type: Map_Load_Error_Type,
msg: string,
}
Map :: struct {
width: i32,
height: i32,
layers: []Layer_Data,
}
Layer_Data :: struct {
data: [][]i32,
}
load_map :: proc(
path: string,
allocator: runtime.Allocator,
) -> (
map_out: Map,
err: Map_Load_Error,
) {
context.allocator = allocator
cfg_data, os_err := os.read_entire_file(path, context.allocator)
if os_err != os.General_Error.None {
return {}, Map_Load_Error{type = .Err_Loading_File, msg = fmt.aprintf("Error reading file: %v (%v)", path, os_err)}
}
unm_map: Map_File
unm_err := json.unmarshal(cfg_data, &unm_map)
if unm_err != nil {
return {}, Map_Load_Error{type = .Err_Unmarshal, msg = fmt.aprintf("Error unmarshalling file: %v (%v)\nOnly Tiled version 1.11.2 is supported", path, unm_err)}
}
assert(!unm_map.infinite, "Infinite maps are not supported")
assert(
unm_map.orientation == "orthogonal",
"Only orthogonal maps are supported",
)
assert(
unm_map.render_order == "right-down",
"Only right-down maps are supported",
)
assert(
unm_map.tile_height == 16 && unm_map.tile_width == 16,
"Only 16x16 tiles are supported",
)
if len(unm_map.layers) == 0 {
return {}, Map_Load_Error{type = .Err_Unmarshal, msg = fmt.aprintf("No layers found in file: %v", path)}
}
if len(unm_map.tile_sets) == 0 {
return {}, Map_Load_Error{type = .Err_Unmarshal, msg = fmt.aprintf("No tilesets found in file: %v", path)}
}
for layer in unm_map.layers {
assert(
layer.type == "tilelayer",
"Only layers with type 'tilelayer' are supported",
)
}
map_out.width = i32(unm_map.width)
map_out.height = i32(unm_map.height)
map_out.layers = make([]Layer_Data, len(unm_map.layers))
for &out, li in map_out.layers {
src := unm_map.layers[li]
out.data = make([][]i32, src.height)
for row in 0 ..< src.height {
out.data[row] = make([]i32, src.width)
for col in 0 ..< src.width {
out.data[row][col] = i32(src.data[row * src.width + col])
}
}
}
// for layer in unm_map.layers {
// for tile, tile_id in layer.data {
// map_out.data[tile_id / layer.width][tile_id % layer.width] = i32(
// tile,
// )
// }
// }
return
}