This commit is contained in:
Camilla Löwy 2017-03-18 23:09:34 +01:00
parent aaf2800c9c
commit 1982543cd2
9 changed files with 32 additions and 30 deletions

View File

@ -66,7 +66,7 @@ typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacO
#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_LIBRARY_TIMER_STATE _GLFWtimerNS ns
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns
@ -151,11 +151,11 @@ typedef struct _GLFWcursorNS
// Cocoa-specific global timer data
//
typedef struct _GLFWtimeNS
typedef struct _GLFWtimerNS
{
uint64_t frequency;
} _GLFWtimeNS;
} _GLFWtimerNS;
void _glfwInitTimerNS(void);

View File

@ -40,7 +40,7 @@ void _glfwInitTimerNS(void)
mach_timebase_info_data_t info;
mach_timebase_info(&info);
_glfw.ns_time.frequency = (info.denom * 1e9) / info.numer;
_glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer;
}
@ -55,6 +55,6 @@ uint64_t _glfwPlatformGetTimerValue(void)
uint64_t _glfwPlatformGetTimerFrequency(void)
{
return _glfw.ns_time.frequency;
return _glfw.timer.ns.frequency;
}

View File

@ -174,7 +174,7 @@ GLFWAPI int glfwInit(void)
}
_glfw.initialized = GLFW_TRUE;
_glfw.timerOffset = _glfwPlatformGetTimerValue();
_glfw.timer.offset = _glfwPlatformGetTimerValue();
// Not all window hints have zero as their default value
glfwDefaultWindowHints();

View File

@ -770,7 +770,7 @@ GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle)
GLFWAPI double glfwGetTime(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(0.0);
return (double) (_glfwPlatformGetTimerValue() - _glfw.timerOffset) /
return (double) (_glfwPlatformGetTimerValue() - _glfw.timer.offset) /
_glfwPlatformGetTimerFrequency();
}
@ -784,7 +784,7 @@ GLFWAPI void glfwSetTime(double time)
return;
}
_glfw.timerOffset = _glfwPlatformGetTimerValue() -
_glfw.timer.offset = _glfwPlatformGetTimerValue() -
(uint64_t) (time * _glfwPlatformGetTimerFrequency());
}

View File

@ -517,10 +517,14 @@ struct _GLFWlibrary
_GLFWjoystick joysticks[GLFW_JOYSTICK_LAST + 1];
uint64_t timerOffset;
_GLFWtls context;
struct {
uint64_t offset;
// This is defined in the platform's time.h
_GLFW_PLATFORM_LIBRARY_TIMER_STATE;
} timer;
struct {
GLFWbool available;
void* handle;
@ -553,8 +557,6 @@ struct _GLFWlibrary
_GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
// This is defined in the context API's context.h
_GLFW_PLATFORM_LIBRARY_CONTEXT_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 egl_context.h

View File

@ -44,14 +44,14 @@ void _glfwInitTimerPOSIX(void)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
{
_glfw.posix_time.monotonic = GLFW_TRUE;
_glfw.posix_time.frequency = 1000000000;
_glfw.timer.posix.monotonic = GLFW_TRUE;
_glfw.timer.posix.frequency = 1000000000;
}
else
#endif
{
_glfw.posix_time.monotonic = GLFW_FALSE;
_glfw.posix_time.frequency = 1000000;
_glfw.timer.posix.monotonic = GLFW_FALSE;
_glfw.timer.posix.frequency = 1000000;
}
}
@ -63,7 +63,7 @@ void _glfwInitTimerPOSIX(void)
uint64_t _glfwPlatformGetTimerValue(void)
{
#if defined(CLOCK_MONOTONIC)
if (_glfw.posix_time.monotonic)
if (_glfw.timer.posix.monotonic)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -80,6 +80,6 @@ uint64_t _glfwPlatformGetTimerValue(void)
uint64_t _glfwPlatformGetTimerFrequency(void)
{
return _glfw.posix_time.frequency;
return _glfw.timer.posix.frequency;
}

View File

@ -28,19 +28,19 @@
#ifndef _glfw3_posix_time_h_
#define _glfw3_posix_time_h_
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time
#define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix
#include <stdint.h>
// POSIX-specific global timer data
//
typedef struct _GLFWtimePOSIX
typedef struct _GLFWtimerPOSIX
{
GLFWbool monotonic;
uint64_t frequency;
} _GLFWtimePOSIX;
} _GLFWtimerPOSIX;
void _glfwInitTimerPOSIX(void);

View File

@ -220,7 +220,7 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(
#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_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
#define _GLFW_PLATFORM_TLS_STATE _GLFWtlsWin32 win32
@ -321,12 +321,12 @@ typedef struct _GLFWcursorWin32
// Win32-specific global timer data
//
typedef struct _GLFWtimeWin32
typedef struct _GLFWtimerWin32
{
GLFWbool hasPC;
uint64_t frequency;
} _GLFWtimeWin32;
} _GLFWtimerWin32;
// Win32-specific thread local storage data
//

View File

@ -40,13 +40,13 @@ void _glfwInitTimerWin32(void)
if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency))
{
_glfw.win32_time.hasPC = GLFW_TRUE;
_glfw.win32_time.frequency = frequency;
_glfw.timer.win32.hasPC = GLFW_TRUE;
_glfw.timer.win32.frequency = frequency;
}
else
{
_glfw.win32_time.hasPC = GLFW_FALSE;
_glfw.win32_time.frequency = 1000;
_glfw.timer.win32.hasPC = GLFW_FALSE;
_glfw.timer.win32.frequency = 1000;
}
}
@ -57,7 +57,7 @@ void _glfwInitTimerWin32(void)
uint64_t _glfwPlatformGetTimerValue(void)
{
if (_glfw.win32_time.hasPC)
if (_glfw.timer.win32.hasPC)
{
uint64_t value;
QueryPerformanceCounter((LARGE_INTEGER*) &value);
@ -69,6 +69,6 @@ uint64_t _glfwPlatformGetTimerValue(void)
uint64_t _glfwPlatformGetTimerFrequency(void)
{
return _glfw.win32_time.frequency;
return _glfw.timer.win32.frequency;
}