KSandbox

A sandbox game simulation for iOS.

2021-01-13

I love simulations, and I love pixels. So I double love the classic pixel simulation "games" that lets you play with different elements and simply watch stuff happen.

KSandbox is a project that I never quite finished (yet as at 20-09-2023, maybe in the future?) and it comes in different iterations.

First Iteration

The first iteration I made was quite rough on the performance because it's very easy to miss-design the basic structure of it and then hit huge bottlenecks when you try to have plenty of particles doing stuff on screen at the same time. I was naively trying to use a single bitmap to draw on the screen, and all the particle updates were drawn by updating pixels on this bitmap, and then drawn all together on the screen in a single draw call. The drawing was uber efficient, but unfortunately all the updates on the bitmap was slowing it down too much.

Second Iteration

In the second iteration, quite some months after the abandoning of the first iteration, I rewrote the entire codebase from scratch structuring it much better with proper inheritance, but kept the bitmap drawing technique. This was better, but not optimal by any means and I quickly re-abandoned this iteration too.

Third Iteration

Lastly, the third iteration forced me to actually learn Metal APIs properly, it was quite easy to understand after the experience with OpenGL with Spacetorio project. So, knowing what I was doing, I rewrote everything again, but now structuring the code to work with instanced rendering, and it was a huge jump in performance this time. One other cool thing is that I wrote all the main simulator login in C++ directly instead of Swift. I decided to take this path because I'd like to have it in a standard language to make it easy to port to other platform eventually in the future.

This feels a really solid base to recreate all the cool interactions on it, but as for now, I (maybe temporarily) moved on to other things.