go faster
This commit is contained in:
parent
1f117ebda5
commit
f8bc84211c
4 changed files with 20 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
from typer import Typer
|
from typer import Typer
|
||||||
from websocket import create_connection
|
from websocket import create_connection
|
||||||
|
|
||||||
|
|
@ -61,6 +62,10 @@ class Client:
|
||||||
return self._ws
|
return self._ws
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from pyinstrument import Profiler
|
||||||
|
|
||||||
|
profiler = Profiler()
|
||||||
|
profiler.start()
|
||||||
while self.running:
|
while self.running:
|
||||||
console.print("running")
|
console.print("running")
|
||||||
console.print("handle_events")
|
console.print("handle_events")
|
||||||
|
|
@ -72,8 +77,11 @@ class Client:
|
||||||
time = self.clock.tick(60)
|
time = self.clock.tick(60)
|
||||||
self.elapsed = time / 100
|
self.elapsed = time / 100
|
||||||
self.ticks += 1
|
self.ticks += 1
|
||||||
|
Console().print(self.clock.get_fps())
|
||||||
console.print(f"time: {time}")
|
console.print(f"time: {time}")
|
||||||
console.print(f"ticks: {self.ticks}")
|
console.print(f"ticks: {self.ticks}")
|
||||||
|
profiler.stop()
|
||||||
|
print(profiler.output_text())
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
|
|
@ -91,7 +99,7 @@ class Client:
|
||||||
self.darkness.fill((light_level, light_level, light_level))
|
self.darkness.fill((light_level, light_level, light_level))
|
||||||
self.light.render()
|
self.light.render()
|
||||||
self.screen.blit(
|
self.screen.blit(
|
||||||
pygame.transform.scale(self.darkness, self.screen.get_size()).convert(),
|
self.darkness,
|
||||||
(0, 0),
|
(0, 0),
|
||||||
special_flags=pygame.BLEND_MULT,
|
special_flags=pygame.BLEND_MULT,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,6 @@ class Light:
|
||||||
)
|
)
|
||||||
v.scale_to_length(self.game.player.hero.flashlight_strength)
|
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.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):
|
for r in range(-25, 25):
|
||||||
_v = v.rotate(r)
|
_v = v.rotate(r)
|
||||||
|
|
@ -84,7 +80,7 @@ class Light:
|
||||||
)
|
)
|
||||||
|
|
||||||
self.game.darkness.blit(
|
self.game.darkness.blit(
|
||||||
pygame.transform.scale(self.surf, self.game.screen.get_size()).convert(),
|
self.surf,
|
||||||
(0, 0),
|
(0, 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
from learn_sql_model.optional import _optional_import_
|
|
||||||
import pydantic
|
import pydantic
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
|
from learn_sql_model.optional import _optional_import_
|
||||||
|
|
||||||
snoise2 = _optional_import_("noise", "snoise2", group="game")
|
snoise2 = _optional_import_("noise", "snoise2", group="game")
|
||||||
pygame = _optional_import_("pygame", group="game")
|
pygame = _optional_import_("pygame", group="game")
|
||||||
|
|
||||||
|
|
@ -38,6 +39,7 @@ class Map:
|
||||||
self.pre_draw()
|
self.pre_draw()
|
||||||
|
|
||||||
def refresh_surf(self):
|
def refresh_surf(self):
|
||||||
|
|
||||||
self.surf = pygame.Surface((self.screen_width, self.screen_height))
|
self.surf = pygame.Surface((self.screen_width, self.screen_height))
|
||||||
|
|
||||||
def get_noise(self, x, y):
|
def get_noise(self, x, y):
|
||||||
|
|
@ -53,7 +55,7 @@ class Map:
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
self.game.screen.blit(
|
self.game.screen.blit(
|
||||||
pygame.transform.scale(self.surf, (self.screen_width, self.screen_height)),
|
self.surf,
|
||||||
(0, 0),
|
(0, 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from learn_sql_model.config import get_config
|
|
||||||
from learn_sql_model.console import console
|
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_
|
from learn_sql_model.optional import _optional_import_
|
||||||
|
|
||||||
pygame = _optional_import_("pygame", group="game")
|
pygame = _optional_import_("pygame", group="game")
|
||||||
|
|
@ -61,10 +60,11 @@ class Player:
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
try:
|
try:
|
||||||
session = get_config().database.session
|
# session = get_config().database.session
|
||||||
hero = session.get(Hero, self.hero.id)
|
# hero = session.get(Hero, self.hero.id)
|
||||||
session.delete(hero)
|
# session.delete(hero)
|
||||||
session.commit()
|
# session.commit()
|
||||||
|
HeroDelete.delete(id=self.hero.id)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue