34 lines
895 B
Plaintext
34 lines
895 B
Plaintext
////////////////////////////////////////////////////////////
|
|
//~ Tile helpers
|
|
|
|
Vec2I32 S_TilePosFromWorldPos(Vec2 p)
|
|
{
|
|
Vec2I32 result;
|
|
result.x = ClampI32((p.x + S_WorldPitch * ((f32)S_WorldPitch / (f32)S_TilesPitch)) * 2, 0, S_TilesPitch - 1);
|
|
result.y = ClampI32((p.y + S_WorldPitch * ((f32)S_WorldPitch / (f32)S_TilesPitch)) * 2, 0, S_TilesPitch - 1);
|
|
return result;
|
|
}
|
|
|
|
i32 S_TileIdxFromTilePos(Vec2I32 p)
|
|
{
|
|
i32 result = ClampI32(p.x + (p.y * S_TilesPitch), 0, S_TilesCount);
|
|
return result;
|
|
}
|
|
|
|
#if IsLanguageC
|
|
String S_TileNameFromKind(S_TileKind kind)
|
|
{
|
|
PERSIST Readonly String tile_names[S_TileKind_COUNT] = {
|
|
#define X(name, ...) [S_TileKind_##name] = CompLit(#name),
|
|
S_TilesXMacro(X)
|
|
#undef X
|
|
};
|
|
String result = Zi;
|
|
if (kind >= 0 && kind < countof(tile_names))
|
|
{
|
|
result = tile_names[kind];
|
|
}
|
|
return result;
|
|
}
|
|
#endif
|