Improved Environment and Entity managment
This commit is contained in:
parent
ea8420f0d8
commit
88ba321f68
@ -1,13 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
|
||||||
#include <array>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Deer/Components.h"
|
#include "Deer/Components.h"
|
||||||
#include "Deer/Log.h"
|
#include "Deer/Log.h"
|
||||||
#include "Deer/Memory.h"
|
#include "Deer/Memory.h"
|
||||||
|
|
||||||
#include "entt/entt.hpp"
|
#include "entt/entt.hpp"
|
||||||
|
|
||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
@ -15,13 +10,18 @@
|
|||||||
#include "DeerRender/SceneCamera.h"
|
#include "DeerRender/SceneCamera.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENVIRONMENT_MAX_ENTITIES 2048
|
#include <algorithm>
|
||||||
#define MAX_ENVIRONMENT_COUNT 64
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
class Entity;
|
class Entity;
|
||||||
|
|
||||||
class Environment {
|
class Environment {
|
||||||
|
// Note: Outdated note
|
||||||
///////// NOTES ///////////
|
///////// NOTES ///////////
|
||||||
// - The entity id means the position in a array defined in Environment
|
// - The entity id means the position in a array defined in Environment
|
||||||
// - The entity id is relative to a Environment so it can be a complete
|
// - The entity id is relative to a Environment so it can be a complete
|
||||||
@ -39,22 +39,25 @@ namespace Deer {
|
|||||||
|
|
||||||
// Clears all entities
|
// Clears all entities
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// Obtains the entity
|
// Obtains the entity
|
||||||
Entity& getEntity(uint16_t id) const;
|
Entity& getEntity(uint16_t id);
|
||||||
bool entityExists(uint16_t id) const;
|
bool entityExists(uint16_t id) const;
|
||||||
uint16_t getEntityCount() const { return m_entityCount; }
|
uint16_t getEntityCount() const;
|
||||||
|
|
||||||
// Creates a entity child at root
|
// Creates a entity child at root
|
||||||
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
Entity& createEntity(const std::string& name = "");
|
Entity& createEntity(const std::string& name = "");
|
||||||
|
// Can be slow! This has to empty the stack of empty entities in case its necessary so use it in ascendent order!
|
||||||
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
Entity& createEntityWithId(uint16_t id, const std::string& name = "");
|
Entity& createEntityWithId(uint16_t id, const std::string& name = "");
|
||||||
void destroyEntity(uint16_t id);
|
void destroyEntity(uint16_t id);
|
||||||
|
|
||||||
// Special behaviour
|
// Special behaviour
|
||||||
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
Entity createEmptyEntity();
|
Entity createEmptyEntity();
|
||||||
|
|
||||||
// FEO
|
// FEO
|
||||||
uint16_t tryGetMainCamera();
|
uint16_t tryGetMainCamera() const;
|
||||||
void setMainCamera(Entity& entity);
|
void setMainCamera(Entity& entity);
|
||||||
|
|
||||||
// Obtains the entity that is on the root of the environment
|
// Obtains the entity that is on the root of the environment
|
||||||
@ -62,112 +65,89 @@ namespace Deer {
|
|||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
void render(SceneCamera& camera);
|
void render(SceneCamera& camera);
|
||||||
#endif
|
#endif
|
||||||
entt::registry m_registry;
|
Scope<entt::registry> m_registry;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_mainCamera = 0;
|
uint16_t m_mainCamera = 0;
|
||||||
// To avoid inecessary loop we set this variable that means that smaller
|
|
||||||
// id's than this numbers are not null, empty or used
|
|
||||||
uint16_t m_idCreationOffset = 0;
|
|
||||||
// Since we don't initialize Entity in the big array for performance we
|
|
||||||
// want to keep track the ones we initialized defined by this value, it
|
|
||||||
// the id is greater it means that any information that it has can't be
|
|
||||||
// seen as valid
|
|
||||||
uint16_t m_maxIdValue = 0;
|
|
||||||
// Number of entities that exists inside
|
|
||||||
uint16_t m_entityCount = 0;
|
|
||||||
// This is where we save the entities, in a const list defined by
|
|
||||||
// ENVIRONMENT_MAX_ENTITIES, we have to make sure this system is as fast
|
|
||||||
// as possible
|
|
||||||
Scope<std::array<Entity, ENVIRONMENT_MAX_ENTITIES>> entities;
|
|
||||||
|
|
||||||
inline uint16_t pullEntityID() {
|
std::stack<u_int16_t> unused_entities_spaces;
|
||||||
m_idCreationOffset++;
|
std::vector<Entity> entities;
|
||||||
if (m_idCreationOffset > m_maxIdValue)
|
|
||||||
m_maxIdValue = m_idCreationOffset;
|
|
||||||
return m_idCreationOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend class Entity;
|
friend class Entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Warning: This calss does not initialize for performance
|
// Warning: This calss does not initialize for performance
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
// This class can not be copied
|
|
||||||
Entity(const Entity&) = delete;
|
|
||||||
Entity() {}
|
Entity() {}
|
||||||
|
Entity(const Entity&) = delete;
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
Entity(Entity&&) noexcept;
|
||||||
T& addComponent(Args&&... args) const {
|
Entity& operator=(Entity&&) noexcept;
|
||||||
DEER_CORE_ASSERT(
|
|
||||||
!m_environment->m_registry.all_of<T>(m_entityHandle),
|
|
||||||
"Entity already have component {0}", typeid(T).name());
|
|
||||||
|
|
||||||
return m_environment->m_registry.emplace<T>(
|
|
||||||
m_entityHandle, std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T& getComponent() const {
|
|
||||||
DEER_CORE_ASSERT(
|
|
||||||
m_environment->m_registry.all_of<T>(m_entityHandle),
|
|
||||||
"Entity has no component {0}", typeid(T).name());
|
|
||||||
|
|
||||||
return m_environment->m_registry.get<T>(m_entityHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool hasComponent() const {
|
|
||||||
return m_environment->m_registry.all_of<T>(m_entityHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void removeComponent() const {
|
|
||||||
DEER_CORE_ASSERT(
|
|
||||||
m_environment->m_registry.all_of<T>(m_entityHandle),
|
|
||||||
"Entity does not have component {0}", typeid(T).name());
|
|
||||||
|
|
||||||
m_environment->m_registry.remove<T>(m_entityHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity& duplicate();
|
Entity& duplicate();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
uint16_t getId() const { return m_entityID; }
|
uint16_t getId() const { return entId; }
|
||||||
Entity& getParent() const;
|
Entity& getParent() const;
|
||||||
inline uint16_t getParentId() const { return m_parentID; }
|
inline uint16_t getParentId() const { return parentId; }
|
||||||
|
|
||||||
// TODO, enable transfer entitys from difrent environments
|
// TODO, enable transfer entitys from difrent environments
|
||||||
void setParent(Entity& parent);
|
void setParent(Entity& parent);
|
||||||
bool isDescendantOf(Entity& parent) const;
|
bool isDescendantOf(Entity& parent) const;
|
||||||
|
|
||||||
Environment* getEnvironment() const { return m_environment; }
|
Environment* getEnvironment() const { return environment; }
|
||||||
|
|
||||||
bool isRoot() const { return m_entityID == 0; }
|
bool isRoot() const { return entId == 0; }
|
||||||
glm::mat4 getWorldMatrix();
|
glm::mat4 getWorldMatrix() const;
|
||||||
glm::mat4 getRelativeMatrix();
|
glm::mat4 getRelativeMatrix() const;
|
||||||
|
|
||||||
void tickExecution();
|
void tickExecution();
|
||||||
|
void clear();
|
||||||
|
|
||||||
inline bool isValid() const { return m_exists; }
|
bool isValid() const;
|
||||||
|
private:
|
||||||
private:
|
Environment* environment = nullptr;
|
||||||
Environment* m_environment = nullptr;
|
entt::entity entHandle = entt::null;
|
||||||
entt::entity m_entityHandle = entt::null;
|
uint16_t entId = 0;
|
||||||
uint16_t m_entityID = 0;
|
uint16_t parentId = 0;
|
||||||
uint16_t m_parentID = 0;
|
|
||||||
bool m_exists = false;
|
|
||||||
|
|
||||||
Entity(entt::entity handle, Environment* scene, uint16_t entityID);
|
Entity(entt::entity handle, Environment* scene, uint16_t entityID);
|
||||||
|
|
||||||
friend class Environment;
|
friend class Environment;
|
||||||
|
public:
|
||||||
|
template <typename T, typename... Args>
|
||||||
|
T& addComponent(Args&&... args) const {
|
||||||
|
DEER_CORE_ASSERT(
|
||||||
|
!environment->m_registry->all_of<T>(entHandle),
|
||||||
|
"Entity already have component {0}", typeid(T).name());
|
||||||
|
|
||||||
|
return environment->m_registry->emplace<T>(
|
||||||
|
entHandle, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T& getComponent() const {
|
||||||
|
DEER_CORE_ASSERT(
|
||||||
|
environment->m_registry->all_of<T>(entHandle),
|
||||||
|
"Entity has no component {0}", typeid(T).name());
|
||||||
|
|
||||||
|
return environment->m_registry->get<T>(entHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool hasComponent() const {
|
||||||
|
return environment->m_registry->all_of<T>(entHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void removeComponent() const {
|
||||||
|
DEER_CORE_ASSERT(
|
||||||
|
environment->m_registry->all_of<T>(entHandle),
|
||||||
|
"Entity does not have component {0}", typeid(T).name());
|
||||||
|
|
||||||
|
environment->m_registry->remove<T>(entHandle);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace EnvironmentManager {
|
|
||||||
uint16_t createEnvironment();
|
|
||||||
Environment& getEnvironment(uint16_t);
|
|
||||||
|
|
||||||
void clearAllEnvironments();
|
|
||||||
}
|
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include "glm/gtc/quaternion.hpp"
|
#include "glm/gtc/quaternion.hpp"
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
#include "glm/gtc/matrix_transform.hpp"
|
#include "glm/gtc/matrix_transform.hpp"
|
||||||
|
|
||||||
#define MAX_TEXTURE_BINDINGS 4
|
#define MAX_TEXTURE_BINDINGS 4
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
@ -1,16 +1,46 @@
|
|||||||
#include "Deer/Components.h"
|
#include "Deer/Components.h"
|
||||||
#include "Deer/Enviroment.h"
|
#include "Deer/Enviroment.h"
|
||||||
|
#include "Deer/Log.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
Entity::Entity(entt::entity handle, Environment* scene, uint16_t entityID)
|
Entity::Entity(entt::entity handle, Environment* scene, uint16_t entityID)
|
||||||
: m_entityHandle(handle),
|
: entHandle(handle),
|
||||||
m_environment(scene),
|
environment(scene),
|
||||||
m_entityID(entityID),
|
entId(entityID) { }
|
||||||
m_exists(true) {}
|
|
||||||
|
Entity::Entity(Entity&& ent) noexcept {
|
||||||
|
environment = ent.environment;
|
||||||
|
entHandle = ent.entHandle;
|
||||||
|
parentId = ent.parentId;
|
||||||
|
entId = ent.entId;
|
||||||
|
|
||||||
|
ent.environment = nullptr;
|
||||||
|
ent.entHandle = entt::null;
|
||||||
|
ent.parentId = 0;
|
||||||
|
ent.entId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity& Entity::operator=(Entity&& ent) noexcept {
|
||||||
|
environment = ent.environment;
|
||||||
|
entHandle = ent.entHandle;
|
||||||
|
parentId = ent.parentId;
|
||||||
|
entId = ent.entId;
|
||||||
|
|
||||||
|
ent.environment = nullptr;
|
||||||
|
ent.entHandle = entt::null;
|
||||||
|
ent.parentId = 0;
|
||||||
|
ent.entId = 0;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Entity::isValid() const {
|
||||||
|
return environment != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void Entity::setParent(Entity& parent) {
|
void Entity::setParent(Entity& parent) {
|
||||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||||
DEER_CORE_ASSERT(parent.m_environment == m_environment,
|
DEER_CORE_ASSERT(parent.environment == environment,
|
||||||
"Can not set parent from diferent environments");
|
"Can not set parent from diferent environments");
|
||||||
DEER_CORE_ASSERT(parent.isValid(), "Parent is not valid");
|
DEER_CORE_ASSERT(parent.isValid(), "Parent is not valid");
|
||||||
if (parent.getId() == getId()) return;
|
if (parent.getId() == getId()) return;
|
||||||
@ -29,7 +59,7 @@ namespace Deer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parentID = parent.getId();
|
parentId = parent.getId();
|
||||||
current_parent.getComponent<RelationshipComponent>().removeChildren(
|
current_parent.getComponent<RelationshipComponent>().removeChildren(
|
||||||
getId());
|
getId());
|
||||||
|
|
||||||
@ -46,7 +76,7 @@ namespace Deer {
|
|||||||
|
|
||||||
Entity& Entity::duplicate() {
|
Entity& Entity::duplicate() {
|
||||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||||
Entity& creation = m_environment->createEntity(
|
Entity& creation = environment->createEntity(
|
||||||
getComponent<TagComponent>().tag + "(d)");
|
getComponent<TagComponent>().tag + "(d)");
|
||||||
|
|
||||||
creation.setParent(getParent());
|
creation.setParent(getParent());
|
||||||
@ -55,12 +85,12 @@ namespace Deer {
|
|||||||
getComponent<TransformComponent>();
|
getComponent<TransformComponent>();
|
||||||
|
|
||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
if (m_environment->m_registry.any_of<MeshComponent>(
|
if (environment->m_registry->any_of<MeshComponent>(
|
||||||
m_entityHandle))
|
entHandle))
|
||||||
creation.addComponent<MeshComponent>(
|
creation.addComponent<MeshComponent>(
|
||||||
getComponent<MeshComponent>());
|
getComponent<MeshComponent>());
|
||||||
|
|
||||||
if (m_environment->m_registry.any_of<CameraComponent>(m_entityHandle))
|
if (environment->m_registry->any_of<CameraComponent>(entHandle))
|
||||||
creation.addComponent<CameraComponent>(
|
creation.addComponent<CameraComponent>(
|
||||||
getComponent<CameraComponent>());
|
getComponent<CameraComponent>());
|
||||||
#endif
|
#endif
|
||||||
@ -70,21 +100,28 @@ namespace Deer {
|
|||||||
void Entity::destroy() {
|
void Entity::destroy() {
|
||||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||||
DEER_CORE_ASSERT(!isRoot(), "Can not destroy the root");
|
DEER_CORE_ASSERT(!isRoot(), "Can not destroy the root");
|
||||||
m_environment->destroyEntity(getId());
|
environment->destroyEntity(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& Entity::getParent() const {
|
Entity& Entity::getParent() const {
|
||||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||||
return m_environment->getEntity(m_parentID);
|
return environment->getEntity(parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 Entity::getWorldMatrix() {
|
glm::mat4 Entity::getWorldMatrix() const {
|
||||||
if (isRoot()) return glm::mat4(1.0f);
|
if (isRoot()) return glm::mat4(1.0f);
|
||||||
|
|
||||||
return getParent().getWorldMatrix() * getRelativeMatrix();
|
return getParent().getWorldMatrix() * getRelativeMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 Entity::getRelativeMatrix() {
|
void Entity::clear() {
|
||||||
|
environment = nullptr;
|
||||||
|
entHandle = entt::null;
|
||||||
|
parentId = 0;
|
||||||
|
entId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Entity::getRelativeMatrix() const {
|
||||||
return getComponent<TransformComponent>().getMatrix();
|
return getComponent<TransformComponent>().getMatrix();
|
||||||
}
|
}
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
@ -9,86 +9,111 @@
|
|||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
Environment::Environment() {
|
Environment::Environment() {
|
||||||
entities = MakeScope<std::array<Entity, ENVIRONMENT_MAX_ENTITIES>>();
|
m_registry = MakeScope<entt::registry>();
|
||||||
clear();
|
createEntityWithId(0, "root");
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment::~Environment() {}
|
Environment::~Environment() {}
|
||||||
|
|
||||||
void Environment::clear() {
|
void Environment::clear() {
|
||||||
// Clear all existing entities and map
|
// Clear all existing entities and map
|
||||||
m_registry.clear();
|
m_registry->clear();
|
||||||
|
|
||||||
m_mainCamera = 0;
|
while (!unused_entities_spaces.empty()) {
|
||||||
m_idCreationOffset = 0;
|
unused_entities_spaces.pop();
|
||||||
m_maxIdValue = 0;
|
}
|
||||||
// We set it to one because we count root
|
entities.clear();
|
||||||
m_entityCount = 1;
|
|
||||||
|
|
||||||
createEntityWithId(0, "root");
|
createEntityWithId(0, "root");
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& Environment::getEntity(uint16_t id) const {
|
uint16_t Environment::getEntityCount() const {
|
||||||
|
return entities.size() - unused_entities_spaces.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity& Environment::getEntity(uint16_t id) {
|
||||||
DEER_CORE_ASSERT(entityExists(id), "Entity id {0} does not exist", id);
|
DEER_CORE_ASSERT(entityExists(id), "Entity id {0} does not exist", id);
|
||||||
Entity& refEntity = (*entities)[id];
|
return entities[id];
|
||||||
return refEntity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Environment::entityExists(uint16_t id) const {
|
bool Environment::entityExists(uint16_t id) const {
|
||||||
if (id < 0) return false;
|
if (id >= entities.size()) return false;
|
||||||
if (id > m_maxIdValue) return false;
|
const Entity& refEntity = entities[id];
|
||||||
if (id >= ENVIRONMENT_MAX_ENTITIES) return false;
|
|
||||||
Entity& refEntity = (*entities)[id];
|
|
||||||
return refEntity.isValid();
|
return refEntity.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& Environment::createEntity(const std::string& name) {
|
Entity& Environment::createEntity(const std::string& name) {
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
do {
|
|
||||||
id = pullEntityID();
|
|
||||||
DEER_CORE_ASSERT(id < ENVIRONMENT_MAX_ENTITIES,
|
|
||||||
"Fatal error, max number of entities exited");
|
|
||||||
} while (entityExists(id));
|
|
||||||
|
|
||||||
entt::entity entityID = m_registry.create();
|
entt::entity entityID = m_registry->create();
|
||||||
Entity& entity = (*entities)[id];
|
if (unused_entities_spaces.empty()) {
|
||||||
|
id = entities.size();
|
||||||
|
entities.push_back({});
|
||||||
|
} else {
|
||||||
|
id = unused_entities_spaces.top();
|
||||||
|
unused_entities_spaces.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity& entity = entities[id];
|
||||||
entity = {entityID, this, id};
|
entity = {entityID, this, id};
|
||||||
|
|
||||||
entity.addComponent<TagComponent>(name, id);
|
entity.addComponent<TagComponent>(name, id);
|
||||||
entity.addComponent<RelationshipComponent>();
|
entity.addComponent<RelationshipComponent>();
|
||||||
entity.addComponent<TransformComponent>();
|
entity.addComponent<TransformComponent>();
|
||||||
entity.m_exists = true;
|
|
||||||
|
|
||||||
m_entityCount++;
|
entity.parentId = 0;
|
||||||
entity.m_parentID = 0;
|
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(id)) {
|
||||||
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(
|
|
||||||
id)) {
|
|
||||||
DEER_CORE_ERROR("Root is full!");
|
DEER_CORE_ERROR("Root is full!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& Environment::createEntityWithId(uint16_t id,
|
Entity& Environment::createEntityWithId(uint16_t id, const std::string& name) {
|
||||||
const std::string& name) {
|
entt::entity entityID = m_registry->create();
|
||||||
// We want to initialize all entities that are not initialized to a
|
|
||||||
// default state of invalid
|
|
||||||
for (int i = m_maxIdValue + 1; i < id; i++) {
|
|
||||||
Entity& nullEntity = (*entities)[i];
|
|
||||||
nullEntity.m_exists = false;
|
|
||||||
}
|
|
||||||
if (m_maxIdValue < id) m_maxIdValue = id;
|
|
||||||
|
|
||||||
Entity& entity = (*entities)[id];
|
// We allocate all the memory until that id
|
||||||
entt::entity entityID = m_registry.create();
|
if (id >= entities.size()) {
|
||||||
entity = {entityID, this, id};
|
if (entities.capacity() <= id)
|
||||||
entity.m_exists = true;
|
entities.reserve(id + 1);
|
||||||
|
|
||||||
|
for (int i = entities.size(); i < id; i++) {
|
||||||
|
entities.push_back({});
|
||||||
|
unused_entities_spaces.push(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
entities.push_back({});
|
||||||
|
} else {
|
||||||
|
static std::stack<uint16_t> unused_entities_spaces_cache;
|
||||||
|
|
||||||
|
// This code its to remove a specific element from a stack
|
||||||
|
// We pop the stack until we find the id or we empty it to
|
||||||
|
// completly remove the target id and then we fill it again with the cache
|
||||||
|
while (!unused_entities_spaces.empty()) {
|
||||||
|
uint16_t topId = unused_entities_spaces.top();
|
||||||
|
unused_entities_spaces.pop();
|
||||||
|
|
||||||
|
if (topId == id)
|
||||||
|
break;
|
||||||
|
unused_entities_spaces_cache.push(topId);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!unused_entities_spaces_cache.empty()) {
|
||||||
|
uint16_t refillId = unused_entities_spaces_cache.top();
|
||||||
|
unused_entities_spaces_cache.pop();
|
||||||
|
|
||||||
|
unused_entities_spaces.push(refillId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity& entity = entities[id];
|
||||||
|
entt::entity _entityId = m_registry->create();
|
||||||
|
entity = {_entityId, this, id};
|
||||||
|
|
||||||
entity.addComponent<TagComponent>(name, id);
|
entity.addComponent<TagComponent>(name, id);
|
||||||
entity.addComponent<RelationshipComponent>();
|
entity.addComponent<RelationshipComponent>();
|
||||||
entity.addComponent<TransformComponent>();
|
entity.addComponent<TransformComponent>();
|
||||||
|
|
||||||
m_entityCount++;
|
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(
|
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(
|
||||||
id)) {
|
id)) {
|
||||||
@ -99,16 +124,13 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Environment::destroyEntity(uint16_t entityID) {
|
void Environment::destroyEntity(uint16_t entityID) {
|
||||||
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist",
|
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist", entityID);
|
||||||
entityID);
|
DEER_CORE_ASSERT(entityID != 0, "Cannot destroy root");
|
||||||
DEER_CORE_ASSERT(entityID != 0, "Can not destroy root");
|
|
||||||
|
|
||||||
Entity& entity = (*entities)[entityID];
|
Entity& entity = entities[entityID];
|
||||||
entity.getParent().getComponent<RelationshipComponent>().removeChildren(
|
entity.getParent().getComponent<RelationshipComponent>().removeChildren(entityID);
|
||||||
entityID);
|
|
||||||
|
|
||||||
RelationshipComponent& relationship =
|
RelationshipComponent& relationship = entity.getComponent<RelationshipComponent>();
|
||||||
entity.getComponent<RelationshipComponent>();
|
|
||||||
// We want to delete all childrens
|
// We want to delete all childrens
|
||||||
for (int i = 0; i < relationship.childCount; i++) {
|
for (int i = 0; i < relationship.childCount; i++) {
|
||||||
uint16_t childID = relationship.getChildrenId(i);
|
uint16_t childID = relationship.getChildrenId(i);
|
||||||
@ -116,14 +138,14 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_mainCamera == entityID) m_mainCamera = 0;
|
if (m_mainCamera == entityID) m_mainCamera = 0;
|
||||||
if (entityID <= m_idCreationOffset) m_idCreationOffset = entityID - 1;
|
|
||||||
|
|
||||||
m_registry.destroy(entity.m_entityHandle);
|
m_registry->destroy(entity.entHandle);
|
||||||
entity.m_exists = false;
|
entity.clear();
|
||||||
m_entityCount--;
|
|
||||||
|
unused_entities_spaces.push(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Environment::tryGetMainCamera() { return m_mainCamera; }
|
uint16_t Environment::tryGetMainCamera() const { return m_mainCamera; }
|
||||||
|
|
||||||
void Environment::setMainCamera(Entity& entity) {
|
void Environment::setMainCamera(Entity& entity) {
|
||||||
if (!entity.isValid()) m_mainCamera = 0;
|
if (!entity.isValid()) m_mainCamera = 0;
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
#include "Deer/Enviroment.h"
|
|
||||||
#include "Deer/Scene.h"
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace EnvironmentManager {
|
|
||||||
struct EnvironmentContainer {
|
|
||||||
Environment* env_data = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
EnvironmentContainer environments[MAX_ENVIRONMENT_COUNT]{};
|
|
||||||
uint16_t maxEnvironmentId = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t EnvironmentManager::createEnvironment() {
|
|
||||||
if (maxEnvironmentId >= MAX_ENVIRONMENT_COUNT) {
|
|
||||||
DEER_CORE_ERROR("Max environment count");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t envId = maxEnvironmentId;
|
|
||||||
maxEnvironmentId++;
|
|
||||||
|
|
||||||
environments[envId].env_data = new Environment();
|
|
||||||
return envId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Environment& EnvironmentManager::getEnvironment(uint16_t id) {
|
|
||||||
DEER_CORE_ASSERT(id >= 0 && id < MAX_ENVIRONMENT_COUNT, "Invalid environment id {0}", id);
|
|
||||||
|
|
||||||
if (id == 0)
|
|
||||||
return Scene::environment;
|
|
||||||
|
|
||||||
return *environments[id].env_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnvironmentManager::clearAllEnvironments() {
|
|
||||||
for (int i = 1; i < maxEnvironmentId; i++) {
|
|
||||||
delete environments[i].env_data;
|
|
||||||
environments[i].env_data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
environments[0].env_data = &Scene::environment;
|
|
||||||
maxEnvironmentId = 1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ namespace Deer {
|
|||||||
// Lets invert the z axis for engine convenience
|
// Lets invert the z axis for engine convenience
|
||||||
glm::mat4 cameraProjectionMatrix = projectionMatrix * invertZ * camMatrix;
|
glm::mat4 cameraProjectionMatrix = projectionMatrix * invertZ * camMatrix;
|
||||||
{
|
{
|
||||||
auto view = m_registry.view<MeshComponent, ShaderComponent, TagComponent>();
|
auto view = m_registry->view<MeshComponent, ShaderComponent, TagComponent>();
|
||||||
for (auto entityId : view) {
|
for (auto entityId : view) {
|
||||||
auto& meshComponent = view.get<MeshComponent>(entityId);
|
auto& meshComponent = view.get<MeshComponent>(entityId);
|
||||||
auto& shaderComponent = view.get<ShaderComponent>(entityId);
|
auto& shaderComponent = view.get<ShaderComponent>(entityId);
|
||||||
@ -75,7 +75,7 @@ namespace Deer {
|
|||||||
RenderUtils::m_lineShader->uploadUniformMat4("u_viewMatrix", cameraProjectionMatrix);
|
RenderUtils::m_lineShader->uploadUniformMat4("u_viewMatrix", cameraProjectionMatrix);
|
||||||
RenderUtils::m_lineShader->uploadUniformFloat3("u_color", glm::vec3(.7f, .85f, 1));
|
RenderUtils::m_lineShader->uploadUniformFloat3("u_color", glm::vec3(.7f, .85f, 1));
|
||||||
|
|
||||||
auto view = m_registry.view<CameraComponent, TagComponent>();
|
auto view = m_registry->view<CameraComponent, TagComponent>();
|
||||||
for (auto entityId : view) {
|
for (auto entityId : view) {
|
||||||
CameraComponent cameraComponent = view.get<CameraComponent>(entityId);
|
CameraComponent cameraComponent = view.get<CameraComponent>(entityId);
|
||||||
cameraComponent.nearZ = .5f;
|
cameraComponent.nearZ = .5f;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[Window][DockSpace Demo]
|
[Window][DockSpace Demo]
|
||||||
Pos=0,0
|
Pos=0,0
|
||||||
Size=1280,720
|
Size=2560,1371
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Debug##Default]
|
[Window][Debug##Default]
|
||||||
@ -9,53 +9,59 @@ Size=400,400
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Terrain Editor]
|
[Window][Terrain Editor]
|
||||||
Pos=854,24
|
Pos=2249,24
|
||||||
Size=426,454
|
Size=311,1128
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000006,0
|
DockId=0x00000006,0
|
||||||
|
|
||||||
[Window][Viewport]
|
[Window][Viewport]
|
||||||
Pos=361,24
|
Pos=299,24
|
||||||
Size=491,454
|
Size=668,477
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,0
|
DockId=0x00000005,0
|
||||||
|
|
||||||
[Window][ViewportPannel]
|
[Window][ViewportPannel]
|
||||||
Pos=361,24
|
Pos=312,24
|
||||||
Size=491,454
|
Size=1935,1128
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,1
|
DockId=0x00000005,0
|
||||||
|
|
||||||
[Window][ShaderExplorer]
|
[Window][ShaderExplorer]
|
||||||
Pos=0,480
|
Pos=0,1154
|
||||||
Size=1280,240
|
Size=2560,217
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000004,1
|
DockId=0x00000004,1
|
||||||
|
|
||||||
[Window][TreePannel]
|
[Window][TreePannel]
|
||||||
Pos=0,24
|
Pos=0,24
|
||||||
Size=359,454
|
Size=310,1128
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000001,0
|
DockId=0x00000001,0
|
||||||
|
|
||||||
[Window][MeshExplorer]
|
[Window][MeshExplorer]
|
||||||
Pos=0,480
|
Pos=0,1154
|
||||||
Size=1280,240
|
Size=2560,217
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000004,0
|
DockId=0x00000004,0
|
||||||
|
|
||||||
[Window][PropertiesPannel]
|
[Window][PropertiesPannel]
|
||||||
Pos=854,24
|
Pos=2249,24
|
||||||
Size=426,454
|
Size=311,1128
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000006,1
|
DockId=0x00000006,1
|
||||||
|
|
||||||
[Docking][Data]
|
[Window][CameraPannel]
|
||||||
DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y Selected=0x34A4C10F
|
Pos=312,24
|
||||||
DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,454 Split=X
|
Size=1935,1128
|
||||||
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=359,696 Selected=0xE45B9F93
|
Collapsed=0
|
||||||
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1380,696 Split=X Selected=0x34A4C10F
|
DockId=0x00000005,1
|
||||||
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=952,454 CentralNode=1 Selected=0x34A4C10F
|
|
||||||
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=426,454 Selected=0xA35A27E3
|
[Docking][Data]
|
||||||
DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,240 Selected=0xD962995A
|
DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=2560,1347 Split=Y Selected=0x34A4C10F
|
||||||
|
DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,477 Split=X
|
||||||
|
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=310,696 Selected=0xE45B9F93
|
||||||
|
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=2248,696 Split=X Selected=0x34A4C10F
|
||||||
|
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=1935,454 CentralNode=1 Selected=0x34A4C10F
|
||||||
|
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=311,454 Selected=0xA35A27E3
|
||||||
|
DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,217 Selected=0xD962995A
|
||||||
|
|
||||||
|
@ -98,13 +98,18 @@ namespace Deer {
|
|||||||
ImGuiID dockspace_id = ImGui::GetID("DockSpace Demo");
|
ImGuiID dockspace_id = ImGui::GetID("DockSpace Demo");
|
||||||
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
// MENUBAR
|
if (ImGui::BeginMenu("Pannel")) {
|
||||||
|
onPannelMenuBar();
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
}
|
}
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
TerrainEditor::onImGui();
|
TerrainEditor::onImGui();
|
||||||
viewport_onImGui();
|
//viewport_onImGui();
|
||||||
EditorEngine::render();
|
EditorEngine::render();
|
||||||
|
|
||||||
Scene::gizmoRenderer.refresh();
|
Scene::gizmoRenderer.refresh();
|
||||||
@ -112,7 +117,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onEvent(Event& e) {
|
void onEvent(Event& e) {
|
||||||
viewport_onEvent(e);
|
//viewport_onEvent(e);
|
||||||
|
|
||||||
EventDispatcher ed(e);
|
EventDispatcher ed(e);
|
||||||
|
|
||||||
|
@ -13,5 +13,8 @@ namespace Deer {
|
|||||||
void main();
|
void main();
|
||||||
|
|
||||||
bool onWindowCloseEvent(WindowCloseEvent&);
|
bool onWindowCloseEvent(WindowCloseEvent&);
|
||||||
|
|
||||||
|
// Other
|
||||||
|
void onPannelMenuBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
class asIScriptEngine;
|
class asIScriptEngine;
|
||||||
class asIScriptModule;
|
class asIScriptModule;
|
||||||
class asIScriptContext;
|
class asIScriptContext;
|
||||||
|
class CScriptBuilder;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
// This namespace implements all interface ported from c++ ImGui to an easier lua aproach with simplifications
|
// This namespace implements all interface ported from c++ ImGui to an easier lua aproach with simplifications
|
||||||
@ -16,9 +17,11 @@ namespace Deer {
|
|||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
// INTERNAL
|
||||||
extern asIScriptEngine* scriptEngine;
|
extern asIScriptEngine* scriptEngine;
|
||||||
extern asIScriptModule* scriptModule;
|
extern asIScriptModule* scriptModule;
|
||||||
extern asIScriptContext* scriptContext;
|
extern asIScriptContext* scriptContext;
|
||||||
|
extern CScriptBuilder builtContext;
|
||||||
extern std::vector<DockPanelObject> dockPanels;
|
extern std::vector<DockPanelObject> dockPanels;
|
||||||
extern DockPanelObject* currentDockPanelExecution;
|
extern DockPanelObject* currentDockPanelExecution;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "GenericRefStructs.h"
|
#include "GenericRefStructs.h"
|
||||||
#include "DeerRender/SceneCamera.h"
|
//#include "DeerRender/SceneCamera.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
class SceneCamera;
|
||||||
|
|
||||||
namespace EditorEngine {
|
namespace EditorEngine {
|
||||||
struct EnvironmentStruct : EnvironmentHandleStruct {
|
struct EnvironmentStruct : EnvironmentHandleStruct {
|
||||||
void render(FrameBufferHandleStruct, SceneCamera&);
|
void render(FrameBufferHandleStruct, SceneCamera&);
|
||||||
|
@ -7,10 +7,14 @@
|
|||||||
#include "Deer/Enviroment.h"
|
#include "Deer/Enviroment.h"
|
||||||
#include "Deer/Scene.h"
|
#include "Deer/Scene.h"
|
||||||
|
|
||||||
#define GET_ENTITY(id) Scene::environment.getEntity(id)
|
#include <vector>
|
||||||
#define GET_MESH_COMPONENT(id) Scene::environment.getEntity(id).getComponent<MeshComponent>()
|
|
||||||
#define GET_SHADER_COMPONENT(id) Scene::environment.getEntity(id).getComponent<ShaderComponent>()
|
#define GET_ENV(env) (*Deer::EditorEngine::environments[env])
|
||||||
#define GET_CAMERA_COMPONENT(id) Scene::environment.getEntity(id).getComponent<CameraComponent>()
|
|
||||||
|
#define GET_ENTITY(env, id) GET_ENV(env).getEntity(id)
|
||||||
|
#define GET_MESH_COMPONENT(env, id) GET_ENV(env).getEntity(id).getComponent<MeshComponent>()
|
||||||
|
#define GET_SHADER_COMPONENT(env, id) GET_ENV(env).getEntity(id).getComponent<ShaderComponent>()
|
||||||
|
#define GET_CAMERA_COMPONENT(env, id) GET_ENV(env).getEntity(id).getComponent<CameraComponent>()
|
||||||
|
|
||||||
#define ASSERT_ENTITY(func, ret) if (!assertEntity(func)) ret;
|
#define ASSERT_ENTITY(func, ret) if (!assertEntity(func)) ret;
|
||||||
#define ASSERT_MESH_COMPONENT(func, ret) if (!assertMeshComponent(func)) ret;
|
#define ASSERT_MESH_COMPONENT(func, ret) if (!assertMeshComponent(func)) ret;
|
||||||
@ -20,6 +24,8 @@
|
|||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace EditorEngine {
|
namespace EditorEngine {
|
||||||
|
extern std::vector <Scope<Environment>> environments;
|
||||||
|
|
||||||
EntityHandleStruct getRoot() {
|
EntityHandleStruct getRoot() {
|
||||||
return EntityStruct(0);
|
return EntityStruct(0);
|
||||||
}
|
}
|
||||||
@ -45,7 +51,7 @@ namespace Deer {
|
|||||||
std::string EntityStruct::getName() {
|
std::string EntityStruct::getName() {
|
||||||
ASSERT_ENTITY("getName()", return "NULL");
|
ASSERT_ENTITY("getName()", return "NULL");
|
||||||
|
|
||||||
return GET_ENTITY(entityId)
|
return GET_ENTITY(environmentId, entityId)
|
||||||
.getComponent<TagComponent>()
|
.getComponent<TagComponent>()
|
||||||
.tag;
|
.tag;
|
||||||
}
|
}
|
||||||
@ -54,7 +60,7 @@ namespace Deer {
|
|||||||
void EntityStruct::setName(std::string& name) {
|
void EntityStruct::setName(std::string& name) {
|
||||||
ASSERT_ENTITY("setName()", return);
|
ASSERT_ENTITY("setName()", return);
|
||||||
|
|
||||||
GET_ENTITY(entityId)
|
GET_ENTITY(environmentId, entityId)
|
||||||
.getComponent<TagComponent>()
|
.getComponent<TagComponent>()
|
||||||
.tag = name;
|
.tag = name;
|
||||||
}
|
}
|
||||||
@ -62,7 +68,7 @@ namespace Deer {
|
|||||||
void EntityStruct::destroy() {
|
void EntityStruct::destroy() {
|
||||||
ASSERT_ENTITY("destroy()", return);
|
ASSERT_ENTITY("destroy()", return);
|
||||||
|
|
||||||
GET_ENTITY(entityId)
|
GET_ENTITY(environmentId, entityId)
|
||||||
.destroy();
|
.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,16 +88,16 @@ namespace Deer {
|
|||||||
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
||||||
ASSERT_ENTITY("setParent()", return);
|
ASSERT_ENTITY("setParent()", return);
|
||||||
|
|
||||||
Entity& parent = GET_ENTITY(parent_struct.entityId);
|
Entity& parent = GET_ENTITY(parent_struct.environmentId, parent_struct.entityId);
|
||||||
|
|
||||||
GET_ENTITY(entityId)
|
GET_ENTITY(environmentId, entityId)
|
||||||
.setParent(parent);
|
.setParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityHandleStruct EntityStruct::getParent() {
|
EntityHandleStruct EntityStruct::getParent() {
|
||||||
ASSERT_ENTITY("getParent()", return *this);
|
ASSERT_ENTITY("getParent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
if (self.isRoot())
|
if (self.isRoot())
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
@ -101,9 +107,9 @@ namespace Deer {
|
|||||||
bool EntityStruct::isDescendantOf(EntityHandleStruct parent_struct) {
|
bool EntityStruct::isDescendantOf(EntityHandleStruct parent_struct) {
|
||||||
ASSERT_ENTITY("isDescendantOf()", return false);
|
ASSERT_ENTITY("isDescendantOf()", return false);
|
||||||
|
|
||||||
Entity& parent = GET_ENTITY(parent_struct.entityId);
|
Entity& parent = GET_ENTITY(parent_struct.environmentId, parent_struct.entityId);
|
||||||
|
|
||||||
return GET_ENTITY(entityId)
|
return GET_ENTITY(environmentId, entityId)
|
||||||
.isDescendantOf(parent);
|
.isDescendantOf(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,43 +128,43 @@ namespace Deer {
|
|||||||
glm::vec3 TransformComponentStruct::getPosition() {
|
glm::vec3 TransformComponentStruct::getPosition() {
|
||||||
ASSERT_ENTITY("getPosition()", return glm::vec3());
|
ASSERT_ENTITY("getPosition()", return glm::vec3());
|
||||||
|
|
||||||
return GET_ENTITY(entityId).getComponent<TransformComponent>().position;
|
return GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().position;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 TransformComponentStruct::getScale() {
|
glm::vec3 TransformComponentStruct::getScale() {
|
||||||
ASSERT_ENTITY("getScale()", return glm::vec3());
|
ASSERT_ENTITY("getScale()", return glm::vec3());
|
||||||
|
|
||||||
return GET_ENTITY(entityId).getComponent<TransformComponent>().scale;
|
return GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 TransformComponentStruct::getRotation() {
|
glm::vec3 TransformComponentStruct::getRotation() {
|
||||||
ASSERT_ENTITY("getRotation()", return glm::vec3());
|
ASSERT_ENTITY("getRotation()", return glm::vec3());
|
||||||
|
|
||||||
return GET_ENTITY(entityId).getComponent<TransformComponent>().getEulerAngles();
|
return GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().getEulerAngles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformComponentStruct::setPosition(glm::vec3 value) {
|
void TransformComponentStruct::setPosition(glm::vec3 value) {
|
||||||
ASSERT_ENTITY("setPosition()", return);
|
ASSERT_ENTITY("setPosition()", return);
|
||||||
|
|
||||||
GET_ENTITY(entityId).getComponent<TransformComponent>().position = value;
|
GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().position = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformComponentStruct::setScale(glm::vec3 value) {
|
void TransformComponentStruct::setScale(glm::vec3 value) {
|
||||||
ASSERT_ENTITY("setScale()", return);
|
ASSERT_ENTITY("setScale()", return);
|
||||||
|
|
||||||
GET_ENTITY(entityId).getComponent<TransformComponent>().scale = value;
|
GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().scale = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformComponentStruct::setRotation(glm::vec3 value) {
|
void TransformComponentStruct::setRotation(glm::vec3 value) {
|
||||||
ASSERT_ENTITY("setRotation()", return);
|
ASSERT_ENTITY("setRotation()", return);
|
||||||
|
|
||||||
GET_ENTITY(entityId).getComponent<TransformComponent>().setEulerAngles(value);
|
GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().setEulerAngles(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EntityChildArrayStruct::getChildCount() {
|
int EntityChildArrayStruct::getChildCount() {
|
||||||
ASSERT_ENTITY("getChildCount()", return 0);
|
ASSERT_ENTITY("getChildCount()", return 0);
|
||||||
|
|
||||||
return GET_ENTITY(entityId)
|
return GET_ENTITY(environmentId, entityId)
|
||||||
.getComponent<RelationshipComponent>()
|
.getComponent<RelationshipComponent>()
|
||||||
.childCount;
|
.childCount;
|
||||||
}
|
}
|
||||||
@ -185,7 +191,7 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityChildArrayStruct::getChild(int i) {
|
EntityHandleStruct EntityChildArrayStruct::getChild(int i) {
|
||||||
ASSERT_ENTITY("getChild()", return *this);
|
ASSERT_ENTITY("getChild()", return *this);
|
||||||
|
|
||||||
RelationshipComponent& rc = GET_ENTITY(entityId)
|
RelationshipComponent& rc = GET_ENTITY(environmentId, entityId)
|
||||||
.getComponent<RelationshipComponent>();
|
.getComponent<RelationshipComponent>();
|
||||||
|
|
||||||
if (i < 0 || i >= rc.childCount) {
|
if (i < 0 || i >= rc.childCount) {
|
||||||
@ -202,10 +208,8 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::createChild(std::string& name) {
|
EntityHandleStruct EntityStruct::createChild(std::string& name) {
|
||||||
ASSERT_ENTITY("createChild()", return *this);
|
ASSERT_ENTITY("createChild()", return *this);
|
||||||
|
|
||||||
Entity& me = GET_ENTITY(entityId);
|
Entity& newEnt = Scene::environment.createEntity(name);
|
||||||
|
Entity& me = GET_ENTITY(environmentId, entityId);
|
||||||
Entity& newEnt = Scene::environment
|
|
||||||
.createEntity(name);
|
|
||||||
|
|
||||||
newEnt.setParent(me);
|
newEnt.setParent(me);
|
||||||
|
|
||||||
@ -215,11 +219,11 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::getMeshComponent() {
|
EntityHandleStruct EntityStruct::getMeshComponent() {
|
||||||
ASSERT_ENTITY("getMeshComponent()", return *this);
|
ASSERT_ENTITY("getMeshComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<MeshComponent>()) {
|
if (!self.hasComponent<MeshComponent>()) {
|
||||||
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have MeshComponent",
|
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have MeshComponent",
|
||||||
GET_ENTITY(entityId).getComponent<TagComponent>().tag.c_str(),
|
GET_ENTITY(environmentId, entityId).getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId
|
entityId
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -233,7 +237,7 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::createMeshComponent() {
|
EntityHandleStruct EntityStruct::createMeshComponent() {
|
||||||
ASSERT_ENTITY("createMeshComponent()", return *this);
|
ASSERT_ENTITY("createMeshComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<MeshComponent>()) {
|
if (!self.hasComponent<MeshComponent>()) {
|
||||||
self.addComponent<MeshComponent>();
|
self.addComponent<MeshComponent>();
|
||||||
@ -245,7 +249,7 @@ namespace Deer {
|
|||||||
bool EntityStruct::hasMeshComponent() {
|
bool EntityStruct::hasMeshComponent() {
|
||||||
ASSERT_ENTITY("hasMeshComponent()", return false);
|
ASSERT_ENTITY("hasMeshComponent()", return false);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
return self.hasComponent<MeshComponent>();
|
return self.hasComponent<MeshComponent>();
|
||||||
}
|
}
|
||||||
@ -253,7 +257,7 @@ namespace Deer {
|
|||||||
void EntityStruct::removeMeshComponent() {
|
void EntityStruct::removeMeshComponent() {
|
||||||
ASSERT_ENTITY("removeMeshComponent()", return);
|
ASSERT_ENTITY("removeMeshComponent()", return);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (self.hasComponent<MeshComponent>()) {
|
if (self.hasComponent<MeshComponent>()) {
|
||||||
self.removeComponent<MeshComponent>();
|
self.removeComponent<MeshComponent>();
|
||||||
@ -263,11 +267,11 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::getCameraComponent() {
|
EntityHandleStruct EntityStruct::getCameraComponent() {
|
||||||
ASSERT_ENTITY("getCameraComponent()", return *this);
|
ASSERT_ENTITY("getCameraComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<CameraComponent>()) {
|
if (!self.hasComponent<CameraComponent>()) {
|
||||||
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have Camera Component",
|
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have Camera Component",
|
||||||
GET_ENTITY(entityId).getComponent<TagComponent>().tag.c_str(),
|
GET_ENTITY(environmentId, entityId).getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId
|
entityId
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -281,7 +285,7 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::createCameraComponent() {
|
EntityHandleStruct EntityStruct::createCameraComponent() {
|
||||||
ASSERT_ENTITY("createCameraComponent()", return *this);
|
ASSERT_ENTITY("createCameraComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<CameraComponent>()) {
|
if (!self.hasComponent<CameraComponent>()) {
|
||||||
self.addComponent<CameraComponent>();
|
self.addComponent<CameraComponent>();
|
||||||
@ -293,7 +297,7 @@ namespace Deer {
|
|||||||
bool EntityStruct::hasCameraComponent() {
|
bool EntityStruct::hasCameraComponent() {
|
||||||
ASSERT_ENTITY("hasCameraComponent()", return false);
|
ASSERT_ENTITY("hasCameraComponent()", return false);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
return self.hasComponent<CameraComponent>();
|
return self.hasComponent<CameraComponent>();
|
||||||
}
|
}
|
||||||
@ -301,7 +305,7 @@ namespace Deer {
|
|||||||
void EntityStruct::removeCameraComponent() {
|
void EntityStruct::removeCameraComponent() {
|
||||||
ASSERT_ENTITY("removeMeshComponent()", return);
|
ASSERT_ENTITY("removeMeshComponent()", return);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (self.hasComponent<CameraComponent>()) {
|
if (self.hasComponent<CameraComponent>()) {
|
||||||
self.removeComponent<CameraComponent>();
|
self.removeComponent<CameraComponent>();
|
||||||
@ -311,11 +315,11 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::getShaderComponent() {
|
EntityHandleStruct EntityStruct::getShaderComponent() {
|
||||||
ASSERT_ENTITY("getShaderComponent()", return *this);
|
ASSERT_ENTITY("getShaderComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<ShaderComponent>()) {
|
if (!self.hasComponent<ShaderComponent>()) {
|
||||||
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have Shader Component",
|
DEER_CORE_ERROR("Error, entity {0} with id {1} does not have Shader Component",
|
||||||
GET_ENTITY(entityId).getComponent<TagComponent>().tag.c_str(),
|
GET_ENTITY(environmentId, entityId).getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId
|
entityId
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -329,7 +333,7 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::createShaderComponent() {
|
EntityHandleStruct EntityStruct::createShaderComponent() {
|
||||||
ASSERT_ENTITY("createShaderComponent()", return *this);
|
ASSERT_ENTITY("createShaderComponent()", return *this);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (!self.hasComponent<ShaderComponent>()) {
|
if (!self.hasComponent<ShaderComponent>()) {
|
||||||
self.addComponent<ShaderComponent>();
|
self.addComponent<ShaderComponent>();
|
||||||
@ -341,14 +345,14 @@ namespace Deer {
|
|||||||
bool EntityStruct::hasShaderComponent() {
|
bool EntityStruct::hasShaderComponent() {
|
||||||
ASSERT_ENTITY("hasShaderComponent()", return false);
|
ASSERT_ENTITY("hasShaderComponent()", return false);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
return self.hasComponent<ShaderComponent>();
|
return self.hasComponent<ShaderComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityStruct::removeShaderComponent() {
|
void EntityStruct::removeShaderComponent() {
|
||||||
ASSERT_ENTITY("removeShaderComponent()", return);
|
ASSERT_ENTITY("removeShaderComponent()", return);
|
||||||
|
|
||||||
Entity& self = GET_ENTITY(entityId);
|
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||||
|
|
||||||
if (self.hasComponent<ShaderComponent>()) {
|
if (self.hasComponent<ShaderComponent>()) {
|
||||||
self.removeComponent<ShaderComponent>();
|
self.removeComponent<ShaderComponent>();
|
||||||
@ -357,44 +361,44 @@ namespace Deer {
|
|||||||
|
|
||||||
bool MeshComponentStruct::isActive() {
|
bool MeshComponentStruct::isActive() {
|
||||||
ASSERT_MESH_COMPONENT("isActive()", return false);
|
ASSERT_MESH_COMPONENT("isActive()", return false);
|
||||||
return GET_MESH_COMPONENT(entityId).isActive();
|
return GET_MESH_COMPONENT(environmentId, entityId).isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshComponentStruct::setActive(bool value) {
|
void MeshComponentStruct::setActive(bool value) {
|
||||||
ASSERT_MESH_COMPONENT("setActive(bool)", return);
|
ASSERT_MESH_COMPONENT("setActive(bool)", return);
|
||||||
|
|
||||||
GET_MESH_COMPONENT(entityId).setActive(value);
|
GET_MESH_COMPONENT(environmentId, entityId).setActive(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeshComponentStruct::hasMesh() {
|
bool MeshComponentStruct::hasMesh() {
|
||||||
ASSERT_MESH_COMPONENT("hasMesh()", return false);
|
ASSERT_MESH_COMPONENT("hasMesh()", return false);
|
||||||
|
|
||||||
return GET_MESH_COMPONENT(entityId).hasMesh();
|
return GET_MESH_COMPONENT(environmentId, entityId).hasMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshComponentStruct::clear() {
|
void MeshComponentStruct::clear() {
|
||||||
ASSERT_MESH_COMPONENT("clear()", return);
|
ASSERT_MESH_COMPONENT("clear()", return);
|
||||||
|
|
||||||
GET_MESH_COMPONENT(entityId).clear();
|
GET_MESH_COMPONENT(environmentId, entityId).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MeshComponentStruct::getMesh() {
|
std::string MeshComponentStruct::getMesh() {
|
||||||
ASSERT_MESH_COMPONENT("getMesh()", return "NULL");
|
ASSERT_MESH_COMPONENT("getMesh()", return "NULL");
|
||||||
|
|
||||||
return GET_MESH_COMPONENT(entityId).getMeshName();
|
return GET_MESH_COMPONENT(environmentId, entityId).getMeshName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshComponentStruct::setMesh(std::string& name) {
|
void MeshComponentStruct::setMesh(std::string& name) {
|
||||||
ASSERT_MESH_COMPONENT("setMesh()", return);
|
ASSERT_MESH_COMPONENT("setMesh()", return);
|
||||||
|
|
||||||
uint16_t meshId = MeshManager::loadModel(name);
|
uint16_t meshId = MeshManager::loadModel(name);
|
||||||
GET_MESH_COMPONENT(entityId).setMesh(meshId);
|
GET_MESH_COMPONENT(environmentId, entityId).setMesh(meshId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderComponentStruct::hasShader() {
|
bool ShaderComponentStruct::hasShader() {
|
||||||
ASSERT_ENTITY("hasShader()", return false);
|
ASSERT_ENTITY("hasShader()", return false);
|
||||||
|
|
||||||
return GET_SHADER_COMPONENT(entityId).hasShader();
|
return GET_SHADER_COMPONENT(environmentId, entityId).hasShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
|
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
|
||||||
@ -419,20 +423,20 @@ namespace Deer {
|
|||||||
void ShaderComponentStruct::clear() {
|
void ShaderComponentStruct::clear() {
|
||||||
ASSERT_SHADER_COMPONENT("clear()", return);
|
ASSERT_SHADER_COMPONENT("clear()", return);
|
||||||
|
|
||||||
GET_SHADER_COMPONENT(entityId).clear();
|
GET_SHADER_COMPONENT(environmentId, entityId).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderComponentStruct::getShader() {
|
std::string ShaderComponentStruct::getShader() {
|
||||||
ASSERT_SHADER_COMPONENT("getShader()", return "NULL");
|
ASSERT_SHADER_COMPONENT("getShader()", return "NULL");
|
||||||
|
|
||||||
return GET_SHADER_COMPONENT(entityId).getName();
|
return GET_SHADER_COMPONENT(environmentId, entityId).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderComponentStruct::setShader(std::string& name) {
|
void ShaderComponentStruct::setShader(std::string& name) {
|
||||||
ASSERT_SHADER_COMPONENT("getShader()", return);
|
ASSERT_SHADER_COMPONENT("getShader()", return);
|
||||||
|
|
||||||
uint16_t shaderId = ShaderManager::loadShader(name);
|
uint16_t shaderId = ShaderManager::loadShader(name);
|
||||||
GET_SHADER_COMPONENT(entityId).setShader(shaderId);
|
GET_SHADER_COMPONENT(environmentId, entityId).setShader(shaderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -458,46 +462,46 @@ namespace Deer {
|
|||||||
float CameraComponentStruct::getFov() {
|
float CameraComponentStruct::getFov() {
|
||||||
ASSERT_CAMERA_COMPONENT("getFov()", return 0);
|
ASSERT_CAMERA_COMPONENT("getFov()", return 0);
|
||||||
|
|
||||||
return GET_CAMERA_COMPONENT(entityId).fov / 3.141f * 180.0f;
|
return GET_CAMERA_COMPONENT(environmentId, entityId).fov / 3.141f * 180.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CameraComponentStruct::getAspectRation() {
|
float CameraComponentStruct::getAspectRation() {
|
||||||
ASSERT_CAMERA_COMPONENT("getAspectRation()", return 0);
|
ASSERT_CAMERA_COMPONENT("getAspectRation()", return 0);
|
||||||
|
|
||||||
return GET_CAMERA_COMPONENT(entityId).aspect;
|
return GET_CAMERA_COMPONENT(environmentId, entityId).aspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CameraComponentStruct::getNearZ() {
|
float CameraComponentStruct::getNearZ() {
|
||||||
ASSERT_CAMERA_COMPONENT("getNearZ()", return 0);
|
ASSERT_CAMERA_COMPONENT("getNearZ()", return 0);
|
||||||
|
|
||||||
return GET_CAMERA_COMPONENT(entityId).nearZ;
|
return GET_CAMERA_COMPONENT(environmentId, entityId).nearZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CameraComponentStruct::getFarZ() {
|
float CameraComponentStruct::getFarZ() {
|
||||||
ASSERT_CAMERA_COMPONENT("getFarZ()", return 0);
|
ASSERT_CAMERA_COMPONENT("getFarZ()", return 0);
|
||||||
|
|
||||||
return GET_CAMERA_COMPONENT(entityId).farZ;
|
return GET_CAMERA_COMPONENT(environmentId, entityId).farZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraComponentStruct::setFov(float v) {
|
void CameraComponentStruct::setFov(float v) {
|
||||||
ASSERT_CAMERA_COMPONENT("getFarZ()", return);
|
ASSERT_CAMERA_COMPONENT("getFarZ()", return);
|
||||||
|
|
||||||
GET_CAMERA_COMPONENT(entityId).fov = v * 3.141f / 180.0f;
|
GET_CAMERA_COMPONENT(environmentId, entityId).fov = v * 3.141f / 180.0f;
|
||||||
}
|
}
|
||||||
void CameraComponentStruct::setAspectRation(float v) {
|
void CameraComponentStruct::setAspectRation(float v) {
|
||||||
ASSERT_CAMERA_COMPONENT("setAspectRation()", return);
|
ASSERT_CAMERA_COMPONENT("setAspectRation()", return);
|
||||||
|
|
||||||
GET_CAMERA_COMPONENT(entityId).aspect = v;
|
GET_CAMERA_COMPONENT(environmentId, entityId).aspect = v;
|
||||||
}
|
}
|
||||||
void CameraComponentStruct::setNearZ(float v) {
|
void CameraComponentStruct::setNearZ(float v) {
|
||||||
ASSERT_CAMERA_COMPONENT("setNearZ()", return);
|
ASSERT_CAMERA_COMPONENT("setNearZ()", return);
|
||||||
|
|
||||||
GET_CAMERA_COMPONENT(entityId).nearZ = v;
|
GET_CAMERA_COMPONENT(environmentId, entityId).nearZ = v;
|
||||||
}
|
}
|
||||||
void CameraComponentStruct::setFarZ(float v) {
|
void CameraComponentStruct::setFarZ(float v) {
|
||||||
ASSERT_CAMERA_COMPONENT("setFarZ()", return);
|
ASSERT_CAMERA_COMPONENT("setFarZ()", return);
|
||||||
|
|
||||||
GET_CAMERA_COMPONENT(entityId).farZ = v;
|
GET_CAMERA_COMPONENT(environmentId, entityId).farZ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
#include "DeerStudio/EditorEngine/API/Environment.h"
|
|
||||||
#include "Deer/Enviroment.h"
|
#include "Deer/Enviroment.h"
|
||||||
|
#include "Deer/Scene.h"
|
||||||
|
#include "Deer/Memory.h"
|
||||||
|
|
||||||
|
#include "DeerStudio/EditorEngine/API/Environment.h"
|
||||||
|
|
||||||
#include "DeerRender/FrameBuffer.h"
|
#include "DeerRender/FrameBuffer.h"
|
||||||
#include "DeerRender/SceneCamera.h"
|
#include "DeerRender/SceneCamera.h"
|
||||||
#include "Deer/Scene.h"
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace EditorEngine {
|
namespace EditorEngine {
|
||||||
|
// The first element has to allways point to the main scene env
|
||||||
|
std::vector <Environment*> environments { &Scene::environment };
|
||||||
|
|
||||||
void EnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, SceneCamera& sc) {
|
void EnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, SceneCamera& sc) {
|
||||||
FrameBuffer& frameBuffer = FrameBufferManager::getFrameBuffer(frameBuffer_handle.frameBufferId);
|
FrameBuffer& frameBuffer = FrameBufferManager::getFrameBuffer(frameBuffer_handle.frameBufferId);
|
||||||
Environment& env = EnvironmentManager::getEnvironment(environmentId);
|
Environment& env = *environments[environmentId];
|
||||||
|
|
||||||
frameBuffer.bind();
|
frameBuffer.bind();
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
Scene::render(sc);
|
env.render(sc);
|
||||||
//env.render(sceneCamera);
|
|
||||||
|
|
||||||
frameBuffer.unbind();
|
frameBuffer.unbind();
|
||||||
}
|
}
|
||||||
@ -32,7 +39,10 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EnvironmentHandleStruct createEnvironment() {
|
EnvironmentHandleStruct createEnvironment() {
|
||||||
return EnvironmentHandleStruct(EnvironmentManager::createEnvironment());
|
uint16_t envId = environments.size();
|
||||||
|
environments.push_back({});
|
||||||
|
|
||||||
|
return EnvironmentHandleStruct(envId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -52,6 +52,10 @@ namespace Deer {
|
|||||||
isValid = true;
|
isValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* EditorEngine::DockPanelObject::getName() {
|
||||||
|
return type->GetName();
|
||||||
|
}
|
||||||
|
|
||||||
EditorEngine::DockPanelObject::~DockPanelObject() {
|
EditorEngine::DockPanelObject::~DockPanelObject() {
|
||||||
if (object)
|
if (object)
|
||||||
object->Release();
|
object->Release();
|
||||||
|
@ -27,10 +27,13 @@ namespace Deer {
|
|||||||
DockPanelObject& operator=(DockPanelObject&& other) noexcept;
|
DockPanelObject& operator=(DockPanelObject&& other) noexcept;
|
||||||
|
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
void executeRender();
|
void executeRender();
|
||||||
void invalidate();
|
void invalidate();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
const char* getName();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,14 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
namespace EditorEngine {
|
||||||
|
CScriptBuilder builtContext;
|
||||||
|
}
|
||||||
|
|
||||||
void EditorEngine::loadScripts() {
|
void EditorEngine::loadScripts() {
|
||||||
Path path = DataStore::rootPath / DEER_EDITOR_PATH;
|
Path path = DataStore::rootPath / DEER_EDITOR_PATH;
|
||||||
CScriptBuilder builder;
|
|
||||||
|
|
||||||
AS_RET_CHECK(builder.StartNewModule(scriptEngine, "DeerModule"));
|
AS_RET_CHECK(builtContext.StartNewModule(scriptEngine, "DeerModule"));
|
||||||
|
|
||||||
DEER_CORE_TRACE("Extracting UI Engine Scripts ");
|
DEER_CORE_TRACE("Extracting UI Engine Scripts ");
|
||||||
for (const auto& entry : fs::recursive_directory_iterator(path)) {
|
for (const auto& entry : fs::recursive_directory_iterator(path)) {
|
||||||
@ -27,12 +30,12 @@ namespace Deer {
|
|||||||
//DEER_UI_ENGINE_TRACE("\t{0}", entry.path().stem().string().c_str());
|
//DEER_UI_ENGINE_TRACE("\t{0}", entry.path().stem().string().c_str());
|
||||||
// We add aditional info to check who caused the error
|
// We add aditional info to check who caused the error
|
||||||
AS_CHECK_ADDITIONAL_INFO(
|
AS_CHECK_ADDITIONAL_INFO(
|
||||||
builder.AddSectionFromFile(entry.path().string().c_str());,
|
builtContext.AddSectionFromFile(entry.path().string().c_str());,
|
||||||
entry.path().string().c_str()
|
entry.path().string().c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AS_RET_CHECK(builder.BuildModule());
|
AS_RET_CHECK(builtContext.BuildModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
20
DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp
Normal file
20
DeerStudio/src/DeerStudio/PannelMenuBarManagment.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "DeerStudio/DeerStudio.h"
|
||||||
|
#include "DeerStudio/EditorEngine.h"
|
||||||
|
#include "DeerStudio/EditorEngine/DockPanelObject.h"
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace DeerStudio {
|
||||||
|
void onPannelMenuBar() {
|
||||||
|
if (ImGui::BeginMenu("Show/Hide")) {
|
||||||
|
for (EditorEngine::DockPanelObject& pannel : EditorEngine::dockPanels) {
|
||||||
|
const char* name = pannel.getName();
|
||||||
|
|
||||||
|
ImGui::MenuItem(name, nullptr, &pannel.enabled);
|
||||||
|
}
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ void printFuncList(const asIScriptEngine& engine) {
|
|||||||
|
|
||||||
asIScriptFunction* f = t->GetFuncdefSignature();
|
asIScriptFunction* f = t->GetFuncdefSignature();
|
||||||
|
|
||||||
stream << "funcdef "<< f->GetDeclaration(false, false, true) << ";\n";
|
stream << "funcdef "<< f->GetDeclaration(true, false, true) << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
roe/Editor/CameraViewport/CameraPannel.as
Normal file
30
roe/Editor/CameraViewport/CameraPannel.as
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
class CameraPannel : DockPanel {
|
||||||
|
FrameBuffer frameBuffer;
|
||||||
|
Environment mainEnv;
|
||||||
|
|
||||||
|
void onRender() {
|
||||||
|
if (!frameBuffer.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int x = UI::getAvailableSizeX();
|
||||||
|
int y = UI::getAvailableSizeY();
|
||||||
|
|
||||||
|
if (x < 10 || y < 10)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frameBuffer.resize(x, y);
|
||||||
|
frameBuffer.clearRGBA(0, 0, 0, 255);
|
||||||
|
|
||||||
|
UI::drawFrameBufferCentered(frameBuffer, x, y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void onInit() {
|
||||||
|
frameBuffer = Engine::createRGBA8FrameBuffer("MainFrameBuffer", 400, 400);
|
||||||
|
mainEnv = Engine::getMainEnvironment();
|
||||||
|
|
||||||
|
UI::disablePannelPadding(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,9 @@ class PropertiesPannel : DockPanel {
|
|||||||
void onRender() {
|
void onRender() {
|
||||||
Entity entity = activeEntity;
|
Entity entity = activeEntity;
|
||||||
|
|
||||||
|
// We don't want to change root options
|
||||||
|
if (entity.isRoot)
|
||||||
|
return;
|
||||||
// NAME
|
// NAME
|
||||||
// -------
|
// -------
|
||||||
// Id:0 [+ add component]
|
// Id:0 [+ add component]
|
||||||
@ -16,9 +19,6 @@ class PropertiesPannel : DockPanel {
|
|||||||
UI::separator();
|
UI::separator();
|
||||||
UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id);
|
UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id);
|
||||||
|
|
||||||
// We don't want to change root options
|
|
||||||
if (entity.isRoot)
|
|
||||||
return;
|
|
||||||
|
|
||||||
UI::sameline();
|
UI::sameline();
|
||||||
if (UI::buttonEnd("Add Component")) {
|
if (UI::buttonEnd("Add Component")) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//This file was generated automatically
|
//This file was generated automatically
|
||||||
funcdef bool less(const T&in a, const T&in b);
|
funcdef bool T[]::less(const T&in a, const T&in b);
|
||||||
funcdef void ReciverFunc(any@);
|
funcdef void ReciverFunc(any@);
|
||||||
funcdef void TransferFunc(any@, any@);
|
funcdef void TransferFunc(any@, any@);
|
||||||
enum key {
|
enum key {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user