Live data from Hacker News

Why I Write Games in C

jonathanwhiting.com

251–260 of 303 posts

Re: Why I Write Games in C

#251
post #71

Earlier quoted context omitted.

My solution is to write Jinja templates of C source files: https://github.com/mcinglis/libarray Libarray (and my other C libraries; Libvec etc) have served me very well on a 20k LOC project. With ~150 source files, the entire project builds from fresh in 20 seconds on a i7-2620M. Rebuilds are super-fast; with proper Makefile specification, there's no need to rerender/recompile the templated files.

AGPL? Never. Ever.

My reasons are made clear in the README. I don't want to contribute to nonfree software. It's pretty simple.

Businesses who want to use my work in nonfree software are welcome to get in touch to negotiate such a license.

IMHO, for anyone who has seriously considered the morality and ethics of software licensing options, the AGPL is the obvious choice. I'm surprised it isn't more popular. It was a shame large donors strongarmed the FSF into splitting it from the GPL, and that the FSF kept pushing the GPL as it's go-to license.

Re: Why I Write Games in C

#252

Earlier quoted context omitted.

I'm not sure sure about a roaring trade. Games consoles are niche platforms. Look at the numbers: http://www.vgchartz.com/ The global life to date figures are 12.4 million Wii Us sold since November, 2012. 19.2 million Xbox Ones and 35.3 million PS4 sold since November, 2013. Contrast that with PC shipments, where 70 million in one quarter is considered a bad result: http://betanews.com/2015/10/09/pc-shipments-declin…

People do not buy PCs, iOS devices and Android phones just to play games. In fact, many people do not play games on these devices at all. E.g. Steam is probably going to be found on any PC that is used for games yet there are just 125M accounts since September 2003[1]. And even if somebody plays a game on a cellphone - they usually do not pay for it [2]. 1. https://en.wikipedia.org/wiki/Steam_(software) 2. http://rec…

From the Wikipedia page that's 125 million currently active users. They define an active account as one which has been used in the last 90 days. 125 million active users is about double the combined lifetime sales of the Wii U, XBox One and the PS4, which demonstrates my point.

It doesn't matter if an individual does or doesn't pay for a game on their phone. What matters is revenue. Worldwide iOS and Android games revenue has outgrown consoles: http://fortune.com/2015/01/15/mobile-console-game-revenues-2...

Re: Why I Write Games in C

#253
post #131

Earlier quoted context omitted.

> Well, to be fair, games are one place where code reuse and maintenance by third parties is less likely to be needed. i feel like this is somehow perpetuated like folklore, but there shouldn't be any reason why game code should be inherently less reusable than other areas of software development. For example, code that deal with geometry data shouldn't really be any different for games, or code that deal with settin…

> code that deal with geometry data shouldn't really be any different for games Counter-example: http://jonathanwhiting.com/games/knossu/ (Highly recommended if you have 20 minutes to spare.) The geometry of this game is unlike any I have seen so far. There is common logic with that of a Doom-like ray caster, but I'd argue not much. The time spent rewriting the generic parts of a ray caster probably pales in comparis…

Great game, thank you!

Re: Why I Write Games in C

#254

Earlier quoted context omitted.

Most C++ projects I have worked with, regardless of their size, had re-compilation times that routinely exceeded 20, sometimes 30 seconds. There are various reasons for this, among which uncontrolled use of templates and nested header inclusions where a forward declaration would have sufficed. C, with its simpler grammar and the absence of template, tend to re-compile under 5seconds even for sizeable projects.

So, roughly speaking, you can expect for a difference in the order of tens of seconds. But my question was, how relevant is this? At least in my experience, and I have worked with projects that took up to 50 minutes to fully recompile (before we moved to newer ms compiler) when taking all dlls, the full recompilation is rarely required. Sometimes you have to recompile project, which can take minute or so, but most of…

As for understandability, I used to work with a lot of EE people building various equipment that required both hardware/software. Everybody was smart, but not necessarily an expert in programming. We also used various programming languages. The rule was keep all code at an "8th grade level" and write everything like C. Everybody regardless of language background can read C. C has become the universal pseudo-code.

Nobody agrees on what "properly written C++" is. A colleague with a C++98 background told me C++11 looks like a completely foreign language to him.

Re: Why I Write Games in C

#255

I see one of the core reasons C is chosen over C++ is the speed of compilation. My question would be, to what extent is compilation speed relevant? What time differences are we talking about? I agree that every second counts, and I understand that fast compilation just feels good to work with for a hobby project, but what serious relevancy it has? At least the way I do it is divide program (a game for example) into s…

C++ compile times are a huge problem for large projects (and painful even on medium projects). The Go designers joke that Go was conceived while waiting for a C++ compile. (Google engineers I know tell me their full C++ compile times can be measured in hours.) AAA game devs I've met tell me their C++ project times are usually 30 min to an hour.

On even the medium size projects I work on, the compile time difference between C and C++ can be magnitudes.

C++ encourages templates, which are typically included by everything, which in turn causes lots of files to need to be recompiled.

Both C/C++ have fragile ABIs so if you have built libraries and you change their memory layout, you need to recompile world. And in some cases, even if your library is internal and not external to your project, a bad build system or a bug can fail to detect this kind of change leading to subtle bugs/crashes, which then in turn encourages developers to do full rebuilds periodically.

It is hard to find real world data converting C++ to C to measure compile times because nobody wants to invest in rewrites like this. However, I am also among those people that have shifted back to pure C from C++ and seen compile times improve by magnitudes. I sometimes work on slow devices, like the Raspberry Pi, and this really magnifies the difference. (On this, the C parts can take 10-20 minutes, and the C++ parts are measured in many hours.)

This one person recently wrote about he switched back to C from C++. He mentions his build times went from about 10 minutes to 4 seconds.

http://chrismdp.com/2015/04/how-i-doubled-the-speed-of-my-ga...

Re: Why I Write Games in C

#256

Earlier quoted context omitted.

People do not buy PCs, iOS devices and Android phones just to play games. In fact, many people do not play games on these devices at all. E.g. Steam is probably going to be found on any PC that is used for games yet there are just 125M accounts since September 2003[1]. And even if somebody plays a game on a cellphone - they usually do not pay for it [2]. 1. https://en.wikipedia.org/wiki/Steam_(software) 2. http://rec…

From the Wikipedia page that's 125 million currently active users. They define an active account as one which has been used in the last 90 days. 125 million active users is about double the combined lifetime sales of the Wii U, XBox One and the PS4, which demonstrates my point. It doesn't matter if an individual does or doesn't pay for a game on their phone. What matters is revenue. Worldwide iOS and Android games re…

I don't think you quite understand what is written on wiki page. There is no "currently" active users, there are just 125M active users according to Valve's definition of owning a product OR being logged in the last 90 days [1]. So the actual number of gaming PCs is less (I, for example, have two active accounts since I play PC games so rarely that I've lost credentials for the account I've created for Half-Life 2 and had to create a new one when somebody has given me a free game, not to mention incentives to have multiple accounts to collect badges and stuff) and is quite comparable to the numbers of a single platform in the previous gen consoles, which is so far is surpassed by the current when you compare sales relative to the launch.

>It doesn't matter if an individual does or doesn't pay for a game on their phone. What matters is revenue. Worldwide iOS and Android games revenue has outgrown consoles: http://fortune.com/2015/01/15/mobile-console-game-revenues-2....

Do you have any better source than a mobile analytics firm speculation? I for one have no clue where to get console game sales and where that firm got them is a mystery.

1. https://en.wikipedia.org/wiki/Steam_(software)#cite_note-12

Re: Why I Write Games in C

#257

> The library support [in Go] for games is quite poor, I'd like to know the author's familiarity of Go libraries. Perhaps he's unaware of what does exist and makes false claims, or perhaps he's saying accurate statements and just has really high standards. I help maintain many of the Go libraries/wrappers for games, so I might be biased, but I'm happy with what is available. Almost more so than when I was using C++,…

I'd like to pick your brain in real-time, but, in a nutshell, how far do you think Go game ecosystem is from something like Corona, LibGDX, Haxe? Have SDL, OpenGL wrappers stabilized, are there native ports? Any frameworks that might be considered close to production-ready?

OpenGL libraries have definitely stabilized and have been that way for multiple years now. GLFW 3 wrapper is go-gettable (some years ago, it required manual installation of the C library separately, now you just go get it). I don't use SDL so I don't know much about it.

I don't know if there are complete frameworks or engines that are finished, but there are some works in process.

https://github.com/avelino/awesome-go#opengl

https://github.com/avelino/awesome-go#game-development

Re: Why I Write Games in C

#258

Earlier quoted context omitted.

> I like the simplicity of C too. You can have a good mental model right down the CPU of what is going on. Not really, with compilers as sophisticated as they are and the spec as liberal with undefined behavior as it is. The C virtual machine that the spec defines is every bit as complex as any other virtual machine. > But these days given how fast CPUs are and how much more productive you can be in a high level lang…

>>Not really, with compilers as sophisticated as they are and the spec as liberal with undefined behavior as it is. The C virtual machine that the spec defines is every bit as complex as any other virtual machine. Having some undefined behavior in your code is just a bug, it has nothing to do with being complicated or compiling to machine code. It's not nearly as complex, in fact there are many people who understand…

> Having some undefined behavior in your code is just a bug, it has nothing to do with being complicated or compiling to machine code.

In theory, yes. In practice, all C/C++ programs have undefined behavior in them, so you have to understand what compilers do to really understand your code.

> It's not nearly as complex, in fact there are many people who understand quite well what the code compiles to.

Not true in my experience. The only people who really understand it are, by and large, compiler developers. There are very few compiler developers.

> Try guessing what Java compiles to.

I know what Java compiles to more or less as well as I know what C++ compiles to. The only real difference is in GC (which is quite simple--inline a nursery bump and fall back to a malloc-like slow path if it fails) and ICs, which are a lot less complicated than things like alias-analysis-sensitive load forwarding.

Re: Why I Write Games in C

#259

> The library support [in Go] for games is quite poor, I'd like to know the author's familiarity of Go libraries. Perhaps he's unaware of what does exist and makes false claims, or perhaps he's saying accurate statements and just has really high standards. I help maintain many of the Go libraries/wrappers for games, so I might be biased, but I'm happy with what is available. Almost more so than when I was using C++,…

Can you point to some blog posts on this subject? I would love to see what's out there.

Libraries and wrappers here:

https://github.com/avelino/awesome-go#opengl

https://github.com/avelino/awesome-go#game-development

I'd also suggest looking over https://www.reddit.com/r/gogamedev.

Re: Why I Write Games in C

#260

Earlier quoted context omitted.

>Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. Wow, that sounds pretty nice. I wish I had a window to look out of.

Or you know, just look away from the monitor, in the physical space of your office/whatever instead of a flat surface, which would have similar benefits.

That doesn't help much when you're in a room where the farthest wall is maybe 15 feet away.
Post reply on HN