Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
TilesetTable.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
12#pragma once
13
14#include <cstdint>
15#include <vector>
16
17namespace esengine {
18namespace tilemap {
19
21 uint16_t first_id = 1; // global tile-id at which this tileset begins (Tiled firstgid)
22 uint32_t texture_handle = 0; // resource::TextureHandle id
23 uint32_t columns = 1; // tiles per row in the tileset texture
24 uint32_t margin = 0; // atlas border in px before the first tile (Tiled margin)
25 uint32_t spacing = 0; // gap in px between adjacent tiles (Tiled spacing)
26 // Duplicated-edge border each cell carries, in px. Non-zero lets the renderer
27 // send the exact cell rect; 0 = a packed atlas, where it must inset half a
28 // texel and stretch the tile instead.
29 uint32_t extrude = 0;
30 bool operator==(const TilesetSlot&) const = default;
31};
32
39inline uint32_t atlasCells(float size, float margin, float tileSize, float spacing) {
40 float step = tileSize + spacing;
41 if (step <= 0.0f) return 0;
42 float n = (size - 2.0f * margin + spacing) / step;
43 return n > 0.0f ? static_cast<uint32_t>(n) : 0;
44}
45
51inline int resolveTilesetSlot(const std::vector<TilesetSlot>& slots, uint16_t id) {
52 int found = -1;
53 for (std::size_t i = 0; i < slots.size(); ++i) {
54 if (id >= slots[i].first_id) {
55 found = static_cast<int>(i);
56 } else {
57 break;
58 }
59 }
60 return found;
61}
62
63} // namespace tilemap
64} // namespace esengine
uint32_t atlasCells(float size, float margin, float tileSize, float spacing)
int resolveTilesetSlot(const std::vector< TilesetSlot > &slots, uint16_t id)
bool operator==(const TilesetSlot &) const =default