a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

world.h (984B)


      1 // TODO: delete
      2 #define MAX_ROOMS 120
      3 
      4 #define ROOM_DIM_X 25
      5 #define ROOM_DIM_Y 10
      6 #define ROOM_TILE_COUNT ROOM_DIM_X * ROOM_DIM_Y
      7 #define ROOM_ASPECT_RATIO (f32)ROOM_DIM_X / (f32)ROOM_DIM_Y
      8 
      9 #define NUM_CHUNK_BUCKETS 2048
     10 static_assert(
     11     math_is_pow_2(NUM_CHUNK_BUCKETS),
     12     "Must be a power of 2 for the hash table"
     13 );
     14 
     15 // TODO: Tune chunk size
     16 #define CHUNK_ROOMS_PER_SIDE 4
     17 static_assert(
     18     math_is_pow_2(CHUNK_ROOMS_PER_SIDE),
     19     "Must be a power of 2 for the chunk mask to work"
     20 );
     21 #define CHUNK_NUM_ROOMS (CHUNK_ROOMS_PER_SIDE * CHUNK_ROOMS_PER_SIDE)
     22 #define CHUNK_MASK_FOR_INTERNAL_ROOM_INDEX ((1 << math_log2(CHUNK_ROOMS_PER_SIDE)) - 1)
     23 
     24 #define ROOM_UNINITIALIZED_Y_VALUE INT32_MIN
     25 
     26 struct Room
     27 {
     28     v2i index;
     29     u8 tileset_offset;
     30     u8 tiles[ROOM_TILE_COUNT];
     31 };
     32 
     33 struct WorldChunk
     34 {
     35     v2i index;
     36     struct Room rooms[CHUNK_NUM_ROOMS];
     37     struct WorldChunk *next;
     38 };
     39 
     40 struct World
     41 {
     42     struct WorldChunk *chunk_ht[NUM_CHUNK_BUCKETS];
     43     u32 num_rooms;
     44 };