Handmade Hero»Forums»Code
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
Edited by Neil Blakey-Milner on Reason: Making the title easier to search for.
As forewarned in the stream chat, my holiday project is to write an XCB (X protocol C-language Binding) platform layer for Handmade Hero.

XCB is the lowest-level X (the Linux and other Unix windowing system) protocol library. Xlib is the more common client library, which is a level up from there. XCB is a retroactive lower-level library, so there are still a lot of rough edges. And the documentation is fairly horrible.

I started over the weekend, and here's what I've got so far:

https://github.com/nxsy/xcb_handmade

Completed (at least partially) so far:

* Game memory allocation
* Graphics
* Keyboard input
* Mouse input (x/y only)
* Load and calling UpdateAndRender game code (and hot reloading)

Still needed:

* Audio
* Frame timing and locking
* XBox360 controller support
* Debug platform functions (read file, write file, free memory)
Christopher
17 posts
Linux/XCB platform layer
Woah. This is cool! I started playing around with Xlib (actually I'm using CLX and following along with Common Lisp, but same difference), and it is very easy to use I think! I usually use SDL and it's really similar. It will be cool to see how Xlib differs from XCB

Are you planning on using ALSA for sound? I think that's what I'm going to use, it seems equivalent to Direct Sound.
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
I'm leaving audio for last - it is the most code, and it is the thing I know the least about.

I've managed to figure out how to get my XBox360 controller to be forwarded to my Linux VM, and jstest is working with great with it (sees the different axes, buttons), so it should be relatively easy from here.

I'm working on the frame timing at the moment - I have it at ~90% of frames at exactly 33.33ms, with some frames taking up to 4ms longer!
Chris
21 posts
Linux/XCB platform layer
nxsy, that is really cool stuff. Have you ever done any similar low-level code for Wayland?
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
Before this weekend, I'd never done any low-level code in xcb!

Does anything actually use Wayland yet?
Chris
21 posts
Linux/XCB platform layer
Haha... true. I thought people were starting to write code against it, but who knows? I was just curious what it would look like. I should take a peek myself. Now, just need to make the time... :P
6 posts
Linux/XCB platform layer
Edited by Bl00drav3n on
Wow, what a coincidence! Yesterday I started to implement a platform layer using XCB on my Raspberry Pi (although not for Handmade Hero). It's slow as hell, because my XServer runs on on a remote netbook, but it's working (with about 5fps on a 256x256 window).
I found it very hard to find any valuable documentation for XCB though, so I appreciate your well documented code - finally I know what that highbit of the event response type means and how to catch the WM_WINDOW_DELETE event. :)

Quick question: does anybody know why, when I run my program on the local X (on the RPI), the window doesn't get updated? I do the exact same thing as nxsy: create an offscreen image buffer and pixmap - call image_put and copy_area, then flush (i use aux_sync but w/e). When I run the program, the window gets created and the loop executes, but the window contents don't get updated. Basically the window seems transparent because no content has been drawn yet.
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
Does running the code I wrote work, or exhibit the same problem?
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
I've now added basic XBox 360 controller support (walks /dev/input/js* and finds any XBox controller, and some hideous axis/button mapping) and frame locking, and support for running Day 28's code (dtForFrame).
6 posts
Linux/XCB platform layer
nxsy
Does running the code I wrote work, or exhibit the same problem?

I will try and implement the necessary calls to get your code running on my RPI tomorrow probably (I did not preorder Handmade Hero - yet). But basically I am doing the same calls as you do in the same order - maybe the X is not getting enough CPU time to render as the App uses up all the resources. I'll check that.
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
I've now added some very very dodgy ALSA sound support. Buffer underruns every once in a while (may be worse on different machines), and lots of assumptions. But it "Works On My Machine"(TM).
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
I've just added debug save state and replay, and ensured it works with Day 30.
Neil Blakey-Milner
45 posts
Linux/XCB platform layer
Now up to date with Day 38.
Christopher
17 posts
Linux/XCB platform layer
Hey! Just tried it out! great work! (I've been using this as a rough guide for some linux things in my version.) I had to comment out audio, because for some reason neither

snd_pcm_avail_delay
snd_pcm_recover

could be found. (Although they are definitely in the .so that I'm using)

Also, I've been having trouble with the joystick in the 360 controller. It seems my joystick is sending a different type of event (maybe one that is bigger than the js_event? It's hard to know.) The rest of the controller works...