Merge branch 'SP3-6-c-scripting' of https://github.com/SHADE-DP/SHADE_Y3 into SP3-6-c-scripting
This commit is contained in:
commit
1477aaaead
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -67,9 +67,16 @@ project "SHADE_Application"
|
|||
|
||||
disablewarnings
|
||||
{
|
||||
"4251"
|
||||
"4251",
|
||||
"26812",
|
||||
"26439",
|
||||
"26451",
|
||||
"26437",
|
||||
"4275"
|
||||
}
|
||||
|
||||
linkoptions { "-IGNORE:4006" }
|
||||
|
||||
warnings 'Extra'
|
||||
|
||||
filter "configurations:Debug"
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <chrono>
|
||||
#include <ratio>
|
||||
#include <ctime>
|
||||
#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN 1
|
||||
#include <SDL.h>
|
||||
|
||||
#include "Scripting/SHScriptEngine.h"
|
||||
|
@ -23,15 +22,17 @@
|
|||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
#include "Scene/SHSceneManager.h"
|
||||
#include "Math/Transform/SHTransformSystem.h"
|
||||
#include "Input/SHInputManagerSystem.h"
|
||||
#include "Input/SHInputManager.h"
|
||||
#include "FRC/SHFramerateController.h"
|
||||
//#include "AudioSystem/SHAudioSystem.h"
|
||||
#include "AudioSystem/SHAudioSystem.h"
|
||||
|
||||
#include "Scenes/SBTestScene.h"
|
||||
#include "Math/Transform/SHTransformComponent.h"
|
||||
|
||||
#include "Assets/SHAssetManager.h"
|
||||
|
||||
#include "Tools/SHLogger.h"
|
||||
|
||||
using namespace SHADE;
|
||||
|
||||
namespace Sandbox
|
||||
|
@ -56,8 +57,7 @@ namespace Sandbox
|
|||
// TODO(Diren): Create Physics System here
|
||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHTransformSystem>();
|
||||
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHInputManagerSystem>();
|
||||
//SHADE::SHSystemManager::CreateSystem<SHADE::SHAudioSystem>();
|
||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHAudioSystem>();
|
||||
|
||||
// Create Routines
|
||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::FrameSetUpRoutine>();
|
||||
|
@ -78,16 +78,20 @@ namespace Sandbox
|
|||
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHRenderable>();
|
||||
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHTransformComponent>();
|
||||
|
||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHInputManagerSystem, SHADE::SHInputManagerSystem::InputManagerRoutine>();
|
||||
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/TD_Checker_Base_Color.dds");
|
||||
//SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh");
|
||||
//SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
|
||||
//SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
|
||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex");
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
|
||||
//SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
||||
|
||||
auto id = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
auto id2 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
auto id3 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
|
||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
||||
|
||||
// Set up graphics system and windows
|
||||
graphicsSystem->SetWindow(&window);
|
||||
|
@ -100,7 +104,9 @@ namespace Sandbox
|
|||
#else
|
||||
#endif
|
||||
|
||||
|
||||
SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
|
||||
|
||||
SHFrameRateController::UpdateFRC();
|
||||
}
|
||||
|
||||
|
@ -111,6 +117,7 @@ namespace Sandbox
|
|||
while (!window.WindowShouldClose())
|
||||
{
|
||||
SHFrameRateController::UpdateFRC();
|
||||
SHInputManager::UpdateInput(SHFrameRateController::GetRawDeltaTime());
|
||||
SHSceneManager::UpdateSceneManager();
|
||||
SHSceneManager::SceneUpdate(1/60.0f);
|
||||
//#ifdef SHEDITOR
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Sandbox
|
|||
std::vector<Handle<SHMesh>> handles;
|
||||
for (auto const& mesh : meshes)
|
||||
{
|
||||
if (mesh.meshName == "Cube.012")
|
||||
if (mesh.header.meshName == "Cube.012")
|
||||
{
|
||||
handles.push_back(graphicsSystem->AddMesh(
|
||||
mesh.header.vertexCount,
|
||||
|
@ -71,7 +71,7 @@ namespace Sandbox
|
|||
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
|
||||
auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst);
|
||||
customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f));
|
||||
customMat->SetProperty("data.textureIndex", 1);
|
||||
customMat->SetProperty("data.textureIndex", 0);
|
||||
customMat->SetProperty("data.alpha", 0.1f);
|
||||
|
||||
// Create Stress Test Objects
|
||||
|
@ -115,7 +115,7 @@ namespace Sandbox
|
|||
renderable.SetMaterial(customMat);
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.textureIndex", 1);
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.textureIndex", 0);
|
||||
|
||||
transform.SetWorldPosition ({-3.0f, -1.0f, -1.0f});
|
||||
transform.SetLocalScale({5.0f, 5.0f, 5.0f});
|
||||
|
@ -147,7 +147,7 @@ namespace Sandbox
|
|||
renderableShowcase.SetMaterial(customMat);
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.textureIndex", 1);
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.textureIndex", 0);
|
||||
|
||||
transformShowcase.SetWorldPosition({ 3.0f, -1.0f, -1.0f });
|
||||
transformShowcase.SetLocalScale({ 5.0f, 5.0f, 5.0f });
|
||||
|
|
|
@ -76,9 +76,16 @@ project "SHADE_Engine"
|
|||
|
||||
disablewarnings
|
||||
{
|
||||
"4251"
|
||||
"4251",
|
||||
"26812",
|
||||
"26439",
|
||||
"26451",
|
||||
"26437",
|
||||
"4275"
|
||||
}
|
||||
|
||||
linkoptions { "-IGNORE:4006" }
|
||||
|
||||
defines
|
||||
{
|
||||
"_LIB",
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHMeshAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Struct to contain ready data for loading into GPU. Also used for
|
||||
* compilation into binary files
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
@ -10,6 +22,7 @@ namespace SHADE
|
|||
{
|
||||
uint32_t vertexCount;
|
||||
uint32_t indexCount;
|
||||
std::string meshName;
|
||||
};
|
||||
|
||||
struct SH_API SHMeshAsset
|
||||
|
@ -19,8 +32,6 @@ namespace SHADE
|
|||
|
||||
SHMeshAssetHeader header;
|
||||
|
||||
std::string meshName;
|
||||
|
||||
std::vector<SHVec3> vertexPosition;
|
||||
std::vector<SHVec3> vertexTangent;
|
||||
std::vector<SHVec3> vertexNormal;
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyddsloader.h"
|
||||
|
||||
#include "Graphics/MiddleEnd/Textures/SHTextureLibrary.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHTextureAsset
|
||||
{
|
||||
bool compiled;
|
||||
|
||||
uint32_t numBytes;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHMeshCompiler.cpp
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to write data in SHMeshAsset into binary file for faster
|
||||
* loading in the future
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "SHMeshCompiler.h"
|
||||
#include "Graphics/MiddleEnd/Meshes/SHMeshData.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept
|
||||
{
|
||||
std::string newPath{ path.string() };
|
||||
newPath = newPath.substr(0, newPath.find_last_of('/') + 1);
|
||||
newPath += asset.header.meshName + MESH_EXTENSION;
|
||||
|
||||
std::ofstream file{ newPath, std::ios::out | std::ios::binary | std::ios::trunc };
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string());
|
||||
}
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&(asset.header.vertexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<const char*>(&(asset.header.indexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
auto const vertexVec3Byte {sizeof(SHVec3) * asset.header.vertexCount};
|
||||
auto const vertexVec2Byte {sizeof(SHVec2) * asset.header.vertexCount};
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexPosition.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexTangent.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexNormal.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.texCoords.data()),
|
||||
vertexVec2Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.indices.data()),
|
||||
sizeof(uint32_t) * asset.header.indexCount
|
||||
);
|
||||
|
||||
file.close();
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHMeshCompiler.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to write data in SHMeshAsset into binary file for faster
|
||||
* loading in the future
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../Asset Types/SHMeshAsset.h"
|
||||
#include "../SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHMeshCompiler
|
||||
{
|
||||
private:
|
||||
public:
|
||||
static void CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -1,12 +1,25 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHMeshLoader.cpp
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Implementation for Mesh loader. Accounts for custom binary format
|
||||
* as well as GLTF file format.
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "SHMeshLoader.h"
|
||||
#include <assimp/postprocess.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
Assimp::Importer SHMeshLoader::aiImporter;
|
||||
|
||||
void SHMeshLoader::ProcessNode(aiNode const& node, aiScene const& scene, std::vector<SHMeshAsset>& meshes)
|
||||
void SHMeshLoader::ProcessNode(aiNode const& node, aiScene const& scene, std::vector<SHMeshAsset>& meshes) noexcept
|
||||
{
|
||||
for (size_t i {0}; i < node.mNumMeshes; ++i)
|
||||
{
|
||||
|
@ -20,15 +33,14 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
SHMeshAsset SHMeshLoader::ProcessMesh(aiMesh const& mesh, aiScene const& scene)
|
||||
SHMeshAsset SHMeshLoader::ProcessMesh(aiMesh const& mesh, aiScene const& scene) noexcept
|
||||
{
|
||||
(void)scene;
|
||||
|
||||
SHMeshAsset result
|
||||
{
|
||||
.compiled { false},
|
||||
.changed { false },
|
||||
.meshName { mesh.mName.C_Str() }
|
||||
.changed { false }
|
||||
};
|
||||
|
||||
for (size_t i{0}; i < mesh.mNumVertices; ++i)
|
||||
|
@ -81,24 +93,20 @@ namespace SHADE
|
|||
|
||||
result.header.vertexCount = result.vertexPosition.size();
|
||||
result.header.indexCount = result.indices.size();
|
||||
result.header.meshName = mesh.mName.C_Str();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SHMeshLoader::LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path)
|
||||
void SHMeshLoader::LoadExternal(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept
|
||||
{
|
||||
const aiScene* scene = aiImporter.ReadFile(path.string().c_str(),
|
||||
aiProcess_Triangulate
|
||||
// Make sure we get triangles rather than nvert polygons
|
||||
aiProcess_Triangulate // Make sure we get triangles rather than nvert polygons
|
||||
| aiProcess_GenUVCoords // Convert any type of mapping to uv mapping
|
||||
| aiProcess_TransformUVCoords
|
||||
// preprocess UV transformations (scaling, translation ...)
|
||||
| aiProcess_FindInstances
|
||||
// search for instanced meshes and remove them by references to one master
|
||||
| aiProcess_CalcTangentSpace
|
||||
// calculate tangents and bitangents if possible
|
||||
| aiProcess_JoinIdenticalVertices
|
||||
// join identical vertices/ optimize indexing
|
||||
| aiProcess_TransformUVCoords // preprocess UV transformations (scaling, translation ...)
|
||||
| aiProcess_FindInstances // search for instanced meshes and remove them by references to one master
|
||||
| aiProcess_CalcTangentSpace // calculate tangents and bitangents if possible
|
||||
| aiProcess_JoinIdenticalVertices // join identical vertices/ optimize indexing
|
||||
| aiProcess_RemoveRedundantMaterials // remove redundant materials
|
||||
| aiProcess_FindInvalidData // detect invalid model data, such as invalid normal vectors
|
||||
| aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs
|
||||
|
@ -107,8 +115,9 @@ namespace SHADE
|
|||
if (!scene || !scene->HasMeshes())
|
||||
{
|
||||
SHLOG_ERROR("ERROR in GLTF::ASSIMP: {}\nFile: {}", aiImporter.GetErrorString(), path.string());
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO MATERIALS FROM MESHES
|
||||
//if (scene->HasMaterials())
|
||||
//{
|
||||
|
@ -123,7 +132,101 @@ namespace SHADE
|
|||
//}
|
||||
|
||||
ProcessNode(*scene->mRootNode, *scene, meshes);
|
||||
}
|
||||
|
||||
return true;
|
||||
void SHMeshLoader::LoadSHMesh(SHMeshAsset& mesh, AssetPath path) noexcept
|
||||
{
|
||||
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Unable to open SHMesh File: {}", path.string());
|
||||
}
|
||||
|
||||
std::string name{ path.filename().string() };
|
||||
name = name.substr(0, name.find_last_of('.'));
|
||||
|
||||
file.seekg(0);
|
||||
|
||||
uint32_t vertCount, indexCount;
|
||||
std::vector<SHVec3> vertPos, vertTan, vertNorm;
|
||||
std::vector<SHVec2> texCoord;
|
||||
std::vector<uint32_t> indices;
|
||||
|
||||
file.read(reinterpret_cast<char*>(&vertCount), sizeof(uint32_t));
|
||||
file.read(reinterpret_cast<char*>(&indexCount), sizeof(uint32_t));
|
||||
|
||||
auto const vertexVec3Byte{ sizeof(SHVec3) * vertCount };
|
||||
auto const vertexVec2Byte{ sizeof(SHVec2) * vertCount };
|
||||
|
||||
vertPos.resize(vertCount);
|
||||
vertTan.resize(vertCount);
|
||||
vertNorm.resize(vertCount);
|
||||
texCoord.resize(vertCount);
|
||||
indices.resize(indexCount);
|
||||
|
||||
file.read(reinterpret_cast<char *>(vertPos.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char *>(vertTan.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char *>(vertNorm.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char *>(texCoord.data()), vertexVec2Byte);
|
||||
file.read(reinterpret_cast<char *>(indices.data()), sizeof(uint32_t) * indexCount);
|
||||
|
||||
//for (auto i{ 0 }; i < vertCount; ++i)
|
||||
//{
|
||||
// file >> vertPos[i].x;
|
||||
// file >> vertPos[i].y;
|
||||
// file >> vertPos[i].z;
|
||||
//}
|
||||
//
|
||||
//for (auto i{ 0 }; i < vertCount; ++i)
|
||||
//{
|
||||
// file >> vertTan[i].x;
|
||||
// file >> vertTan[i].y;
|
||||
// file >> vertTan[i].z;
|
||||
//}
|
||||
|
||||
//for (auto i{ 0 }; i < vertCount; ++i)
|
||||
//{
|
||||
// file >> vertNorm[i].x;
|
||||
// file >> vertNorm[i].y;
|
||||
// file >> vertNorm[i].z;
|
||||
//}
|
||||
|
||||
//for (auto i{ 0 }; i < vertCount; ++i)
|
||||
//{
|
||||
// file >> texCoord[i].x;
|
||||
// file >> texCoord[i].y;
|
||||
//}
|
||||
|
||||
//for (auto i{ 0 }; i < indexCount; ++i)
|
||||
//{
|
||||
// file >> indices[i];
|
||||
//}
|
||||
|
||||
mesh.compiled = true;
|
||||
mesh.changed = false;
|
||||
|
||||
mesh.header.indexCount = indexCount;
|
||||
mesh.header.vertexCount = vertCount;
|
||||
mesh.header.meshName = name;
|
||||
|
||||
mesh.vertexPosition = std::move(vertPos);
|
||||
mesh.vertexTangent = std::move(vertTan);
|
||||
mesh.vertexNormal = std::move(vertNorm);
|
||||
mesh.texCoords = std::move(texCoord);
|
||||
mesh.indices = std::move(indices);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void SHMeshLoader::LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept
|
||||
{
|
||||
if (path.extension().string() == GLTF_EXTENSION)
|
||||
{
|
||||
LoadExternal(meshes, path);
|
||||
return;
|
||||
}
|
||||
|
||||
meshes.emplace_back();
|
||||
LoadSHMesh(meshes.back(), path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHMeshLoader.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to load gltf mesh files and custom binary format
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
|
@ -12,10 +23,14 @@ namespace SHADE
|
|||
private:
|
||||
static Assimp::Importer aiImporter;
|
||||
|
||||
static void ProcessNode(aiNode const& node, aiScene const& scene, std::vector<SHMeshAsset>& meshes);
|
||||
static void ProcessNode(aiNode const& node, aiScene const& scene, std::vector<SHMeshAsset>& meshes) noexcept;
|
||||
|
||||
static SHMeshAsset ProcessMesh(aiMesh const& mesh, aiScene const& scene);
|
||||
static SHMeshAsset ProcessMesh(aiMesh const& mesh, aiScene const& scene) noexcept;
|
||||
|
||||
static void LoadExternal(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept;
|
||||
|
||||
static void LoadSHMesh(SHMeshAsset& meshes, AssetPath path) noexcept;
|
||||
public:
|
||||
static bool LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path);
|
||||
static void LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHMeshWriter.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void SHADE::SHMeshWriter::WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept
|
||||
{
|
||||
std::ofstream file{path, std::ios::out | std::ios::binary};
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Unable to open file for writing mesh file: {}", path.string());
|
||||
}
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&(asset.header.vertexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<const char*>(&(asset.header.indexCount)),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
auto const vertexVec3Byte {sizeof(SHVec3) * asset.header.vertexCount};
|
||||
auto const vertexVec2Byte {sizeof(SHVec2) * asset.header.vertexCount};
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexPosition.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexTangent.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.vertexNormal.data()),
|
||||
vertexVec3Byte
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.texCoords.data()),
|
||||
vertexVec2Byte
|
||||
);
|
||||
|
||||
file.close();
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Asset Types/SHMeshAsset.h"
|
||||
#include "../SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHMeshWriter
|
||||
{
|
||||
private:
|
||||
public:
|
||||
static void WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHTextureCompiler.cpp
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to write data in SHTextureAsset into binary file for
|
||||
* faster loading in the future
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "SHTextureCompiler.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path)
|
||||
{
|
||||
std::string newPath{ path.string() };
|
||||
newPath = newPath.substr(0, newPath.find_last_of('.'));
|
||||
newPath += TEXTURE_EXTENSION;
|
||||
|
||||
std::ofstream file{ newPath, std::ios::out | std::ios::binary };
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string());
|
||||
}
|
||||
|
||||
auto const intBytes{sizeof(uint32_t)};
|
||||
|
||||
uint32_t mipOffsetCount{ static_cast<uint32_t>(asset.mipOffsets.size()) };
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&asset.numBytes),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&asset.width),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&asset.height),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&asset.format),
|
||||
sizeof(SHTexture::TextureFormat)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&mipOffsetCount),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.mipOffsets.data()),
|
||||
intBytes * asset.mipOffsets.size()
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.pixelData),
|
||||
asset.numBytes
|
||||
);
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHTextureCompiler.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to write data in SHTextureAsset into binary file for
|
||||
* faster loading in the future
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Assets/Asset Types/SHTextureAsset.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHTextureCompiler
|
||||
{
|
||||
static void CompileTextureBinary(SHTextureAsset const& asset, AssetPath path);
|
||||
};
|
||||
}
|
|
@ -1,3 +1,14 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHTextureLoader.cpp
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to load dds textures and custom binary format
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "SHTextureLoader.h"
|
||||
|
||||
|
@ -58,7 +69,7 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset)
|
||||
void SHTextureLoader::LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept
|
||||
{
|
||||
tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
|
||||
tinyddsloader::DDSFile file;
|
||||
|
@ -82,6 +93,7 @@ namespace SHADE
|
|||
std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes);
|
||||
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(file.GetDDSData()));
|
||||
|
||||
asset.compiled = false;
|
||||
asset.numBytes = totalBytes;
|
||||
asset.width = file.GetWidth();
|
||||
asset.height = file.GetHeight();
|
||||
|
@ -89,4 +101,46 @@ namespace SHADE
|
|||
asset.mipOffsets = std::move(mipOff);
|
||||
asset.pixelData = std::move(pixel);
|
||||
}
|
||||
|
||||
void SHTextureLoader::LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept
|
||||
{
|
||||
std::ifstream file{path.string(), std::ios::in | std::ios::binary};
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("Error opening SHTexture file: {}", path.string());
|
||||
}
|
||||
|
||||
auto const intBytes{ sizeof(uint32_t) };
|
||||
uint32_t mipCount;
|
||||
|
||||
file.read(reinterpret_cast<char*>(&asset.numBytes), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.width), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.height), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.format), sizeof(SHTexture::TextureFormat));
|
||||
|
||||
file.read(reinterpret_cast<char*>(&mipCount), intBytes);
|
||||
std::vector<uint32_t> mips(mipCount);
|
||||
file.read(reinterpret_cast<char*>(mips.data()), intBytes * mipCount);
|
||||
|
||||
auto pixel = new SHTexture::PixelChannel[asset.numBytes];
|
||||
file.read(reinterpret_cast<char*>(pixel), asset.numBytes);
|
||||
|
||||
asset.mipOffsets = std::move(mips);
|
||||
asset.pixelData = std::move( pixel );
|
||||
|
||||
asset.compiled = true;
|
||||
file.close();
|
||||
}
|
||||
|
||||
void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset)
|
||||
{
|
||||
if (path.extension().string() == DDS_EXTENSION)
|
||||
{
|
||||
LoadTinyDDS(path, asset);
|
||||
}
|
||||
else if (path.extension().string() == TEXTURE_EXTENSION)
|
||||
{
|
||||
LoadSHTexture(path, asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHTextureLoader.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Library to load dds textures and custom binary format
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
#define TINYDDSLOADER_IMPLEMENTATION
|
||||
|
||||
|
@ -13,6 +24,9 @@ namespace SHADE
|
|||
static std::string TinyDDSResultToString(tinyddsloader::Result value);
|
||||
static vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear);
|
||||
|
||||
|
||||
static void LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept;
|
||||
static void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept;
|
||||
public:
|
||||
static void LoadImageAsset(AssetPath paths, SHTextureAsset& image);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 30 September 2022
|
||||
* \brief Struct for asset identification and meta file writing
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Filesystem/SHFileSystem.h"
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include "Libraries/SHMeshLoader.h"
|
||||
#include "Libraries/SHTextureLoader.h"
|
||||
|
||||
#include "Libraries/SHMeshCompiler.h"
|
||||
#include "Libraries/SHTextureCompiler.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
FMOD::System* SHAssetManager::audioSystem;
|
||||
|
@ -199,7 +202,9 @@ namespace SHADE
|
|||
{
|
||||
AssetPath path{ p };
|
||||
|
||||
if (path.extension().string() == GLTF_EXTENSION)
|
||||
if (path.extension().string() == FBX_EXTENSION
|
||||
|| path.extension().string() == GLTF_EXTENSION
|
||||
|| path.extension().string() == MESH_EXTENSION)
|
||||
{
|
||||
LoadGLTF(
|
||||
{
|
||||
|
@ -211,7 +216,8 @@ namespace SHADE
|
|||
}
|
||||
);
|
||||
}
|
||||
else if (path.extension().string() == DDS_EXTENSION)
|
||||
else if (path.extension().string() == DDS_EXTENSION
|
||||
|| path.extension().string() == TEXTURE_EXTENSION)
|
||||
{
|
||||
LoadDDS(
|
||||
{
|
||||
|
@ -300,6 +306,11 @@ namespace SHADE
|
|||
for (auto const& mesh : meshes)
|
||||
{
|
||||
meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh);
|
||||
|
||||
if (!mesh.compiled)
|
||||
{
|
||||
SHMeshCompiler::CompileMeshBinary(mesh, asset.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,6 +321,11 @@ namespace SHADE
|
|||
SHTextureLoader::LoadImageAsset(asset.path, image);
|
||||
|
||||
textureCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
||||
|
||||
if (!image.compiled)
|
||||
{
|
||||
SHTextureCompiler::CompileTextureBinary(image, asset.path);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -99,6 +99,7 @@ namespace SHADE
|
|||
****************************************************************************/
|
||||
void SHAssetMetaHandler::WriteMetaData(SHAsset const& meta) noexcept
|
||||
{
|
||||
//TODO: Write into binary eventually
|
||||
std::string path{ meta.path.string() };
|
||||
path.append(META_EXTENSION);
|
||||
|
||||
|
@ -110,8 +111,20 @@ namespace SHADE
|
|||
return;
|
||||
}
|
||||
|
||||
metaFile << "Name: " << meta.name << "\n";
|
||||
metaFile << "ID: " << meta.id << "\n";
|
||||
metaFile << "Type: " << static_cast<int>(meta.type) << std::endl;
|
||||
|
||||
//TODO Add in information that is specific to types like mesh
|
||||
switch(meta.type)
|
||||
{
|
||||
case AssetType::MESH:
|
||||
break;
|
||||
|
||||
default:
|
||||
void;
|
||||
}
|
||||
|
||||
metaFile.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ namespace SHADE
|
|||
void SHADE::SHAudioSystem::Run(float dt)
|
||||
{
|
||||
static_cast<void>(dt);
|
||||
if (GetKeyState(VK_SPACE) & 0x8000)
|
||||
PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
|
||||
//if (GetKeyState(VK_SPACE) & 0x8000)
|
||||
// PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
|
||||
|
||||
fmodStudioSystem->update();
|
||||
if (!denseListener->empty())
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "SHpch.h"
|
||||
#include "../SHECSMacros.h"
|
||||
#include "SH_API.h"
|
||||
#include "ECS_Base/General/SHFamily.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -117,4 +118,7 @@ namespace SHADE
|
|||
|
||||
|
||||
};
|
||||
|
||||
|
||||
template class SH_API SHFamilyID<SHComponent>;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHComponentAddedEvent
|
||||
{
|
||||
EntityID eid;
|
||||
ComponentTypeID addedComponentType;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHComponentRemovedEvent
|
||||
{
|
||||
EntityID eid;
|
||||
ComponentTypeID removedComponentType;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
#include "SHFamily.h"
|
||||
#include "SHpch.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
//initialize currentID as 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -14,16 +14,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "../SHECSMacros.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
template<typename BaseClass>
|
||||
class SHFamilyID
|
||||
class SH_API SHFamilyID
|
||||
{
|
||||
private:
|
||||
//this is used to keep track of the new current ID to be assign to a new Derived class type.
|
||||
static ComponentTypeID currentID;
|
||||
|
||||
|
||||
/*!*************************************************************************
|
||||
* \brief Construct a new SHFamilyID object
|
||||
|
@ -46,6 +47,9 @@ namespace SHADE
|
|||
}
|
||||
public:
|
||||
|
||||
//this is used to keep track of the new current ID to be assign to a new Derived class type.
|
||||
static inline ComponentTypeID currentID = 0;
|
||||
|
||||
/*!*************************************************************************
|
||||
* \brief
|
||||
* Checks if this identifier is cuurrently in use / valid.
|
||||
|
@ -59,7 +63,6 @@ namespace SHADE
|
|||
{
|
||||
return(id < currentID);
|
||||
}
|
||||
|
||||
/*!*************************************************************************
|
||||
* \brief
|
||||
* Get the ID of a derived class type.
|
||||
|
@ -68,16 +71,27 @@ namespace SHADE
|
|||
* @tparam DerivedClass
|
||||
* The derived class type that we are trying to get the ID of.
|
||||
***************************************************************************/
|
||||
#ifdef SH_API_EXPORT
|
||||
template<typename DerivedClass>
|
||||
static ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept
|
||||
static SH_API ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept
|
||||
{
|
||||
//The first time a new derived class type call this get id, it will initialize id using the currentID from familyID class.
|
||||
static ComponentTypeID id = currentID++;
|
||||
static ComponentTypeID id = SHFamilyID<BaseClass>::currentID++;
|
||||
return id;
|
||||
//return 0;
|
||||
}
|
||||
#else
|
||||
template<typename DerivedClass>
|
||||
static SH_API ENABLE_IF_DERIVED(ComponentTypeID, BaseClass, DerivedClass) GetID() noexcept;
|
||||
#endif // SH_API_EXPORT
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
//initialize currentID as 0
|
||||
template<typename BaseClass>
|
||||
ComponentTypeID SHFamilyID<BaseClass>::currentID = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -17,8 +17,11 @@
|
|||
#include "../General/SHSparseSetContainer.h"
|
||||
#include "../Components/SHComponent.h"
|
||||
#include "../Components/SHComponentGroup.h"
|
||||
#include "../Events/SHComponentAddedEvent.h"
|
||||
#include "../Events/SHComponentRemovedEvent.h"
|
||||
//#include "Scene/SHSceneNode.h"
|
||||
#include "SH_API.h"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
|
@ -216,6 +219,11 @@ namespace SHADE
|
|||
comp->OnCreate();
|
||||
}
|
||||
|
||||
SHComponentAddedEvent eventData;
|
||||
eventData.eid = entityID;
|
||||
eventData.addedComponentType = ComponentFamily::GetID<T>();
|
||||
|
||||
SHEventManager::BroadcastEvent<SHComponentAddedEvent>(eventData, SH_COMPONENT_ADDED_EVENT);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -247,6 +255,13 @@ namespace SHADE
|
|||
{
|
||||
comp->OnCreate();
|
||||
}
|
||||
|
||||
SHComponentAddedEvent eventData;
|
||||
eventData.eid = entityID;
|
||||
eventData.addedComponentType = componentTypeID;
|
||||
|
||||
SHEventManager::BroadcastEvent<SHComponentAddedEvent>(eventData, SH_COMPONENT_ADDED_EVENT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -313,6 +328,12 @@ namespace SHADE
|
|||
|
||||
|
||||
componentSet.GetSparseSet<T>()->Remove(EntityHandleGenerator::GetIndex(entityID));
|
||||
|
||||
SHComponentRemovedEvent eventData;
|
||||
eventData.eid = entityID;
|
||||
eventData.removedComponentType = ComponentFamily::GetID<T>();
|
||||
|
||||
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
|
||||
}
|
||||
|
||||
/*!*************************************************************************
|
||||
|
@ -464,11 +485,6 @@ namespace SHADE
|
|||
return componentGroups[index];
|
||||
}
|
||||
|
||||
static void AddScriptComponent(EntityID eid, std::string const& scriptClassName) noexcept;
|
||||
|
||||
static void RemoveScriptComponent(EntityID eid, std::string const& scriptClassName) noexcept;
|
||||
|
||||
|
||||
};// end SHComponentManager
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,9 @@ namespace SHADE
|
|||
id = ((SystemID)version << sizeof(SystemVersionID) * CHAR_BIT) + typeID;
|
||||
}
|
||||
systemContainer.emplace(id, std::make_unique<T>());
|
||||
|
||||
auto size = systemContainer.size();
|
||||
|
||||
systemContainer[id].get()->systemID = id;
|
||||
|
||||
return id;
|
||||
|
|
|
@ -26,4 +26,6 @@ const EntityIndex MAX_EID = 51000;
|
|||
#define ENABLE_IF_UINT(_TYPE, _RETURN)\
|
||||
typename std::enable_if<(std::is_integral<_TYPE>::value && !std::is_signed<_TYPE>::value),_RETURN>::type
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "../SHECSMacros.h"
|
||||
#include "SH_API.h"
|
||||
#include "ECS_Base/General/SHFamily.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -69,5 +70,9 @@ namespace SHADE
|
|||
};
|
||||
|
||||
|
||||
template class SH_API SHFamilyID<SHSystem>;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -45,6 +45,12 @@ namespace SHADE
|
|||
SHEditorWindow::Update();
|
||||
if (Begin())
|
||||
{
|
||||
if (ImGui::Button("AUDIO"))
|
||||
{
|
||||
auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||
audioSystem->PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
|
||||
}
|
||||
|
||||
if (!SHEditor::selectedEntities.empty())
|
||||
{
|
||||
EntityID const& eid = SHEditor::selectedEntities[0];
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "SHEditor.hpp"
|
||||
#include "SHEditorWidgets.hpp"
|
||||
|
||||
#include "Math/Transform/SHTransformSystem.h"
|
||||
|
||||
//#==============================================================#
|
||||
//|| Editor Window Includes ||
|
||||
//#==============================================================#
|
||||
|
@ -87,6 +89,11 @@ namespace SHADE
|
|||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; //Enable docking
|
||||
|
||||
InitFonts();
|
||||
|
||||
|
||||
auto id = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
auto id2 = SHFamilyID<SHSystem>::GetID<SHTransformSystem>();
|
||||
auto id3 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
InitBackend(sdlWindow);
|
||||
|
||||
SetStyle(Style::SHADE);
|
||||
|
@ -104,7 +111,6 @@ namespace SHADE
|
|||
{
|
||||
(void)dt;
|
||||
NewFrame();
|
||||
|
||||
for (const auto& window : editorWindows | std::views::values)
|
||||
{
|
||||
if(window->isOpen)
|
||||
|
|
|
@ -8,3 +8,5 @@ typedef uint32_t SHEventHandle;
|
|||
constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0};
|
||||
constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT{ 1 };
|
||||
constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT{ 2 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT{ 3 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT{ 4 };
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "SHWindowMap.h"
|
||||
#include "SHWindow.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Input/SHInputManagerSystem.h"
|
||||
#include "Input/SHInputManager.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
|
@ -343,10 +343,7 @@ namespace SHADE
|
|||
}
|
||||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
if (auto im = SHSystemManager::GetSystem<SHInputManagerSystem>())
|
||||
{
|
||||
im->PollWheelVerticalDelta(wparam);
|
||||
}
|
||||
SHInputManager::PollWheelVerticalDelta(wparam);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*********************************************************************
|
||||
* \file SHInputManagerSystem.cpp
|
||||
* \file SHInputManager.cpp
|
||||
* \author Ryan Wang Nian Jing
|
||||
* \brief Definition of input manager.
|
||||
* Handles input from keyboard and mouse. Soon to include controller.
|
||||
|
@ -11,7 +11,8 @@
|
|||
|
||||
#pragma once
|
||||
#include <SHpch.h>
|
||||
#include "SHInputManagerSystem.h"
|
||||
#include "SHInputManager.h"
|
||||
#include "../Tools/SHException.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -19,61 +20,34 @@ namespace SHADE
|
|||
/* Static defines */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
unsigned SHInputManagerSystem::keyCount = 0;
|
||||
bool SHInputManagerSystem::keys[MAX_KEYS];
|
||||
bool SHInputManagerSystem::keysLast[MAX_KEYS];
|
||||
double SHInputManagerSystem::keysHeldTime[MAX_KEYS];
|
||||
double SHInputManagerSystem::keysReleasedTime[MAX_KEYS];
|
||||
unsigned SHInputManager::keyCount = 0;
|
||||
bool SHInputManager::keys[MAX_KEYS];
|
||||
bool SHInputManager::keysLast[MAX_KEYS];
|
||||
double SHInputManager::keysHeldTime[MAX_KEYS];
|
||||
double SHInputManager::keysReleasedTime[MAX_KEYS];
|
||||
|
||||
unsigned SHInputManagerSystem::keyToggleCount = 0;
|
||||
bool SHInputManagerSystem::keysToggle[MAX_KEYS];
|
||||
bool SHInputManagerSystem::keysToggleLast[MAX_KEYS];
|
||||
double SHInputManagerSystem::keysToggleOnTime[MAX_KEYS];
|
||||
double SHInputManagerSystem::keysToggleOffTime[MAX_KEYS];
|
||||
unsigned SHInputManager::keyToggleCount = 0;
|
||||
bool SHInputManager::keysToggle[MAX_KEYS];
|
||||
bool SHInputManager::keysToggleLast[MAX_KEYS];
|
||||
double SHInputManager::keysToggleOnTime[MAX_KEYS];
|
||||
double SHInputManager::keysToggleOffTime[MAX_KEYS];
|
||||
|
||||
int SHInputManagerSystem::mouseScreenX = 0;
|
||||
int SHInputManagerSystem::mouseScreenY = 0;
|
||||
int SHInputManagerSystem::mouseScreenXLast = 0;
|
||||
int SHInputManagerSystem::mouseScreenYLast = 0;
|
||||
double SHInputManagerSystem::mouseVelocityX = 0;
|
||||
double SHInputManagerSystem::mouseVelocityY = 0;
|
||||
int SHInputManagerSystem::mouseWheelVerticalDelta = 0;
|
||||
int SHInputManagerSystem::mouseWheelVerticalDeltaPoll = 0;
|
||||
int SHInputManager::mouseScreenX = 0;
|
||||
int SHInputManager::mouseScreenY = 0;
|
||||
int SHInputManager::mouseScreenXLast = 0;
|
||||
int SHInputManager::mouseScreenYLast = 0;
|
||||
double SHInputManager::mouseVelocityX = 0;
|
||||
double SHInputManager::mouseVelocityY = 0;
|
||||
int SHInputManager::mouseWheelVerticalDelta = 0;
|
||||
int SHInputManager::mouseWheelVerticalDeltaPoll = 0;
|
||||
|
||||
void SHInputManagerSystem::Init()
|
||||
{
|
||||
keyCount = 0;
|
||||
SecureZeroMemory(keys, sizeof(keys));
|
||||
SecureZeroMemory(keysLast, sizeof(keysLast));
|
||||
SecureZeroMemory(keysHeldTime, sizeof(keysHeldTime));
|
||||
SecureZeroMemory(keysReleasedTime, sizeof(keysReleasedTime));
|
||||
|
||||
keyToggleCount = 0;
|
||||
SecureZeroMemory(keysToggle, sizeof(keysToggle));
|
||||
SecureZeroMemory(keysToggleLast, sizeof(keysToggleLast));
|
||||
SecureZeroMemory(keysToggleOnTime, sizeof(keysToggleOnTime));
|
||||
SecureZeroMemory(keysToggleOffTime, sizeof(keysToggleOffTime));
|
||||
|
||||
mouseScreenX = 0;
|
||||
mouseScreenY = 0;
|
||||
mouseScreenXLast = 0;
|
||||
mouseScreenYLast = 0;
|
||||
mouseWheelVerticalDelta = 0;
|
||||
mouseWheelVerticalDeltaPoll = 0;
|
||||
}
|
||||
|
||||
void SHInputManagerSystem::Exit()
|
||||
{
|
||||
//No dynamically allocated memory. Nothing to do here.
|
||||
}
|
||||
|
||||
void SHInputManagerSystem::InputManagerRoutine::
|
||||
FixedExecute(double dt) noexcept
|
||||
void SHInputManager::UpdateInput(double dt) noexcept
|
||||
{
|
||||
//Keyboard and Mouse Buttons////////////////////////////////////////////////
|
||||
//Poll
|
||||
unsigned char keyboardState[MAX_KEYS];
|
||||
GetKeyboardState(keyboardState);
|
||||
//if (GetKeyboardState(keyboardState) == false) return;
|
||||
SHASSERT(GetKeyboardState(keyboardState), "SHInputManager:GetKeyboardState() failed ({})", GetLastError());
|
||||
keyCount = 0;
|
||||
keyToggleCount = 0;
|
||||
for (size_t i = 0; i < MAX_KEYS; ++i)
|
||||
|
@ -138,13 +112,17 @@ namespace SHADE
|
|||
mouseScreenX = p.x;
|
||||
mouseScreenY = p.y;
|
||||
|
||||
//Velocity
|
||||
mouseVelocityX = static_cast<double>(mouseScreenX - mouseScreenXLast) / dt;
|
||||
mouseVelocityY = static_cast<double>(mouseScreenY - mouseScreenYLast) / dt;
|
||||
|
||||
//Mouse wheel vertical delta updating
|
||||
mouseWheelVerticalDelta = 0;
|
||||
mouseWheelVerticalDelta = mouseWheelVerticalDeltaPoll;
|
||||
mouseWheelVerticalDeltaPoll = 0;
|
||||
}
|
||||
|
||||
bool SHInputManagerSystem::AnyKeyDown(SH_KEYCODE* firstDetected) noexcept
|
||||
bool SHInputManager::AnyKeyDown(SH_KEYCODE* firstDetected) noexcept
|
||||
{
|
||||
for (size_t i = 0; i < MAX_KEYS; ++i)
|
||||
{
|
||||
|
@ -157,7 +135,7 @@ namespace SHADE
|
|||
return false;
|
||||
}
|
||||
|
||||
bool SHInputManagerSystem::AnyKey(SH_KEYCODE* firstDetected) noexcept
|
||||
bool SHInputManager::AnyKey(SH_KEYCODE* firstDetected) noexcept
|
||||
{
|
||||
for (size_t i = 0; i < MAX_KEYS; ++i)
|
||||
{
|
||||
|
@ -170,7 +148,7 @@ namespace SHADE
|
|||
return false;
|
||||
}
|
||||
|
||||
bool SHInputManagerSystem::AnyKeyUp(SH_KEYCODE* firstDetected) noexcept
|
||||
bool SHInputManager::AnyKeyUp(SH_KEYCODE* firstDetected) noexcept
|
||||
{
|
||||
for (size_t i = 0; i < MAX_KEYS; ++i)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
/*********************************************************************
|
||||
* \file SHInputManagerSystem.h
|
||||
* \file SHInputManager.h
|
||||
* \author Ryan Wang Nian Jing
|
||||
* \brief Declaration of input manager.
|
||||
* Handles input from keyboard and mouse. Soon to include controller.
|
||||
|
@ -13,19 +13,12 @@
|
|||
//#include <Xinput.h>
|
||||
//#include "../../SHADE_Managed/src/SHpch.h"
|
||||
#include "SH_API.h"
|
||||
#include "ECS_Base/System/SHSystem.h"
|
||||
#include "ECS_Base/System/SHFixedSystemRoutine.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SH_API SHInputManagerSystem : public SHSystem
|
||||
class SH_API SHInputManager
|
||||
{
|
||||
public:
|
||||
class SH_API InputManagerRoutine : public SHFixedSystemRoutine
|
||||
{
|
||||
public:
|
||||
virtual void FixedExecute(double dt) noexcept override final;
|
||||
};
|
||||
|
||||
public:
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
@ -276,23 +269,21 @@ namespace SHADE
|
|||
};
|
||||
|
||||
public:
|
||||
//Updates current state of the input, with dt to be fetched from FRC
|
||||
//TODO should dt be fixed or variable?
|
||||
static void UpdateInput(double dt) noexcept;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*------------------------------------------------------------------------*/
|
||||
SHInputManagerSystem() noexcept = default;
|
||||
~SHInputManagerSystem() noexcept = default;
|
||||
SHInputManager() noexcept = default;
|
||||
~SHInputManager() noexcept = default;
|
||||
|
||||
SHInputManagerSystem(const SHInputManagerSystem&) = delete;
|
||||
SHInputManagerSystem(SHInputManagerSystem&&) = delete;
|
||||
SHInputManager(const SHInputManager&) = delete;
|
||||
SHInputManager(SHInputManager&&) = delete;
|
||||
|
||||
SHInputManagerSystem& operator= (const SHInputManagerSystem&) = delete;
|
||||
SHInputManagerSystem& operator= (SHInputManagerSystem&&) = delete;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* SHSystem Overrides */
|
||||
/*------------------------------------------------------------------------*/
|
||||
virtual void Init() override final;
|
||||
virtual void Exit() override final;
|
||||
SHInputManager& operator= (const SHInputManager&) = delete;
|
||||
SHInputManager& operator= (SHInputManager&&) = delete;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Member Functions */
|
||||
|
@ -417,8 +408,8 @@ namespace SHADE
|
|||
{
|
||||
POINT p{ mouseScreenX, mouseScreenY };
|
||||
ScreenToClient(GetActiveWindow(), &p);
|
||||
if (x) *x = mouseScreenX;
|
||||
if (y) *y = mouseScreenY;
|
||||
if (x) *x = p.x;
|
||||
if (y) *y = p.y;
|
||||
}
|
||||
|
||||
//Get the mouse velocity
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <string>
|
||||
#include "SHSceneGraph.h"
|
||||
#include "ECS_Base/General/SHFamily.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -42,6 +43,7 @@ namespace SHADE
|
|||
virtual void Unload() = 0;
|
||||
};
|
||||
|
||||
template class SH_API SHFamilyID<SHScene>;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ namespace SHADE
|
|||
{
|
||||
//prevSceneCreate = newScene;
|
||||
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName = sceneName; };
|
||||
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
|
||||
//nextSceneID = SHFamilyID<SHScene>::GetID<T>();
|
||||
nextSceneID = 0;
|
||||
|
||||
sceneChanged = true;
|
||||
}
|
||||
|
@ -101,13 +102,13 @@ namespace SHADE
|
|||
static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> ChangeScene(std::string const& sceneName) noexcept
|
||||
{
|
||||
//check if this new Scene is current Scene (Use RestartScene instead)
|
||||
if (currentSceneID == SHFamilyID<SHScene>::template GetID<T>())
|
||||
if (currentSceneID == SHFamilyID<SHScene>::GetID<T>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
//prevSceneCreate = newScene;
|
||||
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName; };
|
||||
nextSceneID = SHFamilyID<SHScene>::template GetID<T>();
|
||||
nextSceneID = SHFamilyID<SHScene>::GetID<T>();
|
||||
sceneChanged = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -254,8 +254,8 @@ namespace SHADE
|
|||
</ItemGroup>\n\
|
||||
<ItemGroup>\n\
|
||||
<Reference Include=\"SHADE_Managed\">\n\
|
||||
<HintPath Condition=\"Exists('..\\bin\\Debug\\SHADE_Managed.dll')\">..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\
|
||||
<HintPath Condition=\"Exists('..\\bin\\Release\\SHADE_Managed.dll')\">..\\bin\\Release\\SHADE_Managed.dll</HintPath>\
|
||||
<HintPath Condition=\"Exists('..\\bin\\Debug\\SHADE_Managed.dll')\">..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\n\
|
||||
<HintPath Condition=\"Exists('..\\bin\\Release\\SHADE_Managed.dll')\">..\\bin\\Release\\SHADE_Managed.dll</HintPath>\n\
|
||||
</Reference>\n\
|
||||
</ItemGroup>\n\
|
||||
</Project>";
|
||||
|
@ -520,7 +520,7 @@ namespace SHADE
|
|||
std::wostringstream oss;
|
||||
oss << "dotnet build \"" << SHStringUtils::StrToWstr(CSPROJ_PATH) << "\" -c ";
|
||||
oss << debug ? "Debug" : "Release";
|
||||
oss << " -o \"./tmp/\" -fl -flp:LogFile=build.log;Verbosity=quiet";
|
||||
oss << " -o \"./tmp/\" -fl -flp:LogFile=build.log;Verbosity=quiet -r \"win-x64\"";
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,12 @@ project "SHADE_Managed"
|
|||
"MultiProcessorCompile"
|
||||
}
|
||||
|
||||
disablewarnings
|
||||
{
|
||||
"4275"
|
||||
}
|
||||
|
||||
|
||||
dependson
|
||||
{
|
||||
"yaml-cpp",
|
||||
|
|
Loading…
Reference in New Issue