Compare commits
237 Commits
77d3c54ebb
...
vita
| Author | SHA1 | Date | |
|---|---|---|---|
| 5919881568 | |||
| cbb68a399d | |||
| 0e794f28b1 | |||
| 87d2d9123e | |||
| 6823a4ddb5 | |||
| 20a7c70081 | |||
| 9caa33b3bb | |||
| 2d7e61460a | |||
| a4b7fb3f44 | |||
| 70056cf4ca | |||
| 5f4ab71ade | |||
| f3adb3257b | |||
| 438edda7fd | |||
| d5b0441e6f | |||
| 9ba0ceb000 | |||
| 9474a68995 | |||
| 09c35f0aa6 | |||
| a2113442cb | |||
| d91808487f | |||
| 933949cc19 | |||
| 407620387d | |||
| 98947dea26 | |||
| ebff7af9b5 | |||
| b23c4b83ae | |||
| c0cff40628 | |||
| 97513e354c | |||
| c277ae7aff | |||
| e1835e6282 | |||
| 5ac21db997 | |||
| ca0e9fc3b2 | |||
| 66ebcb1608 | |||
| ff92a78dda | |||
| 7356286fe0 | |||
| 54e8e68f86 | |||
| d21cd7f78b | |||
| 1d7516982a | |||
| c77a11442c | |||
| 5bd43a4643 | |||
| 9b87dfa1a9 | |||
| 2e3173ea40 | |||
| 68eac7cf83 | |||
| 6709505630 | |||
| af6e962a5d | |||
| 18e6bdabaa | |||
| 9743942eae | |||
| 23062137a8 | |||
| 46f7fb5ccd | |||
| 9c90c49a6b | |||
| 4517b63557 | |||
| 58c239f4b4 | |||
| cc8845ba3e | |||
| 6b69ce2901 | |||
| 55300ed21c | |||
| 7346dd4339 | |||
| 2caf3b92ce | |||
| af2cd72a1f | |||
| 3d455ec1f8 | |||
| 15982d7735 | |||
| 5ae3542bd9 | |||
| b1b02ae24b | |||
| f0964e2c92 | |||
| e9661d2998 | |||
| ea6468f2a9 | |||
| a2b38d3b83 | |||
| d67ef02941 | |||
| 549ebe25d8 | |||
| 9a98348582 | |||
| c5f5b025a6 | |||
| 23eaffa3a7 | |||
| c161809248 | |||
| 4bf26dc818 | |||
| 5dd22fad6c | |||
| 2c3fdf7803 | |||
| e984b9f5d7 | |||
| a3c2e37b17 | |||
| edf1b5a0a3 | |||
| 8efdf59ebd | |||
| 5c4537b2fa | |||
| 71e6079054 | |||
| dd048d9b0d | |||
| 93074d653e | |||
| 9139c4350a | |||
| 38ce768168 | |||
| 82b3dc576c | |||
| 2167889f48 | |||
| e9b02c2acf | |||
| 9ee446431b | |||
| df106e3988 | |||
| 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 | |||
| 5cea284906 | |||
| 13dba8b604 | |||
| 22398ddcef | |||
| 94e2cc6210 | |||
| da3513f63d | |||
| 2c83e4ba9f | |||
| c862071126 | |||
| fed819e9b2 | |||
| c6f4518684 | |||
| 053778a502 | |||
| 78e1ae885a | |||
| 982d28a3e0 | |||
| c2cad858a5 | |||
| 794e0574ad | |||
| c190271565 | |||
| ae8a869f64 | |||
| 69d64eb8e4 | |||
| b2f2df650a | |||
| 6af570fab2 | |||
| 9ed902017c | |||
| 32b41c98e1 | |||
| 6bdb4ae30d | |||
| 25dc97e3cc | |||
| cc85983736 | |||
| 6e78ee188d | |||
| 9b73f1717f | |||
| c7b9a53535 | |||
| 2b9be6675c | |||
| fb93453482 | |||
| 81b08b2eba | |||
| d1b03c4cb3 | |||
| 9544d15a18 | |||
| 0392dd0e7f | |||
| 9c25fde548 | |||
| 2c9d0c6cff | |||
| 9897dbe031 | |||
| e78f117cfd | |||
| 07afc3813a | |||
| d788de8637 | |||
| d749ac8a91 | |||
| f71c271c97 | |||
| e1d7b7308f | |||
| 26a71a823a | |||
| 5e39097faa | |||
| 0df7845f2c | |||
| af5bf987c8 | |||
| 024ace1078 | |||
| 8d00fe9d16 | |||
| ab422b14dd | |||
| 95c0690216 | |||
| 6cb80e9e23 | |||
| 83b799caa8 | |||
| a793ac2ff7 | |||
| aec937b04b | |||
| 8ee46fd204 | |||
| 726233e55f | |||
| 7940f4c487 | |||
| b16dbaceec | |||
| f39b2060a8 | |||
| aed202ebf9 | |||
| a495179e5f | |||
| 4e1b404820 | |||
| 8c74ee31e0 |
@@ -1,58 +0,0 @@
|
|||||||
name: Build Dusk
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-linux:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v5
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y build-essential cmake python3 python3-pip python3-polib python3-pil libsdl2-dev libgl1-mesa-dev libzip-dev python3-dotenv python3-pyqt5 python3-opengl liblua5.3-dev
|
|
||||||
- name: Configure CMake
|
|
||||||
run: cmake -S . -B build -DDUSK_TARGET_SYSTEM=linux
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build -- -j$(nproc)
|
|
||||||
- name: List build output
|
|
||||||
run: ls -lh build
|
|
||||||
- name: Upload Linux binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-linux
|
|
||||||
path: build/Dusk
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
build-psp:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v5
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y build-essential cmake python3 python3-pip python3-polib python3-pil libsdl2-dev libgl1-mesa-dev libzip-dev python3-dotenv python3-pyqt5 python3-opengl liblua5.3-dev
|
|
||||||
- name: Configure CMake
|
|
||||||
run: cmake -S . -B build -DDUSK_TARGET_SYSTEM=psp
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build -- -j$(nproc)
|
|
||||||
- name: Move EBOOT.PBP to Dusk subfolder
|
|
||||||
run: |
|
|
||||||
mkdir -p build/gitea/Dusk
|
|
||||||
mv build/EBOOT.PBP build/gitea/Dusk/EBOOT.PBP
|
|
||||||
- name: List build output
|
|
||||||
run: ls -lh build/gitea/Dusk
|
|
||||||
- name: Upload PSP binary
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: dusk-psp
|
|
||||||
path: build/gitea/
|
|
||||||
if-no-files-found: error
|
|
||||||
117
.github/workflows/build.yml
vendored
Normal file
117
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
name: Build Dusk
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
jobs:
|
||||||
|
run-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Run tests in Docker
|
||||||
|
run: ./scripts/test-linux-docker.sh
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Build Linux
|
||||||
|
run: ./scripts/build-linux-docker.sh
|
||||||
|
- name: Upload Linux binary
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: dusk-linux
|
||||||
|
path: build-linux/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-psp:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Build psp
|
||||||
|
run: ./scripts/build-psp-docker.sh
|
||||||
|
- name: Move EBOOT.PBP to Dusk subfolder
|
||||||
|
run: |
|
||||||
|
mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
||||||
|
cp build-psp/EBOOT.PBP ./git-artifcats/Dusk/PSP/GAME/Dusk/EBOOT.PBP
|
||||||
|
- name: Upload psp binary
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: dusk-psp
|
||||||
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-knulli:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Build knulli
|
||||||
|
run: ./scripts/build-knulli-docker.sh
|
||||||
|
- name: Move output to Dusk subfolder
|
||||||
|
run: |
|
||||||
|
mkdir -p ./git-artifcats/Dusk
|
||||||
|
cp -r build-knulli/dusk ./git-artifcats/Dusk
|
||||||
|
- name: Upload knulli binary
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: dusk-knulli
|
||||||
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-gamecube:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Build GameCube
|
||||||
|
run: ./scripts/build-gamecube-docker.sh
|
||||||
|
- name: Copy output files.
|
||||||
|
run: |
|
||||||
|
mkdir -p ./git-artifcats/Dusk
|
||||||
|
cp build-gamecube/Dusk.dol ./git-artifcats/Dusk/Dusk.dol
|
||||||
|
cp build-gamecube/dusk.dsk ./git-artifcats/Dusk/dusk.dsk
|
||||||
|
- name: Upload GameCube binary
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: dusk-gamecube
|
||||||
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-wii:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v5
|
||||||
|
- name: Build Wii
|
||||||
|
run: ./scripts/build-wii-docker.sh
|
||||||
|
- name: Copy output files.
|
||||||
|
run: |
|
||||||
|
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||||
|
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/Dusk.dol
|
||||||
|
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||||
|
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||||
|
- name: Upload Wii binary
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: dusk-wii
|
||||||
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -101,4 +101,7 @@ yarn-error.log
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
.editor
|
.editor
|
||||||
.venv
|
.venv
|
||||||
|
|
||||||
|
/build2
|
||||||
|
/build*
|
||||||
146
CMakeLists.txt
146
CMakeLists.txt
@@ -4,15 +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)
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
option(DUSK_BUILD_TESTS "Enable tests" OFF)
|
||||||
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")
|
||||||
@@ -21,100 +19,96 @@ set(DUSK_CACHE_TARGET "dusk-target")
|
|||||||
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||||
set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
||||||
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
||||||
|
set(DUSK_TEST_DIR "${DUSK_ROOT_DIR}/test")
|
||||||
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
||||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
||||||
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
||||||
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
||||||
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
||||||
set(DUSK_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
|
||||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
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_BINARY_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
|
||||||
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||||
|
set(DUSK_TARGET_SYSTEM "linux")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Create directories
|
# Create directories
|
||||||
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
file(MAKE_DIRECTORY ${DUSK_GENERATED_HEADERS_DIR})
|
||||||
|
file(MAKE_DIRECTORY ${DUSK_TEMP_DIR})
|
||||||
|
file(MAKE_DIRECTORY ${DUSK_BUILT_ASSETS_DIR})
|
||||||
|
|
||||||
# Find packages
|
# Required build packages
|
||||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||||
|
|
||||||
# Toolchains
|
# Init Project.
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
project(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
find_package(pspsdk REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Init Project
|
|
||||||
project(${DUSK_TARGET_NAME}
|
|
||||||
VERSION 1.0.0
|
VERSION 1.0.0
|
||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
)
|
)
|
||||||
|
|
||||||
# Executable
|
# Either, create library and binary separately (used for tests), or make them
|
||||||
add_executable(${DUSK_TARGET_NAME})
|
# one in the same so all code is in the binary only.
|
||||||
|
# Binary Executable
|
||||||
|
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/dusk/null.c)
|
||||||
|
|
||||||
|
if(DUSK_BUILD_TESTS)
|
||||||
|
# MainLibrary
|
||||||
|
add_library(${DUSK_LIBRARY_TARGET_NAME} STATIC)
|
||||||
|
|
||||||
|
# Link library to binary
|
||||||
|
target_link_libraries(${DUSK_BINARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Definitions
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
DUSK_TARGET_SYSTEM="${DUSK_TARGET_SYSTEM}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Toolchains
|
||||||
|
include(cmake/targets/${DUSK_TARGET_SYSTEM}.cmake)
|
||||||
|
|
||||||
# Add tools
|
# Add tools
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
|
|
||||||
# Assets
|
# Include generated headers from tools.
|
||||||
add_subdirectory(assets)
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
|
||||||
# Add libraries
|
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
target_link_libraries(${DUSK_TARGET_NAME} PRIVATE
|
|
||||||
SDL2
|
|
||||||
OpenGL::GL
|
|
||||||
GL
|
|
||||||
)
|
|
||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|
||||||
find_package(SDL2 REQUIRED)
|
|
||||||
find_package(OpenGL REQUIRED)
|
|
||||||
target_link_libraries(${DUSK_TARGET_NAME} PUBLIC
|
|
||||||
${SDL2_LIBRARIES}
|
|
||||||
SDL2
|
|
||||||
OpenGL::GL
|
|
||||||
zip
|
|
||||||
bz2
|
|
||||||
z
|
|
||||||
mbedtls
|
|
||||||
mbedcrypto
|
|
||||||
lzma
|
|
||||||
)
|
|
||||||
target_include_directories(${DUSK_TARGET_NAME} PRIVATE
|
|
||||||
${SDL2_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Add code
|
|
||||||
add_subdirectory(src)
|
|
||||||
|
|
||||||
# Build assets
|
|
||||||
add_custom_target(DUSK_ASSETS_BUILT ALL
|
|
||||||
COMMAND
|
|
||||||
${Python3_EXECUTABLE} ${DUSK_TOOLS_DIR}/assettool.py
|
|
||||||
--assets ${DUSK_GAME_ASSETS_DIR}
|
|
||||||
--output-assets ${DUSK_BUILT_ASSETS_DIR}
|
|
||||||
--output-file ${DUSK_BUILD_DIR}/dusk.dsk
|
|
||||||
--headers-dir ${DUSK_GENERATED_HEADERS_DIR}
|
|
||||||
--input ${DUSK_ASSETS}
|
|
||||||
)
|
|
||||||
add_dependencies(${DUSK_TARGET_NAME} DUSK_ASSETS_BUILT)
|
|
||||||
|
|
||||||
# Include generated headers
|
|
||||||
target_include_directories(${DUSK_TARGET_NAME} PUBLIC
|
|
||||||
${DUSK_GENERATED_HEADERS_DIR}
|
${DUSK_GENERATED_HEADERS_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Postbuild
|
# Add main code
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
add_subdirectory(${DUSK_SOURCES_DIR})
|
||||||
create_pbp_file(
|
|
||||||
TARGET "${DUSK_TARGET_NAME}"
|
# Include generated headers
|
||||||
ICON_PATH NULL
|
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
BACKGROUND_PATH NULL
|
${DUSK_GENERATED_HEADERS_DIR}
|
||||||
PREVIEW_PATH NULL
|
)
|
||||||
TITLE "${DUSK_TARGET_NAME}"
|
|
||||||
PSAR_PATH ${DUSK_BUILD_DIR}/dusk.dsk
|
# Handle tests
|
||||||
VERSION 01.00
|
if(DUSK_BUILD_TESTS)
|
||||||
)
|
enable_testing()
|
||||||
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Build assets
|
||||||
|
file(GLOB_RECURSE DUSK_ASSET_FILES CONFIGURE_DEPENDS "${DUSK_ASSETS_DIR}/*")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${DUSK_ASSETS_ZIP}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
||||||
|
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
||||||
|
DEPENDS ${DUSK_ASSET_FILES}
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
add_custom_target(DUSK_ASSETS_BUILT DEPENDS "${DUSK_ASSETS_ZIP}")
|
||||||
|
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ following packages, depending on your system;
|
|||||||
|
|
||||||
Fedora;
|
Fedora;
|
||||||
```
|
```
|
||||||
sudo dnf install git make gcc python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl
|
sudo dnf install git make gcc cmake python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel zlib-devel libzip-devel bzip2-devel openssl-devel lzma-sdk-devel xz xz-devel lua-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
Ubuntu;
|
Ubuntu;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import sys, os
|
import sys, os
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.processasset import processAsset
|
from tools.asset.process.asset import processAsset
|
||||||
from assetstool.processpalette import processPaletteList
|
from tools.asset.process.palette import processPaletteList
|
||||||
from assetstool.processtileset import processTilesetList
|
from tools.asset.process.tileset import processTilesetList
|
||||||
from assetstool.processlanguage import processLanguageList
|
from tools.asset.process.language import processLanguageList
|
||||||
from assetstool.assethelpers import getBuiltAssetsRelativePath
|
from tools.asset.path import getBuiltAssetsRelativePath
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
# Parse input file args.
|
# Parse input file args.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
|
|
||||||
def getAssetRelativePath(fullPath):
|
def getAssetRelativePath(fullPath):
|
||||||
# Get the relative path to the asset
|
# Get the relative path to the asset
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import sys
|
import sys
|
||||||
# from processtileset import processTileset
|
# from processtileset import processTileset
|
||||||
from assetstool.processimage import processImage
|
from tools.asset.process.image import processImage
|
||||||
from assetstool.processpalette import processPalette
|
from tools.asset.process.palette import processPalette
|
||||||
from assetstool.processtileset import processTileset
|
from tools.asset.process.tileset import processTileset
|
||||||
from assetstool.processmap import processMap
|
from tools.asset.process.map import processMap
|
||||||
from assetstool.processlanguage import processLanguage
|
from tools.asset.process.language import processLanguage
|
||||||
from assetstool.processscript import processScript
|
from tools.asset.process.script import processScript
|
||||||
|
|
||||||
processedAssets = []
|
processedAssets = []
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from assetstool.processpalette import extractPaletteFromImage, palettes
|
from tools.asset.process.palette import extractPaletteFromImage, palettes
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assethelpers import getAssetRelativePath
|
from tools.asset.path import getAssetRelativePath
|
||||||
from assetstool.assetcache import assetGetCache, assetCache
|
from tools.asset.cache import assetGetCache, assetCache
|
||||||
|
|
||||||
images = []
|
images = []
|
||||||
|
|
||||||
@@ -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,9 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assetcache import assetCache, assetGetCache
|
from tools.asset.cache import assetCache, assetGetCache
|
||||||
from assetstool.assethelpers import getAssetRelativePath
|
from tools.asset.path import getAssetRelativePath
|
||||||
from dusk.defs import defs
|
from tools.dusk.defs import defs
|
||||||
import polib
|
import polib
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -141,14 +141,49 @@ def processLanguageList():
|
|||||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
with open(outputFile, "wb") as f:
|
with open(outputFile, "wb") as f:
|
||||||
f.write(langBuffer)
|
f.write(langBuffer)
|
||||||
|
|
||||||
|
|
||||||
# Write out the language keys header file
|
# Write out the language keys header file
|
||||||
outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h")
|
outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h")
|
||||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
with open(outputFile, "w") as f:
|
with open(outputFile, "w") as f:
|
||||||
f.write(headerKeys)
|
f.write(headerKeys)
|
||||||
|
|
||||||
|
# Generate language list.
|
||||||
|
langValues = {}
|
||||||
|
headerLocale = "#pragma once\n#include \"locale/localeinfo.h\"\n\n"
|
||||||
|
headerLocale += "typedef enum {\n"
|
||||||
|
count = 0
|
||||||
|
headerLocale += f" DUSK_LOCALE_NULL = {count},\n"
|
||||||
|
count += 1
|
||||||
|
for lang in LANGUAGE_DATA:
|
||||||
|
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||||
|
langValues[lang] = count
|
||||||
|
headerLocale += f" DUSK_LOCALE_{langKey} = {count},\n"
|
||||||
|
count += 1
|
||||||
|
headerLocale += f" DUSK_LOCALE_COUNT = {count}\n"
|
||||||
|
headerLocale += "} dusklocale_t;\n\n"
|
||||||
|
|
||||||
|
headerLocale += f"static const localeinfo_t LOCALE_INFOS[DUSK_LOCALE_COUNT] = {{\n"
|
||||||
|
for lang in LANGUAGE_DATA:
|
||||||
|
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||||
|
headerLocale += f" [DUSK_LOCALE_{langKey}] = {{\n"
|
||||||
|
headerLocale += f" .file = \"{lang}\"\n"
|
||||||
|
headerLocale += f" }},\n"
|
||||||
|
headerLocale += "};\n"
|
||||||
|
|
||||||
|
headerLocale += f"static const char_t *LOCALE_SCRIPT = \n"
|
||||||
|
for lang in LANGUAGE_DATA:
|
||||||
|
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||||
|
langValue = langValues[lang]
|
||||||
|
headerLocale += f" \"DUSK_LOCALE_{langKey} = {langValue}\\n\"\n"
|
||||||
|
headerLocale += ";\n"
|
||||||
|
|
||||||
|
# Write out the locale enum header file
|
||||||
|
outputFile = os.path.join(args.headers_dir, "locale", "locale.h")
|
||||||
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
|
with open(outputFile, "w") as f:
|
||||||
|
f.write(headerLocale)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'files': files
|
'files': files
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,12 @@ import struct
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assetcache import assetCache, assetGetCache
|
from tools.asset.cache import assetCache, assetGetCache
|
||||||
from assetstool.assethelpers import getAssetRelativePath
|
from tools.asset.path import getAssetRelativePath
|
||||||
from dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_TILE_COUNT
|
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_TILE_COUNT
|
||||||
from dusk.map import Map
|
from tools.dusk.map import Map
|
||||||
from dusk.chunk import Chunk
|
from tools.dusk.chunk import Chunk
|
||||||
|
|
||||||
def convertModelData(modelData):
|
def convertModelData(modelData):
|
||||||
# TLDR; Model data stores things efficiently with indices, but we buffer it
|
# TLDR; Model data stores things efficiently with indices, but we buffer it
|
||||||
@@ -51,7 +51,7 @@ def processChunk(chunk):
|
|||||||
|
|
||||||
# Generate binary buffer for efficient output
|
# Generate binary buffer for efficient output
|
||||||
buffer = bytearray()
|
buffer = bytearray()
|
||||||
buffer.extend(b'DCF')# Header
|
buffer.extend(b'DMC')# Header
|
||||||
buffer.extend(len(chunk.tiles).to_bytes(4, 'little')) # Number of tiles
|
buffer.extend(len(chunk.tiles).to_bytes(4, 'little')) # Number of tiles
|
||||||
buffer.extend(len(models).to_bytes(1, 'little')) # Number of models
|
buffer.extend(len(models).to_bytes(1, 'little')) # Number of models
|
||||||
buffer.extend(len(chunk.entities).to_bytes(1, 'little')) # Number of entities
|
buffer.extend(len(chunk.entities).to_bytes(1, 'little')) # Number of entities
|
||||||
@@ -92,7 +92,7 @@ def processChunk(chunk):
|
|||||||
# Write out map file
|
# Write out map file
|
||||||
relative = getAssetRelativePath(chunk.getFilename())
|
relative = getAssetRelativePath(chunk.getFilename())
|
||||||
fileNameWithoutExt = os.path.splitext(os.path.basename(relative))[0]
|
fileNameWithoutExt = os.path.splitext(os.path.basename(relative))[0]
|
||||||
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dcf")
|
outputFileRelative = os.path.join(os.path.dirname(relative), f"{fileNameWithoutExt}.dmc")
|
||||||
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
outputFilePath = os.path.join(args.output_assets, outputFileRelative)
|
||||||
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
|
||||||
with open(outputFilePath, "wb") as f:
|
with open(outputFilePath, "wb") as f:
|
||||||
@@ -111,11 +111,11 @@ def processMap(asset):
|
|||||||
|
|
||||||
map = Map(None)
|
map = Map(None)
|
||||||
map.load(asset['path'])
|
map.load(asset['path'])
|
||||||
dir = map.getMapDirectory()
|
chunksDir = map.getChunkDirectory()
|
||||||
|
|
||||||
files = os.listdir(dir)
|
files = os.listdir(chunksDir)
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
print(f"Error: No chunk files found in map directory {dir}.")
|
print(f"Error: No chunk files found in {chunksDir}.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
chunkFiles = []
|
chunkFiles = []
|
||||||
@@ -133,21 +133,22 @@ def processMap(asset):
|
|||||||
result = processChunk(chunk)
|
result = processChunk(chunk)
|
||||||
chunkFiles.extend(result['files'])
|
chunkFiles.extend(result['files'])
|
||||||
|
|
||||||
outMap = {
|
# Map file
|
||||||
'files': chunkFiles
|
outBuffer = bytearray()
|
||||||
}
|
outBuffer.extend(b'DMF')
|
||||||
return assetCache(asset['path'], outMap)
|
outBuffer.extend(len(chunkFiles).to_bytes(4, 'little'))
|
||||||
|
|
||||||
# List files
|
# DMF (Dusk Map file)
|
||||||
chunkFiles = []
|
fileRelative = getAssetRelativePath(asset['path'])
|
||||||
for fileName in os.listdir(asset['path']):
|
fileNameWithoutExt = os.path.splitext(os.path.basename(fileRelative))[0]
|
||||||
if not fileName.endswith('.json'):
|
outputMapRelative = os.path.join(os.path.dirname(fileRelative), f"{fileNameWithoutExt}.dmf")
|
||||||
continue
|
outputMapPath = os.path.join(args.output_assets, outputMapRelative)
|
||||||
result = processChunk(os.path.join(asset['path'], fileName))
|
os.makedirs(os.path.dirname(outputMapPath), exist_ok=True)
|
||||||
chunkFiles.extend(result['files'])
|
with open(outputMapPath, "wb") as f:
|
||||||
|
f.write(outBuffer)
|
||||||
|
|
||||||
outMap = {
|
outMap = {
|
||||||
'files': chunkFiles
|
'files': chunkFiles
|
||||||
}
|
}
|
||||||
|
outMap['files'].append(outputMapPath)
|
||||||
return assetCache(asset['path'], outMap)
|
return assetCache(asset['path'], outMap)
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import datetime
|
import datetime
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assetcache import assetCache, assetGetCache
|
from tools.asset.cache import assetCache, assetGetCache
|
||||||
|
|
||||||
palettes = []
|
palettes = []
|
||||||
|
|
||||||
@@ -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"
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assetcache import assetCache, assetGetCache
|
from tools.asset.cache import assetCache, assetGetCache
|
||||||
from assetstool.assethelpers import getAssetRelativePath
|
from tools.asset.path import getAssetRelativePath
|
||||||
from dusk.defs import defs
|
from tools.dusk.defs import fileDefs
|
||||||
|
|
||||||
def processScript(asset):
|
def processScript(asset):
|
||||||
cache = assetGetCache(asset['path'])
|
cache = assetGetCache(asset['path'])
|
||||||
@@ -16,6 +16,10 @@ def processScript(asset):
|
|||||||
|
|
||||||
# TODO: I will precompile or minify the Lua code here in the future
|
# TODO: I will precompile or minify the Lua code here in the future
|
||||||
|
|
||||||
|
# Replace all definitions in the code
|
||||||
|
for key, val in fileDefs.items():
|
||||||
|
luaCode = luaCode.replace(key, str(val))
|
||||||
|
|
||||||
# Create output Dusk Script File (DSF) data
|
# Create output Dusk Script File (DSF) data
|
||||||
data = ""
|
data = ""
|
||||||
data += "DSF"
|
data += "DSF"
|
||||||
@@ -3,10 +3,10 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
from assetstool.processimage import processImage
|
from tools.asset.process.image import processImage
|
||||||
from assetstool.assethelpers import getAssetRelativePath
|
from tools.asset.path import getAssetRelativePath
|
||||||
from assetstool.args import args
|
from tools.asset.args import args
|
||||||
from assetstool.assetcache import assetGetCache, assetCache
|
from tools.asset.cache import assetGetCache, assetCache
|
||||||
|
|
||||||
tilesets = []
|
tilesets = []
|
||||||
|
|
||||||
@@ -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"
|
||||||
47
archive/assetpalette.c
Normal file
47
archive/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
archive/assetpalette.h
Normal file
30
archive/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,11 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from dusk.event import Event
|
from tools.dusk.event import Event
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_VERTEX_COUNT_MAX, TILE_SHAPE_NULL
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_VERTEX_COUNT_MAX, TILE_SHAPE_NULL
|
||||||
from dusk.tile import Tile
|
from tools.dusk.tile import Tile
|
||||||
from dusk.entity import Entity
|
from tools.dusk.entity import Entity
|
||||||
from dusk.region import Region
|
from tools.dusk.region import Region
|
||||||
from editortool.map.vertexbuffer import VertexBuffer
|
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
|
|
||||||
class Chunk:
|
class Chunk:
|
||||||
@@ -131,12 +131,12 @@ class Chunk:
|
|||||||
return self.dirty
|
return self.dirty
|
||||||
|
|
||||||
def getFilename(self):
|
def getFilename(self):
|
||||||
if not self.map or not hasattr(self.map, 'getMapDirectory'):
|
if not self.map or not hasattr(self.map, 'getChunkDirectory'):
|
||||||
return None
|
return None
|
||||||
dir_path = self.map.getMapDirectory()
|
dirPath = self.map.getChunkDirectory()
|
||||||
if dir_path is None:
|
if dirPath is None:
|
||||||
return None
|
return None
|
||||||
return f"{dir_path}/{self.x}_{self.y}_{self.z}.json"
|
return f"{dirPath}/{self.x}_{self.y}_{self.z}.json"
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.vertexBuffer.draw()
|
self.vertexBuffer.draw()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv, dotenv_values
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ if not os.path.isfile(duskDefsPath):
|
|||||||
load_dotenv(dotenv_path=duskDefsPath)
|
load_dotenv(dotenv_path=duskDefsPath)
|
||||||
defs = {key: os.getenv(key) for key in os.environ.keys()}
|
defs = {key: os.getenv(key) for key in os.environ.keys()}
|
||||||
|
|
||||||
|
fileDefs = dotenv_values(dotenv_path=duskDefsPath)
|
||||||
|
|
||||||
# Parsed out definitions
|
# Parsed out definitions
|
||||||
CHUNK_WIDTH = int(defs.get('CHUNK_WIDTH'))
|
CHUNK_WIDTH = int(defs.get('CHUNK_WIDTH'))
|
||||||
CHUNK_HEIGHT = int(defs.get('CHUNK_HEIGHT'))
|
CHUNK_HEIGHT = int(defs.get('CHUNK_HEIGHT'))
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from dusk.defs import ENTITY_TYPE_NULL, ENTITY_TYPE_NPC, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
from tools.dusk.defs import ENTITY_TYPE_NULL, ENTITY_TYPE_NPC, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||||
from editortool.map.vertexbuffer import VertexBuffer
|
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
def __init__(self, chunk, localX=0, localY=0, localZ=0):
|
def __init__(self, chunk, localX=0, localY=0, localZ=0):
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
from dusk.event import Event
|
import sys
|
||||||
|
from tools.dusk.event import Event
|
||||||
from PyQt5.QtWidgets import QFileDialog, QMessageBox
|
from PyQt5.QtWidgets import QFileDialog, QMessageBox
|
||||||
from PyQt5.QtCore import QTimer
|
from PyQt5.QtCore import QTimer
|
||||||
import os
|
import os
|
||||||
from dusk.chunk import Chunk
|
from tools.dusk.chunk import Chunk
|
||||||
from dusk.defs import MAP_WIDTH, MAP_HEIGHT, MAP_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
from tools.dusk.defs import MAP_WIDTH, MAP_HEIGHT, MAP_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../assets/map/')
|
MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../assets/map/')
|
||||||
@@ -129,11 +130,17 @@ class Map:
|
|||||||
return self.mapFileName if self.mapFileName and os.path.exists(self.mapFileName) else None
|
return self.mapFileName if self.mapFileName and os.path.exists(self.mapFileName) else None
|
||||||
|
|
||||||
def getMapDirectory(self):
|
def getMapDirectory(self):
|
||||||
fname = self.getMapFilename()
|
if self.mapFileName is None:
|
||||||
if not fname or not fname.endswith('.json'):
|
|
||||||
return None
|
return None
|
||||||
return fname[:-5] # Remove '.json' extension
|
dirname = os.path.dirname(self.mapFileName)
|
||||||
|
return dirname
|
||||||
|
|
||||||
|
def getChunkDirectory(self):
|
||||||
|
dirName = self.getMapDirectory()
|
||||||
|
if dirName is None:
|
||||||
|
return None
|
||||||
|
return os.path.join(dirName, 'chunks')
|
||||||
|
|
||||||
def anyChunksDirty(self):
|
def anyChunksDirty(self):
|
||||||
for chunk in self.chunks.values():
|
for chunk in self.chunks.values():
|
||||||
if chunk.isDirty():
|
if chunk.isDirty():
|
||||||
@@ -149,7 +156,7 @@ class Map:
|
|||||||
newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2)
|
newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2)
|
||||||
newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2)
|
newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2)
|
||||||
|
|
||||||
if (newTopLeftChunkX != self.topLeftX or
|
if(newTopLeftChunkX != self.topLeftX or
|
||||||
newTopLeftChunkY != self.topLeftY or
|
newTopLeftChunkY != self.topLeftY or
|
||||||
newTopLeftChunkZ != self.topLeftZ):
|
newTopLeftChunkZ != self.topLeftZ):
|
||||||
|
|
||||||
@@ -159,7 +166,7 @@ class Map:
|
|||||||
chunkWorldX = chunk.x
|
chunkWorldX = chunk.x
|
||||||
chunkWorldY = chunk.y
|
chunkWorldY = chunk.y
|
||||||
chunkWorldZ = chunk.z
|
chunkWorldZ = chunk.z
|
||||||
if (chunkWorldX < newTopLeftChunkX or
|
if(chunkWorldX < newTopLeftChunkX or
|
||||||
chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or
|
chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or
|
||||||
chunkWorldY < newTopLeftChunkY or
|
chunkWorldY < newTopLeftChunkY or
|
||||||
chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or
|
chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||||
from editortool.map.vertexbuffer import VertexBuffer
|
from tools.editor.map.vertexbuffer import VertexBuffer
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from OpenGL.GLU import *
|
from OpenGL.GLU import *
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from dusk.defs import (
|
from tools.dusk.defs import (
|
||||||
TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH,
|
TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH,
|
||||||
CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH,
|
CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH,
|
||||||
TILE_SHAPE_NULL, TILE_SHAPE_FLOOR,
|
TILE_SHAPE_NULL, TILE_SHAPE_FLOOR,
|
||||||
@@ -6,9 +6,9 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from OpenGL.GLU import *
|
from OpenGL.GLU import *
|
||||||
from editortool.maptool import MapWindow
|
from tools.editor.maptool import MapWindow
|
||||||
from editortool.langtool import LangToolWindow
|
from tools.editor.langtool import LangToolWindow
|
||||||
from editortool.cutscenetool import CutsceneToolWindow
|
from tools.editor.cutscenetool import CutsceneToolWindow
|
||||||
|
|
||||||
DEFAULT_TOOL = None
|
DEFAULT_TOOL = None
|
||||||
DEFAULT_TOOL = "map"
|
DEFAULT_TOOL = "map"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QListWidget, QListWidgetItem, QMenuBar, QAction, QFileDialog, QMessageBox
|
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QListWidget, QListWidgetItem, QMenuBar, QAction, QFileDialog, QMessageBox
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
from editortool.cutscene.cutsceneitemeditor import CutsceneItemEditor
|
from tools.editor.cutscene.cutsceneitemeditor import CutsceneItemEditor
|
||||||
from editortool.cutscene.cutscenemenubar import CutsceneMenuBar
|
from tools.editor.cutscene.cutscenemenubar import CutsceneMenuBar
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class CutsceneToolWindow(QMainWindow):
|
class CutsceneToolWindow(QMainWindow):
|
||||||
@@ -2,7 +2,7 @@ import math
|
|||||||
import time
|
import time
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from OpenGL.GLU import *
|
from OpenGL.GLU import *
|
||||||
from dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, RPG_CAMERA_PIXELS_PER_UNIT, RPG_CAMERA_Z_OFFSET, RPG_CAMERA_FOV
|
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH, RPG_CAMERA_PIXELS_PER_UNIT, RPG_CAMERA_Z_OFFSET, RPG_CAMERA_FOV
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPES
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPES
|
||||||
|
|
||||||
class ChunkPanel(QWidget):
|
class ChunkPanel(QWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from dusk.entity import Entity
|
from tools.dusk.entity import Entity
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
||||||
|
|
||||||
class EntityPanel(QWidget):
|
class EntityPanel(QWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
from dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
def __init__(self, lines=1000):
|
def __init__(self, lines=1000):
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout, QMessageBox
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout, QMessageBox
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH
|
||||||
|
|
||||||
class MapInfoPanel(QWidget):
|
class MapInfoPanel(QWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QPushButton, QTabWidget, QLabel
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QPushButton, QTabWidget, QLabel
|
||||||
from editortool.map.chunkpanel import ChunkPanel
|
from tools.editor.map.chunkpanel import ChunkPanel
|
||||||
from editortool.map.entitypanel import EntityPanel
|
from tools.editor.map.entitypanel import EntityPanel
|
||||||
from editortool.map.regionpanel import RegionPanel
|
from tools.editor.map.regionpanel import RegionPanel
|
||||||
|
|
||||||
class MapLeftPanel(QWidget):
|
class MapLeftPanel(QWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from PyQt5.QtWidgets import QAction, QMenuBar, QFileDialog
|
from PyQt5.QtWidgets import QAction, QMenuBar, QFileDialog
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
from dusk.map import MAP_DEFAULT_PATH
|
from tools.dusk.map import MAP_DEFAULT_PATH
|
||||||
|
|
||||||
class MapMenubar:
|
class MapMenubar:
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QComboBox, QHBoxLayout, QPushButton, QLineEdit, QListWidget, QListWidgetItem
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from dusk.entity import Entity
|
from tools.dusk.entity import Entity
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, ENTITY_TYPES, ENTITY_TYPE_NULL
|
||||||
|
|
||||||
class RegionPanel(QWidget):
|
class RegionPanel(QWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import OpenGL.GL as gl
|
import OpenGL.GL as gl
|
||||||
from dusk.defs import defs
|
from tools.dusk.defs import defs
|
||||||
import colorsys
|
import colorsys
|
||||||
from dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
from tools.dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
|
||||||
|
|
||||||
class SelectBox:
|
class SelectBox:
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QMessageBox
|
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QMessageBox
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from editortool.map.glwidget import GLWidget
|
from tools.editor.map.glwidget import GLWidget
|
||||||
from editortool.map.mapleftpanel import MapLeftPanel
|
from tools.editor.map.mapleftpanel import MapLeftPanel
|
||||||
from editortool.map.mapinfopanel import MapInfoPanel
|
from tools.editor.map.mapinfopanel import MapInfoPanel
|
||||||
from editortool.map.menubar import MapMenubar
|
from tools.editor.map.menubar import MapMenubar
|
||||||
from editortool.map.statusbar import StatusBar
|
from tools.editor.map.statusbar import StatusBar
|
||||||
from dusk.map import Map
|
from tools.dusk.map import Map
|
||||||
from dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPE_NULL, TILE_SHAPE_FLOOR
|
from tools.dusk.defs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPE_NULL, TILE_SHAPE_FLOOR
|
||||||
from editortool.map.selectbox import SelectBox
|
from tools.editor.map.selectbox import SelectBox
|
||||||
from editortool.map.camera import Camera
|
from tools.editor.map.camera import Camera
|
||||||
from editortool.map.grid import Grid
|
from tools.editor.map.grid import Grid
|
||||||
|
|
||||||
class MapWindow(QMainWindow):
|
class MapWindow(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_asset(MAP map.json)
|
add_subdirectory(testmap)
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_asset(SCRIPT test.lua)
|
add_asset(MAP testmap.json)
|
||||||
3
archive/map/testmap/testmap.json
Normal file
3
archive/map/testmap/testmap.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"name": "Test"
|
||||||
|
}
|
||||||
49
archive/modulemap.h
Normal file
49
archive/modulemap.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "script/scriptcontext.h"
|
||||||
|
#include "debug/debug.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "rpg/overworld/map.h"
|
||||||
|
|
||||||
|
int moduleMapLoad(lua_State *L) {
|
||||||
|
assertNotNull(L, "Lua state cannot be NULL");
|
||||||
|
|
||||||
|
if(!lua_isstring(L, 1)) {
|
||||||
|
luaL_error(L, "Expected string map filename");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Potentially provide up to 3 params
|
||||||
|
chunkpos_t initial = { .x = 0, .y = 0, .z = 0 };
|
||||||
|
if(lua_isnumber(L, 2)) {
|
||||||
|
initial.x = (chunkunit_t)lua_tonumber(L, 2);
|
||||||
|
}
|
||||||
|
if(lua_isnumber(L, 3)) {
|
||||||
|
initial.y = (chunkunit_t)lua_tonumber(L, 3);
|
||||||
|
}
|
||||||
|
if(lua_isnumber(L, 4)) {
|
||||||
|
initial.z = (chunkunit_t)lua_tonumber(L, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the map.
|
||||||
|
errorret_t ret = mapLoad(luaL_checkstring(L, 1), initial);
|
||||||
|
if(ret.code != ERROR_OK) {
|
||||||
|
luaL_error(L, "Failed to load map");
|
||||||
|
errorCatch(errorPrint(ret));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void moduleMapSystem(scriptcontext_t *context) {
|
||||||
|
assertNotNull(context, "Script context cannot be NULL");
|
||||||
|
|
||||||
|
lua_register(context->luaState, "mapLoad", moduleMapLoad);
|
||||||
|
}
|
||||||
12
archive/platform/CMakeLists.txt
Normal file
12
archive/platform/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2025 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
sdl2.c
|
||||||
|
psp.c
|
||||||
|
dolphin.c
|
||||||
|
)
|
||||||
92
archive/platform/dolphin.c
Normal file
92
archive/platform/dolphin.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dolphin.h"
|
||||||
|
|
||||||
|
void displayInitDolphin(void) {
|
||||||
|
VIDEO_Init();
|
||||||
|
DISPLAY.screenMode = VIDEO_GetPreferredMode(NULL);
|
||||||
|
DISPLAY.frameBuffer[0] = MEM_K0_TO_K1(
|
||||||
|
SYS_AllocateFramebuffer(DISPLAY.screenMode)
|
||||||
|
);
|
||||||
|
DISPLAY.frameBuffer[1] = MEM_K0_TO_K1(
|
||||||
|
SYS_AllocateFramebuffer(DISPLAY.screenMode)
|
||||||
|
);
|
||||||
|
VIDEO_Configure(DISPLAY.screenMode);
|
||||||
|
|
||||||
|
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer]);
|
||||||
|
// VIDEO_SetPostRetraceCallback(copy_buffers);
|
||||||
|
VIDEO_SetBlack(FALSE);
|
||||||
|
VIDEO_Flush();
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||||
|
|
||||||
|
DISPLAY.fifoBuffer = memalign(32, DISPLAY_FIFO_SIZE);
|
||||||
|
memoryZero(DISPLAY.fifoBuffer, DISPLAY_FIFO_SIZE);
|
||||||
|
|
||||||
|
GX_Init(DISPLAY.fifoBuffer, DISPLAY_FIFO_SIZE);
|
||||||
|
|
||||||
|
// This seems to be mostly related to interlacing vs progressive
|
||||||
|
GX_SetViewport(
|
||||||
|
0, 0,
|
||||||
|
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight,
|
||||||
|
0, 1
|
||||||
|
);
|
||||||
|
float_t yscale = GX_GetYScaleFactor(
|
||||||
|
DISPLAY.screenMode->efbHeight, DISPLAY.screenMode->xfbHeight
|
||||||
|
);
|
||||||
|
uint32_t xfbHeight = GX_SetDispCopyYScale(yscale);
|
||||||
|
GX_SetScissor(
|
||||||
|
0, 0,
|
||||||
|
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight
|
||||||
|
);
|
||||||
|
GX_SetDispCopySrc(
|
||||||
|
0, 0,
|
||||||
|
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight
|
||||||
|
);
|
||||||
|
GX_SetDispCopyDst(DISPLAY.screenMode->fbWidth, xfbHeight);
|
||||||
|
GX_SetCopyFilter(
|
||||||
|
DISPLAY.screenMode->aa,
|
||||||
|
DISPLAY.screenMode->sample_pattern,
|
||||||
|
GX_TRUE,
|
||||||
|
DISPLAY.screenMode->vfilter
|
||||||
|
);
|
||||||
|
GX_SetFieldMode(
|
||||||
|
DISPLAY.screenMode->field_rendering,
|
||||||
|
(
|
||||||
|
(DISPLAY.screenMode->viHeight == 2 * DISPLAY.screenMode->xfbHeight) ?
|
||||||
|
GX_ENABLE :
|
||||||
|
GX_DISABLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Setup cull modes
|
||||||
|
GX_SetCullMode(GX_CULL_NONE);
|
||||||
|
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE);
|
||||||
|
GX_CopyDisp(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer], GX_TRUE);
|
||||||
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||||
|
|
||||||
|
GX_ClearVtxDesc();
|
||||||
|
GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
|
||||||
|
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX16);
|
||||||
|
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
|
||||||
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
||||||
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_U8, 0);
|
||||||
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayDolphinSwap(void) {
|
||||||
|
GX_DrawDone();
|
||||||
|
|
||||||
|
DISPLAY.whichFrameBuffer ^= 1;
|
||||||
|
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||||
|
GX_SetColorUpdate(GX_TRUE);
|
||||||
|
GX_CopyDisp(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer], GX_TRUE);
|
||||||
|
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer]);
|
||||||
|
VIDEO_Flush();
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
}
|
||||||
27
archive/platform/dolphin.h
Normal file
27
archive/platform/dolphin.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
#include "display/displaydefs.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *frameBuffer[2];// Double-Bufferred
|
||||||
|
int whichFrameBuffer;
|
||||||
|
GXRModeObj *screenMode;
|
||||||
|
void *fifoBuffer;
|
||||||
|
} displaydolphin_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the display for Dolphin.
|
||||||
|
*/
|
||||||
|
void displayDolphinInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the back buffer to the front for Dolphin.
|
||||||
|
*/
|
||||||
|
void displayDolphinSwap(void);
|
||||||
12
archive/platform/psp.c
Normal file
12
archive/platform/psp.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "psp.h"
|
||||||
|
|
||||||
|
void displayInitPSP(void) {
|
||||||
|
DISPLAY.usingShaderedPalettes = false;
|
||||||
|
}
|
||||||
13
archive/platform/psp.h
Normal file
13
archive/platform/psp.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the display for PSP.
|
||||||
|
*/
|
||||||
|
void displayInitPSP(void);
|
||||||
32
archive/platform/sdl2.c
Normal file
32
archive/platform/sdl2.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdl2.h"
|
||||||
|
|
||||||
|
void displaySDL2Update(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void displaySDL2Swap(void) {
|
||||||
|
SDL_GL_SwapWindow(DISPLAY.window);
|
||||||
|
|
||||||
|
GLenum err;
|
||||||
|
while((err = glGetError()) != GL_NO_ERROR) {
|
||||||
|
debugPrint("GL Error: %d\n", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void displaySDL2Dispose(void) {
|
||||||
|
if(DISPLAY.glContext) {
|
||||||
|
SDL_GL_DeleteContext(DISPLAY.glContext);
|
||||||
|
DISPLAY.glContext = NULL;
|
||||||
|
}
|
||||||
|
if(DISPLAY.window) {
|
||||||
|
SDL_DestroyWindow(DISPLAY.window);
|
||||||
|
DISPLAY.window = NULL;
|
||||||
|
}
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
35
archive/platform/sdl2.h
Normal file
35
archive/platform/sdl2.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SDL_Window *window;
|
||||||
|
SDL_GLContext glContext;
|
||||||
|
bool_t usingShaderedPalettes;
|
||||||
|
} displaysdl2_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the display for SDL2.
|
||||||
|
*/
|
||||||
|
void displaySDL2Init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the display for SDL2.
|
||||||
|
*/
|
||||||
|
void displaySDL2Update(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the display buffers for SDL2.
|
||||||
|
*/
|
||||||
|
void displaySDL2Swap(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of the display for SDL2.
|
||||||
|
*/
|
||||||
|
void displaySDL2Dispose(void);
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PRIVATE
|
PUBLIC
|
||||||
rpg.c
|
rpg.c
|
||||||
rpgcamera.c
|
rpgcamera.c
|
||||||
rpgtextbox.c
|
rpgtextbox.c
|
||||||
@@ -14,4 +14,4 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(cutscene)
|
add_subdirectory(cutscene)
|
||||||
add_subdirectory(entity)
|
add_subdirectory(entity)
|
||||||
add_subdirectory(world)
|
add_subdirectory(overworld)
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PRIVATE
|
PUBLIC
|
||||||
cutscenesystem.c
|
cutscenesystem.c
|
||||||
cutscenemode.c
|
cutscenemode.c
|
||||||
)
|
)
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PRIVATE
|
PUBLIC
|
||||||
cutsceneitem.c
|
cutsceneitem.c
|
||||||
)
|
)
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
#include "cutscenewait.h"
|
#include "cutscenewait.h"
|
||||||
#include "cutscenecallback.h"
|
#include "cutscenecallback.h"
|
||||||
#include "cutscenetext.h"
|
#include "cutscenetext.h"
|
||||||
#include "cutscenecutscene.h"
|
|
||||||
|
typedef struct cutscene_s cutscene_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CUTSCENE_ITEM_TYPE_NULL,
|
CUTSCENE_ITEM_TYPE_NULL,
|
||||||
@@ -27,7 +28,7 @@ typedef struct cutsceneitem_s {
|
|||||||
cutscenetext_t text;
|
cutscenetext_t text;
|
||||||
cutscenecallback_t callback;
|
cutscenecallback_t callback;
|
||||||
cutscenewait_t wait;
|
cutscenewait_t wait;
|
||||||
const cutscenecutscene_t cutscene;
|
const cutscene_t *cutscene;
|
||||||
};
|
};
|
||||||
} cutsceneitem_t;
|
} cutsceneitem_t;
|
||||||
|
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PRIVATE
|
PUBLIC
|
||||||
entity.c
|
entity.c
|
||||||
entityanim.c
|
entityanim.c
|
||||||
npc.c
|
npc.c
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
#include "rpg/cutscene/cutscenemode.h"
|
#include "rpg/cutscene/cutscenemode.h"
|
||||||
#include "rpg/world/map.h"
|
#include "rpg/overworld/map.h"
|
||||||
|
|
||||||
entity_t ENTITIES[ENTITY_COUNT];
|
entity_t ENTITIES[ENTITY_COUNT];
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ typedef struct map_s map_t;
|
|||||||
typedef struct entity_s {
|
typedef struct entity_s {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
entitytype_t type;
|
entitytype_t type;
|
||||||
entitytypedata_t;
|
entitytypedata_t data;
|
||||||
|
|
||||||
// Movement
|
// Movement
|
||||||
entitydir_t direction;
|
entitydir_t direction;
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "rpg/world/worldpos.h"
|
#include "rpg/overworld/worldpos.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENTITY_DIR_UP = ENTITY_DIR_NORTH,
|
ENTITY_DIR_UP = ENTITY_DIR_NORTH,
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
typedef struct cutscene_s cutscene_t;
|
typedef struct {
|
||||||
|
void *nothing;
|
||||||
typedef cutscene_t* cutscenecutscene_t;
|
} inventory_t;
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DUSK_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PRIVATE
|
PUBLIC
|
||||||
chunk.c
|
chunk.c
|
||||||
map.c
|
map.c
|
||||||
worldpos.c
|
worldpos.c
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "rpg/world/tile.h"
|
#include "rpg/overworld/tile.h"
|
||||||
#include "worldpos.h"
|
#include "worldpos.h"
|
||||||
#include "display/mesh/quad.h"
|
#include "display/mesh/quad.h"
|
||||||
|
|
||||||
@@ -10,33 +10,92 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "script/scriptcontext.h"
|
||||||
|
|
||||||
map_t MAP;
|
map_t MAP;
|
||||||
|
|
||||||
errorret_t mapInit() {
|
errorret_t mapInit() {
|
||||||
memoryZero(&MAP, sizeof(map_t));
|
memoryZero(&MAP, sizeof(map_t));
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
// Init the default chunks. In future I'll probably make this based on where
|
bool_t mapIsLoaded() {
|
||||||
// the player spawns in to save an initial mapSet.
|
return MAP.filePath[0] != '\0';
|
||||||
chunkindex_t index = 0;
|
}
|
||||||
|
|
||||||
|
errorret_t mapLoad(const char_t *path, const chunkpos_t position) {
|
||||||
|
assertStrLenMin(path, 1, "Map file path cannot be empty");
|
||||||
|
assertStrLenMax(path, MAP_FILE_PATH_MAX - 1, "Map file path too long");
|
||||||
|
|
||||||
|
if(stringCompare(MAP.filePath, path) == 0) {
|
||||||
|
// Same map, no need to reload
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkindex_t i;
|
||||||
|
|
||||||
|
// Unload all loaded chunks
|
||||||
|
if(mapIsLoaded()) {
|
||||||
|
for(i = 0; i < MAP_CHUNK_COUNT; i++) {
|
||||||
|
mapChunkUnload(&MAP.chunks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the map file path
|
||||||
|
stringCopy(MAP.filePath, path, MAP_FILE_PATH_MAX);
|
||||||
|
|
||||||
|
// Determine directory path (it is dirname)
|
||||||
|
stringCopy(MAP.dirPath, path, MAP_FILE_PATH_MAX);
|
||||||
|
char_t *last = stringFindLastChar(MAP.dirPath, '/');
|
||||||
|
if(last == NULL) errorThrow("Invalid map file path");
|
||||||
|
|
||||||
|
// Store filename, sans extension
|
||||||
|
stringCopy(MAP.fileName, last + 1, MAP_FILE_PATH_MAX);
|
||||||
|
*last = '\0'; // Terminate to get directory path
|
||||||
|
|
||||||
|
last = stringFindLastChar(MAP.fileName, '.');
|
||||||
|
if(last == NULL) errorThrow("Map file name has no extension");
|
||||||
|
*last = '\0'; // Terminate to remove extension
|
||||||
|
|
||||||
|
// Reset map position
|
||||||
|
MAP.chunkPosition = position;
|
||||||
|
|
||||||
|
// Perform "initial load"
|
||||||
|
i = 0;
|
||||||
for(chunkunit_t z = 0; z < MAP_CHUNK_DEPTH; z++) {
|
for(chunkunit_t z = 0; z < MAP_CHUNK_DEPTH; z++) {
|
||||||
for(chunkunit_t y = 0; y < MAP_CHUNK_HEIGHT; y++) {
|
for(chunkunit_t y = 0; y < MAP_CHUNK_HEIGHT; y++) {
|
||||||
for(chunkunit_t x = 0; x < MAP_CHUNK_WIDTH; x++) {
|
for(chunkunit_t x = 0; x < MAP_CHUNK_WIDTH; x++) {
|
||||||
chunk_t *chunk = &MAP.chunks[index];
|
chunk_t *chunk = &MAP.chunks[i];
|
||||||
chunk->position.x = x;
|
chunk->position.x = x + position.x;
|
||||||
chunk->position.y = y;
|
chunk->position.y = y + position.y;
|
||||||
chunk->position.z = z;
|
chunk->position.z = z + position.z;
|
||||||
MAP.chunkOrder[index] = chunk;
|
MAP.chunkOrder[i] = chunk;
|
||||||
errorChain(mapChunkLoad(chunk));
|
errorChain(mapChunkLoad(chunk));
|
||||||
index++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute map script.
|
||||||
|
char_t scriptPath[MAP_FILE_PATH_MAX + 16];
|
||||||
|
stringFormat(
|
||||||
|
scriptPath, sizeof(scriptPath), "%s/%s.dsf",
|
||||||
|
MAP.dirPath, MAP.fileName
|
||||||
|
);
|
||||||
|
if(assetFileExists(scriptPath)) {
|
||||||
|
scriptcontext_t ctx;
|
||||||
|
errorChain(scriptContextInit(&ctx));
|
||||||
|
errorChain(scriptContextExecFile(&ctx, scriptPath));
|
||||||
|
scriptContextDispose(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t mapPositionSet(const chunkpos_t newPos) {
|
errorret_t mapPositionSet(const chunkpos_t newPos) {
|
||||||
|
if(!mapIsLoaded()) errorThrow("No map loaded");
|
||||||
|
|
||||||
const chunkpos_t curPos = MAP.chunkPosition;
|
const chunkpos_t curPos = MAP.chunkPosition;
|
||||||
if(chunkPositionIsEqual(curPos, newPos)) {
|
if(chunkPositionIsEqual(curPos, newPos)) {
|
||||||
errorOk();
|
errorOk();
|
||||||
@@ -132,6 +191,7 @@ void mapChunkUnload(chunk_t* chunk) {
|
|||||||
entity_t *entity = &ENTITIES[chunk->entities[i]];
|
entity_t *entity = &ENTITIES[chunk->entities[i]];
|
||||||
entity->type = ENTITY_TYPE_NULL;
|
entity->type = ENTITY_TYPE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint8_t i = 0; i < chunk->meshCount; i++) {
|
for(uint8_t i = 0; i < chunk->meshCount; i++) {
|
||||||
if(chunk->meshes[i].vertexCount == 0) continue;
|
if(chunk->meshes[i].vertexCount == 0) continue;
|
||||||
meshDispose(&chunk->meshes[i]);
|
meshDispose(&chunk->meshes[i]);
|
||||||
@@ -139,28 +199,37 @@ void mapChunkUnload(chunk_t* chunk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorret_t mapChunkLoad(chunk_t* chunk) {
|
errorret_t mapChunkLoad(chunk_t* chunk) {
|
||||||
|
if(!mapIsLoaded()) errorThrow("No map loaded");
|
||||||
|
|
||||||
char_t buffer[64];
|
char_t buffer[64];
|
||||||
|
|
||||||
|
// TODO: Can probably move this to asset load logic?
|
||||||
chunk->meshCount = 0;
|
chunk->meshCount = 0;
|
||||||
memoryZero(chunk->meshes, sizeof(chunk->meshes));
|
memoryZero(chunk->meshes, sizeof(chunk->meshes));
|
||||||
memorySet(chunk->entities, 0xFF, sizeof(chunk->entities));
|
memorySet(chunk->entities, 0xFF, sizeof(chunk->entities));
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "map/map/%d_%d_%d.dcf",
|
// Get chunk filepath.
|
||||||
|
snprintf(buffer, sizeof(buffer), "%s/chunks/%d_%d_%d.dmc",
|
||||||
|
MAP.dirPath,
|
||||||
chunk->position.x,
|
chunk->position.x,
|
||||||
chunk->position.y,
|
chunk->position.y,
|
||||||
chunk->position.z
|
chunk->position.z
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Chunk available?
|
||||||
if(!assetFileExists(buffer)) {
|
if(!assetFileExists(buffer)) {
|
||||||
memoryZero(chunk->tiles, sizeof(chunk->tiles));
|
memoryZero(chunk->tiles, sizeof(chunk->tiles));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load.
|
||||||
errorChain(assetLoad(buffer, chunk));
|
errorChain(assetLoad(buffer, chunk));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
||||||
|
if(!mapIsLoaded()) return -1;
|
||||||
|
|
||||||
chunkpos_t relPos = {
|
chunkpos_t relPos = {
|
||||||
position.x - MAP.chunkPosition.x,
|
position.x - MAP.chunkPosition.x,
|
||||||
position.y - MAP.chunkPosition.y,
|
position.y - MAP.chunkPosition.y,
|
||||||
@@ -181,10 +250,13 @@ chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
|||||||
|
|
||||||
chunk_t* mapGetChunk(const uint8_t index) {
|
chunk_t* mapGetChunk(const uint8_t index) {
|
||||||
if(index >= MAP_CHUNK_COUNT) return NULL;
|
if(index >= MAP_CHUNK_COUNT) return NULL;
|
||||||
|
if(!mapIsLoaded()) return NULL;
|
||||||
return MAP.chunkOrder[index];
|
return MAP.chunkOrder[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_t mapGetTile(const worldpos_t position) {
|
tile_t mapGetTile(const worldpos_t position) {
|
||||||
|
if(!mapIsLoaded()) return TILE_SHAPE_NULL;
|
||||||
|
|
||||||
chunkpos_t chunkPos;
|
chunkpos_t chunkPos;
|
||||||
worldPosToChunkPos(&position, &chunkPos);
|
worldPosToChunkPos(&position, &chunkPos);
|
||||||
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
|
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
|
||||||
@@ -6,9 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "rpg/world/chunk.h"
|
#include "rpg/overworld/chunk.h"
|
||||||
|
|
||||||
|
#define MAP_FILE_PATH_MAX 128
|
||||||
|
|
||||||
typedef struct map_s {
|
typedef struct map_s {
|
||||||
|
char_t filePath[MAP_FILE_PATH_MAX];
|
||||||
|
char_t dirPath[MAP_FILE_PATH_MAX];
|
||||||
|
char_t fileName[MAP_FILE_PATH_MAX];
|
||||||
|
|
||||||
chunk_t chunks[MAP_CHUNK_COUNT];
|
chunk_t chunks[MAP_CHUNK_COUNT];
|
||||||
chunk_t *chunkOrder[MAP_CHUNK_COUNT];
|
chunk_t *chunkOrder[MAP_CHUNK_COUNT];
|
||||||
chunkpos_t chunkPosition;
|
chunkpos_t chunkPosition;
|
||||||
@@ -23,6 +29,25 @@ extern map_t MAP;
|
|||||||
*/
|
*/
|
||||||
errorret_t mapInit();
|
errorret_t mapInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a map is loaded.
|
||||||
|
*
|
||||||
|
* @return true if a map is loaded, false otherwise.
|
||||||
|
*/
|
||||||
|
bool_t mapIsLoaded();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a map from the given file path.
|
||||||
|
*
|
||||||
|
* @param path The file path.
|
||||||
|
* @param position The initial chunk position.
|
||||||
|
* @return An error code.
|
||||||
|
*/
|
||||||
|
errorret_t mapLoad(
|
||||||
|
const char_t *path,
|
||||||
|
const chunkpos_t position
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the map.
|
* Updates the map.
|
||||||
*/
|
*/
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user