I have to switch DragonRuby Game Toolkit over from Oculus's VrApi to OpenXR. This is a good change, as it is going to get us off deprecated libraries and closer to supporting more than just the Oculus Quest.
But I'm looking into how to use OpenXR, and good lord, that shit is daunting.
I mean, look at the Hello World example for crying out loud!
I haven't opened any of these files, they might be three lines of code each, but already my first take is "this is WAY too complex." It's a textbook "you ever see sample code so heavy you had to take a nap?" moment.
Don't write samples like this!
Write samples like this instead!
void start_this_shit_up(void) {
// here's all the stuff you have to do BEFORE ANYTHING ELSE.
// there are 12 parameters, we will walk through them.
// come in here prepared with a HWND/argc+argv/good vibes
MyLib_Init(¶ms);
// this can fail, but we SKIPPED ERROR HANDLING so you
// can see how this API works. Because that's the important part.
}
void use_this_shit(void) {
// there a million Doohickeys in the world from different vendors,
// and eventually you will need to handle their special attributes in
// an abstract way, but for now, this will make the Doohickey you
// probably have on your desk go brrrr
MyLib_DoAThing(1, false, "whatever.xml");
// (xml is terrible. So is json. Don't force them on C programmers.)
}
void shut_this_shit_down(void) {
// If your API can fail during deinit, you fucked up. But it's too
// late now. Make a note of it, DON'T HANDLE IT IN THE
// SAMPLE CODE, and be done.
MyLib_Deinit();
}
int main(int argc, char **argv) {
start_this_shit_up();
use_this_shit();
shut_this_shit_down();
return 0; // I literally do not care.
}
Notice how the functions are listed in this example in the order you will use them. Like, you know, how a brain thinks about a task.
Oh wait, you have platform-specific stuff that needs to be handled? Okay! DO NOT PUT IT IN A SEPARATE FILE.
void start_this_shit_up(void) {
#ifdef __WINDOWS__
MyLib_WindowsMagic(myHwnd);
#elif defined(__LINUX__)
MyLib_LinuxMagic(whatever);
#else
#error Uhoh, check back as we add new platforms!
#endif
MyLib_Init(¶ms);
}
Did this need helloworld_windows.c and helloworld_linux.c? No it did not.
Do you find yourself making subfolders? STOP IT.
Do you find yourself building a GUI for your sample app? DELETE IT.
This just helps obfuscate the thing you actually want people to know about, the API. If I have to dig through some GUI toolkit code to find where you actually use the API, it's just adding complexity, which adds confusion, which adds uncertainty, which all adds up to WASTED TIME.
It is okay to have different ways to build the sample code, in case people want to run it, or experiment with it, or you just want to make sure it actually compiles, but please hide that stuff somewhere so I don't have to care about the marathon that Gradle made you run or whatever. Ideally, you should be able to just drop your ONE .c FILE into anything that looks like a compiler and it'll (mostly) work. Maybe leave a comment at the top about libraries it might need to link to. But if half of what I see when I hit your github is a million project files, I'm already getting distracted from the actual goal.
Which is to understand how to use the API.








