Building with nxsy's XCB platform layer on Arch

Alright, so now that Casey has implemented the Trippy Christmas Tree Triforce Transform™ (day 91), I feel I have to start playing with the code. I've cloned the git repo of nxsy's XCB platform layer to my Arch Linux system and followed the instructions – i.e. installed the prerequisites (listed at the bottom) and symlinked the source for day 38 (just as a starting point) to the git repo's src/ directory – but am getting a bunch of errors, notes and warnings while compiling:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$ sh build.sh
In file included from src/handmade.h:22:0,
                 from src/handmade.cpp:9:
src/handmade_platform.h:57:9: error: ‘size_t’ does not name a type
 typedef size_t memory_index;
         ^
In file included from src/handmade.cpp:9:0:
src/handmade.h:68:5: error: ‘memory_index’ does not name a type
     memory_index Size;
     ^
src/handmade.h:70:5: error: ‘memory_index’ does not name a type
     memory_index Used;
     ^
src/handmade.h:74:38: error: ‘memory_index’ has not been declared
 InitializeArena(memory_arena *Arena, memory_index Size, uint8 *Base)
                                      ^
src/handmade.h: In function ‘void InitializeArena(memory_arena*, int, uint8*)’:
src/handmade.h:76:12: error: ‘struct memory_arena’ has no member named ‘Size’
     Arena->Size = Size;
            ^
src/handmade.h:78:12: error: ‘struct memory_arena’ has no member named ‘Used’
     Arena->Used = 0;
            ^
src/handmade.h: At global scope:
src/handmade.h:84:32: error: ‘memory_index’ has not been declared
 PushSize_(memory_arena *Arena, memory_index Size)
                                ^
src/handmade.h: In function ‘void* PushSize_(memory_arena*, int)’:
src/handmade.h:86:20: error: ‘struct memory_arena’ has no member named ‘Used’
     Assert((Arena->Used + Size) <= Arena->Size);
                    ^
src/handmade.h:32:33: note: in definition of macro ‘Assert’
 #define Assert(Expression) if(!(Expression)) {*(int *)0 = 0;}
                                 ^
src/handmade.h:86:43: error: ‘struct memory_arena’ has no member named ‘Size’
     Assert((Arena->Used + Size) <= Arena->Size);
                                           ^
src/handmade.h:32:33: note: in definition of macro ‘Assert’
 #define Assert(Expression) if(!(Expression)) {*(int *)0 = 0;}
                                 ^
src/handmade.h:87:41: error: ‘struct memory_arena’ has no member named ‘Used’
     void *Result = Arena->Base + Arena->Used;
                                         ^
src/handmade.h:88:12: error: ‘struct memory_arena’ has no member named ‘Used’
     Arena->Used += Size;
            ^
src/handmade.cpp: In function ‘void GameUpdateAndRender(thread_context*, game_memory*, game_input*, game_offscreen_buffer*)’:
src/handmade.cpp:267:97: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
             DEBUGLoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "test/test_background.bmp");
                                                                                                 ^
src/handmade.cpp:269:102: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
             DEBUGLoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "test/test_hero_front_head.bmp");
                                                                                                      ^
src/handmade.cpp:271:102: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
             DEBUGLoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "test/test_hero_front_cape.bmp");
                                                                                                      ^
src/handmade.cpp:273:103: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
             DEBUGLoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "test/test_hero_front_torso.bmp");
                                                                                                       ^

I'm probably missing something really obvious, but I can't see what it is. Any chance you could give me a nudge in the right direction, please, folks?


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$ pacman -Qs gcc\|xcb\|alsa  
local/alsa-lib 1.0.29-1
    An alternative implementation of Linux sound support
local/alsa-oss 1.0.28-1
    OSS compatibility library
local/alsa-plugins 1.0.29-2
    Extra alsa plugins
local/alsa-utils 1.0.29-1
    An alternative implementation of Linux sound support
local/cairo 1.14.2-1
    Cairo vector graphics library
local/gcc 4.9.2-4 (base-devel)
    The GNU Compiler Collection - C and C++ frontends
local/gcc-libs 4.9.2-4 (base)
    Runtime libraries shipped by GCC
local/lib32-alsa-lib 1.0.29-1
    An alternative implementation of Linux sound support (32 bit)
local/lib32-alsa-plugins 1.0.29-2
    Extra alsa plugins (32-bit)
local/lib32-gcc-libs 4.9.2-4
    Runtime libraries shipped by GCC (32-bit)
local/lib32-libxcb 1.11-1
    X11 client-side library (32-bit)
local/lib32-xcb-util 0.4.0-1
    Utility libraries for XC Binding (32-bit)
local/libxcb 1.11-1
    X11 client-side library
local/xcb-proto 1.11-1
    XML-XCB protocol descriptions
local/xcb-util 0.4.0-1
    Utility libraries for XC Binding
local/xcb-util-cursor 0.1.1-1
    XCB cursor library
local/xcb-util-image 0.4.0-1
    Utility libraries for XC Binding - Port of Xlib's XImage and XShmImage functions
local/xcb-util-keysyms 0.4.0-1
    Utility libraries for XC Binding - Standard X key constants and conversion to/from keycodes
local/xcb-util-renderutil 0.3.9-1
    Utility libraries for XC Binding - Convenience functions for the Render extension
local/xcb-util-wm 0.4.1-1
    Utility libraries for XC Binding - client and window-manager helpers for ICCCM
local/zita-alsa-pcmi 0.2.0-2
    The successor of clalsadrv, provides easy access to ALSA PCM devices.

Edited by Matt Mascarenhas on Reason: Added link to the git repo
You need to include stddef.h header for size_t type. It is not builtin type, it is declared in stddef.h file. I actually asked Casey to do that in one of Q&A, but I guess he missed my question.

Depending on compiler or compiler version this header is included by some other standard header (stdlib/io/...), so that's why everything works for other people without including stddef.h.

As for warning - Casey doesn't use const keyword, so string literals will give you warning every time they are assigned/passed to char* type. Just disable this warning: -Wno-write-strings.

Edited by Mārtiņš Možeiko on
Brilliant! Thank you, mmozeiko. Adding #include <stddef.h> to "src/handmade_platform.h" and -Wno-write-strings to the $WARNFLAGS in "build.sh" got rid of all of those messages. Now there's one more error which I'll try and figure out before this evening's stream:

1
2
3
4
src/xcb_handmade.cpp: In function ‘void hhxcb_process_events(hhxcb_context*, hhxcb_state*, game_input*, game_input*)’:
src/xcb_handmade.cpp:491:80: error: ‘GetController’ was not declared in this scope
     game_controller_input *old_keyboard_controller = GetController(old_input, 0);
                                                                                ^


Although this is a different error from those previous ones, so I probably won't be able to solve it in a similar way.

Edited by Matt Mascarenhas on Reason: Missed a word
GetController function is in handmade_platform.h. So as long as you have #include "handmade_platform.h" somewhere at top of xcb_handmade.cpp file, it should work.

Verify that you have this include, and that you have GetController function in handmade_platform.h.
Hmm, interesting. I do have #include "handmade_platform.h" near the top of "xcb_handmade.cpp" but the GetController function is actually in "handmade.h" back on day 38.

I've just tried upgrading to the present day to see what happens. That GetController error seems to be fixed but now there's another one (and a couple of warnings):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Day 91

$ sh build.sh 
In file included from src/handmade.cpp:14:0:
src/handmade_sim_region.cpp: In function ‘void MoveEntity(game_state*, sim_region*, sim_entity*, real32, move_spec*, v3)’:
src/handmade_sim_region.cpp:519:8: warning: variable ‘NewPlayerP’ set but not used [-Wunused-but-set-variable]
     v3 NewPlayerP = OldPlayerP + PlayerDelta;
        ^
In file included from src/handmade.cpp:11:0:
src/handmade_render_group.cpp: At global scope:
src/handmade_render_group.cpp:154:1: warning: ‘void DrawMatte(loaded_bitmap*, loaded_bitmap*, real32, real32, real32)’ defined but not used [-Wunused-function]
 DrawMatte(loaded_bitmap *Buffer, loaded_bitmap *Bitmap,
 ^
In file included from src/handmade.cpp:14:0:
src/handmade_sim_region.cpp:305:1: warning: ‘bool32 TestWall(real32, real32, real32, real32, real32, real32*, real32, real32)’ defined but not used [-Wunused-function]
 TestWall(real32 WallX, real32 RelX, real32 RelY, real32 PlayerDeltaX, real32 PlayerDeltaY,
 ^
src/xcb_handmade.cpp: In function ‘int main()’:
src/xcb_handmade.cpp:1051:21: error: ‘game_offscreen_buffer’ has no member named ‘BytesPerPixel’
         game_buffer.BytesPerPixel = buffer.bytes_per_pixel;
                     ^


I suppose before I delve into this, would you reckon it's worth me getting straight up to speed with the current code, or should I concentrate on getting day 38 compiling, since that's the day with which the xcb_handmade README says we have parity?

Also, <stddef.h> is included now.
Ah, so stddef.h was added there. I forgot that :)

If you want to follow latest development, you'll need to keep xcb platfrom layer up do date. There is no other easy solution I think. Either that, or patch up game code to work with older platform layer.
Yeah, I thought it'd be a little more work to get the platform layer up to date. So I've rolled back to day 38, reckoning that I'd have a better chance of getting something to work that is expected to work, before getting adventurous with the bleeding-edge stuff .

Back with that "was not declared in this scope" error now. I'll double-check that I've got all the necessary headers. The venerable SO says that a missing header could be the problem for one of these, so it must be true…
In case others run into this - I just didn't update the README.md to point out that day 39 was required (it was after Casey added stddef.h to handmade_platform.h at my request).
nxsy, we can actually compile up to Day 45. The first error occurs on day 46:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ ./build.sh                                                                                              
In file included from src/handmade.h:44:0,
                 from src/handmade.cpp:9:
src/handmade_intrinsics.h: In function ‘uint32 RotateLeft(uint32, int32)’:
src/handmade_intrinsics.h:27:40: error: ‘_rotl’ was not declared in this scope
     uint32 Result = _rotl(Value, Amount);
                                        ^
src/handmade_intrinsics.h: In function ‘uint32 RotateRight(uint32, int32)’:
src/handmade_intrinsics.h:35:40: error: ‘_rotr’ was not declared in this scope
     uint32 Result = _rotr(Value, Amount);
                                        ^


Super delighted to have HMH up and running here! And now that I know my build environment's setup right, I can start playing with the code and maybe figuring out how to bring the platform layer more up to date.

!ytmnd
This was fixed few days later - on day 51.
Oh wow, yeah! You know, we can get right up to Day 81 without any compile errors. We'll have to set a key for spawning the hero, but all seems well. Day 82 says:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Day 82

$ ./build.sh                                                                                              
In file included from src/handmade.cpp:12:0:
src/handmade_sim_region.cpp: In function ‘void MoveEntity(game_state*, sim_region*, sim_entity*, real32, move_spec*, v3)’:
src/handmade_sim_region.cpp:675:48: warning: variable ‘TestP’ set but not used [-Wunused-but-set-variable]
                                             v3 TestP = Entity->P + tMinTest*PlayerDelta;
                                                ^
In file included from src/handmade.cpp:12:0:
src/handmade_sim_region.cpp:519:8: warning: variable ‘NewPlayerP’ set but not used [-Wunused-but-set-variable]
     v3 NewPlayerP = OldPlayerP + PlayerDelta;
        ^
src/handmade_sim_region.cpp: At global scope:
src/handmade_sim_region.cpp:305:1: warning: ‘bool32 TestWall(real32, real32, real32, real32, real32, real32*, real32, real32)’ defined but not used [-Wunused-function]
 TestWall(real32 WallX, real32 RelX, real32 RelY, real32 PlayerDeltaX, real32 PlayerDeltaY,
 ^
src/xcb_handmade.cpp: In function ‘int main()’:
src/xcb_handmade.cpp:1051:21: error: ‘game_offscreen_buffer’ has no member named ‘BytesPerPixel’
         game_buffer.BytesPerPixel = buffer.bytes_per_pixel;
                     ^


I suppose it wouldn't hurt to silence those warnings.

EDIT:

Sorry, I was mistaken about needing to set a key for spawning the guy. It's already done. Casey had just switched around the keys for Start and Back – from Escape and Space to Space and Escape – and I'd been trying to spawn the dude with Space.

Edited by Matt Mascarenhas on Reason: Correcting misinformation
Alright, this deserves a fresh post.

I don't know what happened, but I can now build Day 91 (the day!) and enjoy the trippiness in all its glory.

The only thing I changed was the key assignment in "xcb_handmade.cpp" and the $WARNFLAGS in build.sh to:

1
WARNFLAGS="-Wall -Wno-unused-variable -Wno-write-strings -Wno-unused-but-set-variable -Wno-unused-function"


So it seems that the XCB platform layer is automagically up to date.

Thank you to all concerned.

Edited by Matt Mascarenhas on Reason: I'd forgotten to mention the WARNFLAGS