Skip to content
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

scancode handling broken #2

Closed
psilord opened this issue Aug 20, 2013 · 8 comments
Closed

scancode handling broken #2

psilord opened this issue Aug 20, 2013 · 8 comments

Comments

@psilord
Copy link
Contributor

psilord commented Aug 20, 2013

Hello,

In the basic.lisp example, we see the form (equal :sdl-scancode-escape (sdl2:scancode-value keysym)) This test, for me, never passes. The value returned by sdl:scancode-value keysym) is 27, but I'm not sure how one can compare an integer against a keyword symbol and have that work out. I tried a bunch of iterations, some using autowrap:enum-value/key to try and get it working, but to no avail. Also, are the spec/ files from the SDL2 install on the creator's machine? What happens if the SDL2 that I have on my machine is newer, like say the official release? Is it possible that the spec/ header files and the real header files (that the C library was compiled against) could differ in enums and such?

Thank you.

Peter Keller

@photex
Copy link
Contributor

photex commented Aug 20, 2013

Hi Peter,

I'll take a look at the scancode issue you're seeing and see if there isn't something obviously wrong with what I'm doing.

Yeah, there is a bit of a risk that the spec could become out of date. We can regenerate the spec files from the official 2.0 release headers if they weren't already.

I have been working on cl-sdl2 using the steam-runtime because I feel like that's as close to a canonical release as you can find. :)

Chip

@psilord
Copy link
Contributor Author

psilord commented Aug 20, 2013

Hello Chip,

Thank you for your response! I'm happy to try new code out and maybe make some
more examples for things. Are your plans to encode the entire SDL 2.0 API? I
(and a friend of mine) might help with the wrapper if that is the intention now
that SDL 2.0 is officially out. We're (at least) interested in the texture
loading and sound APIs for SDL2.

To reproduce the bug, download and install the official sdl 2.0 library, update
to the most recent distro with quicklisp using sbcl 1.1.10 on an x86-64 linux
machine (I use linux mint 15, but that shouldn't matter). Then clone the git
repo for cl-sdl2 into ~/quicklisp/local-projects, then:

(ql:quickload <a pile of things like cl-opengl, cl-ppcre, cl-autowrap>)
(asdf:load-system :sdl2)
(asdf:load-system :sdl2-examples)
(sdl2-examples::basic-test)

And then hit escape with the mouse in the window. For me, the key is
registered, but it is not EQUAL to :sdl-scancode-escape. An immediate
observation is that since we're comparing against a keyword, I can change it to
EQ instead, but then I noticed that sdl2:scancode-value returns an integer, so
EQ, EQL, or EQUAL are never going to work.

It appears to me that sdl2:scancode-value maybe should return the keyword
itself instead of the integer representation, because then one can do:

(case (sdl2:scancode-value keysym)
(:sdl-scancode-escape ...)
(:sdl-scancode-space ...)
...)

Was that supposed to be the intention?

Thank you!

Pete

@photex
Copy link
Contributor

photex commented Aug 20, 2013

Yep, now that SDL2 has been officially released it is my intention for cl-sdl2 to become a complete wrapper of the library. My initial wrapping got as far as events and opengl as you can see since that was the most immediately interesting portion for me to work on.

sdl2:scancode= is the function that I should be using in the example to test for :sdl-scancode-esc.
This is what should be used to compare a value with a keyword and I just missed that in the last commit. I'll get that fixed tomorrow.

Any contributions you might have even if it's just to the readme are absolutely appreciated. :)

@psilord
Copy link
Contributor Author

psilord commented Aug 20, 2013

Hello,

I tried that function, but

(defun scancode= (scancode scancode-key)
(= scancode (autowrap:enum-value 'sdl2-ffi:sdl-scancode scancode-key)))

always signals a type condition problem because (autowrap:enum-value 'sdl2-ffi:sdl-scancode scancode-key) always seems to return NIL even when giving it things like :sdl-scancode-escape.

Additionally, as a suggestion, shouldn't scancode= be generic method should have two signatures like:

(defmethod scancode= ((scancode integer) (scancode-key symbol))
(= scancode (autowrap:enum-value 'sdl2-ffi:sdl-scancode scancode-key))

(defmethod scancode= ((scancode-key symbol) (scancode integer))
(scancode= scancode scancode-key)

From a human usability of view, the current signature of scancode= is hard to remember.

Thank you!

@rpav
Copy link
Member

rpav commented Aug 20, 2013

Note that as per the example SCANCODE= works via keywords, but these are sans the SDL prefix, e.g.:

(when (scancode= scancode :scancode-w) ...)

@psilord
Copy link
Contributor Author

psilord commented Aug 20, 2013

Ahhh! That's the mistake I was making. The lispbuilder-sdl api is so ingrained into my mind, it didn't even occur to me that I wrote the wrong thing. Thank you!

@psilord
Copy link
Contributor Author

psilord commented Aug 20, 2013

Ok, here is a patch. Thank you!

diff --git a/examples/basic.lisp b/examples/basic.lisp
index 8b7bc3d..f545220 100644
--- a/examples/basic.lisp
+++ b/examples/basic.lisp
@@ -32,7 +32,7 @@
                                  scancode
                                  mod-value))))))
         (:keyup (:keysym keysym)
-          (when (equal :sdl-scancode-escape (sdl2:scancode-value keysym))
+          (when (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape)
             (sdl2:push-event :quit)))
         (:mousemotion (:x x :y y :xrel xrel :yrel yrel :state state)
           (print (format

@photex
Copy link
Contributor

photex commented Aug 20, 2013

Applied and pushed! Thanks for the contribution. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants