Add world destruction logic
This commit is contained in:
parent
76e03225e0
commit
459fb9308e
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user