Compare commits
1 Commits
9ec21f85a0
...
vita
| Author | SHA1 | Date | |
|---|---|---|---|
| 5919881568 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -106,7 +106,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
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assettexture.h"
|
||||
#include "asset/assettype.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "util/endian.h"
|
||||
|
||||
errorret_t assetTextureLoad(assetentire_t entire) {
|
||||
assertNotNull(entire.data, "Data pointer cannot be NULL.");
|
||||
assertNotNull(entire.output, "Output pointer cannot be NULL.");
|
||||
|
||||
assettexture_t *assetData = (assettexture_t *)entire.data;
|
||||
texture_t *texture = (texture_t *)entire.output;
|
||||
|
||||
// Read header and version (first 4 bytes)
|
||||
if(
|
||||
assetData->header[0] != 'D' ||
|
||||
assetData->header[1] != 'T' ||
|
||||
assetData->header[2] != 'X'
|
||||
) {
|
||||
errorThrow("Invalid texture header");
|
||||
}
|
||||
|
||||
// Version (can only be 1 atm)
|
||||
if(assetData->version != 0x01) {
|
||||
errorThrow("Unsupported texture version");
|
||||
}
|
||||
|
||||
// Fix endian
|
||||
assetData->width = endianLittleToHost32(assetData->width);
|
||||
assetData->height = endianLittleToHost32(assetData->height);
|
||||
|
||||
// Check dimensions.
|
||||
if(
|
||||
assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX ||
|
||||
assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX
|
||||
) {
|
||||
errorThrow("Invalid texture dimensions");
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
@@ -70,9 +70,8 @@ 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
|
||||
|
||||
sceneSet('scene/main_menu/main_menu.lua')
|
||||
sceneSet('scene/minesweeper.lua')
|
||||
BIN
assets/main_palette.dpf
Normal file
BIN
assets/main_palette.dpf
Normal file
Binary file not shown.
@@ -1,44 +0,0 @@
|
||||
module('spritebatch')
|
||||
module('camera')
|
||||
module('color')
|
||||
module('ui')
|
||||
module('screen')
|
||||
module('time')
|
||||
module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
module('shader')
|
||||
module('locale')
|
||||
|
||||
screenSetBackground(colorCornflowerBlue())
|
||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||
|
||||
function sceneDispose()
|
||||
end
|
||||
|
||||
function sceneUpdate()
|
||||
end
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
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(
|
||||
-- 32, 32,
|
||||
-- 64, 64,
|
||||
-- colorWhite()
|
||||
-- )
|
||||
-- spriteBatchFlush()
|
||||
|
||||
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||
spriteBatchFlush()
|
||||
end
|
||||
256
assets/scene/minesweeper.lua
Normal file
256
assets/scene/minesweeper.lua
Normal file
@@ -0,0 +1,256 @@
|
||||
module('spritebatch')
|
||||
module('camera')
|
||||
module('color')
|
||||
module('ui')
|
||||
module('screen')
|
||||
module('time')
|
||||
module('glm')
|
||||
module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
|
||||
CELL_STATE_DEFAULT = 0
|
||||
CELL_STATE_HOVER = 1
|
||||
CELL_STATE_DOWN = 2
|
||||
CELL_STATE_DISABLED = 3
|
||||
|
||||
screenSetBackground(colorCornflowerBlue())
|
||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||
|
||||
-- tilesetUi = tilesetGetByName("ui")
|
||||
-- textureUi = textureLoad(tilesetUi.texture)
|
||||
|
||||
-- tilesetBorder = tilesetGetByName("border")
|
||||
-- textureBorder = textureLoad(tilesetBorder.texture)
|
||||
|
||||
-- textureGrid = textureLoad("minesweeper/grid_bg.dpi")
|
||||
|
||||
-- tilesetCell = tilesetGetByName("cell")
|
||||
-- textureCell = textureLoad(tilesetCell.texture)
|
||||
-- cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
|
||||
-- cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
|
||||
-- cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
|
||||
-- cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
|
||||
|
||||
-- sweepwerCols = 10
|
||||
-- sweeperRows = 14
|
||||
|
||||
-- mouseX = -1
|
||||
-- mouseY = -1
|
||||
-- centerX = 0
|
||||
-- centerY = 0
|
||||
-- boardWidth = sweepwerCols * tilesetCell.tileWidth
|
||||
-- boardHeight = sweeperRows * tilesetCell.tileHeight
|
||||
|
||||
-- i = 0
|
||||
-- cells = {}
|
||||
-- for y = 1, sweeperRows do
|
||||
-- for x = 1, sweepwerCols do
|
||||
-- cells[i] = CELL_STATE_DEFAULT
|
||||
-- i = i + 1
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function cellDraw(x, y, type)
|
||||
local slice = cellSliceDefault
|
||||
if type == CELL_STATE_HOVER then
|
||||
slice = cellSliceHover
|
||||
elseif type == CELL_STATE_DOWN then
|
||||
slice = cellSliceDown
|
||||
elseif type == CELL_STATE_DISABLED then
|
||||
slice = cellSliceDisabled
|
||||
end
|
||||
|
||||
spriteBatchPush(textureCell,
|
||||
x, y,
|
||||
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||
colorWhite(),
|
||||
slice.u0, slice.v0,
|
||||
slice.u1, slice.v1
|
||||
)
|
||||
end
|
||||
|
||||
function backgroundDraw()
|
||||
local t = (TIME.time / 40) % 1
|
||||
local scaleX = screenGetWidth() / textureGrid.width
|
||||
local scaleY = screenGetHeight() / textureGrid.height
|
||||
local u0 = t * scaleX
|
||||
local v0 = t * scaleY
|
||||
local u1 = scaleX + u0
|
||||
local v1 = scaleY + v0
|
||||
|
||||
spriteBatchPush(textureGrid,
|
||||
0, 0,
|
||||
screenGetWidth(), screenGetHeight(),
|
||||
colorWhite(),
|
||||
u0, v0,
|
||||
u1, v1
|
||||
)
|
||||
end
|
||||
|
||||
function borderDraw(x, y, innerWidth, innerHeight)
|
||||
-- Top Left
|
||||
local uv = tilesetPositionGetUV(tilesetBorder, 0, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y - tilesetBorder.tileWidth,
|
||||
x, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Top Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y - tilesetBorder.tileHeight,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom Left
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 0, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y + innerHeight,
|
||||
x, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y + innerHeight,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Top
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 1, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x, y - tilesetBorder.tileHeight,
|
||||
x + innerWidth, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 1, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x, y + innerHeight,
|
||||
x + innerWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Left
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 0, 1)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y,
|
||||
x, y + innerHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 1)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
end
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
function sceneDispose()
|
||||
end
|
||||
|
||||
function sceneUpdate()
|
||||
x = x + inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
|
||||
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
|
||||
end
|
||||
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
cameraPushMatrix(camera)
|
||||
camera.bottom = screenGetHeight()
|
||||
camera.right = screenGetWidth()
|
||||
|
||||
spriteBatchPush(
|
||||
nil,
|
||||
x, y, x + 32, y + 32,
|
||||
colorWhite()
|
||||
)
|
||||
|
||||
-- Update mouse position
|
||||
-- if INPUT_POINTER then
|
||||
-- mouseX = inputGetValue(INPUT_ACTION_POINTERX) * screenGetWidth()
|
||||
-- mouseY = inputGetValue(INPUT_ACTION_POINTERY) * screenGetHeight()
|
||||
|
||||
-- -- Draw cursor
|
||||
-- spriteBatchPush(
|
||||
-- nil,
|
||||
-- mouseX - 2, mouseY - 2,
|
||||
-- mouseX + 2, mouseY + 2,
|
||||
-- colorRed(),
|
||||
-- 0, 0,
|
||||
-- 1, 1
|
||||
-- )
|
||||
-- end
|
||||
|
||||
|
||||
-- textDraw(10, 10, "Hello World")
|
||||
|
||||
-- centerX = math.floor(screenGetWidth() / 2)
|
||||
-- centerY = math.floor(screenGetHeight() / 2)
|
||||
|
||||
-- Draw elements
|
||||
-- backgroundDraw()
|
||||
-- borderDraw(
|
||||
-- centerX - (boardWidth / 2), centerY - (boardHeight / 2),
|
||||
-- boardWidth, boardHeight
|
||||
-- )
|
||||
|
||||
-- i = 0
|
||||
-- -- Foreach cell
|
||||
-- local offX = centerX - (boardWidth / 2)
|
||||
-- local offY = centerY - (boardHeight / 2)
|
||||
-- for y = 0, sweeperRows - 1 do
|
||||
-- for x = 0, sweepwerCols - 1 do
|
||||
-- i = y * sweepwerCols + x
|
||||
|
||||
-- -- Hovered
|
||||
-- if
|
||||
-- cells[i] == CELL_STATE_DEFAULT and
|
||||
-- mouseX >= x * tilesetCell.tileWidth + offX and mouseX < (x + 1) * tilesetCell.tileWidth + offX and
|
||||
-- mouseY >= y * tilesetCell.tileHeight + offY and mouseY < (y + 1) * tilesetCell.tileHeight + offY
|
||||
-- then
|
||||
-- cells[i] = CELL_STATE_HOVER
|
||||
-- else
|
||||
-- cells[i] = CELL_STATE_DEFAULT
|
||||
-- end
|
||||
|
||||
-- cellDraw(
|
||||
-- x * tilesetCell.tileWidth + offX,
|
||||
-- y * tilesetCell.tileHeight + offY,
|
||||
-- cells[i]
|
||||
-- )
|
||||
-- end
|
||||
-- end
|
||||
spriteBatchFlush()
|
||||
|
||||
cameraPopMatrix()
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "Dominic",
|
||||
"age": 31,
|
||||
"likes": [
|
||||
"thing1",
|
||||
"thing2"
|
||||
],
|
||||
"options": {
|
||||
"someParam": true,
|
||||
"someSubObject": {
|
||||
"someSubSubParam": 52
|
||||
},
|
||||
"someArray": [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
}
|
||||
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.
|
Before Width: | Height: | Size: 1.2 KiB |
17
cmake/modules/CompileLibZip.cmake
Normal file
17
cmake/modules/CompileLibZip.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
include(FetchContent)
|
||||
|
||||
set(ENABLE_ZSTD OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_REGRESS OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_DOC OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
set(LIBZIP_DO_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
|
||||
FetchContent_Declare(
|
||||
libzip
|
||||
GIT_REPOSITORY https://github.com/nih-at/libzip.git
|
||||
GIT_TAG v1.11.4
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(libzip)
|
||||
20
cmake/modules/CompileLua.cmake
Normal file
20
cmake/modules/CompileLua.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
# Compile lua
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
liblua
|
||||
URL https://www.lua.org/ftp/lua-5.5.0.tar.gz
|
||||
)
|
||||
FetchContent_MakeAvailable(liblua)
|
||||
set(LUA_SRC_DIR "${liblua_SOURCE_DIR}/src")
|
||||
set(LUA_C_FILES
|
||||
lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c
|
||||
ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c
|
||||
loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c
|
||||
lstrlib.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c lzio.c
|
||||
)
|
||||
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||
add_library(liblua STATIC ${LUA_C_FILES})
|
||||
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||
add_library(lua::lua ALIAS liblua)
|
||||
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||
@@ -1,17 +1,43 @@
|
||||
|
||||
# Allow user to manually specify libzip paths
|
||||
# LIBZIP_ROOT: root directory for libzip (optional)
|
||||
# LIBZIP_INCLUDE_DIR: path to zip.h (optional)
|
||||
# LIBZIP_LIBRARY: path to libzip library (optional)
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
find_path(LIBZIP_INCLUDE_DIR NAMES zip.h)
|
||||
if(NOT LIBZIP_INCLUDE_DIR AND LIBZIP_ROOT)
|
||||
find_path(LIBZIP_INCLUDE_DIR NAMES zip.h HINTS "${LIBZIP_ROOT}/include")
|
||||
endif()
|
||||
if(NOT LIBZIP_INCLUDE_DIR)
|
||||
find_path(LIBZIP_INCLUDE_DIR NAMES zip.h)
|
||||
endif()
|
||||
mark_as_advanced(LIBZIP_INCLUDE_DIR)
|
||||
|
||||
find_library(LIBZIP_LIBRARY NAMES zip)
|
||||
if(NOT LIBZIP_LIBRARY AND LIBZIP_ROOT)
|
||||
find_library(LIBZIP_LIBRARY NAMES zip HINTS "${LIBZIP_ROOT}/lib")
|
||||
endif()
|
||||
if(NOT LIBZIP_LIBRARY)
|
||||
find_library(LIBZIP_LIBRARY NAMES zip)
|
||||
endif()
|
||||
mark_as_advanced(LIBZIP_LIBRARY)
|
||||
|
||||
get_filename_component(_libzip_libdir ${LIBZIP_LIBRARY} DIRECTORY)
|
||||
find_file(_libzip_pkgcfg libzip.pc
|
||||
HINTS ${_libzip_libdir} ${LIBZIP_INCLUDE_DIR}/..
|
||||
PATH_SUFFIXES pkgconfig lib/pkgconfig libdata/pkgconfig
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
if(LIBZIP_LIBRARY)
|
||||
get_filename_component(_libzip_libdir ${LIBZIP_LIBRARY} DIRECTORY)
|
||||
endif()
|
||||
if(NOT _libzip_pkgcfg AND LIBZIP_ROOT)
|
||||
find_file(_libzip_pkgcfg libzip.pc
|
||||
HINTS "${LIBZIP_ROOT}/lib/pkgconfig" "${LIBZIP_ROOT}/libdata/pkgconfig"
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
endif()
|
||||
if(NOT _libzip_pkgcfg AND LIBZIP_LIBRARY)
|
||||
find_file(_libzip_pkgcfg libzip.pc
|
||||
HINTS ${_libzip_libdir} ${LIBZIP_INCLUDE_DIR}/..
|
||||
PATH_SUFFIXES pkgconfig lib/pkgconfig libdata/pkgconfig
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
stb
|
||||
GIT_REPOSITORY https://github.com/nothings/stb.git
|
||||
)
|
||||
|
||||
# Fetch stb if not already done
|
||||
FetchContent_MakeAvailable(stb)
|
||||
|
||||
# Find the stb_image.h header
|
||||
set(STB_INCLUDE_DIR "${stb_SOURCE_DIR}")
|
||||
set(STB_IMAGE_HEADER "${stb_SOURCE_DIR}/stb_image.h")
|
||||
|
||||
if(EXISTS "${STB_IMAGE_HEADER}")
|
||||
add_library(stb_image INTERFACE)
|
||||
target_include_directories(stb_image INTERFACE "${STB_INCLUDE_DIR}")
|
||||
set(STB_IMAGE_FOUND TRUE)
|
||||
else()
|
||||
set(STB_IMAGE_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
# Standard CMake variables
|
||||
set(STB_IMAGE_INCLUDE_DIRS "${STB_INCLUDE_DIR}")
|
||||
set(STB_IMAGE_LIBRARIES stb_image)
|
||||
|
||||
mark_as_advanced(STB_IMAGE_INCLUDE_DIRS STB_IMAGE_LIBRARIES STB_IMAGE_FOUND)
|
||||
@@ -1,18 +0,0 @@
|
||||
include(FetchContent)
|
||||
|
||||
if(NOT TARGET yyjson)
|
||||
FetchContent_Declare(
|
||||
yyjson
|
||||
GIT_REPOSITORY https://github.com/ibireme/yyjson.git
|
||||
GIT_TAG 0.12.0
|
||||
)
|
||||
FetchContent_MakeAvailable(yyjson)
|
||||
endif()
|
||||
|
||||
# Provide an imported target if not already available
|
||||
if(NOT TARGET yyjson::yyjson)
|
||||
add_library(yyjson::yyjson ALIAS yyjson)
|
||||
endif()
|
||||
|
||||
# Mark yyjson as found for find_package compatibility
|
||||
set(yyjson_FOUND TRUE)
|
||||
@@ -21,26 +21,7 @@ set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
||||
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
||||
find_package(cglm REQUIRED)
|
||||
|
||||
# Compile lua
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
liblua
|
||||
URL https://www.lua.org/ftp/lua-5.5.0.tar.gz
|
||||
)
|
||||
FetchContent_MakeAvailable(liblua)
|
||||
set(LUA_SRC_DIR "${liblua_SOURCE_DIR}/src")
|
||||
set(LUA_C_FILES
|
||||
lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c
|
||||
ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c
|
||||
loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c
|
||||
lstrlib.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c lzio.c
|
||||
)
|
||||
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||
add_library(liblua STATIC ${LUA_C_FILES})
|
||||
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||
add_library(lua::lua ALIAS liblua)
|
||||
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||
include(cmake/modules/CompileLua.cmake)
|
||||
|
||||
# Link libraries
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
|
||||
62
cmake/targets/vita.cmake
Normal file
62
cmake/targets/vita.cmake
Normal file
@@ -0,0 +1,62 @@
|
||||
include("${VITASDK}/share/vita.cmake" REQUIRED)
|
||||
|
||||
|
||||
# Manually define libzip for Vita
|
||||
set(LIBZIP_LIBRARY "${VITASDK}/lib/libzip.a" CACHE FILEPATH "libzip library for Vita")
|
||||
set(LIBZIP_INCLUDE_DIR "${VITASDK}/include" CACHE PATH "libzip include dir for Vita")
|
||||
|
||||
set(VITA_APP_NAME "Red Rectangle")
|
||||
set(VITA_TITLEID "VSDK00017")
|
||||
set(VITA_VERSION "01.00")
|
||||
|
||||
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
mathneon
|
||||
vitashark
|
||||
kubridge_stub
|
||||
SceAppMgr_stub
|
||||
SceAudio_stub
|
||||
SceCtrl_stub
|
||||
SceCommonDialog_stub
|
||||
SceDisplay_stub
|
||||
SceKernelDmacMgr_stub
|
||||
SceGxm_stub
|
||||
SceShaccCg_stub
|
||||
SceSysmodule_stub
|
||||
ScePower_stub
|
||||
SceTouch_stub
|
||||
SceVshBridge_stub
|
||||
SceIofilemgr_stub
|
||||
SceShaccCgExt
|
||||
SDL2-static
|
||||
libtaihen_stub.a
|
||||
lua::lua
|
||||
zip
|
||||
pthread
|
||||
m
|
||||
)
|
||||
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_SDL2
|
||||
DUSK_OPENGL
|
||||
DUSK_VITA
|
||||
DUSK_INPUT_GAMEPAD
|
||||
DUSK_PLATFORM_ENDIAN_LITTLE
|
||||
DUSK_DISPLAY_WIDTH=960
|
||||
DUSK_DISPLAY_HEIGHT=544
|
||||
)
|
||||
|
||||
vita_create_self(${DUSK_BINARY_TARGET_NAME}.self ${DUSK_BINARY_TARGET_NAME})
|
||||
vita_create_vpk(${DUSK_BINARY_TARGET_NAME}.vpk ${VITA_TITLEID} ${DUSK_BINARY_TARGET_NAME}.self
|
||||
VERSION ${VITA_VERSION}
|
||||
NAME ${VITA_APP_NAME}
|
||||
# FILE sce_sys/icon0.png sce_sys/icon0.png
|
||||
# FILE sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png
|
||||
# FILE sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png
|
||||
# FILE sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml
|
||||
)
|
||||
64
docker/vita/Dockerfile
Normal file
64
docker/vita/Dockerfile
Normal file
@@ -0,0 +1,64 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
cmake \
|
||||
git \
|
||||
curl \
|
||||
sudo \
|
||||
wget \
|
||||
libarchive-tools \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-dotenv \
|
||||
python3-polib \
|
||||
python3-pil \
|
||||
python3-pyqt5 \
|
||||
python3-opengl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN git clone https://github.com/vitasdk/vdpm /vdpm
|
||||
WORKDIR /vdpm
|
||||
RUN ./bootstrap-vitasdk.sh
|
||||
|
||||
ENV VITASDK=/usr/local/vitasdk
|
||||
ENV PATH="${VITASDK}/bin:${PATH}"
|
||||
|
||||
RUN git clone https://github.com/vitasdk/packages.git /vitapackages
|
||||
WORKDIR /vitapackages
|
||||
|
||||
RUN bash -lc '\
|
||||
dir_array=( \
|
||||
zlib \
|
||||
bzip2 \
|
||||
henkaku \
|
||||
taihen \
|
||||
kubridge \
|
||||
openal-soft \
|
||||
openssl \
|
||||
curl \
|
||||
curlpp \
|
||||
expat \
|
||||
opus \
|
||||
opusfile \
|
||||
glm \
|
||||
kuio \
|
||||
vitaShaRK \
|
||||
libmathneon \
|
||||
vitaGL \
|
||||
SceShaccCgExt \
|
||||
sdl2 \
|
||||
libzip \
|
||||
luajit \
|
||||
); \
|
||||
curdir=$(pwd); \
|
||||
for d in "${dir_array[@]}"; do \
|
||||
echo "${curdir}/${d}"; \
|
||||
cd "${curdir}/${d}"; \
|
||||
vita-makepkg; \
|
||||
vdpm *-arm.tar.xz; \
|
||||
done \
|
||||
'
|
||||
|
||||
WORKDIR /workdir
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/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
|
||||
|
||||
3
scripts/build-vita-docker.sh
Executable file
3
scripts/build-vita-docker.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-vita -f docker/vita/Dockerfile .
|
||||
docker run --rm -v $(pwd):/workdir dusk-vita /bin/bash -c "./scripts/build-vita.sh"
|
||||
6
scripts/build-vita.sh
Executable file
6
scripts/build-vita.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
cd /workdir
|
||||
cmake -S . -B build-vita \
|
||||
-DDUSK_TARGET_SYSTEM=vita \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$VITASDK/share/vita.toolchain.cmake"
|
||||
cmake --build build-vita -- -j$(nproc)
|
||||
@@ -4,10 +4,8 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(dusk)
|
||||
# add_subdirectory(duskrpg)
|
||||
add_subdirectory(dusktrivia)
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli" OR DUSK_TARGET_SYSTEM STREQUAL "vita")
|
||||
add_subdirectory(dusklinux)
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskgl)
|
||||
|
||||
@@ -14,24 +14,6 @@ if(NOT libzip_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
||||
endif()
|
||||
|
||||
if(NOT stb_image_FOUND)
|
||||
find_package(stb REQUIRED)
|
||||
if(STB_IMAGE_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
|
||||
else()
|
||||
message(FATAL_ERROR "stb_image not found. Please ensure stb is correctly fetched.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT yyjson_FOUND)
|
||||
find_package(yyjson REQUIRED)
|
||||
if(yyjson_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
|
||||
else()
|
||||
message(FATAL_ERROR "yyjson not found. Please ensure yyjson is correctly fetched.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT Lua_FOUND)
|
||||
find_package(Lua REQUIRED)
|
||||
if(Lua_FOUND AND NOT TARGET Lua::Lua)
|
||||
@@ -70,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,8 +7,7 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
asset.c
|
||||
assetfile.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(loader)
|
||||
add_subdirectory(type)
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "assert/assert.h"
|
||||
#include "asset/assettype.h"
|
||||
#include "engine/engine.h"
|
||||
#include "util/string.h"
|
||||
|
||||
@@ -32,20 +33,107 @@ bool_t assetFileExists(const char_t *filename) {
|
||||
return true;
|
||||
}
|
||||
|
||||
errorret_t assetLoad(
|
||||
const char_t *filename,
|
||||
assetfileloader_t loader,
|
||||
void *params,
|
||||
void *output
|
||||
) {
|
||||
errorret_t assetLoad(const char_t *filename, void *output) {
|
||||
assertStrLenMax(filename, FILENAME_MAX, "Filename too long.");
|
||||
assertNotNull(output, "Output pointer cannot be NULL.");
|
||||
assertNotNull(loader, "Asset file loader cannot be NULL.");
|
||||
|
||||
assetfile_t file;
|
||||
errorChain(assetFileInit(&file, filename, params, output));
|
||||
errorChain(loader(&file));
|
||||
errorChain(assetFileDispose(&file));
|
||||
// Determine the asset type by reading the extension
|
||||
const assettypedef_t *def = NULL;
|
||||
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
|
||||
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
|
||||
assertNotNull(cmp, "Asset type definition cannot be NULL.");
|
||||
if(cmp->extension == NULL) continue;
|
||||
if(!stringEndsWithCaseInsensitive(filename, cmp->extension)) continue;
|
||||
def = cmp;
|
||||
break;
|
||||
}
|
||||
if(def == NULL) {
|
||||
errorThrow("Unknown asset type for file: %s", filename);
|
||||
}
|
||||
|
||||
// Get file size of the asset.
|
||||
zip_stat_t st;
|
||||
zip_stat_init(&st);
|
||||
if(!zip_stat(ASSET.zip, filename, 0, &st) == 0) {
|
||||
errorThrow("Failed to stat asset file: %s", filename);
|
||||
}
|
||||
|
||||
// Minimum file size.
|
||||
zip_int64_t fileSize = (zip_int64_t)st.size;
|
||||
if(fileSize <= 0) {
|
||||
errorThrow("Asset file is empty: %s", filename);
|
||||
}
|
||||
|
||||
// Try to open the file
|
||||
zip_file_t *file = zip_fopen(ASSET.zip, filename, 0);
|
||||
if(file == NULL) {
|
||||
errorThrow("Failed to open asset file: %s", filename);
|
||||
}
|
||||
|
||||
// Load the asset data
|
||||
switch(def->loadStrategy) {
|
||||
case ASSET_LOAD_STRAT_ENTIRE:
|
||||
assertNotNull(def->entire, "Asset load function cannot be NULL.");
|
||||
|
||||
// Must have more to read
|
||||
if(fileSize <= 0) {
|
||||
zip_fclose(file);
|
||||
errorThrow("No data remaining to read for asset: %s", filename);
|
||||
}
|
||||
|
||||
if(fileSize > def->dataSize) {
|
||||
zip_fclose(file);
|
||||
errorThrow(
|
||||
"Asset file has too much data remaining after header: %s",
|
||||
filename
|
||||
);
|
||||
}
|
||||
|
||||
// Create space to read the entire asset data
|
||||
void *data = memoryAllocate(fileSize);
|
||||
if(!data) {
|
||||
zip_fclose(file);
|
||||
errorThrow(
|
||||
"Failed to allocate memory for asset data of file: %s", filename
|
||||
);
|
||||
}
|
||||
|
||||
// Read in the asset data.
|
||||
zip_int64_t bytesRead = zip_fread(file, data, fileSize);
|
||||
if(bytesRead == 0 || bytesRead > fileSize) {
|
||||
memoryFree(data);
|
||||
zip_fclose(file);
|
||||
errorThrow("Failed to read asset data for file: %s", filename);
|
||||
}
|
||||
fileSize -= bytesRead;
|
||||
|
||||
// Close the file now we have the data
|
||||
zip_fclose(file);
|
||||
|
||||
// Pass to the asset type loader
|
||||
assetentire_t entire = {
|
||||
.data = data,
|
||||
.output = output
|
||||
};
|
||||
errorret_t ret = def->entire(entire);
|
||||
memoryFree(data);
|
||||
|
||||
errorChain(ret);
|
||||
break;
|
||||
|
||||
case ASSET_LOAD_STRAT_CUSTOM:
|
||||
assertNotNull(def->custom, "Asset load function cannot be NULL.");
|
||||
assetcustom_t customData = {
|
||||
.zipFile = file,
|
||||
.output = output
|
||||
};
|
||||
errorChain(def->custom(customData));
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown asset load strategy.");
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "assettype.h"
|
||||
#include "asset/assetplatform.h"
|
||||
#include "assetfile.h"
|
||||
|
||||
#ifndef assetInitPlatform
|
||||
#error "Platform must define assetInitPlatform function."
|
||||
@@ -20,7 +20,7 @@
|
||||
#define ASSET_FILE_NAME "dusk.dsk"
|
||||
#define ASSET_HEADER_SIZE 3
|
||||
|
||||
typedef struct asset_s {
|
||||
typedef struct {
|
||||
zip_t *zip;
|
||||
assetplatform_t platform;
|
||||
} asset_t;
|
||||
@@ -41,20 +41,13 @@ errorret_t assetInit(void);
|
||||
bool_t assetFileExists(const char_t *filename);
|
||||
|
||||
/**
|
||||
* Loads an asset by its filename,
|
||||
* Loads an asset by its filename, the output type depends on the asset type.
|
||||
*
|
||||
* @param filename The filename of the asset to retrieve.
|
||||
* @param loader Loader to use for loading the asset file.
|
||||
* @param params Parameters to pass to the loader.
|
||||
* @param output The output pointer to store the loaded asset data.
|
||||
* @return An error code if the asset could not be loaded.
|
||||
*/
|
||||
errorret_t assetLoad(
|
||||
const char_t *filename,
|
||||
assetfileloader_t loader,
|
||||
void *params,
|
||||
void *output
|
||||
);
|
||||
errorret_t assetLoad(const char_t *filename, void *output);
|
||||
|
||||
/**
|
||||
* Disposes/cleans up the asset system.
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "asset/asset.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
errorret_t assetFileInit(
|
||||
assetfile_t *file,
|
||||
const char_t *filename,
|
||||
void *params,
|
||||
void *output
|
||||
) {
|
||||
memoryZero(file, sizeof(assetfile_t));
|
||||
|
||||
file->filename = filename;
|
||||
file->params = params;
|
||||
file->output = output;
|
||||
|
||||
// Stat the file
|
||||
zip_stat_init(&file->stat);
|
||||
if(!zip_stat(ASSET.zip, filename, 0, &file->stat) == 0) {
|
||||
errorThrow("Failed to stat asset file: %s", filename);
|
||||
}
|
||||
|
||||
// Minimum file size.
|
||||
file->size = (zip_int64_t)file->stat.size;
|
||||
if(file->size <= 0) {
|
||||
errorThrow("Invalid asset file size: %s", filename);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetFileOpen(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->filename, "Asset file filename cannot be NULL.");
|
||||
assertNotNull(ASSET.zip, "Asset zip cannot be NULL.");
|
||||
assertNull(file->zipFile, "Asset file already open.");
|
||||
|
||||
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
||||
if(file->zipFile == NULL) {
|
||||
errorThrow("Failed to open asset file: %s", file->filename);
|
||||
}
|
||||
file->position = 0;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetFileRead(
|
||||
assetfile_t *file,
|
||||
void *buffer,
|
||||
const size_t bufferSize
|
||||
) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->zipFile, "Asset file must be opened before reading.");
|
||||
|
||||
// I assume zip_fread takes buffer NULL for skipping?
|
||||
zip_int64_t bytesRead = zip_fread(file->zipFile, buffer, bufferSize);
|
||||
if(bytesRead < 0) {
|
||||
errorThrow("Failed to read from asset file: %s", file->filename);
|
||||
}
|
||||
file->position += bytesRead;
|
||||
file->lastRead = bytesRead;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetFileClose(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->zipFile, "Asset file must be opened before closing.");
|
||||
|
||||
if(zip_fclose(file->zipFile) != 0) {
|
||||
errorThrow("Failed to close asset file: %s", file->filename);
|
||||
}
|
||||
file->zipFile = NULL;
|
||||
file->position = 0;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetFileDispose(assetfile_t *file) {
|
||||
if(file->zipFile != NULL) {
|
||||
errorChain(assetFileClose(file));
|
||||
}
|
||||
memoryZero(file, sizeof(assetfile_t));
|
||||
errorOk();
|
||||
}
|
||||
@@ -1,83 +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 <zip.h>
|
||||
|
||||
typedef struct assetfile_s assetfile_t;
|
||||
|
||||
typedef errorret_t (*assetfileloader_t)(assetfile_t *file);
|
||||
|
||||
typedef struct assetfile_s {
|
||||
const char_t *filename;
|
||||
void *params;
|
||||
void *output;
|
||||
|
||||
zip_stat_t stat;
|
||||
zip_int64_t size;
|
||||
zip_int64_t position;
|
||||
zip_int64_t lastRead;
|
||||
zip_file_t *zipFile;
|
||||
} assetfile_t;
|
||||
|
||||
/**
|
||||
* Initializes the asset file structure in preparation for loading. This will
|
||||
* stat the file but not open the handle.
|
||||
*
|
||||
* @param file The asset file structure to initialize.
|
||||
* @param filename The name of the asset file to load.
|
||||
* @param params Optional loader params.
|
||||
* @param output Output pointer for the loader.
|
||||
* @return Error indicating success or failure.
|
||||
*/
|
||||
errorret_t assetFileInit(
|
||||
assetfile_t *file,
|
||||
const char_t *filename,
|
||||
void *params,
|
||||
void *output
|
||||
);
|
||||
|
||||
/**
|
||||
* Opens the asset file for reading. After opening the loader is responsible
|
||||
* for closing the file.
|
||||
*
|
||||
* @param file The asset file to open.
|
||||
* @return An error code if the file could not be opened.
|
||||
*/
|
||||
errorret_t assetFileOpen(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Read bytes from the asset file. Assumes the file has already been opened
|
||||
* prior to trying to read anything.
|
||||
*
|
||||
* @param file File to read from.
|
||||
* @param buffer Buffer to read the file data into., or NULL to skip bytes.
|
||||
* @param size Size of the buffer to read into.
|
||||
*/
|
||||
errorret_t assetFileRead(
|
||||
assetfile_t *file,
|
||||
void *buffer,
|
||||
const size_t bufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Closes the asset file and releases any resources associated with it.
|
||||
*
|
||||
* @param file The asset file to close.
|
||||
* @return An error code if the file could not be closed properly.
|
||||
*/
|
||||
errorret_t assetFileClose(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Disposes the asset file structure, closing any open handles and zeroing
|
||||
* out the structure.
|
||||
*
|
||||
* @param file The asset file to dispose.
|
||||
* @return An error code if the file could not be disposed properly.
|
||||
*/
|
||||
errorret_t assetFileDispose(assetfile_t *file);
|
||||
106
src/dusk/asset/assettype.h
Normal file
106
src/dusk/asset/assettype.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "type/assettexture.h"
|
||||
// #include "type/assetpalette.h"
|
||||
#include "type/assettileset.h"
|
||||
#include "type/assetlanguage.h"
|
||||
#include "type/assetscript.h"
|
||||
#include "type/assetmap.h"
|
||||
#include "type/assetmapchunk.h"
|
||||
#include <zip.h>
|
||||
|
||||
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;
|
||||
|
||||
typedef enum {
|
||||
ASSET_LOAD_STRAT_ENTIRE,
|
||||
ASSET_LOAD_STRAT_CUSTOM
|
||||
} assetloadstrat_t;
|
||||
|
||||
typedef struct assetentire_s {
|
||||
void *data;
|
||||
void *output;
|
||||
} assetentire_t;
|
||||
|
||||
typedef struct assetcustom_s {
|
||||
zip_file_t *zipFile;
|
||||
void *output;
|
||||
} assetcustom_t;
|
||||
|
||||
typedef struct {
|
||||
const char_t *extension;
|
||||
const size_t dataSize;
|
||||
const assetloadstrat_t loadStrategy;
|
||||
union {
|
||||
errorret_t (*entire)(assetentire_t entire);
|
||||
errorret_t (*custom)(assetcustom_t custom);
|
||||
};
|
||||
} assettypedef_t;
|
||||
|
||||
static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
|
||||
[ASSET_TYPE_NULL] = {
|
||||
0
|
||||
},
|
||||
|
||||
[ASSET_TYPE_TEXTURE] = {
|
||||
.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",
|
||||
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
|
||||
.dataSize = sizeof(assettileset_t),
|
||||
.entire = assetTilesetLoad
|
||||
},
|
||||
|
||||
[ASSET_TYPE_LANGUAGE] = {
|
||||
.extension = "DLF",
|
||||
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
|
||||
.custom = assetLanguageHandler
|
||||
},
|
||||
|
||||
[ASSET_TYPE_SCRIPT] = {
|
||||
.extension = "lua",
|
||||
.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
|
||||
// },
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(script)
|
||||
add_subdirectory(json)
|
||||
@@ -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
|
||||
assettextureloader.c
|
||||
assettilesetloader.c
|
||||
)
|
||||
@@ -1,115 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assettextureloader.h"
|
||||
#include "assert/assert.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include "log/log.h"
|
||||
#include "util/endian.h"
|
||||
|
||||
stbi_io_callbacks ASSET_TEXTURE_STB_CALLBACKS = {
|
||||
.read = assetTextureReader,
|
||||
.skip = assetTextureSkipper,
|
||||
.eof = assetTextureEOF
|
||||
};
|
||||
|
||||
int assetTextureReader(void *user, char *data, int size) {
|
||||
assertNotNull(data, "Data buffer for stb_image callbacks cannot be NULL.");
|
||||
|
||||
assetfile_t *file = (assetfile_t*)user;
|
||||
assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL.");
|
||||
|
||||
errorret_t ret = assetFileRead(file, data, (size_t)size);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return file->lastRead;
|
||||
}
|
||||
|
||||
void assetTextureSkipper(void *user, int n) {
|
||||
assetfile_t *file = (assetfile_t*)user;
|
||||
assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL.");
|
||||
|
||||
errorret_t ret = assetFileRead(file, NULL, (size_t)n);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
}
|
||||
}
|
||||
|
||||
int assetTextureEOF(void *user) {
|
||||
assetfile_t *file = (assetfile_t*)user;
|
||||
assertNotNull(file, "Asset file in stb_image callbacks cannot be NULL.");
|
||||
|
||||
return file->position >= file->size;
|
||||
}
|
||||
|
||||
errorret_t assetTextureLoader(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->params, "Asset file parameters cannot be NULL.");
|
||||
assertNotNull(file->output, "Asset file output cannot be NULL.");
|
||||
|
||||
assettextureloaderparams_t *p = (assettextureloaderparams_t*)file->params;
|
||||
assertNotNull(p, "Asset texture loader parameters cannot be NULL.");
|
||||
|
||||
int channelsDesired;
|
||||
switch(p->format) {
|
||||
case TEXTURE_FORMAT_RGBA:
|
||||
channelsDesired = 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
errorThrow("Bad texture format.");
|
||||
}
|
||||
|
||||
int width, height, channels;
|
||||
errorChain(assetFileOpen(file));
|
||||
uint8_t *data = stbi_load_from_callbacks(
|
||||
&ASSET_TEXTURE_STB_CALLBACKS,
|
||||
file,
|
||||
&width,
|
||||
&height,
|
||||
&channels,
|
||||
channelsDesired
|
||||
);
|
||||
errorChain(assetFileClose(file));
|
||||
|
||||
if(data == NULL) {
|
||||
const char_t *errorStr = stbi_failure_reason();
|
||||
errorThrow("Failed to load texture from file %s.", errorStr);
|
||||
}
|
||||
|
||||
// Fixes a specific bug probably with Dolphin but for now just assuming endian
|
||||
if(!isHostLittleEndian()) {
|
||||
stbi__vertical_flip(data, width, height, channelsDesired);
|
||||
}
|
||||
|
||||
errorChain(textureInit(
|
||||
(texture_t*)file->output,
|
||||
(int32_t)width, (int32_t)height,
|
||||
p->format,
|
||||
(texturedata_t){
|
||||
.rgbaColors = (color_t*)data
|
||||
}
|
||||
));
|
||||
|
||||
stbi_image_free(data);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetTextureLoad(
|
||||
const char_t *path,
|
||||
texture_t *out,
|
||||
const textureformat_t format
|
||||
) {
|
||||
assettextureloaderparams_t params = {
|
||||
.format = format
|
||||
};
|
||||
return assetLoad(path, assetTextureLoader, ¶ms, out);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/asset.h"
|
||||
#include "display/texture/texture.h"
|
||||
|
||||
typedef struct {
|
||||
textureformat_t format;
|
||||
} assettextureloaderparams_t;
|
||||
|
||||
/**
|
||||
* STB image read callback for asset files.
|
||||
*
|
||||
* @param user User data passed to the callback, should be an assetfile_t*.
|
||||
* @param data Buffer to read the file data into.
|
||||
* @param size Size of the buffer to read into.
|
||||
* @return Number of bytes read, or -1 on error.
|
||||
*/
|
||||
int assetTextureReader(void *user, char *data, int size);
|
||||
|
||||
void assetTextureSkipper(void *user, int n);
|
||||
|
||||
int assetTextureEOF(void *user);
|
||||
|
||||
/**
|
||||
* Handler for texture assets.
|
||||
*
|
||||
* @param file Asset file to load the texture from.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetTextureLoader(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Loads a texture from the specified path.
|
||||
*
|
||||
* @param path Path to the texture asset.
|
||||
* @param out Output texture to load into.
|
||||
* @param format Format of the texture to load.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetTextureLoad(
|
||||
const char_t *path,
|
||||
texture_t *out,
|
||||
const textureformat_t format
|
||||
);
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assettilesetloader.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/endian.h"
|
||||
|
||||
errorret_t assetTilesetLoader(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file pointer for tileset loader is null.");
|
||||
|
||||
tileset_t *out = (tileset_t *)file->output;
|
||||
assertNotNull(out, "Output pointer for tileset loader is null.");
|
||||
|
||||
uint8_t *entire = memoryAllocate(file->size);
|
||||
errorChain(assetFileOpen(file));
|
||||
errorChain(assetFileRead(file, entire, file->size));
|
||||
errorChain(assetFileClose(file));
|
||||
assertTrue(file->lastRead == file->size, "Failed to read entire file.");
|
||||
|
||||
|
||||
if(
|
||||
entire[0] != 'D' ||
|
||||
entire[1] != 'T' ||
|
||||
entire[2] != 'F'
|
||||
) {
|
||||
errorThrow("Invalid tileset header");
|
||||
}
|
||||
|
||||
if(entire[3] != 0x00) {
|
||||
errorThrow("Unsupported tileset version");
|
||||
}
|
||||
|
||||
// Fix endianness
|
||||
|
||||
out->tileWidth = endianLittleToHost16(*(uint16_t *)(entire + 4));
|
||||
out->tileHeight = endianLittleToHost16(*(uint16_t *)(entire + 6));
|
||||
out->columns = endianLittleToHost16(*(uint16_t *)(entire + 8));
|
||||
out->rows = endianLittleToHost16(*(uint16_t *)(entire + 10));
|
||||
// out->right = endianLittleToHost16(*(uint16_t *)(entire + 12));
|
||||
// out->bottom = endianLittleToHost16(*(uint16_t *)(entire + 14));
|
||||
|
||||
if(out->tileWidth == 0) {
|
||||
errorThrow("Tile width cannot be 0");
|
||||
}
|
||||
if(out->tileHeight == 0) {
|
||||
errorThrow("Tile height cannot be 0");
|
||||
}
|
||||
if(out->columns == 0) {
|
||||
errorThrow("Column count cannot be 0");
|
||||
}
|
||||
if(out->rows == 0) {
|
||||
errorThrow("Row count cannot be 0");
|
||||
}
|
||||
|
||||
out->uv[0] = endianLittleToHostFloat(*(float *)(entire + 16));
|
||||
out->uv[1] = endianLittleToHostFloat(*(float *)(entire + 20));
|
||||
|
||||
if(out->uv[1] < 0.0f || out->uv[1] > 1.0f) {
|
||||
errorThrow("Invalid v0 value in tileset");
|
||||
}
|
||||
|
||||
// Setup tileset
|
||||
out->tileCount = out->columns * out->rows;
|
||||
|
||||
memoryFree(entire);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetTilesetLoad(
|
||||
const char_t *path,
|
||||
tileset_t *out
|
||||
) {
|
||||
return assetLoad(path, assetTilesetLoader, NULL, out);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/asset.h"
|
||||
#include "display/texture/tileset.h"
|
||||
|
||||
/**
|
||||
* Handler for tileset assets.
|
||||
*
|
||||
* @param file Asset file to load the tileset from.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetTilesetLoader(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Loads a tileset from the specified path.
|
||||
*
|
||||
* @param path Path to the tileset asset.
|
||||
* @param out Output tileset to load into.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetTilesetLoad(
|
||||
const char_t *path,
|
||||
tileset_t *out
|
||||
);
|
||||
@@ -1,10 +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
|
||||
assetjsonloader.c
|
||||
)
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assetjsonloader.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc) {
|
||||
assertNotNull(file, "Asset file pointer for JSON loader is null.");
|
||||
assertNotNull(outDoc, "Output pointer for JSON loader is null.");
|
||||
|
||||
if(file->size > ASSET_JSON_FILE_SIZE_MAX) {
|
||||
errorThrow("JSON exceeds maximum allowed size");
|
||||
}
|
||||
|
||||
// Create buffer
|
||||
uint8_t *buffer = memoryAllocate(file->size);
|
||||
|
||||
errorChain(assetFileOpen(file));
|
||||
|
||||
// Read entire file
|
||||
errorChain(assetFileRead(file, buffer, file->size));
|
||||
assertTrue(file->lastRead == file->size, "Failed to read entire JSON file.");
|
||||
|
||||
errorChain(assetFileClose(file));
|
||||
|
||||
*outDoc = yyjson_read(
|
||||
buffer,
|
||||
file->size,
|
||||
YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS
|
||||
);
|
||||
memoryFree(buffer);
|
||||
|
||||
if(!*outDoc) errorThrow("Failed to parse JSON");
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetJsonLoader(assetfile_t *file) {
|
||||
yyjson_doc **outDoc = (yyjson_doc **)file->output;
|
||||
assertNotNull(outDoc, "Output pointer for JSON loader is null.");
|
||||
return assetJsonLoadFileToDoc(file, outDoc);
|
||||
}
|
||||
|
||||
errorret_t assetJsonLoad(
|
||||
const char_t *path,
|
||||
yyjson_doc **outDoc
|
||||
) {
|
||||
return assetLoad(path, assetJsonLoader, NULL, outDoc);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/asset.h"
|
||||
#include "yyjson.h"
|
||||
|
||||
#define ASSET_JSON_FILE_SIZE_MAX 1024*256
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
} assetjsonloaderparams_t;
|
||||
|
||||
/**
|
||||
* Loads a JSON document from the specified asset file.
|
||||
*
|
||||
* @param file Asset file to load the JSON document from.
|
||||
* @param outDoc Pointer to store the loaded JSON document.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetJsonLoadFileToDoc(assetfile_t *file, yyjson_doc **outDoc);
|
||||
|
||||
/**
|
||||
* Handler for locale assets.
|
||||
*
|
||||
* @param file Asset file to load the locale from.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetJsonLoader(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Loads a locale from the specified path.
|
||||
*
|
||||
* @param path Path to the locale asset.
|
||||
* @param outDoc Pointer to store the loaded JSON document.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetJsonLoad(
|
||||
const char_t *path,
|
||||
yyjson_doc **outDoc
|
||||
);
|
||||
@@ -1,10 +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
|
||||
assetlocaleloader.c
|
||||
)
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assetlocaleloader.h"
|
||||
|
||||
errorret_t assetLocaleLoader(assetfile_t *file) {
|
||||
errorThrow("Locale asset loading is not yet implemented.");
|
||||
}
|
||||
|
||||
errorret_t assetLocaleLoad(
|
||||
const char_t *path,
|
||||
void *nothing
|
||||
) {
|
||||
errorThrow("Locale asset loading is not yet implemented.");
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/asset.h"
|
||||
#include "locale/localemanager.h"
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
} assetlocaleloaderparams_t;
|
||||
|
||||
/**
|
||||
* Handler for locale assets.
|
||||
*
|
||||
* @param file Asset file to load the locale from.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetLocaleLoader(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Loads a locale from the specified path.
|
||||
*
|
||||
* @param path Path to the locale asset.
|
||||
* @param nothing Nothing yet.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetLocaleLoad(
|
||||
const char_t *path,
|
||||
void *nothing
|
||||
);
|
||||
@@ -1,10 +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
|
||||
assetscriptloader.c
|
||||
)
|
||||
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assetscriptloader.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
errorret_t assetScriptLoader(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL");
|
||||
assertNull(file->zipFile, "Asset file zip handle must be NULL");
|
||||
assertNotNull(file->output, "Asset file output cannot be NULL");
|
||||
|
||||
assetscript_t *script = (assetscript_t *)file->output;
|
||||
|
||||
// Open the asset for buffering
|
||||
errorChain(assetFileOpen(file));
|
||||
|
||||
// Request loading
|
||||
if(!lua_load(
|
||||
script->ctx->luaState,
|
||||
assetScriptReader,
|
||||
file,
|
||||
file->filename,
|
||||
NULL
|
||||
) == LUA_OK) {
|
||||
const char_t *strErr = lua_tostring(script->ctx->luaState, -1);
|
||||
lua_pop(script->ctx->luaState, 1);
|
||||
errorThrow("Failed to load Lua script: %s", strErr);
|
||||
}
|
||||
|
||||
// Now loaded, exec
|
||||
if(lua_pcall(script->ctx->luaState, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||
const char_t *strErr = lua_tostring(script->ctx->luaState, -1);
|
||||
lua_pop(script->ctx->luaState, 1);
|
||||
errorThrow("Failed to execute Lua script: %s", strErr);
|
||||
}
|
||||
|
||||
// Close the file
|
||||
return assetFileClose(file);
|
||||
}
|
||||
|
||||
errorret_t assetScriptLoad(const char_t *path, scriptcontext_t *ctx) {
|
||||
assertNotNull(path, "Script path cannot be NULL");
|
||||
assertNotNull(ctx, "Script context cannot be NULL");
|
||||
|
||||
assetscript_t script;
|
||||
script.ctx = ctx;
|
||||
|
||||
return assetLoad(
|
||||
path,
|
||||
assetScriptLoader,
|
||||
NULL,
|
||||
&script
|
||||
);
|
||||
}
|
||||
|
||||
const char_t * assetScriptReader(lua_State* L, void* data, size_t* size) {
|
||||
assetfile_t *file = (assetfile_t*)data;
|
||||
assertNotNull(file, "Script asset file cannot be NULL");
|
||||
assertNotNull(file->zipFile, "Script asset zip handle cannot be NULL");
|
||||
assertNotNull(file->output, "Script asset output cannot be NULL");
|
||||
|
||||
assetscript_t *script = (assetscript_t *)file->output;
|
||||
assertNotNull(script, "Script asset output cannot be NULL");
|
||||
|
||||
zip_int64_t read = zip_fread(
|
||||
file->zipFile,
|
||||
script->buffer,
|
||||
sizeof(script->buffer)
|
||||
);
|
||||
|
||||
if(read < 0) {
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*size = (size_t)read;
|
||||
return script->buffer;
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "asset/asset.h"
|
||||
#include "script/scriptcontext.h"
|
||||
|
||||
#define ASSET_SCRIPT_BUFFER_SIZE 1024
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
} assetscriptloaderparams_t;
|
||||
|
||||
typedef struct {
|
||||
scriptcontext_t *ctx;
|
||||
char_t buffer[ASSET_SCRIPT_BUFFER_SIZE];
|
||||
} assetscript_t;
|
||||
|
||||
/**
|
||||
* Handler for script assets.
|
||||
*
|
||||
* @param file Asset file to load the script from.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetScriptLoader(assetfile_t *file);
|
||||
|
||||
/**
|
||||
* Loads a script from the specified path.
|
||||
*
|
||||
* @param path Path to the script asset.
|
||||
* @param ctx Script context to load the script into.
|
||||
* @return Any error that occurs during loading.
|
||||
*/
|
||||
errorret_t assetScriptLoad(const char_t *path, scriptcontext_t *ctx);
|
||||
|
||||
/**
|
||||
* Reader function for Lua to read script data from the asset.
|
||||
*
|
||||
* @param L Lua state.
|
||||
* @param data Pointer to the scriptcontext_t structure.
|
||||
* @param size Pointer to store the size of the read data.
|
||||
* @return Pointer to the read data buffer.
|
||||
*/
|
||||
const char_t * assetScriptReader(lua_State* L, void* data, size_t* size);
|
||||
@@ -10,4 +10,6 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
assettileset.c
|
||||
assetlanguage.c
|
||||
assetscript.c
|
||||
assetmap.c
|
||||
assetmapchunk.c
|
||||
)
|
||||
15
src/dusk/asset/type/assetmap.c
Normal file
15
src/dusk/asset/type/assetmap.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "asset/asset.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
errorret_t assetMapHandler(assetcustom_t custom) {
|
||||
printf("Map Loaded from asset!\n");
|
||||
errorOk();
|
||||
}
|
||||
20
src/dusk/asset/type/assetmap.h
Normal file
20
src/dusk/asset/type/assetmap.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
typedef struct assetcustom_s assetcustom_t;
|
||||
|
||||
/**
|
||||
* Loads a map asset from the given data pointer into the output map structure.
|
||||
*
|
||||
* @param data Pointer to the raw assetmap_t data.
|
||||
* @param output Pointer to the map_t to load the map into.
|
||||
* @return An error code.
|
||||
*/
|
||||
errorret_t assetMapHandler(assetcustom_t custom);
|
||||
185
src/dusk/asset/type/assetmapchunk.c
Normal file
185
src/dusk/asset/type/assetmapchunk.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "asset/asset.h"
|
||||
#include "assert/assert.h"
|
||||
#include "map/mapchunk.h"
|
||||
#include "util/endian.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint32_t tileCount;
|
||||
uint8_t modelCount;
|
||||
uint8_t entityCount;
|
||||
} assetchunkheader_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
maptile_t tile;
|
||||
} assetchunktiledata_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint32_t vertexCount;
|
||||
} assetchunkmodelheader_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint8_t entityType;
|
||||
uint8_t localX;
|
||||
uint8_t localY;
|
||||
uint8_t localZ;
|
||||
} assetchunkentityheader_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
errorret_t assetMapChunkHandler(assetcustom_t custom) {
|
||||
assertNotNull(custom.output, "Output pointer cannot be NULL");
|
||||
assertNotNull(custom.zipFile, "Zip file pointer cannot be NULL");
|
||||
|
||||
mapchunk_t *chunk = (mapchunk_t *)custom.output;
|
||||
assertTrue(chunk->meshCount == 0, "Chunk is not in a good state");
|
||||
|
||||
// Read header
|
||||
assetchunkheader_t header;
|
||||
size_t bytesRead = zip_fread(
|
||||
custom.zipFile, &header, sizeof(assetchunkheader_t)
|
||||
);
|
||||
if(bytesRead != sizeof(assetchunkheader_t)) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow("Failed to read chunk asset header.");
|
||||
}
|
||||
|
||||
// Fix endianess if necessary
|
||||
header.tileCount = endianLittleToHost32(header.tileCount);
|
||||
|
||||
if(header.tileCount != CHUNK_TILE_COUNT) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow(
|
||||
"Chunk asset has invalid tile count: %d (expected %d).",
|
||||
header.tileCount,
|
||||
CHUNK_TILE_COUNT
|
||||
);
|
||||
}
|
||||
|
||||
if(header.modelCount > CHUNK_MESH_COUNT_MAX) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow(
|
||||
"Chunk asset has too many models: %d (max %d).",
|
||||
header.modelCount,
|
||||
CHUNK_MESH_COUNT_MAX
|
||||
);
|
||||
}
|
||||
|
||||
if(header.entityCount > CHUNK_ENTITY_COUNT_MAX) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow(
|
||||
"Chunk asset has too many entities: %d (max %d).",
|
||||
header.entityCount,
|
||||
CHUNK_ENTITY_COUNT_MAX
|
||||
);
|
||||
}
|
||||
|
||||
chunk->meshCount = header.modelCount;
|
||||
|
||||
// Read tile data
|
||||
bytesRead = zip_fread(
|
||||
custom.zipFile,
|
||||
chunk->tiles,
|
||||
sizeof(assetchunktiledata_t) * header.tileCount
|
||||
);
|
||||
if(bytesRead != sizeof(assetchunktiledata_t) * header.tileCount) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow("Failed to read chunk tile data.");
|
||||
}
|
||||
|
||||
// For each model...
|
||||
uint32_t vertexIndex = 0;
|
||||
for(uint8_t i = 0; i < header.modelCount; i++) {
|
||||
assetchunkmodelheader_t modelHeader;
|
||||
bytesRead = zip_fread(
|
||||
custom.zipFile, &modelHeader, sizeof(assetchunkmodelheader_t)
|
||||
);
|
||||
if(bytesRead != sizeof(assetchunkmodelheader_t)) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow("Failed to read chunk model header.");
|
||||
}
|
||||
|
||||
// Fix endianess if necessary
|
||||
modelHeader.vertexCount = endianLittleToHost32(modelHeader.vertexCount);
|
||||
|
||||
if(
|
||||
vertexIndex + modelHeader.vertexCount >
|
||||
CHUNK_VERTEX_COUNT_MAX
|
||||
) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow("Chunk model vertex count exceeds maximum.");
|
||||
}
|
||||
|
||||
// Read vertex data.
|
||||
bytesRead = zip_fread(
|
||||
custom.zipFile,
|
||||
&chunk->vertices[vertexIndex],
|
||||
sizeof(meshvertex_t) * modelHeader.vertexCount
|
||||
);
|
||||
if(bytesRead != sizeof(meshvertex_t) * modelHeader.vertexCount) {
|
||||
zip_fclose(custom.zipFile);
|
||||
errorThrow("Failed to read chunk model vertex data.");
|
||||
}
|
||||
|
||||
// Init the mesh
|
||||
if(modelHeader.vertexCount > 0) {
|
||||
mesh_t *mesh = &chunk->meshes[i];
|
||||
meshInit(
|
||||
mesh,
|
||||
MESH_PRIMITIVE_TYPE_TRIANGLES,
|
||||
modelHeader.vertexCount,
|
||||
&chunk->vertices[vertexIndex]
|
||||
);
|
||||
|
||||
vertexIndex += modelHeader.vertexCount;
|
||||
} else {
|
||||
// chunk->meshes[i].vertexCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Read entity data
|
||||
// for(uint8_t i = 0; i < header.entityCount; i++) {
|
||||
// assetchunkentityheader_t entityHeader;
|
||||
// bytesRead = zip_fread(
|
||||
// custom.zipFile, &entityHeader, sizeof(assetchunkentityheader_t)
|
||||
// );
|
||||
// if(bytesRead != sizeof(assetchunkentityheader_t)) {
|
||||
// zip_fclose(custom.zipFile);
|
||||
// errorThrow("Failed to read chunk entity header.");
|
||||
// }
|
||||
|
||||
// uint8_t entityIndex = entityGetAvailable();
|
||||
// if(entityIndex == 0xFF) {
|
||||
// zip_fclose(custom.zipFile);
|
||||
// errorThrow("No available entity slots.");
|
||||
// }
|
||||
|
||||
// entity_t *entity = &ENTITIES[entityIndex];
|
||||
// entityInit(entity, (entitytype_t)entityHeader.entityType);
|
||||
// entity->position.x = (
|
||||
// (chunk->position.x * CHUNK_WIDTH) + entityHeader.localX
|
||||
// );
|
||||
// entity->position.y = (
|
||||
// (chunk->position.y * CHUNK_HEIGHT) + entityHeader.localY
|
||||
// );
|
||||
// entity->position.z = (
|
||||
// (chunk->position.z * CHUNK_DEPTH) + entityHeader.localZ
|
||||
// );
|
||||
|
||||
// chunk->entities[i] = entityIndex;
|
||||
// }
|
||||
|
||||
errorOk();
|
||||
}
|
||||
19
src/dusk/asset/type/assetmapchunk.h
Normal file
19
src/dusk/asset/type/assetmapchunk.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
typedef struct assetcustom_s assetcustom_t;
|
||||
|
||||
/**
|
||||
* Handles loading of map chunk data from a map chunk asset file.
|
||||
*
|
||||
* @param custom The custom asset loading parameters.
|
||||
* @return An error code.
|
||||
*/
|
||||
errorret_t assetMapChunkHandler(assetcustom_t custom);
|
||||
61
src/dusk/asset/type/assettexture.c
Normal file
61
src/dusk/asset/type/assettexture.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assettexture.h"
|
||||
#include "asset/assettype.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "util/endian.h"
|
||||
|
||||
errorret_t assetTextureLoad(assetentire_t entire) {
|
||||
// assertNotNull(entire.data, "Data pointer cannot be NULL.");
|
||||
// assertNotNull(entire.output, "Output pointer cannot be NULL.");
|
||||
|
||||
// assettexture_t *assetData = (assettexture_t *)entire.data;
|
||||
// texture_t *texture = (texture_t *)entire.output;
|
||||
|
||||
// // Read header and version (first 4 bytes)
|
||||
// if(
|
||||
// assetData->header[0] != 'D' ||
|
||||
// assetData->header[1] != 'P' ||
|
||||
// assetData->header[2] != 'T'
|
||||
// ) {
|
||||
// errorThrow("Invalid texture header");
|
||||
// }
|
||||
|
||||
// // Version (can only be 1 atm)
|
||||
// if(assetData->version != 0x01) {
|
||||
// errorThrow("Unsupported texture version");
|
||||
// }
|
||||
|
||||
// // Fix endian
|
||||
// assetData->width = endianLittleToHost32(assetData->width);
|
||||
// assetData->height = endianLittleToHost32(assetData->height);
|
||||
|
||||
// // Check dimensions.
|
||||
// if(
|
||||
// assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX ||
|
||||
// assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX
|
||||
// ) {
|
||||
// errorThrow("Invalid texture dimensions");
|
||||
// }
|
||||
|
||||
// textureInit(
|
||||
// texture,
|
||||
// assetData->width,
|
||||
// assetData->height,
|
||||
// TEXTURE_FORMAT_PALETTE,
|
||||
// (texturedata_t){
|
||||
// .paletted = {
|
||||
// .indices = NULL,
|
||||
// .palette = NULL
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -35,9 +35,9 @@ void cameraInitOrthographic(camera_t *camera) {
|
||||
camera->projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC;
|
||||
camera->orthographic.left = 0.0f;
|
||||
camera->orthographic.right = SCREEN.width;
|
||||
camera->orthographic.top = SCREEN.height;
|
||||
camera->orthographic.bottom = 0.0f;
|
||||
camera->nearClip = 0.1f;
|
||||
camera->orthographic.top = 0.0f;
|
||||
camera->orthographic.bottom = SCREEN.height;
|
||||
camera->nearClip = -1.0f;
|
||||
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_ucopy(camera->view, dest);
|
||||
glm_mat4_copy(camera->view, dest);
|
||||
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
|
||||
glm_mat4_identity(dest);
|
||||
glm_lookat(
|
||||
|
||||
@@ -21,3 +21,4 @@ lime,0.75,1,0,1
|
||||
navy,0,0,0.5,1
|
||||
teal,0,0.5,0.5,1
|
||||
cornflower_blue,0.39,0.58,0.93,1
|
||||
salmon,1,0.5,0.5,1
|
||||
|
@@ -20,27 +20,11 @@
|
||||
#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 }
|
||||
}
|
||||
};
|
||||
|
||||
texture_t PALETTE_TEXTURE;
|
||||
texture_t UNCOMPRESSED_TEXTURE;
|
||||
texture_t COMPRESSED_TEXTURE;
|
||||
|
||||
errorret_t displayInit(void) {
|
||||
memoryZero(&DISPLAY, sizeof(DISPLAY));
|
||||
@@ -48,27 +32,64 @@ 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());
|
||||
|
||||
// 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));
|
||||
// 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;
|
||||
|
||||
errorChain(meshInit(&mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, 3, vertices));
|
||||
// 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
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -89,7 +110,38 @@ errorret_t displayUpdate(void) {
|
||||
SCREEN.background
|
||||
);
|
||||
|
||||
errorChain(sceneRender());
|
||||
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()));
|
||||
|
||||
// Render UI
|
||||
// uiRender();
|
||||
|
||||
@@ -7,5 +7,4 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
shader.c
|
||||
shaderunlit.c
|
||||
)
|
||||
@@ -8,19 +8,15 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -32,7 +28,6 @@ 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();
|
||||
}
|
||||
@@ -44,7 +39,6 @@ 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();
|
||||
}
|
||||
@@ -62,7 +56,6 @@ errorret_t shaderSetTexture(
|
||||
|
||||
errorret_t shaderDispose(shader_t *shader) {
|
||||
assertNotNull(shader, "Shader cannot be null");
|
||||
bound = NULL;
|
||||
errorChain(shaderDisposePlatform(shader));
|
||||
errorOk();
|
||||
}
|
||||
@@ -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 };
|
||||
@@ -15,4 +15,4 @@
|
||||
// #define SHADER_UNLIT_COLOR "u_Color"
|
||||
|
||||
extern shaderdefinition_t SHADER_UNLIT_DEFINITION;
|
||||
extern shader_t SHADER_UNLIT;
|
||||
static shader_t SHADER_UNLIT;
|
||||
@@ -35,13 +35,14 @@ errorret_t spriteBatchPush(
|
||||
const float_t u1,
|
||||
const float_t v1
|
||||
) {
|
||||
return spriteBatchPush3D(
|
||||
errorChain(spriteBatchPush3D(
|
||||
(vec3){ minX, minY, 0 },
|
||||
(vec3){ maxX, maxY, 0 },
|
||||
color,
|
||||
(vec2){ u0, v0 },
|
||||
(vec2){ u1, v1 }
|
||||
);
|
||||
));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t spriteBatchPush3D(
|
||||
@@ -52,14 +53,11 @@ errorret_t spriteBatchPush3D(
|
||||
const vec2 uv1
|
||||
) {
|
||||
// Need to flush?
|
||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
|
||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX) {
|
||||
errorChain(spriteBatchFlush());
|
||||
}
|
||||
|
||||
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 +68,6 @@ errorret_t spriteBatchPush3D(
|
||||
|
||||
void spriteBatchClear() {
|
||||
SPRITEBATCH.spriteCount = 0;
|
||||
SPRITEBATCH.spriteFlush = 0;
|
||||
}
|
||||
|
||||
errorret_t spriteBatchFlush() {
|
||||
@@ -79,19 +76,9 @@ errorret_t spriteBatchFlush() {
|
||||
}
|
||||
|
||||
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(meshFlush(&SPRITEBATCH.mesh, 0, vertexCount));
|
||||
errorChain(meshDraw(&SPRITEBATCH.mesh, 0, vertexCount));
|
||||
spriteBatchClear();
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,12 @@
|
||||
#pragma once
|
||||
#include "display/mesh/quad.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;
|
||||
} spritebatch_t;
|
||||
|
||||
// Have to define these seperately because of alignment in certain platforms.
|
||||
|
||||
@@ -9,23 +9,19 @@
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "asset/loader/display/assettextureloader.h"
|
||||
#include "asset/loader/display/assettilesetloader.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "asset/asset.h"
|
||||
|
||||
texture_t DEFAULT_FONT_TEXTURE;
|
||||
tileset_t DEFAULT_FONT_TILESET;
|
||||
|
||||
errorret_t textInit(void) {
|
||||
errorChain(assetTextureLoad(
|
||||
"ui/minogram.png", &DEFAULT_FONT_TEXTURE, TEXTURE_FORMAT_RGBA
|
||||
));
|
||||
errorChain(assetTilesetLoad("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();
|
||||
}
|
||||
|
||||
@@ -49,7 +45,6 @@ errorret_t textDrawChar(
|
||||
vec4 uv;
|
||||
tilesetTileGetUV(tileset, tileIndex, uv);
|
||||
|
||||
|
||||
errorChain(spriteBatchPush(
|
||||
// texture,
|
||||
x, y,
|
||||
@@ -75,17 +70,6 @@ errorret_t textDraw(
|
||||
float_t posX = x;
|
||||
float_t posY = y;
|
||||
|
||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture));
|
||||
|
||||
// errorChain(spriteBatchPush(
|
||||
// // texture,
|
||||
// posX, posY,
|
||||
// posX + texture->width * 1, posY + texture->height * 1,
|
||||
// color,
|
||||
// 0.0f, 0.0f, 1.0f, 1.0f
|
||||
// ));
|
||||
// errorOk();
|
||||
|
||||
char_t c;
|
||||
int32_t i = 0;
|
||||
while((c = text[i++]) != '\0') {
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
#include "scene/scene.h"
|
||||
#include "asset/asset.h"
|
||||
#include "ui/ui.h"
|
||||
#include "map/map.h"
|
||||
#include "script/scriptmanager.h"
|
||||
#include "item/backpack.h"
|
||||
#include "assert/assert.h"
|
||||
#include "game/game.h"
|
||||
|
||||
#include "asset/loader/json/assetjsonloader.h"
|
||||
|
||||
engine_t ENGINE;
|
||||
|
||||
@@ -36,22 +35,9 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
errorChain(scriptManagerInit());
|
||||
errorChain(displayInit());
|
||||
errorChain(uiInit());
|
||||
errorChain(mapInit());
|
||||
errorChain(sceneInit());
|
||||
errorChain(gameInit());
|
||||
|
||||
// JSON test.
|
||||
yyjson_doc *doc;
|
||||
assetJsonLoad("test.json", &doc);
|
||||
|
||||
yyjson_val *root = yyjson_doc_get_root(doc);
|
||||
assertTrue(root, "JSON root is null.");
|
||||
|
||||
yyjson_val *name = yyjson_obj_get(root, "name");
|
||||
assertTrue(name && yyjson_is_str(name), "JSON 'name' field is missing or not a string.");
|
||||
const char *nameStr = yyjson_get_str(name);
|
||||
printf("Name: %s\n", nameStr);
|
||||
|
||||
yyjson_doc_free(doc);
|
||||
backpackInit();
|
||||
|
||||
// Run the initial script.
|
||||
scriptcontext_t ctx;
|
||||
@@ -68,7 +54,7 @@ errorret_t engineUpdate(void) {
|
||||
|
||||
uiUpdate();
|
||||
errorChain(sceneUpdate());
|
||||
errorChain(gameUpdate());
|
||||
mapUpdate();
|
||||
errorChain(displayUpdate());
|
||||
|
||||
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
|
||||
@@ -82,7 +68,7 @@ void engineExit(void) {
|
||||
|
||||
errorret_t engineDispose(void) {
|
||||
sceneDispose();
|
||||
errorChain(gameDispose());
|
||||
mapDispose();
|
||||
localeManagerDispose();
|
||||
uiDispose();
|
||||
errorChain(displayDispose());
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "localemanager.h"
|
||||
#include "util/memory.h"
|
||||
#include "asset/asset.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
localemanager_t LOCALE;
|
||||
|
||||
@@ -32,4 +34,5 @@ errorret_t localeManagerSetLocale(const dusklocale_t locale) {
|
||||
}
|
||||
|
||||
void localeManagerDispose() {
|
||||
assetLanguageDispose(&LOCALE.language);
|
||||
}
|
||||
@@ -6,13 +6,13 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "asset/asset.h"
|
||||
#include "localemanager.h"
|
||||
#include "locale/locale.h"
|
||||
|
||||
typedef struct {
|
||||
dusklocale_t locale;
|
||||
// assetlanguage_t language;
|
||||
assetlanguage_t language;
|
||||
} localemanager_t;
|
||||
|
||||
extern localemanager_t LOCALE;
|
||||
|
||||
@@ -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,6 @@ 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) {
|
||||
@@ -126,7 +116,7 @@ int moduleCameraCreate(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int moduleCameraIndex(lua_State *l) {
|
||||
int moduleCameraIndex(lua_State *l) {
|
||||
assertNotNull(l, "Lua state cannot be NULL.");
|
||||
|
||||
const char_t *key = luaL_checkstring(l, 2);
|
||||
@@ -299,35 +289,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;
|
||||
}
|
||||
@@ -36,19 +36,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();
|
||||
@@ -6,9 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "moduletexture.h"
|
||||
#include "assert/assert.h"
|
||||
#include "asset/asset.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "asset/loader/display/assettextureloader.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
@@ -84,11 +84,6 @@ int moduleTextureLoad(lua_State *l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!lua_isnumber(l, 2)) {
|
||||
luaL_error(l, "Second argument must be a number format.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char_t *filename = lua_tostring(l, 1);
|
||||
assertNotNull(filename, "Filename cannot be NULL.");
|
||||
assertStrLenMin(filename, 1, "Filename cannot be empty.");
|
||||
@@ -97,9 +92,7 @@ int moduleTextureLoad(lua_State *l) {
|
||||
texture_t *tex = (texture_t *)lua_newuserdata(l, sizeof(texture_t));
|
||||
memoryZero(tex, sizeof(texture_t));
|
||||
|
||||
textureformat_t format = (textureformat_t)lua_tonumber(l, 2);
|
||||
|
||||
errorret_t ret = assetTextureLoad(filename, tex, format);
|
||||
errorret_t ret = assetLoad(filename, tex);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
luaL_error(l, "Failed to load texture asset: %s", filename);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user