summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-08 13:45:17 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-08 13:45:17 -0600
commit709abbedae2e2fa5f7a68e6e14e254cf64d897ae (patch)
treeb1fbf91c9bc7ed27f3babffda5b1188b2678cfc8 /apps
parent2cf33eff014e7de2dab04d15159c75a976f337f9 (diff)
downloadnuttx-709abbedae2e2fa5f7a68e6e14e254cf64d897ae.tar.gz
nuttx-709abbedae2e2fa5f7a68e6e14e254cf64d897ae.tar.bz2
nuttx-709abbedae2e2fa5f7a68e6e14e254cf64d897ae.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/graphics/traveler/Kconfig21
-rw-r--r--apps/graphics/traveler/src/trv_graphics.c6
-rw-r--r--apps/graphics/traveler/src/trv_main.c60
-rw-r--r--apps/graphics/traveler/src/trv_world.c1
4 files changed, 69 insertions, 19 deletions
diff --git a/apps/graphics/traveler/Kconfig b/apps/graphics/traveler/Kconfig
index 517cd2a0d..69790e8a5 100644
--- a/apps/graphics/traveler/Kconfig
+++ b/apps/graphics/traveler/Kconfig
@@ -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"
diff --git a/apps/graphics/traveler/src/trv_graphics.c b/apps/graphics/traveler/src/trv_graphics.c
index 32e2e199a..f7ff1249e 100644
--- a/apps/graphics/traveler/src/trv_graphics.c
+++ b/apps/graphics/traveler/src/trv_graphics.c
@@ -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 */
diff --git a/apps/graphics/traveler/src/trv_main.c b/apps/graphics/traveler/src/trv_main.c
index 53cc1cca8..1220f05dd 100644
--- a/apps/graphics/traveler/src/trv_main.c
+++ b/apps/graphics/traveler/src/trv_main.c
@@ -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);
diff --git a/apps/graphics/traveler/src/trv_world.c b/apps/graphics/traveler/src/trv_world.c
index 097205b98..f13e797e3 100644
--- a/apps/graphics/traveler/src/trv_world.c
+++ b/apps/graphics/traveler/src/trv_world.c
@@ -54,7 +54,6 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-
/* Everything related to the camera POV is defined in the camera section. */
#define CAMERA_SECTION_NAME "camera"