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

89464
def_map.json

File diff suppressed because it is too large Load Diff

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()

View File

@@ -33,3 +33,9 @@ if __name__ == "__main__":
# - общие +
main()
# техдолг - draw_data to dd
#pygame.init()
#size = width, height = 640, 480
## Use HWSURFACE and DOUBLEBUF flags
#screen = pygame.display.set_mode(size, pygame.HWSURFACE | pygame.DOUBLEBUF)
# кэширование спрайтов - скалировать сразу все на уровне движка!
# изучить pypmler

View File

@@ -1,8 +1,8 @@
import json
from copy import deepcopy
width = 10
height = 8
width = 100
height = 100
grass_def = {"id": "1", "name": "2", "sprite_name": "grass_small"}
cell_def = {"terrain_obj": grass_def, "item_obj": {}, "creature_obj": {}}