Compare commits

..

22 Commits

Author SHA1 Message Date
Ryan Walters
5deccc54a7 ci: setup codecov coverage & badge 2025-09-05 22:41:49 -05:00
Ryan Walters
2455d9724b test: add ttf renderer tests 2025-09-05 21:22:40 -05:00
Ryan Walters
ac7c1b9ce1 test: remove useless/redundant tests 2025-09-05 21:13:53 -05:00
Ryan Walters
d68d76c854 test: improve input & map_builder test coverage 2025-09-05 21:13:48 -05:00
Ryan Walters
f1927cc67e test: general game testing 2025-09-05 20:04:07 -05:00
Ryan Walters
68ab4627d8 test: add asset tests, file exists & has min size 2025-09-05 19:53:56 -05:00
Ryan Walters
0d8d869580 test: blinking system tests 2025-09-05 19:46:52 -05:00
Ryan Walters
a31b85b5df refactor: use speculoos for all test assertions 2025-09-05 19:34:01 -05:00
Ryan Walters
21b08d4866 fix: remove unused BlinkingTexture 2025-09-05 19:32:22 -05:00
Ryan Walters
f075caaa17 refactor: add ticks to DeltaTime, rewrite Blinking system for tick-based calculations with absolute calculations, rewrite Blinking/Direction tests 2025-09-05 19:20:58 -05:00
Ryan Walters
9422168ffc feat: re-implement CustomFormatter to clone Full formatterr 2025-09-05 18:49:38 -05:00
Ryan Walters
35e557e298 feat: enhance profiling with tick-based timing management and zero-padding for skipped frames 2025-09-05 18:49:33 -05:00
Ryan Walters
e810419063 refactor: use welford's algorithm for one-pass avg/std dev. calculations, input logging tweaks 2025-09-05 15:32:06 -05:00
Ryan Walters
f7e7dee28f chore: move ttf context out of game.rs, remove unnecessary window event logging 2025-09-05 15:21:20 -05:00
Ryan Walters
4b0b8f4f2e refactor: reorganize game.rs new() into separate functions 2025-09-05 15:10:15 -05:00
Ryan Walters
03249c88a4 feat: sprite enums for avoiding hardcoded string paths 2025-09-05 15:08:38 -05:00
Ryan Walters
2d4f97e04b fix: use LARGE_SCALE for BatchedLineResource calculations 2025-09-05 14:22:16 -05:00
Ryan Walters
317fce796c feat: measure total system timings using threading indifferent method, padded formatting 2025-09-05 14:22:16 -05:00
Ryan Walters
9832abd131 chore: move BufferedWriter into tracing_buffer.rs 2025-09-05 13:58:59 -05:00
Ryan Walters
c94ebc6b4b feat: special formatting with game tick counter, remove date from tracing formatter 2025-09-05 13:52:19 -05:00
Ryan Walters
8b23c1c7bd fix(ci): allow dead code in buffered_writer & tracing_buffer for desktop non-windows checks 2025-09-04 16:15:11 -05:00
Ryan Walters
5e325a4691 feat: enumerate and display render driver info, increase node id text opacity 2025-09-04 16:12:26 -05:00
7 changed files with 81 additions and 144 deletions

View File

@@ -9,6 +9,8 @@ env:
jobs: jobs:
coverage: coverage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v5 uses: actions/checkout@v5
@@ -46,12 +48,41 @@ jobs:
- name: Generate coverage report - name: Generate coverage report
run: | run: |
just coverage-codecov just coverage
- name: Upload coverage reports to Codecov - name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4 uses: codecov/codecov-action@v5
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}
files: ./codecov.json files: lcov.info
disable_search: true
verbose: true - name: Download Coveralls CLI
if: ${{ env.COVERALLS_REPO_TOKEN != '' }}
run: |
# use GitHub Releases URL instead of coveralls.io because they can't maintain their own files; it 404s
curl -L https://github.com/coverallsapp/coverage-reporter/releases/download/v0.6.15/coveralls-linux-x86_64.tar.gz | tar -xz -C /usr/local/bin
- name: Upload coverage to Coveralls
if: ${{ env.COVERALLS_REPO_TOKEN != '' }}
run: |
if [ ! -f "lcov.info" ]; then
echo "Error: lcov.info file not found. Coverage generation may have failed."
exit 1
fi
for i in {1..10}; do
echo "Attempt $i: Uploading coverage to Coveralls..."
if coveralls -n report lcov.info; then
echo "Successfully uploaded coverage report."
exit 0
fi
if [ $i -lt 10 ]; then
delay=$((2**i))
echo "Attempt $i failed. Retrying in $delay seconds..."
sleep $delay
fi
done
echo "Failed to upload coverage report after 10 attempts."
exit 1

1
.gitignore vendored
View File

@@ -14,7 +14,6 @@ assets/site/build.css
# Coverage reports # Coverage reports
lcov.info lcov.info
codecov.json
coverage.html coverage.html
# Profiling output # Profiling output

View File

@@ -2,8 +2,8 @@ set shell := ["bash", "-c"]
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
# Regex to exclude files from coverage report, double escapes for Justfile + CLI # Regex to exclude files from coverage report, double escapes for Justfile + CLI
# You can use src/..., but the filename alone is acceptable too # You can use src\\\\..., but the filename alone is acceptable too
coverage_exclude_pattern := "src/app\\.rs|audio\\.rs|src/error\\.rs|platform/emscripten\\.rs|bin/.+\\.rs|main\\.rs|platform/desktop\\.rs|platform/tracing_buffer\\.rs|platform/buffered_writer\\.rs|systems/debug\\.rs|systems/profiling\\.rs" coverage_exclude_pattern := "src\\\\app\\.rs|audio\\.rs|src\\\\error\\.rs|platform\\\\emscripten\\.rs|bin\\\\.+\\.rs|main\\.rs|platform\\\\desktop\\.rs|platform\\\\tracing_buffer\\.rs|platform\\\\buffered_writer\\.rs|systems\\\\debug\\.rs|systems\\\\profiling\\.rs"
binary_extension := if os() == "windows" { ".exe" } else { "" } binary_extension := if os() == "windows" { ".exe" } else { "" }
@@ -11,7 +11,7 @@ binary_extension := if os() == "windows" { ".exe" } else { "" }
# !!! --remap-path-prefix prevents the absolute path from being used in the generated report # !!! --remap-path-prefix prevents the absolute path from being used in the generated report
# Generate HTML report (for humans, source line inspection) # Generate HTML report (for humans, source line inspection)
html: coverage-lcov html: coverage
cargo llvm-cov report \ cargo llvm-cov report \
--remap-path-prefix \ --remap-path-prefix \
--ignore-filename-regex "{{ coverage_exclude_pattern }}" \ --ignore-filename-regex "{{ coverage_exclude_pattern }}" \
@@ -19,13 +19,13 @@ html: coverage-lcov
--open --open
# Display report (for humans) # Display report (for humans)
report-coverage: coverage-lcov report-coverage: coverage
cargo llvm-cov report \ cargo llvm-cov report \
--remap-path-prefix \ --remap-path-prefix \
--ignore-filename-regex "{{ coverage_exclude_pattern }}" --ignore-filename-regex "{{ coverage_exclude_pattern }}"
# Run & generate LCOV report (as base report) # Run & generate report (for CI)
coverage-lcov: coverage:
cargo llvm-cov \ cargo llvm-cov \
--lcov \ --lcov \
--remap-path-prefix \ --remap-path-prefix \
@@ -34,16 +34,6 @@ coverage-lcov:
--profile coverage \ --profile coverage \
--no-fail-fast nextest --no-fail-fast nextest
# Run & generate Codecov report (for CI)
coverage-codecov:
cargo llvm-cov \
--codecov \
--remap-path-prefix \
--ignore-filename-regex "{{ coverage_exclude_pattern }}" \
--output-path codecov.json \
--profile coverage \
--no-fail-fast nextest
# Profile the project using 'samply' # Profile the project using 'samply'
samply: samply:
cargo build --profile profile cargo build --profile profile

View File

@@ -1,3 +0,0 @@
ignore:
- "src/(?:bin|platform))/.+\\.rs"
- "src/(?:app|events|formatter)\\.rs"

View File

@@ -266,7 +266,7 @@ pub fn debug_render_system(
} }
canvas.set_draw_color(Color { canvas.set_draw_color(Color {
a: f32_to_u8(0.65), a: f32_to_u8(0.6),
..Color::RED ..Color::RED
}); });
canvas.set_blend_mode(sdl2::render::BlendMode::Blend); canvas.set_blend_mode(sdl2::render::BlendMode::Blend);

View File

@@ -15,8 +15,6 @@ pub enum PacmanSprite {
Moving(Direction, u8), Moving(Direction, u8),
/// The full, closed-mouth Pac-Man sprite. /// The full, closed-mouth Pac-Man sprite.
Full, Full,
/// A single frame of the dying animation.
Dying(u8),
} }
/// Represents the color of a frightened ghost. /// Represents the color of a frightened ghost.
@@ -62,50 +60,45 @@ impl GameSprite {
/// This path corresponds to the filename in the texture atlas JSON file. /// This path corresponds to the filename in the texture atlas JSON file.
pub fn to_path(self) -> String { pub fn to_path(self) -> String {
match self { match self {
GameSprite::Pacman(PacmanSprite::Moving(dir, frame)) => format!( GameSprite::Pacman(sprite) => match sprite {
"pacman/{}_{}.png", PacmanSprite::Moving(dir, frame) => {
dir.as_ref(), let frame_char = match frame {
match frame { 0 => 'a',
0 => "a", 1 => 'b',
1 => "b", _ => panic!("Invalid animation frame"),
_ => panic!("Invalid animation frame"), };
format!("pacman/{}_{}.png", dir.as_ref().to_lowercase(), frame_char)
} }
), PacmanSprite::Full => "pacman/full.png".to_string(),
GameSprite::Pacman(PacmanSprite::Full) => "pacman/full.png".to_string(), },
GameSprite::Pacman(PacmanSprite::Dying(frame)) => format!("pacman/death/{}.png", frame), GameSprite::Ghost(sprite) => match sprite {
GhostSprite::Normal(ghost, dir, frame) => {
// Ghost sprites let frame_char = match frame {
GameSprite::Ghost(GhostSprite::Normal(ghost_type, dir, frame)) => { 0 => 'a',
let frame_char = match frame { 1 => 'b',
0 => 'a', _ => panic!("Invalid animation frame"),
1 => 'b', };
_ => panic!("Invalid animation frame"), format!("ghost/{}/{}_{}.png", ghost.as_str(), dir.as_ref().to_lowercase(), frame_char)
}; }
format!( GhostSprite::Frightened(color, frame) => {
"ghost/{}/{}_{}.png", let frame_char = match frame {
ghost_type.as_str(), 0 => 'a',
dir.as_ref().to_lowercase(), 1 => 'b',
frame_char _ => panic!("Invalid animation frame"),
) };
} let color_str = match color {
GameSprite::Ghost(GhostSprite::Frightened(color, frame)) => { FrightenedColor::Blue => "blue",
let frame_char = match frame { FrightenedColor::White => "white",
0 => 'a', };
1 => 'b', format!("ghost/frightened/{}_{}.png", color_str, frame_char)
_ => panic!("Invalid animation frame"), }
}; GhostSprite::Eyes(dir) => format!("ghost/eyes/{}.png", dir.as_ref().to_lowercase()),
let color_str = match color { },
FrightenedColor::Blue => "blue", GameSprite::Maze(sprite) => match sprite {
FrightenedColor::White => "white", MazeSprite::Tile(index) => format!("maze/tiles/{}.png", index),
}; MazeSprite::Pellet => "maze/pellet.png".to_string(),
format!("ghost/frightened/{}_{}.png", color_str, frame_char) MazeSprite::Energizer => "maze/energizer.png".to_string(),
} },
GameSprite::Ghost(GhostSprite::Eyes(dir)) => format!("ghost/eyes/{}.png", dir.as_ref().to_lowercase()),
// Maze sprites
GameSprite::Maze(MazeSprite::Tile(index)) => format!("maze/tiles/{}.png", index),
GameSprite::Maze(MazeSprite::Pellet) => "maze/pellet.png".to_string(),
GameSprite::Maze(MazeSprite::Energizer) => "maze/energizer.png".to_string(),
} }
} }
} }

View File

@@ -1,73 +0,0 @@
//! Tests for the sprite path generation.
use pacman::{
game::ATLAS_FRAMES,
map::direction::Direction,
systems::components::Ghost,
texture::sprites::{FrightenedColor, GameSprite, GhostSprite, MazeSprite, PacmanSprite},
};
#[test]
fn test_all_sprite_paths_exist() {
let mut sprites_to_test = Vec::new();
// Pac-Man sprites
for &dir in &[Direction::Up, Direction::Down, Direction::Left, Direction::Right] {
for frame in 0..2 {
sprites_to_test.push(GameSprite::Pacman(PacmanSprite::Moving(dir, frame)));
}
}
sprites_to_test.push(GameSprite::Pacman(PacmanSprite::Full));
for frame in 0..=10 {
sprites_to_test.push(GameSprite::Pacman(PacmanSprite::Dying(frame)));
}
// Ghost sprites
for &ghost in &[Ghost::Blinky, Ghost::Pinky, Ghost::Inky, Ghost::Clyde] {
for &dir in &[Direction::Up, Direction::Down, Direction::Left, Direction::Right] {
for frame in 0..2 {
sprites_to_test.push(GameSprite::Ghost(GhostSprite::Normal(ghost, dir, frame)));
}
sprites_to_test.push(GameSprite::Ghost(GhostSprite::Eyes(dir)));
}
}
for &color in &[FrightenedColor::Blue, FrightenedColor::White] {
for frame in 0..2 {
sprites_to_test.push(GameSprite::Ghost(GhostSprite::Frightened(color, frame)));
}
}
// Maze sprites
for i in 0..=34 {
sprites_to_test.push(GameSprite::Maze(MazeSprite::Tile(i)));
}
sprites_to_test.push(GameSprite::Maze(MazeSprite::Pellet));
sprites_to_test.push(GameSprite::Maze(MazeSprite::Energizer));
for sprite in sprites_to_test {
let path = sprite.to_path();
assert!(
ATLAS_FRAMES.contains_key(&path),
"Sprite path '{}' does not exist in the atlas.",
path
);
}
}
#[test]
fn test_invalid_sprite_paths_do_not_exist() {
let invalid_sprites = vec![
// An invalid Pac-Man dying frame
GameSprite::Pacman(PacmanSprite::Dying(99)),
// An invalid maze tile
GameSprite::Maze(MazeSprite::Tile(99)),
];
for sprite in invalid_sprites {
let path = sprite.to_path();
assert!(
!ATLAS_FRAMES.contains_key(&path),
"Invalid sprite path '{}' was found in the atlas, but it should not exist.",
path
);
}
}