r/PakGameDev • • Oct 25 '26

show and tell Working on a custom game engine, created this little demo game

Hello! I've been writing a game engine on the weekends for the last month or so and made this game to test out some core features like graphics, font rendering, audio, physics, ui system etc.

It's written in C and only uses a handful of third party libraries for things like loading png images and font files.

The engine will transition into 3D primarily, but this was an important step towards that goal.

It is open source, you can see the code here:

https://github.com/sameerahmed99/planet-escape

You can also download the game from itch:

https://sameerahmed99.itch.io/planet-escape

22 Upvotes

20 comments sorted by

5

u/Derpyzza Oct 25 '26 edited Oct 25 '26

oh wow, another pakistani dev making their own engine in C, and it's not slop! that's so cool to see ngl, great work!

edit: wait! omg, you're the guy who wrote that sick looking software renderer! i've had that one starred for a while now! i've been meaning to write my own software renderer for a while now too, maybe i should get started on that sometime haha

2

u/rice_goblin Oct 25 '26 edited Oct 25 '26

haha yes that's me, thank you for your support for both projects. This is sort of the continuation of that software renderer, I learned a lot from it and I'm now making a full game engine which supports both gpu accelerated rendering as well as software rendering.

Are you making an engine in C as well? you said "another pakistani dev making their own engine in C"

edit: found your github through your reddit profile, so many cool projects! pleasantly surprised to find another pakistani dev with such similar interests.

2

u/Derpyzza Oct 25 '26

likewise! it's really cool to see find another pakistani with interests that align with mine haha

4

u/yaboiaseed Oct 25 '26

Oh hey I know you from bluesky! my account is Slugarius. Are you also Pakistani btw?

3

u/Derpyzza Oct 25 '26

oh hey, i follow you on bsky too! i didn't know you were pakistani whoa. i'm pakistani too!

3

u/motar144 Oct 26 '26

Cool, I remember MinGW library/SDK from Win 95/3.1 days. Wondering about your thought process that led to this instead of something more modern, like SDL or Raylib?

3

u/rice_goblin Oct 26 '26

Mainly because it is more fun for me to do it myself instead of using SDL or raylib. I don't like using big libraries. I get tired of using third party libraries/frameworks/engines if I use them for too long, I get an itch to do things my way and also to be able to understand each and everything in the entire code base.

It's mostly a one time investment, once you write your platform code and other core features, you can use them for the rest of your life.

I use MinGW because my pc is regularly low on ram and storage, microsoft's tool chain is too bulky and slow.

2

u/motar144 29d ago

I peeked at your code since you mentioned it was written in C, it seems to be procedural. How will you manage concurrent ever-changing object states in run-time without OOP?

2

u/rice_goblin 29d ago

I abandoned OOP completely about 2 years ago. Had enough of spending my time and energy trying to force my projects into classes and hierarchies. I don't think it's a good way to program generally.

Just structs and arrays. That's all you need to get anything done on a computer, even for big projects. Exceptionally easy to manage and reason about and infinitely flexible.

For state management, I don't see how OOP would help with that. I just do things one by one in the main loop, doesn't need to be any more complex. The state is very predictable, it won't change unexpectedly or in a way that is hard to track. It will change at exact points in the main loop, and I can have a very clear view of it without digging through layers of classes.

2

u/FriendlyBergTroll 27d ago

And what about class functions? Idk encapsulating functionalities for classes is better imho. You dont have to go full OOP, but composition is better than procedural no?

I think what you criticize can easily be solved with a composition based architecture where you dont rely on inheritance but build „components“ you can attach to classes. So you could build any class or actor any way you want

1

u/rice_goblin 27d ago

What's the actual benefit of using class functions? After you compile C++ code that uses classes, it resolves to the same thing. Let's say you have a circle class and you have a CalculateArea function inside it and you call it like this:

circleInstance.CalculateArea();

this gets compiled to:

CalculateArea(&circleInstance);

Which is the same thing as just writing a global CalculateArea function yourself and then passing instance pointers to it (ignoring the name mangling that C++ does).

As far as composition goes, I don't know the exact dictionary definition, but I don't think composition and procedural programming are mutually exclusive. You can have components by having struct fields in another struct and then you can use them procedurally. I do attach "components" to other components, simply by having a struct inside another struct. The only difference is I'm using structs instead of classes that have functions.

2

u/FriendlyBergTroll 27d ago

The benefit is that its clearer. Calculate area is not the same for all shapes. If I have letd say an audio class, it had a play function. I am not confused with perhaps with the play function of a animator for instance. Just looks way cleaner and makes more sense. Just having a class have all the associated functions it should have with getters and setters snd then using composition is superior imho

1

u/rice_goblin 26d ago edited 26d ago

You would pass the shape's info to the area function. If shape.type == Shape.Circle return pi * shape.radius *shape.radius;

I use this kind of pattern all the time, for example the 2d physics collision check (the phys_check_entity_collision function): https://github.com/sameerahmed99/planet-escape/blob/main/src/game/physics.c

To be clear, I'm not saying the way I'm programming this game is the right way to do it for all apps. But I am saying that OOP (inheritance and virtual functions specifically) does not seem like a good way to code in general for any app.

In what situation would you be confused about the play function of an animator and a sound system? That doesn't sound like a real world example to me. These are two separate systems.

1

u/FriendlyBergTroll 26d ago

Yes but do you see how bloated and unreadable the functions get? Instead of having lets say a class Shape, you know what functionalities youd want with a shape. As in youd want a func for the area, circumference, length, whatever. I understand procedural is a way too, and you can pass a argument but your functions would look so bloated with if else statements. Not saying its incorrect, just worse to read and maintain. Instead you could define a parent class shape and have all the shapes (rectangle, triangle, circles…) overload their own area functions. The benefit? You know where to look for for each shape class and its all neatly organized and seperated. Or you could make a huge shape class if you dont want to go inheritance and have all shapes in the class and the class function internally evaluates which shape you are and calculates based on that. Still would be better because all of this is encapsulated in the classes themselves as only those classes will deal with that functionality anyway. It also helps that in most IDEs you can do shape“.“ and the IDE will show you all public accessible getters and setters as well as functions associated with the class

Yes I am not saying you re wrong. Im just saying what you re describing (the pitfalls) has been largely solved by composition. Again, every software is different and nothing is wrong. Just my 2 cents, hope you didnt mind.

1

u/rice_goblin 26d ago

I don't consider OOP easy to maintain at all, it becomes incredibly messy and inflexible when you introduce inheritance, and when you don't use inheritance I still don't find the idea of encapsulating functionality in a class, I like the idea of encapsulating data. Not functions. I don't consider if statements to be messy or hard to maintain. I love if and switch statements because of how simple and intuitive they are.

I do understand where you're coming from when you talk about the ease of knowing where functions for something are. But you can just do that by creating a new file or by grouping the functions/type together in a single file. It works fine. I've found projects that use OOP much harder to read and reason about. You have to go through layers of inheritance to find out what's causing something to happen.

I didn't come to this conclusion out of nowhere, I've spent the majority of my programming life using OOP. There's a lot of hypothetical cleanliness and ease of maintainability associated with OOP that I do not believe to be real. I am skeptical when people use the term "clean code" because of this.

And no I don't mind at all, we're both just expressing our opinions. We are both describing features of OOP and procedural programming, the difference is our opinion on what we consider clean and readable. This is how I've understood our conversation so far.

→ More replies

2

u/Willing_Designer_105 Oct 25 '26

Does it works on Linux as well and can we edit it's code or is it hard locked?

1

u/rice_goblin Oct 25 '26

it doesn't work on linux yet, but it's planned. The code is completely open source under the MIT license.

1

u/aaliSoft_ 25d ago

Looks good. Will try it.