Profiling functions were added.
This commit is contained in:
Binary file not shown.
89464
def_map.json
89464
def_map.json
File diff suppressed because it is too large
Load Diff
21
eb_engine.py
21
eb_engine.py
@@ -3,6 +3,9 @@ import eb_objects
|
|||||||
import eb_terrain_objects
|
import eb_terrain_objects
|
||||||
import eb_creature_objects
|
import eb_creature_objects
|
||||||
|
|
||||||
|
#from pympler import muppy, summary
|
||||||
|
import gc, psutil, os
|
||||||
|
|
||||||
cell_classes = {"grass_small": eb_terrain_objects.Ground,
|
cell_classes = {"grass_small": eb_terrain_objects.Ground,
|
||||||
"sword_default": eb_objects.Item}
|
"sword_default": eb_objects.Item}
|
||||||
|
|
||||||
@@ -78,7 +81,7 @@ class Engine:
|
|||||||
self.sprites = {}
|
self.sprites = {}
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption('Elvenbane')
|
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()
|
self.load_sprites()
|
||||||
print("The engine has started. Sprites were successfully loaded.\n")
|
print("The engine has started. Sprites were successfully loaded.\n")
|
||||||
|
|
||||||
@@ -114,7 +117,19 @@ class Engine:
|
|||||||
global_counter = 0
|
global_counter = 0
|
||||||
global_counter_cap = 100000
|
global_counter_cap = 100000
|
||||||
|
|
||||||
|
# profiling
|
||||||
|
|
||||||
|
process = psutil.Process(os.getpid())
|
||||||
|
gc.collect()
|
||||||
|
mem_before = process.memory_info().rss / 1024
|
||||||
|
|
||||||
while running:
|
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
|
# poll for events
|
||||||
# pygame.QUIT event means the user clicked X to close your window
|
# pygame.QUIT event means the user clicked X to close your window
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@@ -155,4 +170,8 @@ class Engine:
|
|||||||
# limits FPS to 60
|
# limits FPS to 60
|
||||||
clock.tick(max_fps)
|
clock.tick(max_fps)
|
||||||
|
|
||||||
|
if global_counter % 100 == 0:
|
||||||
|
current_fps = clock.get_fps()
|
||||||
|
print(f"Current FPS: {current_fps:.2f}")
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
6
main.py
6
main.py
@@ -33,3 +33,9 @@ if __name__ == "__main__":
|
|||||||
# - общие +
|
# - общие +
|
||||||
main()
|
main()
|
||||||
# техдолг - draw_data to dd
|
# техдолг - 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
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
width = 10
|
width = 100
|
||||||
height = 8
|
height = 100
|
||||||
|
|
||||||
grass_def = {"id": "1", "name": "2", "sprite_name": "grass_small"}
|
grass_def = {"id": "1", "name": "2", "sprite_name": "grass_small"}
|
||||||
cell_def = {"terrain_obj": grass_def, "item_obj": {}, "creature_obj": {}}
|
cell_def = {"terrain_obj": grass_def, "item_obj": {}, "creature_obj": {}}
|
||||||
|
|||||||
Reference in New Issue
Block a user