Add more plan management logic
This commit is contained in:
parent
fa914506ad
commit
969dc2ff41
@ -47,8 +47,8 @@ STACKSIZE = 2048
|
|||||||
|
|
||||||
ASRCS =
|
ASRCS =
|
||||||
CSRCS = trv_bitmaps.c trv_color.c trv_createworld.c trv_doors.c
|
CSRCS = trv_bitmaps.c trv_color.c trv_createworld.c trv_doors.c
|
||||||
CSRCS += trv_graphics.c trv_input.c trv_loadplanes.c trv_mem.c
|
CSRCS += trv_graphics.c trv_input.c trv_mem.c trv_planefiles.c
|
||||||
CSRCS += trv_plane.c trv_pov.c trv_rayavoid.c trv_raycast.c
|
CSRCS += trv_planelists.c trv_pov.c trv_rayavoid.c trv_raycast.c
|
||||||
CSRCS += trv_raycntl.c trv_rayprune.c trv_rayrend.c trv_trigtbl.c
|
CSRCS += trv_raycntl.c trv_rayprune.c trv_rayrend.c trv_trigtbl.c
|
||||||
MAINSRC = trv_main.c
|
MAINSRC = trv_main.c
|
||||||
|
|
||||||
|
@ -139,6 +139,8 @@ extern struct trv_rect_list_s *g_rect_freelist;
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Plane list management */
|
||||||
|
|
||||||
int trv_initialize_planes(void);
|
int trv_initialize_planes(void);
|
||||||
void trv_add_plane(FAR struct trv_rect_list_s *rect,
|
void trv_add_plane(FAR struct trv_rect_list_s *rect,
|
||||||
FAR struct trv_rect_head_s *list);
|
FAR struct trv_rect_head_s *list);
|
||||||
@ -149,9 +151,13 @@ void trv_merge_planelists(FAR struct trv_rect_head_s *outlist,
|
|||||||
FAR struct trv_rect_head_s *inlist);
|
FAR struct trv_rect_head_s *inlist);
|
||||||
void trv_release_planes(void);
|
void trv_release_planes(void);
|
||||||
|
|
||||||
int trv_load_planefile(FAR const char *wldfile);
|
/* Plane memory management */
|
||||||
int trv_load_planes(FAR FILE *fp);
|
|
||||||
int trv_save_planes(const char *wldfile);
|
|
||||||
FAR struct trv_rect_list_s *trv_new_plane(void);
|
FAR struct trv_rect_list_s *trv_new_plane(void);
|
||||||
|
|
||||||
|
/* Plane file management */
|
||||||
|
|
||||||
|
int trv_load_planefile(FAR const char *wldfile);
|
||||||
|
int trv_save_planes(const char *wldfile);
|
||||||
|
|
||||||
#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_PLANE_H */
|
#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_PLANE_H */
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* apps/graphics/traveler/src/trv_loadplanes.c
|
* apps/graphics/traveler/src/trv_planefiles.c
|
||||||
* This file contains the logic to load the world data from the opened file
|
* This file contains the logic to manage the world data files
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -45,7 +45,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -103,17 +103,13 @@ static int trv_load_worldplane(FAR FILE *fp, FAR struct trv_rect_head_s *head,
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: trv_load_planes
|
* Function: trv_load_planes
|
||||||
* Description:
|
* Description:
|
||||||
* This function loads the world data from the opened file
|
* This function loads the world data from the opened file
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
int trv_load_planes(FAR FILE *fp)
|
static int trv_load_planes(FAR FILE *fp)
|
||||||
{
|
{
|
||||||
struct trv_planefile_header_s header;
|
struct trv_planefile_header_s header;
|
||||||
int ret;
|
int ret;
|
||||||
@ -145,3 +141,43 @@ int trv_load_planes(FAR FILE *fp)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: trv_load_planefile
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* This function opens the input file and loads the world plane data from it
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
int trv_load_planefile(FAR const char *wldfile)
|
||||||
|
{
|
||||||
|
FAR FILE *fp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Open the map file which contains the description of the world */
|
||||||
|
|
||||||
|
fp = fopen(wldfile, "rb");
|
||||||
|
if (fp == NULL)
|
||||||
|
{
|
||||||
|
int errcode = errno;
|
||||||
|
fprintf(stderr, "ERROR: Could not open plane file=\"%s\": %d\n",
|
||||||
|
wldfile, errcode);
|
||||||
|
return -errcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load the world data from the file */
|
||||||
|
|
||||||
|
ret = trv_load_planes(fp);
|
||||||
|
|
||||||
|
/* Close the file */
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* apps/graphics/traveler/src/trv_plane.c
|
* apps/graphics/traveler/src/trv_planelist.c
|
||||||
* This file contains the global variable declarations needed by the world
|
* This file contains the logic to manage world plane lists.
|
||||||
* plane management logic.
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -40,6 +39,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "trv_types.h"
|
#include "trv_types.h"
|
||||||
|
#include "trv_mem.h"
|
||||||
#include "trv_plane.h"
|
#include "trv_plane.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -56,7 +56,7 @@ struct trv_rect_head_s g_zplane; /* list of Z=plane rectangles */
|
|||||||
|
|
||||||
/* "Deallocated" planes are retained in a free list */
|
/* "Deallocated" planes are retained in a free list */
|
||||||
|
|
||||||
struct trv_rect_list_s *g_rect_freelist;
|
FAR struct trv_rect_list_s *g_rect_freelist;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@ -298,3 +298,34 @@ void trv_merge_planelists(FAR struct trv_rect_head_s *outlist,
|
|||||||
inlist->head = NULL;
|
inlist->head = NULL;
|
||||||
inlist->tail = NULL;
|
inlist->tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
* Function: trv_new_plane
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function allocates memory for a new plane rectangle.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
FAR struct trv_rect_list_s *trv_new_plane(void)
|
||||||
|
{
|
||||||
|
FAR struct trv_rect_list_s *rect;
|
||||||
|
|
||||||
|
/* Try to get the new structure from the free list */
|
||||||
|
|
||||||
|
rect = g_rect_freelist;
|
||||||
|
if (rect)
|
||||||
|
{
|
||||||
|
/* Got get... remove it from the g_rect_freelist; */
|
||||||
|
|
||||||
|
g_rect_freelist = rect->flink;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Nothing on the free list. Allocate a new one */
|
||||||
|
|
||||||
|
rect = (FAR struct trv_rect_list_s*)trv_malloc(sizeof(struct trv_rect_list_s));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user