Orkn's Pulp Devlog

I think I've reached the end of my current performance optimising of Lolife

I thought wrong :smile:

Here's where I'm at now with entities on screen. The second column is with the enemies alerted, which is a little more complex in behaviour (checking distance to the player and chasing or fleeing, rather than just a random walk).

0 entities = 20 fps | 20 fps
1 entities = 20 fps | 20 fps
2 entities = 20 fps | 20 fps
3 entities = 20 fps | 19 fps
4 entities = 19 fps | 19 fps
5 entities = 19 fps | 18 fps

This was with some more refactoring of my game script, the behaviour is still unchanged.

One significant improvement in the random walk code was in replacing 126 lines of code... with 868 lines of code. The reason that sped things up (despite being a lot more verbose and repetitive) is that I reduced average number of calls of the solid function. Previously I was always checking all four surrounding tiles per entity, now that's the worst case scenario. Unfortunately that mean replacing some relatively tidy code with 24 permutations of very repetitive code. I ended up writing a python script to generate that pulpscript rather than copy-pasting and writing it all myself!

Another significant improvement was in further reducing the number of events being called from the game loop - it's now just one per entity when they are just moving around. The way I achieved that is by changing how each enemy's behaviour is defined. Before I had an event per enemy that strung together different events. I've managed to keep the ease of adding new enemies (and still instanced without sprite duplication) by switching to an approach where I define several attributes of the enemy and these translate into branching code in a single event. It's slightly less flexible but I think it's actually a better fit!

This is all the unique code needed to define my current two enemies:

on mouse do
	damage = 4
	hp = 12
	range = 3
	vigilant = 0
	aggressive = 0
	timid = 1
	nomadic = 1
end

on fox do
	damage = 4
	hp = 32
	range = 3
	vigilant = 0
	aggressive = 1
	timid = 0
	nomadic = 1
end

These stats get queried when each entity instance is registered on room enter so these events are only being called once on enter, not every time the entity moves.

This optimisation has been more than worthwhile, as not only have I significantly improved performance which lets me design with more entities per room, I've made adding new entities even easier. All I have to do is make one set of sprites (for the different directions and attack animations) and define one event like the above, then I can register any number of each entity in each room (up to my simultaneous entity limit).

I really will make some actual content and have some new gifs to share next time! I've already been designing the map and the overal flow/progression, so hopefully I'll have something to show soon :slight_smile:

3 Likes