mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 11:15:46 -06:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 163855b6e7 | |||
| 645d48aeae | |||
| ec800a88fc | |||
| abc37dee4e | |||
| 1ae7839275 | |||
| d976d1bc59 | |||
| 531a5b5d05 |
29
.github/workflows/build.yaml
vendored
29
.github/workflows/build.yaml
vendored
@@ -11,8 +11,6 @@ env:
|
||||
jobs:
|
||||
build:
|
||||
name: Build (${{ matrix.target }})
|
||||
env:
|
||||
VCPKG_SYSTEM_LIBRARIES: "OFF"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -46,16 +44,18 @@ jobs:
|
||||
- name: Cache vcpkg
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
save-always: true # deprecated
|
||||
path: target/vcpkg
|
||||
key: ${{ runner.os }}-vcpkg-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
|
||||
key: vcpkg-${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-vcpkg-
|
||||
${{ runner.os }}-vcpkg
|
||||
vcpkg-${{ runner.os }}-${{ matrix.target }}-
|
||||
|
||||
- name: Vcpkg Linux Dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential gettext libltdl-dev
|
||||
sudo apt-get install -y build-essential gettext libltdl-dev zlib1g-dev
|
||||
|
||||
- name: Vcpkg
|
||||
run: |
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Emscripten SDK
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
uses: pyodide/setup-emsdk@v15
|
||||
with:
|
||||
version: 3.1.43
|
||||
actions-cache-folder: "emsdk-cache"
|
||||
@@ -111,8 +111,21 @@ jobs:
|
||||
version: 8
|
||||
run_install: true
|
||||
|
||||
- name: Build
|
||||
run: ./build.sh -er # release mode, skip emsdk
|
||||
- name: Build with Emscripten
|
||||
run: |
|
||||
cargo build --target=wasm32-unknown-emscripten --release
|
||||
|
||||
- name: Assemble
|
||||
run: |
|
||||
echo "Generating CSS"
|
||||
pnpx postcss-cli ./assets/site/styles.scss -o ./assets/site/build.css
|
||||
|
||||
echo "Copying WASM files"
|
||||
|
||||
mkdir -p dist
|
||||
cp assets/site/{build.css,favicon.ico,index.html} dist
|
||||
output_folder="target/wasm32-unknown-emscripten/release"
|
||||
cp $output_folder/pacman.{wasm,js} $output_folder/deps/pacman.data dist
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
|
||||
@@ -42,7 +42,8 @@ rev = "2024.05.24" # release 2024.05.24 # to check for a new one, check https://
|
||||
[package.metadata.vcpkg.target]
|
||||
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md" }
|
||||
x86_64-unknown-linux-gnu = { triplet = "x64-linux" }
|
||||
# x86_64-apple-darwin = { triplet = "x64-osx-release" }
|
||||
x86_64-apple-darwin = { triplet = "x64-osx" }
|
||||
aarch64-apple-darwin = { triplet = "arm64-osx" }
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||
libc = "0.2.16"
|
||||
|
||||
18
src/asset.rs
18
src/asset.rs
@@ -78,15 +78,17 @@ mod imp {
|
||||
#[cfg(target_os = "emscripten")]
|
||||
mod imp {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use sdl2::rwops::RWops;
|
||||
use std::io::Read;
|
||||
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
|
||||
let path = Path::new("assets/game").join(asset.path());
|
||||
if !path.exists() {
|
||||
return Err(AssetError::NotFound(asset.path().to_string()));
|
||||
}
|
||||
let bytes = fs::read(&path)?;
|
||||
Ok(Cow::Owned(bytes))
|
||||
let path = format!("assets/game/{}", asset.path());
|
||||
let mut rwops = RWops::from_file(&path, "rb").map_err(|_| AssetError::NotFound(asset.path().to_string()))?;
|
||||
let len = rwops.len().ok_or_else(|| AssetError::NotFound(asset.path().to_string()))?;
|
||||
let mut buf = vec![0u8; len];
|
||||
rwops
|
||||
.read_exact(&mut buf)
|
||||
.map_err(|e| AssetError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
|
||||
Ok(Cow::Owned(buf))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ impl Audio {
|
||||
let frequency = 44100;
|
||||
let format = DEFAULT_FORMAT;
|
||||
let channels = 4;
|
||||
let chunk_size = 128;
|
||||
let chunk_size = 256; // 256 is minimum for emscripten
|
||||
|
||||
mixer::open_audio(frequency, format, 1, chunk_size).expect("Failed to open audio");
|
||||
mixer::allocate_channels(channels);
|
||||
|
||||
Reference in New Issue
Block a user