Compare commits
86 Commits
5cea284906
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d0a057e0ee | |||
| 8b49902bf6 | |||
| 71c1e56564 | |||
| 1b12e67de2 | |||
| 291bb4bb81 | |||
| 342ddb19f8 | |||
| 9c9d2d548e | |||
| d7a0bb4509 | |||
| 2b1a3323a8 | |||
| 99d030003c | |||
| 92a753560b | |||
| af9904c892 | |||
| e5e8c49f6c | |||
| b37e5f45ca | |||
| e1f08b07aa | |||
| 073ee8dca9 | |||
| a26e51cf46 | |||
| dfed732825 | |||
| 87aa70c6d2 | |||
| aa2979ffe7 | |||
| 236e16aa6d | |||
| 184bb970e6 | |||
| bd54469891 | |||
| 2f5dccc3ef | |||
| 592edb90a0 | |||
| 3db7e6b1b9 | |||
| 13c4df0d85 | |||
| ef25fb09da | |||
| 03cf4a9efe | |||
| 53dd36efdd | |||
| ad9e841a42 | |||
| 14f3f464c7 | |||
| cbe51cc8d0 | |||
| efaa3f6eea | |||
| 52cce9a3b0 | |||
| b7b390311e | |||
| c1eeddd14b | |||
| 1a7a55dfc3 | |||
| fe5927ea6a | |||
| 119c794ad7 | |||
| e2076b2c1c | |||
| 5208c5148e | |||
| d80660b097 | |||
| b916d0278b | |||
| d51e13e620 | |||
| 40ad4326ef | |||
| b8afc1684a | |||
| 8348b31ac8 | |||
| 411f2dbcce | |||
| ee89c08160 | |||
| 357607a89f | |||
| 8d6dc2df44 | |||
| 5207582ab3 | |||
| 71768e6154 | |||
| ecbe235523 | |||
| afef079d1e | |||
| df17696c69 | |||
| 065bf0908f | |||
| 5b6755e9cf | |||
| b08482acf1 | |||
| 80c9c1d389 | |||
| bb7db57bda | |||
| 6a83ac767c | |||
| 7e47ef9d74 | |||
| e7ec603526 | |||
| 2d8ae09bd8 | |||
| b2affbc0a7 | |||
| d50bc61ada | |||
| ec6b032b45 | |||
| bc72f48496 | |||
| dcf06fbd36 | |||
| 96311d72c2 | |||
| 07938cccc7 | |||
| 097c8c00f9 | |||
| aa5b41fe31 | |||
| 0d56859d94 | |||
| 1af5f238e4 | |||
| dd697d5650 | |||
| 5cf299a1c7 | |||
| 67bf825cc9 | |||
| 56e1696cd4 | |||
| d955fb6430 | |||
| dd910a31aa | |||
| 708c4d0ec3 | |||
| ad13d6c6a1 | |||
| 1c32158142 |
5
.ci/dolphin/Dockerfile
Normal file
5
.ci/dolphin/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
FROM devkitpro/devkitppc
|
||||||
|
|
||||||
|
RUN apt update && \
|
||||||
|
apt install -y python3 python3-pip python3-polib python3-pil python3-dotenv python3-pyqt5 python3-opengl && \
|
||||||
|
dkp-pacman -S --needed --noconfirm gamecube-sdl2 ppc-liblzma ppc-libzip
|
||||||
13
.ci/dolphin/build-gamecube.sh
Executable file
13
.ci/dolphin/build-gamecube.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t myapp:latest -f .ci/dolphin/Dockerfile .
|
||||||
|
docker run -it -v ./:/workdir myapp:latest /bin/bash -c ' \
|
||||||
|
export PATH="$DEVKITPPC/bin:$PATH" && \
|
||||||
|
cd /workdir && \
|
||||||
|
rm -rf build-gamecube && \
|
||||||
|
mkdir -p build-gamecube && \
|
||||||
|
# cmake -S. -Bbuild-gamecube -DDUSK_TARGET_SYSTEM=gamecube -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake" && \
|
||||||
|
cmake -S. -Bbuild-gamecube -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" && \
|
||||||
|
cd build-gamecube && \
|
||||||
|
make -j$(nproc) VERBOSE=1 && \
|
||||||
|
cp ./Dusk.dol ./boot.dol
|
||||||
|
'
|
||||||
13
.ci/dolphin/build-wii.sh
Executable file
13
.ci/dolphin/build-wii.sh
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t myapp:latest -f .ci/dolphin/Dockerfile .
|
||||||
|
docker run -v ./:/workdir myapp:latest /bin/bash -c ' \
|
||||||
|
export PATH="$DEVKITPPC/bin:$PATH" && \
|
||||||
|
cd /workdir && \
|
||||||
|
rm -rf build-wii && \
|
||||||
|
mkdir -p build-wii && \
|
||||||
|
cmake -S. -Bbuild-wii -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" && \
|
||||||
|
cd build-wii && \
|
||||||
|
make -j$(nproc) VERBOSE=1 && \
|
||||||
|
mv ./Dusk.dol ./boot.dol
|
||||||
|
'
|
||||||
|
# docker run -it -v ./:/workdir myapp:latest /bin/bash
|
||||||
10
.ci/dolphin/meta.xml
Normal file
10
.ci/dolphin/meta.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<app version="1">
|
||||||
|
<name>Dusk</name>
|
||||||
|
<version>1.00</version>
|
||||||
|
<release_date></release_date>
|
||||||
|
<coder>YouWish</coder>
|
||||||
|
<short_description>Dusk game</short_description>
|
||||||
|
<long_description>No description yet.</long_description>
|
||||||
|
<ahb_access/>
|
||||||
|
</app>
|
||||||
5
.ci/psp/build-psp.sh
Executable file
5
.ci/psp/build-psp.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
mkdir -p build-psp
|
||||||
|
cd build-psp
|
||||||
|
cmake .. -DDUSK_TARGET_SYSTEM=psp
|
||||||
|
make -j$(nproc)
|
||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5
|
uses: https://git.wish.moe/YourWishes/checkout@main
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
@@ -29,7 +29,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5
|
uses: https://git.wish.moe/YourWishes/checkout@main
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
@@ -41,7 +41,7 @@ jobs:
|
|||||||
- name: List build output
|
- name: List build output
|
||||||
run: ls -lh build
|
run: ls -lh build
|
||||||
- name: Upload Linux binary
|
- name: Upload Linux binary
|
||||||
uses: actions/upload-artifact@v3
|
uses: https://git.wish.moe/YourWishes/upload-artifact@v3/node20
|
||||||
with:
|
with:
|
||||||
name: dusk-linux
|
name: dusk-linux
|
||||||
path: build/Dusk
|
path: build/Dusk
|
||||||
@@ -51,7 +51,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5
|
uses: https://git.wish.moe/YourWishes/checkout@main
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
@@ -67,8 +67,90 @@ jobs:
|
|||||||
- name: List build output
|
- name: List build output
|
||||||
run: ls -lh build/gitea/Dusk
|
run: ls -lh build/gitea/Dusk
|
||||||
- name: Upload PSP binary
|
- name: Upload PSP binary
|
||||||
uses: actions/upload-artifact@v3
|
uses: https://git.wish.moe/YourWishes/upload-artifact@v3/node20
|
||||||
with:
|
with:
|
||||||
name: dusk-psp
|
name: dusk-psp
|
||||||
path: build/gitea/
|
path: build/gitea/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-dolphin:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: https://git.wish.moe/YourWishes/checkout@main
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
# Install devkit pacman
|
||||||
|
if ! [ $(id -u) = 0 ]; then
|
||||||
|
echo "Need root privilege to install!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ensure apt is set up to work with https sources
|
||||||
|
apt-get install apt-transport-https
|
||||||
|
|
||||||
|
# Store devkitPro gpg key locally if we don't have it already
|
||||||
|
if ! [ -f /usr/share/keyring/devkitpro-pub.gpg ]; then
|
||||||
|
mkdir -p /usr/share/keyring/
|
||||||
|
wget -U "dkp apt" -O /usr/share/keyring/devkitpro-pub.gpg https://apt.devkitpro.org/devkitpro-pub.gpg
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add the devkitPro apt repository if we don't have it set up already
|
||||||
|
if ! [ -f /etc/apt/sources.list.d/devkitpro.list ]; then
|
||||||
|
echo "deb [signed-by=/usr/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list
|
||||||
|
fi
|
||||||
|
apt-get update
|
||||||
|
apt-get install devkitpro-pacman --yes
|
||||||
|
apt-get install --yes build-essential cmake python3 python3-pip python3-polib python3-pil python3-dotenv python3-pyqt5 python3-opengl
|
||||||
|
|
||||||
|
sudo dkp-pacman -Syu --noconfirm
|
||||||
|
sudo dkp-pacman -S gamecube-dev wii-dev ppc-liblzma ppc-libzip --needed --noconfirm
|
||||||
|
|
||||||
|
- name: Build GameCube
|
||||||
|
run: |
|
||||||
|
export DEVKITPRO=/opt/devkitpro
|
||||||
|
export DEVKITPPC=/opt/devkitpro/devkitPPC
|
||||||
|
export PATH="$DEVKITPPC/bin:$DEVKITPRO/tools/bin:$PATH"
|
||||||
|
mkdir -p build-gamecube
|
||||||
|
cmake -S. -Bbuild-gamecube -DDUSK_TARGET_SYSTEM=gamecube -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake"
|
||||||
|
cd build-gamecube
|
||||||
|
make -j$(nproc) VERBOSE=1
|
||||||
|
|
||||||
|
- name: Copy GameCube
|
||||||
|
run: |
|
||||||
|
ls -l
|
||||||
|
mkdir -p build/gitea/GameCube/Dusk
|
||||||
|
mv build-gamecube/Dusk.dol build/gitea/GameCube/Dusk/Dusk.dol
|
||||||
|
mv build-gamecube/dusk.dsk build/gitea/GameCube/Dusk/dusk.dsk
|
||||||
|
|
||||||
|
- name: Upload GameCube Binary
|
||||||
|
uses: https://git.wish.moe/YourWishes/upload-artifact@v3/node20
|
||||||
|
with:
|
||||||
|
name: dusk-gamecube
|
||||||
|
path: build/gitea/GameCube
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
- name: Build Wii
|
||||||
|
run: |
|
||||||
|
export DEVKITPRO=/opt/devkitpro
|
||||||
|
export DEVKITPPC=/opt/devkitpro/devkitPPC
|
||||||
|
export PATH="$DEVKITPPC/bin:$DEVKITPRO/tools/bin:$PATH"
|
||||||
|
mkdir -p build-wii
|
||||||
|
cmake -S. -Bbuild-wii -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake"
|
||||||
|
cd build-wii
|
||||||
|
make -j$(nproc) VERBOSE=1
|
||||||
|
|
||||||
|
- name: Copy Wii
|
||||||
|
run: |
|
||||||
|
ls -l
|
||||||
|
mkdir -p build/gitea/Wii/apps/Dusk
|
||||||
|
mv build-wii/Dusk.dol build/gitea/Wii/apps/Dusk/boot.dol
|
||||||
|
mv build-wii/dusk.dsk build/gitea/Wii/apps/Dusk/dusk.dsk
|
||||||
|
cp .ci/dolphin/meta.xml build/gitea/Wii/apps/Dusk/meta.xml
|
||||||
|
|
||||||
|
- name: Upload Wii Binary
|
||||||
|
uses: https://git.wish.moe/YourWishes/upload-artifact@v3/node20
|
||||||
|
with:
|
||||||
|
name: dusk-wii
|
||||||
|
path: build/gitea/Wii
|
||||||
|
if-no-files-found: error
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -102,3 +102,6 @@ yarn.lock
|
|||||||
|
|
||||||
.editor
|
.editor
|
||||||
.venv
|
.venv
|
||||||
|
|
||||||
|
/build2
|
||||||
|
/build*
|
||||||
184
CMakeLists.txt
184
CMakeLists.txt
@@ -4,18 +4,13 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.18)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||||
|
|
||||||
option(ENABLE_TESTS "Enable tests" ON)
|
option(ENABLE_TESTS "Enable tests" OFF)
|
||||||
|
|
||||||
# Set target system
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
|
||||||
set(DUSK_TARGET_SYSTEM "linux")
|
|
||||||
# set(DUSK_TARGET_SYSTEM "psp")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Prep cache
|
# Prep cache
|
||||||
set(DUSK_CACHE_TARGET "dusk-target")
|
set(DUSK_CACHE_TARGET "dusk-target")
|
||||||
@@ -35,6 +30,7 @@ set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk 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" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
|
||||||
# Create directories
|
# Create directories
|
||||||
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
||||||
@@ -42,51 +38,85 @@ file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
|||||||
# Find packages
|
# Find packages
|
||||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||||
|
|
||||||
|
# Set target system, default to linux if not set.
|
||||||
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||||
|
set(DUSK_TARGET_SYSTEM "linux")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Toolchains
|
# Toolchains
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
find_package(pspsdk REQUIRED)
|
find_package(pspsdk REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||||
|
# Override to make library and binary be the same.
|
||||||
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_LIBRARY_TARGET_NAME}.elf" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
endif()
|
||||||
|
|
||||||
# Init Project.
|
# Init Project.
|
||||||
project(${DUSK_LIBRARY_TARGET_NAME}
|
project(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
VERSION 1.0.0
|
VERSION 1.0.0
|
||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
)
|
)
|
||||||
|
|
||||||
# MainLibrary
|
# Either, create library and binary separately (used for tests), or make them
|
||||||
add_library(${DUSK_LIBRARY_TARGET_NAME})
|
# one in the same so all code is in the binary.
|
||||||
|
if(ENABLE_TESTS)
|
||||||
|
# MainLibrary
|
||||||
|
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
||||||
|
|
||||||
# Binary Executable
|
# Binary Executable
|
||||||
add_executable(${DUSK_BINARY_TARGET_NAME})
|
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/null.c)
|
||||||
|
|
||||||
# Link library to binary and test
|
# Link library to binary
|
||||||
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${DUSK_LIBRARY_TARGET_NAME}
|
${DUSK_LIBRARY_TARGET_NAME}
|
||||||
)
|
)
|
||||||
|
else()
|
||||||
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/null.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add tools
|
# Add tools
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
|
|
||||||
# Assets
|
# Per Target Libraries and definitions
|
||||||
add_subdirectory(assets)
|
|
||||||
|
|
||||||
# Add libraries
|
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
SDL2
|
SDL2
|
||||||
|
pthread
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
GL
|
GL
|
||||||
|
m
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
DISPLAY_SDL2=1
|
||||||
|
DISPLAY_WINDOW_WIDTH_DEFAULT=1080
|
||||||
|
DISPLAY_WINDOW_HEIGHT_DEFAULT=810
|
||||||
|
DISPLAY_SCREEN_HEIGHT_DEFAULT=270
|
||||||
|
INPUT_SDL2=1
|
||||||
|
INPUT_KEYBOARD=1
|
||||||
|
INPUT_POINTER=1
|
||||||
|
INPUT_GAMEPAD=1
|
||||||
|
THREAD_PTHREAD=1
|
||||||
|
TIME_SDL2=1
|
||||||
|
TIME_FIXED=0
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
${SDL2_LIBRARIES}
|
${SDL2_LIBRARIES}
|
||||||
SDL2
|
SDL2
|
||||||
|
pthread
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
zip
|
zip
|
||||||
bz2
|
bz2
|
||||||
@@ -94,18 +124,93 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|||||||
mbedtls
|
mbedtls
|
||||||
mbedcrypto
|
mbedcrypto
|
||||||
lzma
|
lzma
|
||||||
|
m
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||||
${SDL2_INCLUDE_DIRS}
|
${SDL2_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
DISPLAY_SDL2=1
|
||||||
|
DISPLAY_WINDOW_WIDTH_DEFAULT=480
|
||||||
|
DISPLAY_WINDOW_HEIGHT_DEFAULT=272
|
||||||
|
DISPLAY_WIDTH=480
|
||||||
|
DISPLAY_HEIGHT=272
|
||||||
|
DISPLAY_SIZE_DYNAMIC=0
|
||||||
|
INPUT_SDL2=1
|
||||||
|
INPUT_GAMEPAD=1
|
||||||
|
THREAD_PTHREAD=1
|
||||||
|
TIME_FIXED=1
|
||||||
|
)
|
||||||
|
|
||||||
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
||||||
|
# configure_file(opengl.pc.in opengl.pc @ONLY)
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(zip IMPORTED_TARGET libzip)
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
DOLPHIN
|
||||||
|
)
|
||||||
|
|
||||||
|
# Disable all warnings
|
||||||
|
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE -w)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Compile lua
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
liblua
|
||||||
|
URL https://www.lua.org/ftp/lua-5.5.0.tar.gz
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(liblua)
|
||||||
|
set(LUA_SRC_DIR "${liblua_SOURCE_DIR}/src")
|
||||||
|
set(LUA_C_FILES
|
||||||
|
lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c
|
||||||
|
ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c
|
||||||
|
loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c
|
||||||
|
lstrlib.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c lzio.c
|
||||||
|
)
|
||||||
|
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||||
|
add_library(liblua STATIC ${LUA_C_FILES})
|
||||||
|
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||||
|
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||||
|
add_library(lua::lua ALIAS liblua)
|
||||||
|
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||||
|
|
||||||
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||||
|
cglm
|
||||||
|
liblua
|
||||||
|
m
|
||||||
|
fat
|
||||||
|
PkgConfig::zip
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
DISPLAY_WINDOW_WIDTH_DEFAULT=640
|
||||||
|
DISPLAY_WINDOW_HEIGHT_DEFAULT=480
|
||||||
|
DISPLAY_WIDTH=640
|
||||||
|
DISPLAY_HEIGHT=480
|
||||||
|
DISPLAY_SIZE_DYNAMIC=0
|
||||||
|
INPUT_GAMEPAD=1
|
||||||
|
THREAD_PTHREAD=1
|
||||||
|
TIME_FIXED=1
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Force turn tests off for now
|
|
||||||
set(ENABLE_TESTS OFF CACHE BOOL "Enable tests" FORCE)
|
|
||||||
|
|
||||||
# Add code
|
# Add code
|
||||||
add_subdirectory(src)
|
add_subdirectory(${DUSK_SOURCES_DIR})
|
||||||
|
|
||||||
|
# Include generated headers
|
||||||
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
${DUSK_GENERATED_HEADERS_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
# Handle tests
|
# Handle tests
|
||||||
if(ENABLE_TESTS)
|
if(ENABLE_TESTS)
|
||||||
@@ -114,22 +219,19 @@ if(ENABLE_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build assets
|
# Build assets
|
||||||
dusk_run_python(
|
file(GLOB_RECURSE DUSK_ASSET_FILES CONFIGURE_DEPENDS "${DUSK_ASSETS_DIR}/*")
|
||||||
DUSK_ASSETS_BUILT
|
add_custom_command(
|
||||||
tools.asset.bundle
|
OUTPUT "${DUSK_ASSETS_ZIP}"
|
||||||
--assets ${DUSK_ASSETS_DIR}
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
||||||
--output-assets ${DUSK_BUILT_ASSETS_DIR}
|
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
||||||
--output-file ${DUSK_BUILD_DIR}/dusk.dsk
|
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
||||||
--headers-dir ${DUSK_GENERATED_HEADERS_DIR}
|
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
||||||
--input ${DUSK_ASSETS}
|
DEPENDS ${DUSK_ASSET_FILES}
|
||||||
|
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)
|
||||||
|
|
||||||
# Include generated headers
|
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|
||||||
${DUSK_GENERATED_HEADERS_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Postbuild
|
# Postbuild
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
create_pbp_file(
|
create_pbp_file(
|
||||||
@@ -138,7 +240,15 @@ if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|||||||
BACKGROUND_PATH NULL
|
BACKGROUND_PATH NULL
|
||||||
PREVIEW_PATH NULL
|
PREVIEW_PATH NULL
|
||||||
TITLE "${DUSK_BINARY_TARGET_NAME}"
|
TITLE "${DUSK_BINARY_TARGET_NAME}"
|
||||||
PSAR_PATH ${DUSK_BUILD_DIR}/dusk.dsk
|
PSAR_PATH ${DUSK_ASSETS_ZIP}
|
||||||
VERSION 01.00
|
VERSION 01.00
|
||||||
)
|
)
|
||||||
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||||
|
set(DUSK_BINARY_TARGET_NAME_DOL "${DUSK_BUILD_DIR}/Dusk.dol")
|
||||||
|
add_custom_command(TARGET ${DUSK_BINARY_TARGET_NAME} POST_BUILD
|
||||||
|
COMMAND elf2dol
|
||||||
|
"$<TARGET_FILE:${DUSK_BINARY_TARGET_NAME}>"
|
||||||
|
"${DUSK_BINARY_TARGET_NAME_DOL}"
|
||||||
|
COMMENT "Generating ${DUSK_BINARY_TARGET_NAME_DOL} from ${DUSK_BINARY_TARGET_NAME}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -35,10 +35,24 @@ def processPalettizedImage(asset):
|
|||||||
imagePalette = extractPaletteFromImage(image)
|
imagePalette = extractPaletteFromImage(image)
|
||||||
|
|
||||||
# Find palette that contains every color
|
# Find palette that contains every color
|
||||||
for palette in palettes:
|
palette = None
|
||||||
if all(color in palette['pixels'] for color in imagePalette):
|
for p in palettes:
|
||||||
|
hasAllColors = True
|
||||||
|
for color in imagePalette:
|
||||||
|
for palColor in p['pixels']:
|
||||||
|
if color[0] == palColor[0] and color[1] == palColor[1] and color[2] == palColor[2] and color[3] == palColor[3]:
|
||||||
|
break
|
||||||
|
elif color[3] == 0 and palColor[3] == 0:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
print('Pallete {} does not contain color #{}'.format(p['paletteName'], '{:02x}{:02x}{:02x}{:02x}'.format(color[0], color[1], color[2], color[3])))
|
||||||
|
hasAllColors = False
|
||||||
|
break
|
||||||
|
if hasAllColors:
|
||||||
|
palette = p
|
||||||
|
break
|
||||||
|
|
||||||
|
if palette is None:
|
||||||
palette = palettes[0] # Just to avoid reference error
|
palette = palettes[0] # Just to avoid reference error
|
||||||
print(f"No matching palette found for {assetPath}!")
|
print(f"No matching palette found for {assetPath}!")
|
||||||
# Find which pixel is missing
|
# Find which pixel is missing
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import datetime
|
import datetime
|
||||||
@@ -78,6 +79,7 @@ def processPalette(asset):
|
|||||||
|
|
||||||
def processPaletteList():
|
def processPaletteList():
|
||||||
data = f"// Auto-generated palette list\n"
|
data = f"// Auto-generated palette list\n"
|
||||||
|
print(f"Generating palette list with {len(palettes)} palettes.")
|
||||||
for palette in palettes:
|
for palette in palettes:
|
||||||
data += f"#include \"{palette['headerFile']}\"\n"
|
data += f"#include \"{palette['headerFile']}\"\n"
|
||||||
data += f"\n"
|
data += f"\n"
|
||||||
@@ -126,6 +126,7 @@ def processTileset(asset):
|
|||||||
data += f"#pragma once\n"
|
data += f"#pragma once\n"
|
||||||
data += f"#include \"display/tileset/tileset.h\"\n\n"
|
data += f"#include \"display/tileset/tileset.h\"\n\n"
|
||||||
data += f"static const tileset_t TILESET_{tilesetNameUpper} = {{\n"
|
data += f"static const tileset_t TILESET_{tilesetNameUpper} = {{\n"
|
||||||
|
data += f" .name = {json.dumps(tilesetName)},\n"
|
||||||
data += f" .tileWidth = {tilesetData['tileWidth']},\n"
|
data += f" .tileWidth = {tilesetData['tileWidth']},\n"
|
||||||
data += f" .tileHeight = {tilesetData['tileHeight']},\n"
|
data += f" .tileHeight = {tilesetData['tileHeight']},\n"
|
||||||
data += f" .tileCount = {tilesetData['columns'] * tilesetData['rows']},\n"
|
data += f" .tileCount = {tilesetData['columns'] * tilesetData['rows']},\n"
|
||||||
@@ -22,13 +22,13 @@ int moduleMapLoad(lua_State *L) {
|
|||||||
// Potentially provide up to 3 params
|
// Potentially provide up to 3 params
|
||||||
chunkpos_t initial = { .x = 0, .y = 0, .z = 0 };
|
chunkpos_t initial = { .x = 0, .y = 0, .z = 0 };
|
||||||
if(lua_isnumber(L, 2)) {
|
if(lua_isnumber(L, 2)) {
|
||||||
initial.x = (chunkunit_t)luaL_checkinteger(L, 2);
|
initial.x = (chunkunit_t)lua_tonumber(L, 2);
|
||||||
}
|
}
|
||||||
if(lua_isnumber(L, 3)) {
|
if(lua_isnumber(L, 3)) {
|
||||||
initial.y = (chunkunit_t)luaL_checkinteger(L, 3);
|
initial.y = (chunkunit_t)lua_tonumber(L, 3);
|
||||||
}
|
}
|
||||||
if(lua_isnumber(L, 4)) {
|
if(lua_isnumber(L, 4)) {
|
||||||
initial.z = (chunkunit_t)luaL_checkinteger(L, 4);
|
initial.z = (chunkunit_t)lua_tonumber(L, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the map.
|
// Load the map.
|
||||||
|
|||||||
@@ -12,10 +12,9 @@
|
|||||||
|
|
||||||
int scriptFuncEntityAdd(lua_State *L) {
|
int scriptFuncEntityAdd(lua_State *L) {
|
||||||
assertNotNull(L, "Lua state cannot be NULL");
|
assertNotNull(L, "Lua state cannot be NULL");
|
||||||
|
assertTrue(lua_isnumber(L, 1), "Expected integer entity type");
|
||||||
|
|
||||||
assertTrue(lua_isinteger(L, 1), "Expected integer entity type");
|
entitytype_t entityType = (entitytype_t)luaL_checknumber(L, 1);
|
||||||
|
|
||||||
lua_Integer entityType = luaL_checkinteger(L, 1);
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
entityType >= ENTITY_TYPE_NULL && entityType < ENTITY_TYPE_COUNT,
|
entityType >= ENTITY_TYPE_NULL && entityType < ENTITY_TYPE_COUNT,
|
||||||
"Invalid entity type passed to scriptFuncEntityAdd"
|
"Invalid entity type passed to scriptFuncEntityAdd"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "uiframe.h"
|
#include "uiframe.h"
|
||||||
#include "display/spritebatch.h"
|
#include "display/spritebatch.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include <math.h>
|
#include "util/math.h"
|
||||||
|
|
||||||
void uiFrameDraw(
|
void uiFrameDraw(
|
||||||
const float_t x,
|
const float_t x,
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
set(DUSK_GAME_ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Game assets directory")
|
|
||||||
|
|
||||||
# Palette asset needs to be added before any images.
|
|
||||||
add_subdirectory(palette)
|
|
||||||
|
|
||||||
# Languages need to be added before anything that uses text.
|
|
||||||
add_subdirectory(locale)
|
|
||||||
|
|
||||||
# Rest, order doesn't matter
|
|
||||||
add_asset(SCRIPT init.lua)
|
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
add_subdirectory(entity)
|
|
||||||
add_subdirectory(map)
|
|
||||||
add_subdirectory(ui)
|
|
||||||
add_subdirectory(scene)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_asset(TILESET entities.tsx)
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 336 B |
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<tileset version="1.10" tiledversion="1.11.2" name="entities" tilewidth="16" tileheight="16" tilecount="64" columns="8">
|
|
||||||
<image source="entities.png" width="128" height="128"/>
|
|
||||||
</tileset>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
module('platform')
|
|
||||||
module('input')
|
module('input')
|
||||||
|
module('platform')
|
||||||
module('scene')
|
module('scene')
|
||||||
module('locale')
|
module('locale')
|
||||||
|
|
||||||
@@ -16,6 +16,20 @@ if PLATFORM == "psp" then
|
|||||||
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
||||||
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
||||||
inputBind("lstick_right", INPUT_ACTION_RIGHT)
|
inputBind("lstick_right", INPUT_ACTION_RIGHT)
|
||||||
|
|
||||||
|
elseif DOLPHIN then
|
||||||
|
inputBind("up", INPUT_ACTION_UP)
|
||||||
|
inputBind("down", INPUT_ACTION_DOWN)
|
||||||
|
inputBind("left", INPUT_ACTION_LEFT)
|
||||||
|
inputBind("right", INPUT_ACTION_RIGHT)
|
||||||
|
inputBind("b", INPUT_ACTION_CANCEL)
|
||||||
|
inputBind("a", INPUT_ACTION_ACCEPT)
|
||||||
|
inputBind("z", INPUT_ACTION_RAGEQUIT)
|
||||||
|
inputBind("lstick_up", INPUT_ACTION_UP)
|
||||||
|
inputBind("lstick_down", INPUT_ACTION_DOWN)
|
||||||
|
inputBind("lstick_left", INPUT_ACTION_LEFT)
|
||||||
|
inputBind("lstick_right", INPUT_ACTION_RIGHT)
|
||||||
|
|
||||||
else
|
else
|
||||||
if INPUT_KEYBOARD then
|
if INPUT_KEYBOARD then
|
||||||
inputBind("w", INPUT_ACTION_UP)
|
inputBind("w", INPUT_ACTION_UP)
|
||||||
@@ -35,7 +49,11 @@ else
|
|||||||
|
|
||||||
inputBind("escape", INPUT_ACTION_RAGEQUIT)
|
inputBind("escape", INPUT_ACTION_RAGEQUIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if INPUT_POINTER then
|
||||||
|
inputBind("mouse_x", INPUT_ACTION_POINTERX)
|
||||||
|
inputBind("mouse_y", INPUT_ACTION_POINTERY)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
localeSet(DUSK_LOCALE_EN_US)
|
sceneSet('scene/minesweeper.lua')
|
||||||
sceneSet('scene/initial.dsf')
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_asset(LANGUAGE en_US.po)
|
|
||||||
@@ -7,9 +7,3 @@ msgstr ""
|
|||||||
|
|
||||||
msgid "ui.test"
|
msgid "ui.test"
|
||||||
msgstr "Hello this is a test."
|
msgstr "Hello this is a test."
|
||||||
|
|
||||||
msgid "map.test"
|
|
||||||
msgstr "This is a map test."
|
|
||||||
|
|
||||||
msgid "test.test2"
|
|
||||||
msgstr "This is another test."
|
|
||||||
|
|||||||
BIN
assets/main_palette.dpf
Normal file
BIN
assets/main_palette.dpf
Normal file
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_asset(PALETTE palette0.png)
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 241 B |
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_asset(SCRIPT initial.lua)
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
module('spritebatch')
|
|
||||||
module('camera')
|
|
||||||
module('color')
|
|
||||||
-- module('ui')
|
|
||||||
module('text')
|
|
||||||
module('screen')
|
|
||||||
module('time')
|
|
||||||
module('map')
|
|
||||||
module('glm')
|
|
||||||
|
|
||||||
screenSetBackground(colorBlack())
|
|
||||||
mapLoad('map/testmap/testmap.dmf')
|
|
||||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
|
||||||
mapCamera = cameraCreate()
|
|
||||||
|
|
||||||
text = "Hello World"
|
|
||||||
|
|
||||||
function sceneDispose()
|
|
||||||
end
|
|
||||||
|
|
||||||
function sceneUpdate()
|
|
||||||
end
|
|
||||||
|
|
||||||
function sceneRender()
|
|
||||||
-- Map Test
|
|
||||||
cameraPushMatrix(mapCamera)
|
|
||||||
mapCamera.position = vec3(300, 300, 300)
|
|
||||||
mapRender()
|
|
||||||
cameraPopMatrix()
|
|
||||||
|
|
||||||
-- UI Test
|
|
||||||
cameraPushMatrix(camera)
|
|
||||||
camera.bottom = screenGetHeight()
|
|
||||||
camera.right = screenGetWidth()
|
|
||||||
|
|
||||||
width, height = textMeasure(text)
|
|
||||||
x = (screenGetWidth() - width)
|
|
||||||
x = math.sin(TIME.time * 2) * (x / 2) + (x / 2)
|
|
||||||
y = (screenGetHeight() - height) / 2
|
|
||||||
y = math.cos(TIME.time * 3) * (y) + (y)
|
|
||||||
textDraw(x, y, text, colorMagenta())
|
|
||||||
|
|
||||||
cameraPopMatrix()
|
|
||||||
end
|
|
||||||
244
assets/scene/minesweeper.lua
Normal file
244
assets/scene/minesweeper.lua
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
module('spritebatch')
|
||||||
|
module('camera')
|
||||||
|
module('color')
|
||||||
|
module('ui')
|
||||||
|
module('screen')
|
||||||
|
module('time')
|
||||||
|
module('glm')
|
||||||
|
module('text')
|
||||||
|
module('tileset')
|
||||||
|
module('texture')
|
||||||
|
module('input')
|
||||||
|
|
||||||
|
CELL_STATE_DEFAULT = 0
|
||||||
|
CELL_STATE_HOVER = 1
|
||||||
|
CELL_STATE_DOWN = 2
|
||||||
|
CELL_STATE_DISABLED = 3
|
||||||
|
|
||||||
|
screenSetBackground(colorBlack())
|
||||||
|
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||||
|
|
||||||
|
-- tilesetUi = tilesetGetByName("ui")
|
||||||
|
-- textureUi = textureLoad(tilesetUi.texture)
|
||||||
|
|
||||||
|
-- tilesetBorder = tilesetGetByName("border")
|
||||||
|
-- textureBorder = textureLoad(tilesetBorder.texture)
|
||||||
|
|
||||||
|
-- textureGrid = textureLoad("minesweeper/grid_bg.dpi")
|
||||||
|
|
||||||
|
-- tilesetCell = tilesetGetByName("cell")
|
||||||
|
-- textureCell = textureLoad(tilesetCell.texture)
|
||||||
|
-- cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
|
||||||
|
-- cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
|
||||||
|
-- cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
|
||||||
|
-- cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
|
||||||
|
|
||||||
|
-- sweepwerCols = 10
|
||||||
|
-- sweeperRows = 14
|
||||||
|
|
||||||
|
-- mouseX = -1
|
||||||
|
-- mouseY = -1
|
||||||
|
-- centerX = 0
|
||||||
|
-- centerY = 0
|
||||||
|
-- boardWidth = sweepwerCols * tilesetCell.tileWidth
|
||||||
|
-- boardHeight = sweeperRows * tilesetCell.tileHeight
|
||||||
|
|
||||||
|
-- i = 0
|
||||||
|
-- cells = {}
|
||||||
|
-- for y = 1, sweeperRows do
|
||||||
|
-- for x = 1, sweepwerCols do
|
||||||
|
-- cells[i] = CELL_STATE_DEFAULT
|
||||||
|
-- i = i + 1
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
function cellDraw(x, y, type)
|
||||||
|
local slice = cellSliceDefault
|
||||||
|
if type == CELL_STATE_HOVER then
|
||||||
|
slice = cellSliceHover
|
||||||
|
elseif type == CELL_STATE_DOWN then
|
||||||
|
slice = cellSliceDown
|
||||||
|
elseif type == CELL_STATE_DISABLED then
|
||||||
|
slice = cellSliceDisabled
|
||||||
|
end
|
||||||
|
|
||||||
|
spriteBatchPush(textureCell,
|
||||||
|
x, y,
|
||||||
|
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
slice.u0, slice.v0,
|
||||||
|
slice.u1, slice.v1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function backgroundDraw()
|
||||||
|
local t = (TIME.time / 40) % 1
|
||||||
|
local scaleX = screenGetWidth() / textureGrid.width
|
||||||
|
local scaleY = screenGetHeight() / textureGrid.height
|
||||||
|
local u0 = t * scaleX
|
||||||
|
local v0 = t * scaleY
|
||||||
|
local u1 = scaleX + u0
|
||||||
|
local v1 = scaleY + v0
|
||||||
|
|
||||||
|
spriteBatchPush(textureGrid,
|
||||||
|
0, 0,
|
||||||
|
screenGetWidth(), screenGetHeight(),
|
||||||
|
colorWhite(),
|
||||||
|
u0, v0,
|
||||||
|
u1, v1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function borderDraw(x, y, innerWidth, innerHeight)
|
||||||
|
-- Top Left
|
||||||
|
local uv = tilesetPositionGetUV(tilesetBorder, 0, 0)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x - tilesetBorder.tileWidth, y - tilesetBorder.tileWidth,
|
||||||
|
x, y,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Top Right
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 10, 0)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x + innerWidth, y - tilesetBorder.tileHeight,
|
||||||
|
x + innerWidth + tilesetBorder.tileWidth, y,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Bottom Left
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 0, 10)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x - tilesetBorder.tileWidth, y + innerHeight,
|
||||||
|
x, y + innerHeight + tilesetBorder.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Bottom Right
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 10, 10)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x + innerWidth, y + innerHeight,
|
||||||
|
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Top
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 1, 0)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x, y - tilesetBorder.tileHeight,
|
||||||
|
x + innerWidth, y,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Bottom
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 1, 10)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x, y + innerHeight,
|
||||||
|
x + innerWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Left
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 0, 1)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x - tilesetBorder.tileWidth, y,
|
||||||
|
x, y + innerHeight,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Right
|
||||||
|
uv = tilesetPositionGetUV(tilesetBorder, 10, 1)
|
||||||
|
spriteBatchPush(textureBorder,
|
||||||
|
x + innerWidth, y,
|
||||||
|
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight,
|
||||||
|
colorWhite(),
|
||||||
|
uv.u0, uv.v0,
|
||||||
|
uv.u1, uv.v1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function sceneDispose()
|
||||||
|
end
|
||||||
|
|
||||||
|
function sceneUpdate()
|
||||||
|
end
|
||||||
|
|
||||||
|
function sceneRender()
|
||||||
|
-- Update camera
|
||||||
|
cameraPushMatrix(camera)
|
||||||
|
camera.bottom = screenGetHeight()
|
||||||
|
camera.right = screenGetWidth()
|
||||||
|
|
||||||
|
-- Update mouse position
|
||||||
|
if INPUT_POINTER then
|
||||||
|
mouseX = inputGetValue(INPUT_ACTION_POINTERX) * screenGetWidth()
|
||||||
|
mouseY = inputGetValue(INPUT_ACTION_POINTERY) * screenGetHeight()
|
||||||
|
|
||||||
|
-- Draw cursor
|
||||||
|
spriteBatchPush(
|
||||||
|
nil,
|
||||||
|
mouseX - 2, mouseY - 2,
|
||||||
|
mouseX + 2, mouseY + 2,
|
||||||
|
colorRed(),
|
||||||
|
0, 0,
|
||||||
|
1, 1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
textDraw(10, 10, "Hello World")
|
||||||
|
|
||||||
|
-- centerX = math.floor(screenGetWidth() / 2)
|
||||||
|
-- centerY = math.floor(screenGetHeight() / 2)
|
||||||
|
|
||||||
|
-- Draw elements
|
||||||
|
-- backgroundDraw()
|
||||||
|
-- borderDraw(
|
||||||
|
-- centerX - (boardWidth / 2), centerY - (boardHeight / 2),
|
||||||
|
-- boardWidth, boardHeight
|
||||||
|
-- )
|
||||||
|
|
||||||
|
-- i = 0
|
||||||
|
-- -- Foreach cell
|
||||||
|
-- local offX = centerX - (boardWidth / 2)
|
||||||
|
-- local offY = centerY - (boardHeight / 2)
|
||||||
|
-- for y = 0, sweeperRows - 1 do
|
||||||
|
-- for x = 0, sweepwerCols - 1 do
|
||||||
|
-- i = y * sweepwerCols + x
|
||||||
|
|
||||||
|
-- -- Hovered
|
||||||
|
-- if
|
||||||
|
-- cells[i] == CELL_STATE_DEFAULT and
|
||||||
|
-- mouseX >= x * tilesetCell.tileWidth + offX and mouseX < (x + 1) * tilesetCell.tileWidth + offX and
|
||||||
|
-- mouseY >= y * tilesetCell.tileHeight + offY and mouseY < (y + 1) * tilesetCell.tileHeight + offY
|
||||||
|
-- then
|
||||||
|
-- cells[i] = CELL_STATE_HOVER
|
||||||
|
-- else
|
||||||
|
-- cells[i] = CELL_STATE_DEFAULT
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- cellDraw(
|
||||||
|
-- x * tilesetCell.tileWidth + offX,
|
||||||
|
-- y * tilesetCell.tileHeight + offY,
|
||||||
|
-- cells[i]
|
||||||
|
-- )
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
spriteBatchFlush()
|
||||||
|
|
||||||
|
cameraPopMatrix()
|
||||||
|
end
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 758 B |
Binary file not shown.
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<tileset version="1.10" tiledversion="1.11.2" name="prarie" tilewidth="16" tileheight="16" tilecount="21" columns="7">
|
|
||||||
<image source="prarie.png" width="112" height="48"/>
|
|
||||||
</tileset>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
add_asset(TILESET minogram.png type=PALETTIZED tileWidth=6 tileHeight=10 columns=16 rows=6)# Fixes PSP rendering
|
|
||||||
BIN
assets/ui/minogram.dpt
Normal file
BIN
assets/ui/minogram.dpt
Normal file
Binary file not shown.
BIN
assets/ui/minogram.dtf
Normal file
BIN
assets/ui/minogram.dtf
Normal file
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -4,9 +4,10 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
cglm
|
cglm
|
||||||
GIT_REPOSITORY https://github.com/recp/cglm.git
|
GIT_REPOSITORY https://git.wish.moe/YourWishes/cglm.git
|
||||||
GIT_TAG v0.9.6
|
GIT_TAG v0.9.6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,19 @@
|
|||||||
# 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
|
||||||
|
|
||||||
find_package(cglm REQUIRED)
|
if(NOT cglm_FOUND)
|
||||||
find_package(libzip REQUIRED)
|
find_package(cglm REQUIRED)
|
||||||
find_package(Lua REQUIRED)
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC cglm)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(Lua_FOUND AND NOT TARGET Lua::Lua)
|
if(NOT libzip_FOUND)
|
||||||
|
find_package(libzip REQUIRED)
|
||||||
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT Lua_FOUND)
|
||||||
|
find_package(Lua REQUIRED)
|
||||||
|
if(Lua_FOUND AND NOT TARGET Lua::Lua)
|
||||||
add_library(Lua::Lua INTERFACE IMPORTED)
|
add_library(Lua::Lua INTERFACE IMPORTED)
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
Lua::Lua
|
Lua::Lua
|
||||||
@@ -15,17 +23,11 @@ if(Lua_FOUND AND NOT TARGET Lua::Lua)
|
|||||||
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
|
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
|
||||||
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
|
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC Lua::Lua)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Libs
|
# Libs
|
||||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME}
|
|
||||||
PUBLIC
|
|
||||||
m
|
|
||||||
cglm
|
|
||||||
zip
|
|
||||||
pthread
|
|
||||||
Lua::Lua
|
|
||||||
)
|
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
@@ -63,7 +65,10 @@ add_subdirectory(map)
|
|||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
add_subdirectory(script)
|
add_subdirectory(script)
|
||||||
add_subdirectory(story)
|
add_subdirectory(story)
|
||||||
add_subdirectory(thread)
|
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
|
|
||||||
|
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
|
add_subdirectory(thread)
|
||||||
|
endif()
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
line,
|
line,
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
|
debugFlush();
|
||||||
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,66 @@
|
|||||||
#include "asset/assettype.h"
|
#include "asset/assettype.h"
|
||||||
#include "engine/engine.h"
|
#include "engine/engine.h"
|
||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
errorret_t assetInit(void) {
|
errorret_t assetInit(void) {
|
||||||
memoryZero(&ASSET, sizeof(asset_t));
|
memoryZero(&ASSET, sizeof(asset_t));
|
||||||
|
|
||||||
|
#if DOLPHIN
|
||||||
|
// Init FAT driver.
|
||||||
|
if(!fatInitDefault()) errorThrow("Failed to initialize FAT filesystem.");
|
||||||
|
|
||||||
|
char_t **dolphinSearchPath = (char_t **)ASSET_DOLPHIN_PATHS;
|
||||||
|
char_t foundPath[FILENAME_MAX];
|
||||||
|
foundPath[0] = '\0';
|
||||||
|
do {
|
||||||
|
// Try open dir
|
||||||
|
DIR *pdir = opendir(*dolphinSearchPath);
|
||||||
|
if(pdir == NULL) continue;
|
||||||
|
|
||||||
|
|
||||||
|
// Scan if file is present
|
||||||
|
while(true) {
|
||||||
|
struct dirent* pent = readdir(pdir);
|
||||||
|
if(pent == NULL) break;
|
||||||
|
|
||||||
|
if(stringCompareInsensitive(pent->d_name, ASSET_FILE) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy out filename
|
||||||
|
snprintf(
|
||||||
|
foundPath,
|
||||||
|
FILENAME_MAX,
|
||||||
|
"%s/%s",
|
||||||
|
*dolphinSearchPath,
|
||||||
|
ASSET_FILE
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close dir.
|
||||||
|
closedir(pdir);
|
||||||
|
|
||||||
|
// Did we find the file here?
|
||||||
|
if(foundPath[0] != '\0') break;
|
||||||
|
} while(*(++dolphinSearchPath) != NULL);
|
||||||
|
|
||||||
|
if(foundPath[0] != '\0') {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did we find the asset file?
|
||||||
|
if(foundPath[0] == '\0') {
|
||||||
|
errorThrow("Failed to find asset file on FAT filesystem.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSET.zip = zip_open(foundPath, ZIP_RDONLY, NULL);
|
||||||
|
if(ASSET.zip == NULL) {
|
||||||
|
errorThrow("Failed to open asset file on FAT filesystem.");
|
||||||
|
}
|
||||||
|
errorOk();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Engine may have been provided the launch path
|
// Engine may have been provided the launch path
|
||||||
if(ENGINE.argc > 0) {
|
if(ENGINE.argc > 0) {
|
||||||
// Get the directory of the executable
|
// Get the directory of the executable
|
||||||
@@ -95,7 +151,6 @@ errorret_t assetInit(void) {
|
|||||||
fclose(ASSET.pbpFile);
|
fclose(ASSET.pbpFile);
|
||||||
errorThrow("Failed to read PBP header", pbpPath);
|
errorThrow("Failed to read PBP header", pbpPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(memoryCompare(
|
if(memoryCompare(
|
||||||
ASSET.pbpHeader.signature,
|
ASSET.pbpHeader.signature,
|
||||||
ASSET_PBP_SIGNATURE,
|
ASSET_PBP_SIGNATURE,
|
||||||
@@ -177,63 +232,85 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
assertStrLenMax(filename, FILENAME_MAX, "Filename too long.");
|
assertStrLenMax(filename, FILENAME_MAX, "Filename too long.");
|
||||||
assertNotNull(output, "Output pointer cannot be NULL.");
|
assertNotNull(output, "Output pointer cannot be NULL.");
|
||||||
|
|
||||||
|
// Determine the asset type by reading the extension
|
||||||
|
const assettypedef_t *def = NULL;
|
||||||
|
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
|
||||||
|
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
|
||||||
|
assertNotNull(cmp, "Asset type definition cannot be NULL.");
|
||||||
|
if(cmp->extension == NULL) continue;
|
||||||
|
if(!stringEndsWithCaseInsensitive(filename, cmp->extension)) continue;
|
||||||
|
def = cmp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(def == NULL) {
|
||||||
|
errorThrow("Unknown asset type for file: %s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get file size of the asset.
|
||||||
|
zip_stat_t st;
|
||||||
|
zip_stat_init(&st);
|
||||||
|
if(!zip_stat(ASSET.zip, filename, 0, &st) == 0) {
|
||||||
|
errorThrow("Failed to stat asset file: %s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minimum file size.
|
||||||
|
zip_int64_t fileSize = (zip_int64_t)st.size;
|
||||||
|
if(fileSize <= 0) {
|
||||||
|
errorThrow("Asset file is empty: %s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to open the file
|
// Try to open the file
|
||||||
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
||||||
if(file == NULL) {
|
if(file == NULL) {
|
||||||
errorThrow("Failed to open asset file: %s", filename);
|
errorThrow("Failed to open asset file: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the header.
|
// Load the asset data
|
||||||
assetheader_t header;
|
|
||||||
memoryZero(&header, sizeof(assetheader_t));
|
|
||||||
zip_int64_t bytesRead = zip_fread(file, &header, sizeof(assetheader_t));
|
|
||||||
if(bytesRead != sizeof(assetheader_t)) {
|
|
||||||
zip_fclose(file);
|
|
||||||
errorThrow("Failed to read asset header for: %s", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the asset type based on the header
|
|
||||||
const assettypedef_t *def = NULL;
|
|
||||||
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
|
|
||||||
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
|
|
||||||
if(cmp->header == NULL) continue;
|
|
||||||
|
|
||||||
// strcmp didn't work because it's a fixed char_t[3] I think, or maybe
|
|
||||||
// because of the packed struct?
|
|
||||||
bool_t match = true;
|
|
||||||
for(size_t h = 0; h < ASSET_HEADER_SIZE; h++) {
|
|
||||||
if(header.header[h] == cmp->header[h]) continue;
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(!match) continue;
|
|
||||||
|
|
||||||
def = cmp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(def == NULL) {
|
|
||||||
zip_fclose(file);
|
|
||||||
errorThrow("Unknown asset type for file: %s", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We found the asset type, now load the asset data
|
|
||||||
switch(def->loadStrategy) {
|
switch(def->loadStrategy) {
|
||||||
case ASSET_LOAD_STRAT_ENTIRE:
|
case ASSET_LOAD_STRAT_ENTIRE:
|
||||||
assertNotNull(def->entire, "Asset load function cannot be NULL.");
|
assertNotNull(def->entire, "Asset load function cannot be NULL.");
|
||||||
void *data = memoryAllocate(def->dataSize);
|
|
||||||
bytesRead = zip_fread(file, data, def->dataSize);
|
// Must have more to read
|
||||||
if(bytesRead == 0 || bytesRead > def->dataSize) {
|
if(fileSize <= 0) {
|
||||||
|
zip_fclose(file);
|
||||||
|
errorThrow("No data remaining to read for asset: %s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fileSize > def->dataSize) {
|
||||||
|
zip_fclose(file);
|
||||||
|
errorThrow(
|
||||||
|
"Asset file has too much data remaining after header: %s",
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create space to read the entire asset data
|
||||||
|
void *data = memoryAllocate(fileSize);
|
||||||
|
if(!data) {
|
||||||
|
zip_fclose(file);
|
||||||
|
errorThrow("Failed to allocate memory for asset data of file: %s", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read in the asset data.
|
||||||
|
zip_int64_t bytesRead = zip_fread(file, data, fileSize);
|
||||||
|
if(bytesRead == 0 || bytesRead > fileSize) {
|
||||||
memoryFree(data);
|
memoryFree(data);
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
errorThrow("Failed to read asset data for file: %s", filename);
|
errorThrow("Failed to read asset data for file: %s", filename);
|
||||||
}
|
}
|
||||||
|
fileSize -= bytesRead;
|
||||||
|
|
||||||
// Close the file now we have the data
|
// Close the file now we have the data
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
|
|
||||||
// Pass to the asset type loader
|
// Pass to the asset type loader
|
||||||
errorret_t ret = def->entire(data, output);
|
assetentire_t entire = {
|
||||||
|
.data = data,
|
||||||
|
.output = output
|
||||||
|
};
|
||||||
|
errorret_t ret = def->entire(entire);
|
||||||
memoryFree(data);
|
memoryFree(data);
|
||||||
|
|
||||||
errorChain(ret);
|
errorChain(ret);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "assettype.h"
|
#include "assettype.h"
|
||||||
|
|
||||||
#if ASSET_TYPE == wad
|
#if PSP
|
||||||
#if PSP
|
|
||||||
#define ASSET_PBP_READ_PBP_FROM_HOST 0
|
#define ASSET_PBP_READ_PBP_FROM_HOST 0
|
||||||
#define ASSET_PBP_SIGNATURE_SIZE 4
|
#define ASSET_PBP_SIGNATURE_SIZE 4
|
||||||
#define ASSET_PBP_SIGNATURE "\0PBP"
|
#define ASSET_PBP_SIGNATURE "\0PBP"
|
||||||
@@ -27,9 +26,37 @@
|
|||||||
uint32_t pspOffset;
|
uint32_t pspOffset;
|
||||||
uint32_t psarOffset;
|
uint32_t psarOffset;
|
||||||
} assetpbp_t;
|
} assetpbp_t;
|
||||||
#endif
|
|
||||||
#else
|
#elif DOLPHIN
|
||||||
#error "Unsupported ASSET_TYPE"
|
#include <fat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static const char_t *ASSET_DOLPHIN_PATHS[] = {
|
||||||
|
"/",
|
||||||
|
"/Dusk",
|
||||||
|
"/dusk",
|
||||||
|
"/DUSK",
|
||||||
|
"/apps",
|
||||||
|
"/apps/Dusk",
|
||||||
|
"/apps/dusk",
|
||||||
|
"/apps/DUSK",
|
||||||
|
".",
|
||||||
|
"./",
|
||||||
|
"./Dusk",
|
||||||
|
"./dusk",
|
||||||
|
"./DUSK",
|
||||||
|
"./apps",
|
||||||
|
"./apps/Dusk",
|
||||||
|
"./apps/dusk",
|
||||||
|
"./apps/DUSK",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASSET_FILE "dusk.dsk"
|
#define ASSET_FILE "dusk.dsk"
|
||||||
@@ -45,12 +72,6 @@ static const char_t *ASSET_SEARCH_PATHS[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
char_t header[ASSET_HEADER_SIZE];
|
|
||||||
} assetheader_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
zip_t *zip;
|
zip_t *zip;
|
||||||
char_t systemPath[FILENAME_MAX];
|
char_t systemPath[FILENAME_MAX];
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "type/assetpaletteimage.h"
|
#include "type/assettexture.h"
|
||||||
#include "type/assetalphaimage.h"
|
#include "type/assetpalette.h"
|
||||||
|
#include "type/assettileset.h"
|
||||||
#include "type/assetlanguage.h"
|
#include "type/assetlanguage.h"
|
||||||
#include "type/assetscript.h"
|
#include "type/assetscript.h"
|
||||||
#include "type/assetmap.h"
|
#include "type/assetmap.h"
|
||||||
@@ -17,8 +18,9 @@
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
ASSET_TYPE_NULL,
|
ASSET_TYPE_NULL,
|
||||||
|
|
||||||
ASSET_TYPE_PALETTE_IMAGE,
|
ASSET_TYPE_TEXTURE,
|
||||||
ASSET_TYPE_ALPHA_IMAGE,
|
ASSET_TYPE_PALETTE,
|
||||||
|
ASSET_TYPE_TILESET,
|
||||||
ASSET_TYPE_LANGUAGE,
|
ASSET_TYPE_LANGUAGE,
|
||||||
ASSET_TYPE_SCRIPT,
|
ASSET_TYPE_SCRIPT,
|
||||||
ASSET_TYPE_MAP,
|
ASSET_TYPE_MAP,
|
||||||
@@ -32,17 +34,22 @@ typedef enum {
|
|||||||
ASSET_LOAD_STRAT_CUSTOM
|
ASSET_LOAD_STRAT_CUSTOM
|
||||||
} assetloadstrat_t;
|
} assetloadstrat_t;
|
||||||
|
|
||||||
|
typedef struct assetentire_s {
|
||||||
|
void *data;
|
||||||
|
void *output;
|
||||||
|
} assetentire_t;
|
||||||
|
|
||||||
typedef struct assetcustom_s {
|
typedef struct assetcustom_s {
|
||||||
zip_file_t *zipFile;
|
zip_file_t *zipFile;
|
||||||
void *output;
|
void *output;
|
||||||
} assetcustom_t;
|
} assetcustom_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char_t *header;
|
const char_t *extension;
|
||||||
const size_t dataSize;
|
const size_t dataSize;
|
||||||
const assetloadstrat_t loadStrategy;
|
const assetloadstrat_t loadStrategy;
|
||||||
union {
|
union {
|
||||||
errorret_t (*entire)(void *data, void *output);
|
errorret_t (*entire)(assetentire_t entire);
|
||||||
errorret_t (*custom)(assetcustom_t custom);
|
errorret_t (*custom)(assetcustom_t custom);
|
||||||
};
|
};
|
||||||
} assettypedef_t;
|
} assettypedef_t;
|
||||||
@@ -52,41 +59,48 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
|||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_PALETTE_IMAGE] = {
|
[ASSET_TYPE_TEXTURE] = {
|
||||||
.header = "DPI",
|
.extension = "dpt",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assetpaletteimage_t),
|
.dataSize = sizeof(assettexture_t),
|
||||||
.entire = assetPaletteImageLoad
|
.entire = assetTextureLoad
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_ALPHA_IMAGE] = {
|
[ASSET_TYPE_PALETTE] = {
|
||||||
.header = "DAI",
|
.extension = "dpf",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assetalphaimage_t),
|
.dataSize = sizeof(palette_t),
|
||||||
.entire = assetAlphaImageLoad
|
.entire = assetPaletteLoad
|
||||||
|
},
|
||||||
|
|
||||||
|
[ASSET_TYPE_TILESET] = {
|
||||||
|
.extension = "dtf",
|
||||||
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
|
.dataSize = sizeof(assettileset_t),
|
||||||
|
.entire = assetTilesetLoad
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_LANGUAGE] = {
|
[ASSET_TYPE_LANGUAGE] = {
|
||||||
.header = "DLF",
|
.extension = "DLF",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.custom = assetLanguageHandler
|
.custom = assetLanguageHandler
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_SCRIPT] = {
|
[ASSET_TYPE_SCRIPT] = {
|
||||||
.header = "DSF",
|
.extension = "lua",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.custom = assetScriptHandler
|
.custom = assetScriptHandler
|
||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_MAP] = {
|
// [ASSET_TYPE_MAP] = {
|
||||||
.header = "DMF",
|
// .extension = "DMF",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.custom = assetMapHandler
|
// .custom = assetMapHandler
|
||||||
},
|
// },
|
||||||
|
|
||||||
[ASSET_TYPE_MAP_CHUNK] = {
|
// [ASSET_TYPE_MAP_CHUNK] = {
|
||||||
.header = "DMC",
|
// .extension = "DMC",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.custom = assetMapChunkHandler
|
// .custom = assetMapChunkHandler
|
||||||
},
|
// },
|
||||||
};
|
};
|
||||||
@@ -6,8 +6,9 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
assetalphaimage.c
|
assettexture.c
|
||||||
assetpaletteimage.c
|
assetpalette.c
|
||||||
|
assettileset.c
|
||||||
assetlanguage.c
|
assetlanguage.c
|
||||||
assetscript.c
|
assetscript.c
|
||||||
assetmap.c
|
assetmap.c
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetalphaimage.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "display/texture.h"
|
|
||||||
|
|
||||||
errorret_t assetAlphaImageLoad(void *data, void *output) {
|
|
||||||
assertNotNull(data, "Data pointer cannot be NULL.");
|
|
||||||
assertNotNull(output, "Output pointer cannot be NULL.");
|
|
||||||
|
|
||||||
assetalphaimage_t *dataPtr = (assetalphaimage_t *)data;
|
|
||||||
texture_t *outputPtr = (texture_t *)output;
|
|
||||||
|
|
||||||
textureInit(
|
|
||||||
outputPtr,
|
|
||||||
dataPtr->width,
|
|
||||||
dataPtr->height,
|
|
||||||
TEXTURE_FORMAT_ALPHA,
|
|
||||||
(texturedata_t){ .alpha = { .data = dataPtr->pixels } }
|
|
||||||
);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "error/error.h"
|
|
||||||
|
|
||||||
#define ASSET_ALPHA_IMAGE_WIDTH_MAX 256
|
|
||||||
#define ASSET_ALPHA_IMAGE_HEIGHT_MAX 256
|
|
||||||
#define ASSET_ALPHA_IMAGE_SIZE_MAX ( \
|
|
||||||
ASSET_ALPHA_IMAGE_WIDTH_MAX * ASSET_ALPHA_IMAGE_HEIGHT_MAX \
|
|
||||||
)
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t height;
|
|
||||||
uint8_t pixels[ASSET_ALPHA_IMAGE_SIZE_MAX];
|
|
||||||
} assetalphaimage_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads an alpha image asset from the given asset structure. The asset must
|
|
||||||
* be of type ASSET_TYPE_ALPHA_IMAGE and must be loaded.
|
|
||||||
*
|
|
||||||
* @param asset The asset to load the alpha image from.
|
|
||||||
* @return An error code.
|
|
||||||
*/
|
|
||||||
errorret_t assetAlphaImageLoad(void *data, void *output);
|
|
||||||
@@ -23,33 +23,7 @@ errorret_t assetLanguageInit(
|
|||||||
assetlanguage_t *lang,
|
assetlanguage_t *lang,
|
||||||
zip_file_t *zipFile
|
zip_file_t *zipFile
|
||||||
) {
|
) {
|
||||||
assertNotNull(lang, "Language asset cannot be NULL");
|
errorThrow("Language asset initialization is not yet implemented.");
|
||||||
assertNotNull(zipFile, "Zip file cannot be NULL");
|
|
||||||
assertNull(lang->zip, "Language asset zip file must be NULL.");
|
|
||||||
// I want this but ubuntu isn't compiling with it right now.
|
|
||||||
// assertTrue(zip_file_is_seekable(zipFile), "Language file must be seekable.");
|
|
||||||
|
|
||||||
// We now own the zip file handle.
|
|
||||||
lang->zip = zipFile;
|
|
||||||
|
|
||||||
// Read in the header.
|
|
||||||
zip_int64_t bytesRead = zip_fread(
|
|
||||||
lang->zip,
|
|
||||||
&lang->header,
|
|
||||||
sizeof(assetlanguageheader_t)
|
|
||||||
);
|
|
||||||
if(bytesRead != sizeof(assetlanguageheader_t)) {
|
|
||||||
zip_fclose(lang->zip);
|
|
||||||
errorThrow("Failed to read language asset header.");
|
|
||||||
}
|
|
||||||
|
|
||||||
lang->chunksOffset = zip_ftell(lang->zip);
|
|
||||||
if(lang->chunksOffset <= 0) {
|
|
||||||
zip_fclose(lang->zip);
|
|
||||||
errorThrow("Failed to get language asset chunks offset.");
|
|
||||||
}
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t assetLanguageRead(
|
errorret_t assetLanguageRead(
|
||||||
@@ -59,47 +33,7 @@ errorret_t assetLanguageRead(
|
|||||||
const uint32_t bufferSize,
|
const uint32_t bufferSize,
|
||||||
uint32_t *outLength
|
uint32_t *outLength
|
||||||
) {
|
) {
|
||||||
assertNotNull(lang, "Language asset cannot be NULL");
|
errorThrow("Language string reading is not yet implemented.");
|
||||||
assertNotNull(lang->zip, "Language asset zip file cannot be NULL");
|
|
||||||
assertTrue(key < LANG_KEY_COUNT, "Language key out of bounds.");
|
|
||||||
|
|
||||||
// Find the string entry
|
|
||||||
assetlanguagestring_t *str = &lang->header.strings[LANG_MAP_TEST];
|
|
||||||
|
|
||||||
// If buffer is NULL, return the string length
|
|
||||||
if(buffer == NULL) {
|
|
||||||
assertNotNull(outLength, "Output length pointer cannot be NULL.");
|
|
||||||
*outLength = str->length;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure buffer is large enough
|
|
||||||
assertTrue(
|
|
||||||
bufferSize >= str->length + 1,
|
|
||||||
"Provided buffer is too small for language string."
|
|
||||||
);
|
|
||||||
|
|
||||||
// Determine the file position
|
|
||||||
zip_int64_t seekTo = lang->chunksOffset + (
|
|
||||||
(str->chunk * ASSET_LANG_CHUNK_CHAR_COUNT) + str->offset
|
|
||||||
);
|
|
||||||
|
|
||||||
// Seek
|
|
||||||
zip_int64_t result = zip_fseek(lang->zip, seekTo, SEEK_SET);
|
|
||||||
if(result != 0) {
|
|
||||||
errorThrow("Failed to seek to language string in asset.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read
|
|
||||||
zip_int64_t readTest = zip_fread(lang->zip, buffer, str->length);
|
|
||||||
if(readTest != str->length) {
|
|
||||||
errorThrow("Failed to read test string from language asset.");
|
|
||||||
}
|
|
||||||
buffer[str->length] = '\0';
|
|
||||||
|
|
||||||
// Set str length if requested
|
|
||||||
if(outLength != NULL) *outLength = str->length;
|
|
||||||
errorOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void assetLanguageDispose(assetlanguage_t *lang) {
|
void assetLanguageDispose(assetlanguage_t *lang) {
|
||||||
|
|||||||
@@ -6,39 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "locale/language/keys.h"
|
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "duskdefs.h"
|
#include "duskdefs.h"
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
|
|
||||||
#define ASSET_LANG_CHUNK_CACHE 4 // Number of chunks to cache in memory
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef char assetlanguagechunk_t[ASSET_LANG_CHUNK_CHAR_COUNT];
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
uint32_t chunk;
|
|
||||||
uint32_t offset;
|
|
||||||
uint32_t length;
|
|
||||||
} assetlanguagestring_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
assetlanguagestring_t strings[LANG_KEY_COUNT];
|
|
||||||
} assetlanguageheader_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
zip_file_t *zip;
|
zip_file_t *zip;
|
||||||
assetlanguageheader_t header;
|
|
||||||
zip_int64_t chunksOffset;
|
zip_int64_t chunksOffset;
|
||||||
|
|
||||||
// Chunk cache
|
|
||||||
assetlanguagechunk_t chunks[ASSET_LANG_CHUNK_CACHE];
|
|
||||||
uint32_t chunkIndices[ASSET_LANG_CHUNK_CACHE];
|
|
||||||
} assetlanguage_t;
|
} assetlanguage_t;
|
||||||
|
|
||||||
typedef struct assetcustom_s assetcustom_t;
|
typedef struct assetcustom_s assetcustom_t;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "map/mapchunk.h"
|
#include "map/mapchunk.h"
|
||||||
|
#include "util/endian.h"
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -55,6 +56,9 @@ errorret_t assetMapChunkHandler(assetcustom_t custom) {
|
|||||||
errorThrow("Failed to read chunk asset header.");
|
errorThrow("Failed to read chunk asset header.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix endianess if necessary
|
||||||
|
header.tileCount = endianLittleToHost32(header.tileCount);
|
||||||
|
|
||||||
if(header.tileCount != CHUNK_TILE_COUNT) {
|
if(header.tileCount != CHUNK_TILE_COUNT) {
|
||||||
zip_fclose(custom.zipFile);
|
zip_fclose(custom.zipFile);
|
||||||
errorThrow(
|
errorThrow(
|
||||||
@@ -107,6 +111,9 @@ errorret_t assetMapChunkHandler(assetcustom_t custom) {
|
|||||||
errorThrow("Failed to read chunk model header.");
|
errorThrow("Failed to read chunk model header.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix endianess if necessary
|
||||||
|
modelHeader.vertexCount = endianLittleToHost32(modelHeader.vertexCount);
|
||||||
|
|
||||||
if(
|
if(
|
||||||
vertexIndex + modelHeader.vertexCount >
|
vertexIndex + modelHeader.vertexCount >
|
||||||
CHUNK_VERTEX_COUNT_MAX
|
CHUNK_VERTEX_COUNT_MAX
|
||||||
|
|||||||
47
src/asset/type/assetpalette.c
Normal file
47
src/asset/type/assetpalette.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "assetpalette.h"
|
||||||
|
#include "asset/assettype.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
|
||||||
|
errorret_t assetPaletteLoad(assetentire_t entire) {
|
||||||
|
assertNotNull(entire.data, "Data pointer cannot be NULL.");
|
||||||
|
assertNotNull(entire.output, "Output pointer cannot be NULL.");
|
||||||
|
|
||||||
|
assetpalette_t *assetData = (assetpalette_t *)entire.data;
|
||||||
|
palette_t *palette = (palette_t *)entire.output;
|
||||||
|
|
||||||
|
// Read header and version (first 4 bytes)
|
||||||
|
if(
|
||||||
|
assetData->header[0] != 'D' ||
|
||||||
|
assetData->header[1] != 'P' ||
|
||||||
|
assetData->header[2] != 'F'
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid palette header");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version (can only be 1 atm)
|
||||||
|
if(assetData->version != 0x01) {
|
||||||
|
errorThrow("Unsupported palette version");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check color count.
|
||||||
|
if(
|
||||||
|
assetData->colorCount == 0 ||
|
||||||
|
assetData->colorCount > PALETTE_COLOR_COUNT_MAX
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid palette color count");
|
||||||
|
}
|
||||||
|
|
||||||
|
paletteInit(
|
||||||
|
palette,
|
||||||
|
assetData->colorCount,
|
||||||
|
assetData->colors
|
||||||
|
);
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
30
src/asset/type/assetpalette.h
Normal file
30
src/asset/type/assetpalette.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* 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 "display/texture/palette.h"
|
||||||
|
|
||||||
|
typedef struct assetentire_s assetentire_t;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct {
|
||||||
|
char_t header[3];
|
||||||
|
uint8_t version;
|
||||||
|
|
||||||
|
uint8_t colorCount;
|
||||||
|
color_t colors[PALETTE_COLOR_COUNT_MAX];
|
||||||
|
} assetpalette_t;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a palette from the given data pointer into the output palette.
|
||||||
|
*
|
||||||
|
* @param entire Data received from the asset loader system.
|
||||||
|
* @return An error code.
|
||||||
|
*/
|
||||||
|
errorret_t assetPaletteLoad(assetentire_t entire);
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "assetpaletteimage.h"
|
|
||||||
#include "assert/assert.h"
|
|
||||||
#include "display/texture.h"
|
|
||||||
|
|
||||||
errorret_t assetPaletteImageLoad(void *data, void *output) {
|
|
||||||
assertNotNull(data, "Data pointer cannot be NULL.");
|
|
||||||
assertNotNull(output, "Output pointer cannot be NULL.");
|
|
||||||
|
|
||||||
assetpaletteimage_t *assetData = (assetpaletteimage_t *)data;
|
|
||||||
texture_t *texture = (texture_t *)output;
|
|
||||||
|
|
||||||
textureInit(
|
|
||||||
texture,
|
|
||||||
assetData->width,
|
|
||||||
assetData->height,
|
|
||||||
TEXTURE_FORMAT_PALETTE,
|
|
||||||
(texturedata_t){
|
|
||||||
.palette = {
|
|
||||||
.palette = assetData->paletteIndex,
|
|
||||||
.data = assetData->palette
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user