Alternatives from a polling-based system?

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! :slight_smile:

As far as efficiency it’s pretty efficient from the look of it.


The only thing that you probably can improve on is how you organize your thing really. If you add an item to your game, you might have to go around and edit each individual script so everything works properly.

In my game, I have a variety of objects that affect each other, and it would be tedious to edit all the scripts when I add some small item to the game.

I organize my objects like so: each object is only coded to affect itself, and others. This is a very efficient way of handling things, as if you add in an item to the game, you would have to only create one script to handle all of the same objects.

2 Likes

I totally agree. I’m actually using a pile of modules that specifically handle each object type; so there’s absolutely no script replication between game objects, the object’s code is ran from the corresponding module directly.

Also, thanks for your reply. :slight_smile:

1 Like