1. Kingdoms
  2. News
  3. UPDATE 0.671 [PERFORMANCE AND MULTITHREADING]

UPDATE 0.671 [PERFORMANCE AND MULTITHREADING]

FOREWORD MULTITHREADING

    This one took good half of the total amount of work. At first I wanted to experiment and understand on practice where multithreading is able to give real performance boosts. After numerous tests the result was: pathfinding and spawning can use multithreading at 100% speed, AI though can use it in some heavy code parts like complicate formula calculations. Of course the result depends on cores you have - 8-cores CPU will give much better result than 2-cores CPU.
SCRIPTS

    The next global goal was to clean up all possible game scripts and change their logic in such way so they could use less CPU resources and give the same results. Update() functions were mainly removed and replaces with IENumerators() - this gave significant boosts to settlers, houses and animals scripts. Memory leaking code parts (i.e. with many GetComponent<> calls) were removed, cleaned and rewritten. Scripts are now working asynchronically to remove all performance spikes from the game.
    Some systems, that worked individually for each object and took significant amount of performance - like AI finding place for house - are now calculated in separate threads.
BACKGROUND CALCULATIONS

    The main key point of Kingdoms is breathing and living world. When playing it you can be sure, that even at very large distance settlers do exact the same thing they do near you - building, trading, crafting, selling, growing stuff at farms etc. For me it was and is to not cheat the player and calculate something in a tricky way, like spawn goods at shops or add settlers to the settlement - even at the distance world should have the same logic as at the very close distance. Most players won't even notice that, but for me it was important to make the world live in any point of the island even of player doesn't see it. And to tell you the truth all these calculation took quite significant part of script calculations. So I revisited all of them to understand where I can improve performance without loosing mechanics working. It was long and quite monotone process but the result is in the game, which is totally fine by me.
LOADING SPEED

    Now game uses different compression method and this method increases overall loading time about 80-100%. Another issue was long saves loading, in particular - long roads calculation. This was because game also calculated walls all over the map at start of roads calculation. This was also improved - walls now can spawn much faster and as result it increases save loading about 200%. But roads spawn is not the single spawn system that was changed.
STATIC SPAWN AND MEMORY LEAKS FIXES

    Another serious issue that needed to be fixed is periodically memory leaks. In most cases it was inefficient spawn of static objects. That's why the whole spawn system for static (i.e houses, scaffolds etc.) was rewritten from scratch to remove memory leaks. Vegetation was changed as well. First of, now it uses multithreading, plus many connected systems were changed as well in order to increase performance - masks on structures (that remove grass and other objects), masks on roads, all vegetation textures were compressed, distances were tweaked, LODs were optimized, colliders were optimized as well.
AI BODY SPAWN OPTIMIZATION

    Previous AI bodies also affected performance in a negative way, causing fps drops there and there sometimes so the goal here was to make it work as fast as possible. Was was changes - body texture and mesh combiner scripts are now multithreaded, meshes were optimized (as a bonus all body customization options are more visible now), textures were compressed.
PATHFINDING OPTIMIZATION

    The main thing here is multithreading support. Also some additional features were added to scripts in order to increase performance, i.e. occlusion culling.
SIEGES PERFORMANCE FIXES

    As many of you could notice sieges in game affected performance in a very negative way sometimes, so this update will fix it. Many scripts were rewritten here as well, plus optimization of light sources and particles now give significant performance boost.
WHAT'S NEXT?

    So, the huge optimization work is over and we're back to usual schedule - three update per week, the next one (0.672) is coming Wednesday. Plus update contains a LOT of bugfixes, I decided not to add them to this announce, they will be added to Wednesday patch note.
    Thanks to all the players for support and patience, I really hope that you'll like the result!
FULL LIST OF UPDATES

IMPORTANT
1) Please, feel free to use built-in bug reporter (F11) - it will help development a lot.
2) If something is broken make sure you have verified game files and started new world, remember -KINGDOMS is still EA, I try to make saves compatibility for every new version of the game, but can't guarantee it all the time.
3) The game is still in development, it's NOT finished product, updates are coming 3-4 times a week and that will inevitably cause various issues. Updates for game in development and for finished game - are two absolutely different things, remember that. Game mechanics come and gone, bugs are being fixed and new ones appear all the time. Its a normal thing for development process. If you want to experience KINGDOMS as it was initially designed - smooth, without bugs and full of working mechanics - please, wait till final version will be out.
4) You can support development of KINGDOMS on my official Patreon page.
Thanks for your support, see you very soon!
Cyfieithydd