diff --git a/core/simulation_engine.py b/core/simulation_engine.py index 0095dcb..90c5982 100644 --- a/core/simulation_engine.py +++ b/core/simulation_engine.py @@ -122,8 +122,20 @@ class SimulationEngine: self._handle_sprint_mode() return + # Only process one tick per frame if enough time has passed 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: self.last_tick_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) pygame.display.flip() self.clock.tick(MAX_FPS) + self.last_tick_time = time.perf_counter() def _handle_simulation_ticks(self, tick_interval, deltatime): current_time = time.perf_counter() @@ -204,8 +217,8 @@ class SimulationEngine: self.hud.draw_splitters(self.screen) # self.hud.render_mouse_position(self.screen, self.camera, self.sim_view_rect) - # self.hud.render_fps(self.screen, self.clock) - # self.hud.render_tps(self.screen, self.actual_tps) + self.hud.render_fps(self.screen, self.clock) + self.hud.render_tps(self.screen, self.actual_tps) # 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_legend(self.screen, self.input_handler.show_legend) diff --git a/world/world.py b/world/world.py index 392f9a5..1b95e92 100644 --- a/world/world.py +++ b/world/world.py @@ -162,6 +162,8 @@ class World: """ 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 self.buffers[next_buffer].clear()