Travel: Fix more initialization errors, mostly related to file path problems

This commit is contained in:
Gregory Nutt 2014-12-08 12:39:02 -06:00
parent 0f6c4e0814
commit ccc8557cd9
5 changed files with 37 additions and 14 deletions

View File

@ -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 */

View File

@ -45,6 +45,7 @@
#include "trv_fsutils.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
@ -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();

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;