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
17
namespace
esengine
{
18
namespace
tilemap
{
19
20
struct
TilesetSlot
{
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
39
inline
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
51
inline
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
esengine::tilemap
Definition
TilemapRenderPlugin.hpp:15
esengine::tilemap::atlasCells
uint32_t atlasCells(float size, float margin, float tileSize, float spacing)
Definition
TilesetTable.hpp:39
esengine::tilemap::resolveTilesetSlot
int resolveTilesetSlot(const std::vector< TilesetSlot > &slots, uint16_t id)
Definition
TilesetTable.hpp:51
esengine
Definition
EasingFunctions.hpp:10
esengine::tilemap::TilesetSlot
Definition
TilesetTable.hpp:20
esengine::tilemap::TilesetSlot::spacing
uint32_t spacing
Definition
TilesetTable.hpp:25
esengine::tilemap::TilesetSlot::columns
uint32_t columns
Definition
TilesetTable.hpp:23
esengine::tilemap::TilesetSlot::margin
uint32_t margin
Definition
TilesetTable.hpp:24
esengine::tilemap::TilesetSlot::operator==
bool operator==(const TilesetSlot &) const =default
esengine::tilemap::TilesetSlot::extrude
uint32_t extrude
Definition
TilesetTable.hpp:29
esengine::tilemap::TilesetSlot::first_id
uint16_t first_id
Definition
TilesetTable.hpp:21
esengine::tilemap::TilesetSlot::texture_handle
uint32_t texture_handle
Definition
TilesetTable.hpp:22
src
esengine
tilemap
TilesetTable.hpp
Generated by
1.15.0