summaryrefslogtreecommitdiff
path: root/apps/graphics
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-06 12:00:25 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-06 12:00:25 -0600
commit0aae446c231bb6382ecbac30505a0166a95a098c (patch)
treec6d40e701d8ca608c93827fac9f7ece9eb3ef2d0 /apps/graphics
parentcdb12002bb2b78ef1458509921475448c9ff92a3 (diff)
downloadnuttx-0aae446c231bb6382ecbac30505a0166a95a098c.tar.gz
nuttx-0aae446c231bb6382ecbac30505a0166a95a098c.tar.bz2
nuttx-0aae446c231bb6382ecbac30505a0166a95a098c.zip
Add more plan management logic
Diffstat (limited to 'apps/graphics')
-rw-r--r--apps/graphics/traveler/Makefile4
-rw-r--r--apps/graphics/traveler/include/trv_plane.h10
-rw-r--r--apps/graphics/traveler/src/trv_planefiles.c (renamed from apps/graphics/traveler/src/trv_loadplanes.c)52
-rw-r--r--apps/graphics/traveler/src/trv_planelists.c (renamed from apps/graphics/traveler/src/trv_plane.c)39
4 files changed, 89 insertions, 16 deletions
diff --git a/apps/graphics/traveler/Makefile b/apps/graphics/traveler/Makefile
index 91840fed2..5f66d75f4 100644
--- a/apps/graphics/traveler/Makefile
+++ b/apps/graphics/traveler/Makefile
@@ -47,8 +47,8 @@ STACKSIZE = 2048
ASRCS =
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_plane.c trv_pov.c trv_rayavoid.c trv_raycast.c
+CSRCS += trv_graphics.c trv_input.c trv_mem.c trv_planefiles.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
MAINSRC = trv_main.c
diff --git a/apps/graphics/traveler/include/trv_plane.h b/apps/graphics/traveler/include/trv_plane.h
index 57a1adf1d..936fc4e9e 100644
--- a/apps/graphics/traveler/include/trv_plane.h
+++ b/apps/graphics/traveler/include/trv_plane.h
@@ -139,6 +139,8 @@ extern struct trv_rect_list_s *g_rect_freelist;
* Public Function Prototypes
****************************************************************************/
+/* Plane list management */
+
int trv_initialize_planes(void);
void trv_add_plane(FAR struct trv_rect_list_s *rect,
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);
void trv_release_planes(void);
+/* Plane memory management */
+
+FAR struct trv_rect_list_s *trv_new_plane(void);
+
+/* Plane file management */
+
int trv_load_planefile(FAR const char *wldfile);
-int trv_load_planes(FAR FILE *fp);
int trv_save_planes(const char *wldfile);
-FAR struct trv_rect_list_s *trv_new_plane(void);
#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_PLANE_H */
diff --git a/apps/graphics/traveler/src/trv_loadplanes.c b/apps/graphics/traveler/src/trv_planefiles.c
index a57fb5105..828d6c06d 100644
--- a/apps/graphics/traveler/src/trv_loadplanes.c
+++ b/apps/graphics/traveler/src/trv_planefiles.c
@@ -1,6 +1,6 @@
/*******************************************************************************
- * apps/graphics/traveler/src/trv_loadplanes.c
- * This file contains the logic to load the world data from the opened file
+ * apps/graphics/traveler/src/trv_planefiles.c
+ * This file contains the logic to manage the world data files
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -45,7 +45,7 @@
#include <errno.h>
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************
@@ -104,16 +104,12 @@ static int trv_load_worldplane(FAR FILE *fp, FAR struct trv_rect_head_s *head,
}
/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
* Function: trv_load_planes
* Description:
* 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;
int ret;
@@ -145,3 +141,43 @@ int trv_load_planes(FAR FILE *fp)
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;
+}
+
diff --git a/apps/graphics/traveler/src/trv_plane.c b/apps/graphics/traveler/src/trv_planelists.c
index 7337c482d..bfca88d65 100644
--- a/apps/graphics/traveler/src/trv_plane.c
+++ b/apps/graphics/traveler/src/trv_planelists.c
@@ -1,7 +1,6 @@
/*******************************************************************************
- * apps/graphics/traveler/src/trv_plane.c
- * This file contains the global variable declarations needed by the world
- * plane management logic.
+ * apps/graphics/traveler/src/trv_planelist.c
+ * This file contains the logic to manage world plane lists.
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -40,6 +39,7 @@
****************************************************************************/
#include "trv_types.h"
+#include "trv_mem.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 */
-struct trv_rect_list_s *g_rect_freelist;
+FAR struct trv_rect_list_s *g_rect_freelist;
/****************************************************************************
* Public Functions
@@ -298,3 +298,34 @@ void trv_merge_planelists(FAR struct trv_rect_head_s *outlist,
inlist->head = 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;
+}