Compare commits
23 Commits
70056cf4ca
...
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 |
176
.github/workflows/build.yml
vendored
176
.github/workflows/build.yml
vendored
@@ -1,5 +1,4 @@
|
||||
name: Build Dusk
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@@ -7,94 +6,52 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
# run-tests:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v6
|
||||
# - name: Set up Docker
|
||||
# uses: docker/setup-docker-action@v5
|
||||
# - name: Run tests in Docker
|
||||
# run: ./scripts/test-linux-docker.sh
|
||||
run-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Run tests in Docker
|
||||
run: ./scripts/test-linux-docker.sh
|
||||
|
||||
# build-linux:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v6
|
||||
# - name: Set up Docker
|
||||
# uses: docker/setup-docker-action@v5
|
||||
# - name: Build Linux
|
||||
# run: ./scripts/build-linux-docker.sh
|
||||
# - name: Upload Linux binary
|
||||
# uses: actions/upload-artifact@v6
|
||||
# with:
|
||||
# name: dusk-linux
|
||||
# path: build-linux/Dusk
|
||||
# if-no-files-found: error
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build Linux
|
||||
run: ./scripts/build-linux-docker.sh
|
||||
- name: Upload Linux binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-linux
|
||||
path: build-linux/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
# build-psp:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v6
|
||||
# - name: Set up Docker
|
||||
# uses: docker/setup-docker-action@v5
|
||||
# - name: Build psp
|
||||
# run: ./scripts/build-psp-docker.sh
|
||||
# - name: Move EBOOT.PBP to Dusk subfolder
|
||||
# run: |
|
||||
# mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
||||
# cp build-psp/EBOOT.PBP ./git-artifcats/Dusk/PSP/GAME/Dusk/EBOOT.PBP
|
||||
# - name: Upload psp binary
|
||||
# uses: actions/upload-artifact@v6
|
||||
# with:
|
||||
# name: dusk-psp
|
||||
# path: ./git-artifcats/Dusk
|
||||
# if-no-files-found: error
|
||||
|
||||
# build-gamecube:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v6
|
||||
# - name: Set up Docker
|
||||
# uses: docker/setup-docker-action@v5
|
||||
# - name: Build GameCube
|
||||
# run: ./scripts/build-gamecube-docker.sh
|
||||
# - name: Copy output files.
|
||||
# run: |
|
||||
# mkdir -p ./git-artifcats/Dusk
|
||||
# cp build-gamecube/Dusk.dol ./git-artifcats/Dusk/Dusk.dol
|
||||
# cp build-gamecube/dusk.dsk ./git-artifcats/Dusk/dusk.dsk
|
||||
# - name: Upload GameCube binary
|
||||
# uses: actions/upload-artifact@v6
|
||||
# with:
|
||||
# name: dusk-gamecube
|
||||
# path: ./git-artifcats/Dusk
|
||||
|
||||
# build-wii:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repository
|
||||
# uses: actions/checkout@v6
|
||||
# - name: Set up Docker
|
||||
# uses: docker/setup-docker-action@v5
|
||||
# - name: Build Wii
|
||||
# run: ./scripts/build-wii-docker.sh
|
||||
# - name: Copy output files.
|
||||
# run: |
|
||||
# mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||
# cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/Dusk.dol
|
||||
# cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||
# cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||
# - name: Upload Wii binary
|
||||
# uses: actions/upload-artifact@v6
|
||||
# with:
|
||||
# name: dusk-wii
|
||||
# path: ./git-artifcats/Dusk
|
||||
build-psp:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build psp
|
||||
run: ./scripts/build-psp-docker.sh
|
||||
- name: Move EBOOT.PBP to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
||||
cp build-psp/EBOOT.PBP ./git-artifcats/Dusk/PSP/GAME/Dusk/EBOOT.PBP
|
||||
- name: Upload psp binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-psp
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-knulli:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -105,13 +62,56 @@ jobs:
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build knulli
|
||||
run: ./scripts/build-knulli-docker.sh
|
||||
- name: Upload knulli binary
|
||||
uses: actions/upload-artifact@v6
|
||||
- name: Move output to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp -r build-knulli/dusk ./git-artifcats/Dusk
|
||||
- name: Upload knulli binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-knulli
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-gamecube:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build GameCube
|
||||
run: ./scripts/build-gamecube-docker.sh
|
||||
- name: Copy output files.
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
cp build-gamecube/Dusk.dol ./git-artifcats/Dusk/Dusk.dol
|
||||
cp build-gamecube/dusk.dsk ./git-artifcats/Dusk/dusk.dsk
|
||||
- name: Upload GameCube binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-gamecube
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
|
||||
build-wii:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Docker
|
||||
uses: docker/setup-docker-action@v5
|
||||
- name: Build Wii
|
||||
run: ./scripts/build-wii-docker.sh
|
||||
- name: Copy output files.
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
|
||||
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
|
||||
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
|
||||
- name: Upload Wii binary
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: dusk-wii
|
||||
path: ./git-artifcats/Dusk
|
||||
if-no-files-found: error
|
||||
@@ -70,6 +70,7 @@ 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,6 +9,7 @@ module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
module('shader')
|
||||
|
||||
CELL_STATE_DEFAULT = 0
|
||||
CELL_STATE_HOVER = 1
|
||||
@@ -62,7 +63,7 @@ function cellDraw(x, y, type)
|
||||
slice = cellSliceDisabled
|
||||
end
|
||||
|
||||
spriteBatchPush(textureCell,
|
||||
spriteBatchPush(
|
||||
x, y,
|
||||
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||
colorWhite(),
|
||||
@@ -182,18 +183,28 @@ function sceneUpdate()
|
||||
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
|
||||
end
|
||||
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
cameraPushMatrix(camera)
|
||||
camera.bottom = screenGetHeight()
|
||||
camera.bottom = 0
|
||||
camera.top = 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(
|
||||
nil,
|
||||
x, y, x + 32, y + 32,
|
||||
x, y,
|
||||
x + 32, y + 32,
|
||||
colorWhite()
|
||||
)
|
||||
spriteBatchFlush()
|
||||
|
||||
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||
spriteBatchFlush()
|
||||
|
||||
-- Update mouse position
|
||||
-- if INPUT_POINTER then
|
||||
@@ -250,7 +261,4 @@ function sceneRender()
|
||||
-- )
|
||||
-- end
|
||||
-- end
|
||||
spriteBatchFlush()
|
||||
|
||||
cameraPopMatrix()
|
||||
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.
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"]
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(dusk)
|
||||
add_subdirectory(duskrpg)
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||
add_subdirectory(dusklinux)
|
||||
|
||||
@@ -40,9 +40,6 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
||||
main.c
|
||||
)
|
||||
|
||||
# Defs
|
||||
dusk_env_to_h(duskdefs.env duskdefs.h)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
@@ -52,12 +49,9 @@ 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)
|
||||
|
||||
@@ -19,12 +19,9 @@ 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;
|
||||
@@ -60,21 +57,14 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
||||
},
|
||||
|
||||
[ASSET_TYPE_TEXTURE] = {
|
||||
.extension = "dpt",
|
||||
.extension = "DTX",
|
||||
.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
|
||||
@@ -91,16 +81,4 @@ 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] != 'P' ||
|
||||
assetData->header[2] != 'T'
|
||||
assetData->header[1] != 'T' ||
|
||||
assetData->header[2] != 'X'
|
||||
) {
|
||||
errorThrow("Invalid texture header");
|
||||
}
|
||||
@@ -44,18 +44,35 @@ errorret_t assetTextureLoad(assetentire_t entire) {
|
||||
errorThrow("Invalid texture dimensions");
|
||||
}
|
||||
|
||||
textureInit(
|
||||
texture,
|
||||
assetData->width,
|
||||
assetData->height,
|
||||
TEXTURE_FORMAT_PALETTE,
|
||||
(texturedata_t){
|
||||
.paletted = {
|
||||
.indices = NULL,
|
||||
.palette = NULL
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
errorChain(textureInit(
|
||||
texture, assetData->width, assetData->height, format, data
|
||||
));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/color.h"
|
||||
|
||||
#define ASSET_TEXTURE_WIDTH_MAX 2048
|
||||
#define ASSET_TEXTURE_HEIGHT_MAX 2048
|
||||
@@ -20,9 +21,10 @@ 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 palette[ASSET_TEXTURE_SIZE_MAX];
|
||||
uint8_t data[ASSET_TEXTURE_SIZE_MAX * sizeof(color4b_t)];
|
||||
} assettexture_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
@@ -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 = -1.0f;
|
||||
camera->nearClip = 0.1f;
|
||||
camera->farClip = 1.0f;
|
||||
|
||||
camera->viewType = CAMERA_VIEW_TYPE_2D;
|
||||
@@ -84,7 +84,7 @@ void cameraGetViewMatrix(camera_t *camera, mat4 dest) {
|
||||
assertNotNull(dest, "Destination matrix must not be null");
|
||||
|
||||
if(camera->viewType == CAMERA_VIEW_TYPE_MATRIX) {
|
||||
glm_mat4_copy(camera->view, dest);
|
||||
glm_mat4_ucopy(camera->view, dest);
|
||||
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
|
||||
glm_mat4_identity(dest);
|
||||
glm_lookat(
|
||||
|
||||
@@ -20,11 +20,27 @@
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "time/time.h"
|
||||
|
||||
display_t DISPLAY = { 0 };
|
||||
#include "script/module/display/moduleshader.h"
|
||||
|
||||
texture_t PALETTE_TEXTURE;
|
||||
texture_t UNCOMPRESSED_TEXTURE;
|
||||
texture_t COMPRESSED_TEXTURE;
|
||||
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));
|
||||
@@ -32,64 +48,27 @@ errorret_t displayInit(void) {
|
||||
#ifdef displayPlatformInit
|
||||
errorChain(displayPlatformInit());
|
||||
#endif
|
||||
|
||||
errorChain(shaderInit(&SHADER_UNLIT, &SHADER_UNLIT_DEFINITION));
|
||||
errorChain(quadInit());
|
||||
errorChain(frameBufferInitBackBuffer());
|
||||
errorChain(spriteBatchInit());
|
||||
errorChain(textInit());
|
||||
errorChain(screenInit());
|
||||
|
||||
PALETTES[0].colors[0] = COLOR_RED;
|
||||
PALETTES[0].colors[1] = COLOR_GREEN;
|
||||
PALETTES[0].colors[2] = COLOR_BLUE;
|
||||
PALETTES[0].colors[3] = COLOR_WHITE;
|
||||
PALETTES[0].colors[4] = COLOR_MAGENTA;
|
||||
PALETTES[0].colors[5] = COLOR_CYAN;
|
||||
PALETTES[0].colors[6] = COLOR_YELLOW;
|
||||
PALETTES[0].colors[7] = COLOR_BLACK;
|
||||
PALETTES[0].count = 8;
|
||||
// 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));
|
||||
|
||||
uint8_t indices[64] = {
|
||||
0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,
|
||||
3,3,3,3,3,3,3,3,
|
||||
4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,
|
||||
6,6,6,6,6,6,6,6,
|
||||
7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
errorChain(textureInit(
|
||||
&PALETTE_TEXTURE,
|
||||
8, 8,
|
||||
TEXTURE_FORMAT_PALETTE,
|
||||
(texturedata_t){
|
||||
.paletted = {
|
||||
.indices = indices,
|
||||
.palette = &PALETTES[0]
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
errorChain(textureInit(
|
||||
&UNCOMPRESSED_TEXTURE,
|
||||
8, 8,
|
||||
TEXTURE_FORMAT_RGBA,
|
||||
(texturedata_t){
|
||||
.rgbaColors = (color_t[]){
|
||||
COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK,
|
||||
COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED,
|
||||
COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN,
|
||||
COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
|
||||
COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE,
|
||||
COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA,
|
||||
COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN,
|
||||
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW
|
||||
}
|
||||
}
|
||||
));
|
||||
errorChain(meshInit(&mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, 3, vertices));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -110,38 +89,7 @@ errorret_t displayUpdate(void) {
|
||||
SCREEN.background
|
||||
);
|
||||
|
||||
camera_t camera;
|
||||
// cameraInitOrthographic(&camera);
|
||||
// camera.orthographic.left = 0.0f;
|
||||
// camera.orthographic.right = SCREEN.width;
|
||||
// camera.orthographic.top = SCREEN.height;
|
||||
// camera.orthographic.bottom = 0.0f;
|
||||
cameraInitPerspective(&camera);
|
||||
camera.lookat.position[0] = 3.0f;
|
||||
camera.lookat.position[1] = 3.0f;
|
||||
camera.lookat.position[2] = 3.0f;
|
||||
|
||||
mat4 proj, view, model;
|
||||
cameraGetProjectionMatrix(&camera, proj);
|
||||
cameraGetViewMatrix(&camera, view);
|
||||
glm_mat4_identity(model);
|
||||
|
||||
errorChain(shaderBind(&SHADER_UNLIT));
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
||||
// errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &PALETTE_TEXTURE));
|
||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &UNCOMPRESSED_TEXTURE));
|
||||
errorChain(spriteBatchPush(
|
||||
0.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
COLOR_WHITE,
|
||||
0.0f, 0.0f,
|
||||
1.0f, 1.0f
|
||||
));
|
||||
errorChain(spriteBatchFlush());
|
||||
|
||||
// errorCatch(errorPrint(sceneRender()));
|
||||
errorChain(sceneRender());
|
||||
|
||||
// Render UI
|
||||
// uiRender();
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
shader.c
|
||||
shaderunlit.c
|
||||
)
|
||||
@@ -8,15 +8,19 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -28,6 +32,7 @@ errorret_t shaderSetMatrix(
|
||||
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();
|
||||
}
|
||||
@@ -39,6 +44,7 @@ errorret_t shaderSetTexture(
|
||||
) {
|
||||
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();
|
||||
}
|
||||
@@ -56,6 +62,7 @@ errorret_t shaderSetTexture(
|
||||
|
||||
errorret_t shaderDispose(shader_t *shader) {
|
||||
assertNotNull(shader, "Shader cannot be null");
|
||||
bound = NULL;
|
||||
errorChain(shaderDisposePlatform(shader));
|
||||
errorOk();
|
||||
}
|
||||
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 };
|
||||
@@ -15,4 +15,4 @@
|
||||
// #define SHADER_UNLIT_COLOR "u_Color"
|
||||
|
||||
extern shaderdefinition_t SHADER_UNLIT_DEFINITION;
|
||||
static shader_t SHADER_UNLIT;
|
||||
extern shader_t SHADER_UNLIT;
|
||||
@@ -35,14 +35,13 @@ errorret_t spriteBatchPush(
|
||||
const float_t u1,
|
||||
const float_t v1
|
||||
) {
|
||||
errorChain(spriteBatchPush3D(
|
||||
return spriteBatchPush3D(
|
||||
(vec3){ minX, minY, 0 },
|
||||
(vec3){ maxX, maxY, 0 },
|
||||
color,
|
||||
(vec2){ u0, v0 },
|
||||
(vec2){ u1, v1 }
|
||||
));
|
||||
errorOk();
|
||||
);
|
||||
}
|
||||
|
||||
errorret_t spriteBatchPush3D(
|
||||
@@ -53,11 +52,14 @@ errorret_t spriteBatchPush3D(
|
||||
const vec2 uv1
|
||||
) {
|
||||
// Need to flush?
|
||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX) {
|
||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
|
||||
errorChain(spriteBatchFlush());
|
||||
}
|
||||
|
||||
size_t vertexOffset = SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT;
|
||||
size_t vertexOffset = (
|
||||
SPRITEBATCH.spriteCount +
|
||||
(SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH)
|
||||
) * QUAD_VERTEX_COUNT;
|
||||
quadBuffer3D(
|
||||
&SPRITEBATCH_VERTICES[vertexOffset],
|
||||
min, max, color, uv0, uv1
|
||||
@@ -68,6 +70,7 @@ errorret_t spriteBatchPush3D(
|
||||
|
||||
void spriteBatchClear() {
|
||||
SPRITEBATCH.spriteCount = 0;
|
||||
SPRITEBATCH.spriteFlush = 0;
|
||||
}
|
||||
|
||||
errorret_t spriteBatchFlush() {
|
||||
@@ -76,9 +79,19 @@ errorret_t spriteBatchFlush() {
|
||||
}
|
||||
|
||||
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
|
||||
errorChain(meshFlush(&SPRITEBATCH.mesh, 0, vertexCount));
|
||||
errorChain(meshDraw(&SPRITEBATCH.mesh, 0, vertexCount));
|
||||
spriteBatchClear();
|
||||
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;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
#pragma once
|
||||
#include "display/mesh/quad.h"
|
||||
|
||||
#define SPRITEBATCH_SPRITES_MAX 16
|
||||
#define SPRITEBATCH_SPRITES_MAX 32
|
||||
#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;
|
||||
} spritebatch_t;
|
||||
|
||||
// Have to define these seperately because of alignment in certain platforms.
|
||||
|
||||
@@ -11,17 +11,19 @@
|
||||
#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.dpt", &DEFAULT_FONT_TEXTURE));
|
||||
// errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
||||
errorChain(assetLoad("ui/minogram.dtx", &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();
|
||||
}
|
||||
|
||||
@@ -45,6 +47,7 @@ errorret_t textDrawChar(
|
||||
vec4 uv;
|
||||
tilesetTileGetUV(tileset, tileIndex, uv);
|
||||
|
||||
|
||||
errorChain(spriteBatchPush(
|
||||
// texture,
|
||||
x, y,
|
||||
@@ -70,6 +73,8 @@ 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') {
|
||||
|
||||
@@ -26,7 +26,6 @@ typedef union texturedata_u {
|
||||
palette_t *palette;
|
||||
} paletted;
|
||||
color_t *rgbaColors;
|
||||
uint8_t *compressedData;
|
||||
} texturedata_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
@@ -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,11 +7,8 @@
|
||||
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,4 +15,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
modulescreen.c
|
||||
moduletileset.c
|
||||
moduletexture.c
|
||||
moduleshader.c
|
||||
)
|
||||
@@ -69,6 +69,16 @@ void moduleCamera(scriptcontext_t *context) {
|
||||
|
||||
// Methods
|
||||
lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
|
||||
lua_register(
|
||||
context->luaState,
|
||||
"cameraGetProjectionMatrix",
|
||||
moduleCameraGetProjectionMatrix
|
||||
);
|
||||
lua_register(
|
||||
context->luaState,
|
||||
"cameraGetViewMatrix",
|
||||
moduleCameraGetViewMatrix
|
||||
);
|
||||
}
|
||||
|
||||
int moduleCameraCreate(lua_State *L) {
|
||||
@@ -289,3 +299,35 @@ 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;
|
||||
}
|
||||
@@ -36,3 +36,19 @@ 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);
|
||||
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();
|
||||
@@ -10,7 +10,6 @@
|
||||
#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"
|
||||
@@ -18,13 +17,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[] = {
|
||||
@@ -33,7 +32,6 @@ 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 },
|
||||
@@ -43,10 +41,13 @@ 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 ( \
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
|
||||
void cameraPushMatrixDolphin(camera_t *camera) {
|
||||
assertNotNull(camera, "Camera cannot be null");
|
||||
assertTrue(
|
||||
camera->nearClip > 0.0f,
|
||||
"Camera near clip must be greater than 0 for Dolphin"
|
||||
);
|
||||
|
||||
Mtx44 guProjection;
|
||||
Mtx guView;
|
||||
|
||||
@@ -77,7 +77,8 @@ errorret_t displayInitDolphin(void) {
|
||||
|
||||
// Setup cull modes
|
||||
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_SetColorUpdate(GX_TRUE);
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ errorret_t meshDrawDolphin(
|
||||
assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong");
|
||||
assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong");
|
||||
|
||||
textureDolphinUploadTEV();
|
||||
|
||||
DCFlushRange(
|
||||
(void*)&mesh->vertices[vertexOffset],
|
||||
sizeof(meshvertex_t) * vertexCount
|
||||
@@ -62,6 +60,8 @@ errorret_t meshDrawDolphin(
|
||||
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_InvVtxCache();
|
||||
|
||||
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
||||
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
|
||||
GX_Position1x16(i);
|
||||
|
||||
@@ -77,6 +77,88 @@ errorret_t shaderSetMatrixDolphin(
|
||||
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");
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "display/texture/texture.h"
|
||||
|
||||
typedef struct {
|
||||
mat4 view;
|
||||
@@ -66,6 +66,20 @@ errorret_t shaderSetMatrixDolphin(
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -14,5 +14,5 @@ typedef shaderdefinitiondolphin_t shaderdefinitionplatform_t;
|
||||
#define shaderInitPlatform shaderInitDolphin
|
||||
#define shaderBindPlatform shaderBindDolphin
|
||||
#define shaderSetMatrixPlatform shaderSetMatrixDolphin
|
||||
// #define shaderSetTexturePlatform shaderSetTextureDolphin
|
||||
#define shaderSetTexturePlatform shaderSetTextureDolphin
|
||||
#define shaderDisposePlatform shaderDisposeDolphin
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "display/texture/texture.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
errorret_t textureInitDolphin(
|
||||
texturedolphin_t *texture,
|
||||
@@ -15,191 +16,101 @@ errorret_t textureInitDolphin(
|
||||
const textureformatdolphin_t format,
|
||||
const texturedata_t data
|
||||
) {
|
||||
// switch(format) {
|
||||
// case TEXTURE_FORMAT_RGBA:
|
||||
// assertTrue(
|
||||
// (width % 4) == 0 && (height % 4) == 0,
|
||||
// "RGB5A3 requires w/h multiple of 4 (or pad)"
|
||||
// );
|
||||
switch(format) {
|
||||
case TEXTURE_FORMAT_RGBA: {
|
||||
size_t rgbaSize = width * height * sizeof(uint8_t) * 4;
|
||||
|
||||
// // Convert to RGB5A3 format
|
||||
// size_t rgbaSize = width * height * sizeof(u16);
|
||||
// texture->rgba = (u16*)memalign(32, rgbaSize);
|
||||
// assertNotNull(texture->rgba, "Failed to allocate texture RGBA data");
|
||||
// Dolphin takes the RGBA data as 4x4 tiled layout.
|
||||
texture->rgba = memoryAllocate(rgbaSize);
|
||||
|
||||
// for(uint32_t y = 0; y < height; ++y) {
|
||||
// for(uint32_t x = 0; x < width; ++x) {
|
||||
// const int src = y * width + x;
|
||||
for(uint32_t y = 0; y < height; ++y) {
|
||||
for(uint32_t x = 0; x < width; ++x) {
|
||||
const int src = y * width + x;
|
||||
|
||||
// const int tileX = x >> 2;
|
||||
// const int tileY = y >> 2;
|
||||
// const int tilesPerRow = width >> 2;
|
||||
// const int tileIndex = tileY * tilesPerRow + tileX;
|
||||
// const int tileBaseWords = tileIndex * 16;
|
||||
// const int inTile = ((y & 3) << 2) + (x & 3);
|
||||
// const int dest = tileBaseWords + inTile;
|
||||
const int tileX = x >> 2;
|
||||
const int tileY = y >> 2;
|
||||
const int tilesPerRow = width >> 2;
|
||||
const int tileIndex = tileY * tilesPerRow + tileX;
|
||||
const int inTile = ((y & 3) << 2) + (x & 3);
|
||||
const int tileBase = tileIndex * 64;
|
||||
|
||||
// color4b_t col = data.rgba.colors[src];
|
||||
color_t col = data.rgbaColors[src];
|
||||
|
||||
// u16 outCol;
|
||||
// if(col.a < 255) {
|
||||
// // 0AAA RRRR GGGG BBBB
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// AR plane
|
||||
texture->rgba[tileBase + inTile * 2 + 0] = col.a;
|
||||
texture->rgba[tileBase + inTile * 2 + 1] = col.r;
|
||||
|
||||
// DCFlushRange(texture->rgba, rgbaSize);
|
||||
// GX_InitTexObj(
|
||||
// &texture->texObj,
|
||||
// texture->rgba,
|
||||
// width, height,
|
||||
// GX_TF_RGB5A3,
|
||||
// GX_REPEAT, GX_REPEAT,
|
||||
// GX_FALSE
|
||||
// );
|
||||
// GB plane
|
||||
texture->rgba[tileBase + 32 + inTile * 2 + 0] = col.g;
|
||||
texture->rgba[tileBase + 32 + inTile * 2 + 1] = col.b;
|
||||
}
|
||||
}
|
||||
DCFlushRange(texture->rgba, rgbaSize);
|
||||
GX_InitTexObj(
|
||||
&texture->texObj,
|
||||
texture->rgba,
|
||||
width, height,
|
||||
format,
|
||||
GX_REPEAT, GX_REPEAT,
|
||||
GX_FALSE
|
||||
);
|
||||
|
||||
// DCFlushRange(texture->rgba, rgbaSize);
|
||||
// GX_InvalidateTexAll();
|
||||
DCFlushRange(texture->rgba, rgbaSize);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
// GX_InitTexObjLOD(
|
||||
// &texture->texObj,
|
||||
// GX_NEAR, GX_NEAR,
|
||||
// 0.0f, 0.0f, 0.0f,
|
||||
// GX_FALSE,
|
||||
// GX_FALSE,
|
||||
// GX_ANISO_1
|
||||
// );
|
||||
// break;
|
||||
GX_InitTexObjLOD(
|
||||
&texture->texObj,
|
||||
GX_NEAR, GX_NEAR,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
GX_FALSE,
|
||||
GX_FALSE,
|
||||
GX_ANISO_1
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
// case TEXTURE_FORMAT_PALETTE: {
|
||||
// // Not supported, convert to RGBA using lookup
|
||||
// color_t* formatted = memoryAllocate(width * height * sizeof(color_t));
|
||||
// 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];
|
||||
// }
|
||||
case TEXTURE_FORMAT_PALETTE: {
|
||||
assertUnreachable("Paletted textures not yet implemented for Dolphin");
|
||||
break;
|
||||
}
|
||||
|
||||
// textureInit(
|
||||
// texture, width, height, TEXTURE_FORMAT_RGBA,
|
||||
// (texturedata_t){
|
||||
// .rgba = { .colors = formatted }
|
||||
// }
|
||||
// );
|
||||
// memoryFree(formatted);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// default:
|
||||
// assertUnreachable("Unsupported texture format for Dolphin");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// texture->ready = true;
|
||||
default: {
|
||||
assertUnreachable("Unsupported texture format for Dolphin");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
|
||||
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 {
|
||||
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
|
||||
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
|
||||
// TEXTURE_FORMAT_RGB4A3 = GX_TF_RGB5A3,
|
||||
// TEXTURE_FORMAT_RGB5 = GX_TF_RGB565,
|
||||
} textureformatdolphin_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -20,6 +22,11 @@ typedef struct {
|
||||
textureformatdolphin_t format;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
|
||||
union {
|
||||
uint8_t *rgba;
|
||||
// u16 *rgba;
|
||||
};
|
||||
} texturedolphin_t;
|
||||
|
||||
/**
|
||||
@@ -55,9 +62,3 @@ errorret_t textureBindDolphin(texturedolphin_t *texture);
|
||||
* @return An error if the texture failed to dispose, otherwise success.
|
||||
*/
|
||||
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);
|
||||
@@ -59,7 +59,7 @@ void cameraPushMatrixGL(camera_t *camera) {
|
||||
|
||||
switch(camera->viewType) {
|
||||
case CAMERA_VIEW_TYPE_MATRIX:
|
||||
glm_mat4_copy(camera->view, view);
|
||||
glm_mat4_ucopy(camera->view, view);
|
||||
break;
|
||||
|
||||
case CAMERA_VIEW_TYPE_LOOKAT:
|
||||
|
||||
@@ -11,13 +11,6 @@ errorret_t displayOpenGLInit(void) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#if DUSK_OPENGL_LEGACY
|
||||
glDisable(GL_LIGHTING);// PSP defaults this on?
|
||||
errorChain(errorGLCheck());
|
||||
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
|
||||
errorChain(errorGLCheck());
|
||||
#endif
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
errorChain(errorGLCheck());
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
@@ -32,5 +25,12 @@ errorret_t displayOpenGLInit(void) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#if DUSK_OPENGL_LEGACY
|
||||
glDisable(GL_LIGHTING);// PSP defaults this on?
|
||||
errorChain(errorGLCheck());
|
||||
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
|
||||
errorChain(errorGLCheck());
|
||||
#endif
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -113,8 +113,10 @@ errorret_t meshFlushGL(
|
||||
errorChain(errorGLCheck());
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertCount * sizeof(meshvertex_t),
|
||||
&mesh->vertices[vertOffset],
|
||||
mesh->vertexCount * sizeof(meshvertex_t),
|
||||
mesh->vertices,
|
||||
// vertCount * sizeof(meshvertex_t),
|
||||
// &mesh->vertices[vertOffset],
|
||||
GL_DYNAMIC_DRAW
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
@@ -157,11 +157,10 @@ errorret_t shaderParamGetLocationGL(
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
assertUnreachable("Cannot get uniform locations on legacy opengl.");
|
||||
#else
|
||||
shadergl_t *shaderGL = (shadergl_t *)shader;
|
||||
*location = glGetUniformLocation(shaderGL->shaderProgramId, name);
|
||||
errorret_t err = errorGLCheck();
|
||||
if(err.code != ERROR_OK) {
|
||||
errorChain(err);
|
||||
*location = glGetUniformLocation(shader->shaderProgramId, name);
|
||||
errorChain(errorGLCheck());
|
||||
if(*location == -1) {
|
||||
errorThrow("Uniform '%s' not found in shader.", name);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -174,25 +173,26 @@ errorret_t shaderSetMatrixGL(
|
||||
mat4 mat
|
||||
) {
|
||||
assertNotNull(shader, "Shader cannot be null");
|
||||
assertNotNull(mat, "Matrix data cannot be null");
|
||||
assertStrLenMin(name, 1, "Uniform name cannot be empty");
|
||||
assertNotNull(mat, "Matrix data cannot be null");
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
assertTrue(
|
||||
SHADER_LEGACY.boundShader == shader,
|
||||
"Shader must be bound to set legacy matrices."
|
||||
);
|
||||
// Use unaligned copy to safely handle possibly unaligned input matrices
|
||||
if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) {
|
||||
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_PROJ;
|
||||
glm_mat4_copy(mat, shader->proj);
|
||||
glm_mat4_ucopy(mat, shader->proj);
|
||||
|
||||
} else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) {
|
||||
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_VIEW;
|
||||
glm_mat4_copy(mat, shader->view);
|
||||
glm_mat4_ucopy(mat, shader->view);
|
||||
|
||||
} else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) {
|
||||
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_MODEL;
|
||||
glm_mat4_copy(mat, shader->model);
|
||||
glm_mat4_ucopy(mat, shader->model);
|
||||
|
||||
} else {
|
||||
assertUnreachable("Cannot use a custom matrix on legacy opengl.");
|
||||
@@ -233,6 +233,8 @@ errorret_t shaderSetTextureGL(
|
||||
errorChain(errorGLCheck());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#else
|
||||
if(shader->setTexture == NULL) {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
// Uniforms
|
||||
"uniform sampler2D u_Texture;\n"
|
||||
"uniform int u_TextureType;\n"
|
||||
"uniform vec4 u_Colors[256];\n"// For paletted textures.
|
||||
"uniform uint u_Colors[256];\n"// For paletted textures.
|
||||
"uniform int u_ColorCount;\n"
|
||||
// Fragment shader inputs
|
||||
"in vec4 v_Color;\n"
|
||||
@@ -140,8 +140,13 @@
|
||||
" }\n"
|
||||
" if(u_TextureType == 2) {\n"// Paletted texture
|
||||
" vec4 texColor = texture(u_Texture, v_TexCoord);\n"
|
||||
" int index = int(floor(texColor.r * 255.0));\n"
|
||||
" vec4 paletteColor = u_Colors[index];\n"
|
||||
" uint index = uint(floor(texColor.r * 255.0));\n"
|
||||
" uint palColor = u_Colors[index];\n"
|
||||
" float r = float((palColor >> 24) & 0xFFu) / 255.0;\n"
|
||||
" float g = float((palColor >> 16) & 0xFFu) / 255.0;\n"
|
||||
" float b = float((palColor >> 8) & 0xFFu) / 255.0;\n"
|
||||
" float a = float((palColor >> 0) & 0xFFu) / 255.0;\n"
|
||||
" vec4 paletteColor = vec4(r, g, b, a);\n"
|
||||
" FragColor = paletteColor;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
|
||||
@@ -78,10 +78,6 @@ errorret_t textureInitGL(
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
#endif
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
|
||||
16
src/duskrpg/CMakeLists.txt
Normal file
16
src/duskrpg/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(map)
|
||||
add_subdirectory(story)
|
||||
add_subdirectory(script)
|
||||
7
src/duskrpg/script/CMakeLists.txt
Normal file
7
src/duskrpg/script/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(module)
|
||||
9
src/duskrpg/script/module/CMakeLists.txt
Normal file
9
src/duskrpg/script/module/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirectories
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(map)
|
||||
add_subdirectory(story)
|
||||
16
src/duskrpg/script/scriptgame.h
Normal file
16
src/duskrpg/script/scriptgame.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/item/moduleitem.h"
|
||||
#include "script/module/story/modulestoryflag.h"
|
||||
#include "script/module/map/modulemap.h"
|
||||
|
||||
#define SCRIPT_GAME_LIST \
|
||||
{ .name = "item", .callback = moduleItem }, \
|
||||
{ .name = "storyflag", .callback = moduleStoryFlag }, \
|
||||
{ .name = "map", .callback = moduleMap },
|
||||
@@ -4,4 +4,3 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(run_python)
|
||||
add_subdirectory(env_to_h)
|
||||
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(dusk_env_to_h INPUT_PATH OUTPUT_NAME_RELATIVE)
|
||||
set(DUSK_DEFS_TARGET_NAME "DUSK_DEFS_${OUTPUT_NAME_RELATIVE}")
|
||||
dusk_run_python(
|
||||
${DUSK_DEFS_TARGET_NAME}
|
||||
tools.env_to_h
|
||||
--env "${CMAKE_CURRENT_LIST_DIR}/${INPUT_PATH}"
|
||||
--output ${DUSK_GENERATED_HEADERS_DIR}/${OUTPUT_NAME_RELATIVE}
|
||||
)
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} ${DUSK_DEFS_TARGET_NAME})
|
||||
endfunction()
|
||||
@@ -1,46 +0,0 @@
|
||||
import argparse
|
||||
import os
|
||||
from dotenv import load_dotenv, dotenv_values
|
||||
|
||||
parser = argparse.ArgumentParser(description="Convert .env to .h defines")
|
||||
parser.add_argument("--env", required=True, help="Path to .env file")
|
||||
parser.add_argument("--output", required=True, help="Path to output .h file")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Load .env file
|
||||
load_dotenv(dotenv_path=args.env)
|
||||
fileDefs = dotenv_values(dotenv_path=args.env)
|
||||
|
||||
outHeader = ""
|
||||
outHeader += "#include \"dusk.h\"\n\n"
|
||||
for key, value in fileDefs.items():
|
||||
# Determine type and print out appropriate C type define.
|
||||
|
||||
# Integer
|
||||
try:
|
||||
asInt = int(value)
|
||||
outHeader += f"#define {key} {asInt}\n"
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
|
||||
# Float
|
||||
try:
|
||||
asFloat = float(value)
|
||||
outHeader += f"#define {key} {asFloat}f\n"
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
|
||||
# Boolean
|
||||
if value.lower() in ['true', 'false']:
|
||||
asBool = '1' if value.lower() == 'true' else '0'
|
||||
outHeader += f"#define {key} {asBool}\n"
|
||||
continue
|
||||
|
||||
# String
|
||||
outHeader += f'#define {key} "{value}"\n'
|
||||
|
||||
# Write to output file
|
||||
with open(args.output, 'w') as outFile:
|
||||
outFile.write(outHeader)
|
||||
417
tools/texture-creator.html
Normal file
417
tools/texture-creator.html
Normal file
@@ -0,0 +1,417 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dusk Tools / Texture Creator</title>
|
||||
|
||||
<style type="text/css">
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
canvas {
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Dusk Texture Creator</h1>
|
||||
<p>
|
||||
Creates texture files. This will not create palletized textures, use the
|
||||
palette-indexer.html tool for that. This will instead work for all other
|
||||
kinds of textures.
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<input type="file" data-file-input />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Settings</h2>
|
||||
|
||||
<div>
|
||||
Texture Format:
|
||||
<div>
|
||||
<label>
|
||||
RGBA
|
||||
<input type="radio" name="texture-type" value="rgba" />
|
||||
</label><br />
|
||||
|
||||
<label>
|
||||
RGB
|
||||
<input type="radio" name="texture-type" value="rgb" />
|
||||
</label><br />
|
||||
|
||||
<label>
|
||||
RGB565
|
||||
<input type="radio" name="texture-type" value="rgb565" checked />
|
||||
</label><br />
|
||||
|
||||
<label>
|
||||
RGB5A3 (Dolphin Only)
|
||||
<input type="radio" name="texture-type" value="rgb5a3" />
|
||||
</label><br />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="pad-power-of-two">
|
||||
Pad to power of two
|
||||
<input type="checkbox" id="pad-power-of-two" name="pad-power-of-two" checked />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Preview</h2>
|
||||
<div>
|
||||
<label>
|
||||
Preview Scale:
|
||||
<input type="number" value="2" data-preview-scale min="1" step="1" />
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
Preview Background:
|
||||
<button data-page-bg-white>White</button>
|
||||
<button data-page-bg-transparent>Black</button>
|
||||
<button data-page-bg-checkerboard>Checkerboard</button>
|
||||
<button data-page-bg-magenta>Magenta</button>
|
||||
<button data-page-bg-blue>Blue</button>
|
||||
<button data-page-bg-green>Green</button>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<canvas data-output-preview style="border:1px solid black;"></canvas>
|
||||
</div>
|
||||
<div>
|
||||
<textarea data-output-information readonly rows="15" style="width: 500px;"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<button data-download>Download Texture</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
const elFileInput = document.querySelector('[data-file-input]');
|
||||
const elFileError = document.querySelector('[data-file-error]');
|
||||
const elPreviewScale = document.querySelector('[data-preview-scale]');
|
||||
const elOutputPreview = document.querySelector('[data-output-preview]');
|
||||
const elOutputInformation = document.querySelector('[data-output-information]');
|
||||
const elTextureType = document.querySelectorAll('input[name="texture-type"]');
|
||||
const elPadPowerOfTwo = document.querySelector('#pad-power-of-two');
|
||||
const btnDownload = document.querySelector('[data-download]');
|
||||
const btnBackgroundWhite = document.querySelector('[data-page-bg-white]');
|
||||
const btnBackgroundTransparent = document.querySelector('[data-page-bg-transparent]');
|
||||
const btnBackgroundCheckerboard = document.querySelector('[data-page-bg-checkerboard]');
|
||||
const btnBackgroundMagenta = document.querySelector('[data-page-bg-magenta]');
|
||||
const btnBackgroundBlue = document.querySelector('[data-page-bg-blue]');
|
||||
const btnBackgroundGreen = document.querySelector('[data-page-bg-green]');
|
||||
|
||||
let image;
|
||||
let imageName;
|
||||
let textureData;
|
||||
let rawData;
|
||||
let width, height, paddedWidth, paddedHeight;
|
||||
|
||||
// Methods
|
||||
const nextPowerOfTwo = n => {
|
||||
if(n <= 0) return 1;
|
||||
return 2 ** Math.ceil(Math.log2(n));
|
||||
}
|
||||
|
||||
const updatePreview = () => {
|
||||
if(!image) return;
|
||||
|
||||
console.log('Updating preview with image:', image);
|
||||
|
||||
const scale = parseInt(elPreviewScale.value) || 1;
|
||||
const padToPowerOfTwo = elPadPowerOfTwo.checked;
|
||||
const textureType = Array.from(elTextureType).find(r => r.checked)?.value || 'rgba';
|
||||
|
||||
width = image.width;
|
||||
height = image.height;
|
||||
let scaledWidth = width * scale;
|
||||
let scaledHeight = height * scale;
|
||||
paddedWidth = padToPowerOfTwo ? nextPowerOfTwo(width) : width;
|
||||
paddedHeight = padToPowerOfTwo ? nextPowerOfTwo(height) : height;
|
||||
let paddedScaledWidth = paddedWidth * scale;
|
||||
let paddedScaledHeight = paddedHeight * scale;
|
||||
|
||||
const tempCanvas = document.createElement('canvas');
|
||||
tempCanvas.width = paddedWidth;
|
||||
tempCanvas.height = paddedHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d');
|
||||
tempCtx.imageSmoothingEnabled = false;
|
||||
tempCtx.clearRect(0, 0, tempCanvas.width, tempCanvas.height);
|
||||
tempCtx.drawImage(image, 0, 0, width, height);
|
||||
|
||||
const pixels = tempCtx.getImageData(0, 0, paddedWidth, paddedHeight);
|
||||
|
||||
let sizeBytes;
|
||||
let strTextureType = Array.from(elTextureType).find(r => r.checked)?.value || 'rgba';
|
||||
strTextureType = strTextureType.toLowerCase();
|
||||
rawData = new Uint8Array(paddedWidth * paddedHeight * 4);
|
||||
|
||||
if(strTextureType === 'rgba') {
|
||||
textureData = new Uint8Array(pixels.data.buffer);
|
||||
rawData = new Uint8Array(pixels.data.buffer);
|
||||
sizeBytes = paddedWidth * paddedHeight * 4;
|
||||
|
||||
} else if(strTextureType === 'rgb') {
|
||||
sizeBytes = paddedWidth * paddedHeight * 3;
|
||||
textureData = new Uint8Array(sizeBytes);
|
||||
|
||||
for(let i = 0, j = 0; i < textureData.length; i += 4, j += 3) {
|
||||
textureData[j] = pixels.data[i]; // R
|
||||
textureData[j + 1] = pixels.data[i + 1]; // G
|
||||
textureData[j + 2] = pixels.data[i + 2]; // B
|
||||
|
||||
rawData[i] = pixels.data[i]; // R
|
||||
rawData[i + 1] = pixels.data[i + 1]; // G
|
||||
rawData[i + 2] = pixels.data[i + 2]; // B
|
||||
rawData[i + 3] = 255;
|
||||
}
|
||||
} else if(strTextureType === 'rgb565') {
|
||||
sizeBytes = paddedWidth * paddedHeight * 2;
|
||||
textureData = new Uint8Array(sizeBytes);
|
||||
|
||||
let j = 0;
|
||||
for (let i = 0; i < pixels.data.length; i += 4) {
|
||||
const r = pixels.data[i];
|
||||
const g = pixels.data[i + 1];
|
||||
const b = pixels.data[i + 2];
|
||||
|
||||
const value =
|
||||
((r & 0xf8) << 8) |
|
||||
((g & 0xfc) << 3) |
|
||||
(b >> 3);
|
||||
|
||||
textureData[j++] = (value >> 8) & 0xff; // high byte
|
||||
textureData[j++] = value & 0xff; // low byte
|
||||
}
|
||||
|
||||
// Now convert back to RGBA for preview
|
||||
for(let i = 0, j = 0; i < textureData.length; i += 2, j += 4) {
|
||||
const value = (textureData[i] << 8) | textureData[i + 1];
|
||||
const r = (value >> 11) & 0x1f;
|
||||
const g = (value >> 5) & 0x3f;
|
||||
const b = value & 0x1f;
|
||||
rawData[j] = (r << 3) | (r >> 2); // R
|
||||
rawData[j + 1] = (g << 2) | (g >> 4); // G
|
||||
rawData[j + 2] = (b << 3) | (b >> 2); // B
|
||||
rawData[j + 3] = 255; // A
|
||||
}
|
||||
|
||||
} else if(strTextureType === 'rgb5a3') {
|
||||
sizeBytes = paddedWidth * paddedHeight * 2;
|
||||
textureData = new Uint8Array(sizeBytes);
|
||||
|
||||
let j = 0;
|
||||
for (let i = 0; i < pixels.data.length; i += 4) {
|
||||
const r8 = pixels.data[i];
|
||||
const g8 = pixels.data[i + 1];
|
||||
const b8 = pixels.data[i + 2];
|
||||
const a8 = pixels.data[i + 3];
|
||||
|
||||
let value;
|
||||
|
||||
// Opaque: 1RRRRRGGGGGBBBBB
|
||||
if (a8 >= 224) {
|
||||
const r5 = r8 >> 3;
|
||||
const g5 = g8 >> 3;
|
||||
const b5 = b8 >> 3;
|
||||
|
||||
value =
|
||||
0x8000 |
|
||||
(r5 << 10) |
|
||||
(g5 << 5) |
|
||||
b5;
|
||||
} else {
|
||||
// Transparent/translucent: 0AAARRRRGGGGBBBB
|
||||
const a3 = a8 >> 5;
|
||||
const r4 = r8 >> 4;
|
||||
const g4 = g8 >> 4;
|
||||
const b4 = b8 >> 4;
|
||||
|
||||
value =
|
||||
(a3 << 12) |
|
||||
(r4 << 8) |
|
||||
(g4 << 4) |
|
||||
b4;
|
||||
}
|
||||
|
||||
textureData[j++] = (value >> 8) & 0xff; // high byte
|
||||
textureData[j++] = value & 0xff; // low byte
|
||||
}
|
||||
|
||||
// Convert back to RGBA for preview
|
||||
for (let i = 0, j = 0; i < textureData.length; i += 2, j += 4) {
|
||||
const value = (textureData[i] << 8) | textureData[i + 1];
|
||||
|
||||
if (value & 0x8000) {
|
||||
// 1RRRRRGGGGGBBBBB
|
||||
const r5 = (value >> 10) & 0x1f;
|
||||
const g5 = (value >> 5) & 0x1f;
|
||||
const b5 = value & 0x1f;
|
||||
|
||||
rawData[j] = (r5 << 3) | (r5 >> 2);
|
||||
rawData[j + 1] = (g5 << 3) | (g5 >> 2);
|
||||
rawData[j + 2] = (b5 << 3) | (b5 >> 2);
|
||||
rawData[j + 3] = 255;
|
||||
} else {
|
||||
// 0AAARRRRGGGGBBBB
|
||||
const a3 = (value >> 12) & 0x7;
|
||||
const r4 = (value >> 8) & 0xf;
|
||||
const g4 = (value >> 4) & 0xf;
|
||||
const b4 = value & 0xf;
|
||||
|
||||
rawData[j] = (r4 << 4) | r4;
|
||||
rawData[j + 1] = (g4 << 4) | g4;
|
||||
rawData[j + 2] = (b4 << 4) | b4;
|
||||
rawData[j + 3] = (a3 << 5) | (a3 << 2) | (a3 >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return alert('Unsupported texture type selected.');
|
||||
}
|
||||
|
||||
// Write out pixels.
|
||||
const imageData = new ImageData(new Uint8ClampedArray(rawData.buffer), paddedWidth, paddedHeight);
|
||||
tempCanvas.width = paddedWidth;
|
||||
tempCanvas.height = paddedHeight;
|
||||
const tempCtx2 = tempCanvas.getContext('2d');
|
||||
tempCtx2.imageSmoothingEnabled = false;
|
||||
tempCtx2.putImageData(imageData, 0, 0);
|
||||
|
||||
elOutputPreview.width = paddedScaledWidth;
|
||||
elOutputPreview.height = paddedScaledHeight;
|
||||
const ctx = elOutputPreview.getContext('2d');
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
ctx.clearRect(0, 0, elOutputPreview.width, elOutputPreview.height);
|
||||
ctx.drawImage(tempCanvas, 0, 0, paddedScaledWidth, paddedScaledHeight);
|
||||
|
||||
// Output information
|
||||
elOutputInformation.value = `Original Size: ${width}x${height}\n`;
|
||||
elOutputInformation.value += `New Size: ${paddedWidth}x${paddedHeight}\n`;
|
||||
elOutputInformation.value += `Texture Format: ${textureType}\n`;
|
||||
elOutputInformation.value += `Size: ${sizeBytes} bytes / (${(sizeBytes / 1024).toFixed(2)} KB)\n`;
|
||||
}
|
||||
|
||||
|
||||
const onFile = async file => {
|
||||
elFileInput.disabled = true;
|
||||
console.log('Selected file:', file);
|
||||
|
||||
imageName = file.name;
|
||||
|
||||
// Load as image
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
image = img;
|
||||
elFileInput.disabled = false;
|
||||
updatePreview();
|
||||
};
|
||||
img.onerror = () => {
|
||||
alert('Failed to load image. Please select a valid image file.');
|
||||
elFileInput.disabled = false;
|
||||
};
|
||||
img.src = URL.createObjectURL(file);
|
||||
}
|
||||
|
||||
// Listeners
|
||||
elFileInput.addEventListener('change', event => {
|
||||
if(!event.target.files || event.target.files.length <= 0) {
|
||||
return alert('No file selected.');
|
||||
}
|
||||
|
||||
const file = event.target.files[0];
|
||||
if(!file.type.startsWith('image/')) {
|
||||
return alert('Selected file is not an image.');
|
||||
}
|
||||
|
||||
onFile(file);
|
||||
});
|
||||
|
||||
btnBackgroundWhite.addEventListener('click', () => {
|
||||
document.body.style.background = 'white';
|
||||
});
|
||||
btnBackgroundTransparent.addEventListener('click', () => {
|
||||
document.body.style.background = 'black';
|
||||
});
|
||||
btnBackgroundCheckerboard.addEventListener('click', () => {
|
||||
document.body.style.background = 'repeating-conic-gradient(#ccc 0% 25%, #eee 0% 50%) 50% / 20px 20px';
|
||||
});
|
||||
btnBackgroundMagenta.addEventListener('click', () => {
|
||||
document.body.style.background = 'magenta';
|
||||
});
|
||||
btnBackgroundBlue.addEventListener('click', () => {
|
||||
document.body.style.background = 'blue';
|
||||
});
|
||||
btnBackgroundGreen.addEventListener('click', () => {
|
||||
document.body.style.background = 'green';
|
||||
});
|
||||
|
||||
elPreviewScale.addEventListener('input', () => {
|
||||
updatePreview();
|
||||
});
|
||||
elPadPowerOfTwo.addEventListener('change', () => {
|
||||
updatePreview();
|
||||
});
|
||||
elTextureType.forEach(radio => {
|
||||
radio.addEventListener('change', () => {
|
||||
updatePreview();
|
||||
});
|
||||
})
|
||||
|
||||
btnDownload.addEventListener('click', () => {
|
||||
if(!image) {
|
||||
return alert('Please select an image file before downloading.');
|
||||
}
|
||||
|
||||
// DTX, then texture type, then width, then height, then raw data
|
||||
const dtfHeader = new TextEncoder().encode('DTX');
|
||||
|
||||
const versionHeader = new Uint8Array([1]); // Version 1
|
||||
|
||||
let strTextureType = Array.from(elTextureType).find(r => r.checked)?.value || 'rgba';
|
||||
strTextureType = strTextureType.toLowerCase();
|
||||
|
||||
let typeHeader;
|
||||
if(strTextureType === 'rgba') {
|
||||
typeHeader = new Uint8Array([0]);
|
||||
} else if(strTextureType === 'rgb') {
|
||||
typeHeader = new Uint8Array([1]);
|
||||
} else if(strTextureType === 'rgb565') {
|
||||
typeHeader = new Uint8Array([2]);
|
||||
} else if(strTextureType === 'rgb5a3') {
|
||||
typeHeader = new Uint8Array([3]);
|
||||
} else {
|
||||
return alert('Unsupported texture type selected.');
|
||||
}
|
||||
|
||||
const widthBytes = new Uint32Array([ paddedWidth ]);
|
||||
const heightBytes = new Uint32Array([ paddedHeight ]);
|
||||
|
||||
const blob = new Blob([dtfHeader, versionHeader, typeHeader, widthBytes, heightBytes, textureData], { type: 'application/octet-stream' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${imageName.replace(/\.[^/.]+$/, "")}.dtx`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
btnBackgroundCheckerboard.click();
|
||||
</script>
|
||||
</html>
|
||||
@@ -151,23 +151,24 @@
|
||||
const getValues = () => {
|
||||
if(!pixels) return null;
|
||||
|
||||
const right = parseInt(elRight.value) || 0;
|
||||
const bottom = parseInt(elBottom.value) || 0;
|
||||
|
||||
let tileWidth, tileHeight, columnCount, rowCount;
|
||||
if(elDefineBySize.checked) {
|
||||
console.log('Defining by size');
|
||||
tileWidth = parseInt(elTileWidth.value) || 0;
|
||||
tileHeight = parseInt(elTileHeight.value) || 0;
|
||||
columnCount = Math.floor(imageWidth / tileWidth);
|
||||
rowCount = Math.floor(imageHeight / tileHeight);
|
||||
columnCount = Math.floor((imageWidth - right) / tileWidth);
|
||||
rowCount = Math.floor((imageHeight - bottom) / tileHeight);
|
||||
} else {
|
||||
console.log('Defining by count');
|
||||
columnCount = parseInt(elColumnCount.value) || 0;
|
||||
rowCount = parseInt(elRowCount.value) || 0;
|
||||
tileWidth = Math.floor(imageWidth / columnCount);
|
||||
tileHeight = Math.floor(imageHeight / rowCount);
|
||||
tileWidth = Math.floor((imageWidth - right) / columnCount);
|
||||
tileHeight = Math.floor((imageHeight - bottom) / rowCount);
|
||||
}
|
||||
|
||||
const right = parseInt(elRight.value) || 0;
|
||||
const bottom = parseInt(elBottom.value) || 0;
|
||||
|
||||
const scale = parseInt(elScale.value) || 1;
|
||||
const scaledWidth = imageWidth * scale;
|
||||
|
||||
Reference in New Issue
Block a user