Excitement

I’m constantly coming up with ideas for whatever game I’m working on. I never have time to try them all, so I tend to bank the riskier ones for use in a sequel. But we’re still in the prototype stage in Soulcaster 3, so it’s the perfect opportunity to test a new combat idea I had last week. Once I saw this in action, I felt an excitement I haven’t felt yet in this project.

Sorry for the tiny file, WordPress is acting up and not allowing files larger than 3MB.
Sorry for the tiny file, WordPress is acting up and not allowing files larger than 3MB.

OG Soulcaster players will immediately see what the difference is here. Instead of recalling summons one at a time and placing them only when you have an orb available, you can now queue up “future summons” with markers. As the existing summons are recalled or destroyed, the orbs powering them will look for a marker to inhabit and spawn a new summon. If there aren’t any, the orbs zoom back to the player.

I haven’t exhaustively tested this yet, but in basic test arenas, it allows for much more strategic play. In the original games, if your defensive line collapsed and you had to reform your summons in a good formation, you were struggling to place them while kiting enemies, and since they appeared one at a time, they were way less effective. This way, you can have a whole new formation set up ahead of time to get back on your feet quickly.

Even better, it gives the player something to do while the guardians attack the enemies. You can choose where to take the battle next based on which monsters are appearing.

One new challenge with this system is what to do if the monsters walk over the markers before the orbs get to them. Should they get destroyed? Or do they only break if the orb reaches them and a monster is still walking over them? There are only a few options for what to do, so I will just try out a few things and see what feels best.

Equipment Systems Improvement

Part of rapidly putting together a prototype is knowing that, at some point, I’ve got to go back and clean up the code. Make it work, first, then make it work right (and finally, make it work fast if you need to). Before I can go any further it’s a good idea to clean up the code and solidify one of the most fragile systems, which is the equipment/weapons/attack generation code.

Vision Field Improvement

I had a bit of inspiration for how to dramatically simplify vision checks in the game.

Vision checks are used in two situations:

  1. Ranged summons (archer and bomber) look for a suitable target
  2. Monsters check if a hero is directly walkable, so they switch from pathing to Gauntlet style movement

These checks are very expensive for the CPU, because they have to iterate to check for obstruction with the world and other actors in the scene.  I realized that we don’t need this level of precision for monster hunting behavior–tile-based granularity is fine, and since there are few targets (summoner and summons), it’s best to broadcast vision from these sources rather than do constant checks.

Pillars obstruct sight. Monsters on blue tinted tiles will move towards player instead of using pathfinding.
Pillars obstruct sight. Monsters on blue tinted tiles will move towards player instead of using pathfinding.

In this new system, every time the summoner moves to a new tile, it calculates which tiles are visible from that position. Monsters only need to check if they step into one of these zones, and this check is only done when they move from tile to tile. Even with the brute force evaluation of visibility, this is probably 50x faster than the old system. (If it needs to be optimized, there is no shortage of methods for calculating vision).

As a side bonus, the monsters don’t need to be on an interval timer for sight checks. It always checks just when it needs to (on a tile change). There were problems before with monsters stepping too far away from the player because their vision timer hadn’t reset yet, and they were still pathing to a stale position. Now they are way less likely to be confused and aimless at close range.

Just a Few Performance Optimizations

It’s not going to be productive to spend lots of time optimizing code at this stage, because things are still pretty fluid. I like to save detail work until later in the project. But today was devoted to some quick optimizations of the AI, pathing, and collision check routines.

Over the IndieCade weekend, I tried a few of the pathing exhibition levels on my laptop on battery power, and it went down to about 1 FPS once all 50 rats were on the screen. I was expecting this, since I didn’t put any effort into performance yet–I just wanted to get it working.

Visual Studio 2012 impressed me with its performance and memory profiler. I was able to quickly see what the slowdown was being caused by. It’s mostly collision detection, as usual, but the traffic field system was also grinding things down. The vision checks are pretty much the biggest culprit, because they do multiple collision tests per frame to check if one creature can see another.

There are some more robust solutions I can do later, but I only wanted to spend one day on it, so:

  • Traffic field builds itself for entire map, rather than dynamically as creatures move.
  • Vision field keeps separate lists of monsters and heroes so it doesn’t need to do checks or filters in the “detect foe” vision checks.
  • Position comparison checks reduced by bailing out earlier for most cases (early returns from functions when it doesn’t make sense to do further tests on the actor).

Just the above cut the time spent in the update routine by about half. Meaning… on battery power, the torture test levels run upwards of 2 FPS!  Okay, so there’s more to do (most likely a bucketing system to split the room into sectors, like Escape Goat). But this will do for now–I mainly wanted to make sure none of the systems I developed were going to pose such a performance threat that they would need to be removed later.