fix: Update test files to use current API patterns
Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system
Tests now serve as valid API usage examples.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c025cd7da3
commit
9f481a2e4a
53 changed files with 614 additions and 586 deletions
|
|
@ -34,12 +34,15 @@ grid = mcrfpy.Grid(
|
|||
size=(1024, 768)
|
||||
)
|
||||
|
||||
# Add color layer for floor pattern
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
# Simple floor pattern
|
||||
for x in range(100):
|
||||
for y in range(100):
|
||||
cell = grid.at((x, y))
|
||||
cell = grid.at(x, y)
|
||||
cell.tilesprite = 0
|
||||
cell.color = (40, 40, 40, 255)
|
||||
color_layer.set(x, y, mcrfpy.Color(40, 40, 40, 255))
|
||||
|
||||
# Create 50 entities with random positions and velocities
|
||||
entities = []
|
||||
|
|
@ -47,15 +50,15 @@ ENTITY_COUNT = 50
|
|||
|
||||
for i in range(ENTITY_COUNT):
|
||||
entity = mcrfpy.Entity(
|
||||
grid_pos=(random.randint(0, 99), random.randint(0, 99)),
|
||||
sprite_index=random.randint(10, 20) # Use varied sprites
|
||||
(random.randint(0, 99), random.randint(0, 99)),
|
||||
sprite_index=random.randint(10, 20), # Use varied sprites
|
||||
grid=grid
|
||||
)
|
||||
|
||||
# Give each entity a random velocity
|
||||
# Give each entity a random velocity (stored as Python attributes)
|
||||
entity.velocity_x = random.uniform(-0.5, 0.5)
|
||||
entity.velocity_y = random.uniform(-0.5, 0.5)
|
||||
|
||||
grid.entities.append(entity)
|
||||
entities.append(entity)
|
||||
|
||||
ui.append(grid)
|
||||
|
|
|
|||
|
|
@ -282,23 +282,23 @@ def setup_grid_stress():
|
|||
grid.center = (400, 400) # Center view
|
||||
ui.append(grid)
|
||||
|
||||
# Fill with alternating colors
|
||||
# Add color layer and fill with alternating colors
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
for y in range(50):
|
||||
for x in range(50):
|
||||
cell = grid.at(x, y)
|
||||
if (x + y) % 2 == 0:
|
||||
cell.color = mcrfpy.Color(60, 60, 80)
|
||||
color_layer.set(x, y, mcrfpy.Color(60, 60, 80))
|
||||
else:
|
||||
cell.color = mcrfpy.Color(40, 40, 60)
|
||||
color_layer.set(x, y, mcrfpy.Color(40, 40, 60))
|
||||
|
||||
# Add 50 entities
|
||||
try:
|
||||
texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
||||
|
||||
for i in range(50):
|
||||
# Entity takes positional args: (position, texture, sprite_index, grid)
|
||||
pos = mcrfpy.Vector(random.randint(5, 45), random.randint(5, 45))
|
||||
entity = mcrfpy.Entity(pos, texture, random.randint(0, 100), grid)
|
||||
# Entity takes tuple position and keyword args
|
||||
pos = (random.randint(5, 45), random.randint(5, 45))
|
||||
entity = mcrfpy.Entity(pos, texture=texture, sprite_index=random.randint(0, 100), grid=grid)
|
||||
grid.entities.append(entity)
|
||||
except Exception as e:
|
||||
print(f" Note: Could not create entities: {e}")
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ Uses C++ benchmark logger (start_benchmark/end_benchmark) for accurate timing.
|
|||
Results written to JSON files for analysis.
|
||||
|
||||
Compares rendering performance between:
|
||||
1. Traditional grid.at(x,y).color API (no caching)
|
||||
2. New layer system with dirty flag caching
|
||||
1. ColorLayer with per-cell modifications (no caching benefit)
|
||||
2. ColorLayer with dirty flag caching (static after fill)
|
||||
3. Various layer configurations
|
||||
|
||||
NOTE: The old grid.at(x,y).color API no longer exists. All color operations
|
||||
now go through the ColorLayer system. This benchmark compares different
|
||||
layer usage patterns to measure caching effectiveness.
|
||||
|
||||
Usage:
|
||||
./mcrogueface --exec tests/benchmarks/layer_performance_test.py
|
||||
# Results in benchmark_*.json files
|
||||
|
|
@ -94,7 +98,7 @@ def run_next_test():
|
|||
# ============================================================================
|
||||
|
||||
def setup_base_layer_static():
|
||||
"""Traditional grid.at(x,y).color API - no modifications during render."""
|
||||
"""ColorLayer with per-cell set() calls - static after initial fill."""
|
||||
mcrfpy.createScene("test_base_static")
|
||||
ui = mcrfpy.sceneUI("test_base_static")
|
||||
|
||||
|
|
@ -102,17 +106,17 @@ def setup_base_layer_static():
|
|||
pos=(10, 10), size=(600, 600))
|
||||
ui.append(grid)
|
||||
|
||||
# Fill base layer using traditional API
|
||||
# Fill using ColorLayer with per-cell set() calls (baseline)
|
||||
layer = grid.add_layer("color", z_index=-1)
|
||||
for y in range(GRID_SIZE):
|
||||
for x in range(GRID_SIZE):
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color((x * 2) % 256, (y * 2) % 256, 128, 255)
|
||||
layer.set(x, y, mcrfpy.Color((x * 2) % 256, (y * 2) % 256, 128, 255))
|
||||
|
||||
mcrfpy.setScene("test_base_static")
|
||||
|
||||
|
||||
def setup_base_layer_modified():
|
||||
"""Traditional API with single cell modified each frame."""
|
||||
"""ColorLayer with single cell modified each frame - tests dirty flag."""
|
||||
mcrfpy.createScene("test_base_mod")
|
||||
ui = mcrfpy.sceneUI("test_base_mod")
|
||||
|
||||
|
|
@ -120,19 +124,16 @@ def setup_base_layer_modified():
|
|||
pos=(10, 10), size=(600, 600))
|
||||
ui.append(grid)
|
||||
|
||||
# Fill base layer
|
||||
for y in range(GRID_SIZE):
|
||||
for x in range(GRID_SIZE):
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color(100, 100, 100, 255)
|
||||
# Fill using ColorLayer
|
||||
layer = grid.add_layer("color", z_index=-1)
|
||||
layer.fill(mcrfpy.Color(100, 100, 100, 255))
|
||||
|
||||
# Timer to modify one cell per frame
|
||||
# Timer to modify one cell per frame (triggers dirty flag each frame)
|
||||
mod_counter = [0]
|
||||
def modify_cell(runtime):
|
||||
x = mod_counter[0] % GRID_SIZE
|
||||
y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color(255, 0, 0, 255)
|
||||
layer.set(x, y, mcrfpy.Color(255, 0, 0, 255))
|
||||
mod_counter[0] += 1
|
||||
|
||||
mcrfpy.setScene("test_base_mod")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue