Changed environment to entity environment

This commit is contained in:
Chewico 2026-01-22 17:01:46 +01:00
parent 67b316a70b
commit f246d0e227
34 changed files with 251 additions and 258 deletions

View File

@ -20,22 +20,22 @@
namespace Deer {
class Entity;
class Environment {
class EntityEnvironment {
// 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
// - The entity id means the position in a array defined in EntityEnvironment
// - The entity id is relative to a EntityEnvironment so it can be a complete
// diferent entity in other environments
// - The entity number 0 is allways the root
// - There is a limit defined by ENVIRONMENT_MAX_ENTITIES of how many
// entities can be in an Environment
// entities can be in an EntityEnvironment
///////// NOTES ///////////
public:
Environment();
~Environment();
EntityEnvironment();
~EntityEnvironment();
// This class can not be copyed
Environment(const Environment&) = delete;
Environment& operator=(Environment&) = delete;
EntityEnvironment(const EntityEnvironment&) = delete;
EntityEnvironment& operator=(EntityEnvironment&) = delete;
// Clears all entities
void clear();
@ -80,15 +80,15 @@ namespace Deer {
int toDo;
};
struct EnvironmentData {
struct EntityEnvironmentData {
std::vector<EntityData> entities;
};
template <>
class ResourceBuilder<Environment> {
class ResourceBuilder<EntityEnvironment> {
public:
using BaseDataType = EnvironmentData;
static Scope<Environment> buildResource(const BaseDataType& baseData);
using BaseDataType = EntityEnvironmentData;
static Scope<EntityEnvironment> buildResource(const BaseDataType& baseData);
};
// Warning: This calss does not initialize for performance
@ -111,7 +111,7 @@ namespace Deer {
void setParent(Entity& parent);
bool isDescendantOf(Entity& parent) const;
Environment* getEnvironment() const { return environment; }
EntityEnvironment* getEntityEnvironment() const { return environment; }
bool isRoot() const { return entId == 0; }
glm::mat4 getWorldMatrix() const;
@ -123,14 +123,14 @@ namespace Deer {
bool isValid() const;
private:
Environment* environment = nullptr;
EntityEnvironment* environment = nullptr;
entt::entity entHandle = entt::null;
uint16_t entId = 0;
uint16_t parentId = 0;
Entity(entt::entity handle, Environment* scene, uint16_t entityID);
Entity(entt::entity handle, EntityEnvironment* scene, uint16_t entityID);
friend class Environment;
friend class EntityEnvironment;
public:
template <typename T, typename... Args>

View File

@ -2,7 +2,7 @@
#include "DeerCore/Tools/TypeDefs.h"
namespace Deer {
class Environment;
class EntityEnvironment;
class SceneCamera;
class GizmoRenderer;
@ -27,6 +27,6 @@ namespace Deer {
extern GizmoRenderer gizmoRenderer;
#endif
extern Environment environment;
extern EntityEnvironment environment;
} // namespace Scene
} // namespace Deer

View File

@ -1,7 +1,7 @@
#pragma once
#include "DeerRender/Enviroment.h"
#include "DeerRender/Render/FrameBuffer.h"
#include "DeerRender/Tools/Memory.h"
#include "DeerRender/Enviroment.h"
namespace Deer {
class RenderPiperline {
@ -9,7 +9,8 @@ namespace Deer {
RenderPiperline(RenderPiperline&) = delete;
RenderPiperline(PiperlineOptions);
void render(const Environment&);
void render(const EntityEnvironment&);
private:
Scope<FrameBuffer> resultImage;
PiperlineOptions options;
@ -19,4 +20,4 @@ namespace Deer {
int width = 100;
int height = 100;
};
}
} // namespace Deer

View File

@ -3,7 +3,7 @@
#include "DeerCore/Log.h"
namespace Deer {
Entity::Entity(entt::entity handle, Environment* scene, uint16_t entityID)
Entity::Entity(entt::entity handle, EntityEnvironment* scene, uint16_t entityID)
: entHandle(handle),
environment(scene),
entId(entityID) {}

View File

@ -7,14 +7,14 @@
#include "DeerRender/Render/Texture.h"
namespace Deer {
Environment::Environment() {
EntityEnvironment::EntityEnvironment() {
m_registry = MakeScope<entt::registry>();
createEntityWithId(0, "root");
}
Environment::~Environment() {}
EntityEnvironment::~EntityEnvironment() {}
void Environment::clear() {
void EntityEnvironment::clear() {
// Clear all existing entities and map
m_registry->clear();
@ -26,23 +26,23 @@ namespace Deer {
createEntityWithId(0, "root");
}
uint16_t Environment::getEntityCount() const {
uint16_t EntityEnvironment::getEntityCount() const {
return entities.size() - unused_entities_spaces.size();
}
Entity& Environment::getEntity(uint16_t id) {
Entity& EntityEnvironment::getEntity(uint16_t id) {
DEER_CORE_ASSERT(entityExists(id), "Entity id {0} does not exist", id);
return entities[id];
}
bool Environment::entityExists(uint16_t id) const {
bool EntityEnvironment::entityExists(uint16_t id) const {
if (id >= entities.size())
return false;
const Entity& refEntity = entities[id];
return refEntity.isValid();
}
Entity& Environment::createEntity(const std::string& name) {
Entity& EntityEnvironment::createEntity(const std::string& name) {
uint16_t id;
entt::entity entityID = m_registry->create();
@ -67,7 +67,7 @@ namespace Deer {
return entity;
}
Entity& Environment::createEntityWithId(uint16_t id, const std::string& name) {
Entity& EntityEnvironment::createEntityWithId(uint16_t id, const std::string& name) {
entt::entity entityID = m_registry->create();
// We allocate all the memory until that id
@ -118,7 +118,7 @@ namespace Deer {
return entity;
}
void Environment::destroyEntity(uint16_t entityID) {
void EntityEnvironment::destroyEntity(uint16_t entityID) {
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist", entityID);
DEER_CORE_ASSERT(entityID != 0, "Cannot destroy root");
@ -141,9 +141,9 @@ namespace Deer {
unused_entities_spaces.push(entityID);
}
uint16_t Environment::tryGetMainCamera() const { return m_mainCamera; }
uint16_t EntityEnvironment::tryGetMainCamera() const { return m_mainCamera; }
void Environment::setMainCamera(Entity& entity) {
void EntityEnvironment::setMainCamera(Entity& entity) {
if (!entity.isValid())
m_mainCamera = 0;

View File

@ -1,8 +1,8 @@
#include "DeerCore/Enviroment.h"
namespace Deer {
Scope<Environment> ResourceBuilder<Environment>::buildResource(const BaseDataType& baseData) {
Scope<Environment> env = MakeScope<Environment>();
Scope<EntityEnvironment> ResourceBuilder<EntityEnvironment>::buildResource(const BaseDataType& baseData) {
Scope<EntityEnvironment> env = MakeScope<EntityEnvironment>();
return env;
}
} // namespace Deer

View File

@ -20,6 +20,7 @@ namespace Deer {
ResourceManager<Shader>::unloadResources();
ResourceManager<GPUMesh>::unloadResources();
ResourceManager<FrameBuffer>::unloadResources();
ResourceManager<Texture>::unloadResources();
#endif
}

View File

@ -3,7 +3,7 @@
namespace Deer {
namespace Scene {
Environment environment;
EntityEnvironment environment;
bool isExecuting = false;
} // namespace Scene

View File

@ -2,10 +2,10 @@
#include "DeerCore/Tools/Memory.h"
namespace Deer {
class Environment;
class EntityEnvironment;
namespace Scene {
extern Environment environment;
extern EntityEnvironment environment;
extern bool isExecuting;
} // namespace Scene

View File

@ -2,9 +2,9 @@
#include <cstdint>
namespace Deer {
class Environment;
class EntityEnvironment;
struct EntitySerializationStruct {
uint16_t entityID;
Environment* env;
EntityEnvironment* env;
};
} // namespace Deer

View File

@ -6,25 +6,25 @@
#include "EntitySerializationStruct.h"
namespace Deer {
struct EnvironmentEntity {
Environment& environment;
EnvironmentEntity(Environment& env) : environment(env) {}
struct EntityEnvironmentEntity {
EntityEnvironment& environment;
EntityEnvironmentEntity(EntityEnvironment& env) : environment(env) {}
};
template <class Archive>
void save(Archive& archive, const Deer::Environment& environment) {
EnvironmentEntity envEnt(const_cast<Deer::Environment&>(environment));
void save(Archive& archive, const Deer::EntityEnvironment& environment) {
EntityEnvironmentEntity envEnt(const_cast<Deer::EntityEnvironment&>(environment));
archive(cereal::make_nvp("entities", envEnt));
}
template <class Archive>
void load(Archive& archive, Deer::Environment& environment) {
EnvironmentEntity envEnt(environment);
void load(Archive& archive, Deer::EntityEnvironment& environment) {
EntityEnvironmentEntity envEnt(environment);
archive(cereal::make_nvp("entities", envEnt));
}
template <class Archive>
void save(Archive& archive, EnvironmentEntity const& m_entities) {
void save(Archive& archive, EntityEnvironmentEntity const& m_entities) {
archive(cereal::make_size_tag(static_cast<cereal::size_type>(
m_entities.environment.getEntityCount())));
@ -35,7 +35,7 @@ namespace Deer {
EntitySerializationStruct serializationStruct;
serializationStruct.env =
const_cast<Environment*>(&m_entities.environment);
const_cast<EntityEnvironment*>(&m_entities.environment);
serializationStruct.entityID = i;
archive(serializationStruct);
@ -43,7 +43,7 @@ namespace Deer {
}
template <class Archive>
void load(Archive& archive, EnvironmentEntity& m_entities) {
void load(Archive& archive, EntityEnvironmentEntity& m_entities) {
cereal::size_type size;
archive(cereal::make_size_tag(size));

View File

@ -12,8 +12,8 @@
#include "DeerCore/Scene/Serialization/Vec3Serialization.h"
// SCENE SPECIFIC
#include "DeerCore/Scene/Serialization/EntityEnvironmentSerialization.h"
#include "DeerCore/Scene/Serialization/EntitySerialization.h"
#include "DeerCore/Scene/Serialization/EnvironmentSerialization.h"
// COMPONENTS SPECIFIC
#include "DeerCore/Scene/Serialization/Components/RelationshipComponentSerialization.h"

View File

@ -13,7 +13,7 @@
#include "DeerRender/Log.h"
namespace Deer {
void Environment::render(const SceneCamera& camera) {
void EntityEnvironment::render(const SceneCamera& camera) {
glm::mat4 camMatrix = glm::inverse(camera.transform.getMatrix());
glm::mat4 projectionMatrix = camera.camera.getMatrix();
glm::mat4 invertZ = glm::scale(glm::mat4(1.0f), glm::vec3(1, 1, -1));

View File

@ -7,14 +7,14 @@ namespace Deer {
class SceneCamera;
namespace StudioAPI {
struct EnvironmentStruct : EnvironmentHandleStruct {
struct EntityEnvironmentStruct : EntityEnvironmentHandleStruct {
void render(FrameBufferHandleStruct, SceneCamera&);
EntityHandleStruct getRootEntity();
EntityHandleStruct getEntity(int);
};
EnvironmentHandleStruct getMainEnvironment();
EnvironmentHandleStruct createLoadEnvironment(std::string& envId);
EntityEnvironmentHandleStruct getMainEntityEnvironment();
EntityEnvironmentHandleStruct createLoadEntityEnvironment(std::string& envId);
} // namespace StudioAPI
} // namespace Deer

View File

@ -2,11 +2,11 @@
#include "DeerRender/Tools/TypeDefs.h"
namespace Deer {
class Environment;
class EntityEnvironment;
namespace StudioAPI {
struct EnvironmentHandleStruct {
EnvironmentHandleStruct(int32_t _id = -1) : environmentId(_id) {}
struct EntityEnvironmentHandleStruct {
EntityEnvironmentHandleStruct(int32_t _id = -1) : environmentId(_id) {}
int32_t environmentId;
};
@ -18,7 +18,7 @@ namespace Deer {
int32_t environmentId;
bool assertEntity(const char* funcName);
Environment* getEntityEnvironment();
EntityEnvironment* getEntityEntityEnvironment();
};
struct FrameBufferHandleStruct {

View File

@ -13,21 +13,7 @@ namespace Deer {
extern CScriptAny* payload;
}
void sameline();
void separator();
void disablePanelPadding(bool);
int getAvailableSizeX();
int getAvailableSizeY();
bool button(std::string&);
bool buttonCenter(std::string&);
bool buttonEnd(std::string&);
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width);
bool cartIconButton_frameBuffer(const std::string& label, FrameBufferHandleStruct frameBuffer, int iconSize, int width);
// Text & titles
void text(std::string&);
void textCenter(std::string&);
void textEnd(std::string&);
@ -38,6 +24,15 @@ namespace Deer {
void titleEnd(std::string&);
void titleCenterY(std::string&, int);
// Buttons
bool button(std::string&);
bool buttonCenter(std::string&);
bool buttonEnd(std::string&);
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width);
bool cartIconButton_frameBuffer(const std::string& label, FrameBufferHandleStruct frameBuffer, int iconSize, int width);
// Icons
void drawIcon(std::string& iconId, int size);
void drawIconCentered(std::string& iconId, int size);
void drawIconHighlight(std::string& iconId, int size);
@ -48,9 +43,22 @@ namespace Deer {
void drawIconHighlight_resource(Resource<Texture> texture, int size);
void drawIconCenteredHighlight_resource(Resource<Texture> texture, int size);
void drawFrameBuffer(FrameBufferHandleStruct frameBuffer, int sizeX, int sizeY);
void drawFrameBufferCentered(FrameBufferHandleStruct frameBuffer, int sizeX, int sizeY);
int getIconId(const std::string& name);
// Layout & panel
void sameline();
void separator();
void disablePanelPadding(bool);
void space();
void space_params(int x, int y);
int getAvailableSizeX();
int getAvailableSizeY();
bool isPanelActive();
// Input widgets
bool inputText(std::string& label, std::string&, std::string&);
bool checkbox(std::string& label, bool);
bool checkboxDisabled(std::string& label, bool);
@ -61,30 +69,31 @@ namespace Deer {
float magicSlider(std::string&, float, float);
glm::vec3 magicSlider3(std::string&, glm::vec3, float);
// Menus
bool menuItem(std::string&);
void menuItemDisabled(std::string&);
void subMenu(std::string&, asIScriptFunction*);
// Drag & Drop
void dragDropSource(std::string&, CScriptAny*, std::string&);
void dragDropTarget(std::string&, asIScriptFunction*);
// Mouse & keyboard input state
bool isItemClicked(int mouse);
bool isMouseDoubleClicked(int mouse);
bool isKeyDown(int);
bool isKeyPressed(int);
bool isMouseDragging(int);
float getMouseDragDeltaX();
float getMouseDragDeltaY();
float getMouseDeltaX();
float getMouseDeltaY();
bool isPanelActive();
bool isKeyDown(int);
bool isKeyPressed(int);
void space();
void space_params(int x, int y);
// Rendering helpers
void drawFrameBuffer(FrameBufferHandleStruct frameBuffer, int sizeX, int sizeY);
void drawFrameBufferCentered(FrameBufferHandleStruct frameBuffer, int sizeX, int sizeY);
int getIconId(const std::string& name);
} // namespace StudioAPI
} // namespace Deer

View File

@ -98,7 +98,7 @@ namespace Deer {
void AngelScriptEngine::registerStructs() {
registerMathStructs();
registerResourceStructs();
registerEnvironmentStructs();
registerEntityEnvironmentStructs();
registerEntityStructs();
registerEngineStructs();
registerFrameBufferStructs();
@ -109,7 +109,7 @@ namespace Deer {
registerUIFunctions();
registerMathFunctions();
registerResourceFunctions();
registerEnvironmentFunctions();
registerEntityEnvironmentFunctions();
registerEntityFunctions();
registerEngineFunctions();
registerFrameBufferFunctions();

View File

@ -33,7 +33,7 @@ namespace Deer {
void registerUIFunctions();
void registerMathFunctions();
void registerResourceFunctions();
void registerEnvironmentFunctions();
void registerEntityEnvironmentFunctions();
void registerEntityFunctions();
void registerEngineFunctions();
void registerFrameBufferFunctions();
@ -41,7 +41,7 @@ namespace Deer {
void registerMathStructs();
void registerUIStructs();
void registerResourceStructs();
void registerEnvironmentStructs();
void registerEntityEnvironmentStructs();
void registerEntityStructs();
void registerEngineStructs();
void registerFrameBufferStructs();

View File

@ -273,7 +273,7 @@ namespace Deer {
stream.clear();
stream.str("");
str.clear();
stream << "// This file is autogenerated";
stream << "// This file is autogenerated\n";
printFuncList(*scriptEngine);
printEnumList(*scriptEngine);

View File

@ -22,11 +22,9 @@ namespace Deer {
AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));
AS_CHECK(scriptEngine->RegisterFuncdef("void Callback()"));
AS_CHECK(scriptEngine->RegisterFuncdef("void AnyCallback(any@)"));
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunc(any@)"));
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunc(any@, any@)"));
AS_CHECK(scriptEngine->RegisterFuncdef("void SimpleFunction()"));
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunction(any@)"));
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunction(any@, any@)"));
}
void AngelScriptEngine::extractBaseTypes() {

View File

@ -1,22 +1,22 @@
#include "DeerStudio/StudioAPI/Environment.h"
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
namespace Deer {
void registerEnvironmentStructs();
void registerEnvironmentFunctions();
void registerEntityEnvironmentStructs();
void registerEntityEnvironmentFunctions();
void AngelScriptEngine::registerEnvironmentStructs() {
AS_CHECK(scriptEngine->RegisterObjectType("Environment", sizeof(StudioAPI::EnvironmentStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EnvironmentStruct>() | asOBJ_APP_CLASS_ALLINTS));
void AngelScriptEngine::registerEntityEnvironmentStructs() {
AS_CHECK(scriptEngine->RegisterObjectType("EntityEnvironment", sizeof(StudioAPI::EntityEnvironmentStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityEnvironmentStruct>() | asOBJ_APP_CLASS_ALLINTS));
}
void AngelScriptEngine::registerEnvironmentFunctions() {
void AngelScriptEngine::registerEntityEnvironmentFunctions() {
scriptEngine->SetDefaultNamespace("Resource");
REGISTER_GLOBAL_FUNC("Environment getMainEnvironment()", StudioAPI::getMainEnvironment);
REGISTER_GLOBAL_FUNC("Environment createLoadEnvironment(const string&in envId)", StudioAPI::createLoadEnvironment);
REGISTER_GLOBAL_FUNC("EntityEnvironment getMainEntityEnvironment()", StudioAPI::getMainEntityEnvironment);
REGISTER_GLOBAL_FUNC("EntityEnvironment createLoadEntityEnvironment(const string&in envId)", StudioAPI::createLoadEntityEnvironment);
scriptEngine->SetDefaultNamespace("");
REGISTER_OBJECT_METHOD("Environment", "void render(FrameBuffer, SceneCamera&in)", StudioAPI::EnvironmentStruct, render);
REGISTER_OBJECT_METHOD("Environment", "Entity getRootEntity()", StudioAPI::EnvironmentStruct, getRootEntity);
REGISTER_OBJECT_METHOD("Environment", "Entity getEntity(int)", StudioAPI::EnvironmentStruct, getEntity);
REGISTER_OBJECT_METHOD("EntityEnvironment", "void render(FrameBuffer, SceneCamera&in)", StudioAPI::EntityEnvironmentStruct, render);
REGISTER_OBJECT_METHOD("EntityEnvironment", "Entity getRootEntity()", StudioAPI::EntityEnvironmentStruct, getRootEntity);
REGISTER_OBJECT_METHOD("EntityEnvironment", "Entity getEntity(int)", StudioAPI::EntityEnvironmentStruct, getEntity);
}
} // namespace Deer

View File

@ -30,7 +30,7 @@ namespace Deer {
// Menus
REGISTER_GLOBAL_FUNC("bool menuItem(const string& in text)", StudioAPI::menuItem);
REGISTER_GLOBAL_FUNC("void menuItemDisabled(const string& in text)", StudioAPI::menuItemDisabled);
REGISTER_GLOBAL_FUNC("void subMenu(const string& in text, Callback@+ func)", StudioAPI::subMenu);
REGISTER_GLOBAL_FUNC("void subMenu(const string& in text, SimpleFunction@+ func)", StudioAPI::subMenu);
// Text
REGISTER_GLOBAL_FUNC("void text(const string& in text)", StudioAPI::text);
@ -90,25 +90,24 @@ namespace Deer {
// Tree & Components
REGISTER_GLOBAL_FUNC("void treeNodeLeaf(const string& in, bool)", StudioAPI::treeNodeLeaf);
REGISTER_GLOBAL_FUNC("bool treeNode(const string& in, bool, Callback@+)", StudioAPI::treeNode);
REGISTER_GLOBAL_FUNC("bool componentNode(const string& in, Callback@+)", StudioAPI::componentNode);
REGISTER_GLOBAL_FUNC("bool componentNodeContextMenu(const string& in, Callback@+, Callback@+)", StudioAPI::componentNodeContextMenu);
REGISTER_GLOBAL_FUNC("bool treeNode(const string& in, bool, SimpleFunction@+)", StudioAPI::treeNode);
REGISTER_GLOBAL_FUNC("bool componentNode(const string& in, SimpleFunction@+)", StudioAPI::componentNode);
REGISTER_GLOBAL_FUNC("bool componentNodeContextMenu(const string& in, SimpleFunction@+, SimpleFunction@+)", StudioAPI::componentNodeContextMenu);
// Popups & Modals
REGISTER_GLOBAL_FUNC("void contextItemPopup(const string& in, Callback@+)", StudioAPI::contextItemPopup);
REGISTER_GLOBAL_FUNC("void contextMenuPopup(const string& in, Callback@+)", StudioAPI::contextMenuPopup);
REGISTER_GLOBAL_FUNC("void modalPopup(const string& in, Callback@+)", StudioAPI::modalPopup);
REGISTER_GLOBAL_FUNC("void simplePopup(const string& in, Callback@+)", StudioAPI::simplePopup);
REGISTER_GLOBAL_FUNC("void contextItemPopup(const string& in, SimpleFunction@+)", StudioAPI::contextItemPopup);
REGISTER_GLOBAL_FUNC("void contextMenuPopup(const string& in, SimpleFunction@+)", StudioAPI::contextMenuPopup);
REGISTER_GLOBAL_FUNC("void modalPopup(const string& in, SimpleFunction@+)", StudioAPI::modalPopup);
REGISTER_GLOBAL_FUNC("void simplePopup(const string& in, SimpleFunction@+)", StudioAPI::simplePopup);
REGISTER_GLOBAL_FUNC("void openPopup(const string& in, any@)", StudioAPI::openPopup);
REGISTER_GLOBAL_FUNC("void closePopup()", StudioAPI::closePopup);
// Drag & Drop
REGISTER_GLOBAL_FUNC("void dragDropSource(const string& in, any@+, const string& in)", StudioAPI::dragDropSource);
REGISTER_GLOBAL_FUNC("void dragDropTarget(const string& in, AnyCallback@+)", StudioAPI::dragDropTarget);
REGISTER_GLOBAL_FUNC("void dragDropTarget(const string& in, ReciverFunction@+)", StudioAPI::dragDropTarget);
scriptEngine->SetDefaultNamespace("");
}
void AngelScriptEngine::registerUIStructs() {
AS_CHECK(scriptEngine->RegisterEnum("key"));
@ -181,5 +180,4 @@ namespace Deer {
AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseMiddle", ImGuiKey_MouseMiddle));
}
} // namespace Deer

View File

@ -9,7 +9,7 @@
#include <vector>
#define GET_ENV(env) ((env < 0) ? Scene::environment : Deer::Resource<Environment>::unsafeFromId(environmentId).getData())
#define GET_ENV(env) ((env < 0) ? Scene::environment : Deer::Resource<EntityEnvironment>::unsafeFromId(environmentId).getData())
#define GET_ENTITY(env, id) GET_ENV(env).getEntity(id)
#define GET_MESH_COMPONENT(env, id) \
@ -34,7 +34,7 @@
namespace Deer {
namespace StudioAPI {
extern std::vector<Scope<Environment>> environments;
extern std::vector<Scope<EntityEnvironment>> environments;
EntityHandleStruct getRoot() { return EntityStruct(0); }
@ -46,14 +46,14 @@ namespace Deer {
EntityStruct::EntityStruct(uint16_t _entId, int32_t _envId) : EntityHandleStruct(_entId, _envId) {}
Environment* EntityHandleStruct::getEntityEnvironment() {
EntityEnvironment* EntityHandleStruct::getEntityEntityEnvironment() {
if (environmentId < 0)
return &Scene::environment;
return &Resource<Environment>::unsafeFromId(environmentId).getData();
return &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
}
bool EntityHandleStruct::assertEntity(const char* funcName) {
Environment* env = getEntityEnvironment();
EntityEnvironment* env = getEntityEntityEnvironment();
if (!env->entityExists(entityId)) {
DEER_EDITOR_ENGINE_ERROR(
"Error, invalid entity calling {0}, entityId : {1}, environmentId : {2}",
@ -196,11 +196,11 @@ namespace Deer {
if (!assertEntity(funcName))
return false;
Environment* env;
EntityEnvironment* env;
if (environmentId < 0)
env = &Scene::environment;
else
env = &Resource<Environment>::unsafeFromId(environmentId).getData();
env = &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
Entity& ent = env->getEntity(entityId);
@ -241,7 +241,7 @@ namespace Deer {
EntityHandleStruct EntityStruct::createChild(std::string& name) {
ASSERT_ENTITY("createChild()", return *this);
Environment* entityEnv = getEntityEnvironment();
EntityEnvironment* entityEnv = getEntityEntityEnvironment();
Entity& newEnt = entityEnv->createEntity(name);
Entity& me = GET_ENTITY(environmentId, entityId);
@ -437,7 +437,7 @@ namespace Deer {
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
if (!assertEntity(funcName))
return false;
Environment* env = getEntityEnvironment();
EntityEnvironment* env = getEntityEntityEnvironment();
Entity& ent = env->getEntity(entityId);
@ -488,7 +488,7 @@ namespace Deer {
bool CameraComponentStruct::assertCameraComponent(const char* funcName) {
if (!assertEntity(funcName))
return false;
Environment* env = getEntityEnvironment();
EntityEnvironment* env = getEntityEntityEnvironment();
Entity& ent = env->getEntity(entityId);

View File

@ -1,9 +1,9 @@
#include "DeerRender/Enviroment.h"
#include "DeerRender/Resource.h"
#include "DeerRender/Scene.h"
#include "DeerRender/Tools/Memory.h"
#include "DeerRender/Resource.h"
#include "DeerStudio/StudioAPI/Environment.h"
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
#include "DeerRender/FrameBuffer.h"
#include "DeerRender/Scene.h"
@ -13,21 +13,21 @@
namespace Deer {
namespace StudioAPI {
// The first element has to allways point to the main scene env
std::vector<Environment*> environments{&Scene::environment};
std::vector<EntityEnvironment*> environments{&Scene::environment};
void EnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, SceneCamera& sc) {
void EntityEnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, SceneCamera& sc) {
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBuffer_handle.frameBufferId);
FrameBuffer& frameBuffer = frameBufferResource.getData();
Environment* envPtr = nullptr;
EntityEnvironment* envPtr = nullptr;
if (environmentId < 0) {
envPtr = &Scene::environment;
} else {
Resource<Environment> environmentResource = Resource<Environment>::unsafeFromId(environmentId);
Resource<EntityEnvironment> environmentResource = Resource<EntityEnvironment>::unsafeFromId(environmentId);
envPtr = &environmentResource.getData();
}
Environment& env = *envPtr;
EntityEnvironment& env = *envPtr;
frameBuffer.bind();
@ -37,24 +37,23 @@ namespace Deer {
frameBuffer.unbind();
}
EntityHandleStruct EnvironmentStruct::getRootEntity() {
EntityHandleStruct EntityEnvironmentStruct::getRootEntity() {
return EntityHandleStruct(0, environmentId);
}
EntityHandleStruct EnvironmentStruct::getEntity(int id) {
EntityHandleStruct EntityEnvironmentStruct::getEntity(int id) {
return EntityHandleStruct(id, environmentId);
}
EnvironmentHandleStruct getMainEnvironment() {
return EnvironmentHandleStruct(-1);
EntityEnvironmentHandleStruct getMainEntityEnvironment() {
return EntityEnvironmentHandleStruct(-1);
}
EnvironmentHandleStruct createLoadEnvironment(std::string& envId) {
EnvironmentData envData;
Resource<Environment> environmentResource = ResourceManager<Environment>::loadResourceFromData(envData, envId);
return EnvironmentHandleStruct(environmentResource.getResourceId());
EntityEnvironmentHandleStruct createLoadEntityEnvironment(std::string& envId) {
EntityEnvironmentData envData;
Resource<EntityEnvironment> environmentResource = ResourceManager<EntityEnvironment>::loadResourceFromData(envData, envId);
return EntityEnvironmentHandleStruct(environmentResource.getResourceId());
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -11,7 +11,7 @@ class ActiveEntity : Service {
}
void init() {
entity = Resource::getMainEnvironment().getRootEntity();
entity = Resource::getMainEntityEnvironment().getRootEntity();
}
[Expose]

View File

@ -7,7 +7,7 @@ class AddComponentRender {
void addComponentPopup() {
UI::titleCenter("\uf055 Add Component");
UI::separator();
UI::subMenu("Rendering", Callback(this.addComponentRendering));
UI::subMenu("Rendering", SimpleFunction(this.addComponentRendering));
if (UI::menuItem("Script Component")) {
}
}

View File

@ -17,7 +17,7 @@ class MeshComponentRender {
UI::drawIcon("empty.png", 32);
}
UI::dragDropTarget("MESH", AnyCallback(this.setMesh));
UI::dragDropTarget("MESH", ReciverFunction(this.setMesh));
if (meshComponent.hasMesh) {
UI::sameline();
@ -25,7 +25,7 @@ class MeshComponentRender {
UI::sameline();
UI::titleCenterY(meshComponent.meshResource.name, 32);
UI::dragDropTarget("MESH", AnyCallback(this.setMesh));
UI::dragDropTarget("MESH", ReciverFunction(this.setMesh));
}
UI::space(20, 20);

View File

@ -10,7 +10,7 @@ class PropertiesPanel : Panel {
// Id:0 [+ add component]
UI::title("\uf1b2 " + entity.name);
if (!entity.isRoot)
UI::contextItemPopup("##MenuOptions", Callback(this.renameEntityMenu));
UI::contextItemPopup("##MenuOptions", SimpleFunction(this.renameEntityMenu));
UI::separator();
UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id);
@ -26,21 +26,21 @@ class PropertiesPanel : Panel {
UI::space();
TransformPropertiesRender transformComponentRender(entity);
UI::componentNode("\uf0b2 Transform Component", Callback(transformComponentRender.renderTransformComponent));
UI::componentNode("\uf0b2 Transform Component", SimpleFunction(transformComponentRender.renderTransformComponent));
if (entity.hasMeshComponent()) {
MeshComponentRender meshComponentRender(entity);
UI::componentNodeContextMenu("\uf248 Mesh Component", Callback(meshComponentRender.render), Callback(meshComponentRender.remove));
UI::componentNodeContextMenu("\uf248 Mesh Component", SimpleFunction(meshComponentRender.render), SimpleFunction(meshComponentRender.remove));
}
if (entity.hasShaderComponent()) {
ShaderComponentRender shaderComponentRender(entity);
UI::componentNodeContextMenu("\uf248 Shader Component", Callback(shaderComponentRender.render), Callback(shaderComponentRender.remove));
UI::componentNodeContextMenu("\uf248 Shader Component", SimpleFunction(shaderComponentRender.render), SimpleFunction(shaderComponentRender.remove));
}
if (entity.hasCameraComponent()) {
CameraComponentRender cameraComponentRender(entity);
UI::componentNodeContextMenu("\uf030 Camera Component", Callback(cameraComponentRender.render), Callback(cameraComponentRender.remove));
UI::componentNodeContextMenu("\uf030 Camera Component", SimpleFunction(cameraComponentRender.render), SimpleFunction(cameraComponentRender.remove));
}
UI::space();
@ -52,8 +52,8 @@ class PropertiesPanel : Panel {
}
AddComponentRender addComponentRender(entity);
UI::simplePopup("ADD_COMPONENT", Callback(addComponentRender.addComponentPopup));
UI::modalPopup("Rename entity", Callback(this.renameEntityMenu));
UI::simplePopup("ADD_COMPONENT", SimpleFunction(addComponentRender.addComponentPopup));
UI::modalPopup("Rename entity", SimpleFunction(this.renameEntityMenu));
}
void renameEntityMenu() {

View File

@ -31,7 +31,7 @@ class ShaderComponentRender {
} else {
UI::drawIcon("empty.png", 32);
}
UI::dragDropTarget("SHADER", AnyCallback(this.setShader));
UI::dragDropTarget("SHADER", ReciverFunction(this.setShader));
if (shaderComponent.hasShader) {
UI::sameline();
@ -39,7 +39,7 @@ class ShaderComponentRender {
UI::sameline();
UI::titleCenterY(shaderComponent.shader.name, 32);
UI::dragDropTarget("SHADER", AnyCallback(this.setShader));
UI::dragDropTarget("SHADER", ReciverFunction(this.setShader));
}
UI::space();
@ -49,7 +49,7 @@ class ShaderComponentRender {
} else {
UI::drawIcon("empty.png", 32);
}
UI::dragDropTarget("TEXTURE", AnyCallback(this.setTexture));
UI::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
if (shaderComponent.texture.isValid()) {
UI::sameline();
@ -57,7 +57,7 @@ class ShaderComponentRender {
UI::sameline();
UI::titleCenterY(shaderComponent.texture.name, 32);
UI::dragDropTarget("TEXTURE", AnyCallback(this.setTexture));
UI::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
}
UI::space(20, 20);

View File

@ -1,11 +1,11 @@
class RenderService : Service {
Environment env;
EntityEnvir nment env;
SceneCamera sceneCamera;
MeshComponent meshC;
Entity child;
void init() {
env = Resource::createLoadEnvironment("PreviewerEnv");
env = Resource::createLoadEntityEnvironment("PreviewerEnv");
child = env.getRootEntity().createChild("Render");
meshC = child.createMeshComponent();

View File

@ -1,8 +0,0 @@
class Test : Service {
void init() {
Engine::print("Initing");
Entity entity = ActiveEntity::getActiveEntity();
Engine::print(entity.name);
Engine::print("Ending");
}
}

View File

@ -1,5 +0,0 @@
{
"patch": 1,
"name": "Test",
"requires": ["ActiveEntity"]
}

View File

@ -23,7 +23,7 @@ class EntityTreeRender {
interaction();
} else {
// ADD ANOTHER NODE
bool opened = UI::treeNode(displayName, isActiveEntity(), Callback(this.renderChilds));
bool opened = UI::treeNode(displayName, isActiveEntity(), SimpleFunction(this.renderChilds));
if (!opened) {
interaction();
}
@ -40,8 +40,8 @@ class EntityTreeRender {
void interaction() {
UI::dragDropSource("ENTITY", any(entity), entity.name);
UI::dragDropTarget("ENTITY", AnyCallback(this.entityDrop));
UI::contextItemPopup("POP_ENTITY_" + entity.id, Callback(this.renderContextMenu));
UI::dragDropTarget("ENTITY", ReciverFunction(this.entityDrop));
UI::contextItemPopup("POP_ENTITY_" + entity.id, SimpleFunction(this.renderContextMenu));
if (UI::isItemClicked(0)) {
ActiveEntity::setActiveEntity(entity);
@ -86,7 +86,7 @@ class TreePanel : Panel {
Entity root = Engine::getRoot();
EntityTreeRender rootTree(root);
UI::contextMenuPopup("Window popup", Callback(rootTree.renderContextMenu));
UI::contextMenuPopup("Window popup", SimpleFunction(rootTree.renderContextMenu));
rootTree.renderEntity();
}
}

View File

@ -1,7 +1,7 @@
class ViewportPanel : Panel {
FrameBuffer frameBuffer;
SceneCamera sceneCamera;
Environment mainEnv;
EntityEnvir nment mainEnv;
float pitch = 0;
float yaw = 0;
@ -70,7 +70,7 @@ class ViewportPanel : Panel {
void init() {
frameBuffer = Resource::createLoadRGBA8FrameBuffer("MainFrameBuffer", 1000, 1000);
mainEnv = Resource::getMainEnvironment();
mainEnv = Resource::getMainEntityEnvironment();
sceneCamera.transform.position = vec3(0, 1, -2);
sceneCamera.camera.nearZ = 0.1;
@ -87,7 +87,7 @@ class ViewportPanel : Panel {
UI::openPopup("ViewportCameraProps", any());
}
UI::simplePopup("ViewportCameraProps", Callback(this.viewportCameraProps));
UI::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps));
}
void viewportCameraProps() {