sholloway / agents-playground

MIT License
4 stars 0 forks source link

Event Based Game Loop #34

Closed sholloway closed 1 year ago

sholloway commented 2 years ago

Create an Event Based Game Loop

Tasks

EDF

This type of game loop leverages a priority queue to schedule future actions to occur. It is an instance of the Earliest deadline first (EDF) pattern.

The Basic Loop is of the Form

def main_loop(self, **data):
    previous_time: TimeInMS = TimeUtilities.now()
    lag: TimeInMS = 0

    while self.simulation_state is not SimulationState.ENDED:
      if self.simulation_state is SimulationState.RUNNING:
        current_time: TimeInMS = TimeUtilities.now()
        elapsed_time: TimeInMS = current_time - previous_time
        previous_time = current_time
        lag += elapsed_time

        process_input()

        while lag >= TIME_PER_UPDATE:
          self._scheduler.run(TIME_PER_UPDATE)
          lag -= TIME_PER_UPDATE

        render()

Resources

sholloway commented 2 years ago

Perhaps I should add the rolling utilization calculation as the game is running. That'll indicate how much head room the sim has for getting all the work done

This video breaks down calculating utilization and load for a scheduling algorithm.

As I'm digging into it, I realize that there is more to an EDF than just using a priority queue and running things based on their due time.

Consider the need to segment high criticality tasks from low criticality.

I need a better simulation to get a sense for if my scheduling implementation is good enough. Thoughts:

Ideally, the same sim should existing using the other Simulation model.

sholloway commented 2 years ago

Are there existing EDF implementations in Python that I can study?