Compare commits
1 Commits
editor
...
71c5756e71
| Author | SHA1 | Date | |
|---|---|---|---|
| 71c5756e71 |
26
.github/workflows/build.yml
vendored
26
.github/workflows/build.yml
vendored
@@ -1,4 +1,5 @@
|
||||
name: Build Dusk
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@@ -6,6 +7,7 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
run-tests:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -53,26 +55,6 @@ jobs:
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-knulli:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build knulli
|
||||
run: ./scripts/build-knulli-docker.sh
|
||||
- name: Move output to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp -r build-knulli/dusk ./git-artifcats/Dusk
|
||||
- name: Upload knulli binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-knulli
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-gamecube:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -92,7 +74,6 @@ jobs:
|
||||
with:
|
||||
name: dusk-gamecube
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-wii:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -106,7 +87,7 @@ jobs:
|
||||
- name: Copy output files.
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
|
||||
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/Dusk.dol
|
||||
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||
- name: Upload Wii binary
|
||||
@@ -114,4 +95,3 @@ jobs:
|
||||
with:
|
||||
name: dusk-wii
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
@@ -42,7 +42,7 @@ file(MAKE_DIRECTORY ${DUSK_TEMP_DIR})
|
||||
file(MAKE_DIRECTORY ${DUSK_BUILT_ASSETS_DIR})
|
||||
|
||||
# Required build packages
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
|
||||
# Init Project.
|
||||
project(${DUSK_LIBRARY_TARGET_NAME}
|
||||
|
||||
@@ -156,7 +156,7 @@ class Map:
|
||||
newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2)
|
||||
newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2)
|
||||
|
||||
if(newTopLeftChunkX != self.topLeftX or
|
||||
if (newTopLeftChunkX != self.topLeftX or
|
||||
newTopLeftChunkY != self.topLeftY or
|
||||
newTopLeftChunkZ != self.topLeftZ):
|
||||
|
||||
@@ -166,7 +166,7 @@ class Map:
|
||||
chunkWorldX = chunk.x
|
||||
chunkWorldY = chunk.y
|
||||
chunkWorldZ = chunk.z
|
||||
if(chunkWorldX < newTopLeftChunkX or
|
||||
if (chunkWorldX < newTopLeftChunkX or
|
||||
chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or
|
||||
chunkWorldY < newTopLeftChunkY or
|
||||
chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or
|
||||
|
||||
@@ -70,7 +70,6 @@ elseif LINUX then
|
||||
inputBind("mouse_x", INPUT_ACTION_POINTERX)
|
||||
inputBind("mouse_y", INPUT_ACTION_POINTERY)
|
||||
end
|
||||
|
||||
else
|
||||
print("Unknown platform, no default input bindings set.")
|
||||
end
|
||||
|
||||
@@ -9,7 +9,6 @@ module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
module('shader')
|
||||
|
||||
CELL_STATE_DEFAULT = 0
|
||||
CELL_STATE_HOVER = 1
|
||||
@@ -63,7 +62,7 @@ function cellDraw(x, y, type)
|
||||
slice = cellSliceDisabled
|
||||
end
|
||||
|
||||
spriteBatchPush(
|
||||
spriteBatchPush(textureCell,
|
||||
x, y,
|
||||
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||
colorWhite(),
|
||||
@@ -183,28 +182,18 @@ function sceneUpdate()
|
||||
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
|
||||
end
|
||||
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
camera.bottom = 0
|
||||
camera.top = screenGetHeight()
|
||||
cameraPushMatrix(camera)
|
||||
camera.bottom = screenGetHeight()
|
||||
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(
|
||||
x, y,
|
||||
x + 32, y + 32,
|
||||
colorWhite()
|
||||
nil,
|
||||
x, y, x + 32, y + 32,
|
||||
colorBlue()
|
||||
)
|
||||
spriteBatchFlush()
|
||||
|
||||
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||
spriteBatchFlush()
|
||||
|
||||
-- Update mouse position
|
||||
-- if INPUT_POINTER then
|
||||
@@ -261,4 +250,7 @@ function sceneRender()
|
||||
-- )
|
||||
-- end
|
||||
-- end
|
||||
spriteBatchFlush()
|
||||
|
||||
cameraPopMatrix()
|
||||
end
|
||||
BIN
assets/ui/minogram.dpt
Normal file
BIN
assets/ui/minogram.dpt
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,45 +0,0 @@
|
||||
# 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,7 +28,6 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_SDL2
|
||||
DUSK_OPENGL
|
||||
# DUSK_OPENGL_LEGACY
|
||||
DUSK_LINUX
|
||||
DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
||||
|
||||
@@ -36,7 +36,6 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_PSP
|
||||
DUSK_INPUT_GAMEPAD
|
||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||
DUSK_OPENGL_LEGACY
|
||||
DUSK_DISPLAY_WIDTH=480
|
||||
DUSK_DISPLAY_HEIGHT=272
|
||||
)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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 "")
|
||||
16
cmake/toolchains/toolchain-aarch64-buildroot.cmake
Normal file
16
cmake/toolchains/toolchain-aarch64-buildroot.cmake
Normal file
@@ -0,0 +1,16 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(CMAKE_C_COMPILER aarch64-buildroot-linux-gnu-gcc)
|
||||
set(CMAKE_CXX_COMPILER aarch64-buildroot-linux-gnu-g++)
|
||||
|
||||
set(CMAKE_SYSROOT /opt/aarch64-buildroot-linux-gnu_sdk-buildroot/aarch64-buildroot-linux-gnu/sysroot)
|
||||
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
|
||||
|
||||
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_SYSROOT_DIR} ${CMAKE_SYSROOT})
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
|
||||
@@ -1,35 +1,40 @@
|
||||
FROM debian:trixie
|
||||
FROM debian:bookworm-slim
|
||||
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 \
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
RUN apt-get -y update && apt-get -y install \
|
||||
python3-dotenv \
|
||||
bc \
|
||||
bison \
|
||||
build-essential \
|
||||
bzip2 \
|
||||
bzr \
|
||||
cmake \
|
||||
make \
|
||||
ninja-build \
|
||||
cmake-curses-gui \
|
||||
cpio \
|
||||
device-tree-compiler \
|
||||
flex \
|
||||
git \
|
||||
file \
|
||||
imagemagick \
|
||||
libncurses5-dev \
|
||||
locales \
|
||||
make \
|
||||
nano \
|
||||
p7zip-full \
|
||||
rsync \
|
||||
sharutils \
|
||||
scons \
|
||||
tree \
|
||||
unzip \
|
||||
vim \
|
||||
wget \
|
||||
zip \
|
||||
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/*
|
||||
gcc-aarch64-linux-gnu \
|
||||
g++-aarch64-linux-gnu \
|
||||
&& apt clean
|
||||
VOLUME ["/workdir"]
|
||||
CMD ["/bin/bash"]
|
||||
41
editor/.gitignore
vendored
41
editor/.gitignore
vendored
@@ -1,41 +0,0 @@
|
||||
# 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
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
reactCompiler: true,
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import Link from "next/link";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<Link href="/texture-creator">Go to Texture Creator</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
'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;
|
||||
@@ -1,12 +0,0 @@
|
||||
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;
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
const Typography:React.FC<{
|
||||
element?:string|React.JSXElementConstructor<any>;
|
||||
}> = (props) => {
|
||||
const Element = props.element || 'p';
|
||||
|
||||
return (
|
||||
<Element>
|
||||
{props.children}
|
||||
</Element>
|
||||
)
|
||||
};
|
||||
|
||||
export default Typography;
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
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;
|
||||
@@ -1,4 +0,0 @@
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-width: 100vw;
|
||||
overflow-x: hidden;
|
||||
font-size: 16px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-width: 100vw;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
:root {
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// Elements
|
||||
@use './elements/root.scss';
|
||||
@use './elements/all.scss';
|
||||
@use './elements/a.scss';
|
||||
@use './elements/html.scss';
|
||||
@use './elements/body.scss';
|
||||
|
||||
// Objects
|
||||
|
||||
// Components
|
||||
|
||||
// Utilities
|
||||
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-knulli -f docker/knulli/Dockerfile .
|
||||
docker build --no-cache -t dusk-knulli -f docker/knulli/Dockerfile .
|
||||
docker run --rm -v $(pwd):/workdir dusk-knulli /bin/bash -c "./scripts/build-knulli.sh"
|
||||
@@ -1,24 +1,15 @@
|
||||
#!/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)
|
||||
git clone --depth 1 --branch SDL2 https://github.com/libsdl-org/SDL.git /tmp/SDL2 && \
|
||||
cmake -S /tmp/SDL2 -B /tmp/SDL2/build \
|
||||
-DCMAKE_TOOLCHAIN_FILE=/workdir/toolchain-aarch64-buildroot.cmake \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX="$SYSROOT/usr" && \
|
||||
cmake --build /tmp/SDL2/build -j"$(nproc)" && \
|
||||
cmake --install /tmp/SDL2/build
|
||||
|
||||
# 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/
|
||||
cmake -S . \
|
||||
-B build-knulli \
|
||||
-DDUSK_BUILD_TESTS=ON \
|
||||
-DDUSK_TARGET_SYSTEM=linux \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/toolchain-aarch64-buildroot.cmake
|
||||
cmake --build build-knulli -- -j$(nproc)
|
||||
@@ -4,9 +4,8 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(dusk)
|
||||
add_subdirectory(duskrpg)
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
add_subdirectory(dusklinux)
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskgl)
|
||||
|
||||
@@ -40,6 +40,9 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
||||
main.c
|
||||
)
|
||||
|
||||
# Defs
|
||||
dusk_env_to_h(duskdefs.env duskdefs.h)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
@@ -49,9 +52,12 @@ add_subdirectory(engine)
|
||||
add_subdirectory(error)
|
||||
add_subdirectory(event)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(map)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(script)
|
||||
add_subdirectory(story)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(util)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "assert.h"
|
||||
#include "log/log.h"
|
||||
#include "util/string.h"
|
||||
|
||||
#ifndef DUSK_ASSERTIONS_FAKED
|
||||
#ifdef DUSK_TEST_ASSERT
|
||||
@@ -99,14 +98,4 @@
|
||||
) {
|
||||
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
|
||||
@@ -104,23 +104,6 @@
|
||||
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.
|
||||
*
|
||||
@@ -195,16 +178,6 @@
|
||||
#define assertStrLenMin(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
|
||||
// If assertions are faked, we define the macros to do nothing.
|
||||
#define assertTrue(x, message) ((void)0)
|
||||
|
||||
@@ -19,9 +19,12 @@ typedef enum {
|
||||
ASSET_TYPE_NULL,
|
||||
|
||||
ASSET_TYPE_TEXTURE,
|
||||
// ASSET_TYPE_PALETTE,
|
||||
ASSET_TYPE_TILESET,
|
||||
ASSET_TYPE_LANGUAGE,
|
||||
ASSET_TYPE_SCRIPT,
|
||||
ASSET_TYPE_MAP,
|
||||
ASSET_TYPE_MAP_CHUNK,
|
||||
|
||||
ASSET_TYPE_COUNT,
|
||||
} assettype_t;
|
||||
@@ -57,14 +60,21 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
||||
},
|
||||
|
||||
[ASSET_TYPE_TEXTURE] = {
|
||||
.extension = "DTX",
|
||||
.extension = "dpt",
|
||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||
.dataSize = sizeof(assettexture_t),
|
||||
.entire = assetTextureLoad
|
||||
},
|
||||
|
||||
// [ASSET_TYPE_PALETTE] = {
|
||||
// .extension = "dpf",
|
||||
// .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||
// .dataSize = sizeof(palette_t),
|
||||
// .entire = assetPaletteLoad
|
||||
// },
|
||||
|
||||
[ASSET_TYPE_TILESET] = {
|
||||
.extension = "DTF",
|
||||
.extension = "dtf",
|
||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||
.dataSize = sizeof(assettileset_t),
|
||||
.entire = assetTilesetLoad
|
||||
@@ -81,4 +91,16 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||
.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)
|
||||
if(
|
||||
assetData->header[0] != 'D' ||
|
||||
assetData->header[1] != 'T' ||
|
||||
assetData->header[2] != 'X'
|
||||
assetData->header[1] != 'P' ||
|
||||
assetData->header[2] != 'T'
|
||||
) {
|
||||
errorThrow("Invalid texture header");
|
||||
}
|
||||
@@ -44,35 +44,15 @@ errorret_t assetTextureLoad(assetentire_t entire) {
|
||||
errorThrow("Invalid texture dimensions");
|
||||
}
|
||||
|
||||
// Validate format
|
||||
textureformat_t format;
|
||||
texturedata_t data;
|
||||
|
||||
switch(assetData->type) {
|
||||
case 0x00: // RGBA8888
|
||||
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");
|
||||
textureInit(
|
||||
texture,
|
||||
assetData->width,
|
||||
assetData->height,
|
||||
TEXTURE_FORMAT_PALETTE,
|
||||
(texturedata_t){
|
||||
.paletteData = assetData->palette
|
||||
}
|
||||
|
||||
errorChain(textureInit(
|
||||
texture, assetData->width, assetData->height, format, data
|
||||
));
|
||||
);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
|
||||
#define ASSET_TEXTURE_WIDTH_MAX 2048
|
||||
#define ASSET_TEXTURE_HEIGHT_MAX 2048
|
||||
@@ -21,10 +20,9 @@ typedef struct assetentire_s assetentire_t;
|
||||
typedef struct {
|
||||
char_t header[3];
|
||||
uint8_t version;
|
||||
uint8_t type;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t data[ASSET_TEXTURE_SIZE_MAX * sizeof(color4b_t)];
|
||||
uint8_t palette[ASSET_TEXTURE_SIZE_MAX];
|
||||
} assettexture_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ add_subdirectory(camera)
|
||||
add_subdirectory(framebuffer)
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(screen)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(spritebatch)
|
||||
add_subdirectory(text)
|
||||
add_subdirectory(texture)
|
||||
|
||||
@@ -37,7 +37,7 @@ void cameraInitOrthographic(camera_t *camera) {
|
||||
camera->orthographic.right = SCREEN.width;
|
||||
camera->orthographic.top = 0.0f;
|
||||
camera->orthographic.bottom = SCREEN.height;
|
||||
camera->nearClip = 0.1f;
|
||||
camera->nearClip = -1.0f;
|
||||
camera->farClip = 1.0f;
|
||||
|
||||
camera->viewType = CAMERA_VIEW_TYPE_2D;
|
||||
@@ -45,63 +45,13 @@ void cameraInitOrthographic(camera_t *camera) {
|
||||
camera->_2d.zoom = 1.0f;
|
||||
}
|
||||
|
||||
void cameraGetProjectionMatrix(camera_t *camera, mat4 dest) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
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 cameraPushMatrix(camera_t *camera) {
|
||||
assertNotNull(camera, "Invalid camera");
|
||||
cameraPushMatrixPlatform(camera);
|
||||
}
|
||||
|
||||
void cameraGetViewMatrix(camera_t *camera, mat4 dest) {
|
||||
assertNotNull(camera, "Not a camera component");
|
||||
assertNotNull(dest, "Destination matrix must not be null");
|
||||
|
||||
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");
|
||||
}
|
||||
void cameraPopMatrix(void) {
|
||||
#ifdef cameraPopMatrixPlatform
|
||||
cameraPopMatrixPlatform();
|
||||
#endif
|
||||
}
|
||||
@@ -86,17 +86,13 @@ void cameraInitPerspective(camera_t *camera);
|
||||
void cameraInitOrthographic(camera_t *camera);
|
||||
|
||||
/**
|
||||
* Gets the projection matrix for a camera.
|
||||
* Pushes the camera's view matrix onto the matrix stack.
|
||||
*
|
||||
* @param camera Camera to get the projection matrix for
|
||||
* @param dest Matrix to store the projection matrix in
|
||||
* @param id The ID of the camera entity to use.
|
||||
*/
|
||||
void cameraGetProjectionMatrix(camera_t *camera, mat4 dest);
|
||||
void cameraPushMatrix(camera_t *camera);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Pops the camera's view matrix off the matrix stack.
|
||||
*/
|
||||
void cameraGetViewMatrix(camera_t *camera, mat4 dest);
|
||||
void cameraPopMatrix(void);
|
||||
@@ -17,30 +17,8 @@
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "asset/asset.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "time/time.h"
|
||||
|
||||
#include "script/module/display/moduleshader.h"
|
||||
|
||||
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) {
|
||||
memoryZero(&DISPLAY, sizeof(DISPLAY));
|
||||
@@ -48,28 +26,13 @@ errorret_t displayInit(void) {
|
||||
#ifdef displayPlatformInit
|
||||
errorChain(displayPlatformInit());
|
||||
#endif
|
||||
|
||||
errorChain(quadInit());
|
||||
errorChain(frameBufferInitBackBuffer());
|
||||
errorChain(spriteBatchInit());
|
||||
errorChain(textInit());
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -83,7 +46,7 @@ errorret_t displayUpdate(void) {
|
||||
errorChain(frameBufferBind(NULL));
|
||||
|
||||
// Bind screen and render scene
|
||||
errorChain(screenBind());
|
||||
screenBind();
|
||||
frameBufferClear(
|
||||
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
||||
SCREEN.background
|
||||
@@ -92,7 +55,7 @@ errorret_t displayUpdate(void) {
|
||||
errorChain(sceneRender());
|
||||
|
||||
// Render UI
|
||||
// uiRender();
|
||||
uiRender();
|
||||
|
||||
// Finish up
|
||||
screenUnbind();
|
||||
@@ -106,7 +69,6 @@ errorret_t displayUpdate(void) {
|
||||
}
|
||||
|
||||
errorret_t displayDispose(void) {
|
||||
errorChain(shaderDispose(&SHADER_UNLIT));
|
||||
errorChain(spriteBatchDispose());
|
||||
screenDispose();
|
||||
errorChain(textDispose());
|
||||
|
||||
@@ -25,29 +25,6 @@ errorret_t meshInit(
|
||||
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(
|
||||
const mesh_t *mesh,
|
||||
const int32_t vertexOffset,
|
||||
@@ -55,7 +32,7 @@ errorret_t meshDraw(
|
||||
) {
|
||||
assertNotNull(mesh, "Mesh cannot be NULL");
|
||||
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative");
|
||||
assertTrue(vertexCount == -1 || vertexCount > 0, "Incorrect vert count");
|
||||
assertTrue(vertexCount >= -1, "Vertex count must be -1 or non-negative");
|
||||
|
||||
int32_t vertDrawCount = vertexCount;
|
||||
if(vertexCount == -1) {
|
||||
|
||||
@@ -40,22 +40,6 @@ errorret_t meshInit(
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/mesh/quad.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
screen_t SCREEN;
|
||||
|
||||
@@ -45,23 +44,22 @@ errorret_t screenInit() {
|
||||
#endif
|
||||
|
||||
// Init screen to backbuffer mode by default
|
||||
errorChain(screenBind());
|
||||
screenBind();
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t screenBind() {
|
||||
void screenBind() {
|
||||
// Assume backbuffer is currently bound.
|
||||
switch(SCREEN.mode) {
|
||||
case SCREEN_MODE_BACKBUFFER: {
|
||||
// Screen mode backbuffer uses the full display size
|
||||
SCREEN.width = frameBufferGetWidth(FRAMEBUFFER_BOUND);
|
||||
SCREEN.height = frameBufferGetHeight(FRAMEBUFFER_BOUND);
|
||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||
|
||||
// No needd for a framebuffer.
|
||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
#endif
|
||||
@@ -81,21 +79,19 @@ errorret_t screenBind() {
|
||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||
if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) {
|
||||
// Correct size, nothing to do.
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
errorOk();
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Need a new framebuffer.
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
|
||||
// Create new framebuffer
|
||||
errorChain(frameBufferInit(
|
||||
&SCREEN.framebuffer, SCREEN.width, SCREEN.height
|
||||
));
|
||||
frameBufferInit(&SCREEN.framebuffer, SCREEN.width, SCREEN.height);
|
||||
SCREEN.framebufferReady = true;
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -113,10 +109,10 @@ errorret_t screenBind() {
|
||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t newFbWidth, newFbHeight;
|
||||
@@ -140,26 +136,24 @@ errorret_t screenBind() {
|
||||
SCREEN.width = newFbWidth;
|
||||
SCREEN.height = newFbHeight;
|
||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
errorOk();
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Need a new framebuffer.
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
|
||||
// Create new framebuffer
|
||||
errorChain(frameBufferInit(
|
||||
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||
));
|
||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
||||
SCREEN.width = newFbWidth;
|
||||
SCREEN.height = newFbHeight;
|
||||
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
|
||||
SCREEN.framebufferReady = true;
|
||||
|
||||
// Bind FB
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -179,10 +173,10 @@ errorret_t screenBind() {
|
||||
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
||||
// No need to use framebuffer.
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
if(SCREEN.framebufferReady) {
|
||||
@@ -191,21 +185,19 @@ errorret_t screenBind() {
|
||||
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
errorOk();
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Need a new framebuffer.
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
|
||||
// Create a new framebuffer.
|
||||
errorChain(frameBufferInit(
|
||||
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||
));
|
||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
||||
SCREEN.framebufferReady = true;
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -225,10 +217,10 @@ errorret_t screenBind() {
|
||||
if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
|
||||
// No need to use framebuffer.
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
if(SCREEN.framebufferReady) {
|
||||
@@ -237,21 +229,19 @@ errorret_t screenBind() {
|
||||
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
|
||||
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
|
||||
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
errorOk();
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Need a new framebuffer.
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
|
||||
// Create a new framebuffer.
|
||||
errorChain(frameBufferInit(
|
||||
&SCREEN.framebuffer, newFbWidth, newFbHeight
|
||||
));
|
||||
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight);
|
||||
SCREEN.framebufferReady = true;
|
||||
errorChain(frameBufferBind(&SCREEN.framebuffer));
|
||||
frameBufferBind(&SCREEN.framebuffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -272,11 +262,9 @@ errorret_t screenBind() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t screenUnbind() {
|
||||
void screenUnbind() {
|
||||
switch(SCREEN.mode) {
|
||||
// Nothing to do here.
|
||||
case SCREEN_MODE_BACKBUFFER:
|
||||
@@ -287,9 +275,7 @@ errorret_t screenUnbind() {
|
||||
case SCREEN_MODE_FIXED_HEIGHT:
|
||||
case SCREEN_MODE_FIXED_SIZE:
|
||||
case SCREEN_MODE_FIXED_WIDTH:
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferBind(NULL));
|
||||
}
|
||||
if(SCREEN.framebufferReady) frameBufferBind(NULL);
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_FIXED_VIEWPORT_HEIGHT:
|
||||
@@ -300,19 +286,17 @@ errorret_t screenUnbind() {
|
||||
assertUnreachable("Invalid screen mode.");
|
||||
break;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t screenRender() {
|
||||
void screenRender() {
|
||||
if(SCREEN.mode == SCREEN_MODE_BACKBUFFER) {
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
if(SCREEN.mode == SCREEN_MODE_FIXED_VIEWPORT_HEIGHT) {
|
||||
glViewport(0, 0, SCREEN.width, SCREEN.height);
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
if(
|
||||
@@ -323,7 +307,7 @@ errorret_t screenRender() {
|
||||
) {
|
||||
if(!SCREEN.framebufferReady) {
|
||||
// Nothing to do here.
|
||||
errorOk();
|
||||
return;
|
||||
}
|
||||
|
||||
float_t bbWidth, bbHeight;
|
||||
@@ -372,34 +356,23 @@ errorret_t screenRender() {
|
||||
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
||||
COLOR_BLACK
|
||||
);
|
||||
cameraPushMatrix(&SCREEN.framebufferCamera);
|
||||
textureBind(&SCREEN.framebuffer.texture);
|
||||
meshDraw(&SCREEN.frameBufferMesh, 0, -1);
|
||||
cameraPopMatrix();
|
||||
|
||||
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();
|
||||
return;
|
||||
};
|
||||
#endif
|
||||
|
||||
assertUnreachable("Invalid screen mode.");
|
||||
errorThrow("Invalid screen mode.");
|
||||
}
|
||||
|
||||
errorret_t screenDispose() {
|
||||
void screenDispose() {
|
||||
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
if(SCREEN.framebufferReady) {
|
||||
errorChain(frameBufferDispose(&SCREEN.framebuffer));
|
||||
frameBufferDispose(&SCREEN.framebuffer);
|
||||
SCREEN.framebufferReady = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -90,28 +90,20 @@ errorret_t screenInit();
|
||||
|
||||
/**
|
||||
* Binds the screen, this is done before rendering game content.
|
||||
*
|
||||
* @return Error code and state, if error occurs.
|
||||
*/
|
||||
errorret_t screenBind();
|
||||
void screenBind();
|
||||
|
||||
/**
|
||||
* Unbinds the screen, does nothing for now.
|
||||
*
|
||||
* @return Error code and state, if error occurs.
|
||||
*/
|
||||
errorret_t screenUnbind();
|
||||
void screenUnbind();
|
||||
|
||||
/**
|
||||
* Renders the screen to the current framebuffer.
|
||||
*
|
||||
* @return Error code and state, if error occurs.
|
||||
*/
|
||||
errorret_t screenRender();
|
||||
void screenRender();
|
||||
|
||||
/**
|
||||
* Disposes the screen system.
|
||||
*
|
||||
* @return Error code and state, if error occurs.
|
||||
*/
|
||||
errorret_t screenDispose();
|
||||
void screenDispose();
|
||||
@@ -1,11 +0,0 @@
|
||||
# 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
|
||||
)
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "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);
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* 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 };
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* 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,12 +19,13 @@ errorret_t spriteBatchInit() {
|
||||
&SPRITEBATCH.mesh,
|
||||
QUAD_PRIMITIVE_TYPE,
|
||||
SPRITEBATCH_VERTEX_COUNT,
|
||||
SPRITEBATCH_VERTICES
|
||||
&SPRITEBATCH_VERTICES[0]
|
||||
));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t spriteBatchPush(
|
||||
texture_t *texture,
|
||||
const float_t minX,
|
||||
const float_t minY,
|
||||
const float_t maxX,
|
||||
@@ -35,16 +36,19 @@ errorret_t spriteBatchPush(
|
||||
const float_t u1,
|
||||
const float_t v1
|
||||
) {
|
||||
return spriteBatchPush3D(
|
||||
errorChain(spriteBatchPush3D(
|
||||
texture,
|
||||
(vec3){ minX, minY, 0 },
|
||||
(vec3){ maxX, maxY, 0 },
|
||||
color,
|
||||
(vec2){ u0, v0 },
|
||||
(vec2){ u1, v1 }
|
||||
);
|
||||
));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t spriteBatchPush3D(
|
||||
texture_t *texture,
|
||||
const vec3 min,
|
||||
const vec3 max,
|
||||
const color_t color,
|
||||
@@ -52,14 +56,15 @@ errorret_t spriteBatchPush3D(
|
||||
const vec2 uv1
|
||||
) {
|
||||
// Need to flush?
|
||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
|
||||
if(
|
||||
SPRITEBATCH.currentTexture != texture ||
|
||||
SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX
|
||||
) {
|
||||
errorChain(spriteBatchFlush());
|
||||
SPRITEBATCH.currentTexture = texture;
|
||||
}
|
||||
|
||||
size_t vertexOffset = (
|
||||
SPRITEBATCH.spriteCount +
|
||||
(SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH)
|
||||
) * QUAD_VERTEX_COUNT;
|
||||
size_t vertexOffset = SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT;
|
||||
quadBuffer3D(
|
||||
&SPRITEBATCH_VERTICES[vertexOffset],
|
||||
min, max, color, uv0, uv1
|
||||
@@ -70,7 +75,7 @@ errorret_t spriteBatchPush3D(
|
||||
|
||||
void spriteBatchClear() {
|
||||
SPRITEBATCH.spriteCount = 0;
|
||||
SPRITEBATCH.spriteFlush = 0;
|
||||
SPRITEBATCH.currentTexture = NULL;
|
||||
}
|
||||
|
||||
errorret_t spriteBatchFlush() {
|
||||
@@ -78,20 +83,11 @@ errorret_t spriteBatchFlush() {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
|
||||
size_t vertexOffset = (
|
||||
SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH *
|
||||
QUAD_VERTEX_COUNT
|
||||
);
|
||||
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;
|
||||
|
||||
errorChain(textureBind(SPRITEBATCH.currentTexture));
|
||||
errorChain(meshDraw(
|
||||
&SPRITEBATCH.mesh, 0, QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount
|
||||
));
|
||||
spriteBatchClear();
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,18 +7,16 @@
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/quad.h"
|
||||
#include "display/texture/texture.h"
|
||||
|
||||
#define SPRITEBATCH_SPRITES_MAX 32
|
||||
#define SPRITEBATCH_SPRITES_MAX 16
|
||||
#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 {
|
||||
mesh_t mesh;
|
||||
int32_t spriteCount;
|
||||
int32_t spriteFlush;
|
||||
texture_t *currentTexture;
|
||||
} spritebatch_t;
|
||||
|
||||
// Have to define these seperately because of alignment in certain platforms.
|
||||
@@ -41,6 +39,7 @@ errorret_t spriteBatchInit();
|
||||
* Currently changing texture pointer will cause the buffer to flush but this is
|
||||
* 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 minY The minimum y coordinate of the sprite.
|
||||
* @param maxX The maximum x coordinate of the sprite.
|
||||
@@ -53,6 +52,7 @@ errorret_t spriteBatchInit();
|
||||
* @return An error code indicating success or failure.
|
||||
*/
|
||||
errorret_t spriteBatchPush(
|
||||
texture_t *texture,
|
||||
const float_t minX,
|
||||
const float_t minY,
|
||||
const float_t maxX,
|
||||
@@ -68,6 +68,7 @@ errorret_t spriteBatchPush(
|
||||
* Pushes a 3D sprite to the batch. This is like spriteBatchPush but takes
|
||||
* 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 max The maximum (x,y,z) coordinate of the sprite.
|
||||
* @param color The color to tint the sprite with.
|
||||
@@ -76,6 +77,7 @@ errorret_t spriteBatchPush(
|
||||
* @return An error code indicating success or failure.
|
||||
*/
|
||||
errorret_t spriteBatchPush3D(
|
||||
texture_t *texture,
|
||||
const vec3 min,
|
||||
const vec3 max,
|
||||
const color_t color,
|
||||
|
||||
@@ -11,19 +11,17 @@
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "asset/asset.h"
|
||||
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
texture_t DEFAULT_FONT_TEXTURE;
|
||||
tileset_t DEFAULT_FONT_TILESET;
|
||||
|
||||
errorret_t textInit(void) {
|
||||
errorChain(assetLoad("ui/minogram.dtx", &DEFAULT_FONT_TEXTURE));
|
||||
errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
||||
// errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE));
|
||||
// errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t textDispose(void) {
|
||||
errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
||||
// errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -47,9 +45,8 @@ errorret_t textDrawChar(
|
||||
vec4 uv;
|
||||
tilesetTileGetUV(tileset, tileIndex, uv);
|
||||
|
||||
|
||||
errorChain(spriteBatchPush(
|
||||
// texture,
|
||||
texture,
|
||||
x, y,
|
||||
x + tileset->tileWidth,
|
||||
y + tileset->tileHeight,
|
||||
@@ -73,8 +70,6 @@ errorret_t textDraw(
|
||||
float_t posX = x;
|
||||
float_t posY = y;
|
||||
|
||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture));
|
||||
|
||||
char_t c;
|
||||
int32_t i = 0;
|
||||
while((c = text[i++]) != '\0') {
|
||||
|
||||
@@ -8,5 +8,4 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
tileset.c
|
||||
texture.c
|
||||
palette.c
|
||||
)
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* 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];
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* 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,6 +11,8 @@
|
||||
#include "util/math.h"
|
||||
#include "display/display.h"
|
||||
|
||||
texture_t *TEXTURE_BOUND = NULL;
|
||||
|
||||
errorret_t textureInit(
|
||||
texture_t *texture,
|
||||
const int32_t width,
|
||||
@@ -23,18 +25,6 @@ errorret_t textureInit(
|
||||
assertTrue(width == mathNextPowTwo(width), "Width 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));
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
@@ -44,9 +34,18 @@ errorret_t textureInit(
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t textureBind(texture_t *texture) {
|
||||
errorChain(textureBindPlatform(texture));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t textureDispose(texture_t *texture) {
|
||||
assertNotNull(texture, "Texture cannot be NULL");
|
||||
|
||||
if(TEXTURE_BOUND == texture) {
|
||||
textureBind(NULL);
|
||||
}
|
||||
|
||||
errorChain(textureDisposePlatform(texture));
|
||||
errorOk();
|
||||
}
|
||||
@@ -7,12 +7,15 @@
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/texture/palette.h"
|
||||
#include "display/color.h"
|
||||
#include "display/texture/textureplatform.h"
|
||||
|
||||
#ifndef textureInitPlatform
|
||||
#error "textureInitPlatform should not be defined."
|
||||
#endif
|
||||
#ifndef textureBindPlatform
|
||||
#error "textureBindPlatform should not be defined."
|
||||
#endif
|
||||
#ifndef textureDisposePlatform
|
||||
#error "textureDisposePlatform should not be defined."
|
||||
#endif
|
||||
@@ -21,13 +24,12 @@ typedef textureformatplatform_t textureformat_t;
|
||||
typedef textureplatform_t texture_t;
|
||||
|
||||
typedef union texturedata_u {
|
||||
struct {
|
||||
uint8_t *indices;
|
||||
palette_t *palette;
|
||||
} paletted;
|
||||
uint8_t *paletteData;
|
||||
color_t *rgbaColors;
|
||||
} texturedata_t;
|
||||
|
||||
extern texture_t *TEXTURE_BOUND;
|
||||
|
||||
/**
|
||||
* Initializes a texture.
|
||||
*
|
||||
@@ -45,6 +47,13 @@ errorret_t textureInit(
|
||||
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.
|
||||
*
|
||||
|
||||
45
src/dusk/duskdefs.env
Normal file
45
src/dusk/duskdefs.env
Normal file
@@ -0,0 +1,45 @@
|
||||
# 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
|
||||
@@ -176,7 +176,7 @@ void mapUpdate() {
|
||||
void mapRender() {
|
||||
if(!mapIsLoaded()) return;
|
||||
|
||||
// textureBind(NULL);
|
||||
textureBind(NULL);
|
||||
for(chunkindex_t i = 0; i < MAP_CHUNK_COUNT; i++) {
|
||||
mapChunkRender(&MAP.chunks[i]);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ errorret_t sceneInit(void) {
|
||||
|
||||
errorret_t sceneUpdate(void) {
|
||||
#ifdef DUSK_TIME_DYNAMIC
|
||||
if(TIME.dynamicUpdate) {
|
||||
if(!TIME.dynamicUpdate) {
|
||||
errorOk();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(event)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(map)
|
||||
add_subdirectory(system)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(story)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(ui)
|
||||
@@ -15,5 +15,4 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
modulescreen.c
|
||||
moduletileset.c
|
||||
moduletexture.c
|
||||
moduleshader.c
|
||||
)
|
||||
@@ -69,16 +69,8 @@ void moduleCamera(scriptcontext_t *context) {
|
||||
|
||||
// Methods
|
||||
lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
|
||||
lua_register(
|
||||
context->luaState,
|
||||
"cameraGetProjectionMatrix",
|
||||
moduleCameraGetProjectionMatrix
|
||||
);
|
||||
lua_register(
|
||||
context->luaState,
|
||||
"cameraGetViewMatrix",
|
||||
moduleCameraGetViewMatrix
|
||||
);
|
||||
lua_register(context->luaState, "cameraPushMatrix", moduleCameraPushMatrix);
|
||||
lua_register(context->luaState, "cameraPopMatrix", moduleCameraPopMatrix);
|
||||
}
|
||||
|
||||
int moduleCameraCreate(lua_State *L) {
|
||||
@@ -126,6 +118,25 @@ int moduleCameraCreate(lua_State *L) {
|
||||
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) {
|
||||
assertNotNull(l, "Lua state cannot be NULL.");
|
||||
|
||||
@@ -299,35 +310,3 @@ int moduleCameraNewIndex(lua_State *l) {
|
||||
|
||||
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,6 +23,22 @@ void moduleCamera(scriptcontext_t *context);
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -36,19 +52,3 @@ int moduleCameraIndex(lua_State *l);
|
||||
* @param l The Lua state.
|
||||
*/
|
||||
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);
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* 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,20 +32,32 @@ int moduleSpriteBatchClear(lua_State *L) {
|
||||
int moduleSpriteBatchPush(lua_State *L) {
|
||||
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
|
||||
if(
|
||||
!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3) ||
|
||||
!lua_isnumber(L, 4)
|
||||
!lua_isnumber(L, 2) || !lua_isnumber(L, 3) || !lua_isnumber(L, 4) ||
|
||||
!lua_isnumber(L, 5)
|
||||
) {
|
||||
return luaL_error(L, "Sprite coordinates must be numbers");
|
||||
}
|
||||
|
||||
// Color (struct) or nil for white
|
||||
color_t *color = NULL;
|
||||
if(lua_gettop(L) < 5 || lua_isnil(L, 5)) {
|
||||
if(lua_gettop(L) < 6 || lua_isnil(L, 6)) {
|
||||
// Allow NULL
|
||||
} else if(lua_isuserdata(L, 5)) {
|
||||
color = (color_t*)luaL_checkudata(L, 5, "color_mt");
|
||||
} else if(lua_isuserdata(L, 6)) {
|
||||
color = (color_t*)luaL_checkudata(L, 6, "color_mt");
|
||||
} else {
|
||||
return luaL_error(L, "Sprite color must be a color struct or nil");
|
||||
}
|
||||
@@ -56,30 +68,31 @@ int moduleSpriteBatchPush(lua_State *L) {
|
||||
float_t u1 = 1.0f;
|
||||
float_t v1 = 1.0f;
|
||||
|
||||
if(lua_gettop(L) >= 7) {
|
||||
if(!lua_isnumber(L, 6) || !lua_isnumber(L, 7)) {
|
||||
if(lua_gettop(L) >= 8) {
|
||||
if(!lua_isnumber(L, 7) || !lua_isnumber(L, 8)) {
|
||||
return luaL_error(L, "Sprite UV min coordinates must be numbers");
|
||||
}
|
||||
|
||||
u0 = (float_t)lua_tonumber(L, 6);
|
||||
v0 = (float_t)lua_tonumber(L, 7);
|
||||
u0 = (float_t)lua_tonumber(L, 7);
|
||||
v0 = (float_t)lua_tonumber(L, 8);
|
||||
}
|
||||
|
||||
if(lua_gettop(L) >= 9) {
|
||||
if(!lua_isnumber(L, 8) || !lua_isnumber(L, 9)) {
|
||||
if(lua_gettop(L) >= 10) {
|
||||
if(!lua_isnumber(L, 9) || !lua_isnumber(L, 10)) {
|
||||
return luaL_error(L, "Sprite UV max coordinates must be numbers");
|
||||
}
|
||||
|
||||
u1 = (float_t)lua_tonumber(L, 8);
|
||||
v1 = (float_t)lua_tonumber(L, 9);
|
||||
u1 = (float_t)lua_tonumber(L, 9);
|
||||
v1 = (float_t)lua_tonumber(L, 10);
|
||||
}
|
||||
|
||||
float_t minX = (float_t)lua_tonumber(L, 1);
|
||||
float_t minY = (float_t)lua_tonumber(L, 2);
|
||||
float_t maxX = (float_t)lua_tonumber(L, 3);
|
||||
float_t maxY = (float_t)lua_tonumber(L, 4);
|
||||
float_t minX = (float_t)lua_tonumber(L, 2);
|
||||
float_t minY = (float_t)lua_tonumber(L, 3);
|
||||
float_t maxX = (float_t)lua_tonumber(L, 4);
|
||||
float_t maxY = (float_t)lua_tonumber(L, 5);
|
||||
|
||||
errorret_t ret = spriteBatchPush(
|
||||
spriteBatchPush(
|
||||
tex,
|
||||
minX,
|
||||
minY,
|
||||
maxX,
|
||||
@@ -90,14 +103,6 @@ int moduleSpriteBatchPush(lua_State *L) {
|
||||
u1,
|
||||
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;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ int moduleSceneSet(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
// Need string
|
||||
if(!lua_isstring(L, 1)) {
|
||||
if (!lua_isstring(L, 1)) {
|
||||
luaL_error(L, "sceneSet requires a string argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ int moduleSysPrint(lua_State *L) {
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
|
||||
for(int i = 1; i <= n; ++i) {
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
size_t len;
|
||||
const char *s = luaL_tolstring(L, i, &len); // converts any value to string
|
||||
luaL_addlstring(&b, s, len);
|
||||
lua_pop(L, 1); // pop result of luaL_tolstring
|
||||
if(i < n) luaL_addlstring(&b, "\t", 1);
|
||||
if (i < n) luaL_addlstring(&b, "\t", 1);
|
||||
}
|
||||
|
||||
luaL_pushresult(&b);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "script/module/input/moduleinput.h"
|
||||
#include "script/module/moduleplatform.h"
|
||||
#include "script/module/scene/modulescene.h"
|
||||
#include "script/module/item/moduleitem.h"
|
||||
#include "script/module/locale/modulelocale.h"
|
||||
#include "script/module/time/moduletime.h"
|
||||
#include "script/module/event/moduleevent.h"
|
||||
@@ -17,13 +18,13 @@
|
||||
#include "script/module/display/modulespritebatch.h"
|
||||
#include "script/module/display/modulecamera.h"
|
||||
#include "script/module/display/moduleglm.h"
|
||||
#include "script/module/display/moduleshader.h"
|
||||
#include "script/module/ui/moduleui.h"
|
||||
#include "script/module/display/moduletext.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/moduletileset.h"
|
||||
#include "script/scriptgame.h"
|
||||
#include "util/string.h"
|
||||
|
||||
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
||||
@@ -32,6 +33,7 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
||||
{ .name = "platform", .callback = modulePlatform },
|
||||
{ .name = "color", .callback = moduleColor },
|
||||
{ .name = "scene", .callback = moduleScene },
|
||||
{ .name = "item", .callback = moduleItem },
|
||||
{ .name = "locale", .callback = moduleLocale },
|
||||
{ .name = "time", .callback = moduleTime },
|
||||
{ .name = "event", .callback = moduleEvent },
|
||||
@@ -41,13 +43,10 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
||||
{ .name = "ui", .callback = moduleUi },
|
||||
{ .name = "text", .callback = moduleText },
|
||||
{ .name = "screen", .callback = moduleScreen },
|
||||
{ .name = "storyflag", .callback = moduleStoryFlag },
|
||||
{ .name = "map", .callback = moduleMap },
|
||||
{ .name = "texture", .callback = moduleTexture },
|
||||
{ .name = "tileset", .callback = moduleTileset },
|
||||
{ .name = "shader", .callback = moduleShader },
|
||||
|
||||
#ifdef SCRIPT_GAME_LIST
|
||||
SCRIPT_GAME_LIST
|
||||
#endif
|
||||
};
|
||||
|
||||
#define SCRIPT_MODULE_COUNT ( \
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user