diff --git a/learn_sql_model/game/game.py b/learn_sql_model/game/game.py index 13c844c..6b15987 100644 --- a/learn_sql_model/game/game.py +++ b/learn_sql_model/game/game.py @@ -1,5 +1,6 @@ import atexit +from rich.console import Console from typer import Typer from websocket import create_connection @@ -61,6 +62,10 @@ class Client: return self._ws def run(self): + from pyinstrument import Profiler + + profiler = Profiler() + profiler.start() while self.running: console.print("running") console.print("handle_events") @@ -72,8 +77,11 @@ class Client: time = self.clock.tick(60) self.elapsed = time / 100 self.ticks += 1 + Console().print(self.clock.get_fps()) console.print(f"time: {time}") console.print(f"ticks: {self.ticks}") + profiler.stop() + print(profiler.output_text()) self.quit() def quit(self): @@ -91,7 +99,7 @@ class Client: self.darkness.fill((light_level, light_level, light_level)) self.light.render() self.screen.blit( - pygame.transform.scale(self.darkness, self.screen.get_size()).convert(), + self.darkness, (0, 0), special_flags=pygame.BLEND_MULT, ) diff --git a/learn_sql_model/game/light.py b/learn_sql_model/game/light.py index 02b0190..9000bd5 100644 --- a/learn_sql_model/game/light.py +++ b/learn_sql_model/game/light.py @@ -38,10 +38,6 @@ class Light: ) v.scale_to_length(self.game.player.hero.flashlight_strength) self.game.player.hero.flashlight_angle = v.angle_to(pygame.math.Vector2(0, 1)) - # self.game.screen.blit( - # pygame.transform.rotate(self.image, pygame.math.Vector2(0, 0).angle_to(v)), - # (self.game.player.hero.x, self.game.player.hero.y - 250), - # ) for r in range(-25, 25): _v = v.rotate(r) @@ -84,7 +80,7 @@ class Light: ) self.game.darkness.blit( - pygame.transform.scale(self.surf, self.game.screen.get_size()).convert(), + self.surf, (0, 0), ) diff --git a/learn_sql_model/game/map.py b/learn_sql_model/game/map.py index 616c75b..efb9b58 100644 --- a/learn_sql_model/game/map.py +++ b/learn_sql_model/game/map.py @@ -1,7 +1,8 @@ -from learn_sql_model.optional import _optional_import_ import pydantic from rich.console import Console +from learn_sql_model.optional import _optional_import_ + snoise2 = _optional_import_("noise", "snoise2", group="game") pygame = _optional_import_("pygame", group="game") @@ -38,6 +39,7 @@ class Map: self.pre_draw() def refresh_surf(self): + self.surf = pygame.Surface((self.screen_width, self.screen_height)) def get_noise(self, x, y): @@ -53,7 +55,7 @@ class Map: def render(self): self.game.screen.blit( - pygame.transform.scale(self.surf, (self.screen_width, self.screen_height)), + self.surf, (0, 0), ) diff --git a/learn_sql_model/game/player.py b/learn_sql_model/game/player.py index d24cf26..268d052 100644 --- a/learn_sql_model/game/player.py +++ b/learn_sql_model/game/player.py @@ -1,6 +1,5 @@ -from learn_sql_model.config import get_config from learn_sql_model.console import console -from learn_sql_model.models.hero import Hero, HeroCreate, HeroUpdate, Heros +from learn_sql_model.models.hero import HeroCreate, HeroDelete, HeroUpdate, Heros from learn_sql_model.optional import _optional_import_ pygame = _optional_import_("pygame", group="game") @@ -61,10 +60,11 @@ class Player: def quit(self): try: - session = get_config().database.session - hero = session.get(Hero, self.hero.id) - session.delete(hero) - session.commit() + # session = get_config().database.session + # hero = session.get(Hero, self.hero.id) + # session.delete(hero) + # session.commit() + HeroDelete.delete(id=self.hero.id) except RuntimeError: pass