Handmade Hero » Forums » Code » Linux/XCB platform layer
nxsy
Neil Blakey-Milner
46 posts
#961 Linux/XCB platform layer
3 years, 1 month ago Edited by Neil Blakey-Milner on Jan. 9, 2015, 12:54 a.m. 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)

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
chebertapps
Christopher
17 posts
#965 XCB platform layer
3 years, 1 month ago

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.
nxsy
Neil Blakey-Milner
46 posts
#967 XCB platform layer
3 years, 1 month ago

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!

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
ChrisG0x20
Chris
21 posts
#974 XCB platform layer
3 years, 1 month ago

nxsy, that is really cool stuff. Have you ever done any similar low-level code for Wayland?
nxsy
Neil Blakey-Milner
46 posts
#985 XCB platform layer
3 years, 1 month ago

Before this weekend, I'd never done any low-level code in xcb!

Does anything actually use Wayland yet?

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
ChrisG0x20
Chris
21 posts
#1001 XCB platform layer
3 years, 1 month ago

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
Bl00drav3n
6 posts
#1036 XCB platform layer
3 years, 1 month ago Edited by Bl00drav3n on Dec. 24, 2014, 3:54 p.m.

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.
nxsy
Neil Blakey-Milner
46 posts
#1055 XCB platform layer
3 years ago

Does running the code I wrote work, or exhibit the same problem?

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
nxsy
Neil Blakey-Milner
46 posts
#1056 XCB platform layer
3 years ago

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).

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
Bl00drav3n
6 posts
#1095 XCB platform layer
3 years ago

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.
nxsy
Neil Blakey-Milner
46 posts
#1151 XCB platform layer
3 years ago

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).

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
nxsy
Neil Blakey-Milner
46 posts
#1179 XCB platform layer
3 years ago

I've just added debug save state and replay, and ensured it works with Day 30.

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
nxsy
Neil Blakey-Milner
46 posts
#1774 Linux/XCB platform layer
3 years ago

Now up to date with Day 38.

Linux XCB platform layer: https://github.com/nxsy/xcb_handmade

Android NDK platform layer: https://github.com/nxsy/ndk_handmade
chebertapps
Christopher
17 posts
#1775 Linux/XCB platform layer
3 years ago

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...