So here’s my scenario:
For the custom character system in my game, right now I’ve laid the system where every frame the system checks to see which keys are being pressed, then updates the character’s move direction and look direction accordingly. Now, I know that this in itself can be easily converted to use a more sufficient event or interrupt-based approach, however, one reason I decided against this is because on top of updating the player’s move direction, I also must use raycasting to determine if an object is in front of the player, and if there is an object in front of the player and they’re moving forward, it’ll move that object in the player’s moving direction.
The other main aspect of my system framework is core game object updates, which work similarly. Basically, on each level there’s a bunch of different game objects. For some of these objects, they require updates on a regular basis. e.g: turrets that shoot every X seconds, or a laser cannon that casts a laser and can deflect it according to how many mirrors are in its path. For this I iterate over all the created objects in a table (used an OOP approach to accomplish this), determine if the current object in the iteration is not updating, and if it has an :Update()
method implemented, and if both conditions are true, it’ll wrap a function in a coroutine and run that to not interfere with other objects that need updates; so it isn’t guaranteed that a new thread is created, it all depends on if that object needs an update.
Looking at both core systems, I’m really puzzled as to how I could even improve this. As far as game performance goes, it seems pretty stable. There might be an occasional microstutter when the player is moving a game object repeatedly, but I don’t think it’s anything crazy. (this could possibly be due to the fact the core game loop manually calls :Update()
on the player model to handle updating its move direction and to push game objects.)
I just wondered if there’s any easy stuff I could do to improve the flow of these systems a bit.
Thanks for reading!