Improved Environment and Entity managment
This commit is contained in:
parent
ea8420f0d8
commit
88ba321f68
@ -1,13 +1,8 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Deer/Components.h"
|
||||
#include "Deer/Log.h"
|
||||
#include "Deer/Memory.h"
|
||||
|
||||
#include "entt/entt.hpp"
|
||||
|
||||
#ifdef DEER_RENDER
|
||||
@ -15,13 +10,18 @@
|
||||
#include "DeerRender/SceneCamera.h"
|
||||
#endif
|
||||
|
||||
#define ENVIRONMENT_MAX_ENTITIES 2048
|
||||
#define MAX_ENVIRONMENT_COUNT 64
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
|
||||
namespace Deer {
|
||||
class Entity;
|
||||
|
||||
class Environment {
|
||||
// Note: Outdated note
|
||||
///////// NOTES ///////////
|
||||
// - 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
|
||||
@ -39,22 +39,25 @@ namespace Deer {
|
||||
|
||||
// Clears all entities
|
||||
void clear();
|
||||
|
||||
// Obtains the entity
|
||||
Entity& getEntity(uint16_t id) const;
|
||||
Entity& getEntity(uint16_t id);
|
||||
bool entityExists(uint16_t id) const;
|
||||
uint16_t getEntityCount() const { return m_entityCount; }
|
||||
uint16_t getEntityCount() const;
|
||||
|
||||
// Creates a entity child at root
|
||||
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||
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 = "");
|
||||
void destroyEntity(uint16_t id);
|
||||
|
||||
// Special behaviour
|
||||
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||
Entity createEmptyEntity();
|
||||
|
||||
// FEO
|
||||
uint16_t tryGetMainCamera();
|
||||
uint16_t tryGetMainCamera() const;
|
||||
void setMainCamera(Entity& entity);
|
||||
|
||||
// Obtains the entity that is on the root of the environment
|
||||
@ -62,112 +65,89 @@ namespace Deer {
|
||||
#ifdef DEER_RENDER
|
||||
void render(SceneCamera& camera);
|
||||
#endif
|
||||
entt::registry m_registry;
|
||||
Scope<entt::registry> m_registry;
|
||||
|
||||
private:
|
||||
private:
|
||||
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() {
|
||||
m_idCreationOffset++;
|
||||
if (m_idCreationOffset > m_maxIdValue)
|
||||
m_maxIdValue = m_idCreationOffset;
|
||||
return m_idCreationOffset;
|
||||
}
|
||||
|
||||
std::stack<u_int16_t> unused_entities_spaces;
|
||||
std::vector<Entity> entities;
|
||||
|
||||
friend class Entity;
|
||||
};
|
||||
|
||||
// Warning: This calss does not initialize for performance
|
||||
class Entity {
|
||||
public:
|
||||
// This class can not be copied
|
||||
Entity(const Entity&) = delete;
|
||||
public:
|
||||
Entity() {}
|
||||
Entity(const Entity&) = delete;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T& addComponent(Args&&... args) const {
|
||||
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(Entity&&) noexcept;
|
||||
Entity& operator=(Entity&&) noexcept;
|
||||
|
||||
Entity& duplicate();
|
||||
void destroy();
|
||||
|
||||
uint16_t getId() const { return m_entityID; }
|
||||
uint16_t getId() const { return entId; }
|
||||
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
|
||||
void setParent(Entity& parent);
|
||||
bool isDescendantOf(Entity& parent) const;
|
||||
|
||||
Environment* getEnvironment() const { return m_environment; }
|
||||
Environment* getEnvironment() const { return environment; }
|
||||
|
||||
bool isRoot() const { return m_entityID == 0; }
|
||||
glm::mat4 getWorldMatrix();
|
||||
glm::mat4 getRelativeMatrix();
|
||||
bool isRoot() const { return entId == 0; }
|
||||
glm::mat4 getWorldMatrix() const;
|
||||
glm::mat4 getRelativeMatrix() const;
|
||||
|
||||
void tickExecution();
|
||||
void clear();
|
||||
|
||||
inline bool isValid() const { return m_exists; }
|
||||
|
||||
private:
|
||||
Environment* m_environment = nullptr;
|
||||
entt::entity m_entityHandle = entt::null;
|
||||
uint16_t m_entityID = 0;
|
||||
uint16_t m_parentID = 0;
|
||||
bool m_exists = false;
|
||||
bool isValid() const;
|
||||
private:
|
||||
Environment* environment = nullptr;
|
||||
entt::entity entHandle = entt::null;
|
||||
uint16_t entId = 0;
|
||||
uint16_t parentId = 0;
|
||||
|
||||
Entity(entt::entity handle, Environment* scene, uint16_t entityID);
|
||||
|
||||
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
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "glm/gtc/quaternion.hpp"
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
|
||||
#define MAX_TEXTURE_BINDINGS 4
|
||||
|
||||
namespace Deer {
|
||||
|
@ -1,16 +1,46 @@
|
||||
#include "Deer/Components.h"
|
||||
#include "Deer/Enviroment.h"
|
||||
#include "Deer/Log.h"
|
||||
|
||||
namespace Deer {
|
||||
Entity::Entity(entt::entity handle, Environment* scene, uint16_t entityID)
|
||||
: m_entityHandle(handle),
|
||||
m_environment(scene),
|
||||
m_entityID(entityID),
|
||||
m_exists(true) {}
|
||||
: entHandle(handle),
|
||||
environment(scene),
|
||||
entId(entityID) { }
|
||||
|
||||
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) {
|
||||
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");
|
||||
DEER_CORE_ASSERT(parent.isValid(), "Parent is not valid");
|
||||
if (parent.getId() == getId()) return;
|
||||
@ -29,7 +59,7 @@ namespace Deer {
|
||||
return;
|
||||
}
|
||||
|
||||
m_parentID = parent.getId();
|
||||
parentId = parent.getId();
|
||||
current_parent.getComponent<RelationshipComponent>().removeChildren(
|
||||
getId());
|
||||
|
||||
@ -46,7 +76,7 @@ namespace Deer {
|
||||
|
||||
Entity& Entity::duplicate() {
|
||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||
Entity& creation = m_environment->createEntity(
|
||||
Entity& creation = environment->createEntity(
|
||||
getComponent<TagComponent>().tag + "(d)");
|
||||
|
||||
creation.setParent(getParent());
|
||||
@ -55,12 +85,12 @@ namespace Deer {
|
||||
getComponent<TransformComponent>();
|
||||
|
||||
#ifdef DEER_RENDER
|
||||
if (m_environment->m_registry.any_of<MeshComponent>(
|
||||
m_entityHandle))
|
||||
if (environment->m_registry->any_of<MeshComponent>(
|
||||
entHandle))
|
||||
creation.addComponent<MeshComponent>(
|
||||
getComponent<MeshComponent>());
|
||||
|
||||
if (m_environment->m_registry.any_of<CameraComponent>(m_entityHandle))
|
||||
if (environment->m_registry->any_of<CameraComponent>(entHandle))
|
||||
creation.addComponent<CameraComponent>(
|
||||
getComponent<CameraComponent>());
|
||||
#endif
|
||||
@ -70,21 +100,28 @@ namespace Deer {
|
||||
void Entity::destroy() {
|
||||
DEER_CORE_ASSERT(isValid(), "Entity is not valid");
|
||||
DEER_CORE_ASSERT(!isRoot(), "Can not destroy the root");
|
||||
m_environment->destroyEntity(getId());
|
||||
environment->destroyEntity(getId());
|
||||
}
|
||||
|
||||
Entity& Entity::getParent() const {
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
} // namespace Deer
|
||||
|
@ -9,86 +9,111 @@
|
||||
|
||||
namespace Deer {
|
||||
Environment::Environment() {
|
||||
entities = MakeScope<std::array<Entity, ENVIRONMENT_MAX_ENTITIES>>();
|
||||
clear();
|
||||
m_registry = MakeScope<entt::registry>();
|
||||
createEntityWithId(0, "root");
|
||||
}
|
||||
|
||||
Environment::~Environment() {}
|
||||
|
||||
void Environment::clear() {
|
||||
// Clear all existing entities and map
|
||||
m_registry.clear();
|
||||
m_registry->clear();
|
||||
|
||||
m_mainCamera = 0;
|
||||
m_idCreationOffset = 0;
|
||||
m_maxIdValue = 0;
|
||||
// We set it to one because we count root
|
||||
m_entityCount = 1;
|
||||
while (!unused_entities_spaces.empty()) {
|
||||
unused_entities_spaces.pop();
|
||||
}
|
||||
entities.clear();
|
||||
|
||||
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);
|
||||
Entity& refEntity = (*entities)[id];
|
||||
return refEntity;
|
||||
return entities[id];
|
||||
}
|
||||
|
||||
bool Environment::entityExists(uint16_t id) const {
|
||||
if (id < 0) return false;
|
||||
if (id > m_maxIdValue) return false;
|
||||
if (id >= ENVIRONMENT_MAX_ENTITIES) return false;
|
||||
Entity& refEntity = (*entities)[id];
|
||||
if (id >= entities.size()) return false;
|
||||
const Entity& refEntity = entities[id];
|
||||
return refEntity.isValid();
|
||||
}
|
||||
|
||||
Entity& Environment::createEntity(const std::string& name) {
|
||||
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();
|
||||
if (unused_entities_spaces.empty()) {
|
||||
id = entities.size();
|
||||
entities.push_back({});
|
||||
} else {
|
||||
id = unused_entities_spaces.top();
|
||||
unused_entities_spaces.pop();
|
||||
}
|
||||
|
||||
entt::entity entityID = m_registry.create();
|
||||
Entity& entity = (*entities)[id];
|
||||
Entity& entity = entities[id];
|
||||
entity = {entityID, this, id};
|
||||
|
||||
entity.addComponent<TagComponent>(name, id);
|
||||
entity.addComponent<RelationshipComponent>();
|
||||
entity.addComponent<TransformComponent>();
|
||||
entity.m_exists = true;
|
||||
|
||||
m_entityCount++;
|
||||
entity.m_parentID = 0;
|
||||
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(
|
||||
id)) {
|
||||
entity.parentId = 0;
|
||||
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(id)) {
|
||||
DEER_CORE_ERROR("Root is full!");
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
Entity& Environment::createEntityWithId(uint16_t id,
|
||||
const std::string& name) {
|
||||
// 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& Environment::createEntityWithId(uint16_t id, const std::string& name) {
|
||||
entt::entity entityID = m_registry->create();
|
||||
|
||||
Entity& entity = (*entities)[id];
|
||||
entt::entity entityID = m_registry.create();
|
||||
entity = {entityID, this, id};
|
||||
entity.m_exists = true;
|
||||
// We allocate all the memory until that id
|
||||
if (id >= entities.size()) {
|
||||
if (entities.capacity() <= id)
|
||||
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<RelationshipComponent>();
|
||||
entity.addComponent<TransformComponent>();
|
||||
|
||||
m_entityCount++;
|
||||
if (id != 0) {
|
||||
if (!getRoot().getComponent<RelationshipComponent>().addChildrenId(
|
||||
id)) {
|
||||
@ -99,16 +124,13 @@ namespace Deer {
|
||||
}
|
||||
|
||||
void Environment::destroyEntity(uint16_t entityID) {
|
||||
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist",
|
||||
entityID);
|
||||
DEER_CORE_ASSERT(entityID != 0, "Can not destroy root");
|
||||
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist", entityID);
|
||||
DEER_CORE_ASSERT(entityID != 0, "Cannot destroy root");
|
||||
|
||||
Entity& entity = (*entities)[entityID];
|
||||
entity.getParent().getComponent<RelationshipComponent>().removeChildren(
|
||||
entityID);
|
||||
Entity& entity = entities[entityID];
|
||||
entity.getParent().getComponent<RelationshipComponent>().removeChildren(entityID);
|
||||
|
||||
RelationshipComponent& relationship =
|
||||
entity.getComponent<RelationshipComponent>();
|
||||
RelationshipComponent& relationship = entity.getComponent<RelationshipComponent>();
|
||||
// We want to delete all childrens
|
||||
for (int i = 0; i < relationship.childCount; i++) {
|
||||
uint16_t childID = relationship.getChildrenId(i);
|
||||
@ -116,14 +138,14 @@ namespace Deer {
|
||||
}
|
||||
|
||||
if (m_mainCamera == entityID) m_mainCamera = 0;
|
||||
if (entityID <= m_idCreationOffset) m_idCreationOffset = entityID - 1;
|
||||
|
||||
m_registry->destroy(entity.entHandle);
|
||||
entity.clear();
|
||||
|
||||
m_registry.destroy(entity.m_entityHandle);
|
||||
entity.m_exists = false;
|
||||
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) {
|
||||
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
|
||||
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) {
|
||||
auto& meshComponent = view.get<MeshComponent>(entityId);
|
||||
auto& shaderComponent = view.get<ShaderComponent>(entityId);
|
||||
@ -75,7 +75,7 @@ namespace Deer {
|
||||
RenderUtils::m_lineShader->uploadUniformMat4("u_viewMatrix", cameraProjectionMatrix);
|
||||
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) {
|
||||
CameraComponent cameraComponent = view.get<CameraComponent>(entityId);
|
||||
cameraComponent.nearZ = .5f;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Window][DockSpace Demo]
|
||||
Pos=0,0
|
||||
Size=1280,720
|
||||
Size=2560,1371
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
@ -9,53 +9,59 @@ Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Terrain Editor]
|
||||
Pos=854,24
|
||||
Size=426,454
|
||||
Pos=2249,24
|
||||
Size=311,1128
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=361,24
|
||||
Size=491,454
|
||||
Pos=299,24
|
||||
Size=668,477
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][ViewportPannel]
|
||||
Pos=361,24
|
||||
Size=491,454
|
||||
Pos=312,24
|
||||
Size=1935,1128
|
||||
Collapsed=0
|
||||
DockId=0x00000005,1
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][ShaderExplorer]
|
||||
Pos=0,480
|
||||
Size=1280,240
|
||||
Pos=0,1154
|
||||
Size=2560,217
|
||||
Collapsed=0
|
||||
DockId=0x00000004,1
|
||||
|
||||
[Window][TreePannel]
|
||||
Pos=0,24
|
||||
Size=359,454
|
||||
Size=310,1128
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Window][MeshExplorer]
|
||||
Pos=0,480
|
||||
Size=1280,240
|
||||
Pos=0,1154
|
||||
Size=2560,217
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][PropertiesPannel]
|
||||
Pos=854,24
|
||||
Size=426,454
|
||||
Pos=2249,24
|
||||
Size=311,1128
|
||||
Collapsed=0
|
||||
DockId=0x00000006,1
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y Selected=0x34A4C10F
|
||||
DockNode ID=0x00000003 Parent=0xA1672E74 SizeRef=1280,454 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=359,696 Selected=0xE45B9F93
|
||||
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1380,696 Split=X Selected=0x34A4C10F
|
||||
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=952,454 CentralNode=1 Selected=0x34A4C10F
|
||||
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=426,454 Selected=0xA35A27E3
|
||||
DockNode ID=0x00000004 Parent=0xA1672E74 SizeRef=1280,240 Selected=0xD962995A
|
||||
[Window][CameraPannel]
|
||||
Pos=312,24
|
||||
Size=1935,1128
|
||||
Collapsed=0
|
||||
DockId=0x00000005,1
|
||||
|
||||
[Docking][Data]
|
||||
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");
|
||||
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
// MENUBAR
|
||||
if (ImGui::BeginMenu("Pannel")) {
|
||||
onPannelMenuBar();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
TerrainEditor::onImGui();
|
||||
viewport_onImGui();
|
||||
//viewport_onImGui();
|
||||
EditorEngine::render();
|
||||
|
||||
Scene::gizmoRenderer.refresh();
|
||||
@ -112,7 +117,7 @@ namespace Deer {
|
||||
}
|
||||
|
||||
void onEvent(Event& e) {
|
||||
viewport_onEvent(e);
|
||||
//viewport_onEvent(e);
|
||||
|
||||
EventDispatcher ed(e);
|
||||
|
||||
|
@ -13,5 +13,8 @@ namespace Deer {
|
||||
void main();
|
||||
|
||||
bool onWindowCloseEvent(WindowCloseEvent&);
|
||||
|
||||
// Other
|
||||
void onPannelMenuBar();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
class asIScriptEngine;
|
||||
class asIScriptModule;
|
||||
class asIScriptContext;
|
||||
class CScriptBuilder;
|
||||
|
||||
namespace Deer {
|
||||
// This namespace implements all interface ported from c++ ImGui to an easier lua aproach with simplifications
|
||||
@ -16,9 +17,11 @@ namespace Deer {
|
||||
|
||||
void render();
|
||||
|
||||
// INTERNAL
|
||||
extern asIScriptEngine* scriptEngine;
|
||||
extern asIScriptModule* scriptModule;
|
||||
extern asIScriptContext* scriptContext;
|
||||
extern CScriptBuilder builtContext;
|
||||
extern std::vector<DockPanelObject> dockPanels;
|
||||
extern DockPanelObject* currentDockPanelExecution;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include "GenericRefStructs.h"
|
||||
#include "DeerRender/SceneCamera.h"
|
||||
|
||||
#include <string>
|
||||
//#include "DeerRender/SceneCamera.h"
|
||||
|
||||
namespace Deer {
|
||||
class SceneCamera;
|
||||
|
||||
namespace EditorEngine {
|
||||
struct EnvironmentStruct : EnvironmentHandleStruct {
|
||||
void render(FrameBufferHandleStruct, SceneCamera&);
|
||||
|
@ -7,10 +7,14 @@
|
||||
#include "Deer/Enviroment.h"
|
||||
#include "Deer/Scene.h"
|
||||
|
||||
#define GET_ENTITY(id) Scene::environment.getEntity(id)
|
||||
#define GET_MESH_COMPONENT(id) Scene::environment.getEntity(id).getComponent<MeshComponent>()
|
||||
#define GET_SHADER_COMPONENT(id) Scene::environment.getEntity(id).getComponent<ShaderComponent>()
|
||||
#define GET_CAMERA_COMPONENT(id) Scene::environment.getEntity(id).getComponent<CameraComponent>()
|
||||
#include <vector>
|
||||
|
||||
#define GET_ENV(env) (*Deer::EditorEngine::environments[env])
|
||||
|
||||
#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_MESH_COMPONENT(func, ret) if (!assertMeshComponent(func)) ret;
|
||||
@ -20,6 +24,8 @@
|
||||
|
||||
namespace Deer {
|
||||
namespace EditorEngine {
|
||||
extern std::vector <Scope<Environment>> environments;
|
||||
|
||||
EntityHandleStruct getRoot() {
|
||||
return EntityStruct(0);
|
||||
}
|
||||
@ -45,7 +51,7 @@ namespace Deer {
|
||||
std::string EntityStruct::getName() {
|
||||
ASSERT_ENTITY("getName()", return "NULL");
|
||||
|
||||
return GET_ENTITY(entityId)
|
||||
return GET_ENTITY(environmentId, entityId)
|
||||
.getComponent<TagComponent>()
|
||||
.tag;
|
||||
}
|
||||
@ -54,7 +60,7 @@ namespace Deer {
|
||||
void EntityStruct::setName(std::string& name) {
|
||||
ASSERT_ENTITY("setName()", return);
|
||||
|
||||
GET_ENTITY(entityId)
|
||||
GET_ENTITY(environmentId, entityId)
|
||||
.getComponent<TagComponent>()
|
||||
.tag = name;
|
||||
}
|
||||
@ -62,7 +68,7 @@ namespace Deer {
|
||||
void EntityStruct::destroy() {
|
||||
ASSERT_ENTITY("destroy()", return);
|
||||
|
||||
GET_ENTITY(entityId)
|
||||
GET_ENTITY(environmentId, entityId)
|
||||
.destroy();
|
||||
}
|
||||
|
||||
@ -82,16 +88,16 @@ namespace Deer {
|
||||
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
||||
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);
|
||||
}
|
||||
|
||||
EntityHandleStruct EntityStruct::getParent() {
|
||||
ASSERT_ENTITY("getParent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
if (self.isRoot())
|
||||
return *this;
|
||||
|
||||
@ -101,9 +107,9 @@ namespace Deer {
|
||||
bool EntityStruct::isDescendantOf(EntityHandleStruct parent_struct) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -122,43 +128,43 @@ namespace Deer {
|
||||
glm::vec3 TransformComponentStruct::getPosition() {
|
||||
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() {
|
||||
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() {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
ASSERT_ENTITY("setRotation()", return);
|
||||
|
||||
GET_ENTITY(entityId).getComponent<TransformComponent>().setEulerAngles(value);
|
||||
GET_ENTITY(environmentId, entityId).getComponent<TransformComponent>().setEulerAngles(value);
|
||||
}
|
||||
|
||||
int EntityChildArrayStruct::getChildCount() {
|
||||
ASSERT_ENTITY("getChildCount()", return 0);
|
||||
|
||||
return GET_ENTITY(entityId)
|
||||
return GET_ENTITY(environmentId, entityId)
|
||||
.getComponent<RelationshipComponent>()
|
||||
.childCount;
|
||||
}
|
||||
@ -185,7 +191,7 @@ namespace Deer {
|
||||
EntityHandleStruct EntityChildArrayStruct::getChild(int i) {
|
||||
ASSERT_ENTITY("getChild()", return *this);
|
||||
|
||||
RelationshipComponent& rc = GET_ENTITY(entityId)
|
||||
RelationshipComponent& rc = GET_ENTITY(environmentId, entityId)
|
||||
.getComponent<RelationshipComponent>();
|
||||
|
||||
if (i < 0 || i >= rc.childCount) {
|
||||
@ -202,10 +208,8 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::createChild(std::string& name) {
|
||||
ASSERT_ENTITY("createChild()", return *this);
|
||||
|
||||
Entity& me = GET_ENTITY(entityId);
|
||||
|
||||
Entity& newEnt = Scene::environment
|
||||
.createEntity(name);
|
||||
Entity& newEnt = Scene::environment.createEntity(name);
|
||||
Entity& me = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
newEnt.setParent(me);
|
||||
|
||||
@ -215,11 +219,11 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::getMeshComponent() {
|
||||
ASSERT_ENTITY("getMeshComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<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
|
||||
);
|
||||
|
||||
@ -233,7 +237,7 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::createMeshComponent() {
|
||||
ASSERT_ENTITY("createMeshComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<MeshComponent>()) {
|
||||
self.addComponent<MeshComponent>();
|
||||
@ -245,7 +249,7 @@ namespace Deer {
|
||||
bool EntityStruct::hasMeshComponent() {
|
||||
ASSERT_ENTITY("hasMeshComponent()", return false);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
return self.hasComponent<MeshComponent>();
|
||||
}
|
||||
@ -253,7 +257,7 @@ namespace Deer {
|
||||
void EntityStruct::removeMeshComponent() {
|
||||
ASSERT_ENTITY("removeMeshComponent()", return);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (self.hasComponent<MeshComponent>()) {
|
||||
self.removeComponent<MeshComponent>();
|
||||
@ -263,11 +267,11 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::getCameraComponent() {
|
||||
ASSERT_ENTITY("getCameraComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<CameraComponent>()) {
|
||||
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
|
||||
);
|
||||
|
||||
@ -281,7 +285,7 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::createCameraComponent() {
|
||||
ASSERT_ENTITY("createCameraComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<CameraComponent>()) {
|
||||
self.addComponent<CameraComponent>();
|
||||
@ -293,7 +297,7 @@ namespace Deer {
|
||||
bool EntityStruct::hasCameraComponent() {
|
||||
ASSERT_ENTITY("hasCameraComponent()", return false);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
return self.hasComponent<CameraComponent>();
|
||||
}
|
||||
@ -301,7 +305,7 @@ namespace Deer {
|
||||
void EntityStruct::removeCameraComponent() {
|
||||
ASSERT_ENTITY("removeMeshComponent()", return);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (self.hasComponent<CameraComponent>()) {
|
||||
self.removeComponent<CameraComponent>();
|
||||
@ -311,11 +315,11 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::getShaderComponent() {
|
||||
ASSERT_ENTITY("getShaderComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<ShaderComponent>()) {
|
||||
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
|
||||
);
|
||||
|
||||
@ -329,7 +333,7 @@ namespace Deer {
|
||||
EntityHandleStruct EntityStruct::createShaderComponent() {
|
||||
ASSERT_ENTITY("createShaderComponent()", return *this);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (!self.hasComponent<ShaderComponent>()) {
|
||||
self.addComponent<ShaderComponent>();
|
||||
@ -341,14 +345,14 @@ namespace Deer {
|
||||
bool EntityStruct::hasShaderComponent() {
|
||||
ASSERT_ENTITY("hasShaderComponent()", return false);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
return self.hasComponent<ShaderComponent>();
|
||||
}
|
||||
|
||||
void EntityStruct::removeShaderComponent() {
|
||||
ASSERT_ENTITY("removeShaderComponent()", return);
|
||||
|
||||
Entity& self = GET_ENTITY(entityId);
|
||||
Entity& self = GET_ENTITY(environmentId, entityId);
|
||||
|
||||
if (self.hasComponent<ShaderComponent>()) {
|
||||
self.removeComponent<ShaderComponent>();
|
||||
@ -357,44 +361,44 @@ namespace Deer {
|
||||
|
||||
bool MeshComponentStruct::isActive() {
|
||||
ASSERT_MESH_COMPONENT("isActive()", return false);
|
||||
return GET_MESH_COMPONENT(entityId).isActive();
|
||||
return GET_MESH_COMPONENT(environmentId, entityId).isActive();
|
||||
}
|
||||
|
||||
void MeshComponentStruct::setActive(bool value) {
|
||||
ASSERT_MESH_COMPONENT("setActive(bool)", return);
|
||||
|
||||
GET_MESH_COMPONENT(entityId).setActive(value);
|
||||
GET_MESH_COMPONENT(environmentId, entityId).setActive(value);
|
||||
}
|
||||
|
||||
bool MeshComponentStruct::hasMesh() {
|
||||
ASSERT_MESH_COMPONENT("hasMesh()", return false);
|
||||
|
||||
return GET_MESH_COMPONENT(entityId).hasMesh();
|
||||
return GET_MESH_COMPONENT(environmentId, entityId).hasMesh();
|
||||
}
|
||||
|
||||
void MeshComponentStruct::clear() {
|
||||
ASSERT_MESH_COMPONENT("clear()", return);
|
||||
|
||||
GET_MESH_COMPONENT(entityId).clear();
|
||||
GET_MESH_COMPONENT(environmentId, entityId).clear();
|
||||
}
|
||||
|
||||
std::string MeshComponentStruct::getMesh() {
|
||||
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) {
|
||||
ASSERT_MESH_COMPONENT("setMesh()", return);
|
||||
|
||||
uint16_t meshId = MeshManager::loadModel(name);
|
||||
GET_MESH_COMPONENT(entityId).setMesh(meshId);
|
||||
GET_MESH_COMPONENT(environmentId, entityId).setMesh(meshId);
|
||||
}
|
||||
|
||||
bool ShaderComponentStruct::hasShader() {
|
||||
ASSERT_ENTITY("hasShader()", return false);
|
||||
|
||||
return GET_SHADER_COMPONENT(entityId).hasShader();
|
||||
return GET_SHADER_COMPONENT(environmentId, entityId).hasShader();
|
||||
}
|
||||
|
||||
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
|
||||
@ -419,20 +423,20 @@ namespace Deer {
|
||||
void ShaderComponentStruct::clear() {
|
||||
ASSERT_SHADER_COMPONENT("clear()", return);
|
||||
|
||||
GET_SHADER_COMPONENT(entityId).clear();
|
||||
GET_SHADER_COMPONENT(environmentId, entityId).clear();
|
||||
}
|
||||
|
||||
std::string ShaderComponentStruct::getShader() {
|
||||
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) {
|
||||
ASSERT_SHADER_COMPONENT("getShader()", return);
|
||||
|
||||
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() {
|
||||
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() {
|
||||
ASSERT_CAMERA_COMPONENT("getAspectRation()", return 0);
|
||||
|
||||
return GET_CAMERA_COMPONENT(entityId).aspect;
|
||||
return GET_CAMERA_COMPONENT(environmentId, entityId).aspect;
|
||||
}
|
||||
|
||||
float CameraComponentStruct::getNearZ() {
|
||||
ASSERT_CAMERA_COMPONENT("getNearZ()", return 0);
|
||||
|
||||
return GET_CAMERA_COMPONENT(entityId).nearZ;
|
||||
return GET_CAMERA_COMPONENT(environmentId, entityId).nearZ;
|
||||
}
|
||||
|
||||
float CameraComponentStruct::getFarZ() {
|
||||
ASSERT_CAMERA_COMPONENT("getFarZ()", return 0);
|
||||
|
||||
return GET_CAMERA_COMPONENT(entityId).farZ;
|
||||
return GET_CAMERA_COMPONENT(environmentId, entityId).farZ;
|
||||
}
|
||||
|
||||
void CameraComponentStruct::setFov(float v) {
|
||||
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) {
|
||||
ASSERT_CAMERA_COMPONENT("setAspectRation()", return);
|
||||
|
||||
GET_CAMERA_COMPONENT(entityId).aspect = v;
|
||||
GET_CAMERA_COMPONENT(environmentId, entityId).aspect = v;
|
||||
}
|
||||
void CameraComponentStruct::setNearZ(float v) {
|
||||
ASSERT_CAMERA_COMPONENT("setNearZ()", return);
|
||||
|
||||
GET_CAMERA_COMPONENT(entityId).nearZ = v;
|
||||
GET_CAMERA_COMPONENT(environmentId, entityId).nearZ = v;
|
||||
}
|
||||
void CameraComponentStruct::setFarZ(float v) {
|
||||
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/Scene.h"
|
||||
#include "Deer/Memory.h"
|
||||
|
||||
#include "DeerStudio/EditorEngine/API/Environment.h"
|
||||
|
||||
#include "DeerRender/FrameBuffer.h"
|
||||
#include "DeerRender/SceneCamera.h"
|
||||
#include "Deer/Scene.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Deer {
|
||||
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) {
|
||||
FrameBuffer& frameBuffer = FrameBufferManager::getFrameBuffer(frameBuffer_handle.frameBufferId);
|
||||
Environment& env = EnvironmentManager::getEnvironment(environmentId);
|
||||
Environment& env = *environments[environmentId];
|
||||
|
||||
frameBuffer.bind();
|
||||
|
||||
// TODO
|
||||
Scene::render(sc);
|
||||
//env.render(sceneCamera);
|
||||
env.render(sc);
|
||||
|
||||
frameBuffer.unbind();
|
||||
}
|
||||
@ -32,7 +39,10 @@ namespace Deer {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const char* EditorEngine::DockPanelObject::getName() {
|
||||
return type->GetName();
|
||||
}
|
||||
|
||||
EditorEngine::DockPanelObject::~DockPanelObject() {
|
||||
if (object)
|
||||
object->Release();
|
||||
|
@ -27,10 +27,13 @@ namespace Deer {
|
||||
DockPanelObject& operator=(DockPanelObject&& other) noexcept;
|
||||
|
||||
uint32_t flags = 0;
|
||||
bool enabled = true;
|
||||
|
||||
void executeRender();
|
||||
void invalidate();
|
||||
void init();
|
||||
|
||||
const char* getName();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,14 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Deer {
|
||||
namespace EditorEngine {
|
||||
CScriptBuilder builtContext;
|
||||
}
|
||||
|
||||
void EditorEngine::loadScripts() {
|
||||
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 ");
|
||||
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());
|
||||
// We add aditional info to check who caused the error
|
||||
AS_CHECK_ADDITIONAL_INFO(
|
||||
builder.AddSectionFromFile(entry.path().string().c_str());,
|
||||
builtContext.AddSectionFromFile(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();
|
||||
|
||||
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() {
|
||||
Entity entity = activeEntity;
|
||||
|
||||
// We don't want to change root options
|
||||
if (entity.isRoot)
|
||||
return;
|
||||
// NAME
|
||||
// -------
|
||||
// Id:0 [+ add component]
|
||||
@ -16,9 +19,6 @@ class PropertiesPannel : DockPanel {
|
||||
UI::separator();
|
||||
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();
|
||||
if (UI::buttonEnd("Add Component")) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
//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 TransferFunc(any@, any@);
|
||||
enum key {
|
||||
|
Loading…
x
Reference in New Issue
Block a user