Changed directory structure to contain less symlinks so dependencies will get recalculated correctly by make
This commit is contained in:
42
project/jni/sdl-1.3/src/timer/SDL_systimer.h
Normal file
42
project/jni/sdl-1.3/src/timer/SDL_systimer.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* The system dependent timer handling functions */
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_timer_c.h"
|
||||
|
||||
|
||||
/* Initialize the system dependent timer subsystem */
|
||||
extern int SDL_SYS_TimerInit(void);
|
||||
|
||||
/* Quit the system dependent timer subsystem */
|
||||
extern void SDL_SYS_TimerQuit(void);
|
||||
|
||||
/* Start a timer set up by SDL_SetTimer() */
|
||||
extern int SDL_SYS_StartTimer(void);
|
||||
|
||||
/* Stop a previously started timer */
|
||||
extern void SDL_SYS_StopTimer(void);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
300
project/jni/sdl-1.3/src/timer/SDL_timer.c
Normal file
300
project/jni/sdl-1.3/src/timer/SDL_timer.c
Normal file
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_timer_c.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_systimer.h"
|
||||
|
||||
/* #define DEBUG_TIMERS */
|
||||
|
||||
int SDL_timer_started = 0;
|
||||
int SDL_timer_running = 0;
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
Uint32 SDL_alarm_interval = 0;
|
||||
SDL_TimerCallback SDL_alarm_callback;
|
||||
|
||||
/* Data used for a thread-based timer */
|
||||
static int SDL_timer_threaded = 0;
|
||||
|
||||
struct _SDL_TimerID
|
||||
{
|
||||
Uint32 interval;
|
||||
SDL_NewTimerCallback cb;
|
||||
void *param;
|
||||
Uint32 last_alarm;
|
||||
struct _SDL_TimerID *next;
|
||||
};
|
||||
|
||||
static SDL_TimerID SDL_timers = NULL;
|
||||
static SDL_mutex *SDL_timer_mutex;
|
||||
static volatile SDL_bool list_changed = SDL_FALSE;
|
||||
|
||||
/* Set whether or not the timer should use a thread.
|
||||
This should not be called while the timer subsystem is running.
|
||||
*/
|
||||
int
|
||||
SDL_SetTimerThreaded(int value)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (SDL_timer_started) {
|
||||
SDL_SetError("Timer already initialized");
|
||||
retval = -1;
|
||||
} else {
|
||||
retval = 0;
|
||||
SDL_timer_threaded = value;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_TimerInit(void)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = 0;
|
||||
if (SDL_timer_started) {
|
||||
SDL_TimerQuit();
|
||||
}
|
||||
if (!SDL_timer_threaded) {
|
||||
retval = SDL_SYS_TimerInit();
|
||||
}
|
||||
if (SDL_timer_threaded) {
|
||||
SDL_timer_mutex = SDL_CreateMutex();
|
||||
}
|
||||
if (retval == 0) {
|
||||
SDL_timer_started = 1;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TimerQuit(void)
|
||||
{
|
||||
SDL_SetTimer(0, NULL);
|
||||
if (SDL_timer_threaded < 2) {
|
||||
SDL_SYS_TimerQuit();
|
||||
}
|
||||
if (SDL_timer_threaded) {
|
||||
SDL_DestroyMutex(SDL_timer_mutex);
|
||||
SDL_timer_mutex = NULL;
|
||||
}
|
||||
SDL_timer_started = 0;
|
||||
SDL_timer_threaded = 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_ThreadedTimerCheck(void)
|
||||
{
|
||||
Uint32 now, ms;
|
||||
SDL_TimerID t, prev, next;
|
||||
SDL_bool removed;
|
||||
|
||||
SDL_mutexP(SDL_timer_mutex);
|
||||
list_changed = SDL_FALSE;
|
||||
now = SDL_GetTicks();
|
||||
for (prev = NULL, t = SDL_timers; t; t = next) {
|
||||
removed = SDL_FALSE;
|
||||
ms = t->interval - SDL_TIMESLICE;
|
||||
next = t->next;
|
||||
if ((int) (now - t->last_alarm) > (int) ms) {
|
||||
struct _SDL_TimerID timer;
|
||||
|
||||
if ((now - t->last_alarm) < t->interval) {
|
||||
t->last_alarm += t->interval;
|
||||
} else {
|
||||
t->last_alarm = now;
|
||||
}
|
||||
#ifdef DEBUG_TIMERS
|
||||
printf("Executing timer %p (thread = %lu)\n", t, SDL_ThreadID());
|
||||
#endif
|
||||
timer = *t;
|
||||
SDL_mutexV(SDL_timer_mutex);
|
||||
ms = timer.cb(timer.interval, timer.param);
|
||||
SDL_mutexP(SDL_timer_mutex);
|
||||
if (list_changed) {
|
||||
/* Abort, list of timers modified */
|
||||
/* FIXME: what if ms was changed? */
|
||||
break;
|
||||
}
|
||||
if (ms != t->interval) {
|
||||
if (ms) {
|
||||
t->interval = ROUND_RESOLUTION(ms);
|
||||
} else {
|
||||
/* Remove timer from the list */
|
||||
#ifdef DEBUG_TIMERS
|
||||
printf("SDL: Removing timer %p\n", t);
|
||||
#endif
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
} else {
|
||||
SDL_timers = next;
|
||||
}
|
||||
SDL_free(t);
|
||||
--SDL_timer_running;
|
||||
removed = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Don't update prev if the timer has disappeared */
|
||||
if (!removed) {
|
||||
prev = t;
|
||||
}
|
||||
}
|
||||
SDL_mutexV(SDL_timer_mutex);
|
||||
}
|
||||
|
||||
static SDL_TimerID
|
||||
SDL_AddTimerInternal(Uint32 interval, SDL_NewTimerCallback callback,
|
||||
void *param)
|
||||
{
|
||||
SDL_TimerID t;
|
||||
t = (SDL_TimerID) SDL_malloc(sizeof(struct _SDL_TimerID));
|
||||
if (t) {
|
||||
t->interval = ROUND_RESOLUTION(interval);
|
||||
t->cb = callback;
|
||||
t->param = param;
|
||||
t->last_alarm = SDL_GetTicks();
|
||||
t->next = SDL_timers;
|
||||
SDL_timers = t;
|
||||
++SDL_timer_running;
|
||||
list_changed = SDL_TRUE;
|
||||
}
|
||||
#ifdef DEBUG_TIMERS
|
||||
printf("SDL_AddTimer(%d) = %08x num_timers = %d\n", interval, (Uint32) t,
|
||||
SDL_timer_running);
|
||||
#endif
|
||||
return t;
|
||||
}
|
||||
|
||||
SDL_TimerID
|
||||
SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param)
|
||||
{
|
||||
SDL_TimerID t;
|
||||
if (!SDL_timer_mutex) {
|
||||
if (SDL_timer_started) {
|
||||
SDL_SetError("This platform doesn't support multiple timers");
|
||||
} else {
|
||||
SDL_SetError("You must call SDL_Init(SDL_INIT_TIMER) first");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if (!SDL_timer_threaded) {
|
||||
SDL_SetError("Multiple timers require threaded events!");
|
||||
return NULL;
|
||||
}
|
||||
SDL_mutexP(SDL_timer_mutex);
|
||||
t = SDL_AddTimerInternal(interval, callback, param);
|
||||
SDL_mutexV(SDL_timer_mutex);
|
||||
return t;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_RemoveTimer(SDL_TimerID id)
|
||||
{
|
||||
SDL_TimerID t, prev = NULL;
|
||||
SDL_bool removed;
|
||||
|
||||
removed = SDL_FALSE;
|
||||
SDL_mutexP(SDL_timer_mutex);
|
||||
/* Look for id in the linked list of timers */
|
||||
for (t = SDL_timers; t; prev = t, t = t->next) {
|
||||
if (t == id) {
|
||||
if (prev) {
|
||||
prev->next = t->next;
|
||||
} else {
|
||||
SDL_timers = t->next;
|
||||
}
|
||||
SDL_free(t);
|
||||
--SDL_timer_running;
|
||||
removed = SDL_TRUE;
|
||||
list_changed = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_TIMERS
|
||||
printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %lu\n",
|
||||
(Uint32) id, removed, SDL_timer_running, SDL_ThreadID());
|
||||
#endif
|
||||
SDL_mutexV(SDL_timer_mutex);
|
||||
return removed;
|
||||
}
|
||||
|
||||
/* Old style callback functions are wrapped through this */
|
||||
static Uint32 SDLCALL
|
||||
callback_wrapper(Uint32 ms, void *param)
|
||||
{
|
||||
SDL_TimerCallback func = (SDL_TimerCallback) param;
|
||||
return (*func) (ms);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback)
|
||||
{
|
||||
int retval;
|
||||
|
||||
#ifdef DEBUG_TIMERS
|
||||
printf("SDL_SetTimer(%d)\n", ms);
|
||||
#endif
|
||||
retval = 0;
|
||||
|
||||
if (SDL_timer_threaded) {
|
||||
SDL_mutexP(SDL_timer_mutex);
|
||||
}
|
||||
if (SDL_timer_running) { /* Stop any currently running timer */
|
||||
if (SDL_timer_threaded) {
|
||||
while (SDL_timers) {
|
||||
SDL_TimerID freeme = SDL_timers;
|
||||
SDL_timers = SDL_timers->next;
|
||||
SDL_free(freeme);
|
||||
}
|
||||
SDL_timer_running = 0;
|
||||
list_changed = SDL_TRUE;
|
||||
} else {
|
||||
SDL_SYS_StopTimer();
|
||||
SDL_timer_running = 0;
|
||||
}
|
||||
}
|
||||
if (ms) {
|
||||
if (SDL_timer_threaded) {
|
||||
if (SDL_AddTimerInternal
|
||||
(ms, callback_wrapper, (void *) callback) == NULL) {
|
||||
retval = -1;
|
||||
}
|
||||
} else {
|
||||
SDL_timer_running = 1;
|
||||
SDL_alarm_interval = ms;
|
||||
SDL_alarm_callback = callback;
|
||||
retval = SDL_SYS_StartTimer();
|
||||
}
|
||||
}
|
||||
if (SDL_timer_threaded) {
|
||||
SDL_mutexV(SDL_timer_mutex);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
47
project/jni/sdl-1.3/src/timer/SDL_timer_c.h
Normal file
47
project/jni/sdl-1.3/src/timer/SDL_timer_c.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Useful functions and variables from SDL_timer.c */
|
||||
#include "SDL_timer.h"
|
||||
|
||||
#define ROUND_RESOLUTION(X) \
|
||||
(((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
|
||||
|
||||
extern int SDL_timer_started;
|
||||
extern int SDL_timer_running;
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
extern Uint32 SDL_alarm_interval;
|
||||
extern SDL_TimerCallback SDL_alarm_callback;
|
||||
|
||||
/* Set whether or not the timer should use a thread.
|
||||
This should be called while the timer subsystem is running.
|
||||
*/
|
||||
extern int SDL_SetTimerThreaded(int value);
|
||||
|
||||
extern int SDL_TimerInit(void);
|
||||
extern void SDL_TimerQuit(void);
|
||||
|
||||
/* This function is called from the SDL event thread if it is available */
|
||||
extern void SDL_ThreadedTimerCheck(void);
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
104
project/jni/sdl-1.3/src/timer/beos/SDL_systimer.c
Normal file
104
project/jni/sdl-1.3/src/timer/beos/SDL_systimer.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_BEOS
|
||||
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
static bigtime_t start;
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
/* Set first ticks value */
|
||||
start = system_time();
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
return ((system_time() - start) / 1000);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
snooze(ms * 1000);
|
||||
}
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static int timer_alive = 0;
|
||||
static SDL_Thread *timer = NULL;
|
||||
|
||||
static int
|
||||
RunTimer(void *unused)
|
||||
{
|
||||
while (timer_alive) {
|
||||
if (SDL_timer_running) {
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* This is only called if the event thread is not running */
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
timer_alive = 1;
|
||||
timer = SDL_CreateThread(RunTimer, NULL);
|
||||
if (timer == NULL)
|
||||
return (-1);
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
timer_alive = 0;
|
||||
if (timer) {
|
||||
SDL_WaitThread(timer, NULL);
|
||||
timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: BeOS uses threaded timer");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_BEOS */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
100
project/jni/sdl-1.3/src/timer/dummy/SDL_systimer.c
Normal file
100
project/jni/sdl-1.3/src/timer/dummy/SDL_systimer.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
}
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static int timer_alive = 0;
|
||||
static SDL_Thread *timer = NULL;
|
||||
|
||||
static int
|
||||
RunTimer(void *unused)
|
||||
{
|
||||
while (timer_alive) {
|
||||
if (SDL_timer_running) {
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
SDL_Delay(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* This is only called if the event thread is not running */
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
timer_alive = 1;
|
||||
timer = SDL_CreateThread(RunTimer, NULL);
|
||||
if (timer == NULL)
|
||||
return (-1);
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
timer_alive = 0;
|
||||
if (timer) {
|
||||
SDL_WaitThread(timer, NULL);
|
||||
timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: threaded timer in use");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
120
project/jni/sdl-1.3/src/timer/nds/SDL_systimer.c
Normal file
120
project/jni/sdl-1.3/src/timer/nds/SDL_systimer.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_NDS
|
||||
|
||||
#include <nds.h>
|
||||
#include <nds/timers.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
#include "../SDL_systimer.h"
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static int timer_alive = 0;
|
||||
static Uint32 timer_ticks;
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
if (!timer_alive) {
|
||||
SDL_SYS_TimerInit();
|
||||
SDL_SYS_StartTimer();
|
||||
}
|
||||
|
||||
timer_ticks = 0;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
return timer_ticks;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
Uint32 start = SDL_GetTicks();
|
||||
while (timer_alive) {
|
||||
if ((SDL_GetTicks() - start) >= ms)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
RunTimer(void *unused)
|
||||
{
|
||||
while (timer_alive) {
|
||||
if (SDL_timer_running) {
|
||||
}
|
||||
SDL_Delay(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
NDS_TimerInterrupt(void)
|
||||
{
|
||||
timer_ticks++;
|
||||
}
|
||||
|
||||
/* This is only called if the event thread is not running */
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
timer_alive = 1;
|
||||
timer_ticks = 0;
|
||||
TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
|
||||
TIMER_DATA(3) = TIMER_FREQ_1024(1000);
|
||||
irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
|
||||
irqEnable(IRQ_TIMER3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
if (timer_alive) {
|
||||
TIMER_CR(3) = 0;
|
||||
}
|
||||
timer_alive = 0;
|
||||
irqDisable(IRQ_TIMER3);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
TIMER_CR(3) |= TIMER_ENABLE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
TIMER_CR(3) &= ~TIMER_ENABLE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_TIMER_NDS */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
248
project/jni/sdl-1.3/src/timer/riscos/SDL_systimer.c
Normal file
248
project/jni/sdl-1.3/src/timer/riscos/SDL_systimer.c
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_RISCOS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
#if SDL_THREADS_DISABLED
|
||||
/* Timer SDL_arraysize(Timer ),start/reset time */
|
||||
static Uint32 timerStart;
|
||||
/* Timer running function */
|
||||
void RISCOS_CheckTimer();
|
||||
#else
|
||||
#include <pthread.h>
|
||||
extern SDL_threadID riscos_main_thread;
|
||||
extern int riscos_using_threads;
|
||||
extern SDL_threadID SDL_ThreadID();
|
||||
extern SDL_threadID SDL_EventThreadID(void);
|
||||
#endif
|
||||
|
||||
|
||||
extern void RISCOS_BackgroundTasks(void);
|
||||
|
||||
/* The first ticks value of the application */
|
||||
clock_t start;
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
/* Set first ticks value */
|
||||
start = clock();
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
clock_t ticks;
|
||||
|
||||
ticks = clock() - start;
|
||||
|
||||
|
||||
#if CLOCKS_PER_SEC == 1000
|
||||
|
||||
return (ticks);
|
||||
|
||||
#elif CLOCKS_PER_SEC == 100
|
||||
|
||||
return (ticks * 10);
|
||||
|
||||
#else
|
||||
|
||||
return ticks * (1000 / CLOCKS_PER_SEC);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
Uint32 now, then, elapsed;
|
||||
#if !SDL_THREADS_DISABLED
|
||||
int is_event_thread;
|
||||
if (riscos_using_threads) {
|
||||
is_event_thread = 0;
|
||||
if (SDL_EventThreadID()) {
|
||||
if (SDL_EventThreadID() == SDL_ThreadID())
|
||||
is_event_thread = 1;
|
||||
} else if (SDL_ThreadID() == riscos_main_thread)
|
||||
is_event_thread = 1;
|
||||
} else
|
||||
is_event_thread = 1;
|
||||
#endif
|
||||
|
||||
/*TODO: Next version of Unixlib may allow us to use usleep here */
|
||||
/* for non event threads */
|
||||
|
||||
/* Set the timeout interval - Linux only needs to do this once */
|
||||
then = SDL_GetTicks();
|
||||
|
||||
do {
|
||||
/* Do background tasks required while sleeping as we are not multithreaded */
|
||||
#if SDL_THREADS_DISABLED
|
||||
RISCOS_BackgroundTasks();
|
||||
#else
|
||||
/* For threaded build only run background tasks in event thread */
|
||||
if (is_event_thread)
|
||||
RISCOS_BackgroundTasks();
|
||||
#endif
|
||||
|
||||
/* Calculate the time interval left (in case of interrupt) */
|
||||
now = SDL_GetTicks();
|
||||
elapsed = (now - then);
|
||||
then = now;
|
||||
if (elapsed >= ms) {
|
||||
break;
|
||||
}
|
||||
ms -= elapsed;
|
||||
#if !SDL_THREADS_DISABLED
|
||||
/* Need to yield to let other threads have a go */
|
||||
if (riscos_using_threads)
|
||||
pthread_yield();
|
||||
#endif
|
||||
|
||||
} while (1);
|
||||
}
|
||||
|
||||
#if SDL_THREADS_DISABLED
|
||||
|
||||
/* Non-threaded version of timer */
|
||||
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
SDL_SetTimer(0, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
timerStart = SDL_GetTicks();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
/* Don't need to do anything as we use SDL_timer_running
|
||||
to detect if we need to check the timer */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RISCOS_CheckTimer()
|
||||
{
|
||||
if (SDL_timer_running
|
||||
&& SDL_GetTicks() - timerStart >= SDL_alarm_interval) {
|
||||
Uint32 ms;
|
||||
|
||||
ms = SDL_alarm_callback(SDL_alarm_interval);
|
||||
if (ms != SDL_alarm_interval) {
|
||||
if (ms) {
|
||||
SDL_alarm_interval = ROUND_RESOLUTION(ms);
|
||||
} else {
|
||||
SDL_alarm_interval = 0;
|
||||
SDL_timer_running = 0;
|
||||
}
|
||||
}
|
||||
if (SDL_alarm_interval)
|
||||
timerStart = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Threaded version of timer - based on code for linux */
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static int timer_alive = 0;
|
||||
static SDL_Thread *timer = NULL;
|
||||
|
||||
static int
|
||||
RunTimer(void *unused)
|
||||
{
|
||||
while (timer_alive) {
|
||||
if (SDL_timer_running) {
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
SDL_Delay(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* This is only called if the event thread is not running */
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
timer_alive = 1;
|
||||
timer = SDL_CreateThread(RunTimer, NULL);
|
||||
if (timer == NULL)
|
||||
return (-1);
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
timer_alive = 0;
|
||||
if (timer) {
|
||||
SDL_WaitThread(timer, NULL);
|
||||
timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: RISC OS uses threaded timer");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
|
||||
#endif /* SDL_TIMER_RISCOS */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
248
project/jni/sdl-1.3/src/timer/unix/SDL_systimer.c
Normal file
248
project/jni/sdl-1.3/src/timer/unix/SDL_systimer.c
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_UNIX
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_systimer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
/* The clock_gettime provides monotonous time, so we should use it if
|
||||
it's available. The clock_gettime function is behind ifdef
|
||||
for __USE_POSIX199309
|
||||
Tommi Kyntola (tommi.kyntola@ray.fi) 27/09/2005
|
||||
*/
|
||||
#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if SDL_THREADS_DISABLED
|
||||
#define USE_ITIMER
|
||||
#endif
|
||||
|
||||
/* The first ticks value of the application */
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
static struct timespec start;
|
||||
#else
|
||||
static struct timeval start;
|
||||
#endif /* HAVE_CLOCK_GETTIME */
|
||||
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
/* Set first ticks value */
|
||||
#if HAVE_CLOCK_GETTIME
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
#else
|
||||
gettimeofday(&start, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
#if HAVE_CLOCK_GETTIME
|
||||
Uint32 ticks;
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
ticks =
|
||||
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_nsec -
|
||||
start.tv_nsec) / 1000000;
|
||||
return (ticks);
|
||||
#else
|
||||
Uint32 ticks;
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
ticks =
|
||||
(now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec -
|
||||
start.tv_usec) / 1000;
|
||||
return (ticks);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
int was_error;
|
||||
|
||||
#if HAVE_NANOSLEEP
|
||||
struct timespec elapsed, tv;
|
||||
#else
|
||||
struct timeval tv;
|
||||
Uint32 then, now, elapsed;
|
||||
#endif
|
||||
|
||||
/* Set the timeout interval */
|
||||
#if HAVE_NANOSLEEP
|
||||
elapsed.tv_sec = ms / 1000;
|
||||
elapsed.tv_nsec = (ms % 1000) * 1000000;
|
||||
#else
|
||||
then = SDL_GetTicks();
|
||||
#endif
|
||||
do {
|
||||
errno = 0;
|
||||
|
||||
#if HAVE_NANOSLEEP
|
||||
tv.tv_sec = elapsed.tv_sec;
|
||||
tv.tv_nsec = elapsed.tv_nsec;
|
||||
was_error = nanosleep(&tv, &elapsed);
|
||||
#else
|
||||
/* Calculate the time interval left (in case of interrupt) */
|
||||
now = SDL_GetTicks();
|
||||
elapsed = (now - then);
|
||||
then = now;
|
||||
if (elapsed >= ms) {
|
||||
break;
|
||||
}
|
||||
ms -= elapsed;
|
||||
tv.tv_sec = ms / 1000;
|
||||
tv.tv_usec = (ms % 1000) * 1000;
|
||||
|
||||
was_error = select(0, NULL, NULL, NULL, &tv);
|
||||
#endif /* HAVE_NANOSLEEP */
|
||||
} while (was_error && (errno == EINTR));
|
||||
}
|
||||
|
||||
#ifdef USE_ITIMER
|
||||
|
||||
static void
|
||||
HandleAlarm(int sig)
|
||||
{
|
||||
Uint32 ms;
|
||||
|
||||
if (SDL_alarm_callback) {
|
||||
ms = (*SDL_alarm_callback) (SDL_alarm_interval);
|
||||
if (ms != SDL_alarm_interval) {
|
||||
SDL_SetTimer(ms, SDL_alarm_callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
|
||||
/* Set the alarm handler (Linux specific) */
|
||||
SDL_memset(&action, 0, sizeof(action));
|
||||
action.sa_handler = HandleAlarm;
|
||||
action.sa_flags = SA_RESTART;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGALRM, &action, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
SDL_SetTimer(0, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
struct itimerval timer;
|
||||
|
||||
timer.it_value.tv_sec = (SDL_alarm_interval / 1000);
|
||||
timer.it_value.tv_usec = (SDL_alarm_interval % 1000) * 1000;
|
||||
timer.it_interval.tv_sec = (SDL_alarm_interval / 1000);
|
||||
timer.it_interval.tv_usec = (SDL_alarm_interval % 1000) * 1000;
|
||||
setitimer(ITIMER_REAL, &timer, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
struct itimerval timer;
|
||||
|
||||
SDL_memset(&timer, 0, (sizeof timer));
|
||||
setitimer(ITIMER_REAL, &timer, NULL);
|
||||
}
|
||||
|
||||
#else /* USE_ITIMER */
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static int timer_alive = 0;
|
||||
static SDL_Thread *timer = NULL;
|
||||
|
||||
static int
|
||||
RunTimer(void *unused)
|
||||
{
|
||||
while (timer_alive) {
|
||||
if (SDL_timer_running) {
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
SDL_Delay(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* This is only called if the event thread is not running */
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
timer_alive = 1;
|
||||
timer = SDL_CreateThread(RunTimer, NULL);
|
||||
if (timer == NULL)
|
||||
return (-1);
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
timer_alive = 0;
|
||||
if (timer) {
|
||||
SDL_WaitThread(timer, NULL);
|
||||
timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: Linux uses threaded timer");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* USE_ITIMER */
|
||||
|
||||
#endif /* SDL_TIMER_UNIX */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
165
project/jni/sdl-1.3/src/timer/win32/SDL_systimer.c
Normal file
165
project/jni/sdl-1.3/src/timer/win32/SDL_systimer.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_WIN32
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
#error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead.
|
||||
#endif
|
||||
|
||||
#define TIME_WRAP_VALUE (~(DWORD)0)
|
||||
|
||||
/* The first (low-resolution) ticks value of the application */
|
||||
static DWORD start;
|
||||
|
||||
#ifndef USE_GETTICKCOUNT
|
||||
/* Store if a high-resolution performance counter exists on the system */
|
||||
static BOOL hires_timer_available;
|
||||
/* The first high-resolution ticks value of the application */
|
||||
static LARGE_INTEGER hires_start_ticks;
|
||||
/* The number of ticks per second of the high-resolution performance counter */
|
||||
static LARGE_INTEGER hires_ticks_per_second;
|
||||
#endif
|
||||
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
/* Set first ticks value */
|
||||
#ifdef USE_GETTICKCOUNT
|
||||
start = GetTickCount();
|
||||
#else
|
||||
#if 0 /* Apparently there are problems with QPC on Win2K */
|
||||
if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
|
||||
hires_timer_available = TRUE;
|
||||
QueryPerformanceCounter(&hires_start_ticks);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
hires_timer_available = FALSE;
|
||||
timeBeginPeriod(1); /* use 1 ms timer precision */
|
||||
start = timeGetTime();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
DWORD now, ticks;
|
||||
#ifndef USE_GETTICKCOUNT
|
||||
LARGE_INTEGER hires_now;
|
||||
#endif
|
||||
|
||||
#ifdef USE_GETTICKCOUNT
|
||||
now = GetTickCount();
|
||||
#else
|
||||
if (hires_timer_available) {
|
||||
QueryPerformanceCounter(&hires_now);
|
||||
|
||||
hires_now.QuadPart -= hires_start_ticks.QuadPart;
|
||||
hires_now.QuadPart *= 1000;
|
||||
hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
|
||||
|
||||
return (DWORD) hires_now.QuadPart;
|
||||
} else {
|
||||
now = timeGetTime();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (now < start) {
|
||||
ticks = (TIME_WRAP_VALUE - start) + now;
|
||||
} else {
|
||||
ticks = (now - start);
|
||||
}
|
||||
return (ticks);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
Sleep(ms);
|
||||
}
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static UINT timerID = 0;
|
||||
|
||||
static void CALLBACK
|
||||
HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser,
|
||||
DWORD_PTR dw1, DWORD_PTR dw2)
|
||||
{
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
MMRESULT result;
|
||||
|
||||
/* Set timer resolution */
|
||||
result = timeBeginPeriod(TIMER_RESOLUTION);
|
||||
if (result != TIMERR_NOERROR) {
|
||||
SDL_SetError("Warning: Can't set %d ms timer resolution",
|
||||
TIMER_RESOLUTION);
|
||||
}
|
||||
/* Allow 10 ms of drift so we don't chew on CPU */
|
||||
timerID =
|
||||
timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC);
|
||||
if (!timerID) {
|
||||
SDL_SetError("timeSetEvent() failed");
|
||||
return (-1);
|
||||
}
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
if (timerID) {
|
||||
timeKillEvent(timerID);
|
||||
}
|
||||
timeEndPeriod(TIMER_RESOLUTION);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: Win32 uses threaded timer");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_WIN32 */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
211
project/jni/sdl-1.3/src/timer/wince/SDL_systimer.c
Normal file
211
project/jni/sdl-1.3/src/timer/wince/SDL_systimer.c
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2010 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_WINCE
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "../SDL_timer_c.h"
|
||||
|
||||
static Uint64 start_date;
|
||||
static Uint64 start_ticks;
|
||||
|
||||
static Uint64
|
||||
wce_ticks(void)
|
||||
{
|
||||
return ((Uint64) GetTickCount());
|
||||
}
|
||||
|
||||
static Uint64
|
||||
wce_date(void)
|
||||
{
|
||||
union
|
||||
{
|
||||
FILETIME ftime;
|
||||
Uint64 itime;
|
||||
} ftime;
|
||||
SYSTEMTIME stime;
|
||||
|
||||
GetSystemTime(&stime);
|
||||
SystemTimeToFileTime(&stime, &ftime.ftime);
|
||||
ftime.itime /= 10000; // Convert 100ns intervals to 1ms intervals
|
||||
// Remove ms portion, which can't be relied on
|
||||
ftime.itime -= (ftime.itime % 1000);
|
||||
return (ftime.itime);
|
||||
}
|
||||
|
||||
static Sint32
|
||||
wce_rel_ticks(void)
|
||||
{
|
||||
return ((Sint32) (wce_ticks() - start_ticks));
|
||||
}
|
||||
|
||||
static Sint32
|
||||
wce_rel_date(void)
|
||||
{
|
||||
return ((Sint32) (wce_date() - start_date));
|
||||
}
|
||||
|
||||
/* Return time in ms relative to when SDL was started */
|
||||
Uint32
|
||||
SDL_GetTicks()
|
||||
{
|
||||
Sint32 offset = wce_rel_date() - wce_rel_ticks();
|
||||
if ((offset < -1000) || (offset > 1000)) {
|
||||
// fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000);
|
||||
start_ticks -= offset;
|
||||
}
|
||||
|
||||
return ((Uint32) wce_rel_ticks());
|
||||
}
|
||||
|
||||
/* Give up approx. givem milliseconds to the OS. */
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
Sleep(ms);
|
||||
}
|
||||
|
||||
/* Recard start-time of application for reference */
|
||||
void
|
||||
SDL_StartTicks(void)
|
||||
{
|
||||
start_date = wce_date();
|
||||
start_ticks = wce_ticks();
|
||||
}
|
||||
|
||||
static UINT WIN_timer;
|
||||
|
||||
#if ( _WIN32_WCE <= 420 )
|
||||
|
||||
static HANDLE timersThread = 0;
|
||||
static HANDLE timersQuitEvent = 0;
|
||||
|
||||
DWORD
|
||||
TimersThreadProc(void *data)
|
||||
{
|
||||
while (WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT) {
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
// create a thread to process a threaded timers
|
||||
// SetTimer does not suit the needs because
|
||||
// TimerCallbackProc will be called only when WM_TIMER occured
|
||||
|
||||
timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0);
|
||||
if (!timersQuitEvent) {
|
||||
SDL_SetError("Cannot create event for timers thread");
|
||||
return -1;
|
||||
}
|
||||
timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0);
|
||||
if (!timersThread) {
|
||||
SDL_SetError
|
||||
("Cannot create timers thread, check amount of RAM available");
|
||||
return -1;
|
||||
}
|
||||
SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST);
|
||||
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
SetEvent(timersQuitEvent);
|
||||
if (WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT)
|
||||
TerminateThread(timersThread, 0);
|
||||
CloseHandle(timersThread);
|
||||
CloseHandle(timersQuitEvent);
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#pragma comment(lib, "mmtimer.lib")
|
||||
|
||||
/* Data to handle a single periodic alarm */
|
||||
static UINT timerID = 0;
|
||||
|
||||
static void CALLBACK
|
||||
HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
|
||||
{
|
||||
SDL_ThreadedTimerCheck();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_TimerInit(void)
|
||||
{
|
||||
MMRESULT result;
|
||||
|
||||
/* Set timer resolution */
|
||||
result = timeBeginPeriod(TIMER_RESOLUTION);
|
||||
if (result != TIMERR_NOERROR) {
|
||||
SDL_SetError("Warning: Can't set %d ms timer resolution",
|
||||
TIMER_RESOLUTION);
|
||||
}
|
||||
/* Allow 10 ms of drift so we don't chew on CPU */
|
||||
timerID =
|
||||
timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC);
|
||||
if (!timerID) {
|
||||
SDL_SetError("timeSetEvent() failed");
|
||||
return (-1);
|
||||
}
|
||||
return (SDL_SetTimerThreaded(1));
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_TimerQuit(void)
|
||||
{
|
||||
if (timerID) {
|
||||
timeKillEvent(timerID);
|
||||
}
|
||||
timeEndPeriod(TIMER_RESOLUTION);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_SYS_StartTimer(void)
|
||||
{
|
||||
SDL_SetError("Internal logic error: WinCE uses threaded timer");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_StopTimer(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_WINCE */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
Reference in New Issue
Block a user