Compare commits
64 Commits
Author | SHA1 | Date | |
---|---|---|---|
bdf18fffd3 | |||
90c3b6149e | |||
a896b772fb | |||
1d16c0ae68 | |||
96fcddea30 | |||
2049a6f7b9 | |||
889c6f9826 | |||
a316febd9f | |||
e779e77922 | |||
588b78be69 | |||
70c15206b8 | |||
6d89abf64e | |||
bfd1ac6953 | |||
7c3225fe10 | |||
f574b60856 | |||
ba305de596 | |||
afa6a1a036 | |||
fe69d85fab | |||
f5958f2879 | |||
e10aea20a1 | |||
2b36a12335 | |||
698aeb2afc | |||
c87f13b063 | |||
b5958189cf | |||
b3c2e0114f | |||
ccd5b36965 | |||
d1d7d46826 | |||
7628f33c25 | |||
876d4c4198 | |||
872e79e4fb | |||
cf9af3a818 | |||
f98be769e7 | |||
d35fba24fa | |||
4e0bb5caa9 | |||
7c68b7bc8b | |||
68f6453da6 | |||
8469da79d0 | |||
250754af0a | |||
9d91fa6435 | |||
e6672945ae | |||
a4774e6189 | |||
223bbed232 | |||
a6ac4f029e | |||
5998037994 | |||
68fab7c94d | |||
7989be5fe7 | |||
e660fade95 | |||
9fd4c2399f | |||
2af55041c8 | |||
ac0f0e86c5 | |||
4dccd7d969 | |||
bcbc8796da | |||
f4120095ed | |||
e91b1983c8 | |||
98f2f3e955 | |||
91caebd385 | |||
4914ec6168 | |||
de55029356 | |||
a2c841288d | |||
274c96bb64 | |||
aefbe17786 | |||
cfa9e0e99a | |||
f8c008fd45 | |||
a02e87c3fa |
56
.github/workflows/build-helloworld-vita.yml
vendored
56
.github/workflows/build-helloworld-vita.yml
vendored
@@ -1,56 +0,0 @@
|
||||
name: build-helloworld-vita
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
VITASDK: /usr/local/vitasdk
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Cache VITASDK
|
||||
id: cache-vitasdk-restore
|
||||
uses: actions/cache/restore@v3
|
||||
with:
|
||||
path: /usr/local/vitasdk
|
||||
key: ${{ runner.os }}-vitasdk
|
||||
|
||||
- name: Install Vita Toolchain
|
||||
if: steps.cache-vitasdk.outputs.cache-hit != 'true'
|
||||
run: ./ci/install-vita-toolchain.sh
|
||||
|
||||
- name: Save VITASDK
|
||||
id: cache-vitasdk-save
|
||||
uses: actions/cache/save@v3
|
||||
with:
|
||||
path: /usr/local/vitasdk
|
||||
key: ${{ steps.cache-vitasdk-restore.outputs.cache-primary-key }}
|
||||
|
||||
- name: Install Libraries
|
||||
run: ./ci/install-libraries.sh
|
||||
|
||||
- name: Build Tools
|
||||
run: ./ci/build-tools.sh
|
||||
|
||||
- name: Build Game
|
||||
run: |
|
||||
export PATH=$VITASDK/bin:$PATH
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
|
||||
make
|
||||
|
||||
- name: Deploying
|
||||
env:
|
||||
DAWN_SSH_KEY: ${{ secrets.DAWN_SSH_KEY }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo -e "${DAWN_SSH_KEY}" > ~/.ssh/id_rsa
|
||||
chmod og-rwx ~/.ssh/id_rsa
|
||||
ssh-keyscan -H wish.moe >> ~/.ssh/known_hosts
|
||||
ssh -t yourwishes@wish.moe "mkdir -p /home/yourwishes/Dawn/vita/debug"
|
||||
scp ./build/src/dawnvita/HelloWorld.vpk yourwishes@wish.moe:/home/yourwishes/Dawn/vita/debug/
|
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
@@ -1,26 +0,0 @@
|
||||
name: build-liminal-glfw-linux64
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Toolchain
|
||||
run: ./ci/install-linux-toolchain.sh
|
||||
|
||||
- name: Install Libraries
|
||||
run: ./ci/install-libraries.sh
|
||||
|
||||
- name: Build Tools
|
||||
run: ./ci/build-tools.sh
|
||||
|
||||
- name: Build Game
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DDAWN_BUILD_TARGET=target-liminial-linux64-glfw
|
||||
make
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -65,7 +65,7 @@ CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
# Custom
|
||||
/build/*
|
||||
build
|
||||
.vscode
|
||||
|
||||
assets/testworld/tileset.png
|
||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,6 +0,0 @@
|
||||
[submodule "lib/openal-soft"]
|
||||
path = lib/openal-soft
|
||||
url = https://github.com/kcat/openal-soft
|
||||
[submodule "lib/AudioFile"]
|
||||
path = lib/AudioFile
|
||||
url = https://github.com/adamstark/AudioFile.git
|
122
CMakeLists.txt
122
CMakeLists.txt
@@ -1,43 +1,125 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Setup
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Variable Caches
|
||||
set(DAWN_CACHE_TARGET "dawn-target")
|
||||
set(DAWN_TARGET_NAME "Dawn")
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
if(NOT DEFINED DAWN_TARGET)
|
||||
set(DAWN_TARGET linux-x64-glfw CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
if(NOT DEFINED DAWN_TARGET_SYSTEM)
|
||||
set(DAWN_TARGET_SYSTEM "linux")
|
||||
endif()
|
||||
|
||||
# Set Common Build Variables
|
||||
# Prep cache
|
||||
set(DAWN_CACHE_TARGET "dawn-target")
|
||||
|
||||
# Build variables
|
||||
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||
set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
||||
set(DAWN_SOURCES_DIR "${DAWN_ROOT_DIR}/src")
|
||||
set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools")
|
||||
set(DAWN_ASSETS_SOURCE_DIR "${DAWN_ROOT_DIR}/assets")
|
||||
set(DAWN_ASSETS_BUILD_DIR "${DAWN_BUILD_DIR}/assets")
|
||||
set(DAWN_GENERATED_DIR "${DAWN_BUILD_DIR}/generated")
|
||||
set(DAWN_TEMP_DIR "${DAWN_BUILD_DIR}/temp")
|
||||
set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools")
|
||||
set(DAWN_DATA_DIR "${DAWN_ROOT_DIR}/data")
|
||||
set(DAWN_ASSETS_DIR "${DAWN_ROOT_DIR}/assets")
|
||||
set(DAWN_BUILT_ASSETS_DIR "${DAWN_BUILD_DIR}/built_assets" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_GENERATED_HEADERS_DIR "${DAWN_BUILD_DIR}/generated")
|
||||
set(DAWN_TARGET_NAME "Dawn" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/Dawn CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_ASSETS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Initialize Project.
|
||||
project(Dawn
|
||||
# Create directories
|
||||
file(MAKE_DIRECTORY ${DAWN_GENERATED_HEADERS_DIR})
|
||||
|
||||
# Find packages
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
|
||||
# Toolchains
|
||||
if(DAWN_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(pspsdk REQUIRED)
|
||||
endif()
|
||||
|
||||
# Init Project
|
||||
project(${DAWN_TARGET_NAME}
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
# Executable
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Add tools
|
||||
add_subdirectory(tools)
|
||||
# add_subdirectory(tools)
|
||||
|
||||
# Add Libraries
|
||||
add_subdirectory(lib)
|
||||
# Assets
|
||||
# add_subdirectory(assets)
|
||||
|
||||
# Add Project Files
|
||||
add_subdirectory(src)
|
||||
# Add libraries
|
||||
if(DAWN_TARGET_SYSTEM STREQUAL "linux")
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SDL2
|
||||
OpenGL::GL
|
||||
GL
|
||||
)
|
||||
|
||||
elseif(DAWN_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${SDL2_LIBRARIES}
|
||||
SDL2
|
||||
OpenGL::GL
|
||||
zip
|
||||
bz2
|
||||
z
|
||||
mbedtls
|
||||
mbedcrypto
|
||||
lzma
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME} PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add code
|
||||
add_subdirectory(src)
|
||||
|
||||
# Include generated headers
|
||||
target_include_directories(${DAWN_TARGET_NAME} PUBLIC
|
||||
${DAWN_GENERATED_HEADERS_DIR}
|
||||
)
|
||||
|
||||
# # Build assets
|
||||
# add_custom_target(DAWN_ASSETS_BUILT ALL
|
||||
# COMMAND
|
||||
# ${Python3_EXECUTABLE} ${DAWN_TOOLS_DIR}/assetstool/main.py
|
||||
# --assets ${DAWN_ASSETS_DIR}
|
||||
# --build-type wad
|
||||
# --output-assets ${DAWN_BUILT_ASSETS_DIR}
|
||||
# --output-file ${DAWN_BUILD_DIR}/dusk.dsk
|
||||
# --output-headers ${DAWN_GENERATED_HEADERS_DIR}/asset/assetbundle.h
|
||||
# --headers-dir ${DAWN_GENERATED_HEADERS_DIR}
|
||||
# --input ${DAWN_ASSETS}
|
||||
# )
|
||||
# add_dependencies(${DAWN_TARGET_NAME} DAWN_ASSETS_BUILT)
|
||||
|
||||
# # Postbuild
|
||||
# if(DAWN_TARGET_SYSTEM STREQUAL "psp")
|
||||
# create_pbp_file(
|
||||
# TARGET "${DAWN_TARGET_NAME}"
|
||||
# ICON_PATH NULL
|
||||
# BACKGROUND_PATH NULL
|
||||
# PREVIEW_PATH NULL
|
||||
# TITLE "${DAWN_TARGET_NAME}"
|
||||
# VERSION 01.00
|
||||
# )
|
||||
# endif()
|
@@ -1,7 +0,0 @@
|
||||
# Copyright (c) 2024 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
tool_truetype(font_silver "${CMAKE_CURRENT_LIST_DIR}/Silver.ttf")
|
||||
tool_copy(json_test "${CMAKE_CURRENT_LIST_DIR}/test.json" "${DAWN_ASSETS_BUILD_DIR}/test.json")
|
Binary file not shown.
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "Some Map",
|
||||
"width": 3,
|
||||
"height": 3,
|
||||
"depth": 3,
|
||||
"tiles": [
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0
|
||||
]
|
||||
}
|
14
cmake/modules/Findglm.cmake
Normal file
14
cmake/modules/Findglm.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
glm
|
||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||
GIT_TAG 1.0.1
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(glm)
|
||||
set(glm_FOUND ON)
|
106
cmake/modules/Findpspsdk.cmake
Normal file
106
cmake/modules/Findpspsdk.cmake
Normal file
@@ -0,0 +1,106 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
if(NOT TARGET pspsdk)
|
||||
message(STATUS "Looking for PSPSDK...")
|
||||
|
||||
set(PSPSDK_FOUND FALSE CACHE INTERNAL "PSPSDK found")
|
||||
set(PSPSDK_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/_pspsdk")
|
||||
set(PSPSDK_SEARCH_ROOTS
|
||||
"${PSPSDK_ROOT}"
|
||||
"$ENV{PSPDEV}"
|
||||
"$ENV{HOME}/pspdev"
|
||||
"/usr/local/pspdev"
|
||||
"/opt/pspdev"
|
||||
"/usr/pspdev"
|
||||
"${PSPSDK_DOWNLOAD_DIR}/pspdev"
|
||||
)
|
||||
|
||||
foreach(root IN LISTS PSPSDK_SEARCH_ROOTS)
|
||||
list(APPEND PSPSDK_BIN_HINTS "${root}/bin")
|
||||
list(APPEND PSPSDK_INCLUDE_HINTS "${root}/include")
|
||||
list(APPEND PSPSDK_LIB_HINTS "${root}/lib")
|
||||
endforeach()
|
||||
|
||||
# Find PSP GCC
|
||||
find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS})
|
||||
|
||||
# If we did not find it, download it.
|
||||
if(NOT PSPSDK_PSP_GCC)
|
||||
message(STATUS "psp-gcc not found in system paths. Downloading PSPSDK tarball...")
|
||||
file(DOWNLOAD
|
||||
"https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz"
|
||||
"${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
||||
EXPECTED_HASH SHA256=2befe2ad83afd88934c106dbe98a72a7ad5ede8d272b7f1e79fda256a22f1062
|
||||
SHOW_PROGRESS
|
||||
)
|
||||
|
||||
# Make output dir
|
||||
file(MAKE_DIRECTORY "${PSPSDK_DOWNLOAD_DIR}")
|
||||
|
||||
# Extract the tarball
|
||||
execute_process(
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E tar xzf "${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
||||
WORKING_DIRECTORY
|
||||
"${PSPSDK_DOWNLOAD_DIR}"
|
||||
RESULT_VARIABLE
|
||||
tar_result
|
||||
)
|
||||
if(NOT tar_result EQUAL 0)
|
||||
message(FATAL_ERROR "Failed to extract PSPSDK tarball")
|
||||
endif()
|
||||
|
||||
# Retry discovery with extracted fallback
|
||||
find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS})
|
||||
endif()
|
||||
|
||||
if(PSPSDK_PSP_GCC)
|
||||
get_filename_component(PSPSDK_BIN_ROOT "${PSPSDK_PSP_GCC}" DIRECTORY)
|
||||
get_filename_component(PSPSDK_ROOT "${PSPSDK_BIN_ROOT}" DIRECTORY)
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
set(ENV{PSPDEV} "${PSPSDK_ROOT}")
|
||||
set(CMAKE_TOOLCHAIN_FILE "${PSPSDK_ROOT}/psp/share/pspdev.cmake")
|
||||
set(BUILD_PRX ON CACHE BOOL "Build PRX modules")
|
||||
|
||||
include("${PSPSDK_ROOT}/psp/share/pspdev.cmake")
|
||||
set(CMAKE_C_COMPILER ${PSPSDK_BIN_ROOT}/psp-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${PSPSDK_BIN_ROOT}/psp-g++)
|
||||
|
||||
if(NOT DEFINED PSP)
|
||||
message(FATAL_ERROR "PSP environment variable is not set correctly.")
|
||||
endif()
|
||||
|
||||
add_library(pspsdk INTERFACE IMPORTED)
|
||||
set_target_properties(pspsdk PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${PSPSDK_INCLUDE_DIR}"
|
||||
INTERFACE_LINK_DIRECTORIES "${PSPSDK_LIB_DIR}"
|
||||
)
|
||||
target_include_directories(pspsdk
|
||||
INTERFACE
|
||||
${PSPDEV}/psp/include
|
||||
${PSPDEV}/psp/sdk/include
|
||||
)
|
||||
target_link_directories(pspsdk
|
||||
INTERFACE
|
||||
${PSPDEV}/lib
|
||||
${PSPDEV}/psp/lib
|
||||
${PSPDEV}/psp/sdk/lib
|
||||
)
|
||||
target_link_libraries(pspsdk INTERFACE
|
||||
pspdebug
|
||||
pspdisplay
|
||||
pspge
|
||||
pspctrl
|
||||
pspgu
|
||||
pspaudio
|
||||
pspaudiolib
|
||||
psputility
|
||||
pspvfpu
|
||||
pspvram
|
||||
psphprm
|
||||
)
|
||||
endif()
|
||||
endif()
|
Submodule lib/AudioFile deleted from 004065d01e
@@ -1,42 +0,0 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# GLM
|
||||
FetchContent_Declare(
|
||||
glm
|
||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||
GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e
|
||||
)
|
||||
FetchContent_MakeAvailable(glm)
|
||||
|
||||
# JSON
|
||||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
|
||||
FetchContent_MakeAvailable(json)
|
||||
|
||||
# GLAD
|
||||
add_subdirectory(glad)
|
||||
|
||||
# GLFW
|
||||
FetchContent_Declare(glfw URL https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip)
|
||||
FetchContent_MakeAvailable(glfw)
|
||||
|
||||
# LibArchive
|
||||
FetchContent_Declare(libarchive URL https://github.com/libarchive/libarchive/releases/download/v3.7.6/libarchive-3.7.6.tar.xz)
|
||||
FetchContent_MakeAvailable(libarchive)
|
||||
|
||||
# FreeType
|
||||
FetchContent_Declare(freetype URL https://psychz.dl.sourceforge.net/project/freetype/freetype2/2.13.3/freetype-2.13.3.tar.xz?viasf=1)
|
||||
FetchContent_MakeAvailable(freetype)
|
||||
|
||||
# if(DAWN_TARGET_OPENAL)
|
||||
# set(LIBTYPE "STATIC")
|
||||
# add_subdirectory(openal-soft)
|
||||
|
||||
# set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
|
||||
# set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)
|
||||
# add_subdirectory(AudioFile)
|
||||
# endif()
|
@@ -1,12 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
project(glad)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
src/glad.c
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
@@ -1,290 +0,0 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
File diff suppressed because it is too large
Load Diff
2522
lib/glad/src/glad.c
2522
lib/glad/src/glad.c
File diff suppressed because it is too large
Load Diff
Submodule lib/openal-soft deleted from d3875f333f
@@ -1,23 +1,52 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Build Project
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Add in base library
|
||||
add_subdirectory(dawn)
|
||||
|
||||
# Compile entry targets
|
||||
if(DAWN_TARGET STREQUAL "linux-x64-glfw")
|
||||
add_subdirectory(dawnlinux)
|
||||
add_subdirectory(dawnglfw)
|
||||
add_subdirectory(dawnopengl)
|
||||
add_subdirectory(dawnrpg)
|
||||
else()
|
||||
message(FATAL_ERROR "You need to define an entry target")
|
||||
endif()
|
||||
|
||||
# Compress the game assets.
|
||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
find_package(glm REQUIRED)
|
||||
find_package(libzip REQUIRED)
|
||||
|
||||
# Libs
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
m
|
||||
glm
|
||||
zip
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
main.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(console)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(rpg)
|
||||
add_subdirectory(time)
|
||||
|
||||
# Platform-specific settings
|
||||
if(DAWN_TARGET_SYSTEM STREQUAL "linux")
|
||||
target_compile_definitions(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DAWN_SDL2=1
|
||||
DAWN_SDL2_GAMEPAD=1
|
||||
)
|
||||
elseif(DAWN_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DAWN_SDL2=1
|
||||
DAWN_SDL2_GAMEPAD=1
|
||||
)
|
||||
endif()
|
85
src/assert/Assert.cpp
Normal file
85
src/assert/Assert.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "Assert.hpp"
|
||||
|
||||
#ifndef ASSERTIONS_FAKED
|
||||
void assertTrueImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const bool_t x,
|
||||
const char_t *message
|
||||
) {
|
||||
if(x != true) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assertion Failed in %s:%i\n\n%s\n",
|
||||
file,
|
||||
line,
|
||||
message
|
||||
);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void assertFalseImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
bool_t x,
|
||||
const char_t *message
|
||||
) {
|
||||
assertTrueImpl(file, line, !x, message);
|
||||
}
|
||||
|
||||
void assertUnreachableImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const char_t *message
|
||||
) {
|
||||
assertTrueImpl(file, line, false, message);
|
||||
}
|
||||
|
||||
void assertNotNullImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char_t *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer != NULL && pointer != nullptr,
|
||||
message
|
||||
);
|
||||
|
||||
// Ensure we can touch it
|
||||
volatile char_t temp;
|
||||
temp = *((char_t*)pointer);
|
||||
}
|
||||
|
||||
void assertNullImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char_t *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer == NULL,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
void assertDeprecatedImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const char_t *message
|
||||
) {
|
||||
assertUnreachableImpl(file, line, message);
|
||||
}
|
||||
#endif
|
143
src/assert/Assert.hpp
Normal file
143
src/assert/Assert.hpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
#ifndef ASSERTIONS_FAKED
|
||||
/**
|
||||
* Assert a given value to be true.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param x Value to assert as true.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertTrueImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const bool_t x,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a given statement to be false.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param x Value to assert as false.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertFalseImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const bool_t x,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts that a given line of code is unreachable. Essentially a forced
|
||||
* assertion failure, good for "edge cases"
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertUnreachableImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Assert a given pointer to not point to a null pointer.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param pointer Pointer to assert is not a null pointer.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertNotNullImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a given pointer to be a nullptr.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param pointer Pointer to assert is nullptr.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertNullImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts a function as being deprecated.
|
||||
*
|
||||
* @param file File that the assertion is being made from.
|
||||
* @param line Line that the assertion is being made from.
|
||||
* @param message Message to throw against assertion failure.
|
||||
*/
|
||||
void assertDeprecatedImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
void assertMemoryRangeMatchesImpl(
|
||||
const char_t *file,
|
||||
const int32_t line,
|
||||
const void *start,
|
||||
const void *end,
|
||||
const size_t size,
|
||||
const char_t *message
|
||||
);
|
||||
|
||||
#define assertTrue(x, message) \
|
||||
assertTrueImpl(__FILE__, __LINE__, x, message)
|
||||
|
||||
#define assertFalse(x, message) \
|
||||
assertFalseImpl(__FILE__, __LINE__, x, message)
|
||||
|
||||
#define assertUnreachable(message) \
|
||||
assertUnreachableImpl(__FILE__, __LINE__, message)
|
||||
|
||||
#define assertNotNull(pointer, message) \
|
||||
assertNotNullImpl(__FILE__, __LINE__, pointer, message)
|
||||
|
||||
#define assertNull(pointer, message) \
|
||||
assertNullImpl(__FILE__, __LINE__, pointer, message)
|
||||
|
||||
#define assertDeprecated(message) \
|
||||
assertDeprecatedImpl(__FILE__, __LINE__, message)
|
||||
|
||||
#define assertStrLenMax(str, len, message) \
|
||||
assertTrue(strlen(str) < len, message)
|
||||
|
||||
#define assertStrLenMin(str, len, message) \
|
||||
assertTrue(strlen(str) >= len, message)
|
||||
|
||||
#else
|
||||
// If assertions are faked, we define the macros to do nothing.
|
||||
#define assertTrue(x, message) ((void)0)
|
||||
#define assertFalse(x, message) ((void)0)
|
||||
#define assertUnreachable(message) ((void)0)
|
||||
#define assertNotNull(pointer, message) ((void)0)
|
||||
#define assertNull(pointer, message) ((void)0)
|
||||
#define assertDeprecated(message) ((void)0)
|
||||
#define assertStrLenMax(str, len, message) ((void)0)
|
||||
#define assertStrLenMin(str, len, message) ((void)0)
|
||||
|
||||
#endif
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
@@ -6,5 +6,5 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Environment.cpp
|
||||
Assert.cpp
|
||||
)
|
16
src/asset/Asset.cpp
Normal file
16
src/asset/Asset.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Asset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Asset::Asset(const std::string &filename) :
|
||||
filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
Asset::~Asset() {
|
||||
}
|
19
src/asset/Asset.hpp
Normal file
19
src/asset/Asset.hpp
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 "dawn.hpp"
|
||||
#include <zip.h>
|
||||
|
||||
namespace Dawn {
|
||||
struct Asset {
|
||||
private:
|
||||
std::string filename;
|
||||
|
||||
public:
|
||||
Asset(const std::string &filename);
|
||||
~Asset();
|
||||
};
|
||||
}
|
21
src/asset/AssetManager.cpp
Normal file
21
src/asset/AssetManager.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AssetManager::AssetManager() :
|
||||
zip(nullptr)
|
||||
{
|
||||
// Find the zip file.
|
||||
}
|
||||
|
||||
AssetManager::~AssetManager() {
|
||||
if(zip) {
|
||||
zip_close(zip);
|
||||
zip = nullptr;
|
||||
}
|
||||
}
|
25
src/asset/AssetManager.hpp
Normal file
25
src/asset/AssetManager.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Asset.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct AssetManager {
|
||||
private:
|
||||
zip_t *zip;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor for the Asset manager.
|
||||
*/
|
||||
AssetManager();
|
||||
|
||||
/**
|
||||
* Destructor for the Asset manager.
|
||||
*/
|
||||
~AssetManager();
|
||||
};
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
@@ -6,6 +6,6 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
CubeMesh.cpp
|
||||
QuadMesh.cpp
|
||||
Asset.cpp
|
||||
AssetManager.cpp
|
||||
)
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
@@ -6,5 +6,5 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
RenderHost.cpp
|
||||
Console.cpp
|
||||
)
|
167
src/console/Console.cpp
Normal file
167
src/console/Console.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Console.hpp"
|
||||
#include "assert/Assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Console::Console(void) :
|
||||
commands(),
|
||||
variables(),
|
||||
buffer()
|
||||
{
|
||||
this->registerCommand("echo", [](auto console, auto args) {
|
||||
if(args.size() == 0) {
|
||||
console.print("Usage: echo <message>");
|
||||
return;
|
||||
}
|
||||
console.print("%s", args[0].c_str());
|
||||
});
|
||||
}
|
||||
|
||||
void Console::registerCommand(
|
||||
const std::string &cmd,
|
||||
const std::function<void(Console&, const std::vector<std::string>&)> &cb
|
||||
) {
|
||||
assertTrue(cmd.length() > 0, "cmd length must be > 0");
|
||||
assertTrue(cb != nullptr, "callback must not be null");
|
||||
|
||||
this->commands[cmd] = cb;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Console::registerVariable(
|
||||
const std::string &var,
|
||||
const std::function<T()> &getter,
|
||||
const std::function<void(const T &)> &setter
|
||||
) {
|
||||
assertTrue(var.length() > 0, "var length must be > 0");
|
||||
assertTrue(getter != nullptr, "getter must not be null");
|
||||
assertTrue(setter != nullptr, "setter must not be null");
|
||||
|
||||
this->variables[var] = std::make_pair(getter, setter);
|
||||
}
|
||||
|
||||
void Console::update() {
|
||||
enum class ParseState { FIND_CMD, FIND_ARG, COMMAND, ARG, ARG_QUOTED };
|
||||
|
||||
for (const auto &cmd : buffer) {
|
||||
std::string cmdName;
|
||||
std::vector<std::string> args;
|
||||
ParseState state = ParseState::FIND_CMD;
|
||||
|
||||
std::string buff;
|
||||
for(size_t i = 0; i < cmd.length(); i++) {
|
||||
char_t c = cmd[i];
|
||||
|
||||
switch(state) {
|
||||
case ParseState::FIND_CMD:
|
||||
if(isspace(c)) continue;
|
||||
state = ParseState::COMMAND;
|
||||
buff += c;
|
||||
break;
|
||||
|
||||
case ParseState::FIND_ARG:
|
||||
if(isspace(c)) continue;
|
||||
if(c == '\"') {
|
||||
state = ParseState::ARG_QUOTED;
|
||||
break;
|
||||
}
|
||||
state = ParseState::ARG;
|
||||
buff += c;
|
||||
break;
|
||||
|
||||
case ParseState::COMMAND:
|
||||
if(isspace(c)) {
|
||||
cmdName = buff;
|
||||
buff.clear();
|
||||
state = ParseState::FIND_ARG;
|
||||
break;
|
||||
}
|
||||
buff += c;
|
||||
break;
|
||||
|
||||
case ParseState::ARG:
|
||||
if(isspace(c)) {
|
||||
args.push_back(buff);
|
||||
buff.clear();
|
||||
state = ParseState::FIND_ARG;
|
||||
break;
|
||||
}
|
||||
buff += c;
|
||||
break;
|
||||
|
||||
case ParseState::ARG_QUOTED:
|
||||
if(c == '\"') {
|
||||
args.push_back(buff);
|
||||
buff.clear();
|
||||
state = ParseState::FIND_ARG;
|
||||
break;
|
||||
}
|
||||
buff += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(buff.length() > 0) {
|
||||
if(state == ParseState::COMMAND) {
|
||||
cmdName = buff;
|
||||
} else {
|
||||
args.push_back(buff);
|
||||
}
|
||||
}
|
||||
|
||||
// Find command
|
||||
auto itCmd = commands.find(cmdName);
|
||||
if(itCmd == commands.end()) {
|
||||
// Find variable
|
||||
auto itVar = variables.find(cmdName);
|
||||
if(itVar == variables.end()) {
|
||||
std::cout << "Console: Unknown command or variable '" << cmdName << "'" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Variable get/set
|
||||
printf("Console: Variable '%s' ", cmdName.c_str());
|
||||
continue;
|
||||
}
|
||||
itCmd->second(*this, args);
|
||||
}
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
void Console::exec(const std::string &str) {
|
||||
// Split strings by command seperator
|
||||
std::istringstream iss(str);
|
||||
std::string token;
|
||||
while(std::getline(iss, token, COMMAND_SEPARATOR)) {
|
||||
// Seperate by newlines too
|
||||
std::istringstream lineIss(token);
|
||||
std::string lineToken;
|
||||
while(std::getline(lineIss, lineToken)) {
|
||||
if(lineToken.length() == 0) continue;
|
||||
buffer.push_back(lineToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Console::print(const char_t *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
vprintf(fmt, args);
|
||||
printf("\n");
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Console::print(std::string str) {
|
||||
this->print("%s", str.c_str());
|
||||
}
|
||||
|
||||
Console::~Console(void) {
|
||||
|
||||
}
|
88
src/console/Console.hpp
Normal file
88
src/console/Console.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Console {
|
||||
private:
|
||||
std::map<
|
||||
std::string,
|
||||
std::function<void(Console&, const std::vector<std::string>&)>
|
||||
> commands;
|
||||
|
||||
std::map<std::string, std::pair<
|
||||
std::function<std::any()>, std::function<void(std::any&)>
|
||||
>> variables;
|
||||
|
||||
std::vector<std::string> buffer;
|
||||
|
||||
public:
|
||||
static constexpr char_t COMMAND_SEPARATOR = ';';
|
||||
|
||||
/**
|
||||
* Constructs the console.
|
||||
*/
|
||||
Console(void);
|
||||
|
||||
/**
|
||||
* Registers a command with the console.
|
||||
*
|
||||
* @param cmd The command string.
|
||||
* @param cb The callback function for the command.
|
||||
*/
|
||||
void registerCommand(
|
||||
const std::string &cmd,
|
||||
const std::function<void(Console&, const std::vector<std::string>&)> &cb
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers a variable with the console.
|
||||
*
|
||||
* @param var The variable name.
|
||||
* @param getter The getter function for the variable.
|
||||
* @param setter The setter function for the variable.
|
||||
*/
|
||||
template<typename T>
|
||||
void registerVariable(
|
||||
const std::string &var,
|
||||
const std::function<T()> &getter,
|
||||
const std::function<void(const T &)> &setter
|
||||
);
|
||||
|
||||
/**
|
||||
* Updates the console state, this will exec the command buffer.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Executes a command string.
|
||||
*
|
||||
* @param str The command string to execute.
|
||||
*/
|
||||
void exec(const std::string &str);
|
||||
|
||||
/**
|
||||
* Prints a formatted string to the console output.
|
||||
*
|
||||
* @param fmt The format string.
|
||||
* @param ... The format arguments.
|
||||
*/
|
||||
void print(const char_t *fmt, ...);
|
||||
|
||||
/**
|
||||
* Prints a string to the console output.
|
||||
*
|
||||
* @param str The string to print.
|
||||
*/
|
||||
void print(std::string str);
|
||||
|
||||
/**
|
||||
* Destructs the console.
|
||||
*/
|
||||
~Console(void);
|
||||
};
|
||||
}
|
64
src/dawn.hpp
Normal file
64
src/dawn.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <float.h>
|
||||
|
||||
// #include <glm/gtc/matrix_transform.hpp>
|
||||
// #include <glm/gtc/type_ptr.hpp>
|
||||
// #include <glm/gtc/constants.hpp>
|
||||
// #include <glm/gtx/string_cast.hpp>
|
||||
// #include <glm/gtx/rotate_vector.hpp>
|
||||
// #include <glm/gtx/vector_angle.hpp>
|
||||
// #include <glm/gtx/norm.hpp>
|
||||
// #include <glm/gtx/compatibility.hpp>
|
||||
// #include <glm/gtx/color_space.hpp>
|
||||
|
||||
#if PSP
|
||||
#include <pspkernel.h>
|
||||
#include <pspdebug.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspctrl.h>
|
||||
#include <psphprm.h>
|
||||
#endif
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef int int_t;
|
||||
typedef float float_t;
|
||||
typedef char char_t;
|
||||
}
|
||||
|
||||
#if DAWN_SDL2
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <any>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <glm/glm.hpp>
|
@@ -1,40 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
glm::glm
|
||||
archive_static
|
||||
freetype
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(audio)
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(environment)
|
||||
add_subdirectory(game)
|
||||
# add_subdirectory(games)
|
||||
# add_subdirectory(input)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(prefab)
|
||||
# add_subdirectory(physics)
|
||||
add_subdirectory(poker)
|
||||
add_subdirectory(save)
|
||||
add_subdirectory(scene)
|
||||
# add_subdirectory(state)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(ui)
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
assert.cpp
|
||||
)
|
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert.hpp"
|
||||
|
||||
void assertTrueImplement(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *func,
|
||||
const bool_t result,
|
||||
const char *message,
|
||||
...
|
||||
) {
|
||||
if(result) return;
|
||||
|
||||
// Print file info.
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assert failed in %s:%i :: %s\n",
|
||||
file,
|
||||
line,
|
||||
func
|
||||
);
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, message);
|
||||
vfprintf(stderr, message, argptr);
|
||||
va_end(argptr);
|
||||
fprintf(stderr, "\n");
|
||||
throw std::runtime_error("Assert failed.");
|
||||
}
|
@@ -1,126 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
/**
|
||||
* Asserts that a given statement must evaluate to true or the assertion fails
|
||||
* and the game will close semi-gracefully.
|
||||
*
|
||||
* @param file String filename of the file that has the assertion.
|
||||
* @param line Integer line number within the file that the assertion is on.
|
||||
* @param func Called function that has the assertion.
|
||||
* @param result The statement that must equate to true.
|
||||
* @param message Message (sprintf format) to send to the stdout.
|
||||
* @param ... Varargs of the sprintf arguments.
|
||||
*/
|
||||
void assertTrueImplement(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *func,
|
||||
const bool_t result,
|
||||
const char *message,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts that a statement must be true in order for the assertion to not cause
|
||||
* an error. Basically this is a throw statement in disguise.
|
||||
*
|
||||
* @param statement Statement of the assertion.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertTrue(...) assertTrueImplement( \
|
||||
__FILE__, __LINE__, __func__, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a statement must be false in order for the assertion to not
|
||||
* cause an error.
|
||||
*
|
||||
* @param statement Statement of the assertion.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFalse(x, ...) assertTrue(!(x), __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a specified piece of code should be entirely unreachable.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertUnreachable(...) assertTrue(false, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given pointer is not null.
|
||||
* @param x Pointer to check.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertNotNull(x, ...) assertTrue(x != nullptr, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given pointer is null.
|
||||
* @param x Pointer to check.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertNull(x, ...) assertTrue(x == nullptr, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given map has a specific key.
|
||||
* @param map Map to check.
|
||||
* @param key Key to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertMapHasKey(map, key, ...) assertTrue( \
|
||||
map.find(key) != map.end(), __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a given map does not have a specific key.
|
||||
* @param map Map to check.
|
||||
* @param key Key to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertMapNotHasKey(map, key, ...) assertTrue( \
|
||||
map.find(key) == map.end(), __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a given value has a specific flag turned off.
|
||||
*
|
||||
* @param value Value to check.
|
||||
* @param flag Flag to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFlagOff(value, flag, ...) assertTrue( \
|
||||
(value & flag) == 0, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a given value has a specific flag turned on.
|
||||
*
|
||||
* @param value Value to check.
|
||||
* @param flag Flag to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFlagOn(value, flag, ...) assertTrue( \
|
||||
(value & flag) == flag, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that the current code is deprecated and should not be used anymore.
|
||||
* @deprecated
|
||||
*/
|
||||
#define assertDeprecated(...) assertUnreachable(__VA_ARGS__)
|
@@ -1,200 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "AssetDataLoader.hpp"
|
||||
#include "util/Math.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
ssize_t assetDataLoaderArchiveRead(
|
||||
struct archive *archive,
|
||||
void *d,
|
||||
const void **buffer
|
||||
) {
|
||||
assertNotNull(archive, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
assertNotNull(buffer, "Buffer is NULL!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
|
||||
*buffer = loader->buffer;
|
||||
size_t read = fread(
|
||||
loader->buffer, 1, ASSET_LOADER_BUFFER_SIZE, loader->assetArchiveFile
|
||||
);
|
||||
if(ferror(loader->assetArchiveFile)) return ARCHIVE_FATAL;
|
||||
return read;
|
||||
}
|
||||
|
||||
int64_t assetDataLoaderArchiveSeek(
|
||||
struct archive *archive,
|
||||
void *d,
|
||||
int64_t offset,
|
||||
int32_t whence
|
||||
) {
|
||||
assertNotNull(archive, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
assertTrue(offset > 0, "Offset must be greater than 0!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
int32_t ret = fseek(loader->assetArchiveFile, offset, whence);
|
||||
assertTrue(ret == 0, "Failed to seek!");
|
||||
return ftell(loader->assetArchiveFile);
|
||||
}
|
||||
|
||||
int32_t assetDataLoaderArchiveOpen(struct archive *a, void *d) {
|
||||
assertNotNull(a, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
|
||||
int32_t ret = fseek(loader->assetArchiveFile, 0, SEEK_SET);
|
||||
assertTrue(ret == 0, "Failed to seek to start of file!");
|
||||
return ARCHIVE_OK;
|
||||
}
|
||||
|
||||
int32_t assetDataLoaderArchiveClose(struct archive *a, void *d) {
|
||||
assertNotNull(a, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
return assetDataLoaderArchiveOpen(a, d);
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
|
||||
assertTrue(
|
||||
fileName.size() > 0,
|
||||
"IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0"
|
||||
);
|
||||
}
|
||||
|
||||
void AssetDataLoader::open() {
|
||||
assertNull(this->assetArchiveFile, "AssetDataLoader::open: File is already open");
|
||||
assertNull(this->assetArchive, "AssetDataLoader::open: Archive is already open");
|
||||
assertNull(this->assetArchiveEntry, "AssetDataLoader::open: Entry is already open");
|
||||
|
||||
this->assetArchiveFile = this->openAssetArchiveFile();
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::open: Failed to open archive file!");
|
||||
|
||||
// Open archive reader
|
||||
assetArchive = archive_read_new();
|
||||
assertNotNull(assetArchive, "AssetDataLoader::open: Failed to create archive reader");
|
||||
|
||||
// Set up the reader
|
||||
archive_read_support_format_tar(assetArchive);
|
||||
|
||||
// Open reader
|
||||
archive_read_set_open_callback(assetArchive, &assetDataLoaderArchiveOpen);
|
||||
archive_read_set_read_callback(assetArchive, &assetDataLoaderArchiveRead);
|
||||
archive_read_set_seek_callback(assetArchive, &assetDataLoaderArchiveSeek);
|
||||
archive_read_set_close_callback(assetArchive, &assetDataLoaderArchiveClose);
|
||||
archive_read_set_callback_data(assetArchive, this);
|
||||
|
||||
int32_t ret = archive_read_open1(assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to open archive!");
|
||||
position = 0;
|
||||
|
||||
// Iterate over each file to find the one for this asset loader.
|
||||
while(archive_read_next_header(assetArchive, &assetArchiveEntry) == ARCHIVE_OK) {
|
||||
const char_t *headerFile = (char_t*)archive_entry_pathname(assetArchiveEntry);
|
||||
if(std::string(headerFile) == this->fileName) return;
|
||||
int32_t ret = archive_read_data_skip(assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to skip data!");
|
||||
}
|
||||
|
||||
assertUnreachable("AssetDataLoader::open: Failed to find file!");
|
||||
}
|
||||
|
||||
int32_t AssetDataLoader::close() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::close: File is NULL");
|
||||
assertNotNull(this->assetArchive, "AssetDataLoader::close: Archive is NULL!");
|
||||
assertNotNull(this->assetArchiveEntry, "AssetDataLoader::close: Entry is NULL!");
|
||||
|
||||
// Close the archive
|
||||
int32_t ret = archive_read_free(this->assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::close: Failed to close archive!");
|
||||
|
||||
this->assetArchive = nullptr;
|
||||
this->assetArchiveEntry = nullptr;
|
||||
|
||||
// Close the file
|
||||
int32_t res = fclose(this->assetArchiveFile);
|
||||
this->assetArchiveFile = nullptr;
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
|
||||
assertNotNull(buffer, "Buffer is NULL!");
|
||||
assertTrue(size > 0, "Size must be greater than 0!");
|
||||
assertNotNull(this->assetArchive, "assetRead: Archive is NULL!");
|
||||
assertNotNull(this->assetArchiveEntry, "assetRead: Entry is NULL!");
|
||||
|
||||
ssize_t read = archive_read_data(this->assetArchive, buffer, size);
|
||||
this->position += read;
|
||||
|
||||
if(read == ARCHIVE_FATAL) {
|
||||
assertUnreachable(archive_error_string(this->assetArchive));
|
||||
}
|
||||
|
||||
assertTrue(read != ARCHIVE_RETRY, "assetRead: Failed to read data (RETRY)!");
|
||||
assertTrue(read != ARCHIVE_WARN, "assetRead: Failed to read data (WARN)!");
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::readUntil(
|
||||
uint8_t *buffer,
|
||||
const size_t maxSize,
|
||||
const char_t delimiter
|
||||
) {
|
||||
size_t totalRead = this->read(buffer, maxSize);
|
||||
size_t i = 0;
|
||||
while(i < totalRead) {
|
||||
if(buffer[i] == delimiter) break;
|
||||
i++;
|
||||
}
|
||||
buffer[i++] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getSize() {
|
||||
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
|
||||
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
|
||||
return archive_entry_size(assetArchiveEntry);
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::skip(size_t n) {
|
||||
assertTrue(n >= 0, "AssetDataLoader::skip: Byte count must be greater than 0.");
|
||||
|
||||
uint8_t dumpBuffer[ASSET_LOADER_BUFFER_SIZE];
|
||||
size_t skipped = 0;
|
||||
size_t n2, n3;
|
||||
while(n != 0) {
|
||||
n2 = Math::min<size_t>(n, ASSET_LOADER_BUFFER_SIZE);
|
||||
n3 = this->read(dumpBuffer, n2);
|
||||
assertTrue(n3 == n2, "AssetDataLoader::skip: Failed to skip bytes!");
|
||||
n -= n3;
|
||||
}
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::setPosition(const size_t position) {
|
||||
assertTrue(position >= 0, "Position must be greater than or equal to 0");
|
||||
this->rewind();
|
||||
return this->skip(position);
|
||||
}
|
||||
|
||||
void AssetDataLoader::rewind() {
|
||||
// TODO: See if I can optimize this
|
||||
this->close();
|
||||
this->open();
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getPosition() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
|
||||
return this->position;
|
||||
}
|
||||
|
||||
AssetDataLoader::~AssetDataLoader() {
|
||||
if(this->assetArchiveFile != nullptr) this->close();
|
||||
}
|
@@ -1,166 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
}
|
||||
|
||||
#define ASSET_LOADER_BUFFER_SIZE 32768
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to read bytes from the archive
|
||||
* file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the read.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @param buffer Pointer to where the buffer pointer should be stored.
|
||||
* @return Count of bytes read.
|
||||
*/
|
||||
ssize_t assetDataLoaderArchiveRead(
|
||||
struct archive *archive,
|
||||
void *data,
|
||||
const void **buffer
|
||||
);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to seek the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the seek.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @param offset Offset to seek to.
|
||||
* @param whence Whence to seek from.
|
||||
* @return The new offset.
|
||||
*/
|
||||
int64_t assetDataLoaderArchiveSeek(
|
||||
struct archive *archive,
|
||||
void *data,
|
||||
int64_t offset,
|
||||
int32_t whence
|
||||
);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to open the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the open.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @return 0 if success, otherwise for failure.
|
||||
*/
|
||||
int32_t assetDataLoaderArchiveOpen(struct archive *a, void *data);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to close the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the close.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @return 0 if success, otherwise for failure.
|
||||
*/
|
||||
int32_t assetDataLoaderArchiveClose(struct archive *a, void *data);
|
||||
|
||||
namespace Dawn {
|
||||
class AssetDataLoader {
|
||||
protected:
|
||||
struct archive *assetArchive = nullptr;
|
||||
struct archive_entry *assetArchiveEntry = nullptr;
|
||||
size_t position;
|
||||
std::string fileName;
|
||||
|
||||
public:
|
||||
uint8_t buffer[ASSET_LOADER_BUFFER_SIZE];
|
||||
FILE *assetArchiveFile = nullptr;
|
||||
|
||||
/**
|
||||
* Unimplemented method intended to be implemented by the platform that
|
||||
* will be used to request a File pointer to the asset.
|
||||
*
|
||||
* @return Pointer to the opened asset archive.
|
||||
*/
|
||||
FILE * openAssetArchiveFile();
|
||||
|
||||
/**
|
||||
* Create a new asset loader. Asset Loaders can be used to load data from
|
||||
* a file in a myriad of ways.
|
||||
*
|
||||
* @param fileName File name of the asset that is to be loaded.
|
||||
*/
|
||||
AssetDataLoader(std::string filename);
|
||||
|
||||
/**
|
||||
* Platform-centric method to open a file buffer to an asset.
|
||||
*/
|
||||
void open();
|
||||
|
||||
/**
|
||||
* Closes the previously ppened asset.
|
||||
* @return 0 if successful, otherwise false.
|
||||
*/
|
||||
int32_t close();
|
||||
|
||||
/**
|
||||
* Read bytes from buffer.
|
||||
* @param buffer Pointer to a ubyte array to buffer data into.
|
||||
* @param size Length of the data buffer (How many bytes to read).
|
||||
* @return The count of bytes read.
|
||||
*/
|
||||
size_t read(uint8_t *buffer, size_t size);
|
||||
|
||||
/**
|
||||
* Reads bytes from the buffer until a given delimiter is found. Returned
|
||||
* position will be the index of the delimiter within the buffer.
|
||||
*
|
||||
* @param buffer Buffer to read into.
|
||||
* @param maxSize Maximum size of the buffer.
|
||||
* @param delimiter Delimiter to read until.
|
||||
* @return The count of bytes read (including null terminator)
|
||||
*/
|
||||
size_t readUntil(
|
||||
uint8_t *buffer,
|
||||
const size_t maxSize,
|
||||
const char_t delimiter
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the size of the asset.
|
||||
* @return The size of the asset in bytes.
|
||||
*/
|
||||
size_t getSize();
|
||||
|
||||
/**
|
||||
* Skips the read head forward to a given position.
|
||||
*
|
||||
* @param n Count of bytes to progress the read head by.
|
||||
* @return Count of bytes progressed.
|
||||
*/
|
||||
size_t skip(size_t n);
|
||||
|
||||
/**
|
||||
* Rewind the read head to the beginning of the file.
|
||||
*/
|
||||
void rewind();
|
||||
|
||||
/**
|
||||
* Sets the absolute position of the read head within the buffer of the
|
||||
* file.
|
||||
*
|
||||
* @param absolutePosition Absolute position to set the read head to.
|
||||
*/
|
||||
size_t setPosition(const size_t absolutePosition);
|
||||
|
||||
/**
|
||||
* Returns the current position of the read head.
|
||||
*
|
||||
* @return The current read head position.
|
||||
*/
|
||||
size_t getPosition();
|
||||
|
||||
/**
|
||||
* Cleanup the asset loader.
|
||||
*/
|
||||
virtual ~AssetDataLoader();
|
||||
};
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AssetLoader::AssetLoader(const std::string name) : name(name) {
|
||||
assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty");
|
||||
}
|
||||
|
||||
AssetLoader::~AssetLoader() {
|
||||
this->loaded = false;
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetLoader {
|
||||
public:
|
||||
const std::string name;
|
||||
bool_t loaded = false;
|
||||
|
||||
/**
|
||||
* Create an abstract Asset object.
|
||||
*
|
||||
* @param name Name of the asset.
|
||||
*/
|
||||
AssetLoader(const std::string name);
|
||||
|
||||
/**
|
||||
* Virtual function that will be called by the asset manager on a
|
||||
* synchronous basis. This will only trigger if the blocks are false and
|
||||
* the loaded is also false.
|
||||
*/
|
||||
virtual void updateSync() = 0;
|
||||
|
||||
/**
|
||||
* Virtual function called by the asset manager asynchronously every tick.
|
||||
* This will only trigger if blocks are false and the loaded state is also
|
||||
* false.
|
||||
*/
|
||||
virtual void updateAsync() = 0;
|
||||
|
||||
/**
|
||||
* Dispose the asset item.
|
||||
*/
|
||||
virtual ~AssetLoader();
|
||||
};
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetManager.hpp"
|
||||
#include "loaders/TextureLoader.hpp"
|
||||
#include "loaders/TrueTypeLoader.hpp"
|
||||
#include "loaders/JSONLoader.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void AssetManager::init() {
|
||||
|
||||
}
|
||||
|
||||
void AssetManager::update() {
|
||||
auto itPending = pendingAssetLoaders.begin();
|
||||
while(itPending != pendingAssetLoaders.end()) {
|
||||
auto loader = *itPending;
|
||||
loader->updateSync();
|
||||
loader->updateAsync();
|
||||
if(loader->loaded) {
|
||||
finishedAssetLoaders.push_back(loader);
|
||||
itPending = pendingAssetLoaders.erase(itPending);
|
||||
} else {
|
||||
itPending++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetManager::removeExisting(const std::string filename) {
|
||||
auto existing = std::find_if(
|
||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
if(existing != pendingAssetLoaders.end()) {
|
||||
pendingAssetLoaders.erase(existing);
|
||||
}
|
||||
|
||||
existing = std::find_if(
|
||||
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
if(existing != finishedAssetLoaders.end()) {
|
||||
finishedAssetLoaders.erase(existing);
|
||||
}
|
||||
}
|
||||
|
||||
bool_t AssetManager::isEverythingLoaded() {
|
||||
return pendingAssetLoaders.size() == 0;
|
||||
}
|
||||
|
||||
bool_t AssetManager::isLoaded(const std::string filename) {
|
||||
auto existing = this->getExisting<AssetLoader>(filename);
|
||||
if(existing) return existing->loaded;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::shared_ptr<TrueTypeTexture> AssetManager::get<TrueTypeTexture>(
|
||||
const std::string filename,
|
||||
const uint32_t fontSize
|
||||
) {
|
||||
auto existing = this->getExisting<TrueTypeLoader>(filename);
|
||||
if(existing) {
|
||||
// Check pointer hasn't gone stale, if it has remove it and create new.
|
||||
auto texture = existing->getTexture(fontSize);
|
||||
if(texture) return texture;
|
||||
this->removeExisting(filename);
|
||||
}
|
||||
|
||||
std::shared_ptr<TrueTypeLoader> loader = std::make_shared<TrueTypeLoader>(
|
||||
filename
|
||||
);
|
||||
pendingAssetLoaders.push_back(std::static_pointer_cast<AssetLoader>(loader));
|
||||
return loader->getTexture(fontSize);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::shared_ptr<json> AssetManager::get<json>(
|
||||
const std::string filename
|
||||
) {
|
||||
auto existing = this->getExisting<JSONLoader>(filename);
|
||||
if(existing) return existing->data;
|
||||
|
||||
std::shared_ptr<JSONLoader> loader = std::make_shared<JSONLoader>(
|
||||
filename
|
||||
);
|
||||
pendingAssetLoaders.push_back(std::static_pointer_cast<AssetLoader>(loader));
|
||||
return loader->data;
|
||||
}
|
||||
|
||||
|
||||
AssetManager::~AssetManager() {
|
||||
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "asset/AssetLoader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetManager final {
|
||||
private:
|
||||
std::vector<std::shared_ptr<AssetLoader>> pendingAssetLoaders;
|
||||
std::vector<std::shared_ptr<AssetLoader>> finishedAssetLoaders;
|
||||
|
||||
/**
|
||||
* Returns an existing asset loader if it exists.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @return The asset loader if it exists, otherwise nullptr.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> getExisting(const std::string filename) {
|
||||
auto existing = std::find_if(
|
||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
|
||||
if(existing == pendingAssetLoaders.end()) {
|
||||
existing = std::find_if(
|
||||
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
|
||||
if(existing == finishedAssetLoaders.end()) return nullptr;
|
||||
}
|
||||
|
||||
return std::static_pointer_cast<T>(*existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an existing asset loader if it exists.
|
||||
*
|
||||
* @param filename The filename of the asset to remove.
|
||||
*/
|
||||
void removeExisting(const std::string filename);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initializes this asset manager so it can begin accepting assets.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Updates the asset manager.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns whether the asset manager has loaded all of the currently
|
||||
* managed assets.
|
||||
*
|
||||
* @return True if all assets have been loaded.
|
||||
*/
|
||||
bool_t isEverythingLoaded();
|
||||
|
||||
/**
|
||||
* Returns whether the asset manager has loaded the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to check.
|
||||
* @return True if the asset has been loaded.
|
||||
*/
|
||||
bool_t isLoaded(const std::string filename);
|
||||
|
||||
/**
|
||||
* Returns the asset loader for the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @param fontSize The font size to get the truetype asset of.
|
||||
* @return The asset loader for the given asset.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> get(const std::string filename);
|
||||
|
||||
/**
|
||||
* Returns the asset loader for the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @param fontSize The font size to get the truetype asset of.
|
||||
* @return The asset loader for the given asset.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> get(
|
||||
const std::string filename,
|
||||
const uint32_t fontSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Dispose the asset manager, and all attached assets.
|
||||
*/
|
||||
~AssetManager();
|
||||
};
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
AssetLoader.cpp
|
||||
AssetDataLoader.cpp
|
||||
AssetManager.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(loaders)
|
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "JSONLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
JSONLoader::JSONLoader(const std::string name) :
|
||||
AssetLoader(name),
|
||||
loader(name + ".json"),
|
||||
state(JSONLoaderLoadState::INITIAL)
|
||||
{
|
||||
data = std::make_shared<json>();
|
||||
}
|
||||
|
||||
void JSONLoader::updateAsync() {
|
||||
if(this->state != JSONLoaderLoadState::INITIAL) return;
|
||||
this->state = JSONLoaderLoadState::LOADING_FILE;
|
||||
|
||||
this->loader.open();
|
||||
auto size = this->loader.getSize();
|
||||
|
||||
auto buffer = new uint8_t[size + 1];
|
||||
assertNotNull(buffer, "Failed to allocate buffer!");
|
||||
|
||||
this->state = JSONLoaderLoadState::PARSING_DATA;
|
||||
auto read = this->loader.read(buffer, size);
|
||||
assertTrue(read == size, "Failed to read entire file!");
|
||||
buffer[size] = '\0';
|
||||
|
||||
*data = json::parse(buffer);
|
||||
delete[] buffer;
|
||||
|
||||
this->state = JSONLoaderLoadState::DONE;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void JSONLoader::updateSync() {
|
||||
}
|
||||
|
||||
JSONLoader::~JSONLoader() {
|
||||
this->data = nullptr;
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetLoader.hpp"
|
||||
#include "asset/AssetDataLoader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class JSONLoaderLoadState {
|
||||
INITIAL,
|
||||
LOADING_FILE,
|
||||
PARSING_DATA,
|
||||
DONE
|
||||
};
|
||||
|
||||
class JSONLoader : public AssetLoader {
|
||||
protected:
|
||||
AssetDataLoader loader;
|
||||
enum JSONLoaderLoadState state;
|
||||
|
||||
public:
|
||||
std::shared_ptr<json> data;
|
||||
|
||||
/**
|
||||
* Constructs a JSON asset loader. You should instead use the parent
|
||||
* asset managers' abstracted load method
|
||||
*
|
||||
* @param name File name asset to load, omitting the extension.
|
||||
*/
|
||||
JSONLoader(const std::string name);
|
||||
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
|
||||
/**
|
||||
* Dispose / Cleanup the JSON asset.
|
||||
*/
|
||||
~JSONLoader();
|
||||
};
|
||||
}
|
@@ -1,147 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TextureLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TextureLoader::TextureLoader(const std::string name) :
|
||||
AssetLoader(name),
|
||||
loader(name + ".texture"),
|
||||
state(TextureLoaderLoadState::INITIAL)
|
||||
{
|
||||
sharedTexture = std::make_shared<Texture>();
|
||||
weakTexture = sharedTexture;
|
||||
}
|
||||
|
||||
void TextureLoader::updateAsync() {
|
||||
if(this->state != TextureLoaderLoadState::INITIAL) return;
|
||||
this->state = TextureLoaderLoadState::ASYNC_LOADING;
|
||||
this->loader.open();
|
||||
|
||||
// Read in the header.
|
||||
uint8_t buffer[TEXTURE_LOADER_HEADER_SIZE];
|
||||
size_t pos = 0;
|
||||
|
||||
// Read Version
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
std::string version = std::string((char*)buffer);
|
||||
assertTrue(version == "DT_2.00", "Invalid Texture Version!");
|
||||
|
||||
// Read Texture Width
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
width = std::stoi(std::string((char*)buffer));
|
||||
assertTrue(width > 0, "Invalid Texture Width!");
|
||||
|
||||
// Read Texture Height
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
height = std::stoi(std::string((char*)buffer));
|
||||
assertTrue(height > 0, "Invalid Texture Height!");
|
||||
|
||||
// Texture Format (RGBA, RGB, etc)
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFormat = std::stoi(std::string((char*)buffer));
|
||||
switch(iFormat) {
|
||||
case 1: format = TextureFormat::R; break;
|
||||
case 2: format = TextureFormat::RG; break;
|
||||
case 3: format = TextureFormat::RGB; break;
|
||||
case 4: format = TextureFormat::RGBA; break;
|
||||
default: assertUnreachable("Invalid Texture Format %i!", iFormat);
|
||||
}
|
||||
|
||||
// Wrap X
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iWrapX = std::stoi(std::string((char*)buffer));
|
||||
switch(iWrapX) {
|
||||
case 0: wrapX = TextureWrapMode::REPEAT; break;
|
||||
case 1: wrapX = TextureWrapMode::MIRRORED_REPEAT; break;
|
||||
case 2: wrapX = TextureWrapMode::CLAMP_TO_EDGE; break;
|
||||
case 3: wrapX = TextureWrapMode::CLAMP_TO_BORDER; break;
|
||||
default: assertUnreachable("Invalid Texture Wrap X %i!", iWrapX);
|
||||
}
|
||||
|
||||
// Wrap Y
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iWrapY = std::stoi(std::string((char*)buffer));
|
||||
switch(iWrapY) {
|
||||
case 0: wrapY = TextureWrapMode::REPEAT; break;
|
||||
case 1: wrapY = TextureWrapMode::MIRRORED_REPEAT; break;
|
||||
case 2: wrapY = TextureWrapMode::CLAMP_TO_EDGE; break;
|
||||
case 3: wrapY = TextureWrapMode::CLAMP_TO_BORDER; break;
|
||||
default: assertUnreachable("Invalid Texture Wrap Y %i!", iWrapY);
|
||||
}
|
||||
|
||||
// Filter Min
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFilterMin = std::stoi(std::string((char*)buffer));
|
||||
switch(iFilterMin) {
|
||||
case 0: filterMin = TextureFilterMode::NEAREST; break;
|
||||
case 1: filterMin = TextureFilterMode::LINEAR; break;
|
||||
default: assertUnreachable("Invalid Texture Filter Min %i!", iFilterMin);
|
||||
}
|
||||
|
||||
// Filter Mag
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFilterMag = std::stoi(std::string((char*)buffer));
|
||||
switch(iFilterMag) {
|
||||
case 0: filterMag = TextureFilterMode::NEAREST; break;
|
||||
case 1: filterMag = TextureFilterMode::LINEAR; break;
|
||||
default: assertUnreachable("Invalid Texture Filter Mag %i!", iFilterMag);
|
||||
}
|
||||
|
||||
// Data begins here. This part is done synchronously directly to the GPU.
|
||||
this->loader.setPosition(pos);
|
||||
size_t bufferSize = width * height * iFormat;
|
||||
data = new uint8_t[bufferSize];
|
||||
assertNotNull(data, "Failed to allocate texture data!");
|
||||
this->loader.read(data, bufferSize);
|
||||
|
||||
// Handoff to sync to buffer to GPU.
|
||||
this->state = TextureLoaderLoadState::ASYNC_DONE;
|
||||
}
|
||||
|
||||
void TextureLoader::updateSync() {
|
||||
if(this->state != TextureLoaderLoadState::ASYNC_DONE) return;
|
||||
this->state = TextureLoaderLoadState::SYNC_LOADING;
|
||||
|
||||
assertNotNull(this->sharedTexture, "Texture is null!");
|
||||
assertNotNull(this->data, "Texture data is null!");
|
||||
|
||||
// Setup Texture
|
||||
this->sharedTexture->setSize(
|
||||
this->width,
|
||||
this->height,
|
||||
this->format,
|
||||
TextureDataFormat::UNSIGNED_BYTE
|
||||
);
|
||||
this->sharedTexture->buffer(this->data);
|
||||
|
||||
// Free data buffer
|
||||
delete[] this->data;
|
||||
this->data = nullptr;
|
||||
|
||||
// Leat go of the held pointer
|
||||
this->sharedTexture = nullptr;
|
||||
|
||||
// Hand off and call done
|
||||
this->state = TextureLoaderLoadState::SYNC_DONE;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
TextureLoader::~TextureLoader() {
|
||||
if(this->data != nullptr) {
|
||||
delete[] this->data;
|
||||
this->data = nullptr;
|
||||
}
|
||||
this->sharedTexture = nullptr;
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetLoader.hpp"
|
||||
#include "asset/AssetDataLoader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
#define TEXTURE_LOADER_HEADER_SIZE 256
|
||||
|
||||
namespace Dawn {
|
||||
enum class TextureLoaderLoadState {
|
||||
INITIAL,
|
||||
ASYNC_LOADING,
|
||||
ASYNC_DONE,
|
||||
SYNC_LOADING,
|
||||
SYNC_DONE
|
||||
};
|
||||
|
||||
class TextureLoader : public AssetLoader {
|
||||
protected:
|
||||
AssetDataLoader loader;
|
||||
enum TextureLoaderLoadState state;
|
||||
uint8_t *data = nullptr;
|
||||
int32_t width = -1, height = -1;
|
||||
enum TextureFormat format;
|
||||
enum TextureWrapMode wrapX;
|
||||
enum TextureWrapMode wrapY;
|
||||
enum TextureFilterMode filterMin;
|
||||
enum TextureFilterMode filterMag;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Texture> sharedTexture;
|
||||
std::weak_ptr<Texture> weakTexture;
|
||||
|
||||
/**
|
||||
* Constructs a texture asset loader. You should instead use the parent
|
||||
* asset managers' abstracted load method
|
||||
*
|
||||
* @param name File name asset to load, omitting the extension.
|
||||
*/
|
||||
TextureLoader(const std::string name);
|
||||
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
|
||||
/**
|
||||
* Dispose / Cleanup the texture asset. Will also dispose the underlying
|
||||
* texture itself.
|
||||
*/
|
||||
~TextureLoader();
|
||||
};
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TrueTypeLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TrueTypeLoader::TrueTypeLoader(const std::string name) :
|
||||
AssetLoader(name),
|
||||
loader(name + ".ttf")
|
||||
{
|
||||
// Init the font.
|
||||
auto ret = FT_Init_FreeType(&fontLibrary);
|
||||
assertTrue(ret == 0, "Failed to initialize FreeType library.");
|
||||
}
|
||||
|
||||
void TrueTypeLoader::updateSync() {
|
||||
if(state != TrueTypeLoaderState::ASYNC_DONE) return;
|
||||
state = TrueTypeLoaderState::SYNC_LOADING;
|
||||
|
||||
// Init all the textures.
|
||||
auto it = textures.begin();
|
||||
while(it != textures.end()) {
|
||||
auto texture = it->second.lock();
|
||||
|
||||
if(texture) {
|
||||
texture->setFace(face);
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
|
||||
it = textures.erase(it);
|
||||
}
|
||||
|
||||
// Done
|
||||
state = TrueTypeLoaderState::SYNC_DONE;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void TrueTypeLoader::updateAsync() {
|
||||
if(state != TrueTypeLoaderState::INITIAL) return;
|
||||
state = TrueTypeLoaderState::ASYNC_LOADING;
|
||||
|
||||
// Load the data.
|
||||
this->loader.open();
|
||||
size_t size = loader.getSize();
|
||||
buffer = new uint8_t[size];
|
||||
|
||||
// Read the data.
|
||||
size_t readSize = loader.read(buffer, size);
|
||||
assertTrue(readSize == size, "Failed to read all data from TrueTypeLoader.");
|
||||
|
||||
// Init the font.
|
||||
auto ret = FT_New_Memory_Face(fontLibrary, buffer, size, 0, &face);
|
||||
assertTrue(ret == 0, "Failed to load font face.");
|
||||
|
||||
// Now close the asset loader
|
||||
loader.close();
|
||||
state = TrueTypeLoaderState::ASYNC_DONE;
|
||||
}
|
||||
|
||||
std::shared_ptr<TrueTypeTexture> TrueTypeLoader::getTexture(
|
||||
const uint32_t fontSize
|
||||
) {
|
||||
// Check if we have the texture already and it hasn't gone stale.
|
||||
auto it = textures.find(fontSize);
|
||||
if(it != textures.end()) {
|
||||
if(!it->second.expired()) return it->second.lock();
|
||||
textures.erase(it);
|
||||
}
|
||||
|
||||
// Create the texture.
|
||||
auto texture = std::make_shared<TrueTypeTexture>(fontSize);
|
||||
textures[fontSize] = texture;
|
||||
if(this->loaded) texture->setFace(face);
|
||||
return texture;
|
||||
}
|
||||
|
||||
TrueTypeLoader::~TrueTypeLoader() {
|
||||
if(
|
||||
this->state == TrueTypeLoaderState::SYNC_DONE ||
|
||||
this->state == TrueTypeLoaderState::SYNC_LOADING ||
|
||||
this->state == TrueTypeLoaderState::ASYNC_DONE
|
||||
) {
|
||||
FT_Done_Face(face);
|
||||
}
|
||||
|
||||
FT_Done_FreeType(fontLibrary);
|
||||
|
||||
if(buffer != nullptr) {
|
||||
delete[] buffer;
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetLoader.hpp"
|
||||
#include "asset/AssetDataLoader.hpp"
|
||||
#include "display/font/TrueTypeTexture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class TrueTypeLoaderState {
|
||||
INITIAL,
|
||||
ASYNC_LOADING,
|
||||
ASYNC_DONE,
|
||||
SYNC_LOADING,
|
||||
SYNC_DONE
|
||||
};
|
||||
|
||||
class TrueTypeLoader : public AssetLoader {
|
||||
protected:
|
||||
FT_Library fontLibrary;
|
||||
FT_Face face;
|
||||
AssetDataLoader loader;
|
||||
std::unordered_map<uint32_t, std::weak_ptr<TrueTypeTexture>> textures;
|
||||
enum TrueTypeLoaderState state = TrueTypeLoaderState::INITIAL;
|
||||
uint8_t *buffer = nullptr;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a TrueTypeLoader. You should instead use the parent
|
||||
* asset managers' abstracted load method
|
||||
*
|
||||
* @param name File name asset to load, omitting the extension.
|
||||
*/
|
||||
TrueTypeLoader(const std::string name);
|
||||
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
|
||||
/**
|
||||
* Returns the texture for the given font size.
|
||||
*
|
||||
* @param fontSize Font size to get the texture for.
|
||||
* @return Texture for the given character.
|
||||
*/
|
||||
std::shared_ptr<TrueTypeTexture> getTexture(
|
||||
const uint32_t fontSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Dispose / Cleanup the truetype asset. Will also dispose the underlying
|
||||
* truetype itself.
|
||||
*/
|
||||
~TrueTypeLoader();
|
||||
};
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IAudioManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IAudioManager::IAudioManager() {
|
||||
}
|
||||
|
||||
IAudioManager::~IAudioManager() {
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IAudioManager {
|
||||
public:
|
||||
/**
|
||||
* Construct a new IAudioManager.
|
||||
*/
|
||||
IAudioManager();
|
||||
|
||||
/**
|
||||
* Initializes the audio manager system.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Ticks/Update the audio manager system.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
/**
|
||||
* Deinitializes the audio manager system.
|
||||
*/
|
||||
virtual ~IAudioManager();
|
||||
};
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SimpleComponent.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(vn)
|
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SimpleComponent::onInit() {
|
||||
this->initMethod(*this, events);
|
||||
}
|
||||
|
||||
void SimpleComponent::onDispose() {
|
||||
for(auto &event : events) {
|
||||
event();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SimpleComponent> Dawn::addSimpleComponent(
|
||||
std::shared_ptr<SceneItem> item,
|
||||
std::function<void(SceneComponent&, std::vector<std::function<void()>>&)> init
|
||||
) {
|
||||
auto cmp = item->addComponent<SimpleComponent>();
|
||||
cmp->initMethod = init;
|
||||
return cmp;
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleComponent final : public SceneComponent {
|
||||
private:
|
||||
std::vector<std::function<void()>> events;
|
||||
|
||||
public:
|
||||
std::function<void(
|
||||
SceneComponent&,
|
||||
std::vector<std::function<void()>>&
|
||||
)> initMethod;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<SimpleComponent> addSimpleComponent(
|
||||
std::shared_ptr<SceneItem> item,
|
||||
std::function<void(
|
||||
SceneComponent&,
|
||||
std::vector<std::function<void()>>&
|
||||
)> init
|
||||
);
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "Camera.hpp"
|
||||
#include "game/Game.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Camera::onInit() {
|
||||
this->onResizeListener = this->getRenderTarget()->onResize.listen([&](
|
||||
float_t width, float_t height
|
||||
) {
|
||||
this->onResize.emit(this->getRenderTarget(), width, height);
|
||||
});
|
||||
}
|
||||
|
||||
void Camera::onDispose() {
|
||||
renderTarget = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderTarget> Camera::getRenderTarget() {
|
||||
if(this->renderTarget) return this->renderTarget;
|
||||
return getGame()->renderHost.getBackBufferRenderTarget();
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjection() {
|
||||
switch(this->type) {
|
||||
case CameraType::ORTHOGONAL:
|
||||
return glm::ortho(
|
||||
(float_t)this->orthoLeft,
|
||||
(float_t)this->orthoRight,
|
||||
(float_t)this->orthoBottom,
|
||||
(float_t)this->orthoTop,
|
||||
(float_t)this->clipNear,
|
||||
(float_t)this->clipFar
|
||||
);
|
||||
|
||||
case CameraType::PERSPECTIVE:
|
||||
return glm::perspective(
|
||||
(float_t)this->fov,
|
||||
this->getAspect(),
|
||||
(float_t)this->clipNear,
|
||||
(float_t)this->clipFar
|
||||
);
|
||||
}
|
||||
|
||||
assertUnreachable("Invalid Camera Type!");
|
||||
return glm::mat4(1.0f);
|
||||
}
|
||||
|
||||
float_t Camera::getAspect() {
|
||||
auto rt = this->getRenderTarget();
|
||||
return rt->getWidth() / rt->getHeight();
|
||||
}
|
||||
|
||||
void Camera::setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) {
|
||||
onResizeListener();
|
||||
this->renderTarget = renderTarget;
|
||||
this->onResizeListener = this->getRenderTarget()->onResize.listen([&](
|
||||
float_t width, float_t height
|
||||
) {
|
||||
this->onResize.emit(this->getRenderTarget(), width, height);
|
||||
});
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItem.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
PERSPECTIVE,
|
||||
ORTHOGONAL
|
||||
};
|
||||
|
||||
class Camera final : public SceneComponent {
|
||||
private:
|
||||
std::shared_ptr<RenderTarget> renderTarget;
|
||||
std::function<void()> onResizeListener;
|
||||
|
||||
public:
|
||||
Event<std::shared_ptr<RenderTarget>, float_t, float_t> onResize;
|
||||
float_t clipNear = 0.01f;
|
||||
float_t clipFar = 1000.0f;
|
||||
enum CameraType type = CameraType::PERSPECTIVE;
|
||||
|
||||
float_t fov = 0.785398f;
|
||||
|
||||
float_t orthoLeft = -1.0f;
|
||||
float_t orthoRight = 1.0f;
|
||||
float_t orthoBottom = -1.0f;
|
||||
float_t orthoTop = 1.0f;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
||||
/**
|
||||
* Returns the aspect ratio that the camera is using. In future I may
|
||||
* allow you to specify a custom ratio for stylistic reasons but for now I
|
||||
* just take the ratio of the specific frame buffer.
|
||||
*
|
||||
* @return The aspect ratio as a ratio of w/h.
|
||||
*/
|
||||
float_t getAspect();
|
||||
|
||||
/**
|
||||
* Returns the render target for this camera.
|
||||
*
|
||||
* @return Render target.
|
||||
*/
|
||||
std::shared_ptr<RenderTarget> getRenderTarget();
|
||||
|
||||
/**
|
||||
* Returns the projection matrix for this camera.
|
||||
*
|
||||
* @return Projection matrix.
|
||||
*/
|
||||
glm::mat4 getProjection();
|
||||
|
||||
/**
|
||||
* Sets the render target for this camera.
|
||||
*
|
||||
* @param renderTarget The render target to set.
|
||||
*/
|
||||
void setRenderTarget(std::shared_ptr<RenderTarget> renderTarget);
|
||||
};
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/pass/RenderPass.hpp"
|
||||
#include "display/pass/RenderPassContext.hpp"
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IRenderableComponent {
|
||||
public:
|
||||
/**
|
||||
* Retreive the list of render passes for this component.
|
||||
*
|
||||
* @param ctx Context for the render pass.
|
||||
* @return List of render passes.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Short-hand function to create a render pass.
|
||||
*
|
||||
* @tparam S Shader type.
|
||||
* @tparam D Shader's data type
|
||||
* @param self Instance of the IRenderableComponent that is creating the pass.
|
||||
* @param data Data to use for the render pass.
|
||||
* @return Created render pass.
|
||||
*/
|
||||
template<class S, typename D>
|
||||
std::shared_ptr<IRenderPass> createRenderPass(
|
||||
SceneComponent &self,
|
||||
const D data,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures = {},
|
||||
const std::shared_ptr<Mesh> mesh = nullptr,
|
||||
const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES,
|
||||
int32_t indiceStart = 0,
|
||||
int32_t indiceCount = -1
|
||||
) {
|
||||
return std::make_shared<RenderPass<S,D>>(
|
||||
self,
|
||||
data,
|
||||
textures,
|
||||
mesh,
|
||||
drawMode,
|
||||
indiceStart,
|
||||
indiceCount
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "MeshRenderer.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void MeshRenderer::onInit() {
|
||||
|
||||
}
|
||||
|
||||
void MeshRenderer::onDispose() {
|
||||
mesh = nullptr;
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class MeshRenderer final : public SceneComponent {
|
||||
public:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Material.cpp
|
||||
SimpleTexturedMaterial.cpp
|
||||
)
|
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Material.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Material::onInit() {
|
||||
|
||||
}
|
||||
|
||||
void Material::onDispose() {
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneComponent.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Material :
|
||||
public SceneComponent,
|
||||
public IRenderableComponent
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleTexturedMaterial.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Color SimpleTexturedMaterial::getColor() {
|
||||
return this->data.color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> SimpleTexturedMaterial::getTexture() {
|
||||
return this->texture;
|
||||
}
|
||||
|
||||
void SimpleTexturedMaterial::setTexture(std::shared_ptr<Texture> texture) {
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void SimpleTexturedMaterial::setColor(const struct Color color) {
|
||||
this->data.color = color;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> SimpleTexturedMaterial::getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) {
|
||||
this->data.model = this->getItem()->getWorldTransform();
|
||||
this->data.projection = ctx.camera->getProjection();
|
||||
this->data.view = ctx.camera->getItem()->getWorldTransform();
|
||||
auto textures = std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
>();
|
||||
|
||||
if(this->texture) {
|
||||
this->data.hasTexture = true;
|
||||
this->data.texture = 0;
|
||||
textures[this->data.texture] = this->texture;
|
||||
} else {
|
||||
this->data.hasTexture = false;
|
||||
}
|
||||
|
||||
return {
|
||||
createRenderPass<SimpleTexturedShader, struct SimpleTexturedShaderData>(
|
||||
*this,
|
||||
data,
|
||||
textures
|
||||
)
|
||||
};
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "component/display/material/Material.hpp"
|
||||
#include "display/shader/SimpleTexturedShader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedMaterial : public Material {
|
||||
private:
|
||||
struct SimpleTexturedShaderData data;
|
||||
std::shared_ptr<Texture> texture;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the color of this material.
|
||||
*/
|
||||
struct Color getColor();
|
||||
|
||||
/**
|
||||
* Returns the texture of this material.
|
||||
*
|
||||
* @return The texture of this material.
|
||||
*/
|
||||
std::shared_ptr<Texture> getTexture();
|
||||
|
||||
/**
|
||||
* Sets the texture of this material.
|
||||
*
|
||||
* @param texture The texture to set.
|
||||
*/
|
||||
void setTexture(std::shared_ptr<Texture> texture);
|
||||
|
||||
/**
|
||||
* Sets the color of this material.
|
||||
*
|
||||
* @param color The color to set.
|
||||
*/
|
||||
void setColor(const struct Color color);
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
};
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UICanvas.cpp
|
||||
)
|
@@ -1,149 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UICanvas.hpp"
|
||||
#include "display/pass/RenderPass.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "ui/UIElement.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void UICanvas::onInit() {
|
||||
mesh = std::make_shared<Mesh>();
|
||||
mesh->createBuffers(
|
||||
QUAD_VERTICE_COUNT * UI_SHADER_QUAD_COUNT,
|
||||
QUAD_INDICE_COUNT * UI_SHADER_QUAD_COUNT
|
||||
);
|
||||
|
||||
for(int32_t i = 0; i < UI_SHADER_QUAD_COUNT; i++) {
|
||||
QuadMesh::bufferWithIndex(
|
||||
mesh,
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
i * QUAD_VERTICE_COUNT,
|
||||
i * QUAD_INDICE_COUNT,
|
||||
i * QUAD_VERTICE_COUNT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void UICanvas::onDispose() {
|
||||
mesh = nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> UICanvas::getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) {
|
||||
if(this->elements.empty()) return {};
|
||||
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
|
||||
// Setup the projection and views
|
||||
data.projection = glm::ortho(
|
||||
0.0f, ctx.renderTarget->getWidth(),
|
||||
ctx.renderTarget->getHeight(), 0.0f,
|
||||
0.0f, 1.0f
|
||||
);
|
||||
data.view = glm::mat4(1.0f);
|
||||
data.model = glm::mat4(1.0f);
|
||||
|
||||
// Reset the passes
|
||||
this->passes.clear();
|
||||
this->textureBindings.clear();
|
||||
this->textures.clear();
|
||||
quadCount = 0;
|
||||
nextBinding = 0;
|
||||
|
||||
// Alignment root
|
||||
const glm::vec2 rootPosition = { 0, 0 };
|
||||
const glm::vec2 rootSize = {
|
||||
ctx.renderTarget->getWidth(),
|
||||
ctx.renderTarget->getHeight()
|
||||
};
|
||||
const float_t rootScale = 1.0f;
|
||||
|
||||
// Get the quads for each component
|
||||
auto itComponents = elements.begin();
|
||||
auto self = std::ref(*this);
|
||||
while(itComponents != elements.end()) {
|
||||
auto component = *itComponents;
|
||||
component->updateAlignment(rootPosition, rootSize, rootScale);
|
||||
component->getQuads(self);
|
||||
++itComponents;
|
||||
}
|
||||
|
||||
// Flush the remaining quads
|
||||
flushPass();
|
||||
return passes;
|
||||
}
|
||||
|
||||
void UICanvas::addQuad(
|
||||
const glm::vec4 quad,
|
||||
const glm::vec4 uvs,
|
||||
const struct Color color,
|
||||
const enum UIShaderQuadStyle style,
|
||||
const std::shared_ptr<Texture> text
|
||||
) {
|
||||
glm::vec4 styleData;
|
||||
styleData[0] = (float_t)style;
|
||||
|
||||
if(text == nullptr) {
|
||||
styleData[1] = -1;
|
||||
} else {
|
||||
shadertexturebinding_t texture;
|
||||
auto bindingIt = textureBindings.find(text);
|
||||
if(bindingIt == textureBindings.end()) {
|
||||
if(nextBinding >= UI_SHADER_TEXTURE_COUNT) {
|
||||
flushPass();
|
||||
}
|
||||
textureBindings[text] = nextBinding;
|
||||
textures[nextBinding] = text;
|
||||
data.textures[nextBinding] = nextBinding;
|
||||
texture = nextBinding++;
|
||||
} else {
|
||||
texture = bindingIt->second;
|
||||
}
|
||||
styleData[1] = (float_t)texture;
|
||||
}
|
||||
|
||||
data.quads[quadCount] = {
|
||||
quad,
|
||||
uvs,
|
||||
color,
|
||||
styleData
|
||||
};
|
||||
quadCount++;
|
||||
if(quadCount == UI_SHADER_QUAD_COUNT) flushPass();
|
||||
}
|
||||
|
||||
void UICanvas::flushPass() {
|
||||
if(quadCount == 0) return;
|
||||
|
||||
auto pass = createRenderPass<UIShader, UIShaderData>(
|
||||
std::ref(*this),
|
||||
data,
|
||||
textures,
|
||||
mesh,
|
||||
MeshDrawMode::TRIANGLES,
|
||||
0,
|
||||
quadCount * QUAD_INDICE_COUNT
|
||||
);
|
||||
passes.push_back(pass);
|
||||
|
||||
quadCount = 0;
|
||||
nextBinding = 0;
|
||||
textures.clear();
|
||||
textureBindings.clear();
|
||||
}
|
||||
|
||||
void UICanvas::addElement(std::shared_ptr<UIElement> element) {
|
||||
elements.push_back(element);
|
||||
}
|
||||
|
||||
void UICanvas::removeElement(std::shared_ptr<UIElement> element) {
|
||||
auto it = std::find(elements.begin(), elements.end(), element);
|
||||
if(it != elements.end()) elements.erase(it);
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItem.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
#include "display/shader/UIShader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIElement;
|
||||
|
||||
class UICanvas :
|
||||
public SceneComponent,
|
||||
public IRenderableComponent
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
UIShaderData data;
|
||||
std::vector<std::shared_ptr<UIElement>> elements;
|
||||
|
||||
size_t quadCount = 0;
|
||||
shadertexturebinding_t nextBinding = 0;
|
||||
std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures;
|
||||
std::map<
|
||||
std::shared_ptr<Texture>, shadertexturebinding_t
|
||||
> textureBindings;
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> passes;
|
||||
|
||||
protected:
|
||||
virtual void onInit() override;
|
||||
virtual void onDispose() override;
|
||||
|
||||
/**
|
||||
* Flushes all pending quads to the render pass. This doesn't actually
|
||||
* render anything, it just flushes the data buffer to a new pass.
|
||||
*/
|
||||
void flushPass();
|
||||
|
||||
public:
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
|
||||
/**
|
||||
* Adds a quad to the canvas and performs a flush if necessary.
|
||||
*
|
||||
* @param quad The quad to add.
|
||||
* @param uvs The UVs to use for the quad.
|
||||
* @param color The color to use for the quad.
|
||||
* @param style Style that the quad should be rendered in.
|
||||
* @param texture The texture to use for the quad, can be null.
|
||||
*/
|
||||
void addQuad(
|
||||
const glm::vec4 quad,
|
||||
const glm::vec4 uvs,
|
||||
const struct Color color,
|
||||
const enum UIShaderQuadStyle style,
|
||||
const std::shared_ptr<Texture> texture = nullptr
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds a component to the canvas.
|
||||
*
|
||||
* @param component The component to add.
|
||||
*/
|
||||
void addElement(std::shared_ptr<UIElement> component);
|
||||
|
||||
/**
|
||||
* Removes a component from the canvas.
|
||||
*
|
||||
* @param component The component to remove.
|
||||
*/
|
||||
void removeElement(std::shared_ptr<UIElement> component);
|
||||
};
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
VNManager.cpp
|
||||
)
|
@@ -1,65 +0,0 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void VNManager::onInit() {
|
||||
assertNotNull(canvas, "Canvas must be set.");
|
||||
assertNotNull(texture, "Texture must be set.");
|
||||
|
||||
container = std::make_shared<UIContainer>();
|
||||
container->align = { 0, 128, 0, 0 };
|
||||
container->alignX = UIAlignmentType::STRETCH;
|
||||
container->alignY = UIAlignmentType::END;
|
||||
|
||||
borders = std::make_shared<UIRectangle>();
|
||||
borders->align = { 0, 0, 0, 0 };
|
||||
borders->alignX = UIAlignmentType::STRETCH;
|
||||
borders->alignY = UIAlignmentType::STRETCH;
|
||||
borders->color = COLOR_BLUE;
|
||||
container->appendChild(borders);
|
||||
|
||||
background = std::make_shared<UIRectangle>();
|
||||
background->align = { 16, 16, 16, 16 };
|
||||
background->alignX = UIAlignmentType::STRETCH;
|
||||
background->alignY = UIAlignmentType::STRETCH;
|
||||
background->color = COLOR_RED;
|
||||
container->appendChild(background);
|
||||
|
||||
label = std::make_shared<UILabel>();
|
||||
label->align = { 16, 16, 16, 16 };
|
||||
label->alignX = UIAlignmentType::STRETCH;
|
||||
label->alignY = UIAlignmentType::STRETCH;
|
||||
label->setFont(texture);
|
||||
label->setText(text);
|
||||
container->appendChild(label);
|
||||
|
||||
canvas->addElement(container);
|
||||
|
||||
listeners.push_back(getScene()->onUnpausedUpdate.listen([&](const float_t d) {
|
||||
|
||||
}));
|
||||
|
||||
auto w = label->getWidth();
|
||||
auto cw = container->getWidth();
|
||||
}
|
||||
|
||||
void VNManager::onDispose() {
|
||||
canvas->removeElement(container);
|
||||
|
||||
container = nullptr;
|
||||
label = nullptr;
|
||||
background = nullptr;
|
||||
borders = nullptr;
|
||||
texture = nullptr;
|
||||
canvas = nullptr;
|
||||
}
|
||||
|
||||
void VNManager::setText(const std::wstring &text) {
|
||||
this->text = text;
|
||||
if(label) label->setText(text);
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItem.hpp"
|
||||
#include "ui/container/UIContainer.hpp"
|
||||
#include "ui/elements/UILabel.hpp"
|
||||
#include "ui/elements/UIRectangle.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VNManager : public SceneComponent {
|
||||
protected:
|
||||
std::shared_ptr<UIContainer> container;
|
||||
std::shared_ptr<UILabel> label;
|
||||
std::shared_ptr<UIRectangle> borders;
|
||||
std::shared_ptr<UIRectangle> background;
|
||||
std::wstring text;
|
||||
|
||||
public:
|
||||
std::shared_ptr<UICanvas> canvas;
|
||||
std::shared_ptr<TrueTypeTexture> texture;
|
||||
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
||||
/**
|
||||
* Sets the text to display.
|
||||
*
|
||||
* @param text The text to display.
|
||||
*/
|
||||
void setText(const std::wstring &text);
|
||||
};
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
// Static Libs
|
||||
extern "C" {
|
||||
// Standard Libs
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef char char_t;
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstdarg>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
// #include <glm/gtx/component_wise.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
// #include <glm/gtx/intersect.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL 1
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
@@ -1,17 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Color.cpp
|
||||
RenderPipeline.cpp
|
||||
IRenderHost.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(font)
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(shader)
|
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "util/String.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Color Color::fromString(const std::string str) {
|
||||
// Convert to lowercase
|
||||
auto lower = String::toLowercase(str);
|
||||
|
||||
if(String::includes(lower, "cornflower")) {
|
||||
return COLOR_CORNFLOWER_BLUE;
|
||||
|
||||
} else if(String::includes(lower, "magenta")) {
|
||||
return COLOR_MAGENTA;
|
||||
|
||||
} else if(String::includes(lower, "white")) {
|
||||
return COLOR_WHITE;
|
||||
|
||||
} else if(String::includes(lower, "black")) {
|
||||
return COLOR_BLACK;
|
||||
|
||||
} else if(String::includes(lower, "red")) {
|
||||
return COLOR_RED;
|
||||
|
||||
} else if(String::includes(lower, "green")) {
|
||||
return COLOR_GREEN;
|
||||
|
||||
} else if(String::includes(lower, "blue")) {
|
||||
return COLOR_BLUE;
|
||||
|
||||
} else if(String::includes(lower, "transparent")) {
|
||||
return COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
// Hex code?
|
||||
if(lower[0] == '#') {
|
||||
// Remove the hash
|
||||
lower = lower.substr(1);
|
||||
|
||||
// Convert to RGB
|
||||
if(lower.length() == 3) {
|
||||
// Convert to 6 digit hex
|
||||
lower = lower[0] + lower[0] + lower[1] + lower[1] + lower[2] + lower[2];
|
||||
}
|
||||
|
||||
// Convert to RGB
|
||||
return {
|
||||
(float_t)std::stoi(lower.substr(0, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(2, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(4, 2), nullptr, 16) / 255.0f,
|
||||
1.0f
|
||||
};
|
||||
}
|
||||
|
||||
// Split by comma
|
||||
auto splitByComma = String::split(str, ",");
|
||||
if(splitByComma.size() == 3) {
|
||||
// RGB
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
1.0f
|
||||
};
|
||||
} else if(splitByComma.size() == 4) {
|
||||
// RGBA
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
(float_t)std::stof(splitByComma[3])
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Parse other kinds of colors
|
||||
assertUnreachable("Failed to find a color match for %s", str);
|
||||
return {};
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct ColorU8 {
|
||||
uint8_t r, g, b, a;
|
||||
};
|
||||
|
||||
struct Color final {
|
||||
/**
|
||||
* Returns a color from a string.
|
||||
*
|
||||
* @param str String to parse.
|
||||
* @return Color parsed.
|
||||
*/
|
||||
static struct Color fromString(const std::string str);
|
||||
|
||||
float_t r, g, b, a;
|
||||
|
||||
const struct Color& operator = (const struct Color &val) {
|
||||
this->r = val.r;
|
||||
this->g = val.g;
|
||||
this->b = val.b;
|
||||
this->a = val.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct Color operator * (const float_t &x) {
|
||||
return {
|
||||
r * x,
|
||||
g * x,
|
||||
b * x,
|
||||
a * x
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator - (const struct Color &color) {
|
||||
return {
|
||||
r - color.r,
|
||||
g - color.g,
|
||||
b - color.b,
|
||||
a - color.a
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator + (const struct Color &color) {
|
||||
return {
|
||||
r + color.r,
|
||||
g + color.g,
|
||||
b + color.b,
|
||||
a + color.a
|
||||
};
|
||||
}
|
||||
|
||||
const bool_t operator == (const struct Color &other) {
|
||||
return r == other.r && g == other.g && b == other.b && a == other.a;
|
||||
}
|
||||
|
||||
operator struct ColorU8() const {
|
||||
return {
|
||||
(uint8_t)(r * 255),
|
||||
(uint8_t)(g * 255),
|
||||
(uint8_t)(b * 255),
|
||||
(uint8_t)(a * 255)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#define COLOR_DEF(r,g,b,a) { r, g, b, a }
|
||||
#define COLOR_WHITE COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_RED COLOR_DEF(1.0f, 0, 0, 1.0f)
|
||||
#define COLOR_GREEN COLOR_DEF(0, 1.0f, 0, 1.0f)
|
||||
#define COLOR_BLUE COLOR_DEF(0, 0, 1.0f, 1.0f)
|
||||
#define COLOR_BLACK COLOR_DEF(0, 0, 0, 1.0f)
|
||||
#define COLOR_MAGENTA COLOR_DEF(1.0f, 0, 1.0f, 1.0f)
|
||||
#define COLOR_DARK_GREY COLOR_DEF(0.2f, 0.2f, 0.2f, 1.0f)
|
||||
#define COLOR_LIGHT_GREY COLOR_DEF(0.8f, 0.8f, 0.8f, 1.0f)
|
||||
#define COLOR_CORNFLOWER_BLUE COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
|
||||
#define COLOR_WHITE_TRANSPARENT COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
|
||||
#define COLOR_BLACK_TRANSPARENT COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
#define COLOR_YELLOW COLOR_DEF(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
#define COLOR_CYAN COLOR_DEF(0.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_TRANSPARENT COLOR_WHITE_TRANSPARENT
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IRenderHost.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IRenderHost::IRenderHost() : renderPipeline(), shaderManager() {
|
||||
}
|
||||
|
||||
IRenderHost::~IRenderHost() {
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "display/RenderPipeline.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
|
||||
class IRenderHost {
|
||||
public:
|
||||
RenderPipeline renderPipeline;
|
||||
ShaderManager shaderManager;
|
||||
|
||||
/**
|
||||
* Creates a render host.
|
||||
*/
|
||||
IRenderHost();
|
||||
|
||||
/**
|
||||
* Initializes the render host, called by the game during the initial
|
||||
* set up of the engine.
|
||||
*
|
||||
* @param game Game that requested the render host to initialize.
|
||||
*/
|
||||
virtual void init(const std::shared_ptr<Game> game) = 0;
|
||||
|
||||
/**
|
||||
* Performs an update/tick of the render host. This would be the game
|
||||
* asking the RenderHost to do the rendering.
|
||||
*/
|
||||
virtual void update(const std::shared_ptr<Game> game) = 0;
|
||||
|
||||
/**
|
||||
* Overridable request from the game that asks if the RenderHost has any
|
||||
* reason that it should need to close. For most libraries this would be
|
||||
* whether or not the window was closed.
|
||||
*
|
||||
* @return True if the render host requests the game to gracefully exit.
|
||||
*/
|
||||
virtual bool_t isCloseRequested() = 0;
|
||||
|
||||
/**
|
||||
* Returns the back buffer render target. This is the render target that
|
||||
* is used to render to the screen.
|
||||
*
|
||||
* @return The back buffer render target.
|
||||
*/
|
||||
virtual std::shared_ptr<RenderTarget> getBackBufferRenderTarget() = 0;
|
||||
|
||||
/**
|
||||
* Destroys the render host.
|
||||
*/
|
||||
virtual ~IRenderHost();
|
||||
};
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class TextureFormat {
|
||||
R = 1,
|
||||
RG = 2,
|
||||
RGB = 3,
|
||||
RGBA = 4
|
||||
};
|
||||
|
||||
enum class TextureWrapMode {
|
||||
REPEAT = 0,
|
||||
MIRRORED_REPEAT = 1,
|
||||
CLAMP_TO_EDGE = 2,
|
||||
CLAMP_TO_BORDER = 3
|
||||
};
|
||||
|
||||
enum class TextureFilterMode {
|
||||
NEAREST = 0,
|
||||
LINEAR = 1
|
||||
};
|
||||
|
||||
enum class TextureDataFormat {
|
||||
UNSIGNED_BYTE = sizeof(uint8_t),
|
||||
FLOAT = sizeof(float_t)
|
||||
};
|
||||
|
||||
class ITexture {
|
||||
public:
|
||||
enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT;
|
||||
enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT;
|
||||
enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST;
|
||||
|
||||
/**
|
||||
* Returns the width of the texture.
|
||||
*
|
||||
* @return Width of the texture.
|
||||
*/
|
||||
virtual int32_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Returns the height of the texture.
|
||||
*
|
||||
* @return Height of the texture.
|
||||
*/
|
||||
virtual int32_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Initializes a texture.
|
||||
*
|
||||
* @param width Width of the texture (in pixels).
|
||||
* @param height Height of the texture (in pixels).
|
||||
* @param format Data format of the texture to use.
|
||||
* @param dataFormat Data format of the texture to use.
|
||||
*/
|
||||
virtual void setSize(
|
||||
const int32_t width,
|
||||
const int32_t height,
|
||||
const enum TextureFormat format,
|
||||
const enum TextureDataFormat dataFormat
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Returns true only when the texture has been loaded, sized and put on
|
||||
* the gpu for rendering.
|
||||
*
|
||||
* @return True if ready, otherwise false.
|
||||
*/
|
||||
virtual bool_t isReady() = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const struct ColorU8 pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const struct Color pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const uint8_t pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Binds the texture to the given slot (for use by the shaders).
|
||||
*
|
||||
* @param slot Slot to bind to.
|
||||
*/
|
||||
virtual void bind(const uint8_t slot) = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the texture.
|
||||
*/
|
||||
virtual ~ITexture() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "RenderPipeline.hpp"
|
||||
#include "game/Game.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderPipeline::RenderPipeline() {
|
||||
|
||||
}
|
||||
|
||||
void RenderPipeline::render(
|
||||
const std::shared_ptr<Game> game
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
|
||||
auto scene = game->getCurrentScene();
|
||||
if(!scene) return;
|
||||
|
||||
this->renderScene(game, scene);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderScene(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
assertNotNull(scene, "Scene cannot be null");
|
||||
|
||||
// TODO: Render Subscenes First
|
||||
|
||||
// Get a list of all cameras in the scene
|
||||
auto cameras = scene->findComponents<Camera>();
|
||||
auto backBuffer = scene->getGame()->renderHost.getBackBufferRenderTarget();
|
||||
|
||||
std::shared_ptr<Camera> backbufferCamera = nullptr;
|
||||
for(auto camera : cameras) {
|
||||
auto rt = camera->getRenderTarget();
|
||||
// Is this camera the backbuffer camera?
|
||||
if(rt == backBuffer) {
|
||||
backbufferCamera = camera;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Render scene with this camera
|
||||
renderSceneCamera(game, scene, camera, rt);
|
||||
}
|
||||
|
||||
if(backbufferCamera) {
|
||||
// Render the backbuffer camera
|
||||
renderSceneCamera(game, scene, backbufferCamera, backBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderSceneCamera(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene,
|
||||
const std::shared_ptr<Camera> camera,
|
||||
const std::shared_ptr<RenderTarget> renderTarget
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
assertNotNull(scene, "Scene cannot be null");
|
||||
assertNotNull(camera, "Camera cannot be null");
|
||||
assertNotNull(renderTarget, "RenderTarget cannot be null");
|
||||
|
||||
struct RenderPassContext ctx = {
|
||||
game,
|
||||
scene,
|
||||
camera,
|
||||
renderTarget
|
||||
};
|
||||
|
||||
// Get list of renderables
|
||||
std::vector<std::shared_ptr<IRenderPass>> renderPasses;
|
||||
auto renderables = scene->findComponents<IRenderableComponent>();
|
||||
for(auto renderable : renderables) {
|
||||
auto rp = renderable->getPasses(ctx);
|
||||
renderPasses.insert(renderPasses.end(), rp.begin(), rp.end());
|
||||
}
|
||||
|
||||
// TODO: Make clearing the buffers editable!
|
||||
renderTarget->bind();
|
||||
renderTarget->clear(
|
||||
RENDER_TARGET_CLEAR_COLOR |
|
||||
RENDER_TARGET_CLEAR_DEPTH
|
||||
);
|
||||
|
||||
for(auto renderPass : renderPasses) {
|
||||
renderPass->bind();
|
||||
renderPass->setData();
|
||||
renderPass->upload();
|
||||
renderPass->draw();
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
class Scene;
|
||||
class Camera;
|
||||
class RenderTarget;
|
||||
|
||||
class RenderPipeline {
|
||||
public:
|
||||
/**
|
||||
* Creates a new RenderPipeline.
|
||||
*/
|
||||
RenderPipeline();
|
||||
|
||||
/**
|
||||
* Renders the game. This will render the current scene.
|
||||
*
|
||||
* @param game Game to render.
|
||||
*/
|
||||
void render(
|
||||
const std::shared_ptr<Game> game
|
||||
);
|
||||
|
||||
/**
|
||||
* Renders a specific scene. This will render all cameras within the
|
||||
* scene.
|
||||
*
|
||||
* @param game Game to render.
|
||||
* @param scene Scene to render.
|
||||
*/
|
||||
void renderScene(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene
|
||||
);
|
||||
|
||||
/**
|
||||
* Renders a specific scene with a specific camera.
|
||||
*
|
||||
* @param game Game to render.
|
||||
* @param scene Scene to render.
|
||||
* @param camera Camera to render.
|
||||
* @param renderTarget Render target to render to.
|
||||
*/
|
||||
void renderSceneCamera(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene,
|
||||
const std::shared_ptr<Camera> camera,
|
||||
const std::shared_ptr<RenderTarget> renderTarget
|
||||
);
|
||||
|
||||
/**
|
||||
* Destroys the RenderPipeline.
|
||||
*/
|
||||
virtual ~RenderPipeline();
|
||||
};
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_COLOR (1 << 0)
|
||||
#define RENDER_TARGET_CLEAR_DEPTH (1 << 1)
|
||||
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
Event<float_t, float_t> onResize;
|
||||
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
* @return The width of the render target.
|
||||
*/
|
||||
virtual float_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Return the height of the render target.
|
||||
*
|
||||
* @return The height of the render target.
|
||||
*/
|
||||
virtual float_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Returns the scale (as in pixel density) of the render target. This is
|
||||
* typically 1.0f, but on high DPI displays this may be 2.0f or higher.
|
||||
*
|
||||
* @return The scale of the render target.
|
||||
*/
|
||||
virtual float_t getScale() = 0;
|
||||
|
||||
/**
|
||||
* Sets the clear color of the render target when the clear method for
|
||||
* the color buffer is requested.
|
||||
*
|
||||
* @param color Color to use for the clear operation.
|
||||
*/
|
||||
virtual void setClearColor(const struct Color color) = 0;
|
||||
|
||||
/**
|
||||
* Request the existing data in the render target to be cleared out. We
|
||||
* typically assume the render target can support multiple buffer types,
|
||||
* so you can opt to only clear certain buffer types.
|
||||
*
|
||||
* @param clearFlags Flags to request what is going to be cleared.
|
||||
*/
|
||||
virtual void clear(const int32_t clearFlags) = 0;
|
||||
|
||||
/**
|
||||
* Bind the render target for rendering to. The proceeding render requests
|
||||
* will want to render to this render target directly. In future I may
|
||||
* see if we can have multiple render targets bound at once to make this
|
||||
* operation perform faster.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Destroys the render target.
|
||||
*/
|
||||
virtual ~RenderTarget() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TrueTypeTexture.cpp
|
||||
)
|
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct TrueTypeCharacter {
|
||||
glm::vec2 advance;
|
||||
glm::vec2 size;
|
||||
glm::vec2 offset;
|
||||
glm::vec4 quad;
|
||||
};
|
||||
}
|
@@ -1,198 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TrueTypeTexture.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "util/Math.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TrueTypeTexture::TrueTypeTexture(const uint32_t fontSize) :
|
||||
fontSize(fontSize)
|
||||
{
|
||||
assertTrue(fontSize > 0, "Font size cannot be zero");
|
||||
texture = std::make_shared<Texture>();
|
||||
}
|
||||
|
||||
void TrueTypeTexture::setFace(const FT_Face face) {
|
||||
this->face = face;
|
||||
assertTrue(fontSize < 256, "Font size cannot be greater than 256");
|
||||
|
||||
// Set freetype font size prior to baking.
|
||||
auto ret = FT_Set_Pixel_Sizes(face, 0, fontSize);
|
||||
if(ret != 0) {
|
||||
assertUnreachable("Failed to set font size %i", ret);
|
||||
}
|
||||
|
||||
// Set the texture size
|
||||
texture->setSize(
|
||||
fontSize * 24,
|
||||
fontSize * 24,
|
||||
TextureFormat::R,
|
||||
TextureDataFormat::UNSIGNED_BYTE
|
||||
);
|
||||
|
||||
// Texture buffer
|
||||
uint8_t *buffer = new uint8_t[texture->getWidth() * texture->getHeight()];
|
||||
// Fill with zeros
|
||||
std::memset(buffer, 0, texture->getWidth() * texture->getHeight());
|
||||
|
||||
size_t offset = 0;
|
||||
struct TrueTypeCharacter info;
|
||||
int32_t textureX = 0, textureY = 0;
|
||||
int32_t rowHeight = 0;
|
||||
|
||||
// Character sets
|
||||
std::vector<wchar_t> characterBlocks;
|
||||
// Latin
|
||||
for(wchar_t c = 0x0020; c < 0x007F; c++) characterBlocks.push_back(c);
|
||||
// Latin-1 Supplement
|
||||
for(wchar_t c = 0x00A0; c < 0x00FF; c++) characterBlocks.push_back(c);
|
||||
// Latin Extended-A
|
||||
for(wchar_t c = 0x0100; c < 0x017F; c++) characterBlocks.push_back(c);
|
||||
// Latin Extended-B
|
||||
for(wchar_t c = 0x0180; c < 0x024F; c++) characterBlocks.push_back(c);
|
||||
// Hiragana
|
||||
for(wchar_t c = 0x3040; c < 0x309F; c++) characterBlocks.push_back(c);
|
||||
// Katakana
|
||||
for(wchar_t c = 0x30A0; c < 0x30FF; c++) characterBlocks.push_back(c);
|
||||
|
||||
// For each character in the character set
|
||||
for(wchar_t c : characterBlocks) {
|
||||
// Load the character
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
assertUnreachable("Failed to load character (1)");
|
||||
}
|
||||
|
||||
// Store the character information
|
||||
info.advance.x = (float_t)(face->glyph->advance.x >> 6);
|
||||
info.advance.y = (float_t)(face->glyph->advance.y >> 6);
|
||||
info.size = glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||
|
||||
// Determine the texture position
|
||||
if(textureX + face->glyph->bitmap.width >= texture->getWidth()) {
|
||||
textureX = 0;
|
||||
textureY += rowHeight + 2;// Tiny gap between rows
|
||||
rowHeight = face->glyph->bitmap.rows;
|
||||
} else {
|
||||
rowHeight = Math::max<int32_t>(rowHeight, face->glyph->bitmap.rows);
|
||||
}
|
||||
|
||||
// Set the quad positions
|
||||
info.offset = glm::vec2(
|
||||
face->glyph->bitmap_left,
|
||||
-face->glyph->bitmap_top
|
||||
);
|
||||
info.quad = glm::vec4(
|
||||
textureX,
|
||||
textureY,
|
||||
textureX + face->glyph->bitmap.width,
|
||||
textureY + face->glyph->bitmap.rows
|
||||
) / glm::vec4(
|
||||
texture->getWidth(),
|
||||
texture->getHeight(),
|
||||
texture->getWidth(),
|
||||
texture->getHeight()
|
||||
);
|
||||
|
||||
// Store the cached character data.
|
||||
this->characterData[c] = info;
|
||||
|
||||
// Determine pixel offset.
|
||||
offset = textureX + (textureY * texture->getWidth());
|
||||
assertTrue(
|
||||
offset + (face->glyph->bitmap.rows * texture->getWidth()) <=
|
||||
texture->getWidth() * texture->getHeight(),
|
||||
"Font texture buffer overflow will occur."
|
||||
);
|
||||
|
||||
// Buffer pixels, we have to do this one row at a time due to the
|
||||
// differences in width between the glyph and the texture.
|
||||
const size_t countPerRow = face->glyph->bitmap.width;
|
||||
int32_t i = 0;
|
||||
while(i != face->glyph->bitmap.rows) {
|
||||
std::memcpy(
|
||||
buffer + offset + (i * texture->getWidth()),
|
||||
face->glyph->bitmap.buffer + (i * countPerRow),
|
||||
countPerRow
|
||||
);
|
||||
i++;
|
||||
}
|
||||
|
||||
// Increment textureX
|
||||
textureX += face->glyph->bitmap.width + 2;// I add a tiny gap between chars
|
||||
}
|
||||
|
||||
this->texture->buffer(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
struct TrueTypeCharacter TrueTypeTexture::getCharacterData(wchar_t c) {
|
||||
return this->characterData[c];
|
||||
}
|
||||
|
||||
glm::vec2 TrueTypeTexture::bufferStringToMesh(
|
||||
std::shared_ptr<Mesh> mesh,
|
||||
const std::wstring text,
|
||||
glm::vec2 &position,
|
||||
bool_t flipY
|
||||
) {
|
||||
assertNotNull(mesh, "Mesh must be supplied and not null");
|
||||
assertTrue(text.size() > 0, "Text must be at least one character long.");
|
||||
|
||||
// Create mesh buffers
|
||||
mesh->createBuffers(
|
||||
text.length() * QUAD_VERTICE_COUNT,
|
||||
text.length() * QUAD_INDICE_COUNT
|
||||
);
|
||||
|
||||
// Foreach char
|
||||
size_t i = 0;
|
||||
glm::vec2 size = { 0, 0 };
|
||||
for(wchar_t c : text) {
|
||||
// Get the character data
|
||||
auto info = this->getCharacterData(c);
|
||||
|
||||
// Buffer the quad
|
||||
glm::vec4 quad = glm::vec4(
|
||||
position.x,
|
||||
position.y,
|
||||
position.x + info.size.x,
|
||||
position.y + info.size.y
|
||||
);
|
||||
if(flipY) {
|
||||
QuadMesh::buffer(
|
||||
mesh,
|
||||
quad,
|
||||
glm::vec4(
|
||||
info.quad.x,
|
||||
info.quad.w,
|
||||
info.quad.z,
|
||||
info.quad.y
|
||||
),
|
||||
i * QUAD_VERTICE_COUNT,
|
||||
i * QUAD_INDICE_COUNT
|
||||
);
|
||||
} else {
|
||||
QuadMesh::buffer(
|
||||
mesh,
|
||||
quad,
|
||||
info.quad,
|
||||
i * QUAD_VERTICE_COUNT,
|
||||
i * QUAD_INDICE_COUNT
|
||||
);
|
||||
}
|
||||
position += info.advance;
|
||||
size += info.advance;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
TrueTypeTexture::~TrueTypeTexture() {
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Texture.hpp"
|
||||
#include "TrueTypeCharacter.hpp"
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace Dawn {
|
||||
class TrueTypeTexture final {
|
||||
private:
|
||||
FT_Face face;
|
||||
|
||||
public:
|
||||
uint32_t fontSize;
|
||||
std::shared_ptr<Texture> texture;
|
||||
std::unordered_map<wchar_t, struct TrueTypeCharacter> characterData;
|
||||
|
||||
/**
|
||||
* Construct a new New True Type Face Texture object
|
||||
*
|
||||
* @param fontSize Size of the font.
|
||||
*/
|
||||
TrueTypeTexture(const uint32_t fontSize);
|
||||
|
||||
/**
|
||||
* Sets the face for this texture.
|
||||
*
|
||||
* @param face Face to set.
|
||||
*/
|
||||
void setFace(const FT_Face face);
|
||||
|
||||
/**
|
||||
* Returns the character data for the given character.
|
||||
*
|
||||
* @param c Character to get data for.
|
||||
* @return The Character data for the given character.
|
||||
*/
|
||||
struct TrueTypeCharacter getCharacterData(wchar_t c);
|
||||
|
||||
/**
|
||||
* Buffers a string to the given mesh.
|
||||
*
|
||||
* @param mesh Mesh to buffer to.
|
||||
* @param text Text to buffer.
|
||||
* @param position Position to buffer to.
|
||||
* @param flipY Whether or not to flip the Y axis.
|
||||
* @return The size of the string.
|
||||
*/
|
||||
glm::vec2 bufferStringToMesh(
|
||||
std::shared_ptr<Mesh> mesh,
|
||||
const std::wstring text,
|
||||
glm::vec2 &position,
|
||||
bool_t flipY = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Destroys this true type face texture.
|
||||
*/
|
||||
~TrueTypeTexture();
|
||||
};
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void CubeMesh::buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec3 pos,
|
||||
const glm::vec3 size,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart
|
||||
) {
|
||||
glm::vec3 positions[CUBE_VERTICE_COUNT] = {
|
||||
pos,
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z),
|
||||
glm::vec3(pos.x+size.x, pos.y+size.y, pos.z),
|
||||
|
||||
glm::vec3(pos.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z+size.z),
|
||||
pos + size
|
||||
};
|
||||
|
||||
glm::vec2 coordinates[CUBE_VERTICE_COUNT] = {
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1),
|
||||
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1)
|
||||
};
|
||||
|
||||
int32_t indices[CUBE_INDICE_COUNT] = {
|
||||
// Back
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3,
|
||||
|
||||
// Right
|
||||
verticeStart + 1, verticeStart + 5, verticeStart + 7,
|
||||
verticeStart + 1, verticeStart + 3, verticeStart + 7,
|
||||
|
||||
// Left
|
||||
verticeStart + 4, verticeStart, verticeStart + 2,
|
||||
verticeStart + 4, verticeStart + 6, verticeStart + 2,
|
||||
|
||||
// Front
|
||||
verticeStart + 5, verticeStart + 4, verticeStart + 6,
|
||||
verticeStart + 5, verticeStart + 7, verticeStart + 6,
|
||||
|
||||
// Top
|
||||
verticeStart + 7, verticeStart + 2, verticeStart + 6,
|
||||
verticeStart + 7, verticeStart + 3, verticeStart + 2,
|
||||
|
||||
// Bottom
|
||||
verticeStart + 1, verticeStart, verticeStart + 4,
|
||||
verticeStart + 1, verticeStart + 4, verticeStart + 5
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define CUBE_VERTICE_COUNT 8
|
||||
#define CUBE_INDICE_COUNT 36
|
||||
|
||||
namespace Dawn {
|
||||
class CubeMesh {
|
||||
public:
|
||||
/**
|
||||
* Buffers cube mesh vertices and indices into the given mesh.
|
||||
*
|
||||
* @param size The size of the cube.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
*/
|
||||
static void buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec3 pos,
|
||||
const glm::vec3 size,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart
|
||||
);
|
||||
};
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum MeshDrawMode {
|
||||
TRIANGLES,
|
||||
TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
LINES,
|
||||
POINTS
|
||||
// LINE_STRIP,
|
||||
};
|
||||
|
||||
class IMesh {
|
||||
protected:
|
||||
/** How many vertices are in the mesh */
|
||||
int32_t verticeCount = -1;
|
||||
/** How many indices are in the mesh */
|
||||
int32_t indiceCount = -1;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new set of buffers for the mesh to use.
|
||||
*
|
||||
* @param verticeCount How many Vertices will this buffer support.
|
||||
* @param indiceCount How many Indices will this buffer support.
|
||||
*/
|
||||
virtual void createBuffers(
|
||||
const int32_t verticeCount,
|
||||
const int32_t indiceCount
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Cleanup the buffers on a given mesh. This is useful if you intend to
|
||||
* expand the count of vertices your mesh supports.
|
||||
*/
|
||||
virtual void disposeBuffers() = 0;
|
||||
|
||||
/**
|
||||
* Write vertice positions to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param vertices Array of positions to write.
|
||||
* @param len How many positions are in the array.
|
||||
*/
|
||||
virtual void bufferPositions(
|
||||
const int32_t pos,
|
||||
const glm::vec3 positions[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Write vertice coordinates to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param coordinates Array of coordinates to write.
|
||||
* @param len How many coordinates are in the array.
|
||||
*/
|
||||
virtual void bufferCoordinates(
|
||||
const int32_t pos,
|
||||
const glm::vec2 coordinates[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Write indices to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param indices Array of indices to write.
|
||||
* @param len How many indices are in the array.
|
||||
*/
|
||||
virtual void bufferIndices(
|
||||
const int32_t pos,
|
||||
const int32_t indices[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Draw a primitive. Primitives are drawn by their indices.
|
||||
*
|
||||
* @param drawMode Which drawing mode to use to draw the primitive.
|
||||
* @param start Start indice (index) to draw.
|
||||
* @param count Count of indices to draw. Use -1 to draw all.
|
||||
*/
|
||||
virtual void draw(
|
||||
const enum MeshDrawMode drawMode,
|
||||
const int32_t start,
|
||||
const int32_t count
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Cleanup a previously initiated mesh.
|
||||
*/
|
||||
virtual ~IMesh() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const float_t depth
|
||||
) {
|
||||
glm::vec3 vertices[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec3(positions.x, positions.y, depth),
|
||||
glm::vec3(positions.z, positions.y, depth),
|
||||
glm::vec3(positions.x, positions.w, depth),
|
||||
glm::vec3(positions.z, positions.w, depth)
|
||||
};
|
||||
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
glm::vec2(coordinates.x, coordinates.w),
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
||||
|
||||
void QuadMesh::bufferWithIndex(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indexOffset
|
||||
) {
|
||||
glm::vec3 vertices[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec3(positions.x, positions.y, indexOffset),
|
||||
glm::vec3(positions.z, positions.y, indexOffset + 1),
|
||||
glm::vec3(positions.x, positions.w, indexOffset + 2),
|
||||
glm::vec3(positions.z, positions.w, indexOffset + 3)
|
||||
};
|
||||
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
glm::vec2(coordinates.x, coordinates.w),
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define QUAD_VERTICE_COUNT 4
|
||||
#define QUAD_INDICE_COUNT 6
|
||||
|
||||
namespace Dawn {
|
||||
class QuadMesh {
|
||||
public:
|
||||
/**
|
||||
* Buffers quad mesh vertices and indices into the given mesh.
|
||||
*
|
||||
* @param mesh The mesh to buffer into.
|
||||
* @param positions The positions of the vertices.
|
||||
* @param coordinates The coordinates of the vertices.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
* @param depth The depth of the vertices (Z coordinate).
|
||||
*/
|
||||
static void buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const float_t depth = 0.0f
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffers quad mesh vertices and indices into the given mesh. This will
|
||||
* store the index of the vertice in the Z component, allowing you to find
|
||||
* which vertex ID you are rendering in your shader.
|
||||
*
|
||||
* @param mesh The mesh to buffer into.
|
||||
* @param positions The positions of the vertices.
|
||||
* @param coordinates The coordinates of the vertices.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
* @param indexOffset The offset to add to the index of each vertex.
|
||||
*/
|
||||
static void bufferWithIndex(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indexOffset = 0
|
||||
);
|
||||
};
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IRenderPass {
|
||||
public:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
|
||||
/**
|
||||
* Binds the shader for this render pass.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Sets the data for this render pass to the shader.
|
||||
*/
|
||||
virtual void setData() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Draws the mesh for this render pass.
|
||||
*/
|
||||
virtual void draw() = 0;
|
||||
|
||||
/**
|
||||
* Cleans up the render pass.
|
||||
*/
|
||||
virtual ~IRenderPass() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/Game.hpp"
|
||||
#include "display/pass/IRenderPass.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
#include "component/display/MeshRenderer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<class S, typename D>
|
||||
class RenderPass : public IRenderPass {
|
||||
private:
|
||||
std::shared_ptr<S> shader;
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures;
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
const enum MeshDrawMode drawMode;
|
||||
const int32_t indiceStart;
|
||||
const int32_t indiceCount;
|
||||
const D data;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new RenderPass.
|
||||
*
|
||||
* @param self Self component instance that is creating this render pass.
|
||||
* @param d The data to use for this render pass.
|
||||
* @param mesh The mesh to use for this render pass.
|
||||
* @param drawMode The draw mode to use for this render pass.
|
||||
* @param indiceStart The indice to start drawing from.
|
||||
* @param indiceCount The number of indices to draw.
|
||||
*/
|
||||
RenderPass(
|
||||
SceneComponent &self,
|
||||
const D d,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures,
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const enum MeshDrawMode drawMode,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indiceCount
|
||||
) :
|
||||
data(d),
|
||||
textures(textures),
|
||||
mesh(mesh),
|
||||
drawMode(drawMode),
|
||||
indiceStart(indiceStart),
|
||||
indiceCount(indiceCount)
|
||||
{
|
||||
//Get the shader
|
||||
shader = (
|
||||
self.getGame()->renderHost.shaderManager.getShader<S>()
|
||||
);
|
||||
assertNotNull(shader, "Shader cannot be null!");
|
||||
|
||||
// Need mesh?
|
||||
if(!this->mesh) {
|
||||
auto meshRenderer = self.getItem()->getComponent<MeshRenderer>();
|
||||
if(meshRenderer) this->mesh = meshRenderer->mesh;
|
||||
}
|
||||
}
|
||||
|
||||
void bind() override {
|
||||
shader->bind();
|
||||
}
|
||||
|
||||
void setData() override {
|
||||
shader->setData(data);
|
||||
}
|
||||
|
||||
void upload() override {
|
||||
for(auto &pair : textures) {
|
||||
if(!pair.second->isReady()) continue;
|
||||
pair.second->bind(pair.first);
|
||||
}
|
||||
shader->upload();
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(mesh) {
|
||||
mesh->draw(drawMode, indiceStart, indiceCount);
|
||||
}
|
||||
}
|
||||
|
||||
~RenderPass() override {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/Game.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct RenderPassContext {
|
||||
std::shared_ptr<Game> game;
|
||||
std::shared_ptr<Scene> scene;
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<RenderTarget> renderTarget;
|
||||
};
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
size_t shaderParameterTypeGetSize(const enum ShaderParameterType type) {
|
||||
switch(type) {
|
||||
case ShaderParameterType::VEC2:
|
||||
return sizeof(glm::vec2);
|
||||
|
||||
case ShaderParameterType::VEC3:
|
||||
return sizeof(glm::vec3);
|
||||
|
||||
case ShaderParameterType::VEC4:
|
||||
return sizeof(glm::vec4);
|
||||
|
||||
case ShaderParameterType::MAT3:
|
||||
return sizeof(glm::mat3);
|
||||
|
||||
case ShaderParameterType::MAT4:
|
||||
return sizeof(glm::mat4);
|
||||
|
||||
case ShaderParameterType::COLOR:
|
||||
return sizeof(struct Color);
|
||||
|
||||
case ShaderParameterType::FLOAT:
|
||||
return sizeof(float);
|
||||
|
||||
case ShaderParameterType::INT:
|
||||
return sizeof(int32_t);
|
||||
|
||||
case ShaderParameterType::TEXTURE:
|
||||
return sizeof(shadertexturebinding_t);
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown ShaderParameterType");
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class ShaderParameterType {
|
||||
VEC2,
|
||||
VEC3,
|
||||
VEC4,
|
||||
MAT3,
|
||||
MAT4,
|
||||
COLOR,
|
||||
FLOAT,
|
||||
INT,
|
||||
TEXTURE,
|
||||
BOOLEAN
|
||||
};
|
||||
|
||||
class IShaderBase {
|
||||
public:
|
||||
virtual ~IShaderBase() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class IShader : public IShaderBase {
|
||||
protected:
|
||||
T data;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the currently uploaded data on the Shader.
|
||||
*
|
||||
* @return The uploaded data.
|
||||
*/
|
||||
T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entire data to be uploaded.
|
||||
*
|
||||
* @param data Data to be uploaded.
|
||||
*/
|
||||
void setData(const T data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the shader, this needs to be called before the shader can
|
||||
* be used.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Binds the shader as the current one, does not upload any data, somewhat
|
||||
* relies on something else uploading the data.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the shader.
|
||||
*/
|
||||
virtual ~IShader() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the ShaderParameterType.
|
||||
*
|
||||
* @param type The type to get the size of.
|
||||
* @return Size of the type.
|
||||
*/
|
||||
size_t shaderParameterTypeGetSize(const enum Dawn::ShaderParameterType type);
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IShaderStage.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IShaderStage::IShaderStage(const enum ShaderStageType type) :
|
||||
type(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IShaderStage::~IShaderStage() {
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class ShaderStageType {
|
||||
VERTEX,
|
||||
FRAGMENT,
|
||||
// COMPUTE
|
||||
};
|
||||
|
||||
class IShaderStage {
|
||||
public:
|
||||
const enum ShaderStageType type;
|
||||
|
||||
/**
|
||||
* Constructs a new Shader Stage.
|
||||
*
|
||||
* @param type Type of shader stage.
|
||||
*/
|
||||
IShaderStage(const enum ShaderStageType type);
|
||||
|
||||
/**
|
||||
* Destroy the IShaderStage object
|
||||
*/
|
||||
virtual ~IShaderStage();
|
||||
};
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ShaderManager {
|
||||
private:
|
||||
std::vector<std::shared_ptr<IShaderBase>> shaders;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Retreives an instance of the shader from the shader manager. If the
|
||||
* shader does not exist it will be created.
|
||||
*
|
||||
* @tparam T Type of shader to retreive.
|
||||
* @return Shader instance.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> getShader() {
|
||||
auto itShaders = shaders.begin();
|
||||
while(itShaders != shaders.end()) {
|
||||
// auto shader = itShaders->lock();
|
||||
// if(!shader) {
|
||||
// itShaders = shaders.erase(itShaders);
|
||||
// continue;
|
||||
// }
|
||||
// std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(shader);
|
||||
|
||||
auto shader = *itShaders;
|
||||
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(shader);
|
||||
if(casted) return casted;
|
||||
itShaders++;
|
||||
}
|
||||
|
||||
auto newShader = std::make_shared<T>();
|
||||
shaders.push_back(newShader);
|
||||
newShader->init();
|
||||
return newShader;
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Environment.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Environment environment;
|
||||
|
||||
bool_t Environment::hasVariable(const std::string &key) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
return this->variables.find(key) != this->variables.end();
|
||||
}
|
||||
|
||||
void Environment::setVariable(
|
||||
const std::string &key,
|
||||
const std::string &value
|
||||
) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
|
||||
this->variables[key] = value;
|
||||
}
|
||||
|
||||
std::string Environment::getVariable(const std::string &key) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
assertTrue(this->hasVariable(key), "Variable does not exist.");
|
||||
return this->variables[key];
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Environment {
|
||||
private:
|
||||
std::map<std::string, std::string> variables;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Checks if the environment has a variable.
|
||||
*
|
||||
* @param key Variable key to check.
|
||||
* @return True if the variable exists, false otherwise.
|
||||
*/
|
||||
bool_t hasVariable(const std::string &key);
|
||||
|
||||
/**
|
||||
* Sets a variable in the environment.
|
||||
*
|
||||
* @param key Variable key to set.
|
||||
* @param value Variable value to set.
|
||||
*/
|
||||
void setVariable(const std::string &key, const std::string &value);
|
||||
|
||||
/**
|
||||
* Gets a variable from the environment.
|
||||
*
|
||||
* @param key Variable key to get.
|
||||
* @return Variable value, or empty string if not found.
|
||||
*/
|
||||
std::string getVariable(const std::string &key);
|
||||
};
|
||||
}
|
||||
|
||||
extern Dawn::Environment environment;
|
@@ -1,141 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class CustomEventResult {
|
||||
NOTHING,
|
||||
REMOVE,
|
||||
INVOKE,
|
||||
INVOKE_AND_REMOVE
|
||||
};
|
||||
|
||||
template<
|
||||
typename InternalData,
|
||||
typename InternalListenerData,
|
||||
typename ListenerArgument,
|
||||
typename ...InvokeArgs
|
||||
>
|
||||
class CustomEvent {
|
||||
private:
|
||||
int32_t nextId = 0;
|
||||
std::unordered_map<
|
||||
int32_t,
|
||||
std::pair<InternalListenerData, std::function<void(InvokeArgs...)>>
|
||||
> listeners;
|
||||
|
||||
protected:
|
||||
InternalData internalData;
|
||||
|
||||
/**
|
||||
* Custom event filter. Decides whether or not the event should be emitted
|
||||
* to the listener.
|
||||
*
|
||||
* @param listenerData Data for this listener.
|
||||
* @param args The arguments to pass to the listeners.
|
||||
* @return The result of the filter.
|
||||
*/
|
||||
virtual enum CustomEventResult shouldEmit(
|
||||
const InternalListenerData &listenerData,
|
||||
const InvokeArgs... args
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Transform the arguments for listener data when the listener is first
|
||||
* subscribed.
|
||||
*
|
||||
* @param argument The argument to transform.
|
||||
* @return The transformed argument into an internal data format.
|
||||
*/
|
||||
virtual InternalListenerData transformData(
|
||||
const ListenerArgument &argument
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Transform the data for listener data after the event has been emitted.
|
||||
*
|
||||
* @param internalData The internal data to transform.
|
||||
* @return Updated/Transformed internal data.
|
||||
*/
|
||||
virtual InternalListenerData transformDataAfterEmit(
|
||||
const InternalListenerData &internalData
|
||||
) {
|
||||
return internalData;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Emits the event.
|
||||
* @param args The arguments to pass to the listeners.
|
||||
*/
|
||||
void emit(InvokeArgs... args) {
|
||||
auto copy = listeners;
|
||||
for(auto &pair : copy) {
|
||||
// Check emit test.
|
||||
auto result = this->shouldEmit(
|
||||
pair.second.first,
|
||||
args...
|
||||
);
|
||||
if(
|
||||
result == CustomEventResult::INVOKE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
pair.second.second(args...);
|
||||
}
|
||||
|
||||
if(
|
||||
result == CustomEventResult::REMOVE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
listeners.erase(pair.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(
|
||||
result == CustomEventResult::INVOKE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
// Update the internal data.
|
||||
listeners[pair.first].first = transformDataAfterEmit(
|
||||
pair.second.first
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the event.
|
||||
*
|
||||
* @param data Listener data to use.
|
||||
* @param listener The listener to add.
|
||||
* @returns A function that can be called to remove the listener.
|
||||
*/
|
||||
std::function<void()> listen(
|
||||
const ListenerArgument &data,
|
||||
const std::function<void(InvokeArgs...)> listener
|
||||
) {
|
||||
int32_t id = nextId++;
|
||||
|
||||
auto pair = std::make_pair(
|
||||
transformData(data),
|
||||
listener
|
||||
);
|
||||
|
||||
listeners[id] = pair;
|
||||
return [this, id]() {
|
||||
listeners.erase(id);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the custom event.
|
||||
*/
|
||||
virtual ~CustomEvent() {
|
||||
listeners.clear();
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<typename ...A>
|
||||
class Event {
|
||||
private:
|
||||
int32_t nextId = 0;
|
||||
std::map<int32_t, std::function<void(A...)>> listeners;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new Event.
|
||||
*/
|
||||
Event() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits the event.
|
||||
* @param args The arguments to pass to the listeners.
|
||||
*/
|
||||
void emit(A ...args) {
|
||||
auto copy = listeners;
|
||||
for(auto &pair : copy) {
|
||||
pair.second(args...);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the event.
|
||||
* @param listener The listener to add.
|
||||
* @returns A function that can be called to remove the listener.
|
||||
*/
|
||||
std::function<void()> listen(
|
||||
const std::function<void(A...)> listener
|
||||
) {
|
||||
int32_t id = nextId++;
|
||||
listeners[id] = listener;
|
||||
return [this, id]() {
|
||||
listeners.erase(id);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the event.
|
||||
*/
|
||||
virtual ~Event() {
|
||||
listeners.clear();
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Game.cpp
|
||||
)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user