Logo
Published on

RTS Simulator

Authors

This project is still in development!


Hey everyone! I wanted to take a moment to share a little bit about my latest journey diving back into C++. It's been something I've wanted to revisit for quite some time now. Over the years, I've tinkered with C++ here and there, working with Unreal Engine, SFML, and Raylib, but I've never fully committed to building something meaningful or large-scale. Now, I'm changing that.

The Motivation Behind the Project

C++ is renowned for its speed and power, as well as its notorious complexity when it comes to managing memory and handling pointers. These low-level concepts are things I've always wanted to deeply understand, beyond the surface-level dabbling I've done in the past. However, I also needed a way to keep this learning process fun and practical. At the same time, I'm still hard at work on Aetherbound, but I needed something smaller to break up my workflow when I want or need a change of pace. Enter my new side project: a 2D sandbox battle simulator!

The Vision: Sandbox Battle Simulator

The idea is simple but exciting: players tweak settings for a battle before watching chaos unfold on the screen. Here are some of the settings players will be able to adjust:

  • Number of teams
  • Number of units per team
  • Map resource nodes
  • And more customizable variables!

The units themselves will be job-focused, meaning they'll automatically know what to do when they spawn in based on their role. For example:

  • Resource gatherers will collect resources.
  • Soldiers will fight hostile units.
  • Builders will, well, build! This includes creating structures and possibly expanding the team's capabilities.

Of course, the depth of the building system and the progression mechanics is something I'll need to figure out as I go. Starting small and simple will help ensure I maintain progress without getting caught up in too many moving parts.

Tackling an ECS Architecture

Right now, I'm laying the foundation for the project by building out an Entity-Component-System (ECS). For those unfamiliar with ECS, it's a common pattern in game development where entities (game objects) are composed of reusable components, which are processed by systems. It provides a great way to organize and optimize complex game logic, especially in a sandbox-style game like this where many objects will interact dynamically.

As I’ve been working on the ECS, I came across a fantastic lecture series from Memorial University, taught by David Churchill, which has been an incredible resource. It’s been helping me learn a lot about C++, SFML, and ECS design. If you're interested, you can check out Lecture 1 here and follow along. He also teaches an Artificial Intelligence class, which I might also look into if it's the type of AI we use in games, and not the type like chatGPT :).

The bulk of the ECS is already taking shape, which feels fantastic. It's been a great way to practice designing and implementing systems cleanly in C++.

It's been a refreshing journey down the path of composition. After working in Unity and C# for so long, I’ve grown accustomed to relying on inheritance as a default approach. While I’ve always known about the advice to favor “composition over inheritance” in Unity, using interfaces and breaking classes into components, it feels different when building a system completely from scratch, like the ECS I’m putting together now. It’s becoming increasingly clear just how much better composition can be. For example: "Oh, you want a target dummy? Just remove the AI component." Or: "Want to enable god mode? Simply drop the health component." It’s such an nice way of thinking. Instead of objects being tied into rigid hierarchies (is-a relationships), they’re defined by what they have (has-a relationships). What’s interesting is that Unity already allows you to loosely follow this pattern by stacking your game objects with reusable components. The issue, however, is how those components are designed. Start leaning too much on inheritance within those components, and you can easily paint yourself into a corner, limiting flexibility and possibilities. So far, I haven’t hit any downsides to ECS, though I recognize that it requires more upfront effort. Building all the components you need, wiring them together, and setting up entities does take time. However, I’m confident that the long-term payoff and greater modularity, flexibility, and maintainability is absolutely worth the cost.

Next Steps: A* Pathfinding and Beyond

Once the ECS is polished, the next major milestone is implementing A* pathfinding. Pathfinding is crucial for getting the units to navigate the map effectively, whether it's soldiers finding enemies or resource gatherers heading to a node. A* is a popular algorithm for its balance of performance and accuracy which is perfect for my needs.

Beyond that, one feature I'd really love to get into is a GOAP (Goal-Oriented Action Planning) system. This would allow units to make more complex, context-based decisions rather than relying on hard-coded behaviors. For example, rather than soldiers blindly attacking enemies, they could weigh options like retreating to heal or protecting an important builder.

Rediscovering the Joy of C++

Getting back into C++ has been a really fun experience so far. There's something both exciting and humbling about working with low-level concepts like memory management and pointers. While C++ can be challenging at times, the control it gives you as a programmer is unmatched. It’s a refreshing change of pace compared to higher-level tools.

I will say though, dealing with packages and trying to import/add external libraries is a pain. I still don't fully understand it all. I am using CMake which I thought made sense. I got SFML to be fetched properly, but then I had trouble getting ImGUI in there too, so I opted to use a premade template that has the 2 already set up for me. You can find the template here if you're interested.

Wrapping Up

So, that's where I'm at right now! This sandbox battle simulator is shaping up to be an amazing learning experience, and I can't wait to keep working on it. Of course, I'll still be focusing on Aetherbound, but this side project is giving me fresh energy and perspective. Once I dive deeper into the pathfinding and GOAP systems, I'll be sure to share more updates with you all.

Thanks for following along with my journey, it means a lot. I hope this post inspires some of you to revisit or start learning C++ yourselves. It's tough, but the rewards are so worth it. Until next time, happy coding!

Have an awesome day!