Compare commits
	
		
			8 Commits
		
	
	
		
			main
			...
			old_engine
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c916e1a6cf | |||
| 50a0847f53 | |||
| 2dc4d23151 | |||
| 4b77d1b613 | |||
| 04be82f034 | |||
| 3bc2f0d372 | |||
| bba4a83240 | |||
| fec8771c75 | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -87,3 +87,5 @@ assets/borrowed
 | 
				
			|||||||
._*
 | 
					._*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*~
 | 
					*~
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					archive/*
 | 
				
			||||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							@@ -19,3 +19,6 @@
 | 
				
			|||||||
[submodule "lib/libarchive"]
 | 
					[submodule "lib/libarchive"]
 | 
				
			||||||
	path = lib/libarchive
 | 
						path = lib/libarchive
 | 
				
			||||||
	url = https://github.com/libarchive/libarchive
 | 
						url = https://github.com/libarchive/libarchive
 | 
				
			||||||
 | 
					[submodule "lib/boxer"]
 | 
				
			||||||
 | 
						path = lib/boxer
 | 
				
			||||||
 | 
						url = https://github.com/aaronmjacobs/Boxer
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,35 +10,97 @@ 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(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")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Build 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()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 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")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Add CMake Tools
 | 
					# Variables
 | 
				
			||||||
add_subdirectory(cmake)
 | 
					set(DAWN_TARGET_NAME "Dawn" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
				
			||||||
 | 
					set(DAWN_ASSETS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
				
			||||||
set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/src/${DAWN_BUILDING}/${DAWN_TARGET_NAME})
 | 
					set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/Dawn CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Initialize Project First.
 | 
					# Initialize Project First.
 | 
				
			||||||
project(Dawn
 | 
					project("${DAWN_PROJECT_NAME}"
 | 
				
			||||||
  VERSION 1.0.0
 | 
					  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,5 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
mkdir tools
 | 
					 | 
				
			||||||
cd tools
 | 
					 | 
				
			||||||
cmake .. -DDAWN_BUILD_TARGET=target-tools
 | 
					 | 
				
			||||||
make
 | 
					 | 
				
			||||||
@@ -1,2 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
git submodule update --init --recursive
 | 
					 | 
				
			||||||
@@ -1,2 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
sudo apt install build-essential
 | 
					 | 
				
			||||||
@@ -1,38 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
sudo apt-get install cmake libarchive-tools
 | 
					 | 
				
			||||||
git clone https://github.com/vitasdk/vdpm ~/vdpm
 | 
					 | 
				
			||||||
cd ~/vdpm
 | 
					 | 
				
			||||||
./bootstrap-vitasdk.sh
 | 
					 | 
				
			||||||
export PATH=$VITASDK/bin:$PATH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
git clone https://github.com/vitasdk/packages.git ~/vitapackages
 | 
					 | 
				
			||||||
cd ~/vitapackages
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
dir_array=(
 | 
					 | 
				
			||||||
  zlib
 | 
					 | 
				
			||||||
  bzip2
 | 
					 | 
				
			||||||
  henkaku
 | 
					 | 
				
			||||||
  taihen
 | 
					 | 
				
			||||||
  kubridge
 | 
					 | 
				
			||||||
  openal-soft
 | 
					 | 
				
			||||||
  openssl
 | 
					 | 
				
			||||||
  curl
 | 
					 | 
				
			||||||
  curlpp
 | 
					 | 
				
			||||||
  expat
 | 
					 | 
				
			||||||
  opus
 | 
					 | 
				
			||||||
  opusfile
 | 
					 | 
				
			||||||
  glm
 | 
					 | 
				
			||||||
  kuio
 | 
					 | 
				
			||||||
  vitaShaRK
 | 
					 | 
				
			||||||
  libmathneon
 | 
					 | 
				
			||||||
  vitaGL
 | 
					 | 
				
			||||||
  SceShaccCgExt
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
curdir=$(pwd)
 | 
					 | 
				
			||||||
for d in "${dir_array[@]}";do
 | 
					 | 
				
			||||||
  echo "${curdir}${d}"
 | 
					 | 
				
			||||||
  cd "${curdir}/${d}"
 | 
					 | 
				
			||||||
  vita-makepkg
 | 
					 | 
				
			||||||
  vdpm *-arm.tar.xz
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
							
								
								
									
										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
 | 
				
			||||||
@@ -1,10 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
mkdir -p vita/build
 | 
					 | 
				
			||||||
cd vita/build
 | 
					 | 
				
			||||||
if [ ! -d "src" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
  cmake ../.. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
make
 | 
					 | 
				
			||||||
cp ./src/dawnvita/*.vpk ../
 | 
					 | 
				
			||||||
cd ../..
 | 
					 | 
				
			||||||
							
								
								
									
										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
 | 
				
			||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Includes
 | 
					 | 
				
			||||||
add_subdirectory(hosts)
 | 
					 | 
				
			||||||
add_subdirectory(targets)
 | 
					 | 
				
			||||||
@@ -1,15 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Check for build target, or default
 | 
					 | 
				
			||||||
if(WIN32)
 | 
					 | 
				
			||||||
  set(DAWN_BUILD_HOST "build-host-win32")
 | 
					 | 
				
			||||||
elseif(UNIX AND NOT APPLE)
 | 
					 | 
				
			||||||
  set(DAWN_BUILD_HOST "build-host-linux")
 | 
					 | 
				
			||||||
elseif(UNIX AND APPLE)
 | 
					 | 
				
			||||||
  set(DAWN_BUILD_HOST "build-host-osx")
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
add_subdirectory(${DAWN_BUILD_HOST})
 | 
					 | 
				
			||||||
@@ -1,4 +0,0 @@
 | 
				
			|||||||
# CMake Hosts
 | 
					 | 
				
			||||||
CMake Hosts help the build system define how a HOST (Not the target/client) does
 | 
					 | 
				
			||||||
its building. Host would be the system you are using, right now, to do the build
 | 
					 | 
				
			||||||
with.
 | 
					 | 
				
			||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILD_HOST_LIBS "m" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -1,49 +0,0 @@
 | 
				
			|||||||
find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h
 | 
					 | 
				
			||||||
  HINTS
 | 
					 | 
				
			||||||
    ENV GLFWDIR
 | 
					 | 
				
			||||||
  PATHS
 | 
					 | 
				
			||||||
    "/usr"
 | 
					 | 
				
			||||||
    "/usr/local"
 | 
					 | 
				
			||||||
    "~/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/opt"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/glfw"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/glfw3"
 | 
					 | 
				
			||||||
  PATH_SUFFIXES
 | 
					 | 
				
			||||||
    include
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Search for the library
 | 
					 | 
				
			||||||
FIND_LIBRARY(GLFW_LIBRARY
 | 
					 | 
				
			||||||
  NAMES
 | 
					 | 
				
			||||||
    glfw glfw3 GLFW GLFW3
 | 
					 | 
				
			||||||
  HINTS
 | 
					 | 
				
			||||||
    ENV GLFWDIR
 | 
					 | 
				
			||||||
  PATHS
 | 
					 | 
				
			||||||
    "/usr"
 | 
					 | 
				
			||||||
    "/usr/local"
 | 
					 | 
				
			||||||
    "~/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/opt"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/glfw"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/glfw3"
 | 
					 | 
				
			||||||
  PATH_SUFFIXES
 | 
					 | 
				
			||||||
    lib
 | 
					 | 
				
			||||||
    lib32
 | 
					 | 
				
			||||||
    lib64
 | 
					 | 
				
			||||||
    libs
 | 
					 | 
				
			||||||
    lib-vc2012
 | 
					 | 
				
			||||||
    lib-vc2013
 | 
					 | 
				
			||||||
    lib-vc2015
 | 
					 | 
				
			||||||
    lib-vc2017
 | 
					 | 
				
			||||||
    lib-vc2019
 | 
					 | 
				
			||||||
    lib-vc2022
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
INCLUDE(FindPackageHandleStandardArgs)
 | 
					 | 
				
			||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
 | 
					 | 
				
			||||||
  GLFW
 | 
					 | 
				
			||||||
  REQUIRED_VARS GLFW_LIBRARY GLFW_INCLUDE_DIR
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
mark_as_advanced(GLFW_LIBRARY GLFW_INCLUDE_DIR)
 | 
					 | 
				
			||||||
@@ -1,49 +0,0 @@
 | 
				
			|||||||
find_path(OPENAL_INCLUDE_DIR al.h
 | 
					 | 
				
			||||||
  HINTS
 | 
					 | 
				
			||||||
    ENV OPENALDIR
 | 
					 | 
				
			||||||
  PATHS
 | 
					 | 
				
			||||||
    "/usr"
 | 
					 | 
				
			||||||
    "/usr/local"
 | 
					 | 
				
			||||||
    "~/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/opt"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/openal"
 | 
					 | 
				
			||||||
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]"
 | 
					 | 
				
			||||||
  PATH_SUFFIXES
 | 
					 | 
				
			||||||
    include/AL
 | 
					 | 
				
			||||||
    AL/AL
 | 
					 | 
				
			||||||
    include/OpenAL
 | 
					 | 
				
			||||||
    include
 | 
					 | 
				
			||||||
    AL
 | 
					 | 
				
			||||||
    OpenAL
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Search for the library
 | 
					 | 
				
			||||||
FIND_LIBRARY(OPENAL_LIBRARY
 | 
					 | 
				
			||||||
  NAMES
 | 
					 | 
				
			||||||
    OpenAL al openal OpenAL32
 | 
					 | 
				
			||||||
  HINTS
 | 
					 | 
				
			||||||
    ENV OPENALDIR
 | 
					 | 
				
			||||||
  PATHS
 | 
					 | 
				
			||||||
    "/usr"
 | 
					 | 
				
			||||||
    "/usr/local"
 | 
					 | 
				
			||||||
    "~/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/Library/Frameworks"
 | 
					 | 
				
			||||||
    "/opt"
 | 
					 | 
				
			||||||
    "$ENV{PROGRAMFILES}/openal"
 | 
					 | 
				
			||||||
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]"
 | 
					 | 
				
			||||||
  PATH_SUFFIXES
 | 
					 | 
				
			||||||
    lib
 | 
					 | 
				
			||||||
    lib32
 | 
					 | 
				
			||||||
    lib64
 | 
					 | 
				
			||||||
    libs
 | 
					 | 
				
			||||||
    ${_OpenAL_ARCH_DIR}
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
INCLUDE(FindPackageHandleStandardArgs)
 | 
					 | 
				
			||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
 | 
					 | 
				
			||||||
  OpenAL
 | 
					 | 
				
			||||||
  REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
 | 
					 | 
				
			||||||
@@ -1,14 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Now validate we have a build target for real
 | 
					 | 
				
			||||||
if(NOT DEFINED DAWN_BUILD_TARGET)
 | 
					 | 
				
			||||||
  set(DAWN_BUILD_TARGET "target-rpg-linux-glfw" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
message("Building target ${DAWN_BUILD_TARGET}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Include the build target
 | 
					 | 
				
			||||||
add_subdirectory(${DAWN_BUILD_TARGET})
 | 
					 | 
				
			||||||
@@ -1,40 +0,0 @@
 | 
				
			|||||||
# CMake Targets
 | 
					 | 
				
			||||||
CMake Targets decide what you are intending to build. Targets are (usually) a 
 | 
					 | 
				
			||||||
specific system, like vita, 3ds, switch, or a specific OS with a library, e.g.
 | 
					 | 
				
			||||||
targetting vulkan on linux vs targetting opengl on linux, or targetting opengl
 | 
					 | 
				
			||||||
on windows, etc.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
In addition the target also decides what project(s) to build. Usually this is
 | 
					 | 
				
			||||||
just the specific game and/or systems to be built, so if you are building a VN
 | 
					 | 
				
			||||||
game the target would need to let the build system know you want to rollup the
 | 
					 | 
				
			||||||
VN parts of the engine also.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Note this is one of the very few build args that is required during the 
 | 
					 | 
				
			||||||
configuration of cmake to make it build properly, failure to specify a target
 | 
					 | 
				
			||||||
will result in a build error.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
-DDAWN_BUILD_TARGET=target-helloworld-linux64-glfw
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Target Systems
 | 
					 | 
				
			||||||
- vita
 | 
					 | 
				
			||||||
- linux
 | 
					 | 
				
			||||||
- osx
 | 
					 | 
				
			||||||
- windows
 | 
					 | 
				
			||||||
- emscripten (Web)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Target Libraries
 | 
					 | 
				
			||||||
- vita (Includes OGL)
 | 
					 | 
				
			||||||
- glfw (Includes OGL)
 | 
					 | 
				
			||||||
- sdl2 (Includes OGL)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Target games
 | 
					 | 
				
			||||||
- liminal
 | 
					 | 
				
			||||||
- helloworld
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Target Arcitectures
 | 
					 | 
				
			||||||
- vita (form of armv7)
 | 
					 | 
				
			||||||
- linux (x64 only)
 | 
					 | 
				
			||||||
- windows (x64 only)
 | 
					 | 
				
			||||||
- osx (targetting arm64 currently)
 | 
					 | 
				
			||||||
@@ -1,15 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_EMSCRIPTEN true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_EMSCRIPTEN_FLAGS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Ensures a .HTML file is generated.
 | 
					 | 
				
			||||||
set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -1,10 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_LINUX true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_ARCHIVE true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -1,21 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_VITA true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Properties
 | 
					 | 
				
			||||||
set(DAWN_VITA_APP_NAME "Hello Vita" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_VITA_TITLEID  "DAWN00000" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_VITA_VERSION  "01.00" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Toolchain
 | 
					 | 
				
			||||||
if(DEFINED ENV{VITASDK})
 | 
					 | 
				
			||||||
  set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
else()
 | 
					 | 
				
			||||||
  message(FATAL_ERROR "VITASDK Environment variable is missing! Either you do not have the VITASDK installed, or it is not set up with the env vars correctly.")
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
# Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
# 
 | 
					 | 
				
			||||||
# This software is released under the MIT License.
 | 
					 | 
				
			||||||
# https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(DAWN_BUILDING dawnrpg CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_LINUX true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_NAME "DawnRPG" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_ARCHIVE true CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
set(DAWN_TARGET_TRUETYPE false CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
@@ -3,51 +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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# GLFW
 | 
					# GLFW/GLAD
 | 
				
			||||||
if(DAWN_TARGET_GLFW)
 | 
					if(DAWN_BUILD_SYSTEM STREQUAL "linux")
 | 
				
			||||||
  if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
 | 
					 | 
				
			||||||
    set(DAWN_EMSCRIPTEN_FLAGS "${DAWN_EMSCRIPTEN_FLAGS} -s USE_GLFW=3" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
    add_subdirectory(glad)
 | 
					 | 
				
			||||||
  else()
 | 
					 | 
				
			||||||
  add_subdirectory(glad)
 | 
					  add_subdirectory(glad)
 | 
				
			||||||
  add_subdirectory(glfw)
 | 
					  add_subdirectory(glfw)
 | 
				
			||||||
  endif()
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# SDL
 | 
					 | 
				
			||||||
if(DAWN_TARGET_SDL2)
 | 
					 | 
				
			||||||
  add_subdirectory(glad)
 | 
					 | 
				
			||||||
  add_subdirectory(SDL)
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# GLM
 | 
					 | 
				
			||||||
add_subdirectory(glm)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# FreeType
 | 
					 | 
				
			||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
 | 
					 | 
				
			||||||
  set(DAWN_EMSCRIPTEN_FLAGS "${DAWN_EMSCRIPTEN_FLAGS} -s USE_FREETYPE=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					 | 
				
			||||||
else()
 | 
					 | 
				
			||||||
  add_subdirectory(freetype)
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# LibArchive
 | 
					 | 
				
			||||||
if(DAWN_TARGET_ARCHIVE)
 | 
					 | 
				
			||||||
  add_subdirectory(libarchive)
 | 
					  add_subdirectory(libarchive)
 | 
				
			||||||
endif()
 | 
					  add_subdirectory(glm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# OpenAL
 | 
					 | 
				
			||||||
if(DAWN_TARGET_OPENAL)
 | 
					 | 
				
			||||||
  set(LIBTYPE "STATIC")
 | 
					  set(LIBTYPE "STATIC")
 | 
				
			||||||
  add_subdirectory(openal-soft)
 | 
					  add_subdirectory(openal-soft)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
 | 
					  set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
 | 
				
			||||||
  set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE) 
 | 
					  set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE) 
 | 
				
			||||||
  add_subdirectory(AudioFile)
 | 
					  add_subdirectory(AudioFile)
 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Emscripten (TESTING ONLY)
 | 
					  add_subdirectory(freetype)
 | 
				
			||||||
if(DEFINED DAWN_EMSCRIPTEN_FLAGS)
 | 
					
 | 
				
			||||||
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					  add_subdirectory(boxer)
 | 
				
			||||||
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					  target_compile_definitions(Boxer PRIVATE UNICODE)
 | 
				
			||||||
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
 | 
					
 | 
				
			||||||
 | 
					elseif(DAWN_BUILD_SYSTEM STREQUAL "vita")
 | 
				
			||||||
 | 
					  add_subdirectory(glm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
 | 
				
			||||||
 | 
					  add_subdirectory(glm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
							
								
								
									
										1
									
								
								lib/boxer
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								lib/boxer
									
									
									
									
									
										Submodule
									
								
							 Submodule lib/boxer added at 65e79c38f1
									
								
							@@ -3,75 +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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Custom variables
 | 
					 | 
				
			||||||
set(
 | 
					 | 
				
			||||||
  DAWN_TARGET_DEPENDENCIES_LAST
 | 
					 | 
				
			||||||
  CACHE INTERNAL ${DAWN_CACHE_TARGET}
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build Project
 | 
					if(DAWN_BUILD_SYSTEM STREQUAL "linux")
 | 
				
			||||||
add_executable(${DAWN_TARGET_NAME})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Change what we are building. Pulled from the cmake/targets dir.
 | 
					 | 
				
			||||||
if(DEFINED DAWN_BUILDING)
 | 
					 | 
				
			||||||
  add_subdirectory(${DAWN_BUILDING})
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Validate game project includes the target name
 | 
					 | 
				
			||||||
if(DEFINED DAWN_TARGET_NAME)
 | 
					 | 
				
			||||||
  # Add in base library
 | 
					 | 
				
			||||||
  add_subdirectory(dawn)
 | 
					  add_subdirectory(dawn)
 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Compile entry targets
 | 
					 | 
				
			||||||
  if(DAWN_TARGET_WIN32)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnwin32)
 | 
					 | 
				
			||||||
  elseif(DAWN_TARGET_LINUX)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnlinux)
 | 
					 | 
				
			||||||
  elseif(DAWN_TARGET_OSX)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnosx)
 | 
					 | 
				
			||||||
  elseif(DAWN_TARGET_VITA)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnvita)
 | 
					 | 
				
			||||||
  elseif(DAWN_TARGET_EMSCRIPTEN)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnemscripten)
 | 
					 | 
				
			||||||
  else()
 | 
					 | 
				
			||||||
    message(FATAL_ERROR "You need to define an entry target")
 | 
					 | 
				
			||||||
  endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Host Libraries
 | 
					 | 
				
			||||||
  target_link_libraries(${DAWN_TARGET_NAME}
 | 
					 | 
				
			||||||
    PUBLIC
 | 
					 | 
				
			||||||
      ${DAWN_BUILD_HOST_LIBS}
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Compile support targets
 | 
					 | 
				
			||||||
  if(DAWN_TARGET_GLFW)
 | 
					 | 
				
			||||||
  add_subdirectory(dawnglfw)
 | 
					  add_subdirectory(dawnglfw)
 | 
				
			||||||
 | 
					  add_subdirectory(dawnlinux)
 | 
				
			||||||
  add_subdirectory(dawnopengl)
 | 
					  add_subdirectory(dawnopengl)
 | 
				
			||||||
  endif()
 | 
					elseif(DAWN_BUILD_SYSTEM STREQUAL "vita")
 | 
				
			||||||
 | 
					  add_subdirectory(dawn)
 | 
				
			||||||
  if(DAWN_TARGET_TRUETYPE)
 | 
					  add_subdirectory(dawnvita)
 | 
				
			||||||
    add_subdirectory(dawntruetype)
 | 
					 | 
				
			||||||
  endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(DAWN_TARGET_SDL2)
 | 
					 | 
				
			||||||
    add_subdirectory(dawnsdl2)
 | 
					 | 
				
			||||||
  add_subdirectory(dawnopengl)
 | 
					  add_subdirectory(dawnopengl)
 | 
				
			||||||
  endif()
 | 
					elseif(DAWN_BUILD_SYSTEM STREQUAL "psp")
 | 
				
			||||||
 | 
					  set(DAWN_OPENGL_SHADERS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
 | 
				
			||||||
  if(DAWN_TARGET_VITA)
 | 
					  set(DAWN_OPENGL_FRAMEBUFFERS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
 | 
				
			||||||
    add_subdirectory(dawnopengl)
 | 
					  set(DAWN_OPENGL_MIPMAPS FALSE CACHE INTERNAL "${DAWN_CACHE_TARGET}")
 | 
				
			||||||
  endif()
 | 
					  add_subdirectory(dawn)
 | 
				
			||||||
 | 
					  add_subdirectory(dawnpsp)
 | 
				
			||||||
  if(DAWN_TARGET_OPENAL)
 | 
					else()
 | 
				
			||||||
    add_subdirectory(dawnopenal)
 | 
					  message(FATAL_ERROR "Unknown build system: ${DAWN_BUILD_SYSTEM}")
 | 
				
			||||||
  endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Late definitions, used by tools
 | 
					 | 
				
			||||||
  if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
 | 
					 | 
				
			||||||
  else()
 | 
					 | 
				
			||||||
    add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
 | 
					 | 
				
			||||||
  endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Compress the game assets.
 | 
					 | 
				
			||||||
  add_dependencies(${DAWN_TARGET_NAME} dawnassets)
 | 
					 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
@@ -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
 | 
				
			||||||
@@ -6,8 +6,6 @@
 | 
				
			|||||||
# Libraries
 | 
					# Libraries
 | 
				
			||||||
target_link_libraries(${DAWN_TARGET_NAME}
 | 
					target_link_libraries(${DAWN_TARGET_NAME}
 | 
				
			||||||
  PUBLIC
 | 
					  PUBLIC
 | 
				
			||||||
    glm
 | 
					 | 
				
			||||||
    archive_static
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Includes
 | 
					# Includes
 | 
				
			||||||
@@ -16,22 +14,22 @@ target_include_directories(${DAWN_TARGET_NAME}
 | 
				
			|||||||
    ${CMAKE_CURRENT_LIST_DIR}
 | 
					    ${CMAKE_CURRENT_LIST_DIR}
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Sources
 | 
				
			||||||
 | 
					target_sources(${DAWN_TARGET_NAME}
 | 
				
			||||||
 | 
					  PRIVATE
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Subdirs
 | 
					# Subdirs
 | 
				
			||||||
add_subdirectory(assert)
 | 
					add_subdirectory(error)
 | 
				
			||||||
add_subdirectory(asset)
 | 
					 | 
				
			||||||
add_subdirectory(audio)
 | 
					 | 
				
			||||||
add_subdirectory(component)
 | 
					 | 
				
			||||||
add_subdirectory(display)
 | 
					 | 
				
			||||||
add_subdirectory(environment)
 | 
					 | 
				
			||||||
add_subdirectory(game)
 | 
					add_subdirectory(game)
 | 
				
			||||||
# add_subdirectory(games)
 | 
					 | 
				
			||||||
# add_subdirectory(input)
 | 
					 | 
				
			||||||
add_subdirectory(locale)
 | 
					add_subdirectory(locale)
 | 
				
			||||||
add_subdirectory(prefab)
 | 
					 | 
				
			||||||
# add_subdirectory(physics)
 | 
					 | 
				
			||||||
add_subdirectory(save)
 | 
					 | 
				
			||||||
add_subdirectory(scene)
 | 
					add_subdirectory(scene)
 | 
				
			||||||
# add_subdirectory(state)
 | 
					 | 
				
			||||||
add_subdirectory(time)
 | 
					 | 
				
			||||||
add_subdirectory(util)
 | 
					add_subdirectory(util)
 | 
				
			||||||
add_subdirectory(ui)
 | 
					
 | 
				
			||||||
 | 
					# Textures
 | 
				
			||||||
 | 
					# tool_texture(texture_test
 | 
				
			||||||
 | 
					#   FILE=${DAWN_ASSETS_DIR}/texture_test.png
 | 
				
			||||||
 | 
					#   FILTER_MIN=NEAREST
 | 
				
			||||||
 | 
					#   FILTER_MAG=NEAREST
 | 
				
			||||||
 | 
					# )
 | 
				
			||||||
@@ -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,64 +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"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
AssetManager::~AssetManager() {
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,106 +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 == finishedAssetLoaders.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.
 | 
					 | 
				
			||||||
       * @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,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,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,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
 | 
					 | 
				
			||||||
    SimpleComponent.cpp
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Subdirs
 | 
					 | 
				
			||||||
add_subdirectory(display)
 | 
					 | 
				
			||||||
add_subdirectory(ui)
 | 
					 | 
				
			||||||
@@ -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,144 +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);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,73 +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);
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										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,50 +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>
 | 
					 | 
				
			||||||
@@ -1,16 +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(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,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
 | 
				
			||||||
							
								
								
									
										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,37 +14,32 @@ Game::Game() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Game::init() {
 | 
					void Game::init() {
 | 
				
			||||||
  renderHost.init(shared_from_this());
 | 
					 | 
				
			||||||
  inputManager.init(shared_from_this());
 | 
					 | 
				
			||||||
  saveManager.init(shared_from_this());
 | 
					 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  auto initialScene = GameInit::getInitialScene();
 | 
					  currentScene = std::make_shared<Scene>(weak_from_this());
 | 
				
			||||||
  nextFrameScene = std::make_shared<Scene>(shared_from_this(), initialScene);
 | 
					  auto myItem = currentScene->addSceneItem<SceneItem2D>("myItem");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Game::update() {
 | 
					void Game::update() {
 | 
				
			||||||
  this->assetManager.update();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(nextFrameScene) {
 | 
					 | 
				
			||||||
    nextFrameScene->stage();
 | 
					 | 
				
			||||||
    currentScene = nextFrameScene;
 | 
					 | 
				
			||||||
    nextFrameScene = nullptr;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  timeManager.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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Game::~Game() {
 | 
					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() {
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -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"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace Dawn {
 | 
					 | 
				
			||||||
  class DawnGame;
 | 
					 | 
				
			||||||
  typedef int_fast16_t inputbind_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  template<typename T>
 | 
					 | 
				
			||||||
  class IInputManager {
 | 
					 | 
				
			||||||
    protected:
 | 
					 | 
				
			||||||
      std::unordered_map<inputbind_t, std::vector<T>> binds;
 | 
					 | 
				
			||||||
      std::unordered_map<inputbind_t, float_t> valuesLeft;
 | 
					 | 
				
			||||||
      std::unordered_map<inputbind_t, 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 inputbind_t 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 inputbind_t 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 inputbind_t 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 inputbind_t 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 inputbind_t negative, const inputbind_t positive) {
 | 
					 | 
				
			||||||
        return -getValue(negative) + getValue(positive);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      glm::vec2 getAxis2D(
 | 
					 | 
				
			||||||
        const inputbind_t negativeX,
 | 
					 | 
				
			||||||
        const inputbind_t positiveX,
 | 
					 | 
				
			||||||
        const inputbind_t negativeY,
 | 
					 | 
				
			||||||
        const inputbind_t 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 inputbind_t x, const inputbind_t 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 inputbind_t 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 inputbind_t 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 inputbind_t 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Sources
 | 
				
			||||||
target_sources(${DAWN_TARGET_NAME}
 | 
					target_sources(${DAWN_TARGET_NAME}
 | 
				
			||||||
  PRIVATE
 | 
					  PRIVATE
 | 
				
			||||||
    LocaleManager.cpp
 | 
					    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,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
 | 
					 | 
				
			||||||
    SimpleSpinningCube.cpp
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@@ -1,49 +0,0 @@
 | 
				
			|||||||
// Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
// 
 | 
					 | 
				
			||||||
// This software is released under the MIT License.
 | 
					 | 
				
			||||||
// https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "SimpleSpinningCube.hpp"
 | 
					 | 
				
			||||||
#include "component/display/MeshRenderer.hpp"
 | 
					 | 
				
			||||||
#include "component/display/material/SimpleTexturedMaterial.hpp"
 | 
					 | 
				
			||||||
#include "display/mesh/CubeMesh.hpp"
 | 
					 | 
				
			||||||
#include "component/SimpleComponent.hpp"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace Dawn;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
std::shared_ptr<SceneItem> Dawn::createSimpleSpinningCube(Scene &s) {
 | 
					 | 
				
			||||||
  // Create the scene item.
 | 
					 | 
				
			||||||
  auto cubeItem = s.createSceneItem();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Create a simple cube mesh.
 | 
					 | 
				
			||||||
  auto cubeMesh = std::make_shared<Mesh>();
 | 
					 | 
				
			||||||
  cubeMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
 | 
					 | 
				
			||||||
  CubeMesh::buffer(cubeMesh, glm::vec3(-1, -1, -1), glm::vec3(2, 2, 2), 0, 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Add a renderer to the scene item.
 | 
					 | 
				
			||||||
  auto cubeMeshRenderer = cubeItem->addComponent<MeshRenderer>();
 | 
					 | 
				
			||||||
  cubeMeshRenderer->mesh = cubeMesh;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Add a material to the scene item.
 | 
					 | 
				
			||||||
  auto cubeMaterial = cubeItem->addComponent<SimpleTexturedMaterial>();
 | 
					 | 
				
			||||||
  cubeMaterial->setColor(COLOR_MAGENTA);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Add a simple event listener component to the scene item.
 | 
					 | 
				
			||||||
  addSimpleComponent(cubeItem, [](auto &cmp, auto &events) {
 | 
					 | 
				
			||||||
    // Note that add component cannot receive a self reference, so we must
 | 
					 | 
				
			||||||
    // capture the component by reference instead.
 | 
					 | 
				
			||||||
    events.push_back(cmp.getScene()->onUnpausedUpdate.listen([&](
 | 
					 | 
				
			||||||
      float_t delta
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      // Since we captured within the lambda, we can access the component
 | 
					 | 
				
			||||||
      // directly.
 | 
					 | 
				
			||||||
      auto item = cmp.getItem();
 | 
					 | 
				
			||||||
      item->setLocalRotation(
 | 
					 | 
				
			||||||
        item->getLocalRotation() *
 | 
					 | 
				
			||||||
        glm::quat(glm::vec3(1, 1, 0) * delta)
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    }));
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return cubeItem;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,11 +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 {
 | 
					 | 
				
			||||||
  std::shared_ptr<SceneItem> createSimpleSpinningCube(Scene &s);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -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
 | 
					 | 
				
			||||||
    SaveFile.cpp
 | 
					 | 
				
			||||||
    SaveManager.cpp
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
// Copyright (c) 2022 Dominic Masters
 | 
					 | 
				
			||||||
// 
 | 
					 | 
				
			||||||
// This software is released under the MIT License.
 | 
					 | 
				
			||||||
// https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "SaveFile.hpp"
 | 
					 | 
				
			||||||
#include "assert/assert.hpp"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using namespace Dawn;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
SaveFile::SaveFile() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool_t SaveFile::doesSaveHaveChanges() {
 | 
					 | 
				
			||||||
  return this->hasChanges;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool_t SaveFile::has(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  return this->data.find(key) != this->data.end();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// String (raw)
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
std::string SaveFile::get<std::string>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return "";
 | 
					 | 
				
			||||||
  return this->data[key];
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<std::string>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const std::string value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  this->data[key] = value;
 | 
					 | 
				
			||||||
  this->hasChanges = true;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// int32_t
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
int32_t SaveFile::get<int32_t>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return 0;
 | 
					 | 
				
			||||||
  return std::stoi(this->data[key]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<int32_t>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const int32_t value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  this->set<std::string>(key, std::to_string(value));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// uint32_t
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
uint32_t SaveFile::get<uint32_t>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return 0;
 | 
					 | 
				
			||||||
  return std::stoul(this->data[key]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<uint32_t>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const uint32_t value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  this->set<std::string>(key, std::to_string(value));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// int64_t
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
int64_t SaveFile::get<int64_t>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return 0;
 | 
					 | 
				
			||||||
  return std::stoll(this->data[key]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<int64_t>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const int64_t value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  this->set<std::string>(key, std::to_string(value));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// uint64_t
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
uint64_t SaveFile::get<uint64_t>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return 0;
 | 
					 | 
				
			||||||
  return std::stoull(this->data[key]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<uint64_t>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const uint64_t value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  this->set<std::string>(key, std::to_string(value));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// float_t
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
float_t SaveFile::get<float_t>(const std::string &key) {
 | 
					 | 
				
			||||||
  assertFalse(key.empty(), "Key cannot be empty.");
 | 
					 | 
				
			||||||
  if(!this->has(key)) return 0.0f;
 | 
					 | 
				
			||||||
  return std::stof(this->data[key]);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template<>
 | 
					 | 
				
			||||||
void SaveFile::set<float_t>(
 | 
					 | 
				
			||||||
  const std::string &key,
 | 
					 | 
				
			||||||
  const float_t value
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
  this->set<std::string>(key, std::to_string(value));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
SaveFile::~SaveFile() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user