Timer overhaul: update tests
This commit is contained in:
parent
5d41292bf6
commit
cec76b63dc
78 changed files with 521 additions and 495 deletions
|
|
@ -97,7 +97,7 @@ def handle_key(key, state):
|
|||
benchmark.on_key = handle_key
|
||||
|
||||
# Update entity positions
|
||||
def update_entities(ms):
|
||||
def update_entities(timer, ms):
|
||||
dt = ms / 1000.0 # Convert to seconds
|
||||
|
||||
for entity in entities:
|
||||
|
|
@ -119,13 +119,13 @@ def update_entities(ms):
|
|||
entity.y = new_y
|
||||
|
||||
# Run movement update every frame (16ms)
|
||||
mcrfpy.setTimer("movement", update_entities, 16)
|
||||
movement_timer = mcrfpy.Timer("movement", update_entities, 16)
|
||||
|
||||
# Benchmark statistics
|
||||
frame_count = 0
|
||||
start_time = None
|
||||
|
||||
def benchmark_timer(ms):
|
||||
def benchmark_callback(timer, ms):
|
||||
global frame_count, start_time
|
||||
|
||||
if start_time is None:
|
||||
|
|
@ -152,4 +152,4 @@ def benchmark_timer(ms):
|
|||
print("=" * 60)
|
||||
# Don't exit - let user review
|
||||
|
||||
mcrfpy.setTimer("benchmark", benchmark_timer, 100)
|
||||
benchmark_timer = mcrfpy.Timer("benchmark", benchmark_callback, 100)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ frame_count = 0
|
|||
metrics_samples = []
|
||||
|
||||
|
||||
def collect_metrics(runtime):
|
||||
def collect_metrics(timer, runtime):
|
||||
"""Timer callback to collect metrics each frame."""
|
||||
global frame_count, metrics_samples
|
||||
|
||||
|
|
@ -65,9 +65,9 @@ def collect_metrics(runtime):
|
|||
|
||||
def finish_scenario():
|
||||
"""Calculate statistics and store results for current scenario."""
|
||||
global results, current_scenario, metrics_samples
|
||||
global results, current_scenario, metrics_samples, benchmark_timer
|
||||
|
||||
mcrfpy.delTimer("benchmark_collect")
|
||||
benchmark_timer.stop()
|
||||
|
||||
if not metrics_samples:
|
||||
print(f" WARNING: No samples collected for {current_scenario}")
|
||||
|
|
@ -149,7 +149,8 @@ def run_next_scenario():
|
|||
scenarios[next_idx][1]()
|
||||
|
||||
# Start collection timer (runs every frame)
|
||||
mcrfpy.setTimer("benchmark_collect", collect_metrics, 1)
|
||||
global benchmark_timer
|
||||
benchmark_timer = mcrfpy.Timer("benchmark_collect", collect_metrics, 1)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ def print_analysis():
|
|||
print(f" Note: This overhead is acceptable given query speedups")
|
||||
|
||||
|
||||
def run_benchmarks(runtime=None):
|
||||
def run_benchmarks(timer=None, runtime=None):
|
||||
"""Main benchmark runner."""
|
||||
global results
|
||||
|
||||
|
|
@ -458,4 +458,4 @@ if __name__ == "__main__":
|
|||
if "--headless" in sys.argv or True: # Always run immediately for benchmarks
|
||||
run_benchmarks()
|
||||
else:
|
||||
mcrfpy.setTimer("run_bench", run_benchmarks, 100)
|
||||
bench_timer = mcrfpy.Timer("run_bench", run_benchmarks, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ frame_count = 0
|
|||
test_results = {} # Store filenames for each test
|
||||
|
||||
|
||||
def run_test_phase(runtime):
|
||||
def run_test_phase(timer, runtime):
|
||||
"""Run through warmup and measurement phases."""
|
||||
global frame_count
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ def run_test_phase(runtime):
|
|||
test_results[current_test] = filename
|
||||
print(f" {current_test}: saved to {filename}")
|
||||
|
||||
mcrfpy.delTimer("test_phase")
|
||||
timer.stop()
|
||||
run_next_test()
|
||||
|
||||
|
||||
|
|
@ -90,7 +90,8 @@ def run_next_test():
|
|||
print(f"\n[{next_idx + 1}/{len(tests)}] Running: {current_test}")
|
||||
tests[next_idx][1]()
|
||||
|
||||
mcrfpy.setTimer("test_phase", run_test_phase, 1)
|
||||
global test_phase_timer
|
||||
test_phase_timer = mcrfpy.Timer("test_phase", run_test_phase, 1)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
|
|
@ -130,14 +131,15 @@ def setup_base_layer_modified():
|
|||
|
||||
# Timer to modify one cell per frame (triggers dirty flag each frame)
|
||||
mod_counter = [0]
|
||||
def modify_cell(runtime):
|
||||
def modify_cell(timer, runtime):
|
||||
x = mod_counter[0] % GRID_SIZE
|
||||
y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE
|
||||
layer.set(x, y, mcrfpy.Color(255, 0, 0, 255))
|
||||
mod_counter[0] += 1
|
||||
|
||||
test_base_mod.activate()
|
||||
mcrfpy.setTimer("modify", modify_cell, 1)
|
||||
global modify_timer
|
||||
modify_timer = mcrfpy.Timer("modify", modify_cell, 1)
|
||||
|
||||
|
||||
def setup_color_layer_static():
|
||||
|
|
@ -170,14 +172,15 @@ def setup_color_layer_modified():
|
|||
|
||||
# Timer to modify one cell per frame - triggers re-render
|
||||
mod_counter = [0]
|
||||
def modify_cell(runtime):
|
||||
def modify_cell(timer, runtime):
|
||||
x = mod_counter[0] % GRID_SIZE
|
||||
y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE
|
||||
layer.set(x, y, mcrfpy.Color(255, 0, 0, 255))
|
||||
mod_counter[0] += 1
|
||||
|
||||
test_color_mod.activate()
|
||||
mcrfpy.setTimer("modify", modify_cell, 1)
|
||||
global modify_timer
|
||||
modify_timer = mcrfpy.Timer("modify", modify_cell, 1)
|
||||
|
||||
|
||||
def setup_tile_layer_static():
|
||||
|
|
@ -222,7 +225,7 @@ def setup_tile_layer_modified():
|
|||
|
||||
# Timer to modify one cell per frame
|
||||
mod_counter = [0]
|
||||
def modify_cell(runtime):
|
||||
def modify_cell(timer, runtime):
|
||||
if layer:
|
||||
x = mod_counter[0] % GRID_SIZE
|
||||
y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE
|
||||
|
|
@ -230,7 +233,8 @@ def setup_tile_layer_modified():
|
|||
mod_counter[0] += 1
|
||||
|
||||
test_tile_mod.activate()
|
||||
mcrfpy.setTimer("modify", modify_cell, 1)
|
||||
global modify_timer
|
||||
modify_timer = mcrfpy.Timer("modify", modify_cell, 1)
|
||||
|
||||
|
||||
def setup_multi_layer_static():
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class StressTestRunner:
|
|||
def add_test(self, name, setup_fn, description=""):
|
||||
self.tests.append({'name': name, 'setup': setup_fn, 'description': description})
|
||||
|
||||
def tick(self, runtime):
|
||||
def tick(self, timer, runtime):
|
||||
"""Single timer callback that manages all test flow"""
|
||||
self.frames_counted += 1
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ class StressTestRunner:
|
|||
self.results[test['name']] = {'error': str(e)}
|
||||
|
||||
def finish_suite(self):
|
||||
mcrfpy.delTimer("tick")
|
||||
self.tick_timer.stop()
|
||||
|
||||
print("\n" + "="*50)
|
||||
print("STRESS TEST COMPLETE")
|
||||
|
|
@ -137,7 +137,7 @@ class StressTestRunner:
|
|||
ui = init.children
|
||||
ui.append(mcrfpy.Frame(pos=(0,0), size=(10,10))) # Required for timer to fire
|
||||
init.activate()
|
||||
mcrfpy.setTimer("tick", self.tick, TIMER_INTERVAL_MS)
|
||||
self.tick_timer = mcrfpy.Timer("tick", self.tick, TIMER_INTERVAL_MS)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import mcrfpy
|
|||
import sys
|
||||
import time
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
print("=" * 60)
|
||||
print("FOV Isolation Test - Is TCOD slow, or is it the Python wrapper?")
|
||||
print("=" * 60)
|
||||
|
|
@ -96,4 +96,4 @@ def run_test(runtime):
|
|||
|
||||
init = mcrfpy.Scene("init")
|
||||
init.activate()
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ init = mcrfpy.Scene("init")
|
|||
init.activate()
|
||||
|
||||
# Use a timer to let the engine initialize
|
||||
def run_benchmark(runtime):
|
||||
def run_benchmark(timer, runtime):
|
||||
main()
|
||||
|
||||
mcrfpy.setTimer("bench", run_benchmark, 100)
|
||||
bench_timer = mcrfpy.Timer("bench", run_benchmark, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class DemoRunner:
|
|||
self.current_index = 0
|
||||
self.render_wait = 0
|
||||
|
||||
def screenshot_cycle(runtime):
|
||||
def screenshot_cycle(timer, runtime):
|
||||
if self.render_wait == 0:
|
||||
# Set scene and wait for render
|
||||
if self.current_index >= len(self.screens):
|
||||
|
|
@ -139,7 +139,7 @@ class DemoRunner:
|
|||
print("Done!")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("screenshot", screenshot_cycle, 50)
|
||||
self.screenshot_timer = mcrfpy.Timer("screenshot", screenshot_cycle, 50)
|
||||
|
||||
def run_interactive(self):
|
||||
"""Run in interactive mode with menu."""
|
||||
|
|
|
|||
|
|
@ -126,9 +126,10 @@ def setup_scene():
|
|||
patrol_demo.on_key = on_keypress
|
||||
|
||||
# Start patrol timer
|
||||
mcrfpy.setTimer("patrol", patrol_step, move_timer_ms)
|
||||
global patrol_timer
|
||||
patrol_timer = mcrfpy.Timer("patrol", patrol_step, move_timer_ms)
|
||||
|
||||
def patrol_step(runtime):
|
||||
def patrol_step(timer, runtime):
|
||||
"""Move entity one step toward current waypoint"""
|
||||
global current_waypoint, patrol_paused
|
||||
|
||||
|
|
|
|||
|
|
@ -784,12 +784,12 @@ def run_demo():
|
|||
demo_state = create_demo_scene()
|
||||
|
||||
# Set up exit timer for headless testing
|
||||
def check_exit(dt):
|
||||
def check_exit(timer, dt):
|
||||
# In headless mode, exit after a short delay
|
||||
# In interactive mode, this won't trigger
|
||||
pass
|
||||
|
||||
# mcrfpy.setTimer("demo_check", check_exit, 100)
|
||||
# check_exit_timer = mcrfpy.Timer("demo_check", check_exit, 100)
|
||||
|
||||
|
||||
# Run if executed directly
|
||||
|
|
@ -801,8 +801,8 @@ if __name__ == "__main__":
|
|||
|
||||
# If --screenshot flag, take a screenshot and exit
|
||||
if "--screenshot" in sys.argv or len(sys.argv) > 1:
|
||||
def take_screenshot(dt):
|
||||
def take_screenshot(timer, dt):
|
||||
automation.screenshot("focus_demo_screenshot.png")
|
||||
print("Screenshot saved: focus_demo_screenshot.png")
|
||||
sys.exit(0)
|
||||
mcrfpy.setTimer("screenshot", take_screenshot, 200)
|
||||
screenshot_timer = mcrfpy.Timer("screenshot", take_screenshot, 200, once=True)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class GeometryDemoRunner:
|
|||
self.current_index = 0
|
||||
self.render_wait = 0
|
||||
|
||||
def screenshot_cycle(runtime):
|
||||
def screenshot_cycle(timer, runtime):
|
||||
if self.render_wait == 0:
|
||||
if self.current_index >= len(self.screens):
|
||||
print("Done!")
|
||||
|
|
@ -162,7 +162,7 @@ class GeometryDemoRunner:
|
|||
print("Done!")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("screenshot", screenshot_cycle, 100)
|
||||
self.screenshot_timer = mcrfpy.Timer("screenshot", screenshot_cycle, 100)
|
||||
|
||||
def run_interactive(self):
|
||||
"""Run in interactive mode with menu."""
|
||||
|
|
|
|||
|
|
@ -46,17 +46,19 @@ class GeometryDemoScreen:
|
|||
|
||||
def cleanup(self):
|
||||
"""Clean up timers when leaving screen."""
|
||||
for timer_name in self.timers:
|
||||
for timer in self.timers:
|
||||
try:
|
||||
mcrfpy.delTimer(timer_name)
|
||||
timer.stop()
|
||||
except:
|
||||
pass
|
||||
|
||||
def restart_timers(self):
|
||||
"""Re-register timers after cleanup."""
|
||||
self.timers = [] # Clear old timer references
|
||||
for name, callback, interval in self._timer_configs:
|
||||
try:
|
||||
mcrfpy.setTimer(name, callback, interval)
|
||||
timer = mcrfpy.Timer(name, callback, interval)
|
||||
self.timers.append(timer)
|
||||
except Exception as e:
|
||||
print(f"Timer restart failed: {e}")
|
||||
|
||||
|
|
@ -111,6 +113,6 @@ class GeometryDemoScreen:
|
|||
if callback is None:
|
||||
print(f"Warning: Timer '{name}' callback is None, skipping")
|
||||
return
|
||||
mcrfpy.setTimer(name, callback, interval)
|
||||
self.timers.append(name)
|
||||
timer = mcrfpy.Timer(name, callback, interval)
|
||||
self.timers.append(timer)
|
||||
self._timer_configs.append((name, callback, interval))
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ class PathfindingAnimatedDemo(GeometryDemoScreen):
|
|||
self.dist_label.fill_color = mcrfpy.Color(150, 150, 150)
|
||||
self.ui.append(self.dist_label)
|
||||
|
||||
def _tick(self, runtime):
|
||||
def _tick(self, timer, runtime):
|
||||
"""Advance one turn."""
|
||||
self.current_time += 1
|
||||
self.time_label.text = f"Turn: {self.current_time}"
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ class SolarSystemDemo(GeometryDemoScreen):
|
|||
self.ui.append(moon_path)
|
||||
self.orbit_rings[moon.name + "_path"] = moon_path
|
||||
|
||||
def _tick(self, runtime):
|
||||
def _tick(self, timer, runtime):
|
||||
"""Advance time by one turn and update planet positions."""
|
||||
self.current_time += 1
|
||||
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ def handle_keypress(scene_name, keycode):
|
|||
sys.exit(0)
|
||||
|
||||
# Timer callback for animation
|
||||
def update_animation(dt):
|
||||
def update_animation(timer, dt):
|
||||
"""Update animation state"""
|
||||
animate_movement(dt / 1000.0) # Convert ms to seconds
|
||||
|
||||
|
|
@ -335,7 +335,7 @@ for i, entity in enumerate(entities):
|
|||
dijkstra_enhanced.on_key = handle_keypress
|
||||
|
||||
# Set up animation timer (60 FPS)
|
||||
mcrfpy.setTimer("animation", update_animation, 16)
|
||||
animation_timer = mcrfpy.Timer("animation", update_animation, 16)
|
||||
|
||||
# Show the scene
|
||||
dijkstra_enhanced.activate()
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ def test_dijkstra(grid, entities):
|
|||
|
||||
return results
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run tests and take screenshot"""
|
||||
# Run pathfinding tests
|
||||
results = test_dijkstra(grid, entities)
|
||||
|
|
@ -101,8 +101,8 @@ def run_test(runtime):
|
|||
ui.append(caption)
|
||||
y_pos += 20
|
||||
|
||||
# Take screenshot
|
||||
mcrfpy.setTimer("screenshot", lambda rt: take_screenshot(), 500)
|
||||
# Take screenshot (one-shot timer)
|
||||
screenshot_timer = mcrfpy.Timer("screenshot", lambda t, rt: take_screenshot(), 500, once=True)
|
||||
|
||||
def take_screenshot():
|
||||
"""Take screenshot and exit"""
|
||||
|
|
@ -140,7 +140,7 @@ ui.append(legend)
|
|||
# Set scene
|
||||
dijkstra_test.activate()
|
||||
|
||||
# Run test after scene loads
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
# Run test after scene loads (one-shot timer)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
||||
print("Running Dijkstra tests...")
|
||||
|
|
@ -9,7 +9,7 @@ This test verifies that:
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def timer_that_raises(runtime):
|
||||
def timer_that_raises(timer, runtime):
|
||||
"""A timer callback that raises an exception"""
|
||||
raise ValueError("Intentional test exception")
|
||||
|
||||
|
|
@ -17,8 +17,8 @@ def timer_that_raises(runtime):
|
|||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
|
||||
# Schedule the timer - it will fire after 50ms
|
||||
mcrfpy.setTimer("raise_exception", timer_that_raises, 50)
|
||||
# Schedule the timer - it will fire after 50ms (one-shot timer)
|
||||
exception_timer = mcrfpy.Timer("raise_exception", timer_that_raises, 50, once=True)
|
||||
|
||||
# This test expects:
|
||||
# - Default behavior: exit with code 1 after first exception
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ def test_edge_cases():
|
|||
print(" Edge cases: PASS")
|
||||
return True
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run tests after scene is active"""
|
||||
results = []
|
||||
|
||||
|
|
@ -185,4 +185,4 @@ if __name__ == "__main__":
|
|||
test.activate()
|
||||
|
||||
# Run tests after scene is active
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import mcrfpy
|
|||
import sys
|
||||
import time
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
print("=" * 60)
|
||||
print("Issue #146 Regression Test: compute_fov() returns None")
|
||||
print("=" * 60)
|
||||
|
|
@ -111,4 +111,4 @@ def run_test(runtime):
|
|||
# Initialize and run
|
||||
init = mcrfpy.Scene("init")
|
||||
init.activate()
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ Tests:
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
print("=" * 60)
|
||||
print("Issue #147 Regression Test: Dynamic Layer System for Grid")
|
||||
print("=" * 60)
|
||||
|
|
@ -190,4 +190,4 @@ def run_test(runtime):
|
|||
# Initialize and run
|
||||
init = mcrfpy.Scene("init")
|
||||
init.activate()
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import mcrfpy
|
|||
import sys
|
||||
import time
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
print("=" * 60)
|
||||
print("Issue #148 Regression Test: Layer Dirty Flags and Caching")
|
||||
print("=" * 60)
|
||||
|
|
@ -154,4 +154,4 @@ def run_test(runtime):
|
|||
# Initialize and run
|
||||
init = mcrfpy.Scene("init")
|
||||
init.activate()
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class CustomEntity(mcrfpy.Entity):
|
|||
def custom_method(self):
|
||||
return "Custom method called"
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Test that derived entity classes maintain their type in collections"""
|
||||
try:
|
||||
# Create a grid
|
||||
|
|
@ -85,4 +85,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -149,7 +149,7 @@ def test_color_properties():
|
|||
|
||||
return tests_passed == tests_total
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run the test"""
|
||||
try:
|
||||
success = test_color_properties()
|
||||
|
|
@ -167,4 +167,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -183,7 +183,7 @@ def test_property_introspection():
|
|||
|
||||
return tests_passed, tests_total
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run the test"""
|
||||
try:
|
||||
print("=== Testing Texture and Font Properties (Issue #99) ===\n")
|
||||
|
|
@ -221,4 +221,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -7,7 +7,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Test RenderTexture resizing"""
|
||||
print("Testing Issue #9: RenderTexture resize (minimal)")
|
||||
|
||||
|
|
@ -64,4 +64,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -209,7 +209,7 @@ def test_rendertexture_resize():
|
|||
|
||||
print(f"\nScreenshots saved to /tmp/issue_9_*.png")
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run the test"""
|
||||
try:
|
||||
test_rendertexture_resize()
|
||||
|
|
@ -226,4 +226,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -9,7 +9,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Test that UIGrid properly handles resizing"""
|
||||
try:
|
||||
# Create a grid with initial size
|
||||
|
|
@ -86,4 +86,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -64,7 +64,7 @@ def demonstrate_solution():
|
|||
}
|
||||
""")
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback"""
|
||||
try:
|
||||
demonstrate_solution()
|
||||
|
|
@ -80,4 +80,4 @@ def run_test(runtime):
|
|||
# Set up scene and run
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
@ -4,7 +4,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
from datetime import datetime
|
||||
|
||||
def run_automation_tests():
|
||||
def run_automation_tests(timer, runtime):
|
||||
"""This runs AFTER the game loop has started and rendered frames"""
|
||||
print("\n=== Automation Test Running (1 second after start) ===")
|
||||
|
||||
|
|
@ -34,13 +34,14 @@ def run_automation_tests():
|
|||
print("3. The RenderTexture now contains actual rendered content")
|
||||
|
||||
# Cancel this timer so it doesn't repeat
|
||||
mcrfpy.delTimer("automation_test")
|
||||
timer.stop()
|
||||
|
||||
# Optional: exit after a moment
|
||||
def exit_game():
|
||||
def exit_game(t, r):
|
||||
print("Exiting...")
|
||||
mcrfpy.exit()
|
||||
mcrfpy.setTimer("exit", exit_game, 500) # Exit 500ms later
|
||||
global exit_timer
|
||||
exit_timer = mcrfpy.Timer("exit", exit_game, 500, once=True)
|
||||
|
||||
# This code runs during --exec script execution
|
||||
print("=== Setting Up Test Scene ===")
|
||||
|
|
@ -73,7 +74,7 @@ frame.on_click = frame_clicked
|
|||
print("Scene setup complete. Setting timer for automation tests...")
|
||||
|
||||
# THIS IS THE KEY: Set timer to run AFTER the game loop starts
|
||||
mcrfpy.setTimer("automation_test", run_automation_tests, 1000)
|
||||
automation_test_timer = mcrfpy.Timer("automation_test", run_automation_tests, 1000, once=True)
|
||||
|
||||
print("Timer set. Game loop will start after this script completes.")
|
||||
print("Automation tests will run 1 second later when content is visible.")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import sys
|
|||
import os
|
||||
import json
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to test benchmark logging"""
|
||||
# Stop the benchmark and get filename
|
||||
try:
|
||||
|
|
@ -132,4 +132,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule test completion after ~100ms (to capture some frames)
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ print("\nTest 7: Path after potential sync")
|
|||
path4 = grid.compute_astar_path(0, 0, 5, 5)
|
||||
print(f" A* path: {path4}")
|
||||
|
||||
def timer_cb(dt):
|
||||
def timer_cb(timer, runtime):
|
||||
sys.exit(0)
|
||||
|
||||
# Quick UI setup
|
||||
ui = debug.children
|
||||
ui.append(grid)
|
||||
debug.activate()
|
||||
mcrfpy.setTimer("exit", timer_cb, 100)
|
||||
exit_timer = mcrfpy.Timer("exit", timer_cb, 100, once=True)
|
||||
|
||||
print("\nStarting timer...")
|
||||
|
|
@ -404,7 +404,7 @@ screenshots = [
|
|||
("combined_example", "ui_combined_example.png")
|
||||
]
|
||||
|
||||
def take_screenshots(runtime):
|
||||
def take_screenshots(timer, runtime):
|
||||
"""Timer callback to take screenshots sequentially"""
|
||||
global current_screenshot
|
||||
|
||||
|
|
@ -420,7 +420,7 @@ def take_screenshots(runtime):
|
|||
mcrfpy.current_scene = scene_name
|
||||
|
||||
# Take screenshot after a short delay to ensure rendering
|
||||
def capture():
|
||||
def capture(t, r):
|
||||
global current_screenshot
|
||||
full_path = f"{output_dir}/{filename}"
|
||||
result = automation.screenshot(full_path)
|
||||
|
|
@ -429,23 +429,25 @@ def take_screenshots(runtime):
|
|||
current_screenshot += 1
|
||||
|
||||
# Schedule next screenshot
|
||||
mcrfpy.setTimer("next_screenshot", take_screenshots, 200)
|
||||
global next_screenshot_timer
|
||||
next_screenshot_timer = mcrfpy.Timer("next_screenshot", take_screenshots, 200, once=True)
|
||||
|
||||
# Give scene time to render
|
||||
mcrfpy.setTimer("capture", lambda r: capture(), 100)
|
||||
global capture_timer
|
||||
capture_timer = mcrfpy.Timer("capture", capture, 100, once=True)
|
||||
|
||||
# Start with the first scene
|
||||
caption_example.activate()
|
||||
|
||||
# Start the screenshot process
|
||||
print(f"\nStarting screenshot capture of {len(screenshots)} scenes...")
|
||||
mcrfpy.setTimer("start", take_screenshots, 500)
|
||||
start_timer = mcrfpy.Timer("start", take_screenshots, 500, once=True)
|
||||
|
||||
# Safety timeout
|
||||
def safety_exit(runtime):
|
||||
def safety_exit(timer, runtime):
|
||||
print("\nERROR: Safety timeout reached! Exiting...")
|
||||
mcrfpy.exit()
|
||||
|
||||
mcrfpy.setTimer("safety", safety_exit, 30000)
|
||||
safety_timer = mcrfpy.Timer("safety", safety_exit, 30000, once=True)
|
||||
|
||||
print("Setup complete. Game loop starting...")
|
||||
|
|
@ -5,7 +5,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def capture_grid(runtime):
|
||||
def capture_grid(timer, runtime):
|
||||
"""Capture grid example after render loop starts"""
|
||||
|
||||
# Take screenshot
|
||||
|
|
@ -112,4 +112,4 @@ ui.append(info)
|
|||
grid.activate()
|
||||
|
||||
# Set timer to capture after rendering starts
|
||||
mcrfpy.setTimer("capture", capture_grid, 100)
|
||||
capture_timer = mcrfpy.Timer("capture", capture_grid, 100, once=True)
|
||||
|
|
@ -5,7 +5,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def capture_sprites(runtime):
|
||||
def capture_sprites(timer, runtime):
|
||||
"""Capture sprite examples after render loop starts"""
|
||||
|
||||
# Take screenshot
|
||||
|
|
@ -157,4 +157,4 @@ ui.append(scale_label)
|
|||
sprites.activate()
|
||||
|
||||
# Set timer to capture after rendering starts
|
||||
mcrfpy.setTimer("capture", capture_sprites, 100)
|
||||
capture_timer = mcrfpy.Timer("capture", capture_sprites, 100, once=True)
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
Test for keypressScene() validation - should reject non-callable arguments
|
||||
"""
|
||||
|
||||
def test_keypress_validation(timer_name):
|
||||
def test_keypress_validation(timer, runtime):
|
||||
"""Test that keypressScene validates its argument is callable"""
|
||||
import mcrfpy
|
||||
import sys
|
||||
|
|
@ -90,4 +90,4 @@ def test_keypress_validation(timer_name):
|
|||
|
||||
# Execute the test after a short delay
|
||||
import mcrfpy
|
||||
mcrfpy.setTimer("test", test_keypress_validation, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_keypress_validation, 100, once=True)
|
||||
|
|
@ -6,7 +6,7 @@ from mcrfpy import automation
|
|||
import sys
|
||||
import time
|
||||
|
||||
def take_screenshot(runtime):
|
||||
def take_screenshot(timer, runtime):
|
||||
"""Take screenshot after render starts"""
|
||||
print(f"Timer callback fired at runtime: {runtime}")
|
||||
|
||||
|
|
@ -41,5 +41,5 @@ test.activate()
|
|||
|
||||
# Use timer to ensure rendering has started
|
||||
print("Setting timer...")
|
||||
mcrfpy.setTimer("screenshot", take_screenshot, 500) # Wait 0.5 seconds
|
||||
mcrfpy.Timer("screenshot", take_screenshot, 500, once=True) # Wait 0.5 seconds
|
||||
print("Timer set, entering game loop...")
|
||||
|
|
@ -6,7 +6,7 @@ from mcrfpy import automation
|
|||
# Counter to track timer calls
|
||||
call_count = 0
|
||||
|
||||
def take_screenshot_and_exit():
|
||||
def take_screenshot_and_exit(timer, runtime):
|
||||
"""Timer callback that takes screenshot then exits"""
|
||||
global call_count
|
||||
call_count += 1
|
||||
|
|
@ -35,6 +35,6 @@ frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200),
|
|||
ui.append(frame)
|
||||
|
||||
print("Setting timer to fire in 100ms...")
|
||||
mcrfpy.setTimer("screenshot_timer", take_screenshot_and_exit, 100)
|
||||
mcrfpy.Timer("screenshot_timer", take_screenshot_and_exit, 100, once=True)
|
||||
|
||||
print("Setup complete. Game loop starting...")
|
||||
|
|
@ -6,6 +6,7 @@ import sys
|
|||
|
||||
# Global state to track callback
|
||||
callback_count = 0
|
||||
callback_demo = None # Will be set in setup_and_run
|
||||
|
||||
def my_callback(anim, target):
|
||||
"""Simple callback that prints when animation completes"""
|
||||
|
|
@ -16,6 +17,7 @@ def my_callback(anim, target):
|
|||
|
||||
def setup_and_run():
|
||||
"""Set up scene and run animation with callback"""
|
||||
global callback_demo
|
||||
# Create scene
|
||||
callback_demo = mcrfpy.Scene("callback_demo")
|
||||
callback_demo.activate()
|
||||
|
|
@ -31,11 +33,11 @@ def setup_and_run():
|
|||
anim.start(frame)
|
||||
|
||||
# Schedule check after animation should complete
|
||||
mcrfpy.setTimer("check", check_result, 1500)
|
||||
mcrfpy.Timer("check", check_result, 1500, once=True)
|
||||
|
||||
def check_result(runtime):
|
||||
def check_result(timer, runtime):
|
||||
"""Check if callback fired correctly"""
|
||||
global callback_count
|
||||
global callback_count, callback_demo
|
||||
|
||||
if callback_count == 1:
|
||||
print("SUCCESS: Callback fired exactly once!")
|
||||
|
|
@ -48,12 +50,12 @@ def check_result(runtime):
|
|||
anim2 = mcrfpy.Animation("y", 300.0, 0.5, "linear")
|
||||
anim2.start(frame)
|
||||
|
||||
mcrfpy.setTimer("final", final_check, 700)
|
||||
mcrfpy.Timer("final", final_check, 700, once=True)
|
||||
else:
|
||||
print(f"FAIL: Expected 1 callback, got {callback_count}")
|
||||
sys.exit(1)
|
||||
|
||||
def final_check(runtime):
|
||||
def final_check(timer, runtime):
|
||||
"""Final check - callback count should still be 1"""
|
||||
global callback_count
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ class PathAnimator:
|
|||
if self.current_index >= len(self.path):
|
||||
# Path complete
|
||||
self.animating = False
|
||||
mcrfpy.delTimer(self.check_timer_name)
|
||||
if hasattr(self, '_check_timer'):
|
||||
self._check_timer.stop()
|
||||
if self.on_complete:
|
||||
self.on_complete()
|
||||
return
|
||||
|
|
@ -56,14 +57,14 @@ class PathAnimator:
|
|||
self.entity.update_visibility()
|
||||
|
||||
# Set timer to check completion
|
||||
mcrfpy.setTimer(self.check_timer_name, self._check_completion, 50)
|
||||
self._check_timer = mcrfpy.Timer(self.check_timer_name, self._check_completion, 50)
|
||||
|
||||
def _check_completion(self, dt):
|
||||
def _check_completion(self, timer, runtime):
|
||||
"""Check if current animation is complete"""
|
||||
if hasattr(self.anim_x, 'is_complete') and self.anim_x.is_complete:
|
||||
# Move to next step
|
||||
self.current_index += 1
|
||||
mcrfpy.delTimer(self.check_timer_name)
|
||||
timer.stop()
|
||||
self._animate_next_step()
|
||||
|
||||
# Create test scene
|
||||
|
|
@ -165,7 +166,7 @@ def animate_both():
|
|||
# Camera follow test
|
||||
camera_follow = False
|
||||
|
||||
def update_camera(dt):
|
||||
def update_camera(timer, runtime):
|
||||
"""Update camera to follow player if enabled"""
|
||||
if camera_follow and player_animator and player_animator.animating:
|
||||
# Smooth camera follow
|
||||
|
|
@ -205,7 +206,7 @@ chain_test.activate()
|
|||
chain_test.on_key = handle_input
|
||||
|
||||
# Camera update timer
|
||||
mcrfpy.setTimer("cam_update", update_camera, 100)
|
||||
cam_update_timer = mcrfpy.Timer("cam_update", update_camera, 100)
|
||||
|
||||
print("Animation Chaining Test")
|
||||
print("=======================")
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ class AnimationTracker:
|
|||
|
||||
# Set timer to check completion
|
||||
check_interval = 100 # ms
|
||||
mcrfpy.setTimer(f"check_{self.name}", self._check_complete, check_interval)
|
||||
self._check_timer = mcrfpy.Timer(f"check_{self.name}", self._check_complete, check_interval)
|
||||
|
||||
def _check_complete(self, dt):
|
||||
def _check_complete(self, timer, runtime):
|
||||
"""Check if animation is complete"""
|
||||
if self.animation and hasattr(self.animation, 'is_complete') and self.animation.is_complete:
|
||||
# Log completion
|
||||
|
|
@ -56,7 +56,7 @@ class AnimationTracker:
|
|||
del active_animations[self.name]
|
||||
|
||||
# Stop checking
|
||||
mcrfpy.delTimer(f"check_{self.name}")
|
||||
timer.stop()
|
||||
|
||||
# Create test scene
|
||||
anim_debug = mcrfpy.Scene("anim_debug")
|
||||
|
|
@ -119,12 +119,13 @@ def test_rapid_fire():
|
|||
anim1.start()
|
||||
|
||||
# Start another after 500ms (before first completes)
|
||||
def start_second(dt):
|
||||
def start_second(timer, runtime):
|
||||
anim2 = AnimationTracker("rapid_2", entity, "x", 12.0, 1.0)
|
||||
anim2.start()
|
||||
mcrfpy.delTimer("rapid_timer")
|
||||
timer.stop()
|
||||
|
||||
mcrfpy.setTimer("rapid_timer", start_second, 500)
|
||||
global rapid_timer
|
||||
rapid_timer = mcrfpy.Timer("rapid_timer", start_second, 500, once=True)
|
||||
|
||||
def test_sequential():
|
||||
"""Test proper sequential animations"""
|
||||
|
|
@ -149,7 +150,7 @@ def test_sequential():
|
|||
|
||||
# Schedule next
|
||||
delay = int(duration * 1000) + 100 # Add buffer
|
||||
mcrfpy.setTimer(f"seq_timer_{index}", lambda dt: run_sequence(index + 1), delay)
|
||||
mcrfpy.Timer(f"seq_timer_{index}", lambda t, r: run_sequence(index + 1), delay, once=True)
|
||||
|
||||
run_sequence()
|
||||
|
||||
|
|
@ -163,16 +164,17 @@ def test_conflicting():
|
|||
anim1.start()
|
||||
|
||||
# After 1 second, start conflicting animation to x=2
|
||||
def start_conflict(dt):
|
||||
def start_conflict(timer, runtime):
|
||||
print("Starting conflicting animation!")
|
||||
anim2 = AnimationTracker("conflict_2", entity, "x", 2.0, 1.0)
|
||||
anim2.start()
|
||||
mcrfpy.delTimer("conflict_timer")
|
||||
timer.stop()
|
||||
|
||||
mcrfpy.setTimer("conflict_timer", start_conflict, 1000)
|
||||
global conflict_timer
|
||||
conflict_timer = mcrfpy.Timer("conflict_timer", start_conflict, 1000, once=True)
|
||||
|
||||
# Update display
|
||||
def update_display(dt):
|
||||
def update_display(timer, runtime):
|
||||
pos_display.text = f"Entity position: ({entity.x:.2f}, {entity.y:.2f})"
|
||||
active_display.text = f"Active animations: {len(active_animations)}"
|
||||
|
||||
|
|
@ -217,7 +219,7 @@ def handle_input(key, state):
|
|||
# Setup
|
||||
anim_debug.activate()
|
||||
anim_debug.on_key = handle_input
|
||||
mcrfpy.setTimer("update", update_display, 100)
|
||||
update_display_timer = mcrfpy.Timer("update", update_display, 100)
|
||||
|
||||
print("Animation Debug Tool")
|
||||
print("====================")
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ def test_8_replace_completes_old():
|
|||
test_result("Replace completes old animation", False, str(e))
|
||||
|
||||
|
||||
def run_all_tests(runtime):
|
||||
def run_all_tests(timer, runtime):
|
||||
"""Run all property locking tests"""
|
||||
print("\nRunning Animation Property Locking Tests...")
|
||||
print("-" * 50)
|
||||
|
|
@ -246,4 +246,4 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Start tests after a brief delay to allow scene to initialize
|
||||
mcrfpy.setTimer("start", run_all_tests, 100)
|
||||
mcrfpy.Timer("start", run_all_tests, 100, once=True)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ def test_4_multiple_animations_timer():
|
|||
"""Test creating multiple animations in timer callback"""
|
||||
success = False
|
||||
|
||||
def create_animations(runtime):
|
||||
def create_animations(timer, runtime):
|
||||
nonlocal success
|
||||
try:
|
||||
ui = test.children
|
||||
|
|
@ -110,15 +110,15 @@ def test_4_multiple_animations_timer():
|
|||
except Exception as e:
|
||||
print(f"Timer animation error: {e}")
|
||||
finally:
|
||||
mcrfpy.setTimer("exit", lambda t: None, 100)
|
||||
mcrfpy.Timer("exit", lambda t, r: None, 100, once=True)
|
||||
|
||||
# Clear scene
|
||||
ui = test.children
|
||||
while len(ui) > 0:
|
||||
ui.remove(len(ui) - 1)
|
||||
|
||||
mcrfpy.setTimer("test", create_animations, 50)
|
||||
mcrfpy.setTimer("check", lambda t: test_result("Multiple animations in timer", success), 200)
|
||||
mcrfpy.Timer("test", create_animations, 50, once=True)
|
||||
mcrfpy.Timer("check", lambda t, r: test_result("Multiple animations in timer", success), 200, once=True)
|
||||
|
||||
def test_5_scene_cleanup():
|
||||
"""Test that changing scenes cleans up animations"""
|
||||
|
|
@ -168,7 +168,7 @@ def test_6_animation_after_clear():
|
|||
except Exception as e:
|
||||
test_result("Animation after UI clear", False, str(e))
|
||||
|
||||
def run_all_tests(runtime):
|
||||
def run_all_tests(timer, runtime):
|
||||
"""Run all RAII tests"""
|
||||
print("\nRunning RAII Animation Tests...")
|
||||
print("-" * 40)
|
||||
|
|
@ -181,25 +181,25 @@ def run_all_tests(runtime):
|
|||
test_6_animation_after_clear()
|
||||
|
||||
# Schedule result summary
|
||||
mcrfpy.setTimer("results", print_results, 500)
|
||||
mcrfpy.Timer("results", print_results, 500, once=True)
|
||||
|
||||
def print_results(runtime):
|
||||
def print_results(timer, runtime):
|
||||
"""Print test results"""
|
||||
print("\n" + "=" * 40)
|
||||
print(f"Tests passed: {tests_passed}")
|
||||
print(f"Tests failed: {tests_failed}")
|
||||
|
||||
if tests_failed == 0:
|
||||
print("\n✓ All tests passed! RAII implementation is working correctly.")
|
||||
print("\n+ All tests passed! RAII implementation is working correctly.")
|
||||
else:
|
||||
print(f"\n✗ {tests_failed} tests failed.")
|
||||
print(f"\nx {tests_failed} tests failed.")
|
||||
print("\nFailed tests:")
|
||||
for name, passed, details in test_results:
|
||||
if not passed:
|
||||
print(f" - {name}: {details}")
|
||||
|
||||
# Exit
|
||||
mcrfpy.setTimer("exit", lambda t: sys.exit(0 if tests_failed == 0 else 1), 500)
|
||||
mcrfpy.Timer("exit", lambda t, r: sys.exit(0 if tests_failed == 0 else 1), 500, once=True)
|
||||
|
||||
# Setup and run
|
||||
test = mcrfpy.Scene("test")
|
||||
|
|
@ -212,4 +212,4 @@ bg.fill_color = mcrfpy.Color(20, 20, 30)
|
|||
ui.append(bg)
|
||||
|
||||
# Start tests
|
||||
mcrfpy.setTimer("start", run_all_tests, 100)
|
||||
start_timer = mcrfpy.Timer("start", run_all_tests, 100, once=True)
|
||||
|
|
@ -6,7 +6,7 @@ Test if the crash is related to removing animated objects
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def clear_and_recreate(runtime):
|
||||
def clear_and_recreate(timer, runtime):
|
||||
"""Clear UI and recreate - mimics demo switching"""
|
||||
print(f"\nTimer called at {runtime}")
|
||||
|
||||
|
|
@ -33,7 +33,8 @@ def clear_and_recreate(runtime):
|
|||
print("New objects created and animated")
|
||||
|
||||
# Schedule exit
|
||||
mcrfpy.setTimer("exit", lambda t: sys.exit(0), 2000)
|
||||
global exit_timer
|
||||
exit_timer = mcrfpy.Timer("exit", lambda t, r: sys.exit(0), 2000, once=True)
|
||||
|
||||
# Create initial scene
|
||||
print("Creating scene...")
|
||||
|
|
@ -60,6 +61,6 @@ for i in range(10):
|
|||
print(f"Initial scene has {len(ui)} elements")
|
||||
|
||||
# Schedule the clear and recreate
|
||||
mcrfpy.setTimer("switch", clear_and_recreate, 1000)
|
||||
switch_timer = mcrfpy.Timer("switch", clear_and_recreate, 1000, once=True)
|
||||
|
||||
print("\nEntering game loop...")
|
||||
|
|
@ -114,7 +114,7 @@ print(" - Empty paths returned for blocked destinations")
|
|||
print(" - Diagonal movement supported")
|
||||
|
||||
# Quick visual test
|
||||
def visual_test(runtime):
|
||||
def visual_test(timer, runtime):
|
||||
print("\nVisual test timer fired")
|
||||
sys.exit(0)
|
||||
|
||||
|
|
@ -125,6 +125,6 @@ grid.position = (50, 50)
|
|||
grid.size = (400, 400)
|
||||
|
||||
astar_test.activate()
|
||||
mcrfpy.setTimer("visual", visual_test, 100)
|
||||
visual_test_timer = mcrfpy.Timer("visual", visual_test, 100, once=True)
|
||||
|
||||
print("\nStarting visual test...")
|
||||
|
|
@ -6,7 +6,7 @@ Test #94: Color helper methods - from_hex, to_hex, lerp
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def test_color_helpers(runtime):
|
||||
def test_color_helpers(timer, runtime):
|
||||
"""Test Color helper methods"""
|
||||
|
||||
all_pass = True
|
||||
|
|
@ -179,4 +179,4 @@ def test_color_helpers(runtime):
|
|||
|
||||
# Run test
|
||||
test = mcrfpy.Scene("test")
|
||||
mcrfpy.setTimer("test", test_color_helpers, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_color_helpers, 100, once=True)
|
||||
|
|
@ -183,7 +183,7 @@ def test_multi_target_scenario():
|
|||
cell.tilesprite = 83 # S for safe
|
||||
grid._color_layer.set(best_pos[0], best_pos[1], mcrfpy.Color(0, 255, 0))
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Timer callback to run tests after scene loads"""
|
||||
test_basic_dijkstra()
|
||||
test_libtcod_interface()
|
||||
|
|
@ -221,7 +221,7 @@ title.fill_color = mcrfpy.Color(255, 255, 255)
|
|||
ui.append(title)
|
||||
|
||||
# Set timer to run tests
|
||||
mcrfpy.setTimer("test", run_test, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 100, once=True)
|
||||
|
||||
# Show scene
|
||||
dijkstra_test.activate()
|
||||
|
|
@ -20,7 +20,7 @@ def test_method_docs():
|
|||
'createSoundBuffer', 'loadMusic', 'setMusicVolume', 'setSoundVolume',
|
||||
'playSound', 'getMusicVolume', 'getSoundVolume', 'sceneUI',
|
||||
'currentScene', 'setScene', 'createScene', 'keypressScene',
|
||||
'setTimer', 'delTimer', 'exit', 'setScale', 'find', 'findAll',
|
||||
'exit', 'setScale', 'find', 'findAll',
|
||||
'getMetrics'
|
||||
]
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ def test_class_docs():
|
|||
"""Test class documentation."""
|
||||
print("=== Class Documentation ===")
|
||||
|
||||
classes = ['Frame', 'Caption', 'Sprite', 'Grid', 'Entity', 'Color', 'Vector', 'Texture', 'Font']
|
||||
classes = ['Frame', 'Caption', 'Sprite', 'Grid', 'Entity', 'Color', 'Vector', 'Texture', 'Font', 'Timer']
|
||||
|
||||
for class_name in classes:
|
||||
if hasattr(mcrfpy, class_name):
|
||||
|
|
@ -80,12 +80,12 @@ def test_method_signatures():
|
|||
else:
|
||||
print("✗ setScene signature incorrect or missing")
|
||||
|
||||
if hasattr(mcrfpy, 'setTimer'):
|
||||
doc = mcrfpy.setTimer.__doc__
|
||||
if doc and 'setTimer(name: str, handler: callable, interval: int)' in doc:
|
||||
print("✓ setTimer signature correct")
|
||||
if hasattr(mcrfpy, 'Timer'):
|
||||
doc = mcrfpy.Timer.__doc__
|
||||
if doc and 'Timer' in doc:
|
||||
print("+ Timer class documentation present")
|
||||
else:
|
||||
print("✗ setTimer signature incorrect or missing")
|
||||
print("x Timer class documentation missing")
|
||||
|
||||
if hasattr(mcrfpy, 'find'):
|
||||
doc = mcrfpy.find.__doc__
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ test.activate()
|
|||
print("Scene created, no animations added")
|
||||
print("Starting game loop in 100ms...")
|
||||
|
||||
def check_alive(runtime):
|
||||
def check_alive(timer, runtime):
|
||||
print(f"Timer fired at {runtime}ms - AnimationManager survived!")
|
||||
mcrfpy.setTimer("exit", lambda t: mcrfpy.exit(), 100)
|
||||
mcrfpy.Timer("exit", lambda t, r: mcrfpy.exit(), 100, once=True)
|
||||
|
||||
mcrfpy.setTimer("check", check_alive, 1000)
|
||||
mcrfpy.Timer("check", check_alive, 1000, once=True)
|
||||
print("If this crashes immediately, AnimationManager has an issue with empty state")
|
||||
|
|
@ -77,7 +77,7 @@ current_waypoint = 0
|
|||
animating = False
|
||||
waypoints = [(5,5), (10,5), (10,10), (5,10), (5,5)]
|
||||
|
||||
def update_position_display(dt):
|
||||
def update_position_display(timer, runtime):
|
||||
"""Update position display every 200ms"""
|
||||
pos_display.text = f"Entity Position: ({entity.x:.2f}, {entity.y:.2f})"
|
||||
|
||||
|
|
@ -126,7 +126,8 @@ def animate_to_next_waypoint():
|
|||
current_waypoint += 1
|
||||
|
||||
# Schedule next waypoint
|
||||
mcrfpy.setTimer("next_waypoint", lambda dt: animate_to_next_waypoint(), int(duration * 1000 + 100))
|
||||
global next_waypoint_timer
|
||||
next_waypoint_timer = mcrfpy.Timer("next_waypoint", lambda t, r: animate_to_next_waypoint(), int(duration * 1000 + 100), once=True)
|
||||
|
||||
def start_animation():
|
||||
"""Start or restart the animation sequence"""
|
||||
|
|
@ -186,7 +187,7 @@ test_anim.activate()
|
|||
test_anim.on_key = handle_input
|
||||
|
||||
# Start position update timer
|
||||
mcrfpy.setTimer("update_pos", update_position_display, 200)
|
||||
update_pos_timer = mcrfpy.Timer("update_pos", update_position_display, 200)
|
||||
|
||||
# No perspective (omniscient view)
|
||||
grid.perspective = -1
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ status.fill_color = mcrfpy.Color(200, 200, 200)
|
|||
ui.append(status)
|
||||
|
||||
# Update display
|
||||
def update_display(dt):
|
||||
def update_display(timer, runtime):
|
||||
pos_info.text = f"Entity Grid Position: ({entity.x:.2f}, {entity.y:.2f})"
|
||||
# We can't access sprite position from Python, but in C++ it would show
|
||||
# the issue: sprite position would be (2, 2) instead of pixel coords
|
||||
|
|
@ -113,7 +113,7 @@ def handle_input(key, state):
|
|||
# Setup
|
||||
fix_demo.activate()
|
||||
fix_demo.on_key = handle_input
|
||||
mcrfpy.setTimer("update", update_display, 100)
|
||||
update_timer = mcrfpy.Timer("update", update_display, 100)
|
||||
|
||||
print("Ready to demonstrate the issue.")
|
||||
print()
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import sys
|
|||
# Module-level state to avoid closures
|
||||
_test_state = {}
|
||||
|
||||
def take_second_screenshot(runtime):
|
||||
def take_second_screenshot(timer, runtime):
|
||||
"""Take final screenshot and exit"""
|
||||
mcrfpy.delTimer("screenshot2")
|
||||
timer.stop()
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_animated.png")
|
||||
print("\nTest completed successfully!")
|
||||
|
|
@ -19,20 +19,21 @@ def take_second_screenshot(runtime):
|
|||
print(" - frame_clipping_animated.png (with animation)")
|
||||
sys.exit(0)
|
||||
|
||||
def animate_frames(runtime):
|
||||
def animate_frames(timer, runtime):
|
||||
"""Animate frames to demonstrate clipping"""
|
||||
mcrfpy.delTimer("animate")
|
||||
timer.stop()
|
||||
scene = test.children
|
||||
# Move child frames
|
||||
parent1 = scene[0]
|
||||
parent2 = scene[1]
|
||||
parent1.children[1].x = 50
|
||||
parent2.children[1].x = 50
|
||||
mcrfpy.setTimer("screenshot2", take_second_screenshot, 500)
|
||||
global screenshot2_timer
|
||||
screenshot2_timer = mcrfpy.Timer("screenshot2", take_second_screenshot, 500, once=True)
|
||||
|
||||
def test_clipping(runtime):
|
||||
def test_clipping(timer, runtime):
|
||||
"""Test that clip_children property works correctly"""
|
||||
mcrfpy.delTimer("test_clipping")
|
||||
timer.stop()
|
||||
|
||||
print("Testing UIFrame clipping functionality...")
|
||||
|
||||
|
|
@ -115,7 +116,8 @@ def test_clipping(runtime):
|
|||
print(f"PASS: clip_children correctly rejected non-boolean: {e}")
|
||||
|
||||
# Start animation after a short delay
|
||||
mcrfpy.setTimer("animate", animate_frames, 100)
|
||||
global animate_timer
|
||||
animate_timer = mcrfpy.Timer("animate", animate_frames, 100, once=True)
|
||||
|
||||
def handle_keypress(key, modifiers):
|
||||
if key == "c":
|
||||
|
|
@ -129,5 +131,5 @@ print("Creating test scene...")
|
|||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
test.on_key = handle_keypress
|
||||
mcrfpy.setTimer("test_clipping", test_clipping, 100)
|
||||
test_clipping_timer = mcrfpy.Timer("test_clipping", test_clipping, 100, once=True)
|
||||
print("Test scheduled, running...")
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import mcrfpy
|
|||
from mcrfpy import Color, Frame, Caption, Vector
|
||||
import sys
|
||||
|
||||
def test_nested_clipping(runtime):
|
||||
def test_nested_clipping(timer, runtime):
|
||||
"""Test nested frames with clipping"""
|
||||
mcrfpy.delTimer("test_nested_clipping")
|
||||
timer.stop()
|
||||
|
||||
print("Testing advanced UIFrame clipping with nested frames...")
|
||||
|
||||
|
|
@ -62,8 +62,8 @@ def test_nested_clipping(runtime):
|
|||
print(f"Inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Dynamically resize frames to test RenderTexture recreation
|
||||
def resize_test(runtime):
|
||||
mcrfpy.delTimer("resize_test")
|
||||
def resize_test(timer, runtime):
|
||||
timer.stop()
|
||||
print("Resizing frames to test RenderTexture recreation...")
|
||||
outer.w = 450
|
||||
outer.h = 350
|
||||
|
|
@ -73,10 +73,11 @@ def test_nested_clipping(runtime):
|
|||
print(f"New inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Take screenshot after resize
|
||||
mcrfpy.setTimer("screenshot_resize", take_resize_screenshot, 500)
|
||||
global screenshot_resize_timer
|
||||
screenshot_resize_timer = mcrfpy.Timer("screenshot_resize", take_resize_screenshot, 500, once=True)
|
||||
|
||||
def take_resize_screenshot(runtime):
|
||||
mcrfpy.delTimer("screenshot_resize")
|
||||
def take_resize_screenshot(timer, runtime):
|
||||
timer.stop()
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_resized.png")
|
||||
print("\nAdvanced test completed!")
|
||||
|
|
@ -90,7 +91,8 @@ def test_nested_clipping(runtime):
|
|||
print("Initial screenshot saved: frame_clipping_nested.png")
|
||||
|
||||
# Schedule resize test
|
||||
mcrfpy.setTimer("resize_test", resize_test, 1000)
|
||||
global resize_test_timer
|
||||
resize_test_timer = mcrfpy.Timer("resize_test", resize_test, 1000, once=True)
|
||||
|
||||
# Main execution
|
||||
print("Creating advanced test scene...")
|
||||
|
|
@ -98,6 +100,6 @@ test = mcrfpy.Scene("test")
|
|||
test.activate()
|
||||
|
||||
# Schedule the test
|
||||
mcrfpy.setTimer("test_nested_clipping", test_nested_clipping, 100)
|
||||
test_nested_clipping_timer = mcrfpy.Timer("test_nested_clipping", test_nested_clipping, 100, once=True)
|
||||
|
||||
print("Advanced test scheduled, running...")
|
||||
|
|
@ -42,25 +42,25 @@ def test_grid_background():
|
|||
# Activate the scene
|
||||
test.activate()
|
||||
|
||||
def run_tests(dt):
|
||||
def run_tests(timer, runtime):
|
||||
"""Run background color tests"""
|
||||
mcrfpy.delTimer("run_tests")
|
||||
timer.stop()
|
||||
|
||||
print("\nTest 1: Default background color")
|
||||
default_color = grid.background_color
|
||||
print(f"Default: R={default_color.r}, G={default_color.g}, B={default_color.b}, A={default_color.a}")
|
||||
color_display.text = f"R:{default_color.r} G:{default_color.g} B:{default_color.b}"
|
||||
|
||||
def test_set_color(dt):
|
||||
mcrfpy.delTimer("test_set")
|
||||
def test_set_color(timer, runtime):
|
||||
timer.stop()
|
||||
print("\nTest 2: Set background to blue")
|
||||
grid.background_color = mcrfpy.Color(20, 40, 100)
|
||||
new_color = grid.background_color
|
||||
print(f"✓ Set to: R={new_color.r}, G={new_color.g}, B={new_color.b}")
|
||||
print(f"+ Set to: R={new_color.r}, G={new_color.g}, B={new_color.b}")
|
||||
color_display.text = f"R:{new_color.r} G:{new_color.g} B:{new_color.b}"
|
||||
|
||||
def test_animation(dt):
|
||||
mcrfpy.delTimer("test_anim")
|
||||
def test_animation(timer, runtime):
|
||||
timer.stop()
|
||||
print("\nTest 3: Manual color cycling")
|
||||
# Manually change color to test property is working
|
||||
colors = [
|
||||
|
|
@ -71,39 +71,39 @@ def test_grid_background():
|
|||
|
||||
color_index = [0] # Use list to allow modification in nested function
|
||||
|
||||
def cycle_red(dt):
|
||||
mcrfpy.delTimer("cycle_0")
|
||||
def cycle_red(t, r):
|
||||
t.stop()
|
||||
grid.background_color = colors[0]
|
||||
c = grid.background_color
|
||||
color_display.text = f"R:{c.r} G:{c.g} B:{c.b}"
|
||||
print(f"✓ Set to Red: R={c.r}, G={c.g}, B={c.b}")
|
||||
print(f"+ Set to Red: R={c.r}, G={c.g}, B={c.b}")
|
||||
|
||||
def cycle_green(dt):
|
||||
mcrfpy.delTimer("cycle_1")
|
||||
def cycle_green(t, r):
|
||||
t.stop()
|
||||
grid.background_color = colors[1]
|
||||
c = grid.background_color
|
||||
color_display.text = f"R:{c.r} G:{c.g} B:{c.b}"
|
||||
print(f"✓ Set to Green: R={c.r}, G={c.g}, B={c.b}")
|
||||
print(f"+ Set to Green: R={c.r}, G={c.g}, B={c.b}")
|
||||
|
||||
def cycle_blue(dt):
|
||||
mcrfpy.delTimer("cycle_2")
|
||||
def cycle_blue(t, r):
|
||||
t.stop()
|
||||
grid.background_color = colors[2]
|
||||
c = grid.background_color
|
||||
color_display.text = f"R:{c.r} G:{c.g} B:{c.b}"
|
||||
print(f"✓ Set to Blue: R={c.r}, G={c.g}, B={c.b}")
|
||||
print(f"+ Set to Blue: R={c.r}, G={c.g}, B={c.b}")
|
||||
|
||||
# Cycle through colors
|
||||
mcrfpy.setTimer("cycle_0", cycle_red, 100)
|
||||
mcrfpy.setTimer("cycle_1", cycle_green, 400)
|
||||
mcrfpy.setTimer("cycle_2", cycle_blue, 700)
|
||||
mcrfpy.Timer("cycle_0", cycle_red, 100, once=True)
|
||||
mcrfpy.Timer("cycle_1", cycle_green, 400, once=True)
|
||||
mcrfpy.Timer("cycle_2", cycle_blue, 700, once=True)
|
||||
|
||||
def test_complete(dt):
|
||||
mcrfpy.delTimer("complete")
|
||||
def test_complete(timer, runtime):
|
||||
timer.stop()
|
||||
print("\nTest 4: Final color check")
|
||||
final_color = grid.background_color
|
||||
print(f"Final: R={final_color.r}, G={final_color.g}, B={final_color.b}")
|
||||
|
||||
print("\n✓ Grid background color tests completed!")
|
||||
print("\n+ Grid background color tests completed!")
|
||||
print("- Default background color works")
|
||||
print("- Setting background color works")
|
||||
print("- Color cycling works")
|
||||
|
|
@ -111,12 +111,12 @@ def test_grid_background():
|
|||
sys.exit(0)
|
||||
|
||||
# Schedule tests
|
||||
mcrfpy.setTimer("test_set", test_set_color, 1000)
|
||||
mcrfpy.setTimer("test_anim", test_animation, 2000)
|
||||
mcrfpy.setTimer("complete", test_complete, 4500)
|
||||
mcrfpy.Timer("test_set", test_set_color, 1000, once=True)
|
||||
mcrfpy.Timer("test_anim", test_animation, 2000, once=True)
|
||||
mcrfpy.Timer("complete", test_complete, 4500, once=True)
|
||||
|
||||
# Start tests
|
||||
mcrfpy.setTimer("run_tests", run_tests, 100)
|
||||
mcrfpy.Timer("run_tests", run_tests, 100, once=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_grid_background()
|
||||
|
|
@ -4,18 +4,18 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def take_screenshot(runtime):
|
||||
def take_screenshot(timer, runtime):
|
||||
"""Take screenshot after render completes"""
|
||||
mcrfpy.delTimer("screenshot")
|
||||
timer.stop()
|
||||
automation.screenshot("test_grid_children_result.png")
|
||||
|
||||
print("Screenshot saved to test_grid_children_result.png")
|
||||
print("PASS - Grid.children test completed")
|
||||
sys.exit(0)
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Main test - runs after scene is set up"""
|
||||
mcrfpy.delTimer("test")
|
||||
timer.stop()
|
||||
|
||||
# Get the scene UI
|
||||
ui = test.children
|
||||
|
|
@ -119,11 +119,11 @@ def run_test(runtime):
|
|||
print(f"\nFinal children count: {len(grid.children)}")
|
||||
|
||||
# Schedule screenshot for next frame
|
||||
mcrfpy.setTimer("screenshot", take_screenshot, 100)
|
||||
mcrfpy.Timer("screenshot", take_screenshot, 100, once=True)
|
||||
|
||||
# Create a test scene
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 50)
|
||||
mcrfpy.Timer("test", run_test, 50, once=True)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200))
|
|||
frame.fill_color = mcrfpy.Color(255, 100, 100, 255)
|
||||
ui.append(frame)
|
||||
|
||||
def test_mode(runtime):
|
||||
def test_mode(timer, runtime):
|
||||
try:
|
||||
# Try to take a screenshot - this should work in both modes
|
||||
automation.screenshot("test_screenshot.png")
|
||||
|
|
@ -36,4 +36,4 @@ def test_mode(runtime):
|
|||
sys.exit(0)
|
||||
|
||||
# Run test after render loop starts
|
||||
mcrfpy.setTimer("test", test_mode, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_mode, 100, once=True)
|
||||
|
|
@ -22,8 +22,8 @@ ui.append(caption)
|
|||
print("Script started. Window should appear unless --headless was specified.")
|
||||
|
||||
# Exit after 2 seconds
|
||||
def exit_test(runtime):
|
||||
def exit_test(timer, runtime):
|
||||
print("Test complete. Exiting.")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("exit", exit_test, 2000)
|
||||
exit_timer = mcrfpy.Timer("exit", exit_test, 2000, once=True)
|
||||
|
|
@ -5,8 +5,12 @@ import mcrfpy
|
|||
import sys
|
||||
import time
|
||||
|
||||
def test_metrics(runtime):
|
||||
# Track success across callbacks
|
||||
success = True
|
||||
|
||||
def test_metrics(timer, runtime):
|
||||
"""Test the metrics after timer starts"""
|
||||
global success
|
||||
print("\nRunning metrics test...")
|
||||
|
||||
# Get metrics
|
||||
|
|
@ -23,7 +27,6 @@ def test_metrics(runtime):
|
|||
print(f" Runtime: {metrics['runtime']:.2f} seconds")
|
||||
|
||||
# Test that metrics are reasonable
|
||||
success = True
|
||||
|
||||
# Frame time should be positive
|
||||
if metrics['frame_time'] <= 0:
|
||||
|
|
@ -71,8 +74,13 @@ def test_metrics(runtime):
|
|||
# Test metrics update over multiple frames
|
||||
print("\n\nTesting metrics over multiple frames...")
|
||||
|
||||
# Store initial metrics for comparison
|
||||
initial_frame = metrics['current_frame']
|
||||
initial_runtime = metrics['runtime']
|
||||
|
||||
# Schedule another check after 100ms
|
||||
def check_later(runtime2):
|
||||
def check_later(timer2, runtime2):
|
||||
global success
|
||||
metrics2 = mcrfpy.getMetrics()
|
||||
|
||||
print(f"\nMetrics after 100ms:")
|
||||
|
|
@ -82,15 +90,14 @@ def test_metrics(runtime):
|
|||
print(f" Current Frame: {metrics2['current_frame']}")
|
||||
|
||||
# Frame count should have increased
|
||||
if metrics2['current_frame'] > metrics['current_frame']:
|
||||
if metrics2['current_frame'] > initial_frame:
|
||||
print(" PASS: Frame count increased")
|
||||
else:
|
||||
print(" FAIL: Frame count did not increase")
|
||||
nonlocal success
|
||||
success = False
|
||||
|
||||
# Runtime should have increased
|
||||
if metrics2['runtime'] > metrics['runtime']:
|
||||
if metrics2['runtime'] > initial_runtime:
|
||||
print(" PASS: Runtime increased")
|
||||
else:
|
||||
print(" FAIL: Runtime did not increase")
|
||||
|
|
@ -104,7 +111,7 @@ def test_metrics(runtime):
|
|||
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
mcrfpy.setTimer("check_later", check_later, 100)
|
||||
mcrfpy.Timer("check_later", check_later, 100, once=True)
|
||||
|
||||
# Set up test scene
|
||||
print("Setting up metrics test scene...")
|
||||
|
|
@ -136,4 +143,4 @@ ui.append(grid)
|
|||
print(f"Created {len(ui)} UI elements (1 invisible)")
|
||||
|
||||
# Schedule test to run after render loop starts
|
||||
mcrfpy.setTimer("test", test_metrics, 50)
|
||||
mcrfpy.Timer("test", test_metrics, 50, once=True)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ This verifies the fix for requiring arguments even with safe default constructor
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def test_ui_constructors(runtime):
|
||||
def test_ui_constructors(timer, runtime):
|
||||
"""Test that UI classes can be instantiated without arguments"""
|
||||
|
||||
print("Testing UI class instantiation without arguments...")
|
||||
|
|
@ -88,4 +88,4 @@ def test_ui_constructors(runtime):
|
|||
test = mcrfpy.Scene("test")
|
||||
|
||||
# Schedule the test to run after game initialization
|
||||
mcrfpy.setTimer("test", test_ui_constructors, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_ui_constructors, 100, once=True)
|
||||
|
|
@ -63,7 +63,7 @@ for y in range(5):
|
|||
print("\nIf colors are changing in data but not visually, it may be a rendering issue.")
|
||||
|
||||
# Quick visual test
|
||||
def check_visual(runtime):
|
||||
def check_visual(timer, runtime):
|
||||
print("\nTimer fired - checking if scene is rendering...")
|
||||
# Take screenshot to see actual rendering
|
||||
try:
|
||||
|
|
@ -81,6 +81,6 @@ grid.position = (50, 50)
|
|||
grid.size = (250, 250)
|
||||
|
||||
test.activate()
|
||||
mcrfpy.setTimer("check", check_visual, 500)
|
||||
check_timer = mcrfpy.Timer("check", check_visual, 500, once=True)
|
||||
|
||||
print("\nStarting render test...")
|
||||
|
|
@ -48,11 +48,11 @@ print("\n✓ Pathfinding integration working correctly!")
|
|||
print("Enhanced demos are ready for interactive use.")
|
||||
|
||||
# Quick animation test
|
||||
def test_timer(dt):
|
||||
print(f"Timer callback received: dt={dt}ms")
|
||||
def test_timer(timer, runtime):
|
||||
print(f"Timer callback received: runtime={runtime}ms")
|
||||
sys.exit(0)
|
||||
|
||||
# Set a quick timer to test animation system
|
||||
mcrfpy.setTimer("test", test_timer, 100)
|
||||
timer = mcrfpy.Timer("test", test_timer, 100, once=True)
|
||||
|
||||
print("\nTesting timer system for animations...")
|
||||
|
|
@ -3,8 +3,8 @@
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def test_properties(runtime):
|
||||
mcrfpy.delTimer("test_properties")
|
||||
def test_properties(timer, runtime):
|
||||
timer.stop()
|
||||
|
||||
print("\n=== Testing Properties ===")
|
||||
|
||||
|
|
@ -54,4 +54,4 @@ def test_properties(runtime):
|
|||
sys.exit(0)
|
||||
|
||||
test = mcrfpy.Scene("test")
|
||||
mcrfpy.setTimer("test_properties", test_properties, 100)
|
||||
test_properties_timer = mcrfpy.Timer("test_properties", test_properties, 100, once=True)
|
||||
|
|
@ -21,7 +21,7 @@ def test(condition, message):
|
|||
test_results.append(f"✗ {message}")
|
||||
test_passed = False
|
||||
|
||||
def run_tests(runtime):
|
||||
def run_tests(timer, runtime):
|
||||
"""Timer callback to run tests after game loop starts"""
|
||||
global test_passed
|
||||
|
||||
|
|
@ -146,6 +146,6 @@ test_scene = mcrfpy.Scene("test_scene")
|
|||
test_scene.activate()
|
||||
|
||||
# Schedule tests to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_tests, 100)
|
||||
test_timer = mcrfpy.Timer("test", run_tests, 100, once=True)
|
||||
|
||||
print("Python object cache test initialized. Running tests...")
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ for s in (red_scene, blue_scene, green_scene, menu_scene):
|
|||
|
||||
# Option to run automatic test
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--auto":
|
||||
mcrfpy.setTimer("auto_test", test_automatic_transitions, 1000)
|
||||
mcrfpy.Timer("auto_test", lambda t, r: test_automatic_transitions(r), 1000, once=True)
|
||||
else:
|
||||
print("\nManual test mode. Use keyboard controls shown on screen.")
|
||||
print("Run with --auto flag for automatic transition demo.")
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@ test.activate()
|
|||
e = mcrfpy.Entity((0, 0), texture=None, sprite_index=0)
|
||||
a = mcrfpy.Animation("x", 1.0, 0.1, "linear", callback=cb)
|
||||
a.start(e)
|
||||
mcrfpy.setTimer("exit", lambda r: sys.exit(0), 200)
|
||||
mcrfpy.Timer("exit", lambda t, r: sys.exit(0), 200, once=True)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def simple_test(runtime):
|
||||
mcrfpy.delTimer("simple_test")
|
||||
def simple_test(timer, runtime):
|
||||
timer.stop()
|
||||
|
||||
try:
|
||||
# Test basic functionality
|
||||
|
|
@ -27,4 +27,4 @@ def simple_test(runtime):
|
|||
sys.exit(0)
|
||||
|
||||
test = mcrfpy.Scene("test")
|
||||
mcrfpy.setTimer("simple_test", simple_test, 100)
|
||||
simple_test_timer = mcrfpy.Timer("simple_test", simple_test, 100, once=True)
|
||||
|
|
@ -90,7 +90,7 @@ def create_demo():
|
|||
text_demo.activate()
|
||||
|
||||
# Run demo test
|
||||
def run_test(timer_name):
|
||||
def run_test(timer, runtime):
|
||||
print("\n=== Text Input Widget Test ===")
|
||||
print("Features:")
|
||||
print("- Click to focus fields")
|
||||
|
|
@ -103,7 +103,7 @@ def create_demo():
|
|||
print("- Press Escape to exit")
|
||||
print("\nTry it out!")
|
||||
|
||||
mcrfpy.setTimer("info", run_test, 100)
|
||||
info_timer = mcrfpy.Timer("info", run_test, 100, once=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1,34 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test timer callback arguments
|
||||
Test timer callback arguments with new Timer API (#173)
|
||||
"""
|
||||
import mcrfpy
|
||||
import sys
|
||||
|
||||
call_count = 0
|
||||
|
||||
def old_style_callback(arg):
|
||||
"""Old style callback - should receive just runtime"""
|
||||
def new_style_callback(timer, runtime):
|
||||
"""New style callback - receives timer object and runtime"""
|
||||
global call_count
|
||||
call_count += 1
|
||||
print(f"Old style callback called with: {arg} (type: {type(arg)})")
|
||||
print(f"Callback called with: timer={timer} (type: {type(timer)}), runtime={runtime} (type: {type(runtime)})")
|
||||
if hasattr(timer, 'once'):
|
||||
print(f"Got Timer object! once={timer.once}")
|
||||
if call_count >= 2:
|
||||
sys.exit(0)
|
||||
|
||||
def new_style_callback(arg1, arg2=None):
|
||||
"""New style callback - should receive timer object and runtime"""
|
||||
print(f"New style callback called with: arg1={arg1} (type: {type(arg1)}), arg2={arg2} (type: {type(arg2) if arg2 else 'None'})")
|
||||
if hasattr(arg1, 'once'):
|
||||
print(f"Got Timer object! once={arg1.once}")
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
|
||||
# Set up the scene
|
||||
test_scene = mcrfpy.Scene("test_scene")
|
||||
test_scene.activate()
|
||||
|
||||
print("Testing old style timer with setTimer...")
|
||||
mcrfpy.setTimer("old_timer", old_style_callback, 100)
|
||||
|
||||
print("\nTesting new style timer with Timer object...")
|
||||
timer = mcrfpy.Timer("new_timer", new_style_callback, 200)
|
||||
print("Testing new Timer callback signature (timer, runtime)...")
|
||||
timer = mcrfpy.Timer("test_timer", new_style_callback, 100)
|
||||
print(f"Timer created: {timer}")
|
||||
|
|
@ -1,26 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test legacy timer API still works
|
||||
Test Timer API works correctly (#173)
|
||||
Replaces old legacy setTimer test
|
||||
"""
|
||||
import mcrfpy
|
||||
import sys
|
||||
|
||||
count = 0
|
||||
|
||||
def timer_callback(runtime):
|
||||
def timer_callback(timer, runtime):
|
||||
global count
|
||||
count += 1
|
||||
print(f"Timer fired! Count: {count}, Runtime: {runtime}")
|
||||
|
||||
if count >= 3:
|
||||
print("Test passed - timer fired 3 times")
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
|
||||
# Set up the scene
|
||||
test_scene = mcrfpy.Scene("test_scene")
|
||||
test_scene.activate()
|
||||
|
||||
# Create a timer the old way
|
||||
mcrfpy.setTimer("test_timer", timer_callback, 100)
|
||||
# Create a timer with new API
|
||||
timer = mcrfpy.Timer("test_timer", timer_callback, 100)
|
||||
|
||||
print("Legacy timer test starting...")
|
||||
print("Timer test starting...")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test the new mcrfpy.Timer object with pause/resume/cancel functionality
|
||||
Test the new mcrfpy.Timer object with pause/resume/stop functionality
|
||||
Updated for new Timer API (#173)
|
||||
"""
|
||||
import mcrfpy
|
||||
import sys
|
||||
|
|
@ -25,10 +26,10 @@ def cancel_test_callback(timer, runtime):
|
|||
cancel_test_count += 1
|
||||
print(f"Cancel test timer: {cancel_test_count} - This should only print once!")
|
||||
|
||||
def run_tests(runtime):
|
||||
def run_tests(timer, runtime):
|
||||
"""Main test function that runs after game loop starts"""
|
||||
# Delete the timer that called us to prevent re-running
|
||||
mcrfpy.delTimer("run_tests")
|
||||
# Stop the timer that called us to prevent re-running
|
||||
timer.stop()
|
||||
|
||||
print("\n=== Testing mcrfpy.Timer object ===\n")
|
||||
|
||||
|
|
@ -45,35 +46,34 @@ def run_tests(runtime):
|
|||
timer2 = mcrfpy.Timer("pause_test", pause_test_callback, 200)
|
||||
|
||||
# Schedule pause after 250ms
|
||||
def pause_timer2(runtime):
|
||||
def pause_timer2(t, rt):
|
||||
print(" Pausing timer2...")
|
||||
timer2.pause()
|
||||
print(f" Timer2 paused: {timer2.paused}")
|
||||
print(f" Timer2 active: {timer2.active}")
|
||||
|
||||
# Schedule resume after another 400ms
|
||||
def resume_timer2(runtime):
|
||||
def resume_timer2(t2, rt2):
|
||||
print(" Resuming timer2...")
|
||||
timer2.resume()
|
||||
print(f" Timer2 paused: {timer2.paused}")
|
||||
print(f" Timer2 active: {timer2.active}")
|
||||
|
||||
mcrfpy.setTimer("resume_timer2", resume_timer2, 400)
|
||||
mcrfpy.Timer("resume_timer2", resume_timer2, 400, once=True)
|
||||
|
||||
mcrfpy.setTimer("pause_timer2", pause_timer2, 250)
|
||||
mcrfpy.Timer("pause_timer2", pause_timer2, 250, once=True)
|
||||
|
||||
# Test 3: Test cancel
|
||||
print("\nTest 3: Testing cancel functionality")
|
||||
# Test 3: Test cancel/stop
|
||||
print("\nTest 3: Testing stop functionality")
|
||||
timer3 = mcrfpy.Timer("cancel_test", cancel_test_callback, 300)
|
||||
|
||||
# Cancel after 350ms (should fire once)
|
||||
def cancel_timer3(runtime):
|
||||
mcrfpy.delTimer("cancel_timer3") # Make this a one-shot timer
|
||||
print(" Canceling timer3...")
|
||||
timer3.cancel()
|
||||
print(" Timer3 canceled")
|
||||
def cancel_timer3(t, rt):
|
||||
print(" Stopping timer3...")
|
||||
timer3.stop()
|
||||
print(" Timer3 stopped")
|
||||
|
||||
mcrfpy.setTimer("cancel_timer3", cancel_timer3, 350)
|
||||
mcrfpy.Timer("cancel_timer3", cancel_timer3, 350, once=True)
|
||||
|
||||
# Test 4: Test interval modification
|
||||
print("\nTest 4: Testing interval modification")
|
||||
|
|
@ -87,13 +87,13 @@ def run_tests(runtime):
|
|||
|
||||
# Test 5: Test remaining time
|
||||
print("\nTest 5: Testing remaining time")
|
||||
def check_remaining(runtime):
|
||||
def check_remaining(t, rt):
|
||||
if timer1.active:
|
||||
print(f" Timer1 remaining: {timer1.remaining}ms")
|
||||
if timer2.active or timer2.paused:
|
||||
print(f" Timer2 remaining: {timer2.remaining}ms (paused: {timer2.paused})")
|
||||
|
||||
mcrfpy.setTimer("check_remaining", check_remaining, 150)
|
||||
remaining_timer = mcrfpy.Timer("check_remaining", check_remaining, 150)
|
||||
|
||||
# Test 6: Test restart
|
||||
print("\nTest 6: Testing restart functionality")
|
||||
|
|
@ -109,7 +109,7 @@ def run_tests(runtime):
|
|||
timer5 = mcrfpy.Timer("restart_test", restart_test, 400)
|
||||
|
||||
# Final verification after 2 seconds
|
||||
def final_check(runtime):
|
||||
def final_check(t, rt):
|
||||
print("\n=== Final Results ===")
|
||||
print(f"Timer1 call count: {call_count} (expected: ~4)")
|
||||
print(f"Pause test count: {pause_test_count} (expected: ~6-7, with pause gap)")
|
||||
|
|
@ -120,7 +120,7 @@ def run_tests(runtime):
|
|||
try:
|
||||
print(f"\nTimer1 active: {timer1.active}")
|
||||
print(f"Timer2 active: {timer2.active}")
|
||||
print(f"Timer3 active: {timer3.active} (should be False after cancel)")
|
||||
print(f"Timer3 active: {timer3.active} (should be False after stop)")
|
||||
print(f"Timer4 active: {timer4.active}")
|
||||
print(f"Timer5 active: {timer5.active}")
|
||||
except:
|
||||
|
|
@ -129,13 +129,13 @@ def run_tests(runtime):
|
|||
print("\n✓ All Timer object tests completed!")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("final_check", final_check, 2000)
|
||||
mcrfpy.Timer("final_check", final_check, 2000, once=True)
|
||||
|
||||
# Create a minimal scene
|
||||
timer_test = mcrfpy.Scene("timer_test")
|
||||
timer_test.activate()
|
||||
|
||||
# Start tests after game loop begins
|
||||
mcrfpy.setTimer("run_tests", run_tests, 100)
|
||||
mcrfpy.Timer("run_tests", run_tests, 100, once=True)
|
||||
|
||||
print("Timer object tests starting...")
|
||||
|
|
@ -4,18 +4,18 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def take_screenshot(runtime):
|
||||
def take_screenshot(timer, runtime):
|
||||
"""Take screenshot after render completes"""
|
||||
mcrfpy.delTimer("screenshot")
|
||||
timer.stop()
|
||||
automation.screenshot("test_uiarc_result.png")
|
||||
|
||||
print("Screenshot saved to test_uiarc_result.png")
|
||||
print("PASS - UIArc test completed")
|
||||
sys.exit(0)
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Main test - runs after scene is set up"""
|
||||
mcrfpy.delTimer("test")
|
||||
timer.stop()
|
||||
|
||||
# Get the scene UI
|
||||
ui = test.children
|
||||
|
|
@ -127,11 +127,12 @@ def run_test(runtime):
|
|||
print(f" Arc 10 (reverse): {a10}")
|
||||
|
||||
# Schedule screenshot for next frame
|
||||
mcrfpy.setTimer("screenshot", take_screenshot, 50)
|
||||
global screenshot_timer
|
||||
screenshot_timer = mcrfpy.Timer("screenshot", take_screenshot, 50, once=True)
|
||||
|
||||
# Create a test scene
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 50)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 50, once=True)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from mcrfpy import automation
|
|||
import sys
|
||||
import time
|
||||
|
||||
def run_visual_test(runtime):
|
||||
def run_visual_test(timer, runtime):
|
||||
"""Timer callback to run visual tests and take screenshots."""
|
||||
print("\nRunning visual tests...")
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ def main():
|
|||
print("Scene setup complete. Scheduling visual tests...")
|
||||
|
||||
# Schedule visual test to run after render loop starts
|
||||
mcrfpy.setTimer("visual_test", run_visual_test, 100)
|
||||
visual_test_timer = mcrfpy.Timer("visual_test", run_visual_test, 100, once=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -4,18 +4,18 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def take_screenshot(runtime):
|
||||
def take_screenshot(timer, runtime):
|
||||
"""Take screenshot after render completes"""
|
||||
mcrfpy.delTimer("screenshot")
|
||||
timer.stop()
|
||||
automation.screenshot("test_uicircle_result.png")
|
||||
|
||||
print("Screenshot saved to test_uicircle_result.png")
|
||||
print("PASS - UICircle test completed")
|
||||
sys.exit(0)
|
||||
|
||||
def run_test(runtime):
|
||||
def run_test(timer, runtime):
|
||||
"""Main test - runs after scene is set up"""
|
||||
mcrfpy.delTimer("test")
|
||||
timer.stop()
|
||||
|
||||
# Get the scene UI
|
||||
ui = test.children
|
||||
|
|
@ -118,11 +118,12 @@ def run_test(runtime):
|
|||
print(f" c1 moved from {old_center} to {new_center}")
|
||||
|
||||
# Schedule screenshot for next frame
|
||||
mcrfpy.setTimer("screenshot", take_screenshot, 50)
|
||||
global screenshot_timer
|
||||
screenshot_timer = mcrfpy.Timer("screenshot", take_screenshot, 50, once=True)
|
||||
|
||||
# Create a test scene
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
|
||||
# Schedule test to run after game loop starts
|
||||
mcrfpy.setTimer("test", run_test, 50)
|
||||
test_timer = mcrfpy.Timer("test", run_test, 50, once=True)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Test UTF-8 encoding support
|
|||
import mcrfpy
|
||||
import sys
|
||||
|
||||
def test_utf8(runtime):
|
||||
def test_utf8(timer, runtime):
|
||||
"""Test UTF-8 encoding in print statements"""
|
||||
|
||||
# Test various unicode characters
|
||||
|
|
@ -32,4 +32,4 @@ def test_utf8(runtime):
|
|||
|
||||
# Run test
|
||||
test = mcrfpy.Scene("test")
|
||||
mcrfpy.setTimer("test", test_utf8, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_utf8, 100, once=True)
|
||||
|
|
@ -7,7 +7,7 @@ import mcrfpy
|
|||
import sys
|
||||
import math
|
||||
|
||||
def test_vector_arithmetic(runtime):
|
||||
def test_vector_arithmetic(timer, runtime):
|
||||
"""Test vector arithmetic operations"""
|
||||
|
||||
all_pass = True
|
||||
|
|
@ -244,4 +244,4 @@ def test_vector_arithmetic(runtime):
|
|||
|
||||
# Run test
|
||||
test = mcrfpy.Scene("test")
|
||||
mcrfpy.setTimer("test", test_vector_arithmetic, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_vector_arithmetic, 100, once=True)
|
||||
|
|
@ -5,9 +5,9 @@ import mcrfpy
|
|||
from mcrfpy import Window, Frame, Caption, Color, Vector
|
||||
import sys
|
||||
|
||||
def test_viewport_modes(runtime):
|
||||
def test_viewport_modes(timer, runtime):
|
||||
"""Test all three viewport scaling modes"""
|
||||
mcrfpy.delTimer("test_viewport")
|
||||
timer.stop()
|
||||
|
||||
print("Testing viewport scaling modes...")
|
||||
|
||||
|
|
@ -82,8 +82,8 @@ def test_viewport_modes(runtime):
|
|||
scene.append(instructions)
|
||||
|
||||
# Test changing modes
|
||||
def test_mode_changes(runtime):
|
||||
mcrfpy.delTimer("test_modes")
|
||||
def test_mode_changes(t, r):
|
||||
t.stop()
|
||||
from mcrfpy import automation
|
||||
|
||||
print("\nTesting scaling modes:")
|
||||
|
|
@ -95,10 +95,10 @@ def test_viewport_modes(runtime):
|
|||
automation.screenshot("viewport_center_mode.png")
|
||||
|
||||
# Schedule next mode test
|
||||
mcrfpy.setTimer("test_stretch", test_stretch_mode, 1000)
|
||||
mcrfpy.Timer("test_stretch", test_stretch_mode, 1000, once=True)
|
||||
|
||||
def test_stretch_mode(runtime):
|
||||
mcrfpy.delTimer("test_stretch")
|
||||
def test_stretch_mode(t, r):
|
||||
t.stop()
|
||||
from mcrfpy import automation
|
||||
|
||||
window.scaling_mode = "stretch"
|
||||
|
|
@ -107,10 +107,10 @@ def test_viewport_modes(runtime):
|
|||
automation.screenshot("viewport_stretch_mode.png")
|
||||
|
||||
# Schedule next mode test
|
||||
mcrfpy.setTimer("test_fit", test_fit_mode, 1000)
|
||||
mcrfpy.Timer("test_fit", test_fit_mode, 1000, once=True)
|
||||
|
||||
def test_fit_mode(runtime):
|
||||
mcrfpy.delTimer("test_fit")
|
||||
def test_fit_mode(t, r):
|
||||
t.stop()
|
||||
from mcrfpy import automation
|
||||
|
||||
window.scaling_mode = "fit"
|
||||
|
|
@ -119,10 +119,10 @@ def test_viewport_modes(runtime):
|
|||
automation.screenshot("viewport_fit_mode.png")
|
||||
|
||||
# Test different window sizes
|
||||
mcrfpy.setTimer("test_resize", test_window_resize, 1000)
|
||||
mcrfpy.Timer("test_resize", test_window_resize, 1000, once=True)
|
||||
|
||||
def test_window_resize(runtime):
|
||||
mcrfpy.delTimer("test_resize")
|
||||
def test_window_resize(t, r):
|
||||
t.stop()
|
||||
from mcrfpy import automation
|
||||
|
||||
print("\nTesting window resize with fit mode:")
|
||||
|
|
@ -133,13 +133,13 @@ def test_viewport_modes(runtime):
|
|||
print(f"Window resized to: {window.resolution}")
|
||||
automation.screenshot("viewport_fit_wide.png")
|
||||
# Make window taller
|
||||
mcrfpy.setTimer("test_tall", test_tall_window, 1000)
|
||||
mcrfpy.Timer("test_tall", test_tall_window, 1000, once=True)
|
||||
except RuntimeError as e:
|
||||
print(f" Skipping window resize tests (headless mode): {e}")
|
||||
mcrfpy.setTimer("test_game_res", test_game_resolution, 100)
|
||||
mcrfpy.Timer("test_game_res", test_game_resolution, 100, once=True)
|
||||
|
||||
def test_tall_window(runtime):
|
||||
mcrfpy.delTimer("test_tall")
|
||||
def test_tall_window(t, r):
|
||||
t.stop()
|
||||
from mcrfpy import automation
|
||||
|
||||
try:
|
||||
|
|
@ -150,10 +150,10 @@ def test_viewport_modes(runtime):
|
|||
print(f" Skipping tall window test (headless mode): {e}")
|
||||
|
||||
# Test game resolution change
|
||||
mcrfpy.setTimer("test_game_res", test_game_resolution, 1000)
|
||||
mcrfpy.Timer("test_game_res", test_game_resolution, 1000, once=True)
|
||||
|
||||
def test_game_resolution(runtime):
|
||||
mcrfpy.delTimer("test_game_res")
|
||||
def test_game_resolution(t, r):
|
||||
t.stop()
|
||||
|
||||
print("\nTesting game resolution change:")
|
||||
window.game_resolution = (800, 600)
|
||||
|
|
@ -180,7 +180,7 @@ def test_viewport_modes(runtime):
|
|||
sys.exit(0)
|
||||
|
||||
# Start test sequence
|
||||
mcrfpy.setTimer("test_modes", test_mode_changes, 500)
|
||||
mcrfpy.Timer("test_modes", test_mode_changes, 500, once=True)
|
||||
|
||||
# Set up keyboard handler for manual testing
|
||||
def handle_keypress(key, state):
|
||||
|
|
@ -240,7 +240,7 @@ test.activate()
|
|||
test.on_key = handle_keypress
|
||||
|
||||
# Schedule the test
|
||||
mcrfpy.setTimer("test_viewport", test_viewport_modes, 100)
|
||||
test_viewport_timer = mcrfpy.Timer("test_viewport", test_viewport_modes, 100, once=True)
|
||||
|
||||
print("Viewport test running...")
|
||||
print("Use number keys to switch modes, R to resize window, G to change game resolution")
|
||||
|
|
@ -95,7 +95,7 @@ except IndexError as e:
|
|||
print(f" ✓ Correctly rejected invalid perspective: {e}")
|
||||
|
||||
# Test 4: Visual demonstration
|
||||
def visual_test(runtime):
|
||||
def visual_test(timer, runtime):
|
||||
print(f"\nVisual test - cycling perspectives at {runtime}ms")
|
||||
|
||||
# Cycle through perspectives
|
||||
|
|
@ -159,14 +159,14 @@ ui.append(legend)
|
|||
visibility_test.activate()
|
||||
|
||||
# Set timer to cycle perspectives
|
||||
mcrfpy.setTimer("cycle", visual_test, 2000) # Every 2 seconds
|
||||
cycle_timer = mcrfpy.Timer("cycle", visual_test, 2000) # Every 2 seconds
|
||||
|
||||
print("\nTest complete! Visual demo cycling through perspectives...")
|
||||
print("Perspectives will cycle: Omniscient → Entity 0 → Entity 1 → Entity 2 → Omniscient")
|
||||
|
||||
# Quick test to exit after screenshots
|
||||
def exit_timer(dt):
|
||||
def exit_timer_cb(timer, runtime):
|
||||
print("\nExiting after demo...")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("exit", exit_timer, 10000) # Exit after 10 seconds
|
||||
exit_timer_obj = mcrfpy.Timer("exit", exit_timer_cb, 10000, once=True) # Exit after 10 seconds
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ grid.fill_color = mcrfpy.Color(0, 0, 0)
|
|||
# Add color layer for cell coloring
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
def check_render(dt):
|
||||
def check_render(timer, runtime):
|
||||
"""Timer callback to verify rendering"""
|
||||
print(f"\nTimer fired after {dt}ms")
|
||||
print(f"\nTimer fired after {runtime}ms")
|
||||
|
||||
# Take screenshot
|
||||
from mcrfpy import automation
|
||||
|
|
@ -78,6 +78,6 @@ ui.append(title)
|
|||
visual_test.activate()
|
||||
|
||||
# Set timer to check rendering
|
||||
mcrfpy.setTimer("check", check_render, 500)
|
||||
check_timer = mcrfpy.Timer("check", check_render, 500, once=True)
|
||||
|
||||
print("\nScene ready. Path should be visible in green.")
|
||||
|
|
@ -4,7 +4,7 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def test_grid_none_texture(runtime):
|
||||
def test_grid_none_texture(timer, runtime):
|
||||
"""Test Grid functionality without texture"""
|
||||
print("\n=== Testing Grid with None texture ===")
|
||||
|
||||
|
|
@ -95,5 +95,5 @@ background = mcrfpy.Frame(pos=(0, 0), size=(800, 600),
|
|||
ui.append(background)
|
||||
|
||||
# Schedule test
|
||||
mcrfpy.setTimer("test", test_grid_none_texture, 100)
|
||||
test_timer = mcrfpy.Timer("test", test_grid_none_texture, 100, once=True)
|
||||
print("Test scheduled...")
|
||||
Loading…
Add table
Add a link
Reference in a new issue