Cleaning up shutdown

This commit is contained in:
Confideo-IOM
2026-08-17 21:44:00 +01:00
parent 139fb149b2
commit 282243a16b
89 changed files with 2112 additions and 855 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ class CLASS_DEFINE HydraActor : public HydraObject
virtual void DeferredInitialiseComponents() {};
HydraID GetID() {return m_id;}
virtual void FixedTick(float delta_t) {};
virtual void Destroy() = 0;
virtual void Destroy()= 0;
};
+11 -238
View File
@@ -27,8 +27,16 @@ std::vector<HydraID> &HydraActorManager::GetChildren(HydraID actor_id)
}
void HydraActorManager::DeleteActor(HydraID actorID)
{
m_actors_waiting_for_delete.push_back(actorID);
{
assert(actorID <= m_actors.size() && "DeleteActor::INVALID ACTOR ID");
std::lock_guard<std::mutex> lock(m_mutex);
if(m_actors[actorID] != nullptr)
{
m_actors[actorID]->Destroy();
_SetActorDeleted(actorID);
}
}
void HydraActorManager::_SetActorDeleted(HydraID actorID)
@@ -52,197 +60,7 @@ HydraID HydraActorManager::LoadActor(std::string filename)
task_scheduler->WaitForTask(load_task_id);
return actor_id;
}
/*
HydraID HydraActorManager::_ProcessGLTFNode(aiScene const *scene, aiNode *parent_node, std::vector<uint32_t>material_lookup)
{
HydraID parent_actor_id = CreateActor<HydraGLTFActor>();
HydraECS *ecs = GetEngine()->ECS();
HydraECSPositionComponent position_component;
aiVector3D tmp_scaling = {};
aiQuaternion tmp_rotation = {};
aiVector3D tmp_position = {};
parent_node->mTransformation.Decompose(tmp_scaling, tmp_rotation, tmp_position);
glm::dvec3 scaling = glm::dvec3(tmp_scaling.x, tmp_scaling.y, tmp_scaling.z);
glm::quat rotation = glm::quat(tmp_rotation.w, tmp_rotation.x, tmp_rotation.y, tmp_rotation.z);
glm::dvec3 position = glm::dvec3(tmp_position.x, tmp_position.y, tmp_position.z);
ecs->AddComponent<HydraECSPositionComponent>(parent_actor_id, position_component);
SetPosition(parent_actor_id, position, rotation, false);
for (uint32_t i_mesh = 0; i_mesh < parent_node->mNumMeshes; i_mesh++)
{
aiMesh *mesh = scene->mMeshes[parent_node->mMeshes[i_mesh]];
_ProcessGLTFMesh(scene, parent_actor_id, mesh, material_lookup);
}
for (uint32_t i_node = 0; i_node < parent_node->mNumChildren; i_node++)
{
HydraID child_actor_id = _ProcessGLTFNode(scene, parent_node->mChildren[i_node], material_lookup);
SetRelationship(parent_actor_id, child_actor_id);
}
return parent_actor_id;
}
void HydraActorManager::_ProcessGLTFMesh(aiScene const *scene, HydraID parent_actor_id, aiMesh *mesh, std::vector<uint32_t>material_lookup)
{
HydraID mesh_actor_id = CreateActor<HydraGLTFActor>();
aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
std::vector<StandardVertexStruct> vertexes;
HydraECS *ecs = GetEngine()->ECS();
HydraECSPositionComponent position_component = {};
ecs->AddComponent<HydraECSPositionComponent>(mesh_actor_id, position_component);
for (uint32_t i_face = 0; i_face < mesh->mNumFaces; i_face++)
{
aiFace face = mesh->mFaces[i_face];
for (uint32_t i_index = 0; i_index < face.mNumIndices; i_index++)
{
uint32_t current_idx = face.mIndices[i_index];
StandardVertexStruct vert = {};
if (mesh->HasPositions())
{
vert.vertex[0] = mesh->mVertices[current_idx].x;
vert.vertex[1] = mesh->mVertices[current_idx].y;
vert.vertex[2] = mesh->mVertices[current_idx].z;
}
if (mesh->HasNormals())
{
vert.normal[0] = mesh->mNormals[current_idx].x;
vert.normal[1] = mesh->mNormals[current_idx].y;
vert.normal[2] = mesh->mNormals[current_idx].z;
}
if (mesh->HasTextureCoords(0))
{
vert.uv[0] = mesh->mTextureCoords[0][current_idx].x;
vert.uv[1] = mesh->mTextureCoords[0][current_idx].y;
}
vert.indexes[0] = mesh_actor_id;
vertexes.push_back(vert);
}
}
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
HydraID mesh_id = mesh_manager->CreateMesh(mesh_actor_id);
mesh_manager->SetVertexes(mesh_id, vertexes);
mesh_manager->CalculateNormals(mesh_id);
HydraECSMeshComponent mesh_comp;
mesh_comp.mesh_id = mesh_id;
ecs->AddComponent<HydraECSMeshComponent>(mesh_actor_id, mesh_comp);
aiString mat_name;
mat->Get(AI_MATKEY_NAME, mat_name);
HydraID material_id = material_lookup[mesh->mMaterialIndex];
if(material_id != INVALID_HYDRA_ID)
{
HydraECSMaterialComponent mat_comp;
mat_comp.material_id = material_id;
ecs->AddComponent<HydraECSMaterialComponent>(mesh_actor_id, mat_comp);
HydraMaterialStruct const * const mat_data = GetEngine()->MaterialManager()->GetMaterial(material_id);
GetEngine()->BufferManager()->AddMaterial(mesh_actor_id, material_id, *mat_data);
}
mesh_manager->SetMeshWaiting(mesh_id);
//Add renderable component
HydraPipelineManager* pipeline_manager = GetEngine()->PipelineManager();
uint32_t pipeline_id = pipeline_manager->GetPipelineID("FORWARD");
uint32_t shadow_pipeline_id = pipeline_manager->GetPipelineID("SHADOW");
uint32_t deferred_pipeline_id = pipeline_manager->GetPipelineID("DEFERRED");
HydraECSRenderableComponent render_comp;
if(pipeline_id != INVALID_HYDRA_ID)
{
render_comp.pipelines.set(pipeline_id);
}
render_comp.pipelines.set(shadow_pipeline_id);
render_comp.pipelines.set(deferred_pipeline_id);
ecs->AddComponent<HydraECSRenderableComponent>(mesh_actor_id, render_comp);
SetRelationship(parent_actor_id, mesh_actor_id);
}
/// @brief Load all of the scene textures
/// @param scene containing scene
/// @param texture_lookup index of texture in the scene to the Hydra texture ID
void HydraActorManager::_ProcessGLTFTextures(aiScene const *scene, std::vector<uint32_t> &texture_lookup)
{
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
// Make space for the texture lookups
texture_lookup.resize(scene->mNumTextures);
for (uint32_t i_tex = 0; i_tex < scene->mNumTextures; i_tex++)
{
aiTexture *tex = scene->mTextures[i_tex];
// Create a holder for the texture
HydraID texture_id = texture_manager->CreateTexture(0, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false);
// load the texture data from the scene texture
texture_manager->FillTexture(texture_id, reinterpret_cast<unsigned char *>(tex->pcData), tex->mWidth);
// store the texture id against the scene index for the texture. Materials will have *n where n is the index
texture_lookup[i_tex] = texture_id;
texture_manager->FinaliseTexture(texture_id);
}
}
void HydraActorManager::_ProcessGLTFMaterials(aiScene const *scene,
std::vector<uint32_t>& texture_lookup,
std::vector<uint32_t>& material_lookup,
std::string filename)
{
material_lookup.resize(scene->mNumMaterials);
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
for (uint32_t i_mat = 0; i_mat < scene->mNumMaterials; i_mat++)
{
HydraMaterialStruct material;
aiMaterial *mat = scene->mMaterials[i_mat];
aiColor3D color(0.f, 0.f, 0.f);
aiString name;
mat->Get(AI_MATKEY_COLOR_DIFFUSE, color);
mat->Get(AI_MATKEY_NAME, name);
std::string mat_name = filename + std::to_string(i_mat);
aiTexture diffuse_tex;
uint32_t diffuse_tex_count = mat->GetTextureCount(aiTextureType::aiTextureType_DIFFUSE);
// have to do something here for multiple diffuse textures at some point.
aiString texture_path;
aiTextureMapping texture_mapping;
uint32_t uv_index;
if (diffuse_tex_count > 0)
{
mat->GetTexture(aiTextureType::aiTextureType_DIFFUSE, 0, &texture_path, &texture_mapping, &uv_index);
std::string path = std::string(texture_path.C_Str());
uint32_t texture_index = atoi(path.substr(1).c_str());
HydraID texture_id = texture_lookup[texture_index];
material.diffuse_texture = texture_id;
material.texture_types += static_cast<uint32_t>(HYDRA_TEXTURE_TYPE::DIFFUSE_TEXTURE);
}
material.diffuse_colour = glm::vec4(color.r, color.g, color.b, 1);
HydraID material_id = GetEngine()->MaterialManager()->CreateMaterial(mat_name, material);
material_lookup[i_mat] = material_id;
if (material_id == INVALID_HYDRA_ID)
{
throw std::runtime_error("Could not create material");
}
}
}
*/
HydraID HydraActorManager::_SaveActor(HydraActor *actor)
{
@@ -427,18 +245,7 @@ void HydraActorManager::TranslateActor(HydraID actorID, glm::dvec3 translation)
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
}
void HydraActorManager::AddComponentType(HydraID actorID, uint32_t component_type)
{
if (actorID < m_actors.size())
{
HydraActor *actor = m_actors[actorID];
if (actor != nullptr)
{
actor->m_component_types.push_back(component_type);
actor->m_components_waiting++;
}
}
}
glm::mat4 HydraActorManager::GetActorPose(HydraID actorID)
{
@@ -474,40 +281,6 @@ glm::dvec3 HydraActorManager::GetActorPosition(HydraID actorID)
return pos_comp.position;
}
bool HydraActorManager::HasComponentType(HydraID actorID, uint32_t component_type)
{
if (actorID < m_actors.size())
{
HydraActor *actor = m_actors[actorID];
if (actor != nullptr)
{
for (int i = 0; i < actor->m_component_types.size(); i++)
{
if (actor->m_component_types[i] == component_type)
{
return true;
}
}
}
}
return false;
}
void HydraActorManager::RemoveComponentType(HydraID actorID, uint32_t component_type)
{
if (actorID < m_actors.size())
{
HydraActor *actor = m_actors[actorID];
if (actor != nullptr)
{
uint32_t comp_type = static_cast<uint32_t>(component_type);
if (actor->m_component_types.size() > comp_type)
{
actor->m_component_types.erase(actor->m_component_types.begin() + comp_type);
}
}
}
}
HydraID HydraActorManager::GetParent(HydraID actor_id)
{
+4 -3
View File
@@ -32,6 +32,7 @@ class CLASS_DEFINE HydraActorManager : public HydraObject
public:
void Initialise(size_t max_actors);
template<class T> HydraID CreateActor();
HydraID LoadActor(std::string filename);
void DeleteActor(HydraID actorID);
@@ -52,9 +53,9 @@ class CLASS_DEFINE HydraActorManager : public HydraObject
void TranslateActor(HydraID actorID, glm::dvec3 translation);
void SetRelationship(HydraID parent_id, HydraID child_id);
void AddComponentType(HydraID actorID, uint32_t component_type);
bool HasComponentType(HydraID actorID, uint32_t component_type);
void RemoveComponentType(HydraID actorID, uint32_t component_type);
// void AddComponentType(HydraID actorID, uint32_t component_type);
// bool HasComponentType(HydraID actorID, uint32_t component_type);
// void RemoveComponentType(HydraID actorID, uint32_t component_type);
HydraID GetParent(HydraID actor_id);
HydraID GetRoot(HydraID actor_id);
@@ -0,0 +1,214 @@
#include "HydraPlanetActor.h"
#include "../../engine/HydraEngine.h"
#include "../../actor/HydraActorManager.h"
#include "../../task/HydraTask.h"
#include "../../ecs/HydraECS.h"
#include "../../ecs/components/HydraPositionComponent.h"
#include "../../ecs/components/HydraMeshComponent.h"
#include "../../ecs/components/HydraRenderableComponent.h"
#include "../../ecs/components/HydraMaterialComponent.h"
#include "../../buffer/HydraMaterialBufferManager.h"
#include "../../buffer/HydraTextureBufferManager.h"
#include "../../buffer/HydraMaterialBuffer.h"
#include "../../mesh/HydraMeshManager.h"
#include "../../mesh/HydraMesh.h"
void HydraPlanetActor::InitialiseComponents()
{
// HydraECS* ecs = GetEngine()->ECS();
// HydraID entity_id = ecs->CreateEntity();
_CreatePosition();
// _CreatePhysics();
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
_CreateQuads();
}
void HydraPlanetActor::DeferredInitialiseComponents()
{
}
void HydraPlanetActor::_CreatePosition()
{
HydraECS *ecs = GetEngine()->ECS();
HydraPositionComponent position_component;
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
}
void HydraPlanetActor::_CreateMesh()
{
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
HydraID mesh_id = mesh_manager->CreateMesh();
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
mesh->vertexes.resize(24);
mesh->indexes.resize(36);
float scale_x = 10000.0f;
float scale_y = 10000.0f;
float scale_z = 10000.0f;
float min_x = -0.5f * scale_x;
float min_y = -0.5f * scale_y;
float min_z = -0.5f * scale_z;
float max_x = 0.5f * scale_x;
float max_y = 0.5f * scale_y;
float max_z = 0.5f * scale_z;
float min_u = 100;
float min_v = 100;
float max_u = 0;
float max_v = 0;
// 1---2 5---6
//| / | | / |
// 0---3 4---7
HydraID actor_id = GetID();
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
// Face 0
mesh->indexes[0] = 0;
mesh->indexes[1] = 1;
mesh->indexes[2] = 2;
mesh->indexes[3] = 0;
mesh->indexes[4] = 2;
mesh->indexes[5] = 3;
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[6] = 4;
mesh->indexes[7] = 5;
mesh->indexes[8] = 6;
mesh->indexes[9] = 4;
mesh->indexes[10] = 6;
mesh->indexes[11] = 7;
// Back Face
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[12] = 8;
mesh->indexes[13] = 9;
mesh->indexes[14] = 10;
mesh->indexes[15] = 8;
mesh->indexes[16] = 10;
mesh->indexes[17] = 11;
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[18] = 12;
mesh->indexes[19] = 13;
mesh->indexes[20] = 14;
mesh->indexes[21] = 12;
mesh->indexes[22] = 14;
mesh->indexes[23] = 15;
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[24] = 16;
mesh->indexes[25] = 17;
mesh->indexes[26] = 18;
mesh->indexes[27] = 16;
mesh->indexes[28] = 18;
mesh->indexes[29] = 19;
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[30] = 20;
mesh->indexes[31] = 21;
mesh->indexes[32] = 22;
mesh->indexes[33] = 20;
mesh->indexes[34] = 22;
mesh->indexes[35] = 23;
mesh_manager->CalculateNormals(mesh->mesh_id);
HydraECS *ecs = GetEngine()->ECS();
HydraMeshComponent mesh_comp;
mesh_comp.mesh_id = mesh_id;
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
}
void HydraPlanetActor::_CreateMaterial()
{
HydraEngine *engine = GetEngine();
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
HydraMaterialBuffer material = {};
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
mat_comp.material_id = mat_id;
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
}
void HydraPlanetActor::_CreatePhysics()
{
// HydraECSPhysicsComponent physics_component;
// physics_component.physics_state = Hydra_State::Waiting;
// physics_component.physics_definition.actor_id = GetID();
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
// physics_component.physics_definition.mass = 100000.0f;
// physics_component.physics_definition.extent_x = 1000.0f;
// physics_component.physics_definition.extent_y = 0.5f;
// physics_component.physics_definition.extent_z = 1000.0f;
// physics_component.physics_definition.dynamic_friction = 0.5f;
// physics_component.physics_definition.restitution = 0.5f;
// HydraECS* ecs = GetEngine()->ECS();
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
}
void HydraPlanetActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}
void HydraPlanetActor::_CreateQuads()
{
}
@@ -0,0 +1,31 @@
#ifndef HYDRAPLANETACTOR
#define HYDRAPLANETACTOR
#include "../HydraActor.h"
class CLASS_DEFINE HydraPlanetActor : public HydraActor
{
private:
double m_scale = 1.0;
double m_widthscale = 1000.0f;
HydraID m_material_component = INVALID_HYDRA_ID;
HydraID m_position_component = INVALID_HYDRA_ID;
HydraID m_mesh_component = INVALID_HYDRA_ID;
protected:
void _CreatePosition();
void _CreateMesh();
void _CreateMaterial();
void _CreatePhysics();
void _CreateRenderableComponent();
void _CreateQuads();
public:
virtual void InitialiseComponents();
virtual void DeferredInitialiseComponents();
virtual void Destroy(){}
};
#endif /* HYDRAPLANETACTOR */
@@ -0,0 +1,208 @@
#include "HydraPlanetQuadActor.h"
#include "../../engine/HydraEngine.h"
#include "../../actor/HydraActorManager.h"
#include "../../task/HydraTask.h"
#include "../../ecs/HydraECS.h"
#include "../../ecs/components/HydraPositionComponent.h"
#include "../../ecs/components/HydraMeshComponent.h"
#include "../../ecs/components/HydraRenderableComponent.h"
#include "../../ecs/components/HydraMaterialComponent.h"
#include "../../buffer/HydraMaterialBufferManager.h"
#include "../../buffer/HydraTextureBufferManager.h"
#include "../../buffer/HydraMaterialBuffer.h"
#include "../../mesh/HydraMeshManager.h"
#include "../../mesh/HydraMesh.h"
void HydraPlanetQuadActor::InitialiseComponents()
{
// HydraECS* ecs = GetEngine()->ECS();
// HydraID entity_id = ecs->CreateEntity();
_CreatePosition();
// _CreatePhysics();
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
}
void HydraPlanetQuadActor::DeferredInitialiseComponents()
{
}
void HydraPlanetQuadActor::_CreatePosition()
{
HydraECS *ecs = GetEngine()->ECS();
HydraPositionComponent position_component;
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
}
void HydraPlanetQuadActor::_CreateMesh()
{
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
HydraID mesh_id = mesh_manager->CreateMesh();
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
mesh->vertexes.resize(24);
mesh->indexes.resize(36);
float scale_x = 10000.0f;
float scale_y = 10000.0f;
float scale_z = 10000.0f;
float min_x = -0.5f * scale_x;
float min_y = -0.5f * scale_y;
float min_z = -0.5f * scale_z;
float max_x = 0.5f * scale_x;
float max_y = 0.5f * scale_y;
float max_z = 0.5f * scale_z;
float min_u = 100;
float min_v = 100;
float max_u = 0;
float max_v = 0;
// 1---2 5---6
//| / | | / |
// 0---3 4---7
HydraID actor_id = GetID();
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
// Face 0
mesh->indexes[0] = 0;
mesh->indexes[1] = 1;
mesh->indexes[2] = 2;
mesh->indexes[3] = 0;
mesh->indexes[4] = 2;
mesh->indexes[5] = 3;
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[6] = 4;
mesh->indexes[7] = 5;
mesh->indexes[8] = 6;
mesh->indexes[9] = 4;
mesh->indexes[10] = 6;
mesh->indexes[11] = 7;
// Back Face
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[12] = 8;
mesh->indexes[13] = 9;
mesh->indexes[14] = 10;
mesh->indexes[15] = 8;
mesh->indexes[16] = 10;
mesh->indexes[17] = 11;
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[18] = 12;
mesh->indexes[19] = 13;
mesh->indexes[20] = 14;
mesh->indexes[21] = 12;
mesh->indexes[22] = 14;
mesh->indexes[23] = 15;
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[24] = 16;
mesh->indexes[25] = 17;
mesh->indexes[26] = 18;
mesh->indexes[27] = 16;
mesh->indexes[28] = 18;
mesh->indexes[29] = 19;
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
mesh->indexes[30] = 20;
mesh->indexes[31] = 21;
mesh->indexes[32] = 22;
mesh->indexes[33] = 20;
mesh->indexes[34] = 22;
mesh->indexes[35] = 23;
mesh_manager->CalculateNormals(mesh->mesh_id);
HydraECS *ecs = GetEngine()->ECS();
HydraMeshComponent mesh_comp;
mesh_comp.mesh_id = mesh_id;
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
}
void HydraPlanetQuadActor::_CreateMaterial()
{
HydraEngine *engine = GetEngine();
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
HydraMaterialBuffer material = {};
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
mat_comp.material_id = mat_id;
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
}
void HydraPlanetQuadActor::_CreatePhysics()
{
// HydraECSPhysicsComponent physics_component;
// physics_component.physics_state = Hydra_State::Waiting;
// physics_component.physics_definition.actor_id = GetID();
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
// physics_component.physics_definition.mass = 100000.0f;
// physics_component.physics_definition.extent_x = 1000.0f;
// physics_component.physics_definition.extent_y = 0.5f;
// physics_component.physics_definition.extent_z = 1000.0f;
// physics_component.physics_definition.dynamic_friction = 0.5f;
// physics_component.physics_definition.restitution = 0.5f;
// HydraECS* ecs = GetEngine()->ECS();
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
}
void HydraPlanetQuadActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}
@@ -0,0 +1,33 @@
#ifndef HYDRAPLANETQUADACTOR
#define HYDRAPLANETQUADACTOR
#include "../HydraActor.h"
class CLASS_DEFINE HydraPlanetQuadActor : public HydraActor
{
private:
double m_scale = 1.0;
double m_widthscale = 1000.0f;
HydraID m_material_component = INVALID_HYDRA_ID;
HydraID m_position_component = INVALID_HYDRA_ID;
HydraID m_mesh_component = INVALID_HYDRA_ID;
protected:
void _CreatePosition();
void _CreateMesh();
void _CreateMaterial();
void _CreatePhysics();
void _CreateRenderableComponent();
public:
virtual void InitialiseComponents();
virtual void DeferredInitialiseComponents();
virtual void Destroy(){}
};
#endif /* HYDRAPLANETQUADACTOR */