Profiling functions were added.

This commit is contained in:
shiva404
2026-02-16 01:31:16 +03:00
parent 2e6e75866b
commit f89e0a86c4
5 changed files with 89491 additions and 6 deletions

View File

@@ -3,6 +3,9 @@ import eb_objects
import eb_terrain_objects
import eb_creature_objects
#from pympler import muppy, summary
import gc, psutil, os
cell_classes = {"grass_small": eb_terrain_objects.Ground,
"sword_default": eb_objects.Item}
@@ -78,7 +81,7 @@ class Engine:
self.sprites = {}
pygame.init()
pygame.display.set_caption('Elvenbane')
self.screen = pygame.display.set_mode((self.width, self.height))
self.screen = pygame.display.set_mode((self.width, self.height), pygame.HWSURFACE | pygame.DOUBLEBUF)
self.load_sprites()
print("The engine has started. Sprites were successfully loaded.\n")
@@ -114,7 +117,19 @@ class Engine:
global_counter = 0
global_counter_cap = 100000
# profiling
process = psutil.Process(os.getpid())
gc.collect()
mem_before = process.memory_info().rss / 1024
while running:
#pygame.event.clear()
if global_counter % 1000 == 0:
gc.collect()
mem_after = process.memory_info().rss / 1024
print(f"Leak: {mem_after - mem_before:.1f} KB per 1000 frames")
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get():
@@ -155,4 +170,8 @@ class Engine:
# limits FPS to 60
clock.tick(max_fps)
if global_counter % 100 == 0:
current_fps = clock.get_fps()
print(f"Current FPS: {current_fps:.2f}")
pygame.quit()