Separated time state from window system state.

This commit is contained in:
Camilla Berglund 2014-03-27 17:19:22 +01:00
parent 7a4623e034
commit 17d9051b82
10 changed files with 56 additions and 47 deletions

View File

@ -15,8 +15,8 @@ if (_GLFW_COCOA)
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h
posix_tls.h)
set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_gamma.c
cocoa_init.m cocoa_monitor.m cocoa_time.c cocoa_window.m
iokit_joystick.m posix_tls.c)
cocoa_init.m cocoa_monitor.m cocoa_window.m
iokit_joystick.m mach_time.c posix_tls.c)
elseif (_GLFW_WIN32)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h
winmm_joystick.h)

View File

@ -49,6 +49,7 @@ typedef void* id;
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns
@ -76,11 +77,6 @@ typedef struct _GLFWwindowNS
//------------------------------------------------------------------------
typedef struct _GLFWlibraryNS
{
struct {
double base;
double resolution;
} timer;
CGEventSourceRef eventSource;
id delegate;
id autoreleasePool;
@ -112,6 +108,16 @@ typedef struct _GLFWcursorNS
} _GLFWcursorNS;
//------------------------------------------------------------------------
// Platform-specific time structure
//------------------------------------------------------------------------
typedef struct _GLFWtimeNS
{
double base;
double resolution;
} _GLFWtimeNS;
//========================================================================
// Prototypes for platform specific internal functions
//========================================================================

View File

@ -349,6 +349,8 @@ struct _GLFWlibrary
_GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
// This is defined in the context API's platform.h
_GLFW_PLATFORM_LIBRARY_OPENGL_STATE;
// This is defined in the platform's time.h
_GLFW_PLATFORM_LIBRARY_TIME_STATE;
// This is defined in the platform's joystick.h
_GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
// This is defined in the platform's tls.h

View File

@ -48,8 +48,8 @@ void _glfwInitTimer(void)
mach_timebase_info_data_t info;
mach_timebase_info(&info);
_glfw.ns.timer.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfw.ns.timer.base = getRawTime();
_glfw.ns_time.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfw.ns_time.base = getRawTime();
}
@ -59,13 +59,13 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void)
{
return (double) (getRawTime() - _glfw.ns.timer.base) *
_glfw.ns.timer.resolution;
return (double) (getRawTime() - _glfw.ns_time.base) *
_glfw.ns_time.resolution;
}
void _glfwPlatformSetTime(double time)
{
_glfw.ns.timer.base = getRawTime() -
(uint64_t) (time / _glfw.ns.timer.resolution);
_glfw.ns_time.base = getRawTime() -
(uint64_t) (time / _glfw.ns_time.resolution);
}

View File

@ -35,7 +35,7 @@
static uint64_t getRawTime(void)
{
#if defined(CLOCK_MONOTONIC)
if (_GLFW_POSIX_TIME_CONTEXT.monotonic)
if (_glfw.posix_time.monotonic)
{
struct timespec ts;
@ -66,16 +66,16 @@ void _glfwInitTimer(void)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
{
_GLFW_POSIX_TIME_CONTEXT.monotonic = GL_TRUE;
_GLFW_POSIX_TIME_CONTEXT.resolution = 1e-9;
_glfw.posix_time.monotonic = GL_TRUE;
_glfw.posix_time.resolution = 1e-9;
}
else
#endif
{
_GLFW_POSIX_TIME_CONTEXT.resolution = 1e-6;
_glfw.posix_time.resolution = 1e-6;
}
_GLFW_POSIX_TIME_CONTEXT.base = getRawTime();
_glfw.posix_time.base = getRawTime();
}
@ -85,13 +85,13 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void)
{
return (double) (getRawTime() - _GLFW_POSIX_TIME_CONTEXT.base) *
_GLFW_POSIX_TIME_CONTEXT.resolution;
return (double) (getRawTime() - _glfw.posix_time.base) *
_glfw.posix_time.resolution;
}
void _glfwPlatformSetTime(double time)
{
_GLFW_POSIX_TIME_CONTEXT.base = getRawTime() -
(uint64_t) (time / _GLFW_POSIX_TIME_CONTEXT.resolution);
_glfw.posix_time.base = getRawTime() -
(uint64_t) (time / _glfw.posix_time.resolution);
}

View File

@ -28,6 +28,8 @@
#ifndef _posix_time_h_
#define _posix_time_h_
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time
#include <stdint.h>
typedef struct _GLFWtimePOSIX

View File

@ -36,10 +36,8 @@
#error "The Wayland backend depends on EGL platform support"
#endif
#include "linux_joystick.h"
#define _GLFW_POSIX_TIME_CONTEXT _glfw.wl.timer
#include "posix_time.h"
#include "linux_joystick.h"
#define _GLFW_EGL_NATIVE_WINDOW window->wl.native
#define _GLFW_EGL_NATIVE_DISPLAY _glfw.wl.display
@ -74,7 +72,6 @@ typedef struct _GLFWlibraryWayland
int monitorsCount;
int monitorsSize;
_GLFWtimePOSIX timer;
} _GLFWlibraryWayland;
typedef struct _GLFWmonitorWayland

View File

@ -167,6 +167,7 @@ typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*);
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
@ -203,13 +204,6 @@ typedef struct _GLFWlibraryWin32
DWORD foregroundLockTimeout;
char* clipboardString;
// Timer data
struct {
GLboolean hasPC;
double resolution;
unsigned __int64 base;
} timer;
#ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll
struct {
@ -259,6 +253,18 @@ typedef struct _GLFWcursorWin32
} _GLFWcursorWin32;
//------------------------------------------------------------------------
// Platform-specific time structure
//------------------------------------------------------------------------
typedef struct _GLFWtimeWin32
{
GLboolean hasPC;
double resolution;
unsigned __int64 base;
} _GLFWtimeWin32;
//========================================================================
// Prototypes for platform specific internal functions
//========================================================================

View File

@ -32,7 +32,7 @@
//
static unsigned __int64 getRawTime(void)
{
if (_glfw.win32.timer.hasPC)
if (_glfw.win32_time.hasPC)
{
unsigned __int64 time;
QueryPerformanceCounter((LARGE_INTEGER*) &time);
@ -55,16 +55,16 @@ void _glfwInitTimer(void)
if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency))
{
_glfw.win32.timer.hasPC = GL_TRUE;
_glfw.win32.timer.resolution = 1.0 / (double) frequency;
_glfw.win32_time.hasPC = GL_TRUE;
_glfw.win32_time.resolution = 1.0 / (double) frequency;
}
else
{
_glfw.win32.timer.hasPC = GL_FALSE;
_glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms
_glfw.win32_time.hasPC = GL_FALSE;
_glfw.win32_time.resolution = 0.001; // winmm resolution is 1 ms
}
_glfw.win32.timer.base = getRawTime();
_glfw.win32_time.base = getRawTime();
}
@ -74,13 +74,13 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void)
{
return (double) (getRawTime() - _glfw.win32.timer.base) *
_glfw.win32.timer.resolution;
return (double) (getRawTime() - _glfw.win32_time.base) *
_glfw.win32_time.resolution;
}
void _glfwPlatformSetTime(double time)
{
_glfw.win32.timer.base = getRawTime() -
(unsigned __int64) (time / _glfw.win32.timer.resolution);
_glfw.win32_time.base = getRawTime() -
(unsigned __int64) (time / _glfw.win32_time.resolution);
}

View File

@ -62,9 +62,7 @@
#error "No supported context creation API selected"
#endif
#define _GLFW_POSIX_TIME_CONTEXT _glfw.x11.timer
#include "posix_time.h"
#include "linux_joystick.h"
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 x11
@ -204,8 +202,6 @@ typedef struct _GLFWlibraryX11
int exposure;
} saver;
_GLFWtimePOSIX timer;
struct {
char* string;
} selection;