#Threading or not for boss attacks

4 messages · Page 1 of 1 (latest)

halcyon zinc
#

Context

I’m making a Touhou-style bullet he’ll game. Bosses in this game will have a list of distinct patterns they will throw at the player, and will move on to the next pattern once the player has dealt enough damage.

I want to use inheritance to implement this, I’ll have a base Attack class which holds helper methods, alongside one empty method which will contain the actual attack logic that the subclasses will implement.

The Question

Which option should I pick for implementing this?

  1. Call the attack logic function once in a new thread when the attack is to start. Thread sleep can be used for timing. The attack logic will contain its own loops and keep the thread running until the main thread stops it when the attack is defeated.

  2. Call the attack function every frame, and keep track of the lifetime of the attack for timing everything.

1 allows for more intuitive timing implementation for parts of the attack, but risks some concurrency issues and bugs with pausing the game. Also call deferred needs to be used for most things, which makes bulk-processing of bullet movement tricky.

2 is annoying for getting the timing to work, but lacks the concurrency issues, will be synced to the games physics framerate, and is able to handle bulk bullet movement (handling movement inside the attack script instead of physics process in each bullet node)

I’m leaning towards 2, but I’d love to hear more opinions on this!

fossil coyote
#

Option 2 for sure. Sleeping a thread is not a reliable timer.

dry orbit
#

One minor addition is that I would put the entire attack coroutine into a child node -- rather than having the boss object's process_physics also manage the attack coroutine steps, I would have the boss create an AttackLogic child, have the AttackLogic child do the intense _process_physics calculations around timing and spawning stuff and shooting stuff on the parent, and leave the more state-machine-y transition-y parts of the logic up at the parent boss (for instance, if it changes tactics during PhaseII or something you can trash the PhaseIAttackLogic child cleanly). You can do this in a lot of ways though (like, a Resource or something!), but if it's a node it might be easier to tune in the editor (like: setting NodePaths elsewhere in the scene etc)

halcyon zinc