1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

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 set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h
posix_tls.h) posix_tls.h)
set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_gamma.c set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_gamma.c
cocoa_init.m cocoa_monitor.m cocoa_time.c cocoa_window.m cocoa_init.m cocoa_monitor.m cocoa_window.m
iokit_joystick.m posix_tls.c) iokit_joystick.m mach_time.c posix_tls.c)
elseif (_GLFW_WIN32) elseif (_GLFW_WIN32)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_tls.h
winmm_joystick.h) winmm_joystick.h)

View File

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

View File

@ -349,6 +349,8 @@ struct _GLFWlibrary
_GLFW_PLATFORM_LIBRARY_WINDOW_STATE; _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
// This is defined in the context API's platform.h // This is defined in the context API's platform.h
_GLFW_PLATFORM_LIBRARY_OPENGL_STATE; _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 // This is defined in the platform's joystick.h
_GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE; _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE;
// This is defined in the platform's tls.h // 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_data_t info;
mach_timebase_info(&info); mach_timebase_info(&info);
_glfw.ns.timer.resolution = (double) info.numer / (info.denom * 1.0e9); _glfw.ns_time.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfw.ns.timer.base = getRawTime(); _glfw.ns_time.base = getRawTime();
} }
@ -59,13 +59,13 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void) double _glfwPlatformGetTime(void)
{ {
return (double) (getRawTime() - _glfw.ns.timer.base) * return (double) (getRawTime() - _glfw.ns_time.base) *
_glfw.ns.timer.resolution; _glfw.ns_time.resolution;
} }
void _glfwPlatformSetTime(double time) void _glfwPlatformSetTime(double time)
{ {
_glfw.ns.timer.base = getRawTime() - _glfw.ns_time.base = getRawTime() -
(uint64_t) (time / _glfw.ns.timer.resolution); (uint64_t) (time / _glfw.ns_time.resolution);
} }

View File

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

View File

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

View File

@ -36,10 +36,8 @@
#error "The Wayland backend depends on EGL platform support" #error "The Wayland backend depends on EGL platform support"
#endif #endif
#include "linux_joystick.h"
#define _GLFW_POSIX_TIME_CONTEXT _glfw.wl.timer
#include "posix_time.h" #include "posix_time.h"
#include "linux_joystick.h"
#define _GLFW_EGL_NATIVE_WINDOW window->wl.native #define _GLFW_EGL_NATIVE_WINDOW window->wl.native
#define _GLFW_EGL_NATIVE_DISPLAY _glfw.wl.display #define _GLFW_EGL_NATIVE_DISPLAY _glfw.wl.display
@ -74,7 +72,6 @@ typedef struct _GLFWlibraryWayland
int monitorsCount; int monitorsCount;
int monitorsSize; int monitorsSize;
_GLFWtimePOSIX timer;
} _GLFWlibraryWayland; } _GLFWlibraryWayland;
typedef struct _GLFWmonitorWayland 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_WINDOW_STATE _GLFWwindowWin32 win32
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 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_MONITOR_STATE _GLFWmonitorWin32 win32
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
@ -203,13 +204,6 @@ typedef struct _GLFWlibraryWin32
DWORD foregroundLockTimeout; DWORD foregroundLockTimeout;
char* clipboardString; char* clipboardString;
// Timer data
struct {
GLboolean hasPC;
double resolution;
unsigned __int64 base;
} timer;
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll // winmm.dll
struct { struct {
@ -259,6 +253,18 @@ typedef struct _GLFWcursorWin32
} _GLFWcursorWin32; } _GLFWcursorWin32;
//------------------------------------------------------------------------
// Platform-specific time structure
//------------------------------------------------------------------------
typedef struct _GLFWtimeWin32
{
GLboolean hasPC;
double resolution;
unsigned __int64 base;
} _GLFWtimeWin32;
//======================================================================== //========================================================================
// Prototypes for platform specific internal functions // Prototypes for platform specific internal functions
//======================================================================== //========================================================================

View File

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

View File

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