Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
authorSam Lantinga <slouken@libsdl.org>
Sat, 13 Jul 2013 03:13:41 -0700
changeset 743258908b180ebd
parent 7431 0fc94f315dac
child 7433 8f118396264b
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Added an API to watch hint changes: SDL_AddHintCallback(), SDL_DelHintCallback()
You can now dynamically set the joystick background event hint.
Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
include/SDL_hints.h
src/SDL_hints.c
src/SDL_hints_c.h
src/joystick/SDL_joystick.c
src/timer/windows/SDL_systimer.c
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Sat Jul 13 11:06:34 2013 +0800
     1.2 +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Sat Jul 13 03:13:41 2013 -0700
     1.3 @@ -67,7 +67,6 @@
     1.4  		04F7808512FB753F00FC43C0 /* SDL_nullframebuffer.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F7808312FB753F00FC43C0 /* SDL_nullframebuffer.c */; };
     1.5  		04FFAB8B12E23B8D00BA343D /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8912E23B8D00BA343D /* SDL_atomic.c */; };
     1.6  		04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; };
     1.7 -		22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 22C905CC13A22646003FE4E4 /* SDL_hints_c.h */; };
     1.8  		56EA86FB13E9EC2B002E47EB /* SDL_coreaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 56EA86F913E9EC2B002E47EB /* SDL_coreaudio.c */; };
     1.9  		56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */; };
    1.10  		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
    1.11 @@ -260,7 +259,6 @@
    1.12  		04F7808312FB753F00FC43C0 /* SDL_nullframebuffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullframebuffer.c; sourceTree = "<group>"; };
    1.13  		04FFAB8912E23B8D00BA343D /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    1.14  		04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
    1.15 -		22C905CC13A22646003FE4E4 /* SDL_hints_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_hints_c.h; path = ../../src/SDL_hints_c.h; sourceTree = "<group>"; };
    1.16  		56EA86F913E9EC2B002E47EB /* SDL_coreaudio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_coreaudio.c; path = coreaudio/SDL_coreaudio.c; sourceTree = "<group>"; };
    1.17  		56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_coreaudio.h; path = coreaudio/SDL_coreaudio.h; sourceTree = "<group>"; };
    1.18  		56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
    1.19 @@ -747,7 +745,6 @@
    1.20  				FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
    1.21  				FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
    1.22  				0442EC5412FE1C3F004C9285 /* SDL_hints.c */,
    1.23 -				22C905CC13A22646003FE4E4 /* SDL_hints_c.h */,
    1.24  				04BAC09B1300C1290055DE28 /* SDL_log.c */,
    1.25  				FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
    1.26  			);
    1.27 @@ -967,7 +964,6 @@
    1.28  				0442EC5012FE1C1E004C9285 /* SDL_render_sw_c.h in Headers */,
    1.29  				0402A85A12FE70C600CECEE3 /* SDL_shaders_gles2.h in Headers */,
    1.30  				04BAC09C1300C1290055DE28 /* SDL_assert_c.h in Headers */,
    1.31 -				22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
    1.32  				56EA86FC13E9EC2B002E47EB /* SDL_coreaudio.h in Headers */,
    1.33  				93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */,
    1.34  				AA628ADC159369E3005138DD /* SDL_rotate.h in Headers */,
     2.1 --- a/include/SDL_hints.h	Sat Jul 13 11:06:34 2013 +0800
     2.2 +++ b/include/SDL_hints.h	Sat Jul 13 03:13:41 2013 -0700
     2.3 @@ -218,13 +218,13 @@
     2.4  /**
     2.5   *  \brief  A variable that lets you enable joystick (and gamecontroller) events even when your app is in the background.
     2.6   *
     2.7 - * The default value is "0".
     2.8 - *
     2.9   *  The variable can be set to the following values:
    2.10   *    "0"       - Disable joystick & gamecontroller input events when the
    2.11   *                application is in the background.
    2.12   *    "1"       - Enable joystick & gamecontroller input events when the
    2.13   *                application is in the backgroumd.
    2.14 + *
    2.15 + *  The default value is "0".  This hint may be set at any time.
    2.16   */
    2.17  #define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
    2.18  
    2.19 @@ -240,6 +240,23 @@
    2.20  #define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST"
    2.21  
    2.22  
    2.23 +/**
    2.24 + *  \brief A variable that controls the timer resolution, in milliseconds.
    2.25 + *
    2.26 + *  The higher resolution the timer, the more frequently the CPU services
    2.27 + *  timer interrupts, and the more precise delays are, but this takes up
    2.28 + *  power and CPU time.  This hint is only used on Windows 7 and earlier.
    2.29 + *
    2.30 + *  See this blog post for more information:
    2.31 + *  http://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/
    2.32 + *
    2.33 + *  If this variable is set to "0", the system timer resolution is not set.
    2.34 + *
    2.35 + *  The default value is "1". This hint may be set at any time.
    2.36 + */
    2.37 +#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
    2.38 +
    2.39 +
    2.40  
    2.41  /**
    2.42   *  \brief  An enumeration of hint priorities
    2.43 @@ -273,7 +290,6 @@
    2.44  extern DECLSPEC SDL_bool SDLCALL SDL_SetHint(const char *name,
    2.45                                               const char *value);
    2.46  
    2.47 -
    2.48  /**
    2.49   *  \brief Get a hint
    2.50   *
    2.51 @@ -282,6 +298,29 @@
    2.52  extern DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
    2.53  
    2.54  /**
    2.55 + *  \brief Add a function to watch a particular hint
    2.56 + *
    2.57 + *  \param name The hint to watch
    2.58 + *  \param callback The function to call when the hint value changes
    2.59 + *  \param userdata A pointer to pass to the callback function
    2.60 + */
    2.61 +typedef void (*SDL_HintCallback)(void *userdata, const char *name, const char *oldValue, const char *newValue);
    2.62 +extern DECLSPEC void SDLCALL SDL_AddHintCallback(const char *name,
    2.63 +                                                 SDL_HintCallback callback,
    2.64 +                                                 void *userdata);
    2.65 +
    2.66 +/**
    2.67 + *  \brief Remove a function watching a particular hint
    2.68 + *
    2.69 + *  \param name The hint being watched
    2.70 + *  \param callback The function being called when the hint value changes
    2.71 + *  \param userdata A pointer being passed to the callback function
    2.72 + */
    2.73 +extern DECLSPEC void SDLCALL SDL_DelHintCallback(const char *name,
    2.74 +                                                 SDL_HintCallback callback,
    2.75 +                                                 void *userdata);
    2.76 +
    2.77 +/**
    2.78   *  \brief  Clear all hints
    2.79   *
    2.80   *  This function is called during SDL_Quit() to free stored hints.
     3.1 --- a/src/SDL_hints.c	Sat Jul 13 11:06:34 2013 +0800
     3.2 +++ b/src/SDL_hints.c	Sat Jul 13 03:13:41 2013 -0700
     3.3 @@ -21,43 +21,35 @@
     3.4  #include "SDL_config.h"
     3.5  
     3.6  #include "SDL_hints.h"
     3.7 -#include "SDL_hints_c.h"
     3.8 +#include "SDL_error.h"
     3.9  
    3.10  
    3.11  /* Assuming there aren't many hints set and they aren't being queried in
    3.12 -   critical performance paths, we'll just use a linked list here.
    3.13 +   critical performance paths, we'll just use linked lists here.
    3.14   */
    3.15 +typedef struct SDL_HintWatch {
    3.16 +    SDL_HintCallback callback;
    3.17 +    void *userdata;
    3.18 +    struct SDL_HintWatch *next;
    3.19 +} SDL_HintWatch;
    3.20 +
    3.21  typedef struct SDL_Hint {
    3.22      char *name;
    3.23      char *value;
    3.24      SDL_HintPriority priority;
    3.25 -    SDL_HintChangedCb callback;
    3.26 +    SDL_HintWatch *callbacks;
    3.27      struct SDL_Hint *next;
    3.28  } SDL_Hint;
    3.29  
    3.30  static SDL_Hint *SDL_hints;
    3.31  
    3.32  SDL_bool
    3.33 -SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb)
    3.34 -{
    3.35 -    SDL_Hint *hint;
    3.36 -
    3.37 -    for (hint = SDL_hints; hint; hint = hint->next) {
    3.38 -        if (SDL_strcmp(name, hint->name) == 0) {
    3.39 -            hint->callback = hintCb;
    3.40 -            return SDL_TRUE;
    3.41 -        }
    3.42 -    }
    3.43 -
    3.44 -    return SDL_FALSE;
    3.45 -}
    3.46 -
    3.47 -SDL_bool
    3.48  SDL_SetHintWithPriority(const char *name, const char *value,
    3.49                          SDL_HintPriority priority)
    3.50  {
    3.51      const char *env;
    3.52      SDL_Hint *hint;
    3.53 +    SDL_HintWatch *entry;
    3.54  
    3.55      if (!name || !value) {
    3.56          return SDL_FALSE;
    3.57 @@ -73,12 +65,21 @@
    3.58              if (priority < hint->priority) {
    3.59                  return SDL_FALSE;
    3.60              }
    3.61 -            if (SDL_strcmp(hint->value, value) != 0) {
    3.62 -                if (hint->callback != NULL) {
    3.63 -                    (*hint->callback)(name, hint->value, value);
    3.64 +            if (!hint->value || !value || SDL_strcmp(hint->value, value) != 0) {
    3.65 +                for (entry = hint->callbacks; entry; ) {
    3.66 +                    /* Save the next entry in case this one is deleted */
    3.67 +                    SDL_HintWatch *next = entry->next;
    3.68 +                    entry->callback(entry->userdata, name, hint->value, value);
    3.69 +                    entry = next;
    3.70                  }
    3.71 -                SDL_free(hint->value);
    3.72 -                hint->value = SDL_strdup(value);
    3.73 +                if (hint->value) {
    3.74 +                    SDL_free(hint->value);
    3.75 +                }
    3.76 +                if (value) {
    3.77 +                    hint->value = SDL_strdup(value);
    3.78 +                } else {
    3.79 +                    hint->value = NULL;
    3.80 +                }
    3.81              }
    3.82              hint->priority = priority;
    3.83              return SDL_TRUE;
    3.84 @@ -91,9 +92,9 @@
    3.85          return SDL_FALSE;
    3.86      }
    3.87      hint->name = SDL_strdup(name);
    3.88 -    hint->value = SDL_strdup(value);
    3.89 +    hint->value = value ? SDL_strdup(value) : NULL;
    3.90      hint->priority = priority;
    3.91 -    hint->callback = NULL;
    3.92 +    hint->callbacks = NULL;
    3.93      hint->next = SDL_hints;
    3.94      SDL_hints = hint;
    3.95      return SDL_TRUE;
    3.96 @@ -123,16 +124,100 @@
    3.97      return env;
    3.98  }
    3.99  
   3.100 +void
   3.101 +SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
   3.102 +{
   3.103 +    SDL_Hint *hint;
   3.104 +    SDL_HintWatch *entry;
   3.105 +    const char *value;
   3.106 +
   3.107 +    if (!name || !*name) {
   3.108 +        SDL_InvalidParamError("name");
   3.109 +        return;
   3.110 +    }
   3.111 +    if (!callback) {
   3.112 +        SDL_InvalidParamError("callback");
   3.113 +        return;
   3.114 +    }
   3.115 +
   3.116 +    SDL_DelHintCallback(name, callback, userdata);
   3.117 +
   3.118 +    entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
   3.119 +    entry->callback = callback;
   3.120 +    entry->userdata = userdata;
   3.121 +
   3.122 +    for (hint = SDL_hints; hint; hint = hint->next) {
   3.123 +        if (SDL_strcmp(name, hint->name) == 0) {
   3.124 +            break;
   3.125 +        }
   3.126 +    }
   3.127 +    if (!hint) {
   3.128 +        /* Need to add a hint entry for this watcher */
   3.129 +        hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
   3.130 +        if (!hint) {
   3.131 +            return;
   3.132 +        }
   3.133 +        hint->name = SDL_strdup(name);
   3.134 +        hint->value = NULL;
   3.135 +        hint->priority = SDL_HINT_DEFAULT;
   3.136 +        hint->callbacks = NULL;
   3.137 +        hint->next = SDL_hints;
   3.138 +        SDL_hints = hint;
   3.139 +    }
   3.140 +
   3.141 +    /* Add it to the callbacks for this hint */
   3.142 +    entry->next = hint->callbacks;
   3.143 +    hint->callbacks = entry;
   3.144 +
   3.145 +    /* Now call it with the current value */
   3.146 +    value = SDL_GetHint(name);
   3.147 +    callback(userdata, name, value, value);
   3.148 +}
   3.149 +
   3.150 +void
   3.151 +SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
   3.152 +{
   3.153 +    SDL_Hint *hint;
   3.154 +    SDL_HintWatch *entry, *prev;
   3.155 +
   3.156 +    for (hint = SDL_hints; hint; hint = hint->next) {
   3.157 +        if (SDL_strcmp(name, hint->name) == 0) {
   3.158 +            prev = NULL;
   3.159 +            for (entry = hint->callbacks; entry; entry = entry->next) {
   3.160 +                if (callback == entry->callback && userdata == entry->userdata) {
   3.161 +                    if (prev) {
   3.162 +                        prev->next = entry->next;
   3.163 +                    } else {
   3.164 +                        hint->callbacks = entry->next;
   3.165 +                    }
   3.166 +                    SDL_free(entry);
   3.167 +                    break;
   3.168 +                }
   3.169 +                prev = entry;
   3.170 +            }
   3.171 +            return;
   3.172 +        }
   3.173 +    }
   3.174 +}
   3.175 +
   3.176  void SDL_ClearHints(void)
   3.177  {
   3.178      SDL_Hint *hint;
   3.179 +    SDL_HintWatch *entry;
   3.180  
   3.181      while (SDL_hints) {
   3.182          hint = SDL_hints;
   3.183          SDL_hints = hint->next;
   3.184  
   3.185          SDL_free(hint->name);
   3.186 -        SDL_free(hint->value);
   3.187 +        if (hint->value) {
   3.188 +            SDL_free(hint->value);
   3.189 +        }
   3.190 +        for (entry = hint->callbacks; entry; ) {
   3.191 +            SDL_HintWatch *freeable = entry;
   3.192 +            entry = entry->next;
   3.193 +            SDL_free(freeable);
   3.194 +        }
   3.195          SDL_free(hint);
   3.196      }
   3.197  }
     4.1 --- a/src/SDL_hints_c.h	Sat Jul 13 11:06:34 2013 +0800
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,34 +0,0 @@
     4.4 -/*
     4.5 - Simple DirectMedia Layer
     4.6 - Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4.7 -
     4.8 - This software is provided 'as-is', without any express or implied
     4.9 - warranty.  In no event will the authors be held liable for any damages
    4.10 - arising from the use of this software.
    4.11 -
    4.12 - Permission is granted to anyone to use this software for any purpose,
    4.13 - including commercial applications, and to alter it and redistribute it
    4.14 - freely, subject to the following restrictions:
    4.15 -
    4.16 - 1. The origin of this software must not be misrepresented; you must not
    4.17 - claim that you wrote the original software. If you use this software
    4.18 - in a product, an acknowledgment in the product documentation would be
    4.19 - appreciated but is not required.
    4.20 - 2. Altered source versions must be plainly marked as such, and must not be
    4.21 - misrepresented as being the original software.
    4.22 - 3. This notice may not be removed or altered from any source distribution.
    4.23 - */
    4.24 -
    4.25 -#ifndef _SDL_hints_c_h
    4.26 -#define _SDL_hints_c_h
    4.27 -
    4.28 -/**
    4.29 - *  \brief  A callback function that is optionally called when a hint changes
    4.30 - */
    4.31 -typedef void (*SDL_HintChangedCb)(const char *name, const char *oldValue, const char *newValue);
    4.32 -
    4.33 -extern SDL_bool SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb);
    4.34 -
    4.35 -#endif /* _SDL_hints_c_h */
    4.36 -
    4.37 -/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/joystick/SDL_joystick.c	Sat Jul 13 11:06:34 2013 +0800
     5.2 +++ b/src/joystick/SDL_joystick.c	Sat Jul 13 03:13:41 2013 -0700
     5.3 @@ -36,17 +36,24 @@
     5.4  static SDL_Joystick *SDL_joysticks = NULL;
     5.5  static SDL_Joystick *SDL_updating_joystick = NULL;
     5.6  
     5.7 +static void
     5.8 +SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
     5.9 +{
    5.10 +    if (hint && *hint == '1') {
    5.11 +        SDL_joystick_allows_background_events = SDL_TRUE;
    5.12 +    } else {
    5.13 +        SDL_joystick_allows_background_events = SDL_FALSE;
    5.14 +    }
    5.15 +}
    5.16 +
    5.17  int
    5.18  SDL_JoystickInit(void)
    5.19  {
    5.20 -    const char *hint;
    5.21      int status;
    5.22  	
    5.23 -    /* Check to see if we should allow joystick events while in the background */
    5.24 -    hint = SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
    5.25 -    if (hint && *hint == '1') {
    5.26 -        SDL_joystick_allows_background_events = SDL_TRUE;
    5.27 -    }
    5.28 +    /* See if we should allow joystick events while in the background */
    5.29 +    SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
    5.30 +                        SDL_JoystickAllowBackgroundEventsChanged, NULL);
    5.31  
    5.32  #if !SDL_EVENTS_DISABLED
    5.33      if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
     6.1 --- a/src/timer/windows/SDL_systimer.c	Sat Jul 13 11:06:34 2013 +0800
     6.2 +++ b/src/timer/windows/SDL_systimer.c	Sat Jul 13 03:13:41 2013 -0700
     6.3 @@ -26,8 +26,8 @@
     6.4  #include <mmsystem.h>
     6.5  
     6.6  #include "SDL_timer.h"
     6.7 +#include "SDL_hints.h"
     6.8  
     6.9 -#define TIME_WRAP_VALUE (~(DWORD)0)
    6.10  
    6.11  /* The first (low-resolution) ticks value of the application */
    6.12  static DWORD start;
    6.13 @@ -41,6 +41,40 @@
    6.14  static LARGE_INTEGER hires_ticks_per_second;
    6.15  #endif
    6.16  
    6.17 +static void
    6.18 +timeSetPeriod(UINT uPeriod)
    6.19 +{
    6.20 +    static UINT timer_period = 0;
    6.21 +
    6.22 +    if (uPeriod != timer_period) {
    6.23 +        if (timer_period) {
    6.24 +            timeEndPeriod(timer_period);
    6.25 +        }
    6.26 +
    6.27 +        timer_period = uPeriod;
    6.28 +
    6.29 +        if (timer_period) {
    6.30 +            timeBeginPeriod(timer_period);
    6.31 +        }
    6.32 +    }
    6.33 +}
    6.34 +
    6.35 +static void
    6.36 +SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    6.37 +{
    6.38 +    UINT uPeriod;
    6.39 +
    6.40 +    /* Unless the hint says otherwise, let's have good sleep precision */
    6.41 +    if (hint && *hint) {
    6.42 +        uPeriod = SDL_atoi(hint);
    6.43 +    } else {
    6.44 +        uPeriod = 1;
    6.45 +    }
    6.46 +    if (uPeriod || oldValue != hint) {
    6.47 +        timeSetPeriod(uPeriod);
    6.48 +    }
    6.49 +}
    6.50 +
    6.51  void
    6.52  SDL_StartTicks(void)
    6.53  {
    6.54 @@ -56,16 +90,19 @@
    6.55          QueryPerformanceCounter(&hires_start_ticks);
    6.56      } else {
    6.57          hires_timer_available = FALSE;
    6.58 -        timeBeginPeriod(1);     /* use 1 ms timer precision */
    6.59 +        timeSetPeriod(1);     /* use 1 ms timer precision */
    6.60          start = timeGetTime();
    6.61      }
    6.62  #endif
    6.63 +
    6.64 +    SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
    6.65 +                        SDL_TimerResolutionChanged, NULL);
    6.66  }
    6.67  
    6.68  Uint32
    6.69  SDL_GetTicks(void)
    6.70  {
    6.71 -    DWORD now, ticks;
    6.72 +    DWORD now;
    6.73  #ifndef USE_GETTICKCOUNT
    6.74      LARGE_INTEGER hires_now;
    6.75  #endif
    6.76 @@ -86,12 +123,7 @@
    6.77      }
    6.78  #endif
    6.79  
    6.80 -    if (now < start) {
    6.81 -        ticks = (TIME_WRAP_VALUE - start) + now;
    6.82 -    } else {
    6.83 -        ticks = (now - start);
    6.84 -    }
    6.85 -    return (ticks);
    6.86 +    return (now - start);
    6.87  }
    6.88  
    6.89  Uint64
     7.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Sat Jul 13 11:06:34 2013 +0800
     7.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sat Jul 13 03:13:41 2013 -0700
     7.3 @@ -25,7 +25,6 @@
     7.4  #include "../SDL_sysvideo.h"
     7.5  #include "SDL_assert.h"
     7.6  #include "SDL_hints.h"
     7.7 -#include "../../SDL_hints_c.h"
     7.8  #include "SDL_system.h"
     7.9  #include "SDL_main.h"
    7.10  
    7.11 @@ -69,11 +68,10 @@
    7.12      return exit_status;
    7.13  }
    7.14  
    7.15 -static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, const char *newValue)
    7.16 +static void
    7.17 +SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    7.18  {
    7.19 -    SDL_assert(SDL_strcmp(name, SDL_HINT_IDLE_TIMER_DISABLED) == 0);
    7.20 -
    7.21 -    BOOL disable = (*newValue != '0');
    7.22 +    BOOL disable = (hint && *hint != '0');
    7.23      [UIApplication sharedApplication].idleTimerDisabled = disable;
    7.24  }
    7.25  
    7.26 @@ -218,8 +216,8 @@
    7.27      [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
    7.28  
    7.29      /* register a callback for the idletimer hint */
    7.30 -    SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "0");
    7.31 -    SDL_RegisterHintChangedCb(SDL_HINT_IDLE_TIMER_DISABLED, &SDL_IdleTimerDisabledChanged);
    7.32 +    SDL_AddHintCallback(SDL_HINT_IDLE_TIMER_DISABLED,
    7.33 +                        SDL_IdleTimerDisabledChanged, NULL);
    7.34  
    7.35      SDL_SetMainReady();
    7.36      [self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];