Compare commits
49 Commits
1d7516982a
...
editor
| Author | SHA1 | Date | |
|---|---|---|---|
| 888918face | |||
| 0885da8d44 | |||
| 8af961c6d3 | |||
| ef5febdde3 | |||
| 6d7fbd3926 | |||
| 2680d373d8 | |||
| 2b2ddb3cf2 | |||
| 85ff95296b | |||
| 314a2de41a | |||
| 26fafab47a | |||
| e56ff20e2d | |||
| 55d44f229d | |||
| 1c5e50cc4d | |||
| ea898da6c2 | |||
| dbb7e9f53c | |||
| 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 |
36
.github/workflows/build.yml
vendored
36
.github/workflows/build.yml
vendored
@@ -1,5 +1,4 @@
|
|||||||
name: Build Dusk
|
name: Build Dusk
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@@ -7,13 +6,12 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
run-tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
- name: Set up Docker
|
- name: Set up Docker
|
||||||
uses: docker/setup-docker-action@v5
|
uses: docker/setup-docker-action@v5
|
||||||
- name: Run tests in Docker
|
- name: Run tests in Docker
|
||||||
@@ -23,7 +21,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
- name: Set up Docker
|
- name: Set up Docker
|
||||||
uses: docker/setup-docker-action@v5
|
uses: docker/setup-docker-action@v5
|
||||||
- name: Build Linux
|
- name: Build Linux
|
||||||
@@ -39,7 +37,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
- name: Set up Docker
|
- name: Set up Docker
|
||||||
uses: docker/setup-docker-action@v5
|
uses: docker/setup-docker-action@v5
|
||||||
- name: Build psp
|
- name: Build psp
|
||||||
@@ -55,11 +53,31 @@ jobs:
|
|||||||
path: ./git-artifcats/Dusk
|
path: ./git-artifcats/Dusk
|
||||||
if-no-files-found: error
|
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:
|
build-gamecube:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
- name: Set up Docker
|
- name: Set up Docker
|
||||||
uses: docker/setup-docker-action@v5
|
uses: docker/setup-docker-action@v5
|
||||||
- name: Build GameCube
|
- name: Build GameCube
|
||||||
@@ -74,12 +92,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: dusk-gamecube
|
name: dusk-gamecube
|
||||||
path: ./git-artifcats/Dusk
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
build-wii:
|
build-wii:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
- name: Set up Docker
|
- name: Set up Docker
|
||||||
uses: docker/setup-docker-action@v5
|
uses: docker/setup-docker-action@v5
|
||||||
- name: Build Wii
|
- name: Build Wii
|
||||||
@@ -87,7 +106,7 @@ jobs:
|
|||||||
- name: Copy output files.
|
- name: Copy output files.
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||||
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/Dusk.dol
|
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
|
||||||
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||||
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||||
- name: Upload Wii binary
|
- name: Upload Wii binary
|
||||||
@@ -95,3 +114,4 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: dusk-wii
|
name: dusk-wii
|
||||||
path: ./git-artifcats/Dusk
|
path: ./git-artifcats/Dusk
|
||||||
|
if-no-files-found: error
|
||||||
@@ -30,7 +30,7 @@ elseif DOLPHIN 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)
|
||||||
|
|
||||||
else
|
elseif LINUX then
|
||||||
if INPUT_KEYBOARD then
|
if INPUT_KEYBOARD then
|
||||||
inputBind("w", INPUT_ACTION_UP)
|
inputBind("w", INPUT_ACTION_UP)
|
||||||
inputBind("s", INPUT_ACTION_DOWN)
|
inputBind("s", INPUT_ACTION_DOWN)
|
||||||
@@ -70,6 +70,9 @@ else
|
|||||||
inputBind("mouse_x", INPUT_ACTION_POINTERX)
|
inputBind("mouse_x", INPUT_ACTION_POINTERX)
|
||||||
inputBind("mouse_y", INPUT_ACTION_POINTERY)
|
inputBind("mouse_y", INPUT_ACTION_POINTERY)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
print("Unknown platform, no default input bindings set.")
|
||||||
end
|
end
|
||||||
|
|
||||||
sceneSet('scene/minesweeper.lua')
|
sceneSet('scene/minesweeper.lua')
|
||||||
@@ -9,6 +9,7 @@ module('text')
|
|||||||
module('tileset')
|
module('tileset')
|
||||||
module('texture')
|
module('texture')
|
||||||
module('input')
|
module('input')
|
||||||
|
module('shader')
|
||||||
|
|
||||||
CELL_STATE_DEFAULT = 0
|
CELL_STATE_DEFAULT = 0
|
||||||
CELL_STATE_HOVER = 1
|
CELL_STATE_HOVER = 1
|
||||||
@@ -62,7 +63,7 @@ function cellDraw(x, y, type)
|
|||||||
slice = cellSliceDisabled
|
slice = cellSliceDisabled
|
||||||
end
|
end
|
||||||
|
|
||||||
spriteBatchPush(textureCell,
|
spriteBatchPush(
|
||||||
x, y,
|
x, y,
|
||||||
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||||
colorWhite(),
|
colorWhite(),
|
||||||
@@ -178,36 +179,32 @@ function sceneDispose()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function sceneUpdate()
|
function sceneUpdate()
|
||||||
if inputIsDown(INPUT_ACTION_RIGHT) then
|
x = x + inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
|
||||||
x = x + 1
|
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
|
||||||
end
|
end
|
||||||
|
|
||||||
if inputIsDown(INPUT_ACTION_LEFT) then
|
|
||||||
x = x - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if inputIsDown(INPUT_ACTION_DOWN) then
|
|
||||||
print("down")
|
|
||||||
y = y + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if inputIsDown(INPUT_ACTION_UP) then
|
|
||||||
y = y - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function sceneRender()
|
function sceneRender()
|
||||||
-- Update camera
|
-- Update camera
|
||||||
cameraPushMatrix(camera)
|
camera.bottom = 0
|
||||||
camera.bottom = screenGetHeight()
|
camera.top = screenGetHeight()
|
||||||
camera.right = screenGetWidth()
|
camera.right = screenGetWidth()
|
||||||
|
|
||||||
|
shaderBind(SHADER_UNLIT)
|
||||||
|
proj = cameraGetProjectionMatrix(camera)
|
||||||
|
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)
|
||||||
|
view = cameraGetViewMatrix(camera)
|
||||||
|
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view)
|
||||||
|
|
||||||
|
shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil)
|
||||||
spriteBatchPush(
|
spriteBatchPush(
|
||||||
nil,
|
x, y,
|
||||||
x, y, x + 32, y + 32,
|
x + 32, y + 32,
|
||||||
colorBlue()
|
colorWhite()
|
||||||
)
|
)
|
||||||
|
spriteBatchFlush()
|
||||||
|
|
||||||
|
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||||
|
spriteBatchFlush()
|
||||||
|
|
||||||
-- Update mouse position
|
-- Update mouse position
|
||||||
-- if INPUT_POINTER then
|
-- if INPUT_POINTER then
|
||||||
@@ -264,7 +261,4 @@ function sceneRender()
|
|||||||
-- )
|
-- )
|
||||||
-- end
|
-- end
|
||||||
-- end
|
-- end
|
||||||
spriteBatchFlush()
|
|
||||||
|
|
||||||
cameraPopMatrix()
|
|
||||||
end
|
end
|
||||||
Binary file not shown.
Binary file not shown.
BIN
assets/ui/minogram.dtx
Normal file
BIN
assets/ui/minogram.dtx
Normal file
Binary file not shown.
45
cmake/targets/knulli.cmake
Normal file
45
cmake/targets/knulli.cmake
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# Find link platform-specific libraries
|
||||||
|
set(OpenGL_GL_PREFERENCE LEGACY)
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
find_library(EGL_LIB EGL REQUIRED)
|
||||||
|
find_library(GL_LIB GL REQUIRED)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
# Setup endianess at compile time to optimize.
|
||||||
|
include(TestBigEndian)
|
||||||
|
test_big_endian(IS_BIG_ENDIAN)
|
||||||
|
if(IS_BIG_ENDIAN)
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
DUSK_PLATFORM_ENDIAN_BIG
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Link required libraries.
|
||||||
|
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||||
|
SDL2
|
||||||
|
pthread
|
||||||
|
OpenGL::GLES2
|
||||||
|
${GL_LIB}
|
||||||
|
${EGL_LIB}
|
||||||
|
m
|
||||||
|
)
|
||||||
|
|
||||||
|
# Define platform-specific macros.
|
||||||
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
|
DUSK_SDL2
|
||||||
|
DUSK_OPENGL
|
||||||
|
DUSK_OPENGL_ES
|
||||||
|
DUSK_LINUX
|
||||||
|
DUSK_DISPLAY_SIZE_DYNAMIC
|
||||||
|
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
||||||
|
DUSK_DISPLAY_HEIGHT_DEFAULT=480
|
||||||
|
DUSK_DISPLAY_SCREEN_HEIGHT=240
|
||||||
|
DUSK_INPUT_KEYBOARD
|
||||||
|
DUSK_INPUT_POINTER
|
||||||
|
DUSK_INPUT_GAMEPAD
|
||||||
|
DUSK_TIME_DYNAMIC
|
||||||
|
)
|
||||||
@@ -28,6 +28,7 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|||||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||||
DUSK_SDL2
|
DUSK_SDL2
|
||||||
DUSK_OPENGL
|
DUSK_OPENGL
|
||||||
|
# DUSK_OPENGL_LEGACY
|
||||||
DUSK_LINUX
|
DUSK_LINUX
|
||||||
DUSK_DISPLAY_SIZE_DYNAMIC
|
DUSK_DISPLAY_SIZE_DYNAMIC
|
||||||
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
|||||||
DUSK_PSP
|
DUSK_PSP
|
||||||
DUSK_INPUT_GAMEPAD
|
DUSK_INPUT_GAMEPAD
|
||||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||||
|
DUSK_OPENGL_LEGACY
|
||||||
DUSK_DISPLAY_WIDTH=480
|
DUSK_DISPLAY_WIDTH=480
|
||||||
DUSK_DISPLAY_HEIGHT=272
|
DUSK_DISPLAY_HEIGHT=272
|
||||||
)
|
)
|
||||||
|
|||||||
29
cmake/toolchains/aarch64-linux-gnu.cmake
Normal file
29
cmake/toolchains/aarch64-linux-gnu.cmake
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
|
||||||
|
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-gcc)
|
||||||
|
|
||||||
|
set(CMAKE_SYSROOT /)
|
||||||
|
set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu)
|
||||||
|
set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu)
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH
|
||||||
|
/usr/aarch64-linux-gnu
|
||||||
|
/usr/lib/aarch64-linux-gnu
|
||||||
|
/usr/include/aarch64-linux-gnu
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
|
|
||||||
|
set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig")
|
||||||
|
set(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig")
|
||||||
|
|
||||||
|
set(CMAKE_PREFIX_PATH "/usr/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu")
|
||||||
|
|
||||||
|
# Optional: helps some Find modules
|
||||||
|
set(SDL2_DIR "/usr/lib/aarch64-linux-gnu/cmake/SDL2" CACHE PATH "")
|
||||||
35
docker/knulli/Dockerfile
Normal file
35
docker/knulli/Dockerfile
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
FROM debian:trixie
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
WORKDIR /workdir
|
||||||
|
RUN dpkg --add-architecture arm64 && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
crossbuild-essential-arm64 \
|
||||||
|
ca-certificates \
|
||||||
|
pkg-config \
|
||||||
|
cmake \
|
||||||
|
make \
|
||||||
|
ninja-build \
|
||||||
|
git \
|
||||||
|
file \
|
||||||
|
python3 \
|
||||||
|
python3-pip \
|
||||||
|
python3-polib \
|
||||||
|
python3-pil \
|
||||||
|
python3-dotenv \
|
||||||
|
python3-pyqt5 \
|
||||||
|
python3-opengl \
|
||||||
|
liblua5.4-dev:arm64 \
|
||||||
|
xz-utils:arm64 \
|
||||||
|
libbz2-dev:arm64 \
|
||||||
|
zlib1g-dev:arm64 \
|
||||||
|
libzip-dev:arm64 \
|
||||||
|
libssl-dev:arm64 \
|
||||||
|
libsdl2-dev:arm64 \
|
||||||
|
liblzma-dev:arm64 \
|
||||||
|
libopengl0:arm64 \
|
||||||
|
libgl1:arm64 \
|
||||||
|
libegl1:arm64 \
|
||||||
|
libgles2:arm64 \
|
||||||
|
libgl1-mesa-dev:arm64 && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
41
editor/.gitignore
vendored
Normal file
41
editor/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.*
|
||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/versions
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# env files (can opt-in for committing if needed)
|
||||||
|
.env*
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
8
editor/next.config.ts
Normal file
8
editor/next.config.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
/* config options here */
|
||||||
|
reactCompiler: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
23
editor/package.json
Normal file
23
editor/package.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "dusk-editor",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"start:dev": "next dev",
|
||||||
|
"build:prod": "next build",
|
||||||
|
"start:prod": "next start"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"next": "16.2.1",
|
||||||
|
"react": "19.2.4",
|
||||||
|
"react-dom": "19.2.4",
|
||||||
|
"sass": "^1.98.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^19",
|
||||||
|
"@types/react-dom": "^19",
|
||||||
|
"babel-plugin-react-compiler": "1.0.0",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
editor/src/app/layout.tsx
Normal file
23
editor/src/app/layout.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import "@/styles/styles.scss";
|
||||||
|
import Navbar from "@/components/Navbar/Navbar";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Dusk Editor",
|
||||||
|
description: "Editor for the Dusk Game Engine",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<Navbar />
|
||||||
|
{children}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
9
editor/src/app/page.tsx
Normal file
9
editor/src/app/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Link href="/texture-creator">Go to Texture Creator</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
17
editor/src/app/texture-creator/page.tsx
Normal file
17
editor/src/app/texture-creator/page.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
'use client';
|
||||||
|
import React, { createContext, useContext, useState } from "react";
|
||||||
|
|
||||||
|
type TexturePageContextType = {
|
||||||
|
};
|
||||||
|
|
||||||
|
const TexturePageContext = createContext<TexturePageContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
const TextureCreatorPage: React.FC<{ children: React.ReactNode }> = (props) => {
|
||||||
|
return (
|
||||||
|
<TexturePageContext.Provider value={{ }}>
|
||||||
|
<Typography</Typography>
|
||||||
|
</TexturePageContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextureCreatorPage;
|
||||||
12
editor/src/components/Navbar/Navbar.tsx
Normal file
12
editor/src/components/Navbar/Navbar.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import * as styles from './Navbar.module.scss';
|
||||||
|
|
||||||
|
const Navbar:React.FC<{}> = (props) => {
|
||||||
|
return (
|
||||||
|
<nav className={styles.navbar}>
|
||||||
|
navbar
|
||||||
|
</nav>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Navbar;
|
||||||
14
editor/src/objects/Typography/Typography.tsx
Normal file
14
editor/src/objects/Typography/Typography.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
const Typography:React.FC<{
|
||||||
|
element?:string|React.JSXElementConstructor<any>;
|
||||||
|
}> = (props) => {
|
||||||
|
const Element = props.element || 'p';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Element>
|
||||||
|
{props.children}
|
||||||
|
</Element>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Typography;
|
||||||
17
editor/src/pages/TextureCreator/TextureCreator.tsx
Normal file
17
editor/src/pages/TextureCreator/TextureCreator.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
import React, { createContext, useContext, useState } from "react";
|
||||||
|
|
||||||
|
type TextureContextType = {
|
||||||
|
};
|
||||||
|
|
||||||
|
const TextureContext = createContext<TextureContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
const TextureCreator: React.FC<{ children: React.ReactNode }> = (props) => {
|
||||||
|
return (
|
||||||
|
<TextureContext.Provider value={{ }}>
|
||||||
|
{props.children}
|
||||||
|
</TextureContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextureCreator;
|
||||||
4
editor/src/styles/elements/a.scss
Normal file
4
editor/src/styles/elements/a.scss
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
3
editor/src/styles/elements/all.scss
Normal file
3
editor/src/styles/elements/all.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
8
editor/src/styles/elements/body.scss
Normal file
8
editor/src/styles/elements/body.scss
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
max-width: 100vw;
|
||||||
|
overflow-x: hidden;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
6
editor/src/styles/elements/html.scss
Normal file
6
editor/src/styles/elements/html.scss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
max-width: 100vw;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
3
editor/src/styles/elements/root.scss
Normal file
3
editor/src/styles/elements/root.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
:root {
|
||||||
|
|
||||||
|
}
|
||||||
12
editor/src/styles/styles.scss
Normal file
12
editor/src/styles/styles.scss
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Elements
|
||||||
|
@use './elements/root.scss';
|
||||||
|
@use './elements/all.scss';
|
||||||
|
@use './elements/a.scss';
|
||||||
|
@use './elements/html.scss';
|
||||||
|
@use './elements/body.scss';
|
||||||
|
|
||||||
|
// Objects
|
||||||
|
|
||||||
|
// Components
|
||||||
|
|
||||||
|
// Utilities
|
||||||
34
editor/tsconfig.json
Normal file
34
editor/tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
".next/types/**/*.ts",
|
||||||
|
".next/dev/types/**/*.ts",
|
||||||
|
"**/*.mts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
3
scripts/build-knulli-docker.sh
Executable file
3
scripts/build-knulli-docker.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t dusk-knulli -f docker/knulli/Dockerfile .
|
||||||
|
docker run --rm -v $(pwd):/workdir dusk-knulli /bin/bash -c "./scripts/build-knulli.sh"
|
||||||
24
scripts/build-knulli.sh
Executable file
24
scripts/build-knulli.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cmake -S . -B build-knulli -G Ninja \
|
||||||
|
-DDUSK_BUILD_TESTS=ON \
|
||||||
|
-DDUSK_TARGET_SYSTEM=knulli \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/aarch64-linux-gnu.cmake \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build build-knulli -- -j$(nproc)
|
||||||
|
|
||||||
|
# Copy necessary libs out
|
||||||
|
mkdir -p ./build-knulli/dusk
|
||||||
|
cp ./build-knulli/Dusk ./build-knulli/dusk/Dusk
|
||||||
|
cp ./build-knulli/dusk.dsk ./build-knulli/dusk/dusk.dsk
|
||||||
|
echo '#!/bin/bash' > build-knulli/dusk/Dusk.sh
|
||||||
|
echo 'cd "$(dirname "$(readlink -f "$0")")"' >> build-knulli/dusk/Dusk.sh
|
||||||
|
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(dirname "$(readlink -f "$0")")' >> build-knulli/dusk/Dusk.sh
|
||||||
|
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/gl4es' >> build-knulli/dusk/Dusk.sh
|
||||||
|
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib' >> build-knulli/dusk/Dusk.sh
|
||||||
|
echo '$(dirname "$(readlink -f "$0")")/Dusk' >> build-knulli/dusk/Dusk.sh
|
||||||
|
chmod +x build-knulli/dusk/Dusk.sh
|
||||||
|
cp /usr/lib/aarch64-linux-gnu/liblua5.4.so.0 build-knulli/dusk/
|
||||||
|
# cp /usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0 build-knulli/dusk/
|
||||||
|
# cp /usr/lib/aarch64-linux-gnu/libGL.so.1 build-knulli/dusk/
|
||||||
|
# cp /usr/lib/aarch64-linux-gnu/libEGL.so.1 build-knulli/dusk/
|
||||||
|
# cp /usr/lib/aarch64-linux-gnu/libGLESv2.so.2 build-knulli/dusk/
|
||||||
@@ -4,8 +4,9 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_subdirectory(dusk)
|
add_subdirectory(dusk)
|
||||||
|
add_subdirectory(duskrpg)
|
||||||
|
|
||||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||||
add_subdirectory(dusklinux)
|
add_subdirectory(dusklinux)
|
||||||
add_subdirectory(dusksdl2)
|
add_subdirectory(dusksdl2)
|
||||||
add_subdirectory(duskgl)
|
add_subdirectory(duskgl)
|
||||||
|
|||||||
@@ -40,24 +40,18 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
|||||||
main.c
|
main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Defs
|
|
||||||
dusk_env_to_h(duskdefs.env duskdefs.h)
|
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(assert)
|
add_subdirectory(assert)
|
||||||
add_subdirectory(asset)
|
add_subdirectory(asset)
|
||||||
add_subdirectory(debug)
|
add_subdirectory(log)
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
add_subdirectory(error)
|
add_subdirectory(error)
|
||||||
add_subdirectory(event)
|
add_subdirectory(event)
|
||||||
add_subdirectory(input)
|
add_subdirectory(input)
|
||||||
add_subdirectory(item)
|
|
||||||
add_subdirectory(locale)
|
add_subdirectory(locale)
|
||||||
add_subdirectory(map)
|
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
add_subdirectory(script)
|
add_subdirectory(script)
|
||||||
add_subdirectory(story)
|
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "debug/debug.h"
|
#include "log/log.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
#ifndef DUSK_ASSERTIONS_FAKED
|
#ifndef DUSK_ASSERTIONS_FAKED
|
||||||
#ifdef DUSK_TEST_ASSERT
|
#ifdef DUSK_TEST_ASSERT
|
||||||
@@ -31,14 +32,12 @@
|
|||||||
const char *message
|
const char *message
|
||||||
) {
|
) {
|
||||||
if(x != true) {
|
if(x != true) {
|
||||||
debugPrint(
|
logError(
|
||||||
"Assertion Failed in %s:%i\n\n%s\n",
|
"Assertion Failed in %s:%i\n\n%s\n",
|
||||||
file,
|
file,
|
||||||
line,
|
line,
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
debugFlush();
|
|
||||||
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,4 +99,14 @@
|
|||||||
) {
|
) {
|
||||||
assertUnreachableImpl(file, line, message);
|
assertUnreachableImpl(file, line, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void assertStringEqualImpl(
|
||||||
|
const char *file,
|
||||||
|
const int32_t line,
|
||||||
|
const char *a,
|
||||||
|
const char *b,
|
||||||
|
const char *message
|
||||||
|
) {
|
||||||
|
assertTrueImpl(file, line, stringCompare(a, b) == 0, message);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -104,6 +104,23 @@
|
|||||||
const char *message
|
const char *message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts two strings to be equal.
|
||||||
|
*
|
||||||
|
* @param file File that the assertion is being made from.
|
||||||
|
* @param line Line that the assertion is being made from.
|
||||||
|
* @param a First string to compare.
|
||||||
|
* @param b Second string to compare.
|
||||||
|
* @param message Message to throw against assertion failure.
|
||||||
|
*/
|
||||||
|
void assertStringEqualImpl(
|
||||||
|
const char *file,
|
||||||
|
const int32_t line,
|
||||||
|
const char *a,
|
||||||
|
const char *b,
|
||||||
|
const char *message
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts a given value to be true.
|
* Asserts a given value to be true.
|
||||||
*
|
*
|
||||||
@@ -178,6 +195,16 @@
|
|||||||
#define assertStrLenMin(str, len, message) \
|
#define assertStrLenMin(str, len, message) \
|
||||||
assertTrue(strlen(str) >= len, message)
|
assertTrue(strlen(str) >= len, message)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts two strings to be equal.
|
||||||
|
*
|
||||||
|
* @param a First string to compare.
|
||||||
|
* @param b Second string to compare.
|
||||||
|
* @param message Message to throw against assertion failure.
|
||||||
|
*/
|
||||||
|
#define assertStringEqual(a, b, message) \
|
||||||
|
assertStringEqualImpl(__FILE__, __LINE__, a, b, message)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// If assertions are faked, we define the macros to do nothing.
|
// If assertions are faked, we define the macros to do nothing.
|
||||||
#define assertTrue(x, message) ((void)0)
|
#define assertTrue(x, message) ((void)0)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "asset/assettype.h"
|
#include "asset/assettype.h"
|
||||||
#include "engine/engine.h"
|
#include "engine/engine.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
asset_t ASSET;
|
asset_t ASSET;
|
||||||
|
|||||||
@@ -19,12 +19,9 @@ typedef enum {
|
|||||||
ASSET_TYPE_NULL,
|
ASSET_TYPE_NULL,
|
||||||
|
|
||||||
ASSET_TYPE_TEXTURE,
|
ASSET_TYPE_TEXTURE,
|
||||||
// ASSET_TYPE_PALETTE,
|
|
||||||
ASSET_TYPE_TILESET,
|
ASSET_TYPE_TILESET,
|
||||||
ASSET_TYPE_LANGUAGE,
|
ASSET_TYPE_LANGUAGE,
|
||||||
ASSET_TYPE_SCRIPT,
|
ASSET_TYPE_SCRIPT,
|
||||||
ASSET_TYPE_MAP,
|
|
||||||
ASSET_TYPE_MAP_CHUNK,
|
|
||||||
|
|
||||||
ASSET_TYPE_COUNT,
|
ASSET_TYPE_COUNT,
|
||||||
} assettype_t;
|
} assettype_t;
|
||||||
@@ -60,21 +57,14 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[ASSET_TYPE_TEXTURE] = {
|
[ASSET_TYPE_TEXTURE] = {
|
||||||
.extension = "dpt",
|
.extension = "DTX",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assettexture_t),
|
.dataSize = sizeof(assettexture_t),
|
||||||
.entire = assetTextureLoad
|
.entire = assetTextureLoad
|
||||||
},
|
},
|
||||||
|
|
||||||
// [ASSET_TYPE_PALETTE] = {
|
|
||||||
// .extension = "dpf",
|
|
||||||
// .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
|
||||||
// .dataSize = sizeof(palette_t),
|
|
||||||
// .entire = assetPaletteLoad
|
|
||||||
// },
|
|
||||||
|
|
||||||
[ASSET_TYPE_TILESET] = {
|
[ASSET_TYPE_TILESET] = {
|
||||||
.extension = "dtf",
|
.extension = "DTF",
|
||||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||||
.dataSize = sizeof(assettileset_t),
|
.dataSize = sizeof(assettileset_t),
|
||||||
.entire = assetTilesetLoad
|
.entire = assetTilesetLoad
|
||||||
@@ -91,16 +81,4 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
|||||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||||
.custom = assetScriptHandler
|
.custom = assetScriptHandler
|
||||||
},
|
},
|
||||||
|
|
||||||
// [ASSET_TYPE_MAP] = {
|
|
||||||
// .extension = "DMF",
|
|
||||||
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
|
||||||
// .custom = assetMapHandler
|
|
||||||
// },
|
|
||||||
|
|
||||||
// [ASSET_TYPE_MAP_CHUNK] = {
|
|
||||||
// .extension = "DMC",
|
|
||||||
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
|
||||||
// .custom = assetMapChunkHandler
|
|
||||||
// },
|
|
||||||
};
|
};
|
||||||
@@ -21,8 +21,8 @@ errorret_t assetTextureLoad(assetentire_t entire) {
|
|||||||
// Read header and version (first 4 bytes)
|
// Read header and version (first 4 bytes)
|
||||||
if(
|
if(
|
||||||
assetData->header[0] != 'D' ||
|
assetData->header[0] != 'D' ||
|
||||||
assetData->header[1] != 'P' ||
|
assetData->header[1] != 'T' ||
|
||||||
assetData->header[2] != 'T'
|
assetData->header[2] != 'X'
|
||||||
) {
|
) {
|
||||||
errorThrow("Invalid texture header");
|
errorThrow("Invalid texture header");
|
||||||
}
|
}
|
||||||
@@ -44,15 +44,35 @@ errorret_t assetTextureLoad(assetentire_t entire) {
|
|||||||
errorThrow("Invalid texture dimensions");
|
errorThrow("Invalid texture dimensions");
|
||||||
}
|
}
|
||||||
|
|
||||||
textureInit(
|
// Validate format
|
||||||
texture,
|
textureformat_t format;
|
||||||
assetData->width,
|
texturedata_t data;
|
||||||
assetData->height,
|
|
||||||
TEXTURE_FORMAT_PALETTE,
|
switch(assetData->type) {
|
||||||
(texturedata_t){
|
case 0x00: // RGBA8888
|
||||||
.paletteData = assetData->palette
|
format = TEXTURE_FORMAT_RGBA;
|
||||||
|
data.rgbaColors = (color_t *)assetData->data;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// case 0x01:
|
||||||
|
// format = TEXTURE_FORMAT_RGB;
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case 0x02:
|
||||||
|
// format = TEXTURE_FORMAT_RGB565;
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case 0x03:
|
||||||
|
// format = TEXTURE_FORMAT_RGB5A3;
|
||||||
|
// break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
errorThrow("Unsupported texture format");
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
errorChain(textureInit(
|
||||||
|
texture, assetData->width, assetData->height, format, data
|
||||||
|
));
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
|
#include "display/color.h"
|
||||||
|
|
||||||
#define ASSET_TEXTURE_WIDTH_MAX 2048
|
#define ASSET_TEXTURE_WIDTH_MAX 2048
|
||||||
#define ASSET_TEXTURE_HEIGHT_MAX 2048
|
#define ASSET_TEXTURE_HEIGHT_MAX 2048
|
||||||
@@ -20,9 +21,10 @@ typedef struct assetentire_s assetentire_t;
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char_t header[3];
|
char_t header[3];
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
|
uint8_t type;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint8_t palette[ASSET_TEXTURE_SIZE_MAX];
|
uint8_t data[ASSET_TEXTURE_SIZE_MAX * sizeof(color4b_t)];
|
||||||
} assettexture_t;
|
} assettexture_t;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ add_subdirectory(camera)
|
|||||||
add_subdirectory(framebuffer)
|
add_subdirectory(framebuffer)
|
||||||
add_subdirectory(mesh)
|
add_subdirectory(mesh)
|
||||||
add_subdirectory(screen)
|
add_subdirectory(screen)
|
||||||
|
add_subdirectory(shader)
|
||||||
add_subdirectory(spritebatch)
|
add_subdirectory(spritebatch)
|
||||||
add_subdirectory(text)
|
add_subdirectory(text)
|
||||||
add_subdirectory(texture)
|
add_subdirectory(texture)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void cameraInitOrthographic(camera_t *camera) {
|
|||||||
camera->orthographic.right = SCREEN.width;
|
camera->orthographic.right = SCREEN.width;
|
||||||
camera->orthographic.top = 0.0f;
|
camera->orthographic.top = 0.0f;
|
||||||
camera->orthographic.bottom = SCREEN.height;
|
camera->orthographic.bottom = SCREEN.height;
|
||||||
camera->nearClip = -1.0f;
|
camera->nearClip = 0.1f;
|
||||||
camera->farClip = 1.0f;
|
camera->farClip = 1.0f;
|
||||||
|
|
||||||
camera->viewType = CAMERA_VIEW_TYPE_2D;
|
camera->viewType = CAMERA_VIEW_TYPE_2D;
|
||||||
@@ -45,13 +45,63 @@ void cameraInitOrthographic(camera_t *camera) {
|
|||||||
camera->_2d.zoom = 1.0f;
|
camera->_2d.zoom = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraPushMatrix(camera_t *camera) {
|
void cameraGetProjectionMatrix(camera_t *camera, mat4 dest) {
|
||||||
assertNotNull(camera, "Invalid camera");
|
assertNotNull(camera, "Not a camera component");
|
||||||
cameraPushMatrixPlatform(camera);
|
assertNotNull(dest, "Destination matrix must not be null");
|
||||||
|
|
||||||
|
if(
|
||||||
|
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
|
||||||
|
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
|
||||||
|
) {
|
||||||
|
glm_mat4_identity(dest);
|
||||||
|
glm_perspective(
|
||||||
|
camera->perspective.fov,
|
||||||
|
SCREEN.aspect,
|
||||||
|
camera->nearClip,
|
||||||
|
camera->farClip,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
|
||||||
|
if(camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED) {
|
||||||
|
dest[1][1] *= -1.0f;
|
||||||
|
}
|
||||||
|
} else if(camera->projType == CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
|
||||||
|
glm_mat4_identity(dest);
|
||||||
|
glm_ortho(
|
||||||
|
camera->orthographic.left,
|
||||||
|
camera->orthographic.right,
|
||||||
|
camera->orthographic.top,
|
||||||
|
camera->orthographic.bottom,
|
||||||
|
camera->nearClip,
|
||||||
|
camera->farClip,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cameraPopMatrix(void) {
|
void cameraGetViewMatrix(camera_t *camera, mat4 dest) {
|
||||||
#ifdef cameraPopMatrixPlatform
|
assertNotNull(camera, "Not a camera component");
|
||||||
cameraPopMatrixPlatform();
|
assertNotNull(dest, "Destination matrix must not be null");
|
||||||
#endif
|
|
||||||
|
if(camera->viewType == CAMERA_VIEW_TYPE_MATRIX) {
|
||||||
|
glm_mat4_ucopy(camera->view, dest);
|
||||||
|
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
|
||||||
|
glm_mat4_identity(dest);
|
||||||
|
glm_lookat(
|
||||||
|
camera->lookat.position,
|
||||||
|
camera->lookat.target,
|
||||||
|
camera->lookat.up,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
} else if(camera->viewType == CAMERA_VIEW_TYPE_2D) {
|
||||||
|
glm_mat4_identity(dest);
|
||||||
|
glm_lookat(
|
||||||
|
(vec3){ camera->_2d.position[0], camera->_2d.position[1], 0.5f },
|
||||||
|
(vec3){ camera->_2d.position[0], camera->_2d.position[1], 0.0f },
|
||||||
|
(vec3){ 0.0f, 1.0f, 0.0f },
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT) {
|
||||||
|
assertUnreachable("LOOKAT_PIXEL_PERFECT view type is not implemented yet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -86,13 +86,17 @@ void cameraInitPerspective(camera_t *camera);
|
|||||||
void cameraInitOrthographic(camera_t *camera);
|
void cameraInitOrthographic(camera_t *camera);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pushes the camera's view matrix onto the matrix stack.
|
* Gets the projection matrix for a camera.
|
||||||
*
|
*
|
||||||
* @param id The ID of the camera entity to use.
|
* @param camera Camera to get the projection matrix for
|
||||||
|
* @param dest Matrix to store the projection matrix in
|
||||||
*/
|
*/
|
||||||
void cameraPushMatrix(camera_t *camera);
|
void cameraGetProjectionMatrix(camera_t *camera, mat4 dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pops the camera's view matrix off the matrix stack.
|
* Gets the view matrix for a camera.
|
||||||
|
*
|
||||||
|
* @param camera Camera to get the view matrix for
|
||||||
|
* @param dest Matrix to store the view matrix in
|
||||||
*/
|
*/
|
||||||
void cameraPopMatrix(void);
|
void cameraGetViewMatrix(camera_t *camera, mat4 dest);
|
||||||
@@ -12,14 +12,35 @@
|
|||||||
#include "display/mesh/quad.h"
|
#include "display/mesh/quad.h"
|
||||||
#include "display/screen/screen.h"
|
#include "display/screen/screen.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
#include "display/text/text.h"
|
#include "display/text/text.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
|
#include "display/shader/shaderunlit.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
|
#include "script/module/display/moduleshader.h"
|
||||||
|
|
||||||
display_t DISPLAY = { 0 };
|
display_t DISPLAY = { 0 };
|
||||||
|
mesh_t mesh;
|
||||||
|
meshvertex_t vertices[3] = {
|
||||||
|
{
|
||||||
|
.color = { 255, 0, 0, 255 },
|
||||||
|
.uv = { 0.0f, 0.0f },
|
||||||
|
.pos = { 0.0f, 0.5f, 0.0f }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.color = { 0, 255, 0, 255 },
|
||||||
|
.uv = { 0.5f, 1.0f },
|
||||||
|
.pos = { -0.5f, -0.5f, 0.0f }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.color = { 0, 0, 255, 255 },
|
||||||
|
.uv = { 1.0f, 0.0f },
|
||||||
|
.pos = { 0.5f, -0.5f, 0.0f }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
errorret_t displayInit(void) {
|
errorret_t displayInit(void) {
|
||||||
memoryZero(&DISPLAY, sizeof(DISPLAY));
|
memoryZero(&DISPLAY, sizeof(DISPLAY));
|
||||||
@@ -27,13 +48,28 @@ errorret_t displayInit(void) {
|
|||||||
#ifdef displayPlatformInit
|
#ifdef displayPlatformInit
|
||||||
errorChain(displayPlatformInit());
|
errorChain(displayPlatformInit());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
errorChain(quadInit());
|
errorChain(quadInit());
|
||||||
errorChain(frameBufferInitBackBuffer());
|
errorChain(frameBufferInitBackBuffer());
|
||||||
errorChain(spriteBatchInit());
|
errorChain(spriteBatchInit());
|
||||||
errorChain(textInit());
|
errorChain(textInit());
|
||||||
errorChain(screenInit());
|
errorChain(screenInit());
|
||||||
|
|
||||||
|
// Setup initial shader with default values
|
||||||
|
errorChain(shaderInit(&SHADER_UNLIT, &SHADER_UNLIT_DEFINITION));
|
||||||
|
camera_t cam;
|
||||||
|
cameraInit(&cam);
|
||||||
|
mat4 mat;
|
||||||
|
cameraGetProjectionMatrix(&cam, mat);
|
||||||
|
errorChain(shaderBind(&SHADER_UNLIT));
|
||||||
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, mat));
|
||||||
|
cameraGetViewMatrix(&cam, mat);
|
||||||
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, mat));
|
||||||
|
glm_mat4_identity(mat);
|
||||||
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
|
||||||
|
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, NULL));
|
||||||
|
|
||||||
|
errorChain(meshInit(&mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, 3, vertices));
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +83,7 @@ errorret_t displayUpdate(void) {
|
|||||||
errorChain(frameBufferBind(NULL));
|
errorChain(frameBufferBind(NULL));
|
||||||
|
|
||||||
// Bind screen and render scene
|
// Bind screen and render scene
|
||||||
screenBind();
|
errorChain(screenBind());
|
||||||
frameBufferClear(
|
frameBufferClear(
|
||||||
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
||||||
SCREEN.background
|
SCREEN.background
|
||||||
@@ -56,7 +92,7 @@ errorret_t displayUpdate(void) {
|
|||||||
errorChain(sceneRender());
|
errorChain(sceneRender());
|
||||||
|
|
||||||
// Render UI
|
// Render UI
|
||||||
uiRender();
|
// uiRender();
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
screenUnbind();
|
screenUnbind();
|
||||||
@@ -70,6 +106,7 @@ errorret_t displayUpdate(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorret_t displayDispose(void) {
|
errorret_t displayDispose(void) {
|
||||||
|
errorChain(shaderDispose(&SHADER_UNLIT));
|
||||||
errorChain(spriteBatchDispose());
|
errorChain(spriteBatchDispose());
|
||||||
screenDispose();
|
screenDispose();
|
||||||
errorChain(textDispose());
|
errorChain(textDispose());
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
|
|
||||||
errorret_t meshInit(
|
errorret_t meshInit(
|
||||||
mesh_t *mesh,
|
mesh_t *mesh,
|
||||||
@@ -26,6 +25,29 @@ errorret_t meshInit(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorret_t meshFlush(
|
||||||
|
mesh_t *mesh,
|
||||||
|
const int32_t vertexOffset,
|
||||||
|
const int32_t vertexCount
|
||||||
|
) {
|
||||||
|
#ifdef meshFlushPlatform
|
||||||
|
assertNotNull(mesh, "Mesh cannot be NULL");
|
||||||
|
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative.");
|
||||||
|
assertTrue(vertexCount == -1 || vertexCount > 0, "Vertex count incorrect.");
|
||||||
|
|
||||||
|
int32_t vertCount = meshGetVertexCount(mesh);
|
||||||
|
assertTrue(vertexOffset < (vertCount - 1), "Need at least one vert to draw");
|
||||||
|
|
||||||
|
int32_t drawCount = vertexCount;
|
||||||
|
if(vertexCount == -1) {
|
||||||
|
drawCount = vertCount - vertexOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorChain(meshFlushPlatform(mesh, vertexOffset, vertexCount));
|
||||||
|
#endif
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
errorret_t meshDraw(
|
errorret_t meshDraw(
|
||||||
const mesh_t *mesh,
|
const mesh_t *mesh,
|
||||||
const int32_t vertexOffset,
|
const int32_t vertexOffset,
|
||||||
@@ -33,7 +55,7 @@ errorret_t meshDraw(
|
|||||||
) {
|
) {
|
||||||
assertNotNull(mesh, "Mesh cannot be NULL");
|
assertNotNull(mesh, "Mesh cannot be NULL");
|
||||||
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative");
|
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative");
|
||||||
assertTrue(vertexCount >= -1, "Vertex count must be -1 or non-negative");
|
assertTrue(vertexCount == -1 || vertexCount > 0, "Incorrect vert count");
|
||||||
|
|
||||||
int32_t vertDrawCount = vertexCount;
|
int32_t vertDrawCount = vertexCount;
|
||||||
if(vertexCount == -1) {
|
if(vertexCount == -1) {
|
||||||
|
|||||||
@@ -40,6 +40,22 @@ errorret_t meshInit(
|
|||||||
const meshvertex_t *vertices
|
const meshvertex_t *vertices
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs the mesh to flush the vertices to the GPU. This is surprisingly
|
||||||
|
* only really necessary on modern devices, as we tend to let older devices
|
||||||
|
* read the vertices from the main memory directly.
|
||||||
|
*
|
||||||
|
* @param mesh Mesh to flush the vertices for.
|
||||||
|
* @param vertexOffset Start vertex to flush.
|
||||||
|
* @param vertexCount Count of vertices to flush, set to -1 for all.
|
||||||
|
* @return Error state.
|
||||||
|
*/
|
||||||
|
errorret_t meshFlush(
|
||||||
|
mesh_t *mesh,
|
||||||
|
const int32_t vertexOffset,
|
||||||
|
const int32_t vertexCount
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a mesh.
|
* Draws a mesh.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "quad.h"
|
#include "quad.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
|
|
||||||
mesh_t QUAD_MESH_SIMPLE;
|
mesh_t QUAD_MESH_SIMPLE;
|
||||||
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "display/mesh/quad.h"
|
#include "display/mesh/quad.h"
|
||||||
|
#include "display/shader/shaderunlit.h"
|
||||||
|
|
||||||
screen_t SCREEN;
|
screen_t SCREEN;
|
||||||
|
|
||||||
@@ -44,22 +45,23 @@ errorret_t screenInit() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Init screen to backbuffer mode by default
|
// Init screen to backbuffer mode by default
|
||||||
screenBind();
|
errorChain(screenBind());
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenBind() {
|
errorret_t screenBind() {
|
||||||
// Assume backbuffer is currently bound.
|
// Assume backbuffer is currently bound.
|
||||||
switch(SCREEN.mode) {
|
switch(SCREEN.mode) {
|
||||||
case SCREEN_MODE_BACKBUFFER: {
|
case SCREEN_MODE_BACKBUFFER: {
|
||||||
// Screen mode backbuffer uses the full display size
|
// Screen mode backbuffer uses the full display size
|
||||||
SCREEN.width = frameBufferGetWidth(FRAMEBUFFER_BOUND);
|
SCREEN.width = frameBufferGetWidth(FRAMEBUFFER_BOUND);
|
||||||
SCREEN.height = frameBufferGetHeight(FRAMEBUFFER_BOUND);
|
SCREEN.height = frameBufferGetHeight(FRAMEBUFFER_BOUND);
|
||||||
|
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||||
|
|
||||||
// No needd for a framebuffer.
|
// No needd for a framebuffer.
|
||||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -79,19 +81,21 @@ void screenBind() {
|
|||||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||||
if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) {
|
if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) {
|
||||||
// Correct size, nothing to do.
|
// Correct size, nothing to do.
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need a new framebuffer.
|
// Need a new framebuffer.
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new framebuffer
|
// Create new framebuffer
|
||||||
frameBufferInit(&SCREEN.framebuffer, SCREEN.width, SCREEN.height);
|
errorChain(frameBufferInit(
|
||||||
|
&SCREEN.framebuffer, SCREEN.width, SCREEN.height
|
||||||
|
));
|
||||||
SCREEN.framebufferReady = true;
|
SCREEN.framebufferReady = true;
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +113,10 @@ void screenBind() {
|
|||||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||||
|
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t newFbWidth, newFbHeight;
|
int32_t newFbWidth, newFbHeight;
|
||||||
@@ -136,24 +140,26 @@ void screenBind() {
|
|||||||
SCREEN.width = newFbWidth;
|
SCREEN.width = newFbWidth;
|
||||||
SCREEN.height = newFbHeight;
|
SCREEN.height = newFbHeight;
|
||||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need a new framebuffer.
|
// Need a new framebuffer.
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new framebuffer
|
// Create new framebuffer
|
||||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
errorChain(frameBufferInit(
|
||||||
|
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||||
|
));
|
||||||
SCREEN.width = newFbWidth;
|
SCREEN.width = newFbWidth;
|
||||||
SCREEN.height = newFbHeight;
|
SCREEN.height = newFbHeight;
|
||||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||||
SCREEN.framebufferReady = true;
|
SCREEN.framebufferReady = true;
|
||||||
|
|
||||||
// Bind FB
|
// Bind FB
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,10 +179,10 @@ void screenBind() {
|
|||||||
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
||||||
// No need to use framebuffer.
|
// No need to use framebuffer.
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
@@ -185,19 +191,21 @@ void screenBind() {
|
|||||||
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
||||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||||
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need a new framebuffer.
|
// Need a new framebuffer.
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new framebuffer.
|
// Create a new framebuffer.
|
||||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
errorChain(frameBufferInit(
|
||||||
|
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||||
|
));
|
||||||
SCREEN.framebufferReady = true;
|
SCREEN.framebufferReady = true;
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,10 +225,10 @@ void screenBind() {
|
|||||||
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
||||||
// No need to use framebuffer.
|
// No need to use framebuffer.
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
@@ -229,19 +237,21 @@ void screenBind() {
|
|||||||
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
||||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||||
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need a new framebuffer.
|
// Need a new framebuffer.
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new framebuffer.
|
// Create a new framebuffer.
|
||||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
errorChain(frameBufferInit(
|
||||||
|
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||||
|
));
|
||||||
SCREEN.framebufferReady = true;
|
SCREEN.framebufferReady = true;
|
||||||
frameBufferBind(&SCREEN.framebuffer);
|
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,9 +272,11 @@ void screenBind() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenUnbind() {
|
errorret_t screenUnbind() {
|
||||||
switch(SCREEN.mode) {
|
switch(SCREEN.mode) {
|
||||||
// Nothing to do here.
|
// Nothing to do here.
|
||||||
case SCREEN_MODE_BACKBUFFER:
|
case SCREEN_MODE_BACKBUFFER:
|
||||||
@@ -275,7 +287,9 @@ void screenUnbind() {
|
|||||||
case SCREEN_MODE_FIXED_HEIGHT:
|
case SCREEN_MODE_FIXED_HEIGHT:
|
||||||
case SCREEN_MODE_FIXED_SIZE:
|
case SCREEN_MODE_FIXED_SIZE:
|
||||||
case SCREEN_MODE_FIXED_WIDTH:
|
case SCREEN_MODE_FIXED_WIDTH:
|
||||||
if(SCREEN.framebufferReady) frameBufferBind(NULL);
|
if(SCREEN.framebufferReady) {
|
||||||
|
errorChain(frameBufferBind(NULL));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCREEN_MODE_FIXED_VIEWPORT_HEIGHT:
|
case SCREEN_MODE_FIXED_VIEWPORT_HEIGHT:
|
||||||
@@ -286,17 +300,19 @@ void screenUnbind() {
|
|||||||
assertUnreachable("Invalid screen mode.");
|
assertUnreachable("Invalid screen mode.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenRender() {
|
errorret_t screenRender() {
|
||||||
if(SCREEN.mode == SCREEN_MODE_BACKBUFFER) {
|
if(SCREEN.mode == SCREEN_MODE_BACKBUFFER) {
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||||
if(SCREEN.mode == SCREEN_MODE_FIXED_VIEWPORT_HEIGHT) {
|
if(SCREEN.mode == SCREEN_MODE_FIXED_VIEWPORT_HEIGHT) {
|
||||||
glViewport(0, 0, SCREEN.width, SCREEN.height);
|
glViewport(0, 0, SCREEN.width, SCREEN.height);
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
@@ -307,7 +323,7 @@ void screenRender() {
|
|||||||
) {
|
) {
|
||||||
if(!SCREEN.framebufferReady) {
|
if(!SCREEN.framebufferReady) {
|
||||||
// Nothing to do here.
|
// Nothing to do here.
|
||||||
return;
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t bbWidth, bbHeight;
|
float_t bbWidth, bbHeight;
|
||||||
@@ -356,23 +372,34 @@ void screenRender() {
|
|||||||
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
||||||
COLOR_BLACK
|
COLOR_BLACK
|
||||||
);
|
);
|
||||||
cameraPushMatrix(&SCREEN.framebufferCamera);
|
|
||||||
textureBind(&SCREEN.framebuffer.texture);
|
|
||||||
meshDraw(&SCREEN.frameBufferMesh, 0, -1);
|
|
||||||
cameraPopMatrix();
|
|
||||||
|
|
||||||
return;
|
shaderBind(&SHADER_UNLIT);
|
||||||
|
mat4 proj, view, model;
|
||||||
|
cameraGetProjectionMatrix(&SCREEN.framebufferCamera, proj);
|
||||||
|
cameraGetViewMatrix(&SCREEN.framebufferCamera, view);
|
||||||
|
glm_mat4_identity(model);
|
||||||
|
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj);
|
||||||
|
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view);
|
||||||
|
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model);
|
||||||
|
|
||||||
|
// errorChain(textureBind(&SCREEN.framebuffer.texture));
|
||||||
|
errorChain(meshDraw(&SCREEN.frameBufferMesh, 0, -1));
|
||||||
|
|
||||||
|
errorOk();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assertUnreachable("Invalid screen mode.");
|
assertUnreachable("Invalid screen mode.");
|
||||||
|
errorThrow("Invalid screen mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenDispose() {
|
errorret_t screenDispose() {
|
||||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||||
if(SCREEN.framebufferReady) {
|
if(SCREEN.framebufferReady) {
|
||||||
frameBufferDispose(&SCREEN.framebuffer);
|
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||||
SCREEN.framebufferReady = false;
|
SCREEN.framebufferReady = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -90,20 +90,28 @@ errorret_t screenInit();
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds the screen, this is done before rendering game content.
|
* Binds the screen, this is done before rendering game content.
|
||||||
|
*
|
||||||
|
* @return Error code and state, if error occurs.
|
||||||
*/
|
*/
|
||||||
void screenBind();
|
errorret_t screenBind();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unbinds the screen, does nothing for now.
|
* Unbinds the screen, does nothing for now.
|
||||||
|
*
|
||||||
|
* @return Error code and state, if error occurs.
|
||||||
*/
|
*/
|
||||||
void screenUnbind();
|
errorret_t screenUnbind();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the screen to the current framebuffer.
|
* Renders the screen to the current framebuffer.
|
||||||
|
*
|
||||||
|
* @return Error code and state, if error occurs.
|
||||||
*/
|
*/
|
||||||
void screenRender();
|
errorret_t screenRender();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes the screen system.
|
* Disposes the screen system.
|
||||||
|
*
|
||||||
|
* @return Error code and state, if error occurs.
|
||||||
*/
|
*/
|
||||||
void screenDispose();
|
errorret_t screenDispose();
|
||||||
11
src/dusk/display/shader/CMakeLists.txt
Normal file
11
src/dusk/display/shader/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
shader.c
|
||||||
|
shaderunlit.c
|
||||||
|
)
|
||||||
68
src/dusk/display/shader/shader.c
Normal file
68
src/dusk/display/shader/shader.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shader.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
|
||||||
|
shader_t *bound = NULL;
|
||||||
|
|
||||||
|
errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def) {
|
||||||
|
assertNotNull(shader, "Shader cannot be null");
|
||||||
|
errorChain(shaderInitPlatform(shader, def));
|
||||||
|
bound = NULL;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderBind(shader_t *shader) {
|
||||||
|
assertNotNull(shader, "Shader cannot be null");
|
||||||
|
errorChain(shaderBindPlatform(shader));
|
||||||
|
bound = shader;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderSetMatrix(
|
||||||
|
shader_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
mat4 matrix
|
||||||
|
) {
|
||||||
|
assertNotNull(shader, "Shader cannot be null");
|
||||||
|
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||||
|
assertNotNull(matrix, "Matrix cannot be null");
|
||||||
|
assertTrue(bound == shader, "Shader must be bound.");
|
||||||
|
errorChain(shaderSetMatrixPlatform(shader, name, matrix));
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderSetTexture(
|
||||||
|
shader_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
texture_t *texture
|
||||||
|
) {
|
||||||
|
assertNotNull(shader, "Shader cannot be null");
|
||||||
|
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||||
|
assertTrue(bound == shader, "Shader must be bound.");
|
||||||
|
errorChain(shaderSetTexturePlatform(shader, name, texture));
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
// errorret_t shaderSetColor(
|
||||||
|
// shader_t *shader,
|
||||||
|
// const char_t *name,
|
||||||
|
// color_t color
|
||||||
|
// ) {
|
||||||
|
// assertNotNull(shader, "Shader cannot be null");
|
||||||
|
// assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||||
|
// errorChain(shaderSetColorPlatform(shader, name, color));
|
||||||
|
// errorOk();
|
||||||
|
// }
|
||||||
|
|
||||||
|
errorret_t shaderDispose(shader_t *shader) {
|
||||||
|
assertNotNull(shader, "Shader cannot be null");
|
||||||
|
bound = NULL;
|
||||||
|
errorChain(shaderDisposePlatform(shader));
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
94
src/dusk/display/shader/shader.h
Normal file
94
src/dusk/display/shader/shader.h
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* 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/texture.h"
|
||||||
|
#include "display/shader/shaderplatform.h"
|
||||||
|
|
||||||
|
#ifndef shaderInitPlatform
|
||||||
|
#error "shaderInitPlatform must be defined to use shader.h"
|
||||||
|
#endif
|
||||||
|
#ifndef shaderBindPlatform
|
||||||
|
#error "shaderBindPlatform must be defined to use shader.h"
|
||||||
|
#endif
|
||||||
|
#ifndef shaderSetMatrixPlatform
|
||||||
|
#error "shaderSetMatrixPlatform must be defined to use shader.h"
|
||||||
|
#endif
|
||||||
|
#ifndef shaderDisposePlatform
|
||||||
|
#error "shaderDisposePlatform must be defined to use shader.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef shaderplatform_t shader_t;
|
||||||
|
typedef shaderdefinitionplatform_t shaderdefinition_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to initialize
|
||||||
|
* @param def Definition of the shader to initialize with.
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to bind
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
errorret_t shaderBind(shader_t *shader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a matrix uniform in the shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to set the matrix in
|
||||||
|
* @param name Name of the uniform to set
|
||||||
|
* @param matrix Matrix to set
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
errorret_t shaderSetMatrix(
|
||||||
|
shader_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
mat4 matrix
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a texture uniform in the shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to set the texture in
|
||||||
|
* @param name Name of the uniform to set
|
||||||
|
* @param texture Texture to set
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
errorret_t shaderSetTexture(
|
||||||
|
shader_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
texture_t *texture
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a color uniform in the shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to set the color in
|
||||||
|
* @param name Name of the uniform to set
|
||||||
|
* @param color Color to set
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
// errorret_t shaderSetColor(
|
||||||
|
// shader_t *shader,
|
||||||
|
// const char_t *name,
|
||||||
|
// color_t color
|
||||||
|
// );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of a shader. This is platform dependant.
|
||||||
|
*
|
||||||
|
* @param shader Shader to dispose
|
||||||
|
* @return Error if failure, otherwise errorOk
|
||||||
|
*/
|
||||||
|
errorret_t shaderDispose(shader_t *shader);
|
||||||
10
src/dusk/display/shader/shaderunlit.c
Normal file
10
src/dusk/display/shader/shaderunlit.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "shaderunlit.h"
|
||||||
|
|
||||||
|
shader_t SHADER_UNLIT = { 0 };
|
||||||
18
src/dusk/display/shader/shaderunlit.h
Normal file
18
src/dusk/display/shader/shaderunlit.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "shader.h"
|
||||||
|
|
||||||
|
#define SHADER_UNLIT_PROJECTION "u_Proj"
|
||||||
|
#define SHADER_UNLIT_VIEW "u_View"
|
||||||
|
#define SHADER_UNLIT_MODEL "u_Model"
|
||||||
|
#define SHADER_UNLIT_TEXTURE "u_Texture"
|
||||||
|
// #define SHADER_UNLIT_COLOR "u_Color"
|
||||||
|
|
||||||
|
extern shaderdefinition_t SHADER_UNLIT_DEFINITION;
|
||||||
|
extern shader_t SHADER_UNLIT;
|
||||||
@@ -19,13 +19,12 @@ errorret_t spriteBatchInit() {
|
|||||||
&SPRITEBATCH.mesh,
|
&SPRITEBATCH.mesh,
|
||||||
QUAD_PRIMITIVE_TYPE,
|
QUAD_PRIMITIVE_TYPE,
|
||||||
SPRITEBATCH_VERTEX_COUNT,
|
SPRITEBATCH_VERTEX_COUNT,
|
||||||
&SPRITEBATCH_VERTICES[0]
|
SPRITEBATCH_VERTICES
|
||||||
));
|
));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t spriteBatchPush(
|
errorret_t spriteBatchPush(
|
||||||
texture_t *texture,
|
|
||||||
const float_t minX,
|
const float_t minX,
|
||||||
const float_t minY,
|
const float_t minY,
|
||||||
const float_t maxX,
|
const float_t maxX,
|
||||||
@@ -36,19 +35,16 @@ errorret_t spriteBatchPush(
|
|||||||
const float_t u1,
|
const float_t u1,
|
||||||
const float_t v1
|
const float_t v1
|
||||||
) {
|
) {
|
||||||
errorChain(spriteBatchPush3D(
|
return spriteBatchPush3D(
|
||||||
texture,
|
|
||||||
(vec3){ minX, minY, 0 },
|
(vec3){ minX, minY, 0 },
|
||||||
(vec3){ maxX, maxY, 0 },
|
(vec3){ maxX, maxY, 0 },
|
||||||
color,
|
color,
|
||||||
(vec2){ u0, v0 },
|
(vec2){ u0, v0 },
|
||||||
(vec2){ u1, v1 }
|
(vec2){ u1, v1 }
|
||||||
));
|
);
|
||||||
errorOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t spriteBatchPush3D(
|
errorret_t spriteBatchPush3D(
|
||||||
texture_t *texture,
|
|
||||||
const vec3 min,
|
const vec3 min,
|
||||||
const vec3 max,
|
const vec3 max,
|
||||||
const color_t color,
|
const color_t color,
|
||||||
@@ -56,15 +52,14 @@ errorret_t spriteBatchPush3D(
|
|||||||
const vec2 uv1
|
const vec2 uv1
|
||||||
) {
|
) {
|
||||||
// Need to flush?
|
// Need to flush?
|
||||||
if(
|
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
|
||||||
SPRITEBATCH.currentTexture != texture ||
|
|
||||||
SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX
|
|
||||||
) {
|
|
||||||
errorChain(spriteBatchFlush());
|
errorChain(spriteBatchFlush());
|
||||||
SPRITEBATCH.currentTexture = texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t vertexOffset = SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT;
|
size_t vertexOffset = (
|
||||||
|
SPRITEBATCH.spriteCount +
|
||||||
|
(SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH)
|
||||||
|
) * QUAD_VERTEX_COUNT;
|
||||||
quadBuffer3D(
|
quadBuffer3D(
|
||||||
&SPRITEBATCH_VERTICES[vertexOffset],
|
&SPRITEBATCH_VERTICES[vertexOffset],
|
||||||
min, max, color, uv0, uv1
|
min, max, color, uv0, uv1
|
||||||
@@ -75,7 +70,7 @@ errorret_t spriteBatchPush3D(
|
|||||||
|
|
||||||
void spriteBatchClear() {
|
void spriteBatchClear() {
|
||||||
SPRITEBATCH.spriteCount = 0;
|
SPRITEBATCH.spriteCount = 0;
|
||||||
SPRITEBATCH.currentTexture = NULL;
|
SPRITEBATCH.spriteFlush = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t spriteBatchFlush() {
|
errorret_t spriteBatchFlush() {
|
||||||
@@ -83,11 +78,20 @@ errorret_t spriteBatchFlush() {
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorChain(textureBind(SPRITEBATCH.currentTexture));
|
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
|
||||||
errorChain(meshDraw(
|
size_t vertexOffset = (
|
||||||
&SPRITEBATCH.mesh, 0, QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount
|
SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH *
|
||||||
));
|
QUAD_VERTEX_COUNT
|
||||||
spriteBatchClear();
|
);
|
||||||
|
errorChain(meshFlush(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
|
||||||
|
errorChain(meshDraw(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
|
||||||
|
|
||||||
|
SPRITEBATCH.spriteFlush++;
|
||||||
|
if(SPRITEBATCH.spriteFlush >= SPRITEBATCH_FLUSH_COUNT) {
|
||||||
|
SPRITEBATCH.spriteFlush = 0;
|
||||||
|
}
|
||||||
|
SPRITEBATCH.spriteCount = 0;
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "display/mesh/quad.h"
|
#include "display/mesh/quad.h"
|
||||||
#include "display/texture/texture.h"
|
|
||||||
|
|
||||||
#define SPRITEBATCH_SPRITES_MAX 16
|
#define SPRITEBATCH_SPRITES_MAX 32
|
||||||
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
|
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
|
||||||
|
#define SPRITEBATCH_FLUSH_COUNT 4
|
||||||
|
#define SPRITEBATCH_SPRITES_MAX_PER_FLUSH (\
|
||||||
|
SPRITEBATCH_SPRITES_MAX / SPRITEBATCH_FLUSH_COUNT \
|
||||||
|
)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mesh_t mesh;
|
mesh_t mesh;
|
||||||
int32_t spriteCount;
|
int32_t spriteCount;
|
||||||
texture_t *currentTexture;
|
int32_t spriteFlush;
|
||||||
} spritebatch_t;
|
} spritebatch_t;
|
||||||
|
|
||||||
// Have to define these seperately because of alignment in certain platforms.
|
// Have to define these seperately because of alignment in certain platforms.
|
||||||
@@ -39,7 +41,6 @@ errorret_t spriteBatchInit();
|
|||||||
* Currently changing texture pointer will cause the buffer to flush but this is
|
* Currently changing texture pointer will cause the buffer to flush but this is
|
||||||
* also likely to change in the future.
|
* also likely to change in the future.
|
||||||
*
|
*
|
||||||
* @param texture The texture to use for the sprite.
|
|
||||||
* @param minX The minimum x coordinate of the sprite.
|
* @param minX The minimum x coordinate of the sprite.
|
||||||
* @param minY The minimum y coordinate of the sprite.
|
* @param minY The minimum y coordinate of the sprite.
|
||||||
* @param maxX The maximum x coordinate of the sprite.
|
* @param maxX The maximum x coordinate of the sprite.
|
||||||
@@ -52,7 +53,6 @@ errorret_t spriteBatchInit();
|
|||||||
* @return An error code indicating success or failure.
|
* @return An error code indicating success or failure.
|
||||||
*/
|
*/
|
||||||
errorret_t spriteBatchPush(
|
errorret_t spriteBatchPush(
|
||||||
texture_t *texture,
|
|
||||||
const float_t minX,
|
const float_t minX,
|
||||||
const float_t minY,
|
const float_t minY,
|
||||||
const float_t maxX,
|
const float_t maxX,
|
||||||
@@ -68,7 +68,6 @@ errorret_t spriteBatchPush(
|
|||||||
* Pushes a 3D sprite to the batch. This is like spriteBatchPush but takes
|
* Pushes a 3D sprite to the batch. This is like spriteBatchPush but takes
|
||||||
* 3D coordinates instead of 2D.
|
* 3D coordinates instead of 2D.
|
||||||
*
|
*
|
||||||
* @param texture The texture to use for the sprite.
|
|
||||||
* @param min The minimum (x,y,z) coordinate of the sprite.
|
* @param min The minimum (x,y,z) coordinate of the sprite.
|
||||||
* @param max The maximum (x,y,z) coordinate of the sprite.
|
* @param max The maximum (x,y,z) coordinate of the sprite.
|
||||||
* @param color The color to tint the sprite with.
|
* @param color The color to tint the sprite with.
|
||||||
@@ -77,7 +76,6 @@ errorret_t spriteBatchPush(
|
|||||||
* @return An error code indicating success or failure.
|
* @return An error code indicating success or failure.
|
||||||
*/
|
*/
|
||||||
errorret_t spriteBatchPush3D(
|
errorret_t spriteBatchPush3D(
|
||||||
texture_t *texture,
|
|
||||||
const vec3 min,
|
const vec3 min,
|
||||||
const vec3 max,
|
const vec3 max,
|
||||||
const color_t color,
|
const color_t color,
|
||||||
|
|||||||
@@ -11,17 +11,19 @@
|
|||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
|
|
||||||
|
#include "display/shader/shaderunlit.h"
|
||||||
|
|
||||||
texture_t DEFAULT_FONT_TEXTURE;
|
texture_t DEFAULT_FONT_TEXTURE;
|
||||||
tileset_t DEFAULT_FONT_TILESET;
|
tileset_t DEFAULT_FONT_TILESET;
|
||||||
|
|
||||||
errorret_t textInit(void) {
|
errorret_t textInit(void) {
|
||||||
// errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE));
|
errorChain(assetLoad("ui/minogram.dtx", &DEFAULT_FONT_TEXTURE));
|
||||||
// errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t textDispose(void) {
|
errorret_t textDispose(void) {
|
||||||
// errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +47,9 @@ errorret_t textDrawChar(
|
|||||||
vec4 uv;
|
vec4 uv;
|
||||||
tilesetTileGetUV(tileset, tileIndex, uv);
|
tilesetTileGetUV(tileset, tileIndex, uv);
|
||||||
|
|
||||||
|
|
||||||
errorChain(spriteBatchPush(
|
errorChain(spriteBatchPush(
|
||||||
texture,
|
// texture,
|
||||||
x, y,
|
x, y,
|
||||||
x + tileset->tileWidth,
|
x + tileset->tileWidth,
|
||||||
y + tileset->tileHeight,
|
y + tileset->tileHeight,
|
||||||
@@ -70,6 +73,8 @@ errorret_t textDraw(
|
|||||||
float_t posX = x;
|
float_t posX = x;
|
||||||
float_t posY = y;
|
float_t posY = y;
|
||||||
|
|
||||||
|
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture));
|
||||||
|
|
||||||
char_t c;
|
char_t c;
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
while((c = text[i++]) != '\0') {
|
while((c = text[i++]) != '\0') {
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
tileset.c
|
tileset.c
|
||||||
texture.c
|
texture.c
|
||||||
|
palette.c
|
||||||
)
|
)
|
||||||
10
src/dusk/display/texture/palette.c
Normal file
10
src/dusk/display/texture/palette.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "palette.h"
|
||||||
|
|
||||||
|
palette_t PALETTES[PALETTE_COUNT];
|
||||||
19
src/dusk/display/texture/palette.h
Normal file
19
src/dusk/display/texture/palette.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "display/color.h"
|
||||||
|
|
||||||
|
#define PALETTE_COLOR_COUNT 0xFF
|
||||||
|
#define PALETTE_COUNT 6
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
color_t colors[PALETTE_COLOR_COUNT];
|
||||||
|
uint8_t count;
|
||||||
|
} palette_t;
|
||||||
|
|
||||||
|
extern palette_t PALETTES[PALETTE_COUNT];
|
||||||
@@ -11,8 +11,6 @@
|
|||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
#include "display/display.h"
|
#include "display/display.h"
|
||||||
|
|
||||||
texture_t *TEXTURE_BOUND = NULL;
|
|
||||||
|
|
||||||
errorret_t textureInit(
|
errorret_t textureInit(
|
||||||
texture_t *texture,
|
texture_t *texture,
|
||||||
const int32_t width,
|
const int32_t width,
|
||||||
@@ -25,6 +23,18 @@ errorret_t textureInit(
|
|||||||
assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2.");
|
assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2.");
|
||||||
assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2.");
|
assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2.");
|
||||||
|
|
||||||
|
if(texture->format == TEXTURE_FORMAT_RGBA) {
|
||||||
|
assertNotNull(data.rgbaColors, "RGBA color data cannot be NULL");
|
||||||
|
} else if(texture->format == TEXTURE_FORMAT_PALETTE) {
|
||||||
|
assertNotNull(data.paletted.indices, "Palette indices cannot be NULL");
|
||||||
|
assertNotNull(data.paletted.palette, "Palette colors cannot be NULL");
|
||||||
|
assertTrue(
|
||||||
|
data.paletted.palette->count ==
|
||||||
|
mathNextPowTwo(data.paletted.palette->count),
|
||||||
|
"Palette color count must be a power of 2"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
memoryZero(texture, sizeof(texture_t));
|
memoryZero(texture, sizeof(texture_t));
|
||||||
texture->width = width;
|
texture->width = width;
|
||||||
texture->height = height;
|
texture->height = height;
|
||||||
@@ -34,18 +44,9 @@ errorret_t textureInit(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t textureBind(texture_t *texture) {
|
|
||||||
errorChain(textureBindPlatform(texture));
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t textureDispose(texture_t *texture) {
|
errorret_t textureDispose(texture_t *texture) {
|
||||||
assertNotNull(texture, "Texture cannot be NULL");
|
assertNotNull(texture, "Texture cannot be NULL");
|
||||||
|
|
||||||
if(TEXTURE_BOUND == texture) {
|
|
||||||
textureBind(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorChain(textureDisposePlatform(texture));
|
errorChain(textureDisposePlatform(texture));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "display/color.h"
|
#include "display/texture/palette.h"
|
||||||
#include "display/texture/textureplatform.h"
|
#include "display/texture/textureplatform.h"
|
||||||
|
|
||||||
#ifndef textureInitPlatform
|
#ifndef textureInitPlatform
|
||||||
#error "textureInitPlatform should not be defined."
|
#error "textureInitPlatform should not be defined."
|
||||||
#endif
|
#endif
|
||||||
#ifndef textureBindPlatform
|
|
||||||
#error "textureBindPlatform should not be defined."
|
|
||||||
#endif
|
|
||||||
#ifndef textureDisposePlatform
|
#ifndef textureDisposePlatform
|
||||||
#error "textureDisposePlatform should not be defined."
|
#error "textureDisposePlatform should not be defined."
|
||||||
#endif
|
#endif
|
||||||
@@ -24,12 +21,13 @@ typedef textureformatplatform_t textureformat_t;
|
|||||||
typedef textureplatform_t texture_t;
|
typedef textureplatform_t texture_t;
|
||||||
|
|
||||||
typedef union texturedata_u {
|
typedef union texturedata_u {
|
||||||
uint8_t *paletteData;
|
struct {
|
||||||
|
uint8_t *indices;
|
||||||
|
palette_t *palette;
|
||||||
|
} paletted;
|
||||||
color_t *rgbaColors;
|
color_t *rgbaColors;
|
||||||
} texturedata_t;
|
} texturedata_t;
|
||||||
|
|
||||||
extern texture_t *TEXTURE_BOUND;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a texture.
|
* Initializes a texture.
|
||||||
*
|
*
|
||||||
@@ -47,13 +45,6 @@ errorret_t textureInit(
|
|||||||
const texturedata_t data
|
const texturedata_t data
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a texture for rendering. Providing NULL will unbind any texture.
|
|
||||||
*
|
|
||||||
* @param texture The texture to bind.
|
|
||||||
*/
|
|
||||||
errorret_t textureBind(texture_t *texture);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes a texture.
|
* Disposes a texture.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
# Copyright (c) 2025 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
ENTITY_DIR_SOUTH = 0
|
|
||||||
ENTITY_DIR_WEST = 1
|
|
||||||
ENTITY_DIR_EAST = 2
|
|
||||||
ENTITY_DIR_NORTH = 3
|
|
||||||
|
|
||||||
ENTITY_COUNT = 128
|
|
||||||
|
|
||||||
ENTITY_TYPE_NULL = 0
|
|
||||||
ENTITY_TYPE_PLAYER = 1
|
|
||||||
ENTITY_TYPE_NPC = 2
|
|
||||||
ENTITY_TYPE_COUNT = 3
|
|
||||||
|
|
||||||
CHUNK_WIDTH = 16
|
|
||||||
CHUNK_HEIGHT = 16
|
|
||||||
CHUNK_DEPTH = 4
|
|
||||||
# CHUNK_VERTEX_COUNT_MAX = QUAD_VERTEXES * CHUNK_WIDTH * CHUNK_HEIGHT * 4
|
|
||||||
CHUNK_VERTEX_COUNT_MAX=6144
|
|
||||||
CHUNK_MESH_COUNT_MAX = 14
|
|
||||||
CHUNK_ENTITY_COUNT_MAX = 8
|
|
||||||
|
|
||||||
TILE_WIDTH = 16.0
|
|
||||||
TILE_HEIGHT = 16.0
|
|
||||||
TILE_DEPTH = 16.0
|
|
||||||
|
|
||||||
TILE_SHAPE_NULL = 0
|
|
||||||
TILE_SHAPE_FLOOR = 1
|
|
||||||
TILE_SHAPE_RAMP_SOUTH = 2
|
|
||||||
TILE_SHAPE_RAMP_WEST = 3
|
|
||||||
TILE_SHAPE_RAMP_EAST = 4
|
|
||||||
TILE_SHAPE_RAMP_NORTH = 5
|
|
||||||
TILE_SHAPE_RAMP_SOUTHWEST = 6
|
|
||||||
TILE_SHAPE_RAMP_SOUTHEAST = 7
|
|
||||||
TILE_SHAPE_RAMP_NORTHWEST = 8
|
|
||||||
TILE_SHAPE_RAMP_NORTHEAST = 9
|
|
||||||
|
|
||||||
RPG_CAMERA_FOV = 70
|
|
||||||
RPG_CAMERA_PIXELS_PER_UNIT = 1.0
|
|
||||||
RPG_CAMERA_Z_OFFSET = 24.0
|
|
||||||
|
|
||||||
ASSET_LANG_CHUNK_CHAR_COUNT = 6144
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "debug/debug.h"
|
#include "log/log.h"
|
||||||
|
|
||||||
errorstate_t ERROR_STATE = { 0 };
|
errorstate_t ERROR_STATE = { 0 };
|
||||||
|
|
||||||
@@ -125,12 +125,11 @@ errorret_t errorPrint(const errorret_t retval) {
|
|||||||
assertNotNull(retval.state, "Error state cannot be NULL");
|
assertNotNull(retval.state, "Error state cannot be NULL");
|
||||||
assertNotNull(retval.state->message, "Message cannot be NULL");
|
assertNotNull(retval.state->message, "Message cannot be NULL");
|
||||||
|
|
||||||
debugPrint(
|
logError(
|
||||||
ERROR_PRINT_FORMAT,
|
ERROR_PRINT_FORMAT,
|
||||||
retval.state->code,
|
retval.state->code,
|
||||||
retval.state->message,
|
retval.state->message,
|
||||||
retval.state->lines
|
retval.state->lines
|
||||||
);
|
);
|
||||||
debugFlush();
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
|
|
||||||
input_t INPUT;
|
input_t INPUT;
|
||||||
|
|
||||||
@@ -24,10 +23,6 @@ errorret_t inputInit(void) {
|
|||||||
INPUT.actions[i].currentValue = 0.0f;
|
INPUT.actions[i].currentValue = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DUSK_INPUT_GAMEPAD
|
|
||||||
INPUT.deadzone = 0.2f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef inputInitPlatform
|
#ifdef inputInitPlatform
|
||||||
errorChain(inputInitPlatform());
|
errorChain(inputInitPlatform());
|
||||||
#endif
|
#endif
|
||||||
@@ -196,3 +191,8 @@ void inputBind(const inputbutton_t button, const inputaction_t act) {
|
|||||||
// Bind the action.
|
// Bind the action.
|
||||||
data->action = act;
|
data->action = act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float_t inputDeadzone(const float_t rawValue, const float_t deadzone) {
|
||||||
|
if(rawValue < deadzone) return 0.0f;
|
||||||
|
return (rawValue - deadzone) / (1.0f - deadzone);
|
||||||
|
}
|
||||||
@@ -27,10 +27,6 @@ typedef struct {
|
|||||||
event_t eventReleased;
|
event_t eventReleased;
|
||||||
|
|
||||||
inputplatform_t platform;
|
inputplatform_t platform;
|
||||||
|
|
||||||
#ifdef DUSK_INPUT_GAMEPAD
|
|
||||||
float_t deadzone;
|
|
||||||
#endif
|
|
||||||
} input_t;
|
} input_t;
|
||||||
|
|
||||||
extern input_t INPUT;
|
extern input_t INPUT;
|
||||||
@@ -131,3 +127,14 @@ float_t inputAxis(const inputaction_t neg, const inputaction_t pos);
|
|||||||
* @param action The input action to bind the button to.
|
* @param action The input action to bind the button to.
|
||||||
*/
|
*/
|
||||||
void inputBind(const inputbutton_t button, const inputaction_t act);
|
void inputBind(const inputbutton_t button, const inputaction_t act);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies deadzone formula to a raw input value. This will;
|
||||||
|
* return 0 if input is less than the deadzone.
|
||||||
|
* re-map the range between 0 and 1 in deadzone-space.
|
||||||
|
*
|
||||||
|
* @param rawValue The raw input value to apply the deadzone to.
|
||||||
|
* @param deadzone The deadzone threshold (0.0f to 1.0f).
|
||||||
|
* @return The input value after applying the deadzone.
|
||||||
|
*/
|
||||||
|
float_t inputDeadzone(const float_t rawValue, const float_t deadzone);
|
||||||
@@ -14,9 +14,13 @@
|
|||||||
* @param message The message format string.
|
* @param message The message format string.
|
||||||
* @param ... Additional arguments for the format string.
|
* @param ... Additional arguments for the format string.
|
||||||
*/
|
*/
|
||||||
void debugPrint(const char_t *message, ...);
|
void logDebug(const char_t *message, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flushes the debug output buffer.
|
* Prints a message to the error console. For some platforms this will pause
|
||||||
|
* the program.
|
||||||
|
*
|
||||||
|
* @param message The message format string.
|
||||||
|
* @param ... Additional arguments for the format string.
|
||||||
*/
|
*/
|
||||||
void debugFlush();
|
void logError(const char_t *message, ...);
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "debug/debug.h"
|
#include "log/log.h"
|
||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "display/camera/camera.h"
|
#include "display/camera/camera.h"
|
||||||
#include "display/screen/screen.h"
|
#include "display/screen/screen.h"
|
||||||
@@ -22,7 +22,7 @@ errorret_t sceneInit(void) {
|
|||||||
|
|
||||||
errorret_t sceneUpdate(void) {
|
errorret_t sceneUpdate(void) {
|
||||||
#ifdef DUSK_TIME_DYNAMIC
|
#ifdef DUSK_TIME_DYNAMIC
|
||||||
if(!TIME.dynamicUpdate) {
|
if(TIME.dynamicUpdate) {
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -84,8 +84,7 @@ void sceneDispose(void) {
|
|||||||
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
|
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
|
||||||
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
|
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
|
||||||
lua_pop(SCENE.scriptContext.luaState, 1);
|
lua_pop(SCENE.scriptContext.luaState, 1);
|
||||||
debugPrint("Failed to call function '%s': %s\n", "sceneDispose", strErr);
|
logDebug("Failed to call function '%s': %s\n", "sceneDispose", strErr);
|
||||||
debugFlush();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lua_pop(SCENE.scriptContext.luaState, 1);
|
lua_pop(SCENE.scriptContext.luaState, 1);
|
||||||
|
|||||||
@@ -7,11 +7,8 @@
|
|||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(event)
|
add_subdirectory(event)
|
||||||
add_subdirectory(input)
|
add_subdirectory(input)
|
||||||
add_subdirectory(item)
|
|
||||||
add_subdirectory(locale)
|
add_subdirectory(locale)
|
||||||
add_subdirectory(map)
|
|
||||||
add_subdirectory(system)
|
add_subdirectory(system)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
add_subdirectory(story)
|
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
@@ -15,4 +15,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
modulescreen.c
|
modulescreen.c
|
||||||
moduletileset.c
|
moduletileset.c
|
||||||
moduletexture.c
|
moduletexture.c
|
||||||
|
moduleshader.c
|
||||||
)
|
)
|
||||||
@@ -69,8 +69,16 @@ void moduleCamera(scriptcontext_t *context) {
|
|||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
|
lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
|
||||||
lua_register(context->luaState, "cameraPushMatrix", moduleCameraPushMatrix);
|
lua_register(
|
||||||
lua_register(context->luaState, "cameraPopMatrix", moduleCameraPopMatrix);
|
context->luaState,
|
||||||
|
"cameraGetProjectionMatrix",
|
||||||
|
moduleCameraGetProjectionMatrix
|
||||||
|
);
|
||||||
|
lua_register(
|
||||||
|
context->luaState,
|
||||||
|
"cameraGetViewMatrix",
|
||||||
|
moduleCameraGetViewMatrix
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleCameraCreate(lua_State *L) {
|
int moduleCameraCreate(lua_State *L) {
|
||||||
@@ -118,25 +126,6 @@ int moduleCameraCreate(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleCameraPushMatrix(lua_State *L) {
|
|
||||||
assertNotNull(L, "Lua state cannot be NULL.");
|
|
||||||
assertTrue(lua_gettop(L) >= 1, "cameraPushMatrix requires 1 arg.");
|
|
||||||
assertTrue(lua_isuserdata(L, 1), "cameraPushMatrix arg must be userdata.");
|
|
||||||
|
|
||||||
// Camera should be provided (pointer to camera_t).
|
|
||||||
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
|
|
||||||
assertNotNull(cam, "Camera pointer cannot be NULL.");
|
|
||||||
|
|
||||||
cameraPushMatrix(cam);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int moduleCameraPopMatrix(lua_State *L) {
|
|
||||||
assertNotNull(L, "Lua state cannot be NULL.");
|
|
||||||
cameraPopMatrix();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int moduleCameraIndex(lua_State *l) {
|
int moduleCameraIndex(lua_State *l) {
|
||||||
assertNotNull(l, "Lua state cannot be NULL.");
|
assertNotNull(l, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
@@ -310,3 +299,35 @@ int moduleCameraNewIndex(lua_State *l) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int moduleCameraGetProjectionMatrix(lua_State *L) {
|
||||||
|
assertNotNull(L, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
|
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
|
||||||
|
assertNotNull(cam, "Camera pointer cannot be NULL.");
|
||||||
|
|
||||||
|
// Create mat4
|
||||||
|
mat4 test;
|
||||||
|
cameraGetProjectionMatrix(cam, test);
|
||||||
|
|
||||||
|
// Lua needs to own this matrix now
|
||||||
|
mat4 *m = (mat4 *)lua_newuserdata(L, sizeof(mat4));
|
||||||
|
memoryCopy(m, test, sizeof(mat4));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int moduleCameraGetViewMatrix(lua_State *L) {
|
||||||
|
assertNotNull(L, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
|
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
|
||||||
|
assertNotNull(cam, "Camera pointer cannot be NULL.");
|
||||||
|
|
||||||
|
// Create mat4
|
||||||
|
mat4 test;
|
||||||
|
cameraGetViewMatrix(cam, test);
|
||||||
|
|
||||||
|
// Lua needs to own this matrix now
|
||||||
|
mat4 *m = (mat4 *)lua_newuserdata(L, sizeof(mat4));
|
||||||
|
memoryCopy(m, test, sizeof(mat4));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -23,22 +23,6 @@ void moduleCamera(scriptcontext_t *context);
|
|||||||
*/
|
*/
|
||||||
int moduleCameraCreate(lua_State *L);
|
int moduleCameraCreate(lua_State *L);
|
||||||
|
|
||||||
/**
|
|
||||||
* Script binding for pushing the camera matrix onto the matrix stack.
|
|
||||||
*
|
|
||||||
* @param L The Lua state.
|
|
||||||
* @return Number of return values on the Lua stack.
|
|
||||||
*/
|
|
||||||
int moduleCameraPushMatrix(lua_State *L);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Script binding for popping the camera matrix from the matrix stack.
|
|
||||||
*
|
|
||||||
* @param L The Lua state.
|
|
||||||
* @return Number of return values on the Lua stack.
|
|
||||||
*/
|
|
||||||
int moduleCameraPopMatrix(lua_State *L);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for camera structure fields.
|
* Getter for camera structure fields.
|
||||||
*
|
*
|
||||||
@@ -52,3 +36,19 @@ int moduleCameraIndex(lua_State *l);
|
|||||||
* @param l The Lua state.
|
* @param l The Lua state.
|
||||||
*/
|
*/
|
||||||
int moduleCameraNewIndex(lua_State *l);
|
int moduleCameraNewIndex(lua_State *l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for getting a camera's projection matrix.
|
||||||
|
*
|
||||||
|
* @param L The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleCameraGetProjectionMatrix(lua_State *L);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for getting a camera's view matrix.
|
||||||
|
*
|
||||||
|
* @param L The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleCameraGetViewMatrix(lua_State *L);
|
||||||
120
src/dusk/script/module/display/moduleshader.c
Normal file
120
src/dusk/script/module/display/moduleshader.c
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "moduleshader.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "display/shader/shader.h"
|
||||||
|
#include "display/shader/shaderunlit.h"
|
||||||
|
#include "display/camera/camera.h"
|
||||||
|
|
||||||
|
void moduleShader(scriptcontext_t *context) {
|
||||||
|
assertNotNull(context, "Context cannot be NULL.");
|
||||||
|
|
||||||
|
// Shader unlit defs
|
||||||
|
lua_pushlightuserdata(context->luaState, &SHADER_UNLIT);
|
||||||
|
lua_setglobal(context->luaState, "SHADER_UNLIT");
|
||||||
|
|
||||||
|
lua_pushstring(context->luaState, SHADER_UNLIT_PROJECTION);
|
||||||
|
lua_setglobal(context->luaState, "SHADER_UNLIT_PROJECTION");
|
||||||
|
lua_pushstring(context->luaState, SHADER_UNLIT_VIEW);
|
||||||
|
lua_setglobal(context->luaState, "SHADER_UNLIT_VIEW");
|
||||||
|
lua_pushstring(context->luaState, SHADER_UNLIT_MODEL);
|
||||||
|
lua_setglobal(context->luaState, "SHADER_UNLIT_MODEL");
|
||||||
|
lua_pushstring(context->luaState, SHADER_UNLIT_TEXTURE);
|
||||||
|
lua_setglobal(context->luaState, "SHADER_UNLIT_TEXTURE");
|
||||||
|
|
||||||
|
// Shader methods
|
||||||
|
lua_register(context->luaState, "shaderBind", moduleShaderBind);
|
||||||
|
lua_register(context->luaState, "shaderSetMatrix", moduleShaderSetMatrix);
|
||||||
|
lua_register(context->luaState, "shaderSetTexture", moduleShaderSetTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
int moduleShaderBind(lua_State *l) {
|
||||||
|
assertNotNull(l, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
|
// Should be passed a shader userdata pointer only.
|
||||||
|
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
|
||||||
|
assertNotNull(shader, "Shader pointer cannot be NULL.");
|
||||||
|
|
||||||
|
errorret_t ret = shaderBind(shader);
|
||||||
|
if(ret.code != ERROR_OK) {
|
||||||
|
luaL_error(l, "Failed to bind shader: %s", ret.state->message);
|
||||||
|
errorCatch(errorPrint(ret));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int moduleShaderSetMatrix(lua_State *l) {
|
||||||
|
assertNotNull(l, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
|
// Expect shader, string and matrix.
|
||||||
|
if(!lua_isuserdata(l, 1)) {
|
||||||
|
luaL_error(l, "First argument must be a shader_mt userdata.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!lua_isstring(l, 2)) {
|
||||||
|
luaL_error(l, "Second argument must be a string.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!lua_isuserdata(l, 3)) {
|
||||||
|
luaL_error(l, "Third argument must be a mat4_mt userdata.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
|
||||||
|
assertNotNull(shader, "Shader pointer cannot be NULL.");
|
||||||
|
|
||||||
|
const char_t *uniformName = luaL_checkstring(l, 2);
|
||||||
|
assertStrLenMin(uniformName, 1, "Uniform name cannot be empty.");
|
||||||
|
|
||||||
|
mat4 *mat = (mat4 *)lua_touserdata(l, 3);
|
||||||
|
assertNotNull(mat, "Matrix pointer cannot be NULL.");
|
||||||
|
|
||||||
|
errorret_t ret = shaderSetMatrix(shader, uniformName, *mat);
|
||||||
|
if(ret.code != ERROR_OK) {
|
||||||
|
luaL_error(l, "Failed to set shader matrix: %s", ret.state->message);
|
||||||
|
errorCatch(errorPrint(ret));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int moduleShaderSetTexture(lua_State *l) {
|
||||||
|
assertNotNull(l, "Lua state cannot be NULL.");
|
||||||
|
|
||||||
|
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
|
||||||
|
assertNotNull(shader, "Shader pointer cannot be NULL.");
|
||||||
|
|
||||||
|
const char_t *uniformName = luaL_checkstring(l, 2);
|
||||||
|
assertStrLenMin(uniformName, 1, "Uniform name cannot be empty.");
|
||||||
|
|
||||||
|
texture_t *texture;
|
||||||
|
// Texture can be Nil or a pointer, if not nil it must be a texture pointer.
|
||||||
|
if(lua_isnil(l, 3)) {
|
||||||
|
texture = NULL;
|
||||||
|
} else if(lua_isuserdata(l, 3)) {
|
||||||
|
texture = (texture_t *)lua_touserdata(l, 3);
|
||||||
|
assertNotNull(texture, "Texture pointer cannot be NULL.");
|
||||||
|
} else {
|
||||||
|
luaL_error(l, "Third argument must be a texture_mt userdata or nil.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t ret = shaderSetTexture(shader, uniformName, texture);
|
||||||
|
if(ret.code != ERROR_OK) {
|
||||||
|
luaL_error(l, "Failed to set shader texture: %s", ret.state->message);
|
||||||
|
errorCatch(errorPrint(ret));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
42
src/dusk/script/module/display/moduleshader.h
Normal file
42
src/dusk/script/module/display/moduleshader.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "script/scriptcontext.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register shader functions to the given script context.
|
||||||
|
*
|
||||||
|
* @param context The script context to register shader functions to.
|
||||||
|
*/
|
||||||
|
void moduleShader(scriptcontext_t *context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for binding a shader.
|
||||||
|
*
|
||||||
|
* @param l The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleShaderBind(lua_State *l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for setting a matrix uniform in a shader.
|
||||||
|
*
|
||||||
|
* @param l The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleShaderSetMatrix(lua_State *l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for setting a texture uniform in a shader.
|
||||||
|
*
|
||||||
|
* @param l The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleShaderSetTexture(lua_State *l);
|
||||||
|
|
||||||
|
errorret_t doThing();
|
||||||
@@ -32,32 +32,20 @@ int moduleSpriteBatchClear(lua_State *L) {
|
|||||||
int moduleSpriteBatchPush(lua_State *L) {
|
int moduleSpriteBatchPush(lua_State *L) {
|
||||||
assertNotNull(L, "Lua state is null");
|
assertNotNull(L, "Lua state is null");
|
||||||
|
|
||||||
// Texture pointer or Nil for no texture
|
|
||||||
if(!lua_isuserdata(L, 1) && !lua_isnil(L, 1)) {
|
|
||||||
return luaL_error(L, "First argument must be a texture or nil");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If texture is not nil, check it's a texture userdata
|
|
||||||
texture_t *tex = NULL;
|
|
||||||
if(lua_isuserdata(L, 1)) {
|
|
||||||
tex = (texture_t *)luaL_checkudata(L, 1, "texture_mt");
|
|
||||||
assertNotNull(tex, "Texture pointer cannot be NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
// MinX, MinY, MaxX, MaxY
|
// MinX, MinY, MaxX, MaxY
|
||||||
if(
|
if(
|
||||||
!lua_isnumber(L, 2) || !lua_isnumber(L, 3) || !lua_isnumber(L, 4) ||
|
!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3) ||
|
||||||
!lua_isnumber(L, 5)
|
!lua_isnumber(L, 4)
|
||||||
) {
|
) {
|
||||||
return luaL_error(L, "Sprite coordinates must be numbers");
|
return luaL_error(L, "Sprite coordinates must be numbers");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color (struct) or nil for white
|
// Color (struct) or nil for white
|
||||||
color_t *color = NULL;
|
color_t *color = NULL;
|
||||||
if(lua_gettop(L) < 6 || lua_isnil(L, 6)) {
|
if(lua_gettop(L) < 5 || lua_isnil(L, 5)) {
|
||||||
// Allow NULL
|
// Allow NULL
|
||||||
} else if(lua_isuserdata(L, 6)) {
|
} else if(lua_isuserdata(L, 5)) {
|
||||||
color = (color_t*)luaL_checkudata(L, 6, "color_mt");
|
color = (color_t*)luaL_checkudata(L, 5, "color_mt");
|
||||||
} else {
|
} else {
|
||||||
return luaL_error(L, "Sprite color must be a color struct or nil");
|
return luaL_error(L, "Sprite color must be a color struct or nil");
|
||||||
}
|
}
|
||||||
@@ -68,31 +56,30 @@ int moduleSpriteBatchPush(lua_State *L) {
|
|||||||
float_t u1 = 1.0f;
|
float_t u1 = 1.0f;
|
||||||
float_t v1 = 1.0f;
|
float_t v1 = 1.0f;
|
||||||
|
|
||||||
if(lua_gettop(L) >= 8) {
|
if(lua_gettop(L) >= 7) {
|
||||||
if(!lua_isnumber(L, 7) || !lua_isnumber(L, 8)) {
|
if(!lua_isnumber(L, 6) || !lua_isnumber(L, 7)) {
|
||||||
return luaL_error(L, "Sprite UV min coordinates must be numbers");
|
return luaL_error(L, "Sprite UV min coordinates must be numbers");
|
||||||
}
|
}
|
||||||
|
|
||||||
u0 = (float_t)lua_tonumber(L, 7);
|
u0 = (float_t)lua_tonumber(L, 6);
|
||||||
v0 = (float_t)lua_tonumber(L, 8);
|
v0 = (float_t)lua_tonumber(L, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lua_gettop(L) >= 10) {
|
if(lua_gettop(L) >= 9) {
|
||||||
if(!lua_isnumber(L, 9) || !lua_isnumber(L, 10)) {
|
if(!lua_isnumber(L, 8) || !lua_isnumber(L, 9)) {
|
||||||
return luaL_error(L, "Sprite UV max coordinates must be numbers");
|
return luaL_error(L, "Sprite UV max coordinates must be numbers");
|
||||||
}
|
}
|
||||||
|
|
||||||
u1 = (float_t)lua_tonumber(L, 9);
|
u1 = (float_t)lua_tonumber(L, 8);
|
||||||
v1 = (float_t)lua_tonumber(L, 10);
|
v1 = (float_t)lua_tonumber(L, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t minX = (float_t)lua_tonumber(L, 2);
|
float_t minX = (float_t)lua_tonumber(L, 1);
|
||||||
float_t minY = (float_t)lua_tonumber(L, 3);
|
float_t minY = (float_t)lua_tonumber(L, 2);
|
||||||
float_t maxX = (float_t)lua_tonumber(L, 4);
|
float_t maxX = (float_t)lua_tonumber(L, 3);
|
||||||
float_t maxY = (float_t)lua_tonumber(L, 5);
|
float_t maxY = (float_t)lua_tonumber(L, 4);
|
||||||
|
|
||||||
spriteBatchPush(
|
errorret_t ret = spriteBatchPush(
|
||||||
tex,
|
|
||||||
minX,
|
minX,
|
||||||
minY,
|
minY,
|
||||||
maxX,
|
maxX,
|
||||||
@@ -103,6 +90,14 @@ int moduleSpriteBatchPush(lua_State *L) {
|
|||||||
u1,
|
u1,
|
||||||
v1
|
v1
|
||||||
);
|
);
|
||||||
|
if(ret.code != ERROR_OK) {
|
||||||
|
int err = luaL_error(L,
|
||||||
|
"Failed to push sprite to batch: %s",
|
||||||
|
ret.state->message
|
||||||
|
);
|
||||||
|
errorCatch(errorPrint(ret));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
#include "display/texture/tileset.h"
|
#include "display/texture/tileset.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
|
|
||||||
void moduleTileset(scriptcontext_t *ctx) {
|
void moduleTileset(scriptcontext_t *ctx) {
|
||||||
assertNotNull(ctx, "Script context cannot be NULL");
|
assertNotNull(ctx, "Script context cannot be NULL");
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ void moduleInput(scriptcontext_t *context) {
|
|||||||
lua_register(context->luaState, "inputPressed", moduleInputPressed);
|
lua_register(context->luaState, "inputPressed", moduleInputPressed);
|
||||||
lua_register(context->luaState, "inputReleased", moduleInputReleased);
|
lua_register(context->luaState, "inputReleased", moduleInputReleased);
|
||||||
lua_register(context->luaState, "inputGetValue", moduleInputGetValue);
|
lua_register(context->luaState, "inputGetValue", moduleInputGetValue);
|
||||||
|
lua_register(context->luaState, "inputAxis", moduleInputAxis);
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleInputIndex(lua_State *l) {
|
int moduleInputIndex(lua_State *l) {
|
||||||
@@ -190,3 +191,27 @@ int moduleInputGetValue(lua_State *L) {
|
|||||||
lua_pushnumber(L, inputGetCurrentValue(action));
|
lua_pushnumber(L, inputGetCurrentValue(action));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int moduleInputAxis(lua_State *L) {
|
||||||
|
assertNotNull(L, "Lua state cannot be NULL");
|
||||||
|
|
||||||
|
if(!lua_isnumber(L, 1) || !lua_isnumber(L, 2)) {
|
||||||
|
luaL_error(L, "inputAxis: Expected two action IDs as arguments (neg, pos)");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputaction_t neg = (inputaction_t)lua_tonumber(L, 1);
|
||||||
|
const inputaction_t pos = (inputaction_t)lua_tonumber(L, 2);
|
||||||
|
|
||||||
|
if(neg < INPUT_ACTION_NULL || neg >= INPUT_ACTION_COUNT) {
|
||||||
|
luaL_error(L, "inputAxis: Invalid negative action ID %d", neg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(pos < INPUT_ACTION_NULL || pos >= INPUT_ACTION_COUNT) {
|
||||||
|
luaL_error(L, "inputAxis: Invalid positive action ID %d", pos);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushnumber(L, inputAxis(neg, pos));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -61,3 +61,11 @@ int moduleInputReleased(lua_State *L);
|
|||||||
* @return Number of return values on the Lua stack.
|
* @return Number of return values on the Lua stack.
|
||||||
*/
|
*/
|
||||||
int moduleInputGetValue(lua_State *L);
|
int moduleInputGetValue(lua_State *L);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script binding for inputAxis.
|
||||||
|
*
|
||||||
|
* @param L The Lua state.
|
||||||
|
* @return Number of return values on the Lua stack.
|
||||||
|
*/
|
||||||
|
int moduleInputAxis(lua_State *L);
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modulesystem.h"
|
#include "modulesystem.h"
|
||||||
#include "debug/debug.h"
|
#include "log/log.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "script/scriptmodule.h"
|
#include "script/scriptmodule.h"
|
||||||
@@ -36,8 +36,7 @@ int moduleSysPrint(lua_State *L) {
|
|||||||
|
|
||||||
luaL_pushresult(&b);
|
luaL_pushresult(&b);
|
||||||
const char *msg = lua_tostring(L, -1);
|
const char *msg = lua_tostring(L, -1);
|
||||||
debugPrint("%s\n", msg);
|
logDebug("%s\n", msg);
|
||||||
debugFlush();
|
|
||||||
return 0; // no values returned to Lua
|
return 0; // no values returned to Lua
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
#include "script/scriptmodule.h"
|
#include "script/scriptmodule.h"
|
||||||
#include "event/event.h"
|
#include "event/event.h"
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "scriptmanager.h"
|
#include "scriptmanager.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
|
|
||||||
scriptmanager_t SCRIPT_MANAGER;
|
scriptmanager_t SCRIPT_MANAGER;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include "script/module/input/moduleinput.h"
|
#include "script/module/input/moduleinput.h"
|
||||||
#include "script/module/moduleplatform.h"
|
#include "script/module/moduleplatform.h"
|
||||||
#include "script/module/scene/modulescene.h"
|
#include "script/module/scene/modulescene.h"
|
||||||
#include "script/module/item/moduleitem.h"
|
|
||||||
#include "script/module/locale/modulelocale.h"
|
#include "script/module/locale/modulelocale.h"
|
||||||
#include "script/module/time/moduletime.h"
|
#include "script/module/time/moduletime.h"
|
||||||
#include "script/module/event/moduleevent.h"
|
#include "script/module/event/moduleevent.h"
|
||||||
@@ -18,13 +17,13 @@
|
|||||||
#include "script/module/display/modulespritebatch.h"
|
#include "script/module/display/modulespritebatch.h"
|
||||||
#include "script/module/display/modulecamera.h"
|
#include "script/module/display/modulecamera.h"
|
||||||
#include "script/module/display/moduleglm.h"
|
#include "script/module/display/moduleglm.h"
|
||||||
|
#include "script/module/display/moduleshader.h"
|
||||||
#include "script/module/ui/moduleui.h"
|
#include "script/module/ui/moduleui.h"
|
||||||
#include "script/module/display/moduletext.h"
|
#include "script/module/display/moduletext.h"
|
||||||
#include "script/module/display/modulescreen.h"
|
#include "script/module/display/modulescreen.h"
|
||||||
#include "script/module/story/modulestoryflag.h"
|
|
||||||
#include "script/module/map/modulemap.h"
|
|
||||||
#include "script/module/display/moduletexture.h"
|
#include "script/module/display/moduletexture.h"
|
||||||
#include "script/module/display/moduletileset.h"
|
#include "script/module/display/moduletileset.h"
|
||||||
|
#include "script/scriptgame.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
||||||
@@ -33,7 +32,6 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
|||||||
{ .name = "platform", .callback = modulePlatform },
|
{ .name = "platform", .callback = modulePlatform },
|
||||||
{ .name = "color", .callback = moduleColor },
|
{ .name = "color", .callback = moduleColor },
|
||||||
{ .name = "scene", .callback = moduleScene },
|
{ .name = "scene", .callback = moduleScene },
|
||||||
{ .name = "item", .callback = moduleItem },
|
|
||||||
{ .name = "locale", .callback = moduleLocale },
|
{ .name = "locale", .callback = moduleLocale },
|
||||||
{ .name = "time", .callback = moduleTime },
|
{ .name = "time", .callback = moduleTime },
|
||||||
{ .name = "event", .callback = moduleEvent },
|
{ .name = "event", .callback = moduleEvent },
|
||||||
@@ -43,10 +41,13 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
|||||||
{ .name = "ui", .callback = moduleUi },
|
{ .name = "ui", .callback = moduleUi },
|
||||||
{ .name = "text", .callback = moduleText },
|
{ .name = "text", .callback = moduleText },
|
||||||
{ .name = "screen", .callback = moduleScreen },
|
{ .name = "screen", .callback = moduleScreen },
|
||||||
{ .name = "storyflag", .callback = moduleStoryFlag },
|
|
||||||
{ .name = "map", .callback = moduleMap },
|
|
||||||
{ .name = "texture", .callback = moduleTexture },
|
{ .name = "texture", .callback = moduleTexture },
|
||||||
{ .name = "tileset", .callback = moduleTileset },
|
{ .name = "tileset", .callback = moduleTileset },
|
||||||
|
{ .name = "shader", .callback = moduleShader },
|
||||||
|
|
||||||
|
#ifdef SCRIPT_GAME_LIST
|
||||||
|
SCRIPT_GAME_LIST
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCRIPT_MODULE_COUNT ( \
|
#define SCRIPT_MODULE_COUNT ( \
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
#include "display/screen/screen.h"
|
#include "display/screen/screen.h"
|
||||||
#include "debug/debug.h"
|
|
||||||
|
|
||||||
ui_t UI;
|
ui_t UI;
|
||||||
|
|
||||||
@@ -31,11 +30,11 @@ void uiRender(void) {
|
|||||||
UI.camera.orthographic.right = SCREEN.width;
|
UI.camera.orthographic.right = SCREEN.width;
|
||||||
UI.camera.orthographic.top = SCREEN.height;
|
UI.camera.orthographic.top = SCREEN.height;
|
||||||
|
|
||||||
cameraPushMatrix(&UI.camera);
|
// cameraPushMatrix(&UI.camera);
|
||||||
spriteBatchClear();
|
spriteBatchClear();
|
||||||
|
|
||||||
spriteBatchFlush();
|
spriteBatchFlush();
|
||||||
cameraPopMatrix();
|
// cameraPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDispose(void) {
|
void uiDispose(void) {
|
||||||
|
|||||||
@@ -229,3 +229,10 @@ bool_t stringEndsWithCaseInsensitive(
|
|||||||
if(suffixLen > strLen) return false;
|
if(suffixLen > strLen) return false;
|
||||||
return strcasecmp(str + strLen - suffixLen, suffix) == 0;
|
return strcasecmp(str + strLen - suffixLen, suffix) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool_t stringIncludesString(const char_t *haystack, const char_t *needle) {
|
||||||
|
assertNotNull(haystack, "haystack must not be NULL");
|
||||||
|
assertNotNull(needle, "needle must not be NULL");
|
||||||
|
|
||||||
|
return strstr(haystack, needle) != NULL;
|
||||||
|
}
|
||||||
@@ -161,3 +161,12 @@ bool_t stringEndsWith(const char_t *str, const char_t *suffix);
|
|||||||
* @return TRUE if the string ends with the suffix, FALSE otherwise.
|
* @return TRUE if the string ends with the suffix, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
bool_t stringEndsWithCaseInsensitive(const char_t *str, const char_t *suffix);
|
bool_t stringEndsWithCaseInsensitive(const char_t *str, const char_t *suffix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a string includes a specified substring.
|
||||||
|
*
|
||||||
|
* @param haystack The string to check.
|
||||||
|
* @param needle The substring to check for.
|
||||||
|
* @return TRUE if the string includes the substring, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
bool_t stringIncludesString(const char_t *haystack, const char_t *needle);
|
||||||
@@ -16,6 +16,6 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
|||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(asset)
|
add_subdirectory(asset)
|
||||||
add_subdirectory(debug)
|
add_subdirectory(log)
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(input)
|
add_subdirectory(input)
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2026 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "debug/debug.h"
|
|
||||||
#include "display/display.h"
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
static char_t DEBUG_ERROR_BUFFER[16*1024] = {0};
|
|
||||||
|
|
||||||
void debugPrint(const char_t *message, ...) {
|
|
||||||
size_t start = strlen(DEBUG_ERROR_BUFFER);
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, message);
|
|
||||||
|
|
||||||
// Print to stdout
|
|
||||||
va_list copy;
|
|
||||||
va_copy(copy, args);
|
|
||||||
vfprintf(stdout, message, copy);
|
|
||||||
va_end(copy);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
// Append to buffer
|
|
||||||
// vsnprintf(
|
|
||||||
// DEBUG_ERROR_BUFFER + start,
|
|
||||||
// sizeof(DEBUG_ERROR_BUFFER) - start,
|
|
||||||
// message,
|
|
||||||
// args
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
void debugFlush() {
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
// Either create graphics, or hijack the displays' graphics.
|
|
||||||
// void *xfb = NULL;
|
|
||||||
// GXRModeObj *rmode = NULL;
|
|
||||||
// void *framebuffer;
|
|
||||||
|
|
||||||
// if(DISPLAY.frameBuffer[0]) {
|
|
||||||
// console_init(
|
|
||||||
// DISPLAY.frameBuffer[0],
|
|
||||||
// 20,
|
|
||||||
// 20,
|
|
||||||
// DISPLAY.screenMode->fbWidth,
|
|
||||||
// DISPLAY.screenMode->xfbHeight,
|
|
||||||
// DISPLAY.screenMode->fbWidth * VI_DISPLAY_PIX_SZ
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// VIDEO_Init();
|
|
||||||
// rmode = VIDEO_GetPreferredMode(NULL);
|
|
||||||
// framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
|
||||||
// console_init(
|
|
||||||
// framebuffer,
|
|
||||||
// 20,
|
|
||||||
// 20,
|
|
||||||
// rmode->fbWidth,
|
|
||||||
// rmode->xfbHeight,
|
|
||||||
// rmode->fbWidth*VI_DISPLAY_PIX_SZ
|
|
||||||
// );
|
|
||||||
// VIDEO_Configure(rmode);
|
|
||||||
// VIDEO_SetNextFramebuffer(framebuffer);
|
|
||||||
// VIDEO_SetBlack(FALSE);
|
|
||||||
// VIDEO_Flush();
|
|
||||||
// VIDEO_WaitVSync();
|
|
||||||
// if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Printf
|
|
||||||
// printf("SOB\n");
|
|
||||||
// printf(DEBUG_ERROR_BUFFER);
|
|
||||||
// printf("\nEOB.");
|
|
||||||
|
|
||||||
while(SYS_MainLoop()) {
|
|
||||||
VIDEO_WaitVSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,3 +15,4 @@ add_subdirectory(camera)
|
|||||||
add_subdirectory(framebuffer)
|
add_subdirectory(framebuffer)
|
||||||
add_subdirectory(mesh)
|
add_subdirectory(mesh)
|
||||||
add_subdirectory(texture)
|
add_subdirectory(texture)
|
||||||
|
add_subdirectory(shader)
|
||||||
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
void cameraPushMatrixDolphin(camera_t *camera) {
|
void cameraPushMatrixDolphin(camera_t *camera) {
|
||||||
assertNotNull(camera, "Camera cannot be null");
|
assertNotNull(camera, "Camera cannot be null");
|
||||||
|
assertTrue(
|
||||||
|
camera->nearClip > 0.0f,
|
||||||
|
"Camera near clip must be greater than 0 for Dolphin"
|
||||||
|
);
|
||||||
|
|
||||||
Mtx44 guProjection;
|
Mtx44 guProjection;
|
||||||
Mtx guView;
|
Mtx guView;
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ errorret_t displayInitDolphin(void) {
|
|||||||
|
|
||||||
// Setup cull modes
|
// Setup cull modes
|
||||||
GX_SetCullMode(GX_CULL_NONE);
|
GX_SetCullMode(GX_CULL_NONE);
|
||||||
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE);
|
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
|
||||||
|
GX_SetZMode(GX_TRUE, GX_ALWAYS, GX_FALSE);
|
||||||
GX_SetDispCopyGamma(GX_GM_1_0);
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||||
GX_SetColorUpdate(GX_TRUE);
|
GX_SetColorUpdate(GX_TRUE);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "display/mesh/mesh.h"
|
#include "display/mesh/mesh.h"
|
||||||
#include "display/texture/texture.h"
|
#include "display/texture/texture.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "debug/debug.h"
|
#include "display/shader/shader.h"
|
||||||
|
|
||||||
errorret_t meshInitDolphin(
|
errorret_t meshInitDolphin(
|
||||||
meshdolphin_t *mesh,
|
meshdolphin_t *mesh,
|
||||||
@@ -47,18 +47,21 @@ errorret_t meshDrawDolphin(
|
|||||||
assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong");
|
assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong");
|
||||||
assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong");
|
assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong");
|
||||||
|
|
||||||
textureDolphinUploadTEV();
|
|
||||||
|
|
||||||
DCFlushRange(
|
DCFlushRange(
|
||||||
(void*)&mesh->vertices[vertexOffset],
|
(void*)&mesh->vertices[vertexOffset],
|
||||||
sizeof(meshvertex_t) * vertexCount
|
sizeof(meshvertex_t) * vertexCount
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Update matrix.
|
||||||
|
errorChain(shaderUpdateMVPDolphin());
|
||||||
|
|
||||||
const uint8_t stride = (uint8_t)sizeof(meshvertex_t);
|
const uint8_t stride = (uint8_t)sizeof(meshvertex_t);
|
||||||
GX_SetArray(GX_VA_POS, (void*)&mesh->vertices[vertexOffset].pos[0], stride);
|
GX_SetArray(GX_VA_POS, (void*)&mesh->vertices[vertexOffset].pos[0], stride);
|
||||||
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
|
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
|
||||||
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
|
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
|
||||||
|
|
||||||
|
GX_InvVtxCache();
|
||||||
|
|
||||||
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
||||||
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
|
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
|
||||||
GX_Position1x16(i);
|
GX_Position1x16(i);
|
||||||
|
|||||||
11
src/duskdolphin/display/shader/CMakeLists.txt
Normal file
11
src/duskdolphin/display/shader/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
shaderdolphin.c
|
||||||
|
shaderunlitdolphin.c
|
||||||
|
)
|
||||||
245
src/duskdolphin/display/shader/shaderdolphin.c
Normal file
245
src/duskdolphin/display/shader/shaderdolphin.c
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "display/shader/shaderunlit.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "log/log.h"
|
||||||
|
|
||||||
|
shaderdolphin_t *SHADER_BOUND;
|
||||||
|
|
||||||
|
errorret_t shaderInitDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const shaderdefinitiondolphin_t *def
|
||||||
|
) {
|
||||||
|
assertNotNull(shader, "Shader must not be null");
|
||||||
|
assertNotNull(def, "Shader definition must not be null");
|
||||||
|
|
||||||
|
memoryZero(shader, sizeof(shaderdolphin_t));
|
||||||
|
|
||||||
|
glm_mat4_identity(shader->view);
|
||||||
|
glm_mat4_identity(shader->proj);
|
||||||
|
glm_mat4_identity(shader->model);
|
||||||
|
shader->dirtyMatrix = (
|
||||||
|
SHADER_DOLPHIN_DIRTY_MODEL |
|
||||||
|
SHADER_DOLPHIN_DIRTY_PROJ |
|
||||||
|
SHADER_DOLPHIN_DIRTY_VIEW
|
||||||
|
);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderBindDolphin(shaderdolphin_t *shader) {
|
||||||
|
assertNotNull(shader, "Shader must not be null");
|
||||||
|
|
||||||
|
SHADER_BOUND = shader;
|
||||||
|
|
||||||
|
|
||||||
|
GX_LoadProjectionMtx(
|
||||||
|
shader->matrixProjection,
|
||||||
|
shader->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
|
||||||
|
);
|
||||||
|
GX_LoadPosMtxImm(shader->matrixModelView, GX_PNMTX0);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderSetMatrixDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
mat4 mat
|
||||||
|
) {
|
||||||
|
assertNotNull(shader, "Shader must not be null");
|
||||||
|
assertNotNull(name, "Uniform name must not be null");
|
||||||
|
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||||
|
|
||||||
|
if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) {
|
||||||
|
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_PROJ;
|
||||||
|
glm_mat4_copy(mat, shader->proj);
|
||||||
|
|
||||||
|
} else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) {
|
||||||
|
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_VIEW;
|
||||||
|
glm_mat4_copy(mat, shader->view);
|
||||||
|
|
||||||
|
} else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) {
|
||||||
|
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_MODEL;
|
||||||
|
glm_mat4_copy(mat, shader->model);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
assertUnreachable("Cannot use a custom matrix on dolphin.");
|
||||||
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderSetTextureDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
texture_t *texture
|
||||||
|
) {
|
||||||
|
assertNotNull(shader, "Shader must not be null");
|
||||||
|
assertNotNull(name, "Uniform name must not be null");
|
||||||
|
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||||
|
|
||||||
|
if(texture == NULL) {
|
||||||
|
// GX_SetNumChans(0);
|
||||||
|
GX_SetNumChans(1);
|
||||||
|
GX_SetChanCtrl(
|
||||||
|
GX_COLOR0A0,
|
||||||
|
GX_DISABLE,
|
||||||
|
GX_SRC_REG,
|
||||||
|
GX_SRC_VTX,
|
||||||
|
GX_LIGHTNULL,
|
||||||
|
GX_DF_NONE,
|
||||||
|
GX_AF_NONE
|
||||||
|
);
|
||||||
|
GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){ 0, 0, 0, 0 });
|
||||||
|
GX_SetChanMatColor(GX_COLOR0A0, (GXColor){ 255, 255, 255, 255 });
|
||||||
|
|
||||||
|
GX_SetNumTexGens(0);
|
||||||
|
|
||||||
|
GX_SetNumTevStages(1);
|
||||||
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
|
||||||
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
|
|
||||||
|
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
|
||||||
|
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add channel for vertex color
|
||||||
|
GX_LoadTexObj(&texture->texObj, GX_TEXMAP0);
|
||||||
|
GX_SetNumChans(1);
|
||||||
|
GX_SetChanCtrl(
|
||||||
|
GX_COLOR0A0,// Store in color channel 0
|
||||||
|
GX_DISABLE,// Lighting disabled
|
||||||
|
GX_SRC_REG,// Ambient color?
|
||||||
|
GX_SRC_VTX,// Material color?
|
||||||
|
GX_LIGHTNULL,// Light Mask
|
||||||
|
GX_DF_NONE,// Diffuse function
|
||||||
|
GX_AF_NONE// Attenuation function
|
||||||
|
);
|
||||||
|
|
||||||
|
// One set of UVs
|
||||||
|
GX_SetNumTexGens(1);
|
||||||
|
GX_SetTexCoordGen(
|
||||||
|
GX_TEXCOORD0,
|
||||||
|
GX_TG_MTX2x4,
|
||||||
|
GX_TG_TEX0,
|
||||||
|
GX_IDENTITY
|
||||||
|
);
|
||||||
|
|
||||||
|
// Basically the shader setup
|
||||||
|
switch(texture->format) {
|
||||||
|
case TEXTURE_FORMAT_RGBA:
|
||||||
|
// One TEV stage: vertex color * texture color
|
||||||
|
GX_SetNumTevStages(1);
|
||||||
|
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
||||||
|
GX_SetTevOrder(
|
||||||
|
GX_TEVSTAGE0,
|
||||||
|
GX_TEXCOORD0,
|
||||||
|
GX_TEXMAP0,
|
||||||
|
GX_COLOR0A0
|
||||||
|
);
|
||||||
|
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
|
||||||
|
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Unknown texture format in meshDraw");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderDisposeDolphin(shaderdolphin_t *shader) {
|
||||||
|
assertNotNull(shader, "Shader must not be null");
|
||||||
|
|
||||||
|
SHADER_BOUND = NULL;
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t shaderUpdateMVPDolphin() {
|
||||||
|
assertNotNull(SHADER_BOUND, "Shader must not be null");
|
||||||
|
|
||||||
|
// Any changes?
|
||||||
|
if(SHADER_BOUND->dirtyMatrix == 0) errorOk();
|
||||||
|
|
||||||
|
// Need to update projection?
|
||||||
|
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_PROJ) != 0) {
|
||||||
|
shaderMat4ToMtx44(SHADER_BOUND->proj, SHADER_BOUND->matrixProjection);
|
||||||
|
|
||||||
|
// Fix projection Z mapping between GLM and GX.
|
||||||
|
float A = SHADER_BOUND->matrixProjection[2][2];
|
||||||
|
float B = SHADER_BOUND->matrixProjection[2][3];
|
||||||
|
SHADER_BOUND->matrixProjection[2][2] = 0.5f * (A + 1.0f);
|
||||||
|
SHADER_BOUND->matrixProjection[2][3] = 0.5f * B;
|
||||||
|
|
||||||
|
// Is this perspective or ortho originally? Dolphin cares for some reason.
|
||||||
|
const float_t epsilon = 0.0001f;
|
||||||
|
SHADER_BOUND->isProjectionPerspective = (
|
||||||
|
fabsf(SHADER_BOUND->proj[3][2]) > epsilon &&
|
||||||
|
fabsf(SHADER_BOUND->proj[3][3]) < epsilon
|
||||||
|
);
|
||||||
|
|
||||||
|
GX_LoadProjectionMtx(
|
||||||
|
SHADER_BOUND->matrixProjection,
|
||||||
|
SHADER_BOUND->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to update view or model?
|
||||||
|
bool_t mvDirt = false;
|
||||||
|
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_VIEW) != 0) {
|
||||||
|
shaderMat4ToMtx(SHADER_BOUND->view, SHADER_BOUND->matrixView);
|
||||||
|
mvDirt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_MODEL) != 0) {
|
||||||
|
shaderMat4ToMtx(SHADER_BOUND->model, SHADER_BOUND->matrixModel);
|
||||||
|
mvDirt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Model/View Matrix
|
||||||
|
if(mvDirt) {
|
||||||
|
guMtxConcat(
|
||||||
|
SHADER_BOUND->matrixView,
|
||||||
|
SHADER_BOUND->matrixModel,
|
||||||
|
SHADER_BOUND->matrixModelView
|
||||||
|
);
|
||||||
|
GX_LoadPosMtxImm(SHADER_BOUND->matrixModelView, GX_PNMTX0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHADER_BOUND->dirtyMatrix = 0;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaderMat4ToMtx44(const mat4 inGlmMatrix, Mtx44 outGXMatrix) {
|
||||||
|
assertNotNull(inGlmMatrix, "Input matrix cannot be null");
|
||||||
|
assertNotNull(outGXMatrix, "Output matrix cannot be null");
|
||||||
|
|
||||||
|
for(int row = 0; row < 4; ++row) {
|
||||||
|
for(int col = 0; col < 4; ++col) {
|
||||||
|
outGXMatrix[row][col] = inGlmMatrix[col][row];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaderMat4ToMtx(const mat4 inGlmMatrix, Mtx outGXMatrix) {
|
||||||
|
assertNotNull(inGlmMatrix, "Input matrix cannot be null");
|
||||||
|
assertNotNull(outGXMatrix, "Output matrix cannot be null");
|
||||||
|
|
||||||
|
for(int row = 0; row < 3; ++row) {
|
||||||
|
for(int col = 0; col < 4; ++col) {
|
||||||
|
outGXMatrix[row][col] = inGlmMatrix[col][row];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
113
src/duskdolphin/display/shader/shaderdolphin.h
Normal file
113
src/duskdolphin/display/shader/shaderdolphin.h
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "display/texture/texture.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mat4 view;
|
||||||
|
mat4 proj;
|
||||||
|
mat4 model;
|
||||||
|
|
||||||
|
bool_t isProjectionPerspective;
|
||||||
|
Mtx44 matrixProjection;
|
||||||
|
Mtx matrixView;
|
||||||
|
Mtx matrixModel;
|
||||||
|
Mtx matrixModelView;
|
||||||
|
|
||||||
|
uint_fast8_t dirtyMatrix;
|
||||||
|
} shaderdolphin_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *empty;
|
||||||
|
} shaderdefinitiondolphin_t;
|
||||||
|
|
||||||
|
#define SHADER_DOLPHIN_DIRTY_MODEL (1 << 0)
|
||||||
|
#define SHADER_DOLPHIN_DIRTY_PROJ (1 << 1)
|
||||||
|
#define SHADER_DOLPHIN_DIRTY_VIEW (1 << 2)
|
||||||
|
|
||||||
|
extern shaderdolphin_t *SHADER_BOUND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a dolphin shader. Basically a render parameter pipeline.
|
||||||
|
*
|
||||||
|
* @param shader Shader to initialize.
|
||||||
|
* @param def Definition of the shader to initialize with.
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderInitDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const shaderdefinitiondolphin_t *def
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a dolphin shader. Basically sets the render parameters for rendering.
|
||||||
|
*
|
||||||
|
* @param shader Shader to bind.
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderBindDolphin(shaderdolphin_t *shader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a matrix uniform in the dolphin shader. Basically does nothing.
|
||||||
|
*
|
||||||
|
* @param shader Shader to set the matrix in.
|
||||||
|
* @param name Name of the uniform to set.
|
||||||
|
* @param matrix Matrix to set.
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderSetMatrixDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
mat4 matrix
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a texture uniform in the dolphin shader. Basically does nothing.
|
||||||
|
*
|
||||||
|
* @param shader Shader to set the texture in.
|
||||||
|
* @param name Name of the uniform to set.
|
||||||
|
* @param texture Texture to set.
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderSetTextureDolphin(
|
||||||
|
shaderdolphin_t *shader,
|
||||||
|
const char_t *name,
|
||||||
|
texture_t *texture
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes a dolphin shader. Basically does nothing.
|
||||||
|
*
|
||||||
|
* @param shader Shader to dispose.
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderDisposeDolphin(shaderdolphin_t *shader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal Dolphin method, called right before a draw call to perform a matrix
|
||||||
|
* update and recalc.
|
||||||
|
*
|
||||||
|
* @return Error code if failure.
|
||||||
|
*/
|
||||||
|
errorret_t shaderUpdateMVPDolphin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a glm style column major mat4 to a GX compatible row major Mtx44.
|
||||||
|
*
|
||||||
|
* @param in Matrix to convert.
|
||||||
|
* @param out Output converted matrix.
|
||||||
|
*/
|
||||||
|
void shaderMat4ToMtx44(const mat4 in, Mtx44 out);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a glm style column major mat4 to a GX compatible row major Mtx.
|
||||||
|
*
|
||||||
|
* @param inGlmMatrix Matrix to convert.
|
||||||
|
* @param outGXMatrix Output converted matrix.
|
||||||
|
*/
|
||||||
|
void shaderMat4ToMtx(const mat4 inGlmMatrix, Mtx outGXMatrix);
|
||||||
18
src/duskdolphin/display/shader/shaderplatform.h
Normal file
18
src/duskdolphin/display/shader/shaderplatform.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "shaderdolphin.h"
|
||||||
|
|
||||||
|
typedef shaderdolphin_t shaderplatform_t;
|
||||||
|
typedef shaderdefinitiondolphin_t shaderdefinitionplatform_t;
|
||||||
|
|
||||||
|
#define shaderInitPlatform shaderInitDolphin
|
||||||
|
#define shaderBindPlatform shaderBindDolphin
|
||||||
|
#define shaderSetMatrixPlatform shaderSetMatrixDolphin
|
||||||
|
#define shaderSetTexturePlatform shaderSetTextureDolphin
|
||||||
|
#define shaderDisposePlatform shaderDisposeDolphin
|
||||||
12
src/duskdolphin/display/shader/shaderunlitdolphin.c
Normal file
12
src/duskdolphin/display/shader/shaderunlitdolphin.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 "display/shader/shaderunlit.h"
|
||||||
|
|
||||||
|
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
|
||||||
|
0
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "display/texture/texture.h"
|
#include "display/texture/texture.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
errorret_t textureInitDolphin(
|
errorret_t textureInitDolphin(
|
||||||
texturedolphin_t *texture,
|
texturedolphin_t *texture,
|
||||||
@@ -15,191 +16,101 @@ errorret_t textureInitDolphin(
|
|||||||
const textureformatdolphin_t format,
|
const textureformatdolphin_t format,
|
||||||
const texturedata_t data
|
const texturedata_t data
|
||||||
) {
|
) {
|
||||||
// switch(format) {
|
switch(format) {
|
||||||
// case TEXTURE_FORMAT_RGBA:
|
case TEXTURE_FORMAT_RGBA: {
|
||||||
// assertTrue(
|
size_t rgbaSize = width * height * sizeof(uint8_t) * 4;
|
||||||
// (width % 4) == 0 && (height % 4) == 0,
|
|
||||||
// "RGB5A3 requires w/h multiple of 4 (or pad)"
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // Convert to RGB5A3 format
|
// Dolphin takes the RGBA data as 4x4 tiled layout.
|
||||||
// size_t rgbaSize = width * height * sizeof(u16);
|
texture->rgba = memoryAllocate(rgbaSize);
|
||||||
// texture->rgba = (u16*)memalign(32, rgbaSize);
|
|
||||||
// assertNotNull(texture->rgba, "Failed to allocate texture RGBA data");
|
|
||||||
|
|
||||||
// for(uint32_t y = 0; y < height; ++y) {
|
for(uint32_t y = 0; y < height; ++y) {
|
||||||
// for(uint32_t x = 0; x < width; ++x) {
|
for(uint32_t x = 0; x < width; ++x) {
|
||||||
// const int src = y * width + x;
|
const int src = y * width + x;
|
||||||
|
|
||||||
// const int tileX = x >> 2;
|
const int tileX = x >> 2;
|
||||||
// const int tileY = y >> 2;
|
const int tileY = y >> 2;
|
||||||
// const int tilesPerRow = width >> 2;
|
const int tilesPerRow = width >> 2;
|
||||||
// const int tileIndex = tileY * tilesPerRow + tileX;
|
const int tileIndex = tileY * tilesPerRow + tileX;
|
||||||
// const int tileBaseWords = tileIndex * 16;
|
const int inTile = ((y & 3) << 2) + (x & 3);
|
||||||
// const int inTile = ((y & 3) << 2) + (x & 3);
|
const int tileBase = tileIndex * 64;
|
||||||
// const int dest = tileBaseWords + inTile;
|
|
||||||
|
|
||||||
// color4b_t col = data.rgba.colors[src];
|
color_t col = data.rgbaColors[src];
|
||||||
|
|
||||||
// u16 outCol;
|
// AR plane
|
||||||
// if(col.a < 255) {
|
texture->rgba[tileBase + inTile * 2 + 0] = col.a;
|
||||||
// // 0AAA RRRR GGGG BBBB
|
texture->rgba[tileBase + inTile * 2 + 1] = col.r;
|
||||||
// outCol = (
|
|
||||||
// (0u << 15) |
|
|
||||||
// ((u16)(col.a >> 5) << 12) |
|
|
||||||
// ((u16)(col.r >> 4) << 8) |
|
|
||||||
// ((u16)(col.g >> 4) << 4) |
|
|
||||||
// ((u16)(col.b >> 4) << 0)
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// // 1RRRR RRGG GGGB BBBB
|
|
||||||
// outCol = (
|
|
||||||
// (1u << 15) |
|
|
||||||
// ((u16)(col.r >> 3) << 10) |
|
|
||||||
// ((u16)(col.g >> 3) << 5) |
|
|
||||||
// ((u16)(col.b >> 3) << 0)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// texture->rgba[dest] = outCol;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// DCFlushRange(texture->rgba, rgbaSize);
|
// GB plane
|
||||||
// GX_InitTexObj(
|
texture->rgba[tileBase + 32 + inTile * 2 + 0] = col.g;
|
||||||
// &texture->texObj,
|
texture->rgba[tileBase + 32 + inTile * 2 + 1] = col.b;
|
||||||
// texture->rgba,
|
}
|
||||||
// width, height,
|
}
|
||||||
// GX_TF_RGB5A3,
|
DCFlushRange(texture->rgba, rgbaSize);
|
||||||
// GX_REPEAT, GX_REPEAT,
|
GX_InitTexObj(
|
||||||
// GX_FALSE
|
&texture->texObj,
|
||||||
// );
|
texture->rgba,
|
||||||
|
width, height,
|
||||||
|
format,
|
||||||
|
GX_REPEAT, GX_REPEAT,
|
||||||
|
GX_FALSE
|
||||||
|
);
|
||||||
|
|
||||||
// DCFlushRange(texture->rgba, rgbaSize);
|
DCFlushRange(texture->rgba, rgbaSize);
|
||||||
// GX_InvalidateTexAll();
|
GX_InvalidateTexAll();
|
||||||
|
|
||||||
// GX_InitTexObjLOD(
|
GX_InitTexObjLOD(
|
||||||
// &texture->texObj,
|
&texture->texObj,
|
||||||
// GX_NEAR, GX_NEAR,
|
GX_NEAR, GX_NEAR,
|
||||||
// 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f,
|
||||||
// GX_FALSE,
|
GX_FALSE,
|
||||||
// GX_FALSE,
|
GX_FALSE,
|
||||||
// GX_ANISO_1
|
GX_ANISO_1
|
||||||
// );
|
);
|
||||||
// break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// case TEXTURE_FORMAT_PALETTE: {
|
case TEXTURE_FORMAT_PALETTE: {
|
||||||
// // Not supported, convert to RGBA using lookup
|
assertUnreachable("Paletted textures not yet implemented for Dolphin");
|
||||||
// color_t* formatted = memoryAllocate(width * height * sizeof(color_t));
|
break;
|
||||||
// for(int32_t i = 0; i < width * height; i++) {
|
}
|
||||||
// uint8_t index = data.palette.data[i];
|
|
||||||
// assertTrue(
|
|
||||||
// index < data.palette.palette->colorCount,
|
|
||||||
// "Palette index out of range"
|
|
||||||
// );
|
|
||||||
// formatted[i] = data.palette.palette->colors[index];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// textureInit(
|
default: {
|
||||||
// texture, width, height, TEXTURE_FORMAT_RGBA,
|
assertUnreachable("Unsupported texture format for Dolphin");
|
||||||
// (texturedata_t){
|
break;
|
||||||
// .rgba = { .colors = formatted }
|
}
|
||||||
// }
|
}
|
||||||
// );
|
|
||||||
// memoryFree(formatted);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// default:
|
|
||||||
// assertUnreachable("Unsupported texture format for Dolphin");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// texture->ready = true;
|
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t textureBindDolphin(texturedolphin_t *texture) {
|
|
||||||
if(texture == NULL) {
|
|
||||||
GX_SetNumChans(0);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
GX_SetNumChans(1);
|
|
||||||
GX_LoadTexObj(&texture->texObj, GX_TEXMAP0);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t textureDisposeDolphin(texturedolphin_t *texture) {
|
errorret_t textureDisposeDolphin(texturedolphin_t *texture) {
|
||||||
|
switch(texture->format) {
|
||||||
|
case TEXTURE_FORMAT_RGBA: {
|
||||||
|
if(texture->rgba) {
|
||||||
|
memoryFree(texture->rgba);
|
||||||
|
texture->rgba = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// case TEXTURE_FORMAT_RGB4A3: {
|
||||||
|
// assertUnreachable("RGB4A3 texture format not yet implemented");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// case TEXTURE_FORMAT_RGB5: {
|
||||||
|
// assertUnreachable("RGB5 texture format not yet implemented");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// case TEXTURE_FORMAT_PALETTE: {
|
||||||
|
// assertUnreachable("Paletted textures not yet implemented for Dolphin");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
default: {
|
||||||
|
assertUnreachable("Unsupported texture format for Dolphin");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void textureDolphinUploadTEV(void) {
|
|
||||||
if(TEXTURE_BOUND == NULL) {
|
|
||||||
GX_SetNumChans(1);
|
|
||||||
GX_SetChanCtrl(
|
|
||||||
GX_COLOR0A0,
|
|
||||||
GX_DISABLE,
|
|
||||||
GX_SRC_REG,
|
|
||||||
GX_SRC_VTX,
|
|
||||||
GX_LIGHTNULL,
|
|
||||||
GX_DF_NONE,
|
|
||||||
GX_AF_NONE
|
|
||||||
);
|
|
||||||
GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){0, 0, 0, 0});
|
|
||||||
GX_SetChanMatColor(GX_COLOR0A0, (GXColor){255, 255, 255, 255});
|
|
||||||
|
|
||||||
GX_SetNumTexGens(0);
|
|
||||||
|
|
||||||
GX_SetNumTevStages(1);
|
|
||||||
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
|
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
|
||||||
|
|
||||||
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
|
|
||||||
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add channel for vertex color
|
|
||||||
GX_SetNumChans(1);
|
|
||||||
GX_SetChanCtrl(
|
|
||||||
GX_COLOR0A0,// Store in color channel 0
|
|
||||||
GX_DISABLE,// Lighting disabled
|
|
||||||
GX_SRC_REG,// Ambient color?
|
|
||||||
GX_SRC_VTX,// Material color?
|
|
||||||
GX_LIGHTNULL,// Light Mask
|
|
||||||
GX_DF_NONE,// Diffuse function
|
|
||||||
GX_AF_NONE// Attenuation function
|
|
||||||
);
|
|
||||||
|
|
||||||
// One set of UVs
|
|
||||||
GX_SetNumTexGens(1);
|
|
||||||
GX_SetTexCoordGen(
|
|
||||||
GX_TEXCOORD0,
|
|
||||||
GX_TG_MTX2x4,
|
|
||||||
GX_TG_TEX0,
|
|
||||||
GX_IDENTITY
|
|
||||||
);
|
|
||||||
|
|
||||||
// Basically the shader setup
|
|
||||||
switch(TEXTURE_BOUND->format) {
|
|
||||||
case TEXTURE_FORMAT_RGBA:
|
|
||||||
// One TEV stage: vertex color * texture color
|
|
||||||
GX_SetNumTevStages(1);
|
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
|
|
||||||
GX_SetTevOrder(
|
|
||||||
GX_TEVSTAGE0,
|
|
||||||
GX_TEXCOORD0,
|
|
||||||
GX_TEXMAP0,
|
|
||||||
GX_COLOR0A0
|
|
||||||
);
|
|
||||||
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
|
|
||||||
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assertUnreachable("Unknown texture format in meshDraw");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,6 +13,8 @@ typedef union texturedata_u texturedata_t;
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
|
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
|
||||||
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
|
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
|
||||||
|
// TEXTURE_FORMAT_RGB4A3 = GX_TF_RGB5A3,
|
||||||
|
// TEXTURE_FORMAT_RGB5 = GX_TF_RGB565,
|
||||||
} textureformatdolphin_t;
|
} textureformatdolphin_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -20,6 +22,11 @@ typedef struct {
|
|||||||
textureformatdolphin_t format;
|
textureformatdolphin_t format;
|
||||||
int32_t width;
|
int32_t width;
|
||||||
int32_t height;
|
int32_t height;
|
||||||
|
|
||||||
|
union {
|
||||||
|
uint8_t *rgba;
|
||||||
|
// u16 *rgba;
|
||||||
|
};
|
||||||
} texturedolphin_t;
|
} texturedolphin_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,9 +62,3 @@ errorret_t textureBindDolphin(texturedolphin_t *texture);
|
|||||||
* @return An error if the texture failed to dispose, otherwise success.
|
* @return An error if the texture failed to dispose, otherwise success.
|
||||||
*/
|
*/
|
||||||
errorret_t textureDisposeDolphin(texturedolphin_t *texture);
|
errorret_t textureDisposeDolphin(texturedolphin_t *texture);
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal method that uploads the texture environment variables to the GPU
|
|
||||||
* for rendering. This is basically uploading the shader information.
|
|
||||||
*/
|
|
||||||
void textureDolphinUploadTEV(void);
|
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "debug/debug.h"
|
#include "log/log.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||||
#ifdef DUSK_INPUT_GAMEPAD
|
#ifdef DUSK_INPUT_GAMEPAD
|
||||||
@@ -27,13 +28,14 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
|||||||
{ .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = true } } },
|
{ .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = true } } },
|
||||||
{ .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = false } } },
|
{ .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = false } } },
|
||||||
{ .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = true } } },
|
{ .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = true } } },
|
||||||
{ .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = false } } },
|
|
||||||
{ .name = "rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = true } } },
|
{ .name = "rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = true } } },
|
||||||
{ .name = "rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = false } } },
|
{ .name = "rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = false } } },
|
||||||
{ .name = "rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = true } } },
|
{ .name = "rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = true } } },
|
||||||
{ .name = "rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = false } } },
|
{ .name = "rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = false } } },
|
||||||
|
{ .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = false } } },
|
||||||
{ .name = "ltrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_LEFT, .positive = true } } },
|
{ .name = "ltrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_LEFT, .positive = true } } },
|
||||||
{ .name = "rtrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT, .positive = true } } },
|
{ .name = "rtrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT, .positive = true } } },
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ .name = NULL }
|
{ .name = NULL }
|
||||||
@@ -52,29 +54,13 @@ void inputUpdateDolphin(void) {
|
|||||||
for(uint8_t i = 0; i < INPUT_DOLPHIN_PAD_COUNT; i++) {
|
for(uint8_t i = 0; i < INPUT_DOLPHIN_PAD_COUNT; i++) {
|
||||||
INPUT.platform.padState[i] = PAD_ButtonsHeld(i);
|
INPUT.platform.padState[i] = PAD_ButtonsHeld(i);
|
||||||
|
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_X] = (
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_X] = PAD_StickX(i);
|
||||||
INPUT_DOLPHIN_AXIS(PAD_StickX(i))
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_Y] = PAD_StickY(i);
|
||||||
);
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_X] = PAD_SubStickX(i);
|
||||||
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_Y] = PAD_SubStickY(i);
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_Y] = (
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_LEFT]=PAD_TriggerL(i);
|
||||||
INPUT_DOLPHIN_AXIS(PAD_StickY(i))
|
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT]=PAD_TriggerR(i);
|
||||||
);
|
// Because gamecube sticks are hexagons this is going to be weird.
|
||||||
|
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_X] = (
|
|
||||||
INPUT_DOLPHIN_AXIS(PAD_SubStickX(i))
|
|
||||||
);
|
|
||||||
|
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_Y] = (
|
|
||||||
INPUT_DOLPHIN_AXIS(PAD_SubStickY(i))
|
|
||||||
);
|
|
||||||
|
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_LEFT] = (
|
|
||||||
INPUT_DOLPHIN_AXIS(PAD_TriggerL(i))
|
|
||||||
);
|
|
||||||
|
|
||||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT] = (
|
|
||||||
INPUT_DOLPHIN_AXIS(PAD_TriggerR(i))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -88,10 +74,11 @@ float_t inputButtonGetValueDolphin(const inputbutton_t button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
|
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
|
||||||
float_t value = INPUT.platform.pads[0][button.gpAxis.axis];
|
float_t axis = INPUT.platform.pads[0][button.gpAxis.axis];
|
||||||
|
float_t value = axis / 128.0f;
|
||||||
if(!button.gpAxis.positive) value = -value;
|
if(!button.gpAxis.positive) value = -value;
|
||||||
if(value >= INPUT.deadzone) return value;
|
value = inputDeadzone(value, inputGetDeadzoneDolphin(button));
|
||||||
return 0.0f;
|
return value;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -101,3 +88,7 @@ float_t inputButtonGetValueDolphin(const inputbutton_t button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float_t inputGetDeadzoneDolphin(const inputbutton_t button) {
|
||||||
|
return 0.2f;
|
||||||
|
}
|
||||||
@@ -64,3 +64,11 @@ void inputUpdateDolphin(void);
|
|||||||
* @return The value of the button, between 0 and 1.
|
* @return The value of the button, between 0 and 1.
|
||||||
*/
|
*/
|
||||||
float_t inputButtonGetValueDolphin(const inputbutton_t button);
|
float_t inputButtonGetValueDolphin(const inputbutton_t button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the deadzone for the given button.
|
||||||
|
*
|
||||||
|
* @param button The button to get the deadzone of.
|
||||||
|
* @return The deadzone for the button, between 0 and 1.
|
||||||
|
*/
|
||||||
|
float_t inputGetDeadzoneDolphin(const inputbutton_t button);
|
||||||
@@ -7,5 +7,5 @@
|
|||||||
|
|
||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
debug.c
|
log.c
|
||||||
)
|
)
|
||||||
65
src/duskdolphin/log/log.c
Normal file
65
src/duskdolphin/log/log.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "log/log.h"
|
||||||
|
#include "display/display.h"
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
void logDebug(const char_t *message, ...) {
|
||||||
|
// Print to stdout
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
vfprintf(stdout, message, args);
|
||||||
|
va_end(args);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logError(const char_t *message, ...) {
|
||||||
|
// Either create graphics, or hijack the displays' graphics.
|
||||||
|
void *xfb = NULL;
|
||||||
|
GXRModeObj *rmode = NULL;
|
||||||
|
void *framebuffer;
|
||||||
|
|
||||||
|
if(DISPLAY.frameBuffer[0]) {
|
||||||
|
console_init(
|
||||||
|
DISPLAY.frameBuffer[0],
|
||||||
|
20,
|
||||||
|
20,
|
||||||
|
DISPLAY.screenMode->fbWidth,
|
||||||
|
DISPLAY.screenMode->xfbHeight,
|
||||||
|
DISPLAY.screenMode->fbWidth * VI_DISPLAY_PIX_SZ
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
VIDEO_Init();
|
||||||
|
rmode = VIDEO_GetPreferredMode(NULL);
|
||||||
|
framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
||||||
|
console_init(
|
||||||
|
framebuffer,
|
||||||
|
20,
|
||||||
|
20,
|
||||||
|
rmode->fbWidth,
|
||||||
|
rmode->xfbHeight,
|
||||||
|
rmode->fbWidth*VI_DISPLAY_PIX_SZ
|
||||||
|
);
|
||||||
|
VIDEO_Configure(rmode);
|
||||||
|
VIDEO_SetNextFramebuffer(framebuffer);
|
||||||
|
VIDEO_SetBlack(FALSE);
|
||||||
|
VIDEO_Flush();
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
vprintf(message, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
while(SYS_MainLoop()) {
|
||||||
|
VIDEO_WaitVSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user