diff --git a/graphics/traveler/Makefile b/graphics/traveler/Makefile index 7f0b731e1..7540876c3 100644 --- a/graphics/traveler/Makefile +++ b/graphics/traveler/Makefile @@ -46,11 +46,12 @@ STACKSIZE = 2048 # Traveler files ASRCS = -CSRCS = trv_bitmapfile.c trv_bitmaps.c trv_color.c trv_createworld.c -CSRCS += trv_doors.c trv_fsutils.c trv_graphicfile.c trv_graphics.c -CSRCS += trv_input.c trv_mem.c trv_pcx.c trv_planefiles.c trv_planelists.c +CSRCS = trv_bitmapfile.c trv_bitmaps.c trv_color.c trv_doors.c +CSRCS += trv_fsutils.c trv_graphicfile.c trv_graphics.c trv_input.c +CSRCS += trv_mem.c trv_pcx.c trv_planefiles.c trv_planelists.c CSRCS += trv_pov.c trv_rayavoid.c trv_raycast.c trv_raycntl.c CSRCS += trv_rayprune.c trv_rayrend.c trv_texturefile.c trv_trigtbl.c +CSRCS += trv_world.c MAINSRC = trv_main.c ifeq ($(CONFIG_NX),y) diff --git a/graphics/traveler/include/trv_bitmaps.h b/graphics/traveler/include/trv_bitmaps.h index 308119501..948f55dce 100644 --- a/graphics/traveler/include/trv_bitmaps.h +++ b/graphics/traveler/include/trv_bitmaps.h @@ -100,7 +100,7 @@ extern trv_pixel_t g_ground_color; ****************************************************************************/ int trv_initialize_bitmaps(void); -void trv_free_bitmaps(void); +void trv_release_bitmaps(void); int trv_load_bitmapfile(FAR const char *bitmapfile); FAR struct trv_bitmap_s *trv_read_texture(FAR char *filename); diff --git a/graphics/traveler/include/trv_paltable.h b/graphics/traveler/include/trv_paltable.h index a307a1244..f7edec11c 100644 --- a/graphics/traveler/include/trv_paltable.h +++ b/graphics/traveler/include/trv_paltable.h @@ -80,5 +80,6 @@ extern trv_pixel_t *g_paltable[NUM_ZONES]; ****************************************************************************/ int trv_load_paltable(FAR const char *file); +void trv_release_paltable(void); #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_PALTABLE_H */ diff --git a/graphics/traveler/src/trv_bitmapfile.c b/graphics/traveler/src/trv_bitmapfile.c index 834c0bd77..ea39eaae9 100644 --- a/graphics/traveler/src/trv_bitmapfile.c +++ b/graphics/traveler/src/trv_bitmapfile.c @@ -135,7 +135,7 @@ static int trv_load_bitmaps(FAR FILE *fp) /* Discard any bitmaps that we may currently have buffered */ - trv_free_bitmaps(); + trv_release_bitmaps(); /* Get the number of bitmaps in the bitmap file */ @@ -221,7 +221,7 @@ int trv_load_bitmapfile(FAR const char *bitmapfile) ret = trv_load_bitmaps(fp); if (ret < 0) { - trv_free_bitmaps(); + trv_release_bitmaps(); } /* We are all done with the file, so close it */ diff --git a/graphics/traveler/src/trv_bitmaps.c b/graphics/traveler/src/trv_bitmaps.c index 0988b3a2d..c9518ab60 100644 --- a/graphics/traveler/src/trv_bitmaps.c +++ b/graphics/traveler/src/trv_bitmaps.c @@ -120,14 +120,14 @@ int trv_initialize_bitmaps(void) } /************************************************************************* - * Name: trv_free_bitmaps + * Name: trv_release_bitmaps * * Description: * This function deallocates all bitmaps. * ************************************************************************/ -void trv_free_bitmaps(void) +void trv_release_bitmaps(void) { int i; diff --git a/graphics/traveler/src/trv_planelists.c b/graphics/traveler/src/trv_planelists.c index bfca88d65..49d5f8e7f 100644 --- a/graphics/traveler/src/trv_planelists.c +++ b/graphics/traveler/src/trv_planelists.c @@ -58,6 +58,30 @@ struct trv_rect_head_s g_zplane; /* list of Z=plane rectangles */ FAR struct trv_rect_list_s *g_rect_freelist; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_release_worldplane + * + * Description: + * This function deallocates one plane of the world + * + ***************************************************************************/ + +static void trv_release_worldplane(FAR struct trv_rect_list_s *rect) +{ + FAR struct trv_rect_list_s *next; + + while (rect) + { + next = rect->flink; + trv_free((void *) rect); + rect = next; + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -329,3 +353,26 @@ FAR struct trv_rect_list_s *trv_new_plane(void) return rect; } + +/************************************************************************* + * Name: trv_release_planes + * + * Description: + * + * This function deallocates the entire world. + * + ************************************************************************/ + +void trv_release_planes(void) +{ + /* Release all world planes */ + + trv_release_worldplane(g_xplane.head); + trv_release_worldplane(g_yplane.head); + trv_release_worldplane(g_zplane.head); + trv_release_worldplane(g_rect_freelist); + + /* Re-initialize the world plane lists */ + + trv_initialize_planes(); +} diff --git a/graphics/traveler/src/trv_createworld.c b/graphics/traveler/src/trv_world.c similarity index 96% rename from graphics/traveler/src/trv_createworld.c rename to graphics/traveler/src/trv_world.c index 5eacf1e67..b21379be3 100644 --- a/graphics/traveler/src/trv_createworld.c +++ b/graphics/traveler/src/trv_world.c @@ -1,6 +1,6 @@ /******************************************************************************* - * apps/graphics/traveler/src/trv_createworld.c - * This file contains the logic that creates the world. + * apps/graphics/traveler/src/trv_world.c + * This file contains the logic that creates and destroys the world. * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -452,3 +452,18 @@ int trv_world_create(FAR const char *wldfile) inifile_uninitialize(inihandle); return ret; } + +/**************************************************************************** + * Name: trv_world_destroy + * + * Description: + * Destroy the world and release all of its resources + * + ***************************************************************************/ + +void trv_world_destroy(void) +{ + trv_release_planes(); + trv_release_bitmaps(); + trv_release_paltable(); +}