Live data from Hacker News

Why I Write Games in C

jonathanwhiting.com

121–130 of 303 posts

Re: Why I Write Games in C

#121
post #69

Earlier quoted context omitted.

A technique commonly used in C, for example in the Linux kernel. You embed "links" to other nodes in your structs, and find the struct from the link based on offsetof. Linux kernel uses linked lists and red-black trees this way. Probably other data structures too. Intrusive containers are cache friendly and typically require no dynamic allocations (in addition to allocating the data itself). See the link in the post…

Interesting. At first I thought you were claiming this technique made linked lists cache friendly. After looking at it, I have concluded you meant merely that the next and prev pointers are near your data. Am I understanding you correctly?

That's my understanding too. Instead of going to your data structure, and then dereferencing a pointer to your data, after going to your data structure, you're already there.

Re: Why I Write Games in C

#122
post #100
post #87

Earlier quoted context omitted.

"real-time memory browser-editor for your whole engine." Can you describe very briefly how you have the server set up? I've wanted to add this to my c hobby projects for a long time and would enjoy any tidbits of the practicalities involved.

Sure, although I don't have a separate server. Explanation here: http://pastebin.com/Nm6Qta4u

Very interesting approach, and pretty straight-forward as you said. Thanks for sharing that.

Have you considered letting the compiler produce DWARF-formatted debug information and using an existing DWARF library to handle the symbol to address mapping? I've had good success with this method for controlling embedded systems from a desktop PC, though not when the host and target are the same computer.

Re: Why I Write Games in C

#124

I understand the want for simplicity in C (and Go gets closer, but has its issues), however, it seems in the end it drags you down. Just having the C++ ability to have objects doing things is very helpful. But yeah, C++ has the ability to get very complicated But it's your choice to have "complicated C++". Limit yourself to some functionalities and it's much more manageable. Use basic STL and keep it simple (also C++…

>The ability to have objects doing things

C-structs work fine. In my experience, for things like games, C-structs are capable of doing everything you need objects to do. The lack of polymorphism and other OO stuff, makes C code easier to reason about and maintain.

Re: Why I Write Games in C

#125

Since game development often requires interfacing with robust C++ libraries in graphics or physics (i.e. Bullet), I'm curious how you do that... are you either not using physics or writing your own basics physics engine? Or, are you writing parts of your app in c++ just to wrap the interface in a way you can do the rest of the work in C?

Its trivial to expose a C interface from C++ and I would guess most game libraries have an api

Re: Why I Write Games in C

#126

Since game development often requires interfacing with robust C++ libraries in graphics or physics (i.e. Bullet), I'm curious how you do that... are you either not using physics or writing your own basics physics engine? Or, are you writing parts of your app in c++ just to wrap the interface in a way you can do the rest of the work in C?

Its trivial to expose a C interface from C++ and I would guess most game libraries have an api

It's not as trivial as you would think. I'm reading through the long discussions from the Bullet developers, and clearly it's not just a short project.

Re: Why I Write Games in C

#127
post #120
post #105

>Even more than that I care about the speed of the compiler. I am not a zen master of focus, and waiting 10+ seconds is wasteful, yes, but more importantly it breaks my flow. I flick over to Twitter and suddenly 5+ minutes are gone. Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. This gives your eyes much needed break from focusing on a computer moni…

A "focus" application (there are many for macs/pcs) that block certain websites, applications is also helpful. You can set it for an hour at a time, or whatever. It breaks that knee-jerk habit of wasting minutes on twitter/news/etc.

Still better to not look at a computer at all frequently, and focus on something in the distance.

Re: Why I Write Games in C

#128
post #105

>Even more than that I care about the speed of the compiler. I am not a zen master of focus, and waiting 10+ seconds is wasteful, yes, but more importantly it breaks my flow. I flick over to Twitter and suddenly 5+ minutes are gone. Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. This gives your eyes much needed break from focusing on a computer moni…

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

Re: Why I Write Games in C

#129
post #96

You don't really get rid of complexity by using a simple language. You just move the complexity into your own code. Say if your language doesn't have dynamically sized containers, you will end up writing your own. You hack it so you can store different types in it. You have reinvented polymorphism. And then you need sort functions, and everything else that is missing from the language. And it wont be simple any more.…

That's partly true. However, you do get rid of the complexity you never wanted in the first place. For me this is

OOP, RAII, C++ allocators, exceptions, references, vtables (see my post about runtime recompiling), templates (mostly), C++ standard library (I'd have to write my own vector for fast compilation. I'd have to write my own hash map to get contiguous storage (IIRC))

C is by no means optimal, but it's still one of the least bad languages to write games with.

Re: Why I Write Games in C

#130

Are GC pauses really significant? I can understand there being problems if you have to churn through gigabytes of world data, but the author's games don't appear to be on that scale.

Their unpredictablity is a bigger concern than their duration when it comes to games.
Post reply on HN