Compare commits
236
Commits
alpha-0.0.3
..
new
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cad41e456b | ||
|
|
65c4a9c051 | ||
|
|
3710924503 | ||
|
|
3948607b1e | ||
|
|
6c180372fe | ||
|
|
fed04b66b8 | ||
|
|
a4ca718070 | ||
|
|
8dbd3e1dd2 | ||
|
|
7a9a2b9832 | ||
|
|
e8757c33e3 | ||
|
|
b498a12458 | ||
|
|
c9f098693c | ||
|
|
7aeffac9fc | ||
|
|
37e7e95ace | ||
|
|
e3f56c4d12 | ||
|
|
3675ec634f | ||
|
|
d8273a225c | ||
|
|
c1c8174b27 | ||
|
|
5697f5c064 | ||
|
|
3ce16cf7f4 | ||
|
|
2abd5b0c3c | ||
|
|
4b29bf7a30 | ||
|
|
6f1bbe4f2f | ||
|
|
f64364f37d | ||
|
|
d16e0bbfbf | ||
|
|
70ae41bd29 | ||
|
|
abf6863044 | ||
|
|
4279bd9675 | ||
|
|
5910110b95 | ||
|
|
44594f7011 | ||
|
|
dbb5301ade | ||
|
|
74a4290be4 | ||
|
|
3ce892f846 | ||
|
|
68cebce04a | ||
|
|
1646e964b5 | ||
|
|
2ee97ad4ce | ||
|
|
109ddc9e1e | ||
|
|
804f8aa1fa | ||
|
|
49b97ba508 | ||
|
|
6c11d8165d | ||
|
|
93554b39ba | ||
|
|
6af0e9cf28 | ||
|
|
083deb8357 | ||
|
|
ffb375faeb | ||
|
|
b8cbd8ff6a | ||
|
|
c2bd761383 | ||
|
|
878e3438c8 | ||
|
|
3da65370e0 | ||
|
|
83e646cba9 | ||
|
|
0566166af4 | ||
|
|
ed0b8c3911 | ||
|
|
03d753a83f | ||
|
|
cf51ed1988 | ||
|
|
70f46e89d3 | ||
|
|
efd760fb2e | ||
|
|
f303d24f4a | ||
|
|
9688e88a7c | ||
|
|
c8a6325615 | ||
|
|
798db14bb5 | ||
|
|
178d78ef72 | ||
|
|
8139a0ea54 | ||
|
|
327c2bec70 | ||
|
|
fc0195d9f7 | ||
|
|
db42bca44b | ||
|
|
b3623c84a5 | ||
|
|
45c1f9004b | ||
|
|
845a395ff1 | ||
|
|
f63653c307 | ||
|
|
5b523c68a7 | ||
|
|
03efbe0681 | ||
|
|
cebd3d81e7 | ||
|
|
de53bebeb8 | ||
|
|
6ccaedd48f | ||
|
|
707856fcf2 | ||
|
|
3c3dc35e1d | ||
|
|
f9820bd226 | ||
|
|
fe2ef92ef3 | ||
|
|
9364768397 | ||
|
|
9c28d5a3b7 | ||
|
|
d5078b978c | ||
|
|
d49594d3fb | ||
|
|
619ce932f9 | ||
|
|
b564d0b1c1 | ||
|
|
fc1fc9f170 | ||
|
|
fd5bcfae90 | ||
|
|
3ee0a53688 | ||
|
|
62c081ecf2 | ||
|
|
d9beb647c1 | ||
|
|
f8f8a80a21 | ||
|
|
ac8023d50f | ||
|
|
769f2f5702 | ||
|
|
2f6839bcc4 | ||
|
|
d37109f5f7 | ||
|
|
15bd9fc43c | ||
|
|
8049e90853 | ||
|
|
e47a2c3e5c | ||
|
|
9512c22e1f | ||
|
|
8a77001016 | ||
|
|
9b0214ee55 | ||
|
|
7ad735552a | ||
|
|
ea35472ef8 | ||
|
|
50c5621d8a | ||
|
|
da275cfd52 | ||
|
|
0f4ee5d965 | ||
|
|
af8c0f5ccd | ||
|
|
8ea370a1d1 | ||
|
|
fcf0de72af | ||
|
|
320c5e6ce5 | ||
|
|
7a858cc424 | ||
|
|
c0292842a5 | ||
|
|
717902462b | ||
|
|
1d73b9d224 | ||
|
|
51f262efa0 | ||
|
|
a6e4e3f71f | ||
|
|
4387d223b9 | ||
|
|
00bfaf6360 | ||
|
|
709bd7be52 | ||
|
|
80f4348e21 | ||
|
|
e630827b34 | ||
|
|
106d9b0fc0 | ||
|
|
4a26f79945 | ||
|
|
1a199f6ce3 | ||
|
|
ec59e77867 | ||
|
|
cb28d2b611 | ||
|
|
27b6ddf5cb | ||
|
|
475c865e33 | ||
|
|
0b4ba062bb | ||
|
|
28f5e66662 | ||
|
|
e225a076f0 | ||
|
|
774c8ad0f8 | ||
|
|
52d1e7414d | ||
|
|
af4cb53e5f | ||
|
|
c019271e12 | ||
|
|
82ae2bce9d | ||
|
|
092e259a06 | ||
|
|
08b4bbfe91 | ||
|
|
560c51cf27 | ||
|
|
674f86b18a | ||
|
|
e3f10e0926 | ||
|
|
d7223d7387 | ||
|
|
45331c2a60 | ||
|
|
33f50a2c69 | ||
|
|
6c8e4d5cbd | ||
|
|
3b7215876a | ||
|
|
c74f5890bd | ||
|
|
fbd3c71ba7 | ||
|
|
128f9ab9d4 | ||
|
|
36fb359aa2 | ||
|
|
1bd73d69fe | ||
|
|
fb48285143 | ||
|
|
3de50b8370 | ||
|
|
e61cbe25b7 | ||
|
|
8395830be6 | ||
|
|
6e4ec2b9d8 | ||
|
|
f501bb8e28 | ||
|
|
d07cd3397d | ||
|
|
e008fb108a | ||
|
|
9aaffff7a8 | ||
|
|
7357b4a5df | ||
|
|
1ddc298a74 | ||
|
|
e2a9442aa6 | ||
|
|
aa0180571e | ||
|
|
7f7be39230 | ||
|
|
4d95415232 | ||
|
|
2cbd80a004 | ||
|
|
9abf8101da | ||
|
|
24badd06a5 | ||
|
|
7a03ef8eaf | ||
|
|
f3ea507313 | ||
|
|
4b0388a0e1 | ||
|
|
a84137b5ff | ||
|
|
ca02ee0352 | ||
|
|
fbaa54145e | ||
|
|
28754ffbf2 | ||
|
|
470c0eba7a | ||
|
|
7098dcec43 | ||
|
|
07137f57af | ||
|
|
8b7491a3d3 | ||
|
|
8cfa8ddfeb | ||
|
|
ef284a15a1 | ||
|
|
3723921573 | ||
|
|
195399635e | ||
|
|
46e2a924d3 | ||
|
|
b693ea4102 | ||
|
|
a73f55beb0 | ||
|
|
0bd2491ab7 | ||
|
|
860c797c9c | ||
|
|
38c5080f9f | ||
|
|
fae191d8fe | ||
|
|
d83a953e2d | ||
|
|
2dcf0d0f0d | ||
|
|
6dee37d8c1 | ||
|
|
3bad03afb3 | ||
|
|
6a6d8448f7 | ||
|
|
189babd2cf | ||
|
|
988a0f2294 | ||
|
|
85bf455731 | ||
|
|
589e4224f3 | ||
|
|
bd7fa154b4 | ||
|
|
a292f1992b | ||
|
|
88ddf429b7 | ||
|
|
7a1f6662df | ||
|
|
afc68bccc6 | ||
|
|
b4cdc4a64f | ||
|
|
3ad5afb81c | ||
|
|
bed3f20118 | ||
|
|
de67315178 | ||
|
|
8d5c0c7cad | ||
|
|
a8271e01bd | ||
|
|
900b3f8558 | ||
|
|
fdc4e056f9 | ||
|
|
7b98e40ccf | ||
|
|
01d89cf22c | ||
|
|
503a3c799a | ||
|
|
0b21388844 | ||
|
|
117bdf0c00 | ||
|
|
172dc5d37b | ||
|
|
874c6258ab | ||
|
|
a2d0a12c1a | ||
|
|
38b24e1c3d | ||
|
|
5ecbbe296b | ||
|
|
9d7a769d8f | ||
|
|
9b75e5ed83 | ||
|
|
a9ab8dc1d8 | ||
|
|
a34831aa02 | ||
|
|
84ebaa0751 | ||
|
|
55352805ee | ||
|
|
c0a3f2e16a | ||
|
|
28ff331a28 | ||
|
|
f9a53ec719 | ||
|
|
6a403e6caf | ||
|
|
a6f449bb93 | ||
|
|
0614bfc446 | ||
|
|
bb020c36c1 | ||
|
|
f17b0bfcfb | ||
|
|
2a85c9503f |
No files matched your search
@@ -1,49 +0,0 @@
|
|||||||
name: Setup devkitPro
|
|
||||||
description: Install devkitPro with GameCube/Wii packages on an Ubuntu runner
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Install apt dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y \
|
|
||||||
cmake \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
xorriso
|
|
||||||
- name: Install devkitPro pacman
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo ln -sf /proc/self/mounts /etc/mtab
|
|
||||||
wget https://apt.devkitpro.org/install-devkitpro-pacman \
|
|
||||||
-O /tmp/install-devkitpro-pacman
|
|
||||||
echo "=== installer script contents ==="
|
|
||||||
cat /tmp/install-devkitpro-pacman
|
|
||||||
echo "================================="
|
|
||||||
chmod +x /tmp/install-devkitpro-pacman
|
|
||||||
sudo /tmp/install-devkitpro-pacman
|
|
||||||
echo "DEVKITPRO=/opt/devkitpro" >> $GITHUB_ENV
|
|
||||||
echo "DEVKITPPC=/opt/devkitpro/devkitPPC" >> $GITHUB_ENV
|
|
||||||
echo "/opt/devkitpro/tools/bin" >> $GITHUB_PATH
|
|
||||||
echo "/opt/devkitpro/devkitPPC/bin" >> $GITHUB_PATH
|
|
||||||
- name: Install devkitPro GameCube/Wii packages
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo dkp-pacman -S --needed --noconfirm \
|
|
||||||
gamecube-dev \
|
|
||||||
gamecube-sdl2 \
|
|
||||||
ppc-liblzma \
|
|
||||||
ppc-libzip \
|
|
||||||
libogc2 \
|
|
||||||
gamecube-tools \
|
|
||||||
ppc-libmad \
|
|
||||||
ppc-zlib-ng \
|
|
||||||
ppc-bzip2 \
|
|
||||||
ppc-zstd
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
name: Setup pspdev
|
|
||||||
description: Install the pspdev PSP toolchain on an Ubuntu runner
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Install dependencies
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y cmake python3 python3-pip python3-dotenv
|
|
||||||
- name: Install pspdev toolchain
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
wget -q \
|
|
||||||
https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz \
|
|
||||||
-O /tmp/pspdev.tar.gz
|
|
||||||
sudo tar -xzf /tmp/pspdev.tar.gz -C /usr/local
|
|
||||||
echo "PSPDEV=/usr/local/pspdev" >> $GITHUB_ENV
|
|
||||||
echo "/usr/local/pspdev/bin" >> $GITHUB_PATH
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
name: Build Dusk
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
jobs:
|
|
||||||
run-tests:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y \
|
|
||||||
build-essential \
|
|
||||||
cmake \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
libsdl2-dev \
|
|
||||||
libgl1-mesa-dev \
|
|
||||||
libzip-dev \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
xz-utils \
|
|
||||||
liblzma-dev \
|
|
||||||
libbz2-dev \
|
|
||||||
zlib1g-dev \
|
|
||||||
git \
|
|
||||||
libssl-dev
|
|
||||||
- name: Run tests
|
|
||||||
run: ./scripts/test-linux.sh
|
|
||||||
|
|
||||||
build-linux:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y \
|
|
||||||
build-essential \
|
|
||||||
cmake \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
libsdl2-dev \
|
|
||||||
libgl1-mesa-dev \
|
|
||||||
libzip-dev \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
xz-utils \
|
|
||||||
liblzma-dev \
|
|
||||||
libbz2-dev \
|
|
||||||
zlib1g-dev \
|
|
||||||
git \
|
|
||||||
libssl-dev
|
|
||||||
- name: Build Linux
|
|
||||||
run: ./scripts/build-linux.sh
|
|
||||||
- name: Upload Linux binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-linux
|
|
||||||
path: build-linux/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-psp:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Setup pspdev
|
|
||||||
uses: ./.github/actions/setup-pspdev
|
|
||||||
- name: Build PSP
|
|
||||||
run: ./scripts/build-psp.sh
|
|
||||||
- name: Move EBOOT.PBP to Dusk subfolder
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
|
||||||
cp build-psp/EBOOT.PBP ./git-artifcats/Dusk/PSP/GAME/Dusk/EBOOT.PBP
|
|
||||||
- name: Upload PSP binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-psp
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-knulli:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: debian:trixie
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
dpkg --add-architecture arm64
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
crossbuild-essential-arm64 \
|
|
||||||
ca-certificates \
|
|
||||||
pkg-config \
|
|
||||||
cmake \
|
|
||||||
make \
|
|
||||||
ninja-build \
|
|
||||||
git \
|
|
||||||
file \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
liblua5.4-dev:arm64 \
|
|
||||||
xz-utils:arm64 \
|
|
||||||
libbz2-dev:arm64 \
|
|
||||||
zlib1g-dev:arm64 \
|
|
||||||
libzip-dev:arm64 \
|
|
||||||
libssl-dev:arm64 \
|
|
||||||
libsdl2-dev:arm64 \
|
|
||||||
liblzma-dev:arm64 \
|
|
||||||
libopengl0:arm64 \
|
|
||||||
libgl1:arm64 \
|
|
||||||
libegl1:arm64 \
|
|
||||||
libgles2:arm64 \
|
|
||||||
libgl1-mesa-dev:arm64
|
|
||||||
- name: Build Knulli
|
|
||||||
run: ./scripts/build-knulli.sh
|
|
||||||
- name: Move output to Dusk subfolder
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk
|
|
||||||
cp -r build-knulli/dusk ./git-artifcats/Dusk
|
|
||||||
- name: Upload Knulli binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-knulli
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-gamecube:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/extremscorner/libogc2:latest
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install additional dependencies
|
|
||||||
run: |
|
|
||||||
apt-get install -y \
|
|
||||||
python3-pip python3-polib python3-pil \
|
|
||||||
python3-dotenv python3-pyqt5 python3-opengl
|
|
||||||
dkp-pacman -Syu --noconfirm
|
|
||||||
dkp-pacman -S --needed --noconfirm \
|
|
||||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
|
||||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
|
||||||
- name: Build GameCube
|
|
||||||
run: ./scripts/build-gamecube.sh
|
|
||||||
- name: Copy output files
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk
|
|
||||||
cp build-gamecube/Dusk.dol ./git-artifcats/Dusk/Dusk.dol
|
|
||||||
cp build-gamecube/dusk.dsk ./git-artifcats/Dusk/dusk.dsk
|
|
||||||
- name: Upload GameCube binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-gamecube
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-gamecube-iso:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/extremscorner/libogc2:latest
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install additional dependencies
|
|
||||||
run: |
|
|
||||||
apt-get install -y \
|
|
||||||
python3-pip python3-polib python3-pil \
|
|
||||||
python3-dotenv python3-pyqt5 python3-opengl xorriso
|
|
||||||
dkp-pacman -Syu --noconfirm
|
|
||||||
dkp-pacman -S --needed --noconfirm \
|
|
||||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
|
||||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
|
||||||
- name: Build GameCube ISO
|
|
||||||
run: ./scripts/build-gamecube-iso.sh
|
|
||||||
- name: Copy output files
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk
|
|
||||||
cp build-gamecube-iso/Dusk-NTSC-J.iso ./git-artifcats/Dusk/Dusk-NTSC-J.iso
|
|
||||||
cp build-gamecube-iso/Dusk-NTSC-U.iso ./git-artifcats/Dusk/Dusk-NTSC-U.iso
|
|
||||||
cp build-gamecube-iso/Dusk-PAL.iso ./git-artifcats/Dusk/Dusk-PAL.iso
|
|
||||||
- name: Upload GameCube ISO
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-gamecube-iso
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-wii:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/extremscorner/libogc2:latest
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install additional dependencies
|
|
||||||
run: |
|
|
||||||
apt-get install -y \
|
|
||||||
python3-pip python3-polib python3-pil \
|
|
||||||
python3-dotenv python3-pyqt5 python3-opengl
|
|
||||||
dkp-pacman -Syu --noconfirm
|
|
||||||
dkp-pacman -S --needed --noconfirm \
|
|
||||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
|
||||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
|
||||||
- name: Build Wii
|
|
||||||
run: ./scripts/build-wii.sh
|
|
||||||
- name: Copy output files
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
|
||||||
cp build-wii/boot.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
|
|
||||||
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
|
||||||
cp build-wii/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
|
||||||
- name: Upload Wii binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-wii
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-wii-iso:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/extremscorner/libogc2:latest
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install additional dependencies
|
|
||||||
run: |
|
|
||||||
apt-get install -y \
|
|
||||||
python3-pip python3-polib python3-pil \
|
|
||||||
python3-dotenv python3-pyqt5 python3-opengl xorriso
|
|
||||||
dkp-pacman -Syu --noconfirm
|
|
||||||
dkp-pacman -S --needed --noconfirm \
|
|
||||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
|
||||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
|
||||||
- name: Build Wii ISO
|
|
||||||
run: ./scripts/build-wii-iso.sh
|
|
||||||
- name: Copy output files
|
|
||||||
run: |
|
|
||||||
mkdir -p ./git-artifcats/Dusk
|
|
||||||
cp build-wii-iso/Dusk-NTSC-J.iso ./git-artifcats/Dusk/Dusk-NTSC-J.iso
|
|
||||||
cp build-wii-iso/Dusk-NTSC-U.iso ./git-artifcats/Dusk/Dusk-NTSC-U.iso
|
|
||||||
cp build-wii-iso/Dusk-PAL.iso ./git-artifcats/Dusk/Dusk-PAL.iso
|
|
||||||
- name: Upload Wii ISO
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-wii-iso
|
|
||||||
path: ./git-artifcats/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
@@ -107,3 +107,4 @@ yarn.lock
|
|||||||
/assets/test
|
/assets/test
|
||||||
/tools_old
|
/tools_old
|
||||||
/assets/test.png
|
/assets/test.png
|
||||||
|
/assets/audio/boa.mp3
|
||||||
@@ -1,455 +0,0 @@
|
|||||||
# Dusk — Claude Code rules
|
|
||||||
|
|
||||||
## File headers
|
|
||||||
Every C, H, and JS file starts with:
|
|
||||||
|
|
||||||
```c
|
|
||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
JS files use `//` comment style instead.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## C conventions
|
|
||||||
|
|
||||||
### Types
|
|
||||||
Always use the project-defined aliases instead of bare C primitives:
|
|
||||||
|
|
||||||
| Use | Not |
|
|
||||||
|-----------|--------------|
|
|
||||||
| `bool_t` | `bool` |
|
|
||||||
| `int_t` | `int` |
|
|
||||||
| `float_t` | `float` |
|
|
||||||
| `char_t` | `char` |
|
|
||||||
|
|
||||||
Use `uint8_t`, `uint16_t`, `int32_t`, etc. for fixed-width integers.
|
|
||||||
All struct and enum types end in `_t` (`animation_t`, `errorret_t`, …).
|
|
||||||
|
|
||||||
### Naming
|
|
||||||
- **Functions** — snake_case, prefixed with their module:
|
|
||||||
`assetLock()`, `entityPositionInit()`, `moduleAssetBatchCtor()`
|
|
||||||
- **Struct fields** — camelCase: `keyframeCount`, `localPosition`
|
|
||||||
- **Macros / constants** — UPPER_SNAKE_CASE:
|
|
||||||
`ENTITY_ID_INVALID`, `ERROR_OK`, `COMPONENT_TYPE_COUNT`
|
|
||||||
- **Files** — snake_case matching the primary type: `entityposition.c`,
|
|
||||||
`moduleassetbatch.c`
|
|
||||||
|
|
||||||
### Header files (`.h`)
|
|
||||||
- Use `#pragma once` — no include guards.
|
|
||||||
- Declare every public function, `#define`, and `extern` global.
|
|
||||||
- Write a JSDoc block (`/** … */`) above every declaration explaining
|
|
||||||
purpose, `@param`s, and `@returns`.
|
|
||||||
- Only include headers that the `.h` file itself strictly requires for
|
|
||||||
the types it exposes. Move everything else to the `.c` file.
|
|
||||||
Do not use forward declarations as a workaround — use the real
|
|
||||||
include in the `.c` file instead.
|
|
||||||
|
|
||||||
### Implementation files (`.c`)
|
|
||||||
- Contain function bodies only; no declarations.
|
|
||||||
- Pull in whatever additional includes the implementation needs.
|
|
||||||
- Do not use `static` or `inline` on **functions**. Every function,
|
|
||||||
including internal helpers, must be declared in the matching `.h` and
|
|
||||||
defined in the `.c` file. Internal helpers belong near the bottom of
|
|
||||||
the `.c` file, not at the top with a `static` qualifier.
|
|
||||||
`static` and `inline` on functions are only appropriate when the
|
|
||||||
function body is written directly inside a `.h` file.
|
|
||||||
`static` on **variables** (file-scope state) is fine and expected.
|
|
||||||
|
|
||||||
### Formatting
|
|
||||||
- Hard-wrap all lines at **80 characters**.
|
|
||||||
|
|
||||||
### Error handling
|
|
||||||
Return `errorret_t` from fallible functions. Use these macros:
|
|
||||||
|
|
||||||
```c
|
|
||||||
errorOk(); // return success
|
|
||||||
errorThrow("msg %d", val); // return failure with message
|
|
||||||
errorChain(someCall()); // propagate failure, continue on success
|
|
||||||
errorIsOk(ret) / errorIsNotOk(ret) // test a result
|
|
||||||
errorCatch(ret); // handle + free an error
|
|
||||||
```
|
|
||||||
|
|
||||||
Never return raw error codes or use `errno` for in-engine errors.
|
|
||||||
|
|
||||||
### Memory
|
|
||||||
Use the project allocator — never raw `malloc`/`free`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
memoryAllocate(size) // allocate
|
|
||||||
memoryFree(ptr) // free
|
|
||||||
memoryZero(dest, size) // zero a block
|
|
||||||
memoryCopy(dest, src, size) // copy
|
|
||||||
```
|
|
||||||
|
|
||||||
### Asserts
|
|
||||||
Prefer specific assert macros over bare `assert()`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
assertNotNull(ptr, "msg");
|
|
||||||
assertTrue(cond, "msg");
|
|
||||||
assertFalse(cond, "msg");
|
|
||||||
assertUnreachable("msg");
|
|
||||||
assertIsMainThread("msg");
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Build system
|
|
||||||
Each subdirectory has its own `CMakeLists.txt` that adds sources with:
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
myfile.c
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Never add source files to the root `CMakeLists.txt` directly.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Platform support
|
|
||||||
|
|
||||||
### Targets
|
|
||||||
Set `DUSK_TARGET_SYSTEM` at CMake configure time to select a platform:
|
|
||||||
|
|
||||||
| `DUSK_TARGET_SYSTEM` | Macro defined | Platform |
|
|
||||||
|----------------------|-------------------|------------------|
|
|
||||||
| `linux` | `DUSK_LINUX` | Linux desktop |
|
|
||||||
| `knulli` | `DUSK_KNULLI` | Knulli (handheld)|
|
|
||||||
| `psp` | `DUSK_PSP` | Sony PSP |
|
|
||||||
| `vita` | `DUSK_VITA` | PlayStation Vita |
|
|
||||||
| `gamecube` | `DUSK_GAMECUBE` | Nintendo GameCube|
|
|
||||||
| `wii` | `DUSK_WII` | Nintendo Wii |
|
|
||||||
|
|
||||||
### Layer structure
|
|
||||||
```
|
|
||||||
src/dusk/ core, platform-agnostic game logic
|
|
||||||
src/duskgl/ OpenGL abstraction (Linux, Knulli, PSP, Vita)
|
|
||||||
src/dusksdl2/ SDL2 window + input (Linux, Knulli, PSP, Vita)
|
|
||||||
src/dusklinux/ Linux + Knulli platform impl
|
|
||||||
src/duskpsp/ PSP platform impl
|
|
||||||
src/duskvita/ Vita platform impl
|
|
||||||
src/duskdolphin/ GameCube / Wii platform impl (no SDL2/OpenGL)
|
|
||||||
```
|
|
||||||
|
|
||||||
Dolphin is the only target that bypasses SDL2 and OpenGL entirely —
|
|
||||||
it uses native GameCube/Wii rendering and input APIs.
|
|
||||||
|
|
||||||
### Platform guards
|
|
||||||
Use the compile-time macros for platform-specific code:
|
|
||||||
|
|
||||||
```c
|
|
||||||
#ifdef DUSK_PSP
|
|
||||||
// PSP-only path
|
|
||||||
#elif defined(DUSK_GAMECUBE) || defined(DUSK_WII)
|
|
||||||
// GameCube / Wii path
|
|
||||||
#else
|
|
||||||
// Generic / Linux fallback
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
|
|
||||||
Additional capability macros set per-target:
|
|
||||||
`DUSK_SDL2`, `DUSK_OPENGL`, `DUSK_OPENGL_ES`, `DUSK_OPENGL_LEGACY`,
|
|
||||||
`DUSK_INPUT_GAMEPAD`, `DUSK_INPUT_KEYBOARD`, `DUSK_INPUT_POINTER`,
|
|
||||||
`DUSK_PLATFORM_ENDIAN_BIG` / `DUSK_PLATFORM_ENDIAN_LITTLE`.
|
|
||||||
|
|
||||||
### Abstraction pattern
|
|
||||||
Platform-specific implementations are wired in via `#define` macros in
|
|
||||||
each platform's `displayplatform.h` / `inputplatform.h` etc., which
|
|
||||||
the core calls through. Functions that a platform does not support are
|
|
||||||
simply left undefined — the core guards calls with `#ifdef`.
|
|
||||||
|
|
||||||
### Adding platform-specific code
|
|
||||||
- Put it under `src/dusk<platform>/` in the matching subsystem folder.
|
|
||||||
- Gate any core call-site with the appropriate `#ifdef DUSK_<PLATFORM>`
|
|
||||||
or capability macro.
|
|
||||||
- Keep the `src/dusk/` core free of platform ifdefs — delegate through
|
|
||||||
the platform header macros instead.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Adding a new asset loader type
|
|
||||||
1. Add an enum value to `assetloadertype_t` (before `_COUNT`) in
|
|
||||||
`src/dusk/asset/loader/assetloader.h`.
|
|
||||||
2. Add fields to the input/loading/output unions in `assetloader.h`.
|
|
||||||
3. Implement `assetXxxLoaderSync`, `assetXxxLoaderAsync`, and
|
|
||||||
`assetXxxDispose` in a new `src/dusk/asset/loader/xxx/` directory.
|
|
||||||
4. Register the three callbacks in `ASSET_LOADER_CALLBACKS[]` in
|
|
||||||
`src/dusk/asset/loader/assetloader.c`.
|
|
||||||
5. If user-facing, create a JS module (see below) and a `.d.ts` file.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Adding a new entity component
|
|
||||||
1. Create `src/dusk/entity/component/<category>/entityMyComp.h/.c` with
|
|
||||||
struct `entityMyComp_t`, `entityMyCompInit()`, and optionally
|
|
||||||
`entityMyCompDispose()`.
|
|
||||||
2. Add the include to `src/dusk/entity/componentlist.h` header block.
|
|
||||||
3. Add a row to `src/dusk/entity/componentlist.h`:
|
|
||||||
```c
|
|
||||||
X(MYCOMP, entityMyComp_t, myComp, entityMyCompInit, NULL, NULL)
|
|
||||||
```
|
|
||||||
This auto-generates the enum, union field, and definition entry.
|
|
||||||
4. If JS-facing, create the script module and `.d.ts` (see below).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Adding a new script (JS) module
|
|
||||||
1. Create `src/dusk/script/module/<category>/moduleMyMod.h/.c`.
|
|
||||||
- Declare `extern scriptproto_t MODULE_MYMOD_PROTO;` in the header.
|
|
||||||
- Use `moduleBaseFunction(name)` to define JS-callable functions.
|
|
||||||
- Register props/funcs in `moduleMyModInit()` with
|
|
||||||
`scriptProtoDefineProp` / `scriptProtoDefineFunc` /
|
|
||||||
`scriptProtoDefineStaticFunc`.
|
|
||||||
2. `#include` the header in
|
|
||||||
`src/dusk/script/module/modulelist.c` and call
|
|
||||||
`moduleMyModInit()` in `moduleListInit()` (and `Dispose` in
|
|
||||||
`moduleListDispose()`).
|
|
||||||
3. For component modules also register in
|
|
||||||
`src/dusk/script/module/entity/component/modulecomponentlist.c`
|
|
||||||
so `entity.add()` returns the typed wrapper.
|
|
||||||
4. Create `types/<category>/mymod.d.ts` and add a
|
|
||||||
`/// <reference path="..." />` line to `types/index.d.ts`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Script module type declarations
|
|
||||||
Whenever a `src/dusk/script/module/**/*.c` file is created or modified,
|
|
||||||
check whether the corresponding `types/**/*.d.ts` needs updating and
|
|
||||||
apply any changes before finishing the task.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## JavaScript (asset scripts)
|
|
||||||
- Use `var` for module-level state; `const` for values that never
|
|
||||||
change.
|
|
||||||
- Always use semicolons.
|
|
||||||
- Scene objects are plain objects (`var scene = {}`) with assigned
|
|
||||||
methods.
|
|
||||||
- Export via `module.exports = scene`.
|
|
||||||
- Async scene init should use `async function` and `await`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Coding style
|
|
||||||
|
|
||||||
### ASCII only
|
|
||||||
Source files (`.c`, `.h`, `.js`) must contain only ASCII characters (U+0000–U+007F).
|
|
||||||
Non-ASCII characters are banned even in comments and string literals.
|
|
||||||
Use ASCII-only substitutes instead:
|
|
||||||
- `--` or `-` instead of `—` (em dash)
|
|
||||||
- `->` instead of `→` (arrow)
|
|
||||||
- `x` or `*` instead of `×` (multiplication)
|
|
||||||
|
|
||||||
Only non-script asset files (e.g. `.po` locale files) may contain non-ASCII text.
|
|
||||||
|
|
||||||
### Indentation
|
|
||||||
2 spaces. No tabs.
|
|
||||||
|
|
||||||
### Keyword and operator spacing
|
|
||||||
No space between a keyword or function name and its opening parenthesis:
|
|
||||||
|
|
||||||
```c
|
|
||||||
if(!ptr) return;
|
|
||||||
for(uint8_t i = 0; i < count; i++) {
|
|
||||||
while(entry->state != DONE) {
|
|
||||||
switch(type) {
|
|
||||||
sizeof(assetbatch_t)
|
|
||||||
memoryZero(ptr, size)
|
|
||||||
```
|
|
||||||
|
|
||||||
Spaces around all binary operators and after every comma:
|
|
||||||
|
|
||||||
```c
|
|
||||||
pos->flags |= ENTITY_POSITION_FLAG_WORLD_DIRTY;
|
|
||||||
(size_t)end - (size_t)start
|
|
||||||
foo(a, b, c)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Braces
|
|
||||||
Opening brace on the **same line** as the statement (K&R style) for all
|
|
||||||
constructs — functions, `if`, `else`, `for`, `while`, `switch`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
void assetEntryLock(assetentry_t *entry) {
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dirty) {
|
|
||||||
...
|
|
||||||
} else {
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Guard returns
|
|
||||||
Short guards go on one line with no braces:
|
|
||||||
|
|
||||||
```c
|
|
||||||
if(!ptr) return;
|
|
||||||
if(!b || !b->batch) return jerry_undefined();
|
|
||||||
if(!(flags & DIRTY)) return;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Blank lines
|
|
||||||
- One blank line between functions; no blank line at the start or end of
|
|
||||||
a function body.
|
|
||||||
- One blank line between logical blocks inside a function body.
|
|
||||||
- No trailing blank lines at the end of a file.
|
|
||||||
|
|
||||||
### Pointer placement
|
|
||||||
`*` is attached to the variable name, not the type:
|
|
||||||
|
|
||||||
```c
|
|
||||||
assetentry_t *entry
|
|
||||||
const char_t *name
|
|
||||||
void *ptr
|
|
||||||
uint8_t *d = (uint8_t *)dest;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Casts
|
|
||||||
Space between cast and operand:
|
|
||||||
|
|
||||||
```c
|
|
||||||
(assetbatch_t *)user
|
|
||||||
(uint8_t *)dest
|
|
||||||
(textureformat_t)v
|
|
||||||
```
|
|
||||||
|
|
||||||
### Return
|
|
||||||
No parentheses around the return value:
|
|
||||||
|
|
||||||
```c
|
|
||||||
return ptr;
|
|
||||||
return MEMORY_POINTERS_IN_USE;
|
|
||||||
```
|
|
||||||
|
|
||||||
### switch / case
|
|
||||||
`case` indented 2 spaces from `switch`; body indented 2 more from `case`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
switch(type) {
|
|
||||||
case ASSET_LOADER_TYPE_TEXTURE:
|
|
||||||
descs[i].input.texture = (textureformat_t)v;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Multi-line function signatures
|
|
||||||
When parameters don't fit on one line, put each on its own line indented
|
|
||||||
2 spaces; the closing `) {` (definition) or `);` (declaration) goes on
|
|
||||||
its own line at column 0:
|
|
||||||
|
|
||||||
```c
|
|
||||||
void assetEntryInit(
|
|
||||||
assetentry_t *entry,
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
) {
|
|
||||||
|
|
||||||
errorret_t memoryCompare(
|
|
||||||
const void *a,
|
|
||||||
const void *b,
|
|
||||||
const size_t size
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
### Structs and enums
|
|
||||||
Anonymous inner struct or enum with a `typedef`, `_t` suffix, closing
|
|
||||||
brace and name on the same line:
|
|
||||||
|
|
||||||
```c
|
|
||||||
typedef struct {
|
|
||||||
errorcode_t code;
|
|
||||||
char_t *message;
|
|
||||||
} errorstate_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_LOADER_TYPE_NULL,
|
|
||||||
ASSET_LOADER_TYPE_COUNT
|
|
||||||
} assetloadertype_t;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Designated initialisers
|
|
||||||
Spaces inside braces; `.field = value`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
jsassetentry_t e = { .entry = entry };
|
|
||||||
assetbatchloadedpend_t init = { .batch = batch };
|
|
||||||
```
|
|
||||||
|
|
||||||
### Ternary operator
|
|
||||||
Spaces around `?` and `:`:
|
|
||||||
|
|
||||||
```c
|
|
||||||
const float val = psx > 0.0f ? pt[0][0] / psx : 0.0f;
|
|
||||||
```
|
|
||||||
|
|
||||||
### const placement
|
|
||||||
`const` before the type, `*` attached to the variable:
|
|
||||||
|
|
||||||
```c
|
|
||||||
const char_t *name
|
|
||||||
const void *src
|
|
||||||
const size_t size
|
|
||||||
```
|
|
||||||
|
|
||||||
### Comments in `.c` files
|
|
||||||
- Do not use section dividers (`/* ---- ... ---- */`). Just let the
|
|
||||||
functions follow one another with a single blank line between them.
|
|
||||||
- Multi-line explanatory comments inside function bodies use `//` lines:
|
|
||||||
```c
|
|
||||||
// Script modules are freed; orphaned JS wrapper objects now get GC'd
|
|
||||||
// so their finalizers fire before assetDispose() checks ref counts.
|
|
||||||
jerry_heap_gc(JERRY_GC_PRESSURE_HIGH);
|
|
||||||
```
|
|
||||||
- Do not use `/* */` for inline or inline-block comments inside `.c`
|
|
||||||
function bodies.
|
|
||||||
|
|
||||||
### Comments in `.h` files
|
|
||||||
Every public declaration gets a Javadoc block (`/** … */`) with
|
|
||||||
`@param` and `@returns` where relevant. Keep it on the lines immediately
|
|
||||||
above the declaration with no blank line in between.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Color system
|
|
||||||
|
|
||||||
Colors are defined in `src/dusk/display/color.csv` and code-generated
|
|
||||||
into a `color.h` header by `tools/color/csv/__main__.py`.
|
|
||||||
|
|
||||||
Each row in the CSV has `name,r,g,b,a` with channel values in `[0.0, 1.0]`.
|
|
||||||
The script emits four `#define` variants per color plus a bare alias:
|
|
||||||
|
|
||||||
```
|
|
||||||
COLOR_<NAME>_4B color4b(r8, g8, b8, a8) // default alias target
|
|
||||||
COLOR_<NAME>_3B color3b(r8, g8, b8)
|
|
||||||
COLOR_<NAME>_3F color3f(rf, gf, bf)
|
|
||||||
COLOR_<NAME>_4F color4f(rf, gf, bf, af)
|
|
||||||
COLOR_<NAME> COLOR_<NAME>_4B
|
|
||||||
```
|
|
||||||
|
|
||||||
`color_t` is `color4b_t` (four `uint8_t` channels).
|
|
||||||
|
|
||||||
To add a new color, append a row to `color.csv` and rebuild — do not
|
|
||||||
hand-edit the generated header.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
- Tests live in `test/` mirroring `src/dusk/` structure.
|
|
||||||
- Use cmocka; include `dusktest.h`.
|
|
||||||
- Test functions: `static void test_something(void **state)`.
|
|
||||||
- After each test, assert `memoryGetAllocatedCount() == 0` to catch
|
|
||||||
leaks.
|
|
||||||
- Build with `-DDUSK_BUILD_TESTS=ON`.
|
|
||||||
+62
-94
@@ -1,130 +1,98 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
# Copyright (c) 2026 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Setup
|
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
|
||||||
cmake_policy(SET CMP0079 NEW)
|
|
||||||
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
|
||||||
|
|
||||||
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
# Directories
|
||||||
|
|
||||||
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
|
||||||
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder")
|
|
||||||
set(DUSK_GAME_SHORT_DESCRIPTION "Dusk game" CACHE STRING "One-line description")
|
|
||||||
set(DUSK_GAME_LONG_DESCRIPTION "No description yet." CACHE STRING "Full description")
|
|
||||||
|
|
||||||
# Prep cache
|
|
||||||
set(DUSK_CACHE_TARGET "dusk-target")
|
|
||||||
|
|
||||||
# Build variables
|
|
||||||
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||||
set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
|
||||||
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
||||||
set(DUSK_TEST_DIR "${DUSK_ROOT_DIR}/test")
|
|
||||||
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
|
||||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
|
||||||
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
|
||||||
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
||||||
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
set(DUSK_BUILT_ASSETS_DIR "${CMAKE_BINARY_DIR}/assets")
|
||||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
set(DUSK_GENERATED_HEADERS_DIR "${CMAKE_BINARY_DIR}/generated")
|
||||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
set(DUSK_ASSETS "" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
set(DUSK_LIBRARY_TARGET_NAME "DuskCore" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
set(DUSK_BINARY_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
|
||||||
set(DUSK_TARGET_SYSTEM "linux")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Create directories
|
|
||||||
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
||||||
file(MAKE_DIRECTORY ${DUSK_TEMP_DIR})
|
|
||||||
file(MAKE_DIRECTORY ${DUSK_BUILT_ASSETS_DIR})
|
|
||||||
|
|
||||||
# Required build packages
|
project(DuskCore VERSION 1.0.0 LANGUAGES C)
|
||||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
|
||||||
|
|
||||||
# Init Project.
|
# Work out the target platform unless one was given explicitly.
|
||||||
project(${DUSK_LIBRARY_TARGET_NAME}
|
include(${DUSK_ROOT_DIR}/cmake/determineplatform.cmake)
|
||||||
VERSION 1.0.0
|
|
||||||
LANGUAGES C
|
# Platform defaults and definitions (sets DUSK_DEFAULT_* and
|
||||||
|
# DUSK_PLATFORM_DIRS / DUSK_PLATFORM_DEFINITIONS).
|
||||||
|
set(DUSK_TARGET_FILE
|
||||||
|
"${DUSK_ROOT_DIR}/cmake/${DUSK_TARGET_SYSTEM}/target.cmake"
|
||||||
)
|
)
|
||||||
|
if(NOT EXISTS "${DUSK_TARGET_FILE}")
|
||||||
|
message(FATAL_ERROR "Unknown DUSK_TARGET_SYSTEM: ${DUSK_TARGET_SYSTEM}")
|
||||||
|
endif()
|
||||||
|
include("${DUSK_TARGET_FILE}")
|
||||||
|
|
||||||
# Either, create library and binary separately (used for tests), or make them
|
# All options and their defaults.
|
||||||
# one in the same so all code is in the binary only.
|
include(${DUSK_ROOT_DIR}/cmake/option.cmake)
|
||||||
# Binary Executable
|
|
||||||
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/dusk/null.c)
|
# Targets. Tests split the code into a library plus the binary, otherwise all
|
||||||
|
# code is compiled straight into the binary.
|
||||||
|
set(DUSK_BINARY_TARGET_NAME "Dusk")
|
||||||
|
add_executable(${DUSK_BINARY_TARGET_NAME})
|
||||||
|
|
||||||
if(DUSK_BUILD_TESTS)
|
if(DUSK_BUILD_TESTS)
|
||||||
# MainLibrary
|
set(DUSK_LIBRARY_TARGET_NAME "DuskCore")
|
||||||
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
||||||
|
target_link_libraries(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||||
# Link library to binary
|
|
||||||
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
${DUSK_LIBRARY_TARGET_NAME}
|
${DUSK_LIBRARY_TARGET_NAME}
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_VERSION)
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
string(TIMESTAMP DUSK_VERSION "debug-%y%m%d%H%M%S")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Definitions
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
DUSK_TARGET_SYSTEM="${DUSK_TARGET_SYSTEM}"
|
DUSK_TARGET_SYSTEM="${DUSK_TARGET_SYSTEM}"
|
||||||
DUSK_GAME_NAME="${DUSK_GAME_NAME}"
|
DUSK_GAME_NAME="${DUSK_GAME_NAME}"
|
||||||
DUSK_GAME_AUTHOR="${DUSK_GAME_AUTHOR}"
|
DUSK_GAME_AUTHOR="${DUSK_GAME_AUTHOR}"
|
||||||
DUSK_GAME_SHORT_DESCRIPTION="${DUSK_GAME_SHORT_DESCRIPTION}"
|
|
||||||
DUSK_GAME_LONG_DESCRIPTION="${DUSK_GAME_LONG_DESCRIPTION}"
|
|
||||||
DUSK_VERSION="${DUSK_VERSION}"
|
DUSK_VERSION="${DUSK_VERSION}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Toolchains
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
${DUSK_PLATFORM_DEFINITIONS}
|
||||||
|
|
||||||
# Add tools
|
|
||||||
add_subdirectory(tools)
|
|
||||||
|
|
||||||
# Include generated headers from tools.
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
${DUSK_GENERATED_HEADERS_DIR}
|
|
||||||
)
|
)
|
||||||
|
foreach(OPT ASSERTIONS_FAKED BACKTRACE TRACK_MEMORY NETWORK)
|
||||||
|
if(DUSK_${OPT})
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC DUSK_${OPT})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
# Add main code
|
if(DUSK_BACKTRACE)
|
||||||
add_subdirectory(${DUSK_SOURCES_DIR})
|
target_link_options(${DUSK_LIBRARY_TARGET_NAME} PUBLIC -rdynamic)
|
||||||
|
|
||||||
# Include generated headers
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
${DUSK_GENERATED_HEADERS_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Handle tests
|
|
||||||
if(DUSK_BUILD_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(test)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build assets
|
# Tools (run during the build to generate headers)
|
||||||
file(GLOB_RECURSE DUSK_ASSET_FILES CONFIGURE_DEPENDS "${DUSK_ASSETS_DIR}/*")
|
add_subdirectory(tools)
|
||||||
add_custom_command(
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
OUTPUT "${DUSK_ASSETS_ZIP}"
|
${DUSK_GENERATED_HEADERS_DIR}
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
|
||||||
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
|
||||||
DEPENDS ${DUSK_ASSET_FILES}
|
|
||||||
VERBATIM
|
|
||||||
)
|
)
|
||||||
add_custom_target(DUSK_ASSETS_BUILT DEPENDS "${DUSK_ASSETS_ZIP}")
|
|
||||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
# Core engine code
|
||||||
|
add_subdirectory(${DUSK_SOURCES_DIR}/dusk)
|
||||||
|
|
||||||
|
# Assets, copied into <build>/assets
|
||||||
|
include(${DUSK_ROOT_DIR}/cmake/asset/asset.cmake)
|
||||||
|
# Separate binary dir, so <build>/assets only contains built assets.
|
||||||
|
add_subdirectory(${DUSK_ROOT_DIR}/assets ${CMAKE_BINARY_DIR}/assets_cmake)
|
||||||
|
dusk_assets_finalize(DuskAssets)
|
||||||
|
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DuskAssets)
|
||||||
|
|
||||||
|
# Game code
|
||||||
|
add_subdirectory(${DUSK_SOURCES_DIR}/${DUSK_GAME})
|
||||||
|
|
||||||
|
# Platform code
|
||||||
|
foreach(DIR ${DUSK_PLATFORM_DIRS})
|
||||||
|
add_subdirectory(${DUSK_SOURCES_DIR}/${DIR})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(DUSK_BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
endif()
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
# Dusk
|
|
||||||
RPG Game Project, small and able to run on a PSP.
|
|
||||||
|
|
||||||
# Building
|
|
||||||
Each build target has different requirements. You can take a look at the git
|
|
||||||
workflow to see how the builds are done for each target. In addition, for
|
|
||||||
accessing the editor and building the game on your host system, install the
|
|
||||||
following packages, depending on your system;
|
|
||||||
|
|
||||||
Fedora;
|
|
||||||
```
|
|
||||||
sudo dnf install git make gcc cmake python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel zlib-devel libzip-devel bzip2-devel openssl-devel lzma-sdk-devel xz xz-devel lua-devel
|
|
||||||
```
|
|
||||||
|
|
||||||
Ubuntu;
|
|
||||||
```
|
|
||||||
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl
|
|
||||||
```
|
|
||||||
|
|
||||||
Arch Linux;
|
|
||||||
```
|
|
||||||
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl
|
|
||||||
```
|
|
||||||
@@ -3,8 +3,4 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
include(dusktest)
|
add_asset(cube.obj)
|
||||||
|
|
||||||
# Tests
|
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
|||||||
|
# Unit cube, centered on the origin, with per face normals and UVs.
|
||||||
|
o Cube
|
||||||
|
|
||||||
|
v -0.5 -0.5 -0.5
|
||||||
|
v 0.5 -0.5 -0.5
|
||||||
|
v 0.5 0.5 -0.5
|
||||||
|
v -0.5 0.5 -0.5
|
||||||
|
v -0.5 -0.5 0.5
|
||||||
|
v 0.5 -0.5 0.5
|
||||||
|
v 0.5 0.5 0.5
|
||||||
|
v -0.5 0.5 0.5
|
||||||
|
|
||||||
|
vt 0.0 0.0
|
||||||
|
vt 1.0 0.0
|
||||||
|
vt 1.0 1.0
|
||||||
|
vt 0.0 1.0
|
||||||
|
|
||||||
|
vn 0.0 0.0 -1.0
|
||||||
|
vn 0.0 0.0 1.0
|
||||||
|
vn -1.0 0.0 0.0
|
||||||
|
vn 1.0 0.0 0.0
|
||||||
|
vn 0.0 -1.0 0.0
|
||||||
|
vn 0.0 1.0 0.0
|
||||||
|
|
||||||
|
# Back (-Z)
|
||||||
|
f 2/1/1 1/2/1 4/3/1
|
||||||
|
f 2/1/1 4/3/1 3/4/1
|
||||||
|
# Front (+Z)
|
||||||
|
f 5/1/2 6/2/2 7/3/2
|
||||||
|
f 5/1/2 7/3/2 8/4/2
|
||||||
|
# Left (-X)
|
||||||
|
f 1/1/3 5/2/3 8/3/3
|
||||||
|
f 1/1/3 8/3/3 4/4/3
|
||||||
|
# Right (+X)
|
||||||
|
f 6/1/4 2/2/4 3/3/4
|
||||||
|
f 6/1/4 3/3/4 7/4/4
|
||||||
|
# Bottom (-Y)
|
||||||
|
f 1/1/5 2/2/5 6/3/5
|
||||||
|
f 1/1/5 6/3/5 5/4/5
|
||||||
|
# Top (+Y)
|
||||||
|
f 8/1/6 7/2/6 3/3/6
|
||||||
|
f 8/1/6 3/3/6 4/4/6
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
const platformNames = {
|
|
||||||
[System.PLATFORM_LINUX]: 'Linux',
|
|
||||||
[System.PLATFORM_KNULLI]: 'Knulli',
|
|
||||||
[System.PLATFORM_PSP]: 'PSP',
|
|
||||||
[System.PLATFORM_GAMECUBE]: 'GameCube',
|
|
||||||
[System.PLATFORM_WII]: 'Wii',
|
|
||||||
};
|
|
||||||
|
|
||||||
Console.print('Platform: ' + (platformNames[System.platform] || 'Unknown'));
|
|
||||||
|
|
||||||
UIFullboxOver.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
requireAsync('testscene.js').then(Scene.set).catch(err => {
|
|
||||||
Console.print('Error loading scene: ' + err);
|
|
||||||
Engine.exit();
|
|
||||||
});
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Project-Id-Version: ExampleApp 1.0\n"
|
|
||||||
"Language: en\n"
|
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
|
||||||
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : n==2 ? 1 : (n<7 ? 2 : 3));\n"
|
|
||||||
|
|
||||||
#: ui/menu.c:10
|
|
||||||
msgid "ui.title"
|
|
||||||
msgstr ""
|
|
||||||
"Welcome"
|
|
||||||
|
|
||||||
#: ui/user.c:22
|
|
||||||
msgid "ui.greeting"
|
|
||||||
msgstr "Hello, %s!"
|
|
||||||
|
|
||||||
#: ui/files.c:40
|
|
||||||
msgid "ui.file_status"
|
|
||||||
msgstr "%s has %d files."
|
|
||||||
|
|
||||||
#: ui/cart.c:55
|
|
||||||
msgid "cart.item_count"
|
|
||||||
msgid_plural "cart.item_count"
|
|
||||||
msgstr[0] "%d item"
|
|
||||||
msgstr[1] "%d items (dual)"
|
|
||||||
msgstr[2] "%d items (few)"
|
|
||||||
msgstr[3] "%d items (many)"
|
|
||||||
|
|
||||||
#: ui/notifications.c:71
|
|
||||||
msgid ""
|
|
||||||
"ui.multiline_help"
|
|
||||||
msgstr ""
|
|
||||||
"Line one of the help text.\n"
|
|
||||||
"Line two continues here.\n"
|
|
||||||
"Line three ends here."
|
|
||||||
|
|
||||||
#: ui/errors.c:90
|
|
||||||
msgid ""
|
|
||||||
"error.upload_failed.long"
|
|
||||||
msgstr ""
|
|
||||||
"Upload failed for file \"%s\".\n"
|
|
||||||
"Please try again later or contact support."
|
|
||||||
|
|
||||||
#: ui/messages.c:110
|
|
||||||
msgid ""
|
|
||||||
"user.invite_status"
|
|
||||||
msgid_plural ""
|
|
||||||
"user.invite_status"
|
|
||||||
msgstr[0] ""
|
|
||||||
"%s invited %d user.\n"
|
|
||||||
"Please review the request."
|
|
||||||
msgstr[1] ""
|
|
||||||
"%s invited %d users (dual).\n"
|
|
||||||
"Please review the requests."
|
|
||||||
msgstr[2] ""
|
|
||||||
"%s invited %d users (few).\n"
|
|
||||||
"Please review the requests."
|
|
||||||
msgstr[3] ""
|
|
||||||
"%s invited %d users (many).\n"
|
|
||||||
"Please review the requests."
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
const PLAYER_SPEED = 5.0;
|
|
||||||
// 1 world unit = 16 pixels.
|
|
||||||
const PIXEL_SCALE = 1.0 / 16.0;
|
|
||||||
// Player sprite is 32x32 px (test.png dimensions).
|
|
||||||
const PLAYER_W = 32 * PIXEL_SCALE;
|
|
||||||
const PLAYER_H = 32 * PIXEL_SCALE;
|
|
||||||
|
|
||||||
var player = {};
|
|
||||||
|
|
||||||
player.getAssets = () => {
|
|
||||||
return [
|
|
||||||
{ path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
player.init = function(scene) {
|
|
||||||
var texture = scene.assets.getAssetByPath('test.png');
|
|
||||||
Console.print('Player init: got texture ' + texture);
|
|
||||||
|
|
||||||
_entity = Entity.create();
|
|
||||||
_position = _entity.add(Component.POSITION);
|
|
||||||
_physics = _entity.add(Component.PHYSICS);
|
|
||||||
|
|
||||||
_physics.bodyType = Physics.DYNAMIC;
|
|
||||||
_physics.shape = Physics.SHAPE_CUBE;
|
|
||||||
_physics.gravityScale = 1.0;
|
|
||||||
|
|
||||||
var r = _entity.add(Component.RENDERABLE);
|
|
||||||
r.texture = texture.texture;
|
|
||||||
r.type = Renderable.SPRITEBATCH;
|
|
||||||
r.color = new Color(220, 80, 80);
|
|
||||||
// Upright quad centered on X, bottom-aligned on Y.
|
|
||||||
r.sprites = [[-PLAYER_W/2, 0, 0, PLAYER_W/2, PLAYER_H, 0, 0, 1, 1, 0]];
|
|
||||||
|
|
||||||
_position.localPosition = new Vec3(0, PLAYER_H, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
player.getPosition = function() {
|
|
||||||
return _position;
|
|
||||||
};
|
|
||||||
|
|
||||||
player.update = function() {
|
|
||||||
if(!_physics) return;
|
|
||||||
var vx = Input.axis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT) * PLAYER_SPEED;
|
|
||||||
var vz = Input.axis(INPUT_ACTION_DOWN, INPUT_ACTION_UP) * PLAYER_SPEED;
|
|
||||||
// Preserve vertical velocity so gravity and landing work correctly.
|
|
||||||
var vy = _physics.velocity.y;
|
|
||||||
_physics.velocity = new Vec3(vx, vy, vz);
|
|
||||||
};
|
|
||||||
|
|
||||||
player.dispose = function() {
|
|
||||||
Entity.dispose(_entity);
|
|
||||||
_entity = null;
|
|
||||||
_position = null;
|
|
||||||
_physics = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = player;
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
var scene = {};
|
|
||||||
|
|
||||||
// Pokemon DS-style camera: ~34 degrees elevation (atan(6/9)).
|
|
||||||
// CAM_HEIGHT / CAM_DIST ratio controls the tilt - keep it under 0.7 for
|
|
||||||
// the characteristically shallow DS angle.
|
|
||||||
const CAM_HEIGHT = 6;
|
|
||||||
const CAM_DIST = 9;
|
|
||||||
|
|
||||||
scene.init = async function() {
|
|
||||||
// Camera
|
|
||||||
scene.cam = Entity.create();
|
|
||||||
var camPos = scene.cam.add(Component.POSITION);
|
|
||||||
var cam = scene.cam.add(Component.CAMERA);
|
|
||||||
camPos.localPosition = new Vec3(3, 3, 3);
|
|
||||||
camPos.lookAt(new Vec3(0, 0, 0));
|
|
||||||
|
|
||||||
// Floor - large flat slab, no texture needed.
|
|
||||||
scene.floor = Entity.create();
|
|
||||||
var floorPos = scene.floor.add(Component.POSITION);
|
|
||||||
var floorR = scene.floor.add(Component.RENDERABLE);
|
|
||||||
floorR.type = Renderable.SHADER_MATERIAL;
|
|
||||||
floorR.color = Color.BLUE;
|
|
||||||
// floorPos.localScale = new Vec3(16, 0.2, 16);
|
|
||||||
// floorPos.localPosition = new Vec3(0, -0.1, 0);
|
|
||||||
|
|
||||||
await UIFullboxOver.transition(Color.BLACK, Color.TRANSPARENT, 1.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
scene.update = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
scene.dispose = function() {
|
|
||||||
Entity.dispose(scene.floor);
|
|
||||||
Entity.dispose(scene.cam);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = scene;
|
|
||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -1,6 +0,0 @@
|
|||||||
module = {
|
|
||||||
render() {
|
|
||||||
Text.draw(0, 0, "Hello World");
|
|
||||||
SpriteBatch.flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Asset building. Include this from the root CMakeLists.txt.
|
||||||
|
#
|
||||||
|
# Assets are registered with add_asset() and built by dusk_assets_finalize().
|
||||||
|
# Each asset is dispatched on its file extension to a handler function named
|
||||||
|
# dusk_asset_<extension> (e.g. dusk_asset_obj), defined in its own file in this
|
||||||
|
# directory. Extensions without a handler fall back to a plain copy.
|
||||||
|
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/copy.cmake)
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/obj.cmake)
|
||||||
|
|
||||||
|
# Registers an asset to be built into the project. The path is relative to the
|
||||||
|
# calling CMakeLists.txt, and is kept relative to the root assets directory in
|
||||||
|
# the output, so assets/models/a.obj ends up at <build>/assets/models/a.obj.
|
||||||
|
#
|
||||||
|
# This only records the asset. The build rules are created by
|
||||||
|
# dusk_assets_finalize() from the root CMakeLists.txt, because a custom command
|
||||||
|
# output can only be used by targets in the directory it was defined in.
|
||||||
|
function(add_asset ASSET_PATH)
|
||||||
|
set(ASSET_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/${ASSET_PATH}")
|
||||||
|
if(NOT EXISTS "${ASSET_SOURCE}")
|
||||||
|
message(FATAL_ERROR "add_asset: ${ASSET_SOURCE} does not exist")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(GLOBAL APPEND PROPERTY DUSK_ASSET_SOURCES "${ASSET_SOURCE}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Determines the lowercase extension of an asset, without the leading dot.
|
||||||
|
function(dusk_asset_extension ASSET_SOURCE OUT_VAR)
|
||||||
|
get_filename_component(ASSET_EXT "${ASSET_SOURCE}" LAST_EXT)
|
||||||
|
string(TOLOWER "${ASSET_EXT}" ASSET_EXT)
|
||||||
|
string(REGEX REPLACE "^\\." "" ASSET_EXT "${ASSET_EXT}")
|
||||||
|
set(${OUT_VAR} "${ASSET_EXT}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Creates the TARGET_NAME target, which builds every asset registered with
|
||||||
|
# add_asset(). Call once from the root CMakeLists.txt after adding the assets.
|
||||||
|
function(dusk_assets_finalize TARGET_NAME)
|
||||||
|
get_property(ASSET_SOURCES GLOBAL PROPERTY DUSK_ASSET_SOURCES)
|
||||||
|
|
||||||
|
set(ASSET_OUTPUTS "")
|
||||||
|
foreach(ASSET_SOURCE IN LISTS ASSET_SOURCES)
|
||||||
|
file(RELATIVE_PATH ASSET_RELATIVE "${DUSK_ASSETS_DIR}" "${ASSET_SOURCE}")
|
||||||
|
dusk_asset_extension("${ASSET_SOURCE}" ASSET_EXT)
|
||||||
|
|
||||||
|
# Dispatch on the extension, falling back to a plain copy.
|
||||||
|
set(ASSET_OUTPUT "")
|
||||||
|
if(COMMAND dusk_asset_${ASSET_EXT})
|
||||||
|
cmake_language(CALL dusk_asset_${ASSET_EXT}
|
||||||
|
"${ASSET_SOURCE}" "${ASSET_RELATIVE}" ASSET_OUTPUT
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(STATUS "Asset ${ASSET_RELATIVE}: no handler for '.${ASSET_EXT}', copying")
|
||||||
|
dusk_asset_copy("${ASSET_SOURCE}" "${ASSET_RELATIVE}" ASSET_OUTPUT)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND ASSET_OUTPUTS "${ASSET_OUTPUT}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_custom_target(${TARGET_NAME} ALL DEPENDS ${ASSET_OUTPUTS})
|
||||||
|
endfunction()
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Handler that copies an asset into the built assets directory as is. Every
|
||||||
|
# handler has the signature (SOURCE RELATIVE OUT_VAR) and must set OUT_VAR, in
|
||||||
|
# the caller's scope, to the file it produces.
|
||||||
|
function(dusk_asset_copy ASSET_SOURCE ASSET_RELATIVE OUT_VAR)
|
||||||
|
set(ASSET_OUTPUT "${DUSK_BUILT_ASSETS_DIR}/${ASSET_RELATIVE}")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${ASSET_OUTPUT}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${ASSET_SOURCE}" "${ASSET_OUTPUT}"
|
||||||
|
DEPENDS "${ASSET_SOURCE}"
|
||||||
|
COMMENT "Copying asset ${ASSET_RELATIVE}"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
set(${OUT_VAR} "${ASSET_OUTPUT}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Handler for .obj (Wavefront mesh) assets. Currently just copies the file.
|
||||||
|
function(dusk_asset_obj ASSET_SOURCE ASSET_RELATIVE OUT_VAR)
|
||||||
|
dusk_asset_copy("${ASSET_SOURCE}" "${ASSET_RELATIVE}" ASSET_OUTPUT)
|
||||||
|
set(${OUT_VAR} "${ASSET_OUTPUT}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Determines DUSK_TARGET_SYSTEM when it was not explicitly provided with
|
||||||
|
# -DDUSK_TARGET_SYSTEM=<target>. Must be included after project() so that the
|
||||||
|
# compiler and CMAKE_SYSTEM_NAME are known.
|
||||||
|
#
|
||||||
|
# Console toolchains all cross compile as "Generic", so they are recognised by
|
||||||
|
# the compiler they configure.
|
||||||
|
|
||||||
|
if(DUSK_TARGET_SYSTEM)
|
||||||
|
message(STATUS "Dusk target: ${DUSK_TARGET_SYSTEM} (explicit)")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_C_COMPILER MATCHES "psp-")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "psp")
|
||||||
|
elseif(CMAKE_C_COMPILER MATCHES "arm-vita-eabi")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "vita")
|
||||||
|
elseif(CMAKE_C_COMPILER MATCHES "powerpc-eabi")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "dolphin")
|
||||||
|
elseif(CMAKE_C_COMPILER MATCHES "ps2")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "ps2")
|
||||||
|
elseif(CMAKE_C_COMPILER MATCHES "sh-elf")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "dreamcast")
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "windows")
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
set(DUSK_DETECTED_SYSTEM "linux")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Could not determine the target platform (system: ${CMAKE_SYSTEM_NAME}, "
|
||||||
|
"compiler: ${CMAKE_C_COMPILER}). Pass -DDUSK_TARGET_SYSTEM=<target>."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(DUSK_TARGET_SYSTEM "${DUSK_DETECTED_SYSTEM}" CACHE STRING
|
||||||
|
"Target platform" FORCE
|
||||||
|
)
|
||||||
|
set_property(CACHE DUSK_TARGET_SYSTEM PROPERTY STRINGS
|
||||||
|
linux windows psp dolphin vita ps2 dreamcast
|
||||||
|
)
|
||||||
|
message(STATUS "Dusk target: ${DUSK_TARGET_SYSTEM} (detected)")
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the dolphin target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskdolphin)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
# Assertions are faked (compiled out) unless this is a Debug build.
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
else()
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED ON)
|
||||||
|
endif()
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY OFF)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_BIG
|
||||||
|
DUSK_DOLPHIN
|
||||||
|
DUSK_THREAD_PTHREAD
|
||||||
|
)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the dreamcast target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskdreamcast)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
# Assertions are faked (compiled out) unless this is a Debug build.
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
else()
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED ON)
|
||||||
|
endif()
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY OFF)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_DREAMCAST
|
||||||
|
)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the linux target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS dusklinux dusksdl3 duskvulkan)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE ON)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY ON)
|
||||||
|
|
||||||
|
# Linux runs on both endiannesses, so detect it from the target compiler.
|
||||||
|
include(TestBigEndian)
|
||||||
|
test_big_endian(DUSK_IS_BIG_ENDIAN)
|
||||||
|
if(DUSK_IS_BIG_ENDIAN)
|
||||||
|
set(DUSK_ENDIAN_DEFINITION DUSK_PLATFORM_ENDIAN_BIG)
|
||||||
|
else()
|
||||||
|
set(DUSK_ENDIAN_DEFINITION DUSK_PLATFORM_ENDIAN_LITTLE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
${DUSK_ENDIAN_DEFINITION}
|
||||||
|
DUSK_LINUX
|
||||||
|
DUSK_THREAD_PTHREAD
|
||||||
|
DUSK_TIME_DYNAMIC
|
||||||
|
)
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
cglm
|
|
||||||
# GIT_REPOSITORY https://git.wish.moe/YourWishes/cglm.git
|
|
||||||
GIT_REPOSITORY https://github.com/recp/cglm.git
|
|
||||||
GIT_TAG v0.9.6
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(cglm)
|
|
||||||
set(cglm_FOUND ON)
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
cmocka
|
|
||||||
GIT_REPOSITORY https://gitlab.com/cmocka/cmocka.git
|
|
||||||
GIT_TAG cmocka-2.0.1
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(cmocka)
|
|
||||||
set(cmocka_FOUND ON)
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
find_package(ZLIB REQUIRED)
|
|
||||||
|
|
||||||
find_path(LIBZIP_INCLUDE_DIR NAMES zip.h)
|
|
||||||
mark_as_advanced(LIBZIP_INCLUDE_DIR)
|
|
||||||
|
|
||||||
find_library(LIBZIP_LIBRARY NAMES zip)
|
|
||||||
mark_as_advanced(LIBZIP_LIBRARY)
|
|
||||||
|
|
||||||
get_filename_component(_libzip_libdir ${LIBZIP_LIBRARY} DIRECTORY)
|
|
||||||
find_file(_libzip_pkgcfg libzip.pc
|
|
||||||
HINTS ${_libzip_libdir} ${LIBZIP_INCLUDE_DIR}/..
|
|
||||||
PATH_SUFFIXES pkgconfig lib/pkgconfig libdata/pkgconfig
|
|
||||||
NO_DEFAULT_PATH
|
|
||||||
)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(
|
|
||||||
LIBZIP
|
|
||||||
REQUIRED_VARS
|
|
||||||
LIBZIP_LIBRARY
|
|
||||||
LIBZIP_INCLUDE_DIR
|
|
||||||
_libzip_pkgcfg
|
|
||||||
)
|
|
||||||
|
|
||||||
if(LIBZIP_FOUND)
|
|
||||||
if(NOT TARGET libzip::zip)
|
|
||||||
add_library(libzip::zip UNKNOWN IMPORTED)
|
|
||||||
set_target_properties(libzip::zip
|
|
||||||
PROPERTIES
|
|
||||||
INTERFACE_INCLUDE_DIRECTORIES ${LIBZIP_INCLUDE_DIR}
|
|
||||||
INTERFACE_LINK_LIBRARIES ZLIB::ZLIB
|
|
||||||
IMPORTED_LOCATION ${LIBZIP_LIBRARY}
|
|
||||||
)
|
|
||||||
# (Ab)use the (always) installed pkgconfig file to check if BZip2 is required
|
|
||||||
file(STRINGS ${_libzip_pkgcfg} _have_extra_libs REGEX Libs)
|
|
||||||
if(_have_extra_libs MATCHES "-lbz2")
|
|
||||||
find_package(BZip2 REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES BZip2::BZip2)
|
|
||||||
endif()
|
|
||||||
if(_have_extra_libs MATCHES "-lcrypto")
|
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
|
|
||||||
endif()
|
|
||||||
if(_have_extra_libs MATCHES "-lgnutls")
|
|
||||||
find_package(GnuTLS REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES GnuTLS::GnuTLS)
|
|
||||||
endif()
|
|
||||||
if(_have_extra_libs MATCHES "-lnettle")
|
|
||||||
find_package(Nettle REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES Nettle::Nettle)
|
|
||||||
endif()
|
|
||||||
if(_have_extra_libs MATCHES "-llzma")
|
|
||||||
find_package(LibLZMA REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES LibLZMA::LibLZMA)
|
|
||||||
endif()
|
|
||||||
if(_have_extra_libs MATCHES "-lz")
|
|
||||||
find_package(ZLIB REQUIRED)
|
|
||||||
set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
stb
|
|
||||||
GIT_REPOSITORY https://github.com/nothings/stb.git
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fetch stb if not already done
|
|
||||||
FetchContent_MakeAvailable(stb)
|
|
||||||
|
|
||||||
# Find the stb_image.h header
|
|
||||||
set(STB_INCLUDE_DIR "${stb_SOURCE_DIR}")
|
|
||||||
set(STB_IMAGE_HEADER "${stb_SOURCE_DIR}/stb_image.h")
|
|
||||||
|
|
||||||
if(EXISTS "${STB_IMAGE_HEADER}")
|
|
||||||
add_library(stb_image INTERFACE)
|
|
||||||
target_include_directories(stb_image INTERFACE "${STB_INCLUDE_DIR}")
|
|
||||||
set(STB_IMAGE_FOUND TRUE)
|
|
||||||
else()
|
|
||||||
set(STB_IMAGE_FOUND FALSE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Standard CMake variables
|
|
||||||
set(STB_IMAGE_INCLUDE_DIRS "${STB_INCLUDE_DIR}")
|
|
||||||
set(STB_IMAGE_LIBRARIES stb_image)
|
|
||||||
|
|
||||||
mark_as_advanced(STB_IMAGE_INCLUDE_DIRS STB_IMAGE_LIBRARIES STB_IMAGE_FOUND)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
include(FetchContent)
|
|
||||||
|
|
||||||
if(NOT TARGET yyjson)
|
|
||||||
FetchContent_Declare(
|
|
||||||
yyjson
|
|
||||||
GIT_REPOSITORY https://github.com/ibireme/yyjson.git
|
|
||||||
GIT_TAG 0.12.0
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(yyjson)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Provide an imported target if not already available
|
|
||||||
if(NOT TARGET yyjson::yyjson)
|
|
||||||
add_library(yyjson::yyjson ALIAS yyjson)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Mark yyjson as found for find_package compatibility
|
|
||||||
set(yyjson_FOUND TRUE)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
find_package(cmocka REQUIRED)
|
|
||||||
|
|
||||||
# Function to create a test executable from a single .c file
|
|
||||||
function(dusktest TEST_C_FILE)
|
|
||||||
# Create target name from file name
|
|
||||||
get_filename_component(TEST_NAME ${TEST_C_FILE} NAME_WE)
|
|
||||||
|
|
||||||
# Create the executable target
|
|
||||||
add_executable(${TEST_NAME})
|
|
||||||
|
|
||||||
# Setup some compiler definitions.
|
|
||||||
target_compile_definitions(${TEST_NAME} PRIVATE
|
|
||||||
DUSK_TEST_ASSERT=1
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add the test file
|
|
||||||
target_sources(${TEST_NAME} PRIVATE ${TEST_C_FILE})
|
|
||||||
|
|
||||||
# Add sources, both common and test-specific
|
|
||||||
target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${DUSK_TEST_DIR})
|
|
||||||
|
|
||||||
# Link against DuskCore and cmocka
|
|
||||||
target_link_libraries(${TEST_NAME} PUBLIC ${DUSK_LIBRARY_TARGET_NAME} cmocka)
|
|
||||||
|
|
||||||
# Add as a CTest
|
|
||||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
|
||||||
endfunction()
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# All user facing CMake options and their defaults. Included by the root
|
||||||
|
# CMakeLists.txt after the platform's target.cmake, which supplies the
|
||||||
|
# DUSK_DEFAULT_* values used below. DUSK_TARGET_SYSTEM itself is declared by
|
||||||
|
# determineplatform.cmake.
|
||||||
|
|
||||||
|
# General
|
||||||
|
option(DUSK_BUILD_TESTS "Enable tests." OFF)
|
||||||
|
option(DUSK_NETWORK "Enable network support." ON)
|
||||||
|
|
||||||
|
# Game metadata
|
||||||
|
set(DUSK_GAME "duskexample" CACHE STRING
|
||||||
|
"Directory under src/ containing the game to build (provides game/game.c)."
|
||||||
|
)
|
||||||
|
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name.")
|
||||||
|
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder.")
|
||||||
|
if(NOT DEFINED DUSK_VERSION)
|
||||||
|
string(TIMESTAMP DUSK_VERSION "debug-%y%m%d%H%M%S")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Platform dependent defaults
|
||||||
|
option(DUSK_ASSERTIONS_FAKED
|
||||||
|
"Compile assertions out (they do nothing)."
|
||||||
|
${DUSK_DEFAULT_ASSERTIONS_FAKED}
|
||||||
|
)
|
||||||
|
option(DUSK_BACKTRACE
|
||||||
|
"Log a stack trace on assertion failure."
|
||||||
|
${DUSK_DEFAULT_BACKTRACE}
|
||||||
|
)
|
||||||
|
option(DUSK_TRACK_MEMORY
|
||||||
|
"Track memoryAllocate() call sites to help find memory leaks."
|
||||||
|
${DUSK_DEFAULT_TRACK_MEMORY}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Tests mock assertions, so they can never be faked.
|
||||||
|
if(DUSK_BUILD_TESTS AND DUSK_ASSERTIONS_FAKED)
|
||||||
|
message(STATUS "DUSK_BUILD_TESTS: forcing DUSK_ASSERTIONS_FAKED off")
|
||||||
|
set(DUSK_ASSERTIONS_FAKED OFF CACHE BOOL "" FORCE)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the ps2 target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskps2)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
# Assertions are faked (compiled out) unless this is a Debug build.
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
else()
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED ON)
|
||||||
|
endif()
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY OFF)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_PS2
|
||||||
|
)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the psp target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskpsp)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
# Assertions are faked (compiled out) unless this is a Debug build.
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
else()
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED ON)
|
||||||
|
endif()
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY OFF)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_PSP
|
||||||
|
DUSK_THREAD_PTHREAD
|
||||||
|
)
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
# Build type: DOL (SD/USB via libfat) or ISO (DVD disc via libogc DVD driver)
|
|
||||||
set(DUSK_DOLPHIN_BUILD_TYPE "DOL" CACHE STRING "Dolphin asset source: DOL (SD/USB) or ISO (DVD disc)")
|
|
||||||
set_property(CACHE DUSK_DOLPHIN_BUILD_TYPE PROPERTY STRINGS "DOL" "ISO")
|
|
||||||
|
|
||||||
# Numeric tokens so #if DUSK_DOLPHIN_BUILD_TYPE == DOL works in C.
|
|
||||||
# DUSK_DOLPHIN_BUILD_TYPE is passed without quotes so it expands to the identifier.
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_DOLPHIN
|
|
||||||
DUSK_INPUT_GAMEPAD
|
|
||||||
# DUSK_DISPLAY_WIDTH=640
|
|
||||||
# DUSK_DISPLAY_HEIGHT=480
|
|
||||||
DUSK_DISPLAY_WIDTH=320
|
|
||||||
DUSK_DISPLAY_HEIGHT=240
|
|
||||||
DUSK_DISPLAY_OVERSCAN=16
|
|
||||||
DUSK_THREAD_PTHREAD
|
|
||||||
DOL=1
|
|
||||||
ISO=2
|
|
||||||
DUSK_DOLPHIN_BUILD_TYPE=${DUSK_DOLPHIN_BUILD_TYPE}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Custom compiler flags
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
|
||||||
|
|
||||||
# Disable all warnings
|
|
||||||
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE -w)
|
|
||||||
|
|
||||||
# cglm: fetched at source level via Findcglm.cmake (FetchContent, headers only)
|
|
||||||
find_package(cglm REQUIRED)
|
|
||||||
|
|
||||||
# Pre-create ZLIB::ZLIB so any downstream cmake module that resolves it
|
|
||||||
# (FindZLIB, pkg-config IMPORTED_TARGET Requires processing) gets plain -lz
|
|
||||||
# rather than an unresolvable IMPORTED target that the PPC linker rejects.
|
|
||||||
if(NOT TARGET ZLIB::ZLIB)
|
|
||||||
add_library(ZLIB::ZLIB INTERFACE IMPORTED GLOBAL)
|
|
||||||
set_target_properties(ZLIB::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES "z")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Mark libzip as found so src/dusk/CMakeLists.txt skips Findlibzip.cmake.
|
|
||||||
# Findlibzip.cmake calls find_package(ZLIB) which can recreate a broken
|
|
||||||
# ZLIB::ZLIB IMPORTED target, bypassing the shim above.
|
|
||||||
set(libzip_FOUND TRUE CACHE BOOL "libzip found (devkitpro portlibs)" FORCE)
|
|
||||||
|
|
||||||
# Locate zip.h in the devkitpro sysroot (respects CMAKE_FIND_ROOT_PATH).
|
|
||||||
find_path(_dusk_zip_inc NAMES zip.h)
|
|
||||||
if(_dusk_zip_inc)
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE "${_dusk_zip_inc}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Link libraries.
|
|
||||||
# zip/z/lzma use target_link_options (raw flags) to bypass cmake target
|
|
||||||
# resolution - pkg-config-generated targets for these carry ZLIB::ZLIB in
|
|
||||||
# INTERFACE_LINK_LIBRARIES which breaks the PPC link step.
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
||||||
cglm
|
|
||||||
m
|
|
||||||
zip
|
|
||||||
bz2
|
|
||||||
zstd
|
|
||||||
z
|
|
||||||
lzma
|
|
||||||
)
|
|
||||||
|
|
||||||
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC DUSK_DOLPHIN_BUILD_ISO)
|
|
||||||
else()
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE fat)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Postbuild: ELF -> DOL
|
|
||||||
set(DUSK_BINARY_TARGET_NAME_DOL "${DUSK_BUILD_DIR}/Dusk.dol")
|
|
||||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
|
||||||
COMMAND elf2dol
|
|
||||||
"$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>"
|
|
||||||
"${DUSK_BINARY_TARGET_NAME_DOL}"
|
|
||||||
COMMENT "Generating ${DUSK_BINARY_TARGET_NAME_DOL} from ${DUSK_BINARY_TARGET_NAME}"
|
|
||||||
)
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
include(cmake/targets/dolphin.cmake)
|
|
||||||
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_GAMECUBE
|
|
||||||
)
|
|
||||||
|
|
||||||
# Link libraries
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
||||||
# bba
|
|
||||||
)
|
|
||||||
|
|
||||||
# ISO post-build: produce NTSC-J, NTSC-U and PAL disc images
|
|
||||||
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
|
||||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
|
||||||
COMMAND ${Python3_EXECUTABLE}
|
|
||||||
"${CMAKE_SOURCE_DIR}/tools/makedolphiniso.py"
|
|
||||||
"GCN"
|
|
||||||
"${DUSK_BINARY_TARGET_NAME_DOL}"
|
|
||||||
"${DUSK_ASSETS_ZIP}"
|
|
||||||
"${DUSK_GAME_NAME}"
|
|
||||||
"${DUSK_BUILD_DIR}"
|
|
||||||
COMMENT "Building GameCube ISO images (NTSC-J, NTSC-U, PAL)"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# Find link platform-specific libraries
|
|
||||||
set(OpenGL_GL_PREFERENCE LEGACY)
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_library(EGL_LIB EGL REQUIRED)
|
|
||||||
find_library(GL_LIB GL REQUIRED)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
|
|
||||||
# Setup endianess at compile time to optimize.
|
|
||||||
include(TestBigEndian)
|
|
||||||
test_big_endian(IS_BIG_ENDIAN)
|
|
||||||
if(IS_BIG_ENDIAN)
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_PLATFORM_ENDIAN_BIG
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Link required libraries.
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
||||||
SDL2
|
|
||||||
pthread
|
|
||||||
OpenGL::GLES2
|
|
||||||
${GL_LIB}
|
|
||||||
${EGL_LIB}
|
|
||||||
m
|
|
||||||
)
|
|
||||||
|
|
||||||
# Define platform-specific macros.
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_SDL2
|
|
||||||
DUSK_OPENGL
|
|
||||||
DUSK_OPENGL_ES
|
|
||||||
DUSK_LINUX
|
|
||||||
DUSK_KNULLI
|
|
||||||
DUSK_DISPLAY_SIZE_DYNAMIC
|
|
||||||
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
|
||||||
DUSK_DISPLAY_HEIGHT_DEFAULT=480
|
|
||||||
DUSK_DISPLAY_SCREEN_HEIGHT=240
|
|
||||||
DUSK_INPUT_KEYBOARD
|
|
||||||
DUSK_INPUT_POINTER
|
|
||||||
DUSK_INPUT_GAMEPAD
|
|
||||||
DUSK_TIME_DYNAMIC
|
|
||||||
)
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
# Find link platform-specific libraries
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
# find_package(CURL REQUIRED)
|
|
||||||
|
|
||||||
# Setup endianess at compile time to optimize.
|
|
||||||
include(TestBigEndian)
|
|
||||||
test_big_endian(IS_BIG_ENDIAN)
|
|
||||||
if(IS_BIG_ENDIAN)
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_PLATFORM_ENDIAN_BIG
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Link required libraries.
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
SDL2
|
|
||||||
pthread
|
|
||||||
OpenGL::GL
|
|
||||||
GL
|
|
||||||
m
|
|
||||||
# CURL::libcurl
|
|
||||||
)
|
|
||||||
|
|
||||||
set(DUSK_BACKTRACE ON CACHE BOOL "Enable backtrace support for assert failures.")
|
|
||||||
|
|
||||||
# Define platform-specific macros.
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_SDL2
|
|
||||||
DUSK_OPENGL
|
|
||||||
DUSK_CONSOLE_POSIX
|
|
||||||
# DUSK_OPENGL_LEGACY
|
|
||||||
DUSK_LINUX
|
|
||||||
DUSK_DISPLAY_SIZE_DYNAMIC
|
|
||||||
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
|
||||||
DUSK_DISPLAY_HEIGHT_DEFAULT=480
|
|
||||||
DUSK_DISPLAY_SCREEN_HEIGHT=240
|
|
||||||
DUSK_INPUT_KEYBOARD
|
|
||||||
DUSK_INPUT_POINTER
|
|
||||||
DUSK_INPUT_GAMEPAD
|
|
||||||
DUSK_TIME_DYNAMIC
|
|
||||||
DUSK_NETWORK_IPV6
|
|
||||||
DUSK_THREAD_PTHREAD
|
|
||||||
)
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
set(CMAKE_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
|
||||||
set(CMAKE_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" CACHE FILEPATH "" FORCE)
|
|
||||||
set(CMAKE_C_COMPILER_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
|
||||||
set(CMAKE_C_COMPILER_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" CACHE FILEPATH "" FORCE)
|
|
||||||
set(CMAKE_C_ARCHIVE_CREATE "$ENV{PSPDEV}/bin/psp-ar qc <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
||||||
set(CMAKE_C_ARCHIVE_APPEND "$ENV{PSPDEV}/bin/psp-ar q <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
||||||
set(CMAKE_C_ARCHIVE_FINISH "$ENV{PSPDEV}/bin/psp-ranlib <TARGET>")
|
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "" FORCE)
|
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_C OFF CACHE BOOL "" FORCE)
|
|
||||||
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
target_link_libraries(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|
||||||
${SDL2_LIBRARIES}
|
|
||||||
SDL2
|
|
||||||
pthread
|
|
||||||
OpenGL::GL
|
|
||||||
zip
|
|
||||||
bz2
|
|
||||||
z
|
|
||||||
mbedtls
|
|
||||||
mbedcrypto
|
|
||||||
lzma
|
|
||||||
m
|
|
||||||
|
|
||||||
pspdebug
|
|
||||||
pspdisplay
|
|
||||||
pspge
|
|
||||||
pspctrl
|
|
||||||
pspgu
|
|
||||||
pspaudio
|
|
||||||
pspaudiolib
|
|
||||||
psputility
|
|
||||||
pspvfpu
|
|
||||||
pspvram
|
|
||||||
psphprm
|
|
||||||
pspnet
|
|
||||||
pspnet_inet
|
|
||||||
pspnet_apctl
|
|
||||||
psphttp
|
|
||||||
pspssl
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${DUSK_BINARY_TARGET_NAME} PRIVATE
|
|
||||||
${SDL2_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_SDL2
|
|
||||||
DUSK_OPENGL
|
|
||||||
DUSK_PSP
|
|
||||||
DUSK_INPUT_GAMEPAD
|
|
||||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
|
||||||
DUSK_OPENGL_LEGACY
|
|
||||||
DUSK_DISPLAY_WIDTH=480
|
|
||||||
DUSK_DISPLAY_HEIGHT=272
|
|
||||||
DUSK_THREAD_PTHREAD
|
|
||||||
)
|
|
||||||
|
|
||||||
# Postbuild, create .pbp file for PSP.
|
|
||||||
create_pbp_file(
|
|
||||||
TARGET "${DUSK_BINARY_TARGET_NAME}"
|
|
||||||
ICON_PATH NULL
|
|
||||||
BACKGROUND_PATH NULL
|
|
||||||
PREVIEW_PATH NULL
|
|
||||||
TITLE "${DUSK_BINARY_TARGET_NAME}"
|
|
||||||
PSAR_PATH ${DUSK_ASSETS_ZIP}
|
|
||||||
VERSION 01.00
|
|
||||||
)
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
if(NOT DEFINED ENV{VITASDK})
|
|
||||||
message(FATAL_ERROR "VITASDK environment variable is not set.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
|
|
||||||
|
|
||||||
set(VITA_APP_NAME "Dusk")
|
|
||||||
set(VITA_TITLEID "DUSK00001")
|
|
||||||
set(VITA_VERSION "01.00")
|
|
||||||
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
|
|
||||||
# Custom flags for cglm
|
|
||||||
set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
|
||||||
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
|
||||||
find_package(cglm REQUIRED)
|
|
||||||
|
|
||||||
# Link libraries
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
${SDL2_LIBRARIES}
|
|
||||||
cglm
|
|
||||||
SDL2
|
|
||||||
SDL2main
|
|
||||||
zip
|
|
||||||
bz2
|
|
||||||
z
|
|
||||||
zstd
|
|
||||||
crypto
|
|
||||||
lzma
|
|
||||||
m
|
|
||||||
pthread
|
|
||||||
stdc++
|
|
||||||
vitaGL
|
|
||||||
mathneon
|
|
||||||
vitashark
|
|
||||||
kubridge_stub
|
|
||||||
SceAppMgr_stub
|
|
||||||
SceAudio_stub
|
|
||||||
SceCtrl_stub
|
|
||||||
SceCommonDialog_stub
|
|
||||||
SceDisplay_stub
|
|
||||||
SceKernelDmacMgr_stub
|
|
||||||
SceGxm_stub
|
|
||||||
SceShaccCg_stub
|
|
||||||
SceSysmodule_stub
|
|
||||||
ScePower_stub
|
|
||||||
SceTouch_stub
|
|
||||||
SceVshBridge_stub
|
|
||||||
SceIofilemgr_stub
|
|
||||||
SceShaccCgExt
|
|
||||||
libtaihen_stub.a
|
|
||||||
|
|
||||||
|
|
||||||
# SceKernel_stub
|
|
||||||
SceAppUtil_stub
|
|
||||||
SceHid_stub
|
|
||||||
SceRtc_stub
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|
||||||
${SDL2_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_SDL2
|
|
||||||
DUSK_OPENGL
|
|
||||||
DUSK_VITA
|
|
||||||
DUSK_INPUT_GAMEPAD
|
|
||||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
|
||||||
DUSK_OPENGL_LEGACY
|
|
||||||
DUSK_DISPLAY_WIDTH=960
|
|
||||||
DUSK_DISPLAY_HEIGHT=544
|
|
||||||
)
|
|
||||||
|
|
||||||
# Post-build: create SELF from the ELF binary (UNSAFE = homebrew, no signing)
|
|
||||||
vita_create_self(${DUSK_BINARY_TARGET_NAME}.self ${DUSK_BINARY_TARGET_NAME} UNSAFE)
|
|
||||||
|
|
||||||
# Post-build: package SELF + assets into a .vpk installable on the Vita
|
|
||||||
vita_create_vpk(${DUSK_BINARY_TARGET_NAME}.vpk ${VITA_TITLEID} ${DUSK_BINARY_TARGET_NAME}.self
|
|
||||||
VERSION ${VITA_VERSION}
|
|
||||||
NAME ${VITA_APP_NAME}
|
|
||||||
FILE ${DUSK_ASSETS_ZIP} dusk.dsk
|
|
||||||
)
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
include(cmake/targets/dolphin.cmake)
|
|
||||||
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_WII
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate Homebrew Channel meta.xml from project identity variables
|
|
||||||
string(TIMESTAMP DUSK_BUILD_DATE "%Y%m%d000000" UTC)
|
|
||||||
configure_file(
|
|
||||||
"${CMAKE_SOURCE_DIR}/docker/dolphin/meta.xml.in"
|
|
||||||
"${DUSK_BUILD_DIR}/meta.xml"
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
# ISO post-build: produce NTSC-J, NTSC-U and PAL disc images
|
|
||||||
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
|
||||||
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
|
||||||
COMMAND ${Python3_EXECUTABLE}
|
|
||||||
"${CMAKE_SOURCE_DIR}/tools/makedolphiniso.py"
|
|
||||||
"WII"
|
|
||||||
"${DUSK_BINARY_TARGET_NAME_DOL}"
|
|
||||||
"${DUSK_ASSETS_ZIP}"
|
|
||||||
"${DUSK_GAME_NAME}"
|
|
||||||
"${DUSK_BUILD_DIR}"
|
|
||||||
COMMENT "Building Wii ISO images (NTSC-J, NTSC-U, PAL)"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
set(CMAKE_SYSTEM_NAME Linux)
|
|
||||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
|
||||||
|
|
||||||
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
|
||||||
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
|
|
||||||
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-gcc)
|
|
||||||
|
|
||||||
set(CMAKE_SYSROOT /)
|
|
||||||
set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu)
|
|
||||||
set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu)
|
|
||||||
|
|
||||||
set(CMAKE_FIND_ROOT_PATH
|
|
||||||
/usr/aarch64-linux-gnu
|
|
||||||
/usr/lib/aarch64-linux-gnu
|
|
||||||
/usr/include/aarch64-linux-gnu
|
|
||||||
)
|
|
||||||
|
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
|
||||||
|
|
||||||
set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig")
|
|
||||||
set(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig")
|
|
||||||
|
|
||||||
set(CMAKE_PREFIX_PATH "/usr/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu")
|
|
||||||
|
|
||||||
# Optional: helps some Find modules
|
|
||||||
set(SDL2_DIR "/usr/lib/aarch64-linux-gnu/cmake/SDL2" CACHE PATH "")
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the vita target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskvita)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
# Assertions are faked (compiled out) unless this is a Debug build.
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
else()
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED ON)
|
||||||
|
endif()
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY OFF)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_VITA
|
||||||
|
DUSK_THREAD_PTHREAD
|
||||||
|
)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Platform setup for the windows target, included by the root CMakeLists.txt.
|
||||||
|
# Only sets defaults and definitions; the root applies them.
|
||||||
|
|
||||||
|
# Source directories to build for this platform.
|
||||||
|
set(DUSK_PLATFORM_DIRS duskwindows dusksdl3 duskvulkan)
|
||||||
|
|
||||||
|
# Default values for the shared options declared in the root CMakeLists.txt.
|
||||||
|
set(DUSK_DEFAULT_ASSERTIONS_FAKED OFF)
|
||||||
|
set(DUSK_DEFAULT_BACKTRACE OFF)
|
||||||
|
set(DUSK_DEFAULT_TRACK_MEMORY ON)
|
||||||
|
|
||||||
|
# Platform definitions.
|
||||||
|
set(DUSK_PLATFORM_DEFINITIONS
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_WINDOWS
|
||||||
|
)
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
FROM ghcr.io/extremscorner/libogc2
|
|
||||||
WORKDIR /workdir
|
|
||||||
RUN apt update && \
|
|
||||||
dkp-pacman -Syu --noconfirm && \
|
|
||||||
apt install -y python3 python3-pip python3-polib python3-pil python3-dotenv python3-pyqt5 python3-opengl xorriso && \
|
|
||||||
dkp-pacman -S --needed --noconfirm gamecube-sdl2 ppc-liblzma ppc-libzip libogc2 gamecube-tools ppc-libmad ppc-zlib-ng ppc-liblzma ppc-bzip2 ppc-zstd
|
|
||||||
VOLUME ["/workdir"]
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
||||||
<app version="1">
|
|
||||||
<name>@DUSK_GAME_NAME@</name>
|
|
||||||
<version>@PROJECT_VERSION@</version>
|
|
||||||
<release_date>@DUSK_BUILD_DATE@</release_date>
|
|
||||||
<coder>@DUSK_GAME_AUTHOR@</coder>
|
|
||||||
<short_description>@DUSK_GAME_SHORT_DESCRIPTION@</short_description>
|
|
||||||
<long_description>@DUSK_GAME_LONG_DESCRIPTION@</long_description>
|
|
||||||
<ahb_access/>
|
|
||||||
</app>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
FROM debian:trixie
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
|
||||||
WORKDIR /workdir
|
|
||||||
RUN dpkg --add-architecture arm64 && \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
crossbuild-essential-arm64 \
|
|
||||||
ca-certificates \
|
|
||||||
pkg-config \
|
|
||||||
cmake \
|
|
||||||
make \
|
|
||||||
ninja-build \
|
|
||||||
git \
|
|
||||||
file \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
liblua5.4-dev:arm64 \
|
|
||||||
xz-utils:arm64 \
|
|
||||||
libbz2-dev:arm64 \
|
|
||||||
zlib1g-dev:arm64 \
|
|
||||||
libzip-dev:arm64 \
|
|
||||||
libssl-dev:arm64 \
|
|
||||||
libsdl2-dev:arm64 \
|
|
||||||
liblzma-dev:arm64 \
|
|
||||||
libopengl0:arm64 \
|
|
||||||
libgl1:arm64 \
|
|
||||||
libegl1:arm64 \
|
|
||||||
libgles2:arm64 \
|
|
||||||
libgl1-mesa-dev:arm64 && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
+3
-22
@@ -1,24 +1,5 @@
|
|||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
WORKDIR /workdir
|
WORKDIR /workdir
|
||||||
RUN apt-get update
|
COPY scripts/linux/install.sh /tmp/install.sh
|
||||||
RUN apt-get install -y \
|
RUN chmod +x /tmp/install.sh && /tmp/install.sh && rm /tmp/install.sh
|
||||||
build-essential \
|
|
||||||
cmake \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-polib \
|
|
||||||
python3-pil \
|
|
||||||
libsdl2-dev \
|
|
||||||
libgl1-mesa-dev \
|
|
||||||
libzip-dev \
|
|
||||||
python3-dotenv \
|
|
||||||
python3-pyqt5 \
|
|
||||||
python3-opengl \
|
|
||||||
xz-utils \
|
|
||||||
liblzma-dev \
|
|
||||||
libbz2-dev \
|
|
||||||
zlib1g-dev \
|
|
||||||
libzip-dev \
|
|
||||||
libbz2-dev \
|
|
||||||
git \
|
|
||||||
libssl-dev
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
FROM pspdev/pspdev:latest
|
FROM pspdev/pspdev:latest
|
||||||
WORKDIR /workdir
|
WORKDIR /workdir
|
||||||
RUN apk add --no-cache \
|
COPY scripts/psp/install.sh /tmp/install.sh
|
||||||
python3 \
|
RUN chmod +x /tmp/install.sh && /tmp/install.sh && rm /tmp/install.sh
|
||||||
py3-pip \
|
|
||||||
py3-dotenv
|
|
||||||
VOLUME ["/workdir"]
|
VOLUME ["/workdir"]
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
FROM vitasdk/vitasdk:latest
|
|
||||||
WORKDIR /workdir
|
|
||||||
|
|
||||||
# Install vitaGL and its dependencies (vitashark, SceShaccCg) via vdpm
|
|
||||||
RUN which vdpm
|
|
||||||
|
|
||||||
# Install Python (needed for Dusk code generation tools)
|
|
||||||
RUN apk add --no-cache \
|
|
||||||
python3 \
|
|
||||||
py3-pip \
|
|
||||||
py3-dotenv
|
|
||||||
|
|
||||||
VOLUME ["/workdir"]
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-gamecube.sh"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-gamecube-iso.sh"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$DEVKITPRO" ]; then
|
|
||||||
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-gamecube-iso
|
|
||||||
cmake -S. -Bbuild-gamecube-iso \
|
|
||||||
-DDUSK_TARGET_SYSTEM=gamecube \
|
|
||||||
-DDUSK_DOLPHIN_BUILD_TYPE=ISO \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake"
|
|
||||||
cd build-gamecube-iso
|
|
||||||
make -j$(nproc) VERBOSE=1
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$DEVKITPRO" ]; then
|
|
||||||
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-gamecube
|
|
||||||
cmake -S. -Bbuild-gamecube \
|
|
||||||
-DDUSK_TARGET_SYSTEM=gamecube \
|
|
||||||
-DDUSK_DOLPHIN_BUILD_TYPE=DOL \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake" \
|
|
||||||
-DDKP_OGC_PLATFORM_LIBRARY=libogc2
|
|
||||||
cd build-gamecube
|
|
||||||
make -j$(nproc) VERBOSE=1
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-knulli -f docker/knulli/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-knulli /bin/bash -c "./scripts/build-knulli.sh"
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
cmake -S . -B build-knulli -G Ninja \
|
|
||||||
-DDUSK_BUILD_TESTS=ON \
|
|
||||||
-DDUSK_TARGET_SYSTEM=knulli \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/aarch64-linux-gnu.cmake \
|
|
||||||
-DCMAKE_BUILD_TYPE=Release
|
|
||||||
cmake --build build-knulli -- -j$(nproc)
|
|
||||||
|
|
||||||
# Copy necessary libs out
|
|
||||||
mkdir -p ./build-knulli/dusk
|
|
||||||
cp ./build-knulli/Dusk ./build-knulli/dusk/Dusk
|
|
||||||
cp ./build-knulli/dusk.dsk ./build-knulli/dusk/dusk.dsk
|
|
||||||
echo '#!/bin/bash' > build-knulli/dusk/Dusk.sh
|
|
||||||
echo 'cd "$(dirname "$(readlink -f "$0")")"' >> build-knulli/dusk/Dusk.sh
|
|
||||||
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(dirname "$(readlink -f "$0")")' >> build-knulli/dusk/Dusk.sh
|
|
||||||
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/gl4es' >> build-knulli/dusk/Dusk.sh
|
|
||||||
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib' >> build-knulli/dusk/Dusk.sh
|
|
||||||
echo '$(dirname "$(readlink -f "$0")")/Dusk' >> build-knulli/dusk/Dusk.sh
|
|
||||||
chmod +x build-knulli/dusk/Dusk.sh
|
|
||||||
cp /usr/lib/aarch64-linux-gnu/liblua5.4.so.0 build-knulli/dusk/
|
|
||||||
# cp /usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0 build-knulli/dusk/
|
|
||||||
# cp /usr/lib/aarch64-linux-gnu/libGL.so.1 build-knulli/dusk/
|
|
||||||
# cp /usr/lib/aarch64-linux-gnu/libEGL.so.1 build-knulli/dusk/
|
|
||||||
# cp /usr/lib/aarch64-linux-gnu/libGLESv2.so.2 build-knulli/dusk/
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
cmake -S . -B build-linux -DDUSK_BUILD_TESTS=ON -DDUSK_TARGET_SYSTEM=linux
|
|
||||||
cmake --build build-linux -- -j$(nproc)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$PSPDEV" ]; then
|
|
||||||
echo "PSPDEV environment variable is not set. Please set it to the path of your PSP development environment."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-psp
|
|
||||||
cd build-psp
|
|
||||||
psp-cmake -DDUSK_TARGET_SYSTEM=psp -DCMAKE_TOOLCHAIN_FILE=$PSPDEV/psp/share/pspdev.cmake -DBUILD_PRX=1 ..
|
|
||||||
make -j$(nproc)
|
|
||||||
# psp-cmake -DDUSK_TARGET_SYSTEM=psp -DCMAKE_TOOLCHAIN_FILE=$PSPDEV/psp/share/pspdev.cmake -DBUILD_PRX=1 -DCMAKE_BUILD_TYPE=Debug ..
|
|
||||||
# make
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-vita -f docker/vita/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-vita /bin/bash -c "./scripts/build-vita.sh"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$VITASDK" ]; then
|
|
||||||
echo "VITASDK environment variable is not set. Please set it to the path of your VitaSDK installation."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-vita
|
|
||||||
cd build-vita
|
|
||||||
cmake \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake \
|
|
||||||
-DDUSK_TARGET_SYSTEM=vita \
|
|
||||||
..
|
|
||||||
make -j$(nproc)
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-wii.sh"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-wii-iso.sh"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$DEVKITPRO" ]; then
|
|
||||||
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-wii-iso
|
|
||||||
cmake -S. -Bbuild-wii-iso \
|
|
||||||
-DDUSK_TARGET_SYSTEM=wii \
|
|
||||||
-DDUSK_DOLPHIN_BUILD_TYPE=ISO \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake"
|
|
||||||
cd build-wii-iso
|
|
||||||
make -j$(nproc) VERBOSE=1
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -z "$DEVKITPRO" ]; then
|
|
||||||
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build-wii
|
|
||||||
cmake -S. -Bbuild-wii \
|
|
||||||
-DDUSK_TARGET_SYSTEM=wii \
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" \
|
|
||||||
-DDUSK_DOLPHIN_BUILD_TYPE=DOL
|
|
||||||
cd build-wii
|
|
||||||
make -j$(nproc) VERBOSE=1
|
|
||||||
mv Dusk.dol boot.dol
|
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
|
docker build -t dusk-linux -f docker/linux/Dockerfile .
|
||||||
|
docker run --rm -v "$(pwd):/workdir" dusk-linux /bin/bash -c "./scripts/linux/build.sh"
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
|
cmake -S . -B build-linux -DDUSK_TARGET_SYSTEM=linux
|
||||||
|
cmake --build build-linux -- -j"$(nproc)"
|
||||||
Executable
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Installs the packages required to build and test Dusk on Linux.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SUDO=""
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
SUDO="sudo"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
|
$SUDO apt-get update
|
||||||
|
$SUDO apt-get install -y \
|
||||||
|
build-essential \
|
||||||
|
cmake \
|
||||||
|
git \
|
||||||
|
python3 \
|
||||||
|
python3-pip \
|
||||||
|
python3-polib \
|
||||||
|
python3-pil \
|
||||||
|
python3-dotenv \
|
||||||
|
python3-numpy \
|
||||||
|
libsdl3-dev \
|
||||||
|
libvulkan-dev \
|
||||||
|
libzip-dev \
|
||||||
|
libbz2-dev \
|
||||||
|
liblzma-dev \
|
||||||
|
zlib1g-dev \
|
||||||
|
libssl-dev \
|
||||||
|
xz-utils
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then
|
||||||
|
$SUDO dnf install -y \
|
||||||
|
git make gcc cmake python python-polib python3-pillow python3-dotenv \
|
||||||
|
python3-numpy SDL2-devel mesa-libGL-devel zlib-devel libzip-devel \
|
||||||
|
bzip2-devel openssl-devel xz xz-devel
|
||||||
|
elif command -v pacman >/dev/null 2>&1; then
|
||||||
|
$SUDO pacman -Sy --noconfirm --needed \
|
||||||
|
base-devel git cmake python python-polib python-pillow python-dotenv \
|
||||||
|
python-numpy sdl2 mesa libzip bzip2 openssl xz zlib
|
||||||
|
else
|
||||||
|
echo "Unsupported package manager; install dependencies manually." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
docker build -t dusk-linux -f docker/linux/Dockerfile .
|
docker build -t dusk-linux -f docker/linux/Dockerfile .
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-linux /bin/bash -c "./scripts/build-linux.sh"
|
docker run --rm -v "$(pwd):/workdir" dusk-linux /bin/bash -c "./scripts/linux/test.sh"
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
|
rm -rf build-tests
|
||||||
|
cmake -S . -B build-tests -DDUSK_BUILD_TESTS=ON -DDUSK_TARGET_SYSTEM=linux
|
||||||
|
cmake --build build-tests -- -j"$(nproc)"
|
||||||
|
ctest --output-on-failure --test-dir build-tests
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
docker build -t dusk-psp -f docker/psp/Dockerfile .
|
docker build -t dusk-psp -f docker/psp/Dockerfile .
|
||||||
docker run --rm -v "$(pwd):/workdir" dusk-psp /bin/bash -c "./scripts/build-psp.sh"
|
docker run --rm -v "$(pwd):/workdir" dusk-psp /bin/bash -c "./scripts/psp/build.sh"
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")/../.."
|
||||||
|
if [ -z "$PSPDEV" ]; then
|
||||||
|
echo "PSPDEV environment variable is not set." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
psp-cmake -S . -B build-psp \
|
||||||
|
-DDUSK_TARGET_SYSTEM=psp \
|
||||||
|
-DBUILD_PRX=1 \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build-psp -- -j"$(nproc)"
|
||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Installs the packages required to build Dusk for the PSP. The PSP toolchain
|
||||||
|
# itself (pspdev) must already be installed; the pspdev/pspdev docker image
|
||||||
|
# provides it.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SUDO=""
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
SUDO="sudo"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v apk >/dev/null 2>&1; then
|
||||||
|
$SUDO apk add --no-cache git cmake make python3 py3-pip py3-dotenv
|
||||||
|
elif command -v apt-get >/dev/null 2>&1; then
|
||||||
|
$SUDO apt-get update
|
||||||
|
$SUDO apt-get install -y git cmake make python3 python3-pip python3-dotenv
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then
|
||||||
|
$SUDO dnf install -y git cmake make python python3-dotenv
|
||||||
|
elif command -v pacman >/dev/null 2>&1; then
|
||||||
|
$SUDO pacman -Sy --noconfirm --needed git cmake make python python-dotenv
|
||||||
|
else
|
||||||
|
echo "Unsupported package manager; install dependencies manually." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PSPDEV" ] || ! command -v psp-cmake >/dev/null 2>&1; then
|
||||||
|
echo "pspdev toolchain not found. Install it from https://pspdev.github.io/" >&2
|
||||||
|
echo "and set PSPDEV, or use scripts/psp/build-docker.sh." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
docker build -t dusk-linux -f docker/linux/Dockerfile .
|
|
||||||
docker run \
|
|
||||||
--rm \
|
|
||||||
-v "${GITHUB_WORKSPACE}:/workdir" \
|
|
||||||
dusk-linux \
|
|
||||||
/bin/bash -c "./scripts/test-linux.sh"
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
rm -rf build-tests
|
|
||||||
cmake -S . -B build-tests -DDUSK_BUILD_TESTS=ON -DDUSK_TARGET_SYSTEM=linux
|
|
||||||
cmake --build build-tests -- -j$(nproc)
|
|
||||||
ctest --output-on-failure --test-dir build-tests
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_subdirectory(dusk)
|
|
||||||
|
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
|
||||||
add_subdirectory(dusklinux)
|
|
||||||
add_subdirectory(dusksdl2)
|
|
||||||
add_subdirectory(duskgl)
|
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|
||||||
add_subdirectory(duskpsp)
|
|
||||||
add_subdirectory(dusksdl2)
|
|
||||||
add_subdirectory(duskgl)
|
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "vita")
|
|
||||||
add_subdirectory(duskvita)
|
|
||||||
add_subdirectory(dusksdl2)
|
|
||||||
add_subdirectory(duskgl)
|
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "wii" OR DUSK_TARGET_SYSTEM STREQUAL "gamecube")
|
|
||||||
add_subdirectory(duskdolphin)
|
|
||||||
|
|
||||||
endif()
|
|
||||||
+9
-61
@@ -1,74 +1,22 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
# Copyright (c) 2026 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Required Libraries
|
# Headers are included relative to this directory (e.g. "util/string.h").
|
||||||
if(NOT cglm_FOUND)
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
find_package(cglm REQUIRED)
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC cglm)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT libzip_FOUND)
|
|
||||||
find_package(libzip REQUIRED)
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT stb_image_FOUND)
|
|
||||||
find_package(stb REQUIRED)
|
|
||||||
if(STB_IMAGE_FOUND)
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "stb_image not found. Please ensure stb is correctly fetched.")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT yyjson_FOUND)
|
|
||||||
find_package(yyjson REQUIRED)
|
|
||||||
if(yyjson_FOUND)
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "yyjson not found. Please ensure yyjson is correctly fetched.")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DUSK_BACKTRACE)
|
|
||||||
target_link_options(${DUSK_LIBRARY_TARGET_NAME} PUBLIC -rdynamic)
|
|
||||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_BACKTRACE
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Includes
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Main Binary Source
|
# Modules
|
||||||
target_sources(${DUSK_BINARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
main.c
|
|
||||||
)
|
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
add_subdirectory(animation)
|
|
||||||
add_subdirectory(event)
|
|
||||||
add_subdirectory(assert)
|
|
||||||
add_subdirectory(asset)
|
add_subdirectory(asset)
|
||||||
|
add_subdirectory(assert)
|
||||||
add_subdirectory(console)
|
add_subdirectory(console)
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(log)
|
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
add_subdirectory(error)
|
add_subdirectory(error)
|
||||||
add_subdirectory(input)
|
add_subdirectory(perf)
|
||||||
add_subdirectory(locale)
|
add_subdirectory(resource)
|
||||||
add_subdirectory(rpg)
|
|
||||||
add_subdirectory(scene)
|
|
||||||
add_subdirectory(system)
|
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(ui)
|
|
||||||
add_subdirectory(network)
|
|
||||||
add_subdirectory(save)
|
|
||||||
add_subdirectory(util)
|
|
||||||
add_subdirectory(thread)
|
add_subdirectory(thread)
|
||||||
|
add_subdirectory(util)
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "animation.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/math.h"
|
|
||||||
|
|
||||||
void animationInit(
|
|
||||||
animation_t *anim,
|
|
||||||
keyframe_t *keyframes,
|
|
||||||
uint16_t keyframeCount
|
|
||||||
) {
|
|
||||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
|
||||||
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
|
||||||
assertTrue(keyframeCount > 0, "Keyframe count must be more than 0.");
|
|
||||||
|
|
||||||
anim->keyframes = keyframes;
|
|
||||||
anim->keyframeCount = keyframeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t animationGetValue(animation_t *anim, const float_t time) {
|
|
||||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
|
||||||
assertNotNull(anim->keyframes, "Keyframes pointer cannot be null.");
|
|
||||||
assertTrue(anim->keyframeCount > 0, "Keyframe count invalid.");
|
|
||||||
assertTrue(time >= 0, "Time must be non-negative.");
|
|
||||||
|
|
||||||
keyframe_t *start;
|
|
||||||
keyframe_t *end;
|
|
||||||
keyframe_t *last = anim->keyframes + anim->keyframeCount - 1;
|
|
||||||
keyframe_t *current = anim->keyframes;
|
|
||||||
start = current;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(current->time > time) {
|
|
||||||
end = current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
start = current;
|
|
||||||
current++;
|
|
||||||
|
|
||||||
if(current > last) {
|
|
||||||
end = start;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(true);
|
|
||||||
|
|
||||||
float_t t = (time - start->time) / (end->time - start->time);
|
|
||||||
return mathLerp(start->value, end->value, easingApply(start->easing, t));
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "keyframe.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
keyframe_t *keyframes;
|
|
||||||
uint16_t keyframeCount;
|
|
||||||
} animation_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes an animation.
|
|
||||||
*
|
|
||||||
* @param anim The animation to initialize.
|
|
||||||
* @param keyframes The keyframes to use for the animation.
|
|
||||||
* @param keyframeCount The number of keyframes in the animation.
|
|
||||||
*/
|
|
||||||
void animationInit(
|
|
||||||
animation_t *anim,
|
|
||||||
keyframe_t *keyframes,
|
|
||||||
uint16_t keyframeCount
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the animation at a given time.
|
|
||||||
*
|
|
||||||
* @param anim The animation to get the value from.
|
|
||||||
* @param time The time at which to get the value, in seconds.
|
|
||||||
* @return The value of the animation at the given time.
|
|
||||||
*/
|
|
||||||
float_t animationGetValue(animation_t *anim, const float_t time);
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "easing.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/math.h"
|
|
||||||
|
|
||||||
const easingfn_t EASING_FUNCTIONS[EASING_COUNT] = {
|
|
||||||
easingLinear,
|
|
||||||
easingInSine,
|
|
||||||
easingOutSine,
|
|
||||||
easingInOutSine,
|
|
||||||
easingInQuad,
|
|
||||||
easingOutQuad,
|
|
||||||
easingInOutQuad,
|
|
||||||
easingInCubic,
|
|
||||||
easingOutCubic,
|
|
||||||
easingInOutCubic,
|
|
||||||
easingInQuart,
|
|
||||||
easingOutQuart,
|
|
||||||
easingInOutQuart,
|
|
||||||
easingInBack,
|
|
||||||
easingOutBack,
|
|
||||||
easingInOutBack,
|
|
||||||
};
|
|
||||||
|
|
||||||
float_t easingApply(const easingtype_t type, const float_t t) {
|
|
||||||
assertTrue(type < EASING_COUNT, "Invalid easing type");
|
|
||||||
return EASING_FUNCTIONS[type](t);
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingLinear(const float_t t) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInSine(const float_t t) {
|
|
||||||
return 1.0f - cosf(t * MATH_PI * 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingOutSine(const float_t t) {
|
|
||||||
return sinf(t * MATH_PI * 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInOutSine(const float_t t) {
|
|
||||||
return -(cosf(MATH_PI * t) - 1.0f) * 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInQuad(const float_t t) {
|
|
||||||
return t * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingOutQuad(const float_t t) {
|
|
||||||
float_t u = 1.0f - t;
|
|
||||||
return 1.0f - u * u;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInOutQuad(const float_t t) {
|
|
||||||
if(t < 0.5f) return 2.0f * t * t;
|
|
||||||
float_t u = -2.0f * t + 2.0f;
|
|
||||||
return 1.0f - u * u * 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInCubic(const float_t t) {
|
|
||||||
return t * t * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingOutCubic(const float_t t) {
|
|
||||||
float_t u = 1.0f - t;
|
|
||||||
return 1.0f - u * u * u;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInOutCubic(const float_t t) {
|
|
||||||
if(t < 0.5f) return 4.0f * t * t * t;
|
|
||||||
float_t u = -2.0f * t + 2.0f;
|
|
||||||
return 1.0f - u * u * u * 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInQuart(const float_t t) {
|
|
||||||
return t * t * t * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingOutQuart(const float_t t) {
|
|
||||||
float_t u = 1.0f - t;
|
|
||||||
return 1.0f - u * u * u * u;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInOutQuart(const float_t t) {
|
|
||||||
if(t < 0.5f) return 8.0f * t * t * t * t;
|
|
||||||
float_t u = -2.0f * t + 2.0f;
|
|
||||||
return 1.0f - u * u * u * u * 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInBack(const float_t t) {
|
|
||||||
return EASING_C3 * t * t * t - EASING_C1 * t * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingOutBack(const float_t t) {
|
|
||||||
float_t u = t - 1.0f;
|
|
||||||
return 1.0f + EASING_C3 * u * u * u + EASING_C1 * u * u;
|
|
||||||
}
|
|
||||||
|
|
||||||
float_t easingInOutBack(const float_t t) {
|
|
||||||
if(t < 0.5f) {
|
|
||||||
float_t u = 2.0f * t;
|
|
||||||
return u * u * ((EASING_C2 + 1.0f) * u - EASING_C2) * 0.5f;
|
|
||||||
}
|
|
||||||
float_t u = 2.0f * t - 2.0f;
|
|
||||||
return (u * u * ((EASING_C2 + 1.0f) * u + EASING_C2) + 2.0f) * 0.5f;
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "dusk.h"
|
|
||||||
|
|
||||||
#define EASING_PI 3.14159265358979323846f
|
|
||||||
#define EASING_C1 1.70158f
|
|
||||||
#define EASING_C2 (EASING_C1 * 1.525f)
|
|
||||||
#define EASING_C3 (EASING_C1 + 1.0f)
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
EASING_LINEAR,
|
|
||||||
EASING_IN_SINE,
|
|
||||||
EASING_OUT_SINE,
|
|
||||||
EASING_IN_OUT_SINE,
|
|
||||||
EASING_IN_QUAD,
|
|
||||||
EASING_OUT_QUAD,
|
|
||||||
EASING_IN_OUT_QUAD,
|
|
||||||
EASING_IN_CUBIC,
|
|
||||||
EASING_OUT_CUBIC,
|
|
||||||
EASING_IN_OUT_CUBIC,
|
|
||||||
EASING_IN_QUART,
|
|
||||||
EASING_OUT_QUART,
|
|
||||||
EASING_IN_OUT_QUART,
|
|
||||||
EASING_IN_BACK,
|
|
||||||
EASING_OUT_BACK,
|
|
||||||
EASING_IN_OUT_BACK,
|
|
||||||
|
|
||||||
EASING_COUNT
|
|
||||||
} easingtype_t;
|
|
||||||
|
|
||||||
typedef float_t (*easingfn_t)(const float_t t);
|
|
||||||
|
|
||||||
extern const easingfn_t EASING_FUNCTIONS[EASING_COUNT];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies the specified easing function to t.
|
|
||||||
*
|
|
||||||
* @param type The easing type to apply.
|
|
||||||
* @param t The input time, in the range [0, 1].
|
|
||||||
* @return The eased value, in the range [0, 1].
|
|
||||||
*/
|
|
||||||
float_t easingApply(const easingtype_t type, const float_t t);
|
|
||||||
|
|
||||||
float_t easingLinear(const float_t t);
|
|
||||||
float_t easingInSine(const float_t t);
|
|
||||||
float_t easingOutSine(const float_t t);
|
|
||||||
float_t easingInOutSine(const float_t t);
|
|
||||||
float_t easingInQuad(const float_t t);
|
|
||||||
float_t easingOutQuad(const float_t t);
|
|
||||||
float_t easingInOutQuad(const float_t t);
|
|
||||||
float_t easingInCubic(const float_t t);
|
|
||||||
float_t easingOutCubic(const float_t t);
|
|
||||||
float_t easingInOutCubic(const float_t t);
|
|
||||||
float_t easingInQuart(const float_t t);
|
|
||||||
float_t easingOutQuart(const float_t t);
|
|
||||||
float_t easingInOutQuart(const float_t t);
|
|
||||||
float_t easingInBack(const float_t t);
|
|
||||||
float_t easingOutBack(const float_t t);
|
|
||||||
float_t easingInOutBack(const float_t t);
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// Copyright (c) 2026 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "easing.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float_t time;
|
|
||||||
float_t value;
|
|
||||||
easingtype_t easing;
|
|
||||||
} keyframe_t;
|
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void assertLogBacktrace(void) {
|
void assertLogBacktrace(void) {
|
||||||
void *frames[64];
|
void *frames[64];
|
||||||
int count = backtrace(frames, 64);
|
int count = backtrace(frames, 64);
|
||||||
char **symbols = backtrace_symbols(frames, count);
|
char **symbols = backtrace_symbols(frames, count);
|
||||||
|
|||||||
@@ -22,12 +22,21 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DUSK_ASSERTIONS_FAKED
|
#ifndef DUSK_ASSERTIONS_FAKED
|
||||||
|
#define DUSK_ASSERTIONS 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the assert system. Must be the very first call in engine
|
* Initializes the assert system. Must be the very first call in engine
|
||||||
* startup.
|
* startup.
|
||||||
*/
|
*/
|
||||||
void assertInit(void);
|
void assertInit(void);
|
||||||
|
|
||||||
|
#ifdef DUSK_BACKTRACE
|
||||||
|
/**
|
||||||
|
* Logs a stack trace of the current call stack to the error log.
|
||||||
|
*/
|
||||||
|
void assertLogBacktrace(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert a given value to be true.
|
* Assert a given value to be true.
|
||||||
*
|
*
|
||||||
@@ -274,8 +283,25 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Static Assertions
|
// Static Assertions. These are compile time only, so they are never faked.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts a constant expression at compile time. Never faked, even when
|
||||||
|
* DUSK_ASSERTIONS_FAKED is set.
|
||||||
|
*
|
||||||
|
* @param x Constant expression that must be true.
|
||||||
|
* @param message Message to show on failure, must be a string literal.
|
||||||
|
*/
|
||||||
|
#define assertStatic(x, message) \
|
||||||
|
_Static_assert(x, message)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts the size of a struct at compile time.
|
||||||
|
*
|
||||||
|
* @param struct The struct type to check.
|
||||||
|
* @param size The size in bytes the struct must be.
|
||||||
|
*/
|
||||||
#define assertStructSize(struct, size) \
|
#define assertStructSize(struct, size) \
|
||||||
_Static_assert(sizeof(struct) == size, "Size of " #struct " must be " #size)
|
assertStatic(sizeof(struct) == size, "Size of " #struct " must be " #size)
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
# Copyright (c) 2026 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
asset.c
|
asset.c
|
||||||
assetbatch.c
|
|
||||||
assetfile.c
|
assetfile.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
add_subdirectory(loader)
|
|
||||||
+36
-405
@@ -5,431 +5,62 @@
|
|||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "asset.h"
|
#include "asset/asset.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "engine/engine.h"
|
|
||||||
#include "util/string.h"
|
|
||||||
#include "console/console.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
asset_t ASSET;
|
asset_t ASSET;
|
||||||
|
|
||||||
errorret_t assetInit(void) {
|
errorret_t assetInit(void) {
|
||||||
memoryZero(&ASSET, sizeof(asset_t));
|
memoryZero(&ASSET, sizeof(asset_t));
|
||||||
|
|
||||||
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
// The platform must set ASSET.baseDirectory or throw an error.
|
||||||
threadMutexInit(&ASSET.loading[i].mutex);
|
errorChain(assetInitPlatform());
|
||||||
|
assertStrLenMin(ASSET.baseDirectory, 1, "Asset directory empty without error.");
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t assetGetPath(
|
||||||
|
const char_t *filename,
|
||||||
|
char_t *out,
|
||||||
|
const size_t outSize
|
||||||
|
) {
|
||||||
|
assertNotNull(filename, "Filename cannot be NULL.");
|
||||||
|
assertNotNull(out, "Output cannot be NULL.");
|
||||||
|
|
||||||
|
if(filename[0] == '\0') {
|
||||||
|
errorThrow("Asset filename cannot be empty.");
|
||||||
|
}
|
||||||
|
if(filename[0] == '/' || stringIncludesString(filename, "..")) {
|
||||||
|
errorThrow("Invalid asset filename: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// assetInitPlatform must either define ASSET.zip or throw an error.
|
int32_t len = stringFormat(out, outSize, "%s/%s", ASSET.baseDirectory, filename);
|
||||||
errorChain(assetInitPlatform());
|
if(len < 0 || (size_t)len >= outSize) {
|
||||||
assertNotNull(ASSET.zip, "Asset zip null without error.");
|
errorThrow("Asset path too long: %s", filename);
|
||||||
threadInit(&ASSET.loadThread, assetUpdateAsync);
|
}
|
||||||
threadStart(&ASSET.loadThread);
|
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t assetFileExists(const char_t *filename) {
|
bool_t assetFileExists(const char_t *filename) {
|
||||||
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
char_t path[ASSET_PATH_MAX];
|
||||||
|
errorret_t ret = assetGetPath(filename, path, sizeof(path));
|
||||||
|
if(errorIsNotOk(ret)) {
|
||||||
|
errorCatch(ret);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
zip_int64_t idx = zip_name_locate(ASSET.zip, filename, 0);
|
FILE *file = fopen(path, "rb");
|
||||||
if(idx < 0) return false;
|
if(file == NULL) return false;
|
||||||
|
fclose(file);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
assetentry_t * assetGetEntry(
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
) {
|
|
||||||
// Is there an existing asset?
|
|
||||||
assetentry_t *entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(entry->type == ASSET_LOADER_TYPE_NULL) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(stringEquals(entry->name, name)) {
|
|
||||||
assertTrue(entry->type == type, "Asset entry type mismatch.");
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
// We did not find one existing, Find first available slot.
|
|
||||||
entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(entry->type != ASSET_LOADER_TYPE_NULL) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entry->state == ASSET_ENTRY_STATE_NOT_STARTED) {
|
|
||||||
assetEntryInit(entry, name, type, input);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
assertUnreachable("No available asset entry slots.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t assetGetEntriesOfType(
|
|
||||||
assetentry_t **outEntries,
|
|
||||||
const assetloadertype_t type
|
|
||||||
) {
|
|
||||||
assertNotNull(outEntries, "Output entries cannot be NULL.");
|
|
||||||
|
|
||||||
uint32_t count = 0;
|
|
||||||
assetentry_t *entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(entry->type == type) {
|
|
||||||
outEntries[count++] = entry;
|
|
||||||
}
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetRequireLoaded(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL.");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
assertIsMainThread("Currently only works on main thread.");
|
|
||||||
|
|
||||||
if(entry->state == ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lock to prevent the reaper from collecting the entry mid-spin.
|
|
||||||
assetEntryLock(entry);
|
|
||||||
|
|
||||||
while(entry->state != ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
usleep(1000);
|
|
||||||
errorret_t ret = assetUpdate();
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetRequireDisposed(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL.");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
assertIsMainThread("Currently only works on main thread.");
|
|
||||||
|
|
||||||
if(entry->type == ASSET_LOADER_TYPE_NULL) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(
|
|
||||||
entry->state == ASSET_ENTRY_STATE_NOT_STARTED ||
|
|
||||||
entry->state == ASSET_ENTRY_STATE_ERROR
|
|
||||||
) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(
|
|
||||||
entry->refs.count == 0,
|
|
||||||
"Cannot require disposal of an entry with active references."
|
|
||||||
);
|
|
||||||
|
|
||||||
// Lock to prevent the reaper from collecting the entry mid-spin.
|
|
||||||
assetEntryLock(entry);
|
|
||||||
|
|
||||||
while(entry->type != ASSET_LOADER_TYPE_NULL) {
|
|
||||||
usleep(1000);
|
|
||||||
errorret_t ret = assetUpdate();
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetentry_t * assetLock(
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
) {
|
|
||||||
assetentry_t *entry = assetGetEntry(name, type, input);
|
|
||||||
assetEntryLock(entry);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetUnlock(const char_t *name) {
|
|
||||||
assertNotNull(name, "Name cannot be NULL.");
|
|
||||||
|
|
||||||
assetentry_t *entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(
|
|
||||||
entry->type != ASSET_LOADER_TYPE_NULL &&
|
|
||||||
stringEquals(entry->name, name)
|
|
||||||
) {
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
assertUnreachable("Asset entry not found for unlock.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetUnlockEntry(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL.");
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetUpdate(void) {
|
|
||||||
assertIsMainThread("assetUpdate must be called from the main thread.");
|
|
||||||
|
|
||||||
// Determine how many available loading slots we have.
|
|
||||||
assetloading_t *availableLoading[ASSET_LOADING_COUNT_MAX];
|
|
||||||
uint8_t availableLoadingCount = 0;
|
|
||||||
assetloading_t *loading = ASSET.loading;
|
|
||||||
assetentry_t *entry;
|
|
||||||
|
|
||||||
|
|
||||||
do {
|
|
||||||
// We only care about NULL entry references. Nothing async touches this so
|
|
||||||
// it's fine to use raw here.
|
|
||||||
if(loading->entry != NULL) {
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
availableLoading[availableLoadingCount++] = loading;
|
|
||||||
loading++;
|
|
||||||
} while(loading < ASSET.loading + ASSET_LOADING_COUNT_MAX);
|
|
||||||
|
|
||||||
|
|
||||||
// Now we can check for pending asset entries, we can't do anything if there
|
|
||||||
// is no available slots though.
|
|
||||||
if(availableLoadingCount > 0) {
|
|
||||||
entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
// Is this asset "ready to start loading" ?
|
|
||||||
if(entry->type == ASSET_LOADER_TYPE_NULL) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We only care about assets not started.
|
|
||||||
if(entry->state != ASSET_ENTRY_STATE_NOT_STARTED) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pop a loading slot for this asset entry.
|
|
||||||
loading = availableLoading[--availableLoadingCount];
|
|
||||||
|
|
||||||
// Start loading this asset.
|
|
||||||
assetEntryStartLoading(entry, loading);
|
|
||||||
entry++;
|
|
||||||
|
|
||||||
// Did we run out of loading slots?
|
|
||||||
if(availableLoadingCount == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now walk over all the loading slots and see what needs to be done.
|
|
||||||
loading = ASSET.loading;
|
|
||||||
do {
|
|
||||||
// Is the loading slot in use? Entry can only be modified synchronously.
|
|
||||||
if(loading->entry == NULL) {
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lock the loading slot. This will prevent any async modifications.
|
|
||||||
threadMutexLock(&loading->mutex);
|
|
||||||
|
|
||||||
// Check the state of the entry.
|
|
||||||
switch(loading->entry->state) {
|
|
||||||
// This thing is pending synchronous loading.
|
|
||||||
case ASSET_ENTRY_STATE_PENDING_SYNC:
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADING_SYNC;
|
|
||||||
// Unlock before calling loadSync. The sync loader may re-enter
|
|
||||||
// assetUpdate (e.g. a script loading another asset), and the async
|
|
||||||
// thread never touches LOADING_SYNC entries, so this is safe.
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
|
|
||||||
errorret_t ret = (
|
|
||||||
ASSET_LOADER_CALLBACKS[loading->type].loadSync(loading)
|
|
||||||
);
|
|
||||||
|
|
||||||
// After a sync load, these are the only valid states.
|
|
||||||
assertTrue(
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_LOADED ||
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_ERROR ||
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_PENDING_SYNC ||
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_PENDING_ASYNC,
|
|
||||||
"Loader did not set entry state to loaded or error on finished load."
|
|
||||||
);
|
|
||||||
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
errorCatch(errorPrint(ret));
|
|
||||||
assertTrue(
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_ERROR,
|
|
||||||
"Loader did not set entry state to error on failed load."
|
|
||||||
);
|
|
||||||
} else if(loading->entry->state == ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
eventInvoke(&loading->entry->onLoaded, loading->entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
loading++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_ENTRY_STATE_LOADING_SYNC:
|
|
||||||
// A re-entrant assetUpdate call (e.g. from a script loading another
|
|
||||||
// asset) will see this entry mid-sync-load. Skip it.
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Done loading, we can just free it up.
|
|
||||||
case ASSET_ENTRY_STATE_LOADED:
|
|
||||||
loading->entry = NULL;
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_ENTRY_STATE_ERROR: {
|
|
||||||
assetentry_t *errEntry = loading->entry;
|
|
||||||
loading->entry = NULL;
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
eventInvoke(&errEntry->onError, errEntry);
|
|
||||||
errorThrow("Failed to load asset asynchronously.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} while(loading < ASSET.loading + ASSET_LOADING_COUNT_MAX);
|
|
||||||
|
|
||||||
|
|
||||||
// Reap unused entries.
|
|
||||||
entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(entry->state != ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entry->type == ASSET_LOADER_TYPE_NULL) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entry->refs.count > 0) {
|
|
||||||
entry++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
consolePrint("Reaping asset %s", entry->name);
|
|
||||||
errorChain(assetEntryDispose(entry));
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetUpdateAsync(thread_t *thread) {
|
|
||||||
assertNotMainThread("assetUpdateAsync must not run on the main thread.");
|
|
||||||
|
|
||||||
while(!threadShouldStop(thread)) {
|
|
||||||
// Walk over each asset
|
|
||||||
assetloading_t *loading;
|
|
||||||
loading = ASSET.loading;
|
|
||||||
|
|
||||||
do {
|
|
||||||
threadMutexLock(&loading->mutex);
|
|
||||||
|
|
||||||
if(loading->entry == NULL) {
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(loading->entry->state) {
|
|
||||||
case ASSET_ENTRY_STATE_PENDING_ASYNC:
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADING_ASYNC;
|
|
||||||
assertNotNull(
|
|
||||||
ASSET_LOADER_CALLBACKS[loading->type].loadAsync,
|
|
||||||
"Loader does not support async loading."
|
|
||||||
);
|
|
||||||
errorret_t ret = (
|
|
||||||
ASSET_LOADER_CALLBACKS[loading->type].loadAsync(loading)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
errorCatch(errorPrint(ret));
|
|
||||||
assertTrue(
|
|
||||||
loading->entry->state == ASSET_ENTRY_STATE_ERROR,
|
|
||||||
"Loader did not set entry state to error on failed load."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_ENTRY_STATE_LOADING_ASYNC:
|
|
||||||
assertUnreachable(
|
|
||||||
"Entry is in a pending async state still?"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
threadMutexUnlock(&loading->mutex);
|
|
||||||
loading++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} while(loading < ASSET.loading + ASSET_LOADING_COUNT_MAX);
|
|
||||||
|
|
||||||
if(threadShouldStop(thread)) break;
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetDispose(void) {
|
errorret_t assetDispose(void) {
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
threadStop(&ASSET.loadThread);
|
|
||||||
|
|
||||||
// Dispose every non-null entry so type-specific dispose callbacks
|
|
||||||
// (e.g. assetScriptDispose freeing jerry values) run before the
|
|
||||||
// scripting engine is torn down.
|
|
||||||
assetentry_t *entry = ASSET.entries;
|
|
||||||
do {
|
|
||||||
if(entry->type != ASSET_LOADER_TYPE_NULL) {
|
|
||||||
errorChain(assetEntryDispose(entry));
|
|
||||||
}
|
|
||||||
entry++;
|
|
||||||
} while(entry < ASSET.entries + ASSET_ENTRY_COUNT_MAX);
|
|
||||||
|
|
||||||
// Cleanup zip file.
|
|
||||||
if(ASSET.zip != NULL) {
|
|
||||||
if(zip_close(ASSET.zip) != 0) {
|
|
||||||
errorThrow("Failed to close asset zip archive.");
|
|
||||||
}
|
|
||||||
ASSET.zip = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetDisposePlatform());
|
errorChain(assetDisposePlatform());
|
||||||
|
memoryZero(&ASSET, sizeof(asset_t));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
+28
-116
@@ -8,10 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "asset/assetplatform.h"
|
#include "asset/assetplatform.h"
|
||||||
#include "assetfile.h"
|
#include "asset/assetfile.h"
|
||||||
#include "thread/thread.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
|
|
||||||
#ifndef assetInitPlatform
|
#ifndef assetInitPlatform
|
||||||
#error "Platform must define assetInitPlatform function."
|
#error "Platform must define assetInitPlatform function."
|
||||||
@@ -20,134 +17,49 @@
|
|||||||
#error "Platform must define assetDisposePlatform function."
|
#error "Platform must define assetDisposePlatform function."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASSET_FILE_NAME "dusk.dsk"
|
#define ASSET_BASE_DIRECTORY_MAX 256
|
||||||
#define ASSET_HEADER_SIZE 3
|
|
||||||
|
|
||||||
#define ASSET_LOADING_COUNT_MAX 4
|
typedef struct {
|
||||||
#define ASSET_ENTRY_COUNT_MAX 128
|
// Directory that every asset filename is resolved relative to. Set by the
|
||||||
|
// platform in assetInitPlatform.
|
||||||
typedef struct asset_s {
|
char_t baseDirectory[ASSET_BASE_DIRECTORY_MAX];
|
||||||
zip_t *zip;
|
|
||||||
assetplatform_t platform;
|
|
||||||
|
|
||||||
// Background loading thread.
|
|
||||||
thread_t loadThread;
|
|
||||||
|
|
||||||
// Assets that are mid loading.
|
|
||||||
assetloading_t loading[ASSET_LOADING_COUNT_MAX];
|
|
||||||
assetentry_t entries[ASSET_ENTRY_COUNT_MAX];
|
|
||||||
} asset_t;
|
} asset_t;
|
||||||
|
|
||||||
extern asset_t ASSET;
|
extern asset_t ASSET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the asset system.
|
* Initializes the asset system. The platform locates the assets and sets
|
||||||
|
* ASSET.baseDirectory, or throws an error if it cannot.
|
||||||
*
|
*
|
||||||
* @return An error code if the asset system could not be initialized properly.
|
* @return An errorret_t indicating success or failure.
|
||||||
*/
|
*/
|
||||||
errorret_t assetInit(void);
|
errorret_t assetInit(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if an asset file exists.
|
* Builds the full path of an asset on disk.
|
||||||
*
|
*
|
||||||
* @param filename The filename of the asset to check.
|
* @param filename Asset filename, relative to the asset directory.
|
||||||
* @return true if the asset file exists, false otherwise.
|
* @param out Buffer to write the null terminated path into.
|
||||||
|
* @param outSize Size of the buffer in bytes.
|
||||||
|
* @return An error if the filename is invalid or the path does not fit.
|
||||||
|
*/
|
||||||
|
errorret_t assetGetPath(
|
||||||
|
const char_t *filename,
|
||||||
|
char_t *out,
|
||||||
|
const size_t outSize
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an asset exists.
|
||||||
|
*
|
||||||
|
* @param filename Asset filename, relative to the asset directory.
|
||||||
|
* @return True if the asset exists and can be opened for reading.
|
||||||
*/
|
*/
|
||||||
bool_t assetFileExists(const char_t *filename);
|
bool_t assetFileExists(const char_t *filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets, or creates, a new asset entry. Internal - prefer assetLock.
|
* Disposes of the asset system.
|
||||||
*
|
*
|
||||||
* @param name Filename of the asset.
|
* @return An errorret_t indicating success or failure.
|
||||||
* @param type Type of the asset.
|
|
||||||
* @param input Loader-specific parameters.
|
|
||||||
*/
|
|
||||||
assetentry_t * assetGetEntry(
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all asset entries of a given type.
|
|
||||||
*
|
|
||||||
* @param outEntries Output array to write the entries to.
|
|
||||||
* @param type Type of the asset entries to get.
|
|
||||||
* @return The number of entries written to outEntries.
|
|
||||||
*/
|
|
||||||
uint32_t assetGetEntriesOfType(
|
|
||||||
assetentry_t **outEntries,
|
|
||||||
const assetloadertype_t type
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets, creates, and locks an asset entry. The asset will begin loading on
|
|
||||||
* the next assetUpdate. Call assetUnlock when done to allow the entry to be
|
|
||||||
* reclaimed.
|
|
||||||
*
|
|
||||||
* @param name Filename of the asset.
|
|
||||||
* @param type Type of the asset.
|
|
||||||
* @param input Loader-specific parameters.
|
|
||||||
* @return The locked asset entry.
|
|
||||||
*/
|
|
||||||
assetentry_t * assetLock(
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Releases a lock on an asset entry by name. When all locks are released the
|
|
||||||
* entry will be reclaimed at the start of the next assetUpdate.
|
|
||||||
*
|
|
||||||
* @param name Filename of the asset to unlock.
|
|
||||||
*/
|
|
||||||
void assetUnlock(const char_t *name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Releases a lock on an asset entry by pointer. When all locks are released
|
|
||||||
* the entry will be reclaimed at the start of the next assetUpdate.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to unlock.
|
|
||||||
*/
|
|
||||||
void assetUnlockEntry(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requires an asset entry to be loaded. This will block until the asset entry
|
|
||||||
* is fully loaded.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to require.
|
|
||||||
* @return An error code if the asset entry could not be loaded properly.
|
|
||||||
*/
|
|
||||||
errorret_t assetRequireLoaded(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requires an asset entry to be disposed. This will block until the asset entry
|
|
||||||
* is fully disposed.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to require disposal of.
|
|
||||||
* @return An error code if the asset entry could not be disposed properly.
|
|
||||||
*/
|
|
||||||
errorret_t assetRequireDisposed(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the asset system.
|
|
||||||
*
|
|
||||||
* @return An error code if the asset system could not be updated properly.
|
|
||||||
*/
|
|
||||||
errorret_t assetUpdate(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the background asset loading thread. The thread runs assetUpdate
|
|
||||||
* in a loop with a short sleep until stopped.
|
|
||||||
*
|
|
||||||
* @param thread The thread runner.
|
|
||||||
*/
|
|
||||||
void assetUpdateAsync(thread_t *thread);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disposes/cleans up the asset system.
|
|
||||||
*
|
|
||||||
* @return An error code if the asset system could not be disposed properly.
|
|
||||||
*/
|
*/
|
||||||
errorret_t assetDispose(void);
|
errorret_t assetDispose(void);
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetbatch.h"
|
|
||||||
#include "asset.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void assetBatchInit(
|
|
||||||
assetbatch_t *batch,
|
|
||||||
const uint16_t count,
|
|
||||||
const assetbatchdesc_t *descs
|
|
||||||
) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
assertNotNull(descs, "Descs cannot be NULL.");
|
|
||||||
assertTrue(count > 0, "Count must be greater than 0.");
|
|
||||||
assertTrue(
|
|
||||||
count <= ASSET_BATCH_COUNT_MAX, "Count exceeds ASSET_BATCH_COUNT_MAX."
|
|
||||||
);
|
|
||||||
|
|
||||||
memoryZero(batch, sizeof(assetbatch_t));
|
|
||||||
batch->count = count;
|
|
||||||
|
|
||||||
eventInit(
|
|
||||||
&batch->onLoaded,
|
|
||||||
batch->onLoadedCallbacks, batch->onLoadedUsers, ASSET_BATCH_EVENT_MAX
|
|
||||||
);
|
|
||||||
eventInit(
|
|
||||||
&batch->onEntryLoaded,
|
|
||||||
batch->onEntryLoadedCallbacks,
|
|
||||||
batch->onEntryLoadedUsers,
|
|
||||||
ASSET_BATCH_EVENT_MAX
|
|
||||||
);
|
|
||||||
eventInit(
|
|
||||||
&batch->onError,
|
|
||||||
batch->onErrorCallbacks, batch->onErrorUsers, ASSET_BATCH_EVENT_MAX
|
|
||||||
);
|
|
||||||
eventInit(
|
|
||||||
&batch->onEntryError,
|
|
||||||
batch->onEntryErrorCallbacks,
|
|
||||||
batch->onEntryErrorUsers,
|
|
||||||
ASSET_BATCH_EVENT_MAX
|
|
||||||
);
|
|
||||||
|
|
||||||
for(uint16_t i = 0; i < count; i++) {
|
|
||||||
batch->inputs[i] = descs[i].input;
|
|
||||||
batch->entries[i] = assetLock(
|
|
||||||
descs[i].path, descs[i].type, &batch->inputs[i]
|
|
||||||
);
|
|
||||||
|
|
||||||
if(batch->entries[i]->state == ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
// Already loaded (cached) - count it now, no subscription needed.
|
|
||||||
batch->loadedCount++;
|
|
||||||
} else if(batch->entries[i]->state == ASSET_ENTRY_STATE_ERROR) {
|
|
||||||
batch->errorCount++;
|
|
||||||
} else {
|
|
||||||
eventSubscribe(
|
|
||||||
&batch->entries[i]->onLoaded, assetBatchEntryOnLoadedCb, batch
|
|
||||||
);
|
|
||||||
eventSubscribe(
|
|
||||||
&batch->entries[i]->onError, assetBatchEntryOnErrorCb, batch
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetBatchLock(assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
assetEntryLock(batch->entries[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetBatchUnlock(assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
assetEntryUnlock(batch->entries[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_t assetBatchIsLoaded(const assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
if(batch->entries[i]->state != ASSET_ENTRY_STATE_LOADED) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_t assetBatchHasError(const assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
if(batch->entries[i]->state == ASSET_ENTRY_STATE_ERROR) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetBatchRequireLoaded(assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
|
|
||||||
bool_t allDone;
|
|
||||||
do {
|
|
||||||
allDone = true;
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
const assetentrystate_t state = batch->entries[i]->state;
|
|
||||||
if(state == ASSET_ENTRY_STATE_ERROR) {
|
|
||||||
errorThrow("Asset '%s' failed to load.", batch->entries[i]->name);
|
|
||||||
}
|
|
||||||
if(state != ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
allDone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!allDone) {
|
|
||||||
usleep(1000);
|
|
||||||
errorChain(assetUpdate());
|
|
||||||
}
|
|
||||||
} while(!allDone);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetBatchDispose(assetbatch_t *batch) {
|
|
||||||
assertNotNull(batch, "Batch cannot be NULL.");
|
|
||||||
for(uint16_t i = 0; i < batch->count; i++) {
|
|
||||||
if(batch->entries[i]) {
|
|
||||||
// Unsubscribe while we still hold a lock so the entry is live.
|
|
||||||
eventUnsubscribe(&batch->entries[i]->onLoaded, assetBatchEntryOnLoadedCb);
|
|
||||||
eventUnsubscribe(&batch->entries[i]->onError, assetBatchEntryOnErrorCb);
|
|
||||||
assetUnlockEntry(batch->entries[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
memoryZero(batch, sizeof(assetbatch_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetBatchEntryOnLoadedCb(void *params, void *user) {
|
|
||||||
assetentry_t *entry = (assetentry_t *)params;
|
|
||||||
assetbatch_t *batch = (assetbatch_t *)user;
|
|
||||||
|
|
||||||
batch->loadedCount++;
|
|
||||||
eventInvoke(&batch->onEntryLoaded, entry);
|
|
||||||
|
|
||||||
if((uint16_t)(batch->loadedCount + batch->errorCount) >= batch->count) {
|
|
||||||
if(batch->errorCount == 0) {
|
|
||||||
eventInvoke(&batch->onLoaded, batch);
|
|
||||||
} else {
|
|
||||||
eventInvoke(&batch->onError, batch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetBatchEntryOnErrorCb(void *params, void *user) {
|
|
||||||
assetentry_t *entry = (assetentry_t *)params;
|
|
||||||
assetbatch_t *batch = (assetbatch_t *)user;
|
|
||||||
|
|
||||||
batch->errorCount++;
|
|
||||||
eventInvoke(&batch->onEntryError, entry);
|
|
||||||
|
|
||||||
if((uint16_t)(batch->loadedCount + batch->errorCount) >= batch->count) {
|
|
||||||
eventInvoke(&batch->onError, batch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
#include "asset/loader/assetloader.h"
|
|
||||||
#include "event/event.h"
|
|
||||||
|
|
||||||
#define ASSET_BATCH_COUNT_MAX 64
|
|
||||||
#define ASSET_BATCH_EVENT_MAX 4
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char_t *path;
|
|
||||||
assetloadertype_t type;
|
|
||||||
assetloaderinput_t input;
|
|
||||||
} assetbatchdesc_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetentry_t *entries[ASSET_BATCH_COUNT_MAX];
|
|
||||||
assetloaderinput_t inputs[ASSET_BATCH_COUNT_MAX];
|
|
||||||
uint16_t count;
|
|
||||||
uint16_t loadedCount;
|
|
||||||
uint16_t errorCount;
|
|
||||||
|
|
||||||
/** Fires once when every entry loaded. params = assetbatch_t * */
|
|
||||||
event_t onLoaded;
|
|
||||||
eventcallback_t onLoadedCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
||||||
void *onLoadedUsers[ASSET_BATCH_EVENT_MAX];
|
|
||||||
|
|
||||||
/** Fires each time a single entry loads. params = assetentry_t * */
|
|
||||||
event_t onEntryLoaded;
|
|
||||||
eventcallback_t onEntryLoadedCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
||||||
void *onEntryLoadedUsers[ASSET_BATCH_EVENT_MAX];
|
|
||||||
|
|
||||||
/** Fires when all entries finish (any with errors). params: assetbatch_t * */
|
|
||||||
event_t onError;
|
|
||||||
eventcallback_t onErrorCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
||||||
void *onErrorUsers[ASSET_BATCH_EVENT_MAX];
|
|
||||||
|
|
||||||
/** Fires each time a single entry errors. params = assetentry_t * */
|
|
||||||
event_t onEntryError;
|
|
||||||
eventcallback_t onEntryErrorCallbacks[ASSET_BATCH_EVENT_MAX];
|
|
||||||
void *onEntryErrorUsers[ASSET_BATCH_EVENT_MAX];
|
|
||||||
} assetbatch_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialises the batch from an array of descriptors. Each entry is locked
|
|
||||||
* and queued for loading immediately.
|
|
||||||
*
|
|
||||||
* @param batch Batch to initialise.
|
|
||||||
* @param descs Array of entry descriptors (need not outlive this call).
|
|
||||||
* @param count Number of descriptors (must be <= ASSET_BATCH_COUNT_MAX).
|
|
||||||
*/
|
|
||||||
void assetBatchInit(
|
|
||||||
assetbatch_t *batch,
|
|
||||||
uint16_t count,
|
|
||||||
const assetbatchdesc_t *descs
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Acquires one additional lock on every entry in the batch.
|
|
||||||
*
|
|
||||||
* @param batch Batch to lock.
|
|
||||||
*/
|
|
||||||
void assetBatchLock(assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Releases one lock from every entry in the batch. When an entry's lock
|
|
||||||
* count reaches zero it will be reaped on the next assetUpdate.
|
|
||||||
*
|
|
||||||
* @param batch Batch to unlock.
|
|
||||||
*/
|
|
||||||
void assetBatchUnlock(assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if every entry in the batch has finished loading.
|
|
||||||
*
|
|
||||||
* @param batch Batch to query.
|
|
||||||
*/
|
|
||||||
bool_t assetBatchIsLoaded(const assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if any entry in the batch is in an error state.
|
|
||||||
*
|
|
||||||
* @param batch Batch to query.
|
|
||||||
*/
|
|
||||||
bool_t assetBatchHasError(const assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blocks until every entry is loaded. Returns an error if any entry fails.
|
|
||||||
*
|
|
||||||
* @param batch Batch to wait on.
|
|
||||||
*/
|
|
||||||
errorret_t assetBatchRequireLoaded(assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Releases the batch's lock on every entry and clears the batch. After this
|
|
||||||
* call the batch struct may be reused with assetBatchInit.
|
|
||||||
*
|
|
||||||
* @param batch Batch to dispose.
|
|
||||||
*/
|
|
||||||
void assetBatchDispose(assetbatch_t *batch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event trampoline invoked when a batch entry finishes loading.
|
|
||||||
* Increments the loaded counter and fires batch-level events.
|
|
||||||
*
|
|
||||||
* @param params The loaded assetentry_t pointer.
|
|
||||||
* @param user The owning assetbatch_t pointer.
|
|
||||||
*/
|
|
||||||
void assetBatchEntryOnLoadedCb(void *params, void *user);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event trampoline invoked when a batch entry fails to load.
|
|
||||||
* Increments the error counter and fires batch-level events.
|
|
||||||
*
|
|
||||||
* @param params The errored assetentry_t pointer.
|
|
||||||
* @param user The owning assetbatch_t pointer.
|
|
||||||
*/
|
|
||||||
void assetBatchEntryOnErrorCb(void *params, void *user);
|
|
||||||
+77
-299
@@ -8,109 +8,113 @@
|
|||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
|
|
||||||
errorret_t assetFileInit(
|
errorret_t assetFileInit(assetfile_t *file, const char_t *filename) {
|
||||||
assetfile_t *file,
|
|
||||||
const char_t *filename,
|
|
||||||
void *params,
|
|
||||||
void *output
|
|
||||||
) {
|
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
|
assertNotNull(filename, "Filename cannot be NULL.");
|
||||||
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
||||||
|
|
||||||
memoryZero(file, sizeof(assetfile_t));
|
memoryZero(file, sizeof(assetfile_t));
|
||||||
memoryCopy(file->filename, filename, ASSET_FILE_NAME_MAX);
|
stringCopy(file->filename, filename, ASSET_FILE_NAME_MAX);
|
||||||
file->params = params;
|
|
||||||
file->output = output;
|
|
||||||
|
|
||||||
// Stat the file
|
// Open temporarily to find the size.
|
||||||
zip_stat_init(&file->stat);
|
char_t path[ASSET_PATH_MAX];
|
||||||
if(!zip_stat(ASSET.zip, filename, 0, &file->stat) == 0) {
|
errorChain(assetGetPath(filename, path, sizeof(path)));
|
||||||
errorThrow("Failed to stat asset file: %s", filename);
|
|
||||||
|
FILE *handle = fopen(path, "rb");
|
||||||
|
if(handle == NULL) {
|
||||||
|
errorThrow("Failed to open asset file: %s", filename);
|
||||||
|
}
|
||||||
|
if(fseek(handle, 0, SEEK_END) != 0) {
|
||||||
|
fclose(handle);
|
||||||
|
errorThrow("Failed to seek asset file: %s", filename);
|
||||||
|
}
|
||||||
|
long size = ftell(handle);
|
||||||
|
fclose(handle);
|
||||||
|
if(size < 0) {
|
||||||
|
errorThrow("Failed to get size of asset file: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minimum file size.
|
file->size = (size_t)size;
|
||||||
file->size = (zip_int64_t)file->stat.size;
|
|
||||||
if(file->size <= 0) {
|
|
||||||
errorThrow("Invalid asset file size: %s", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetFileRewind(assetfile_t *file) {
|
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
|
||||||
assertNotNull(file->zipFile, "Asset file must be opened before rewinding.");
|
|
||||||
|
|
||||||
if(file->position == 0) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileClose(file));
|
|
||||||
errorChain(assetFileOpen(file));
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetFileOpen(assetfile_t *file) {
|
errorret_t assetFileOpen(assetfile_t *file) {
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
assertNotNull(file->filename, "Asset file filename cannot be NULL.");
|
assertNull(file->file, "Asset file already open.");
|
||||||
assertNotNull(ASSET.zip, "Asset zip cannot be NULL.");
|
|
||||||
assertNull(file->zipFile, "Asset file already open.");
|
|
||||||
|
|
||||||
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
char_t path[ASSET_PATH_MAX];
|
||||||
if(file->zipFile == NULL) {
|
errorChain(assetGetPath(file->filename, path, sizeof(path)));
|
||||||
|
|
||||||
|
file->file = fopen(path, "rb");
|
||||||
|
if(file->file == NULL) {
|
||||||
errorThrow("Failed to open asset file: %s", file->filename);
|
errorThrow("Failed to open asset file: %s", file->filename);
|
||||||
}
|
}
|
||||||
file->position = 0;
|
file->position = 0;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorret_t assetFileRewind(assetfile_t *file) {
|
||||||
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
|
assertNotNull(file->file, "Asset file must be opened before rewinding.");
|
||||||
|
|
||||||
|
if(fseek(file->file, 0, SEEK_SET) != 0) {
|
||||||
|
errorThrow("Failed to rewind asset file: %s", file->filename);
|
||||||
|
}
|
||||||
|
file->position = 0;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
errorret_t assetFileRead(
|
errorret_t assetFileRead(
|
||||||
assetfile_t *file,
|
assetfile_t *file,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
const size_t bufferSize
|
const size_t bufferSize
|
||||||
) {
|
) {
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
assertNotNull(file->zipFile, "Asset file must be opened before reading.");
|
assertNotNull(file->file, "Asset file must be opened before reading.");
|
||||||
|
|
||||||
|
// No buffer, skip the bytes.
|
||||||
if(buffer == NULL) {
|
if(buffer == NULL) {
|
||||||
size_t bytesRemaining = bufferSize;
|
size_t skipped = 0;
|
||||||
uint8_t tempBuffer[256];
|
uint8_t temp[256];
|
||||||
while(bytesRemaining > 0) {
|
while(skipped < bufferSize) {
|
||||||
size_t chunkSize = mathMin(bytesRemaining, sizeof(tempBuffer));
|
size_t chunk = mathMin(bufferSize - skipped, sizeof(temp));
|
||||||
errorChain(assetFileRead(file, tempBuffer, chunkSize));
|
size_t got = fread(temp, 1, chunk, file->file);
|
||||||
file->position += chunkSize;
|
skipped += got;
|
||||||
bytesRemaining -= chunkSize;
|
if(got < chunk) break;
|
||||||
}
|
}
|
||||||
file->lastRead = bufferSize;
|
file->position += skipped;
|
||||||
|
file->lastRead = skipped;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// I assume zip_fread takes buffer NULL for skipping?
|
size_t got = fread(buffer, 1, bufferSize, file->file);
|
||||||
zip_int64_t bytesRead = zip_fread(file->zipFile, buffer, bufferSize);
|
if(got < bufferSize && ferror(file->file)) {
|
||||||
if(bytesRead < 0) {
|
|
||||||
errorThrow("Failed to read from asset file: %s", file->filename);
|
errorThrow("Failed to read from asset file: %s", file->filename);
|
||||||
}
|
}
|
||||||
file->position += bytesRead;
|
file->position += got;
|
||||||
file->lastRead = bytesRead;
|
file->lastRead = got;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetFileClose(assetfile_t *file) {
|
errorret_t assetFileClose(assetfile_t *file) {
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
assertNotNull(file->zipFile, "Asset file must be opened before closing.");
|
assertNotNull(file->file, "Asset file must be opened before closing.");
|
||||||
|
|
||||||
if(zip_fclose(file->zipFile) != 0) {
|
int result = fclose(file->file);
|
||||||
|
file->file = NULL;
|
||||||
|
file->position = 0;
|
||||||
|
if(result != 0) {
|
||||||
errorThrow("Failed to close asset file: %s", file->filename);
|
errorThrow("Failed to close asset file: %s", file->filename);
|
||||||
}
|
}
|
||||||
file->zipFile = NULL;
|
|
||||||
file->position = 0;
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetFileDispose(assetfile_t *file) {
|
errorret_t assetFileDispose(assetfile_t *file) {
|
||||||
if(file->zipFile != NULL) {
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
|
if(file->file != NULL) {
|
||||||
errorChain(assetFileClose(file));
|
errorChain(assetFileClose(file));
|
||||||
}
|
}
|
||||||
memoryZero(file, sizeof(assetfile_t));
|
memoryZero(file, sizeof(assetfile_t));
|
||||||
@@ -125,256 +129,30 @@ errorret_t assetFileReadEntire(
|
|||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
assertNotNull(file, "Asset file cannot be NULL.");
|
||||||
assertNotNull(outBuffer, "outBuffer cannot be NULL.");
|
assertNotNull(outBuffer, "outBuffer cannot be NULL.");
|
||||||
assertNotNull(outSize, "outSize cannot be NULL.");
|
assertNotNull(outSize, "outSize cannot be NULL.");
|
||||||
assertTrue(
|
assertNull(file->file, "Asset file must be closed before reading entire.");
|
||||||
file->size > 0,
|
|
||||||
"Asset file has no size; call assetFileInit first."
|
if(file->size == 0) {
|
||||||
|
errorThrow("Asset file is empty: %s", file->filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
errorChain(assetFileOpen(file));
|
||||||
|
|
||||||
|
uint8_t *buffer = (uint8_t *)memoryAllocate(file->size);
|
||||||
|
errorret_t ret = assetFileRead(file, buffer, file->size);
|
||||||
|
if(errorIsOk(ret) && file->lastRead != file->size) {
|
||||||
|
ret = errorThrowImpl(
|
||||||
|
&ERROR_STATE, ERROR_NOT_OK, __FILE__, __func__, __LINE__,
|
||||||
|
"Failed to read entire asset file: %s", file->filename
|
||||||
);
|
);
|
||||||
|
|
||||||
// File should be closed currently.
|
|
||||||
assertNull(file->zipFile, "Asset file must be closed before reading entire.");
|
|
||||||
|
|
||||||
// Open file
|
|
||||||
errorret_t ret = assetFileOpen(file);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set output.
|
|
||||||
size_t size = (size_t)file->size;
|
|
||||||
uint8_t *buffer = (uint8_t *)memoryAllocate(size);
|
|
||||||
|
|
||||||
// Read entire file.
|
|
||||||
ret = assetFileRead(file, buffer, size);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
memoryFree(buffer);
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the file.
|
|
||||||
ret = assetFileClose(file);
|
|
||||||
if(errorIsNotOk(ret)) {
|
if(errorIsNotOk(ret)) {
|
||||||
memoryFree(buffer);
|
memoryFree(buffer);
|
||||||
|
assetFileClose(file);
|
||||||
errorChain(ret);
|
errorChain(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorChain(assetFileClose(file));
|
||||||
*outBuffer = buffer;
|
*outBuffer = buffer;
|
||||||
*outSize = size;
|
*outSize = file->size;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Line Reader;
|
|
||||||
void assetFileLineReaderInit(
|
|
||||||
assetfilelinereader_t *reader,
|
|
||||||
assetfile_t *file,
|
|
||||||
uint8_t *readBuffer,
|
|
||||||
const size_t readBufferSize,
|
|
||||||
uint8_t *outBuffer,
|
|
||||||
const size_t outBufferSize
|
|
||||||
) {
|
|
||||||
assertNotNull(reader, "Line reader cannot be NULL.");
|
|
||||||
assertNotNull(file, " File cannot be NULL.");
|
|
||||||
assertNotNull(readBuffer, "Read buffer cannot be NULL.");
|
|
||||||
assertNotNull(outBuffer, "Output buffer cannot be NULL.");
|
|
||||||
assertTrue(readBufferSize > 0, "Read buffer size must be greater than 0.");
|
|
||||||
assertTrue(outBufferSize > 0, "Output buffer size must be greater than 0.");
|
|
||||||
|
|
||||||
memoryZero(reader, sizeof(assetfilelinereader_t));
|
|
||||||
|
|
||||||
reader->file = file;
|
|
||||||
reader->readBuffer = readBuffer;
|
|
||||||
reader->readBufferSize = readBufferSize;
|
|
||||||
reader->outBuffer = outBuffer;
|
|
||||||
reader->outBufferSize = outBufferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t assetFileLineReaderUnreadBytes(const assetfilelinereader_t *reader) {
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertTrue(reader->bufferEnd >= reader->bufferStart, "Invalid buffer state.");
|
|
||||||
return reader->bufferEnd - reader->bufferStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t *assetFileLineReaderUnreadPtr(
|
|
||||||
const assetfilelinereader_t *reader
|
|
||||||
) {
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->readBuffer, "Read buffer cannot be NULL.");
|
|
||||||
return reader->readBuffer + reader->bufferStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
static errorret_t assetFileLineReaderAppend(
|
|
||||||
assetfilelinereader_t *reader,
|
|
||||||
const uint8_t *src,
|
|
||||||
size_t srcLength
|
|
||||||
) {
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
|
||||||
|
|
||||||
if(srcLength == 0) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reserve room for optional NUL terminator */
|
|
||||||
if(reader->lineLength + srcLength >= reader->outBufferSize) {
|
|
||||||
errorThrow("Line length exceeds output buffer size.");
|
|
||||||
}
|
|
||||||
|
|
||||||
memoryCopy(reader->outBuffer + reader->lineLength, src, srcLength);
|
|
||||||
reader->lineLength += srcLength;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
|
||||||
assertTrue(
|
|
||||||
reader->lineLength < reader->outBufferSize,
|
|
||||||
"Line length exceeds out buffer."
|
|
||||||
);
|
|
||||||
reader->outBuffer[reader->lineLength] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t assetFileLineReaderFindNewline(
|
|
||||||
const assetfilelinereader_t *reader
|
|
||||||
) {
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->readBuffer, "Read buffer cannot be NULL.");
|
|
||||||
|
|
||||||
for(i = reader->bufferStart; i < reader->bufferEnd; ++i) {
|
|
||||||
if(reader->readBuffer[i] == '\n') {
|
|
||||||
return (ssize_t)i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetFileLineReaderFill(assetfilelinereader_t *reader) {
|
|
||||||
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->file, "File cannot be NULL.");
|
|
||||||
assertNotNull(reader->readBuffer, "Read buffer cannot be NULL.");
|
|
||||||
|
|
||||||
if(reader->eof) errorOk();
|
|
||||||
|
|
||||||
errorret_t ret;
|
|
||||||
|
|
||||||
size_t unreadBytes = assetFileLineReaderUnreadBytes(reader);
|
|
||||||
|
|
||||||
/* If buffer is fully consumed, refill from start. */
|
|
||||||
if(unreadBytes == 0) {
|
|
||||||
reader->bufferStart = 0;
|
|
||||||
reader->bufferEnd = 0;
|
|
||||||
|
|
||||||
errorChain(assetFileRead(
|
|
||||||
reader->file,
|
|
||||||
reader->readBuffer,
|
|
||||||
reader->readBufferSize
|
|
||||||
));
|
|
||||||
|
|
||||||
if(reader->file->lastRead == 0) {
|
|
||||||
reader->eof = true;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
reader->bufferStart = 0;
|
|
||||||
reader->bufferEnd = reader->file->lastRead;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* There are unread bytes left but no newline in them.
|
|
||||||
* If bufferStart > 0, slide unread bytes to front so we can read more.
|
|
||||||
* This only happens when necessary to make space.
|
|
||||||
*/
|
|
||||||
if(reader->bufferEnd == reader->readBufferSize) {
|
|
||||||
if(reader->bufferStart == 0) {
|
|
||||||
/*
|
|
||||||
* Entire read buffer is unread and contains no newline.
|
|
||||||
* Caller must have a large enough outBuffer to accumulate across fills,
|
|
||||||
* so we consume these bytes into outBuffer before refilling.
|
|
||||||
*/
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
memoryMove(
|
|
||||||
reader->readBuffer,
|
|
||||||
reader->readBuffer + reader->bufferStart,
|
|
||||||
unreadBytes
|
|
||||||
);
|
|
||||||
reader->bufferStart = 0;
|
|
||||||
reader->bufferEnd = unreadBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileRead(
|
|
||||||
reader->file,
|
|
||||||
reader->readBuffer + reader->bufferEnd,
|
|
||||||
reader->readBufferSize - reader->bufferEnd
|
|
||||||
));
|
|
||||||
|
|
||||||
if(reader->file->lastRead == 0) {
|
|
||||||
reader->eof = true;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
reader->bufferEnd += reader->file->lastRead;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetFileLineReaderNext(assetfilelinereader_t *reader) {
|
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
|
||||||
assertNotNull(reader->file, "File cannot be NULL.");
|
|
||||||
assertNotNull(reader->readBuffer, "Read buffer cannot be NULL.");
|
|
||||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
|
||||||
|
|
||||||
reader->lineLength = 0;
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
ssize_t newlineIndex = assetFileLineReaderFindNewline(reader);
|
|
||||||
|
|
||||||
if(newlineIndex >= 0) {
|
|
||||||
size_t chunkLength = (size_t)newlineIndex - reader->bufferStart;
|
|
||||||
errorret_t ret;
|
|
||||||
|
|
||||||
/* strip CR in CRLF */
|
|
||||||
if(
|
|
||||||
chunkLength > 0 &&
|
|
||||||
reader->readBuffer[(size_t)newlineIndex - 1] == '\r'
|
|
||||||
) {
|
|
||||||
chunkLength--;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileLineReaderAppend(
|
|
||||||
reader,
|
|
||||||
reader->readBuffer + reader->bufferStart,
|
|
||||||
chunkLength
|
|
||||||
));
|
|
||||||
|
|
||||||
reader->bufferStart = (size_t)newlineIndex + 1;
|
|
||||||
assetFileLineReaderTerminate(reader);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(assetFileLineReaderUnreadBytes(reader) > 0) {
|
|
||||||
errorChain(assetFileLineReaderAppend(
|
|
||||||
reader,
|
|
||||||
assetFileLineReaderUnreadPtr(reader),
|
|
||||||
assetFileLineReaderUnreadBytes(reader)
|
|
||||||
));
|
|
||||||
|
|
||||||
reader->bufferStart = reader->bufferEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(reader->eof) {
|
|
||||||
if(reader->lineLength > 0) {
|
|
||||||
assetFileLineReaderTerminate(reader);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorThrow("End of file reached.");
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileLineReaderFill(reader));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+39
-99
@@ -7,67 +7,55 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include <zip.h>
|
|
||||||
|
|
||||||
#define ASSET_FILE_NAME_MAX 48
|
#define ASSET_FILE_NAME_MAX 128
|
||||||
|
|
||||||
typedef struct assetfile_s assetfile_t;
|
// Full on disk path, base directory plus filename.
|
||||||
|
#define ASSET_PATH_MAX 512
|
||||||
|
|
||||||
typedef errorret_t (*assetfileloader_t)(assetfile_t *file);
|
typedef struct {
|
||||||
|
|
||||||
// Describes a file not yet loaded.
|
|
||||||
typedef struct assetfile_s {
|
|
||||||
char_t filename[ASSET_FILE_NAME_MAX];
|
char_t filename[ASSET_FILE_NAME_MAX];
|
||||||
void *params;
|
FILE *file;
|
||||||
void *output;
|
size_t size;
|
||||||
|
size_t position;
|
||||||
zip_stat_t stat;
|
size_t lastRead;
|
||||||
zip_int64_t size;
|
|
||||||
zip_int64_t position;
|
|
||||||
zip_int64_t lastRead;
|
|
||||||
zip_file_t *zipFile;
|
|
||||||
} assetfile_t;
|
} assetfile_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the asset file structure in preparation for loading. This will
|
* Initializes an asset file, checking it exists and reading its size. Does not
|
||||||
* stat the file but not open the handle.
|
* open it.
|
||||||
*
|
*
|
||||||
* @param file The asset file structure to initialize.
|
* @param file The asset file to initialize.
|
||||||
* @param filename The name of the asset file to load.
|
* @param filename Asset filename, relative to the asset directory.
|
||||||
* @param params Optional loader params.
|
* @return An error if the file does not exist or cannot be read.
|
||||||
* @param output Output pointer for the loader.
|
|
||||||
* @return Error indicating success or failure.
|
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileInit(
|
errorret_t assetFileInit(assetfile_t *file, const char_t *filename);
|
||||||
assetfile_t *file,
|
|
||||||
const char_t *filename,
|
|
||||||
void *params,
|
|
||||||
void *output
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the asset file for reading. After opening the loader is responsible
|
* Opens an asset file for reading, positioned at the start.
|
||||||
* for closing the file.
|
|
||||||
*
|
*
|
||||||
* @param file The asset file to open.
|
* @param file The asset file to open. Must not already be open.
|
||||||
* @return An error code if the file could not be opened.
|
* @return An error if the file cannot be opened.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileOpen(assetfile_t *file);
|
errorret_t assetFileOpen(assetfile_t *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewind the file to the initial position.
|
* Moves an open asset file back to its start.
|
||||||
*
|
*
|
||||||
* @param file The asset file to rewind.
|
* @param file The asset file to rewind. Must be open.
|
||||||
|
* @return An error if the file cannot be rewound.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileRewind(assetfile_t *file);
|
errorret_t assetFileRewind(assetfile_t *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read bytes from the asset file. Assumes the file has already been opened
|
* Reads bytes from an open asset file. The number of bytes actually read is
|
||||||
* prior to trying to read anything.
|
* stored in file->lastRead, which is less than bufferSize at the end of the
|
||||||
|
* file.
|
||||||
*
|
*
|
||||||
* @param file File to read from.
|
* @param file The asset file to read from. Must be open.
|
||||||
* @param buffer Buffer to read the file data into., or NULL to skip bytes.
|
* @param buffer Buffer to read into. If NULL the bytes are skipped.
|
||||||
* @param size Size of the buffer to read into.
|
* @param bufferSize Number of bytes to read.
|
||||||
|
* @return An error if reading fails.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileRead(
|
errorret_t assetFileRead(
|
||||||
assetfile_t *file,
|
assetfile_t *file,
|
||||||
@@ -76,81 +64,33 @@ errorret_t assetFileRead(
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the asset file and releases any resources associated with it.
|
* Closes an open asset file.
|
||||||
*
|
*
|
||||||
* @param file The asset file to close.
|
* @param file The asset file to close. Must be open.
|
||||||
* @return An error code if the file could not be closed properly.
|
* @return An error if the file cannot be closed.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileClose(assetfile_t *file);
|
errorret_t assetFileClose(assetfile_t *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes the asset file structure, closing any open handles and zeroing
|
* Disposes an asset file, closing it first if it is still open.
|
||||||
* out the structure.
|
|
||||||
*
|
*
|
||||||
* @param file The asset file to dispose.
|
* @param file The asset file to dispose.
|
||||||
* @return An error code if the file could not be disposed properly.
|
* @return An error if the file cannot be closed.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileDispose(assetfile_t *file);
|
errorret_t assetFileDispose(assetfile_t *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the entire contents of the asset file into a newly allocated buffer.
|
* Reads a whole asset file into a newly allocated buffer. The file is opened
|
||||||
* The caller is responsible for freeing the buffer with memoryFree.
|
* and closed by this call, and must not already be open.
|
||||||
*
|
*
|
||||||
* @param file The asset file to read. Must be initialized but not open.
|
* @param file The asset file to read, already initialized.
|
||||||
* @param outBuffer Receives a pointer to the allocated buffer.
|
* @param outBuffer Output buffer, allocated with memoryAllocate. The caller
|
||||||
* @param outSize Receives the number of bytes written to the buffer.
|
* must memoryFree it.
|
||||||
* @return An error code if the file could not be read.
|
* @param outSize Output size of the buffer in bytes.
|
||||||
|
* @return An error if the file cannot be read in full.
|
||||||
*/
|
*/
|
||||||
errorret_t assetFileReadEntire(
|
errorret_t assetFileReadEntire(
|
||||||
assetfile_t *file,
|
assetfile_t *file,
|
||||||
uint8_t **outBuffer,
|
uint8_t **outBuffer,
|
||||||
size_t *outSize
|
size_t *outSize
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetfile_t *file;
|
|
||||||
uint8_t *readBuffer;
|
|
||||||
size_t readBufferSize;
|
|
||||||
uint8_t *outBuffer;
|
|
||||||
size_t outBufferSize;
|
|
||||||
|
|
||||||
// A
|
|
||||||
size_t bufferStart;
|
|
||||||
size_t bufferEnd;
|
|
||||||
bool_t eof;//?
|
|
||||||
|
|
||||||
// Updated each reach:
|
|
||||||
size_t lineLength;
|
|
||||||
} assetfilelinereader_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a line reader for the given asset file. The line reader will read
|
|
||||||
* lines from the file into the provided line buffer, using the provided buffer
|
|
||||||
* for reading chunks of the file.
|
|
||||||
*
|
|
||||||
* @param file The asset file to read from. Must already be opened.
|
|
||||||
* @param readBuffer Buffer to use for reading chunks of the file.
|
|
||||||
* @param readBufferSize Size of the read buffer.
|
|
||||||
* @param outBuffer Buffer to read lines into. Lines will be null-terminated.
|
|
||||||
* @param outBufferSize Size of the output buffer.
|
|
||||||
* @return An initialized line reader structure.
|
|
||||||
*/
|
|
||||||
void assetFileLineReaderInit(
|
|
||||||
assetfilelinereader_t *reader,
|
|
||||||
assetfile_t *file,
|
|
||||||
uint8_t *readBuffer,
|
|
||||||
const size_t readBufferSize,
|
|
||||||
uint8_t *outBuffer,
|
|
||||||
const size_t outBufferSize
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the next line from the asset file into the line buffer. The line
|
|
||||||
* buffer is null-terminated and does not include the newline character.
|
|
||||||
*
|
|
||||||
* @param reader The line reader to read from.
|
|
||||||
* @return An error code if a failure occurs, or errorOk() if a line was read
|
|
||||||
* successfully. If the end of the file is reached, errorEndOfFile() is
|
|
||||||
* returned.
|
|
||||||
*/
|
|
||||||
errorret_t assetFileLineReaderNext(assetfilelinereader_t *reader);
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
# Sources
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
assetentry.c
|
|
||||||
assetloader.c
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
add_subdirectory(display)
|
|
||||||
add_subdirectory(locale)
|
|
||||||
add_subdirectory(json)
|
|
||||||
add_subdirectory(chunk)
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetentry.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/string.h"
|
|
||||||
|
|
||||||
void assetEntryInit(
|
|
||||||
assetentry_t *entry,
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertStrLenMin(name, 1, "Name cannot be empty");
|
|
||||||
assertStrLenMax(name, ASSET_FILE_NAME_MAX - 1, "Name too long");
|
|
||||||
assertTrue(type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
assertTrue(type < ASSET_LOADER_TYPE_COUNT, "Invalid loader type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
memoryZero(entry, sizeof(assetentry_t));
|
|
||||||
stringCopy(entry->name, name, ASSET_FILE_NAME_MAX);
|
|
||||||
entry->type = type;
|
|
||||||
entry->state = ASSET_ENTRY_STATE_NOT_STARTED;
|
|
||||||
if(input) {
|
|
||||||
entry->inputData = *input;
|
|
||||||
entry->input = &entry->inputData;
|
|
||||||
} else {
|
|
||||||
memoryZero(&entry->inputData, sizeof(assetloaderinput_t));
|
|
||||||
entry->input = NULL;
|
|
||||||
}
|
|
||||||
refInit(&entry->refs, entry, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
eventInit(
|
|
||||||
&entry->onLoaded,
|
|
||||||
entry->onLoadedCallbacks, entry->onLoadedUsers,
|
|
||||||
ASSET_ENTRY_EVENT_MAX
|
|
||||||
);
|
|
||||||
eventInit(
|
|
||||||
&entry->onUnloaded,
|
|
||||||
entry->onUnloadedCallbacks, entry->onUnloadedUsers,
|
|
||||||
ASSET_ENTRY_EVENT_MAX
|
|
||||||
);
|
|
||||||
eventInit(
|
|
||||||
&entry->onError,
|
|
||||||
entry->onErrorCallbacks, entry->onErrorUsers,
|
|
||||||
ASSET_ENTRY_EVENT_MAX
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetEntryLock(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
|
|
||||||
refLock(&entry->refs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetEntryUnlock(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
|
|
||||||
refUnlock(&entry->refs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetEntryStartLoading(
|
|
||||||
assetentry_t *entry,
|
|
||||||
assetloading_t *loading
|
|
||||||
) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
assertTrue(
|
|
||||||
entry->state == ASSET_ENTRY_STATE_NOT_STARTED,
|
|
||||||
"Can only start loading from NOT_STARTED state."
|
|
||||||
);
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
memoryZero(&loading->loading, sizeof(assetloaderloading_t));
|
|
||||||
loading->type = entry->type;
|
|
||||||
loading->entry = entry;
|
|
||||||
// At this point the asset manager will manage this thing's loading
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetEntryDispose(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
|
|
||||||
assertTrue(entry->type < ASSET_LOADER_TYPE_COUNT, "Invalid loader type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
assertTrue(
|
|
||||||
entry->refs.count == 0,
|
|
||||||
"Asset entry still refed at dispose time."
|
|
||||||
);
|
|
||||||
|
|
||||||
eventInvoke(&entry->onUnloaded, entry);
|
|
||||||
errorChain(ASSET_LOADER_CALLBACKS[entry->type].dispose(entry));
|
|
||||||
memoryZero(entry, sizeof(assetentry_t));
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "event/event.h"
|
|
||||||
#include "util/ref.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_ENTRY_STATE_NOT_STARTED,
|
|
||||||
ASSET_ENTRY_STATE_PENDING_ASYNC,
|
|
||||||
ASSET_ENTRY_STATE_LOADING_ASYNC,
|
|
||||||
ASSET_ENTRY_STATE_PENDING_SYNC,
|
|
||||||
ASSET_ENTRY_STATE_LOADING_SYNC,
|
|
||||||
ASSET_ENTRY_STATE_LOADED,
|
|
||||||
ASSET_ENTRY_STATE_ERROR
|
|
||||||
} assetentrystate_t;
|
|
||||||
|
|
||||||
/** Maximum number of subscribers for each per-entry event. */
|
|
||||||
#define ASSET_ENTRY_EVENT_MAX 2
|
|
||||||
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
struct assetentry_s {
|
|
||||||
char_t name[ASSET_FILE_NAME_MAX];
|
|
||||||
assetloadertype_t type;
|
|
||||||
assetloaderoutput_t data;
|
|
||||||
assetentrystate_t state;
|
|
||||||
ref_t refs;
|
|
||||||
assetloaderinput_t *input;
|
|
||||||
assetloaderinput_t inputData;
|
|
||||||
/**
|
|
||||||
* Fired once when loading completes successfully (params = assetentry_t *).
|
|
||||||
* Always invoked on the main thread.
|
|
||||||
*/
|
|
||||||
event_t onLoaded;
|
|
||||||
eventcallback_t onLoadedCallbacks[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
void *onLoadedUsers[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired once when the entry is disposed/reaped (params = assetentry_t *).
|
|
||||||
* The asset data is still accessible when the callback runs.
|
|
||||||
* Always invoked on the main thread.
|
|
||||||
*/
|
|
||||||
event_t onUnloaded;
|
|
||||||
eventcallback_t onUnloadedCallbacks[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
void *onUnloadedUsers[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired once when loading fails (params = assetentry_t *).
|
|
||||||
* Always invoked on the main thread.
|
|
||||||
*/
|
|
||||||
event_t onError;
|
|
||||||
eventcallback_t onErrorCallbacks[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
void *onErrorUsers[ASSET_ENTRY_EVENT_MAX];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes an asset entry with the given name and type. This does not load
|
|
||||||
* the asset.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to initialize.
|
|
||||||
* @param name The name of the asset, used as a key for loading and caching.
|
|
||||||
* @param type The type of asset this entry represents.
|
|
||||||
* @param input Data that will be passed to the loader about how it should load.
|
|
||||||
*/
|
|
||||||
void assetEntryInit(
|
|
||||||
assetentry_t *entry,
|
|
||||||
const char_t *name,
|
|
||||||
const assetloadertype_t type,
|
|
||||||
assetloaderinput_t *input
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Locks an asset entry, preventing it from being freed until it is unlocked.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to lock.
|
|
||||||
*/
|
|
||||||
void assetEntryLock(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlocks an asset entry, allowing it to be freed if there are no more locks.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to unlock.
|
|
||||||
*/
|
|
||||||
void assetEntryUnlock(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts loading the given asset entry using an assetloading slot. This will
|
|
||||||
* be called by the asset manager when it deems it's a good time to begin the
|
|
||||||
* loading of this asset entry.
|
|
||||||
*
|
|
||||||
* Currently we return the error but in future this will not be returned.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to start loading.
|
|
||||||
* @param loading The assetloading slot to use for loading this asset entry.
|
|
||||||
* @return Any error that occurs during loading.
|
|
||||||
*/
|
|
||||||
void assetEntryStartLoading(assetentry_t *entry, assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disposes an asset entry, freeing any resources it holds.
|
|
||||||
* Fires the onUnloaded event before releasing asset data.
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to dispose.
|
|
||||||
* @return Any error that occurs during disposal.
|
|
||||||
*/
|
|
||||||
errorret_t assetEntryDispose(assetentry_t *entry);
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetloader.h"
|
|
||||||
|
|
||||||
assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
|
||||||
[ASSET_LOADER_TYPE_NULL] = { 0 },
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_MESH] = {
|
|
||||||
.loadSync = assetMeshLoaderSync,
|
|
||||||
.loadAsync = assetMeshLoaderAsync,
|
|
||||||
.dispose = assetMeshDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_TEXTURE] = {
|
|
||||||
.loadSync = assetTextureLoaderSync,
|
|
||||||
.loadAsync = assetTextureLoaderAsync,
|
|
||||||
.dispose = assetTextureDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_TILESET] = {
|
|
||||||
.loadSync = assetTilesetLoaderSync,
|
|
||||||
.loadAsync = assetTilesetLoaderAsync,
|
|
||||||
.dispose = assetTilesetDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_LOCALE] = {
|
|
||||||
.loadSync = assetLocaleLoaderSync,
|
|
||||||
.loadAsync = assetLocaleLoaderAsync,
|
|
||||||
.dispose = assetLocaleDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_JSON] = {
|
|
||||||
.loadSync = assetJsonLoaderSync,
|
|
||||||
.loadAsync = assetJsonLoaderAsync,
|
|
||||||
.dispose = assetJsonDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_CHUNK] = {
|
|
||||||
.loadSync = assetChunkLoaderSync,
|
|
||||||
.loadAsync = assetChunkLoaderAsync,
|
|
||||||
.dispose = assetChunkDispose
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "asset/loader/display/assetmeshloader.h"
|
|
||||||
#include "asset/loader/display/assettextureloader.h"
|
|
||||||
#include "asset/loader/display/assettilesetloader.h"
|
|
||||||
#include "asset/loader/locale/assetlocaleloader.h"
|
|
||||||
#include "asset/loader/json/assetjsonloader.h"
|
|
||||||
#include "asset/loader/chunk/assetchunkloader.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_LOADER_TYPE_NULL,
|
|
||||||
|
|
||||||
ASSET_LOADER_TYPE_MESH,
|
|
||||||
ASSET_LOADER_TYPE_TEXTURE,
|
|
||||||
ASSET_LOADER_TYPE_TILESET,
|
|
||||||
ASSET_LOADER_TYPE_LOCALE,
|
|
||||||
ASSET_LOADER_TYPE_JSON,
|
|
||||||
ASSET_LOADER_TYPE_CHUNK,
|
|
||||||
|
|
||||||
ASSET_LOADER_TYPE_COUNT
|
|
||||||
} assetloadertype_t;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
assetmeshloaderinput_t mesh;
|
|
||||||
assettextureloaderinput_t texture;
|
|
||||||
assettilesetloaderinput_t tileset;
|
|
||||||
assetlocaleloaderinput_t locale;
|
|
||||||
assetjsonloaderinput_t json;
|
|
||||||
assetchunkloaderinput_t chunk;
|
|
||||||
} assetloaderinput_t;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
assetmeshloaderloading_t mesh;
|
|
||||||
assettextureloaderloading_t texture;
|
|
||||||
assettilesetloaderloading_t tileset;
|
|
||||||
assetlocaleloaderloading_t locale;
|
|
||||||
assetjsonloaderloading_t json;
|
|
||||||
assetchunkloaderloading_t chunk;
|
|
||||||
} assetloaderloading_t;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
assetmeshoutput_t mesh;
|
|
||||||
assettextureoutput_t texture;
|
|
||||||
assettilesetoutput_t tileset;
|
|
||||||
assetlocaleoutput_t locale;
|
|
||||||
assetjsonoutput_t json;
|
|
||||||
assetchunkoutput_t chunk;
|
|
||||||
} assetloaderoutput_t;
|
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef errorret_t (assetloadersynccallback_t)(assetloading_t *loading);
|
|
||||||
typedef errorret_t (assetloaderasynccallback_t)(assetloading_t *loading);
|
|
||||||
typedef errorret_t (assetloaderdisposecallback_t)(assetentry_t *entry);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetloadersynccallback_t *loadSync;
|
|
||||||
assetloaderasynccallback_t *loadAsync;
|
|
||||||
assetloaderdisposecallback_t *dispose;
|
|
||||||
} assetloadercallbacks_t;
|
|
||||||
|
|
||||||
extern assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to both chain an error (against the loader state) and to
|
|
||||||
* set the asset entry state to error.
|
|
||||||
*
|
|
||||||
* @param loading The asset loading slot.
|
|
||||||
* @param ret The error return value to check and chain if it's an error.
|
|
||||||
*/
|
|
||||||
#define assetLoaderErrorChain(loading, _expr) {\
|
|
||||||
errorret_t _alec = (_expr); \
|
|
||||||
if(errorIsNotOk(_alec)) { \
|
|
||||||
(loading)->entry->state = ASSET_ENTRY_STATE_ERROR; \
|
|
||||||
errorChain(_alec); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to both throw an error (against the loader state) and to
|
|
||||||
* set the asset entry state to error.
|
|
||||||
*
|
|
||||||
* @param loading The asset loading slot.
|
|
||||||
* @param ... Format string and arguments for the error message.
|
|
||||||
*/
|
|
||||||
#define assetLoaderErrorThrow(loading, ...) {\
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_ERROR; \
|
|
||||||
errorThrow(__VA_ARGS__); \
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "assetloader.h"
|
|
||||||
#include "asset/assetfile.h"
|
|
||||||
#include "thread/threadmutex.h"
|
|
||||||
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef struct assetloading_s {
|
|
||||||
threadmutex_t mutex;
|
|
||||||
assetloadertype_t type;
|
|
||||||
assetentry_t *entry;
|
|
||||||
assetloaderloading_t loading;
|
|
||||||
} assetloading_t;
|
|
||||||
|
|
||||||
typedef errorret_t (assetloadingcallback_t)(assetloading_t *loading);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetloadingcallback_t *loadSync;
|
|
||||||
} assetloadingcallbacks_t;
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetchunkloader.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/endian.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
|
|
||||||
errorret_t assetChunkLoaderAsync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertNotMainThread("Should be called from an async thread.");
|
|
||||||
|
|
||||||
if(loading->loading.chunk.state != ASSET_CHUNK_LOADING_STATE_READ_FILE) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNull(loading->loading.chunk.data, "Data already defined?");
|
|
||||||
|
|
||||||
assetfile_t *file = &loading->loading.chunk.file;
|
|
||||||
assetLoaderErrorChain(loading,
|
|
||||||
assetFileInit(file, loading->entry->name, NULL, NULL)
|
|
||||||
);
|
|
||||||
|
|
||||||
uint8_t *data = memoryAllocate(file->size);
|
|
||||||
assetLoaderErrorChain(loading, assetFileOpen(file));
|
|
||||||
assetLoaderErrorChain(loading, assetFileRead(file, data, file->size));
|
|
||||||
assetLoaderErrorChain(loading, assetFileClose(file));
|
|
||||||
assetLoaderErrorChain(loading, assetFileDispose(file));
|
|
||||||
assertTrue(
|
|
||||||
file->lastRead == file->size,
|
|
||||||
"Failed to read entire chunk file."
|
|
||||||
);
|
|
||||||
|
|
||||||
loading->loading.chunk.data = data;
|
|
||||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_PARSE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetChunkLoaderSync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertTrue(loading->type == ASSET_LOADER_TYPE_CHUNK, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
switch(loading->loading.chunk.state) {
|
|
||||||
case ASSET_CHUNK_LOADING_STATE_INITIAL:
|
|
||||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_READ_FILE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
|
||||||
errorOk();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_CHUNK_LOADING_STATE_PARSE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *data = loading->loading.chunk.data;
|
|
||||||
assertNotNull(data, "Chunk data should have been loaded by now.");
|
|
||||||
|
|
||||||
if(data[0] != 'D' || data[1] != 'C' || data[2] != 'F') {
|
|
||||||
memoryFree(data);
|
|
||||||
assetLoaderErrorThrow(loading, "Invalid chunk file header");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t version = endianLittleToHost32(*(uint32_t *)(data + 4));
|
|
||||||
if(version != ASSET_CHUNK_FILE_VERSION) {
|
|
||||||
memoryFree(data);
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Unsupported chunk file version %u", version
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
assetchunkoutput_t *out = &loading->entry->data.chunk;
|
|
||||||
size_t offset = 8;
|
|
||||||
|
|
||||||
size_t tileSize = CHUNK_TILE_COUNT * sizeof(tile_t);
|
|
||||||
memoryCopy(out->tiles, data + offset, tileSize);
|
|
||||||
offset += tileSize;
|
|
||||||
|
|
||||||
out->vertCount = endianLittleToHost32(*(uint32_t *)(data + offset));
|
|
||||||
offset += sizeof(uint32_t);
|
|
||||||
|
|
||||||
assertTrue(
|
|
||||||
out->vertCount <= CHUNK_VERTEX_COUNT,
|
|
||||||
"Chunk vertex count exceeds maximum."
|
|
||||||
);
|
|
||||||
|
|
||||||
memoryCopy(
|
|
||||||
out->vertices,
|
|
||||||
data + offset,
|
|
||||||
out->vertCount * sizeof(meshvertex_t)
|
|
||||||
);
|
|
||||||
|
|
||||||
memoryFree(data);
|
|
||||||
loading->loading.chunk.data = NULL;
|
|
||||||
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetChunkDispose(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertTrue(entry->type == ASSET_LOADER_TYPE_CHUNK, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "asset/assetfile.h"
|
|
||||||
#include "rpg/overworld/chunk.h"
|
|
||||||
|
|
||||||
#define ASSET_CHUNK_FILE_VERSION 1
|
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
void *nothing;
|
|
||||||
} assetchunkloaderinput_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_CHUNK_LOADING_STATE_INITIAL,
|
|
||||||
ASSET_CHUNK_LOADING_STATE_READ_FILE,
|
|
||||||
ASSET_CHUNK_LOADING_STATE_PARSE,
|
|
||||||
ASSET_CHUNK_LOADING_STATE_DONE
|
|
||||||
} assetchunkloadingstate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetfile_t file;
|
|
||||||
assetchunkloadingstate_t state;
|
|
||||||
uint8_t *data;
|
|
||||||
} assetchunkloaderloading_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
tile_t tiles[CHUNK_TILE_COUNT];
|
|
||||||
uint32_t vertCount;
|
|
||||||
meshvertex_t vertices[CHUNK_VERTEX_COUNT];
|
|
||||||
} assetchunkoutput_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asynchronous loader for chunk assets. Reads the raw DCF file bytes into
|
|
||||||
* the loading buffer so the sync phase can parse without blocking the
|
|
||||||
* main thread on I/O.
|
|
||||||
*
|
|
||||||
* @param loading Loading information for the asset being loaded.
|
|
||||||
* @return Error code indicating success or failure of the load operation.
|
|
||||||
*/
|
|
||||||
errorret_t assetChunkLoaderAsync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronous loader for chunk assets. Validates the DCF binary previously
|
|
||||||
* read by the async phase and populates the output assetchunkoutput_t.
|
|
||||||
*
|
|
||||||
* @param loading Loading information for the asset being loaded.
|
|
||||||
* @return Error code indicating success or failure of the load operation.
|
|
||||||
*/
|
|
||||||
errorret_t assetChunkLoaderSync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disposer for chunk assets.
|
|
||||||
*
|
|
||||||
* @param entry Asset entry containing the chunk data to dispose.
|
|
||||||
* @return Error code indicating success or failure of the dispose operation.
|
|
||||||
*/
|
|
||||||
errorret_t assetChunkDispose(assetentry_t *entry);
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
# Sources
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
assetmeshloader.c
|
|
||||||
assettextureloader.c
|
|
||||||
assettilesetloader.c
|
|
||||||
)
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetmeshloader.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/endian.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
|
|
||||||
errorret_t assetMeshLoaderAsync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
|
|
||||||
if(loading->loading.mesh.state != ASSET_MESH_LOADING_STATE_READ_FILE) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetmeshoutput_t *out = &loading->entry->data.mesh;
|
|
||||||
assetfile_t *file = &loading->loading.mesh.file;
|
|
||||||
assetmeshinputaxis_t axis = loading->entry->inputData.mesh;
|
|
||||||
|
|
||||||
assetLoaderErrorChain(loading,
|
|
||||||
assetFileInit(file, loading->entry->name, NULL, NULL)
|
|
||||||
);
|
|
||||||
assetLoaderErrorChain(loading, assetFileOpen(file));
|
|
||||||
|
|
||||||
// Skip the 80-byte STL header.
|
|
||||||
assetLoaderErrorChain(loading, assetFileRead(file, NULL, 80));
|
|
||||||
if(file->lastRead != 80) {
|
|
||||||
assetLoaderErrorThrow(loading, "Failed to skip STL header.");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t triangleCount;
|
|
||||||
assetLoaderErrorChain(loading,
|
|
||||||
assetFileRead(file, &triangleCount, sizeof(uint32_t))
|
|
||||||
);
|
|
||||||
if(file->lastRead != sizeof(uint32_t)) {
|
|
||||||
assetLoaderErrorThrow(loading, "Failed to read tri count");
|
|
||||||
}
|
|
||||||
triangleCount = endianLittleToHost32(triangleCount);
|
|
||||||
|
|
||||||
out->vertices = memoryAllocate(sizeof(meshvertex_t) * triangleCount * 3);
|
|
||||||
meshvertex_t *verts = out->vertices;
|
|
||||||
|
|
||||||
errorret_t ret;
|
|
||||||
for(uint32_t i = 0; i < triangleCount; i++) {
|
|
||||||
assetmeshstltriangle_t triData;
|
|
||||||
ret = assetFileRead(file, &triData, sizeof(triData));
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
memoryFree(verts);
|
|
||||||
out->vertices = NULL;
|
|
||||||
assetLoaderErrorChain(loading, ret);
|
|
||||||
}
|
|
||||||
if(file->lastRead != sizeof(triData)) {
|
|
||||||
memoryFree(verts);
|
|
||||||
out->vertices = NULL;
|
|
||||||
assetLoaderErrorThrow(loading, "Failed to read triangle data");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(uint8_t j = 0; j < 3; j++) {
|
|
||||||
#if MESH_ENABLE_COLOR
|
|
||||||
verts[i * 3 + j].color.r = (
|
|
||||||
(uint8_t)(endianLittleToHostFloat(triData.normal[0]) * 255.0f)
|
|
||||||
);
|
|
||||||
verts[i * 3 + j].color.g = (
|
|
||||||
(uint8_t)(endianLittleToHostFloat(triData.normal[1]) * 255.0f)
|
|
||||||
);
|
|
||||||
verts[i * 3 + j].color.b = (
|
|
||||||
(uint8_t)(endianLittleToHostFloat(triData.normal[2]) * 255.0f)
|
|
||||||
);
|
|
||||||
verts[i * 3 + j].color.a = 0xFF;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
verts[i * 3 + j].uv[0] = 0.0f;
|
|
||||||
verts[i * 3 + j].uv[1] = 0.0f;
|
|
||||||
|
|
||||||
for(uint8_t k = 0; k < 3; k++) {
|
|
||||||
verts[i * 3 + j].pos[k] = endianLittleToHostFloat(
|
|
||||||
triData.positions[j][k]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(axis) {
|
|
||||||
case MESH_INPUT_AXIS_Z_UP: {
|
|
||||||
float_t temp = verts[i * 3 + j].pos[1];
|
|
||||||
verts[i * 3 + j].pos[1] = verts[i * 3 + j].pos[2];
|
|
||||||
verts[i * 3 + j].pos[2] = temp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESH_INPUT_AXIS_X_UP: {
|
|
||||||
float_t temp = verts[i * 3 + j].pos[0];
|
|
||||||
verts[i * 3 + j].pos[0] = verts[i * 3 + j].pos[1];
|
|
||||||
verts[i * 3 + j].pos[1] = temp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESH_INPUT_AXIS_Y_DOWN:
|
|
||||||
verts[i * 3 + j].pos[1] = -verts[i * 3 + j].pos[1];
|
|
||||||
break;
|
|
||||||
case MESH_INPUT_AXIS_Z_DOWN: {
|
|
||||||
float_t temp = verts[i * 3 + j].pos[1];
|
|
||||||
verts[i * 3 + j].pos[1] = -verts[i * 3 + j].pos[2];
|
|
||||||
verts[i * 3 + j].pos[2] = temp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESH_INPUT_AXIS_X_DOWN: {
|
|
||||||
float_t temp = verts[i * 3 + j].pos[0];
|
|
||||||
verts[i * 3 + j].pos[0] = verts[i * 3 + j].pos[1];
|
|
||||||
verts[i * 3 + j].pos[1] = -temp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESH_INPUT_AXIS_Y_UP:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = assetFileClose(file);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
memoryFree(verts);
|
|
||||||
out->vertices = NULL;
|
|
||||||
assetLoaderErrorChain(loading, ret);
|
|
||||||
}
|
|
||||||
assetFileDispose(file);
|
|
||||||
|
|
||||||
loading->loading.mesh.triangleCount = triangleCount;
|
|
||||||
loading->loading.mesh.state = ASSET_MESH_LOADING_STATE_CREATE_MESH;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetMeshLoaderSync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertTrue(loading->type == ASSET_LOADER_TYPE_MESH, "Invalid type.");
|
|
||||||
|
|
||||||
switch(loading->loading.mesh.state) {
|
|
||||||
case ASSET_MESH_LOADING_STATE_INITIAL:
|
|
||||||
loading->loading.mesh.state = ASSET_MESH_LOADING_STATE_READ_FILE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
|
||||||
errorOk();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_MESH_LOADING_STATE_CREATE_MESH:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetmeshoutput_t *out = &loading->entry->data.mesh;
|
|
||||||
assertNotNull(out->vertices, "Mesh vertices should have been loaded by now.");
|
|
||||||
|
|
||||||
errorret_t ret = meshInit(
|
|
||||||
&out->mesh,
|
|
||||||
MESH_PRIMITIVE_TYPE_TRIANGLES,
|
|
||||||
loading->loading.mesh.triangleCount * 3,
|
|
||||||
out->vertices
|
|
||||||
);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_ERROR;
|
|
||||||
memoryFree(out->vertices);
|
|
||||||
out->vertices = NULL;
|
|
||||||
assetLoaderErrorChain(loading, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetMeshDispose(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Asset entry cannot be NULL");
|
|
||||||
assertTrue(entry->type == ASSET_LOADER_TYPE_MESH, "Invalid type.");
|
|
||||||
errorChain(meshDispose(&entry->data.mesh.mesh));
|
|
||||||
memoryFree(entry->data.mesh.vertices);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "asset/assetfile.h"
|
|
||||||
#include "display/mesh/mesh.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
MESH_INPUT_AXIS_Y_UP,
|
|
||||||
MESH_INPUT_AXIS_Z_UP,
|
|
||||||
MESH_INPUT_AXIS_X_UP,
|
|
||||||
|
|
||||||
MESH_INPUT_AXIS_Y_DOWN,
|
|
||||||
MESH_INPUT_AXIS_Z_DOWN,
|
|
||||||
MESH_INPUT_AXIS_X_DOWN,
|
|
||||||
} assetmeshinputaxis_t;
|
|
||||||
|
|
||||||
typedef assetmeshinputaxis_t assetmeshloaderinput_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_MESH_LOADING_STATE_INITIAL,
|
|
||||||
ASSET_MESH_LOADING_STATE_READ_FILE,
|
|
||||||
ASSET_MESH_LOADING_STATE_CREATE_MESH,
|
|
||||||
ASSET_MESH_LOADING_STATE_DONE
|
|
||||||
} assetmeshloadingstate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetfile_t file;
|
|
||||||
assetmeshloadingstate_t state;
|
|
||||||
uint32_t triangleCount;
|
|
||||||
} assetmeshloaderloading_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
mesh_t mesh;
|
|
||||||
meshvertex_t *vertices;
|
|
||||||
} assetmeshoutput_t;
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
vec3 normal;
|
|
||||||
float_t positions[3][3];
|
|
||||||
uint16_t attributeByteCount;
|
|
||||||
} assetmeshstltriangle_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
assertStructSize(assetmeshstltriangle_t, 50);
|
|
||||||
|
|
||||||
errorret_t assetMeshLoaderAsync(assetloading_t *loading);
|
|
||||||
errorret_t assetMeshLoaderSync(assetloading_t *loading);
|
|
||||||
errorret_t assetMeshDispose(assetentry_t *entry);
|
|
||||||
Loaded 100 of 650 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user