My apologies for the delayed update, life got in the way and it’s likely that next week will be problematic as well. When I have to make a choice between coding and writing here, I favor the former. So don’t get alarmed by the erratic schedule, development goes on as usual.
Anyway, I made a fair bit of progress toward the release of the Beta 3 with a massive performance and stability boost, the new “free trading” AI module for your ships and multiple smaller other changes i made to the game.
Let’s get to it, shall we.
Performance Boost
As explained in the last devlog, the amount of ships the game has to handle simultaneously kinda skyrocketed due to the new sector ownership system. It lead me to check the whole code-base, which is about 70.000 lines long. Well, not all of it because I was using dedicated tools (called profilers) to find the bottlenecks, but it was still a very long and arduous read.
Without entering in too much technical details, I put in place a sort of cache that store and periodically update the most often requested lists (as an example: all ships or loot drops in given sector). So, instead of fully rebuilding said list each time an agent (ship, dock, bullet…) needs it, the cache delivers the already calculated list instead.
I also made more code oriented optimizations by rewriting commonly used functions in a more efficient way. It’s kinda funny to read several month old code, I can’t remember typing it but I can see how tired I was.
Anyway, I think the best way to illustrate this is to post a benchmark. My computer’s CPU is a AMD Phenom II X4 965. It’s a 4 core CPU running at 3.4Ghz. It’s a relatively old but still decent chipset. My RAM is 2x2Gb Corsair PC3-12800 DDR3 SDRAM (4gb so). None of them are overclocked for the test.
Scenario : Letting the game run itself for 8 hours in the Galaxia map (700 sectors).
Beta 2: The game features around 13.000 agents and would constantly hit 90-100% CPU usage on all cores. The gameplay often feels sluggish.
Beta 3: The game features around 17.000 agents and total CPU usage oscillates between 40% and 90% with some short spikes at 100%. The gameplay feels fine.
So I let the game run on the Imperium (game’s deluxe edition) map. This is a 1000 sector large map. I didn’t do a proper test on the beta 2, but i recall that the game would feel very sluggish after only a few hours and with constant 100% CPU usage. In the beta 3, however, we get 18-19k agents with the same pattern as in Galaxia, 50-90% CPU usage, some 100% spikes, but the gameplay isn’t really affected.
What’s good with my engine is that it’s scalable. If you have a 8x core CPU, you’ll basically double the performances. Above that (if it exists), you’ll have to ask me for another executable file that I will provide and you’ll get another nearly linear performance boost.
If it wasn’t perfectly obvious before, I am pretty happy about the results. I have fairly complex agents, who use path-finding (which tend to be CPU hungry) a lot, and I can still manage to run about 20.000 of them in real time without relying on ‘cheats’. A small city, basically. There’s still some room for optimizations by the way, but now is not the time to do so.
That said, the game will still be a bit laggy during massive fleet battles (those you’re looking at, not those happening in the background) due to collision detection and, well, the graphical engine. This is one of the reason why I am reluctant about adding a mechanism to prevent ships from “stacking” on top of one another as it would consume even more CPU power. There’s a few ways I can improve this, but it would be quite time consuming and I am not yet set on how large military fleets should be, to be honest.
Free Traders
Yes, some trade related stuff has indeed been done (finally) !
I built a new AI module for your ships to run. Basically once you set one of your ships as a Free Trader, it will start buying low and selling high in the current solar system it’s in. If it’s not in a solar system, it will just trade in a region with a 3 sector width radius. That’s the equivalent of the X3’s sector and universe traders, basically. It can make an awful lot of money relatively quickly, however if you run too many free traders in the same system, they’ll basically start competing with each other and you will be at a loss. Also, they tend to attract pirate raiders.
This AI module is primarily intended to be used on cargo ships, but nothing prevent you from using a dock trader or any other ship. And as usual with AI modules, you can assign them escort ships (protect order) to make them more “pirate-proof”.
Diplomatic Screen
One thing I noticed while playing the game is that it was fairly difficult to know who is allied or enemy with who. Also, the diplomatic options were taking too much screen estate.
With that in mind, I redesigned the screen. It immediately show who are the allies and foes of the selected faction, all diplomatic actions are put into the same menu, and so on.
I also fixed a few bugs related to this menu, the “request tribute” button isn’t a free money generating tool and it’s not possible to ask a faction its relation with itself anymore.
Asset List
The asset list was one of the big improvements in Beta 2. However it was far from perfect as you’d need to press a button to update the list and it was generally kinda clunky.
No more ! The list is updated in real time (well, once every second or so) now and it doesn’t scroll without you asking it to do so.
Also, mass assigning AI packages to ships was very problematic in the previous beta, it kinda worked, but you had to work against the UI to do so. It has been fixed, and it’s now as simple as selecting the proper package in the relevant menu.
Misc Improvements
Oh boy ! There’s plenty of that. Factions will spawn a mission to destroy enemy military bases in their vicinity (loads of money and reputation). Factories in occupied territory will send 20% of their benefits to the sector’s owner. Spaceflies spawn correctly now. The galactic map is much more responsive. Most menus are more responsive too. I also added new factories and wares. Rebalanced prices, and cargo size of most items. And, given that I have read a hell lot of my old code, I fixed a bazillion bugs that may or may not be featured in the official changelog.
All things considered, that was a pretty good week code wise. I still need to make sure free traders are working properly. I also need to finish a few things regarding pirate bases and the guild system and we should be ready to go with the beta 3 🙂
Cheers,
SK.
One thought on “Devlog: Free Traders, code optimization and stuff”
Comments are closed.