Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
bfd1ac6953 | |||
7c3225fe10 | |||
f574b60856 | |||
ba305de596 | |||
afa6a1a036 | |||
fe69d85fab | |||
f5958f2879 | |||
e10aea20a1 | |||
2b36a12335 | |||
698aeb2afc | |||
c87f13b063 | |||
b5958189cf | |||
b3c2e0114f | |||
ccd5b36965 | |||
d1d7d46826 | |||
7628f33c25 | |||
876d4c4198 | |||
872e79e4fb | |||
cf9af3a818 | |||
f98be769e7 | |||
d35fba24fa | |||
4e0bb5caa9 | |||
7c68b7bc8b | |||
68f6453da6 | |||
8469da79d0 | |||
250754af0a | |||
9d91fa6435 | |||
e6672945ae | |||
a4774e6189 | |||
223bbed232 | |||
a6ac4f029e | |||
5998037994 | |||
68fab7c94d | |||
7989be5fe7 | |||
e660fade95 | |||
9fd4c2399f | |||
2af55041c8 | |||
ac0f0e86c5 | |||
4dccd7d969 | |||
bcbc8796da | |||
f4120095ed | |||
e91b1983c8 | |||
98f2f3e955 | |||
91caebd385 | |||
4914ec6168 | |||
de55029356 | |||
a2c841288d | |||
274c96bb64 | |||
aefbe17786 | |||
cfa9e0e99a | |||
f8c008fd45 | |||
a02e87c3fa |
47
.gitea/workflows/release.yml
Normal file
47
.gitea/workflows/release.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
name: build-linux-glfw-x64
|
||||||
|
on:
|
||||||
|
# ON tag
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
mkdir release
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
build-essential \
|
||||||
|
cmake \
|
||||||
|
xorg-dev \
|
||||||
|
libglu1-mesa-dev \
|
||||||
|
libglfw3-dev \
|
||||||
|
libx11-dev \
|
||||||
|
libxkbcommon-dev \
|
||||||
|
python3-pil
|
||||||
|
|
||||||
|
|
||||||
|
- name: Build Linux GLFW x64
|
||||||
|
run: |
|
||||||
|
if [ -d "build" ]; then
|
||||||
|
rm -rf build
|
||||||
|
fi
|
||||||
|
mkdir build
|
||||||
|
mkdir release/linux-glfw-x64
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
|
cp build/src/Dawn release/linux-glfw-x64/Dawn
|
||||||
|
cp build/dawn.tar release/linux-glfw-x64/dawn.tar
|
||||||
|
|
||||||
|
# - name: Release
|
||||||
|
# uses: akkuman/gitea-release-action@v1
|
||||||
|
# with:
|
||||||
|
# files: |-
|
||||||
|
# release/
|
56
.github/workflows/build-helloworld-vita.yml
vendored
56
.github/workflows/build-helloworld-vita.yml
vendored
@ -1,56 +0,0 @@
|
|||||||
name: build-helloworld-vita
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
VITASDK: /usr/local/vitasdk
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Cache VITASDK
|
|
||||||
id: cache-vitasdk-restore
|
|
||||||
uses: actions/cache/restore@v3
|
|
||||||
with:
|
|
||||||
path: /usr/local/vitasdk
|
|
||||||
key: ${{ runner.os }}-vitasdk
|
|
||||||
|
|
||||||
- name: Install Vita Toolchain
|
|
||||||
if: steps.cache-vitasdk.outputs.cache-hit != 'true'
|
|
||||||
run: ./ci/install-vita-toolchain.sh
|
|
||||||
|
|
||||||
- name: Save VITASDK
|
|
||||||
id: cache-vitasdk-save
|
|
||||||
uses: actions/cache/save@v3
|
|
||||||
with:
|
|
||||||
path: /usr/local/vitasdk
|
|
||||||
key: ${{ steps.cache-vitasdk-restore.outputs.cache-primary-key }}
|
|
||||||
|
|
||||||
- name: Install Libraries
|
|
||||||
run: ./ci/install-libraries.sh
|
|
||||||
|
|
||||||
- name: Build Tools
|
|
||||||
run: ./ci/build-tools.sh
|
|
||||||
|
|
||||||
- name: Build Game
|
|
||||||
run: |
|
|
||||||
export PATH=$VITASDK/bin:$PATH
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake .. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
|
|
||||||
make
|
|
||||||
|
|
||||||
- name: Deploying
|
|
||||||
env:
|
|
||||||
DAWN_SSH_KEY: ${{ secrets.DAWN_SSH_KEY }}
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo -e "${DAWN_SSH_KEY}" > ~/.ssh/id_rsa
|
|
||||||
chmod og-rwx ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan -H wish.moe >> ~/.ssh/known_hosts
|
|
||||||
ssh -t yourwishes@wish.moe "mkdir -p /home/yourwishes/Dawn/vita/debug"
|
|
||||||
scp ./build/src/dawnvita/HelloWorld.vpk yourwishes@wish.moe:/home/yourwishes/Dawn/vita/debug/
|
|
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
@ -1,26 +0,0 @@
|
|||||||
name: build-liminal-glfw-linux64
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Toolchain
|
|
||||||
run: ./ci/install-linux-toolchain.sh
|
|
||||||
|
|
||||||
- name: Install Libraries
|
|
||||||
run: ./ci/install-libraries.sh
|
|
||||||
|
|
||||||
- name: Build Tools
|
|
||||||
run: ./ci/build-tools.sh
|
|
||||||
|
|
||||||
- name: Build Game
|
|
||||||
run: |
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake .. -DDAWN_BUILD_TARGET=target-liminial-linux64-glfw
|
|
||||||
make
|
|
21
.gitmodules
vendored
21
.gitmodules
vendored
@ -1,21 +0,0 @@
|
|||||||
[submodule "lib/glfw"]
|
|
||||||
path = lib/glfw
|
|
||||||
url = https://github.com/glfw/glfw.git
|
|
||||||
[submodule "lib/glm"]
|
|
||||||
path = lib/glm
|
|
||||||
url = https://github.com/g-truc/glm.git
|
|
||||||
[submodule "lib/SDL"]
|
|
||||||
path = lib/SDL
|
|
||||||
url = https://github.com/libsdl-org/SDL.git
|
|
||||||
[submodule "lib/openal-soft"]
|
|
||||||
path = lib/openal-soft
|
|
||||||
url = https://github.com/kcat/openal-soft
|
|
||||||
[submodule "lib/AudioFile"]
|
|
||||||
path = lib/AudioFile
|
|
||||||
url = https://github.com/adamstark/AudioFile.git
|
|
||||||
[submodule "lib/freetype"]
|
|
||||||
path = lib/freetype
|
|
||||||
url = https://gitlab.freedesktop.org/freetype/freetype.git
|
|
||||||
[submodule "lib/libarchive"]
|
|
||||||
path = lib/libarchive
|
|
||||||
url = https://github.com/libarchive/libarchive
|
|
@ -7,11 +7,11 @@ cmake_minimum_required(VERSION 3.13)
|
|||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
|
||||||
|
|
||||||
# Variable Caches
|
# Variable Caches
|
||||||
set(DAWN_CACHE_TARGET "dawn-target")
|
set(DAWN_CACHE_TARGET "dawn-target")
|
||||||
|
set(DAWN_TARGET_NAME "Dawn")
|
||||||
|
|
||||||
# Set Common Build Variables
|
# Set Common Build Variables
|
||||||
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||||
@ -23,10 +23,9 @@ set(DAWN_ASSETS_BUILD_DIR "${DAWN_BUILD_DIR}/assets")
|
|||||||
set(DAWN_GENERATED_DIR "${DAWN_BUILD_DIR}/generated")
|
set(DAWN_GENERATED_DIR "${DAWN_BUILD_DIR}/generated")
|
||||||
set(DAWN_TEMP_DIR "${DAWN_BUILD_DIR}/temp")
|
set(DAWN_TEMP_DIR "${DAWN_BUILD_DIR}/temp")
|
||||||
|
|
||||||
# Add CMake Tools
|
# Options
|
||||||
add_subdirectory(cmake)
|
option(DAWN_ENABLE_PHYSICS "Enable Physics" OFF)
|
||||||
|
option(DAWN_DEBUG_SHADERS "Enable Debug Shaders" ON)
|
||||||
set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/src/${DAWN_BUILDING}/${DAWN_TARGET_NAME})
|
|
||||||
|
|
||||||
# Initialize Project First.
|
# Initialize Project First.
|
||||||
project(Dawn
|
project(Dawn
|
||||||
|
@ -87,6 +87,27 @@ namespace Dawn {
|
|||||||
assertNoGLError();
|
assertNoGLError();
|
||||||
assertTrue(status == GL_TRUE, "Failed to link shader program.");
|
assertTrue(status == GL_TRUE, "Failed to link shader program.");
|
||||||
|
|
||||||
|
std::vector<std::string> uniformNames;
|
||||||
|
GLint numUniforms = 0;
|
||||||
|
|
||||||
|
// Get the number of active uniforms
|
||||||
|
glGetProgramiv(shaderProgram, GL_ACTIVE_UNIFORMS, &numUniforms);
|
||||||
|
assertNoGLError();
|
||||||
|
|
||||||
|
// Iterate through each uniform
|
||||||
|
// for (GLint i = 0; i < numUniforms; ++i) {
|
||||||
|
// char name[256];
|
||||||
|
// GLsizei length;
|
||||||
|
// GLint size;
|
||||||
|
// GLenum type;
|
||||||
|
|
||||||
|
// // Get the uniform name
|
||||||
|
// glGetActiveUniform(shaderProgram, i, sizeof(name), &length, &size, &type, name);
|
||||||
|
// assertNoGLError();
|
||||||
|
// std::cout << "Uniform: " << i << ":" << name << std::endl;
|
||||||
|
// // uniformNames.push_back(std::string(name));
|
||||||
|
// }
|
||||||
|
|
||||||
// Map parameters correctly.
|
// Map parameters correctly.
|
||||||
std::for_each(
|
std::for_each(
|
||||||
parameters.begin(),
|
parameters.begin(),
|
74
archive/ShaderStage.cpp
Normal file
74
archive/ShaderStage.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "assert/assertgl.hpp"
|
||||||
|
#include "assert/assert.hpp"
|
||||||
|
#include "ShaderStage.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
ShaderStage::ShaderStage(
|
||||||
|
const enum ShaderStageType type,
|
||||||
|
const std::string source
|
||||||
|
) : IShaderStage(type) {
|
||||||
|
// Get OpenGL Shader Type
|
||||||
|
GLenum shaderType;
|
||||||
|
switch(this->type) {
|
||||||
|
case ShaderStageType::VERTEX:
|
||||||
|
shaderType = GL_VERTEX_SHADER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ShaderStageType::FRAGMENT:
|
||||||
|
shaderType = GL_FRAGMENT_SHADER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// case ShaderStageType::COMPUTE:
|
||||||
|
// shaderType = GL_COMPUTE;
|
||||||
|
// break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertUnreachable("Unknown ShaderStageType");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the shader
|
||||||
|
this->id = glCreateShader(shaderType);
|
||||||
|
assertNoGLError();
|
||||||
|
|
||||||
|
// Compile the shader
|
||||||
|
auto cSource = source.c_str();
|
||||||
|
glShaderSource(this->id, 1, &cSource, NULL);
|
||||||
|
assertNoGLError();
|
||||||
|
glCompileShader(this->id);
|
||||||
|
assertNoGLError();
|
||||||
|
|
||||||
|
// glShaderBinary(1, &this->id, GL_SHADER_BINARY_FORMAT_SPIR_V, source.data(), source.size());
|
||||||
|
// assertNoGLError();
|
||||||
|
// glSpecializeShader(this->id, "main", 0, NULL, NULL);
|
||||||
|
// assertNoGLError();
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
GLint status;
|
||||||
|
glGetShaderiv(this->id, GL_COMPILE_STATUS, &status);
|
||||||
|
assertNoGLError();
|
||||||
|
|
||||||
|
if(!status) {
|
||||||
|
// Failed to compile
|
||||||
|
GLint logLength;
|
||||||
|
glGetShaderiv(this->id, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
assertNoGLError();
|
||||||
|
|
||||||
|
GLchar *log = new GLchar[logLength];
|
||||||
|
glGetShaderInfoLog(this->id, logLength, NULL, log);
|
||||||
|
assertNoGLError();
|
||||||
|
assertUnreachable("Failed to compile shader stage %i:\n%s", type, log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderStage::~ShaderStage() {
|
||||||
|
if(this->id != -1) {
|
||||||
|
glDeleteShader(this->id);
|
||||||
|
assertNoGLError();
|
||||||
|
}
|
||||||
|
}
|
28
archive/ShaderStage.hpp
Normal file
28
archive/ShaderStage.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawnopengl.hpp"
|
||||||
|
#include "display/shader/IShaderStage.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class ShaderStage : public IShaderStage {
|
||||||
|
public:
|
||||||
|
GLuint id = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new ShaderStage.
|
||||||
|
*
|
||||||
|
* @param type The type of shader this is.
|
||||||
|
* @param source The source code to compile.
|
||||||
|
*/
|
||||||
|
ShaderStage(const enum ShaderStageType type, const std::string source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of the shader stage.
|
||||||
|
*/
|
||||||
|
~ShaderStage();
|
||||||
|
};
|
||||||
|
}
|
@ -39,6 +39,7 @@ namespace Dawn {
|
|||||||
* @param getParameters A callback that, when invoked, will populate the
|
* @param getParameters A callback that, when invoked, will populate the
|
||||||
* parameters vector with the parameters for this
|
* parameters vector with the parameters for this
|
||||||
* structure.
|
* structure.
|
||||||
|
* @param count The number of structures to create.
|
||||||
*/
|
*/
|
||||||
ShaderStructure(
|
ShaderStructure(
|
||||||
const std::string &structureName,
|
const std::string &structureName,
|
230
archive/SimpleTexturedShader.cpp
Normal file
230
archive/SimpleTexturedShader.cpp
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "display/shader/SimpleTexturedShader.hpp"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include "slang.h"
|
||||||
|
#include "slang-gfx.h"
|
||||||
|
using namespace slang;
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
void SimpleTexturedShader::getStages(
|
||||||
|
const enum ShaderOpenGLVariant variant,
|
||||||
|
const struct SimpleTexturedShaderData *rel,
|
||||||
|
std::vector<std::shared_ptr<ShaderStage>> &stages,
|
||||||
|
std::vector<struct ShaderParameter> ¶meters,
|
||||||
|
std::vector<struct IShaderStructure> &structures
|
||||||
|
) {
|
||||||
|
// Stages
|
||||||
|
std::shared_ptr<ShaderStage> vertex;
|
||||||
|
std::shared_ptr<ShaderStage> fragment;
|
||||||
|
|
||||||
|
std::string shader = R"(
|
||||||
|
cbuffer Uniforms {
|
||||||
|
float4x4 u_Projection;
|
||||||
|
float4x4 u_View;
|
||||||
|
float4x4 u_Model;
|
||||||
|
float4 u_Color;
|
||||||
|
bool u_HasTexture;
|
||||||
|
uniform Sampler2D u_Texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AssembledVertex {
|
||||||
|
float3 position : POSITION;
|
||||||
|
float2 texcoord : TEXCOORD;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Fragment {
|
||||||
|
float4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexStageOutput {
|
||||||
|
float2 uv : UV;
|
||||||
|
float4 sv_position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VertexStageOutput vertexMain(
|
||||||
|
AssembledVertex assembledVertex
|
||||||
|
) {
|
||||||
|
VertexStageOutput output;
|
||||||
|
|
||||||
|
float3 position = assembledVertex.position;
|
||||||
|
|
||||||
|
output.uv = assembledVertex.texcoord;
|
||||||
|
|
||||||
|
output.sv_position = mul(
|
||||||
|
float4(position, 1.0),
|
||||||
|
mul(u_Model, mul(u_View, u_Projection))
|
||||||
|
);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
Fragment fragmentMain(
|
||||||
|
float2 uv: UV
|
||||||
|
) : SV_Target {
|
||||||
|
Fragment output;
|
||||||
|
if(u_HasTexture) {
|
||||||
|
output.color = u_Texture.Sample(uv) * u_Color;
|
||||||
|
} else {
|
||||||
|
output.color = u_Color;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
Slang::ComPtr<IGlobalSession> globalSession;
|
||||||
|
createGlobalSession(globalSession.writeRef());
|
||||||
|
|
||||||
|
SessionDesc sessionDesc;
|
||||||
|
|
||||||
|
TargetDesc targetDesc;
|
||||||
|
targetDesc.format = SLANG_GLSL;
|
||||||
|
targetDesc.profile = globalSession->findProfile("glsl_330");
|
||||||
|
sessionDesc.targets = &targetDesc;
|
||||||
|
sessionDesc.targetCount = 1;
|
||||||
|
|
||||||
|
Slang::ComPtr<IBlob> diagnostics;
|
||||||
|
const char* searchPaths[] = { "/home/yourwishes/htdocs/Dawn/assets/shaders/" };
|
||||||
|
sessionDesc.searchPaths = searchPaths;
|
||||||
|
sessionDesc.searchPathCount = 1;
|
||||||
|
|
||||||
|
Slang::ComPtr<ISession> session;
|
||||||
|
globalSession->createSession(sessionDesc, session.writeRef());
|
||||||
|
auto module = session->loadModuleFromSourceString(
|
||||||
|
"hello-world.slang",
|
||||||
|
"hello-world.slang",
|
||||||
|
shader.c_str(),
|
||||||
|
diagnostics.writeRef()
|
||||||
|
);
|
||||||
|
if(diagnostics) {
|
||||||
|
assertUnreachable("Failed to load module %s", (const char*) diagnostics->getBufferPointer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Slang::ComPtr<IEntryPoint> vertexEntryPoint;
|
||||||
|
Slang::ComPtr<IEntryPoint> fragEntryPoint;
|
||||||
|
module->findEntryPointByName("vertexMain", vertexEntryPoint.writeRef());
|
||||||
|
module->findEntryPointByName("fragmentMain", fragEntryPoint.writeRef());
|
||||||
|
|
||||||
|
IComponentType* components[] = { module, vertexEntryPoint, fragEntryPoint };
|
||||||
|
Slang::ComPtr<IComponentType> program;
|
||||||
|
session->createCompositeComponentType(
|
||||||
|
components,
|
||||||
|
sizeof(components) / sizeof(components[0]),
|
||||||
|
program.writeRef()
|
||||||
|
);
|
||||||
|
|
||||||
|
Slang::ComPtr<IComponentType> linkedProgram;
|
||||||
|
auto result = program->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
||||||
|
std::cout << "Result: " << result << std::endl;
|
||||||
|
if(diagnostics) {
|
||||||
|
assertUnreachable("%s\n", (const char*) diagnostics->getBufferPointer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int entryPointIndex = 0;
|
||||||
|
int targetIndex = 0; // only one target
|
||||||
|
Slang::ComPtr<IBlob> vertexBlob;
|
||||||
|
result = linkedProgram->getEntryPointCode(
|
||||||
|
entryPointIndex,
|
||||||
|
targetIndex,
|
||||||
|
vertexBlob.writeRef(),
|
||||||
|
diagnostics.writeRef()
|
||||||
|
);
|
||||||
|
if(diagnostics) {
|
||||||
|
assertUnreachable("%s\n", (const char*) diagnostics->getBufferPointer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
slang::ProgramLayout* layout = program->getLayout();
|
||||||
|
unsigned parameterCount = layout->getParameterCount();
|
||||||
|
for(unsigned pp = 0; pp < parameterCount; pp++) {
|
||||||
|
slang::VariableLayoutReflection* parameter = layout->getParameterByIndex(pp);
|
||||||
|
std::cout << "Parameter: " << parameter->getName() << std::endl;
|
||||||
|
|
||||||
|
auto layout = parameter->getTypeLayout();
|
||||||
|
auto fields = layout->getFieldCount();
|
||||||
|
for(unsigned ff = 0; ff < fields; ff++) {
|
||||||
|
slang::VariableLayoutReflection* field = layout->getFieldByIndex(ff);
|
||||||
|
std::string fieldName = field->getName();
|
||||||
|
std::cout << "Field: " << fieldName << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string vertexString = (const char*)vertexBlob->getBufferPointer();
|
||||||
|
|
||||||
|
entryPointIndex = 1;
|
||||||
|
Slang::ComPtr<IBlob> fragmentBlob;
|
||||||
|
result = linkedProgram->getEntryPointCode(
|
||||||
|
entryPointIndex,
|
||||||
|
targetIndex,
|
||||||
|
fragmentBlob.writeRef(),
|
||||||
|
diagnostics.writeRef()
|
||||||
|
);
|
||||||
|
if(diagnostics) {
|
||||||
|
assertUnreachable("%s\n", (const char*) diagnostics->getBufferPointer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string fragmentString = (const char*)fragmentBlob->getBufferPointer();
|
||||||
|
|
||||||
|
vertex = std::make_shared<ShaderStage>(
|
||||||
|
ShaderStageType::VERTEX, vertexString
|
||||||
|
);
|
||||||
|
stages.push_back(vertex);
|
||||||
|
|
||||||
|
fragment = std::make_shared<ShaderStage>(
|
||||||
|
ShaderStageType::FRAGMENT, fragmentString
|
||||||
|
);
|
||||||
|
stages.push_back(fragment);
|
||||||
|
|
||||||
|
structures.push_back(ShaderStructure<struct SimpleTexturedShaderDataSub>(
|
||||||
|
"block_SLANG_ParameterGroup_Uniforms_std140_0",
|
||||||
|
&rel->data,
|
||||||
|
ShaderOpenGLStructureType::STD140,
|
||||||
|
[](const SimpleTexturedShaderDataSub &data, std::vector<struct ShaderParameter> ¶meters) {
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"u_Projection_0",
|
||||||
|
&data.projection,
|
||||||
|
ShaderParameterType::MAT4
|
||||||
|
));
|
||||||
|
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"u_View_0",
|
||||||
|
&data.view,
|
||||||
|
ShaderParameterType::MAT4
|
||||||
|
));
|
||||||
|
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"u_Model_0",
|
||||||
|
&data.model,
|
||||||
|
ShaderParameterType::MAT4
|
||||||
|
));
|
||||||
|
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"u_Color_0",
|
||||||
|
&data.color,
|
||||||
|
ShaderParameterType::COLOR
|
||||||
|
));
|
||||||
|
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"u_HasTexture_0",
|
||||||
|
&data.hasTexture,
|
||||||
|
ShaderParameterType::BOOLEAN
|
||||||
|
));
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
// Parameters
|
||||||
|
parameters.push_back(ShaderParameter(
|
||||||
|
"Uniforms_u_Texture_0",
|
||||||
|
&rel->texture,
|
||||||
|
ShaderParameterType::TEXTURE
|
||||||
|
));
|
||||||
|
}
|
@ -7,12 +7,17 @@
|
|||||||
#include "display/shader/Shader.hpp"
|
#include "display/shader/Shader.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct SimpleTexturedShaderData {
|
struct SimpleTexturedShaderDataSub {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 view;
|
glm::mat4 view;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
struct Color color = COLOR_WHITE;
|
struct Color color = COLOR_WHITE;
|
||||||
|
|
||||||
bool hasTexture = false;
|
bool hasTexture = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleTexturedShaderData {
|
||||||
|
struct SimpleTexturedShaderDataSub data;
|
||||||
shadertexturebinding_t texture = 0;
|
shadertexturebinding_t texture = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -139,6 +139,6 @@ void UICanvas::flushPass() {
|
|||||||
textureBindings.clear();
|
textureBindings.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICanvas::addElement(std::shared_ptr<UIElement> element) {
|
void UICanvas::addElement(const std::shared_ptr<UIElement> element) {
|
||||||
elements.push_back(element);
|
elements.push_back(element);
|
||||||
}
|
}
|
@ -68,6 +68,6 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param component The component to add.
|
* @param component The component to add.
|
||||||
*/
|
*/
|
||||||
void addElement(std::shared_ptr<UIElement> component);
|
void addElement(const std::shared_ptr<UIElement> component);
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
UILabel.cpp
|
||||||
UIRectangle.cpp
|
UIRectangle.cpp
|
||||||
)
|
)
|
42
assets/en.json
Normal file
42
assets/en.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"main_menu": {
|
||||||
|
"new_game": "New Game",
|
||||||
|
"load_game": "Load Game",
|
||||||
|
"options": "Options",
|
||||||
|
"exit": "Exit"
|
||||||
|
},
|
||||||
|
"tiles": {
|
||||||
|
"water": {
|
||||||
|
"interact": "A refreshing body of water."
|
||||||
|
},
|
||||||
|
"lamp": {
|
||||||
|
"interact": "An electric lamp.\nA real lightbulb idea."
|
||||||
|
},
|
||||||
|
"rail": {
|
||||||
|
"interact": "Train tracks.\n...Better not cross them."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"entities": {
|
||||||
|
"sign": {
|
||||||
|
"name": "Sign"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maps": {
|
||||||
|
"testmap": {
|
||||||
|
"bob": "Hello, I am Bob.",
|
||||||
|
"sign": "This is a sign.",
|
||||||
|
"sign2": {
|
||||||
|
"1": "This is another sign.",
|
||||||
|
"2": "It has two lines."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"train_station": {
|
||||||
|
"stair_sign": {
|
||||||
|
"0": "Stairs slippery when wet.\n\n<- West to Town.\n-> East to lakefront."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battle": {
|
||||||
|
"start": "Battle Start!"
|
||||||
|
}
|
||||||
|
}
|
8
assets/maps/testmap.json
Normal file
8
assets/maps/testmap.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Test Map",
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
8
assets/materials/simple-textured.json
Normal file
8
assets/materials/simple-textured.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"assets": {
|
||||||
|
"simpleTexturedShader": {
|
||||||
|
"type": "shader",
|
||||||
|
"path": "shaders/simple-textured.shader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
assets/prefabs/npc.json
Normal file
26
assets/prefabs/npc.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "Rosa",
|
||||||
|
|
||||||
|
"assets": {
|
||||||
|
"rosa": {
|
||||||
|
"type": "texture",
|
||||||
|
"path": "rosa.texture"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"components": {
|
||||||
|
"mesh": {
|
||||||
|
"type": "QuadMesh"
|
||||||
|
},
|
||||||
|
"material": {
|
||||||
|
"type": "SimpleTexturedMaterial",
|
||||||
|
"texture": "rosa"
|
||||||
|
},
|
||||||
|
"meshRenderer": {
|
||||||
|
"type": "MeshRenderer"
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"type": "RPGEntity"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
assets/prefabs/rosa.json
Normal file
29
assets/prefabs/rosa.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "Rosa",
|
||||||
|
|
||||||
|
"assets": {
|
||||||
|
"rosa": {
|
||||||
|
"type": "texture",
|
||||||
|
"path": "rosa.texture"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"components": {
|
||||||
|
"mesh": {
|
||||||
|
"type": "QuadMesh"
|
||||||
|
},
|
||||||
|
"material": {
|
||||||
|
"type": "SimpleTexturedMaterial",
|
||||||
|
"texture": "rosa"
|
||||||
|
},
|
||||||
|
"meshRenderer": {
|
||||||
|
"type": "MeshRenderer"
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"type": "RPGEntity"
|
||||||
|
},
|
||||||
|
"player": {
|
||||||
|
"type": "RPGPlayer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
assets/rosa.png
Normal file
BIN
assets/rosa.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
47
assets/scenes/test_rpg_scene.json
Normal file
47
assets/scenes/test_rpg_scene.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "Test RPG Scene",
|
||||||
|
|
||||||
|
"assets": {
|
||||||
|
"rosa": {
|
||||||
|
"type": "prefab",
|
||||||
|
"path": "prefabs/rosa.json"
|
||||||
|
},
|
||||||
|
"npc": {
|
||||||
|
"type": "prefab",
|
||||||
|
"path": "prefabs/npc.json"
|
||||||
|
},
|
||||||
|
"rosatext": {
|
||||||
|
"type": "texture",
|
||||||
|
"path": "rosa.texture"
|
||||||
|
},
|
||||||
|
"simpleTexturedShader": {
|
||||||
|
"type": "shader",
|
||||||
|
"path": "shaders/simple-textured.slang"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"items": {
|
||||||
|
"camera": {
|
||||||
|
"components": {
|
||||||
|
"camera": {
|
||||||
|
"type": "camera"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"rosa": {
|
||||||
|
"prefab": "rosa",
|
||||||
|
"position": [ 0, 0, 0 ],
|
||||||
|
"components": {
|
||||||
|
"player": {
|
||||||
|
"camera": "camera"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"npc": {
|
||||||
|
"prefab": "npc",
|
||||||
|
"position": [ 32, 0, 0 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
assets/shaders/simple-textured.slang
Normal file
53
assets/shaders/simple-textured.slang
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
uniform float4x4 projection;
|
||||||
|
uniform float4x4 view;
|
||||||
|
uniform float4x4 model;
|
||||||
|
uniform float4 color;
|
||||||
|
uniform bool hasTexture;
|
||||||
|
uniform Sampler2D texture;
|
||||||
|
|
||||||
|
struct AssembledVertex {
|
||||||
|
float3 position : POSITION;
|
||||||
|
float2 texcoord : TEXCOORD;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Fragment {
|
||||||
|
float4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexStageOutput {
|
||||||
|
float2 uv : UV;
|
||||||
|
float4 sv_position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VertexStageOutput vertexMain(
|
||||||
|
AssembledVertex assembledVertex
|
||||||
|
) {
|
||||||
|
VertexStageOutput output;
|
||||||
|
|
||||||
|
float3 position = assembledVertex.position;
|
||||||
|
|
||||||
|
output.uv = assembledVertex.texcoord;
|
||||||
|
|
||||||
|
output.sv_position = mul(
|
||||||
|
float4(position, 1.0),
|
||||||
|
mul(model, mul(view, projection))
|
||||||
|
);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
Fragment fragmentMain(
|
||||||
|
float2 uv: UV
|
||||||
|
) : SV_Target {
|
||||||
|
Fragment output;
|
||||||
|
|
||||||
|
if (hasTexture) {
|
||||||
|
output.color = texture.Sample(uv) * color;
|
||||||
|
} else {
|
||||||
|
output.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
@ -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
|
|
@ -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 ../..
|
|
@ -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})
|
|
@ -1,340 +0,0 @@
|
|||||||
# Compiling, Debugging and Running
|
|
||||||
This document's purpose is to explain how to compile, debug and run the project
|
|
||||||
on your machine. It is assumed that you have a basic understanding of the
|
|
||||||
fundamentals of your operating system and how to use a terminal.
|
|
||||||
|
|
||||||
## Preamble
|
|
||||||
The Dawn project is written almost entirely in C and C++. This includes all of
|
|
||||||
the tooling used to generate the project and assets. The only non-C/C++ code is
|
|
||||||
used by CMake to generate the output compilation files. This provides the Dawn
|
|
||||||
project an extremely high level of portability not typically seen in other
|
|
||||||
projects.
|
|
||||||
|
|
||||||
## TLDR; Version
|
|
||||||
This document is going to go over the installation and configuration of the
|
|
||||||
following items. If you are already familiar with these tools, you can skip to
|
|
||||||
the "Downloading the Source Code" section.
|
|
||||||
- C/C++ Compiler
|
|
||||||
- CMake
|
|
||||||
- Git
|
|
||||||
- IDE
|
|
||||||
You may also need *python*, since we depend on third-party libraries that may use
|
|
||||||
python scripts to generate their own build files. This is not required for the
|
|
||||||
Dawn project itself.
|
|
||||||
|
|
||||||
## Pre-Configuration
|
|
||||||
In order to compile the Dawn project, you are required to have the following
|
|
||||||
tools installed on your machine.
|
|
||||||
|
|
||||||
### 1. A C/C++ Compiler
|
|
||||||
The exact tool(s) will depend on your specific scenario. The compiler is used to
|
|
||||||
take the .cpp/.hpp files and generating binaries that execute on the target
|
|
||||||
machine. Typically you will use your own C/C++ compiler for the machine that you
|
|
||||||
are currently running, e.g. if you are running Windows, you will use the Visual
|
|
||||||
Studio compiler. If you are running Linux, you will use GCC or Clang. If you are
|
|
||||||
running macOS, you will use Clang, and so-on.
|
|
||||||
|
|
||||||
If you are intending to compile on a different machine than the one you are
|
|
||||||
currently running, you will need to use a cross-compiler that is specific for
|
|
||||||
your use-case. You will also need to refer to the documentation for creating a
|
|
||||||
new Dawn engine target.
|
|
||||||
|
|
||||||
Please follow the instructions for your specific operating system to install the
|
|
||||||
appropriate C/C++ compiler.
|
|
||||||
|
|
||||||
**Windows**
|
|
||||||
You will need to download and install [Visual Studio](https://visualstudio.microsoft.com/downloads/).
|
|
||||||
Visual Studio (not to be confused with Visual Studio Code) is a full IDE that
|
|
||||||
bundles the official Microsoft C/C++ compiler. It is the recommended compiler
|
|
||||||
for building the Dawn project on Windows.
|
|
||||||
|
|
||||||
Advanced used can also use [MinGW](http://www.mingw.org/) or another compiler if
|
|
||||||
they wish, however this is not officially supported.
|
|
||||||
|
|
||||||
After installing Visual Studio, you will need to install the C++ development
|
|
||||||
tools. This can be done by opening the Visual Studio Installer and selecting
|
|
||||||
the "Desktop development with C++" workload.
|
|
||||||
|
|
||||||
**Linux**
|
|
||||||
You will need to install the GCC and Clang compilers. The compilers are usually
|
|
||||||
installed either by default or by installing the necessary packages for your
|
|
||||||
Linux distribution.
|
|
||||||
|
|
||||||
For example, on Ubuntu, you can install the GCC and Clang compilers by running
|
|
||||||
the following command:
|
|
||||||
```bash
|
|
||||||
sudo apt install build-essential clang
|
|
||||||
```
|
|
||||||
|
|
||||||
On Arch Linux, you can install the GCC and Clang compilers by running the
|
|
||||||
following command:
|
|
||||||
```bash
|
|
||||||
sudo pacman -S base-devel clang
|
|
||||||
```
|
|
||||||
|
|
||||||
And on Fedora, you can install the GCC and Clang compilers by running the
|
|
||||||
following command:
|
|
||||||
```bash
|
|
||||||
sudo dnf install @development-tools clang
|
|
||||||
```
|
|
||||||
|
|
||||||
For other distributions, please refer to your distribution's documentation.
|
|
||||||
|
|
||||||
**macOS**
|
|
||||||
You will need to install the Xcode command line tools. This can be done by done
|
|
||||||
by running the following command in your terminal:
|
|
||||||
```bash
|
|
||||||
xcode-select --install
|
|
||||||
```
|
|
||||||
|
|
||||||
Afterwards you will need to install and enable [Brew](https://brew.sh/). This
|
|
||||||
can be done by running the following command in your terminal:
|
|
||||||
```bash
|
|
||||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### 2. CMake
|
|
||||||
CMake is a tool that is used to generate the compilation files for the Dawn
|
|
||||||
project. In short this is used to create versions of the Dawn project that can
|
|
||||||
be compiled on all different sets of compilers, so if you are compiling on, for
|
|
||||||
example, Windows, you can use CMake to generate the compilation files for the
|
|
||||||
Visual Studio compiler, or if you are compiling on Linux, you can use CMake to
|
|
||||||
generate the compilation files for the GCC or Clang compilers, and so-on.
|
|
||||||
|
|
||||||
To install CMake, please follow the instructions for your specific operating
|
|
||||||
system. All other operating systems can be found on the [CMake downloads page](https://cmake.org/download/).
|
|
||||||
|
|
||||||
**Windows**
|
|
||||||
You will need to download and install [CMake](https://cmake.org/download/). The
|
|
||||||
installer will guide you through the installation process and will install the
|
|
||||||
CMake executable to your system. It is recommended that you add CMake to your
|
|
||||||
system PATH if requested by the installer.
|
|
||||||
|
|
||||||
**Linux**
|
|
||||||
Like installing the C/C++ compilers, you will need to install CMake using your
|
|
||||||
specific Linux distribution's package manager, there is also a chance that CMake
|
|
||||||
can be installed using flatpak or snap. Please refer to your distribution's
|
|
||||||
documentation for more information.
|
|
||||||
|
|
||||||
For Ubuntu and other Debian-based distributions, you can install CMake by using
|
|
||||||
the following command:
|
|
||||||
```bash
|
|
||||||
sudo apt install cmake
|
|
||||||
```
|
|
||||||
|
|
||||||
For Arch Linux, you can install CMake by using the following command:
|
|
||||||
```bash
|
|
||||||
sudo pacman -S cmake
|
|
||||||
```
|
|
||||||
|
|
||||||
And for Fedora, you can install CMake by using the following command:
|
|
||||||
```bash
|
|
||||||
sudo dnf install cmake
|
|
||||||
```
|
|
||||||
|
|
||||||
**macOS**
|
|
||||||
You will install CMake using brew. We detailed how to install brew in the C/C++
|
|
||||||
compiler section. To install CMake, run the following command in your terminal:
|
|
||||||
```bash
|
|
||||||
brew install cmake
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Git
|
|
||||||
Git is a version control system that is used to manage the Dawn project's source
|
|
||||||
code. It is used to download the source code, and to update the source code to
|
|
||||||
the latest version. It is also used to manage the project's dependencies. Git is
|
|
||||||
a standard tool in the programming industry and is used to manage complex
|
|
||||||
projects, especially those that are worked on by multiple people.
|
|
||||||
|
|
||||||
Git, like all of the above tools, is installed slightly differently depending on
|
|
||||||
your operating system. Please follow the instructions for your specific
|
|
||||||
operating system.
|
|
||||||
|
|
||||||
**Windows**
|
|
||||||
You will need to download and install [Git](https://git-scm.com/downloads). The
|
|
||||||
installer will guide you through the installation process and will install the
|
|
||||||
Git executable to your system. It is recommended that you add Git to your system
|
|
||||||
PATH if requested by the installer. You do not need to add the Context-menu
|
|
||||||
items to your system.
|
|
||||||
|
|
||||||
**Linux**
|
|
||||||
Like installing the C/C++ compilers, you will need to install Git using your
|
|
||||||
specific Linux distribution's package manager. It is also likely that git would
|
|
||||||
have been installed by default. Please refer to your distribution's docs for
|
|
||||||
more information.
|
|
||||||
|
|
||||||
For Ubuntu and other Debian-based distributions, you can install Git by using
|
|
||||||
the following command:
|
|
||||||
```bash
|
|
||||||
sudo apt install git
|
|
||||||
```
|
|
||||||
|
|
||||||
For Arch Linux, you can install Git by using the following command:
|
|
||||||
```bash
|
|
||||||
sudo pacman -S git
|
|
||||||
```
|
|
||||||
|
|
||||||
And for Fedora, you can install Git by using the following command:
|
|
||||||
```bash
|
|
||||||
sudo dnf install git
|
|
||||||
```
|
|
||||||
|
|
||||||
**macOS**
|
|
||||||
You will install Git using brew. We detailed how to install brew in the C/C++
|
|
||||||
compiler section. To install Git, run the following command in your terminal:
|
|
||||||
```bash
|
|
||||||
brew install git
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. An IDE
|
|
||||||
An IDE (Integrated Development Environment) is a tool that is used to view and
|
|
||||||
edit code of projects. While it is not required to use an IDE, it is recommended
|
|
||||||
since it can make the process of editing and running the project much easier.
|
|
||||||
|
|
||||||
There are many different IDEs available, and often people chose an IDE that will
|
|
||||||
suit their preferences and needs, however if you are unsure of which IDE you
|
|
||||||
should be using, the Dawn project recommends using [Visual Studio Code](https://code.visualstudio.com/),
|
|
||||||
not to be confused with Visual Studio.
|
|
||||||
|
|
||||||
Visual Studio Code is a free and open-source IDE that is widely used in the
|
|
||||||
industry for its simple, modern and configurable interface. For example you can
|
|
||||||
configure VSCode to work on Web Projects, Game Projects, and more. It acts like
|
|
||||||
a text editor with a bunch of extra tools.
|
|
||||||
|
|
||||||
In addition to installing the VSCode IDE, we will add several recommended
|
|
||||||
plugins that will make editing the Dawn project easier and more seamless.
|
|
||||||
|
|
||||||
To install VSCode follow the instructions for your specific operating system on
|
|
||||||
the [VSCode downloads page](https://code.visualstudio.com/download), as it can
|
|
||||||
vary a lot between operating systems.
|
|
||||||
|
|
||||||
After installing VSCode, you will need to install the following plugins, by
|
|
||||||
clicking on the "Extensions" icon on the left-hand side of the VSCode window,
|
|
||||||
and searching for the following plugins. You may also be able to click on the
|
|
||||||
following links to install the plugins directly, but it may not work.
|
|
||||||
- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
|
|
||||||
- [CMake](https://marketplace.visualstudio.com/items?itemName=twxs.cmake)
|
|
||||||
- [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
|
|
||||||
|
|
||||||
## Downloading the Source Code
|
|
||||||
Now that you have all of the necessary tools installed, you can download the
|
|
||||||
source code of the project and using it to build. The source code contains all
|
|
||||||
of the code of the project, as well as the assets and the build scripts. This is
|
|
||||||
confidential information and should not be shared with anyone.
|
|
||||||
|
|
||||||
### 1. Cloning the Repository
|
|
||||||
We previously installed the git tool, which is used to download the source code
|
|
||||||
of the project, and some third-party libraries. To download the source code, you
|
|
||||||
will need to open a terminal and navigate to the directory where you want to
|
|
||||||
download the source code to.
|
|
||||||
|
|
||||||
Afterwards, you will need to run the following command:
|
|
||||||
```bash
|
|
||||||
git clone https://git.wish.moe/YourWishes/Dawn.git
|
|
||||||
```
|
|
||||||
This will download the source code of the project to a new subdirectory called
|
|
||||||
"Dawn" and put all of the projects' source code within there.
|
|
||||||
|
|
||||||
### 2. Installing the Dependencies / Libraries.
|
|
||||||
I try to keep dependencies on third-party libraries to a minimum, however there
|
|
||||||
are a few libraries that are required to build the Dawn project. These libraries
|
|
||||||
are not included in the source code, and must be downloaded separately. This is
|
|
||||||
done using the git tool.
|
|
||||||
|
|
||||||
After you have cloned the above repository, you will need to open a terminal and
|
|
||||||
navigate to the directory where you downloaded the source code to. Afterwards,
|
|
||||||
you will need to run the following command:
|
|
||||||
```bash
|
|
||||||
git submodule update --init --recursive
|
|
||||||
```
|
|
||||||
This will fetch all of the third-party libraries that are required to build the
|
|
||||||
Dawn project. This may take a while depending on your internet connection.
|
|
||||||
|
|
||||||
### 3. Loading the Project
|
|
||||||
This step is semi-optional. We are aiming to build the project using CMake, and
|
|
||||||
the easiest way to do this is to use the CMake Tools plugin for VSCode that we
|
|
||||||
installed earlier. This plugin will automatically detect the CMake files in the
|
|
||||||
project and will allow us to build the project using the VSCode interface.
|
|
||||||
|
|
||||||
If you opted out of using VSCode, you will need to set up your CMake environment
|
|
||||||
to suit your IDE or needs. This is outside of the scope of this document, and
|
|
||||||
you will need to refer to your IDE's documentation for more information.
|
|
||||||
|
|
||||||
To load the project, you will need to open VSCode and open the Dawn project
|
|
||||||
directory. Most operating systems will allow you to do this by dragging the
|
|
||||||
Dawn project directory onto the VSCode window. If this does not work, you can
|
|
||||||
open VSCode and click on the "File" menu, and click on "Open Folder". You will
|
|
||||||
then need to navigate to the Dawn project directory and click "Open".
|
|
||||||
|
|
||||||
Afterwards you will likely be prompted autometically to configure the CMake
|
|
||||||
Tools plugin. If you are not, you can click on the "CMake" icon on the left-hand
|
|
||||||
side of the VSCode window, and click on "Configure". This will configure the
|
|
||||||
CMake Tools plugin to use the CMake files in the Dawn project directory.
|
|
||||||
|
|
||||||
You may also be asked to select a compiler. If you are using Windows, you will
|
|
||||||
need to select the Visual Studio compiler. If you are using Linux, you will need
|
|
||||||
to select the GCC or Clang compiler. If you are using macOS, you will need to
|
|
||||||
select the Clang compiler. If you are using a different compiler, you will need
|
|
||||||
to select the appropriate compiler.
|
|
||||||
|
|
||||||
If prompted to select a build type, select "Debug".
|
|
||||||
|
|
||||||
## Compiling the Project
|
|
||||||
Now that we have the project loaded into our IDE, we can compile the project.
|
|
||||||
This is done using the CMake Tools plugin for VSCode. If you are not using
|
|
||||||
VSCode you will need to refer to your IDE's documentation for more information.
|
|
||||||
|
|
||||||
Firstly, you will need to create a settings file to configure the project. In
|
|
||||||
VSCode you can create a new folder called `.vscode` (Including the leading `.`)
|
|
||||||
in the Dawn project root directory. Afterwards, you will need to create a new
|
|
||||||
file called `settings.json` in the `.vscode` directory. You will then need to
|
|
||||||
paste the following into the file:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"cmake.configureArgs": [
|
|
||||||
"-DDAWN_BUILD_TOOLS=true",
|
|
||||||
"-DDAWN_BUILD_TARGET=target-liminal-win32-glfw",
|
|
||||||
"-DDAWN_DEBUG_BUILD=true"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
And save the file. You may want to alter the values to suit your needs. For
|
|
||||||
example, if you are compiling on Linux, you will need to change
|
|
||||||
`target-liminal-win32-glfw` to `target-liminal-linux-glfw`. If you are compiling
|
|
||||||
on macOS, you will need to change it to `target-liminal-osx-glfw`. The specific
|
|
||||||
configure arguments are outside of the scope of this document, and you will need
|
|
||||||
to refer to the specific target documentation for more information.
|
|
||||||
|
|
||||||
After you have created the settings file, you will need to configure and build
|
|
||||||
the project. To perform the build you need to click "Build" button the bottom of
|
|
||||||
the VSCode window. This will compile the project and will output the resulting
|
|
||||||
binaries in to a "build" directory within the Dawn project directory.
|
|
||||||
|
|
||||||
Upon clicking the "Build" button, you will see an output panel appear at the
|
|
||||||
bottom of the VSCode window. This will show the process of the build, and will
|
|
||||||
show any errors that may occur. This is used to debug and fix any issues that
|
|
||||||
may occur during the build process.
|
|
||||||
|
|
||||||
If the build was successful, you will see a "Build finished" message in the
|
|
||||||
output panel, typically read as;
|
|
||||||
```bash
|
|
||||||
[build] Build finished with exit code 0
|
|
||||||
```
|
|
||||||
If you do not see this message, or if the exit code is not 0, you will need to
|
|
||||||
debug the issue. The output panel will show the error message which is helpful
|
|
||||||
so we can debug the issue. If you are unable to debug the issue, you can ask for
|
|
||||||
help in the Discord server.
|
|
||||||
|
|
||||||
## Running the built project
|
|
||||||
After the build process succeeds you will be able to run the project. This is
|
|
||||||
done by clicking on the Run icon, which looks like a play button, on the bottom
|
|
||||||
of the VSCode window. This will run the project in production mode and will not
|
|
||||||
show any debug information.
|
|
||||||
|
|
||||||
If the program hangs, crashes or does not run, you can click the Debug icon,
|
|
||||||
which looks like a ladybug, on the bottom of the VSCode window. This will run
|
|
||||||
the project in debug mode and will show debug information and HALT the program
|
|
||||||
if there is an error detected. If program HALTS in debug mode you can use this
|
|
||||||
information to debug the issue. If you are unable to debug the issue, you can
|
|
||||||
ask for help in the Discord server.
|
|
Submodule lib/AudioFile deleted from 004065d01e
@ -3,51 +3,72 @@
|
|||||||
# 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
|
include(FetchContent)
|
||||||
if(DAWN_TARGET_GLFW)
|
|
||||||
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(glfw)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# SDL
|
# GLFW
|
||||||
if(DAWN_TARGET_SDL2)
|
FetchContent_Declare(glfw URL https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip)
|
||||||
add_subdirectory(glad)
|
FetchContent_MakeAvailable(glfw)
|
||||||
add_subdirectory(SDL)
|
|
||||||
endif()
|
add_subdirectory(glad)
|
||||||
|
|
||||||
# GLM
|
# GLM
|
||||||
add_subdirectory(glm)
|
FetchContent_Declare(
|
||||||
|
glm
|
||||||
|
GIT_REPOSITORY https://github.com/g-truc/glm
|
||||||
|
GIT_TAG 0af55ccecd98d4e5a8d1fad7de25ba429d60e863
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(glm)
|
||||||
|
|
||||||
# FreeType
|
# FreeType
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
|
FetchContent_Declare(
|
||||||
set(DAWN_EMSCRIPTEN_FLAGS "${DAWN_EMSCRIPTEN_FLAGS} -s USE_FREETYPE=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
freetype
|
||||||
else()
|
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype
|
||||||
add_subdirectory(freetype)
|
GIT_TAG VER-2-13-3
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(freetype)
|
||||||
|
|
||||||
|
#LibArchive
|
||||||
|
FetchContent_Declare(
|
||||||
|
libarchive
|
||||||
|
GIT_REPOSITORY https://github.com/libarchive/libarchive
|
||||||
|
GIT_TAG v3.7.6
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(libarchive)
|
||||||
|
|
||||||
|
# JSON
|
||||||
|
FetchContent_Declare(
|
||||||
|
json
|
||||||
|
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(json)
|
||||||
|
|
||||||
|
# JOLT Physics
|
||||||
|
if(DAWN_ENABLE_PHYSICS)
|
||||||
|
FetchContent_Declare(
|
||||||
|
JoltPhysics
|
||||||
|
GIT_REPOSITORY "https://github.com/jrouwe/JoltPhysics"
|
||||||
|
GIT_TAG "v5.2.0"
|
||||||
|
SOURCE_SUBDIR "Build"
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(JoltPhysics)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# LibArchive
|
# SLANG
|
||||||
if(DAWN_TARGET_ARCHIVE)
|
set(SLANG_ENABLE_GFX ON CACHE BOOL "Enable GFX" FORCE)
|
||||||
add_subdirectory(libarchive)
|
FetchContent_Declare(
|
||||||
endif()
|
slang
|
||||||
|
GIT_REPOSITORY https://github.com/shader-slang/slang
|
||||||
|
GIT_TAG v2024.17
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(slang)
|
||||||
|
|
||||||
|
|
||||||
# OpenAL
|
# OpenAL
|
||||||
if(DAWN_TARGET_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()
|
# endif()
|
||||||
|
|
||||||
# Emscripten (TESTING ONLY)
|
|
||||||
if(DEFINED DAWN_EMSCRIPTEN_FLAGS)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
|
||||||
endif()
|
|
1
lib/SDL
1
lib/SDL
Submodule lib/SDL deleted from fb1497566c
Submodule lib/freetype deleted from 7ff43d3e9f
@ -153,6 +153,20 @@ typedef int64_t khronos_int64_t;
|
|||||||
typedef uint64_t khronos_uint64_t;
|
typedef uint64_t khronos_uint64_t;
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(__VMS ) || defined(__sgi)
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
@ -235,14 +249,21 @@ typedef unsigned short int khronos_uint16_t;
|
|||||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
* to be the only LLP64 architecture in current use.
|
* to be the only LLP64 architecture in current use.
|
||||||
*/
|
*/
|
||||||
#ifdef _WIN64
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
typedef signed long long int khronos_intptr_t;
|
typedef signed long long int khronos_intptr_t;
|
||||||
typedef unsigned long long int khronos_uintptr_t;
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
typedef signed long long int khronos_ssize_t;
|
|
||||||
typedef unsigned long long int khronos_usize_t;
|
|
||||||
#else
|
#else
|
||||||
typedef signed long int khronos_intptr_t;
|
typedef signed long int khronos_intptr_t;
|
||||||
typedef unsigned long int khronos_uintptr_t;
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
typedef signed long int khronos_ssize_t;
|
typedef signed long int khronos_ssize_t;
|
||||||
typedef unsigned long int khronos_usize_t;
|
typedef unsigned long int khronos_usize_t;
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
1869
lib/glad/src/glad.c
1869
lib/glad/src/glad.c
File diff suppressed because it is too large
Load Diff
1
lib/glfw
1
lib/glfw
Submodule lib/glfw deleted from b35641f4a3
1
lib/glm
1
lib/glm
Submodule lib/glm deleted from 45008b225e
Submodule lib/libarchive deleted from 313aa1fa10
Submodule lib/openal-soft deleted from d3875f333f
@ -3,75 +3,32 @@
|
|||||||
# 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
|
# Build Project
|
||||||
add_executable(${DAWN_TARGET_NAME})
|
add_executable(${DAWN_TARGET_NAME})
|
||||||
|
|
||||||
# Change what we are building. Pulled from the cmake/targets dir.
|
# Validate game project includes the target name
|
||||||
if(DEFINED DAWN_BUILDING)
|
if(NOT DEFINED DAWN_TARGET_NAME)
|
||||||
add_subdirectory(${DAWN_BUILDING})
|
message(FATAL_ERROR "You need to define a target name")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Validate game project includes the target name
|
# Add in base library
|
||||||
if(DEFINED DAWN_TARGET_NAME)
|
add_subdirectory(dawn)
|
||||||
# Add in base library
|
add_subdirectory(dawnrpg)
|
||||||
add_subdirectory(dawn)
|
|
||||||
|
|
||||||
# Compile entry targets
|
if(DAWN_ENABLE_PHYSICS)
|
||||||
if(DAWN_TARGET_WIN32)
|
add_subdirectory(dawnphysics)
|
||||||
add_subdirectory(dawnwin32)
|
endif()
|
||||||
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
|
# Host Libraries
|
||||||
target_link_libraries(${DAWN_TARGET_NAME}
|
target_link_libraries(${DAWN_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${DAWN_BUILD_HOST_LIBS}
|
${DAWN_BUILD_HOST_LIBS}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Compile support targets
|
# Compile support targets
|
||||||
if(DAWN_TARGET_GLFW)
|
add_subdirectory(dawnglfw)
|
||||||
add_subdirectory(dawnglfw)
|
add_subdirectory(dawnopengl)
|
||||||
add_subdirectory(dawnopengl)
|
add_subdirectory(dawnlinux)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DAWN_TARGET_TRUETYPE)
|
# Compress the game assets.
|
||||||
add_subdirectory(dawntruetype)
|
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DAWN_TARGET_SDL2)
|
|
||||||
add_subdirectory(dawnsdl2)
|
|
||||||
add_subdirectory(dawnopengl)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DAWN_TARGET_VITA)
|
|
||||||
add_subdirectory(dawnopengl)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DAWN_TARGET_OPENAL)
|
|
||||||
add_subdirectory(dawnopenal)
|
|
||||||
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()
|
|
@ -6,8 +6,11 @@
|
|||||||
# Libraries
|
# Libraries
|
||||||
target_link_libraries(${DAWN_TARGET_NAME}
|
target_link_libraries(${DAWN_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
glm
|
|
||||||
archive_static
|
archive_static
|
||||||
|
glm::glm
|
||||||
|
nlohmann_json::nlohmann_json
|
||||||
|
freetype
|
||||||
|
slang
|
||||||
)
|
)
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
@ -16,6 +19,12 @@ target_include_directories(${DAWN_TARGET_NAME}
|
|||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Definitions
|
||||||
|
target_compile_definitions(${DAWN_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
DAWN_DEBUG_SHADERS=$<BOOL:${DAWN_DEBUG_SHADERS}>
|
||||||
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(assert)
|
add_subdirectory(assert)
|
||||||
add_subdirectory(asset)
|
add_subdirectory(asset)
|
||||||
@ -24,14 +33,16 @@ add_subdirectory(component)
|
|||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(environment)
|
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(save)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
# add_subdirectory(state)
|
add_subdirectory(settings)
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
add_subdirectory(ui)
|
|
||||||
|
|
||||||
|
# Assets
|
||||||
|
tool_copy(en en.json)
|
||||||
|
tool_copy(simpleTexturedShader shaders/simple-textured.slang)
|
||||||
|
|
||||||
|
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "util/Flag.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that a given statement must evaluate to true or the assertion fails
|
* Asserts that a given statement must evaluate to true or the assertion fails
|
||||||
@ -84,6 +84,17 @@ void assertTrueImplement(
|
|||||||
map.find(key) != map.end(), __VA_ARGS__ \
|
map.find(key) != map.end(), __VA_ARGS__ \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that a given map does not have a specific key.
|
||||||
|
* @param map Map to check.
|
||||||
|
* @param key Key to check for.
|
||||||
|
* @param message Message (sprintf format) to send to the logger.
|
||||||
|
* @param args Optional TParam args for the sprintf message to accept.
|
||||||
|
*/
|
||||||
|
#define assertMapNotHasKey(map, key, ...) assertTrue( \
|
||||||
|
map.find(key) == map.end(), __VA_ARGS__ \
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that a given value has a specific flag turned off.
|
* Asserts that a given value has a specific flag turned off.
|
||||||
*
|
*
|
||||||
@ -93,7 +104,7 @@ void assertTrueImplement(
|
|||||||
* @param args Optional TParam args for the sprintf message to accept.
|
* @param args Optional TParam args for the sprintf message to accept.
|
||||||
*/
|
*/
|
||||||
#define assertFlagOff(value, flag, ...) assertTrue( \
|
#define assertFlagOff(value, flag, ...) assertTrue( \
|
||||||
(value & flag) == 0, __VA_ARGS__ \
|
Flag::isOff(value, flag), __VA_ARGS__ \
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +116,7 @@ void assertTrueImplement(
|
|||||||
* @param args Optional TParam args for the sprintf message to accept.
|
* @param args Optional TParam args for the sprintf message to accept.
|
||||||
*/
|
*/
|
||||||
#define assertFlagOn(value, flag, ...) assertTrue( \
|
#define assertFlagOn(value, flag, ...) assertTrue( \
|
||||||
(value & flag) == flag, __VA_ARGS__ \
|
Flag::isOn(value, flag), __VA_ARGS__ \
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,24 +60,58 @@ int32_t assetDataLoaderArchiveClose(struct archive *a, void *d) {
|
|||||||
|
|
||||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||||
|
|
||||||
AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
|
AssetDataLoader::AssetDataLoader(const std::string &fileName) :
|
||||||
|
fileName(fileName)
|
||||||
|
{
|
||||||
assertTrue(
|
assertTrue(
|
||||||
fileName.size() > 0,
|
fileName.size() > 0,
|
||||||
"IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0"
|
"IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t AssetDataLoader::getSize() {
|
||||||
|
assertTrue(this->assetArchiveEntry != nullptr, "Entry is NULL!");
|
||||||
|
assertTrue(
|
||||||
|
archive_entry_size_is_set(assetArchiveEntry),
|
||||||
|
"Entry size is not set!"
|
||||||
|
);
|
||||||
|
return archive_entry_size(assetArchiveEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t AssetDataLoader::getPosition() {
|
||||||
|
assertNotNull(this->assetArchiveFile, "File is not open!");
|
||||||
|
return this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssetDataLoader::getEntireContentsAsString() {
|
||||||
|
if(!this->isOpen()) {
|
||||||
|
this->open();
|
||||||
|
} else {
|
||||||
|
this->rewind();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string buffer;
|
||||||
|
buffer.resize(this->getSize());
|
||||||
|
this->read((uint8_t*)buffer.data(), buffer.size());
|
||||||
|
this->close();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool_t AssetDataLoader::isOpen() {
|
||||||
|
return this->assetArchive != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void AssetDataLoader::open() {
|
void AssetDataLoader::open() {
|
||||||
assertNull(this->assetArchiveFile, "AssetDataLoader::open: File is already open");
|
assertNull(this->assetArchiveFile, "File is already open");
|
||||||
assertNull(this->assetArchive, "AssetDataLoader::open: Archive is already open");
|
assertNull(this->assetArchive, "Archive is already open");
|
||||||
assertNull(this->assetArchiveEntry, "AssetDataLoader::open: Entry is already open");
|
assertNull(this->assetArchiveEntry, "Entry is already open");
|
||||||
|
|
||||||
this->assetArchiveFile = this->openAssetArchiveFile();
|
this->assetArchiveFile = this->openAssetArchiveFile();
|
||||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::open: Failed to open archive file!");
|
assertNotNull(this->assetArchiveFile, "Failed to open archive file!");
|
||||||
|
|
||||||
// Open archive reader
|
// Open archive reader
|
||||||
assetArchive = archive_read_new();
|
assetArchive = archive_read_new();
|
||||||
assertNotNull(assetArchive, "AssetDataLoader::open: Failed to create archive reader");
|
assertNotNull(assetArchive, "Failed to create archive reader");
|
||||||
|
|
||||||
// Set up the reader
|
// Set up the reader
|
||||||
archive_read_support_format_tar(assetArchive);
|
archive_read_support_format_tar(assetArchive);
|
||||||
@ -90,28 +124,30 @@ void AssetDataLoader::open() {
|
|||||||
archive_read_set_callback_data(assetArchive, this);
|
archive_read_set_callback_data(assetArchive, this);
|
||||||
|
|
||||||
int32_t ret = archive_read_open1(assetArchive);
|
int32_t ret = archive_read_open1(assetArchive);
|
||||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to open archive!");
|
assertTrue(ret == ARCHIVE_OK, "Failed to open archive!");
|
||||||
position = 0;
|
position = 0;
|
||||||
|
|
||||||
// Iterate over each file to find the one for this asset loader.
|
// Iterate over each file to find the one for this asset loader.
|
||||||
while(archive_read_next_header(assetArchive, &assetArchiveEntry) == ARCHIVE_OK) {
|
while(archive_read_next_header(assetArchive, &assetArchiveEntry)==ARCHIVE_OK){
|
||||||
const char_t *headerFile = (char_t*)archive_entry_pathname(assetArchiveEntry);
|
const char_t *headerFile = (char_t*)archive_entry_pathname(
|
||||||
|
assetArchiveEntry
|
||||||
|
);
|
||||||
if(std::string(headerFile) == this->fileName) return;
|
if(std::string(headerFile) == this->fileName) return;
|
||||||
int32_t ret = archive_read_data_skip(assetArchive);
|
int32_t ret = archive_read_data_skip(assetArchive);
|
||||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to skip data!");
|
assertTrue(ret == ARCHIVE_OK, "Failed to skip data!");
|
||||||
}
|
}
|
||||||
|
|
||||||
assertUnreachable("AssetDataLoader::open: Failed to find file!");
|
assertUnreachable("Failed to find file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t AssetDataLoader::close() {
|
int32_t AssetDataLoader::close() {
|
||||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::close: File is NULL");
|
assertNotNull(this->assetArchiveFile, "File is NULL");
|
||||||
assertNotNull(this->assetArchive, "AssetDataLoader::close: Archive is NULL!");
|
assertNotNull(this->assetArchive, "Archive is NULL!");
|
||||||
assertNotNull(this->assetArchiveEntry, "AssetDataLoader::close: Entry is NULL!");
|
assertNotNull(this->assetArchiveEntry, "Entry is NULL!");
|
||||||
|
|
||||||
// Close the archive
|
// Close the archive
|
||||||
int32_t ret = archive_read_free(this->assetArchive);
|
int32_t ret = archive_read_free(this->assetArchive);
|
||||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::close: Failed to close archive!");
|
assertTrue(ret == ARCHIVE_OK, "Failed to close archive!");
|
||||||
|
|
||||||
this->assetArchive = nullptr;
|
this->assetArchive = nullptr;
|
||||||
this->assetArchiveEntry = nullptr;
|
this->assetArchiveEntry = nullptr;
|
||||||
@ -122,11 +158,11 @@ int32_t AssetDataLoader::close() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
|
size_t AssetDataLoader::read(uint8_t *buffer, const size_t &size) {
|
||||||
assertNotNull(buffer, "Buffer is NULL!");
|
assertNotNull(buffer, "Buffer is NULL!");
|
||||||
assertTrue(size > 0, "Size must be greater than 0!");
|
assertTrue(size > 0, "Size must be greater than 0!");
|
||||||
assertNotNull(this->assetArchive, "assetRead: Archive is NULL!");
|
assertNotNull(this->assetArchive, "Archive is NULL!");
|
||||||
assertNotNull(this->assetArchiveEntry, "assetRead: Entry is NULL!");
|
assertNotNull(this->assetArchiveEntry, "Entry is NULL!");
|
||||||
|
|
||||||
ssize_t read = archive_read_data(this->assetArchive, buffer, size);
|
ssize_t read = archive_read_data(this->assetArchive, buffer, size);
|
||||||
this->position += read;
|
this->position += read;
|
||||||
@ -135,8 +171,8 @@ size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
|
|||||||
assertUnreachable(archive_error_string(this->assetArchive));
|
assertUnreachable(archive_error_string(this->assetArchive));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(read != ARCHIVE_RETRY, "assetRead: Failed to read data (RETRY)!");
|
assertTrue(read != ARCHIVE_RETRY, "Failed to read data (RETRY)!");
|
||||||
assertTrue(read != ARCHIVE_WARN, "assetRead: Failed to read data (WARN)!");
|
assertTrue(read != ARCHIVE_WARN, "Failed to read data (WARN)!");
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
@ -156,23 +192,19 @@ size_t AssetDataLoader::readUntil(
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AssetDataLoader::getSize() {
|
size_t AssetDataLoader::skip(const size_t &n) {
|
||||||
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
|
assertTrue(n >= 0, "Byte count must be greater than 0.");
|
||||||
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
|
assertTrue(n < (this->getSize() - this->position), "Cannot skip past EOF!");
|
||||||
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];
|
uint8_t dumpBuffer[ASSET_LOADER_BUFFER_SIZE];
|
||||||
size_t skipped = 0;
|
size_t skipped = 0;
|
||||||
size_t n2, n3;
|
size_t n2, n3, n4;
|
||||||
while(n != 0) {
|
n4 = n;
|
||||||
n2 = Math::min<size_t>(n, ASSET_LOADER_BUFFER_SIZE);
|
while(n4 != 0) {
|
||||||
|
n2 = Math::min<size_t>(n4, ASSET_LOADER_BUFFER_SIZE);
|
||||||
n3 = this->read(dumpBuffer, n2);
|
n3 = this->read(dumpBuffer, n2);
|
||||||
assertTrue(n3 == n2, "AssetDataLoader::skip: Failed to skip bytes!");
|
assertTrue(n3 == n2, "Failed to skip bytes!");
|
||||||
n -= n3;
|
n4 -= n3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return skipped;
|
return skipped;
|
||||||
@ -185,16 +217,14 @@ size_t AssetDataLoader::setPosition(const size_t position) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssetDataLoader::rewind() {
|
void AssetDataLoader::rewind() {
|
||||||
|
assertTrue(this->isOpen(), "Asset is not open!");
|
||||||
|
if(this->position == 0) return;
|
||||||
|
|
||||||
// TODO: See if I can optimize this
|
// TODO: See if I can optimize this
|
||||||
this->close();
|
this->close();
|
||||||
this->open();
|
this->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AssetDataLoader::getPosition() {
|
|
||||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
|
|
||||||
return this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetDataLoader::~AssetDataLoader() {
|
AssetDataLoader::~AssetDataLoader() {
|
||||||
if(this->assetArchiveFile != nullptr) this->close();
|
if(this->assetArchiveFile != nullptr) this->close();
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
@ -88,7 +88,34 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param fileName File name of the asset that is to be loaded.
|
* @param fileName File name of the asset that is to be loaded.
|
||||||
*/
|
*/
|
||||||
AssetDataLoader(std::string filename);
|
AssetDataLoader(const std::string &filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the size of the asset.
|
||||||
|
* @return The size of the asset in bytes.
|
||||||
|
*/
|
||||||
|
size_t getSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current position of the read head.
|
||||||
|
*
|
||||||
|
* @return The current read head position.
|
||||||
|
*/
|
||||||
|
size_t getPosition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entire contents of the asset as a string.
|
||||||
|
*
|
||||||
|
* @return The entire contents of the asset as a string.
|
||||||
|
*/
|
||||||
|
std::string getEntireContentsAsString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the asset is open.
|
||||||
|
*
|
||||||
|
* @return True if the asset is open, otherwise false.
|
||||||
|
*/
|
||||||
|
bool_t isOpen();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform-centric method to open a file buffer to an asset.
|
* Platform-centric method to open a file buffer to an asset.
|
||||||
@ -107,7 +134,7 @@ namespace Dawn {
|
|||||||
* @param size Length of the data buffer (How many bytes to read).
|
* @param size Length of the data buffer (How many bytes to read).
|
||||||
* @return The count of bytes read.
|
* @return The count of bytes read.
|
||||||
*/
|
*/
|
||||||
size_t read(uint8_t *buffer, size_t size);
|
size_t read(uint8_t *buffer, const size_t &size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads bytes from the buffer until a given delimiter is found. Returned
|
* Reads bytes from the buffer until a given delimiter is found. Returned
|
||||||
@ -123,12 +150,6 @@ namespace Dawn {
|
|||||||
const size_t maxSize,
|
const size_t maxSize,
|
||||||
const char_t delimiter
|
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.
|
* Skips the read head forward to a given position.
|
||||||
@ -136,7 +157,7 @@ namespace Dawn {
|
|||||||
* @param n Count of bytes to progress the read head by.
|
* @param n Count of bytes to progress the read head by.
|
||||||
* @return Count of bytes progressed.
|
* @return Count of bytes progressed.
|
||||||
*/
|
*/
|
||||||
size_t skip(size_t n);
|
size_t skip(const size_t &n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewind the read head to the beginning of the file.
|
* Rewind the read head to the beginning of the file.
|
||||||
@ -151,13 +172,6 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
size_t setPosition(const size_t absolutePosition);
|
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.
|
* Cleanup the asset loader.
|
||||||
*/
|
*/
|
||||||
|
@ -5,13 +5,38 @@
|
|||||||
|
|
||||||
#include "AssetLoader.hpp"
|
#include "AssetLoader.hpp"
|
||||||
#include "assert/assert.hpp"
|
#include "assert/assert.hpp"
|
||||||
|
#include "asset/AssetManager.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
AssetLoader::AssetLoader(const std::string name) : name(name) {
|
const std::string AssetLoader::ASSET_TYPE = "unknown";
|
||||||
assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty");
|
|
||||||
|
AssetLoader::AssetLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
) :
|
||||||
|
assetManager(assetManager),
|
||||||
|
name(name)
|
||||||
|
{
|
||||||
|
assertNotNull(assetManager, "AssetManager cannot be null");
|
||||||
|
assertTrue(name.size() > 0, "Name cannot be empty");
|
||||||
|
|
||||||
|
std::cout << "Loading: " << name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<AssetManager> AssetLoader::getAssetManager() {
|
||||||
|
auto am = this->assetManager.lock();
|
||||||
|
assertNotNull(am, "AssetManager is null");
|
||||||
|
return am;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetLoader::loadImmediately() {
|
||||||
|
while(!this->loaded) {
|
||||||
|
this->getAssetManager()->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetLoader::~AssetLoader() {
|
AssetLoader::~AssetLoader() {
|
||||||
this->loaded = false;
|
this->loaded = false;
|
||||||
|
std::cout << "Unloading: " << name << std::endl;
|
||||||
}
|
}
|
@ -4,11 +4,19 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
|
class AssetManager;
|
||||||
|
|
||||||
class AssetLoader {
|
class AssetLoader {
|
||||||
|
private:
|
||||||
|
std::weak_ptr<AssetManager> assetManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::string typetest;
|
||||||
|
const static std::string ASSET_TYPE;
|
||||||
|
|
||||||
const std::string name;
|
const std::string name;
|
||||||
bool_t loaded = false;
|
bool_t loaded = false;
|
||||||
|
|
||||||
@ -17,7 +25,10 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param name Name of the asset.
|
* @param name Name of the asset.
|
||||||
*/
|
*/
|
||||||
AssetLoader(const std::string name);
|
AssetLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Virtual function that will be called by the asset manager on a
|
* Virtual function that will be called by the asset manager on a
|
||||||
@ -32,6 +43,25 @@ namespace Dawn {
|
|||||||
* false.
|
* false.
|
||||||
*/
|
*/
|
||||||
virtual void updateAsync() = 0;
|
virtual void updateAsync() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the asset type.
|
||||||
|
*
|
||||||
|
* @return The asset type.
|
||||||
|
*/
|
||||||
|
virtual std::string getAssetType() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the asset manager.
|
||||||
|
*
|
||||||
|
* @return The asset manager.
|
||||||
|
*/
|
||||||
|
std::shared_ptr<AssetManager> getAssetManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the asset immediately, this is blocking on the main thread.
|
||||||
|
*/
|
||||||
|
void loadImmediately();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose the asset item.
|
* Dispose the asset item.
|
||||||
|
@ -4,48 +4,61 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "AssetManager.hpp"
|
#include "AssetManager.hpp"
|
||||||
#include "loaders/TextureLoader.hpp"
|
#include "assert/assert.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
void AssetManager::init() {
|
void AssetManager::init(const std::shared_ptr<Game> &game) {
|
||||||
|
assertNotNull(game, "Game is NULL?");
|
||||||
|
this->game = game;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::update() {
|
void AssetManager::update() {
|
||||||
auto itPending = pendingAssetLoaders.begin();
|
auto copyPendingAssets = pendingAssetLoaders;
|
||||||
while(itPending != pendingAssetLoaders.end()) {
|
auto itPending = copyPendingAssets.begin();
|
||||||
|
while(itPending != copyPendingAssets.end()) {
|
||||||
auto loader = *itPending;
|
auto loader = *itPending;
|
||||||
|
|
||||||
loader->updateSync();
|
loader->updateSync();
|
||||||
loader->updateAsync();
|
loader->updateAsync();
|
||||||
if(loader->loaded) {
|
loader->updateSync();
|
||||||
finishedAssetLoaders.push_back(loader);
|
|
||||||
itPending = pendingAssetLoaders.erase(itPending);
|
if(!loader->loaded) {
|
||||||
} else {
|
++itPending;
|
||||||
itPending++;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finishedAssetLoaders.push_back(loader);
|
||||||
|
auto it = std::find(
|
||||||
|
pendingAssetLoaders.begin(),
|
||||||
|
pendingAssetLoaders.end(),
|
||||||
|
loader
|
||||||
|
);
|
||||||
|
assertTrue(it != pendingAssetLoaders.end(), "Loader not found?");
|
||||||
|
pendingAssetLoaders.erase(it);
|
||||||
|
++itPending;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::removeExisting(const std::string filename) {
|
void AssetManager::remove(const std::shared_ptr<AssetLoader> loader) {
|
||||||
auto existing = std::find_if(
|
for(
|
||||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
auto it = pendingAssetLoaders.begin();
|
||||||
[&](auto &loader) {
|
it != pendingAssetLoaders.end();
|
||||||
return loader->name == filename;
|
it++
|
||||||
}
|
) {
|
||||||
);
|
if(*it != loader) continue;
|
||||||
if(existing != pendingAssetLoaders.end()) {
|
pendingAssetLoaders.erase(it);
|
||||||
pendingAssetLoaders.erase(existing);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
existing = std::find_if(
|
for(
|
||||||
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
|
auto it = finishedAssetLoaders.begin();
|
||||||
[&](auto &loader) {
|
it != finishedAssetLoaders.end();
|
||||||
return loader->name == filename;
|
it++
|
||||||
}
|
) {
|
||||||
);
|
if(it->lock() != loader) continue;
|
||||||
if(existing != finishedAssetLoaders.end()) {
|
finishedAssetLoaders.erase(it);
|
||||||
finishedAssetLoaders.erase(existing);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +66,10 @@ bool_t AssetManager::isEverythingLoaded() {
|
|||||||
return pendingAssetLoaders.size() == 0;
|
return pendingAssetLoaders.size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t AssetManager::isLoaded(const std::string filename) {
|
std::shared_ptr<Game> AssetManager::getGame() {
|
||||||
auto existing = this->getExisting<AssetLoader>(filename);
|
auto g = game.lock();
|
||||||
if(existing) return existing->loaded;
|
assertNotNull(g, "Game is NULL?");
|
||||||
return false;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetManager::~AssetManager() {
|
AssetManager::~AssetManager() {
|
||||||
|
@ -4,14 +4,17 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawn.hpp"
|
||||||
#include "asset/AssetLoader.hpp"
|
#include "asset/AssetLoader.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class AssetManager final {
|
class Game;
|
||||||
|
|
||||||
|
class AssetManager final : public std::enable_shared_from_this<AssetManager> {
|
||||||
private:
|
private:
|
||||||
|
std::weak_ptr<Game> game;
|
||||||
std::vector<std::shared_ptr<AssetLoader>> pendingAssetLoaders;
|
std::vector<std::shared_ptr<AssetLoader>> pendingAssetLoaders;
|
||||||
std::vector<std::shared_ptr<AssetLoader>> finishedAssetLoaders;
|
std::vector<std::weak_ptr<AssetLoader>> finishedAssetLoaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an existing asset loader if it exists.
|
* Returns an existing asset loader if it exists.
|
||||||
@ -20,26 +23,22 @@ namespace Dawn {
|
|||||||
* @return The asset loader if it exists, otherwise nullptr.
|
* @return The asset loader if it exists, otherwise nullptr.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
std::shared_ptr<T> getExisting(const std::string filename) {
|
std::shared_ptr<T> getExisting(const std::string &filename) {
|
||||||
auto existing = std::find_if(
|
for(auto &loader : pendingAssetLoaders) {
|
||||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
if(loader->name != filename) continue;
|
||||||
[&](auto &loader) {
|
if(loader->getAssetType() != T::ASSET_TYPE) continue;
|
||||||
return loader->name == filename;
|
return std::static_pointer_cast<T>(loader);
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
for(auto &wLoader : finishedAssetLoaders) {
|
||||||
|
auto loader = wLoader.lock();
|
||||||
|
if(!loader) continue;
|
||||||
|
if(loader->name != filename) continue;
|
||||||
|
if(loader->getAssetType() != T::ASSET_TYPE) continue;
|
||||||
|
return std::static_pointer_cast<T>(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,13 +46,15 @@ namespace Dawn {
|
|||||||
*
|
*
|
||||||
* @param filename The filename of the asset to remove.
|
* @param filename The filename of the asset to remove.
|
||||||
*/
|
*/
|
||||||
void removeExisting(const std::string filename);
|
void removeExisting(const std::string &filename);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initializes this asset manager so it can begin accepting assets.
|
* Initializes this asset manager so it can begin accepting assets.
|
||||||
|
*
|
||||||
|
* @param game Game context that this asset manager is attached to.
|
||||||
*/
|
*/
|
||||||
void init();
|
void init(const std::shared_ptr<Game> &game);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the asset manager.
|
* Updates the asset manager.
|
||||||
@ -68,14 +69,6 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
bool_t isEverythingLoaded();
|
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.
|
* Returns the asset loader for the given asset.
|
||||||
*
|
*
|
||||||
@ -83,20 +76,35 @@ namespace Dawn {
|
|||||||
* @return The asset loader for the given asset.
|
* @return The asset loader for the given asset.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
std::shared_ptr<T> get(const std::string filename);
|
std::shared_ptr<T> get(const std::string &filename) {
|
||||||
|
auto existing = this->getExisting<T>(filename);
|
||||||
|
if(existing) return existing;
|
||||||
|
|
||||||
|
std::shared_ptr<T> loader = std::make_shared<T>(
|
||||||
|
shared_from_this(),
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
pendingAssetLoaders.push_back(
|
||||||
|
std::static_pointer_cast<AssetLoader>(loader)
|
||||||
|
);
|
||||||
|
return loader;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the asset loader for the given asset.
|
* Returns the game context that this asset manager is attached to.
|
||||||
*
|
*
|
||||||
* @param filename The filename of the asset to get.
|
* @return The game context.
|
||||||
* @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<Game> getGame();
|
||||||
std::shared_ptr<T> get(
|
|
||||||
const std::string filename,
|
/**
|
||||||
const uint32_t fontSize
|
* Removes the given asset loader from the asset manager, assumes that
|
||||||
);
|
* nothing else needs to access it and any dangling shared_ptrs will have
|
||||||
|
* to remain in memory.
|
||||||
|
*
|
||||||
|
* @param loader The asset loader to remove.
|
||||||
|
*/
|
||||||
|
void remove(const std::shared_ptr<AssetLoader> loader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose the asset manager, and all attached assets.
|
* Dispose the asset manager, and all attached assets.
|
||||||
|
@ -12,4 +12,4 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(loaders)
|
add_subdirectory(loader)
|
17
src/dawn/asset/loader/CMakeLists.txt
Normal file
17
src/dawn/asset/loader/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright (c) 2022 Dominic Msters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
TextureLoader.cpp
|
||||||
|
JSONLoader.cpp
|
||||||
|
TrueTypeLoader.cpp
|
||||||
|
ShaderLoader.cpp
|
||||||
|
StringLoader.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Subdirs
|
||||||
|
add_subdirectory(scene)
|
43
src/dawn/asset/loader/JSONLoader.cpp
Normal file
43
src/dawn/asset/loader/JSONLoader.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "JSONLoader.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
const std::string JSONLoader::ASSET_TYPE = "json";
|
||||||
|
|
||||||
|
JSONLoader::JSONLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
) :
|
||||||
|
AssetLoader(assetManager, name),
|
||||||
|
loader(name),
|
||||||
|
state(JSONLoaderState::INITIAL)
|
||||||
|
{
|
||||||
|
this->typetest = this->getAssetType();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JSONLoader::updateAsync() {
|
||||||
|
if(this->state != JSONLoaderState::INITIAL) return;
|
||||||
|
|
||||||
|
this->state = JSONLoaderState::LOADING_JSON;
|
||||||
|
std::string jsonContents = loader.getEntireContentsAsString();
|
||||||
|
this->data = json::parse(jsonContents);
|
||||||
|
this->state = JSONLoaderState::DONE;
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JSONLoader::updateSync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string JSONLoader::getAssetType() const {
|
||||||
|
return JSONLoader::ASSET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONLoader::~JSONLoader() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
37
src/dawn/asset/loader/JSONLoader.hpp
Normal file
37
src/dawn/asset/loader/JSONLoader.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
|
||||||
|
#include "asset/AssetLoader.hpp"
|
||||||
|
#include "asset/AssetDataLoader.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
enum class JSONLoaderState {
|
||||||
|
INITIAL,
|
||||||
|
LOADING_JSON,
|
||||||
|
DONE
|
||||||
|
};
|
||||||
|
|
||||||
|
class JSONLoader : public AssetLoader {
|
||||||
|
protected:
|
||||||
|
AssetDataLoader loader;
|
||||||
|
enum JSONLoaderState state;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static std::string ASSET_TYPE;
|
||||||
|
|
||||||
|
json data;
|
||||||
|
|
||||||
|
JSONLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
);
|
||||||
|
void updateSync() override;
|
||||||
|
void updateAsync() override;
|
||||||
|
std::string getAssetType() const override;
|
||||||
|
~JSONLoader();
|
||||||
|
};
|
||||||
|
}
|
60
src/dawn/asset/loader/ShaderLoader.cpp
Normal file
60
src/dawn/asset/loader/ShaderLoader.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "ShaderLoader.hpp"
|
||||||
|
#include "assert/assert.hpp"
|
||||||
|
#include "asset/AssetManager.hpp"
|
||||||
|
#include "game/Game.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
const std::string ShaderLoader::ASSET_TYPE = "shader";
|
||||||
|
|
||||||
|
ShaderLoader::ShaderLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
) :
|
||||||
|
AssetLoader(assetManager, name),
|
||||||
|
state(ShaderLoaderState::INITIAL),
|
||||||
|
shader(std::make_shared<ShaderProgram>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderLoader::updateAsync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderLoader::updateSync() {
|
||||||
|
if(state != ShaderLoaderState::INITIAL) return;
|
||||||
|
this->state = ShaderLoaderState::LOADING;
|
||||||
|
assertFalse(loaded, "ShaderLoader already loaded.");
|
||||||
|
|
||||||
|
// Shorthand.
|
||||||
|
auto sm = this->getAssetManager()->getGame()->shaderManager;
|
||||||
|
|
||||||
|
// Load the shader string
|
||||||
|
Slang::ComPtr<IBlob> diagnostics;
|
||||||
|
auto module = sm->session->loadModule(
|
||||||
|
this->name.c_str(),
|
||||||
|
diagnostics.writeRef()
|
||||||
|
);
|
||||||
|
shader->init(module, sm->session);
|
||||||
|
|
||||||
|
// Finished loading.
|
||||||
|
this->state = ShaderLoaderState::LOADED;
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ShaderLoader::getAssetType() const {
|
||||||
|
return ShaderLoader::ASSET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ShaderProgram> ShaderLoader::getShader() {
|
||||||
|
assertNotNull(shader, "ShaderLoader shader is null.");
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderLoader::~ShaderLoader() {
|
||||||
|
shader = nullptr;
|
||||||
|
}
|
44
src/dawn/asset/loader/ShaderLoader.hpp
Normal file
44
src/dawn/asset/loader/ShaderLoader.hpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "asset/AssetLoader.hpp"
|
||||||
|
#include "asset/AssetDataLoader.hpp"
|
||||||
|
#include "display/shader/ShaderManager.hpp"
|
||||||
|
#include "display/shader/ShaderProgram.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
enum class ShaderLoaderState {
|
||||||
|
INITIAL,
|
||||||
|
LOADING,
|
||||||
|
LOADED
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShaderLoader : public AssetLoader {
|
||||||
|
protected:
|
||||||
|
enum ShaderLoaderState state;
|
||||||
|
std::shared_ptr<ShaderProgram> shader;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static std::string ASSET_TYPE;
|
||||||
|
|
||||||
|
ShaderLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
);
|
||||||
|
void updateSync() override;
|
||||||
|
void updateAsync() override;
|
||||||
|
std::string getAssetType() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retreives the shader program for this loader.
|
||||||
|
*
|
||||||
|
* @return The shader program that this loader is managing.
|
||||||
|
*/
|
||||||
|
std::shared_ptr<ShaderProgram> getShader();
|
||||||
|
|
||||||
|
~ShaderLoader();
|
||||||
|
};
|
||||||
|
}
|
38
src/dawn/asset/loader/StringLoader.cpp
Normal file
38
src/dawn/asset/loader/StringLoader.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "StringLoader.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
const std::string StringLoader::ASSET_TYPE = "string";
|
||||||
|
|
||||||
|
StringLoader::StringLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
) :
|
||||||
|
AssetLoader(assetManager, name),
|
||||||
|
loader(name),
|
||||||
|
state(StringLoaderState::INITIAL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringLoader::updateSync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringLoader::updateAsync() {
|
||||||
|
if(this->state != StringLoaderState::INITIAL) return;
|
||||||
|
this->state = StringLoaderState::LOADING_STRING;
|
||||||
|
this->data = this->loader.getEntireContentsAsString();
|
||||||
|
this->state = StringLoaderState::DONE;
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringLoader::getAssetType() const {
|
||||||
|
return StringLoader::ASSET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringLoader::~StringLoader() {
|
||||||
|
}
|
36
src/dawn/asset/loader/StringLoader.hpp
Normal file
36
src/dawn/asset/loader/StringLoader.hpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) 2024 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "asset/AssetLoader.hpp"
|
||||||
|
#include "asset/AssetDataLoader.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
enum class StringLoaderState {
|
||||||
|
INITIAL,
|
||||||
|
LOADING_STRING,
|
||||||
|
DONE
|
||||||
|
};
|
||||||
|
|
||||||
|
class StringLoader : public AssetLoader {
|
||||||
|
protected:
|
||||||
|
AssetDataLoader loader;
|
||||||
|
enum StringLoaderState state;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const static std::string ASSET_TYPE;
|
||||||
|
|
||||||
|
std::string data;
|
||||||
|
|
||||||
|
StringLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
);
|
||||||
|
void updateSync() override;
|
||||||
|
void updateAsync() override;
|
||||||
|
std::string getAssetType() const override;
|
||||||
|
~StringLoader();
|
||||||
|
};
|
||||||
|
}
|
@ -8,13 +8,18 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
TextureLoader::TextureLoader(const std::string name) :
|
const std::string TextureLoader::ASSET_TYPE = "texture";
|
||||||
AssetLoader(name),
|
|
||||||
loader(name + ".texture"),
|
TextureLoader::TextureLoader(
|
||||||
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
|
const std::string name
|
||||||
|
) :
|
||||||
|
AssetLoader(assetManager, name),
|
||||||
|
loader(name),
|
||||||
state(TextureLoaderLoadState::INITIAL)
|
state(TextureLoaderLoadState::INITIAL)
|
||||||
{
|
{
|
||||||
sharedTexture = std::make_shared<Texture>();
|
this->typetest = this->getAssetType();
|
||||||
weakTexture = sharedTexture;
|
texture = std::make_shared<Texture>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureLoader::updateAsync() {
|
void TextureLoader::updateAsync() {
|
||||||
@ -114,34 +119,39 @@ void TextureLoader::updateSync() {
|
|||||||
if(this->state != TextureLoaderLoadState::ASYNC_DONE) return;
|
if(this->state != TextureLoaderLoadState::ASYNC_DONE) return;
|
||||||
this->state = TextureLoaderLoadState::SYNC_LOADING;
|
this->state = TextureLoaderLoadState::SYNC_LOADING;
|
||||||
|
|
||||||
assertNotNull(this->sharedTexture, "Texture is null!");
|
assertNotNull(this->texture, "Texture is null!");
|
||||||
assertNotNull(this->data, "Texture data is null!");
|
assertNotNull(this->data, "Texture data is null!");
|
||||||
|
|
||||||
// Setup Texture
|
// Setup Texture
|
||||||
this->sharedTexture->setSize(
|
this->texture->setSize(
|
||||||
this->width,
|
this->width,
|
||||||
this->height,
|
this->height,
|
||||||
this->format,
|
this->format,
|
||||||
TextureDataFormat::UNSIGNED_BYTE
|
TextureDataFormat::UNSIGNED_BYTE
|
||||||
);
|
);
|
||||||
this->sharedTexture->buffer(this->data);
|
this->texture->buffer(this->data);
|
||||||
|
|
||||||
// Free data buffer
|
// Free data buffer
|
||||||
delete[] this->data;
|
delete[] this->data;
|
||||||
this->data = nullptr;
|
this->data = nullptr;
|
||||||
|
|
||||||
// Leat go of the held pointer
|
|
||||||
this->sharedTexture = nullptr;
|
|
||||||
|
|
||||||
// Hand off and call done
|
// Hand off and call done
|
||||||
this->state = TextureLoaderLoadState::SYNC_DONE;
|
this->state = TextureLoaderLoadState::SYNC_DONE;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TextureLoader::getAssetType() const {
|
||||||
|
return TextureLoader::ASSET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Texture> TextureLoader::getTexture() {
|
||||||
|
return this->texture;
|
||||||
|
}
|
||||||
|
|
||||||
TextureLoader::~TextureLoader() {
|
TextureLoader::~TextureLoader() {
|
||||||
if(this->data != nullptr) {
|
if(this->data != nullptr) {
|
||||||
delete[] this->data;
|
delete[] this->data;
|
||||||
this->data = nullptr;
|
this->data = nullptr;
|
||||||
}
|
}
|
||||||
this->sharedTexture = nullptr;
|
this->texture = nullptr;
|
||||||
}
|
}
|
@ -30,26 +30,26 @@ namespace Dawn {
|
|||||||
enum TextureWrapMode wrapY;
|
enum TextureWrapMode wrapY;
|
||||||
enum TextureFilterMode filterMin;
|
enum TextureFilterMode filterMin;
|
||||||
enum TextureFilterMode filterMag;
|
enum TextureFilterMode filterMag;
|
||||||
|
std::shared_ptr<Texture> texture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<Texture> sharedTexture;
|
const static std::string ASSET_TYPE;
|
||||||
std::weak_ptr<Texture> weakTexture;
|
|
||||||
|
|
||||||
/**
|
TextureLoader(
|
||||||
* Constructs a texture asset loader. You should instead use the parent
|
const std::shared_ptr<AssetManager> assetManager,
|
||||||
* asset managers' abstracted load method
|
const std::string name
|
||||||
*
|
);
|
||||||
* @param name File name asset to load, omitting the extension.
|
|
||||||
*/
|
|
||||||
TextureLoader(const std::string name);
|
|
||||||
|
|
||||||
void updateSync() override;
|
void updateSync() override;
|
||||||
void updateAsync() override;
|
void updateAsync() override;
|
||||||
|
std::string getAssetType() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose / Cleanup the texture asset. Will also dispose the underlying
|
* Get the texture asset.
|
||||||
* texture itself.
|
*
|
||||||
|
* @return Texture asset.
|
||||||
*/
|
*/
|
||||||
|
std::shared_ptr<Texture> getTexture();
|
||||||
~TextureLoader();
|
~TextureLoader();
|
||||||
};
|
};
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user