Ajout de Jolt Physics + 1ere version des factory entitecomposants - camera, transform, rigidbody, collider, renderer
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
namespace CosmicCore {
|
||||
|
||||
CScene::CScene(std::string name) : CSerializable(),
|
||||
m_name(std::move(name)) {
|
||||
m_name(std::move(name)), m_tangibleWorld(this)
|
||||
{
|
||||
m_tangibleWorld.initWorld();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,47 +23,14 @@ namespace CosmicCore {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CEntity CScene::addEntity(std::string name, std::string description){
|
||||
VulkanImpl* api = dynamic_cast<VulkanImpl*>(GraphicsAPI::getAPI().get());
|
||||
CScene::~CScene()
|
||||
{
|
||||
m_tangibleWorld.destroy();
|
||||
}
|
||||
|
||||
CEntity CScene::createEntity(){
|
||||
auto handle = m_ecManager.registry.create();
|
||||
CEntity handler(m_ecManager, handle, this);
|
||||
m_ecManager().emplace<CTransform>(handle, handler);
|
||||
m_ecManager().emplace<CMetaData>(handle, handler, std::move(name), std::move(description));
|
||||
|
||||
auto& rM = GraphicsAPI::getAPI()->getResourceManager();
|
||||
|
||||
auto model = CModelLoader::loadModel("assets/models/cube.glb", rM);
|
||||
|
||||
rM.getTextureManager().loadedTextures.push_back(std::make_unique<CTexture>("assets/shrekt.png"));
|
||||
auto texture = rM.getTextureManager().loadedTextures.back().get();
|
||||
texture->init();
|
||||
for(auto& mesh : model->getMeshes())
|
||||
{
|
||||
mesh->getMaterial()->textureAlbedo = texture;
|
||||
mesh->getMaterial()->build();
|
||||
}
|
||||
|
||||
m_ecManager().emplace<CRenderer>(handle, handler, model);
|
||||
auto& tr = m_ecManager.registry.get<CTransform>(handle);
|
||||
tr.initUniformBuffer(dynamic_cast<VulkanImpl*>(GraphicsAPI::getAPI().get())->getAllocator());
|
||||
tr.updateUniformBuffer(0);
|
||||
tr.updateUniformBuffer(1);
|
||||
|
||||
auto camHandle = m_ecManager.registry.create();
|
||||
CEntity handlerCam(m_ecManager, camHandle, this);
|
||||
|
||||
auto& transform = m_ecManager().emplace<CTransform>(camHandle, handlerCam);
|
||||
auto& cam = m_ecManager.registry.emplace<CCamera>(camHandle, handlerCam);
|
||||
|
||||
m_ecManager.registry.emplace<CRelationship>(camHandle, handlerCam, std::vector<EntityId>{handle});
|
||||
m_ecManager.registry.emplace<CRelationship>(handle, handler, camHandle);
|
||||
|
||||
transform.setCenter({0.0f, 0.9f, 3.0f});
|
||||
cam.setAspect((float)api->getSwapChainExtent().width / api->getSwapChainExtent().height);
|
||||
cam.initUniformBuffer(api->getAllocator());
|
||||
cam.updateUniformBuffer(0, transform);
|
||||
cam.updateUniformBuffer(1, transform);
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../Utils/CSerializable.hpp"
|
||||
#include <string>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "../Physics/CTangibleWorld.hpp"
|
||||
namespace CosmicCore {
|
||||
class CEntity;
|
||||
class CScene : public CSerializable {
|
||||
@@ -13,15 +13,16 @@ namespace CosmicCore {
|
||||
// The name of the scene.
|
||||
std::string m_name;
|
||||
EntityComponentManager m_ecManager;
|
||||
|
||||
CTangibleWorld m_tangibleWorld;
|
||||
|
||||
public:
|
||||
CScene() = delete;
|
||||
CScene(std::string name);
|
||||
virtual ~CScene() = default;
|
||||
virtual ~CScene();
|
||||
|
||||
unsigned int getNumEntity() const;
|
||||
|
||||
CEntity addEntity(std::string name, std::string description);
|
||||
CEntity createEntity();
|
||||
|
||||
std::string getName() const;
|
||||
|
||||
@@ -29,6 +30,7 @@ namespace CosmicCore {
|
||||
|
||||
void removeEntity(unsigned int index, bool destroy = true);
|
||||
|
||||
CTangibleWorld& getTangibleWorld() {return m_tangibleWorld;};
|
||||
//CEntity* getActiveCamera();
|
||||
//void setActiveCamera(CEntity* newCamera);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user