Skip to content

Commit

Permalink
remove math.h dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Jan 6, 2025
1 parent 7159047 commit b1ba1de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ endif

examples/minimal_links/minimal_links: examples/minimal_links/minimal_links.c RGFW.h
ifeq ($(detected_OS),Linux)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lm -o $@$(EXT)
$(CC) $(CFLAGS) -I. $< -o $@$(EXT)
else ifeq ($(detected_OS),windows)
$(CC) $(CFLAGS) $(WARNINGS) -I. $< -lgdi32 -o $@$(EXT)
else ifeq ($(detected_OS),Darwin)
Expand Down
19 changes: 11 additions & 8 deletions RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ int main() {
#define RGFW_USERPTR NULL
#endif

#ifndef RGFW_ROUND
#define RGFW_ROUND(x) (int)((x) >= 0 ? (x) + 0.5f : (x) - 0.5f)
#endif

#ifndef RGFW_ALLOC
#include <stdlib.h>

Expand Down Expand Up @@ -1263,7 +1267,6 @@ typedef RGFW_ENUM(u8, RGFW_mouseIcons) {

#include <string.h>

#include <math.h>
#include <assert.h>

/*
Expand Down Expand Up @@ -1815,7 +1818,7 @@ u32 RGFW_window_checkFPS(RGFW_window* win, u32 fpsCap) {
u64 deltaTime = RGFW_getTimeNS() - win->event.frameTime;

u32 output_fps = 0;
u64 fps = round(1e+9 / deltaTime);
u64 fps = RGFW_ROUND(1e+9 / deltaTime);
output_fps= fps;

if (fpsCap && fps > fpsCap) {
Expand All @@ -1834,7 +1837,7 @@ u32 RGFW_window_checkFPS(RGFW_window* win, u32 fpsCap) {
return (u32) output_fps;

deltaTime = RGFW_getTimeNS() - win->event.frameTime2;
output_fps = round(1e+9 / deltaTime);
output_fps = RGFW_ROUND(1e+9 / deltaTime);
win->event.frameTime2 = RGFW_getTimeNS();

return output_fps;
Expand Down Expand Up @@ -3860,7 +3863,7 @@ static float XGetSystemContentDPI(Display* display, i32 screen) {
XrmDestroyDatabase(db);
}
#else
dpi = roundf(DisplayWidth(display, screen) / (DisplayWidthMM(display, screen) / 25.4));
dpi = RGFW_ROUND(DisplayWidth(display, screen) / (DisplayWidthMM(display, screen) / 25.4));
#endif

return dpi;
Expand Down Expand Up @@ -3891,8 +3894,8 @@ RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
ci = XRRGetCrtcInfo(display, sr, sr->crtcs[crtc]);
}

float ppi_width = round((float)monitor.rect.w/(float)monitor.physW);
float ppi_height = round((float)monitor.rect.h/(float)monitor.physH);
float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);

monitor.scaleX = (float) (ppi_width) / dpi;
monitor.scaleY = (float) (ppi_height) / dpi;
Expand Down Expand Up @@ -3934,8 +3937,8 @@ RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
monitor.scaleX = 0;
monitor.scaleY = 0;
} else {
float ppi_width = round((float)monitor.rect.w/(float)monitor.physW);
float ppi_height = round((float)monitor.rect.h/(float)monitor.physH);
float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);

monitor.scaleX = (float) (ppi_width) / (float) dpi;
monitor.scaleY = (float) (ppi_height) / (float) dpi;
Expand Down

0 comments on commit b1ba1de

Please sign in to comment.