Skip to content

Commit 3271408

Browse files
committed
Fix samples script
Properly clear the renderer per frame. Use explicit namespace imports for tcod Ignore spelling of Numpy parameters Refactor redundant quit events
1 parent 484b6a2 commit 3271408

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"CFLAGS",
8080
"CHARMAP",
8181
"Chebyshev",
82+
"choicelist",
8283
"cibuildwheel",
8384
"CIBW",
8485
"CLEARAGAIN",
@@ -92,6 +93,7 @@
9293
"Coef",
9394
"COLCTRL",
9495
"COMPILEDVERSION",
96+
"condlist",
9597
"consolas",
9698
"contextdata",
9799
"CONTROLLERAXISMOTION",

examples/samples_tcod.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818

1919
import numpy as np
2020

21+
import tcod.bsp
2122
import tcod.cffi
23+
import tcod.console
2224
import tcod.context
2325
import tcod.event
26+
import tcod.image
27+
import tcod.los
28+
import tcod.map
2429
import tcod.noise
30+
import tcod.path
2531
import tcod.render
2632
import tcod.sdl.mouse
2733
import tcod.sdl.render
34+
import tcod.tileset
2835
from tcod import libtcodpy
2936
from tcod.sdl.video import WindowFlags
3037

@@ -103,15 +110,10 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
103110
else:
104111
libtcodpy.sys_save_screenshot()
105112
print("png")
106-
elif event.sym == tcod.event.KeySym.ESCAPE:
107-
raise SystemExit
108113
elif event.sym in RENDERER_KEYS:
109114
# Swap the active context for one with a different renderer.
110115
init_context(RENDERER_KEYS[event.sym])
111116

112-
def ev_quit(self, event: tcod.event.Quit) -> None:
113-
raise SystemExit
114-
115117

116118
class TrueColorSample(Sample):
117119
def __init__(self) -> None:
@@ -1364,6 +1366,8 @@ def main() -> None:
13641366
sample_console.blit(root_console, SAMPLE_SCREEN_X, SAMPLE_SCREEN_Y)
13651367
draw_stats()
13661368
if context.sdl_renderer:
1369+
context.sdl_renderer.draw_color = (0, 0, 0, 255)
1370+
context.sdl_renderer.clear()
13671371
# SDL renderer support, upload the sample console background to a minimap texture.
13681372
sample_minimap.update(sample_console.rgb.T["bg"])
13691373
# Render the root_console normally, this is the drawing step of context.present without presenting.
@@ -1419,6 +1423,8 @@ def handle_events() -> None:
14191423
SAMPLES[cur_sample].dispatch(event)
14201424
if isinstance(event, tcod.event.Quit):
14211425
raise SystemExit
1426+
if isinstance(event, tcod.event.KeyDown) and event.sym == tcod.event.KeySym.ESCAPE:
1427+
raise SystemExit
14221428

14231429

14241430
def draw_samples_menu() -> None:

0 commit comments

Comments
 (0)