-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flickering - no double buffering..? #4
Comments
Can you provide the code where you encountered the issue? |
Hmm.. I'm having some problems reproducing it in a small testcase. Just writing a grid doesn't trigger the problem. Maybe I have to read some input or do some other work. I recorded a video to show the issue. flicker-2023-10-29_19.40.47.mp4 |
Ok, I found it. It seems struct values isn't initialized to a default value, so because I didn't supply an alpha to This shows the problem (but it's far from minimal). claw-raylib is a bit too low-level for my liking with issues like this :/ But I guess this is as intended and you're focusing on your engine and not a more lispified API for raylib? #+(or)(ql:quickload :claw-raylib)
(defpackage :flicker
(:use #:cl)
(:local-nicknames (#:r #:raylib)))
(in-package :flicker)
(cffi:defcstruct cint
(value :int))
(cobj:define-cobject-class (:struct cint))
(defun flicker ()
(r:with-window ("test" (1920 1080))
(r:set-target-fps 60)
(let* ((+y-factor+ (/ 25 (/ 3129 64)))
(size 36)
(y-size size)
(x-size (* size +y-factor+))
(font (r:load-font-ex (uiop:unix-namestring (asdf:system-relative-pathname :sijo-ion "DejaVuSansMono.ttf"))
size
(cobj:pointer-cobject (cffi:null-pointer) 'cint)
250)))
(do ()
((r:window-should-close))
(r:with-drawing
(r:clear-background r:+blank+)
(dotimes (x 80)
(dotimes (y 50)
(r:draw-text-ex font "#" (r:make-vector2 :x (coerce (* x x-size) 'single-float)
:y (coerce (* y y-size) 'single-float))
(coerce size 'single-float)
(coerce 0 'single-float)
;; NOTE: No alpha causes the flicker
(r:make-color :r 255 :g 255 :b 255))))))))) |
Because C structs do not have default values, we cannot set appropriate default parameters for their constructors during code generation. If we were to initialize fields to 0 by default, it would not be suitable for
I'm not quite sure what you mean by "lispified," but I believe I have struck a good balance between performance and Lisp-like APIs. I rarely encounter the issues you mentioned in my projects because Raylib provides additional creation functions for many types. For example, for |
Yes, I'm probably using it wrong. I have things like the following in my codebase: (cffi:defcstruct cint
(value :int))
(cobj:define-cobject-class (:struct cint))
(cffi:foreign-enum-value enum keyword)
(raylib:make-vector2 :x (coerce (column 0) 'single-float) :y (coerce (row (+ i +map-height+)) 'single-float))
(cobj:pointer-cobject (cffi:null-pointer) 'cint) |
I think I understand what you mean. You want to avoid using C-related code and pointers in the code, right? However, it's difficult to avoid them when directly interacting with C libraries like Raylib.
|
Yes, I don't need to squeece out any performance at all, so I prefer convenience over performance.
Yes, I just don't want to define such things myself, only to update the library later to find out you've done the same work just better ;)
I had the following macro to define (eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro intern-enum (enum &optional (prefix ""))
`(progn
,@(mapcar (lambda (keyword)
`(defconst ,(intern (str:concat "+" (string-upcase prefix) (symbol-name keyword) "+")) ,(cffi:foreign-enum-value enum keyword)))
(cffi:foreign-enum-keyword-list enum)))))
I do this for
Thanks, I'll look into that. It's more that I'd like an easy to use API rather than an actual need.
Thanks, I'll add this. But is there a reason why this, |
Of course, I'm just giving an example to illustrate that it cannot be implemented using constants. In practice, you can write it like this to avoid redundancy: (defun config-flags (&rest flags)
(cffi:foreign-bitfield-value 'raylib:config-flags flags))
(raylib:set-config-flags (config-flags :window-resizable :window-undecorated)) As the name of the repository suggests, I want
If performance is not a concern, you can also omit the definitions of (defun make-cbox (value
&optional
(type
(typecase value
(integer '(signed-byte 32))
(string 'string)
(t (type-of value)))))
(cobj:make-carray 1 :element-type type :initial-element value))
(defun cbox-pointer (cbox)
(cobj:cobject-pointer cbox))
(defun cbox-value (cbox)
(cobj:caref cbox 0))
(defun (setf cbox-value) (value cbox)
(setf (cobj:caref cbox 0) value))
(let ((box (make-cbox 0.0)))
(setf (cbox-value box) 1.0)
(assert (typep (cbox-pointer box) 'cffi:foreign-pointer))
(assert (= (cbox-value box) 1.0))) |
I ported from claylib to claw-raylib, and I'm seeing flickering. Not sure what's going on here. Even at target-fps 1, I can see lot's of fast flickering. I'm drawing a grid of characters, and it's just as if no double buffering is used at all, and I can see cells flickering. But how can this be? Does Raylib even support non-double buffering?
The text was updated successfully, but these errors were encountered: