Compare commits
63 Commits
7e47ef9d74
...
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 |
@@ -1,20 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
docker build -t myapp:latest -f ./.ci/dolphin/Dockerfile .
|
docker build -t myapp:latest -f .ci/dolphin/Dockerfile .
|
||||||
docker run -v ./:/gamecube myapp:latest /bin/bash -c ' \
|
docker run -it -v ./:/workdir myapp:latest /bin/bash -c ' \
|
||||||
export PATH="$DEVKITPPC/bin:$PATH" && \
|
export PATH="$DEVKITPPC/bin:$PATH" && \
|
||||||
echo "Inside Docker container:" && \
|
cd /workdir && \
|
||||||
ls -l && \
|
|
||||||
echo "Current directory:" && \
|
|
||||||
realpath . && \
|
|
||||||
echo "Listing /:" && \
|
|
||||||
ls / && \
|
|
||||||
echo "Changing to /gamecube" && \
|
|
||||||
cd /gamecube && \
|
|
||||||
echo "Contents of /gamecube:" && \
|
|
||||||
ls -l && \
|
|
||||||
rm -rf build-gamecube && \
|
rm -rf build-gamecube && \
|
||||||
mkdir -p 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=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 && \
|
cd build-gamecube && \
|
||||||
make VERBOSE=1
|
make -j$(nproc) VERBOSE=1 && \
|
||||||
|
cp ./Dusk.dol ./boot.dol
|
||||||
'
|
'
|
||||||
@@ -7,7 +7,7 @@ docker run -v ./:/workdir myapp:latest /bin/bash -c ' \
|
|||||||
mkdir -p build-wii && \
|
mkdir -p build-wii && \
|
||||||
cmake -S. -Bbuild-wii -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" && \
|
cmake -S. -Bbuild-wii -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" && \
|
||||||
cd build-wii && \
|
cd build-wii && \
|
||||||
make VERBOSE=1 && \
|
make -j$(nproc) VERBOSE=1 && \
|
||||||
mv ./Dusk.dol ./boot.dol
|
mv ./Dusk.dol ./boot.dol
|
||||||
'
|
'
|
||||||
# docker run -it -v ./:/workdir myapp:latest /bin/bash
|
# 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)
|
||||||
@@ -9,84 +9,11 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-gamecube:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v5
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
|
|
||||||
# Add Docker's official GPG key:
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install ca-certificates curl
|
|
||||||
sudo install -m 0755 -d /etc/apt/keyrings
|
|
||||||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
||||||
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
|
||||||
|
|
||||||
# Add the repository to Apt sources:
|
|
||||||
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
|
|
||||||
Types: deb
|
|
||||||
URIs: https://download.docker.com/linux/ubuntu
|
|
||||||
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
|
|
||||||
Components: stable
|
|
||||||
Signed-By: /etc/apt/keyrings/docker.asc
|
|
||||||
EOF
|
|
||||||
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
|
|
||||||
- name: Build GameCube
|
|
||||||
run: |
|
|
||||||
echo "ls -l ."
|
|
||||||
ls -l
|
|
||||||
echo "Current directory:"
|
|
||||||
realpath .
|
|
||||||
echo "ls /"
|
|
||||||
ls /
|
|
||||||
echo "Run GameCube build script"
|
|
||||||
.ci/dolphin/build-gamecube.sh
|
|
||||||
- name: Copy gamecube
|
|
||||||
run: |
|
|
||||||
mkdir -p build/gitea/Gamecube/Dusk
|
|
||||||
mv build/Dusk.dol build/gitea/Gamecube/Dusk/Dusk.dol
|
|
||||||
mv build/dusk.dsk build/gitea/Gamecube/Dusk/dusk.dsk
|
|
||||||
- name: Upload GameCube Binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-gamecube
|
|
||||||
path: build/gitea/Gamecube
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
# build-wii:
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - name: Checkout repository
|
|
||||||
# uses: actions/checkout@v5
|
|
||||||
# - name: Install dependencies
|
|
||||||
# run: |
|
|
||||||
# apt-get update
|
|
||||||
# apt-get install -y docker.io
|
|
||||||
# - name: Build Wii
|
|
||||||
# run: |
|
|
||||||
# ./.ci/dolphin/build-wii.sh
|
|
||||||
# - name: Copy wii
|
|
||||||
# run: |
|
|
||||||
# mkdir -p build/gitea/Wii/apps/Dusk
|
|
||||||
# mv build/Dusk.dol build/gitea/Wii/apps/Dusk/boot.dol
|
|
||||||
# mv build/dusk.dsk build/gitea/Wii/apps/Dusk/dusk.dsk
|
|
||||||
# - name: Upload Wii Binary
|
|
||||||
# uses: actions/upload-artifact@v3
|
|
||||||
# with:
|
|
||||||
# name: dusk-wii
|
|
||||||
# path: build/gitea/Wii
|
|
||||||
# if-no-files-found: error
|
|
||||||
|
|
||||||
run-tests:
|
run-tests:
|
||||||
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
|
||||||
@@ -102,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
|
||||||
@@ -114,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
|
||||||
@@ -124,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
|
||||||
@@ -140,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
|
||||||
|
|
||||||
|
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
|
if-no-files-found: error
|
||||||
@@ -30,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})
|
||||||
@@ -37,12 +38,9 @@ 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
|
# Set target system, default to linux if not set.
|
||||||
# message(FATAL_ERROR "DISABLED FOR NOW2 ${DUSK_TARGET_SYSTEM}")
|
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||||
set(DUSK_TARGET_SYSTEM "linux")
|
set(DUSK_TARGET_SYSTEM "linux")
|
||||||
# set(DUSK_TARGET_SYSTEM "psp")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Toolchains
|
# Toolchains
|
||||||
@@ -58,7 +56,7 @@ 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 CXX
|
LANGUAGES C
|
||||||
)
|
)
|
||||||
|
|
||||||
# Either, create library and binary separately (used for tests), or make them
|
# Either, create library and binary separately (used for tests), or make them
|
||||||
@@ -76,20 +74,18 @@ if(ENABLE_TESTS)
|
|||||||
${DUSK_LIBRARY_TARGET_NAME}
|
${DUSK_LIBRARY_TARGET_NAME}
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(DUSK_BINARY_TARGET_NAME "${DUSK_LIBRARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
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)
|
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/null.c)
|
||||||
endif()
|
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
|
pthread
|
||||||
@@ -98,9 +94,25 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
|||||||
m
|
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
|
||||||
@@ -114,19 +126,37 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|||||||
lzma
|
lzma
|
||||||
m
|
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")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
||||||
configure_file(opengl.pc.in opengl.pc @ONLY)
|
# configure_file(opengl.pc.in opengl.pc @ONLY)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(zip IMPORTED_TARGET libzip)
|
pkg_check_modules(zip IMPORTED_TARGET libzip)
|
||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
DOLPHIN
|
DOLPHIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Disable all warnings
|
||||||
|
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE -w)
|
||||||
|
|
||||||
# Custom flags for cglm
|
# Custom flags for cglm
|
||||||
set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
||||||
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
||||||
@@ -160,14 +190,28 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wi
|
|||||||
fat
|
fat
|
||||||
PkgConfig::zip
|
PkgConfig::zip
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
# Force turn tests off for now
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
set(ENABLE_TESTS OFF CACHE BOOL "Enable tests" FORCE)
|
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()
|
||||||
|
|
||||||
# Add code
|
# Add code
|
||||||
add_subdirectory(${DUSK_SOURCES_DIR})
|
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)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
@@ -175,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(
|
||||||
@@ -199,7 +240,7 @@ 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")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||||
|
|||||||
@@ -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
|
||||||
|
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
|
break
|
||||||
else:
|
|
||||||
|
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"
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|
||||||
@@ -17,19 +17,18 @@ if PLATFORM == "psp" then
|
|||||||
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 PLATFORM == "gamecube" then
|
elseif DOLPHIN then
|
||||||
-- inputBind("start", INPUT_ACTION_RAGEQUIT)
|
inputBind("up", INPUT_ACTION_UP)
|
||||||
-- inputBind("dpad_up", INPUT_ACTION_UP)
|
inputBind("down", INPUT_ACTION_DOWN)
|
||||||
-- inputBind("dpad_down", INPUT_ACTION_DOWN)
|
inputBind("left", INPUT_ACTION_LEFT)
|
||||||
-- inputBind("dpad_left", INPUT_ACTION_LEFT)
|
inputBind("right", INPUT_ACTION_RIGHT)
|
||||||
-- inputBind("dpad_right", INPUT_ACTION_RIGHT)
|
inputBind("b", INPUT_ACTION_CANCEL)
|
||||||
-- inputBind("button_b", INPUT_ACTION_CANCEL)
|
inputBind("a", INPUT_ACTION_ACCEPT)
|
||||||
-- inputBind("button_a", INPUT_ACTION_ACCEPT)
|
inputBind("z", INPUT_ACTION_RAGEQUIT)
|
||||||
-- inputBind("button_start", INPUT_ACTION_RAGEQUIT)
|
inputBind("lstick_up", INPUT_ACTION_UP)
|
||||||
-- inputBind("lstick_up", INPUT_ACTION_UP)
|
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)
|
|
||||||
|
|
||||||
else
|
else
|
||||||
if INPUT_KEYBOARD then
|
if INPUT_KEYBOARD then
|
||||||
@@ -49,8 +48,12 @@ else
|
|||||||
inputBind("q", INPUT_ACTION_CANCEL)
|
inputBind("q", INPUT_ACTION_CANCEL)
|
||||||
|
|
||||||
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,66 +0,0 @@
|
|||||||
module('spritebatch')
|
|
||||||
module('camera')
|
|
||||||
module('color')
|
|
||||||
-- module('ui')
|
|
||||||
module('text')
|
|
||||||
module('screen')
|
|
||||||
module('time')
|
|
||||||
module('map')
|
|
||||||
module('glm')
|
|
||||||
|
|
||||||
screenSetBackground(colorLime())
|
|
||||||
mapCamera = cameraCreate()
|
|
||||||
text = "Hello, Dusk!"
|
|
||||||
|
|
||||||
x = -35
|
|
||||||
y = 0
|
|
||||||
|
|
||||||
function sceneDispose()
|
|
||||||
end
|
|
||||||
function sceneUpdate()
|
|
||||||
end
|
|
||||||
function sceneRender()
|
|
||||||
mapCamera.position = vec3(50, 50, 50)
|
|
||||||
cameraPushMatrix(mapCamera)
|
|
||||||
|
|
||||||
textDraw(x, y, text, colorBlue())
|
|
||||||
|
|
||||||
spriteBatchFlush()
|
|
||||||
cameraPopMatrix()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
-- mapCamera.position = vec3(300, 300, 300)
|
|
||||||
-- cameraPushMatrix(mapCamera)
|
|
||||||
-- 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,7 +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=ALPHA tileWidth=6 tileHeight=10 columns=16 rows=6)# Fixes PSP rendering
|
|
||||||
# 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 |
@@ -7,7 +7,7 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
10
opengl.pc.in
10
opengl.pc.in
@@ -1,10 +0,0 @@
|
|||||||
prefix=@CMAKE_INSTALL_PREFIX@
|
|
||||||
libdir=${prefix}/lib
|
|
||||||
includedir=${prefix}/include
|
|
||||||
|
|
||||||
Name: OpenGL
|
|
||||||
Description: OpenGL (without GLX) library and headers.
|
|
||||||
Version: @PROJECT_VERSION@
|
|
||||||
Libs.private: -lstdc++ -logc -lm
|
|
||||||
Libs: -L${libdir} -lopengx
|
|
||||||
Cflags: -I${includedir}
|
|
||||||
@@ -151,8 +151,7 @@ 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,
|
||||||
sizeof(ASSET_PBP_SIGNATURE)
|
sizeof(ASSET_PBP_SIGNATURE)
|
||||||
@@ -233,6 +232,20 @@ 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.
|
// Get file size of the asset.
|
||||||
zip_stat_t st;
|
zip_stat_t st;
|
||||||
zip_stat_init(&st);
|
zip_stat_init(&st);
|
||||||
@@ -242,8 +255,8 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
|
|
||||||
// Minimum file size.
|
// Minimum file size.
|
||||||
zip_int64_t fileSize = (zip_int64_t)st.size;
|
zip_int64_t fileSize = (zip_int64_t)st.size;
|
||||||
if(fileSize < sizeof(assetheader_t)) {
|
if(fileSize <= 0) {
|
||||||
errorThrow("Asset file too small to contain header: %s", filename);
|
errorThrow("Asset file is empty: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to open the file
|
// Try to open the file
|
||||||
@@ -251,61 +264,19 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
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.
|
|
||||||
zip_int64_t bytesRemaining = fileSize;
|
|
||||||
assetheader_t header;
|
|
||||||
memoryZero(&header, sizeof(assetheader_t));
|
|
||||||
zip_int64_t bytesRead = zip_fread(
|
|
||||||
file,
|
|
||||||
&header,
|
|
||||||
(zip_uint64_t)sizeof(assetheader_t)
|
|
||||||
);
|
|
||||||
if((size_t)bytesRead != sizeof(assetheader_t)) {
|
|
||||||
zip_fclose(file);
|
|
||||||
errorThrow("Failed to read asset header for: %s", filename);
|
|
||||||
}
|
|
||||||
bytesRemaining -= (zip_uint64_t)bytesRead;
|
|
||||||
|
|
||||||
assertTrue(sizeof(assetheader_t) == ASSET_HEADER_SIZE, "Asset header size mismatch.");
|
// Load the asset data
|
||||||
assertTrue(bytesRead == ASSET_HEADER_SIZE, "Asset header read size mismatch.");
|
|
||||||
|
|
||||||
// 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.");
|
||||||
|
|
||||||
// Must have more to read
|
// Must have more to read
|
||||||
if(bytesRemaining <= 0) {
|
if(fileSize <= 0) {
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
errorThrow("No data remaining to read for asset: %s", filename);
|
errorThrow("No data remaining to read for asset: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bytesRemaining > def->dataSize) {
|
if(fileSize > def->dataSize) {
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
errorThrow(
|
errorThrow(
|
||||||
"Asset file has too much data remaining after header: %s",
|
"Asset file has too much data remaining after header: %s",
|
||||||
@@ -314,26 +285,30 @@ errorret_t assetLoad(const char_t *filename, void *output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create space to read the entire asset data
|
// Create space to read the entire asset data
|
||||||
void *data = memoryAllocate(bytesRemaining);
|
void *data = memoryAllocate(fileSize);
|
||||||
if(!data) {
|
if(!data) {
|
||||||
zip_fclose(file);
|
zip_fclose(file);
|
||||||
errorThrow("Failed to allocate memory for asset data of file: %s", filename);
|
errorThrow("Failed to allocate memory for asset data of file: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read in the asset data.
|
// Read in the asset data.
|
||||||
bytesRead = zip_fread(file, data, bytesRemaining);
|
zip_int64_t bytesRead = zip_fread(file, data, fileSize);
|
||||||
if(bytesRead == 0 || bytesRead > bytesRemaining) {
|
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);
|
||||||
}
|
}
|
||||||
bytesRemaining -= bytesRead;
|
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);
|
||||||
|
|||||||
@@ -72,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,34 +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"
|
|
||||||
|
|
||||||
#include "debug/debug.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;
|
|
||||||
|
|
||||||
// Fix endian
|
|
||||||
dataPtr->width = le32toh(dataPtr->width);
|
|
||||||
dataPtr->height = le32toh(dataPtr->height);
|
|
||||||
|
|
||||||
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,40 +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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix the endianness of the header data.
|
|
||||||
for(uint32_t i = 0; i < LANG_KEY_COUNT; i++) {
|
|
||||||
lang->header.strings[i].chunk = le32toh(lang->header.strings[i].chunk);
|
|
||||||
lang->header.strings[i].offset = le32toh(lang->header.strings[i].offset);
|
|
||||||
lang->header.strings[i].length = le32toh(lang->header.strings[i].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
||||||
@@ -66,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 {
|
||||||
@@ -56,7 +57,7 @@ errorret_t assetMapChunkHandler(assetcustom_t custom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix endianess if necessary
|
// Fix endianess if necessary
|
||||||
header.tileCount = le32toh(header.tileCount);
|
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);
|
||||||
@@ -111,7 +112,7 @@ errorret_t assetMapChunkHandler(assetcustom_t custom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix endianess if necessary
|
// Fix endianess if necessary
|
||||||
modelHeader.vertexCount = le32toh(modelHeader.vertexCount);
|
modelHeader.vertexCount = endianLittleToHost32(modelHeader.vertexCount);
|
||||||
|
|
||||||
if(
|
if(
|
||||||
vertexIndex + modelHeader.vertexCount >
|
vertexIndex + modelHeader.vertexCount >
|
||||||
|
|||||||
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,37 +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;
|
|
||||||
|
|
||||||
// Fix endian
|
|
||||||
assetData->width = le32toh(assetData->width);
|
|
||||||
assetData->height = le32toh(assetData->height);
|
|
||||||
|
|
||||||
textureInit(
|
|
||||||
texture,
|
|
||||||
assetData->width,
|
|
||||||
assetData->height,
|
|
||||||
TEXTURE_FORMAT_PALETTE,
|
|
||||||
(texturedata_t){
|
|
||||||
.palette = {
|
|
||||||
.palette = assetData->paletteIndex,
|
|
||||||
.data = assetData->palette
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
@@ -1,34 +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_PALETTE_IMAGE_WIDTH_MAX 128
|
|
||||||
#define ASSET_PALETTE_IMAGE_HEIGHT_MAX 128
|
|
||||||
#define ASSET_PALETTE_IMAGE_SIZE_MAX ( \
|
|
||||||
ASSET_PALETTE_IMAGE_WIDTH_MAX * ASSET_PALETTE_IMAGE_HEIGHT_MAX \
|
|
||||||
)
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t height;
|
|
||||||
uint8_t paletteIndex;
|
|
||||||
uint8_t palette[ASSET_PALETTE_IMAGE_SIZE_MAX];
|
|
||||||
} assetpaletteimage_t;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a palette image asset from the given data pointer into the output
|
|
||||||
* texture.
|
|
||||||
*
|
|
||||||
* @param data Pointer to the raw assetpaletteimage_t data.
|
|
||||||
* @param output Pointer to the texture_t to load the image into.
|
|
||||||
* @return An error code.
|
|
||||||
*/
|
|
||||||
errorret_t assetPaletteImageLoad(void *data, void *output);
|
|
||||||
58
src/asset/type/assettexture.c
Normal file
58
src/asset/type/assettexture.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "assettexture.h"
|
||||||
|
#include "asset/assettype.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "display/texture/texture.h"
|
||||||
|
#include "util/endian.h"
|
||||||
|
|
||||||
|
errorret_t assetTextureLoad(assetentire_t entire) {
|
||||||
|
assertNotNull(entire.data, "Data pointer cannot be NULL.");
|
||||||
|
assertNotNull(entire.output, "Output pointer cannot be NULL.");
|
||||||
|
|
||||||
|
assettexture_t *assetData = (assettexture_t *)entire.data;
|
||||||
|
texture_t *texture = (texture_t *)entire.output;
|
||||||
|
|
||||||
|
// Read header and version (first 4 bytes)
|
||||||
|
if(
|
||||||
|
assetData->header[0] != 'D' ||
|
||||||
|
assetData->header[1] != 'P' ||
|
||||||
|
assetData->header[2] != 'T'
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid texture header");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version (can only be 1 atm)
|
||||||
|
if(assetData->version != 0x01) {
|
||||||
|
errorThrow("Unsupported texture version");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix endian
|
||||||
|
assetData->width = endianLittleToHost32(assetData->width);
|
||||||
|
assetData->height = endianLittleToHost32(assetData->height);
|
||||||
|
|
||||||
|
// Check dimensions.
|
||||||
|
if(
|
||||||
|
assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX ||
|
||||||
|
assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid texture dimensions");
|
||||||
|
}
|
||||||
|
|
||||||
|
textureInit(
|
||||||
|
texture,
|
||||||
|
assetData->width,
|
||||||
|
assetData->height,
|
||||||
|
TEXTURE_FORMAT_PALETTE,
|
||||||
|
(texturedata_t){
|
||||||
|
.paletteData = assetData->palette
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
37
src/asset/type/assettexture.h
Normal file
37
src/asset/type/assettexture.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* 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_TEXTURE_WIDTH_MAX 2048
|
||||||
|
#define ASSET_TEXTURE_HEIGHT_MAX 2048
|
||||||
|
#define ASSET_TEXTURE_SIZE_MAX ( \
|
||||||
|
ASSET_TEXTURE_WIDTH_MAX * ASSET_TEXTURE_HEIGHT_MAX \
|
||||||
|
)
|
||||||
|
|
||||||
|
typedef struct assetentire_s assetentire_t;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct {
|
||||||
|
char_t header[3];
|
||||||
|
uint8_t version;
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
uint8_t palette[ASSET_TEXTURE_SIZE_MAX];
|
||||||
|
} assettexture_t;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a palettized texture from the given data pointer into the output
|
||||||
|
* texture.
|
||||||
|
*
|
||||||
|
* @param data Pointer to the raw assettexture_t data.
|
||||||
|
* @param output Pointer to the texture_t to load the image into.
|
||||||
|
* @return An error code.
|
||||||
|
*/
|
||||||
|
errorret_t assetTextureLoad(assetentire_t entire);
|
||||||
70
src/asset/type/assettileset.c
Normal file
70
src/asset/type/assettileset.c
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "asset/asset.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "display/texture/tileset.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/endian.h"
|
||||||
|
|
||||||
|
errorret_t assetTilesetLoad(assetentire_t entire) {
|
||||||
|
assertNotNull(entire.data, "Asset data cannot be null");
|
||||||
|
assertNotNull(entire.output, "Asset output cannot be null");
|
||||||
|
|
||||||
|
assettileset_t *tilesetData = (assettileset_t *)entire.data;
|
||||||
|
tileset_t *tileset = (tileset_t *)entire.output;
|
||||||
|
|
||||||
|
if(
|
||||||
|
tilesetData->header[0] != 'D' ||
|
||||||
|
tilesetData->header[1] != 'T' ||
|
||||||
|
tilesetData->header[2] != 'F'
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid tileset header");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tilesetData->version != 0x00) {
|
||||||
|
errorThrow("Unsupported tileset version");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix endianness
|
||||||
|
tilesetData->tileWidth = endianLittleToHost16(tilesetData->tileWidth);
|
||||||
|
tilesetData->tileHeight = endianLittleToHost16(tilesetData->tileHeight);
|
||||||
|
tilesetData->columnCount = endianLittleToHost16(tilesetData->columnCount);
|
||||||
|
tilesetData->rowCount = endianLittleToHost16(tilesetData->rowCount);
|
||||||
|
tilesetData->right = endianLittleToHost16(tilesetData->right);
|
||||||
|
tilesetData->bottom = endianLittleToHost16(tilesetData->bottom);
|
||||||
|
|
||||||
|
if(tilesetData->tileWidth == 0) {
|
||||||
|
errorThrow("Tile width cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->tileHeight == 0) {
|
||||||
|
errorThrow("Tile height cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->columnCount == 0) {
|
||||||
|
errorThrow("Column count cannot be 0");
|
||||||
|
}
|
||||||
|
if(tilesetData->rowCount == 0) {
|
||||||
|
errorThrow("Row count cannot be 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
tilesetData->u0 = endianLittleToHostFloat(tilesetData->u0);
|
||||||
|
tilesetData->v0 = endianLittleToHostFloat(tilesetData->v0);
|
||||||
|
|
||||||
|
if(tilesetData->v0 < 0.0f || tilesetData->v0 > 1.0f) {
|
||||||
|
errorThrow("Invalid v0 value in tileset");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup tileset
|
||||||
|
tileset->tileWidth = tilesetData->tileWidth;
|
||||||
|
tileset->tileHeight = tilesetData->tileHeight;
|
||||||
|
tileset->tileCount = tilesetData->columnCount * tilesetData->rowCount;
|
||||||
|
tileset->columns = tilesetData->columnCount;
|
||||||
|
tileset->rows = tilesetData->rowCount;
|
||||||
|
tileset->uv[0] = tilesetData->u0;
|
||||||
|
tileset->uv[1] = tilesetData->v0;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user