Compare commits
45
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06bc4fcd55 | ||
|
|
42cb84b610 | ||
|
|
f8607d114c | ||
|
|
56230dd340 | ||
|
|
df9fdf26c8 | ||
|
|
8f8fa8f8d1 | ||
|
|
07f98c119a | ||
|
|
d49194fc4d | ||
|
|
e61914bad4 | ||
|
|
015d90519f | ||
|
|
7b4f0abfb8 | ||
|
|
0667a44e14 | ||
|
|
0852b8463b | ||
|
|
1436fda858 | ||
|
|
0826908068 | ||
|
|
7ceb9e571d | ||
|
|
38c2f6b6f9 | ||
|
|
b9f06fef7a | ||
|
|
373f1c1010 | ||
|
|
e80d693d85 | ||
|
|
ef60ddf6a8 | ||
|
|
de0ff2e263 | ||
|
|
13a435e9c1 | ||
|
|
725338cd5a | ||
|
|
acd14f46a8 | ||
|
|
ef78f023ed | ||
|
|
85b6109792 | ||
|
|
6c5738c863 | ||
|
|
1174e471f6 | ||
|
|
a618ff46fe | ||
|
|
1fa5cd316e | ||
|
|
11e5d37563 | ||
|
|
9f86c20129 | ||
|
|
8fb1c9fb42 | ||
|
|
5f08337726 | ||
|
|
0bc80d5df3 | ||
|
|
2432443ea6 | ||
|
|
fa138971e7 | ||
|
|
d7982599d1 | ||
|
|
f16c80aa0f | ||
|
|
ef5adf8274 | ||
|
|
2ffc65b1b1 | ||
|
|
d4a17bd98d | ||
|
|
dcf5f434c5 | ||
|
|
78cd973a33 |
No files matched your search
@@ -33,3 +33,74 @@ jobs:
|
|||||||
libssl-dev
|
libssl-dev
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: ./scripts/test-linux.sh
|
run: ./scripts/test-linux.sh
|
||||||
|
|
||||||
|
# Emulator smoke tests: boot the built disc/EBOOT for a fixed window and
|
||||||
|
# confirm the emulator doesn't crash. Not yet verified against a real
|
||||||
|
# runner (no CI run has exercised these) -- continue-on-error so a
|
||||||
|
# flaky/broken emulator step doesn't block the required Linux test job.
|
||||||
|
run-tests-gamecube-dolphin:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
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 \
|
||||||
|
dolphin-emu xvfb
|
||||||
|
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 and boot it in Dolphin
|
||||||
|
run: ./scripts/test-gamecube-dolphin.sh
|
||||||
|
|
||||||
|
run-tests-wii-dolphin:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
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 \
|
||||||
|
dolphin-emu xvfb
|
||||||
|
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 and boot it in Dolphin
|
||||||
|
run: ./scripts/test-wii-dolphin.sh
|
||||||
|
|
||||||
|
run-tests-psp-ppsspp:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup pspdev
|
||||||
|
uses: ./.github/actions/setup-pspdev
|
||||||
|
- name: Install PPSSPPHeadless build dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git cmake ninja-build libsdl2-dev zlib1g-dev
|
||||||
|
- name: Build PPSSPPHeadless
|
||||||
|
run: |
|
||||||
|
git clone --recursive --depth 1 https://github.com/hrydgard/ppsspp.git /tmp/ppsspp
|
||||||
|
cmake -S /tmp/ppsspp -B /tmp/ppsspp/build -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build /tmp/ppsspp/build --target PPSSPPHeadless -- -j$(nproc)
|
||||||
|
echo "PPSSPP_HEADLESS_BIN=/tmp/ppsspp/build/PPSSPPHeadless" >> "$GITHUB_ENV"
|
||||||
|
- name: Build PSP EBOOT and boot it in PPSSPPHeadless
|
||||||
|
run: ./scripts/test-psp-ppsspp.sh
|
||||||
+1
-2
@@ -106,5 +106,4 @@ yarn.lock
|
|||||||
/build*
|
/build*
|
||||||
/assets/test
|
/assets/test
|
||||||
/tools_old
|
/tools_old
|
||||||
/assets/test.png
|
/assets/test.png
|
||||||
/assets/audio/boa.mp3
|
|
||||||
+15
-40
@@ -8,22 +8,16 @@ 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
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||||
${CMAKE_MODULE_PATH}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
|
|
||||||
)
|
|
||||||
cmake_policy(SET CMP0079 NEW)
|
cmake_policy(SET CMP0079 NEW)
|
||||||
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
||||||
|
|
||||||
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
||||||
option(DUSK_NETWORK "Enable network support" ON)
|
|
||||||
|
|
||||||
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
||||||
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder")
|
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_SHORT_DESCRIPTION "Dusk game" CACHE STRING "One-line description")
|
||||||
set(DUSK_GAME_LONG_DESCRIPTION
|
set(DUSK_GAME_LONG_DESCRIPTION "No description yet." CACHE STRING "Full description")
|
||||||
"No description yet." CACHE STRING "Full description"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Prep cache
|
# Prep cache
|
||||||
set(DUSK_CACHE_TARGET "dusk-target")
|
set(DUSK_CACHE_TARGET "dusk-target")
|
||||||
@@ -37,19 +31,13 @@ set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
|||||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
||||||
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
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"
|
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
||||||
)
|
|
||||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
||||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk
|
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
||||||
)
|
|
||||||
set(DUSK_ASSETS "" 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_LIBRARY_TARGET_NAME "DuskCore" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
set(DUSK_BINARY_TARGET_NAME "Dusk" 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"
|
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||||
set(DUSK_TARGET_SYSTEM "linux")
|
set(DUSK_TARGET_SYSTEM "linux")
|
||||||
@@ -84,9 +72,7 @@ if(DUSK_BUILD_TESTS)
|
|||||||
${DUSK_LIBRARY_TARGET_NAME}
|
${DUSK_LIBRARY_TARGET_NAME}
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}"
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_VERSION)
|
if(NOT DEFINED DUSK_VERSION)
|
||||||
@@ -104,12 +90,6 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
DUSK_VERSION="${DUSK_VERSION}"
|
DUSK_VERSION="${DUSK_VERSION}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(DUSK_NETWORK)
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_NETWORK
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Toolchains
|
# Toolchains
|
||||||
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
||||||
|
|
||||||
@@ -135,21 +115,16 @@ if(DUSK_BUILD_TESTS)
|
|||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build assets. Runs unconditionally on every build (rather than being
|
# Build assets
|
||||||
# gated behind a custom_command's file-level DEPENDS list) because
|
file(GLOB_RECURSE DUSK_ASSET_FILES CONFIGURE_DEPENDS "${DUSK_ASSETS_DIR}/*")
|
||||||
# CONFIGURE_DEPENDS globs only pick up added/removed files on the next
|
add_custom_command(
|
||||||
# CMake configure, so that approach could miss/lag a rebuild behind an
|
OUTPUT "${DUSK_ASSETS_ZIP}"
|
||||||
# asset edit. tools.asset.pack itself decides whether anything actually
|
|
||||||
# changed (see its manifest check) and no-ops quickly when nothing did,
|
|
||||||
# so this stays cheap on a build where assets are untouched.
|
|
||||||
add_custom_target(DUSK_ASSETS_BUILT ALL
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
||||||
COMMAND ${Python3_EXECUTABLE} -m tools.asset.pack
|
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
||||||
--input "${DUSK_ASSETS_DIR}"
|
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
||||||
--output "${DUSK_ASSETS_ZIP}"
|
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
||||||
WORKING_DIRECTORY "${DUSK_ROOT_DIR}"
|
DEPENDS ${DUSK_ASSET_FILES}
|
||||||
BYPRODUCTS "${DUSK_ASSETS_ZIP}"
|
|
||||||
COMMENT "Packing assets into dusk.dsk"
|
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
add_custom_target(DUSK_ASSETS_BUILT DEPENDS "${DUSK_ASSETS_ZIP}")
|
||||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
||||||
@@ -9,18 +9,15 @@ following packages, depending on your system;
|
|||||||
|
|
||||||
Fedora;
|
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 libmad-devel
|
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
|
||||||
```
|
```
|
||||||
`libmad-devel` (used for MP3 decoding) is GPL-licensed and ships in the
|
|
||||||
[RPM Fusion](https://rpmfusion.org/) free repository rather than Fedora's
|
|
||||||
base repos - make sure RPM Fusion is enabled first.
|
|
||||||
|
|
||||||
Ubuntu;
|
Ubuntu;
|
||||||
```
|
```
|
||||||
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl libmad0-dev
|
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl
|
||||||
```
|
```
|
||||||
|
|
||||||
Arch Linux;
|
Arch Linux;
|
||||||
```
|
```
|
||||||
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl libmad
|
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl
|
||||||
```
|
```
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"items": [
|
|
||||||
// First thing, try and find a save device, used for settings and what not.
|
|
||||||
{
|
|
||||||
"type": "MODAL",
|
|
||||||
"title": "initial.checking_save.title",
|
|
||||||
"message": "initial.checking_save.message"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "WAIT",
|
|
||||||
"seconds": 0.2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SAVE_DEVICE_CHECK",
|
|
||||||
"successMarker": "CONTINUE",
|
|
||||||
"failureMarker": "SAVE_DEVICE_NOT_FOUND"
|
|
||||||
},
|
|
||||||
|
|
||||||
// No save device found
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "SAVE_DEVICE_NOT_FOUND"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_CLOSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_OPTIONS_MARKERS",
|
|
||||||
"title": "initial.no_device.title",
|
|
||||||
"message": "initial.no_device.message",
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"text": "initial.no_device.retry",
|
|
||||||
"marker": "SAVE_DEVICE_RETRY"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"text": "initial.no_device.continue",
|
|
||||||
"marker": "CONTINUE"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Save device not found, user to retry, just close modal and loop
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "SAVE_DEVICE_RETRY"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_CLOSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "RESTART"
|
|
||||||
},
|
|
||||||
|
|
||||||
// Save device found (or continuing without one)
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "CONTINUE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_CLOSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "CUTSCENE",
|
|
||||||
"name": "main_menu"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
{
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "MAIN_MENU_IDLE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "UI_SHOW",
|
|
||||||
"name": "main_menu"
|
|
||||||
},
|
|
||||||
|
|
||||||
// Options button goes here - no options screen yet, so this is just
|
|
||||||
// an alias landing right back on the idle loop below.
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "OPTIONS"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "IDLE"
|
|
||||||
},
|
|
||||||
|
|
||||||
// New Game button goes here.
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "NEW_GAME"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL",
|
|
||||||
"title": "main_menu.checking_save.title",
|
|
||||||
"message": "main_menu.checking_save.message"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "WAIT",
|
|
||||||
"seconds": 0.2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SAVE_DEVICE_CHECK",
|
|
||||||
"successMarker": "SAVE_DEVICE_FOUND",
|
|
||||||
"failureMarker": "SAVE_DEVICE_NOT_FOUND"
|
|
||||||
},
|
|
||||||
|
|
||||||
// Save device not found
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "SAVE_DEVICE_NOT_FOUND"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_CLOSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_OPTIONS_MARKERS",
|
|
||||||
"title": "main_menu.no_device.title",
|
|
||||||
"message": "main_menu.no_device.message",
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"text": "main_menu.no_device.retry",
|
|
||||||
"marker": "NEW_GAME"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"text": "main_menu.no_device.continue",
|
|
||||||
"marker": "SAVE_DEVICE_FOUND"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Save data failed to load (e.g. corrupt/unreadable) - only option is
|
|
||||||
// to retry, no "continue without saving" here since we already know a
|
|
||||||
// device is present.
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "LOAD_ERROR"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_OPTIONS_MARKERS",
|
|
||||||
"title": "main_menu.save_load_error.title",
|
|
||||||
"message": "main_menu.save_load_error.message",
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"text": "main_menu.save_load_error.retry",
|
|
||||||
"marker": "NEW_GAME"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Quit Game button goes here. Cancelling jumps back to
|
|
||||||
// MAIN_MENU_IDLE; confirming falls through to QUIT_GAME, which
|
|
||||||
// ends the process directly.
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "QUIT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_OPTIONS_MARKERS",
|
|
||||||
"title": "main_menu.quit_confirm",
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"text": "ui.confirm.confirm",
|
|
||||||
"marker": "QUIT_CONFIRMED"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"text": "ui.confirm.cancel",
|
|
||||||
"marker": "MAIN_MENU_IDLE"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "QUIT_CONFIRMED"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "QUIT_GAME"
|
|
||||||
},
|
|
||||||
|
|
||||||
// main menu just listens for cutscene ending to show the select save modal
|
|
||||||
// so we have that here.
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "SAVE_DEVICE_FOUND"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "MODAL_CLOSE"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SAVE_LOAD_ALL_SLOTS",
|
|
||||||
"successMarker": "LOADED",
|
|
||||||
"failureMarker": "LOAD_ERROR"
|
|
||||||
},
|
|
||||||
|
|
||||||
// Must be the very last item - falling off the end here is what
|
|
||||||
// completes the cutscene and fires uiMainMenuOpenSelectSave (see
|
|
||||||
// cutsceneSystemSetOnComplete in ui/screen/mainmenu/uimainmenu.c).
|
|
||||||
// Placing this anywhere earlier would fall through into whatever
|
|
||||||
// comes next instead (e.g. the QUIT block, if placed just before it).
|
|
||||||
{
|
|
||||||
"type": "MARKER",
|
|
||||||
"name": "LOADED"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -5,107 +5,11 @@ msgstr ""
|
|||||||
"Content-Type: text/plain; charset=UTF-8\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"
|
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : n==2 ? 1 : (n<7 ? 2 : 3));\n"
|
||||||
|
|
||||||
# Initial Scene
|
|
||||||
msgid "initial.checking_save.title"
|
|
||||||
msgstr "Checking for save data"
|
|
||||||
|
|
||||||
msgid "initial.checking_save.message"
|
|
||||||
msgstr "Please wait..."
|
|
||||||
|
|
||||||
msgid "initial.no_device.title"
|
|
||||||
msgstr "No Save Device Found"
|
|
||||||
|
|
||||||
msgid "initial.no_device.message"
|
|
||||||
msgstr "Could not find a save device, ensure it is connected and try again. You can continue, but progress will not be saved."
|
|
||||||
|
|
||||||
msgid "initial.no_device.retry"
|
|
||||||
msgstr "Try again"
|
|
||||||
|
|
||||||
msgid "initial.no_device.continue"
|
|
||||||
msgstr "Continue without saving"
|
|
||||||
|
|
||||||
|
|
||||||
# Main Menu Scene
|
|
||||||
msgid "main_menu.start_game"
|
|
||||||
msgstr "Start Game"
|
|
||||||
|
|
||||||
msgid "main_menu.options"
|
|
||||||
msgstr "Options"
|
|
||||||
|
|
||||||
msgid "main_menu.quit"
|
|
||||||
msgstr "Quit Game"
|
|
||||||
|
|
||||||
msgid "main_menu.quit_confirm"
|
|
||||||
msgstr "Are you sure you want to quit?"
|
|
||||||
|
|
||||||
msgid "main_menu.checking_save.title"
|
|
||||||
msgstr "Checking for save data"
|
|
||||||
|
|
||||||
msgid "main_menu.checking_save.message"
|
|
||||||
msgstr "Please wait..."
|
|
||||||
|
|
||||||
msgid "main_menu.no_device.title"
|
|
||||||
msgstr "No Save Device Found"
|
|
||||||
|
|
||||||
msgid "main_menu.no_device.message"
|
|
||||||
msgstr "Could not find a save device, ensure it is connected and try again. You can continue, but progress will not be saved."
|
|
||||||
|
|
||||||
msgid "main_menu.no_device.retry"
|
|
||||||
msgstr "Try again"
|
|
||||||
|
|
||||||
msgid "main_menu.no_device.continue"
|
|
||||||
msgstr "Continue without saving"
|
|
||||||
|
|
||||||
msgid "main_menu.save_load_error.title"
|
|
||||||
msgstr "Error"
|
|
||||||
|
|
||||||
msgid "main_menu.save_load_error.message"
|
|
||||||
msgstr "Failed to load save data. Please try again."
|
|
||||||
|
|
||||||
msgid "main_menu.save_load_error.retry"
|
|
||||||
msgstr "Try Again"
|
|
||||||
|
|
||||||
|
|
||||||
# Select Save Screen
|
|
||||||
msgid "ui.select_save.title"
|
|
||||||
msgstr "Select Save"
|
|
||||||
|
|
||||||
msgid "ui.select_save.empty"
|
|
||||||
msgstr "Empty Slot"
|
|
||||||
|
|
||||||
msgid "ui.select_save.slot_format"
|
|
||||||
msgstr "%s Lv.%d %s"
|
|
||||||
|
|
||||||
msgid "ui.select_save.delete_mode"
|
|
||||||
msgstr "Delete a Save"
|
|
||||||
|
|
||||||
msgid "ui.select_save.delete_confirm"
|
|
||||||
msgstr "Are you sure you want to delete this save?"
|
|
||||||
|
|
||||||
msgid "ui.select_save.name_title"
|
|
||||||
msgstr "Enter game save file name"
|
|
||||||
|
|
||||||
msgid "ui.save_slot.number_format"
|
|
||||||
msgstr "Slot %d"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#: ui/menu.c:10
|
#: ui/menu.c:10
|
||||||
msgid "ui.title"
|
msgid "ui.title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Welcome"
|
"Welcome"
|
||||||
|
|
||||||
msgid "save.linux.mkdirp_failed"
|
|
||||||
msgstr "Failed to create save directory, check the disk is not full or write-protected."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/settings/uisettings.c
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
msgid "ui.settings.tabs.general"
|
msgid "ui.settings.tabs.general"
|
||||||
msgstr "General"
|
msgstr "General"
|
||||||
@@ -152,114 +56,6 @@ msgstr "Items"
|
|||||||
msgid "ui.game_menu.settings"
|
msgid "ui.game_menu.settings"
|
||||||
msgstr "Settings"
|
msgstr "Settings"
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save"
|
|
||||||
msgstr "Save"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_success"
|
|
||||||
msgstr "Game saved."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_cancelled"
|
|
||||||
msgstr "Save cancelled."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_unavailable"
|
|
||||||
msgstr "Can't save - no save device found."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_temporary"
|
|
||||||
msgstr "This session is temporary - no save device was found, so saving is disabled."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_create_confirm"
|
|
||||||
msgstr "No save data found. Create a new save?"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_failed_format"
|
|
||||||
msgstr "Save failed: %s"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/game/uigamemenu.c
|
|
||||||
msgid "ui.game_menu.save_check_failed_format"
|
|
||||||
msgstr "Can't save: %s"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialnocard.c
|
|
||||||
msgid "ui.initial.no_card.message"
|
|
||||||
msgstr "No save device found. You can continue, but\nprogress will not be saved."
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialnocard.c
|
|
||||||
msgid "ui.initial.no_card.retry"
|
|
||||||
msgstr "Retry"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialnocard.c
|
|
||||||
msgid "ui.initial.no_card.continue"
|
|
||||||
msgstr "Continue Anyway"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialcreatesave.c
|
|
||||||
msgid "ui.initial.create_save.message"
|
|
||||||
msgstr "No save data found. Create a new save?"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialcreatesave.c
|
|
||||||
msgid "ui.initial.create_save.yes"
|
|
||||||
msgstr "Yes"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/initial/uiinitialcreatesave.c
|
|
||||||
msgid "ui.initial.create_save.no"
|
|
||||||
msgstr "No"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/uiconfirm.c
|
|
||||||
msgid "ui.confirm.confirm"
|
|
||||||
msgstr "Confirm"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/uiconfirm.c
|
|
||||||
msgid "ui.confirm.cancel"
|
|
||||||
msgstr "Cancel"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/battle/uibattlemenu.c
|
|
||||||
msgid "ui.battle.menu.attack"
|
|
||||||
msgstr "Attack"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/battle/uibattlemenu.c
|
|
||||||
msgid "ui.battle.menu.flee"
|
|
||||||
msgstr "Flee"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/battle/uibattlemenu.c
|
|
||||||
msgid "ui.battle.menu.target_format"
|
|
||||||
msgstr "Enemy %u (%u/%u HP)"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/battle/uibattlehud.c
|
|
||||||
msgid "ui.battle.hud.hp_format"
|
|
||||||
msgstr "HP %u/%u"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/battle/uibattlehud.c
|
|
||||||
msgid "ui.battle.hud.mp_format"
|
|
||||||
msgstr "MP %u/%u"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/settings/uisettingsaudio.c
|
|
||||||
msgid "ui.settings.audio.placeholder"
|
|
||||||
msgstr "No audio settings yet"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/settings/uisettingsdisplay.c
|
|
||||||
msgid "ui.settings.display.placeholder"
|
|
||||||
msgstr "No display settings yet"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/settings/uisettingsinput.c
|
|
||||||
msgid "ui.settings.input.placeholder"
|
|
||||||
msgstr "No input settings yet"
|
|
||||||
|
|
||||||
#: src/dusk/ui/frame/backpack/uibackpack.c
|
|
||||||
msgid "ui.backpack.category_format"
|
|
||||||
msgstr "Category %u"
|
|
||||||
|
|
||||||
#: src/dusk/ui/overlay/uiloading.c
|
|
||||||
msgid "ui.loading.text"
|
|
||||||
msgstr "loading"
|
|
||||||
|
|
||||||
#: src/dusk/ui/overlay/uiautosave.c
|
|
||||||
msgid "ui.autosave.saving"
|
|
||||||
msgstr "SAVING"
|
|
||||||
|
|
||||||
msgid "item.potion.name"
|
msgid "item.potion.name"
|
||||||
msgstr "Potion"
|
msgstr "Potion"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: ExampleApp 1.0\n"
|
||||||
|
"Language: es\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n==1 ? 0 : 1);\n"
|
||||||
|
|
||||||
|
#: ui/menu.c:10
|
||||||
|
msgid "ui.title"
|
||||||
|
msgstr ""
|
||||||
|
"Bienvenido"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.general"
|
||||||
|
msgstr "General"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.input"
|
||||||
|
msgstr "Entrada"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.display"
|
||||||
|
msgstr "Pantalla"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.audio"
|
||||||
|
msgstr "Audio"
|
||||||
|
|
||||||
|
msgid "ui.settings.input.deadzone"
|
||||||
|
msgstr "Deadzone"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettingsgeneral.c
|
||||||
|
msgid "ui.settings.general.language"
|
||||||
|
msgstr "Idioma"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettingsgeneral.c
|
||||||
|
msgid "ui.settings.general.language_detail"
|
||||||
|
msgstr "Se aplica después de reiniciar la aplicación."
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.apply"
|
||||||
|
msgstr "Aplicar"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/uiconfirm.c
|
||||||
|
msgid "ui.confirm.discard_changes"
|
||||||
|
msgstr "¿Descartar los cambios no guardados?"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.characters"
|
||||||
|
msgstr "Personajes"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.items"
|
||||||
|
msgstr "Objetos"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.settings"
|
||||||
|
msgstr "Configuración"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.potion.name"
|
||||||
|
msgstr "Poción"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.potato.name"
|
||||||
|
msgstr "Papa"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.apple.name"
|
||||||
|
msgstr "Manzana"
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: ExampleApp 1.0\n"
|
||||||
|
"Language: ja\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Plural-Forms: nplurals=1; plural=(0);\n"
|
||||||
|
|
||||||
|
#: ui/menu.c:10
|
||||||
|
msgid "ui.title"
|
||||||
|
msgstr ""
|
||||||
|
"歓迎"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.general"
|
||||||
|
msgstr "一般"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.input"
|
||||||
|
msgstr "入力"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.display"
|
||||||
|
msgstr "表示"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.tabs.audio"
|
||||||
|
msgstr "オーディオ"
|
||||||
|
|
||||||
|
msgid "ui.settings.input.deadzone"
|
||||||
|
msgstr "デッドゾーン"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettingsgeneral.c
|
||||||
|
msgid "ui.settings.general.language"
|
||||||
|
msgstr "言語"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettingsgeneral.c
|
||||||
|
msgid "ui.settings.general.language_detail"
|
||||||
|
msgstr "アプリケーションを再起動すると適用されます。"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/settings/uisettings.c
|
||||||
|
msgid "ui.settings.apply"
|
||||||
|
msgstr "適用"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/uiconfirm.c
|
||||||
|
msgid "ui.confirm.discard_changes"
|
||||||
|
msgstr "未保存の変更を破棄しますか?"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.characters"
|
||||||
|
msgstr "キャラクター"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.items"
|
||||||
|
msgstr "アイテム"
|
||||||
|
|
||||||
|
#: src/dusk/ui/frame/game/uigamemenu.c
|
||||||
|
msgid "ui.game_menu.settings"
|
||||||
|
msgstr "設定"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.potion.name"
|
||||||
|
msgstr "ポーション"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.potato.name"
|
||||||
|
msgstr "ジャガイモ"
|
||||||
|
|
||||||
|
#: src/dusk/rpg/item/item.json
|
||||||
|
msgid "item.apple.name"
|
||||||
|
msgstr "リンゴ"
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"meshes":[{"file":"house_4_4.dmf","pos":[2,1,0]},{"file":"house_6_3.dmf","pos":[1,9,0]},{"file":"house_2_2.dmf","pos":[12,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[6,0],[2,0],[2,0],[2,0],[2,0],[2,0],[2,0],[7,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[4,0],[12,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[9,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[{"file":"house_5_3.dmf","pos":[1,1,0]}],"entities":[{"type":"global","globalId":3,"pos":[8,8,1]},{"type":"item","itemId":1,"quantity":1,"pos":[12,2,0]}],"areas":[{"min":[11,3,0],"max":[16,9,10],"callbackId":1,"notify":3,"trigger":6}]}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"meshes":[{"file":"house_8_4.dmf","pos":[1,1,0]},{"file":"house_3_3.dmf","pos":[11,2,0]},{"file":"house_2_2.dmf","pos":[3,11,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"meshes":[{"file":"house_3_2.dmf","pos":[1,1,0]},{"file":"house_2_3.dmf","pos":[7,2,0]},{"file":"house_4_2.dmf","pos":[1,8,0]},{"file":"house_1_1.dmf","pos":[11,10,0]},{"file":"house_5_2.dmf","pos":[13,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"meshes":[{"file":"house_5_5.dmf","pos":[3,2,0]},{"file":"house_2_3.dmf","pos":[10,3,0]},{"file":"house_3_1.dmf","pos":[1,12,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,1],[4,1],[4,1],[4,1],[4,1],[4,1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[]}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_-1_0_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_0_0_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_0_1_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_1_0_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_1_1_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"mesh": "meshes/chunks/chunk_2_0_0_0.dmf",
|
||||||
|
"color": [
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255
|
||||||
|
],
|
||||||
|
"texture": "tiles.png"
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (c) 2026 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
// Player: dynamic capsule body, moved relative to the camera by PLAYER's
|
||||||
|
// own update callback (see entityplayer.c).
|
||||||
|
class Player {
|
||||||
|
constructor() {
|
||||||
|
this.entity = new Entity();
|
||||||
|
|
||||||
|
this.position = this.entity.add(POSITION);
|
||||||
|
this.position.setLocalPosition(0.0, 2.0, 0.0);
|
||||||
|
|
||||||
|
this.physics = this.entity.add(PHYSICS);
|
||||||
|
this.physics.setShape(PHYSICS_SHAPE_CAPSULE, 0.5, 0.5);
|
||||||
|
|
||||||
|
this.renderable = this.entity.add(RENDERABLE);
|
||||||
|
this.renderable.setMesh(0, MESH_CAPSULE);
|
||||||
|
this.renderable.setColor(0, 0, 255, 255);
|
||||||
|
|
||||||
|
this.entity.add(PLAYER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Player;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright (c) 2026 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
// Entry point run once at startup (see game.c). Swap which scene module
|
||||||
|
// gets passed to Scene.set() here to change what the game boots into.
|
||||||
|
var overworldScene = require('./overworldscene.js');
|
||||||
|
Scene.set(overworldScene);
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) 2026 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
// Radius must stay well outside the floor's footprint (a 20x20 plane has a
|
||||||
|
// corner-to-center distance of 10*sqrt(2) =~ 14.1) -- orbiting inside that
|
||||||
|
// puts parts of the floor's own geometry near/behind the camera's view
|
||||||
|
// direction, which the PSP's legacy GU pipeline can't clip properly and
|
||||||
|
// drops the whole triangle instead of clipping it.
|
||||||
|
var CAMERA_ORBIT_RADIUS = 18.0;
|
||||||
|
var CAMERA_ORBIT_HEIGHT = 10.0;
|
||||||
|
var CAMERA_ORBIT_SPEED = 0.5;
|
||||||
|
|
||||||
|
var Player = require('./Player.js');
|
||||||
|
|
||||||
|
var cameraOrbitAngle = 0.0;
|
||||||
|
var cameraPosition = null;
|
||||||
|
|
||||||
|
// Orbits the camera around the world origin at a fixed radius/height/
|
||||||
|
// speed, always looking back at the origin. Called once up front (so the
|
||||||
|
// very first rendered frame is already positioned correctly) and then
|
||||||
|
// once per frame via update() below.
|
||||||
|
function updateCameraOrbit() {
|
||||||
|
cameraOrbitAngle += Time.delta * CAMERA_ORBIT_SPEED;
|
||||||
|
|
||||||
|
var eyeX = Math.cos(cameraOrbitAngle) * CAMERA_ORBIT_RADIUS;
|
||||||
|
var eyeY = CAMERA_ORBIT_HEIGHT;
|
||||||
|
var eyeZ = Math.sin(cameraOrbitAngle) * CAMERA_ORBIT_RADIUS;
|
||||||
|
|
||||||
|
cameraPosition.lookAt(eyeX, eyeY, eyeZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
// Called once by Scene.set(), right after it creates and activates the
|
||||||
|
// scene this module owns.
|
||||||
|
init: function() {
|
||||||
|
// Camera, orbiting the origin (see updateCameraOrbit above).
|
||||||
|
var camera = new Entity();
|
||||||
|
cameraPosition = camera.add(POSITION);
|
||||||
|
camera.add(CAMERA);
|
||||||
|
updateCameraOrbit();
|
||||||
|
|
||||||
|
// Static ground plane. Physics ignores the entity's position
|
||||||
|
// component -- the shape's own normal/distance fully define the
|
||||||
|
// plane in world space.
|
||||||
|
var plane = new Entity();
|
||||||
|
var planePosition = plane.add(POSITION);
|
||||||
|
planePosition.setLocalPosition(-10.0, 0.0, -10.0);
|
||||||
|
planePosition.setLocalScale(20.0, 1.0, 20.0);
|
||||||
|
|
||||||
|
var planePhysics = plane.add(PHYSICS);
|
||||||
|
planePhysics.setBodyType(PHYSICS_BODY_STATIC);
|
||||||
|
planePhysics.setShape(PHYSICS_SHAPE_PLANE, 0.0, 1.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
var planeRenderable = plane.add(RENDERABLE);
|
||||||
|
planeRenderable.setMesh(0, MESH_PLANE);
|
||||||
|
planeRenderable.setColor(128, 128, 128, 255);
|
||||||
|
|
||||||
|
new Player();
|
||||||
|
},
|
||||||
|
|
||||||
|
// Called once per engine frame while this module is the active scene
|
||||||
|
// (see Scene.set(), engineUpdate() -> moduleSceneUpdateCurrent()).
|
||||||
|
update: function() {
|
||||||
|
if(cameraPosition) updateCameraOrbit();
|
||||||
|
},
|
||||||
|
|
||||||
|
// Called once by Scene.set() when this module is replaced by another,
|
||||||
|
// right before the scene it owns is destroyed.
|
||||||
|
dispose: function() {
|
||||||
|
cameraPosition = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,96 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Turn things off we don't need
|
||||||
|
set(JERRY_CMDLINE OFF CACHE BOOL "" FORCE)
|
||||||
|
set(JERRY_EXT ON CACHE BOOL "" FORCE)
|
||||||
|
set(JERRY_DEBUGGER OFF CACHE BOOL "" FORCE)
|
||||||
|
set(JERRY_BUILTIN_DATE OFF CACHE BOOL "" FORCE)
|
||||||
|
set(ENABLE_LTO OFF CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
|
# Fetch Jerry
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
jerryscript
|
||||||
|
GIT_REPOSITORY https://git.wish.moe/YourWishes/jerryscript
|
||||||
|
GIT_TAG float32-fix
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(jerryscript)
|
||||||
|
|
||||||
|
# Mark found
|
||||||
|
set(jerryscript_FOUND ON)
|
||||||
|
|
||||||
|
# Define targets
|
||||||
|
if(TARGET jerryscript-core)
|
||||||
|
set(JERRY_CORE_TARGET jerryscript-core)
|
||||||
|
elseif(TARGET jerry-core)
|
||||||
|
set(JERRY_CORE_TARGET jerry-core)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET jerryscript-ext)
|
||||||
|
set(JERRY_EXT_TARGET jerryscript-ext)
|
||||||
|
elseif(TARGET jerry-ext)
|
||||||
|
set(JERRY_EXT_TARGET jerry-ext)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET jerryscript-port-default)
|
||||||
|
set(JERRY_PORT_TARGET jerryscript-port-default)
|
||||||
|
elseif(TARGET jerry-port-default)
|
||||||
|
set(JERRY_PORT_TARGET jerry-port-default)
|
||||||
|
elseif(TARGET jerryscript-port)
|
||||||
|
set(JERRY_PORT_TARGET jerryscript-port)
|
||||||
|
elseif(TARGET jerry-port)
|
||||||
|
set(JERRY_PORT_TARGET jerry-port)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT JERRY_CORE_TARGET)
|
||||||
|
message(FATAL_ERROR "JerryScript core target not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT JERRY_EXT_TARGET)
|
||||||
|
message(FATAL_ERROR "JerryScript ext target not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT JERRY_PORT_TARGET)
|
||||||
|
message(FATAL_ERROR "JerryScript port target not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(tgt IN ITEMS
|
||||||
|
${JERRY_CORE_TARGET}
|
||||||
|
${JERRY_EXT_TARGET}
|
||||||
|
${JERRY_PORT_TARGET}
|
||||||
|
)
|
||||||
|
if(TARGET ${tgt})
|
||||||
|
set_property(TARGET ${tgt} PROPERTY INTERPROCEDURAL_OPTIMIZATION OFF)
|
||||||
|
target_compile_definitions(${JERRY_CORE_TARGET} PRIVATE
|
||||||
|
JERRY_NUMBER_TYPE_FLOAT64=0
|
||||||
|
JERRY_BUILTIN_DATE=0
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Export include dirs through the targets
|
||||||
|
target_include_directories(${JERRY_CORE_TARGET} INTERFACE
|
||||||
|
${jerryscript_SOURCE_DIR}/jerry-core/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${JERRY_EXT_TARGET} INTERFACE
|
||||||
|
${jerryscript_SOURCE_DIR}/jerry-ext/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${JERRY_PORT_TARGET} INTERFACE
|
||||||
|
${jerryscript_SOURCE_DIR}/jerry-port/default/include
|
||||||
|
)
|
||||||
|
|
||||||
|
# Suppress JerryScript-only warning
|
||||||
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||||
|
target_compile_options(${JERRY_CORE_TARGET} PRIVATE
|
||||||
|
-Wno-error
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(jerryscript::core ALIAS ${JERRY_CORE_TARGET})
|
||||||
|
add_library(jerryscript::ext ALIAS ${JERRY_EXT_TARGET})
|
||||||
|
add_library(jerryscript::port ALIAS ${JERRY_PORT_TARGET})
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# Copyright (c) 2026 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
# NOTE: libmad itself is GPL-licensed (see https://www.underbit.com/products/mad/),
|
|
||||||
# not MIT like the rest of this project. Any binary linking it must comply
|
|
||||||
# with the GPL - a deliberate tradeoff accepted for MP3 decode correctness
|
|
||||||
# (see audiostreammp3decodersw.c's own comment on why minimp3 wasn't enough).
|
|
||||||
|
|
||||||
find_path(LIBMAD_INCLUDE_DIR NAMES mad.h)
|
|
||||||
mark_as_advanced(LIBMAD_INCLUDE_DIR)
|
|
||||||
|
|
||||||
find_library(LIBMAD_LIBRARY NAMES mad)
|
|
||||||
mark_as_advanced(LIBMAD_LIBRARY)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(
|
|
||||||
libmad
|
|
||||||
REQUIRED_VARS
|
|
||||||
LIBMAD_LIBRARY
|
|
||||||
LIBMAD_INCLUDE_DIR
|
|
||||||
)
|
|
||||||
|
|
||||||
if(libmad_FOUND AND NOT TARGET libmad::mad)
|
|
||||||
add_library(libmad::mad UNKNOWN IMPORTED)
|
|
||||||
set_target_properties(libmad::mad
|
|
||||||
PROPERTIES
|
|
||||||
INTERFACE_INCLUDE_DIRECTORIES ${LIBMAD_INCLUDE_DIR}
|
|
||||||
IMPORTED_LOCATION ${LIBMAD_LIBRARY}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
@@ -61,8 +61,6 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
|||||||
zstd
|
zstd
|
||||||
z
|
z
|
||||||
lzma
|
lzma
|
||||||
asnd
|
|
||||||
mad
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|||||||
|
|
||||||
# Link libraries
|
# Link libraries
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||||
# bba
|
bba
|
||||||
)
|
)
|
||||||
|
|
||||||
# ISO post-build: produce NTSC-J, NTSC-U and PAL disc images
|
# ISO post-build: produce NTSC-J, NTSC-U and PAL disc images
|
||||||
|
|||||||
+5
-68
@@ -1,3 +1,7 @@
|
|||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
set(CMAKE_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
||||||
set(CMAKE_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" 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_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
||||||
@@ -30,7 +34,6 @@ target_link_libraries(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|||||||
pspgu
|
pspgu
|
||||||
pspaudio
|
pspaudio
|
||||||
pspaudiolib
|
pspaudiolib
|
||||||
pspmp3
|
|
||||||
psputility
|
psputility
|
||||||
pspvfpu
|
pspvfpu
|
||||||
pspvram
|
pspvram
|
||||||
@@ -56,46 +59,9 @@ target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|||||||
DUSK_DISPLAY_WIDTH=480
|
DUSK_DISPLAY_WIDTH=480
|
||||||
DUSK_DISPLAY_HEIGHT=272
|
DUSK_DISPLAY_HEIGHT=272
|
||||||
DUSK_THREAD_PTHREAD
|
DUSK_THREAD_PTHREAD
|
||||||
DUSK_TIME_DYNAMIC
|
|
||||||
DUSK_DISPLAY_OVERSCAN=6
|
DUSK_DISPLAY_OVERSCAN=6
|
||||||
)
|
)
|
||||||
|
|
||||||
# logDebug()/logError() additionally write every call to a file on the
|
|
||||||
# Memory Stick (ms0:/PSP/GAME/Dusk/*.log) - a real, measured source of
|
|
||||||
# per-call hitching (fopen+write+fclose every log line), not just a
|
|
||||||
# theoretical cost. Default off so a normal build doesn't pay it; opt in
|
|
||||||
# with -DDUSK_PSP_LOG_FILE=ON when the log file itself is actually needed
|
|
||||||
# (e.g. no way to see stdout on real hardware).
|
|
||||||
set(DUSK_PSP_LOG_FILE OFF CACHE BOOL "Also write PSP debug/error logs to ms0:/PSP/GAME/Dusk/*.log (slow - Memory Stick I/O per call).")
|
|
||||||
if(DUSK_PSP_LOG_FILE)
|
|
||||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_PSP_LOG_FILE
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
||||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_ASSERTIONS_FAKED
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Generate PARAM.SFO as a normal tracked build output (instead of letting
|
|
||||||
# create_pbp_file() auto-generate + delete it) so it can be reused below by
|
|
||||||
# a properly dependency-tracked EBOOT.PBP repack step.
|
|
||||||
set(DUSK_PSP_PARAM_SFO "${DUSK_BUILD_DIR}/PARAM.SFO")
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${DUSK_PSP_PARAM_SFO}"
|
|
||||||
COMMAND "$ENV{PSPDEV}/bin/mksfoex" "-d" "MEMSIZE=1" "-s" "APP_VER=01.00"
|
|
||||||
"${DUSK_BINARY_TARGET_NAME}" "${DUSK_PSP_PARAM_SFO}"
|
|
||||||
COMMENT "Generating PARAM.SFO for ${DUSK_BINARY_TARGET_NAME}"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
add_custom_target(DuskPspParamSfo DEPENDS "${DUSK_PSP_PARAM_SFO}")
|
|
||||||
|
|
||||||
# create_pbp_file()'s own POST_BUILD chain (below) also consumes
|
|
||||||
# DUSK_PSP_PARAM_SFO, so make sure it exists before that chain runs.
|
|
||||||
add_dependencies(${DUSK_BINARY_TARGET_NAME} DuskPspParamSfo)
|
|
||||||
|
|
||||||
# Postbuild, create .pbp file for PSP.
|
# Postbuild, create .pbp file for PSP.
|
||||||
create_pbp_file(
|
create_pbp_file(
|
||||||
TARGET "${DUSK_BINARY_TARGET_NAME}"
|
TARGET "${DUSK_BINARY_TARGET_NAME}"
|
||||||
@@ -105,33 +71,4 @@ create_pbp_file(
|
|||||||
TITLE "${DUSK_BINARY_TARGET_NAME}"
|
TITLE "${DUSK_BINARY_TARGET_NAME}"
|
||||||
PSAR_PATH ${DUSK_ASSETS_ZIP}
|
PSAR_PATH ${DUSK_ASSETS_ZIP}
|
||||||
VERSION 01.00
|
VERSION 01.00
|
||||||
SFO_PATH "${DUSK_PSP_PARAM_SFO}"
|
)
|
||||||
OUTPUT_DIR "${DUSK_BUILD_DIR}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# CreatePBP.cmake's pack-pbp step is a POST_BUILD command tied to the
|
|
||||||
# executable target, so it only reruns when the ELF itself relinks. That
|
|
||||||
# means regenerating dusk.dsk (assets) alone, without touching any C
|
|
||||||
# source, silently leaves EBOOT.PBP embedding a stale asset pak. Repack it
|
|
||||||
# here as a normal file-tracked custom command depending on both the
|
|
||||||
# executable and the asset zip, so EBOOT.PBP always reflects the current
|
|
||||||
# assets even when nothing else about the build changed.
|
|
||||||
set(DUSK_PSP_EBOOT "${DUSK_BUILD_DIR}/EBOOT.PBP")
|
|
||||||
if(BUILD_PRX)
|
|
||||||
set(DUSK_PSP_EXECUTABLE "$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>.prx")
|
|
||||||
else()
|
|
||||||
set(DUSK_PSP_EXECUTABLE "$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>")
|
|
||||||
endif()
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${DUSK_PSP_EBOOT}"
|
|
||||||
COMMAND "$ENV{PSPDEV}/bin/pack-pbp" "${DUSK_PSP_EBOOT}" "${DUSK_PSP_PARAM_SFO}"
|
|
||||||
"NULL" "NULL" "NULL" "NULL" "NULL"
|
|
||||||
"${DUSK_PSP_EXECUTABLE}" "${DUSK_ASSETS_ZIP}"
|
|
||||||
DEPENDS
|
|
||||||
"$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>"
|
|
||||||
"${DUSK_PSP_PARAM_SFO}"
|
|
||||||
"${DUSK_ASSETS_ZIP}"
|
|
||||||
COMMENT "Repacking EBOOT.PBP (tracks executable + asset pak freshness)"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
add_custom_target(DuskPspEbootRepack ALL DEPENDS "${DUSK_PSP_EBOOT}")
|
|
||||||
@@ -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
|
|
||||||
)
|
|
||||||
@@ -4,17 +4,6 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|||||||
DUSK_WII
|
DUSK_WII
|
||||||
)
|
)
|
||||||
|
|
||||||
# Wii save storage method - see src/duskdolphin/save/savedeviceplatform.h.
|
|
||||||
set(DUSK_SAVE_WII_METHOD "SD" CACHE STRING
|
|
||||||
"Wii save storage: NAND (internal storage via ISFS), CARD (GameCube-\
|
|
||||||
compatible memory card emulation), or SD (SD card via libfat)"
|
|
||||||
)
|
|
||||||
set_property(CACHE DUSK_SAVE_WII_METHOD PROPERTY STRINGS "NAND" "CARD" "SD")
|
|
||||||
|
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
DUSK_SAVE_WII_METHOD_${DUSK_SAVE_WII_METHOD}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate Homebrew Channel meta.xml from project identity variables
|
# Generate Homebrew Channel meta.xml from project identity variables
|
||||||
string(TIMESTAMP DUSK_BUILD_DATE "%Y%m%d000000" UTC)
|
string(TIMESTAMP DUSK_BUILD_DATE "%Y%m%d000000" UTC)
|
||||||
configure_file(
|
configure_file(
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
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 dolphin-emu xvfb && \
|
||||||
|
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"]
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
FROM pspdev/pspdev:latest
|
||||||
|
WORKDIR /workdir
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
python3 \
|
||||||
|
py3-pip \
|
||||||
|
py3-dotenv \
|
||||||
|
git \
|
||||||
|
cmake \
|
||||||
|
make \
|
||||||
|
g++ \
|
||||||
|
sdl2-dev \
|
||||||
|
zlib-dev \
|
||||||
|
linux-headers
|
||||||
|
|
||||||
|
# PPSSPP has no Alpine/Linux distro package -- build the "PPSSPPHeadless"
|
||||||
|
# target (the CLI/no-window build PPSSPP's own CI uses for automated runs)
|
||||||
|
# from source instead. The target name and exact CMake options have moved
|
||||||
|
# around across PPSSPP versions -- if this breaks, check
|
||||||
|
# https://github.com/hrydgard/ppsspp's CMakeLists.txt for the current name.
|
||||||
|
RUN git clone --recursive --depth 1 \
|
||||||
|
https://github.com/hrydgard/ppsspp.git /opt/ppsspp && \
|
||||||
|
cd /opt/ppsspp && \
|
||||||
|
cmake -B build -DCMAKE_BUILD_TYPE=Release && \
|
||||||
|
cmake --build build --target PPSSPPHeadless -- -j$(nproc) && \
|
||||||
|
cp build/PPSSPPHeadless /usr/local/bin/PPSSPPHeadless && \
|
||||||
|
rm -rf /opt/ppsspp
|
||||||
|
|
||||||
|
VOLUME ["/workdir"]
|
||||||
@@ -345,14 +345,12 @@
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAP_NAME = "overworld";
|
|
||||||
|
|
||||||
function chunkPaths(x, y, z) {
|
function chunkPaths(x, y, z) {
|
||||||
return {
|
return {
|
||||||
raw: `assetsraw/maps/${MAP_NAME}/chunks/chunk_${x}_${y}_${z}.json`,
|
raw: `assetsraw/chunks/chunk_${x}_${y}_${z}.json`,
|
||||||
dcf: `assets/maps/${MAP_NAME}/chunks/${x}_${y}_${z}.dcf`,
|
dcf: `assets/chunks/${x}_${y}_${z}.dcf`,
|
||||||
terrainDmf: `assets/maps/${MAP_NAME}/meshes/chunks/chunk_${x}_${y}_${z}_0.dmf`,
|
terrainDmf: `assets/meshes/chunks/chunk_${x}_${y}_${z}_0.dmf`,
|
||||||
terrainModel: `assets/maps/${MAP_NAME}/models/chunks/chunk_${x}_${y}_${z}_0.json`,
|
terrainModel: `assets/models/chunks/chunk_${x}_${y}_${z}_0.json`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +767,7 @@
|
|||||||
async function buildChunkBrowseList() {
|
async function buildChunkBrowseList() {
|
||||||
const list = document.getElementById("chunkBrowseList");
|
const list = document.getElementById("chunkBrowseList");
|
||||||
list.innerHTML = "";
|
list.innerHTML = "";
|
||||||
const res = await apiLs(`assetsraw/maps/${MAP_NAME}/chunks`);
|
const res = await apiLs("assetsraw/chunks");
|
||||||
for(const entry of res.entries || []) {
|
for(const entry of res.entries || []) {
|
||||||
const m = entry.name.match(/^chunk_(-?\d+)_(-?\d+)_(-?\d+)\.json$/);
|
const m = entry.name.match(/^chunk_(-?\d+)_(-?\d+)_(-?\d+)\.json$/);
|
||||||
if(!m) continue;
|
if(!m) continue;
|
||||||
|
|||||||
@@ -209,10 +209,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
self.send_json({"error": "invalid chunk coordinates"}, 400)
|
self.send_json({"error": "invalid chunk coordinates"}, 400)
|
||||||
return
|
return
|
||||||
|
|
||||||
json_path = (
|
json_path = PROJECT_ROOT / "assetsraw" / "chunks" / f"chunk_{x}_{y}_{z}.json"
|
||||||
PROJECT_ROOT / "assetsraw" / "maps" / "overworld" / "chunks"
|
|
||||||
/ f"chunk_{x}_{y}_{z}.json"
|
|
||||||
)
|
|
||||||
if not json_path.is_file():
|
if not json_path.is_file():
|
||||||
self.send_json({"error": "chunk json not found"}, 404)
|
self.send_json({"error": "chunk json not found"}, 404)
|
||||||
return
|
return
|
||||||
|
|||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t dusk-dolphin-test -f docker/dolphin-test/Dockerfile .
|
||||||
|
docker run --rm -v "$(pwd):/workdir" dusk-dolphin-test /bin/bash -c "./scripts/test-gamecube-dolphin.sh"
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "$DEVKITPRO" ]; then
|
||||||
|
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DOLPHIN_BIN="${DOLPHIN_BIN:-dolphin-emu}"
|
||||||
|
if ! command -v "$DOLPHIN_BIN" >/dev/null 2>&1; then
|
||||||
|
echo "$DOLPHIN_BIN not found. Install Dolphin Emulator (e.g. 'apt install dolphin-emu')"
|
||||||
|
echo "or set DOLPHIN_BIN to its path."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v xvfb-run >/dev/null 2>&1; then
|
||||||
|
echo "xvfb-run not found. Install it (e.g. 'apt install xvfb') -- Dolphin's"
|
||||||
|
echo "Qt frontend needs a display even in batch mode."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
./scripts/build-gamecube-iso.sh
|
||||||
|
|
||||||
|
DUSK_TEST_DOLPHIN_SECONDS="${DUSK_TEST_DOLPHIN_SECONDS:-20}"
|
||||||
|
ISO="build-gamecube-iso/Dusk-NTSC-U.iso"
|
||||||
|
|
||||||
|
echo "Booting $ISO in Dolphin for up to ${DUSK_TEST_DOLPHIN_SECONDS}s (batch mode, headless via Xvfb)..."
|
||||||
|
|
||||||
|
# Dolphin's batch mode (-b -e) runs the disc until told to stop -- there's
|
||||||
|
# no "the game exited cleanly" signal to wait for, so we bound it with
|
||||||
|
# timeout and treat "still running when the clock ran out" as success.
|
||||||
|
set +e
|
||||||
|
xvfb-run -a timeout "${DUSK_TEST_DOLPHIN_SECONDS}" "$DOLPHIN_BIN" -b -e "$ISO"
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# timeout returns 124 when it had to kill Dolphin after the duration
|
||||||
|
# elapsed -- that means the disc booted and kept running, the expected
|
||||||
|
# smoke-test-passed outcome, not a failure. Any other non-zero status
|
||||||
|
# means Dolphin crashed or refused to boot the disc.
|
||||||
|
if [ "$status" -ne 0 ] && [ "$status" -ne 124 ]; then
|
||||||
|
echo "Dolphin exited with unexpected status $status -- treating as a failure."
|
||||||
|
exit "$status"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "GameCube smoke test passed (Dolphin ran $ISO for ${DUSK_TEST_DOLPHIN_SECONDS}s without crashing)."
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t dusk-psp-test -f docker/psp-test/Dockerfile .
|
||||||
|
docker run --rm -v "$(pwd):/workdir" dusk-psp-test /bin/bash -c "./scripts/test-psp-ppsspp.sh"
|
||||||
Executable
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# PPSSPP doesn't ship a standard Linux package -- build its "PPSSPPHeadless"
|
||||||
|
# target from source (https://github.com/hrydgard/ppsspp) and either put it
|
||||||
|
# on PATH or point PPSSPP_HEADLESS_BIN at it. See docker/psp-test/Dockerfile
|
||||||
|
# for a from-scratch build.
|
||||||
|
PPSSPP_HEADLESS_BIN="${PPSSPP_HEADLESS_BIN:-PPSSPPHeadless}"
|
||||||
|
if ! command -v "$PPSSPP_HEADLESS_BIN" >/dev/null 2>&1; then
|
||||||
|
echo "$PPSSPP_HEADLESS_BIN not found. Build PPSSPP's 'PPSSPPHeadless' target"
|
||||||
|
echo "from source or set PPSSPP_HEADLESS_BIN to its path."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
./scripts/build-psp.sh
|
||||||
|
|
||||||
|
DUSK_TEST_PPSSPP_SECONDS="${DUSK_TEST_PPSSPP_SECONDS:-20}"
|
||||||
|
EBOOT="build-psp/EBOOT.PBP"
|
||||||
|
|
||||||
|
echo "Booting $EBOOT in PPSSPPHeadless (timeout ${DUSK_TEST_PPSSPP_SECONDS}s)..."
|
||||||
|
|
||||||
|
# PPSSPPHeadless is purpose-built for automated/CI runs -- it renders
|
||||||
|
# without a window and is expected to exit on its own once --timeout
|
||||||
|
# elapses, unlike Dolphin's batch mode which has to be killed externally.
|
||||||
|
# Check `"$PPSSPP_HEADLESS_BIN" --help` if these flags don't match your
|
||||||
|
# PPSSPP checkout -- the headless CLI has changed across versions.
|
||||||
|
set +e
|
||||||
|
"$PPSSPP_HEADLESS_BIN" --timeout="${DUSK_TEST_PPSSPP_SECONDS}" "$EBOOT"
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$status" -ne 0 ]; then
|
||||||
|
echo "PPSSPPHeadless exited with status $status"
|
||||||
|
exit "$status"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "PSP smoke test passed (PPSSPPHeadless ran EBOOT.PBP for ${DUSK_TEST_PPSSPP_SECONDS}s without crashing)."
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t dusk-dolphin-test -f docker/dolphin-test/Dockerfile .
|
||||||
|
docker run --rm -v "$(pwd):/workdir" dusk-dolphin-test /bin/bash -c "./scripts/test-wii-dolphin.sh"
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "$DEVKITPRO" ]; then
|
||||||
|
echo "DEVKITPRO environment variable is not set. Please set it to the path of your DEVKITPRO installation."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DOLPHIN_BIN="${DOLPHIN_BIN:-dolphin-emu}"
|
||||||
|
if ! command -v "$DOLPHIN_BIN" >/dev/null 2>&1; then
|
||||||
|
echo "$DOLPHIN_BIN not found. Install Dolphin Emulator (e.g. 'apt install dolphin-emu')"
|
||||||
|
echo "or set DOLPHIN_BIN to its path."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! command -v xvfb-run >/dev/null 2>&1; then
|
||||||
|
echo "xvfb-run not found. Install it (e.g. 'apt install xvfb') -- Dolphin's"
|
||||||
|
echo "Qt frontend needs a display even in batch mode."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
./scripts/build-wii-iso.sh
|
||||||
|
|
||||||
|
DUSK_TEST_DOLPHIN_SECONDS="${DUSK_TEST_DOLPHIN_SECONDS:-20}"
|
||||||
|
ISO="build-wii-iso/Dusk-NTSC-U.iso"
|
||||||
|
|
||||||
|
echo "Booting $ISO in Dolphin for up to ${DUSK_TEST_DOLPHIN_SECONDS}s (batch mode, headless via Xvfb)..."
|
||||||
|
|
||||||
|
# Dolphin's batch mode (-b -e) runs the disc until told to stop -- there's
|
||||||
|
# no "the game exited cleanly" signal to wait for, so we bound it with
|
||||||
|
# timeout and treat "still running when the clock ran out" as success.
|
||||||
|
set +e
|
||||||
|
xvfb-run -a timeout "${DUSK_TEST_DOLPHIN_SECONDS}" "$DOLPHIN_BIN" -b -e "$ISO"
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# timeout returns 124 when it had to kill Dolphin after the duration
|
||||||
|
# elapsed -- that means the disc booted and kept running, the expected
|
||||||
|
# smoke-test-passed outcome, not a failure. Any other non-zero status
|
||||||
|
# means Dolphin crashed or refused to boot the disc.
|
||||||
|
if [ "$status" -ne 0 ] && [ "$status" -ne 124 ]; then
|
||||||
|
echo "Dolphin exited with unexpected status $status -- treating as a failure."
|
||||||
|
exit "$status"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Wii smoke test passed (Dolphin ran $ISO for ${DUSK_TEST_DOLPHIN_SECONDS}s without crashing)."
|
||||||
+3
-16
@@ -4,32 +4,19 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_subdirectory(dusk)
|
add_subdirectory(dusk)
|
||||||
|
add_subdirectory(duskrpg)
|
||||||
if(DUSK_NETWORK)
|
|
||||||
add_subdirectory(dusknetwork)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||||
add_subdirectory(dusklinux)
|
add_subdirectory(dusklinux)
|
||||||
add_subdirectory(dusksdl2)
|
add_subdirectory(dusksdl2)
|
||||||
add_subdirectory(duskgl)
|
add_subdirectory(duskgl)
|
||||||
add_subdirectory(duskmad)
|
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
add_subdirectory(duskpsp)
|
add_subdirectory(duskpsp)
|
||||||
add_subdirectory(dusksdl2)
|
add_subdirectory(dusksdl2)
|
||||||
add_subdirectory(duskgl)
|
add_subdirectory(duskgl)
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "vita")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "wii" OR DUSK_TARGET_SYSTEM STREQUAL "gamecube")
|
||||||
add_subdirectory(duskvita)
|
|
||||||
add_subdirectory(dusksdl2)
|
|
||||||
add_subdirectory(duskgl)
|
|
||||||
|
|
||||||
elseif(
|
|
||||||
DUSK_TARGET_SYSTEM STREQUAL "wii" OR
|
|
||||||
DUSK_TARGET_SYSTEM STREQUAL "gamecube"
|
|
||||||
)
|
|
||||||
add_subdirectory(duskdolphin)
|
add_subdirectory(duskdolphin)
|
||||||
add_subdirectory(duskmad)
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
+17
-16
@@ -14,21 +14,12 @@ if(NOT libzip_FOUND)
|
|||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# assetdsk.c calls crc32() directly (to verify dusk.dsk archive checksums).
|
|
||||||
# find_package(libzip) above already resolves ZLIB as a side effect, so
|
|
||||||
# ZLIB_FOUND may already be true without ZLIB::ZLIB having been linked to
|
|
||||||
# our target - link it unconditionally rather than guarding on ZLIB_FOUND.
|
|
||||||
find_package(ZLIB REQUIRED)
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC ZLIB::ZLIB)
|
|
||||||
|
|
||||||
if(NOT stb_image_FOUND)
|
if(NOT stb_image_FOUND)
|
||||||
find_package(stb REQUIRED)
|
find_package(stb REQUIRED)
|
||||||
if(STB_IMAGE_FOUND)
|
if(STB_IMAGE_FOUND)
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR "stb_image not found. Please ensure stb is correctly fetched.")
|
||||||
"stb_image not found. Please ensure stb is correctly fetched."
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -37,12 +28,19 @@ if(NOT yyjson_FOUND)
|
|||||||
if(yyjson_FOUND)
|
if(yyjson_FOUND)
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR "yyjson not found. Please ensure yyjson is correctly fetched.")
|
||||||
"yyjson not found. Please ensure yyjson is correctly fetched."
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT jerryscript_FOUND)
|
||||||
|
find_package(jerryscript REQUIRED)
|
||||||
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
jerryscript::core
|
||||||
|
jerryscript::ext
|
||||||
|
jerryscript::port
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(DUSK_BACKTRACE)
|
if(DUSK_BACKTRACE)
|
||||||
target_link_options(${DUSK_LIBRARY_TARGET_NAME} PUBLIC -rdynamic)
|
target_link_options(${DUSK_LIBRARY_TARGET_NAME} PUBLIC -rdynamic)
|
||||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||||
@@ -64,22 +62,25 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
|||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(animation)
|
add_subdirectory(animation)
|
||||||
|
add_subdirectory(event)
|
||||||
add_subdirectory(assert)
|
add_subdirectory(assert)
|
||||||
add_subdirectory(asset)
|
add_subdirectory(asset)
|
||||||
add_subdirectory(audio)
|
|
||||||
add_subdirectory(console)
|
add_subdirectory(console)
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
|
add_subdirectory(entity)
|
||||||
add_subdirectory(log)
|
add_subdirectory(log)
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
add_subdirectory(error)
|
add_subdirectory(error)
|
||||||
|
add_subdirectory(game)
|
||||||
add_subdirectory(input)
|
add_subdirectory(input)
|
||||||
add_subdirectory(locale)
|
add_subdirectory(locale)
|
||||||
add_subdirectory(perf)
|
|
||||||
add_subdirectory(rpg)
|
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
add_subdirectory(system)
|
add_subdirectory(system)
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
|
add_subdirectory(network)
|
||||||
|
add_subdirectory(physics)
|
||||||
add_subdirectory(save)
|
add_subdirectory(save)
|
||||||
|
add_subdirectory(script)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
add_subdirectory(thread)
|
add_subdirectory(thread)
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
easing.c
|
easing.c
|
||||||
animation.c
|
|
||||||
keyframe.c
|
keyframe.c
|
||||||
|
keyframeset.c
|
||||||
|
animation.c
|
||||||
)
|
)
|
||||||
+50
-108
@@ -5,128 +5,70 @@
|
|||||||
|
|
||||||
#include "animation.h"
|
#include "animation.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
void animationInit(
|
void animationInit(
|
||||||
animation_t *anim,
|
animation_t *anim,
|
||||||
keyframe_t *keyframes,
|
keyframe_t **tracks,
|
||||||
uint16_t *keyframeCounts,
|
uint16_t *trackCounts,
|
||||||
const uint16_t layerCount
|
uint16_t trackCount
|
||||||
) {
|
) {
|
||||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||||
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
|
||||||
assertNotNull(keyframeCounts, "Keyframe counts pointer cannot be null.");
|
|
||||||
assertTrue(layerCount > 0, "Layer count must be greater than zero.");
|
|
||||||
|
|
||||||
memoryZero(anim, sizeof(animation_t));
|
keyframeSetInit(
|
||||||
anim->keyframes = keyframes;
|
&anim->keyframes, tracks, trackCounts, NULL, NULL, trackCount, NULL
|
||||||
anim->keyframeCounts = keyframeCounts;
|
);
|
||||||
anim->layerCount = layerCount;
|
anim->time = 0.0f;
|
||||||
|
anim->speed = 1.0f;
|
||||||
// Determine duration
|
anim->loop = false;
|
||||||
float_t duration = 0.0f;
|
anim->playing = false;
|
||||||
for(uint16_t layer = 0; layer < layerCount; layer++) {
|
anim->eventTime = 0.0f;
|
||||||
uint16_t keyframeCount = keyframeCounts[layer];
|
anim->eventCallback = NULL;
|
||||||
assertTrue(keyframeCount > 0, "Keyframe count invalid.");
|
anim->eventUser = NULL;
|
||||||
keyframe_t *layerKeyframes = keyframes + layer * keyframeCount;
|
|
||||||
|
|
||||||
#ifdef DUSK_ASSERTIONS
|
|
||||||
// Check that the keyframes are sorted by time.
|
|
||||||
for(uint16_t i = 1; i < keyframeCount; i++) {
|
|
||||||
assertTrue(
|
|
||||||
layerKeyframes[i].time >= layerKeyframes[i - 1].time,
|
|
||||||
"Keyframes must be sorted by time."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
keyframe_t *lastKeyframe = layerKeyframes + keyframeCount - 1;
|
|
||||||
duration = mathMax(duration, lastKeyframe->time);
|
|
||||||
}
|
|
||||||
assertTrue(duration > 0, "Animation duration must be greater than 0.");
|
|
||||||
anim->duration = duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer) {
|
void animationUpdate(animation_t *anim) {
|
||||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||||
assertTrue(layer < anim->layerCount, "Layer index out of bounds.");
|
if(!anim->playing) return;
|
||||||
|
|
||||||
uint16_t keyframeCount = anim->keyframeCounts[layer];
|
float_t duration = keyframeSetGetDuration(&anim->keyframes);
|
||||||
keyframe_t *layerKeyframes = anim->keyframes + layer * keyframeCount;
|
float_t prevTime = anim->time;
|
||||||
return keyframeGetValue(layerKeyframes, keyframeCount, anim->time);
|
anim->time += TIME.delta * anim->speed;
|
||||||
|
|
||||||
|
// Loops that overshoot duration wrap back into [0, duration) -- an event
|
||||||
|
// near the end must still be checked across that wrap, as two segments:
|
||||||
|
// (prevTime, duration] then [0, newTime].
|
||||||
|
bool_t wrapped = anim->loop && duration > 0.0f && anim->time >= duration;
|
||||||
|
|
||||||
|
if(anim->loop) {
|
||||||
|
if(duration > 0.0f) anim->time = mathModFloat(anim->time, duration);
|
||||||
|
} else if(anim->time >= duration) {
|
||||||
|
anim->time = duration;
|
||||||
|
anim->playing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!anim->eventCallback) return;
|
||||||
|
|
||||||
|
bool_t crossed = wrapped
|
||||||
|
? (prevTime < anim->eventTime || anim->time >= anim->eventTime)
|
||||||
|
: (prevTime < anim->eventTime && anim->time >= anim->eventTime);
|
||||||
|
if(crossed) anim->eventCallback(anim, anim->eventUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void animationUpdate(
|
void animationSetEvent(
|
||||||
animation_t *anim,
|
animation_t *anim,
|
||||||
const float_t deltaTime
|
const float_t time,
|
||||||
|
const animationeventcallback_t callback,
|
||||||
|
void *user
|
||||||
) {
|
) {
|
||||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||||
assertTrue(deltaTime >= 0, "Delta time must be non-negative.");
|
anim->eventTime = time;
|
||||||
|
anim->eventCallback = callback;
|
||||||
|
anim->eventUser = user;
|
||||||
|
}
|
||||||
|
|
||||||
bool_t justCompleted = false;
|
float_t animationGetValue(animation_t *anim, const uint16_t trackIndex) {
|
||||||
|
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||||
if(!(anim->flags & ANIMATION_FLAG_INTERNAL_COMPLETED)) {
|
return keyframeSetGetValue(&anim->keyframes, trackIndex, anim->time);
|
||||||
bool_t loop = (anim->flags & ANIMATION_FLAG_LOOP) != 0;
|
}
|
||||||
bool_t pingpong = (anim->flags & ANIMATION_FLAG_PINGPONG) != 0;
|
|
||||||
assertFalse(
|
|
||||||
loop && pingpong,
|
|
||||||
"Cannot set both ANIMATION_FLAG_LOOP and ANIMATION_FLAG_PINGPONG."
|
|
||||||
);
|
|
||||||
|
|
||||||
bool_t backward;
|
|
||||||
if(pingpong) {
|
|
||||||
backward = (anim->flags & ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD) != 0;
|
|
||||||
} else {
|
|
||||||
backward = (anim->flags & ANIMATION_FLAG_REVERSE) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve boundary crossings one at a time, so a single large deltaTime
|
|
||||||
// can correctly loop/pingpong across multiple boundaries in one call.
|
|
||||||
float_t remaining = deltaTime;
|
|
||||||
while(remaining > 0.0f) {
|
|
||||||
float_t toBoundary = (
|
|
||||||
backward ? anim->time : (anim->duration - anim->time)
|
|
||||||
);
|
|
||||||
if(remaining < toBoundary) {
|
|
||||||
anim->time += backward ? -remaining : remaining;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
remaining -= toBoundary;
|
|
||||||
anim->time = backward ? 0.0f : anim->duration;
|
|
||||||
|
|
||||||
bool_t stopHere;
|
|
||||||
if(backward) {
|
|
||||||
stopHere = (anim->flags & ANIMATION_FLAG_STOP_BEGINNING) != 0;
|
|
||||||
} else {
|
|
||||||
stopHere = (anim->flags & ANIMATION_FLAG_STOP_END) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(stopHere) {
|
|
||||||
justCompleted = true;
|
|
||||||
break;
|
|
||||||
} else if(pingpong) {
|
|
||||||
backward = !backward;
|
|
||||||
if(backward) anim->flags |= ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
|
|
||||||
else anim->flags &= ~ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
|
|
||||||
} else if(loop) {
|
|
||||||
anim->time = backward ? anim->duration : 0.0f;
|
|
||||||
if(anim->onLoop) anim->onLoop(anim->user);
|
|
||||||
} else {
|
|
||||||
justCompleted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(justCompleted) anim->flags |= ANIMATION_FLAG_INTERNAL_COMPLETED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call onUpdate for each layer.
|
|
||||||
for(uint16_t layer = 0; layer < anim->layerCount; layer++) {
|
|
||||||
float_t value = animationGetLayerValue(anim, layer);
|
|
||||||
if(anim->onUpdate) anim->onUpdate(layer, value, anim->user);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(justCompleted && anim->onComplete) anim->onComplete(anim->user);
|
|
||||||
}
|
|
||||||
@@ -4,91 +4,99 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "keyframe.h"
|
#include "keyframeset.h"
|
||||||
|
|
||||||
#define ANIMATION_FLAG_LOOP (1 << 0)
|
typedef struct animation_t animation_t;
|
||||||
#define ANIMATION_FLAG_REVERSE (1 << 1)
|
|
||||||
#define ANIMATION_FLAG_PINGPONG (1 << 2)
|
|
||||||
#define ANIMATION_FLAG_STOP_BEGINNING (1 << 3)
|
|
||||||
#define ANIMATION_FLAG_STOP_END (1 << 4)
|
|
||||||
|
|
||||||
// Internal - tracks which direction a pingponging animation is currently
|
/**
|
||||||
// travelling. Do not set this manually, it is managed by animationUpdate().
|
* Callback fired once when animationUpdate() advances time past
|
||||||
#define ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD (1 << 7)
|
* eventTime (see animationSetEvent()).
|
||||||
|
*
|
||||||
|
* @param anim The animation whose event fired.
|
||||||
|
* @param user The user pointer passed to animationSetEvent().
|
||||||
|
*/
|
||||||
|
typedef void (*animationeventcallback_t)(animation_t *anim, void *user);
|
||||||
|
|
||||||
// Internal - set once the animation has stopped advancing (see
|
typedef struct animation_t {
|
||||||
// animationUpdate()). Do not set this manually. There is currently no way to
|
/** The animation's tracks/channels and their raw keyframe data. */
|
||||||
// restart a completed animation short of clearing this bit and resetting
|
keyframeset_t keyframes;
|
||||||
// anim->time by hand.
|
|
||||||
#define ANIMATION_FLAG_INTERNAL_COMPLETED (1 << 6)
|
|
||||||
|
|
||||||
typedef struct {
|
/** Current playback position, in seconds. */
|
||||||
keyframe_t *keyframes;
|
|
||||||
uint16_t *keyframeCounts;
|
|
||||||
uint16_t layerCount;
|
|
||||||
float_t time;
|
float_t time;
|
||||||
float_t duration;
|
|
||||||
uint8_t flags;
|
|
||||||
|
|
||||||
void *user;
|
/** Playback rate multiplier; 1.0 = normal speed. */
|
||||||
void (*onUpdate)(const uint16_t layer, const float_t value, void *user);
|
float_t speed;
|
||||||
void (*onComplete)(void *user);
|
|
||||||
void (*onLoop)(void *user);
|
/** True if animationUpdate() should wrap time back to 0 on reaching the
|
||||||
|
* final keyframe, rather than holding there and clearing playing. */
|
||||||
|
bool_t loop;
|
||||||
|
|
||||||
|
/** True while animationUpdate() should advance time each call. */
|
||||||
|
bool_t playing;
|
||||||
|
|
||||||
|
/** Time (seconds) at which eventCallback fires; see animationSetEvent(). */
|
||||||
|
float_t eventTime;
|
||||||
|
/** Callback fired once when time advances past eventTime, or NULL. */
|
||||||
|
animationeventcallback_t eventCallback;
|
||||||
|
/** User pointer passed to eventCallback unchanged. */
|
||||||
|
void *eventUser;
|
||||||
} animation_t;
|
} animation_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes an animation with the given keyframes and layer count.
|
* Initializes an animation: time 0, speed 1.0, not looping, not playing.
|
||||||
|
* See keyframeSetInit() -- tracks/trackCounts and the keyframe_t arrays
|
||||||
|
* they point to are not copied, and must outlive this animation.
|
||||||
*
|
*
|
||||||
* @param anim Pointer to the animation to initialize.
|
* @param anim The animation to initialize.
|
||||||
* @param keyframes Pointer to the array of keyframes for each layer.
|
* @param tracks Array of trackCount keyframe_t arrays.
|
||||||
* @param keyframeCount Number of keyframes in each layer.
|
* @param trackCounts Array of trackCount keyframe counts, matching tracks.
|
||||||
* @param layerCount Number of layers in the animation.
|
* @param trackCount The number of tracks/channels in this animation.
|
||||||
*/
|
*/
|
||||||
void animationInit(
|
void animationInit(
|
||||||
animation_t *anim,
|
animation_t *anim,
|
||||||
keyframe_t *keyframes,
|
keyframe_t **tracks,
|
||||||
uint16_t *keyframeCounts,
|
uint16_t *trackCounts,
|
||||||
const uint16_t layerCount
|
uint16_t trackCount
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current time of the animation, clamping it to the valid range.
|
* Advances an animation's time by TIME.delta * speed. No-op if not
|
||||||
* This will call the onUpdate callback but none of the other callbacks.
|
* playing. Duration is the latest of every track's final keyframe time
|
||||||
*
|
* (see keyframeSetGetDuration()). If loop is set, time wraps back into
|
||||||
* @param anim Pointer to the animation to set the time for.
|
* [0, duration) on reaching it; otherwise time is clamped there and
|
||||||
* @param time The new time to set for the animation.
|
* playing is cleared.
|
||||||
|
*
|
||||||
|
* If eventCallback is set, it fires once when this call advances time
|
||||||
|
* from at or before eventTime to after it (checked across the loop wrap
|
||||||
|
* point too, so an event near the end of a looping animation still fires
|
||||||
|
* every loop).
|
||||||
|
*
|
||||||
|
* @param anim The animation to update.
|
||||||
*/
|
*/
|
||||||
void animationSetTime(animation_t *anim, const float_t time);
|
void animationUpdate(animation_t *anim);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current value of a specific layer in the animation based on the
|
* Sets (or clears, with callback NULL) the single time-triggered event
|
||||||
* current animation time.
|
* fired by animationUpdate().
|
||||||
|
*
|
||||||
|
* @param anim The animation to set the event on.
|
||||||
|
* @param time The time, in seconds, at which callback fires.
|
||||||
|
* @param callback The callback to invoke, or NULL to clear any event.
|
||||||
|
* @param user Arbitrary pointer forwarded to callback unchanged.
|
||||||
*/
|
*/
|
||||||
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer);
|
void animationSetEvent(
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the animation state based on the elapsed time. Advances anim->time
|
|
||||||
* by deltaTime (or against it, if ANIMATION_FLAG_REVERSE is set), then
|
|
||||||
* resolves whatever happens when it reaches the 0 or duration boundary:
|
|
||||||
*
|
|
||||||
* - ANIMATION_FLAG_PINGPONG: reflects off the boundary and continues playing
|
|
||||||
* in the opposite direction, forever, unless stopped (see below).
|
|
||||||
* - ANIMATION_FLAG_LOOP: wraps back around to the other boundary and keeps
|
|
||||||
* playing in the same direction, forever, unless stopped (see below).
|
|
||||||
* - ANIMATION_FLAG_STOP_BEGINNING / ANIMATION_FLAG_STOP_END: when the
|
|
||||||
* animation reaches that specific boundary, it clamps there and stops
|
|
||||||
* (firing onComplete) instead of looping/pingponging past it.
|
|
||||||
* - If none of the above apply at a boundary, the animation clamps there and
|
|
||||||
* stops, firing onComplete.
|
|
||||||
*
|
|
||||||
* onUpdate is called for every layer on every call. onLoop is called each
|
|
||||||
* time a loop wraps around. onComplete is called at most once, the moment
|
|
||||||
* the animation stops advancing.
|
|
||||||
*
|
|
||||||
* @param anim Pointer to the animation to update.
|
|
||||||
* @param deltaTime Time elapsed since the last update (in seconds).
|
|
||||||
*/
|
|
||||||
void animationUpdate(
|
|
||||||
animation_t *anim,
|
animation_t *anim,
|
||||||
const float_t deltaTime
|
const float_t time,
|
||||||
);
|
const animationeventcallback_t callback,
|
||||||
|
void *user
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of one of the animation's tracks at its current
|
||||||
|
* playback time.
|
||||||
|
*
|
||||||
|
* @param anim The animation to get the value from.
|
||||||
|
* @param trackIndex The track to evaluate, in [0, trackCount).
|
||||||
|
* @return The interpolated value of that track at the current time.
|
||||||
|
*/
|
||||||
|
float_t animationGetValue(animation_t *anim, const uint16_t trackIndex);
|
||||||
@@ -1,45 +1,43 @@
|
|||||||
/**
|
// Copyright (c) 2026 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "keyframe.h"
|
#include "keyframe.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
|
|
||||||
float_t keyframeGetValue(
|
float_t keyframeGetValue(
|
||||||
const keyframe_t *keyframes,
|
keyframe_t *keyframes,
|
||||||
const uint32_t keyframeCount,
|
const uint16_t keyframeCount,
|
||||||
const float_t time
|
const float_t time
|
||||||
) {
|
) {
|
||||||
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
||||||
assertTrue(keyframeCount > 0, "Keyframe count must be more than 0.");
|
assertTrue(keyframeCount > 0, "Keyframe count must be more than 0.");
|
||||||
assertTrue(time >= 0, "Time must be non-negative.");
|
assertTrue(time >= 0, "Time must be non-negative.");
|
||||||
#ifdef DUSK_ASSERTIONS
|
|
||||||
// Checks that the keyframes are sorted by time.
|
|
||||||
for(uint32_t i = 1; i < keyframeCount; i++) {
|
|
||||||
assertTrue(
|
|
||||||
keyframes[i].time >= keyframes[i - 1].time,
|
|
||||||
"Keyframes must be sorted by time."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
keyframe_t *last = (keyframe_t *)(keyframes + keyframeCount - 1);
|
keyframe_t *first = keyframes;
|
||||||
|
keyframe_t *last = keyframes + keyframeCount - 1;
|
||||||
|
|
||||||
|
// Clamp to the boundary keyframes' values directly rather than
|
||||||
|
// interpolating -- start == end at either boundary would otherwise
|
||||||
|
// divide by zero.
|
||||||
|
if(time <= first->time) return first->value;
|
||||||
if(time >= last->time) return last->value;
|
if(time >= last->time) return last->value;
|
||||||
|
|
||||||
// Since time < last->time (checked above), current is guaranteed to stop
|
keyframe_t *start = first;
|
||||||
// at or before reaching last, so no separate end-of-array check is needed.
|
keyframe_t *end;
|
||||||
keyframe_t *current = (keyframe_t *)keyframes;
|
keyframe_t *current = first;
|
||||||
keyframe_t *start = current;
|
|
||||||
while(current->time <= time) {
|
do {
|
||||||
|
if(current->time > time) {
|
||||||
|
end = current;
|
||||||
|
break;
|
||||||
|
}
|
||||||
start = current;
|
start = current;
|
||||||
current++;
|
current++;
|
||||||
}
|
} while(true);
|
||||||
keyframe_t *end = current;
|
|
||||||
|
|
||||||
float_t t = (time - start->time) / (end->time - start->time);
|
float_t t = (time - start->time) / (end->time - start->time);
|
||||||
return mathLerp(start->value, end->value, easingApply(start->easing, t));
|
return mathLerp(start->value, end->value, easingApply(start->easing, t));
|
||||||
}
|
}
|
||||||
@@ -13,15 +13,15 @@ typedef struct {
|
|||||||
} keyframe_t;
|
} keyframe_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of a keyframe at a given time.
|
* Gets the eased, interpolated value of a keyframe array at a given time.
|
||||||
*
|
*
|
||||||
* @param keyframes The keyframes to get the value from.
|
* @param keyframes The keyframes to evaluate, ascending by time.
|
||||||
* @param keyframeCount The number of keyframes in the array.
|
* @param keyframeCount The number of keyframes.
|
||||||
* @param time The time at which to get the value, in seconds.
|
* @param time The time at which to get the value, in seconds.
|
||||||
* @return The value of the keyframe at the given time.
|
* @return The interpolated value at the given time.
|
||||||
*/
|
*/
|
||||||
float_t keyframeGetValue(
|
float_t keyframeGetValue(
|
||||||
const keyframe_t *keyframes,
|
keyframe_t *keyframes,
|
||||||
const uint32_t keyframeCount,
|
const uint16_t keyframeCount,
|
||||||
const float_t time
|
const float_t time
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
// Copyright (c) 2026 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "keyframeset.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
|
||||||
|
void keyframeSetInit(
|
||||||
|
keyframeset_t *set,
|
||||||
|
keyframe_t **tracks,
|
||||||
|
uint16_t *trackCounts,
|
||||||
|
keyframesetcallback_t *callbacks,
|
||||||
|
void **users,
|
||||||
|
uint16_t trackCount,
|
||||||
|
void *user
|
||||||
|
) {
|
||||||
|
assertNotNull(set, "Keyframe set pointer cannot be null.");
|
||||||
|
assertNotNull(tracks, "Tracks pointer cannot be null.");
|
||||||
|
assertNotNull(trackCounts, "Track counts pointer cannot be null.");
|
||||||
|
assertTrue(trackCount > 0, "Track count must be more than 0.");
|
||||||
|
|
||||||
|
set->tracks = tracks;
|
||||||
|
set->trackCounts = trackCounts;
|
||||||
|
set->trackCount = trackCount;
|
||||||
|
set->callbacks = callbacks;
|
||||||
|
set->users = users;
|
||||||
|
set->user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t keyframeSetGetValue(
|
||||||
|
keyframeset_t *set,
|
||||||
|
const uint16_t trackIndex,
|
||||||
|
const float_t time
|
||||||
|
) {
|
||||||
|
assertNotNull(set, "Keyframe set pointer cannot be null.");
|
||||||
|
assertTrue(trackIndex < set->trackCount, "Track index out of bounds.");
|
||||||
|
|
||||||
|
return keyframeGetValue(
|
||||||
|
set->tracks[trackIndex], set->trackCounts[trackIndex], time
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyframeSetGetValues(
|
||||||
|
keyframeset_t *set,
|
||||||
|
const float_t time,
|
||||||
|
float_t *outValues
|
||||||
|
) {
|
||||||
|
assertNotNull(set, "Keyframe set pointer cannot be null.");
|
||||||
|
assertNotNull(outValues, "Output values pointer cannot be null.");
|
||||||
|
|
||||||
|
for(uint16_t i = 0; i < set->trackCount; i++) {
|
||||||
|
outValues[i] = keyframeGetValue(set->tracks[i], set->trackCounts[i], time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t keyframeSetGetDuration(keyframeset_t *set) {
|
||||||
|
assertNotNull(set, "Keyframe set pointer cannot be null.");
|
||||||
|
|
||||||
|
float_t duration = 0.0f;
|
||||||
|
for(uint16_t i = 0; i < set->trackCount; i++) {
|
||||||
|
float_t trackDuration = set->tracks[i][set->trackCounts[i] - 1].time;
|
||||||
|
if(trackDuration > duration) duration = trackDuration;
|
||||||
|
}
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyframeSetFireCallback(keyframeset_t *set, const uint16_t trackIndex) {
|
||||||
|
assertNotNull(set, "Keyframe set pointer cannot be null.");
|
||||||
|
assertTrue(trackIndex < set->trackCount, "Track index out of bounds.");
|
||||||
|
|
||||||
|
if(!set->callbacks || !set->callbacks[trackIndex]) return;
|
||||||
|
set->callbacks[trackIndex](
|
||||||
|
set, trackIndex, set->users ? set->users[trackIndex] : NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
// 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 keyframeset_t keyframeset_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback associated with one track of a keyframe set (see
|
||||||
|
* keyframeSetFireCallback()).
|
||||||
|
*
|
||||||
|
* @param set The keyframe set the track belongs to.
|
||||||
|
* @param trackIndex The track this callback is registered for.
|
||||||
|
* @param user The per-track user pointer passed to keyframeSetInit().
|
||||||
|
*/
|
||||||
|
typedef void (*keyframesetcallback_t)(
|
||||||
|
keyframeset_t *set,
|
||||||
|
const uint16_t trackIndex,
|
||||||
|
void *user
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A group of N parallel keyframe tracks (e.g. one per animated channel --
|
||||||
|
* position.x/y/z, bone rotations, etc.) sharing a single timeline. Each
|
||||||
|
* track is independent: its own keyframe array and count, evaluated at
|
||||||
|
* whatever time is asked for.
|
||||||
|
*/
|
||||||
|
typedef struct keyframeset_t {
|
||||||
|
/** Caller-owned array of trackCount keyframe_t arrays. */
|
||||||
|
keyframe_t **tracks;
|
||||||
|
/** Caller-owned array of trackCount counts, one per entry in tracks. */
|
||||||
|
uint16_t *trackCounts;
|
||||||
|
uint16_t trackCount;
|
||||||
|
|
||||||
|
/** Caller-owned array of trackCount callbacks, one per track. Entries
|
||||||
|
* (or the whole array) may be NULL for tracks with no callback. */
|
||||||
|
keyframesetcallback_t *callbacks;
|
||||||
|
/** Caller-owned array of trackCount user pointers, one per track,
|
||||||
|
* passed to that track's callbacks[] entry. May be NULL. */
|
||||||
|
void **users;
|
||||||
|
/** Extra user data for the set as a whole, not tied to any one track. */
|
||||||
|
void *user;
|
||||||
|
} keyframeset_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a keyframe set. None of the passed-in arrays (or the
|
||||||
|
* keyframe_t arrays tracks points to) are copied -- they must outlive
|
||||||
|
* this keyframeset_t.
|
||||||
|
*
|
||||||
|
* @param set The keyframe set to initialize.
|
||||||
|
* @param tracks Array of trackCount keyframe_t arrays.
|
||||||
|
* @param trackCounts Array of trackCount keyframe counts, matching tracks.
|
||||||
|
* @param callbacks Array of trackCount callbacks, one per track, or NULL
|
||||||
|
* if no track has one.
|
||||||
|
* @param users Array of trackCount user pointers, matching callbacks, or
|
||||||
|
* NULL.
|
||||||
|
* @param trackCount The number of tracks.
|
||||||
|
* @param user Extra user data for the set as a whole; may be NULL.
|
||||||
|
*/
|
||||||
|
void keyframeSetInit(
|
||||||
|
keyframeset_t *set,
|
||||||
|
keyframe_t **tracks,
|
||||||
|
uint16_t *trackCounts,
|
||||||
|
keyframesetcallback_t *callbacks,
|
||||||
|
void **users,
|
||||||
|
uint16_t trackCount,
|
||||||
|
void *user
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of a single track at a given time.
|
||||||
|
*
|
||||||
|
* @param set The keyframe set to evaluate.
|
||||||
|
* @param trackIndex The track to evaluate, in [0, set->trackCount).
|
||||||
|
* @param time The time at which to get the value, in seconds.
|
||||||
|
* @return The interpolated value of that track at the given time.
|
||||||
|
*/
|
||||||
|
float_t keyframeSetGetValue(
|
||||||
|
keyframeset_t *set,
|
||||||
|
const uint16_t trackIndex,
|
||||||
|
const float_t time
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of every track at a given time.
|
||||||
|
*
|
||||||
|
* @param set The keyframe set to evaluate.
|
||||||
|
* @param time The time at which to get the values, in seconds.
|
||||||
|
* @param outValues Destination array of at least set->trackCount floats.
|
||||||
|
*/
|
||||||
|
void keyframeSetGetValues(
|
||||||
|
keyframeset_t *set,
|
||||||
|
const float_t time,
|
||||||
|
float_t *outValues
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set's duration: the latest final-keyframe time across every
|
||||||
|
* track, i.e. how long it takes for every track to finish.
|
||||||
|
*
|
||||||
|
* @param set The keyframe set to measure.
|
||||||
|
* @return The set's duration, in seconds.
|
||||||
|
*/
|
||||||
|
float_t keyframeSetGetDuration(keyframeset_t *set);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invokes a track's callback, if it (and its callbacks array) is set.
|
||||||
|
* No-op otherwise.
|
||||||
|
*
|
||||||
|
* @param set The keyframe set the track belongs to.
|
||||||
|
* @param trackIndex The track whose callback to invoke.
|
||||||
|
*/
|
||||||
|
void keyframeSetFireCallback(keyframeset_t *set, const uint16_t trackIndex);
|
||||||
@@ -8,6 +8,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
|
// Release-style CMake configs (Release, RelWithDebInfo, MinSizeRel) define
|
||||||
|
// NDEBUG automatically; fake assertions there rather than requiring every
|
||||||
|
// platform's CMakeLists to set DUSK_ASSERTIONS_FAKED itself.
|
||||||
|
#if defined(NDEBUG) && !defined(DUSK_ASSERTIONS_FAKED)
|
||||||
|
#define DUSK_ASSERTIONS_FAKED
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DUSK_TEST_ASSERT
|
#ifdef DUSK_TEST_ASSERT
|
||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
|
|
||||||
@@ -22,8 +29,6 @@
|
|||||||
#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.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
asset.c
|
asset.c
|
||||||
assetdsk.c
|
assetbatch.c
|
||||||
assetfile.c
|
assetfile.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+6
-23
@@ -19,8 +19,6 @@ asset_t ASSET;
|
|||||||
errorret_t assetInit(void) {
|
errorret_t assetInit(void) {
|
||||||
memoryZero(&ASSET, sizeof(asset_t));
|
memoryZero(&ASSET, sizeof(asset_t));
|
||||||
|
|
||||||
threadMutexInit(&ASSET.zipLock);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
||||||
threadMutexInit(&ASSET.loading[i].mutex);
|
threadMutexInit(&ASSET.loading[i].mutex);
|
||||||
}
|
}
|
||||||
@@ -37,10 +35,9 @@ errorret_t assetInit(void) {
|
|||||||
bool_t assetFileExists(const char_t *filename) {
|
bool_t assetFileExists(const char_t *filename) {
|
||||||
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
||||||
|
|
||||||
threadMutexLock(&ASSET.zipLock);
|
zip_int64_t idx = zip_name_locate(ASSET.zip, filename, 0);
|
||||||
bool_t found = zip_name_locate(ASSET.zip, filename, 0) >= 0;
|
if(idx < 0) return false;
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
return true;
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assetentry_t * assetGetEntry(
|
assetentry_t * assetGetEntry(
|
||||||
@@ -120,15 +117,6 @@ errorret_t assetRequireLoaded(assetentry_t *entry) {
|
|||||||
assetEntryLock(entry);
|
assetEntryLock(entry);
|
||||||
|
|
||||||
while(entry->state != ASSET_ENTRY_STATE_LOADED) {
|
while(entry->state != ASSET_ENTRY_STATE_LOADED) {
|
||||||
// A failed load transitions to ERROR, not LOADED - without this check
|
|
||||||
// this loop spins forever on any load failure (assetUpdate() itself
|
|
||||||
// still returns OK, since a single asset failing isn't meant to halt
|
|
||||||
// the whole update loop - see its ASSET_ENTRY_STATE_ERROR handling).
|
|
||||||
if(entry->state == ASSET_ENTRY_STATE_ERROR) {
|
|
||||||
assetEntryUnlock(entry);
|
|
||||||
errorThrow("Failed to load asset: %s", entry->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
errorret_t ret = assetUpdate();
|
errorret_t ret = assetUpdate();
|
||||||
if(errorIsNotOk(ret)) {
|
if(errorIsNotOk(ret)) {
|
||||||
@@ -334,9 +322,7 @@ errorret_t assetUpdate(void) {
|
|||||||
} else if(loading->entry->state == ASSET_ENTRY_STATE_LOADED) {
|
} else if(loading->entry->state == ASSET_ENTRY_STATE_LOADED) {
|
||||||
assetentry_t *loadedEntry = loading->entry;
|
assetentry_t *loadedEntry = loading->entry;
|
||||||
loading->entry = NULL;
|
loading->entry = NULL;
|
||||||
if(loadedEntry->onLoaded) {
|
eventInvoke(&loadedEntry->onLoaded, loadedEntry);
|
||||||
loadedEntry->onLoaded(loadedEntry, loadedEntry->onLoadedUser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loading++;
|
loading++;
|
||||||
@@ -360,10 +346,8 @@ errorret_t assetUpdate(void) {
|
|||||||
assetentry_t *errEntry = loading->entry;
|
assetentry_t *errEntry = loading->entry;
|
||||||
loading->entry = NULL;
|
loading->entry = NULL;
|
||||||
threadMutexUnlock(&loading->mutex);
|
threadMutexUnlock(&loading->mutex);
|
||||||
if(errEntry->onError) {
|
eventInvoke(&errEntry->onError, errEntry);
|
||||||
errEntry->onError(errEntry, errEntry->onErrorUser);
|
errorThrow("Failed to load asset asynchronously.");
|
||||||
}
|
|
||||||
loading++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,6 +434,5 @@ errorret_t assetDispose(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorChain(assetDisposePlatform());
|
errorChain(assetDisposePlatform());
|
||||||
threadMutexDispose(&ASSET.zipLock);
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -26,40 +26,10 @@
|
|||||||
#define ASSET_LOADING_COUNT_MAX 10
|
#define ASSET_LOADING_COUNT_MAX 10
|
||||||
#define ASSET_ENTRY_COUNT_MAX 64
|
#define ASSET_ENTRY_COUNT_MAX 64
|
||||||
|
|
||||||
#define ASSET_BASE_DIRECTORY_MAX 256
|
|
||||||
|
|
||||||
typedef struct asset_s {
|
typedef struct asset_s {
|
||||||
// The dusk.dsk archive - a single uncompressed (ZIP_STORED) zip, so
|
|
||||||
// every entry gets the reliable repeated seeking/re-opening that
|
|
||||||
// libzip only supports reliably for uncompressed entries (locale
|
|
||||||
// strings, MP3 loop restarts, etc.).
|
|
||||||
zip_t *zip;
|
zip_t *zip;
|
||||||
|
|
||||||
// Directory dusk.dsk was actually found/opened in (on PSP, the directory
|
|
||||||
// EBOOT.PBP lives in, since dusk.dsk is embedded inside it rather than a
|
|
||||||
// loose file) - populated by each platform's own assetInitXxx() once it
|
|
||||||
// locates the file. Save devices that persist to a real filesystem path
|
|
||||||
// (Linux, PSP, Wii SD) use this as their base directory instead of a
|
|
||||||
// separate hardcoded location, so saves live next to wherever the game
|
|
||||||
// itself was actually launched from rather than some unrelated fixed
|
|
||||||
// path. Not meaningful for devices with no filesystem-path concept at
|
|
||||||
// all (GameCube/Wii memory card, Wii NAND's ISFS namespace).
|
|
||||||
char_t baseDirectory[ASSET_BASE_DIRECTORY_MAX];
|
|
||||||
|
|
||||||
assetplatform_t platform;
|
assetplatform_t platform;
|
||||||
|
|
||||||
// Guards every libzip call against ASSET.zip (zip_fopen,
|
|
||||||
// zip_fread, zip_fclose, zip_fseek, zip_stat, zip_name_locate - see
|
|
||||||
// assetfile.c/assetFileExists). libzip is documented as not thread-safe,
|
|
||||||
// and this asset system genuinely calls it from multiple real threads at
|
|
||||||
// once (main thread, the background load thread below, and - on
|
|
||||||
// platforms that stream PCM from an asset on their own thread, like PSP
|
|
||||||
// - an audio feeder thread too). Confirmed necessary on real PSP
|
|
||||||
// hardware: without this lock, concurrent zip_fopen/zip_fread calls from
|
|
||||||
// different threads corrupted reads (EINVAL, then zlib data errors) once
|
|
||||||
// dusk.dsk stopped being read entirely into memory up front.
|
|
||||||
threadmutex_t zipLock;
|
|
||||||
|
|
||||||
// Background loading thread.
|
// Background loading thread.
|
||||||
thread_t loadThread;
|
thread_t loadThread;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/**
|
||||||
|
* 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);
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetdsk.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/endian.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
errorret_t assetDskParseHeader(
|
|
||||||
const uint8_t *bytes,
|
|
||||||
const size_t bytesSize,
|
|
||||||
assetdskheader_t *outHeader
|
|
||||||
) {
|
|
||||||
assertNotNull(bytes, "Bytes cannot be NULL.");
|
|
||||||
assertNotNull(outHeader, "Out header cannot be NULL.");
|
|
||||||
|
|
||||||
if(bytesSize < ASSET_DSK_HEADER_SIZE) {
|
|
||||||
errorThrow("dusk.dsk header is truncated.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(memoryCompare(bytes, ASSET_DSK_MAGIC, ASSET_DSK_MAGIC_SIZE) != 0) {
|
|
||||||
errorThrow("dusk.dsk has an invalid magic header.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Every field is a little-endian uint32_t regardless of host - convert
|
|
||||||
// to host order (a no-op on little-endian hosts, a real byteswap on
|
|
||||||
// Dolphin's big-endian PowerPC).
|
|
||||||
uint32_t fields[3];
|
|
||||||
memoryCopy(fields, bytes + ASSET_DSK_MAGIC_SIZE, sizeof(fields));
|
|
||||||
for(uint8_t i = 0; i < 3; i++) {
|
|
||||||
fields[i] = endianLittleToHost32(fields[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t version = fields[0];
|
|
||||||
if(version != ASSET_DSK_VERSION) {
|
|
||||||
errorThrow("dusk.dsk has an unsupported version: %u", version);
|
|
||||||
}
|
|
||||||
|
|
||||||
outHeader->size = fields[1];
|
|
||||||
outHeader->checksum = fields[2];
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetDskOpenFromPath(
|
|
||||||
const char_t *path,
|
|
||||||
zip_t **outZip
|
|
||||||
) {
|
|
||||||
errorChain(assetDskOpenFromPathRange(path, 0, SIZE_MAX, outZip));
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetDskOpenFromPathRange(
|
|
||||||
const char_t *path,
|
|
||||||
const size_t baseOffset,
|
|
||||||
const size_t baseSize,
|
|
||||||
zip_t **outZip
|
|
||||||
) {
|
|
||||||
assertNotNull(path, "Path cannot be NULL.");
|
|
||||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
|
||||||
|
|
||||||
*outZip = NULL;
|
|
||||||
|
|
||||||
FILE *headerFile = fopen(path, "rb");
|
|
||||||
if(headerFile == NULL) {
|
|
||||||
errorThrow("Failed to open dusk.dsk: %s", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fseek(headerFile, (long) baseOffset, SEEK_SET) != 0) {
|
|
||||||
fclose(headerFile);
|
|
||||||
errorThrow("Failed to seek to dusk.dsk range in file: %s", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t headerBytes[ASSET_DSK_HEADER_SIZE];
|
|
||||||
size_t headerRead = fread(headerBytes, 1, sizeof(headerBytes), headerFile);
|
|
||||||
fclose(headerFile);
|
|
||||||
if(headerRead != sizeof(headerBytes)) {
|
|
||||||
errorThrow("Failed to read dusk.dsk header: %s", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
assetdskheader_t header;
|
|
||||||
errorChain(assetDskParseHeader(headerBytes, sizeof(headerBytes), &header));
|
|
||||||
|
|
||||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > baseSize) {
|
|
||||||
errorThrow("dusk.dsk header describes a range beyond its containing file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_error_t zipError;
|
|
||||||
zip_error_init(&zipError);
|
|
||||||
|
|
||||||
zip_source_t *source = zip_source_file_create(
|
|
||||||
path,
|
|
||||||
(zip_uint64_t) (baseOffset + ASSET_DSK_HEADER_SIZE),
|
|
||||||
(zip_int64_t) header.size,
|
|
||||||
&zipError
|
|
||||||
);
|
|
||||||
if(source == NULL) {
|
|
||||||
errorThrow(
|
|
||||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
|
||||||
if(*outZip == NULL) {
|
|
||||||
zip_source_free(source);
|
|
||||||
errorThrow(
|
|
||||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetDskOpenFromBuffer(
|
|
||||||
uint8_t *buffer,
|
|
||||||
const size_t bufferSize,
|
|
||||||
zip_t **outZip
|
|
||||||
) {
|
|
||||||
assertNotNull(buffer, "Buffer cannot be NULL.");
|
|
||||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
|
||||||
|
|
||||||
*outZip = NULL;
|
|
||||||
|
|
||||||
assetdskheader_t header;
|
|
||||||
errorChain(assetDskParseHeader(buffer, bufferSize, &header));
|
|
||||||
|
|
||||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > bufferSize) {
|
|
||||||
errorThrow("dusk.dsk header describes a range beyond the buffer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *data = buffer + ASSET_DSK_HEADER_SIZE;
|
|
||||||
uint32_t checksum = (uint32_t) crc32(0L, data, (uInt) header.size);
|
|
||||||
if(checksum != header.checksum) {
|
|
||||||
errorThrow("dusk.dsk archive failed checksum verification.");
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_error_t zipError;
|
|
||||||
zip_error_init(&zipError);
|
|
||||||
|
|
||||||
// freep=0 - this is a non-owning window into the same caller-owned
|
|
||||||
// buffer, not an independent allocation libzip should free.
|
|
||||||
zip_source_t *source = zip_source_buffer_create(
|
|
||||||
data, header.size, 0, &zipError
|
|
||||||
);
|
|
||||||
if(source == NULL) {
|
|
||||||
errorThrow(
|
|
||||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
|
||||||
if(*outZip == NULL) {
|
|
||||||
zip_source_free(source);
|
|
||||||
errorThrow(
|
|
||||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "error/error.h"
|
|
||||||
#include <zip.h>
|
|
||||||
|
|
||||||
// "DSK2" - distinct from a plain zip's "PK\x03\x04" so a stray plain zip
|
|
||||||
// never gets misread as a valid dusk.dsk.
|
|
||||||
#define ASSET_DSK_MAGIC_SIZE 4
|
|
||||||
#define ASSET_DSK_MAGIC "DSK2"
|
|
||||||
#define ASSET_DSK_VERSION 2
|
|
||||||
|
|
||||||
// magic(4) + version(4) + size(4) + checksum(4), all little-endian
|
|
||||||
// regardless of host - see assetDskParseHeader. The zip archive itself
|
|
||||||
// starts immediately after, at ASSET_DSK_HEADER_SIZE.
|
|
||||||
#define ASSET_DSK_HEADER_SIZE 16
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parsed dusk.dsk (DSK2 format) header. dusk.dsk is a single uncompressed
|
|
||||||
* (ZIP_STORED) zip archive (see tools/asset/pack) rather than DEFLATEd -
|
|
||||||
* the bulk of what's packed (audio, images) is already compressed at the
|
|
||||||
* file level, so DEFLATE-ing the whole archive on top buys negligible
|
|
||||||
* space for real CPU cost, and every entry gets the reliable repeated
|
|
||||||
* seeking/re-opening that libzip only supports for uncompressed entries
|
|
||||||
* (locale line-by-line reads, MP3 loop restarts, etc.) instead of just a
|
|
||||||
* hand-picked subset of files.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint32_t size;
|
|
||||||
uint32_t checksum;
|
|
||||||
} assetdskheader_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a DSK2 header from a raw byte buffer (at least
|
|
||||||
* ASSET_DSK_HEADER_SIZE bytes), validating the magic/version and
|
|
||||||
* byte-swapping the little-endian fields to host order.
|
|
||||||
*
|
|
||||||
* @param bytes Buffer containing the header (and beyond).
|
|
||||||
* @param bytesSize Number of bytes available at `bytes`.
|
|
||||||
* @param outHeader Filled with the parsed header on success.
|
|
||||||
* @return OK on success, error if too short, bad magic, or unsupported version.
|
|
||||||
*/
|
|
||||||
errorret_t assetDskParseHeader(
|
|
||||||
const uint8_t *bytes,
|
|
||||||
const size_t bytesSize,
|
|
||||||
assetdskheader_t *outHeader
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the dusk.dsk archive given a filesystem path, using a lazy/
|
|
||||||
* windowed file-backed zip source - no more memory used than the
|
|
||||||
* existing per-platform small read buffers, matching the memory
|
|
||||||
* characteristics of a plain zip_open() on the whole file. The checksum
|
|
||||||
* is intentionally not verified here since doing so would require
|
|
||||||
* reading the whole (potentially large) archive just to compute it.
|
|
||||||
*
|
|
||||||
* See assetDskOpenFromPathRange() for the case where the DSK2 blob isn't
|
|
||||||
* the whole file (e.g. embedded inside another container).
|
|
||||||
*
|
|
||||||
* @param path Filesystem path to the dusk.dsk file.
|
|
||||||
* @param outZip Set to the opened archive on success.
|
|
||||||
* @return OK on success, error if the file is missing, too short, has a
|
|
||||||
* bad header, or the archive fails to open.
|
|
||||||
*/
|
|
||||||
errorret_t assetDskOpenFromPath(
|
|
||||||
const char_t *path,
|
|
||||||
zip_t **outZip
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as assetDskOpenFromPath(), but the DSK2 blob doesn't start at the
|
|
||||||
* beginning of `path` - it's a byte range embedded inside a larger
|
|
||||||
* container file (e.g. the PSAR region of an EBOOT.PBP). Every offset the
|
|
||||||
* header describes is relative to `baseOffset`; `baseSize` bounds them
|
|
||||||
* (the size of the embedded blob, not the whole container file) - pass
|
|
||||||
* SIZE_MAX to skip that check when the caller doesn't know/care.
|
|
||||||
*
|
|
||||||
* @param path Filesystem path to the container file.
|
|
||||||
* @param baseOffset Byte offset within `path` where the DSK2 blob starts.
|
|
||||||
* @param baseSize Number of bytes available at `baseOffset`.
|
|
||||||
* @param outZip Set to the opened archive on success.
|
|
||||||
* @return OK on success, error if the file is missing, too short, has a
|
|
||||||
* bad header, or the archive fails to open.
|
|
||||||
*/
|
|
||||||
errorret_t assetDskOpenFromPathRange(
|
|
||||||
const char_t *path,
|
|
||||||
const size_t baseOffset,
|
|
||||||
const size_t baseSize,
|
|
||||||
zip_t **outZip
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the dusk.dsk archive already fully resident in memory (e.g. a
|
|
||||||
* PSAR embedded in an EBOOT.PBP, or an ISO-embedded file already read via
|
|
||||||
* DVD_ReadAbs - platforms that already buffer the whole file for reasons
|
|
||||||
* unrelated to this format). The returned archive doesn't take ownership
|
|
||||||
* of `buffer` (it's opened as a non-owning sub-range of it) - the caller
|
|
||||||
* remains responsible for freeing it, and must keep it alive for as long
|
|
||||||
* as the archive stays open. Verifies the checksum, since the bytes are
|
|
||||||
* already resident.
|
|
||||||
*
|
|
||||||
* @param buffer The whole dusk.dsk file's bytes.
|
|
||||||
* @param bufferSize Number of bytes at `buffer`.
|
|
||||||
* @param outZip Set to the opened archive on success.
|
|
||||||
* @return OK on success, error if too short, has a bad header/checksum, or
|
|
||||||
* the archive fails to open.
|
|
||||||
*/
|
|
||||||
errorret_t assetDskOpenFromBuffer(
|
|
||||||
uint8_t *buffer,
|
|
||||||
const size_t bufferSize,
|
|
||||||
zip_t **outZip
|
|
||||||
);
|
|
||||||
+14
-70
@@ -24,11 +24,9 @@ errorret_t assetFileInit(
|
|||||||
file->params = params;
|
file->params = params;
|
||||||
file->output = output;
|
file->output = output;
|
||||||
|
|
||||||
|
// Stat the file
|
||||||
zip_stat_init(&file->stat);
|
zip_stat_init(&file->stat);
|
||||||
threadMutexLock(&ASSET.zipLock);
|
if(!zip_stat(ASSET.zip, filename, 0, &file->stat) == 0) {
|
||||||
int statResult = zip_stat(ASSET.zip, filename, 0, &file->stat);
|
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
|
||||||
if(statResult != 0) {
|
|
||||||
errorThrow("Failed to stat asset file: %s", filename);
|
errorThrow("Failed to stat asset file: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,25 +47,6 @@ errorret_t assetFileRewind(assetfile_t *file) {
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefer seeking within the still-open handle over closing and
|
|
||||||
// re-opening it. Repeatedly closing/re-opening the same compressed zip
|
|
||||||
// entry (once per rewind - e.g. once per locale string lookup) was
|
|
||||||
// confirmed unreliable on at least one platform's zip backend, silently
|
|
||||||
// skipping ranges of the decompressed content on some re-opens after
|
|
||||||
// the first. A real seek avoids that failure mode entirely, with no
|
|
||||||
// extra memory cost over the close+reopen fallback.
|
|
||||||
threadMutexLock(&ASSET.zipLock);
|
|
||||||
bool_t seekable = zip_file_is_seekable(file->zipFile);
|
|
||||||
int seekResult = seekable ? zip_fseek(file->zipFile, 0, SEEK_SET) : -1;
|
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
|
||||||
if(seekable) {
|
|
||||||
if(seekResult != 0) {
|
|
||||||
errorThrow("Failed to seek asset file: %s", file->filename);
|
|
||||||
}
|
|
||||||
file->position = 0;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileClose(file));
|
errorChain(assetFileClose(file));
|
||||||
errorChain(assetFileOpen(file));
|
errorChain(assetFileOpen(file));
|
||||||
errorOk();
|
errorOk();
|
||||||
@@ -76,11 +55,10 @@ errorret_t assetFileRewind(assetfile_t *file) {
|
|||||||
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.");
|
assertNotNull(file->filename, "Asset file filename cannot be NULL.");
|
||||||
|
assertNotNull(ASSET.zip, "Asset zip cannot be NULL.");
|
||||||
assertNull(file->zipFile, "Asset file already open.");
|
assertNull(file->zipFile, "Asset file already open.");
|
||||||
|
|
||||||
threadMutexLock(&ASSET.zipLock);
|
|
||||||
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
|
||||||
if(file->zipFile == NULL) {
|
if(file->zipFile == NULL) {
|
||||||
errorThrow("Failed to open asset file: %s", file->filename);
|
errorThrow("Failed to open asset file: %s", file->filename);
|
||||||
}
|
}
|
||||||
@@ -101,52 +79,21 @@ errorret_t assetFileRead(
|
|||||||
uint8_t tempBuffer[256];
|
uint8_t tempBuffer[256];
|
||||||
while(bytesRemaining > 0) {
|
while(bytesRemaining > 0) {
|
||||||
size_t chunkSize = mathMin(bytesRemaining, sizeof(tempBuffer));
|
size_t chunkSize = mathMin(bytesRemaining, sizeof(tempBuffer));
|
||||||
// The recursive call below already advances file->position by
|
|
||||||
// chunkSize (the non-NULL branch does this itself) - do not also
|
|
||||||
// advance it here, or every skip ends up double-counted.
|
|
||||||
errorChain(assetFileRead(file, tempBuffer, chunkSize));
|
errorChain(assetFileRead(file, tempBuffer, chunkSize));
|
||||||
|
file->position += chunkSize;
|
||||||
bytesRemaining -= chunkSize;
|
bytesRemaining -= chunkSize;
|
||||||
}
|
}
|
||||||
file->lastRead = bufferSize;
|
file->lastRead = bufferSize;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some zip_fread() implementations (seen on PSP) reject a single call
|
// I assume zip_fread takes buffer NULL for skipping?
|
||||||
// asking for the entire (potentially large) file at once with EINVAL;
|
zip_int64_t bytesRead = zip_fread(file->zipFile, buffer, bufferSize);
|
||||||
// the line reader above only ever asks for up to 1024 bytes per call and
|
if(bytesRead < 0) {
|
||||||
// works fine, so read in bounded chunks here too.
|
errorThrow("Failed to read from asset file: %s", file->filename);
|
||||||
size_t totalRead = 0;
|
|
||||||
uint8_t *dest = (uint8_t *)buffer;
|
|
||||||
while(totalRead < bufferSize) {
|
|
||||||
size_t chunkSize = mathMin(
|
|
||||||
bufferSize - totalRead, ASSET_FILE_READ_CHUNK_MAX
|
|
||||||
);
|
|
||||||
threadMutexLock(&ASSET.zipLock);
|
|
||||||
zip_int64_t bytesRead = zip_fread(
|
|
||||||
file->zipFile, dest + totalRead, chunkSize
|
|
||||||
);
|
|
||||||
errorret_t readError = errorOkImpl();
|
|
||||||
if(bytesRead < 0) {
|
|
||||||
// Built (not thrown) while still holding the lock, so
|
|
||||||
// zip_file_strerror() reads the just-failed zipFile's error state
|
|
||||||
// before another thread can touch it - errorThrow() itself isn't
|
|
||||||
// used here since it returns immediately, which would leave
|
|
||||||
// ASSET.zipLock held forever.
|
|
||||||
readError = errorThrowImpl(
|
|
||||||
&ERROR_STATE, ERROR_NOT_OK, __FILE__, __func__, __LINE__,
|
|
||||||
"Failed to read from asset file: %s (%s)",
|
|
||||||
file->filename, zip_file_strerror(file->zipFile)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
|
||||||
if(errorIsNotOk(readError)) {
|
|
||||||
errorChain(readError);
|
|
||||||
}
|
|
||||||
if(bytesRead == 0) break;
|
|
||||||
totalRead += (size_t)bytesRead;
|
|
||||||
}
|
}
|
||||||
file->position += totalRead;
|
file->position += bytesRead;
|
||||||
file->lastRead = totalRead;
|
file->lastRead = bytesRead;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +101,7 @@ 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->zipFile, "Asset file must be opened before closing.");
|
||||||
|
|
||||||
threadMutexLock(&ASSET.zipLock);
|
if(zip_fclose(file->zipFile) != 0) {
|
||||||
int closeResult = zip_fclose(file->zipFile);
|
|
||||||
threadMutexUnlock(&ASSET.zipLock);
|
|
||||||
if(closeResult != 0) {
|
|
||||||
errorThrow("Failed to close asset file: %s", file->filename);
|
errorThrow("Failed to close asset file: %s", file->filename);
|
||||||
}
|
}
|
||||||
file->zipFile = NULL;
|
file->zipFile = NULL;
|
||||||
@@ -257,7 +201,7 @@ const uint8_t *assetFileLineReaderUnreadPtr(
|
|||||||
return reader->readBuffer + reader->bufferStart;
|
return reader->readBuffer + reader->bufferStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetFileLineReaderAppend(
|
static errorret_t assetFileLineReaderAppend(
|
||||||
assetfilelinereader_t *reader,
|
assetfilelinereader_t *reader,
|
||||||
const uint8_t *src,
|
const uint8_t *src,
|
||||||
size_t srcLength
|
size_t srcLength
|
||||||
@@ -279,7 +223,7 @@ errorret_t assetFileLineReaderAppend(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
static void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
||||||
assertNotNull(reader, "Reader cannot be NULL.");
|
assertNotNull(reader, "Reader cannot be NULL.");
|
||||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
||||||
assertTrue(
|
assertTrue(
|
||||||
@@ -289,7 +233,7 @@ void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
|||||||
reader->outBuffer[reader->lineLength] = '\0';
|
reader->outBuffer[reader->lineLength] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t assetFileLineReaderFindNewline(
|
static ssize_t assetFileLineReaderFindNewline(
|
||||||
const assetfilelinereader_t *reader
|
const assetfilelinereader_t *reader
|
||||||
) {
|
) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|||||||
@@ -9,13 +9,7 @@
|
|||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
|
|
||||||
#define ASSET_FILE_NAME_MAX 128
|
#define ASSET_FILE_NAME_MAX 48
|
||||||
|
|
||||||
// Max bytes requested per zip_fread() call in assetFileRead(). Some
|
|
||||||
// zip_fread() implementations (seen on PSP) reject a single call asking
|
|
||||||
// for very large amounts of data at once; the locale line reader has
|
|
||||||
// always used 1024-byte reads successfully, so that's the proven-safe cap.
|
|
||||||
#define ASSET_FILE_READ_CHUNK_MAX 1024
|
|
||||||
|
|
||||||
typedef struct assetfile_s assetfile_t;
|
typedef struct assetfile_s assetfile_t;
|
||||||
|
|
||||||
@@ -150,67 +144,10 @@ void assetFileLineReaderInit(
|
|||||||
const size_t outBufferSize
|
const size_t outBufferSize
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of bytes still unread in the line reader's read buffer.
|
|
||||||
*
|
|
||||||
* @param reader The line reader to check.
|
|
||||||
* @return Number of unread bytes remaining in the read buffer.
|
|
||||||
*/
|
|
||||||
size_t assetFileLineReaderUnreadBytes(const assetfilelinereader_t *reader);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a pointer to the first unread byte in the line reader's read
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* @param reader The line reader to check.
|
|
||||||
* @return Pointer to the first unread byte.
|
|
||||||
*/
|
|
||||||
const uint8_t *assetFileLineReaderUnreadPtr(
|
|
||||||
const assetfilelinereader_t *reader
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends src to the line reader's current line buffer, growing lineLength.
|
|
||||||
*
|
|
||||||
* @param reader The line reader whose out buffer to append to.
|
|
||||||
* @param src Bytes to append.
|
|
||||||
* @param srcLength Number of bytes in src.
|
|
||||||
* @return Error state if any (the line would exceed the output buffer).
|
|
||||||
*/
|
|
||||||
errorret_t assetFileLineReaderAppend(
|
|
||||||
assetfilelinereader_t *reader,
|
|
||||||
const uint8_t *src,
|
|
||||||
size_t srcLength
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Null-terminates the line reader's current line buffer at lineLength.
|
|
||||||
*
|
|
||||||
* @param reader The line reader whose out buffer to terminate.
|
|
||||||
*/
|
|
||||||
void assetFileLineReaderTerminate(assetfilelinereader_t *reader);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the line reader's unread buffered bytes for a newline character.
|
|
||||||
*
|
|
||||||
* @param reader The line reader to search.
|
|
||||||
* @return The index of the newline within readBuffer, or -1 if not found.
|
|
||||||
*/
|
|
||||||
ssize_t assetFileLineReaderFindNewline(const assetfilelinereader_t *reader);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refills the line reader's read buffer from the underlying file once its
|
|
||||||
* buffered bytes are fully consumed. A no-op once the file is at EOF.
|
|
||||||
*
|
|
||||||
* @param reader The line reader to refill.
|
|
||||||
* @return Error state if any.
|
|
||||||
*/
|
|
||||||
errorret_t assetFileLineReaderFill(assetfilelinereader_t *reader);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the next line from the asset file into the line buffer. The line
|
* 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.
|
* buffer is null-terminated and does not include the newline character.
|
||||||
*
|
*
|
||||||
* @param reader The line reader to read from.
|
* @param reader The line reader to read from.
|
||||||
* @return An error code if a failure occurs, or errorOk() if a line was read
|
* @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
|
* successfully. If the end of the file is reached, errorEndOfFile() is
|
||||||
|
|||||||
@@ -15,8 +15,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(locale)
|
add_subdirectory(locale)
|
||||||
add_subdirectory(json)
|
add_subdirectory(json)
|
||||||
add_subdirectory(chunk)
|
|
||||||
add_subdirectory(dmf)
|
add_subdirectory(dmf)
|
||||||
add_subdirectory(cutscene)
|
add_subdirectory(animation)
|
||||||
add_subdirectory(wav)
|
|
||||||
add_subdirectory(mp3)
|
|
||||||
+1
-1
@@ -5,5 +5,5 @@
|
|||||||
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
assetcutsceneloader.c
|
assetanimationloader.c
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "assetanimationloader.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "asset/loader/assetloading.h"
|
||||||
|
#include "asset/loader/assetentry.h"
|
||||||
|
|
||||||
|
errorret_t assetAnimationLoaderAsync(assetloading_t *loading) {
|
||||||
|
assertNotNull(loading, "Loading cannot be NULL");
|
||||||
|
assertNotMainThread("Async loader should not be on main thread.");
|
||||||
|
|
||||||
|
if(
|
||||||
|
loading->loading.animation.state != ASSET_ANIMATION_LOADING_STATE_READ_FILE
|
||||||
|
) {
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNull(loading->loading.animation.buffer, "Buffer already defined?");
|
||||||
|
|
||||||
|
assetfile_t *file = &loading->loading.animation.file;
|
||||||
|
assetLoaderErrorChain(
|
||||||
|
loading, assetFileInit(file, loading->entry->name, NULL, NULL)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(file->size > ASSET_ANIMATION_FILE_SIZE_MAX) {
|
||||||
|
assetLoaderErrorThrow(
|
||||||
|
loading, "Animation JSON exceeds maximum allowed size"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *buffer;
|
||||||
|
size_t size;
|
||||||
|
assetLoaderErrorChain(loading, assetFileReadEntire(file, &buffer, &size));
|
||||||
|
assetLoaderErrorChain(loading, assetFileDispose(file));
|
||||||
|
|
||||||
|
loading->loading.animation.buffer = buffer;
|
||||||
|
loading->loading.animation.size = size;
|
||||||
|
loading->loading.animation.state = ASSET_ANIMATION_LOADING_STATE_PARSE;
|
||||||
|
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t assetAnimationLoaderSync(assetloading_t *loading) {
|
||||||
|
assertNotNull(loading, "Loading cannot be NULL");
|
||||||
|
assertTrue(loading->type == ASSET_LOADER_TYPE_ANIMATION, "Invalid type.");
|
||||||
|
assertIsMainThread("Must be called from the main thread.");
|
||||||
|
|
||||||
|
switch(loading->loading.animation.state) {
|
||||||
|
case ASSET_ANIMATION_LOADING_STATE_INITIAL:
|
||||||
|
loading->loading.animation.state =
|
||||||
|
ASSET_ANIMATION_LOADING_STATE_READ_FILE;
|
||||||
|
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
||||||
|
errorOk();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ASSET_ANIMATION_LOADING_STATE_PARSE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *buffer = loading->loading.animation.buffer;
|
||||||
|
assertNotNull(buffer, "Animation buffer should have been loaded by now.");
|
||||||
|
|
||||||
|
yyjson_doc *doc = yyjson_read(
|
||||||
|
(char *)buffer,
|
||||||
|
loading->loading.animation.size,
|
||||||
|
YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
|
||||||
|
);
|
||||||
|
memoryFree(buffer);
|
||||||
|
loading->loading.animation.buffer = NULL;
|
||||||
|
|
||||||
|
if(!doc) assetLoaderErrorThrow(loading, "Failed to parse animation JSON");
|
||||||
|
|
||||||
|
yyjson_val *root = yyjson_doc_get_root(doc);
|
||||||
|
yyjson_val *channelsVal = yyjson_obj_get(root, "channels");
|
||||||
|
if(!channelsVal || !yyjson_is_arr(channelsVal)) {
|
||||||
|
yyjson_doc_free(doc);
|
||||||
|
assetLoaderErrorThrow(loading, "Animation JSON missing 'channels' array");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t channelCount = (uint16_t)yyjson_arr_size(channelsVal);
|
||||||
|
if(channelCount == 0) {
|
||||||
|
yyjson_doc_free(doc);
|
||||||
|
assetLoaderErrorThrow(loading, "Animation must have at least one channel");
|
||||||
|
}
|
||||||
|
|
||||||
|
keyframe_t **tracks = memoryAllocate(channelCount * sizeof(keyframe_t *));
|
||||||
|
uint16_t *trackCounts = memoryAllocate(channelCount * sizeof(uint16_t));
|
||||||
|
|
||||||
|
size_t idx, max;
|
||||||
|
yyjson_val *channelJson;
|
||||||
|
uint16_t parsed = 0;
|
||||||
|
yyjson_arr_foreach(channelsVal, idx, max, channelJson) {
|
||||||
|
keyframe_t *keyframes;
|
||||||
|
uint16_t count;
|
||||||
|
errorret_t ret =
|
||||||
|
assetAnimationParseChannel(channelJson, &keyframes, &count);
|
||||||
|
if(errorIsNotOk(ret)) {
|
||||||
|
assetAnimationFreeChannels(tracks, parsed);
|
||||||
|
memoryFree(trackCounts);
|
||||||
|
yyjson_doc_free(doc);
|
||||||
|
loading->entry->state = ASSET_ENTRY_STATE_ERROR;
|
||||||
|
errorChain(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
tracks[idx] = keyframes;
|
||||||
|
trackCounts[idx] = count;
|
||||||
|
parsed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
animationInit(
|
||||||
|
&loading->entry->data.animation, tracks, trackCounts, channelCount
|
||||||
|
);
|
||||||
|
|
||||||
|
yyjson_val *loopVal = yyjson_obj_get(root, "loop");
|
||||||
|
if(loopVal) loading->entry->data.animation.loop = yyjson_get_bool(loopVal);
|
||||||
|
|
||||||
|
yyjson_val *speedVal = yyjson_obj_get(root, "speed");
|
||||||
|
if(speedVal) {
|
||||||
|
loading->entry->data.animation.speed = (float_t)yyjson_get_num(speedVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
yyjson_doc_free(doc);
|
||||||
|
|
||||||
|
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t assetAnimationDispose(assetentry_t *entry) {
|
||||||
|
assertNotNull(entry, "Asset entry cannot be NULL");
|
||||||
|
assertTrue(entry->type == ASSET_LOADER_TYPE_ANIMATION, "Invalid type.");
|
||||||
|
assertIsMainThread("Must be called from the main thread.");
|
||||||
|
|
||||||
|
// A load that failed before animationInit() ran (e.g. a parse error)
|
||||||
|
// never populated these -- nothing to free in that case.
|
||||||
|
keyframeset_t *set = &entry->data.animation.keyframes;
|
||||||
|
if(set->tracks) {
|
||||||
|
assetAnimationFreeChannels(set->tracks, set->trackCount);
|
||||||
|
memoryFree(set->trackCounts);
|
||||||
|
set->tracks = NULL;
|
||||||
|
set->trackCounts = NULL;
|
||||||
|
set->trackCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t assetAnimationParseEasing(
|
||||||
|
const char_t *name,
|
||||||
|
easingtype_t *outEasing
|
||||||
|
) {
|
||||||
|
if(stringEquals(name, "LINEAR")) *outEasing = EASING_LINEAR;
|
||||||
|
else if(stringEquals(name, "IN_SINE")) *outEasing = EASING_IN_SINE;
|
||||||
|
else if(stringEquals(name, "OUT_SINE")) *outEasing = EASING_OUT_SINE;
|
||||||
|
else if(stringEquals(name, "IN_OUT_SINE")) *outEasing = EASING_IN_OUT_SINE;
|
||||||
|
else if(stringEquals(name, "IN_QUAD")) *outEasing = EASING_IN_QUAD;
|
||||||
|
else if(stringEquals(name, "OUT_QUAD")) *outEasing = EASING_OUT_QUAD;
|
||||||
|
else if(stringEquals(name, "IN_OUT_QUAD")) *outEasing = EASING_IN_OUT_QUAD;
|
||||||
|
else if(stringEquals(name, "IN_CUBIC")) *outEasing = EASING_IN_CUBIC;
|
||||||
|
else if(stringEquals(name, "OUT_CUBIC")) *outEasing = EASING_OUT_CUBIC;
|
||||||
|
else if(stringEquals(name, "IN_OUT_CUBIC")) *outEasing = EASING_IN_OUT_CUBIC;
|
||||||
|
else if(stringEquals(name, "IN_QUART")) *outEasing = EASING_IN_QUART;
|
||||||
|
else if(stringEquals(name, "OUT_QUART")) *outEasing = EASING_OUT_QUART;
|
||||||
|
else if(stringEquals(name, "IN_OUT_QUART")) *outEasing = EASING_IN_OUT_QUART;
|
||||||
|
else if(stringEquals(name, "IN_BACK")) *outEasing = EASING_IN_BACK;
|
||||||
|
else if(stringEquals(name, "OUT_BACK")) *outEasing = EASING_OUT_BACK;
|
||||||
|
else if(stringEquals(name, "IN_OUT_BACK")) *outEasing = EASING_IN_OUT_BACK;
|
||||||
|
else errorThrow("Unknown easing type '%s'", name);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t assetAnimationParseChannel(
|
||||||
|
yyjson_val *channelJson,
|
||||||
|
keyframe_t **outKeyframes,
|
||||||
|
uint16_t *outCount
|
||||||
|
) {
|
||||||
|
if(!yyjson_is_arr(channelJson)) {
|
||||||
|
errorThrow("Animation channel must be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t count = yyjson_arr_size(channelJson);
|
||||||
|
if(count == 0) {
|
||||||
|
errorThrow("Animation channel must have at least one keyframe");
|
||||||
|
}
|
||||||
|
|
||||||
|
keyframe_t *keyframes = memoryAllocate(count * sizeof(keyframe_t));
|
||||||
|
|
||||||
|
size_t idx, max;
|
||||||
|
yyjson_val *keyframeJson;
|
||||||
|
yyjson_arr_foreach(channelJson, idx, max, keyframeJson) {
|
||||||
|
yyjson_val *timeVal = yyjson_obj_get(keyframeJson, "time");
|
||||||
|
yyjson_val *valueVal = yyjson_obj_get(keyframeJson, "value");
|
||||||
|
if(!timeVal || !valueVal) {
|
||||||
|
memoryFree(keyframes);
|
||||||
|
errorThrow("Animation keyframe missing 'time' or 'value'");
|
||||||
|
}
|
||||||
|
|
||||||
|
keyframes[idx].time = (float_t)yyjson_get_num(timeVal);
|
||||||
|
keyframes[idx].value = (float_t)yyjson_get_num(valueVal);
|
||||||
|
|
||||||
|
yyjson_val *easingVal = yyjson_obj_get(keyframeJson, "easing");
|
||||||
|
if(!easingVal) {
|
||||||
|
keyframes[idx].easing = EASING_LINEAR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t ret = assetAnimationParseEasing(
|
||||||
|
yyjson_get_str(easingVal), &keyframes[idx].easing
|
||||||
|
);
|
||||||
|
if(errorIsNotOk(ret)) {
|
||||||
|
memoryFree(keyframes);
|
||||||
|
errorChain(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*outKeyframes = keyframes;
|
||||||
|
*outCount = (uint16_t)count;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
void assetAnimationFreeChannels(keyframe_t **tracks, const uint16_t count) {
|
||||||
|
for(uint16_t i = 0; i < count; i++) memoryFree(tracks[i]);
|
||||||
|
memoryFree(tracks);
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "error/error.h"
|
||||||
|
#include "asset/assetfile.h"
|
||||||
|
#include "animation/animation.h"
|
||||||
|
#include "yyjson.h"
|
||||||
|
|
||||||
|
#define ASSET_ANIMATION_FILE_SIZE_MAX 1024*256
|
||||||
|
|
||||||
|
typedef struct assetloading_s assetloading_t;
|
||||||
|
typedef struct assetentry_s assetentry_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON animation file format:
|
||||||
|
* {
|
||||||
|
* "loop": false,
|
||||||
|
* "speed": 1.0,
|
||||||
|
* "channels": [
|
||||||
|
* [
|
||||||
|
* { "time": 0.0, "value": 0.0, "easing": "LINEAR" },
|
||||||
|
* { "time": 1.0, "value": 10.0 }
|
||||||
|
* ]
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* "loop" and "speed" are optional, defaulting to false and 1.0 (see
|
||||||
|
* animationInit()). "channels" is required and must have at least one
|
||||||
|
* entry; each entry is itself a non-empty array of keyframes, ascending
|
||||||
|
* by "time", sharing one timeline with every other channel (see
|
||||||
|
* keyframeset_t). Each keyframe requires "time" and "value"; "easing" is
|
||||||
|
* optional and defaults to "LINEAR" (see easingtype_t for the full set of
|
||||||
|
* names, e.g. "IN_QUAD", "OUT_BACK", "IN_OUT_CUBIC").
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ASSET_ANIMATION_LOADING_STATE_INITIAL,
|
||||||
|
ASSET_ANIMATION_LOADING_STATE_READ_FILE,
|
||||||
|
ASSET_ANIMATION_LOADING_STATE_PARSE,
|
||||||
|
ASSET_ANIMATION_LOADING_STATE_DONE
|
||||||
|
} assetanimationloadingstate_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
assetfile_t file;
|
||||||
|
assetanimationloadingstate_t state;
|
||||||
|
uint8_t *buffer;
|
||||||
|
size_t size;
|
||||||
|
} assetanimationloaderloading_t;
|
||||||
|
|
||||||
|
typedef animation_t assetanimationoutput_t;
|
||||||
|
|
||||||
|
errorret_t assetAnimationLoaderAsync(assetloading_t *loading);
|
||||||
|
errorret_t assetAnimationLoaderSync(assetloading_t *loading);
|
||||||
|
errorret_t assetAnimationDispose(assetentry_t *entry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal. Maps a JSON easing name (e.g. "IN_OUT_QUAD") to its
|
||||||
|
* easingtype_t.
|
||||||
|
*
|
||||||
|
* @param name The easing name to parse.
|
||||||
|
* @param outEasing Destination for the parsed easing type.
|
||||||
|
* @return Error state; fails if name doesn't match any easingtype_t.
|
||||||
|
*/
|
||||||
|
errorret_t assetAnimationParseEasing(
|
||||||
|
const char_t *name,
|
||||||
|
easingtype_t *outEasing
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal. Parses one "channels" array entry into a heap-allocated
|
||||||
|
* keyframe_t array (memoryAllocate) -- freed later by
|
||||||
|
* assetAnimationFreeChannels() (on a parse failure) or
|
||||||
|
* assetAnimationDispose() (once loaded).
|
||||||
|
*
|
||||||
|
* @param channelJson The channel's JSON array of keyframe objects.
|
||||||
|
* @param outKeyframes Destination for the newly allocated keyframe array.
|
||||||
|
* @param outCount Destination for the number of keyframes parsed.
|
||||||
|
* @return Error state.
|
||||||
|
*/
|
||||||
|
errorret_t assetAnimationParseChannel(
|
||||||
|
yyjson_val *channelJson,
|
||||||
|
keyframe_t **outKeyframes,
|
||||||
|
uint16_t *outCount
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal. Frees the first count entries of tracks (each a
|
||||||
|
* memoryAllocate'd keyframe_t array from assetAnimationParseChannel()),
|
||||||
|
* then frees tracks itself. Used both to unwind a partially-parsed
|
||||||
|
* channel list on failure and to free a fully-loaded animation's
|
||||||
|
* channels in assetAnimationDispose().
|
||||||
|
*
|
||||||
|
* @param tracks The channel array to free.
|
||||||
|
* @param count The number of entries in tracks to free.
|
||||||
|
*/
|
||||||
|
void assetAnimationFreeChannels(keyframe_t **tracks, const uint16_t count);
|
||||||
@@ -35,6 +35,22 @@ void assetEntryInit(
|
|||||||
entry->input = NULL;
|
entry->input = NULL;
|
||||||
}
|
}
|
||||||
refInit(&entry->refs, entry, NULL, NULL, 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) {
|
void assetEntryLock(assetentry_t *entry) {
|
||||||
@@ -81,7 +97,7 @@ errorret_t assetEntryDispose(assetentry_t *entry) {
|
|||||||
"Asset entry still refed at dispose time."
|
"Asset entry still refed at dispose time."
|
||||||
);
|
);
|
||||||
|
|
||||||
if(entry->onUnloaded) entry->onUnloaded(entry, entry->onUnloadedUser);
|
eventInvoke(&entry->onUnloaded, entry);
|
||||||
errorChain(ASSET_LOADER_CALLBACKS[entry->type].dispose(entry));
|
errorChain(ASSET_LOADER_CALLBACKS[entry->type].dispose(entry));
|
||||||
memoryZero(entry, sizeof(assetentry_t));
|
memoryZero(entry, sizeof(assetentry_t));
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "asset/loader/assetloading.h"
|
#include "asset/loader/assetloading.h"
|
||||||
|
#include "event/event.h"
|
||||||
#include "util/ref.h"
|
#include "util/ref.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -19,16 +20,10 @@ typedef enum {
|
|||||||
ASSET_ENTRY_STATE_ERROR
|
ASSET_ENTRY_STATE_ERROR
|
||||||
} assetentrystate_t;
|
} assetentrystate_t;
|
||||||
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
/** Maximum number of subscribers for each per-entry event. */
|
||||||
|
#define ASSET_ENTRY_EVENT_MAX 2
|
||||||
|
|
||||||
/**
|
typedef struct assetentry_s assetentry_t;
|
||||||
* A single asset entry callback. Each entry supports at most one subscriber
|
|
||||||
* per event - a second assignment without clearing the first is a bug.
|
|
||||||
*
|
|
||||||
* @param entry The assetentry_t the event fired on.
|
|
||||||
* @param user The user pointer passed alongside the callback.
|
|
||||||
*/
|
|
||||||
typedef void (*assetentrycallback_t)(assetentry_t *entry, void *user);
|
|
||||||
|
|
||||||
struct assetentry_s {
|
struct assetentry_s {
|
||||||
char_t name[ASSET_FILE_NAME_MAX];
|
char_t name[ASSET_FILE_NAME_MAX];
|
||||||
@@ -38,27 +33,30 @@ struct assetentry_s {
|
|||||||
ref_t refs;
|
ref_t refs;
|
||||||
assetloaderinput_t *input;
|
assetloaderinput_t *input;
|
||||||
assetloaderinput_t inputData;
|
assetloaderinput_t inputData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired once when loading completes successfully.
|
* Fired once when loading completes successfully (params = assetentry_t *).
|
||||||
* Always invoked on the main thread.
|
* Always invoked on the main thread.
|
||||||
*/
|
*/
|
||||||
assetentrycallback_t onLoaded;
|
event_t onLoaded;
|
||||||
void *onLoadedUser;
|
eventcallback_t onLoadedCallbacks[ASSET_ENTRY_EVENT_MAX];
|
||||||
|
void *onLoadedUsers[ASSET_ENTRY_EVENT_MAX];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired once when the entry is disposed/reaped. The asset data is still
|
* Fired once when the entry is disposed/reaped (params = assetentry_t *).
|
||||||
* accessible when the callback runs. Always invoked on the main thread.
|
* The asset data is still accessible when the callback runs.
|
||||||
*/
|
|
||||||
assetentrycallback_t onUnloaded;
|
|
||||||
void *onUnloadedUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired once when loading fails.
|
|
||||||
* Always invoked on the main thread.
|
* Always invoked on the main thread.
|
||||||
*/
|
*/
|
||||||
assetentrycallback_t onError;
|
event_t onUnloaded;
|
||||||
void *onErrorUser;
|
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];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,27 +46,9 @@ assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
|||||||
.dispose = assetJsonDispose
|
.dispose = assetJsonDispose
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_CHUNK] = {
|
[ASSET_LOADER_TYPE_ANIMATION] = {
|
||||||
.loadSync = assetChunkLoaderSync,
|
.loadSync = assetAnimationLoaderSync,
|
||||||
.loadAsync = assetChunkLoaderAsync,
|
.loadAsync = assetAnimationLoaderAsync,
|
||||||
.dispose = assetChunkDispose
|
.dispose = assetAnimationDispose
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_CUTSCENE] = {
|
|
||||||
.loadSync = assetCutsceneLoaderSync,
|
|
||||||
.loadAsync = assetCutsceneLoaderAsync,
|
|
||||||
.dispose = assetCutsceneDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_WAV] = {
|
|
||||||
.loadSync = assetWavLoaderSync,
|
|
||||||
.loadAsync = assetWavLoaderAsync,
|
|
||||||
.dispose = assetWavDispose
|
|
||||||
},
|
|
||||||
|
|
||||||
[ASSET_LOADER_TYPE_MP3] = {
|
|
||||||
.loadSync = assetMp3LoaderSync,
|
|
||||||
.loadAsync = assetMp3LoaderAsync,
|
|
||||||
.dispose = assetMp3Dispose
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -12,10 +12,7 @@
|
|||||||
#include "asset/loader/display/assettilesetloader.h"
|
#include "asset/loader/display/assettilesetloader.h"
|
||||||
#include "asset/loader/locale/assetlocaleloader.h"
|
#include "asset/loader/locale/assetlocaleloader.h"
|
||||||
#include "asset/loader/json/assetjsonloader.h"
|
#include "asset/loader/json/assetjsonloader.h"
|
||||||
#include "asset/loader/chunk/assetchunkloader.h"
|
#include "asset/loader/animation/assetanimationloader.h"
|
||||||
#include "asset/loader/cutscene/assetcutsceneloader.h"
|
|
||||||
#include "asset/loader/wav/assetwavloader.h"
|
|
||||||
#include "asset/loader/mp3/assetmp3loader.h"
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ASSET_LOADER_TYPE_NULL,
|
ASSET_LOADER_TYPE_NULL,
|
||||||
@@ -26,10 +23,7 @@ typedef enum {
|
|||||||
ASSET_LOADER_TYPE_TILESET,
|
ASSET_LOADER_TYPE_TILESET,
|
||||||
ASSET_LOADER_TYPE_LOCALE,
|
ASSET_LOADER_TYPE_LOCALE,
|
||||||
ASSET_LOADER_TYPE_JSON,
|
ASSET_LOADER_TYPE_JSON,
|
||||||
ASSET_LOADER_TYPE_CHUNK,
|
ASSET_LOADER_TYPE_ANIMATION,
|
||||||
ASSET_LOADER_TYPE_CUTSCENE,
|
|
||||||
ASSET_LOADER_TYPE_WAV,
|
|
||||||
ASSET_LOADER_TYPE_MP3,
|
|
||||||
|
|
||||||
ASSET_LOADER_TYPE_COUNT
|
ASSET_LOADER_TYPE_COUNT
|
||||||
} assetloadertype_t;
|
} assetloadertype_t;
|
||||||
@@ -41,10 +35,7 @@ typedef union {
|
|||||||
assettilesetloaderloading_t tileset;
|
assettilesetloaderloading_t tileset;
|
||||||
assetlocaleloaderloading_t locale;
|
assetlocaleloaderloading_t locale;
|
||||||
assetjsonloaderloading_t json;
|
assetjsonloaderloading_t json;
|
||||||
assetchunkloaderloading_t chunk;
|
assetanimationloaderloading_t animation;
|
||||||
assetcutsceneloaderloading_t cutscene;
|
|
||||||
assetwavloaderloading_t wav;
|
|
||||||
assetmp3loaderloading_t mp3;
|
|
||||||
} assetloaderloading_t;
|
} assetloaderloading_t;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -54,10 +45,7 @@ typedef union {
|
|||||||
assettilesetoutput_t tileset;
|
assettilesetoutput_t tileset;
|
||||||
assetlocaleoutput_t locale;
|
assetlocaleoutput_t locale;
|
||||||
assetjsonoutput_t json;
|
assetjsonoutput_t json;
|
||||||
assetchunkoutput_t chunk;
|
assetanimationoutput_t animation;
|
||||||
assetcutsceneoutput_t cutscene;
|
|
||||||
assetwavoutput_t wav;
|
|
||||||
assetmp3output_t mp3;
|
|
||||||
} assetloaderoutput_t;
|
} assetloaderoutput_t;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -65,10 +53,6 @@ typedef union {
|
|||||||
assettilesetloaderinput_t tileset;
|
assettilesetloaderinput_t tileset;
|
||||||
assetlocaleloaderinput_t locale;
|
assetlocaleloaderinput_t locale;
|
||||||
assetjsonloaderinput_t json;
|
assetjsonloaderinput_t json;
|
||||||
assetchunkloaderinput_t chunk;
|
|
||||||
assetcutsceneloaderinput_t cutscene;
|
|
||||||
assetwavloaderinput_t wav;
|
|
||||||
assetmp3loaderinput_t mp3;
|
|
||||||
} assetloaderinput_t;
|
} assetloaderinput_t;
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
typedef struct assetloading_s assetloading_t;
|
||||||
|
|||||||
@@ -1,484 +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/string.h"
|
|
||||||
#include "asset/asset.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
#include "asset/loader/assetloader.h"
|
|
||||||
#include "asset/loader/json/assetjsonloader.h"
|
|
||||||
#include "display/color.h"
|
|
||||||
#include "display/texture/texture.h"
|
|
||||||
#include "rpg/overworld/worldpos.h"
|
|
||||||
#include "yyjson.h"
|
|
||||||
|
|
||||||
#define ASSET_CHUNK_TERRAIN_TEXTURE "tiles.png"
|
|
||||||
|
|
||||||
// Per-shape corner Z offsets (sw, se, ne, nw) as offsets from a tile's own
|
|
||||||
// base Z, ported 1:1 from tools/asset/chunk/__main__.py's _RAMP_CORNERS.
|
|
||||||
// TILE_SHAPE_NULL's row is never read - assetChunkTilesHaveTerrain/
|
|
||||||
// assetChunkBuildTerrain skip those tiles outright.
|
|
||||||
static const float_t CHUNK_RAMP_CORNERS[TILE_SHAPE_COUNT][4] = {
|
|
||||||
[TILE_SHAPE_GROUND] = {0.0f, 0.0f, 0.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_NORTH] = {0.0f, 0.0f, 1.0f, 1.0f},
|
|
||||||
[TILE_SHAPE_RAMP_SOUTH] = {1.0f, 1.0f, 0.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_EAST] = {0.0f, 1.0f, 1.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_WEST] = {1.0f, 0.0f, 0.0f, 1.0f},
|
|
||||||
[TILE_SHAPE_RAMP_NORTHEAST] = {0.0f, 0.0f, 1.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_NORTHWEST] = {0.0f, 0.0f, 0.0f, 1.0f},
|
|
||||||
[TILE_SHAPE_RAMP_SOUTHEAST] = {0.0f, 1.0f, 0.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_SOUTHWEST] = {1.0f, 0.0f, 0.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_NORTHEAST_INNER] = {0.0f, 1.0f, 1.0f, 1.0f},
|
|
||||||
[TILE_SHAPE_RAMP_NORTHWEST_INNER] = {1.0f, 0.0f, 1.0f, 1.0f},
|
|
||||||
[TILE_SHAPE_RAMP_SOUTHEAST_INNER] = {1.0f, 1.0f, 1.0f, 0.0f},
|
|
||||||
[TILE_SHAPE_RAMP_SOUTHWEST_INNER] = {1.0f, 1.0f, 0.0f, 1.0f},
|
|
||||||
};
|
|
||||||
|
|
||||||
errorret_t assetChunkLoaderAsync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertNotMainThread("Should be called from an async thread.");
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool_t assetChunkTilesHaveTerrain(const tile_t *tiles) {
|
|
||||||
for(uint32_t i = 0; i < CHUNK_TILE_COUNT; i++) {
|
|
||||||
if(tiles[i].shape != TILE_SHAPE_NULL) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads the "tiles" array - a dense, fixed-size CHUNK_TILE_COUNT grid,
|
|
||||||
// one slot per (x, y) column at index x + y * CHUNK_WIDTH (position is
|
|
||||||
// implicit in the index, not stored). Each slot is either `null` (empty
|
|
||||||
// column, already zeroed = TILE_SHAPE_NULL) or a 2-element [type, z]
|
|
||||||
// array.
|
|
||||||
static void assetChunkParseTiles(yyjson_val *root, tile_t *tiles) {
|
|
||||||
memoryZero(tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
|
|
||||||
|
|
||||||
yyjson_val *tilesArr = yyjson_obj_get(root, "tiles");
|
|
||||||
if(!yyjson_is_arr(tilesArr)) return;
|
|
||||||
|
|
||||||
size_t idx, len;
|
|
||||||
yyjson_val *tileVal;
|
|
||||||
yyjson_arr_foreach(tilesArr, idx, len, tileVal) {
|
|
||||||
if(idx >= CHUNK_TILE_COUNT) break;
|
|
||||||
if(!yyjson_is_arr(tileVal) || yyjson_arr_size(tileVal) < 2) continue;
|
|
||||||
|
|
||||||
int32_t type = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 0));
|
|
||||||
int32_t z = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 1));
|
|
||||||
tiles[idx] = (tile_t){ .shape = (tileshape_t)type, .z = (uint8_t)z };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolves "meshes" (external building references, by bare filename) into
|
|
||||||
// out->modelNames/meshOffsets starting at *ioIndex, advancing it as
|
|
||||||
// entries are written. Filenames are resolved as
|
|
||||||
// "models/buildings/<basename>.json" - a hardcoded stand-in for
|
|
||||||
// tools/asset/chunk/__main__.py's find_model() recursive search, valid
|
|
||||||
// as long as every building model lives flat under that one directory
|
|
||||||
// (true today - see the raw-json-maps plan notes for the tradeoff).
|
|
||||||
static void assetChunkParseMeshes(
|
|
||||||
yyjson_val *root, assetchunkoutput_t *out, uint8_t *ioIndex
|
|
||||||
) {
|
|
||||||
yyjson_val *meshesArr = yyjson_obj_get(root, "meshes");
|
|
||||||
if(!yyjson_is_arr(meshesArr)) return;
|
|
||||||
|
|
||||||
size_t idx, len;
|
|
||||||
yyjson_val *meshVal;
|
|
||||||
yyjson_arr_foreach(meshesArr, idx, len, meshVal) {
|
|
||||||
if(*ioIndex >= CHUNK_MESH_COUNT_MAX) break;
|
|
||||||
|
|
||||||
yyjson_val *fileVal = yyjson_obj_get(meshVal, "file");
|
|
||||||
if(!fileVal || !yyjson_is_str(fileVal)) continue;
|
|
||||||
|
|
||||||
char_t baseName[CHUNK_MESH_NAME_MAX];
|
|
||||||
stringCopy(baseName, yyjson_get_str(fileVal), sizeof(baseName));
|
|
||||||
char_t *dot = stringFindLastChar(baseName, '.');
|
|
||||||
if(dot != NULL) *dot = '\0';
|
|
||||||
|
|
||||||
uint8_t m = *ioIndex;
|
|
||||||
stringFormat(
|
|
||||||
out->modelNames[m], CHUNK_MESH_NAME_MAX,
|
|
||||||
"models/buildings/%s.json", baseName
|
|
||||||
);
|
|
||||||
|
|
||||||
vec3 offset = {0.0f, 0.0f, 0.0f};
|
|
||||||
yyjson_val *posArr = yyjson_obj_get(meshVal, "pos");
|
|
||||||
if(yyjson_is_arr(posArr) && yyjson_arr_size(posArr) >= 3) {
|
|
||||||
offset[0] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 0));
|
|
||||||
offset[1] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 1));
|
|
||||||
offset[2] = (float_t)yyjson_get_num(yyjson_arr_get(posArr, 2));
|
|
||||||
}
|
|
||||||
memoryCopy(out->meshOffsets[m], offset, sizeof(vec3));
|
|
||||||
|
|
||||||
(*ioIndex)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void assetChunkParseEntities(yyjson_val *root, assetchunkoutput_t *out) {
|
|
||||||
out->entitySpawnCount = 0;
|
|
||||||
|
|
||||||
yyjson_val *arr = yyjson_obj_get(root, "entities");
|
|
||||||
if(!yyjson_is_arr(arr)) return;
|
|
||||||
|
|
||||||
size_t idx, len;
|
|
||||||
yyjson_val *val;
|
|
||||||
yyjson_arr_foreach(arr, idx, len, val) {
|
|
||||||
if(out->entitySpawnCount >= CHUNK_ENTITY_SPAWN_COUNT_MAX) break;
|
|
||||||
|
|
||||||
const char_t *type = yyjson_get_str(yyjson_obj_get(val, "type"));
|
|
||||||
yyjson_val *posArr = yyjson_obj_get(val, "pos");
|
|
||||||
if(type == NULL || !yyjson_is_arr(posArr) || yyjson_arr_size(posArr) < 3) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
worldpos_t pos = {
|
|
||||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 0)),
|
|
||||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 1)),
|
|
||||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(posArr, 2)),
|
|
||||||
};
|
|
||||||
|
|
||||||
chunkentityspawn_t *spawn = &out->entitySpawns[out->entitySpawnCount];
|
|
||||||
if(stringEquals(type, "global")) {
|
|
||||||
spawn->kind = CHUNK_ENTITY_SPAWN_KIND_GLOBAL;
|
|
||||||
spawn->globalId =
|
|
||||||
(uint16_t)yyjson_get_int(yyjson_obj_get(val, "globalId"));
|
|
||||||
spawn->itemId = 0;
|
|
||||||
spawn->itemQuantity = 0;
|
|
||||||
} else if(stringEquals(type, "item")) {
|
|
||||||
spawn->kind = CHUNK_ENTITY_SPAWN_KIND_ITEM;
|
|
||||||
spawn->globalId = 0;
|
|
||||||
spawn->itemId = (uint16_t)yyjson_get_int(yyjson_obj_get(val, "itemId"));
|
|
||||||
spawn->itemQuantity =
|
|
||||||
(uint8_t)yyjson_get_int(yyjson_obj_get(val, "quantity"));
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
spawn->position = pos;
|
|
||||||
out->entitySpawnCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void assetChunkParseAreas(yyjson_val *root, assetchunkoutput_t *out) {
|
|
||||||
out->areaSpawnCount = 0;
|
|
||||||
|
|
||||||
yyjson_val *arr = yyjson_obj_get(root, "areas");
|
|
||||||
if(!yyjson_is_arr(arr)) return;
|
|
||||||
|
|
||||||
size_t idx, len;
|
|
||||||
yyjson_val *val;
|
|
||||||
yyjson_arr_foreach(arr, idx, len, val) {
|
|
||||||
if(out->areaSpawnCount >= CHUNK_AREA_COUNT_MAX) break;
|
|
||||||
|
|
||||||
yyjson_val *minArr = yyjson_obj_get(val, "min");
|
|
||||||
yyjson_val *maxArr = yyjson_obj_get(val, "max");
|
|
||||||
if(
|
|
||||||
!yyjson_is_arr(minArr) || yyjson_arr_size(minArr) < 3 ||
|
|
||||||
!yyjson_is_arr(maxArr) || yyjson_arr_size(maxArr) < 3
|
|
||||||
) continue;
|
|
||||||
|
|
||||||
chunkareaspawn_t *area = &out->areaSpawns[out->areaSpawnCount];
|
|
||||||
area->min = (worldpos_t){
|
|
||||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 0)),
|
|
||||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 1)),
|
|
||||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(minArr, 2)),
|
|
||||||
};
|
|
||||||
area->max = (worldpos_t){
|
|
||||||
.x = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 0)),
|
|
||||||
.y = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 1)),
|
|
||||||
.z = (worldunit_t)yyjson_get_int(yyjson_arr_get(maxArr, 2)),
|
|
||||||
};
|
|
||||||
area->callbackId =
|
|
||||||
(uint16_t)yyjson_get_int(yyjson_obj_get(val, "callbackId"));
|
|
||||||
area->notify = (uint8_t)yyjson_get_int(yyjson_obj_get(val, "notify"));
|
|
||||||
area->trigger = (uint8_t)yyjson_get_int(yyjson_obj_get(val, "trigger"));
|
|
||||||
out->areaSpawnCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Six vertices (2 CCW triangles) for one tile's quad, matching
|
|
||||||
// tools/asset/chunk/__main__.py's _tile_quad. Corner order: SW=(x,y),
|
|
||||||
// SE=(x+1,y), NE=(x+1,y+1), NW=(x,y+1). NORTH=+Y, EAST=+X.
|
|
||||||
static void assetChunkAppendTileQuad(
|
|
||||||
meshvertex_t *verts, uint32_t *vertCount,
|
|
||||||
const uint32_t x, const uint32_t y,
|
|
||||||
const float_t sw, const float_t se, const float_t ne, const float_t nw
|
|
||||||
) {
|
|
||||||
const float_t u0 = (float_t)x / (float_t)CHUNK_WIDTH;
|
|
||||||
const float_t u1 = (float_t)(x + 1) / (float_t)CHUNK_WIDTH;
|
|
||||||
const float_t v0 = (float_t)y / (float_t)CHUNK_HEIGHT;
|
|
||||||
const float_t v1 = (float_t)(y + 1) / (float_t)CHUNK_HEIGHT;
|
|
||||||
const float_t fx = (float_t)x;
|
|
||||||
const float_t fy = (float_t)y;
|
|
||||||
|
|
||||||
meshvertex_t *v = verts + *vertCount;
|
|
||||||
v[0] = (meshvertex_t){ .uv = {u0, v0}, .pos = {fx, fy, sw} };
|
|
||||||
v[1] = (meshvertex_t){ .uv = {u1, v0}, .pos = {fx + 1, fy, se} };
|
|
||||||
v[2] = (meshvertex_t){ .uv = {u1, v1}, .pos = {fx + 1, fy + 1, ne} };
|
|
||||||
v[3] = (meshvertex_t){ .uv = {u0, v0}, .pos = {fx, fy, sw} };
|
|
||||||
v[4] = (meshvertex_t){ .uv = {u1, v1}, .pos = {fx + 1, fy + 1, ne} };
|
|
||||||
v[5] = (meshvertex_t){ .uv = {u0, v1}, .pos = {fx, fy + 1, nw} };
|
|
||||||
*vertCount += 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builds a mesh_t straight from the tile grid - one quad per non-null
|
|
||||||
// tile column, shaped by CHUNK_RAMP_CORNERS - the runtime equivalent of
|
|
||||||
// tools/asset/chunk/__main__.py's build_terrain_verts. Only called once
|
|
||||||
// assetChunkTilesHaveTerrain has confirmed at least one real tile exists.
|
|
||||||
// Mirrors assetMeshLoaderSync's meshInit/meshFlush/free-after-upload
|
|
||||||
// sequence (assetmeshloader.c) since this produces the same
|
|
||||||
// assetmeshoutput_t shape, just from generated verts instead of a file.
|
|
||||||
static errorret_t assetChunkBuildTerrain(
|
|
||||||
const tile_t *tiles, assetmeshoutput_t *out
|
|
||||||
) {
|
|
||||||
meshvertex_t *verts = memoryAllocate(
|
|
||||||
CHUNK_TILE_COUNT * 6 * sizeof(meshvertex_t)
|
|
||||||
);
|
|
||||||
uint32_t vertCount = 0;
|
|
||||||
|
|
||||||
for(uint32_t y = 0; y < CHUNK_HEIGHT; y++) {
|
|
||||||
for(uint32_t x = 0; x < CHUNK_WIDTH; x++) {
|
|
||||||
const tile_t *tile = &tiles[x + y * CHUNK_WIDTH];
|
|
||||||
if(tile->shape == TILE_SHAPE_NULL) continue;
|
|
||||||
|
|
||||||
const float_t *corners = CHUNK_RAMP_CORNERS[tile->shape];
|
|
||||||
const float_t fz = (float_t)tile->z;
|
|
||||||
assetChunkAppendTileQuad(
|
|
||||||
verts, &vertCount, x, y,
|
|
||||||
(fz + corners[0]) * WORLD_LAYER_HEIGHT,
|
|
||||||
(fz + corners[1]) * WORLD_LAYER_HEIGHT,
|
|
||||||
(fz + corners[2]) * WORLD_LAYER_HEIGHT,
|
|
||||||
(fz + corners[3]) * WORLD_LAYER_HEIGHT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(vertCount > 0, "Terrain build called with no terrain tiles.");
|
|
||||||
|
|
||||||
out->vertices = verts;
|
|
||||||
errorret_t ret = meshInit(
|
|
||||||
&out->mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, (int32_t)vertCount, verts
|
|
||||||
);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
memoryFree(out->vertices);
|
|
||||||
out->vertices = NULL;
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
|
||||||
out->meshInitialized = true;
|
|
||||||
|
|
||||||
ret = meshFlush(&out->mesh, 0, (int32_t)vertCount);
|
|
||||||
if(errorIsNotOk(ret)) {
|
|
||||||
meshDispose(&out->mesh);
|
|
||||||
out->meshInitialized = false;
|
|
||||||
memoryFree(out->vertices);
|
|
||||||
out->vertices = NULL;
|
|
||||||
errorChain(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(DUSK_OPENGL) && !defined(DUSK_OPENGL_LEGACY)
|
|
||||||
memoryFree(out->vertices);
|
|
||||||
out->vertices = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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.");
|
|
||||||
|
|
||||||
assetchunkoutput_t *out = &loading->entry->data.chunk;
|
|
||||||
|
|
||||||
switch(loading->loading.chunk.state) {
|
|
||||||
case ASSET_CHUNK_LOADING_STATE_INITIAL:
|
|
||||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_PARSE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
|
|
||||||
case ASSET_CHUNK_LOADING_STATE_PARSE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_CHUNK_LOADING_STATE_LOAD_MODELS:
|
|
||||||
while(loading->loading.chunk.modelIndex < out->meshCount) {
|
|
||||||
uint8_t m = loading->loading.chunk.modelIndex;
|
|
||||||
if(out->modelEntries[m] == NULL) {
|
|
||||||
out->modelEntries[m] = assetLock(
|
|
||||||
out->modelNames[m], ASSET_LOADER_TYPE_MODEL, NULL
|
|
||||||
);
|
|
||||||
assertNotNull(out->modelEntries[m], "Failed to lock model.");
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
if(out->modelEntries[m]->state == ASSET_ENTRY_STATE_ERROR) {
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Model failed to load: %s", out->modelNames[m]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if(out->modelEntries[m]->state != ASSET_ENTRY_STATE_LOADED) {
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
loading->loading.chunk.modelIndex++;
|
|
||||||
}
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
|
|
||||||
default:
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- PARSE: lock+require the chunk's own JSON as a sub-asset, exactly
|
|
||||||
// like assetmodelloader.c's ASSET_MODEL_LOADING_STATE_LOCK_ASSETS does
|
|
||||||
// for its model descriptor, then read everything out of it before
|
|
||||||
// unlocking (the yyjson_doc/vals only stay valid while jsonEntry does).
|
|
||||||
char_t jsonKey[ASSET_FILE_NAME_MAX];
|
|
||||||
stringFormat(jsonKey, sizeof(jsonKey), "json:%s", loading->entry->name);
|
|
||||||
assetloaderinput_t jsonInput;
|
|
||||||
memoryZero(&jsonInput, sizeof(jsonInput));
|
|
||||||
stringCopy(
|
|
||||||
jsonInput.json.path, loading->entry->name, ASSET_FILE_NAME_MAX
|
|
||||||
);
|
|
||||||
assetentry_t *jsonEntry =
|
|
||||||
assetLock(jsonKey, ASSET_LOADER_TYPE_JSON, &jsonInput);
|
|
||||||
errorret_t jsonRet = assetRequireLoaded(jsonEntry);
|
|
||||||
if(errorIsNotOk(jsonRet)) {
|
|
||||||
assetUnlockEntry(jsonEntry);
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Failed to load chunk JSON: %s", loading->entry->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
yyjson_val *root = yyjson_doc_get_root(jsonEntry->data.json);
|
|
||||||
|
|
||||||
tile_t tiles[CHUNK_TILE_COUNT];
|
|
||||||
assetChunkParseTiles(root, tiles);
|
|
||||||
out->hasTerrain = assetChunkTilesHaveTerrain(tiles);
|
|
||||||
|
|
||||||
uint8_t meshIndex = out->hasTerrain ? 1 : 0;
|
|
||||||
assetChunkParseMeshes(root, out, &meshIndex);
|
|
||||||
out->meshCount = meshIndex;
|
|
||||||
|
|
||||||
assetChunkParseEntities(root, out);
|
|
||||||
assetChunkParseAreas(root, out);
|
|
||||||
|
|
||||||
assetUnlockEntry(jsonEntry);
|
|
||||||
|
|
||||||
out->tiles = memoryAllocate(CHUNK_TILE_COUNT * sizeof(tile_t));
|
|
||||||
memoryCopy(out->tiles, tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
|
|
||||||
|
|
||||||
// Terrain: build the mesh, then wrap it in synthetic (non-cache,
|
|
||||||
// non-refcounted) mesh/model entries so modelEntries[0] behaves exactly
|
|
||||||
// like a real file-backed model entry for every downstream consumer -
|
|
||||||
// see the header's doc comment on hasTerrain/terrainMeshEntry.
|
|
||||||
if(out->hasTerrain) {
|
|
||||||
assetmeshoutput_t terrainMesh;
|
|
||||||
memoryZero(&terrainMesh, sizeof(terrainMesh));
|
|
||||||
errorret_t terrainRet = assetChunkBuildTerrain(out->tiles, &terrainMesh);
|
|
||||||
if(errorIsNotOk(terrainRet)) {
|
|
||||||
memoryFree(out->tiles);
|
|
||||||
out->tiles = NULL;
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Failed to build chunk terrain mesh: %s",
|
|
||||||
loading->entry->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
assetloaderinput_t texInput = { .texture = TEXTURE_FORMAT_RGBA };
|
|
||||||
assetentry_t *texEntry = assetLock(
|
|
||||||
ASSET_CHUNK_TERRAIN_TEXTURE, ASSET_LOADER_TYPE_TEXTURE, &texInput
|
|
||||||
);
|
|
||||||
errorret_t texRet = assetRequireLoaded(texEntry);
|
|
||||||
if(errorIsNotOk(texRet)) {
|
|
||||||
assetUnlockEntry(texEntry);
|
|
||||||
meshDispose(&terrainMesh.mesh);
|
|
||||||
memoryFree(out->tiles);
|
|
||||||
out->tiles = NULL;
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Failed to load chunk terrain texture: %s",
|
|
||||||
loading->entry->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
out->terrainTexEntry = texEntry;
|
|
||||||
|
|
||||||
out->terrainMeshEntry = memoryAllocate(sizeof(assetentry_t));
|
|
||||||
memoryZero(out->terrainMeshEntry, sizeof(assetentry_t));
|
|
||||||
out->terrainMeshEntry->type = ASSET_LOADER_TYPE_MESH;
|
|
||||||
out->terrainMeshEntry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
out->terrainMeshEntry->data.mesh = terrainMesh;
|
|
||||||
|
|
||||||
out->terrainModelEntry = memoryAllocate(sizeof(assetentry_t));
|
|
||||||
memoryZero(out->terrainModelEntry, sizeof(assetentry_t));
|
|
||||||
out->terrainModelEntry->type = ASSET_LOADER_TYPE_MODEL;
|
|
||||||
out->terrainModelEntry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
out->terrainModelEntry->data.model.meshEntry = out->terrainMeshEntry;
|
|
||||||
out->terrainModelEntry->data.model.texEntry = out->terrainTexEntry;
|
|
||||||
out->terrainModelEntry->data.model.color = COLOR_WHITE;
|
|
||||||
|
|
||||||
out->modelEntries[0] = out->terrainModelEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(out->meshCount == 0) {
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
loading->loading.chunk.state = ASSET_CHUNK_LOADING_STATE_LOAD_MODELS;
|
|
||||||
loading->loading.chunk.modelIndex = out->hasTerrain ? 1 : 0;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
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.");
|
|
||||||
|
|
||||||
assetchunkoutput_t *out = &entry->data.chunk;
|
|
||||||
|
|
||||||
if(out->tiles != NULL) {
|
|
||||||
memoryFree(out->tiles);
|
|
||||||
out->tiles = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(uint8_t m = 0; m < out->meshCount; m++) {
|
|
||||||
if(out->modelEntries[m] == NULL) continue;
|
|
||||||
if(out->hasTerrain && m == 0) continue; // synthetic - freed below.
|
|
||||||
assetUnlockEntry(out->modelEntries[m]);
|
|
||||||
out->modelEntries[m] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(out->hasTerrain) {
|
|
||||||
if(out->terrainMeshEntry != NULL) {
|
|
||||||
assetmeshoutput_t *meshOut = &out->terrainMeshEntry->data.mesh;
|
|
||||||
if(meshOut->meshInitialized) {
|
|
||||||
meshDispose(&meshOut->mesh);
|
|
||||||
meshOut->meshInitialized = false;
|
|
||||||
}
|
|
||||||
if(meshOut->vertices != NULL) {
|
|
||||||
memoryFree(meshOut->vertices);
|
|
||||||
meshOut->vertices = NULL;
|
|
||||||
}
|
|
||||||
memoryFree(out->terrainMeshEntry);
|
|
||||||
out->terrainMeshEntry = NULL;
|
|
||||||
}
|
|
||||||
if(out->terrainModelEntry != NULL) {
|
|
||||||
memoryFree(out->terrainModelEntry);
|
|
||||||
out->terrainModelEntry = NULL;
|
|
||||||
}
|
|
||||||
if(out->terrainTexEntry != NULL) {
|
|
||||||
assetUnlockEntry(out->terrainTexEntry);
|
|
||||||
out->terrainTexEntry = NULL;
|
|
||||||
}
|
|
||||||
out->modelEntries[0] = NULL;
|
|
||||||
out->hasTerrain = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,120 +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"
|
|
||||||
|
|
||||||
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_PARSE,
|
|
||||||
ASSET_CHUNK_LOADING_STATE_LOAD_MODELS,
|
|
||||||
ASSET_CHUNK_LOADING_STATE_DONE
|
|
||||||
} assetchunkloadingstate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetchunkloadingstate_t state;
|
|
||||||
|
|
||||||
// Index into assetchunkoutput_t.modelNames/modelEntries the external
|
|
||||||
// (non-terrain) model polling loop has reached - see
|
|
||||||
// ASSET_CHUNK_LOADING_STATE_LOAD_MODELS.
|
|
||||||
uint8_t modelIndex;
|
|
||||||
} assetchunkloaderloading_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
CHUNK_ENTITY_SPAWN_KIND_GLOBAL,
|
|
||||||
CHUNK_ENTITY_SPAWN_KIND_ITEM
|
|
||||||
} chunkentityspawnkind_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
chunkentityspawnkind_t kind;
|
|
||||||
uint16_t globalId; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_GLOBAL.
|
|
||||||
uint16_t itemId; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_ITEM.
|
|
||||||
uint8_t itemQuantity; // Valid when kind == CHUNK_ENTITY_SPAWN_KIND_ITEM.
|
|
||||||
worldpos_t position;
|
|
||||||
} chunkentityspawn_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
worldpos_t min;
|
|
||||||
worldpos_t max;
|
|
||||||
uint16_t callbackId; // Index into MAP_AREA_CALLBACK_LIST.
|
|
||||||
uint8_t notify;
|
|
||||||
uint8_t trigger;
|
|
||||||
} chunkareaspawn_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
tile_t *tiles;
|
|
||||||
uint8_t meshCount;
|
|
||||||
char_t modelNames[CHUNK_MESH_COUNT_MAX][CHUNK_MESH_NAME_MAX];
|
|
||||||
vec3 meshOffsets[CHUNK_MESH_COUNT_MAX];
|
|
||||||
assetentry_t *modelEntries[CHUNK_MESH_COUNT_MAX];
|
|
||||||
|
|
||||||
// Terrain mesh generated at load time from the tile grid (no baked
|
|
||||||
// .dmf/.json - see assetChunkBuildTerrain in assetchunkloader.c). NULL
|
|
||||||
// (with hasTerrain false) for a chunk with no non-null tiles, in which
|
|
||||||
// case modelEntries[0] (if meshCount > 0) is the first external mesh
|
|
||||||
// instead - matches the old baked pipeline's "only write a terrain
|
|
||||||
// model if it has vertices" behavior.
|
|
||||||
//
|
|
||||||
// terrainMeshEntry/terrainModelEntry are heap-allocated, plain
|
|
||||||
// assetentry_t values that are never passed to assetLock/assetGetEntry/
|
|
||||||
// assetUnlockEntry (only a real, name-keyed, ref-counted entry may be)
|
|
||||||
// - they exist purely so modelEntries[0] can point at something with
|
|
||||||
// the same ->state/->data.model/->data.mesh.mesh shape every other
|
|
||||||
// model/mesh entry has, so chunk.c/map.c/sceneoverworld.c don't need to
|
|
||||||
// know terrain isn't file-backed. Freed directly (not assetUnlockEntry)
|
|
||||||
// in assetChunkDispose. terrainTexEntry is a real, ref-counted texture
|
|
||||||
// entry (the shared "tiles.png") and must be assetUnlockEntry'd there.
|
|
||||||
bool_t hasTerrain;
|
|
||||||
assetentry_t *terrainMeshEntry;
|
|
||||||
assetentry_t *terrainModelEntry;
|
|
||||||
assetentry_t *terrainTexEntry;
|
|
||||||
|
|
||||||
uint8_t entitySpawnCount;
|
|
||||||
chunkentityspawn_t entitySpawns[CHUNK_ENTITY_SPAWN_COUNT_MAX];
|
|
||||||
|
|
||||||
uint8_t areaSpawnCount;
|
|
||||||
chunkareaspawn_t areaSpawns[CHUNK_AREA_COUNT_MAX];
|
|
||||||
} assetchunkoutput_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Async loader stub for chunk assets. Chunk loading is performed entirely
|
|
||||||
* on the main thread (it delegates to the JSON asset loader and to
|
|
||||||
* meshInit/meshFlush, both main-thread-only); this callback is never
|
|
||||||
* reached.
|
|
||||||
*
|
|
||||||
* @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. Locks the chunk's JSON descriptor
|
|
||||||
* as a sub-asset, parses tiles/external mesh references/entity spawns/
|
|
||||||
* area spawns, generates the terrain mesh directly from the tile grid,
|
|
||||||
* and locks/waits for every referenced model (and the terrain's shared
|
|
||||||
* tileset texture) to finish loading.
|
|
||||||
*
|
|
||||||
* @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,225 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetcutsceneloader.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/string.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
#include "asset/loader/assetloader.h"
|
|
||||||
#include "asset/asset.h"
|
|
||||||
#include "rpg/cutscene/item/json/cutscenejsonpauseflags.h"
|
|
||||||
|
|
||||||
errorret_t assetCutsceneParseItem(
|
|
||||||
assetloading_t *loading,
|
|
||||||
yyjson_val *itemObj,
|
|
||||||
cutsceneitem_t *item,
|
|
||||||
uint8_t *pool,
|
|
||||||
size_t *poolOffset,
|
|
||||||
const uint8_t index
|
|
||||||
) {
|
|
||||||
if(!yyjson_is_obj(itemObj)) {
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading,
|
|
||||||
"Cutscene item %u is not an object",
|
|
||||||
(uint32_t)index
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char_t *typeName = yyjson_get_str(yyjson_obj_get(itemObj, "type"));
|
|
||||||
if(!cutsceneItemLookupType(typeName, &item->type)) {
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading,
|
|
||||||
"Cutscene item %u: missing/unsupported item type %s",
|
|
||||||
(uint32_t)index,
|
|
||||||
typeName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
cutsceneitemloadcallback_t *load = CUTSCENE_ITEM_CALLBACKS[item->type].load;
|
|
||||||
if(load == NULL) {
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Cutscene item %u: unhandled item type %u", (uint32_t)index,
|
|
||||||
(uint32_t)item->type
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t result = load(itemObj, item, pool, poolOffset);
|
|
||||||
if(errorIsNotOk(result)) {
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_ERROR;
|
|
||||||
errorChain(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t assetCutsceneComputePoolSize(yyjson_val *itemsArr) {
|
|
||||||
size_t size = 0;
|
|
||||||
yyjson_arr_iter iter = yyjson_arr_iter_with(itemsArr);
|
|
||||||
yyjson_val *itemVal;
|
|
||||||
while((itemVal = yyjson_arr_iter_next(&iter)) != NULL) {
|
|
||||||
const char_t *typeName = yyjson_get_str(yyjson_obj_get(itemVal, "type"));
|
|
||||||
cutsceneitemtype_t type;
|
|
||||||
if(!cutsceneItemLookupType(typeName, &type)) continue;
|
|
||||||
|
|
||||||
cutsceneitempoolsizecallback_t *poolSize =
|
|
||||||
CUTSCENE_ITEM_CALLBACKS[type].poolSize;
|
|
||||||
if(poolSize == NULL) continue;
|
|
||||||
|
|
||||||
size = cutsceneJsonPoolAlign(size) + poolSize(itemVal);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetCutsceneFreeParsed(assetcutsceneoutput_t *out) {
|
|
||||||
if(out->items != NULL) {
|
|
||||||
memoryFree(out->items);
|
|
||||||
out->items = NULL;
|
|
||||||
}
|
|
||||||
if(out->pool != NULL) {
|
|
||||||
memoryFree(out->pool);
|
|
||||||
out->pool = NULL;
|
|
||||||
}
|
|
||||||
if(out->doc != NULL) {
|
|
||||||
yyjson_doc_free(out->doc);
|
|
||||||
out->doc = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetCutsceneLoaderAsync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertNotMainThread("Should be called from an async thread.");
|
|
||||||
|
|
||||||
if(
|
|
||||||
loading->loading.cutscene.state != ASSET_CUTSCENE_LOADING_STATE_READ_FILE
|
|
||||||
) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNull(loading->loading.cutscene.buffer, "Buffer already defined?");
|
|
||||||
|
|
||||||
assetfile_t *file = &loading->loading.cutscene.file;
|
|
||||||
assetLoaderErrorChain(loading,
|
|
||||||
assetFileInit(file, loading->entry->name, NULL, NULL)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(file->size > ASSET_CUTSCENE_FILE_SIZE_MAX) {
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Cutscene JSON exceeds maximum allowed size"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fileSize = (size_t)file->size;
|
|
||||||
uint8_t *buffer = memoryAllocate(fileSize);
|
|
||||||
assetLoaderErrorChain(loading, assetFileOpen(file));
|
|
||||||
assetLoaderErrorChain(loading, assetFileRead(file, buffer, fileSize));
|
|
||||||
assertTrue(
|
|
||||||
file->lastRead == file->size,
|
|
||||||
"Failed to read entire cutscene file."
|
|
||||||
);
|
|
||||||
assetLoaderErrorChain(loading, assetFileClose(file));
|
|
||||||
assetLoaderErrorChain(loading, assetFileDispose(file));
|
|
||||||
|
|
||||||
loading->loading.cutscene.buffer = buffer;
|
|
||||||
loading->loading.cutscene.size = fileSize;
|
|
||||||
loading->loading.cutscene.state = ASSET_CUTSCENE_LOADING_STATE_PARSE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetCutsceneLoaderSync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertTrue(loading->type == ASSET_LOADER_TYPE_CUTSCENE, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
if(loading->loading.cutscene.state == ASSET_CUTSCENE_LOADING_STATE_INITIAL) {
|
|
||||||
loading->loading.cutscene.state = ASSET_CUTSCENE_LOADING_STATE_READ_FILE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetcutsceneoutput_t *out = &loading->entry->data.cutscene;
|
|
||||||
uint8_t *buffer = loading->loading.cutscene.buffer;
|
|
||||||
assertNotNull(buffer, "Cutscene data should have been loaded by now.");
|
|
||||||
size_t bufferSize = loading->loading.cutscene.size;
|
|
||||||
|
|
||||||
yyjson_doc *doc = yyjson_read(
|
|
||||||
(char *)buffer, bufferSize,
|
|
||||||
YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
|
|
||||||
);
|
|
||||||
memoryFree(buffer);
|
|
||||||
loading->loading.cutscene.buffer = NULL;
|
|
||||||
|
|
||||||
if(doc == NULL) {
|
|
||||||
assetLoaderErrorThrow(loading, "Failed to parse cutscene JSON");
|
|
||||||
}
|
|
||||||
out->doc = doc;
|
|
||||||
|
|
||||||
yyjson_val *root = yyjson_doc_get_root(doc);
|
|
||||||
yyjson_val *itemsArr = yyjson_obj_get(root, "items");
|
|
||||||
if(!yyjson_is_arr(itemsArr)) {
|
|
||||||
assetCutsceneFreeParsed(out);
|
|
||||||
assetLoaderErrorThrow(loading, "Cutscene JSON is missing an 'items' array");
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t itemCount = yyjson_arr_size(itemsArr);
|
|
||||||
if(itemCount > UINT8_MAX) {
|
|
||||||
assetCutsceneFreeParsed(out);
|
|
||||||
assetLoaderErrorThrow(loading, "Cutscene has more than 255 items");
|
|
||||||
}
|
|
||||||
|
|
||||||
cutscenepause_t pause = CUTSCENE_PAUSE_DEFAULT;
|
|
||||||
yyjson_val *pauseArr = yyjson_obj_get(root, "pause");
|
|
||||||
if(yyjson_is_arr(pauseArr)) {
|
|
||||||
if(!cutsceneJsonParsePauseFlags(pauseArr, &pause)) {
|
|
||||||
assetCutsceneFreeParsed(out);
|
|
||||||
assetLoaderErrorThrow(
|
|
||||||
loading, "Cutscene JSON has an invalid 'pause' flag"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out->items = memoryAllocate(itemCount * sizeof(cutsceneitem_t));
|
|
||||||
memoryZero(out->items, itemCount * sizeof(cutsceneitem_t));
|
|
||||||
|
|
||||||
size_t poolSize = assetCutsceneComputePoolSize(itemsArr);
|
|
||||||
out->pool = poolSize > 0 ? memoryAllocate(poolSize) : NULL;
|
|
||||||
|
|
||||||
size_t poolOffset = 0;
|
|
||||||
yyjson_arr_iter itemIter = yyjson_arr_iter_with(itemsArr);
|
|
||||||
yyjson_val *itemVal;
|
|
||||||
uint8_t index = 0;
|
|
||||||
while((itemVal = yyjson_arr_iter_next(&itemIter)) != NULL) {
|
|
||||||
errorret_t itemResult = assetCutsceneParseItem(
|
|
||||||
loading, itemVal, &out->items[index], out->pool, &poolOffset, index
|
|
||||||
);
|
|
||||||
if(errorIsNotOk(itemResult)) {
|
|
||||||
assetCutsceneFreeParsed(out);
|
|
||||||
errorChain(itemResult);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
out->cutscene.items = out->items;
|
|
||||||
out->cutscene.itemCount = (uint8_t)itemCount;
|
|
||||||
out->cutscene.pause = pause;
|
|
||||||
out->cutscene.dataSize = 0;
|
|
||||||
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetCutsceneDispose(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Entry cannot be NULL");
|
|
||||||
assertTrue(entry->type == ASSET_LOADER_TYPE_CUTSCENE, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
assetCutsceneFreeParsed(&entry->data.cutscene);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,106 +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/cutscene/cutscene.h"
|
|
||||||
#include "rpg/cutscene/item/cutsceneitem.h"
|
|
||||||
#include "rpg/cutscene/item/json/cutscenejsonpool.h"
|
|
||||||
#include "yyjson.h"
|
|
||||||
|
|
||||||
#define ASSET_CUTSCENE_FILE_SIZE_MAX (1024 * 64)
|
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
void *nothing;
|
|
||||||
} assetcutsceneloaderinput_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_CUTSCENE_LOADING_STATE_INITIAL,
|
|
||||||
ASSET_CUTSCENE_LOADING_STATE_READ_FILE,
|
|
||||||
ASSET_CUTSCENE_LOADING_STATE_PARSE
|
|
||||||
} assetcutsceneloadingstate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetfile_t file;
|
|
||||||
assetcutsceneloadingstate_t state;
|
|
||||||
uint8_t *buffer;
|
|
||||||
size_t size;
|
|
||||||
} assetcutsceneloaderloading_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
cutscene_t cutscene;
|
|
||||||
cutsceneitem_t *items;
|
|
||||||
uint8_t *pool;
|
|
||||||
yyjson_doc *doc;
|
|
||||||
} assetcutsceneoutput_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses one cutscene item object into item, writing any pool-backed
|
|
||||||
* array data (entityWalkTo positions, mapAreaWait areaIds) into pool at
|
|
||||||
* *poolOffset and advancing it. Every field/enum name is validated as
|
|
||||||
* real (untrusted, authored) file content - failures are real errors, not
|
|
||||||
* asserts. Dispatches to the matching type's Load callback (see
|
|
||||||
* CUTSCENE_ITEM_CALLBACKS in rpg/cutscene/item/cutsceneitem.h) - the
|
|
||||||
* per-type parsing logic itself lives there now, colocated with that
|
|
||||||
* type's runtime behavior.
|
|
||||||
*
|
|
||||||
* @param loading Loading information for the asset being loaded.
|
|
||||||
* @param itemObj The item's JSON object.
|
|
||||||
* @param item Destination item, already zeroed by the caller.
|
|
||||||
* @param pool Base pointer of the entry's pool allocation (may be NULL if
|
|
||||||
* assetCutsceneComputePoolSize returned 0).
|
|
||||||
* @param poolOffset In/out cursor into pool.
|
|
||||||
* @param index Index of this item within the cutscene, for error messages.
|
|
||||||
* @return Error code indicating success or failure of the parse.
|
|
||||||
*/
|
|
||||||
errorret_t assetCutsceneParseItem(
|
|
||||||
assetloading_t *loading,
|
|
||||||
yyjson_val *itemObj,
|
|
||||||
cutsceneitem_t *item,
|
|
||||||
uint8_t *pool,
|
|
||||||
size_t *poolOffset,
|
|
||||||
const uint8_t index
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees whatever of out->items/out->pool/out->doc is currently non-NULL
|
|
||||||
* and clears them - shared by both the normal disposer and every parse
|
|
||||||
* failure path's cleanup.
|
|
||||||
*
|
|
||||||
* @param out The output to free.
|
|
||||||
*/
|
|
||||||
void assetCutsceneFreeParsed(assetcutsceneoutput_t *out);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asynchronous loader for cutscene assets. Reads the raw JSONC 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 assetCutsceneLoaderAsync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronous loader for cutscene assets. Parses the JSONC previously read
|
|
||||||
* by the async phase into a heap-allocated cutsceneitem_t array + pool.
|
|
||||||
*
|
|
||||||
* @param loading Loading information for the asset being loaded.
|
|
||||||
* @return Error code indicating success or failure of the load operation.
|
|
||||||
*/
|
|
||||||
errorret_t assetCutsceneLoaderSync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disposer for cutscene assets.
|
|
||||||
*
|
|
||||||
* @param entry Asset entry containing the cutscene data to dispose.
|
|
||||||
* @return Error code indicating success or failure of the dispose operation.
|
|
||||||
*/
|
|
||||||
errorret_t assetCutsceneDispose(assetentry_t *entry);
|
|
||||||
@@ -127,14 +127,6 @@ errorret_t assetMeshLoaderSync(assetloading_t *loading) {
|
|||||||
errorChain(ret);
|
errorChain(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DUSK_OPENGL) && !defined(DUSK_OPENGL_LEGACY)
|
|
||||||
// VBO owns the data now; CPU copy is no longer needed. The platform
|
|
||||||
// mesh object itself still needs meshDispose later - tracked via
|
|
||||||
// out->meshInitialized, independent of the CPU buffer's lifetime.
|
|
||||||
memoryFree(out->vertices);
|
|
||||||
out->vertices = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,8 +115,7 @@ errorret_t assetModelLoaderSync(assetloading_t *loading) {
|
|||||||
assetUnlockEntry(jsonEntry);
|
assetUnlockEntry(jsonEntry);
|
||||||
|
|
||||||
// Lock and load the mesh sub-asset.
|
// Lock and load the mesh sub-asset.
|
||||||
assetentry_t *meshEntry =
|
assetentry_t *meshEntry = assetLock(meshName, ASSET_LOADER_TYPE_MESH, NULL);
|
||||||
assetLock(meshName, ASSET_LOADER_TYPE_MESH, NULL);
|
|
||||||
ret = assetRequireLoaded(meshEntry);
|
ret = assetRequireLoaded(meshEntry);
|
||||||
if(errorIsNotOk(ret)) {
|
if(errorIsNotOk(ret)) {
|
||||||
assetUnlockEntry(meshEntry);
|
assetUnlockEntry(meshEntry);
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ errorret_t assetLocaleLoaderAsync(assetloading_t *loading) {
|
|||||||
assetLoaderErrorChain(loading, assetFileOpen(&localeFile->file));
|
assetLoaderErrorChain(loading, assetFileOpen(&localeFile->file));
|
||||||
|
|
||||||
char_t buffer[1024];
|
char_t buffer[1024];
|
||||||
assetLoaderErrorChain(loading, assetLocaleGetHeader(
|
assetLoaderErrorChain(loading, assetLocaleGetString(
|
||||||
localeFile, buffer, sizeof(buffer)
|
localeFile, "", 0, buffer, sizeof(buffer)
|
||||||
));
|
));
|
||||||
assetLoaderErrorChain(loading, assetLocaleParseHeader(
|
assetLoaderErrorChain(loading, assetLocaleParseHeader(
|
||||||
localeFile, buffer, sizeof(buffer)
|
localeFile, buffer, sizeof(buffer)
|
||||||
@@ -71,12 +71,6 @@ errorret_t assetLocaleDispose(assetentry_t *entry) {
|
|||||||
assertIsMainThread("Must be called from the main thread.");
|
assertIsMainThread("Must be called from the main thread.");
|
||||||
|
|
||||||
assetlocalefile_t *localeFile = &entry->data.locale;
|
assetlocalefile_t *localeFile = &entry->data.locale;
|
||||||
|
|
||||||
if(localeFile->cache != NULL) {
|
|
||||||
memoryFree(localeFile->cache);
|
|
||||||
localeFile->cache = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(assetFileClose(&localeFile->file));
|
errorChain(assetFileClose(&localeFile->file));
|
||||||
return assetFileDispose(&localeFile->file);
|
return assetFileDispose(&localeFile->file);
|
||||||
}
|
}
|
||||||
@@ -476,94 +470,7 @@ errorret_t assetLocaleLineUnbuffer(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetLocaleCacheFind(
|
errorret_t assetLocaleGetString(
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize,
|
|
||||||
bool_t *outHit
|
|
||||||
) {
|
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
|
||||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
|
||||||
assertNotNull(outHit, "outHit cannot be NULL.");
|
|
||||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
|
||||||
|
|
||||||
*outHit = false;
|
|
||||||
if(file->cache == NULL) errorOk();
|
|
||||||
|
|
||||||
assetlocalecache_t *cache = file->cache;
|
|
||||||
for(uint8_t i = 0; i < ASSET_LOCALE_CACHE_COUNT; i++) {
|
|
||||||
assetlocalecacheentry_t *entry = &cache->entries[i];
|
|
||||||
if(entry->messageId[0] == '\0') break;// unused tail - nothing further
|
|
||||||
if(entry->pluralCount != pluralCount) continue;
|
|
||||||
if(!stringEquals(entry->messageId, messageId)) continue;
|
|
||||||
|
|
||||||
// Move to the front of the LRU order (a no-op when already there).
|
|
||||||
if(i > 0) {
|
|
||||||
assetlocalecacheentry_t hit = *entry;
|
|
||||||
memoryMove(
|
|
||||||
&cache->entries[1], &cache->entries[0],
|
|
||||||
i * sizeof(assetlocalecacheentry_t)
|
|
||||||
);
|
|
||||||
cache->entries[0] = hit;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t len = strlen(cache->entries[0].value);
|
|
||||||
if(len >= stringBufferSize) errorThrow("String buffer overflow");
|
|
||||||
memoryCopy(stringBuffer, cache->entries[0].value, len + 1);
|
|
||||||
*outHit = true;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
void assetLocaleCacheInsert(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
const char_t *value
|
|
||||||
) {
|
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
|
||||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
|
||||||
assertNotNull(value, "Value cannot be NULL.");
|
|
||||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
|
||||||
|
|
||||||
// Caching is a pure optimization - a message ID or value too long for a
|
|
||||||
// fixed cache slot is just never cached, not an error.
|
|
||||||
if(strlen(messageId) >= ASSET_LOCALE_CACHE_KEY_MAX) return;
|
|
||||||
if(strlen(value) >= ASSET_LOCALE_CACHE_VALUE_MAX) return;
|
|
||||||
|
|
||||||
if(file->cache == NULL) {
|
|
||||||
file->cache =
|
|
||||||
(assetlocalecache_t *)memoryAllocate(sizeof(assetlocalecache_t));
|
|
||||||
memoryZero(file->cache, sizeof(assetlocalecache_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shift every entry down one slot, dropping the least-recently-used one
|
|
||||||
// off the end, to make room for the new entry at the front. This assumes
|
|
||||||
// messageId is never already present elsewhere in the cache, which holds
|
|
||||||
// as long as callers only insert after a confirmed assetLocaleCacheFind
|
|
||||||
// miss (a hit would have returned before reaching this point).
|
|
||||||
memoryMove(
|
|
||||||
&file->cache->entries[1], &file->cache->entries[0],
|
|
||||||
(ASSET_LOCALE_CACHE_COUNT - 1) * sizeof(assetlocalecacheentry_t)
|
|
||||||
);
|
|
||||||
|
|
||||||
assetlocalecacheentry_t *entry = &file->cache->entries[0];
|
|
||||||
stringCopy(entry->messageId, messageId, ASSET_LOCALE_CACHE_KEY_MAX);
|
|
||||||
entry->pluralCount = pluralCount;
|
|
||||||
stringCopy(entry->value, value, ASSET_LOCALE_CACHE_VALUE_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shared by assetLocaleGetString (external callers, messageId required
|
|
||||||
// non-empty) and assetLocaleGetHeader (messageId "", the PO format's own
|
|
||||||
// sentinel for its header entry - see assetLocaleGetHeader). Caching is
|
|
||||||
// skipped entirely for an empty messageId: assetLocaleCacheFind/Insert
|
|
||||||
// both reject one outright (same guard as assetLocaleGetString's own),
|
|
||||||
// and it's a one-shot boot-time read anyway, not worth caching.
|
|
||||||
errorret_t assetLocaleGetStringLookup(
|
|
||||||
assetlocalefile_t *file,
|
assetlocalefile_t *file,
|
||||||
const char_t *messageId,
|
const char_t *messageId,
|
||||||
const int32_t pluralCount,
|
const int32_t pluralCount,
|
||||||
@@ -575,15 +482,6 @@ errorret_t assetLocaleGetStringLookup(
|
|||||||
assertTrue(pluralCount >= 0, "Plural index cannot be negative.");
|
assertTrue(pluralCount >= 0, "Plural index cannot be negative.");
|
||||||
assertNotNull(stringBuffer, "String buffer cannot be NULL.");
|
assertNotNull(stringBuffer, "String buffer cannot be NULL.");
|
||||||
assertTrue(stringBufferSize > 0, "String buffer size must be > 0");
|
assertTrue(stringBufferSize > 0, "String buffer size must be > 0");
|
||||||
|
|
||||||
bool_t cacheHit = false;
|
|
||||||
if(messageId[0] != '\0') {
|
|
||||||
errorChain(assetLocaleCacheFind(
|
|
||||||
file, messageId, pluralCount, stringBuffer, stringBufferSize, &cacheHit
|
|
||||||
));
|
|
||||||
if(cacheHit) errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetfilelinereader_t reader;
|
assetfilelinereader_t reader;
|
||||||
|
|
||||||
bool_t msgidFound = false, msgidPluralFound = false, msgstrFound = false;
|
bool_t msgidFound = false, msgidPluralFound = false, msgstrFound = false;
|
||||||
@@ -727,38 +625,9 @@ errorret_t assetLocaleGetStringLookup(
|
|||||||
errorThrow("Failed to find msgstr for message ID: %s", messageId);
|
errorThrow("Failed to find msgstr for message ID: %s", messageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(messageId[0] != '\0') {
|
|
||||||
assetLocaleCacheInsert(file, messageId, pluralCount, stringBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetLocaleGetString(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize
|
|
||||||
) {
|
|
||||||
assertNotNull(messageId, "Message ID cannot be NULL.");
|
|
||||||
assertStrLenMin(messageId, 1, "Message ID cannot be empty.");
|
|
||||||
|
|
||||||
return assetLocaleGetStringLookup(
|
|
||||||
file, messageId, pluralCount, stringBuffer, stringBufferSize
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetLocaleGetHeader(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize
|
|
||||||
) {
|
|
||||||
return assetLocaleGetStringLookup(
|
|
||||||
file, "", 0, stringBuffer, stringBufferSize
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetLocaleGetStringWithVA(
|
errorret_t assetLocaleGetStringWithVA(
|
||||||
assetlocalefile_t *file,
|
assetlocalefile_t *file,
|
||||||
const char_t *messageId,
|
const char_t *messageId,
|
||||||
|
|||||||
@@ -70,41 +70,6 @@ typedef struct {
|
|||||||
};
|
};
|
||||||
} assetlocalearg_t;
|
} assetlocalearg_t;
|
||||||
|
|
||||||
/** Number of recently resolved strings @ref assetlocalecache_t remembers. */
|
|
||||||
#define ASSET_LOCALE_CACHE_COUNT 128
|
|
||||||
|
|
||||||
/** Max length (excluding null terminator) of a cacheable message ID. */
|
|
||||||
#define ASSET_LOCALE_CACHE_KEY_MAX 64
|
|
||||||
|
|
||||||
/** Max length (excluding null terminator) of a cacheable resolved string. */
|
|
||||||
#define ASSET_LOCALE_CACHE_VALUE_MAX 256
|
|
||||||
|
|
||||||
/** One (messageId, pluralCount) -> resolved string cache slot. */
|
|
||||||
typedef struct {
|
|
||||||
char_t messageId[ASSET_LOCALE_CACHE_KEY_MAX];
|
|
||||||
int32_t pluralCount;
|
|
||||||
char_t value[ASSET_LOCALE_CACHE_VALUE_MAX];
|
|
||||||
} assetlocalecacheentry_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixed-size move-to-front LRU cache of recently resolved locale strings.
|
|
||||||
* assetLocaleGetString() re-scans and re-decompresses the whole PO file on
|
|
||||||
* every miss, which is expensive to repeat for strings a screen fetches
|
|
||||||
* every time it opens (menu labels, etc) - this cache lets identical
|
|
||||||
* (messageId, pluralCount) lookups skip that entirely.
|
|
||||||
*
|
|
||||||
* Lazily allocated on the first cache insert (see assetlocalefile_t.cache)
|
|
||||||
* so locale entries that are never queried, or a file that's disposed
|
|
||||||
* before anything is cached, never pay for it.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
/**
|
|
||||||
* Entries ordered most-recently-used first. An entry with
|
|
||||||
* messageId[0] == '\0' (and every entry after it) is unused.
|
|
||||||
*/
|
|
||||||
assetlocalecacheentry_t entries[ASSET_LOCALE_CACHE_COUNT];
|
|
||||||
} assetlocalecache_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime state for an open locale file.
|
* Runtime state for an open locale file.
|
||||||
*
|
*
|
||||||
@@ -133,16 +98,6 @@ typedef struct {
|
|||||||
|
|
||||||
/** Form index used when no conditional clause matches. */
|
/** Form index used when no conditional clause matches. */
|
||||||
uint8_t pluralDefaultIndex;
|
uint8_t pluralDefaultIndex;
|
||||||
|
|
||||||
/**
|
|
||||||
* Recently resolved string cache, or NULL if nothing has been cached yet.
|
|
||||||
* Heap-allocated rather than embedded because assetlocalefile_t lives
|
|
||||||
* inside the shared assetloaderoutput_t union alongside every other
|
|
||||||
* asset type - embedding a 128-entry cache there would size that union
|
|
||||||
* (and therefore every one of the ASSET_ENTRY_COUNT_MAX asset slots,
|
|
||||||
* regardless of what type of asset occupies it) up by the same amount.
|
|
||||||
*/
|
|
||||||
assetlocalecache_t *cache;
|
|
||||||
} assetlocalefile_t;
|
} assetlocalefile_t;
|
||||||
|
|
||||||
/** Convenience alias - the loaded output type of a locale asset entry. */
|
/** Convenience alias - the loaded output type of a locale asset entry. */
|
||||||
@@ -248,93 +203,15 @@ errorret_t assetLocaleLineUnbuffer(
|
|||||||
const size_t stringBufferSize
|
const size_t stringBufferSize
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches a locale file's cache for a previously resolved
|
|
||||||
* (messageId, pluralCount) pair.
|
|
||||||
*
|
|
||||||
* On a hit, copies the cached value into `stringBuffer` (erroring if it
|
|
||||||
* doesn't fit, same contract as @ref assetLocaleGetString) and moves the
|
|
||||||
* entry to the front of the cache's move-to-front LRU order. On a miss,
|
|
||||||
* `stringBuffer` is left untouched.
|
|
||||||
*
|
|
||||||
* @param file Locale file whose cache to search. Its cache may be NULL
|
|
||||||
* (nothing cached yet), which is treated as a miss.
|
|
||||||
* @param messageId Message ID to look up.
|
|
||||||
* @param pluralCount Plural count the original lookup used.
|
|
||||||
* @param stringBuffer Destination buffer, filled only on a hit.
|
|
||||||
* @param stringBufferSize Capacity of `stringBuffer` in bytes.
|
|
||||||
* @param outHit Set to true on a cache hit, false on a miss.
|
|
||||||
* @return OK on success (hit or miss), error if a hit's cached value does
|
|
||||||
* not fit `stringBuffer`.
|
|
||||||
*/
|
|
||||||
errorret_t assetLocaleCacheFind(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize,
|
|
||||||
bool_t *outHit
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Records a resolved (messageId, pluralCount) -> value string at the front
|
|
||||||
* of the cache's move-to-front LRU order, evicting the least-recently-used
|
|
||||||
* entry if the cache is already full. Lazily allocates the cache (see
|
|
||||||
* assetlocalefile_t.cache) on the first call.
|
|
||||||
*
|
|
||||||
* Caching is a pure optimization: if `messageId` or `value` is too long to
|
|
||||||
* fit the cache's fixed-size slots, this silently does nothing rather than
|
|
||||||
* erroring or growing the cache.
|
|
||||||
*
|
|
||||||
* @param file Locale file whose cache to insert into.
|
|
||||||
* @param messageId Message ID that was looked up.
|
|
||||||
* @param pluralCount Plural count the lookup was made with.
|
|
||||||
* @param value Resolved string to cache.
|
|
||||||
*/
|
|
||||||
void assetLocaleCacheInsert(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
const char_t *value
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared lookup core behind assetLocaleGetString and assetLocaleGetHeader:
|
|
||||||
* checks the file's cache first (see @ref assetLocaleCacheFind; skipped
|
|
||||||
* entirely for an empty messageId, since the cache rejects one), on a
|
|
||||||
* miss rewinds the file and scans from the beginning, then caches the
|
|
||||||
* result (see @ref assetLocaleCacheInsert, same empty-messageId skip)
|
|
||||||
* before returning. For plural entries (`msgid_plural`) the
|
|
||||||
* `pluralCount` is evaluated against the loaded plural rules to select
|
|
||||||
* the correct `msgstr[N]` form.
|
|
||||||
*
|
|
||||||
* Unlike assetLocaleGetString, messageId may be `""` here (see
|
|
||||||
* assetLocaleGetHeader) - this is the shared implementation both of
|
|
||||||
* them delegate to, not a public entry point of its own in practice.
|
|
||||||
*
|
|
||||||
* @param file Locale file to search. Must be open.
|
|
||||||
* @param messageId PO message ID to find, or `""` for the header entry.
|
|
||||||
* @param pluralCount Count used to select the plural form (ignored for
|
|
||||||
* singular entries).
|
|
||||||
* @param stringBuffer Buffer to receive the translated string.
|
|
||||||
* @param stringBufferSize Capacity of `stringBuffer` in bytes.
|
|
||||||
* @return OK on success, error if the message ID is not found or I/O fails.
|
|
||||||
*/
|
|
||||||
errorret_t assetLocaleGetStringLookup(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
const char_t *messageId,
|
|
||||||
const int32_t pluralCount,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up a translated string by message ID from the open locale file.
|
* Looks up a translated string by message ID from the open locale file.
|
||||||
* See @ref assetLocaleGetStringLookup for the lookup/caching mechanics.
|
*
|
||||||
|
* Rewinds the file and scans from the beginning on every call. For plural
|
||||||
|
* entries (`msgid_plural`) the `pluralCount` is evaluated against the loaded
|
||||||
|
* plural rules to select the correct `msgstr[N]` form.
|
||||||
*
|
*
|
||||||
* @param file Locale file to search. Must be open.
|
* @param file Locale file to search. Must be open.
|
||||||
* @param messageId PO message ID to find. Must be non-empty - use
|
* @param messageId PO message ID to find (`""` retrieves the header entry).
|
||||||
* @ref assetLocaleGetHeader to read the header entry.
|
|
||||||
* @param pluralCount Count used to select the plural form (ignored for
|
* @param pluralCount Count used to select the plural form (ignored for
|
||||||
* singular entries).
|
* singular entries).
|
||||||
* @param stringBuffer Buffer to receive the translated string.
|
* @param stringBuffer Buffer to receive the translated string.
|
||||||
@@ -349,27 +226,6 @@ errorret_t assetLocaleGetString(
|
|||||||
const size_t stringBufferSize
|
const size_t stringBufferSize
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the PO file's header entry (the `msgid ""` block every PO file
|
|
||||||
* starts with, holding metadata like the plural-forms rule) - see @ref
|
|
||||||
* assetLocaleParseHeader, its caller. A dedicated function rather than
|
|
||||||
* calling assetLocaleGetString(file, "", ...) since messageId "" is a
|
|
||||||
* PO-format-internal sentinel, not a real (untrusted) caller-supplied
|
|
||||||
* message ID, so it doesn't go through assetLocaleGetString's normal
|
|
||||||
* non-empty validation.
|
|
||||||
*
|
|
||||||
* @param file Locale file to search. Must be open.
|
|
||||||
* @param stringBuffer Buffer to receive the raw header block.
|
|
||||||
* @param stringBufferSize Capacity of `stringBuffer` in bytes.
|
|
||||||
* @return OK on success, error if the header entry is missing or I/O
|
|
||||||
* fails.
|
|
||||||
*/
|
|
||||||
errorret_t assetLocaleGetHeader(
|
|
||||||
assetlocalefile_t *file,
|
|
||||||
char_t *stringBuffer,
|
|
||||||
const size_t stringBufferSize
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up a translated string and formats it with a `printf`-style variadic
|
* Looks up a translated string and formats it with a `printf`-style variadic
|
||||||
* argument list.
|
* argument list.
|
||||||
|
|||||||
@@ -1,255 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetmp3loader.h"
|
|
||||||
#include "util/memory.h"
|
|
||||||
#include "util/math.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "asset/loader/assetloading.h"
|
|
||||||
#include "asset/loader/assetentry.h"
|
|
||||||
|
|
||||||
// How far into the file (after any ID3v2 tag) assetMp3ParseHeader() will
|
|
||||||
// search for the first valid MPEG frame sync. Real encoders write it
|
|
||||||
// within the first handful of bytes; this is a generous sane upper bound
|
|
||||||
// (matching assetwavloader.c's own approach to bounding a stack buffer)
|
|
||||||
// rather than a real expectation of needing that much.
|
|
||||||
#define ASSET_MP3_HEADER_SEARCH_MAX 8192
|
|
||||||
|
|
||||||
// MPEG-1 Layer III bitrates (kbps), indexed by the header's 4-bit bitrate
|
|
||||||
// index. Index 0 ("free format") and 15 (reserved) aren't supported.
|
|
||||||
static const uint16_t ASSET_MP3_BITRATE_MPEG1_L3[16] = {
|
|
||||||
0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
// MPEG-2/2.5 Layer III bitrates (kbps) - a different table from MPEG-1's.
|
|
||||||
static const uint16_t ASSET_MP3_BITRATE_MPEG2_L3[16] = {
|
|
||||||
0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint32_t ASSET_MP3_SAMPLE_RATE_MPEG1[4] = {
|
|
||||||
44100, 48000, 32000, 0
|
|
||||||
};
|
|
||||||
static const uint32_t ASSET_MP3_SAMPLE_RATE_MPEG2[4] = {
|
|
||||||
22050, 24000, 16000, 0
|
|
||||||
};
|
|
||||||
static const uint32_t ASSET_MP3_SAMPLE_RATE_MPEG25[4] = {
|
|
||||||
11025, 12000, 8000, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
errorret_t assetMp3LoaderAsync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertNotMainThread("Async loader should not be on main thread.");
|
|
||||||
|
|
||||||
if(loading->loading.mp3.state != ASSET_MP3_LOADER_STATE_READ_HEADER) {
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
assetmp3file_t *mp3File = &loading->entry->data.mp3;
|
|
||||||
memoryZero(mp3File, sizeof(assetmp3file_t));
|
|
||||||
|
|
||||||
assetfile_t file;
|
|
||||||
assetLoaderErrorChain(loading, assetFileInit(
|
|
||||||
&file, loading->entry->name, NULL, NULL
|
|
||||||
));
|
|
||||||
assetLoaderErrorChain(loading, assetFileOpen(&file));
|
|
||||||
assetLoaderErrorChain(loading, assetMp3ParseHeader(&file, mp3File));
|
|
||||||
assetLoaderErrorChain(loading, assetFileClose(&file));
|
|
||||||
assetLoaderErrorChain(loading, assetFileDispose(&file));
|
|
||||||
|
|
||||||
loading->loading.mp3.state = ASSET_MP3_LOADER_STATE_DONE;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_SYNC;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetMp3LoaderSync(assetloading_t *loading) {
|
|
||||||
assertNotNull(loading, "Loading cannot be NULL");
|
|
||||||
assertTrue(loading->type == ASSET_LOADER_TYPE_MP3, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
switch(loading->loading.mp3.state) {
|
|
||||||
case ASSET_MP3_LOADER_STATE_INITIAL:
|
|
||||||
loading->loading.mp3.state = ASSET_MP3_LOADER_STATE_READ_HEADER;
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_PENDING_ASYNC;
|
|
||||||
errorOk();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ASSET_MP3_LOADER_STATE_DONE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetMp3Dispose(assetentry_t *entry) {
|
|
||||||
assertNotNull(entry, "Asset entry cannot be NULL");
|
|
||||||
assertTrue(entry->type == ASSET_LOADER_TYPE_MP3, "Invalid type.");
|
|
||||||
assertIsMainThread("Must be called from the main thread.");
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t assetMp3ParseHeader(assetfile_t *file, assetmp3file_t *mp3File) {
|
|
||||||
assertNotNull(file, "Asset file cannot be NULL.");
|
|
||||||
assertNotNull(mp3File, "Mp3 file cannot be NULL.");
|
|
||||||
|
|
||||||
memoryZero(mp3File, sizeof(assetmp3file_t));
|
|
||||||
|
|
||||||
// Skip a leading ID3v2 tag if present: "ID3" + version(2) + flags(1) + a
|
|
||||||
// 4-byte syncsafe (7 usable bits/byte) size covering everything after
|
|
||||||
// this 10-byte header.
|
|
||||||
uint8_t id3Header[10];
|
|
||||||
errorChain(assetFileRead(file, id3Header, sizeof(id3Header)));
|
|
||||||
|
|
||||||
size_t searchBase;
|
|
||||||
if(memoryCompare(id3Header, "ID3", 3) == 0) {
|
|
||||||
const uint32_t tagSize = (
|
|
||||||
((uint32_t) (id3Header[6] & 0x7F) << 21) |
|
|
||||||
((uint32_t) (id3Header[7] & 0x7F) << 14) |
|
|
||||||
((uint32_t) (id3Header[8] & 0x7F) << 7) |
|
|
||||||
((uint32_t) (id3Header[9] & 0x7F))
|
|
||||||
);
|
|
||||||
errorChain(assetFileRead(file, NULL, tagSize));
|
|
||||||
searchBase = sizeof(id3Header) + tagSize;
|
|
||||||
} else {
|
|
||||||
// No ID3v2 tag - rewind the probe bytes just consumed so the frame
|
|
||||||
// sync search below starts from the true beginning of the file.
|
|
||||||
errorChain(assetFileRewind(file));
|
|
||||||
searchBase = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t searchWindowSize = mathMin(
|
|
||||||
(size_t) ASSET_MP3_HEADER_SEARCH_MAX,
|
|
||||||
(size_t) file->size > searchBase ? (size_t) file->size - searchBase : 0
|
|
||||||
);
|
|
||||||
if(searchWindowSize < 4) {
|
|
||||||
errorThrow(
|
|
||||||
"MP3 file is too short to contain a frame header: %s", file->filename
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *window = (uint8_t *) memoryAllocate(searchWindowSize);
|
|
||||||
errorret_t readRet = assetFileRead(file, window, searchWindowSize);
|
|
||||||
if(errorIsNotOk(readRet)) {
|
|
||||||
memoryFree(window);
|
|
||||||
errorChain(readRet);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_t found = false;
|
|
||||||
size_t frameIndex = 0;
|
|
||||||
|
|
||||||
for(size_t i = 0; i + 4 <= searchWindowSize; i++) {
|
|
||||||
if(window[i] != 0xFF || (window[i + 1] & 0xE0) != 0xE0) continue;
|
|
||||||
|
|
||||||
const uint8_t versionBits = (window[i + 1] >> 3) & 0x3;
|
|
||||||
const uint8_t layerBits = (window[i + 1] >> 1) & 0x3;
|
|
||||||
// reserved version, or not Layer III
|
|
||||||
if(versionBits == 1 || layerBits != 1) continue;
|
|
||||||
|
|
||||||
const uint8_t bitrateIndex = (window[i + 2] >> 4) & 0xF;
|
|
||||||
const uint8_t sampleRateIndex = (window[i + 2] >> 2) & 0x3;
|
|
||||||
if(
|
|
||||||
bitrateIndex == 0 || bitrateIndex == 15 || sampleRateIndex == 3
|
|
||||||
) continue;
|
|
||||||
|
|
||||||
const uint8_t channelMode = (window[i + 3] >> 6) & 0x3;
|
|
||||||
const bool_t isMpeg1 = versionBits == 3;
|
|
||||||
|
|
||||||
mp3File->bitrateKbps = isMpeg1
|
|
||||||
? ASSET_MP3_BITRATE_MPEG1_L3[bitrateIndex]
|
|
||||||
: ASSET_MP3_BITRATE_MPEG2_L3[bitrateIndex];
|
|
||||||
mp3File->sampleRate = isMpeg1
|
|
||||||
? ASSET_MP3_SAMPLE_RATE_MPEG1[sampleRateIndex]
|
|
||||||
: (versionBits == 2
|
|
||||||
? ASSET_MP3_SAMPLE_RATE_MPEG2[sampleRateIndex]
|
|
||||||
: ASSET_MP3_SAMPLE_RATE_MPEG25[sampleRateIndex]);
|
|
||||||
mp3File->samplesPerFrame = isMpeg1 ? 1152 : 576;
|
|
||||||
mp3File->channels = channelMode == 3 ? 1 : 2;
|
|
||||||
|
|
||||||
// A Xing/Info header, if present, sits right after the side info -
|
|
||||||
// whose size depends on MPEG version and channel mode - immediately
|
|
||||||
// following the 4-byte header (plus a 2-byte CRC, if the protection
|
|
||||||
// bit says one follows).
|
|
||||||
const bool_t hasCrc = (window[i + 1] & 0x1) == 0;
|
|
||||||
const size_t sideInfoSize = isMpeg1
|
|
||||||
? (mp3File->channels == 1 ? 17 : 32)
|
|
||||||
: (mp3File->channels == 1 ? 9 : 17);
|
|
||||||
const size_t xingOffset = i + 4 + (hasCrc ? 2 : 0) + sideInfoSize;
|
|
||||||
|
|
||||||
if(
|
|
||||||
xingOffset + 8 <= searchWindowSize &&
|
|
||||||
(
|
|
||||||
memoryCompare(window + xingOffset, "Xing", 4) == 0 ||
|
|
||||||
memoryCompare(window + xingOffset, "Info", 4) == 0
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
const uint8_t *flagsBytes = window + xingOffset + 4;
|
|
||||||
const uint32_t flags = (
|
|
||||||
((uint32_t) flagsBytes[0] << 24) | ((uint32_t) flagsBytes[1] << 16) |
|
|
||||||
((uint32_t) flagsBytes[2] << 8) | (uint32_t) flagsBytes[3]
|
|
||||||
);
|
|
||||||
if((flags & 0x1) != 0 && xingOffset + 12 <= searchWindowSize) {
|
|
||||||
const uint8_t *framesBytes = window + xingOffset + 8;
|
|
||||||
const uint32_t xingFrameCount = (
|
|
||||||
((uint32_t) framesBytes[0] << 24) |
|
|
||||||
((uint32_t) framesBytes[1] << 16) |
|
|
||||||
((uint32_t) framesBytes[2] << 8) |
|
|
||||||
(uint32_t) framesBytes[3]
|
|
||||||
);
|
|
||||||
// The Xing/Info header's frame count includes the header's own
|
|
||||||
// frame (this one, at `i`) - which libmad (and sceMp3) will
|
|
||||||
// attempt to decode like any other, but which doesn't contribute a
|
|
||||||
// real decodable frame of audio the way every other one does.
|
|
||||||
// Confirmed against a real LAME-encoded file: its Xing header
|
|
||||||
// declared 40 frames, but decoding actually produced exactly 39
|
|
||||||
// frames' worth of real PCM - without this -1, playback would
|
|
||||||
// permanently stall one frame short of the declared total (audible
|
|
||||||
// as "never loops"), since real decode output can never catch up
|
|
||||||
// to an overstated total.
|
|
||||||
if(xingFrameCount > 0) {
|
|
||||||
mp3File->totalFrames =
|
|
||||||
(size_t) (xingFrameCount - 1) * mp3File->samplesPerFrame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frameIndex = i;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
memoryFree(window);
|
|
||||||
|
|
||||||
if(!found) {
|
|
||||||
errorThrow(
|
|
||||||
"MP3 file has no valid MPEG-1/2/2.5 Layer III frame within the first "
|
|
||||||
"%u bytes: %s",
|
|
||||||
(uint32_t) searchWindowSize, file->filename
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
mp3File->dataOffset = searchBase + frameIndex;
|
|
||||||
mp3File->dataSize = (size_t) file->size - mp3File->dataOffset;
|
|
||||||
|
|
||||||
// No Xing/Info header found - estimate assuming constant bitrate (the
|
|
||||||
// common case when one's genuinely absent; a real VBR file without one
|
|
||||||
// is rare and will just get an approximate duration/loop point instead
|
|
||||||
// of an exact one).
|
|
||||||
if(mp3File->totalFrames == 0) {
|
|
||||||
const float_t durationSeconds = (
|
|
||||||
((float_t) mp3File->dataSize * 8.0f) /
|
|
||||||
((float_t) mp3File->bitrateKbps * 1000.0f)
|
|
||||||
);
|
|
||||||
mp3File->totalFrames =
|
|
||||||
(size_t) (durationSeconds * (float_t) mp3File->sampleRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "error/error.h"
|
|
||||||
#include "asset/assetfile.h"
|
|
||||||
|
|
||||||
typedef struct assetloading_s assetloading_t;
|
|
||||||
typedef struct assetentry_s assetentry_t;
|
|
||||||
|
|
||||||
typedef struct { void *nothing; } assetmp3loaderinput_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ASSET_MP3_LOADER_STATE_INITIAL,
|
|
||||||
ASSET_MP3_LOADER_STATE_READ_HEADER,
|
|
||||||
ASSET_MP3_LOADER_STATE_DONE
|
|
||||||
} assetmp3loaderstate_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
assetmp3loaderstate_t state;
|
|
||||||
} assetmp3loaderloading_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parsed metadata for an MP3 asset - deliberately just enough to configure
|
|
||||||
* a decoder and know the clip's total length, not anything about its
|
|
||||||
* actual compressed content (which is read/decoded on demand at playback
|
|
||||||
* time - see audiostreammp3.c). Only MPEG-1/2/2.5 Layer III ("MP3" in the
|
|
||||||
* everyday sense) is supported; Layers I/II are rejected.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint32_t sampleRate;
|
|
||||||
uint8_t channels;
|
|
||||||
|
|
||||||
// 1152 for MPEG-1, 576 for MPEG-2/2.5 - how many PCM samples (per
|
|
||||||
// channel) one compressed MPEG frame decodes to.
|
|
||||||
uint16_t samplesPerFrame;
|
|
||||||
|
|
||||||
// The first frame's bitrate, in kbps. Used only as a fallback duration
|
|
||||||
// estimate (assuming CBR) when no Xing/Info header is found - see
|
|
||||||
// assetMp3ParseHeader()'s own comment.
|
|
||||||
uint32_t bitrateKbps;
|
|
||||||
|
|
||||||
// Byte offset (from the start of the file) of the first real MPEG
|
|
||||||
// frame, i.e. right after any leading ID3v2 tag.
|
|
||||||
size_t dataOffset;
|
|
||||||
|
|
||||||
// Bytes of compressed MPEG data, from dataOffset to the end of the file.
|
|
||||||
size_t dataSize;
|
|
||||||
|
|
||||||
// Decoded PCM frame count for the whole clip - exact if a Xing/Info
|
|
||||||
// header was found (the common case for anything encoded with a modern
|
|
||||||
// tool), otherwise estimated from bitrateKbps/dataSize assuming CBR (see
|
|
||||||
// assetMp3ParseHeader()'s own comment) - unlike assetwavfile_t.dataSize,
|
|
||||||
// MP3 has no header field that gives this directly.
|
|
||||||
size_t totalFrames;
|
|
||||||
} assetmp3file_t;
|
|
||||||
|
|
||||||
typedef assetmp3file_t assetmp3output_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Async (background-thread) half of the MP3 loader - opens the asset file,
|
|
||||||
* parses its header (see assetMp3ParseHeader()), and closes it again. Never
|
|
||||||
* buffers the compressed MPEG data itself; that's read on demand at
|
|
||||||
* playback time by audiostreammp3.c via its own independent file handle.
|
|
||||||
*
|
|
||||||
* @param loading The asset loading slot.
|
|
||||||
* @return Error indicating success or failure.
|
|
||||||
*/
|
|
||||||
errorret_t assetMp3LoaderAsync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sync (main-thread) half of the MP3 loader - a simple state machine that
|
|
||||||
* schedules the async header parse and marks the entry loaded once it's
|
|
||||||
* done, mirroring assetWavLoaderSync()'s shape exactly.
|
|
||||||
*
|
|
||||||
* @param loading The asset loading slot.
|
|
||||||
* @return Error indicating success or failure.
|
|
||||||
*/
|
|
||||||
errorret_t assetMp3LoaderSync(assetloading_t *loading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disposes an MP3 asset entry. A no-op - an assetmp3file_t owns no heap
|
|
||||||
* allocations, and playback streams open their own independent file
|
|
||||||
* handles (see audiostreammp3.c).
|
|
||||||
*
|
|
||||||
* @param entry The asset entry to dispose.
|
|
||||||
* @return Error indicating success or failure.
|
|
||||||
*/
|
|
||||||
errorret_t assetMp3Dispose(assetentry_t *entry);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses an MP3 file's metadata from an already-opened asset file
|
|
||||||
* positioned at its very start: skips a leading ID3v2 tag if present,
|
|
||||||
* scans forward for the first valid MPEG-1/2/2.5 Layer III frame header
|
|
||||||
* (rejecting anything else - other layers, or no valid frame found within
|
|
||||||
* a sane search window), and checks that frame for a Xing/Info header
|
|
||||||
* (found in the vast majority of real-world MP3s, VBR or CBR) to get an
|
|
||||||
* exact total-frame count; falls back to a CBR estimate from the first
|
|
||||||
* frame's bitrate and the file's remaining size if absent.
|
|
||||||
*
|
|
||||||
* Never reads more than a bounded lookahead window into memory - the bulk
|
|
||||||
* of the file (the actual compressed audio, following the parsed frame's
|
|
||||||
* position) is left untouched, exactly like assetWavParseHeader().
|
|
||||||
*
|
|
||||||
* @param file Asset file to parse, positioned at offset 0.
|
|
||||||
* @param mp3File Filled with the parsed metadata on success.
|
|
||||||
* @return Error indicating success or failure.
|
|
||||||
*/
|
|
||||||
errorret_t assetMp3ParseHeader(assetfile_t *file, assetmp3file_t *mp3File);
|
|
||||||
Loaded 100 of 976 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user