My game makes use of an Entity-Component-System (ECS) It’s a much better method of organizing data and functions than Object Oriented Programming (OOP) for videogames. For this purpose, I made use of free software libraries: entt at first for C++, then flecs for C99. My first impression of ECS as very complex in general was tainted by these libraries. Part of it is because I did not write the code myself, but still I found ECS libraries to be hard to understand by reading the actual source code. It does not help that these libraries are HUGE: flecs.h combined with flecs.c, and the single include header file entt.hpp all have more than 40000 lines!
Adding to that, they started to get on my nerves. For example, entt is C++ only. Flecs has some features that are useless for my project, some terms in the docs are never defined, it’s not compileable with tcc, it crashes for optimization level above zero, I could not compile newer versions… Also, looking at the flecs benchmarks in detail made me realize that it isn’t as fast as it appeared to me as first. To prove the final point once and for all, and because I admire people who build their own tools, I started to build my own C99 ECS library. At first I had named it simplecs but that name is much too common. It’s name is tnecs, for tiny nECS because it sounds funny. Tnecs v1.0 is available now on Github and Gitlab
Anyhow, after an arduous month and slightly more of work, tnecs v1.0 is done with all tests passing and 100% code coverage. More tests are coming, but I think it is fully functional. According to all my homemade speed benchmarks, tnecs is faster than flecs in all respects except for system iteration, where both libraries are equally fast. I haven’t repeated the benchmarks up to 1000s time yet, but still…
The most important advantage of building your own tools is that you can make it however you want it to be. For me, tnecs is simple, small and performant, with a limited set of features and a very simple API (as reflected by the short tutorial). It’s less than 2000 lines of code, for now I don’t need more. If tnecs ever is lacking in any way I can modify it, but I think it has all the features I need and I will work around its limitations.
I had to do some design work which forced me to understand more about ECS than before. Making your own tools is worth it on a personal, growth and learning level… Never let anyone tell you that you can’t possibly make a program faster than someone else… Other programmers are only human for one. Sometimes, they also make deliberate design decisions that decrease performance, for good or bad reasons. Anyhow, just as more better programmers encouraged me to build my own tools, I encourage you to do it too. If you ever build an ECS with better performance than mine, I might just use it in Codename: Firesaga…