a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 8cef059876ea71395dec1365af7fe4c4c9ddfc31
parent e187e876f473c8d17c3eb3677d3625aa472ba344
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Sat, 11 May 2019 17:09:57 -0700

Only get initialized rooms

Diffstat:
Msrc/game.c | 8++++----
Msrc/world.c | 19+++++++++++++++++--
2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -64,11 +64,11 @@ internal void game_init(struct GameMemory *game_memory, v2u framebuffer) //world_room_set(game_state->world, collision_test_zone, &game_state->world_allocator); //world_room_set(game_state->world, knytt_hanging_fly_village, &game_state->world_allocator); - i32 s = -100; - i32 f = 100; - for (i32 x = s; x < f; x++) + i32 s = -3; + i32 f = 3; + for (i32 x = s; x <= f; x++) { - for (i32 y = s; y < f; y++) + for (i32 y = s; y <= f; y++) { struct Room r = { .index = {x, y}, diff --git a/src/world.c b/src/world.c @@ -141,6 +141,16 @@ internal size_t world_room_get_index_within_chunk(v2i room_i) return room_i_within_chunk; } +internal inline bool world_room_is_initialized(struct Room *room) +{ + bool is_initialized = false; + if (room->index.y != ROOM_UNINITIALIZED_Y_VALUE) + { + is_initialized = true; + } + return is_initialized; +} + internal struct Room* world_room_get(struct World *world, v2i room_i) { struct Room *result = NULL; @@ -150,7 +160,12 @@ internal struct Room* world_room_get(struct World *world, v2i room_i) if (chunk) { size_t room_i_in_chunk = world_room_get_index_within_chunk(room_i); - result = &chunk->rooms[room_i_in_chunk]; + struct Room *room = &chunk->rooms[room_i_in_chunk]; + if (world_room_is_initialized(room)) + { + result = room; + room = NULL; + } } return result; @@ -166,7 +181,7 @@ internal struct Room* world_room_set(struct World *world, struct Room room, stru if (chunk) { size_t room_i_in_chunk = world_room_get_index_within_chunk(room.index); - assert(chunk->rooms[room_i_in_chunk].index.y == ROOM_UNINITIALIZED_Y_VALUE); + assert(!world_room_is_initialized(&chunk->rooms[room_i_in_chunk])); chunk->rooms[room_i_in_chunk] = room; result = &chunk->rooms[room_i_in_chunk]; }