60

Forensic Friday 60: Experiment/Research System Done!

đź“ŁDillan

Intro #

Fancy seeing you lot here! It’s been a while since I started a blog post (FF53 to be precise). After a random spurt of work, I’m in a position to talk through a small portion of what’s been happening this week! Getting started with the word that must not be named…

đź“ŁDavid

Intro 2 #

I HAVE TAKEN CONTROL OF THE INTRO. Frankly too short for my liking! Well, this week in the 60th Forensic Friday we have a lot to discuss! Pipes have gone through a small makeover (and are practically fully finished), and NPC pathing gotten a fresh lick of paint. Most important of all, however, is that Feature Batch 1 has been completed! This means that we are moving on to new things. Those things are Facility Raids and Hiring NPCs. Very exciting! Anyways, pretend like this was all written by Dillan… Oh and onto the thing that shall not be named… (very scary)

đź“ŁDillan

Pipes resurfaced #

What else would have brought me out of a mini-retirement other than pipes? After “conquering” them a while back now, changes towards tick rate optimisations have made them slightly unusable. Our main problem was fluid in Pipe A wouldn’t get to Pipe B unless the game was put on max time warp, and we waited for a little while - not game-breaking - but close enough and definitely not playable. We needed what was happening to run more often, without sabotaging game performance.

A quick run-through of possible solutions led to a fairly quick solution. Rip it up and don’t look back. I’m happy to say this wasn’t a rewrite, just simplifying some of our older logic, and leaning on the advantages of using a probability-based system. It wasn’t always plain sailing…

However, after a little tweaking, the pipes are now unbroken again (we think). Subject to some more testing and playing around, fluids now flow happily in real time again - what a time to be alive!

Pumps are now far more powerful than they used to be, completely filling fluid holders next to them consistently.

Powerless fluid systems are now similar to fluid systems with pumps before the changes! With such large-scale changes in our codebase over the last few months, regression was always going to happen - but at least this should be out of the way for the foreseeable future!

Wiki Updates #

While I’m here, I thought I’d just mention some QoL updates on our wiki. Hazard Signs are now easier to navigate since you can filter signs by name! Thanks to Jpkrus in our Discord for the suggestion!

You can find the updated page here!

đź“ŁDavid

Pathfinding Optimisations #

This week I spent some time doing optimisations for pathfinding. Which was definitely not needed! There are still a few hitches, but for the most part, it works pretty beautifully. There was actually only one optimisation, but it’s a pretty major one! It involves something we call “Sectors”.

Sector Optimisation #

Sectors are, in short, a way for NPCs to remember paths that have taken before, which means they don’t need to be recalculated. So for example, if a NPC frequently travels between their office and the site cafeteria, there is no need to recalculate this path every time they want to use it, instead, they calculate it once, then if they need to travel that route again, they used the cached path. This information is not private but rather shared amongst every entity. So if one NPC finds a route to the toilet, every NPC will use that route. However, routes that are infrequently used delete themselves. This allows for dead routes to eventually be deleted. In the future, we will make it so there is a random chance for an NPC to recalculate a path, and if it happens to be shorter, they will update the route!

As a side effect of this, NPCs will not always take the shortest route, at least when considering the system over a larger scale. We likely will even implement imperfect pathing for all NPCs, since NPCs shouldn’t really perfectly know where to go! Anyways below is a more technical explanation for all those interested:

NPCs using sectors to path between rooms instead of calculating path

Explanation for Nerds #

In our system, sectors serve as a memory aid for NPCs, streamlining their movement by storing previously calculated paths. Rather than recalculating routes for common journeys, NPCs create sectors during pathfinding, marking distinct areas on the map.

For each NPC pathfinding event, a brief flood-fill operation runs at the start and end points, defining two sectors. Subsequent pathfinding checks begin by examining the current position’s sector. If the target is accessible from this sector, the existing sector is utilised. If no sector is found, a new one is created. In cases of sector overlap, merging occurs to maintain efficiency.

In rooms, sectors can be directly generated without a flood fill, enhancing speed. If an NPC encounters an obstacle while following a sector path, the affected sector is marked as void and subsequently deleted. You can look at the pseudocode below if you want to get an idea of how it all works!

Function NPC_Pathfinding(start, end):
    if there is a sector at the start position and end position:
        if end sector is accessible from one of start sector's routes:
            if existing route from start sector has obstacle:
                mark start sector as void and delete it
            else:
                path with the existing route from start sector
                return
        else:
            create route to end sector
    
    create a new sector at start if none exists 
    create a new sector at end if none exists 

    if the new sector collides with another sector:
        merge them

    path to target position

Long-term implications involve the gradual expansion of sectors. Initially, with fewer NPCs in the game, there are fewer sectors. As more NPCs join, sectors multiply, minimising the need for constant sector creation and raw pathfinding. Only significant player-driven building developments trigger sector recalculation. All in all, our sector-based pathfinding optimisation significantly diminishes the computational load associated with frequent path calculation!

Lots of sectors!

Pathing Polishing #

I also spent some time polishing the pathing. NPCs now move very smoothly, maybe too smoothly… their paths are also less jagged, so all it in looks a lot more aesthetically pleasing. As with things visual, it is better to show rather than tell:

NPC moving around convoluted corridors. Notice how they slow down at bends

Old Jagged Paths
A straight B-line (who walks in a jagged path anyways!)

NPC moving around a corner. White tiles from simplification algorithm

I won’t go too deeply into how it works, as it’s a well-documented problem, but for the paths to be smoothed, we use spline interpolation. Specifically a Hermite curve, which you can read about here. For simplifying the paths, we use a simple post-processing algorithm, a link to it can be found here but pseudocode is provided below for reference!

start at the beginning of the path
while (there's a next point):
    if there's a clear path from where you are to the next point:
        make a straight path to that point
    else:
        move to the next point

A gross over-simplication, but just check out the resource linked above!

Experiment & Research System Finished #

The experiment system, in an unexpected turn of events, is now finished! A lot of work has been going into it, and it happens to be one of the most involved feature branches we have had for a long while. However, a night and day difference was implementing the experiment gameplay loop this time around (compared to when we first implemented it with the old AI system). It’s quite a scary notion thinking about how horrific development would be if we still had hardcoded AI. Even from a bug standpoint, it’s considerably more stable; less edge cases!

Research nodes actually progressing now!

Moving on into the near future, there are still some closing features that we want to add to the experiment system. These features concern Category C, specifically with the memory system and recycling them. However this will likely be pushed back to when we implement prisoner onboarding, so it’s full steam ahead on features! We have also made a move to our new developmental organisational tool, and now we are going to start getting our new developers working on the game (hopefully). So it’s a bright and relatively good future we have ahead of us!

đź“ŁDavid

Case Closed #

I sort of wrote in the sentiment of a case closed in the previous section, so most of what I would have said has been said already! I had a thought about the design of storytellers which I am excited to share next Friday, but that’ll have to wait. Also expect some new art assets (research desks) for next week 👀. All in all, development continues at a very solid pace despite our time commitments. Though I can’t say the delays in the blogs have been great! Hopefully, that gets sorted, but in the end, a late blog is better than no blog!

Time to file this one away…

GOODBYE!!!

P.S. Changed the layout of heading pictures so they only show up when the speaker changes!

Case Closed.
The Team
Plasmarc Studios