Game Design, Programming and running a one-man games business…

The big Production Line performance issue: route-finding

Unlike a game its often compared to (factorio), Production Line has intelligent routing. In factorio, things on conveyor belts go in the direction you send them without thought as to if thats the right way. In Production Line, every object has intelligence, and will pick the best route from its current location to its desired location, which allows for some really cool layouts. It is also a performance nightmare.

Obviously every time the game creates a new axle, wheel, airbag or other component, we dont want to calculate a new route along all the overhead conveyors. Thats madness, so we cache a whole bunch of routes. Also, when we decide which resource importer should be assigned with (for example) airbags, we dont want to do a comparison of routes over every possible combination, so we also cache the location of the nearest 2 import bays. Once we have worked out the nearest 2 bays, we never EVER have to recalculate them unless a bay is added, deleted, or a piece of the conveyor network is added or deleted. So thats cool.

The problem is, this happens ALL THE TIME, and its a big part of gameplay. If we have, for example 100 production line slots, and 20 import bays, then we need those 100 slots to check 20 routes each, every time we change anything related to the resource network. Thats 2,000 route calculations per change. if the player is slapping down one every 3 seconds, then thats 600 routes per second, so ten routes a frame, which isn’t *that bad*.

If the map is bigger and we have 200 slots and 40 bays, then suddenly its 40 routes per frame that need calculating. Very quickly you end up with profiling data (multithreaded) like this:

There are multiple solutions that occur to me. One of them is to spread out the re-calculation over more frames, which means that the import location could be sub-optimal for a second or two longer (hardly a catastrophe). Another would be to do some clever code that works out partial routes and re-uses them as well. (If my neighbour is 1 tile away and his routes are optimal, and I have only one possible path from me to him…calculating new routes entirely is madness).

In any case, I have some actual proper bugs relating to routes *not* being calculated, which is obviously the priority, but I need to improve on this system, as it is by far the biggest cause of performance issues. FWIW, it only happens on really super-full large maps, and custom maps, but its still annoying… Eventually I’ll find a really easy fix and feel like an idiot.

Meanwhile Production Line was updated to build 1.38, with loads of cool improvements. Hope you like it.

Hybrid and electric engines in Production Line

So I have put it off long enough, due to fixing and improving existing things, but the ongoing clamour from the user-base to include these features into Production Line (which for new readers, is my PC car-factory tycoon game), means that I needed to give in and stasrt work on getting it into the game, which is what I’ve done for the last few days.

The design basically comes down to defining each car as being one of three types, based on what people generally refer to as the ‘power-train’. A car is either ICE (internal combustion engine (diesel/petrol), Electric or Hybrid. This is simple enough, and I can work this out from a cars design simply by seeing if certain mutually-exclusive features have been added, for example ‘hybrid power-train’. Any car that is not explicitly hybrid or electric is assumed to be ICE. (This system also allows support for me to at some later stage maybe implement diesel/petrol as two distinctly different technologies.

The slight complexity comes from the fact that for the first time in the design of the simulation, this has to be applied to each CAR, not each design. This is because you can (and players do) change the features of a car design while cars are actively being produced. Its no good changing car type A from ICE to electric when 33 cars of that design have already skipped battery installs and have fuel tanks and radiators…

So thats the first obstacle I had to get over. the second one is to add new power-train-specific support to each production slot. For example, the ‘fit fuel tank’ slot will now fix a battery instead if the car at that slot happens to be a hybrid or electric car (and each of those their own battery size). There also is now support for entirely skipping a slot if the task its performing is irrelevant, which in the case of radiators and pure-electric cars is indeed the case (also exhausts).

So those are the big code changes that have been needed, along with support (with backwards compatibility) for saving and loading the power-train type of each car currently in the game. The other steps are relatively simple, in that they involve setting up new research, new unlockable upgrades and the applicable car features for Hybrid power-train, Electric power-train, and Large Battery support. (Electric cars will initially default to small batteries, with large ones being a researchable option). I also needed to add new resources for electric motors, and 3 different battery types, plus a composite resource for a hybrid power-train. That gives me ‘basic’ support for a choice between ICE, Hybrid and Electric . From then on, in future updates, I can introduce slots to manufacture those components, such as make battery, make electric motor etc, and maybe some researchable techs for higher power-density batteries etc. Thats all in the future.

For now it just feels good to know I’ll have this new tech in the game in a few days time.

In the meantime I am off to Indiecade Paris where I will be giving my down-to-earth honest talk called ‘how not to go bankrupt’.

Oh and by the way, if you are a steam customer, or a direct-bought customer with a steam key (which comes with every order), you might be interested to know that we now have cool Steam Trading cards available for the game.

Oh…and last thing, the steam Halloween sale is on, with a ton of cool positech bargains. Production Line is NOT discounted, nor will it be in any other sales this year, but you can buy it from the link below for $17.99 :D

Version 1.34 released. price change any day/hour now

So I tested and released build 1.34 of Production Line today with the following changes:

1) [Bug] Fixed crash bug when dragging production line route placer off the map.
2) [Bug] Fixed bug where queued research could disappear and be untriggerable if requirements not met.
3) [GUI] Various usability improvements to the research queue and R&D screen.
4) [SFX] Factory sounds now controlled by SFX volume, and muted during research.
5) [Bug] Fixed bug where after reloading the same games, some cars were invisible at certain zoom levels.
6) [Tutorial] Hint now given if player has not done any research after producing 10 cars.
7) [Graphics] Added a bunch more machine animations for the metalpresses.
8) [Feature] Pickup truck is a new body style option!
9) [Simulation] Sports Cars, Compacts & pickups now require half as many seats.
10) [Bug] Fixed bug where wingmirror painted layers were not painted the right color.
11) [Balance] Adjustments to AI competition and component price variation.
12) [Bug] Fixed bug preventing dragging scrollbars vertically.

This is a fairly content-heavy update, with new animations and a new car body style. Who would have guessed that in the USA 18% of vehicle sales are pickup trucks? Anyway… its more stuff to research and sell, and hopefully people will be pleased to see the extra content.

I have a big list of minor things I really need to get fixed/changed/tweaked for the next build, and then eventually it will be time for me to tackle the big hybrid./electric power-train thing. In-between all that we have our super artist working away on steam trading card art, which is going to be AMAZING, so with any luck we will have those in the next update, for people who like that sort of thing. I’m also thinking that there should be a bit more variety in the games factory equipment. I would love to be able to tell from a distance which slot is which, and the re-use of a lot of components throughout the factory makes that tricky. Some items, like the Tyre-press or glass-cutter are distinct to specific slots, but a lot of it isn’t and I think its about time I addressed that and got some more little factory things made so that I can create more distinct looks for each slot. Plus that gives me an excuse to look at factory videos :D

I’ve set the new price to be $17.99 but valve have to ‘approve’ it before it changes, so if you are on the fence, buy NOW :D.

Or buy it now at full price from us direct … :D