Traveler: Add logic to limit the frame rate. This is kind of a silly feature -- why would you ever want to limit the frame rate? Well, you need to that on the simulated platform to make bandwidth for other things to run like the simulated timer

This commit is contained in:
Gregory Nutt 2014-12-08 13:45:17 -06:00
parent ccc8557cd9
commit 0643fb90f7
4 changed files with 69 additions and 19 deletions

View File

@ -26,6 +26,27 @@ config GRAPHICS_TRAVELER_DEFPATH
can be found. The default world file name is transfrom.wld (not
configurable).
config GRAPHICS_TRAVELER_LIMITFPS
bool "Limit frame rate"
default y if ARCH_SIM
default n if !ARCH_SIM
---help---
In the UNLIKELY event that the frame rate is too high, this option
may to selected to limit the frame rate to upper limit. This is
most likely not something that you either want or need to do.
However, in the special case of the PC-based simulation environment,
it turns out to be necessary to limit the frame rate in order to
allow other processing to occur. This is a consequence of the low
fidelity timing in the simulation.
config GRAPHICS_TRAVELER_MAXFPS
int "Max frame rate"
default 30
depends on GRAPHICS_TRAVELER_LIMITFPS
---help---
if GRAPHICS_TRAVELER_LIMITFPS is selected, then this is the maximum
frame rate that will be permitted.
config GRAPHICS_TRAVELER_PALRANGES
bool "Use ranged palette"

View File

@ -352,7 +352,7 @@ void trv_row_update(struct trv_graphics_info_s *ginfo,
}
/****************************************************************************
* Name: trv_row_tranfer
* Name: trv_row_transfer
*
* Description:
* Transfer one line from the line buffer to the NX window.
@ -544,7 +544,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
#ifdef CONFIG_NX
/* Transfer the row buffer to the NX window */
trv_row_tranfer(ginfo, dest, destrow);
trv_row_transfer(ginfo, dest, destrow);
destrow++;
#else
first = dest;
@ -558,7 +558,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
#ifdef CONFIG_NX
/* Transfer the row buffer to the NX window */
trv_row_tranfer(ginfo, dest, destrow);
trv_row_transfer(ginfo, dest, destrow);
destrow++;
#else
/* Point to the next row in the frame buffer */

View File

@ -56,7 +56,8 @@
#include "trv_debug.h"
#include "trv_main.h"
#if CONFIG_GRAPHICS_TRAVELER_PERFMON
#if defined(CONFIG_GRAPHICS_TRAVELER_PERFMON) || \
defined(CONFIG_GRAPHICS_TRAVELER_LIMITFPS)
# include <sys/types.h>
# include <sys/time.h>
#endif
@ -70,16 +71,14 @@
# define CONFIG_GRAPHICS_TRAVELER_DEFPATH "/mnt/world"
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Frame rate governer */
static void trv_exit(int exitcode) noreturn_function;
static void trv_usage(char *execname);
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
static double trv_current_time(void);
#ifdef CONFIG_GRAPHICS_TRAVELER_MAXFPS
# define CONFIG_GRAPHICS_TRAVELER_MAXFPS 30
#endif
#define MIN_FRAME_TIME (1.0 / (double)CONFIG_GRAPHICS_TRAVELER_MAXFPS)
/****************************************************************************
* Public Data
*************************************************************************/
@ -104,6 +103,7 @@ static FAR struct trv_graphics_info_s g_trv_ginfo;
* Description:
****************************************************************************/
static void trv_exit(int exitcode) noreturn_function;
static void trv_exit(int exitcode)
{
/* Release memory held by the ray casting engine */
@ -139,7 +139,8 @@ static void trv_usage(char *execname)
* Description:
****************************************************************************/
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
#if defined(CONFIG_GRAPHICS_TRAVELER_PERFMON) || \
defined(CONFIG_GRAPHICS_TRAVELER_LIMITFPS)
static double trv_current_time(void)
{
struct timeval tv;
@ -167,9 +168,17 @@ int traveler_main(int argc, char *argv[])
{
FAR const char *wldpath;
FAR const char *wldfile;
#if defined(CONFIG_GRAPHICS_TRAVELER_PERFMON) || \
defined(CONFIG_GRAPHICS_TRAVELER_LIMITFPS)
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
int32_t frame_count = 0;
double start_time;
double now;
#endif
#ifdef CONFIG_GRAPHICS_TRAVELER_LIMITFPS
double frame_start;
#endif
double elapsed;
#endif
int ret;
int i;
@ -237,12 +246,21 @@ int traveler_main(int argc, char *argv[])
trv_input_initialize();
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
/* Get the start time for performance monitoring */
start_time = trv_current_time();
#endif
g_trv_terminate = false;
while (!g_trv_terminate)
{
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
start_time = trv_current_time();
#ifdef CONFIG_GRAPHICS_TRAVELER_LIMITFPS
/* Get the start time from frame rate limiting */
frame_start = trv_current_time();
#endif
trv_input_read();
/* Select the POV to use on this viewing cycle */
@ -265,14 +283,26 @@ int traveler_main(int argc, char *argv[])
trv_display_update(&g_trv_ginfo);
#ifdef CONFIG_GRAPHICS_TRAVELER_LIMITFPS
/* In the unlikely event that we are running "too" fast, we can delay
* here to enforce a maixmum frame rate.
*/
elapsed = trv_current_time() - frame_start;
if (elapsed < MIN_FRAME_TIME)
{
usleep(1000000 * (elapsed - MIN_FRAME_TIME));
}
#endif
#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON
/* Show the frame rate */
/* Show the realized frame rate */
frame_count++;
if (frame_count == 100)
if (frame_count >= 100)
{
double now = trv_current_time();
double elapsed = now - start_time;
now = trv_current_time();
elapsed = now - start_time;
fprintf(stderr, "fps = %3.2f\n", (double)frame_count / elapsed);

View File

@ -54,7 +54,6 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Everything related to the camera POV is defined in the camera section. */
#define CAMERA_SECTION_NAME "camera"