Fix compile.

This commit is contained in:
Relintai 2023-12-19 15:01:48 +01:00
parent eda9c2a063
commit b93fd08530
10 changed files with 254 additions and 195 deletions

View File

@ -39,6 +39,23 @@
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/mutex.cpp -o sfw/mutex.o
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/stime.cpp -o sfw/stime.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/application.cpp -o sfw/application/application.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -o sfw/application/scene.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/application.cpp -o sfw/application/application.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -o sfw/application/scene.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/window.cpp -o sfw/application/window.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c game_scene.cpp -o game_scene.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o
g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/aabb.o sfw/basis.o sfw/color.o sfw/face3.o sfw/logger.o sfw/math_funcs.o \
sfw/memory.o sfw/pcg.o sfw/plane.o sfw/projection.o sfw/quaternion.o sfw/random_pcg.o \
sfw/rect2.o sfw/rect2i.o sfw/safe_refcount.o sfw/transform_2d.o sfw/transform.o \
sfw/ustring.o sfw/vector2.o sfw/vector2i.o sfw/vector3.o sfw/vector3i.o sfw/vector4.o sfw/vector4i.o \
sfw/pool_vector.o sfw/pool_allocator.o sfw/mutex.o sfw/stime.o \
sfw/application/application.o sfw/application/scene.o sfw/application/window.o \
game_scene.o main.o \
-o game
#export args="-lm -ldl -lpthread -lX11 -w -Iengine/ $args"

View File

@ -2,7 +2,8 @@
#include "application.h"
void GameScene::event(const SDL_Event &ev) {
void GameScene::event() {
/*
switch (ev.type) {
case SDL_WINDOWEVENT: {
switch (ev.window.event) {
@ -51,9 +52,11 @@ void GameScene::event(const SDL_Event &ev) {
break;
}
}
*/
}
void GameScene::update(float delta) {
/*
if (up) {
sprite->position.y += delta * 3.0;
}
@ -85,9 +88,11 @@ void GameScene::update(float delta) {
if (sprite->position.y > 14.5) {
sprite->position.y = 14.5;
}
*/
}
void GameScene::render() {
/*
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@ -96,9 +101,11 @@ void GameScene::render() {
tile_map->render();
sprite->render();
*/
}
GameScene::GameScene() {
/*
left = false;
right = false;
up = false;
@ -154,12 +161,15 @@ GameScene::GameScene() {
}
tile_map->build_mesh();
*/
}
GameScene::~GameScene() {
/*
delete camera;
delete texture;
delete material;
delete tile_map;
delete sprite;
*/
}

View File

@ -3,22 +3,24 @@
#include "scene.h"
/*
#include "camera.h"
#include "mesh_instance.h"
#include "texture.h"
#include "texture_material.h"
#include "tile_map.h"
#include "sprite.h"
*/
class GameScene : public Scene {
public:
virtual void event(const SDL_Event &ev);
virtual void event();
virtual void update(float delta);
virtual void render();
GameScene();
~GameScene();
/*
bool left;
bool right;
bool up;
@ -29,6 +31,7 @@ public:
TextureMaterial *material;
TileMap *tile_map;
Sprite *sprite;
*/
};
#endif

View File

@ -10964,6 +10964,7 @@ typedef struct _GLFWwindowNull
}
// Swaps the provided pointers
/*
#define _GLFW_SWAP_POINTERS(x, y) \
{ \
void* t; \
@ -10971,6 +10972,15 @@ typedef struct _GLFWwindowNull
x = y; \
y = t; \
}
*/
#define _GLFW_SWAP_POINTERS(m_x, m_y) __glfw_ptr_swap_tmpl((m_x), (m_y))
template <class T>
inline void __glfw_ptr_swap_tmpl(T &x, T &y) {
T aux = x;
x = y;
y = aux;
}
// Per-thread error structure
//
@ -11427,7 +11437,7 @@ void _glfwPlatformWaitEvents(void);
void _glfwPlatformWaitEventsTimeout(double timeout);
void _glfwPlatformPostEmptyEvent(void);
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions);
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
VkPhysicalDevice device,
uint32_t queuefamily);
@ -12031,10 +12041,10 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
return GLFW_FALSE;
}
nativeConfigs = calloc(nativeCount, sizeof(EGLConfig));
nativeConfigs = (EGLConfig*)calloc(nativeCount, sizeof(EGLConfig));
eglGetConfigs(_glfw.egl.display, nativeConfigs, nativeCount, &nativeCount);
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
usableConfigs = (_GLFWfbconfig*)calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0;
for (i = 0; i < nativeCount; i++)
@ -12151,7 +12161,7 @@ static void makeContextCurrentEGL(_GLFWwindow* window)
static void swapBuffersEGL(_GLFWwindow* window)
{
if (window != _glfwPlatformGetTls(&_glfw.contextSlot))
if (window != (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: The context must be current on the calling thread when swapping buffers");
@ -12186,7 +12196,7 @@ static int extensionSupportedEGL(const char* extension)
static GLFWglproc getProcAddressEGL(const char* procname)
{
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
_GLFWwindow* window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (window->context.egl.client)
{
@ -13097,7 +13107,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
window->context.source = ctxconfig->source;
window->context.client = GLFW_OPENGL_API;
previous = _glfwPlatformGetTls(&_glfw.contextSlot);
previous = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
glfwMakeContextCurrent((GLFWwindow*) window);
window->context.GetIntegerv = (PFNGLGETINTEGERVPROC)
@ -13352,7 +13362,7 @@ GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions
GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFWwindow* previous = _glfwPlatformGetTls(&_glfw.contextSlot);
_GLFWwindow* previous = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
_GLFW_REQUIRE_INIT();
@ -13376,7 +13386,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
GLFWAPI GLFWwindow* glfwGetCurrentContext(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return _glfwPlatformGetTls(&_glfw.contextSlot);
return (GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
}
GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
@ -13402,7 +13412,7 @@ GLFWAPI void glfwSwapInterval(int interval)
_GLFW_REQUIRE_INIT();
window = _glfwPlatformGetTls(&_glfw.contextSlot);
window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (!window)
{
_glfwInputError(GLFW_NO_CURRENT_CONTEXT,
@ -13420,7 +13430,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
window = _glfwPlatformGetTls(&_glfw.contextSlot);
window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (!window)
{
_glfwInputError(GLFW_NO_CURRENT_CONTEXT,
@ -13486,7 +13496,7 @@ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
window = _glfwPlatformGetTls(&_glfw.contextSlot);
window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (!window)
{
_glfwInputError(GLFW_NO_CURRENT_CONTEXT,
@ -13650,7 +13660,7 @@ size_t _glfwEncodeUTF8(char* s, uint32_t codepoint)
char* _glfw_strdup(const char* source)
{
const size_t length = strlen(source);
char* result = calloc(length + 1, 1);
char* result = (char*)calloc(length + 1, 1);
strcpy(result, source);
return result;
}
@ -13729,10 +13739,10 @@ void _glfwInputError(int code, const char* format, ...)
if (_glfw.initialized)
{
error = _glfwPlatformGetTls(&_glfw.errorSlot);
error = (_GLFWerror*)_glfwPlatformGetTls(&_glfw.errorSlot);
if (!error)
{
error = calloc(1, sizeof(_GLFWerror));
error = (_GLFWerror*)calloc(1, sizeof(_GLFWerror));
_glfwPlatformSetTls(&_glfw.errorSlot, error);
_glfwPlatformLockMutex(&_glfw.errorLock);
error->next = _glfw.errorListHead;
@ -13839,7 +13849,7 @@ GLFWAPI int glfwGetError(const char** description)
*description = NULL;
if (_glfw.initialized)
error = _glfwPlatformGetTls(&_glfw.errorSlot);
error = (_GLFWerror*)_glfwPlatformGetTls(&_glfw.errorSlot);
else
error = &_glfwMainThreadError;
@ -15280,7 +15290,7 @@ void _glfwInitGamepadMappings(void)
int jid;
size_t i;
const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*);
_glfw.mappings = calloc(count, sizeof(_GLFWmapping));
_glfw.mappings = (_GLFWmapping*)calloc(count, sizeof(_GLFWmapping));
for (i = 0; i < count; i++)
{
@ -15318,9 +15328,9 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
js = _glfw.joysticks + jid;
js->present = GLFW_TRUE;
js->axes = calloc(axisCount, sizeof(float));
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = calloc(hatCount, 1);
js->axes = (float*)calloc(axisCount, sizeof(float));
js->buttons = (unsigned char *)calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = (unsigned char *)calloc(hatCount, 1);
js->axisCount = axisCount;
js->buttonCount = buttonCount;
js->hatCount = hatCount;
@ -15631,7 +15641,7 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
cursor = calloc(1, sizeof(_GLFWcursor));
cursor = (_GLFWcursor*)calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
@ -15661,7 +15671,7 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)
return NULL;
}
cursor = calloc(1, sizeof(_GLFWcursor));
cursor = (_GLFWcursor*)calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
@ -16042,7 +16052,7 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
{
_glfw.mappingCount++;
_glfw.mappings =
realloc(_glfw.mappings,
(_GLFWmapping*)realloc(_glfw.mappings,
sizeof(_GLFWmapping) * _glfw.mappingCount);
_glfw.mappings[_glfw.mappingCount - 1] = mapping;
}
@ -16299,8 +16309,8 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void)
//
static int compareVideoModes(const void* fp, const void* sp)
{
const GLFWvidmode* fm = fp;
const GLFWvidmode* sm = sp;
const GLFWvidmode* fm = (GLFWvidmode*)fp;
const GLFWvidmode* sm = (GLFWvidmode*)sp;
const int fbpp = fm->redBits + fm->greenBits + fm->blueBits;
const int sbpp = sm->redBits + sm->greenBits + sm->blueBits;
const int farea = fm->width * fm->height;
@ -16357,7 +16367,7 @@ void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement)
if (action == GLFW_CONNECTED)
{
_glfw.monitorCount++;
_glfw.monitors =
_glfw.monitors = (_GLFWmonitor**)
realloc(_glfw.monitors, sizeof(_GLFWmonitor*) * _glfw.monitorCount);
if (placement == _GLFW_INSERT_FIRST)
@ -16424,7 +16434,7 @@ void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window)
//
_GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM)
{
_GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor));
_GLFWmonitor* monitor = (_GLFWmonitor*)calloc(1, sizeof(_GLFWmonitor));
monitor->widthMM = widthMM;
monitor->heightMM = heightMM;
@ -16453,9 +16463,9 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor)
//
void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size)
{
ramp->red = calloc(size, sizeof(unsigned short));
ramp->green = calloc(size, sizeof(unsigned short));
ramp->blue = calloc(size, sizeof(unsigned short));
ramp->red = (unsigned short*)calloc(size, sizeof(unsigned short));
ramp->green = (unsigned short*)calloc(size, sizeof(unsigned short));
ramp->blue = (unsigned short*)calloc(size, sizeof(unsigned short));
ramp->size = size;
}
@ -16730,7 +16740,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
if (!original)
return;
values = calloc(original->size, sizeof(unsigned short));
values = (unsigned short*)calloc(original->size, sizeof(unsigned short));
for (i = 0; i < original->size; i++)
{
@ -16916,7 +16926,7 @@ GLFWbool _glfwInitVulkan(int mode)
return GLFW_FALSE;
}
ep = calloc(count, sizeof(VkExtensionProperties));
ep = (VkExtensionProperties*)calloc(count, sizeof(VkExtensionProperties));
err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep);
if (err)
@ -16957,7 +16967,7 @@ GLFWbool _glfwInitVulkan(int mode)
_glfw.vk.available = GLFW_TRUE;
_glfwPlatformGetRequiredInstanceExtensions(_glfw.vk.extensions);
_glfwPlatformGetRequiredInstanceExtensions((const char **)_glfw.vk.extensions);
return GLFW_TRUE;
}
@ -17332,7 +17342,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
if (!_glfwIsValidContextConfig(&ctxconfig))
return NULL;
window = calloc(1, sizeof(_GLFWwindow));
window = (_GLFWwindow*)calloc(1, sizeof(_GLFWwindow));
window->next = _glfw.windowListHead;
_glfw.windowListHead = window;
@ -17601,7 +17611,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
// The window's context must not be current on another thread when the
// window is destroyed
if (window == _glfwPlatformGetTls(&_glfw.contextSlot))
if (window == (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot))
glfwMakeContextCurrent(NULL);
_glfwPlatformDestroyWindow(window);
@ -22693,7 +22703,7 @@ const char* _glfwPlatformGetClipboardString(void)
return _glfw.win32.clipboardString;
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions)
{
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_win32_surface)
return;
@ -22904,7 +22914,7 @@ static int choosePixelFormat(_GLFWwindow* window,
NULL);
}
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
usableConfigs = (_GLFWfbconfig*)calloc(nativeCount, sizeof(_GLFWfbconfig));
for (i = 0; i < nativeCount; i++)
{
@ -23118,7 +23128,7 @@ static void swapBuffersWGL(_GLFWwindow* window)
static void swapIntervalWGL(int interval)
{
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
_GLFWwindow* window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
window->context.wgl.interval = interval;
@ -24033,7 +24043,7 @@ int _glfwPlatformGetKeyScancode(int key)
return -1;
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions)
{
}
@ -24347,7 +24357,7 @@ static void createKeyTables(void)
const struct
{
int key;
char* name;
const char* name;
} keymap[] =
{
{ GLFW_KEY_GRAVE_ACCENT, "TLDE" },
@ -24482,7 +24492,7 @@ static void createKeyTables(void)
// keyboard layout. Because function keys aren't mapped correctly
// when using traditional KeySym translations, they are mapped
// here instead.
for (int i = 0; i < sizeof(keymap) / sizeof(keymap[0]); i++)
for (unsigned int i = 0; i < sizeof(keymap) / sizeof(keymap[0]); i++)
{
if (strncmp(desc->names->keys[scancode].name,
keymap[i].name,
@ -24506,7 +24516,7 @@ static void createKeyTables(void)
continue;
}
for (int j = 0; j < sizeof(keymap) / sizeof(keymap[0]); j++)
for (unsigned int j = 0; j < sizeof(keymap) / sizeof(keymap[0]); j++)
{
if (strncmp(desc->names->key_aliases[i].alias,
keymap[j].name,
@ -25507,7 +25517,7 @@ void _glfwPollMonitorsX11(void)
disconnectedCount = _glfw.monitorCount;
if (disconnectedCount)
{
disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
disconnected = (_GLFWmonitor**)calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected,
_glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*));
@ -25568,10 +25578,10 @@ void _glfwPollMonitorsX11(void)
for (j = 0; j < screenCount; j++)
{
if (screens[j].x_org == ci->x &&
screens[j].y_org == ci->y &&
screens[j].width == ci->width &&
screens[j].height == ci->height)
if ((int)screens[j].x_org == ci->x &&
(int)screens[j].y_org == ci->y &&
(unsigned int)screens[j].width == ci->width &&
(unsigned int)screens[j].height == ci->height)
{
monitor->x11.index = j;
break;
@ -25841,7 +25851,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
result = calloc(oi->nmode, sizeof(GLFWvidmode));
result = (GLFWvidmode*)calloc(oi->nmode, sizeof(GLFWvidmode));
for (int i = 0; i < oi->nmode; i++)
{
@ -25873,7 +25883,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
else
{
*count = 1;
result = calloc(1, sizeof(GLFWvidmode));
result = (GLFWvidmode*)calloc(1, sizeof(GLFWvidmode));
_glfwPlatformGetVideoMode(monitor, result);
}
@ -25952,7 +25962,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
{
if (XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) != ramp->size)
if ((unsigned int)XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) != ramp->size)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Gamma ramp size must match current ramp size");
@ -26158,7 +26168,7 @@ static GLFWbool waitForAnyEvent(double* timeout)
if (!waitForData(fds, count, timeout))
return GLFW_FALSE;
for (int i = 1; i < count; i++)
for (unsigned int i = 1; i < count; i++)
{
if (fds[i].revents & POLLIN)
return GLFW_TRUE;
@ -26497,8 +26507,8 @@ static char** parseUriList(char* text, int* count)
(*count)++;
char* path = calloc(strlen(line) + 1, 1);
paths = realloc(paths, *count * sizeof(char*));
char* path = (char*)calloc(strlen(line) + 1, 1);
paths = (char**)realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path;
while (*line)
@ -26555,7 +26565,7 @@ static char* convertLatin1toUTF8(const char* source)
for (sp = source; *sp; sp++)
size += (*sp & 0x80) ? 2 : 1;
char* target = calloc(size, 1);
char* target = (char*)calloc(size, 1);
char* tp = target;
for (sp = source; *sp; sp++)
@ -27118,7 +27128,7 @@ static const char* getSelectionString(Atom selection)
if (itemCount)
{
size += itemCount;
string = realloc(string, size);
string = (char*)realloc(string, size);
string[size - itemCount - 1] = '\0';
strcat(string, data);
}
@ -27272,7 +27282,7 @@ static void processEvent(XEvent *event)
XGetEventData(_glfw.x11.display, &event->xcookie) &&
event->xcookie.evtype == XI_RawMotion)
{
XIRawEvent* re = event->xcookie.data;
XIRawEvent* re = (XIRawEvent*)event->xcookie.data;
if (re->valuators.mask_len)
{
const double* values = re->raw_values;
@ -27366,7 +27376,7 @@ static void processEvent(XEvent *event)
if (status == XBufferOverflow)
{
chars = calloc(count + 1, 1);
chars = (char*)calloc(count + 1, 1);
count = Xutf8LookupString(window->x11.ic,
&event->xkey,
chars, count,
@ -27445,7 +27455,7 @@ static void processEvent(XEvent *event)
if (next.type == KeyPress &&
next.xkey.window == event->xkey.window &&
next.xkey.keycode == keycode)
next.xkey.keycode == (unsigned int)keycode)
{
// HACK: The time of repeat events sometimes doesn't
// match that of the press event, so add an
@ -28183,7 +28193,7 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
for (i = 0; i < count; i++)
longCount += 2 + images[i].width * images[i].height;
unsigned long* icon = calloc(longCount, sizeof(unsigned long));
unsigned long* icon = (unsigned long*)calloc(longCount, sizeof(unsigned long));
unsigned long* target = icon;
for (i = 0; i < count; i++)
@ -29046,7 +29056,7 @@ const char* _glfwPlatformGetClipboardString(void)
return getSelectionString(_glfw.x11.CLIPBOARD);
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions)
{
if (!_glfw.vk.KHR_surface)
return;
@ -29320,7 +29330,7 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired,
return GLFW_FALSE;
}
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
usableConfigs = (_GLFWfbconfig*)calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0;
for (i = 0; i < nativeCount; i++)
@ -29436,7 +29446,7 @@ static void swapBuffersGLX(_GLFWwindow* window)
static void swapIntervalGLX(int interval)
{
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
_GLFWwindow* window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (_glfw.glx.EXT_swap_control)
{
@ -29473,7 +29483,7 @@ static GLFWglproc getProcAddressGLX(const char* procname)
else if (_glfw.glx.GetProcAddressARB)
return _glfw.glx.GetProcAddressARB((const GLubyte*) procname);
else
return _glfw_dlsym(_glfw.glx.handle, procname);
return (GLFWglproc)_glfw_dlsym(_glfw.glx.handle, procname);
}
static void destroyContextGLX(_GLFWwindow* window)
@ -29533,31 +29543,31 @@ GLFWbool _glfwInitGLX(void)
}
_glfw.glx.GetFBConfigs =
_glfw_dlsym(_glfw.glx.handle, "glXGetFBConfigs");
(PFNGLXGETFBCONFIGSPROC)_glfw_dlsym(_glfw.glx.handle, "glXGetFBConfigs");
_glfw.glx.GetFBConfigAttrib =
_glfw_dlsym(_glfw.glx.handle, "glXGetFBConfigAttrib");
(PFNGLXGETFBCONFIGATTRIBPROC)_glfw_dlsym(_glfw.glx.handle, "glXGetFBConfigAttrib");
_glfw.glx.GetClientString =
_glfw_dlsym(_glfw.glx.handle, "glXGetClientString");
(PFNGLXGETCLIENTSTRINGPROC)_glfw_dlsym(_glfw.glx.handle, "glXGetClientString");
_glfw.glx.QueryExtension =
_glfw_dlsym(_glfw.glx.handle, "glXQueryExtension");
(PFNGLXQUERYEXTENSIONPROC)_glfw_dlsym(_glfw.glx.handle, "glXQueryExtension");
_glfw.glx.QueryVersion =
_glfw_dlsym(_glfw.glx.handle, "glXQueryVersion");
(PFNGLXQUERYVERSIONPROC)_glfw_dlsym(_glfw.glx.handle, "glXQueryVersion");
_glfw.glx.DestroyContext =
_glfw_dlsym(_glfw.glx.handle, "glXDestroyContext");
(PFNGLXDESTROYCONTEXTPROC)_glfw_dlsym(_glfw.glx.handle, "glXDestroyContext");
_glfw.glx.MakeCurrent =
_glfw_dlsym(_glfw.glx.handle, "glXMakeCurrent");
(PFNGLXMAKECURRENTPROC)_glfw_dlsym(_glfw.glx.handle, "glXMakeCurrent");
_glfw.glx.SwapBuffers =
_glfw_dlsym(_glfw.glx.handle, "glXSwapBuffers");
(PFNGLXSWAPBUFFERSPROC)_glfw_dlsym(_glfw.glx.handle, "glXSwapBuffers");
_glfw.glx.QueryExtensionsString =
_glfw_dlsym(_glfw.glx.handle, "glXQueryExtensionsString");
(PFNGLXQUERYEXTENSIONSSTRINGPROC)_glfw_dlsym(_glfw.glx.handle, "glXQueryExtensionsString");
_glfw.glx.CreateNewContext =
_glfw_dlsym(_glfw.glx.handle, "glXCreateNewContext");
(PFNGLXCREATENEWCONTEXTPROC)_glfw_dlsym(_glfw.glx.handle, "glXCreateNewContext");
_glfw.glx.CreateWindow =
_glfw_dlsym(_glfw.glx.handle, "glXCreateWindow");
(PFNGLXCREATEWINDOWPROC)_glfw_dlsym(_glfw.glx.handle, "glXCreateWindow");
_glfw.glx.DestroyWindow =
_glfw_dlsym(_glfw.glx.handle, "glXDestroyWindow");
(PFNGLXDESTROYWINDOWPROC)_glfw_dlsym(_glfw.glx.handle, "glXDestroyWindow");
_glfw.glx.GetVisualFromFBConfig =
_glfw_dlsym(_glfw.glx.handle, "glXGetVisualFromFBConfig");
(PFNGLXGETVISUALFROMFBCONFIGPROC)_glfw_dlsym(_glfw.glx.handle, "glXGetVisualFromFBConfig");
if (!_glfw.glx.GetFBConfigs ||
!_glfw.glx.GetFBConfigAttrib ||
@ -33434,7 +33444,7 @@ const char* _glfwPlatformGetClipboardString(void)
return _glfw.wl.clipboardString;
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions)
{
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_wayland_surface)
return;
@ -34236,7 +34246,7 @@ static void swapIntervalNSGL(int interval)
{
@autoreleasepool {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
_GLFWwindow* window = (_GLFWwindow*)_glfwPlatformGetTls(&_glfw.contextSlot);
if (window)
{
[window->context.nsgl.object setValues:&interval
@ -37388,7 +37398,7 @@ const char* _glfwPlatformGetClipboardString(void)
} // autoreleasepool
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions)
{
if (_glfw.vk.KHR_surface && _glfw.vk.EXT_metal_surface)
{
@ -38058,8 +38068,8 @@ static void closeJoystick(_GLFWjoystick* js)
//
static int compareJoysticks(const void* fp, const void* sp)
{
const _GLFWjoystick* fj = fp;
const _GLFWjoystick* sj = sp;
const _GLFWjoystick* fj = (const _GLFWjoystick*)fp;
const _GLFWjoystick* sj = (const _GLFWjoystick*)sp;
return strcmp(fj->linjs.path, sj->linjs.path);
}

View File

@ -3,14 +3,31 @@
#include "window.h"
#define GLAD_GL_IMPLEMENTATION // glad
#include "3rd_glad.h"
#define _GLFW_IMPLEMENTATION // glfw337
#define GLFW_INCLUDE_NONE // glfw337
#ifdef __APPLE__
#define _GLFW_COCOA // glfw osx
#elif defined(_WIN32) || defined(_WIN64)
#define _GLFW_WIN32 // glfw win32
#else
#define _GLFW_X11 // glfw linux, also _GLFW_OSMESA or _GLFW_WAYLAND
#endif
#undef _GNU_SOURCE
#include "3rd_glfw3.h"
#undef timeGetTime
#undef Time
#include "error_macros.h"
#include "stime.h"
#include "ustring.h"
#include "vector4.h"
#include "3rd_glad.h"
#include "3rd_glfw3.h"
#include "stime.h"
/*
static volatile float framerate = 0;
static volatile unsigned fps_active, timer_counter, loop_counter;
@ -19,11 +36,11 @@ static int fps__timing_thread(void *arg) {
while (fps_active) {
if (framerate <= 0) {
loop_counter = timer_counter = 0;
Time::sleep_ms(250);
STime::sleep_ms(250);
} else {
timer_counter++;
int64_t tt = (int64_t)(1e9 / (float)framerate) - ns_excess;
uint64_t took = -Time::time_ns();
uint64_t took = -STime::time_ns();
#if is(win32)
timeBeginPeriod(1);
Sleep(tt > 0 ? tt / 1e6 : 0);
@ -63,7 +80,7 @@ static int fps_wait() {
// if we throttled too much, cpu idle wait
while (fps_active && (loop_counter > timer_counter)) {
//thread_yield();
Time::sleep_ns(100);
STime::sleep_ns(100);
}
// max auto frameskip is 10: ie, even if speed is low paint at least one frame every 10
@ -76,7 +93,7 @@ static int fps_wait() {
// only draw if we are fast enough, otherwise skip the frame
return loop_counter >= timer_counter;
}
static void Window::vsync(float hz) {
static void AppWindow::vsync(float hz) {
if (hz <= 0)
return;
do_once fps_locker(1);
@ -91,7 +108,7 @@ static void Window::vsync(float hz) {
static void (*hooks[64])() = {0};
static void *userdatas[64] = {0};
bool Window::hook(void (*func)(), void* user) {
bool AppWindow::hook(void (*func)(), void* user) {
unhook( func );
for( int i = 0; i < 64; ++i ) {
if( !hooks[i] ) {
@ -102,7 +119,7 @@ bool Window::hook(void (*func)(), void* user) {
}
return false;
}
void Window::unhook(void (*func)()) {
void AppWindow::unhook(void (*func)()) {
for( int i = 0; i < 64; ++i ) {
if(hooks[i] == func) {
hooks[i] = 0;
@ -115,7 +132,7 @@ void Window::unhook(void (*func)()) {
// -----------------------------------------------------------------------------
// glfw
void Window::glfw_error_callback(int error, const char *description) {
void AppWindow::glfw_error_callback(int error, const char *description) {
#ifdef __APPLE__
if (error == 65544)
return; // whitelisted
@ -124,11 +141,11 @@ void Window::glfw_error_callback(int error, const char *description) {
CRASH_MSG(String(description) + " (error " + String::num(error) + ")");
}
void Window::glfw_quit(void) {
void AppWindow::glfw_quit(void) {
glfwTerminate();
}
void Window::glfw_init() {
void AppWindow::glfw_init() {
glfwSetErrorCallback(glfw_error_callback);
int ok = glfwInit();
@ -137,10 +154,10 @@ void Window::glfw_init() {
atexit(glfw_quit); //glfwTerminate);
}
void Window::drop_callback(GLFWwindow *window, int count, const char **paths) {
void AppWindow::drop_callback(GLFWwindow *window, int count, const char **paths) {
}
void Window::window_hints(unsigned flags) {
void AppWindow::window_hints(unsigned flags) {
#ifdef __APPLE__
//glfwInitHint( GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE );
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); // @todo: remove silicon mac M1 hack
@ -190,10 +207,10 @@ void Window::window_hints(unsigned flags) {
//if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
//if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
Window::get_singleton()->_window_flags = flags;
AppWindow::get_singleton()->_window_flags = flags;
}
void Window::glNewFrame() {
void AppWindow::glNewFrame() {
// @transparent debug
// if( input_down(KEY_F1) ) transparent(window_has_transparent()^1);
// if( input_down(KEY_F2) ) maximize(window_has_maximize()^1);
@ -211,8 +228,8 @@ void Window::glNewFrame() {
//printf("%dx%d\n", w, h);
#endif
Window::get_singleton()->width = w;
Window::get_singleton()->height = h;
AppWindow::get_singleton()->width = w;
AppWindow::get_singleton()->height = h;
// blending defaults
glEnable(GL_BLEND);
@ -241,7 +258,7 @@ void Window::glNewFrame() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
bool Window::create_from_handle(void *handle, float scale, unsigned flags) {
bool AppWindow::create_from_handle(void *handle, float scale, unsigned int flags) {
// abort run if any test suite failed in unit-test mode
glfw_init();
@ -391,16 +408,14 @@ bool Window::create_from_handle(void *handle, float scale, unsigned flags) {
return true;
}
bool Window::create(float scale, unsigned flags) {
bool AppWindow::create(float scale, unsigned int flags) {
return create_from_handle(NULL, scale, flags);
}
static double boot_time = 0;
char *Window::get_stats() {
char *AppWindow::get_stats() {
static double num_frames = 0, begin = FLT_MAX, prev_frame = 0;
double now = Time::time_ss();
double now = STime::time_ss();
if (boot_time < 0)
boot_time = now;
@ -432,7 +447,7 @@ char *Window::get_stats() {
return buf + strspn(buf, " ");
}
int Window::frame_begin() {
int AppWindow::frame_begin() {
glfwPollEvents();
if (glfwWindowShouldClose(_window)) {
@ -452,7 +467,7 @@ int Window::frame_begin() {
return 1;
}
void Window::frame_end() {
void AppWindow::frame_end() {
// flush batching systems that need to be rendered before frame swapping. order matters.
{
/*
@ -472,7 +487,7 @@ void Window::frame_end() {
}
}
void Window::frame_swap() {
void AppWindow::frame_swap() {
// glFinish();
/*
#ifndef __EMSCRIPTEN__
@ -483,11 +498,11 @@ void Window::frame_swap() {
// emscripten_webgl_commit_frame();
}
void Window::shutdown() {
void AppWindow::shutdown() {
loop_exit(); // finish emscripten loop automatically
}
int Window::swap() {
int AppWindow::swap() {
// end frame
if (frame_count > 0) {
frame_end();
@ -505,7 +520,7 @@ int Window::swap() {
return 1;
}
void Window::resize() {
void AppWindow::resize() {
#ifdef __EMSCRIPTEN__
EM_ASM(canvas.canResize = 0);
if (g->flags & WINDOW_FIXED)
@ -523,8 +538,8 @@ void Window::resize() {
#endif /* __EMSCRIPTEN__ */
}
void Window::loop_wrapper(void *loopArg) {
Window *w = Window::get_singleton();
void AppWindow::loop_wrapper(void *loopArg) {
AppWindow *w = AppWindow::get_singleton();
if (w->frame_begin()) {
w->resize();
w->render_callback(loopArg);
@ -535,7 +550,7 @@ void Window::loop_wrapper(void *loopArg) {
}
}
void Window::loop(void (*user_function)(void *loopArg), void *loopArg) {
void AppWindow::loop(void (*user_function)(void *loopArg), void *loopArg) {
#ifdef __EMSCRIPTEN__
render_callback = user_function;
emscripten_set_main_loop_arg(window_loop_wrapper, loopArg, 0, 1);
@ -546,7 +561,7 @@ void Window::loop(void (*user_function)(void *loopArg), void *loopArg) {
#endif /* __EMSCRIPTEN__ */
}
void Window::loop_exit() {
void AppWindow::loop_exit() {
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#else
@ -554,7 +569,7 @@ void Window::loop_exit() {
#endif /* __EMSCRIPTEN__ */
}
Vector2 Window::canvas() {
Vector2 AppWindow::get_canvas() {
#ifdef __EMSCRIPTEN__
int width = EM_ASM_INT_V(return canvas.width);
int height = EM_ASM_INT_V(return canvas.height);
@ -567,41 +582,41 @@ Vector2 Window::canvas() {
#endif /* __EMSCRIPTEN__ */
}
int Window::get_width() {
int AppWindow::get_width() {
return w;
}
int Window::get_height() {
int AppWindow::get_height() {
return h;
}
double Window::get_time() {
double AppWindow::get_time() {
return t;
}
double Window::get_delta() {
double AppWindow::get_delta() {
return dt;
}
double Window::get_fps() {
double AppWindow::get_fps() {
return fps;
}
void Window::fps_lock(float fps) {
void AppWindow::fps_lock(float fps) {
hz = fps;
}
void Window::fps_unlock() {
void AppWindow::fps_unlock() {
hz = 0;
}
double Window::get_fps_target() {
double AppWindow::get_fps_target() {
return hz;
}
uint64_t Window::frame() {
uint64_t AppWindow::frame() {
return frame_count;
}
void Window::set_title(const char *title_) {
void AppWindow::set_title(const char *title_) {
snprintf(title, 128, "%s", title_);
if (!title[0])
glfwSetWindowTitle(_window, title);
}
void Window::set_color(unsigned color) {
void AppWindow::set_color(unsigned color) {
unsigned r = (color >> 0) & 255;
unsigned g = (color >> 8) & 255;
unsigned b = (color >> 16) & 255;
@ -609,10 +624,10 @@ void Window::set_color(unsigned color) {
winbgcolor = Color(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
}
int Window::has_icon() {
int AppWindow::has_icon() {
return _has_icon;
}
void Window::set_icon(const char *file_icon) {
void AppWindow::set_icon(const char *file_icon) {
/*
int len = 0;
void *data = vfs_load(file_icon, &len);
@ -645,11 +660,11 @@ void Window::set_icon(const char *file_icon) {
#endif
*/
}
void *Window::get_handle() {
void *AppWindow::get_handle() {
return _window;
}
Vector2 Window::dpi() {
Vector2 AppWindow::dpi() {
Vector2 dpi = Vector2(1, 1);
#if !defined(__EMSCRIPTEN__) && !defined(__APPLE__) // @todo: remove silicon mac M1 hack`
@ -661,7 +676,7 @@ Vector2 Window::dpi() {
// -----------------------------------------------------------------------------
// fullscreen
GLFWmonitor *Window::find_monitor(int wx, int wy) {
GLFWmonitor *AppWindow::find_monitor(int wx, int wy) {
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
// find best monitor given current window coordinates. @todo: select by ocuppied window area inside each monitor instead.
@ -681,7 +696,7 @@ GLFWmonitor *Window::find_monitor(int wx, int wy) {
#if 0 // to deprecate
void Window::fullscreen(int enabled) {
void AppWindow::fullscreen(int enabled) {
fullscreen = !!enabled;
#ifndef __EMSCRIPTEN__
if( fullscreen ) {
@ -699,13 +714,13 @@ void Window::fullscreen(int enabled) {
}
#endif
}
int Window::has_fullscreen() {
int AppWindow::has_fullscreen() {
return fullscreen;
}
#else
int Window::has_fullscreen() {
int AppWindow::has_fullscreen() {
#ifdef __EMSCRIPTEN__
EmscriptenFullscreenChangeEvent fsce;
emscripten_get_fullscreen_status(&fsce);
@ -715,7 +730,7 @@ int Window::has_fullscreen() {
#endif /* __EMSCRIPTEN__ */
}
void Window::set_fullscreen(int enabled) {
void AppWindow::set_fullscreen(int enabled) {
if (has_fullscreen() == !!enabled)
return;
@ -778,20 +793,20 @@ void Window::set_fullscreen(int enabled) {
#endif
void Window::set_pause(int enabled) {
void AppWindow::set_pause(int enabled) {
paused = enabled;
}
int Window::has_pause() {
int AppWindow::has_pause() {
return paused;
}
void Window::set_focus() {
void AppWindow::set_focus() {
glfwFocusWindow(_window);
}
int Window::has_focus() {
int AppWindow::has_focus() {
return !!glfwGetWindowAttrib(_window, GLFW_FOCUSED);
}
void Window::create_default_cursors() {
void AppWindow::create_default_cursors() {
if (_cursors_initialized) {
return;
}
@ -813,7 +828,7 @@ void Window::create_default_cursors() {
}
}
void Window::set_cursor_shape(unsigned mode) {
void AppWindow::set_cursor_shape(unsigned mode) {
_cursorshape = (mode &= 7);
create_default_cursors();
@ -824,14 +839,14 @@ void Window::set_cursor_shape(unsigned mode) {
glfwSetCursor(_window, mode < 7 ? cursors[mode] : NULL);
}
}
void Window::set_cursor(int visible) {
void AppWindow::set_cursor(int visible) {
glfwSetInputMode(_window, GLFW_CURSOR, visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
}
int Window::has_cursor() {
int AppWindow::has_cursor() {
return glfwGetInputMode(_window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL;
}
void Window::set_visible(int visible) {
void AppWindow::set_visible(int visible) {
if (!_window)
return;
@ -843,14 +858,14 @@ void Window::set_visible(int visible) {
glfwPollEvents();
#endif
}
int Window::has_visible() {
int AppWindow::has_visible() {
return glfwGetWindowAttrib(_window, GLFW_VISIBLE);
}
double Window::get_aspect() {
double AppWindow::get_aspect() {
return (double)w / (h + !h);
}
void Window::aspect_lock(unsigned numer, unsigned denom) {
void AppWindow::aspect_lock(unsigned numer, unsigned denom) {
if (!_window)
return;
if (numer * denom != 0) {
@ -859,13 +874,13 @@ void Window::aspect_lock(unsigned numer, unsigned denom) {
glfwSetWindowAspectRatio(_window, GLFW_DONT_CARE, GLFW_DONT_CARE);
}
}
void Window::aspect_unlock() {
void AppWindow::aspect_unlock() {
if (!_window)
return;
Window::aspect_lock(0, 0);
AppWindow::aspect_lock(0, 0);
}
void Window::set_transparent(int enabled) {
void AppWindow::set_transparent(int enabled) {
#ifndef __EMSCRIPTEN__
if (!has_fullscreen()) {
if (enabled) {
@ -880,7 +895,7 @@ void Window::set_transparent(int enabled) {
}
#endif
}
int Window::has_transparent() {
int AppWindow::has_transparent() {
#ifndef __EMSCRIPTEN__
return glfwGetWindowAttrib(_window, GLFW_DECORATED) != GLFW_TRUE;
#else
@ -888,7 +903,7 @@ int Window::has_transparent() {
#endif
}
void Window::set_maximize(int enabled) {
void AppWindow::set_maximize(int enabled) {
#ifndef __EMSCRIPTEN__
if (!has_fullscreen()) {
if (enabled) {
@ -899,7 +914,7 @@ void Window::set_maximize(int enabled) {
}
#endif
}
int Window::has_maximize() {
int AppWindow::has_maximize() {
#ifndef __EMSCRIPTEN__
return glfwGetWindowAttrib(_window, GLFW_MAXIMIZED) == GLFW_TRUE;
#else
@ -907,28 +922,31 @@ int Window::has_maximize() {
#endif
}
const char *Window::get_clipboard() {
const char *AppWindow::get_clipboard() {
return glfwGetClipboardString(_window);
}
void Window::set_clipboard(const char *text) {
void AppWindow::set_clipboard(const char *text) {
glfwSetClipboardString(_window, text);
}
double Window::get_scale() { // ok? @testme
double AppWindow::get_scale() { // ok? @testme
float xscale, yscale;
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
return MAX(xscale, yscale);
}
Window *Window::get_singleton() {
AppWindow *AppWindow::get_singleton() {
return _singleton;
}
Window::Window() {
AppWindow::AppWindow() {
_singleton = this;
_window = NULL;
boot_time = 0;
w = 0;
h = 0;
xpos = 0;
@ -977,8 +995,8 @@ Window::Window() {
cursor_enums[5] = GLFW_HAND_CURSOR;
cursor_enums[6] = GLFW_CROSSHAIR_CURSOR;
}
Window::~Window() {
AppWindow::~AppWindow() {
_singleton = NULL;
}
Window *Window::_singleton = NULL;
AppWindow *AppWindow::_singleton = NULL;

View File

@ -17,7 +17,7 @@ struct GLFWwindow;
struct GLFWcursor;
struct GLFWmonitor;
class Window {
class AppWindow {
public:
enum WINDOW_FLAGS {
WINDOW_MSAA2 = 0x02,
@ -37,8 +37,8 @@ public:
WINDOW_VSYNC_DISABLED = 0x2000,
};
bool create(float scale, unsigned flags);
bool create_from_handle(void *handle, float scale, unsigned flags);
bool create(float scale, unsigned int flags);
bool create_from_handle(void *handle, float scale, unsigned int flags);
int frame_begin();
void frame_end();
@ -107,10 +107,10 @@ public:
const char *get_clipboard();
void set_clipboard(const char *text);
static Window *get_singleton();
static AppWindow *get_singleton();
Window();
~Window();
AppWindow();
~AppWindow();
protected:
static void glfw_quit();
@ -123,11 +123,12 @@ protected:
void resize();
static void loop_wrapper(void *loopArg);
void glNewFrame();
Vector2 canvas();
double get_scale();
void create_default_cursors();
static Window *_singleton;
static AppWindow *_singleton;
double boot_time;
GLFWwindow *_window;
int w;

View File

@ -9,42 +9,42 @@
#include <ctime>
#if 0
uint64_t Time::time_gpu() {
uint64_t STime::time_gpu() {
GLint64 t = 123456789;
glGetInteger64v(GL_TIMESTAMP, &t);
return (uint64_t)t;
}
#endif
uint64_t Time::date() {
uint64_t STime::date() {
//time_t epoch = time(0);
//struct tm *ti = localtime(&epoch);
//return atoi64(va("%04d%02d%02d%02d%02d%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec));
return 0;
}
char *Time::date_string() {
char *STime::date_string() {
//time_t epoch = time(0);
//struct tm *ti = localtime(&epoch);
//return va("%04d-%02d-%02d %02d:%02d:%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec);
return 0;
}
uint64_t Time::date_epoch() {
uint64_t STime::date_epoch() {
time_t epoch = time(0);
return epoch;
}
#if 0
double Time::time_ss() {
double STime::time_ss() {
return glfwGetTime();
}
double Time::time_ms() {
double STime::time_ms() {
return glfwGetTime() * 1000.0;
}
uint64_t Time::time_us() {
uint64_t STime::time_us() {
return (uint64_t)(glfwGetTime() * 1000000.0); // @fixme: use a high resolution timer instead, or time_gpu below
}
uint64_t Time::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead
uint64_t STime::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead
return sleep_ms( us / 1000.0 );
}
double Time::sleep_ms(double ms) {
double STime::sleep_ms(double ms) {
double now = time_ms();
if( ms <= 0 ) {
#if defined(_WIN64) || defined(_WIN32)
@ -111,7 +111,7 @@ static uint64_t nanotimer(uint64_t *out_freq) {
#endif
}
uint64_t Time::time_ns() {
uint64_t STime::time_ns() {
static __thread uint64_t epoch = 0;
static __thread uint64_t freq = 0;
if (!freq) {
@ -128,23 +128,23 @@ uint64_t Time::time_ns() {
uint64_t r = a % c;
return q * b + r * b / c;
}
uint64_t Time::time_us() {
uint64_t STime::time_us() {
return time_ns() / TIMER_E3;
}
uint64_t Time::time_ms() {
uint64_t STime::time_ms() {
return time_ns() / TIMER_E6;
}
double Time::time_ss() {
double STime::time_ss() {
return time_ns() / 1e9; // TIMER_E9;
}
double Time::time_mm() {
double STime::time_mm() {
return time_ss() / 60;
}
double Time::time_hh() {
double STime::time_hh() {
return time_mm() / 60;
}
void Time::sleep_ns(double ns) {
void STime::sleep_ns(double ns) {
#if defined(_WIN64) || defined(_WIN32)
if (ns >= 100) {
LARGE_INTEGER li; // Windows sleep in 100ns units
@ -168,12 +168,12 @@ void Time::sleep_ns(double ns) {
#endif
}
}
void Time::sleep_us(double us) {
void STime::sleep_us(double us) {
sleep_ns(us * 1e3);
}
void Time::sleep_ms(double ms) {
void STime::sleep_ms(double ms) {
sleep_ns(ms * 1e6);
}
void Time::sleep_ss(double ss) {
void STime::sleep_ss(double ss) {
sleep_ns(ss * 1e9);
}

View File

@ -7,7 +7,7 @@
#include "int_types.h"
class Time {
class STime {
public:
static uint64_t date(); // YYYYMMDDhhmmss
static uint64_t date_epoch(); // linux epoch