Merge pull request #70 from tsoding/39

(#39) Unhardcode refresh rate
This commit is contained in:
Alexey Kutepov 2019-12-05 00:50:07 +07:00 committed by GitHub
commit 989291a74a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -9,10 +9,11 @@ in rec {
pkgconfig
nim_1_0
xorg.libX11
xorg.libXrandr
libGL
libGLU
freeglut
];
LD_LIBRARY_PATH="/run/opengl-driver/lib;${xorg.libX11}/lib/;${libGL}/lib/;${libGLU}/lib;${freeglut}/lib";
LD_LIBRARY_PATH="/run/opengl-driver/lib;${xorg.libX11}/lib/;${libGL}/lib/;${libGLU}/lib;${freeglut}/lib;${xorg.libXrandr}/lib";
};
}

View File

@ -4,7 +4,7 @@ import navigation
import image
import config
import x11/xlib, x11/x, x11/xutil, x11/keysym
import x11/xlib, x11/x, x11/xutil, x11/keysym, x11/xrandr
import opengl, opengl/glx
import math
import la
@ -148,6 +148,10 @@ proc main() =
var root = DefaultRootWindow(display)
var screenConfig = XRRGetScreenInfo(display, root)
let rate = XRRConfigCurrentRate(screenConfig)
echo "Screen rate: ", rate
var screenshot = takeScreenshot(display, root)
assert screenshot.bpp == 32
@ -282,6 +286,7 @@ proc main() =
isEnabled: false,
radius: 200.0)
let dt = 1.0 / rate.float
while not quitting:
var wa: TXWindowAttributes
discard XGetWindowAttributes(display, win, addr wa)
@ -304,7 +309,7 @@ proc main() =
# delta is the distance the mouse traveled in a single
# frame. To turn the velocity into units/second we need to
# multiple it by FPS.
camera.velocity = delta * config.fps.float
camera.velocity = delta * rate.float
mouse.prev = mouse.curr
@ -379,7 +384,6 @@ proc main() =
else:
discard
let dt = 1.0 / config.fps.float
camera.update(config, dt, mouse, screenshot,
vec2(wa.width.float32, wa.height.float32))
flashlight.update(dt)
@ -389,5 +393,6 @@ proc main() =
mouse, flashlight)
glXSwapBuffers(display, win)
glFinish()
main()

View File

@ -4,13 +4,11 @@ type Config* = object
scrollSpeed*: float
dragFriction*: float
scaleFriction*: float
fps*: int
const defaultConfig* = Config(
scrollSpeed: 1.5,
dragFriction: 6.0,
scaleFriction: 4.0,
fps: 60
)
macro parseObject(obj: typed, key, val: string) =

View File

@ -1,4 +1,3 @@
import math
import config
import la
import image