Traveler: Change the way that the world path is managed.
This commit is contained in:
parent
ac159589f8
commit
3c55c8c6bf
graphics/traveler
@ -18,6 +18,15 @@ config GRAPHICS_TRAVELER_RGB32_888
|
||||
|
||||
endchoice # Color format
|
||||
|
||||
config GRAPHICS_TRAVELER_DEFPATH
|
||||
string "Default path to world data"
|
||||
default "/mnt/world"
|
||||
---help---
|
||||
This is the default path to the directory where the world file data
|
||||
can be found. The default world file name is transfrom.wld (not
|
||||
configurable).
|
||||
|
||||
|
||||
config GRAPHICS_TRAVELER_PALRANGES
|
||||
bool "Use ranged palette"
|
||||
default y
|
||||
|
@ -49,5 +49,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
int16_t trv_read_decimal(FAR FILE *fp);
|
||||
FAR char *trv_fullpath(FAR const char *path, FAR const char *name);
|
||||
|
||||
#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_FSUTILS_H */
|
||||
|
@ -85,7 +85,7 @@ extern trv_coord_t g_run_stepheight;
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int trv_world_create(FAR const char *mapfile);
|
||||
int trv_world_create(FAR const char *wldpath, FAR const char *wldfile);
|
||||
void trv_world_destroy(void);
|
||||
|
||||
#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H */
|
||||
|
@ -95,3 +95,26 @@ int16_t trv_read_decimal(FAR FILE *fp)
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: trv_fullpath
|
||||
*
|
||||
* Description:
|
||||
* Concatenate a filename and a path to produce the full, absolute path
|
||||
* to the file. The pointer returned by this function is allocated and
|
||||
* must be freed by the caller.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
FAR char *trv_fullpath(FAR const char *path, FAR const char *name)
|
||||
{
|
||||
FAR char *fullpath = NULL;
|
||||
|
||||
(void)asprintf(&fullpath, "%s/%s", path, name);
|
||||
if (!fullpath)
|
||||
{
|
||||
trv_abort("ERROR: Failured to created full path\n");
|
||||
}
|
||||
|
||||
return fullpath;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ static FAR struct fb_vtable_s *trv_get_fbdev(void)
|
||||
ret = up_fbinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("up_fbinitialize failed: %d\n", -ret);
|
||||
trv_abort("ERROR: up_fbinitialize failed: %d\n", -ret);
|
||||
}
|
||||
|
||||
/* Set up to use video plane 0. There is no support for anything but
|
||||
@ -96,7 +96,7 @@ static FAR struct fb_vtable_s *trv_get_fbdev(void)
|
||||
fbdev = up_fbgetvplane(0);
|
||||
if (!fbdev)
|
||||
{
|
||||
trv_abort("up_fbgetvplane(0) failed\n");
|
||||
trv_abort("ERROR: up_fbgetvplane(0) failed\n");
|
||||
}
|
||||
|
||||
return fbdev;
|
||||
@ -128,7 +128,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
ret = fbdev->getvideoinfo(fbdev, &vinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("getvideoinfo() failed\n");
|
||||
trv_abort("ERROR: getvideoinfo() failed\n");
|
||||
}
|
||||
|
||||
ginfo->xres = vinfo.xres;
|
||||
@ -137,7 +137,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
ret = fbdev->getplaneinfo(fbdev, 0, &pinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("getplaneinfo() failed\n");
|
||||
trv_abort("ERROR: getplaneinfo() failed\n");
|
||||
}
|
||||
|
||||
ginfo->stride = pinfo.stride;
|
||||
@ -145,7 +145,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
|
||||
if (vinfo.fmt != TRV_COLOR_FMT || pinfo.bpp != TRV_BPP)
|
||||
{
|
||||
trv_abort("Bad color format(%d)/bpp(%b)\n", vinfo.fmt, pinfo.bpp);
|
||||
trv_abort("ERROR: Bad color format(%d)/bpp(%d)\n", vinfo.fmt, pinfo.bpp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -118,7 +118,7 @@ static struct trv_input_info_s g_trv_input_info;
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK
|
||||
static void trv_joystick_calibrate(void)
|
||||
{
|
||||
#warning Missing logic"
|
||||
#warning Missing logic
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -59,25 +59,17 @@
|
||||
#if CONFIG_GRAPHICS_TRAVELER_PERFMON
|
||||
# include <sys/types.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
static void trv_exit(int exitCode);
|
||||
static void trv_usage(char *execname);
|
||||
#if CONFIG_GRAPHICS_TRAVELER_PERFMON
|
||||
static double trv_current_time(void);
|
||||
#ifndef CONFIG_GRAPHICS_TRAVELER_DEFPATH
|
||||
# define CONFIG_GRAPHICS_TRAVELER_DEFPATH "/mnt/world"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
*************************************************************************/
|
||||
|
||||
bool g_trv_terminate;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
@ -88,11 +80,18 @@ static void trv_usage(char *execname);
|
||||
static double trv_current_time(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
*************************************************************************/
|
||||
|
||||
bool g_trv_terminate;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
*************************************************************************/
|
||||
|
||||
static const char g_default_worldfile[] = "transfrm.wld";
|
||||
static const char g_default_worldpath[] = CONFIG_GRAPHICS_TRAVELER_DEFPATH;
|
||||
static FAR struct trv_graphics_info_s g_trv_ginfo;
|
||||
|
||||
/****************************************************************************
|
||||
@ -166,7 +165,8 @@ int main(int argc, FAR char *argv[])
|
||||
int traveler_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
FAR const char *world_filename;
|
||||
FAR const char *wldpath;
|
||||
FAR const char *wldfile;
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
|
||||
int32_t frame_count = 0;
|
||||
double elapsed_time = 0.0;
|
||||
@ -175,9 +175,13 @@ int traveler_main(int argc, char *argv[])
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Defaults */
|
||||
|
||||
wldpath = g_default_worldpath;
|
||||
wldfile = g_default_worldfile;
|
||||
|
||||
/* Check for command line arguments */
|
||||
|
||||
world_filename = g_default_worldfile;
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
FAR char *ptr = argv[i];
|
||||
@ -187,13 +191,7 @@ int traveler_main(int argc, char *argv[])
|
||||
switch (*ptr)
|
||||
{
|
||||
case 'p' :
|
||||
ptr++;
|
||||
printf("World data path = %s\n", ptr);
|
||||
if (chdir(ptr))
|
||||
{
|
||||
fprintf(stderr, "Bad path name\n");
|
||||
trv_usage(argv[0]);
|
||||
}
|
||||
wldpath = ptr++;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -204,11 +202,12 @@ int traveler_main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
world_filename = ptr;
|
||||
wldfile = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
trv_debug("World data file = %s\n", world_filename);
|
||||
trv_debug("World data file: %s\n", wldfile);
|
||||
trv_debug("World data path: %s\n", wldpath);
|
||||
|
||||
/* Initialize the graphics interface */
|
||||
|
||||
@ -216,11 +215,11 @@ int traveler_main(int argc, char *argv[])
|
||||
|
||||
/* Load the word data structures */
|
||||
|
||||
ret = trv_world_create(world_filename);
|
||||
ret = trv_world_create(wldpath, wldfile);
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("ERROR: Failed to load world file %s: %d\n",
|
||||
world_filename, ret);
|
||||
wldfile, ret);
|
||||
}
|
||||
|
||||
/* Release color mapping tables */
|
||||
|
@ -39,12 +39,15 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "trv_types.h"
|
||||
#include "trv_main.h"
|
||||
#include "trv_fsutils.h"
|
||||
#include "trv_paltable.h"
|
||||
#include "trv_world.h"
|
||||
#include "trv_plane.h"
|
||||
#include "trv_bitmaps.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <apps/inifile.h>
|
||||
|
||||
@ -101,9 +104,10 @@ static int trv_ini_short(INIHANDLE inihandle, FAR int16_t *value,
|
||||
static int trv_ini_long(INIHANDLE inihandle, FAR long *value,
|
||||
FAR const char *section, FAR const char *name);
|
||||
#endif
|
||||
static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename,
|
||||
FAR const char *section, FAR const char *name);
|
||||
static int trv_manage_wldfile(INIHANDLE inihandle);
|
||||
static int trv_ini_filename(INIHANDLE inihandle, FAR const char *wldpath,
|
||||
FAR const char *section, FAR const char *name,
|
||||
FAR char **filename);
|
||||
static int trv_manage_wldfile(INIHANDLE inihandle, FAR const char *wldfile);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
@ -239,8 +243,9 @@ static uint8_t trv_ini_long(INIHANDLE inihandle, FAR long *value,
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename,
|
||||
FAR const char *section, FAR const char *name)
|
||||
static int trv_ini_filename(INIHANDLE inihandle, FAR const char *path,
|
||||
FAR const char *section, FAR const char *name,
|
||||
FAR char **filename)
|
||||
{
|
||||
/* Read the string from the .INI file. We supply the default value of
|
||||
* NULL. If this value is returned, we assume that that is evidence that
|
||||
@ -264,7 +269,8 @@ static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename,
|
||||
}
|
||||
else
|
||||
{
|
||||
*filename = value;
|
||||
*filename = trv_fullpath(path, value);
|
||||
inifile_free_string(value);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
@ -277,7 +283,7 @@ static int trv_ini_filename(INIHANDLE inihandle, FAR char **filename,
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
static int trv_manage_wldfile(INIHANDLE inihandle, FAR const char *wldpath)
|
||||
{
|
||||
FAR char *filename;
|
||||
int ret;
|
||||
@ -348,8 +354,8 @@ static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
|
||||
/* Get the name of the file containing the world map */
|
||||
|
||||
ret = trv_ini_filename(inihandle, &filename,
|
||||
g_world_section_name, g_world_map_name);
|
||||
ret = trv_ini_filename(inihandle, wldpath, g_world_section_name,
|
||||
g_world_map_name, &filename);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@ -369,14 +375,14 @@ static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
inifile_free_string(filename);
|
||||
free(filename);
|
||||
|
||||
/* Get the name of the file containing the palette table which is used
|
||||
* to adjust the lighting with distance.
|
||||
*/
|
||||
|
||||
ret = trv_ini_filename(inihandle, &filename,
|
||||
g_world_section_name, g_world_palette_name);
|
||||
ret = trv_ini_filename(inihandle,wldpath, g_world_section_name,
|
||||
g_world_palette_name, &filename);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@ -390,12 +396,12 @@ static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
return ret;
|
||||
}
|
||||
|
||||
inifile_free_string(filename);
|
||||
free(filename);
|
||||
|
||||
/* Get the name of the file containing the texture data */
|
||||
|
||||
ret = trv_ini_filename(inihandle, &filename,
|
||||
g_world_section_name, g_world_images_name);
|
||||
ret = trv_ini_filename(inihandle, wldpath, g_world_section_name,
|
||||
g_world_images_name, &filename);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@ -410,7 +416,7 @@ static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
}
|
||||
|
||||
ret = trv_load_bitmapfile(filename);
|
||||
inifile_free_string(filename);
|
||||
free(filename);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -427,8 +433,9 @@ static int trv_manage_wldfile(INIHANDLE inihandle)
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
int trv_world_create(FAR const char *wldfile)
|
||||
int trv_world_create(FAR const char *wldpath, FAR const char *wldfile)
|
||||
{
|
||||
FAR char *fullpath;
|
||||
INIHANDLE inihandle;
|
||||
int ret;
|
||||
|
||||
@ -436,16 +443,19 @@ int trv_world_create(FAR const char *wldfile)
|
||||
* need to construct the world
|
||||
*/
|
||||
|
||||
inihandle = inifile_initialize(wldfile);
|
||||
fullpath = trv_fullpath(wldpath, wldfile);
|
||||
inihandle = inifile_initialize(fullpath);
|
||||
free(fullpath);
|
||||
|
||||
if (!inihandle)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Could not open INI file=\"%s\"\n", wldfile);
|
||||
fprintf(stderr, "ERROR: Could not open INI file=\"%s\"\n", fullpath);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Load the world file data */
|
||||
|
||||
ret = trv_manage_wldfile(inihandle);
|
||||
ret = trv_manage_wldfile(inihandle, wldfile);
|
||||
|
||||
/* Close the INI file and return */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user