Refine simulation tick handling to ensure consistent timing and update HUD rendering
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 1m11s

This commit is contained in:
Sam 2025-06-25 00:19:22 -05:00
parent 8bb669d6b2
commit 4e90ecb885
2 changed files with 18 additions and 3 deletions

View File

@ -122,8 +122,20 @@ class SimulationEngine:
self._handle_sprint_mode() self._handle_sprint_mode()
return return
# Only process one tick per frame if enough time has passed
if not self.input_handler.is_paused: if not self.input_handler.is_paused:
self._handle_simulation_ticks(tick_interval, deltatime) current_time = time.perf_counter()
if current_time - self.last_tick_time >= tick_interval:
self.last_tick_time += tick_interval
self.tick_counter += 1
self.total_ticks += 1
self.input_handler.update_selected_objects()
self.world.tick_all()
self.hud.manager.update(deltatime)
if current_time - self.last_tps_time >= 1.0:
self.actual_tps = self.tick_counter
self.tick_counter = 0
self.last_tps_time += 1.0
else: else:
self.last_tick_time = time.perf_counter() self.last_tick_time = time.perf_counter()
self.last_tps_time = time.perf_counter() self.last_tps_time = time.perf_counter()
@ -167,6 +179,7 @@ class SimulationEngine:
self.hud.render_sprint_debug(self.screen, self.actual_tps, self.total_ticks, cell_count) self.hud.render_sprint_debug(self.screen, self.actual_tps, self.total_ticks, cell_count)
pygame.display.flip() pygame.display.flip()
self.clock.tick(MAX_FPS) self.clock.tick(MAX_FPS)
self.last_tick_time = time.perf_counter()
def _handle_simulation_ticks(self, tick_interval, deltatime): def _handle_simulation_ticks(self, tick_interval, deltatime):
current_time = time.perf_counter() current_time = time.perf_counter()
@ -204,8 +217,8 @@ class SimulationEngine:
self.hud.draw_splitters(self.screen) self.hud.draw_splitters(self.screen)
# self.hud.render_mouse_position(self.screen, self.camera, self.sim_view_rect) # self.hud.render_mouse_position(self.screen, self.camera, self.sim_view_rect)
# self.hud.render_fps(self.screen, self.clock) self.hud.render_fps(self.screen, self.clock)
# self.hud.render_tps(self.screen, self.actual_tps) self.hud.render_tps(self.screen, self.actual_tps)
# self.hud.render_tick_count(self.screen, self.total_ticks) # self.hud.render_tick_count(self.screen, self.total_ticks)
# self.hud.render_selected_objects_info(self.screen, self.input_handler.selected_objects) # self.hud.render_selected_objects_info(self.screen, self.input_handler.selected_objects)
self.hud.render_legend(self.screen, self.input_handler.show_legend) self.hud.render_legend(self.screen, self.input_handler.show_legend)

View File

@ -162,6 +162,8 @@ class World:
""" """
Advances all objects in the world by one tick, updating their state and handling interactions. Advances all objects in the world by one tick, updating their state and handling interactions.
""" """
print("Ticking all objects in the world")
next_buffer: int = 1 - self.current_buffer next_buffer: int = 1 - self.current_buffer
self.buffers[next_buffer].clear() self.buffers[next_buffer].clear()