feat: GPU optimization — lighting, viewport CA, benchmark mode, 531 FPS
- Resolution: 8x8 world cells, 2x2 UI cells (UI_SCALE=4) - GPU lighting: vertex-shader computed, light source list buffer (max 64) instead of O(N×R²) grid scan, O(N×S) per cell - Viewport-aware CA: iterate only active chunks, not all 250×250 - Flat array entity/item/shadow maps instead of HashMaps - Flat 128-entry ASCII atlas array instead of HashMap lookup - Partial grid upload: viewport + 30-cell margin only - Pre-allocated viewport arrays in renderer structs (zero alloc/frame) - Skip CPU lighting for GPU modes (pass None) - Benchmark mode: --mode benchmark with per-subsystem timing - GpuLightSource struct, light_count in push constants - gather_sources_in_range() for viewport-scoped source gathering Benchmark (600 ticks, release): Graphics: 531 FPS (was 386, +38%), render 1013us (was 1699us, -40%) ASCII: 402 FPS (was 313, +28%), render 1502us (was 2346us, -36%) All 171 tests + 14 scenarios pass.
This commit is contained in:
+76
-15
@@ -1,11 +1,17 @@
|
||||
use verbatim::ai::GameSession;
|
||||
use verbatim::ai::AiAction;
|
||||
use verbatim::ai::GameSession;
|
||||
|
||||
fn setup() -> GameSession {
|
||||
let mut s = GameSession::new_seeded(42);
|
||||
s.init_empty();
|
||||
s.clear_area(90, 90, 50, 50);
|
||||
s.perform_action(&AiAction::FillRect { x: 80, y: 130, w: 80, h: 15, material: "stone".into() });
|
||||
s.perform_action(&AiAction::FillRect {
|
||||
x: 80,
|
||||
y: 130,
|
||||
w: 80,
|
||||
h: 15,
|
||||
material: "stone".into(),
|
||||
});
|
||||
s
|
||||
}
|
||||
|
||||
@@ -18,7 +24,12 @@ fn move_left_changes_x_position() {
|
||||
s.perform_action(&AiAction::MoveLeft);
|
||||
s.step(5);
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!(p1.pos[0] < x0, "player should move left: {} -> {}", x0, p1.pos[0]);
|
||||
assert!(
|
||||
p1.pos[0] < x0,
|
||||
"player should move left: {} -> {}",
|
||||
x0,
|
||||
p1.pos[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -30,7 +41,12 @@ fn move_right_changes_x_position() {
|
||||
s.perform_action(&AiAction::MoveRight);
|
||||
s.step(5);
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!(p1.pos[0] > x0, "player should move right: {} -> {}", x0, p1.pos[0]);
|
||||
assert!(
|
||||
p1.pos[0] > x0,
|
||||
"player should move right: {} -> {}",
|
||||
x0,
|
||||
p1.pos[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -44,7 +60,12 @@ fn move_left_then_right_cancels() {
|
||||
s.perform_action(&AiAction::MoveRight);
|
||||
s.step(5);
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!((p1.pos[0] - x0).abs() < 3.0, "left+right should roughly cancel: {} -> {}", x0, p1.pos[0]);
|
||||
assert!(
|
||||
(p1.pos[0] - x0).abs() < 3.0,
|
||||
"left+right should roughly cancel: {} -> {}",
|
||||
x0,
|
||||
p1.pos[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -56,10 +77,20 @@ fn jump_goes_up_then_falls_back() {
|
||||
s.perform_action(&AiAction::Jump);
|
||||
s.step(5);
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!(p1.pos[1] < y0, "player should go up after jump: {} -> {}", y0, p1.pos[1]);
|
||||
assert!(
|
||||
p1.pos[1] < y0,
|
||||
"player should go up after jump: {} -> {}",
|
||||
y0,
|
||||
p1.pos[1]
|
||||
);
|
||||
s.step(60);
|
||||
let p2 = s.get_player().unwrap();
|
||||
assert!((p2.pos[1] - y0).abs() < 5.0, "player should fall back after jump: {} -> {}", y0, p2.pos[1]);
|
||||
assert!(
|
||||
(p2.pos[1] - y0).abs() < 5.0,
|
||||
"player should fall back after jump: {} -> {}",
|
||||
y0,
|
||||
p2.pos[1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -77,7 +108,12 @@ fn jump_while_airborne_does_nothing() {
|
||||
s2.step(3);
|
||||
let p1 = s1.get_player().unwrap();
|
||||
let p2 = s2.get_player().unwrap();
|
||||
assert!((p1.pos[1] - p2.pos[1]).abs() < 2.0, "double jump should not add height: single={} double={}", p1.pos[1], p2.pos[1]);
|
||||
assert!(
|
||||
(p1.pos[1] - p2.pos[1]).abs() < 2.0,
|
||||
"double jump should not add height: single={} double={}",
|
||||
p1.pos[1],
|
||||
p2.pos[1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -100,7 +136,12 @@ fn rapid_move_right_accumulates_velocity() {
|
||||
};
|
||||
let single_dx = single - x0;
|
||||
let multi_dx = p1.pos[0] - x0;
|
||||
assert!(multi_dx > single_dx, "rapid moves should accumulate: 1x={} 5x={}", single_dx, multi_dx);
|
||||
assert!(
|
||||
multi_dx > single_dx,
|
||||
"rapid moves should accumulate: 1x={} 5x={}",
|
||||
single_dx,
|
||||
multi_dx
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -112,8 +153,14 @@ fn wait_does_not_move() {
|
||||
s.perform_action(&AiAction::Wait);
|
||||
s.step(10);
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!((p1.pos[0] - pos0.0).abs() < 1.0 && (p1.pos[1] - pos0.1).abs() < 1.0,
|
||||
"wait should not move player: ({},{}) -> ({},{})", pos0.0, pos0.1, p1.pos[0], p1.pos[1]);
|
||||
assert!(
|
||||
(p1.pos[0] - pos0.0).abs() < 1.0 && (p1.pos[1] - pos0.1).abs() < 1.0,
|
||||
"wait should not move player: ({},{}) -> ({},{})",
|
||||
pos0.0,
|
||||
pos0.1,
|
||||
p1.pos[0],
|
||||
p1.pos[1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -128,14 +175,22 @@ fn continuous_movement_does_not_fall_through_floor() {
|
||||
}
|
||||
let p1 = s.get_player().unwrap();
|
||||
assert!(p1.alive, "player should survive extended movement");
|
||||
assert!((p1.pos[1] - y0).abs() < 5.0, "player should not fall through floor during movement: y0={} y1={}", y0, p1.pos[1]);
|
||||
assert!(
|
||||
(p1.pos[1] - y0).abs() < 5.0,
|
||||
"player should not fall through floor during movement: y0={} y1={}",
|
||||
y0,
|
||||
p1.pos[1]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn player_on_ground_check() {
|
||||
let mut s = setup();
|
||||
s.step(40);
|
||||
assert!(s.game.check_on_ground(), "player should be on ground after settling");
|
||||
assert!(
|
||||
s.game.check_on_ground(),
|
||||
"player should be on ground after settling"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -145,7 +200,10 @@ fn player_not_on_ground_while_jumping() {
|
||||
assert!(s.game.check_on_ground(), "player should start on ground");
|
||||
s.perform_action(&AiAction::Jump);
|
||||
s.step(3);
|
||||
assert!(!s.game.check_on_ground(), "player should not be on ground mid-jump");
|
||||
assert!(
|
||||
!s.game.check_on_ground(),
|
||||
"player should not be on ground mid-jump"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -153,7 +211,10 @@ fn player_health_stays_full_without_damage() {
|
||||
let mut s = setup();
|
||||
s.step(60);
|
||||
let p = s.get_player().unwrap();
|
||||
assert_eq!(p.health, 100.0, "player should have full health without damage");
|
||||
assert_eq!(
|
||||
p.health, p.max_health,
|
||||
"player should have full health without damage"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user