How to Write a Physics System for a 2D Engine: Dynamics, Kinematics, and Motion in ECS

Welp, it’s Sunday again. Some weeks later but I haven’t abandoned my new project (yet). So here we go with another post nobody asked for.

Every game has physics, even if you don’t treat it as a first-class citizen. Mine does.
I’ve spent some weekends building small chunks of systems and started separating my project into core, client, server, and engine layers.
Naturally, one of the first things that popped up on the engine side was a very primitive physics engine. So here we are.

In this post, I’ll walk through how I’m building the physics foundation for my 2D ECS engine in C++ with EnTT. Focusing on dynamics (forces, acceleration, velocity) and kinematics (movement).
Collisions will come later, they deserve a post of their own.

Continue reading “How to Write a Physics System for a 2D Engine: Dynamics, Kinematics, and Motion in ECS”

Building a flexible stock allocation system in pure ECS

In this post, I’ll walk through the design of a flexible stock allocation system built using pure ECS principles in C++ (with ENTT). We’ll go from problem definition to implementation details, discussing elasticity, priorities, and resource management in a simulation-like environment.

From time to time, I start a new project only to abandon it a few weeks later. That’s been my life for the last 20 years, I’ve grown to accept that I rarely finish them.

I started a new one this weekend. It’s going to be different this time (no, it won’t), and I’ve decided that even if I’m not going to finish it (yes, I won’t), my effort will still be worth it if I can at least extract a few posts for my fancy blog. So here we are.

I’ve been obsessed with Shadow Empire and Aurora 4x for years, and I’ve finally decided to build my own (as an MMORTS, just as God intended, because I’ll probably abandon ship eventually anyway, so… why not?).

Here I am, documenting my journey and sharing my work. Enjoy my failure. ❤

Continue reading “Building a flexible stock allocation system in pure ECS”

MMO Architecture: Optimizing Server Performance with Lockless Queues

More on MMO Architecture:
- MMO Architecture: Source of truth, Dataflows, I/O bottlenecks and how to solve them
- MMO Architecture: client connections, sockets, threads and connection-oriented servers
- MMO Architecture: Area-Based Sharding, Shared State, and the Art of Herding Digital Cats

I'm writing this article within the last 2 hours of 2024, so I guess I'm forced to say Merry Christmas ❤ Thank you for your time, I hope you enjoy it and learn something new.


In modern MMO (Massively Multiplayer Online) games, server performance is as crucial as any other part of the game’s architecture. You want your servers to handle thousands of player connections seamlessly, process real-time game logic, and keep latency as low as possible.

A common technique in building such systems (and any other high performance socket-based software tbh, you already know my obsession with MMOs…) is to separate the networking thread from the main game logic thread(s) so the application doesn’t stall on big net transfers. This separation goes a long way to improving performance, maintainability, and scalability, especially in high-concurrency environments.

In this article, we will explore the reasons behind this design decision, discuss race conditions and how they can occur in multi-threaded code, and see why lockless queues are often a great choice for handling messages between threads in.

Finally, we will present a working C++ implementation of a lockless SPMCQueue (Single Producer, Multiple Consumer Queue) and discuss the key concepts behind it. This queue allows a single producing thread to push data into the queue while multiple consumer threads can pop data concurrently.

Continue reading “MMO Architecture: Optimizing Server Performance with Lockless Queues”

How to write a game engine in pure C: Part 3 – The Engine Entity

If you haven’t read the other posts, go now:

This is the third post of the series and it might be the less appealing, but it’ll set the foundations for all the system that we are to build.

Every software piece should have an architecture to keep the code clean and tidy with it’s modules where they belong, and a game engine is no more than a piece of software, so here we are.

Continue reading “How to write a game engine in pure C: Part 3 – The Engine Entity”

How to write a game engine in pure C: Part 2 – The Graphic initialization

If you haven’t read the other posts, go now:

 

We have a state manager now but a game without graphic representation and user interaction has nothing to do in 2019.
In this new chapter we will initialize the ‘human’ layer: graphics and input.

We could write everything from scratch but it’s a pain in the ass (trust me) so we will use SDL to do so. SDL is an abstraction library written in C that gives a common API to system calls for different architectures and OSs.
We don’t want to couple our engine to a library too much, and we will cover that in future posts, but for now we will use SDL tightly coupled, don’t worry, it wont stay like this forever.

Continue reading “How to write a game engine in pure C: Part 2 – The Graphic initialization”

Hiding malware in Windows – The basics of code injection

There are hundreds of teams working professionally trying to break into any single digital device to compromise sensitive data leaving no fingerprint.Malware industry is bigger than you might think, more than 4,000 ransom-ware attacks have occurred every day since the beginning of 2016 and much more general system vulnerations.

I remember viruses in Win95 where you got a freeze screen, a broken OS or a BSOD; that’s not the case anymore, today access violations leave no trace and usually patches the vulnerabilities behind them so no other malware can take control of the system.
A guy i met once told me that “the best AV you could ever have is a harmless virus”, I don’t fully agree, but that sentence hides a bit of truth.

But, how can this malicious code run freely in a host machine without the user noticing?
Continue reading “Hiding malware in Windows – The basics of code injection”

Videogames programming: ECS system in plain C

ECS stands for Entity – Component – System, it’s a paradigm introduced in the industry more than a decade ago but even today it’s still being one of the most used options while designing games.

When building a game your code goes messy really fast, even faster if you haven’t defined everything clearly beforehand, games have interdependencies, connections, interactions and states that makes them really hard and tricky to design, and, when they grow they tend to be a messy hank of code and classes, here’s where ECS comes to the rescue.

Continue reading “Videogames programming: ECS system in plain C”

How to parse key-value strings into associative arrays in ANSI C89

We all know that C is one of the best languages for many reasons and especially the ANSI C89 standard (old and solid as fuck) but it also has it’s own drawbacks. There are many situtations in software development where inbuilt data structures can’t suit the programer’s needs and in a language like C, where there are not as many options to choose from (without relying on glibc or similar) as you can have in python or javascript, sometimes the solution can get really hard to figure out.
Continue reading “How to parse key-value strings into associative arrays in ANSI C89”

Event-driven programming with C 89

As you may know, C is not a dynamic language by default, the behaviour of this marvelous technology tends to be imperative and sequential, we tend to manage the software’s flow by using callbacks or conditional statements and other techniques like  event-driven are not usually used, but, does it means that it’s not possible?

Continue reading “Event-driven programming with C 89”

Design a site like this with WordPress.com
Get started