aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-23 22:45:55 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-23 22:45:55 +0000
commitbaa565c5bce6629ca1fddd95693c02777f6aa1cb (patch)
tree5862d0b61ec267e97ece126dcc61fa868dcc2351 /src
parentab6eb4442d011d1d2e1f81e9988920262f7fcecb (diff)
Recurse into room connectivity
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@160 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src')
-rw-r--r--src/game.c86
-rw-r--r--src/types.h1
2 files changed, 54 insertions, 33 deletions
diff --git a/src/game.c b/src/game.c
index 8f942a1..7c4880c 100644
--- a/src/game.c
+++ b/src/game.c
@@ -129,7 +129,6 @@ static Room *room_load(int rx, int ry, int rz, ModelContext *models, RenderConte
fclose(fh);
- r->needed_this_time = 1;
return r;
}
@@ -171,17 +170,58 @@ static void game_delete_room(Game *game, int idx) {
}
+static void game_load_all_connected(Room *room, Game *game) {
+
+ int i;
+
+ room->checked_this_time = 1;
+
+ for ( i=0; i<room->num_connected; i++ ) {
+
+ Room *con;
+ int rx, ry, rz;
+
+ rx = room->connected[i].rx;
+ ry = room->connected[i].ry;
+ rz = room->connected[i].rz;
+
+ con = game_find_room(game, rx, ry, rz);
+
+ if ( con == NULL ) {
+
+ if ( game->debug ) printf("GM: Loading %2i %2i %2i\n", rx, ry, rz);
+ con = room_load(rx, ry, rz, game->models, game->render);
+
+ /* Add the new room to the list */
+ con->needed_this_time = 1;
+ con->checked_this_time = 0;
+ game->rooms[game->num_rooms] = con;
+ game->num_rooms++;
+
+ } else {
+
+ con->needed_this_time = 1;
+ if ( game->debug ) printf("GM: %2i %2i %2i is still relevant\n", con->rx, con->ry, con->rz);
+
+ }
+
+ /* Recurse */
+ if ( !con->checked_this_time ) game_load_all_connected(con, game);
+
+ }
+
+}
+
/* Load the current room and all rooms causally connected */
-static void game_load_all_connected(Game *game) {
+static void game_load_all_relevant(Game *game) {
int i;
Room *room;
- if ( game->debug ) printf("GM: Loading all relevant rooms...\n");
-
/* Go down the current list of rooms, setting 'needed_this_time' to 0 */
for ( i=0; i<game->num_rooms; i++ ) {
game->rooms[i]->needed_this_time = 0;
+ game->rooms[i]->checked_this_time = 0;
}
/* Is the current room in the list? Load it if not */
@@ -191,6 +231,7 @@ static void game_load_all_connected(Game *game) {
room = room_load(game->cur_room_x, game->cur_room_y, game->cur_room_z, game->models, game->render);
if ( room == NULL ) {
/* This room couldn't be loaded. */
+ if ( game->debug ) printf("GM: Couldn't load the current room. Giving up.\n");
return;
}
game->rooms[game->num_rooms] = room;
@@ -198,26 +239,7 @@ static void game_load_all_connected(Game *game) {
}
room->needed_this_time = 1;
- /* Check that all connected rooms are loaded as well */
- for ( i=0; i<room->num_connected; i++ ) {
-
- Room *con;
- int rx, ry, rz;
-
- rx = room->connected[i].rx;
- ry = room->connected[i].ry;
- rz = room->connected[i].rz;
- con = game_find_room(game, rx, ry, rz);
- if ( con == NULL ) {
- if ( game->debug ) printf("GM: Loading %2i %2i %2i\n", rx, ry, rz);
- game->rooms[game->num_rooms] = room_load(rx, ry, rz, game->models, game->render);
- game->num_rooms++;
- } else {
- con->needed_this_time = 1;
- if ( game->debug ) printf("GM: %2i %2i %2i is still relevant\n", con->rx, con->ry, con->rz);
- }
-
- }
+ game_load_all_connected(room, game);
/* Remove any rooms left in the list which are no longer needed */
for ( i=0; i<game->num_rooms; i++ ) {
@@ -228,8 +250,6 @@ static void game_load_all_connected(Game *game) {
}
}
- if ( game->debug ) printf("GM: Done.\n");
-
}
/* Create a new "game" structure */
@@ -288,7 +308,7 @@ Game *game_new(int width, int height, GameOptions gameopts) {
return NULL;
}
- game_load_all_connected(g);
+ game_load_all_relevant(g);
/* Initialise the craft */
g->lander = model_instance_new(g->models, "lander", g->render);
@@ -324,7 +344,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->x -= 10.0;
game->cur_room_x += 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
if ( game->lander->x < -5.0 ) {
@@ -334,7 +354,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->x += 10.0;
game->cur_room_x -= 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
@@ -346,7 +366,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->y -= 10.0;
game->cur_room_y += 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
if ( game->lander->y < -5.0 ) {
@@ -356,7 +376,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->y += 10.0;
game->cur_room_y -= 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
@@ -368,7 +388,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->z -= 10.0;
game->cur_room_z += 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
if ( game->lander->z < -5.0 ) {
@@ -378,7 +398,7 @@ void game_check_handoff(Game *game) {
} else {
game->lander->z += 10.0;
game->cur_room_z -= 1;
- game_load_all_connected(game);
+ game_load_all_relevant(game);
}
}
diff --git a/src/types.h b/src/types.h
index 925cdd5..21c5787 100644
--- a/src/types.h
+++ b/src/types.h
@@ -213,6 +213,7 @@ typedef struct {
int rz;
int needed_this_time;
+ int checked_this_time;
Connection connected[MAX_ROOMS];
int num_connected;