Compare commits
8 Commits
test
...
old_engine
Author | SHA1 | Date | |
---|---|---|---|
c916e1a6cf | |||
50a0847f53 | |||
2dc4d23151 | |||
4b77d1b613 | |||
04be82f034 | |||
3bc2f0d372 | |||
bba4a83240 | |||
fec8771c75 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -65,7 +65,7 @@ CTestTestfile.cmake
|
|||||||
_deps
|
_deps
|
||||||
|
|
||||||
# Custom
|
# Custom
|
||||||
/build/*
|
build
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
assets/testworld/tileset.png
|
assets/testworld/tileset.png
|
||||||
@ -86,4 +86,6 @@ assets/borrowed
|
|||||||
|
|
||||||
._*
|
._*
|
||||||
|
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
archive/*
|
18
.gitmodules
vendored
18
.gitmodules
vendored
@ -1,6 +1,24 @@
|
|||||||
|
[submodule "lib/glfw"]
|
||||||
|
path = lib/glfw
|
||||||
|
url = https://github.com/glfw/glfw.git
|
||||||
|
[submodule "lib/glm"]
|
||||||
|
path = lib/glm
|
||||||
|
url = https://github.com/g-truc/glm.git
|
||||||
|
[submodule "lib/SDL"]
|
||||||
|
path = lib/SDL
|
||||||
|
url = https://github.com/libsdl-org/SDL.git
|
||||||
[submodule "lib/openal-soft"]
|
[submodule "lib/openal-soft"]
|
||||||
path = lib/openal-soft
|
path = lib/openal-soft
|
||||||
url = https://github.com/kcat/openal-soft
|
url = https://github.com/kcat/openal-soft
|
||||||
[submodule "lib/AudioFile"]
|
[submodule "lib/AudioFile"]
|
||||||
path = lib/AudioFile
|
path = lib/AudioFile
|
||||||
url = https://github.com/adamstark/AudioFile.git
|
url = https://github.com/adamstark/AudioFile.git
|
||||||
|
[submodule "lib/freetype"]
|
||||||
|
path = lib/freetype
|
||||||
|
url = https://gitlab.freedesktop.org/freetype/freetype.git
|
||||||
|
[submodule "lib/libarchive"]
|
||||||
|
path = lib/libarchive
|
||||||
|
url = https://github.com/libarchive/libarchive
|
||||||
|
[submodule "lib/boxer"]
|
||||||
|
path = lib/boxer
|
||||||
|
url = https://github.com/aaronmjacobs/Boxer
|
||||||
|
@ -8,36 +8,99 @@ set(CMAKE_C_STANDARD 99)
|
|||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
||||||
|
|
||||||
|
set(DAWN_PROJECT_NAME "Dawn")
|
||||||
|
set(DAWN_PROJECT_VERSION "01.00")
|
||||||
|
|
||||||
# Variable Caches
|
# Variable Caches
|
||||||
set(DAWN_CACHE_TARGET "dawn-target")
|
set(DAWN_CACHE_TARGET "dawn-target")
|
||||||
set(DAWN_TARGET_NAME "Dawn")
|
|
||||||
|
|
||||||
if(NOT DEFINED DAWN_TARGET)
|
# Build target
|
||||||
set(DAWN_TARGET linux-x64-glfw CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
if(DEFINED ENV{DAWN_BUILD_SYSTEM})
|
||||||
|
set(DAWN_BUILD_SYSTEM $ENV{DAWN_BUILD_SYSTEM} CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
else()
|
||||||
|
set(DAWN_BUILD_SYSTEM "linux" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Build tools specifics
|
||||||
|
if(DAWN_BUILD_SYSTEM STREQUAL "vita")
|
||||||
|
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||||
|
if(DEFINED ENV{VITASDK})
|
||||||
|
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
|
||||||
|
|
||||||
|
set(DAWN_VITA_APP_NAME "${DAWN_PROJECT_NAME}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
set(DAWN_VITA_TITLEID "YWSH00001" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
set(DAWN_VITA_VERSION "${DAWN_PROJECT_VERSION}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
|
||||||
|
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||||
|
if(DEFINED ENV{PSPDEV})
|
||||||
|
set(CMAKE_TOOLCHAIN_FILE "$ENV{PSPDEV}/psp/share/pspdev.cmake" CACHE PATH "toolchain file")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please define PSPDEV to point to your SDK path!")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include("$ENV{PSPDEV}/psp/share/pspdev.cmake" REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set Common Build Variables
|
# Set Common Build Variables
|
||||||
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||||
set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
||||||
set(DAWN_SOURCES_DIR "${DAWN_ROOT_DIR}/src")
|
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_TEMP_DIR "${DAWN_BUILD_DIR}/temp")
|
||||||
|
set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools")
|
||||||
|
set(DAWN_ASSETS_DIR "${DAWN_ROOT_DIR}/assets")
|
||||||
|
set(DAWN_ASSETS_BUILD_DIR "${DAWN_BUILD_DIR}/assets")
|
||||||
|
|
||||||
# Initialize Project.
|
# Variables
|
||||||
project(Dawn
|
set(DAWN_TARGET_NAME "Dawn" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
VERSION 1.0.0
|
set(DAWN_ASSETS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/Dawn CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||||
|
|
||||||
|
# Initialize Project First.
|
||||||
|
project("${DAWN_PROJECT_NAME}"
|
||||||
|
VERSION "${DAWN_PROJECT_VERSION}"
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(${DAWN_TARGET_NAME})
|
||||||
|
|
||||||
# Add tools
|
# Add tools
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
|
|
||||||
# Add Libraries
|
# Libraries
|
||||||
add_subdirectory(lib)
|
add_subdirectory(lib)
|
||||||
|
|
||||||
# Add Project Files
|
# Sources
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
# Append assets
|
||||||
|
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||||
|
|
||||||
|
if(DAWN_BUILD_SYSTEM STREQUAL "vita")
|
||||||
|
vita_create_self(${DAWN_TARGET_NAME}.self ${DAWN_BUILD_BINARY})
|
||||||
|
vita_create_vpk(
|
||||||
|
${DAWN_TARGET_NAME}.vpk
|
||||||
|
${DAWN_VITA_TITLEID}
|
||||||
|
${DAWN_TARGET_NAME}.self
|
||||||
|
VERSION ${DAWN_VITA_VERSION}
|
||||||
|
NAME ${DAWN_VITA_APP_NAME}
|
||||||
|
)
|
||||||
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
|
||||||
|
create_pbp_file(
|
||||||
|
TARGET ${PROJECT_NAME}
|
||||||
|
ICON_PATH NULL
|
||||||
|
BACKGROUND_PATH NULL
|
||||||
|
PREVIEW_PATH NULL
|
||||||
|
TITLE ${PROJECT_NAME}
|
||||||
|
VERSION ${DAWN_PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
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
|
|
||||||
]
|
|
||||||
}
|
|
3
ci/linux-x64/Dockerfile
Normal file
3
ci/linux-x64/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM debian:latest
|
||||||
|
RUN apt update && apt upgrade -y && apt install -y git cmake build-essential libx11-dev libgtk-3-dev python3 python3-pip
|
||||||
|
RUN ln -s /usr/bin/python3 /usr/bin/python
|
18
ci/linux-x64/docker-compose.yml
Normal file
18
ci/linux-x64/docker-compose.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
services:
|
||||||
|
dawn-linux64:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- ./../../:/Dawn
|
||||||
|
working_dir: /Dawn
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
ln -s /usr/bin/python3 /usr/bin/python
|
||||||
|
if [ ! -d ./lib/glfw ]; then
|
||||||
|
git submodule update --init
|
||||||
|
fi
|
||||||
|
mkdir -p ./build/linux-x64
|
||||||
|
cd ./build/linux-x64
|
||||||
|
cmake ../.. -DDAWN_BUILD_SYSTEM=linux -DGLFW_BUILD_X11=ON -DGLFW_BUILD_WAYLAND=OFF
|
||||||
|
make
|
3
ci/psp/Dockerfile
Normal file
3
ci/psp/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM pspdev/pspdev
|
||||||
|
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
|
||||||
|
RUN psp-pacman -Sy pspgl glm
|
14
ci/psp/docker-compose.yml
Normal file
14
ci/psp/docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
dawn-psp:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- ./../../:/Dawn
|
||||||
|
working_dir: /Dawn
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
mkdir -p ./build/psp
|
||||||
|
cd ./build/psp
|
||||||
|
psp-cmake ../.. -DDAWN_BUILD_SYSTEM=psp -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
make
|
15
ci/vita/docker-compose.yml
Normal file
15
ci/vita/docker-compose.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
services:
|
||||||
|
dawn-vita:
|
||||||
|
image: gnuton/vitasdk-docker
|
||||||
|
volumes:
|
||||||
|
- ./../../:/Dawn
|
||||||
|
working_dir: /Dawn
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
rm -rf ./build/vita
|
||||||
|
mkdir -p ./build/vita
|
||||||
|
cd ./build/vita
|
||||||
|
cmake ../.. -DDAWN_BUILD_SYSTEM=vita -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
make
|
340
docs/COMPILING.md
Normal file
340
docs/COMPILING.md
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
# Compiling, Debugging and Running
|
||||||
|
This document's purpose is to explain how to compile, debug and run the project
|
||||||
|
on your machine. It is assumed that you have a basic understanding of the
|
||||||
|
fundamentals of your operating system and how to use a terminal.
|
||||||
|
|
||||||
|
## Preamble
|
||||||
|
The Dawn project is written almost entirely in C and C++. This includes all of
|
||||||
|
the tooling used to generate the project and assets. The only non-C/C++ code is
|
||||||
|
used by CMake to generate the output compilation files. This provides the Dawn
|
||||||
|
project an extremely high level of portability not typically seen in other
|
||||||
|
projects.
|
||||||
|
|
||||||
|
## TLDR; Version
|
||||||
|
This document is going to go over the installation and configuration of the
|
||||||
|
following items. If you are already familiar with these tools, you can skip to
|
||||||
|
the "Downloading the Source Code" section.
|
||||||
|
- C/C++ Compiler
|
||||||
|
- CMake
|
||||||
|
- Git
|
||||||
|
- IDE
|
||||||
|
You may also need *python*, since we depend on third-party libraries that may use
|
||||||
|
python scripts to generate their own build files. This is not required for the
|
||||||
|
Dawn project itself.
|
||||||
|
|
||||||
|
## Pre-Configuration
|
||||||
|
In order to compile the Dawn project, you are required to have the following
|
||||||
|
tools installed on your machine.
|
||||||
|
|
||||||
|
### 1. A C/C++ Compiler
|
||||||
|
The exact tool(s) will depend on your specific scenario. The compiler is used to
|
||||||
|
take the .cpp/.hpp files and generating binaries that execute on the target
|
||||||
|
machine. Typically you will use your own C/C++ compiler for the machine that you
|
||||||
|
are currently running, e.g. if you are running Windows, you will use the Visual
|
||||||
|
Studio compiler. If you are running Linux, you will use GCC or Clang. If you are
|
||||||
|
running macOS, you will use Clang, and so-on.
|
||||||
|
|
||||||
|
If you are intending to compile on a different machine than the one you are
|
||||||
|
currently running, you will need to use a cross-compiler that is specific for
|
||||||
|
your use-case. You will also need to refer to the documentation for creating a
|
||||||
|
new Dawn engine target.
|
||||||
|
|
||||||
|
Please follow the instructions for your specific operating system to install the
|
||||||
|
appropriate C/C++ compiler.
|
||||||
|
|
||||||
|
**Windows**
|
||||||
|
You will need to download and install [Visual Studio](https://visualstudio.microsoft.com/downloads/).
|
||||||
|
Visual Studio (not to be confused with Visual Studio Code) is a full IDE that
|
||||||
|
bundles the official Microsoft C/C++ compiler. It is the recommended compiler
|
||||||
|
for building the Dawn project on Windows.
|
||||||
|
|
||||||
|
Advanced used can also use [MinGW](http://www.mingw.org/) or another compiler if
|
||||||
|
they wish, however this is not officially supported.
|
||||||
|
|
||||||
|
After installing Visual Studio, you will need to install the C++ development
|
||||||
|
tools. This can be done by opening the Visual Studio Installer and selecting
|
||||||
|
the "Desktop development with C++" workload.
|
||||||
|
|
||||||
|
**Linux**
|
||||||
|
You will need to install the GCC and Clang compilers. The compilers are usually
|
||||||
|
installed either by default or by installing the necessary packages for your
|
||||||
|
Linux distribution.
|
||||||
|
|
||||||
|
For example, on Ubuntu, you can install the GCC and Clang compilers by running
|
||||||
|
the following command:
|
||||||
|
```bash
|
||||||
|
sudo apt install build-essential clang
|
||||||
|
```
|
||||||
|
|
||||||
|
On Arch Linux, you can install the GCC and Clang compilers by running the
|
||||||
|
following command:
|
||||||
|
```bash
|
||||||
|
sudo pacman -S base-devel clang
|
||||||
|
```
|
||||||
|
|
||||||
|
And on Fedora, you can install the GCC and Clang compilers by running the
|
||||||
|
following command:
|
||||||
|
```bash
|
||||||
|
sudo dnf install @development-tools clang
|
||||||
|
```
|
||||||
|
|
||||||
|
For other distributions, please refer to your distribution's documentation.
|
||||||
|
|
||||||
|
**macOS**
|
||||||
|
You will need to install the Xcode command line tools. This can be done by done
|
||||||
|
by running the following command in your terminal:
|
||||||
|
```bash
|
||||||
|
xcode-select --install
|
||||||
|
```
|
||||||
|
|
||||||
|
Afterwards you will need to install and enable [Brew](https://brew.sh/). This
|
||||||
|
can be done by running the following command in your terminal:
|
||||||
|
```bash
|
||||||
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 2. CMake
|
||||||
|
CMake is a tool that is used to generate the compilation files for the Dawn
|
||||||
|
project. In short this is used to create versions of the Dawn project that can
|
||||||
|
be compiled on all different sets of compilers, so if you are compiling on, for
|
||||||
|
example, Windows, you can use CMake to generate the compilation files for the
|
||||||
|
Visual Studio compiler, or if you are compiling on Linux, you can use CMake to
|
||||||
|
generate the compilation files for the GCC or Clang compilers, and so-on.
|
||||||
|
|
||||||
|
To install CMake, please follow the instructions for your specific operating
|
||||||
|
system. All other operating systems can be found on the [CMake downloads page](https://cmake.org/download/).
|
||||||
|
|
||||||
|
**Windows**
|
||||||
|
You will need to download and install [CMake](https://cmake.org/download/). The
|
||||||
|
installer will guide you through the installation process and will install the
|
||||||
|
CMake executable to your system. It is recommended that you add CMake to your
|
||||||
|
system PATH if requested by the installer.
|
||||||
|
|
||||||
|
**Linux**
|
||||||
|
Like installing the C/C++ compilers, you will need to install CMake using your
|
||||||
|
specific Linux distribution's package manager, there is also a chance that CMake
|
||||||
|
can be installed using flatpak or snap. Please refer to your distribution's
|
||||||
|
documentation for more information.
|
||||||
|
|
||||||
|
For Ubuntu and other Debian-based distributions, you can install CMake by using
|
||||||
|
the following command:
|
||||||
|
```bash
|
||||||
|
sudo apt install cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
For Arch Linux, you can install CMake by using the following command:
|
||||||
|
```bash
|
||||||
|
sudo pacman -S cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
And for Fedora, you can install CMake by using the following command:
|
||||||
|
```bash
|
||||||
|
sudo dnf install cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
**macOS**
|
||||||
|
You will install CMake using brew. We detailed how to install brew in the C/C++
|
||||||
|
compiler section. To install CMake, run the following command in your terminal:
|
||||||
|
```bash
|
||||||
|
brew install cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Git
|
||||||
|
Git is a version control system that is used to manage the Dawn project's source
|
||||||
|
code. It is used to download the source code, and to update the source code to
|
||||||
|
the latest version. It is also used to manage the project's dependencies. Git is
|
||||||
|
a standard tool in the programming industry and is used to manage complex
|
||||||
|
projects, especially those that are worked on by multiple people.
|
||||||
|
|
||||||
|
Git, like all of the above tools, is installed slightly differently depending on
|
||||||
|
your operating system. Please follow the instructions for your specific
|
||||||
|
operating system.
|
||||||
|
|
||||||
|
**Windows**
|
||||||
|
You will need to download and install [Git](https://git-scm.com/downloads). The
|
||||||
|
installer will guide you through the installation process and will install the
|
||||||
|
Git executable to your system. It is recommended that you add Git to your system
|
||||||
|
PATH if requested by the installer. You do not need to add the Context-menu
|
||||||
|
items to your system.
|
||||||
|
|
||||||
|
**Linux**
|
||||||
|
Like installing the C/C++ compilers, you will need to install Git using your
|
||||||
|
specific Linux distribution's package manager. It is also likely that git would
|
||||||
|
have been installed by default. Please refer to your distribution's docs for
|
||||||
|
more information.
|
||||||
|
|
||||||
|
For Ubuntu and other Debian-based distributions, you can install Git by using
|
||||||
|
the following command:
|
||||||
|
```bash
|
||||||
|
sudo apt install git
|
||||||
|
```
|
||||||
|
|
||||||
|
For Arch Linux, you can install Git by using the following command:
|
||||||
|
```bash
|
||||||
|
sudo pacman -S git
|
||||||
|
```
|
||||||
|
|
||||||
|
And for Fedora, you can install Git by using the following command:
|
||||||
|
```bash
|
||||||
|
sudo dnf install git
|
||||||
|
```
|
||||||
|
|
||||||
|
**macOS**
|
||||||
|
You will install Git using brew. We detailed how to install brew in the C/C++
|
||||||
|
compiler section. To install Git, run the following command in your terminal:
|
||||||
|
```bash
|
||||||
|
brew install git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. An IDE
|
||||||
|
An IDE (Integrated Development Environment) is a tool that is used to view and
|
||||||
|
edit code of projects. While it is not required to use an IDE, it is recommended
|
||||||
|
since it can make the process of editing and running the project much easier.
|
||||||
|
|
||||||
|
There are many different IDEs available, and often people chose an IDE that will
|
||||||
|
suit their preferences and needs, however if you are unsure of which IDE you
|
||||||
|
should be using, the Dawn project recommends using [Visual Studio Code](https://code.visualstudio.com/),
|
||||||
|
not to be confused with Visual Studio.
|
||||||
|
|
||||||
|
Visual Studio Code is a free and open-source IDE that is widely used in the
|
||||||
|
industry for its simple, modern and configurable interface. For example you can
|
||||||
|
configure VSCode to work on Web Projects, Game Projects, and more. It acts like
|
||||||
|
a text editor with a bunch of extra tools.
|
||||||
|
|
||||||
|
In addition to installing the VSCode IDE, we will add several recommended
|
||||||
|
plugins that will make editing the Dawn project easier and more seamless.
|
||||||
|
|
||||||
|
To install VSCode follow the instructions for your specific operating system on
|
||||||
|
the [VSCode downloads page](https://code.visualstudio.com/download), as it can
|
||||||
|
vary a lot between operating systems.
|
||||||
|
|
||||||
|
After installing VSCode, you will need to install the following plugins, by
|
||||||
|
clicking on the "Extensions" icon on the left-hand side of the VSCode window,
|
||||||
|
and searching for the following plugins. You may also be able to click on the
|
||||||
|
following links to install the plugins directly, but it may not work.
|
||||||
|
- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
|
||||||
|
- [CMake](https://marketplace.visualstudio.com/items?itemName=twxs.cmake)
|
||||||
|
- [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
|
||||||
|
|
||||||
|
## Downloading the Source Code
|
||||||
|
Now that you have all of the necessary tools installed, you can download the
|
||||||
|
source code of the project and using it to build. The source code contains all
|
||||||
|
of the code of the project, as well as the assets and the build scripts. This is
|
||||||
|
confidential information and should not be shared with anyone.
|
||||||
|
|
||||||
|
### 1. Cloning the Repository
|
||||||
|
We previously installed the git tool, which is used to download the source code
|
||||||
|
of the project, and some third-party libraries. To download the source code, you
|
||||||
|
will need to open a terminal and navigate to the directory where you want to
|
||||||
|
download the source code to.
|
||||||
|
|
||||||
|
Afterwards, you will need to run the following command:
|
||||||
|
```bash
|
||||||
|
git clone https://git.wish.moe/YourWishes/Dawn.git
|
||||||
|
```
|
||||||
|
This will download the source code of the project to a new subdirectory called
|
||||||
|
"Dawn" and put all of the projects' source code within there.
|
||||||
|
|
||||||
|
### 2. Installing the Dependencies / Libraries.
|
||||||
|
I try to keep dependencies on third-party libraries to a minimum, however there
|
||||||
|
are a few libraries that are required to build the Dawn project. These libraries
|
||||||
|
are not included in the source code, and must be downloaded separately. This is
|
||||||
|
done using the git tool.
|
||||||
|
|
||||||
|
After you have cloned the above repository, you will need to open a terminal and
|
||||||
|
navigate to the directory where you downloaded the source code to. Afterwards,
|
||||||
|
you will need to run the following command:
|
||||||
|
```bash
|
||||||
|
git submodule update --init --recursive
|
||||||
|
```
|
||||||
|
This will fetch all of the third-party libraries that are required to build the
|
||||||
|
Dawn project. This may take a while depending on your internet connection.
|
||||||
|
|
||||||
|
### 3. Loading the Project
|
||||||
|
This step is semi-optional. We are aiming to build the project using CMake, and
|
||||||
|
the easiest way to do this is to use the CMake Tools plugin for VSCode that we
|
||||||
|
installed earlier. This plugin will automatically detect the CMake files in the
|
||||||
|
project and will allow us to build the project using the VSCode interface.
|
||||||
|
|
||||||
|
If you opted out of using VSCode, you will need to set up your CMake environment
|
||||||
|
to suit your IDE or needs. This is outside of the scope of this document, and
|
||||||
|
you will need to refer to your IDE's documentation for more information.
|
||||||
|
|
||||||
|
To load the project, you will need to open VSCode and open the Dawn project
|
||||||
|
directory. Most operating systems will allow you to do this by dragging the
|
||||||
|
Dawn project directory onto the VSCode window. If this does not work, you can
|
||||||
|
open VSCode and click on the "File" menu, and click on "Open Folder". You will
|
||||||
|
then need to navigate to the Dawn project directory and click "Open".
|
||||||
|
|
||||||
|
Afterwards you will likely be prompted autometically to configure the CMake
|
||||||
|
Tools plugin. If you are not, you can click on the "CMake" icon on the left-hand
|
||||||
|
side of the VSCode window, and click on "Configure". This will configure the
|
||||||
|
CMake Tools plugin to use the CMake files in the Dawn project directory.
|
||||||
|
|
||||||
|
You may also be asked to select a compiler. If you are using Windows, you will
|
||||||
|
need to select the Visual Studio compiler. If you are using Linux, you will need
|
||||||
|
to select the GCC or Clang compiler. If you are using macOS, you will need to
|
||||||
|
select the Clang compiler. If you are using a different compiler, you will need
|
||||||
|
to select the appropriate compiler.
|
||||||
|
|
||||||
|
If prompted to select a build type, select "Debug".
|
||||||
|
|
||||||
|
## Compiling the Project
|
||||||
|
Now that we have the project loaded into our IDE, we can compile the project.
|
||||||
|
This is done using the CMake Tools plugin for VSCode. If you are not using
|
||||||
|
VSCode you will need to refer to your IDE's documentation for more information.
|
||||||
|
|
||||||
|
Firstly, you will need to create a settings file to configure the project. In
|
||||||
|
VSCode you can create a new folder called `.vscode` (Including the leading `.`)
|
||||||
|
in the Dawn project root directory. Afterwards, you will need to create a new
|
||||||
|
file called `settings.json` in the `.vscode` directory. You will then need to
|
||||||
|
paste the following into the file:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"cmake.configureArgs": [
|
||||||
|
"-DDAWN_BUILD_TOOLS=true",
|
||||||
|
"-DDAWN_BUILD_TARGET=target-liminal-win32-glfw",
|
||||||
|
"-DDAWN_DEBUG_BUILD=true"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
And save the file. You may want to alter the values to suit your needs. For
|
||||||
|
example, if you are compiling on Linux, you will need to change
|
||||||
|
`target-liminal-win32-glfw` to `target-liminal-linux-glfw`. If you are compiling
|
||||||
|
on macOS, you will need to change it to `target-liminal-osx-glfw`. The specific
|
||||||
|
configure arguments are outside of the scope of this document, and you will need
|
||||||
|
to refer to the specific target documentation for more information.
|
||||||
|
|
||||||
|
After you have created the settings file, you will need to configure and build
|
||||||
|
the project. To perform the build you need to click "Build" button the bottom of
|
||||||
|
the VSCode window. This will compile the project and will output the resulting
|
||||||
|
binaries in to a "build" directory within the Dawn project directory.
|
||||||
|
|
||||||
|
Upon clicking the "Build" button, you will see an output panel appear at the
|
||||||
|
bottom of the VSCode window. This will show the process of the build, and will
|
||||||
|
show any errors that may occur. This is used to debug and fix any issues that
|
||||||
|
may occur during the build process.
|
||||||
|
|
||||||
|
If the build was successful, you will see a "Build finished" message in the
|
||||||
|
output panel, typically read as;
|
||||||
|
```bash
|
||||||
|
[build] Build finished with exit code 0
|
||||||
|
```
|
||||||
|
If you do not see this message, or if the exit code is not 0, you will need to
|
||||||
|
debug the issue. The output panel will show the error message which is helpful
|
||||||
|
so we can debug the issue. If you are unable to debug the issue, you can ask for
|
||||||
|
help in the Discord server.
|
||||||
|
|
||||||
|
## Running the built project
|
||||||
|
After the build process succeeds you will be able to run the project. This is
|
||||||
|
done by clicking on the Run icon, which looks like a play button, on the bottom
|
||||||
|
of the VSCode window. This will run the project in production mode and will not
|
||||||
|
show any debug information.
|
||||||
|
|
||||||
|
If the program hangs, crashes or does not run, you can click the Debug icon,
|
||||||
|
which looks like a ladybug, on the bottom of the VSCode window. This will run
|
||||||
|
the project in debug mode and will show debug information and HALT the program
|
||||||
|
if there is an error detected. If program HALTS in debug mode you can use this
|
||||||
|
information to debug the issue. If you are unable to debug the issue, you can
|
||||||
|
ask for help in the Discord server.
|
@ -3,40 +3,29 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
include(FetchContent)
|
# GLFW/GLAD
|
||||||
|
if(DAWN_BUILD_SYSTEM STREQUAL "linux")
|
||||||
|
add_subdirectory(glad)
|
||||||
|
add_subdirectory(glfw)
|
||||||
|
add_subdirectory(libarchive)
|
||||||
|
add_subdirectory(glm)
|
||||||
|
|
||||||
# GLM
|
set(LIBTYPE "STATIC")
|
||||||
FetchContent_Declare(
|
add_subdirectory(openal-soft)
|
||||||
glm
|
|
||||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
|
||||||
GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(glm)
|
|
||||||
|
|
||||||
# JSON
|
set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
|
||||||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
|
set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)
|
||||||
FetchContent_MakeAvailable(json)
|
add_subdirectory(AudioFile)
|
||||||
|
|
||||||
# GLAD
|
add_subdirectory(freetype)
|
||||||
add_subdirectory(glad)
|
|
||||||
|
|
||||||
# GLFW
|
add_subdirectory(boxer)
|
||||||
FetchContent_Declare(glfw URL https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip)
|
target_compile_definitions(Boxer PRIVATE UNICODE)
|
||||||
FetchContent_MakeAvailable(glfw)
|
|
||||||
|
|
||||||
# LibArchive
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "vita")
|
||||||
FetchContent_Declare(libarchive URL https://github.com/libarchive/libarchive/releases/download/v3.7.6/libarchive-3.7.6.tar.xz)
|
add_subdirectory(glm)
|
||||||
FetchContent_MakeAvailable(libarchive)
|
|
||||||
|
|
||||||
# FreeType
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
|
||||||
FetchContent_Declare(freetype URL https://psychz.dl.sourceforge.net/project/freetype/freetype2/2.13.3/freetype-2.13.3.tar.xz?viasf=1)
|
add_subdirectory(glm)
|
||||||
FetchContent_MakeAvailable(freetype)
|
|
||||||
|
|
||||||
# if(DAWN_TARGET_OPENAL)
|
endif()
|
||||||
# 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
lib/SDL
Submodule
1
lib/SDL
Submodule
Submodule lib/SDL added at fb1497566c
1
lib/boxer
Submodule
1
lib/boxer
Submodule
Submodule lib/boxer added at 65e79c38f1
1
lib/freetype
Submodule
1
lib/freetype
Submodule
Submodule lib/freetype added at 7ff43d3e9f
1
lib/glfw
Submodule
1
lib/glfw
Submodule
Submodule lib/glfw added at b35641f4a3
1
lib/glm
Submodule
1
lib/glm
Submodule
Submodule lib/glm added at 45008b225e
1
lib/libarchive
Submodule
1
lib/libarchive
Submodule
Submodule lib/libarchive added at 313aa1fa10
@ -3,21 +3,22 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Build Project
|
|
||||||
add_executable(${DAWN_TARGET_NAME})
|
|
||||||
|
|
||||||
# Add in base library
|
if(DAWN_BUILD_SYSTEM STREQUAL "linux")
|
||||||
add_subdirectory(dawn)
|
add_subdirectory(dawn)
|
||||||
|
|
||||||
# Compile entry targets
|
|
||||||
if(DAWN_TARGET STREQUAL "linux-x64-glfw")
|
|
||||||
add_subdirectory(dawnlinux)
|
|
||||||
add_subdirectory(dawnglfw)
|
add_subdirectory(dawnglfw)
|
||||||
|
add_subdirectory(dawnlinux)
|
||||||
add_subdirectory(dawnopengl)
|
add_subdirectory(dawnopengl)
|
||||||
add_subdirectory(dawnrpg)
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "vita")
|
||||||
|
add_subdirectory(dawn)
|
||||||
|
add_subdirectory(dawnvita)
|
||||||
|
add_subdirectory(dawnopengl)
|
||||||
|
elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
|
||||||
|
set(DAWN_OPENGL_SHADERS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
|
||||||
|
set(DAWN_OPENGL_FRAMEBUFFERS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
|
||||||
|
set(DAWN_OPENGL_MIPMAPS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
|
||||||
|
add_subdirectory(dawn)
|
||||||
|
add_subdirectory(dawnpsp)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "You need to define an entry target")
|
message(FATAL_ERROR "Unknown build system: ${DAWN_BUILD_SYSTEM}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Compress the game assets.
|
|
||||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
|
@ -1,40 +1,35 @@
|
|||||||
# Copyright (c) 2022 Dominic Masters
|
# Copyright (c) 2024 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
target_link_libraries(${DAWN_TARGET_NAME}
|
target_link_libraries(${DAWN_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
glm::glm
|
)
|
||||||
archive_static
|
|
||||||
freetype
|
# Includes
|
||||||
nlohmann_json::nlohmann_json
|
target_include_directories(${DAWN_TARGET_NAME}
|
||||||
)
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
# Includes
|
)
|
||||||
target_include_directories(${DAWN_TARGET_NAME}
|
|
||||||
PUBLIC
|
# Sources
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
)
|
PRIVATE
|
||||||
|
|
||||||
# Subdirs
|
)
|
||||||
add_subdirectory(assert)
|
|
||||||
add_subdirectory(asset)
|
# Subdirs
|
||||||
add_subdirectory(audio)
|
add_subdirectory(error)
|
||||||
add_subdirectory(component)
|
add_subdirectory(game)
|
||||||
add_subdirectory(display)
|
add_subdirectory(locale)
|
||||||
add_subdirectory(environment)
|
add_subdirectory(scene)
|
||||||
add_subdirectory(game)
|
add_subdirectory(util)
|
||||||
# add_subdirectory(games)
|
|
||||||
# add_subdirectory(input)
|
# Textures
|
||||||
add_subdirectory(locale)
|
# tool_texture(texture_test
|
||||||
add_subdirectory(prefab)
|
# FILE=${DAWN_ASSETS_DIR}/texture_test.png
|
||||||
# add_subdirectory(physics)
|
# FILTER_MIN=NEAREST
|
||||||
add_subdirectory(poker)
|
# FILTER_MAG=NEAREST
|
||||||
add_subdirectory(save)
|
# )
|
||||||
add_subdirectory(scene)
|
|
||||||
# add_subdirectory(state)
|
|
||||||
add_subdirectory(time)
|
|
||||||
add_subdirectory(util)
|
|
||||||
add_subdirectory(ui)
|
|
@ -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,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,12 +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
|
|
||||||
TextureLoader.cpp
|
|
||||||
TrueTypeLoader.cpp
|
|
||||||
JSONLoader.cpp
|
|
||||||
)
|
|
@ -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,10 +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
|
|
||||||
IAudioManager.cpp
|
|
||||||
)
|
|
@ -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,13 +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
|
|
||||||
Camera.cpp
|
|
||||||
MeshRenderer.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# Subdirs
|
|
||||||
add_subdirectory(material)
|
|
@ -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);
|
|
||||||
};
|
|
||||||
}
|
|
37
src/dawn/dawn.hpp
Normal file
37
src/dawn/dawn.hpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define DAWN_GAME_NAME "Dawn"
|
||||||
|
#define DAWN_GAME_NAME_U8 u8"Dawn"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <map>
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
// #define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
// #include <glm/glm.hpp>
|
||||||
|
// #include <glm/gtc/type_ptr.hpp>
|
||||||
|
// #include <glm/gtx/matrix_decompose.hpp>
|
||||||
|
|
||||||
|
typedef char char_t;
|
||||||
|
typedef char8_t u8char_t;
|
||||||
|
typedef float float_t;
|
||||||
|
typedef double double_t;
|
||||||
|
typedef bool bool_t;
|
@ -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,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,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,11 +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
|
|
||||||
CubeMesh.cpp
|
|
||||||
QuadMesh.cpp
|
|
||||||
)
|
|
@ -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,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,10 +0,0 @@
|
|||||||
# Copyright (c) 2023 Dominic Msters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
# Sources
|
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
|
||||||
PRIVATE
|
|
||||||
Environment.cpp
|
|
||||||
)
|
|
@ -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;
|
|
25
src/dawn/error/assert.cpp
Normal file
25
src/dawn/error/assert.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (c) 2024 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) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
fprintf(stderr, "Assertion failed in %s:%d (%s): ", file, line, func);
|
||||||
|
vfprintf(stderr, message, args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
va_end(args);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that a given statement must evaluate to true or the assertion fails
|
* Asserts that a given statement must evaluate to true or the assertion fails
|
||||||
@ -84,17 +84,6 @@ void assertTrueImplement(
|
|||||||
map.find(key) != map.end(), __VA_ARGS__ \
|
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.
|
* Asserts that a given value has a specific flag turned off.
|
||||||
*
|
*
|
22
src/dawn/error/error.hpp
Normal file
22
src/dawn/error/error.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawn.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows an error message box on the host device. This method should be blocking
|
||||||
|
* and should not return until the user has acknowledged the error.
|
||||||
|
*
|
||||||
|
* @param message Message to display.
|
||||||
|
*/
|
||||||
|
void errorMessageBox(const std::u8string &message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an error message to the host device.
|
||||||
|
*
|
||||||
|
* @param message Message to log.
|
||||||
|
*/
|
||||||
|
void errorLog(const std::string &message);
|
@ -4,7 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2022 Dominic Masters
|
# Copyright (c) 2024 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2024 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "game/Game.hpp"
|
#include "Game.hpp"
|
||||||
#include "game/GameInit.hpp"
|
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/Scene.hpp"
|
||||||
|
#include "scene/item/SceneItem2D.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -14,43 +14,32 @@ Game::Game() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::init() {
|
void Game::init() {
|
||||||
renderHost.init(shared_from_this());
|
|
||||||
inputManager.init(shared_from_this());
|
currentScene = std::make_shared<Scene>(weak_from_this());
|
||||||
saveManager.init(shared_from_this());
|
auto myItem = currentScene->addSceneItem<SceneItem2D>("myItem");
|
||||||
|
|
||||||
auto initialScene = Scene::getInitialScene();
|
|
||||||
this->nextFrameScene = std::make_shared<Scene>(shared_from_this(), initialScene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::update() {
|
void Game::update() {
|
||||||
this->assetManager.update();
|
|
||||||
|
|
||||||
if(nextFrameScene) {
|
|
||||||
nextFrameScene->stage();
|
|
||||||
currentScene = nextFrameScene;
|
|
||||||
nextFrameScene = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeManager.update();
|
|
||||||
inputManager.update();
|
|
||||||
if(currentScene) currentScene->update();
|
|
||||||
renderHost.update(shared_from_this());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_t Game::isCloseRequested() {
|
|
||||||
return (
|
|
||||||
renderHost.isCloseRequested()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Scene> Game::getCurrentScene() {
|
std::shared_ptr<Scene> Game::getCurrentScene() {
|
||||||
return currentScene;
|
return currentScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::setActiveScene(std::shared_ptr<Scene> scene) {
|
||||||
|
auto previousCurrent = currentScene;
|
||||||
|
if(previousCurrent != nullptr) {
|
||||||
|
previousCurrent->inactive();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentScene = scene;
|
||||||
|
|
||||||
|
if(currentScene != nullptr) {
|
||||||
|
currentScene->active();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Game::~Game() {
|
Game::~Game() {
|
||||||
currentScene = nullptr;
|
|
||||||
nextFrameScene = nullptr;
|
|
||||||
|
|
||||||
assertTrue(SCENE_ITEMS_ACTIVE == 0, "Some scene items are still active?");
|
|
||||||
assertTrue(SCENE_COMPONENTS_ACTIVE == 0, "Some scene components are still active?");
|
|
||||||
}
|
}
|
@ -1,67 +1,53 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2024 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
#include "display/RenderHost.hpp"
|
|
||||||
#include "input/InputManager.hpp"
|
|
||||||
#include "time/TimeManager.hpp"
|
|
||||||
#include "asset/AssetManager.hpp"
|
|
||||||
#include "locale/LocaleManager.hpp"
|
|
||||||
#include "save/SaveManager.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class Scene;
|
class Scene;
|
||||||
|
|
||||||
class Game : public std::enable_shared_from_this<Game> {
|
class Game : public std::enable_shared_from_this<Game> {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Scene> currentScene = nullptr;
|
std::shared_ptr<Scene> currentScene;
|
||||||
std::shared_ptr<Scene> nextFrameScene = nullptr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderHost renderHost;
|
|
||||||
InputManager inputManager;
|
|
||||||
TimeManager timeManager;
|
|
||||||
AssetManager assetManager;
|
|
||||||
LocaleManager localeManager;
|
|
||||||
SaveManager saveManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the game instance, does not initialize anything.
|
* Constructs a new instance of Game, the class majorily responsible for
|
||||||
|
* handling all internal dawn functions outside of platform-centric things
|
||||||
|
* like windowing and graphics.
|
||||||
*/
|
*/
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the game and all of its components.
|
* Initializes the game and all sub managers used by game.
|
||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a single update tick on the game engine, and in turn all of
|
* Updates the game and all sub managers used by game.
|
||||||
* the game's sub systems.
|
|
||||||
*/
|
*/
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the game has been requested to gracefully close at the
|
* Returns the current active scene.
|
||||||
* next available opportunity.
|
|
||||||
*
|
*
|
||||||
* @return True if the game should close.
|
* @return The current active scene.
|
||||||
*/
|
|
||||||
bool_t isCloseRequested();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current scene that is active.
|
|
||||||
*
|
|
||||||
* @return The current scene.
|
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<Scene> getCurrentScene();
|
std::shared_ptr<Scene> getCurrentScene();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deconstructs the game instance, does not deinitialize anything.
|
* Sets the active scene for the game.
|
||||||
|
*
|
||||||
|
* @param scene The scene to set as active.
|
||||||
*/
|
*/
|
||||||
virtual ~Game();
|
void setActiveScene(std::shared_ptr<Scene> scene);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deloads game and all sub managers used by game.
|
||||||
|
*/
|
||||||
|
~Game();
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,15 +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"
|
|
||||||
|
|
||||||
namespace Dawn {
|
|
||||||
class GameInit {
|
|
||||||
public:
|
|
||||||
static std::function<void(Scene&)> getInitialScene();
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,208 +0,0 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "util/Math.hpp"
|
|
||||||
#include "input/InputBinds.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
|
||||||
class DawnGame;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class IInputManager {
|
|
||||||
protected:
|
|
||||||
std::unordered_map<enum InputBind, std::vector<T>> binds;
|
|
||||||
std::unordered_map<enum InputBind, float_t> valuesLeft;
|
|
||||||
std::unordered_map<enum InputBind, float_t> valuesRight;
|
|
||||||
bool_t currentIsLeft = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to be overwritten by the host, reads a RAW input value from
|
|
||||||
* the pad/input device directly.
|
|
||||||
*
|
|
||||||
* @param axis Axis to get the value of.
|
|
||||||
* @return The current input value (between 0 and 1).
|
|
||||||
*/
|
|
||||||
virtual float_t getInputValue(const T axis) = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Binds an axis to a bind.
|
|
||||||
*
|
|
||||||
* @param bind Bind to bind the axis to.
|
|
||||||
* @param axis Axis to use for this bind.
|
|
||||||
*/
|
|
||||||
void bind(const enum InputBind bind, const T axis) {
|
|
||||||
this->binds[bind].push_back(axis);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unbind a previously bound axis from a bind.
|
|
||||||
*
|
|
||||||
* @param bind Bind to remove all binds from.
|
|
||||||
*/
|
|
||||||
void unbind(const enum InputBind bind) {
|
|
||||||
this->binds[bind].clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unbind all values, all of them.
|
|
||||||
*/
|
|
||||||
void unbindAll() {
|
|
||||||
this->binds.clear();
|
|
||||||
this->values.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current bind value.
|
|
||||||
*
|
|
||||||
* @param bind Bind to get the value of.
|
|
||||||
* @return The current input state (between 0 and 1).
|
|
||||||
*/
|
|
||||||
float_t getValue(const enum InputBind bind) {
|
|
||||||
if(this->currentIsLeft) {
|
|
||||||
auto exist = this->valuesLeft.find(bind);
|
|
||||||
return exist == this->valuesLeft.end() ? 0.0f : exist->second;
|
|
||||||
} else {
|
|
||||||
auto exist = this->valuesRight.find(bind);
|
|
||||||
return exist == this->valuesRight.end() ? 0.0f : exist->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the bind value from the previous frame.
|
|
||||||
*
|
|
||||||
* @param bind Bind to get the value of.
|
|
||||||
* @return The value of the bind, last frame.
|
|
||||||
*/
|
|
||||||
float_t getValueLastUpdate(const enum InputBind bind) {
|
|
||||||
if(this->currentIsLeft) {
|
|
||||||
auto exist = this->valuesRight.find(bind);
|
|
||||||
return exist == this->valuesRight.end() ? 0.0f : exist->second;
|
|
||||||
} else {
|
|
||||||
auto exist = this->valuesLeft.find(bind);
|
|
||||||
return exist == this->valuesLeft.end() ? 0.0f : exist->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an axis input for a given negative and positive bind. This will
|
|
||||||
* combine and clamp the values to be between -1 and 1. For example, if
|
|
||||||
* the negative bind is 100% actuated and positive is not at all actuated,
|
|
||||||
* then the value will be -1. If instead positive is 50% actuated, then
|
|
||||||
* the value will be -0.5. If both are equally actuacted, then the value
|
|
||||||
* will be 0.
|
|
||||||
*
|
|
||||||
* @param negative Bind to use for the negative axis.
|
|
||||||
* @param positive Bind to use for the positive axis.
|
|
||||||
* @return A value between -1 and 1.
|
|
||||||
*/
|
|
||||||
float_t getAxis(const enum InputBind negative, const enum InputBind positive) {
|
|
||||||
return -getValue(negative) + getValue(positive);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec2 getAxis2D(
|
|
||||||
const enum InputBind negativeX,
|
|
||||||
const enum InputBind positiveX,
|
|
||||||
const enum InputBind negativeY,
|
|
||||||
const enum InputBind positiveY
|
|
||||||
) {
|
|
||||||
return glm::vec2(
|
|
||||||
getAxis(negativeX, positiveX),
|
|
||||||
getAxis(negativeY, positiveY)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the 2D Axis for the given binds.
|
|
||||||
*
|
|
||||||
* @param x X Axis bind.
|
|
||||||
* @param y Y Axis bind.
|
|
||||||
* @return 2D vector of the two given input binds.
|
|
||||||
*/
|
|
||||||
glm::vec2 getAxis2D(const enum InputBind x, const enum InputBind y) {
|
|
||||||
return glm::vec2(getValue(x), getValue(y));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given bind is currently being pressed (a non-zero
|
|
||||||
* value).
|
|
||||||
*
|
|
||||||
* @param bind Bind to check if pressed.
|
|
||||||
* @return True if value is non-zero, or false for zero.
|
|
||||||
*/
|
|
||||||
bool_t isDown(const enum InputBind bind) {
|
|
||||||
return this->getValue(bind) != 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true on the first frame an input was pressed (when the state
|
|
||||||
* had changed from 0 to non-zero).
|
|
||||||
*
|
|
||||||
* @param bind Bind to check if pressed.
|
|
||||||
* @return True if down this frame and not down last frame.
|
|
||||||
*/
|
|
||||||
bool_t isPressed(const enum InputBind bind) {
|
|
||||||
return this->getValue(bind) != 0 && this->getValueLastUpdate(bind) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true on the first frame an input was released (when the state
|
|
||||||
* had changed from non-zero to 0).
|
|
||||||
*
|
|
||||||
* @param bind Bind to check if released.
|
|
||||||
* @return True if up this frame, and down last frame.
|
|
||||||
*/
|
|
||||||
bool_t wasReleased(const enum InputBind bind) {
|
|
||||||
return this->getValue(bind) == 0 && this->getValueLastUpdate(bind) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal method to update the input state, checks current input raws
|
|
||||||
* and decides what values are set for the inputs.
|
|
||||||
*/
|
|
||||||
void update() {
|
|
||||||
auto it = this->binds.begin();
|
|
||||||
this->currentIsLeft = !this->currentIsLeft;
|
|
||||||
|
|
||||||
// For each bind...
|
|
||||||
while(it != this->binds.end()) {
|
|
||||||
float_t value = 0.0f, valCurrent;
|
|
||||||
|
|
||||||
// For each input axis...
|
|
||||||
auto bindIt = it->second.begin();
|
|
||||||
while(bindIt != it->second.end()) {
|
|
||||||
// Get value and make the new max.
|
|
||||||
float_t inputValue = this->getInputValue(*bindIt);
|
|
||||||
value = Math::max<float_t>(value, inputValue);
|
|
||||||
++bindIt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set into current values
|
|
||||||
if(this->currentIsLeft) {
|
|
||||||
valCurrent = this->valuesRight[it->first];
|
|
||||||
this->valuesLeft[it->first] = value;
|
|
||||||
} else {
|
|
||||||
valCurrent = this->valuesLeft[it->first];
|
|
||||||
this->valuesRight[it->first] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire events when necessary.
|
|
||||||
if(value == 0 && valCurrent == 1) {
|
|
||||||
// eventBindReleased.invoke(it->first);
|
|
||||||
} else if(valCurrent == 0 && value == 1) {
|
|
||||||
// eventBindPressed.invoke(it->first);
|
|
||||||
}
|
|
||||||
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: trigger events
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~IInputManager() {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,9 +1,10 @@
|
|||||||
# Copyright (c) 2023 Dominic Masters
|
# Copyright (c) 2024 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
# Sources
|
||||||
PRIVATE
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
LocaleManager.cpp
|
PRIVATE
|
||||||
|
Language.cpp
|
||||||
)
|
)
|
15
src/dawn/locale/Language.cpp
Normal file
15
src/dawn/locale/Language.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "Language.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
std::u8string Language::get(
|
||||||
|
const char_t key[],
|
||||||
|
const std::pair<std::string, std::u8string> &args
|
||||||
|
) {
|
||||||
|
return u8"Some language string 👍";
|
||||||
|
}
|
24
src/dawn/locale/Language.hpp
Normal file
24
src/dawn/locale/Language.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawn.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class Language {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Gets a language string from the language definition set.
|
||||||
|
*
|
||||||
|
* @param key The key to look up in the language file.
|
||||||
|
* @param args A pair of strings to replace in the language string.
|
||||||
|
* @return The language string.
|
||||||
|
*/
|
||||||
|
static std::u8string get(
|
||||||
|
const char_t key[],
|
||||||
|
const std::pair<std::string, std::u8string> &args = std::make_pair("", u8"")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "LocaleManager.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
|
@ -1,15 +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 LocaleManager final {
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,15 +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
|
|
||||||
Card.cpp
|
|
||||||
PokerPot.cpp
|
|
||||||
PokerPlayer.cpp
|
|
||||||
PokerGame.cpp
|
|
||||||
PokerWinning.cpp
|
|
||||||
PokerTurn.cpp
|
|
||||||
)
|
|
@ -1,94 +0,0 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "Card.hpp"
|
|
||||||
#include "util/Random.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
|
||||||
|
|
||||||
void Card::shuffle(std::vector<struct Card> &deck) {
|
|
||||||
for(uint8_t i = 0; i < deck.size(); i++) {
|
|
||||||
uint8_t swap = Random::random<uint8_t>(0, deck.size() - 1);
|
|
||||||
struct Card tmp = deck[i];
|
|
||||||
deck[i] = deck[swap];
|
|
||||||
deck[swap] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Card::fillDeck(std::vector<struct Card> &deck) {
|
|
||||||
deck.clear();
|
|
||||||
for(uint8_t i = 0; i < CARD_DECK_SIZE; i++) {
|
|
||||||
deck.push_back(Card(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t Card::contains(
|
|
||||||
const std::vector<struct Card> &deck,
|
|
||||||
const struct Card c
|
|
||||||
) {
|
|
||||||
if(deck.size() == 0) return -1;
|
|
||||||
|
|
||||||
return std::distance(
|
|
||||||
deck.begin(),
|
|
||||||
std::find_if(
|
|
||||||
deck.begin(),
|
|
||||||
deck.end(),
|
|
||||||
[c](struct Card card) {
|
|
||||||
return card.cardValue == c.cardValue;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t Card::containsValue(
|
|
||||||
const std::vector<struct Card> &deck,
|
|
||||||
const enum CardValue number
|
|
||||||
) {
|
|
||||||
if(deck.size() == 0) return -1;
|
|
||||||
|
|
||||||
return std::distance(
|
|
||||||
deck.begin(),
|
|
||||||
std::find_if(
|
|
||||||
deck.begin(),
|
|
||||||
deck.end(),
|
|
||||||
[number](struct Card c) {
|
|
||||||
return c.getValue() == number;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<struct Card> Card::countPairs(
|
|
||||||
const std::vector<struct Card> &deck,
|
|
||||||
const enum CardValue val
|
|
||||||
) {
|
|
||||||
std::vector<struct Card> pairs;
|
|
||||||
|
|
||||||
std::for_each(
|
|
||||||
deck.begin(),
|
|
||||||
deck.end(),
|
|
||||||
[&pairs, val](struct Card c) {
|
|
||||||
if(c.getValue() == val) pairs.push_back(c);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return pairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool_t Card::cardSorter(struct Card left, struct Card right) {
|
|
||||||
return left.cardValue < right.cardValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Card::sort(std::vector<struct Card> &deck) {
|
|
||||||
std::sort(deck.begin(), deck.end(), &Card::cardSorter);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CardValue Card::getValue() {
|
|
||||||
return (enum CardValue)(cardValue % CARD_COUNT_PER_SUIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CardSuit Card::getSuit() {
|
|
||||||
return (enum CardSuit)(cardValue / CARD_COUNT_PER_SUIT);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user