You are not logged in.

Read the FAQ and Knowledge Base before posting.
We won't make a 3DS/2DS emulator.

#1 Re: Technical » Patch: Desmume-cli better FPS limiting » 2010-12-01 21:42:07

I couldn't find the download link on the sourceforge tracker for the patch either...

#2 Re: Technical » Desmume and autoconf w/patch » 2010-12-01 21:39:47

Here's the patch since sourceforges patch tracker seems to be confusing...:

From a481bbf847993268e1d4a822594a44e6d4d16452 Mon Sep 17 00:00:00 2001
From: Thomas Jones
Date: Tue, 30 Nov 2010 16:10:09 -0500
Subject: [PATCH] autoconf: use AC_CANONICAL_HOST not AC_CANONICAL_TARGET

AC_CANONICAL_TARGET is for compilers, desmume is not a compiler. It
figures out what platform the compiler should generate binaries for.

AC_CANONICAL_HOST is for figuring out what platform you will run on.
---
 desmume/configure.ac |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/desmume/configure.ac b/desmume/configure.ac
index cd1711f..f344b88 100644
--- a/desmume/configure.ac
+++ b/desmume/configure.ac
@@ -4,8 +4,8 @@ dnl --- Release version is second argument to AC_INIT
 AC_INIT(desmume, [svn])
 
 dnl -- find target architecture for some os specific libraries
-AC_CANONICAL_TARGET
-case $target in
+AC_CANONICAL_HOST
+case $host in
   *linux*) desmume_arch=linux;;
   *mingw*) desmume_arch=windows;;
   *darwin*) desmume_arch=linux;;
@@ -270,7 +270,7 @@ AC_ARG_ENABLE(wifi,
           ])
 
 dnl Set compiler library flags per target.
-case $target in
+case $host in
   *linux* | *bsd*)
     LIBS="$LIBS -lGLU"
     ;;
-- 
1.7.2.2

#3 Re: Technical » Patch: Desmume-cli better FPS limiting » 2010-12-01 21:37:07

I dunno... here's the patch:

From 0ba9592a3593af562756d11079bae408845087c0 Mon Sep 17 00:00:00 2001
From: Thomas Jones
Date: Wed, 1 Dec 2010 09:34:14 -0500
Subject: [PATCH] cli: much better FPS limiting

This patch makes the emulator frame rate more stable, and also makes it
run at full speed more often!

Only done for desmume-cli
---
 desmume/src/cli/main.cpp |   72 +++++++--------------------------------------
 1 files changed, 12 insertions(+), 60 deletions(-)

diff --git a/desmume/src/cli/main.cpp b/desmume/src/cli/main.cpp
index 77ae06f..386860e 100644
--- a/desmume/src/cli/main.cpp
+++ b/desmume/src/cli/main.cpp
@@ -73,6 +73,7 @@ static float nds_screen_size_ratio = 1.0f;
 
 
 #define FPS_LIMITER_FRAME_PERIOD 8
+#define FPS_LIMITER_FPS 60
 
 static SDL_Surface * surface;
 
@@ -275,30 +276,6 @@ joinThread_gdb( void *thread_handle) {
 }
 #endif
 
-
-
-/** 
- * A SDL timer callback function. Signals the supplied SDL semaphore
- * if its value is small.
- * 
- * @param interval The interval since the last call (in ms)
- * @param param The pointer to the semaphore.
- * 
- * @return The interval to the next call (required by SDL)
- */
-static Uint32
-fps_limiter_fn( Uint32 interval, void *param) {
-  SDL_sem *sdl_semaphore = (SDL_sem *)param;
-
-  /* signal the semaphore if it is getting low */
-  if ( SDL_SemValue( sdl_semaphore) < 4) {
-    SDL_SemPost( sdl_semaphore);
-  }
-
-  return interval;
-}
-
-
 #ifdef INCLUDE_OPENGL_2D
 /* initialization openGL function */
 static int
@@ -518,8 +495,7 @@ int main(int argc, char ** argv) {
 #endif
 
   int limiter_frame_counter = 0;
-  SDL_sem *fps_limiter_semaphore = NULL;
-  SDL_TimerID limiter_timer = NULL;
+  int limiter_tick0 = 0;
   int error;
 
   GKeyFile *keyfile;
@@ -726,27 +702,6 @@ int main(int argc, char ** argv) {
   /* Since gtk has a different mapping the keys stop to work with the saved configuration :| */
   load_default_config(cli_kb_cfg);
 
-  if ( !my_config.disable_limiter) {
-    /* create the semaphore used for fps limiting */
-    fps_limiter_semaphore = SDL_CreateSemaphore( 1);
-
-    /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD frames to keep us at 60 fps */
-    if ( fps_limiter_semaphore != NULL) {
-      limiter_timer = SDL_AddTimer( 16 * my_config.fps_limiter_frame_period,
-                                  fps_limiter_fn, fps_limiter_semaphore);
-    }
-
-    if ( limiter_timer == NULL) {
-      fprintf( stderr, "Error trying to start FPS limiter timer: %s\n",
-               SDL_GetError());
-      if ( fps_limiter_semaphore != NULL) {
-        SDL_DestroySemaphore( fps_limiter_semaphore);
-        fps_limiter_semaphore = NULL;
-      }
-      return 1;
-    }
-  }
-
   if(my_config.load_slot != -1){
     loadstate_slot(my_config.load_slot);
   }
@@ -786,14 +741,17 @@ int main(int argc, char ** argv) {
     }
 
     if ( !my_config.disable_limiter && !ctrls_cfg.boost) {
-      limiter_frame_counter += 1 + my_config.frameskip;
-      if ( limiter_frame_counter >= my_config.fps_limiter_frame_period) {
-        limiter_frame_counter = 0;
-
-        /* wait for the timer to expire */
-        SDL_SemWait( fps_limiter_semaphore);
-      }
+        int now = SDL_GetTicks();
+        int delay =  (limiter_tick0 + limiter_frame_counter*1000/FPS_LIMITER_FPS) - now;
+        if (delay > 0) {
+            SDL_Delay(delay);
+        } else if (delay < -500) { // reset if we fall too far behind don't want to run super fast until we catch up
+            limiter_tick0 = now;
+            limiter_frame_counter = 0;
+        }
     }
+    // always count frames, we'll mess up if the limiter gets turned on later otherwise
+    limiter_frame_counter += 1 + my_config.frameskip;
 
 #ifdef DISPLAY_FPS
     fps_frame_counter += 1;
@@ -818,12 +776,6 @@ int main(int argc, char ** argv) {
   /* Unload joystick */
   uninit_joy();
 
-  if ( !my_config.disable_limiter) {
-    /* tidy up the FPS limiter timer and semaphore */
-    SDL_RemoveTimer( limiter_timer);
-    SDL_DestroySemaphore( fps_limiter_semaphore);
-  }
-
   SDL_Quit();
   NDS_DeInit();
 
-- 
1.7.2.2

#4 Technical » Patch: Desmume-cli better FPS limiting » 2010-12-01 15:09:50

Spudd86
Replies: 5

I've got a patch that improves FPS limiting in desmume-cli.

It removes the callback and semaphore, and instead does this:

if ( !my_config.disable_limiter && !ctrls_cfg.boost) {
    int now = SDL_GetTicks();
    int delay =  (limiter_tick0 + limiter_frame_counter*1000/FPS_LIMITER_FPS) - now;
    if (delay > 0) {
        SDL_Delay(delay);
    } else if (delay < -500) { // reset if we fall too far behind don't want to run super fast until we catch up
        limiter_tick0 = now;
        limiter_frame_counter = 0;
    }
}
// always count frames, we'll mess up if the limiter gets turned on later otherwise
limiter_frame_counter += 1 + my_config.frameskip;

I tried it, it took some things that were running at half speed (regardless of what I set frameskip too...) and now runs them at full speed and it gives a MUCH more stable frame rate as long as we're running at full speed. Note that FPS_LIMITER_FPS is 60.

I only did desmume-cli because it didn't look like it would be quite so strait forward for the others, and I wanted to submit this by itself and get some feedback before I did any others, also I don't have a Windows or OSX machine to test...

#5 Technical » Desmume and autoconf w/patch » 2010-12-01 14:57:27

Spudd86
Replies: 1

Desmume's current configure.ac kinda sucks, it's doing some stuff wrong, and some other things that are just not a good thing to do.

First it's using AC_CANONICAL_TARGET, this is wrong, it should use AC_CANONICAL_HOST, I've posted a patch to fix this on the sourceforge tracker.

EDIT: patch

EDIT2: more info on AC_CANONICAL_*

The second thing is more about what it doesn't do, all optional features should have a --disable option source based Linux distro's need this because without it stuff breaks (see here for why it's bad, and here for the right thing to do)

I have some questions about some of the other bits, in particular:

dnl - Check for pkg-config macros
m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG])
dnl - Check for intltool/gettext macros
m4_ifdef([IT_PROG_INTLTOOL],[IT_PROG_INTLTOOL])

Why do this? You only need to have intltool or pkg-config on the system when running autogen.sh/aclocal to get the macros, so it wouldn't affect people building released versions, only subversion builds... and if you have mingw and the GTK development stuff you get pkg-config with that... I don't know about OSX however.

The other minor issue is, I've noticed that the script has a tendency to make new variables when one autoconf provides automatically would due (ie the osmesa one, autoconf already gives enable_osmesa with almost the same values, and to make the script work with that it could just look like:

AC_ARG_ENABLE([osmesa],
               [AC_HELP_STRING([--enable-osmesa], [use off-screen mesa])])

if test "x$enable_osmesa" = "xyes" ; then

and it would get exactly the same results... I could do up some patches if that'd be good.

Board footer

Powered by FluxBB