Live data from Hacker News

Writing a game engine in pure C: The Graphic Initialization

prdeving.wordpress.com

101–110 of 129 posts

Re: Writing a game engine in pure C: The Graphic Initialization

#101
post #2

Reading the title my mind immediately went to mov ax, 13h int 10h I'm old.

A starting point... after which the countless "out_port" incantations begin.

All just to get to unchained mode (aka Mode-X) with hardware scrolling & split screen, 256 kB VRAM, VGA latch fills and VRAM to VRAM latch blitting. It was amazing to be able to set or copy four 256 color pixels by writing just a single byte.

Of course VGA latch blitting didn't make any sense on 486s, but on 8088 it could be almost 4x performance boost — 256 colors with similar CPU load as CGA's 4 colors! At least as long as you needed to blit something to an x-coordinate that's divisible by 4...

Re: Writing a game engine in pure C: The Graphic Initialization

#102
This looks like a lot of complexity up front with no foreseeable payoff.

Why are we implementing a whole dynamically allocated stack for states before doing anything domain specific?

How many states could you possibly be expecting to have in a full game? 3? 12? 100? The examples of states were like the menu, action screen, and pause screen. So it sounds like very few. Drop the realloc'ing and free'ing and just statically allocate N states and be done with it. Save this complexity for something that really needs it.

Plus are you going to free the stack any time other than when you quit the app? I doubt it. The OS will free everything for you when you quit so there's no reason to waste time on that either.

The code so far looks like mostly a waste of time.

Re: Writing a game engine in pure C: The Graphic Initialization

#103
post #2

Reading the title my mind immediately went to mov ax, 13h int 10h I'm old.

I share the same feelings with you and all the people that replied. That's why some days ago I started a set of single-file libraries for opening a window and pushing pixels in the same fashion: by writing directly to memory (to a RGB or Indexed (256 palette) frame buffer).

The goal is to have multiple implementations, in different languages and OSs. For example, right now I wrote (partial or full) support (in C) to:

PNG, windows GDI, linux X11, linux OpenGL, linux Framebuffer and Javascript Canvas

https://github.com/feiss/zero

(I've just started! expect it to be incomplete, broken, faulty and buggy!)

Re: Writing a game engine in pure C: The Graphic Initialization

#104
post #50

As a tutorial series, I think using plain C is a cool approach and will help illuminate what's going on under the hood and what parts of the engine are really essential. But if you yourself want to write your own game with just you or a small team of like-minded people, I would highly encourage using C++. As long as you don't have too many cooks arguing about which C++ features to throw into the pot, you can pick a s…

”...it's mostly a matter of choosing which better C you want.” For a beginner that can make things more difficult: in addition to the actual thing you want to learn, you need to first become a capable curator of language features from the past 35 years. JavaScript today has the same problem: you can’t just start writing a web app because two lines into a tutorial you’ll be barraged with “So this is actually an ES2017…

>JavaScript today has the same problem: you can’t just start writing a web app because two lines into a tutorial you’ll be barraged with “So this is actually an ES2017b.71 feature that we’re enabling using babel-ts-flooginator, therefore you also need TypeScript and that means you need to...”

That's not a problem with javascript, it's a problem with the development culture, its schizoid relationship with the language and its obsessive need to be "cutting edge." You can, absolutely, just start writing a webapp because vanilla JS and even jQuery still work perfectly well. What you can't as easily do is find tutorials that don't assume Javascript has to be compiled from another language and pushed through a complex tech stack before you can even approach it.

Re: Writing a game engine in pure C: The Graphic Initialization

#105
post #77
post #63

Earlier quoted context omitted.

I'm a (primarily) C developer who would love to use C++ this way. I have some C++ experience but not enough to know which elements I should include or exclude. Or even how to begin effectively deciding that. Can you point to any resources I can use to learn?

If you want to know what a reasonable subset of C++ looks like don't hesitate to check out the source code for Doom 3.

Which contains: #define private public #define protected public

Re: Writing a game engine in pure C: The Graphic Initialization

#106
post #100

Earlier quoted context omitted.

Nobody's complaining about the barbaric OS and network stack written in C. The safety nazis' bleating means little if they can't produce a viable alternative. Where are the high performance OSs written in Ada or whatever next big thing is?

What? Operating systems are big projects and the tools to write them safely (and open source) haven't existed for very long, so it's a question of manpower and effort not technology. C has almost no performance benefits these days, either, due to advances in compiler optimization; if anything it can be less as other languages can provide more static guarantees to the compiler to use when optimising. That network stac…

What do you propose? Replacing the system stack with Ada?

Modern successors to C, such as Zig, and modern successors to C++, such as Rust, are still too young to be used for serious re-implementations of the lower layers.

Re: Writing a game engine in pure C: The Graphic Initialization

#107
post #4

Seems like it is going to take a long time to get to a fully functional game if this is the second article and they're only just calling SDL_CreateWindow.

such is life. that is the reality of making games without an engine.

It's pretty simple to get a working window in SDL, though. That part doesn't need to be complicated.

Re: Writing a game engine in pure C: The Graphic Initialization

#108

Interested people may also be interested in Handmade Hero[0]. The game is being developed — from scratch, engine and all — in real-time and streamed by Casey Muratori. It’s cpp technically, but he uses very little and sticks to mostly C if I remember correctly. [0] https://handmadehero.org/

Handmade Hero is not at all a demonstration of how one would actually approach making a game in C/C++, though. In real life, you would use existing libraries instead of reimplementing everything from scratch.

Re: Writing a game engine in pure C: The Graphic Initialization

#109
post #53

Interested people may also be interested in Handmade Hero[0]. The game is being developed — from scratch, engine and all — in real-time and streamed by Casey Muratori. It’s cpp technically, but he uses very little and sticks to mostly C if I remember correctly. [0] https://handmadehero.org/

https://twitter.com/epyoncf/status/1123155254760038400

I'm well past my fifth iteration... does it count as an iteration if you never actually finish a version before starting it over?

Re: Writing a game engine in pure C: The Graphic Initialization

#110
Right now I'm heavy into C++, especially C++17, but mostly due to the current project I'm working on (tools engineer @ gamedev)

20 years ago, my first project was being part of 4 people team porting Metal Gear Solid from PS1 (PSX) to PC. This is when I saw how good written "C" code could be done. Even if it had only japanese comments in the code (understandable).

The pure and simple structure, where most of the functions had TCL-like interface:

int ACT_Work( int argc, sometype* argv ) { // bit of argc/argv parsing Do_Work() }

then above was exposed to a TCL-like scripting language, used for setting up level objects... We are talking about 500-600kb of memory used by the main executable + 300-400kb of 'overlay' memory where "shared, e.g. dll/so-like" code gets replaced depending on what objects needs to be in the game (Mentioned "overlay" as this was very well established practice back in the DOS days).

Things really were plain and simple. API-s too. It was so easy to grasp what's going on.

Then again, since this was running on what looks like really limited machine, it had to do only such and such. No fancy animation controllers, advanced physics, collision, etc. etc.

at some point, especially if it's a content creation tool (think Maya, or any Autodesk product, Houdini, etc.) then you need to be able to handle tons of "nodes", "entities", meta-data, etc. - but when it comes to a game, even nowadays - pre-cooking gets you there, and quick deserializing - either piecewise, or whole sections, and then pointer fixup.

Point is, is your game, and engine meant to be content creation tool too?

Post reply on HN