summaryrefslogtreecommitdiff
path: root/apps/graphics
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-07 10:32:24 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-07 10:32:24 -0600
commit8691d42c60f47e1727a86c5259deee8b891f4d3f (patch)
treec9314ccce98c735250d9b0086ab74e774c3b3b52 /apps/graphics
parente76e0f2b89563a5745ad3302e9ee6a12aec12951 (diff)
downloadnuttx-8691d42c60f47e1727a86c5259deee8b891f4d3f.tar.gz
nuttx-8691d42c60f47e1727a86c5259deee8b891f4d3f.tar.bz2
nuttx-8691d42c60f47e1727a86c5259deee8b891f4d3f.zip
Add world destruction logic
Diffstat (limited to 'apps/graphics')
-rw-r--r--apps/graphics/traveler/Makefile7
-rw-r--r--apps/graphics/traveler/include/trv_bitmaps.h2
-rw-r--r--apps/graphics/traveler/include/trv_paltable.h1
-rw-r--r--apps/graphics/traveler/src/trv_bitmapfile.c4
-rw-r--r--apps/graphics/traveler/src/trv_bitmaps.c4
-rw-r--r--apps/graphics/traveler/src/trv_planelists.c47
-rw-r--r--apps/graphics/traveler/src/trv_world.c (renamed from apps/graphics/traveler/src/trv_createworld.c)19
7 files changed, 74 insertions, 10 deletions
diff --git a/apps/graphics/traveler/Makefile b/apps/graphics/traveler/Makefile
index 7f0b731e1..7540876c3 100644
--- a/apps/graphics/traveler/Makefile
+++ b/apps/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/apps/graphics/traveler/include/trv_bitmaps.h b/apps/graphics/traveler/include/trv_bitmaps.h
index 308119501..948f55dce 100644
--- a/apps/graphics/traveler/include/trv_bitmaps.h
+++ b/apps/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/apps/graphics/traveler/include/trv_paltable.h b/apps/graphics/traveler/include/trv_paltable.h
index a307a1244..f7edec11c 100644
--- a/apps/graphics/traveler/include/trv_paltable.h
+++ b/apps/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/apps/graphics/traveler/src/trv_bitmapfile.c b/apps/graphics/traveler/src/trv_bitmapfile.c
index 834c0bd77..ea39eaae9 100644
--- a/apps/graphics/traveler/src/trv_bitmapfile.c
+++ b/apps/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/apps/graphics/traveler/src/trv_bitmaps.c b/apps/graphics/traveler/src/trv_bitmaps.c
index 0988b3a2d..c9518ab60 100644
--- a/apps/graphics/traveler/src/trv_bitmaps.c
+++ b/apps/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/apps/graphics/traveler/src/trv_planelists.c b/apps/graphics/traveler/src/trv_planelists.c
index bfca88d65..49d5f8e7f 100644
--- a/apps/graphics/traveler/src/trv_planelists.c
+++ b/apps/graphics/traveler/src/trv_planelists.c
@@ -59,6 +59,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/apps/graphics/traveler/src/trv_createworld.c b/apps/graphics/traveler/src/trv_world.c
index 5eacf1e67..b21379be3 100644
--- a/apps/graphics/traveler/src/trv_createworld.c
+++ b/apps/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 <gnutt@nuttx.org>
@@ -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();
+}