From 2cf33eff014e7de2dab04d15159c75a976f337f9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 Dec 2014 12:39:02 -0600 Subject: Travel: Fix more initialization errors, mostly related to file path problems --- apps/graphics/traveler/include/trv_bitmaps.h | 4 ++-- apps/graphics/traveler/src/trv_bitmapfile.c | 28 +++++++++++++++++++++++----- apps/graphics/traveler/src/trv_main.c | 13 +++++++++---- apps/graphics/traveler/src/trv_texturefile.c | 4 ++-- apps/graphics/traveler/src/trv_world.c | 2 +- 5 files changed, 37 insertions(+), 14 deletions(-) (limited to 'apps') diff --git a/apps/graphics/traveler/include/trv_bitmaps.h b/apps/graphics/traveler/include/trv_bitmaps.h index 948f55dce..b3a2caabf 100644 --- a/apps/graphics/traveler/include/trv_bitmaps.h +++ b/apps/graphics/traveler/include/trv_bitmaps.h @@ -101,7 +101,7 @@ extern trv_pixel_t g_ground_color; int trv_initialize_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); +int trv_load_bitmapfile(FAR const char *bitmapfile, FAR const char *wldpath); +FAR struct trv_bitmap_s *trv_read_texture(FAR const char *filename); #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H */ diff --git a/apps/graphics/traveler/src/trv_bitmapfile.c b/apps/graphics/traveler/src/trv_bitmapfile.c index ea39eaae9..a17986868 100644 --- a/apps/graphics/traveler/src/trv_bitmapfile.c +++ b/apps/graphics/traveler/src/trv_bitmapfile.c @@ -45,6 +45,7 @@ #include "trv_fsutils.h" #include +#include #include #include @@ -127,8 +128,9 @@ static int trv_read_filename(FAR FILE *fp, FAR char *filename) * ***************************************************************************/ -static int trv_load_bitmaps(FAR FILE *fp) +static int trv_load_bitmaps(FAR FILE *fp, FAR const char *wldpath) { + FAR char *fullpath; char filename[FILENAME_MAX]; int mapndx; int ret = OK; @@ -163,7 +165,15 @@ static int trv_load_bitmaps(FAR FILE *fp) return ret; } - g_even_bitmaps[mapndx] = trv_read_texture(filename); + /* Get the full path to the even bit map file */ + + fullpath = trv_fullpath(wldpath, filename); + + /* Read the bitmap texture file */ + + g_even_bitmaps[mapndx] = trv_read_texture(fullpath); + free(fullpath); + if (!g_even_bitmaps[mapndx]) { return -EIO; @@ -179,7 +189,15 @@ static int trv_load_bitmaps(FAR FILE *fp) } #ifndef WEDIT - g_odd_bitmaps[mapndx] = trv_read_texture(filename); + /* Get the full path to the even bit map file */ + + fullpath = trv_fullpath(wldpath, filename); + + /* Read the bitmap texture file */ + + g_odd_bitmaps[mapndx] = trv_read_texture(fullpath); + free(fullpath); + if (!g_odd_bitmaps[mapndx]) { return -EIO; @@ -202,7 +220,7 @@ static int trv_load_bitmaps(FAR FILE *fp) * ***************************************************************************/ -int trv_load_bitmapfile(FAR const char *bitmapfile) +int trv_load_bitmapfile(FAR const char *bitmapfile, FAR const char *wldpath) { FAR FILE *fp; int ret; @@ -218,7 +236,7 @@ int trv_load_bitmapfile(FAR const char *bitmapfile) /* Load all of the bitmaps */ - ret = trv_load_bitmaps(fp); + ret = trv_load_bitmaps(fp, wldpath); if (ret < 0) { trv_release_bitmaps(); diff --git a/apps/graphics/traveler/src/trv_main.c b/apps/graphics/traveler/src/trv_main.c index 078a5aef9..53cc1cca8 100644 --- a/apps/graphics/traveler/src/trv_main.c +++ b/apps/graphics/traveler/src/trv_main.c @@ -169,7 +169,6 @@ int traveler_main(int argc, char *argv[]) FAR const char *wldfile; #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON int32_t frame_count = 0; - double elapsed_time = 0.0; double start_time; #endif int ret; @@ -265,14 +264,20 @@ int traveler_main(int argc, char *argv[]) /* Display the world. */ trv_display_update(&g_trv_ginfo); + #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON + /* Show the frame rate */ + frame_count++; - elapsed_time += trv_current_time() - start_time; if (frame_count == 100) { - fprintf(stderr, "fps = %3.2f\n", (double) frame_count / elapsed_time); + double now = trv_current_time(); + double elapsed = now - start_time; + + fprintf(stderr, "fps = %3.2f\n", (double)frame_count / elapsed); + frame_count = 0; - elapsed_time = 0.0; + start_time = now; } #endif } diff --git a/apps/graphics/traveler/src/trv_texturefile.c b/apps/graphics/traveler/src/trv_texturefile.c index 8fb5d2404..671e01c83 100644 --- a/apps/graphics/traveler/src/trv_texturefile.c +++ b/apps/graphics/traveler/src/trv_texturefile.c @@ -178,7 +178,7 @@ static void trv_quantize_texture(FAR struct trv_graphicfile_s *gfile, * ***************************************************************************/ -FAR struct trv_bitmap_s *trv_read_texture(char *filename) +FAR struct trv_bitmap_s *trv_read_texture(FAR const char *filename) { FAR struct trv_graphicfile_s *gfile; FAR struct trv_bitmap_s *bitmap; @@ -186,7 +186,7 @@ FAR struct trv_bitmap_s *trv_read_texture(char *filename) gfile = tvr_graphicfile_read(filename); if (gfile == NULL) { - fprintf(stderr, "Error reading texture %s.", filename); + fprintf(stderr, "ERROR: Read failed for texture %s\n", filename); return NULL; } diff --git a/apps/graphics/traveler/src/trv_world.c b/apps/graphics/traveler/src/trv_world.c index 084a1ea74..097205b98 100644 --- a/apps/graphics/traveler/src/trv_world.c +++ b/apps/graphics/traveler/src/trv_world.c @@ -415,7 +415,7 @@ static int trv_manage_wldfile(INIHANDLE inihandle, FAR const char *wldpath) return ret; } - ret = trv_load_bitmapfile(filename); + ret = trv_load_bitmapfile(filename, wldpath); free(filename); return ret; -- cgit v1.2.3