Compare commits
2 Commits
67b316a70b
...
9e6ee7b2e2
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e6ee7b2e2 | |||
| f246d0e227 |
@ -8,7 +8,7 @@
|
||||
|
||||
#ifdef DEER_RENDER
|
||||
#include "DeerRender/Render/FrameBuffer.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/World.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
@ -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();
|
||||
@ -63,7 +63,7 @@ namespace Deer {
|
||||
// Obtains the entity that is on the root of the environment
|
||||
inline Entity& getRoot() { return getEntity(0); }
|
||||
#ifdef DEER_RENDER
|
||||
void render(const SceneCamera& camera);
|
||||
void render(const WorldCamera& camera);
|
||||
#endif
|
||||
Scope<entt::registry> m_registry;
|
||||
|
||||
@ -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>
|
||||
@ -2,14 +2,12 @@
|
||||
#include "DeerCore/Tools/TypeDefs.h"
|
||||
|
||||
namespace Deer {
|
||||
class Environment;
|
||||
class SceneCamera;
|
||||
class EntityEnvironment;
|
||||
class WorldCamera;
|
||||
class GizmoRenderer;
|
||||
|
||||
// A scene is a 3d simulation with its environment and voxel world in case
|
||||
// of initialized, here things can be simulated
|
||||
namespace Scene {
|
||||
// Clears all the assets and memory the Scene had conained
|
||||
namespace World {
|
||||
// Clears all the assets and memory the World had conained
|
||||
void clear();
|
||||
|
||||
// This is the cycle to execution of scripts and physics
|
||||
@ -23,10 +21,10 @@ namespace Deer {
|
||||
#ifdef DEER_RENDER
|
||||
// This function renders with the default camera in the environment
|
||||
void render();
|
||||
void render(const SceneCamera&);
|
||||
void render(const WorldCamera&);
|
||||
|
||||
extern GizmoRenderer gizmoRenderer;
|
||||
#endif
|
||||
extern Environment environment;
|
||||
} // namespace Scene
|
||||
extern EntityEnvironment environment;
|
||||
} // namespace World
|
||||
} // namespace Deer
|
||||
2
Deer/Include/DeerRender/EntityEnviroment.h
Normal file
2
Deer/Include/DeerRender/EntityEnviroment.h
Normal file
@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
@ -1,2 +0,0 @@
|
||||
#pragma once
|
||||
#include "DeerCore/Enviroment.h"
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "DeerRender/EntityEnviroment.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
|
||||
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include "DeerCore/Scene.h"
|
||||
#include "DeerCore/World.h"
|
||||
#include "DeerRender/Components.h"
|
||||
|
||||
namespace Deer {
|
||||
struct SceneCamera {
|
||||
struct WorldCamera {
|
||||
TransformComponent transform;
|
||||
CameraComponent camera;
|
||||
|
||||
SceneCamera() {}
|
||||
SceneCamera(TransformComponent _transform, CameraComponent _camera) : transform(_transform), camera(_camera) {}
|
||||
WorldCamera() {}
|
||||
WorldCamera(TransformComponent _transform, CameraComponent _camera) : transform(_transform), camera(_camera) {}
|
||||
};
|
||||
} // namespace Deer
|
||||
@ -1,8 +0,0 @@
|
||||
#include "DeerCore/Enviroment.h"
|
||||
|
||||
namespace Deer {
|
||||
Scope<Environment> ResourceBuilder<Environment>::buildResource(const BaseDataType& baseData) {
|
||||
Scope<Environment> env = MakeScope<Environment>();
|
||||
return env;
|
||||
}
|
||||
} // namespace Deer
|
||||
@ -1,10 +0,0 @@
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/Tools/Memory.h"
|
||||
|
||||
namespace Deer {
|
||||
namespace Scene {
|
||||
Environment environment;
|
||||
bool isExecuting = false;
|
||||
} // namespace Scene
|
||||
|
||||
} // namespace Deer
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "cereal/cereal.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
|
||||
// Serialization Vars
|
||||
#include "DeerCore/Scene/Serialization/SerializationGlobalVars.h"
|
||||
|
||||
// GENERICS
|
||||
#include "DeerCore/Scene/Serialization/QuatSerialization.h"
|
||||
#include "DeerCore/Scene/Serialization/Vec3Serialization.h"
|
||||
|
||||
// SCENE SPECIFIC
|
||||
#include "DeerCore/Scene/Serialization/EntitySerialization.h"
|
||||
#include "DeerCore/Scene/Serialization/EnvironmentSerialization.h"
|
||||
|
||||
// COMPONENTS SPECIFIC
|
||||
#include "DeerCore/Scene/Serialization/Components/RelationshipComponentSerialization.h"
|
||||
#include "DeerCore/Scene/Serialization/Components/TransformComponentSerialization.h"
|
||||
|
||||
// RENDER SPECIFIC
|
||||
#ifdef DEER_RENDER
|
||||
#include "DeerRender/Scene/Serialization/Components/CameraSerializationComponent.h"
|
||||
#include "DeerRender/Scene/Serialization/Components/MeshRenderComponentSerialization.h"
|
||||
#include "DeerRender/Scene/Serialization/Components/TextureBindingSerializationComponent.h"
|
||||
#endif
|
||||
@ -1,9 +1,9 @@
|
||||
#include "DeerCore/Components.h"
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
#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) {}
|
||||
@ -1,4 +1,4 @@
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
|
||||
#include "DeerCore/Application.h"
|
||||
#include "DeerCore/Components.h"
|
||||
@ -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;
|
||||
|
||||
8
Deer/src/DeerCore/World/EnvironmentBuilder.cpp
Normal file
8
Deer/src/DeerCore/World/EnvironmentBuilder.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
|
||||
namespace Deer {
|
||||
Scope<EntityEnvironment> ResourceBuilder<EntityEnvironment>::buildResource(const BaseDataType& baseData) {
|
||||
Scope<EntityEnvironment> env = MakeScope<EntityEnvironment>();
|
||||
return env;
|
||||
}
|
||||
} // namespace Deer
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "DeerCore/Components.h"
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/Scene/Serialization/SerializationGlobalVars.h"
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
#include "DeerCore/World/Serialization/SerializationGlobalVars.h"
|
||||
#include "EntitySerializationStruct.h"
|
||||
|
||||
namespace Deer {
|
||||
@ -2,9 +2,9 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace Deer {
|
||||
class Environment;
|
||||
class EntityEnvironment;
|
||||
struct EntitySerializationStruct {
|
||||
uint16_t entityID;
|
||||
Environment* env;
|
||||
EntityEnvironment* env;
|
||||
};
|
||||
} // namespace Deer
|
||||
@ -2,29 +2,29 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
#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));
|
||||
|
||||
27
Deer/src/DeerCore/World/Serialization/Serialization.h
Executable file
27
Deer/src/DeerCore/World/Serialization/Serialization.h
Executable file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "cereal/cereal.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
|
||||
// Serialization Vars
|
||||
#include "DeerCore/World/Serialization/SerializationGlobalVars.h"
|
||||
|
||||
// GENERICS
|
||||
#include "DeerCore/World/Serialization/QuatSerialization.h"
|
||||
#include "DeerCore/World/Serialization/Vec3Serialization.h"
|
||||
|
||||
// SCENE SPECIFIC
|
||||
#include "DeerCore/World/Serialization/EntityEnvironmentSerialization.h"
|
||||
#include "DeerCore/World/Serialization/EntitySerialization.h"
|
||||
|
||||
// COMPONENTS SPECIFIC
|
||||
#include "DeerCore/World/Serialization/Components/RelationshipComponentSerialization.h"
|
||||
#include "DeerCore/World/Serialization/Components/TransformComponentSerialization.h"
|
||||
|
||||
// RENDER SPECIFIC
|
||||
#ifdef DEER_RENDER
|
||||
#include "DeerRender/World/Serialization/Components/CameraSerializationComponent.h"
|
||||
#include "DeerRender/World/Serialization/Components/MeshRenderComponentSerialization.h"
|
||||
#include "DeerRender/World/Serialization/Components/TextureBindingSerializationComponent.h"
|
||||
#endif
|
||||
@ -1,10 +1,10 @@
|
||||
#include "DeerCore/Scene.h"
|
||||
#include "DeerCore/World.h"
|
||||
|
||||
#include "DeerCore/Components.h"
|
||||
#include "DeerCore/Enviroment.h"
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
#include "DeerCore/Log.h"
|
||||
#include "DeerCore/Scene/SceneData.h"
|
||||
#include "DeerCore/Tools/Memory.h"
|
||||
#include "DeerCore/World/WorldData.h"
|
||||
|
||||
#ifdef DEER_RENDER
|
||||
#include "DeerRender/FrameBuffer.h"
|
||||
@ -13,29 +13,30 @@
|
||||
#endif
|
||||
|
||||
namespace Deer {
|
||||
void Scene::clear() {
|
||||
void World::clear() {
|
||||
environment.clear();
|
||||
|
||||
#ifdef DEER_RENDER
|
||||
ResourceManager<Shader>::unloadResources();
|
||||
ResourceManager<GPUMesh>::unloadResources();
|
||||
ResourceManager<FrameBuffer>::unloadResources();
|
||||
ResourceManager<Texture>::unloadResources();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Scene::getExecutingState() {
|
||||
bool World::getExecutingState() {
|
||||
return isExecuting;
|
||||
}
|
||||
|
||||
void Scene::initExecution() {
|
||||
void World::initExecution() {
|
||||
DEER_CORE_ASSERT(!isExecuting, "Deer scene is already executing");
|
||||
isExecuting = true;
|
||||
}
|
||||
|
||||
void Scene::tickExecution() {
|
||||
void World::tickExecution() {
|
||||
}
|
||||
|
||||
void Scene::endExecution() {
|
||||
void World::endExecution() {
|
||||
DEER_CORE_ASSERT(isExecuting, "Deer scene is not executing");
|
||||
isExecuting = false;
|
||||
}
|
||||
10
Deer/src/DeerCore/World/WorldData.cpp
Normal file
10
Deer/src/DeerCore/World/WorldData.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "DeerCore/EntityEnviroment.h"
|
||||
#include "DeerCore/Tools/Memory.h"
|
||||
|
||||
namespace Deer {
|
||||
namespace World {
|
||||
EntityEnvironment environment;
|
||||
bool isExecuting = false;
|
||||
} // namespace World
|
||||
|
||||
} // namespace Deer
|
||||
@ -2,11 +2,11 @@
|
||||
#include "DeerCore/Tools/Memory.h"
|
||||
|
||||
namespace Deer {
|
||||
class Environment;
|
||||
class EntityEnvironment;
|
||||
|
||||
namespace Scene {
|
||||
extern Environment environment;
|
||||
namespace World {
|
||||
extern EntityEnvironment environment;
|
||||
extern bool isExecuting;
|
||||
} // namespace Scene
|
||||
} // namespace World
|
||||
|
||||
} // namespace Deer
|
||||
@ -1,4 +1,4 @@
|
||||
#include "DeerRender/Enviroment.h"
|
||||
#include "DeerRender/EntityEnviroment.h"
|
||||
|
||||
#include "DeerRender/Application.h"
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include "DeerRender/Log.h"
|
||||
|
||||
namespace Deer {
|
||||
void Environment::render(const SceneCamera& camera) {
|
||||
void EntityEnvironment::render(const WorldCamera& 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));
|
||||
@ -1,25 +1,25 @@
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
#include "DeerRender/Components.h"
|
||||
#include "DeerRender/Enviroment.h"
|
||||
#include "DeerRender/EntityEnviroment.h"
|
||||
#include "DeerRender/Render/RenderCommand.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
namespace Deer {
|
||||
void Scene::render() {
|
||||
void World::render() {
|
||||
uint32_t mainCamera = environment.tryGetMainCamera();
|
||||
if (mainCamera == 0)
|
||||
return;
|
||||
|
||||
Entity& m_cameraEntity = environment.getEntity(mainCamera);
|
||||
SceneCamera sceneCamera;
|
||||
WorldCamera sceneCamera;
|
||||
sceneCamera.camera = m_cameraEntity.getComponent<CameraComponent>();
|
||||
sceneCamera.transform = m_cameraEntity.getComponent<TransformComponent>();
|
||||
|
||||
Scene::render(sceneCamera);
|
||||
World::render(sceneCamera);
|
||||
}
|
||||
|
||||
void Scene::render(const SceneCamera& sceneCamera) {
|
||||
void World::render(const WorldCamera& sceneCamera) {
|
||||
RenderCommand::setDepthBuffer(true);
|
||||
environment.render(sceneCamera);
|
||||
|
||||
20
DeerStudio/headers/DeerStudio/StudioAPI/EntityEnvironment.h
Normal file
20
DeerStudio/headers/DeerStudio/StudioAPI/EntityEnvironment.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "GenericRefStructs.h"
|
||||
#include <string>
|
||||
// #include "DeerRender/World.h"
|
||||
|
||||
namespace Deer {
|
||||
class WorldCamera;
|
||||
|
||||
namespace StudioAPI {
|
||||
struct EntityEnvironmentStruct : EntityEnvironmentHandleStruct {
|
||||
void render(FrameBufferHandleStruct, WorldCamera&);
|
||||
|
||||
EntityHandleStruct getRootEntity();
|
||||
EntityHandleStruct getEntity(int);
|
||||
};
|
||||
|
||||
EntityEnvironmentHandleStruct getMainEntityEnvironment();
|
||||
EntityEnvironmentHandleStruct createLoadEntityEnvironment(std::string& envId);
|
||||
} // namespace StudioAPI
|
||||
} // namespace Deer
|
||||
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include "GenericRefStructs.h"
|
||||
#include <string>
|
||||
// #include "DeerRender/Scene.h"
|
||||
|
||||
namespace Deer {
|
||||
class SceneCamera;
|
||||
|
||||
namespace StudioAPI {
|
||||
struct EnvironmentStruct : EnvironmentHandleStruct {
|
||||
void render(FrameBufferHandleStruct, SceneCamera&);
|
||||
|
||||
EntityHandleStruct getRootEntity();
|
||||
EntityHandleStruct getEntity(int);
|
||||
};
|
||||
|
||||
EnvironmentHandleStruct getMainEnvironment();
|
||||
EnvironmentHandleStruct createLoadEnvironment(std::string& envId);
|
||||
} // namespace StudioAPI
|
||||
} // namespace Deer
|
||||
@ -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 {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include "glm/gtc/quaternion.hpp"
|
||||
|
||||
#include "DeerRender/Components.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
namespace Deer {
|
||||
namespace StudioAPI {
|
||||
@ -26,7 +26,7 @@ namespace Deer {
|
||||
|
||||
void transform_construct(TransformComponent*);
|
||||
void camera_construct(CameraComponent*);
|
||||
void sceneCamera_Construct(SceneCamera*);
|
||||
void sceneCamera_Construct(WorldCamera*);
|
||||
|
||||
glm::vec3 transform_relative(glm::vec3, TransformComponent*);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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, WorldCamera&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
|
||||
@ -27,9 +27,9 @@ namespace Deer {
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ)));
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ)));
|
||||
|
||||
AS_CHECK(scriptEngine->RegisterObjectType("SceneCamera", sizeof(SceneCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<SceneCamera>()));
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("SceneCamera", "Camera camera", asOFFSET(SceneCamera, camera)));
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("SceneCamera", "Transform transform", asOFFSET(SceneCamera, transform)));
|
||||
AS_CHECK(scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>()));
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera)));
|
||||
AS_CHECK(scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform)));
|
||||
}
|
||||
|
||||
void AngelScriptEngine::registerMathFunctions() {
|
||||
@ -49,7 +49,7 @@ namespace Deer {
|
||||
|
||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("Transform", "void f()", StudioAPI::transform_construct);
|
||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("Camera", "void f()", StudioAPI::camera_construct);
|
||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("SceneCamera", "void f()", StudioAPI::sceneCamera_Construct);
|
||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("WorldCamera", "void f()", StudioAPI::sceneCamera_Construct);
|
||||
|
||||
REGISTER_EXT_OBJECT_METHOD("Transform", "vec3 relative(vec3)", StudioAPI::transform_relative);
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -2,8 +2,8 @@
|
||||
#include "DeerStudio/AngelScriptEngine.h"
|
||||
|
||||
#include "DeerRender/DataStore.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/Tools/Path.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
#include "DeerRender/Application.h"
|
||||
|
||||
@ -44,7 +44,7 @@ namespace Deer {
|
||||
AngelScriptEngine::deinitialize();
|
||||
RenderUtils::deinitializeRenderUtils();
|
||||
|
||||
Scene::clear();
|
||||
World::clear();
|
||||
|
||||
Application::shutdownWindow();
|
||||
Log::shutdown();
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
#include "DeerStudio/AngelScriptEngine.h"
|
||||
|
||||
#include "DeerRender/Components.h"
|
||||
#include "DeerRender/Enviroment.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/EntityEnviroment.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
#include "DeerRender/Resource.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define GET_ENV(env) ((env < 0) ? Scene::environment : Deer::Resource<Environment>::unsafeFromId(environmentId).getData())
|
||||
#define GET_ENV(env) ((env < 0) ? World::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 &World::environment;
|
||||
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}",
|
||||
@ -93,7 +93,7 @@ namespace Deer {
|
||||
bool EntityStruct::exists() {
|
||||
ASSERT_ENTITY("exists()", return false);
|
||||
|
||||
return Scene::environment.entityExists(entityId);
|
||||
return World::environment.entityExists(entityId);
|
||||
}
|
||||
|
||||
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
||||
@ -196,11 +196,11 @@ namespace Deer {
|
||||
if (!assertEntity(funcName))
|
||||
return false;
|
||||
|
||||
Environment* env;
|
||||
EntityEnvironment* env;
|
||||
if (environmentId < 0)
|
||||
env = &Scene::environment;
|
||||
env = &World::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);
|
||||
|
||||
|
||||
59
DeerStudio/src/DeerStudio/StudioAPI/EntityEnvironment.cpp
Normal file
59
DeerStudio/src/DeerStudio/StudioAPI/EntityEnvironment.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "DeerRender/EntityEnviroment.h"
|
||||
#include "DeerRender/Resource.h"
|
||||
#include "DeerRender/Tools/Memory.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
|
||||
|
||||
#include "DeerRender/FrameBuffer.h"
|
||||
#include "DeerRender/World.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Deer {
|
||||
namespace StudioAPI {
|
||||
// The first element has to allways point to the main scene env
|
||||
std::vector<EntityEnvironment*> environments{&World::environment};
|
||||
|
||||
void EntityEnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, WorldCamera& sc) {
|
||||
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBuffer_handle.frameBufferId);
|
||||
FrameBuffer& frameBuffer = frameBufferResource.getData();
|
||||
|
||||
EntityEnvironment* envPtr = nullptr;
|
||||
if (environmentId < 0) {
|
||||
envPtr = &World::environment;
|
||||
} else {
|
||||
Resource<EntityEnvironment> environmentResource = Resource<EntityEnvironment>::unsafeFromId(environmentId);
|
||||
envPtr = &environmentResource.getData();
|
||||
}
|
||||
|
||||
EntityEnvironment& env = *envPtr;
|
||||
|
||||
frameBuffer.bind();
|
||||
|
||||
// TODO
|
||||
env.render(sc);
|
||||
|
||||
frameBuffer.unbind();
|
||||
}
|
||||
|
||||
EntityHandleStruct EntityEnvironmentStruct::getRootEntity() {
|
||||
return EntityHandleStruct(0, environmentId);
|
||||
}
|
||||
|
||||
EntityHandleStruct EntityEnvironmentStruct::getEntity(int id) {
|
||||
return EntityHandleStruct(id, environmentId);
|
||||
}
|
||||
|
||||
EntityEnvironmentHandleStruct getMainEntityEnvironment() {
|
||||
return EntityEnvironmentHandleStruct(-1);
|
||||
}
|
||||
|
||||
EntityEnvironmentHandleStruct createLoadEntityEnvironment(std::string& envId) {
|
||||
EntityEnvironmentData envData;
|
||||
Resource<EntityEnvironment> environmentResource = ResourceManager<EntityEnvironment>::loadResourceFromData(envData, envId);
|
||||
|
||||
return EntityEnvironmentHandleStruct(environmentResource.getResourceId());
|
||||
}
|
||||
} // namespace StudioAPI
|
||||
} // namespace Deer
|
||||
@ -1,60 +0,0 @@
|
||||
#include "DeerRender/Enviroment.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
#include "DeerRender/Tools/Memory.h"
|
||||
#include "DeerRender/Resource.h"
|
||||
|
||||
#include "DeerStudio/StudioAPI/Environment.h"
|
||||
|
||||
#include "DeerRender/FrameBuffer.h"
|
||||
#include "DeerRender/Scene.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Deer {
|
||||
namespace StudioAPI {
|
||||
// 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) {
|
||||
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBuffer_handle.frameBufferId);
|
||||
FrameBuffer& frameBuffer = frameBufferResource.getData();
|
||||
|
||||
Environment* envPtr = nullptr;
|
||||
if (environmentId < 0) {
|
||||
envPtr = &Scene::environment;
|
||||
} else {
|
||||
Resource<Environment> environmentResource = Resource<Environment>::unsafeFromId(environmentId);
|
||||
envPtr = &environmentResource.getData();
|
||||
}
|
||||
|
||||
Environment& env = *envPtr;
|
||||
|
||||
frameBuffer.bind();
|
||||
|
||||
// TODO
|
||||
env.render(sc);
|
||||
|
||||
frameBuffer.unbind();
|
||||
}
|
||||
|
||||
EntityHandleStruct EnvironmentStruct::getRootEntity() {
|
||||
return EntityHandleStruct(0, environmentId);
|
||||
}
|
||||
|
||||
EntityHandleStruct EnvironmentStruct::getEntity(int id) {
|
||||
return EntityHandleStruct(id, environmentId);
|
||||
}
|
||||
|
||||
EnvironmentHandleStruct getMainEnvironment() {
|
||||
return EnvironmentHandleStruct(-1);
|
||||
}
|
||||
|
||||
EnvironmentHandleStruct createLoadEnvironment(std::string& envId) {
|
||||
EnvironmentData envData;
|
||||
Resource<Environment> environmentResource = ResourceManager<Environment>::loadResourceFromData(envData, envId);
|
||||
|
||||
return EnvironmentHandleStruct(environmentResource.getResourceId());
|
||||
|
||||
}
|
||||
} // namespace StudioAPI
|
||||
} // namespace Deer
|
||||
@ -49,8 +49,8 @@ namespace Deer {
|
||||
void camera_construct(CameraComponent* mem) {
|
||||
new (mem) CameraComponent();
|
||||
}
|
||||
void sceneCamera_Construct(SceneCamera* mem) {
|
||||
new (mem) SceneCamera();
|
||||
void sceneCamera_Construct(WorldCamera* mem) {
|
||||
new (mem) WorldCamera();
|
||||
}
|
||||
|
||||
} // namespace StudioAPI
|
||||
|
||||
@ -11,7 +11,7 @@ class ActiveEntity : Service {
|
||||
}
|
||||
|
||||
void init() {
|
||||
entity = Resource::getMainEnvironment().getRootEntity();
|
||||
entity = Resource::getMainEntityEnvironment().getRootEntity();
|
||||
}
|
||||
|
||||
[Expose]
|
||||
|
||||
@ -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")) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
class RenderService : Service {
|
||||
Environment env;
|
||||
SceneCamera sceneCamera;
|
||||
EntityEnvir nment env;
|
||||
WorldCamera sceneCamera;
|
||||
MeshComponent meshC;
|
||||
Entity child;
|
||||
|
||||
void init() {
|
||||
env = Resource::createLoadEnvironment("PreviewerEnv");
|
||||
env = Resource::createLoadEntityEnvironment("PreviewerEnv");
|
||||
|
||||
child = env.getRootEntity().createChild("Render");
|
||||
meshC = child.createMeshComponent();
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
class Test : Service {
|
||||
void init() {
|
||||
Engine::print("Initing");
|
||||
Entity entity = ActiveEntity::getActiveEntity();
|
||||
Engine::print(entity.name);
|
||||
Engine::print("Ending");
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"patch": 1,
|
||||
"name": "Test",
|
||||
"requires": ["ActiveEntity"]
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class ViewportPanel : Panel {
|
||||
FrameBuffer frameBuffer;
|
||||
SceneCamera sceneCamera;
|
||||
Environment mainEnv;
|
||||
WorldCamera sceneCamera;
|
||||
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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user