HandmadeHero/project/engine/tile_map.hpp

68 lines
1.1 KiB
C++
Raw Normal View History

2023-10-11 14:52:13 -07:00
/*
*/
#pragma once
#if INTELLISENSE_DIRECTIVES
#include "platform/platform.hpp"
#include "engine_module.hpp"
#endif
NS_ENGINE_BEGIN
2023-10-21 19:21:53 -07:00
// TODO(Ed) : I switch the tile coordinates to signed values, I'm clamping rn to force positive
2023-10-11 14:52:13 -07:00
struct TileChunk
{
2023-10-21 19:21:53 -07:00
s32* tiles;
2023-10-11 14:52:13 -07:00
};
/*
This is a "backend" transient datatype for handling lookup of tile data from "chunks" of tiles.
*/
struct TileChunkPosition
{
2023-10-21 19:21:53 -07:00
s32 tile_chunk_x;
s32 tile_chunk_y;
s32 tile_chunk_z;
2023-10-11 14:52:13 -07:00
// "Chunk-relative (x, y)
2023-10-21 19:21:53 -07:00
s32 tile_x;
s32 tile_y;
2023-10-11 14:52:13 -07:00
};
struct TileMap
{
// TODO(Ed) : Beginner's sparseness
s32 tile_chunks_num_x;
s32 tile_chunks_num_y;
2023-10-17 20:50:28 -07:00
s32 tile_chunks_num_z;
2023-10-11 14:52:13 -07:00
f32 tile_size_in_meters;
2023-10-17 20:50:28 -07:00
// TODO(Ed) : Real sparseness ? (not use the giant pointer array)
2023-10-21 19:21:53 -07:00
s32 chunk_shift;
s32 chunk_mask;
s32 chunk_dimension;
2023-10-11 14:52:13 -07:00
TileChunk* chunks;
};
struct TileMapPos
2023-10-11 14:52:13 -07:00
{
2023-10-19 11:16:50 -07:00
// Note(Ed) : Relative position from tile center.
Vec2 rel_pos;
2023-10-11 14:52:13 -07:00
// "World-relative (x, y), AKA: Absolute Position
// Fixed point tile locations.
// High bits are the tile-chunk index, and the low bits are the tile index in the chunk.
2023-10-21 19:21:53 -07:00
s32 tile_x;
s32 tile_y;
s32 tile_z;
2023-10-11 14:52:13 -07:00
};
NS_ENGINE_END