commit 40060121e2870bb6ae588c4c69dca69cc2621021
parent 95ca73881d3574d11836b15c9f57c5612e2be527
Author: amin <dev@aminmesbah.com>
Date: Sun, 12 May 2019 00:09:56 +0000
Only get initialized rooms
FossilOrigin-Name: f50c5128e4050cdcc56dee9bdae331c1367976ba0a2fd0b6471176a8c323306c
Diffstat:
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];
}