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

@ -37,8 +37,25 @@
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_vector.cpp -o sfw/pool_vector.o # g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_vector.cpp -o sfw/pool_vector.o
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_allocator.cpp -o sfw/pool_allocator.o # g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_allocator.cpp -o sfw/pool_allocator.o
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/mutex.cpp -o sfw/mutex.o # 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 -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/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/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 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" #include "application.h"
void GameScene::event(const SDL_Event &ev) { void GameScene::event() {
/*
switch (ev.type) { switch (ev.type) {
case SDL_WINDOWEVENT: { case SDL_WINDOWEVENT: {
switch (ev.window.event) { switch (ev.window.event) {
@ -51,9 +52,11 @@ void GameScene::event(const SDL_Event &ev) {
break; break;
} }
} }
*/
} }
void GameScene::update(float delta) { void GameScene::update(float delta) {
/*
if (up) { if (up) {
sprite->position.y += delta * 3.0; sprite->position.y += delta * 3.0;
} }
@ -85,9 +88,11 @@ void GameScene::update(float delta) {
if (sprite->position.y > 14.5) { if (sprite->position.y > 14.5) {
sprite->position.y = 14.5; sprite->position.y = 14.5;
} }
*/
} }
void GameScene::render() { void GameScene::render() {
/*
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -96,9 +101,11 @@ void GameScene::render() {
tile_map->render(); tile_map->render();
sprite->render(); sprite->render();
*/
} }
GameScene::GameScene() { GameScene::GameScene() {
/*
left = false; left = false;
right = false; right = false;
up = false; up = false;
@ -154,12 +161,15 @@ GameScene::GameScene() {
} }
tile_map->build_mesh(); tile_map->build_mesh();
*/
} }
GameScene::~GameScene() { GameScene::~GameScene() {
/*
delete camera; delete camera;
delete texture; delete texture;
delete material; delete material;
delete tile_map; delete tile_map;
delete sprite; delete sprite;
*/
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -9,42 +9,42 @@
#include <ctime> #include <ctime>
#if 0 #if 0
uint64_t Time::time_gpu() { uint64_t STime::time_gpu() {
GLint64 t = 123456789; GLint64 t = 123456789;
glGetInteger64v(GL_TIMESTAMP, &t); glGetInteger64v(GL_TIMESTAMP, &t);
return (uint64_t)t; return (uint64_t)t;
} }
#endif #endif
uint64_t Time::date() { uint64_t STime::date() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //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 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; return 0;
} }
char *Time::date_string() { char *STime::date_string() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //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 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; return 0;
} }
uint64_t Time::date_epoch() { uint64_t STime::date_epoch() {
time_t epoch = time(0); time_t epoch = time(0);
return epoch; return epoch;
} }
#if 0 #if 0
double Time::time_ss() { double STime::time_ss() {
return glfwGetTime(); return glfwGetTime();
} }
double Time::time_ms() { double STime::time_ms() {
return glfwGetTime() * 1000.0; 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 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 ); return sleep_ms( us / 1000.0 );
} }
double Time::sleep_ms(double ms) { double STime::sleep_ms(double ms) {
double now = time_ms(); double now = time_ms();
if( ms <= 0 ) { if( ms <= 0 ) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
@ -111,7 +111,7 @@ static uint64_t nanotimer(uint64_t *out_freq) {
#endif #endif
} }
uint64_t Time::time_ns() { uint64_t STime::time_ns() {
static __thread uint64_t epoch = 0; static __thread uint64_t epoch = 0;
static __thread uint64_t freq = 0; static __thread uint64_t freq = 0;
if (!freq) { if (!freq) {
@ -128,23 +128,23 @@ uint64_t Time::time_ns() {
uint64_t r = a % c; uint64_t r = a % c;
return q * b + r * b / c; return q * b + r * b / c;
} }
uint64_t Time::time_us() { uint64_t STime::time_us() {
return time_ns() / TIMER_E3; return time_ns() / TIMER_E3;
} }
uint64_t Time::time_ms() { uint64_t STime::time_ms() {
return time_ns() / TIMER_E6; return time_ns() / TIMER_E6;
} }
double Time::time_ss() { double STime::time_ss() {
return time_ns() / 1e9; // TIMER_E9; return time_ns() / 1e9; // TIMER_E9;
} }
double Time::time_mm() { double STime::time_mm() {
return time_ss() / 60; return time_ss() / 60;
} }
double Time::time_hh() { double STime::time_hh() {
return time_mm() / 60; return time_mm() / 60;
} }
void Time::sleep_ns(double ns) { void STime::sleep_ns(double ns) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
if (ns >= 100) { if (ns >= 100) {
LARGE_INTEGER li; // Windows sleep in 100ns units LARGE_INTEGER li; // Windows sleep in 100ns units
@ -168,12 +168,12 @@ void Time::sleep_ns(double ns) {
#endif #endif
} }
} }
void Time::sleep_us(double us) { void STime::sleep_us(double us) {
sleep_ns(us * 1e3); sleep_ns(us * 1e3);
} }
void Time::sleep_ms(double ms) { void STime::sleep_ms(double ms) {
sleep_ns(ms * 1e6); sleep_ns(ms * 1e6);
} }
void Time::sleep_ss(double ss) { void STime::sleep_ss(double ss) {
sleep_ns(ss * 1e9); sleep_ns(ss * 1e9);
} }

View File

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