Finished refactoring

This commit is contained in:
Chewico 2026-02-05 21:38:30 +01:00
parent 5d3fc40d74
commit 2d15ff8c07
83 changed files with 1208 additions and 2686 deletions

View File

@ -18,10 +18,16 @@
namespace Deer { namespace Deer {
class ComponentScriptInstance; class ComponentScriptInstance;
enum class EntityNetworkBehaviour : uint32_t {
PARENT = 0,
SERVER = 1 << 0,
CLIENT = 1 << 1
};
struct TagComponent { struct TagComponent {
std::string tag; std::string tag;
uint32_t entityUID; uint32_t entityUID;
EntityNetworkBehaviour networkBehaviour = EntityNetworkBehaviour::PARENT;
TagComponent() = default; TagComponent() = default;
TagComponent(const TagComponent&) = default; TagComponent(const TagComponent&) = default;
@ -75,9 +81,9 @@ namespace Deer {
glm::vec3 scale = glm::vec3(1.0f); glm::vec3 scale = glm::vec3(1.0f);
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f); glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
TransformComponent() = default; TransformComponent() {}
TransformComponent(glm::vec3 _position) : position(_position) {} TransformComponent(glm::vec3 _position) : position(_position) {}
TransformComponent(const TransformComponent&) = default; TransformComponent(const TransformComponent&) {}
inline const glm::vec3 getEulerAngles() { inline const glm::vec3 getEulerAngles() {
return glm::degrees(glm::eulerAngles(rotation)); return glm::degrees(glm::eulerAngles(rotation));

View File

@ -82,6 +82,9 @@ namespace Deer {
Entity& getParent() const; Entity& getParent() const;
inline uint32_t getParentId() const { return parentId; } inline uint32_t getParentId() const { return parentId; }
EntityNetworkBehaviour getForcedNetworkBehaviour();
bool isValidNetworkBehaviour(EntityNetworkBehaviour nb = EntityNetworkBehaviour::PARENT);
// TODO, enable transfer entitys from difrent environments // TODO, enable transfer entitys from difrent environments
void setParent(Entity& parent); void setParent(Entity& parent);
bool isDescendantOf(Entity& parent) const; bool isDescendantOf(Entity& parent) const;

View File

@ -42,10 +42,18 @@ namespace Deer {
WorldState getExecutionState(); WorldState getExecutionState();
Scope<EntityEnvironment> entityEnvironment; Scope<EntityEnvironment> entityEnvironment;
const WorldSettings& getWorldSettings() { return worldSettings; }
#ifdef DEER_RENDER
inline float getRenderDeltaTime() { return renderDeltaTime; }
void setRenderFrequency(int);
#endif
private: private:
std::atomic<WorldState> executingState; std::atomic<WorldState> executingState;
WorldSettings worldSettings; WorldSettings worldSettings;
#ifdef DEER_RENDER
float renderDeltaTime;
#endif
}; // namespace World }; // namespace World
} // namespace Deer } // namespace Deer

View File

@ -31,8 +31,8 @@ namespace Deer {
}; };
struct CameraComponent { struct CameraComponent {
CameraComponent() = default; CameraComponent() {}
CameraComponent(const CameraComponent&) = default; CameraComponent(const CameraComponent&) {}
float fov = glm::radians(50.0f); float fov = glm::radians(50.0f);
float aspect = 16 / 9; float aspect = 16 / 9;

View File

@ -33,6 +33,12 @@ namespace Deer {
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \ AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
clasdef, asBEHAVE_CONSTRUCT, funcdef, \ clasdef, asBEHAVE_CONSTRUCT, funcdef, \
asFUNCTION(func), asCALL_CDECL_OBJLAST)) asFUNCTION(func), asCALL_CDECL_OBJLAST))
#define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
clasdef, asBEHAVE_DESTRUCT, funcdef, \
asFUNCTION(func), asCALL_CDECL_OBJLAST))
#define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \ #define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \ AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
clasdef, asBEHAVE_DESTRUCT, funcdef, \ clasdef, asBEHAVE_DESTRUCT, funcdef, \

View File

@ -21,11 +21,6 @@ namespace Deer {
asIScriptContext* context = asGetActiveContext(); asIScriptContext* context = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData();
if (handle.environmentId == 0) {
return environmentData->world->entityEnvironment->getEntity(handle.entityId);
}
// Implement entity reference of other environments
return environmentData->world->entityEnvironment->getEntity(handle.entityId); return environmentData->world->entityEnvironment->getEntity(handle.entityId);
} }
@ -33,11 +28,6 @@ namespace Deer {
asIScriptContext* context = asGetActiveContext(); asIScriptContext* context = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData();
if (handle.environmentId == 0) {
return *environmentData->world->entityEnvironment.get();
}
// Implement entity reference of other environments
return *environmentData->world->entityEnvironment.get(); return *environmentData->world->entityEnvironment.get();
} }
@ -46,11 +36,6 @@ namespace Deer {
asIScriptContext* context = asGetActiveContext(); asIScriptContext* context = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData();
if (handle.environmentId == 0) {
return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>();
}
// Implement entity reference of other environments
return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>(); return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>();
} }
@ -82,6 +67,22 @@ namespace Deer {
getContextEntity(handle).destroy(); getContextEntity(handle).destroy();
} }
int Scripting::entity_getNetworkBehaviour(EntityHandle& handle) {
return (int)getContextEntityComponent<TagComponent>(handle).networkBehaviour;
}
void Scripting::entity_setNetworkBehaviour(int value, EntityHandle& handle) {
getContextEntityComponent<TagComponent>(handle).networkBehaviour = (EntityNetworkBehaviour)value;
}
int Scripting::entity_getForcedNetworkBehaviour(EntityHandle& handle) {
return (int)getContextEntity(handle).getForcedNetworkBehaviour();
}
bool Scripting::entity_isValidNetworkBehaviour(EntityHandle& handle) {
return getContextEntity(handle).isValidNetworkBehaviour();
}
CScriptArray* Scripting::entity_getChildrens(EntityHandle& handle) { CScriptArray* Scripting::entity_getChildrens(EntityHandle& handle) {
Entity& entity = getContextEntity(handle); Entity& entity = getContextEntity(handle);
@ -92,7 +93,7 @@ namespace Deer {
size_t childCount = relationship.getChildCount(); size_t childCount = relationship.getChildCount();
for (size_t i = 0; i < childCount; i++) { for (size_t i = 0; i < childCount; i++) {
EntityHandle entity(relationship.getChildId(i), handle.environmentId); EntityHandle entity(relationship.getChildId(i));
array->Resize(array->GetSize() + 1); array->Resize(array->GetSize() + 1);
array->SetValue(array->GetSize() - 1, &entity); array->SetValue(array->GetSize() - 1, &entity);
@ -107,7 +108,7 @@ namespace Deer {
child.setParent(self); child.setParent(self);
child.getComponent<TagComponent>().tag = childName; child.getComponent<TagComponent>().tag = childName;
return EntityHandle(child.getId(), handle.environmentId); return EntityHandle(child.getId());
} }
void Scripting::entity_setParent(EntityHandle other_handle, EntityHandle& self_handle) { void Scripting::entity_setParent(EntityHandle other_handle, EntityHandle& self_handle) {
@ -118,7 +119,7 @@ namespace Deer {
} }
EntityHandle Scripting::entity_getParent(EntityHandle& handle) { EntityHandle Scripting::entity_getParent(EntityHandle& handle) {
return EntityHandle(getContextEntity(handle).getParentId(), handle.environmentId); return EntityHandle(getContextEntity(handle).getParentId());
} }
bool Scripting::entity_isDescendantOf(EntityHandle other_handle, EntityHandle& self_handle) { bool Scripting::entity_isDescendantOf(EntityHandle other_handle, EntityHandle& self_handle) {
@ -129,7 +130,7 @@ namespace Deer {
} }
bool Scripting::entity_opEquals(EntityHandle& other, EntityHandle& self_handle) { bool Scripting::entity_opEquals(EntityHandle& other, EntityHandle& self_handle) {
return other.entityId == self_handle.entityId and other.environmentId == self_handle.environmentId; return other.entityId == self_handle.entityId;
} }
void Scripting::entity_addGenericComponent(asIScriptGeneric* generic) { void Scripting::entity_addGenericComponent(asIScriptGeneric* generic) {
@ -254,4 +255,6 @@ namespace Deer {
void Scripting::constructEntityStruct(void* memory) { void Scripting::constructEntityStruct(void* memory) {
new (memory) EntityHandle(); new (memory) EntityHandle();
} }
void Scripting::destructEntityStruct(void* memory) {}
} // namespace Deer } // namespace Deer

View File

@ -11,10 +11,8 @@ namespace Deer {
class EntityEnvironment; class EntityEnvironment;
struct EntityHandle { struct EntityHandle {
uint32_t entityId = 0; uint32_t entityId;
uint32_t environmentId = 0; EntityHandle(uint32_t _id = 0) : entityId(_id) {}
EntityHandle(uint32_t _id = 0, uint32_t _env = 0) : entityId(_id), environmentId(_env) {}
}; };
namespace Scripting { namespace Scripting {
@ -34,6 +32,11 @@ namespace Deer {
void entity_destroy(EntityHandle&); void entity_destroy(EntityHandle&);
CScriptArray* entity_getChildrens(EntityHandle&); CScriptArray* entity_getChildrens(EntityHandle&);
int entity_getNetworkBehaviour(EntityHandle&);
void entity_setNetworkBehaviour(int, EntityHandle&);
int entity_getForcedNetworkBehaviour(EntityHandle&);
bool entity_isValidNetworkBehaviour(EntityHandle&);
EntityHandle entity_createChild(std::string&, EntityHandle&); EntityHandle entity_createChild(std::string&, EntityHandle&);
void entity_setParent(EntityHandle, EntityHandle&); void entity_setParent(EntityHandle, EntityHandle&);
EntityHandle entity_getParent(EntityHandle&); EntityHandle entity_getParent(EntityHandle&);
@ -55,5 +58,6 @@ namespace Deer {
void transform_setRotation(glm::vec3, EntityHandle&); void transform_setRotation(glm::vec3, EntityHandle&);
void constructEntityStruct(void* memory); void constructEntityStruct(void* memory);
void destructEntityStruct(void* memory);
} // namespace Scripting } // namespace Scripting
} // namespace Deer } // namespace Deer

View File

@ -5,13 +5,13 @@
namespace Deer { namespace Deer {
void Scripting::errorCallback_angelscript(const asSMessageInfo* msg, void* param) { void Scripting::errorCallback_angelscript(const asSMessageInfo* msg, void* param) {
if (msg->type == asMSGTYPE_WARNING) { if (msg->type == asMSGTYPE_WARNING) {
DEER_EDITOR_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); DEER_EDITOR_ENGINE_WARN("{0}:{1}:{2} : {3}", msg->section, msg->row, msg->col, msg->message);
} else if (msg->type == asMSGTYPE_INFORMATION) { } else if (msg->type == asMSGTYPE_INFORMATION) {
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2} : {3}", msg->section, msg->row, msg->col, msg->message);
} else if (msg->type == asMSGTYPE_ERROR) { } else if (msg->type == asMSGTYPE_ERROR) {
DEER_EDITOR_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); DEER_EDITOR_ENGINE_ERROR("{0}:{1}:{2} : {3}", msg->section, msg->row, msg->col, msg->message);
} else { } else {
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2} : {3}", msg->section, msg->row, msg->col, msg->message);
} }
} }

View File

@ -3,6 +3,10 @@
namespace Deer { namespace Deer {
namespace Scripting { namespace Scripting {
void vec3_constructor(void* mem) {
new (mem) glm::vec3();
}
void vec3_constructor_params(float x, float y, float z, void* mem) { void vec3_constructor_params(float x, float y, float z, void* mem) {
new (mem) glm::vec3(x, y, z); new (mem) glm::vec3(x, y, z);
} }

View File

@ -2,6 +2,6 @@
namespace Deer { namespace Deer {
EntityHandle Scripting::getRoot() { EntityHandle Scripting::getRoot() {
return EntityHandle(0, 0); return EntityHandle();
} }
} // namespace Deer } // namespace Deer

View File

@ -1,3 +1,4 @@
#include "DeerCore/Components.h"
#include "DeerCore/Scripting/Helpers.h" #include "DeerCore/Scripting/Helpers.h"
#include "DeerCore/Scripting/InternalAPI/Entity.h" #include "DeerCore/Scripting/InternalAPI/Entity.h"
@ -30,6 +31,11 @@ namespace Deer {
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool opEquals(const Entity &in) const", entity_opEquals); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool opEquals(const Entity &in) const", entity_opEquals);
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "array<Entity>@ getChildrens()", entity_getChildrens); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "array<Entity>@ getChildrens()", entity_getChildrens);
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "EntityNetworkBehaviour get_networkBehaviour() const property", entity_getNetworkBehaviour);
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "void set_networkBehaviour(EntityNetworkBehaviour) property", entity_setNetworkBehaviour);
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "EntityNetworkBehaviour getForcedNetworkBehaviour()", entity_getForcedNetworkBehaviour);
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool isValidNetworkBehaviour()", entity_isValidNetworkBehaviour);
REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T getComponent<T>()", entity_getGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T getComponent<T>()", entity_getGenericComponent);
REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T addComponent<T>()", entity_addGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T addComponent<T>()", entity_addGenericComponent);
REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "void removeComponent<T>()", entity_removeGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "void removeComponent<T>()", entity_removeGenericComponent);
@ -44,11 +50,16 @@ namespace Deer {
} }
void Scripting::registerEntityStructs() { void Scripting::registerEntityStructs() {
AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<EntityHandle>() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<EntityHandle>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<EntityHandle>() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<EntityHandle>() | asOBJ_APP_CLASS_ALLINTS));
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Entity", "void f()", constructEntityStruct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Entity", "void f()", constructEntityStruct);
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "TransformComponent", "void f()", constructEntityStruct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "TransformComponent", "void f()", constructEntityStruct);
AS_CHECK(scriptEngine->RegisterEnum("EntityNetworkBehaviour"));
AS_CHECK(scriptEngine->RegisterEnumValue("EntityNetworkBehaviour", "Parent", (int)EntityNetworkBehaviour::PARENT));
AS_CHECK(scriptEngine->RegisterEnumValue("EntityNetworkBehaviour", "Client", (int)EntityNetworkBehaviour::CLIENT));
AS_CHECK(scriptEngine->RegisterEnumValue("EntityNetworkBehaviour", "Server", (int)EntityNetworkBehaviour::SERVER));
} }
} // namespace Deer } // namespace Deer

View File

@ -13,13 +13,14 @@ namespace Deer {
} // namespace Scripting } // namespace Scripting
void Scripting::registerMathStructs() { void Scripting::registerMathStructs() {
scriptEngine->RegisterObjectType("vec3", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS); scriptEngine->RegisterObjectType("vec3", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::vec3>() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_MORE_CONSTRUCTORS);
scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x)); scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x));
scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y)); scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y));
scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z)); scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z));
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "vec3", "void f(float = 0, float = 0, float = 0)", vec3_constructor_params); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "vec3", "void f()", vec3_constructor);
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "vec3", "void f(float, float = 0, float = 0)", vec3_constructor_params);
scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS); scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_MORE_CONSTRUCTORS);
scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x)); scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x));
scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y)); scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y));
scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z)); scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z));
@ -27,20 +28,20 @@ namespace Deer {
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f()", quat_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f()", quat_construct);
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f(float, float, float, float)", quat_constructFromValue); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f(float, float, float, float)", quat_constructFromValue);
scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>()); scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR);
scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position)); scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position));
scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale)); scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale));
scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation)); scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation));
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Transform", "void f()", transform_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Transform", "void f()", transform_construct);
scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>()); scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR);
scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov)); scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov));
scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect)); scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect));
scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ)); scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ));
scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ)); scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ));
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Camera", "void f()", camera_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Camera", "void f()", camera_construct);
scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>()); scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR);
scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera)); scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera));
scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform)); scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform));
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "WorldCamera", "void f()", sceneCamera_Construct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "WorldCamera", "void f()", sceneCamera_Construct);

View File

@ -183,7 +183,7 @@ namespace Deer {
asIScriptFunction* function = system->environmentFunctions[eventIndex]; asIScriptFunction* function = system->environmentFunctions[eventIndex];
if (!function) if (!function)
return; continue;
environment->context->Prepare(function); environment->context->Prepare(function);
environment->context->SetObject(systemInstances[i]); environment->context->SetObject(systemInstances[i]);

View File

@ -8,6 +8,7 @@
#include "scriptbuilder.h" #include "scriptbuilder.h"
#include "scriptdictionary.h" #include "scriptdictionary.h"
#include "scripthandle.h" #include "scripthandle.h"
#include "scriptmath.h"
#include "scriptstdstring.h" #include "scriptstdstring.h"
#include <array> #include <array>
@ -25,6 +26,7 @@ namespace Deer {
void registerResources(); void registerResources();
void registerEntity_Render(); void registerEntity_Render();
void registerImGui(); void registerImGui();
void registerWorld_Render();
#endif #endif
}; // namespace Scripting }; // namespace Scripting
@ -40,15 +42,17 @@ namespace Deer {
RegisterScriptAny(scriptEngine); RegisterScriptAny(scriptEngine);
RegisterScriptArray(scriptEngine, true); RegisterScriptArray(scriptEngine, true);
RegisterScriptDictionary(scriptEngine); RegisterScriptDictionary(scriptEngine);
RegisterScriptMath(scriptEngine);
registerMath(); registerMath();
registerEngine(); registerEngine();
registerEntity(); registerEntity();
registerWorld();
#ifdef DEER_RENDER #ifdef DEER_RENDER
registerResources(); registerResources();
registerEntity_Render(); registerEntity_Render();
registerWorld();
registerImGui(); registerImGui();
registerWorld_Render();
#endif #endif
} }

View File

@ -63,6 +63,37 @@ namespace Deer {
parentId = parent.getId(); parentId = parent.getId();
} }
EntityNetworkBehaviour Entity::getForcedNetworkBehaviour() {
if (entId == 0)
return EntityNetworkBehaviour::PARENT;
TagComponent& tag = getComponent<TagComponent>();
if (tag.networkBehaviour == EntityNetworkBehaviour::CLIENT)
return EntityNetworkBehaviour::CLIENT;
else if (tag.networkBehaviour == EntityNetworkBehaviour::SERVER)
return EntityNetworkBehaviour::SERVER;
return getParent().getForcedNetworkBehaviour();
}
bool Entity::isValidNetworkBehaviour(EntityNetworkBehaviour networkBehaviour) {
if (entId == 0)
return true;
TagComponent& tag = getComponent<TagComponent>();
if (tag.networkBehaviour == EntityNetworkBehaviour::PARENT)
return getParent().isValidNetworkBehaviour(networkBehaviour);
if (tag.networkBehaviour == networkBehaviour)
return getParent().isValidNetworkBehaviour(networkBehaviour);
if (networkBehaviour == EntityNetworkBehaviour::PARENT)
return getParent().isValidNetworkBehaviour(tag.networkBehaviour);
return false;
}
bool Entity::isDescendantOf(Entity& parent) const { bool Entity::isDescendantOf(Entity& parent) const {
DEER_CORE_ASSERT(isValid(), "Entity is not valid"); DEER_CORE_ASSERT(isValid(), "Entity is not valid");
if (getId() == parent.getId()) if (getId() == parent.getId())

View File

@ -88,8 +88,6 @@ namespace Deer {
RenderCommand::setClearColor({0.2f, 0.2f, 0.3f, 1.0f}); RenderCommand::setClearColor({0.2f, 0.2f, 0.3f, 1.0f});
RenderCommand::clear(); RenderCommand::clear();
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = 1.0f / 60;
ImGuiLayer::begin(); ImGuiLayer::begin();
} }

View File

@ -25,13 +25,18 @@ namespace Deer {
REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonCenter(const string& in text)", Scripting::buttonCenter); REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonCenter(const string& in text)", Scripting::buttonCenter);
REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonEnd(const string& in text)", Scripting::buttonEnd); REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonEnd(const string& in text)", Scripting::buttonEnd);
REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, const string& in icon, int iconSize, int width)", Scripting::cartIconButton); REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, Texture texture, int iconSize, int width)", Scripting::cartIconButton);
REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, FrameBuffer frameBuffer, int iconSize, int width)", Scripting::cartIconButton_frameBuffer); REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, FrameBuffer frameBuffer, int iconSize, int width)", Scripting::cartIconButton_frameBuffer);
// Checkboxes // Checkboxes
REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkbox(const string& in text, bool value)", Scripting::checkbox); REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkbox(const string& in text, bool value)", Scripting::checkbox);
REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkboxDisabled(const string& in text, bool value)", Scripting::checkboxDisabled); REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkboxDisabled(const string& in text, bool value)", Scripting::checkboxDisabled);
// Combo
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawCombo(const string& in name, const string& in value, SimpleFunction@+)", Scripting::drawCombo);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawComboEnd(const string& in name, const string& in value, SimpleFunction@+)", Scripting::drawCombo_end);
REGISTER_GLOBAL_FUNC(scriptEngine, "bool drawComboItem(const string& in text, bool selected)", Scripting::drawComboItem);
// Sliders & Inputs // Sliders & Inputs
REGISTER_GLOBAL_FUNC(scriptEngine, "float magicSlider(const string& in text, float value, float speed)", Scripting::magicSlider); REGISTER_GLOBAL_FUNC(scriptEngine, "float magicSlider(const string& in text, float value, float speed)", Scripting::magicSlider);
REGISTER_GLOBAL_FUNC(scriptEngine, "vec3 magicSlider3(const string& in text, vec3 value, float speed)", Scripting::magicSlider3); REGISTER_GLOBAL_FUNC(scriptEngine, "vec3 magicSlider3(const string& in text, vec3 value, float speed)", Scripting::magicSlider3);
@ -62,18 +67,13 @@ namespace Deer {
REGISTER_GLOBAL_FUNC(scriptEngine, "void space()", Scripting::space); REGISTER_GLOBAL_FUNC(scriptEngine, "void space()", Scripting::space);
REGISTER_GLOBAL_FUNC(scriptEngine, "void space(int x, int y = 10)", Scripting::space_params); REGISTER_GLOBAL_FUNC(scriptEngine, "void space(int x, int y = 10)", Scripting::space_params);
// Drawing REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(Texture texture, int)", Scripting::drawIcon);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBuffer(FrameBuffer, int, int)", Scripting::drawFrameBuffer); REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(Texture texture, int)", Scripting::drawIconCentered);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBufferCentered(FrameBuffer, int, int)", Scripting::drawFrameBufferCentered); REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(Texture texture, int)", Scripting::drawIconHighlight);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(const string& in, int)", Scripting::drawIcon); REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(Texture texture, int)", Scripting::drawIconCenteredHighlight);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(const string& in, int)", Scripting::drawIconCentered);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(const string& in, int)", Scripting::drawIconHighlight);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(const string& in, int)", Scripting::drawIconCenteredHighlight);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(Texture texture, int)", Scripting::drawIcon_resource); REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBuffer(FrameBuffer texture, int, int)", Scripting::drawFrameBuffer);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(Texture texture, int)", Scripting::drawIconCentered_resource); REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBufferCentered(FrameBuffer texture, int, int)", Scripting::drawFrameBufferCentered);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(Texture texture, int)", Scripting::drawIconHighlight_resource);
REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(Texture texture, int)", Scripting::drawIconCenteredHighlight_resource);
// Input state // Input state
REGISTER_GLOBAL_FUNC(scriptEngine, "bool isKeyDown(key)", Scripting::isKeyDown); REGISTER_GLOBAL_FUNC(scriptEngine, "bool isKeyDown(key)", Scripting::isKeyDown);
@ -87,6 +87,7 @@ namespace Deer {
REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDragDeltaY()", Scripting::getMouseDragDeltaY); REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDragDeltaY()", Scripting::getMouseDragDeltaY);
REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaX()", Scripting::getMouseDeltaX); REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaX()", Scripting::getMouseDeltaX);
REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaY()", Scripting::getMouseDeltaY); REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaY()", Scripting::getMouseDeltaY);
REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseWheel()", Scripting::getMouseWheel);
// Panel & layout co(scriptEngine, trol // Panel & layout co(scriptEngine, trol
REGISTER_GLOBAL_FUNC(scriptEngine, "bool isPanelActive()", Scripting::isPanelActive); REGISTER_GLOBAL_FUNC(scriptEngine, "bool isPanelActive()", Scripting::isPanelActive);

View File

@ -10,11 +10,6 @@ namespace Deer {
asIScriptContext* context = asGetActiveContext(); asIScriptContext* context = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData();
if (handle.environmentId == 0) {
return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>();
}
// Implement entity reference of other environments
return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>(); return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent<T>();
} }

View File

@ -80,10 +80,8 @@ namespace Deer {
else else
sizeX = ImGui::GetContentRegionAvail().x; sizeX = ImGui::GetContentRegionAvail().x;
float textWidth = float textWidth = ImGui::CalcTextSize(txt.c_str(), nullptr, false).x;
ImGui::CalcTextSize(txt.c_str(), nullptr, false).x; float padding = (sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2);
float padding =
(sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2);
if (padding > 0.0f) if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
@ -91,7 +89,28 @@ namespace Deer {
return ImGui::Button(txt.c_str()); return ImGui::Button(txt.c_str());
} }
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width) { void setCursorElementRight(std::string& txt, bool has_padding) {
float sizeX;
if (ImGui::GetColumnsCount() > 1)
sizeX = ImGui::GetColumnWidth(-1);
else
sizeX = ImGui::GetContentRegionAvail().x;
float textWidth = ImGui::CalcTextSize(txt.c_str(), nullptr, false).x;
float padding = sizeX - textWidth;
if (has_padding)
padding -= ImGui::GetStyle().FramePadding.x * 2;
if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
}
bool cartIconButton(const std::string& label, Resource<Texture> texture, int iconSize, int width) {
if (!texture.isValid()) {
ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture");
return false;
}
ImGui::BeginGroup(); ImGui::BeginGroup();
int offset = 16; int offset = 16;
@ -119,7 +138,6 @@ namespace Deer {
p.x + (itemWidth - iconSize) * 0.5f, p.x + (itemWidth - iconSize) * 0.5f,
p.y + 2.0f + offset); p.y + 2.0f + offset);
Resource<Texture> texture = ResourceManager<Texture>::getResource(icon);
dl->AddImage( dl->AddImage(
(ImTextureID)texture.getData().getTextureID(), (ImTextureID)texture.getData().getTextureID(),
iconPos, iconPos,
@ -235,31 +253,20 @@ namespace Deer {
ImGui::Text("%s", msg.c_str()); ImGui::Text("%s", msg.c_str());
} }
void drawIcon(std::string& name, int size) { void drawIcon(Resource<Texture> texture, int size) {
Resource<Texture> texture = ResourceManager<Texture>::getResource(name); if (!texture.isValid()) {
ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture");
return;
}
ImGui::Image((void*)(uint64_t)texture.getData().getTextureID(), ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0)); ImGui::Image((void*)(uint64_t)texture.getData().getTextureID(), ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0));
} }
void drawIcon_resource(Resource<Texture> texture, int size) { void drawIconHighlight(Resource<Texture> texture, int size) {
int iconId = texture.getData().getTextureID(); if (!texture.isValid()) {
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0)); ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture");
}
void drawIconHighlight_resource(Resource<Texture> texture, int size) {
int iconId = texture.getData().getTextureID();
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0, 0, 0, 0));
}
void drawIconHighlight(std::string& name, int size) {
Resource<Texture> texture = ResourceManager<Texture>::getResource(name);
int iconId = texture.getData().getTextureID();
if (iconId < 0) {
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
return; return;
} }
ImGui::Image((void*)(uint64_t)texture.getData().getTextureID(), ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0, 0, 0, 0));
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0, 0, 0, 0));
} }
void drawFrameBuffer(Resource<FrameBuffer> frameBufferResource, int sizeX, int sizeY) { void drawFrameBuffer(Resource<FrameBuffer> frameBufferResource, int sizeX, int sizeY) {
@ -292,30 +299,11 @@ namespace Deer {
ImVec2(0, 1), ImVec2(1, 0)); ImVec2(0, 1), ImVec2(1, 0));
} }
void drawIconCentered_resource(Resource<Texture> texture, int size) { void drawIconCentered(Resource<Texture> texture, int size) {
float sizeX; if (!texture.isValid()) {
if (ImGui::GetColumnsCount() > 1) ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture");
sizeX = ImGui::GetColumnWidth(-1);
else
sizeX = ImGui::GetContentRegionAvail().x;
float iconWidth = size;
float padding = (sizeX - iconWidth) * 0.5f;
if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
drawIcon_resource(texture, size);
}
void drawIconCentered(std::string& name, int size) {
Resource<Texture> texture = ResourceManager<Texture>::getResource(name);
int iconId = texture.getData().getTextureID();
if (iconId < 0) {
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
return; return;
} }
float sizeX; float sizeX;
if (ImGui::GetColumnsCount() > 1) if (ImGui::GetColumnsCount() > 1)
sizeX = ImGui::GetColumnWidth(-1); sizeX = ImGui::GetColumnWidth(-1);
@ -328,32 +316,14 @@ namespace Deer {
if (padding > 0.0f) if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
drawIcon(name, size); drawIcon(texture, size);
}
void drawIconCenteredHighlight_resource(Resource<Texture> texture, int size) {
float sizeX;
if (ImGui::GetColumnsCount() > 1)
sizeX = ImGui::GetColumnWidth(-1);
else
sizeX = ImGui::GetContentRegionAvail().x;
float iconWidth = size;
float padding = (sizeX - iconWidth) * 0.5f;
if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
drawIconHighlight_resource(texture, size);
} }
void drawIconCenteredHighlight(std::string& name, int size) { void drawIconCenteredHighlight(Resource<Texture> texture, int size) {
Resource<Texture> texture = ResourceManager<Texture>::getResource(name); if (!texture.isValid()) {
int iconId = texture.getData().getTextureID(); ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture");
if (iconId < 0) {
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
return; return;
} }
float sizeX; float sizeX;
if (ImGui::GetColumnsCount() > 1) if (ImGui::GetColumnsCount() > 1)
sizeX = ImGui::GetColumnWidth(-1); sizeX = ImGui::GetColumnWidth(-1);
@ -366,7 +336,7 @@ namespace Deer {
if (padding > 0.0f) if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
drawIconHighlight(name, size); drawIconHighlight(texture, size);
} }
bool isItemClicked(int mouse) { return ImGui::IsItemClicked(mouse); } bool isItemClicked(int mouse) { return ImGui::IsItemClicked(mouse); }
@ -616,6 +586,11 @@ namespace Deer {
return io.MouseDelta.y; return io.MouseDelta.y;
} }
float getMouseWheel() {
ImGuiIO& io = ImGui::GetIO();
return io.MouseWheel;
}
float getMouseDragDeltaX() { return ImGui::GetMouseDragDelta().x; } float getMouseDragDeltaX() { return ImGui::GetMouseDragDelta().x; }
float getMouseDragDeltaY() { return ImGui::GetMouseDragDelta().y; } float getMouseDragDeltaY() { return ImGui::GetMouseDragDelta().y; }
@ -717,6 +692,59 @@ namespace Deer {
return false; return false;
} }
void drawCombo(std::string& name, std::string& selectedValue, asIScriptFunction* function) {
if (ImGui::BeginCombo(name.c_str(), selectedValue.c_str(), ImGuiComboFlags_WidthFitPreview)) {
asIScriptContext* scriptContext = asGetActiveContext();
if (scriptContext->PushState() == asSUCCESS) {
AS_CHECK(scriptContext->Prepare(function));
AS_CHECK(scriptContext->Execute());
scriptContext->PopState();
} else {
ImGui::Text("Something failed");
}
ImGui::EndCombo();
}
}
void drawCombo_end(std::string& name, std::string& selectedValue, asIScriptFunction* function) {
float sizeX;
if (ImGui::GetColumnsCount() > 1)
sizeX = ImGui::GetColumnWidth(-1);
else
sizeX = ImGui::GetContentRegionAvail().x;
float padding = (sizeX - 200);
if (padding > 0.0f)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding);
ImGui::SetNextItemWidth(200);
if (ImGui::BeginCombo(name.c_str(), selectedValue.c_str())) {
asIScriptContext* scriptContext = asGetActiveContext();
if (scriptContext->PushState() == asSUCCESS) {
AS_CHECK(scriptContext->Prepare(function));
AS_CHECK(scriptContext->Execute());
scriptContext->PopState();
} else {
ImGui::Text("Something failed");
}
ImGui::EndCombo();
}
}
bool drawComboItem(std::string& value, bool active) {
bool selected = ImGui::Selectable(value.c_str(), active);
if (active)
ImGui::SetItemDefaultFocus();
return selected;
}
bool componentNodeContextMenu(std::string& txt, asIScriptFunction* func, asIScriptFunction* menu) { bool componentNodeContextMenu(std::string& txt, asIScriptFunction* func, asIScriptFunction* menu) {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
@ -884,7 +912,6 @@ namespace Deer {
asIScriptContext* scriptContext = asGetActiveContext(); asIScriptContext* scriptContext = asGetActiveContext();
if (scriptContext->PushState() == asSUCCESS) { if (scriptContext->PushState() == asSUCCESS) {
AS_CHECK(scriptContext->Prepare(func)); AS_CHECK(scriptContext->Prepare(func));
AS_CHECK(scriptContext->SetArgObject(0, MenuContext::payload));
AS_CHECK(scriptContext->Execute()); AS_CHECK(scriptContext->Execute());
scriptContext->PopState(); scriptContext->PopState();
} else { } else {

View File

@ -31,19 +31,16 @@ namespace Deer {
bool buttonCenter(std::string&); bool buttonCenter(std::string&);
bool buttonEnd(std::string&); bool buttonEnd(std::string&);
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width); bool cartIconButton(const std::string& label, Resource<Texture> icon, int iconSize, int width);
bool cartIconButton_frameBuffer(const std::string& label, Resource<FrameBuffer> frameBuffer, int iconSize, int width); bool cartIconButton_frameBuffer(const std::string& label, Resource<FrameBuffer> frameBuffer, int iconSize, int width);
// Icons void drawIcon(Resource<Texture> texture, int size);
void drawIcon(std::string& iconId, int size); void drawIconCentered(Resource<Texture> texture, int size);
void drawIconCentered(std::string& iconId, int size); void drawIconHighlight(Resource<Texture> texture, int size);
void drawIconHighlight(std::string& iconId, int size); void drawIconCenteredHighlight(Resource<Texture> texture, int size);
void drawIconCenteredHighlight(std::string& iconId, int size);
void drawIcon_resource(Resource<Texture> texture, int size); void drawFrameBuffer(Resource<FrameBuffer> frameBuffer, int sizeX, int sizeY);
void drawIconCentered_resource(Resource<Texture> texture, int size); void drawFrameBufferCentered(Resource<FrameBuffer> frameBuffer, int sizeX, int sizeY);
void drawIconHighlight_resource(Resource<Texture> texture, int size);
void drawIconCenteredHighlight_resource(Resource<Texture> texture, int size);
int getIconId(const std::string& name); int getIconId(const std::string& name);
@ -89,14 +86,15 @@ namespace Deer {
float getMouseDragDeltaY(); float getMouseDragDeltaY();
float getMouseDeltaX(); float getMouseDeltaX();
float getMouseDeltaY(); float getMouseDeltaY();
float getMouseWheel();
void drawCombo(std::string&, std::string&, asIScriptFunction*);
void drawCombo_end(std::string&, std::string&, asIScriptFunction*);
bool drawComboItem(std::string&, bool active);
bool isKeyDown(int); bool isKeyDown(int);
bool isKeyPressed(int); bool isKeyPressed(int);
// Rendering helpers
void drawFrameBuffer(Resource<FrameBuffer> frameBuffer, int sizeX, int sizeY);
void drawFrameBufferCentered(Resource<FrameBuffer> frameBuffer, int sizeX, int sizeY);
void automaticColumns(int pixelSize); void automaticColumns(int pixelSize);
void columns(int); void columns(int);
void nextColumn(); void nextColumn();

View File

@ -0,0 +1,38 @@
#include "DeerRender/Scripting/InternalAPI/World.h"
#include "DeerCore/Scripting/ScriptEnvironmentContextData.h"
#include "DeerRender/EntityEnviroment.h"
#include "DeerRender/FrameBuffer.h"
#include "angelscript.h"
namespace Deer {
void Scripting::world_render(Resource<FrameBuffer> frameBuffer, WorldCamera worldCamera) {
asIScriptContext* scriptContext = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)scriptContext->GetUserData();
frameBuffer.getData().bind();
environmentData->world->entityEnvironment->render(worldCamera);
frameBuffer.getData().unbind();
}
float Scripting::getRenderDeltaTime() {
asIScriptContext* scriptContext = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)scriptContext->GetUserData();
return environmentData->world->getRenderDeltaTime();
}
void Scripting::setRenderFrequency(int freq) {
asIScriptContext* scriptContext = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)scriptContext->GetUserData();
environmentData->world->setRenderFrequency(freq);
}
int Scripting::getRenderFrequency() {
asIScriptContext* scriptContext = asGetActiveContext();
ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)scriptContext->GetUserData();
return environmentData->world->getWorldSettings().renderFrequency;
}
} // namespace Deer

View File

@ -0,0 +1,12 @@
#pragma once
#include "DeerRender/World.h"
#include "Resources.h"
namespace Deer {
namespace Scripting {
void world_render(Resource<FrameBuffer>, WorldCamera);
float getRenderDeltaTime();
void setRenderFrequency(int);
int getRenderFrequency();
} // namespace Scripting
} // namespace Deer

View File

@ -31,12 +31,6 @@ namespace Deer {
AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(Resource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Shader>>())); AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(Resource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Shader>>()));
AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(Resource<Texture>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Texture>>())); AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(Resource<Texture>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Texture>>()));
AS_CHECK(scriptEngine->RegisterObjectType("FrameBuffer", sizeof(Resource<FrameBuffer>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<FrameBuffer>>())); AS_CHECK(scriptEngine->RegisterObjectType("FrameBuffer", sizeof(Resource<FrameBuffer>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<FrameBuffer>>()));
scriptEngine->RegisterEnum("ResourceType");
scriptEngine->RegisterEnumValue("ResourceType", "None", (int)ResourceType::NONE);
scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH);
scriptEngine->RegisterEnumValue("ResourceType", "Shader", (int)ResourceType::SHADER);
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)ResourceType::TEXTURE);
} }
int frameBuffer_getWidth(Resource<FrameBuffer>&); int frameBuffer_getWidth(Resource<FrameBuffer>&);
int frameBuffer_getHeight(Resource<FrameBuffer>&); int frameBuffer_getHeight(Resource<FrameBuffer>&);

View File

@ -0,0 +1,25 @@
#include "DeerCore/Scripting/Helpers.h"
#include "DeerRender/Scripting/InternalAPI/World.h"
namespace Deer {
namespace Scripting {
extern asIScriptEngine* scriptEngine;
void registerWorld_Render();
void registerWorldFunctions_Render();
} // namespace Scripting
void Scripting::registerWorld_Render() {
registerWorldFunctions_Render();
}
void Scripting::registerWorldFunctions_Render() {
scriptEngine->SetDefaultNamespace("World");
REGISTER_GLOBAL_FUNC(scriptEngine, "void render(FrameBuffer, WorldCamera)", world_render);
REGISTER_GLOBAL_FUNC(scriptEngine, "float getRenderDeltaTime()", getRenderDeltaTime);
REGISTER_GLOBAL_FUNC(scriptEngine, "void setRenderFrequency(int)", setRenderFrequency);
REGISTER_GLOBAL_FUNC(scriptEngine, "int getRenderFrequency()", getRenderFrequency);
scriptEngine->SetDefaultNamespace("");
}
} // namespace Deer

View File

@ -13,18 +13,19 @@ namespace Deer {
if (worldSettings.updateFrequency == 0) if (worldSettings.updateFrequency == 0)
return; return;
auto previousTime = std::chrono::high_resolution_clock::now(); auto previousTime = std::chrono::steady_clock::now();
double accumulatedUpdateTime = 0.0; double accumulatedUpdateTime = 0.0;
double accumulatedRenderTime = 0.0; double accumulatedRenderTime = 0.0;
double targetUpdateTime = 1.0f / worldSettings.updateFrequency; double targetUpdateTime = 1.0f / worldSettings.updateFrequency;
double targetRenderTime = 0; double targetRenderTime = 0;
if (worldSettings.renderFrequency > 0)
targetRenderTime = 1.0f / worldSettings.renderFrequency;
executingState = WorldState::Executing; executingState = WorldState::Executing;
while (executingState == WorldState::Executing) { while (executingState == WorldState::Executing) {
auto currentTime = std::chrono::high_resolution_clock::now(); if (worldSettings.renderFrequency > 0)
targetRenderTime = 1.0f / worldSettings.renderFrequency;
auto currentTime = std::chrono::steady_clock::now();
std::chrono::duration<double> deltaTime = currentTime - previousTime; std::chrono::duration<double> deltaTime = currentTime - previousTime;
previousTime = currentTime; previousTime = currentTime;
@ -33,17 +34,16 @@ namespace Deer {
while (accumulatedUpdateTime >= targetUpdateTime) { while (accumulatedUpdateTime >= targetUpdateTime) {
accumulatedUpdateTime -= targetUpdateTime; accumulatedUpdateTime -= targetUpdateTime;
worldSettings.updateCallback(*this); worldSettings.updateCallback(*this);
} }
if (targetRenderTime > 0 && accumulatedRenderTime >= targetRenderTime) { if (targetRenderTime > 0 && accumulatedRenderTime >= targetRenderTime) {
renderDeltaTime = accumulatedRenderTime;
worldSettings.renderCallback(*this); worldSettings.renderCallback(*this);
while (accumulatedRenderTime >= targetRenderTime) accumulatedRenderTime = 0;
accumulatedRenderTime -= targetRenderTime;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::microseconds(1));
} }
if (executingState == WorldState::DestroyQueued) if (executingState == WorldState::DestroyQueued)
@ -52,4 +52,9 @@ namespace Deer {
executingState = WorldState::Stopped; executingState = WorldState::Stopped;
} }
void World::setRenderFrequency(int freq) {
if (freq < 1)
return;
worldSettings.renderFrequency = freq;
}
} // namespace Deer } // namespace Deer

View File

@ -35,7 +35,8 @@ namespace Deer {
m_renderContext = new OpenGLContext(m_window); m_renderContext = new OpenGLContext(m_window);
m_renderContext->init(); m_renderContext->init();
setVSync(true); setVSync(false);
glfwSetWindowUserPointer(m_window, &m_data); glfwSetWindowUserPointer(m_window, &m_data);
// Set GLFW callback // Set GLFW callback

View File

@ -0,0 +1,29 @@
#pragma once
#include "DeerRender/Resource.h"
#include <string>
class CScriptArray;
class CScriptDictionary;
namespace Deer {
class Texture;
enum class ResourceType : int {
NONE = 0,
MESH = 1,
SHADER = 2,
TEXTURE = 3
};
namespace StudioAPI {
Resource<Texture> getIcon(std::string&);
CScriptArray* getResourceFolders(std::string& path);
CScriptArray* getResourceFiles(std::string& path);
CScriptDictionary* getResourceMetadata(std::string& resource);
CScriptDictionary* setResourceMetadata(std::string& resource);
ResourceType getResourceType(std::string&);
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,37 +0,0 @@
#pragma once
#include "DeerRender/Mesh.h"
#include "DeerRender/Shader.h"
#include "DeerRender/Texture.h"
#include "DeerStudio/EditorDataImporter.h"
#include "DeerStudio/ResourceDataSource.h"
#include "scriptarray.h"
#include "scriptdictionary.h"
#include <stdint.h>
#include <string>
namespace Deer {
namespace StudioAPI {
template <typename T>
class APIResource : public Resource<T> {
public:
std::string getPath() const { return ResourceManager<T>::getStorageId(*this); }
std::string getName() const { return Path(ResourceManager<T>::getStorageId(*this)).stem().string(); }
};
enum ResourceType : uint32_t {
NONE = 0,
MESH = 1,
SHADER = 2,
TEXTURE = 3,
};
CScriptArray* getResourceFolders(std::string& path);
CScriptArray* getResourceFiles(std::string& path);
CScriptDictionary* getResourceMetadata(std::string& resource);
CScriptDictionary* setResourceMetadata(std::string& resource);
ResourceType getResourceType(std::string&);
} // namespace StudioAPI
} // namespace Deer

View File

@ -102,6 +102,7 @@ namespace Deer {
bool componentNode(std::string&, asIScriptFunction*); bool componentNode(std::string&, asIScriptFunction*);
bool componentNodeContextMenu(std::string&, asIScriptFunction*, asIScriptFunction*); bool componentNodeContextMenu(std::string&, asIScriptFunction*, asIScriptFunction*);
void treeNodeLeaf(std::string&, bool); void treeNodeLeaf(std::string&, bool);
bool treeNode(std::string&, bool, asIScriptFunction&); bool treeNode(std::string&, bool, asIScriptFunction&);

View File

@ -0,0 +1,7 @@
#pragma once
namespace Deer {
namespace StudioScripting {
void registerStudioScripting();
}
} // namespace Deer

View File

@ -1,118 +0,0 @@
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "DeerStudio/StudioAPI/Resources.h"
#include "DeerStudio/StudioAPI/Debug.h"
#include "angelscript.h"
#include "scriptany.h"
#include "scriptarray.h"
#include "scriptbuilder.h"
#include "scriptdictionary.h"
#include "scripthandle.h"
#include "scriptstdstring.h"
namespace Deer {
// GLOBAL DECLARATIONS
namespace StudioAPI {
asIScriptEngine* scriptEngine;
asIScriptContext* scriptContext;
CScriptBuilder scriptBuilder;
std::vector<Module> modules;
std::unordered_map<std::string, int> module_id;
Module* executingModule;
asITypeInfo* panelBaseType;
asITypeInfo* serviceBaseType;
asITypeInfo* arrayStringBaseType;
} // namespace StudioAPI
void StudioAPI::raiseError() {
if (StudioAPI::executingModule)
executingModule->invalidate();
}
void StudioAPI::initialize() {
int err = 0;
// Deinitialize if its initialized
deinitialize();
scriptEngine = asCreateScriptEngine();
AS_RET_CHECK(scriptEngine->SetMessageCallback(asFUNCTION(Deer::StudioAPI::errorCallback_angelscript), 0, asCALL_CDECL));
RegisterScriptHandle(scriptEngine);
RegisterScriptAny(scriptEngine);
RegisterStdString(scriptEngine);
RegisterScriptArray(scriptEngine, true);
RegisterScriptDictionary(scriptEngine);
registerStructs();
registerFunctions();
extractBaseTypes();
loadModules();
scriptContext = scriptEngine->CreateContext();
for (Module& module : modules) {
module.init();
}
}
void StudioAPI::update() {
for (Module& module : modules) {
module.update();
}
}
void StudioAPI::shutdown() {
for (Module& module : modules) {
module.shutdown();
}
}
void StudioAPI::render() {
for (Module& module : modules) {
module.render();
}
}
void StudioAPI::deinitialize() {
for (Module& module : modules) {
module.shutdown();
}
modules.clear();
module_id.clear();
if (scriptContext)
scriptContext->Release();
if (scriptEngine)
scriptEngine->ShutDownAndRelease();
scriptContext = nullptr;
scriptEngine = nullptr;
}
void StudioAPI::registerStructs() {
registerMathStructs();
registerResourceStructs();
registerEntityEnvironmentStructs();
registerEntityStructs();
registerEngineStructs();
registerFrameBufferStructs();
registerUIStructs();
}
void StudioAPI::registerFunctions() {
registerUIFunctions();
registerMathFunctions();
registerResourceFunctions();
registerEntityEnvironmentFunctions();
registerEntityFunctions();
registerEngineFunctions();
registerFrameBufferFunctions();
}
} // namespace Deer

View File

@ -1,65 +0,0 @@
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "angelscript.h"
namespace Deer {
namespace StudioAPI {
const char* getAngelScriptReturnCodeString(int code) {
switch (code) {
case asSUCCESS:
return "SUCCESS (The operation was successful)";
case asERROR:
return "ERROR (A generic error occurred)";
case asCONTEXT_ACTIVE:
return "CONTEXT_ACTIVE (A context was active during an invalid operation)";
case asCONTEXT_NOT_FINISHED:
return "CONTEXT_NOT_FINISHED (Context has not finished execution)";
case asCONTEXT_NOT_PREPARED:
return "CONTEXT_NOT_PREPARED (Context is not prepared)";
case asINVALID_ARG:
return "INVALID_ARG (An invalid argument was provided)";
case asNO_FUNCTION:
return "NO_FUNCTION (Function not found)";
case asNOT_SUPPORTED:
return "NOT_SUPPORTED (Feature not supported by build configuration)";
case asINVALID_NAME:
return "INVALID_NAME (Name is not allowed or invalid)";
case asNAME_TAKEN:
return "NAME_TAKEN (Name is already taken by another entity)";
case asINVALID_DECLARATION:
return "INVALID_DECLARATION (The declaration is invalid)";
case asINVALID_OBJECT:
return "INVALID_OBJECT (Invalid object handle or object type)";
case asINVALID_TYPE:
return "INVALID_TYPE (Invalid type provided)";
case asALREADY_REGISTERED:
return "ALREADY_REGISTERED (Item is already registered)";
case asMULTIPLE_FUNCTIONS:
return "MULTIPLE_FUNCTIONS (More than one matching function found)";
case asNO_MODULE:
return "NO_MODULE (Module was not found)";
case asNO_GLOBAL_VAR:
return "NO_GLOBAL_VAR (Global variable was not found)";
case asINVALID_CONFIGURATION:
return "INVALID_CONFIGURATION (Invalid configuration, likely during registration)";
case asINVALID_INTERFACE:
return "INVALID_INTERFACE (Invalid interface registration)";
case asCANT_BIND_ALL_FUNCTIONS:
return "CANT_BIND_ALL_FUNCTIONS (Couldn't bind all functions for a virtual interface)";
case asLOWER_ARRAY_DIMENSION_NOT_REGISTERED:
return "LOWER_ARRAY_DIMENSION_NOT_REGISTERED (Lower dimension type for array not registered)";
default:
return "Unknown AngelScript error code";
}
}
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface) {
for (uint32_t i = 0; i < type->GetInterfaceCount(); i++) {
if (type->GetInterface(i) == iface)
return true;
}
return false;
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,33 +0,0 @@
#pragma once
#include "DeerRender/Log.h"
#include "angelscript.h"
namespace Deer {
namespace StudioAPI {
const char* getAngelScriptReturnCodeString(int code);
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface);
} // namespace StudioAPI
} // namespace Deer
#define AS_CHECK(f) \
{ \
int __r = f; \
if (__r < 0) { \
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r)); \
} \
}
#define AS_CHECK_ADDITIONAL_INFO(f, i) \
{ \
int __r = f; \
if (__r < 0) { \
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r), i); \
} \
}
#define AS_RET_CHECK(f) \
{ \
int __r = f; \
if (__r < 0) { \
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r)); \
return; \
} \
}

View File

@ -1,93 +0,0 @@
#include "DeerRender/Log.h"
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "angelscript.h"
namespace Deer {
namespace StudioAPI {
Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {}
void Module::extract(asIScriptModule* _module) {
if (state != ModuleState::Built)
return;
angelscriptModule = _module;
scriptEngine->SetDefaultNamespace(moduleInfo.moduleName.c_str());
uint32_t typeCount = angelscriptModule->GetObjectTypeCount();
for (uint32_t typeId = 0; typeId < typeCount; typeId++) {
asITypeInfo* typeInfo = angelscriptModule->GetObjectTypeByIndex(typeId);
if (ImplementsInterface(typeInfo, serviceBaseType)) {
services.push_back({typeInfo});
services.back().registerApiExpose();
} else if (ImplementsInterface(typeInfo, panelBaseType)) {
panels.push_back({typeInfo});
panels.back().registerApiExpose();
}
}
scriptEngine->SetDefaultNamespace("");
}
void Module::updateTypes() {
if (state != ModuleState::Built)
return;
angelscriptModule = StudioAPI::scriptEngine->GetModule(moduleInfo.moduleName.c_str());
for (Service& service : services)
service.updateTypes(angelscriptModule);
for (Panel& panel : panels)
panel.updateTypes(angelscriptModule);
}
void Module::init() {
if (state != ModuleState::Built)
return;
angelscriptModule->BindAllImportedFunctions();
for (Service& service : services)
service.init();
for (Panel& panel : panels)
panel.init();
}
void Module::update() {
if (state != ModuleState::Built)
return;
for (Service& service : services)
service.update();
for (Panel& panel : panels)
panel.update();
}
void Module::render() {
if (state != ModuleState::Built)
return;
for (Panel& panel : panels)
panel.render();
}
void Module::shutdown() {
if (state != ModuleState::Built)
return;
for (Service& service : services)
service.shutdown();
for (Panel& panel : panels)
panel.shutdown();
}
Module::~Module() {
services.clear();
panels.clear();
}
}; // namespace StudioAPI
}; // namespace Deer

View File

@ -1,17 +0,0 @@
#pragma once
#include "DeerStudio/AngelScriptEngine.h"
#include <cereal/types/string.hpp>
#include <cereal/types/vector.hpp>
namespace Deer {
namespace StudioAPI {
template <class Archive>
void serialize(Archive& archive,
ModuleDescription& m) {
archive(cereal::make_nvp("name", m.moduleName));
archive(cereal::make_nvp("patch", m.patchVersion));
archive(cereal::make_nvp("requires", m.module_requires));
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,195 +0,0 @@
#include "DeerRender/Tools/Path.h"
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "DeerStudio/AngelScriptEngine/ModuleDescriptorSerializer.h"
#include "angelscript.h"
#include "cereal/archives/json.hpp"
#include "scriptbuilder.h"
#include "DeerRender/Log.h"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>
namespace fs = std::filesystem;
namespace Deer {
namespace StudioAPI {
bool loadModule(Module& module);
void loadModuleInfo(const Path& path);
} // namespace StudioAPI
asIScriptFunction* StudioAPI::getFactory(asITypeInfo* type) {
std::string callString = "";
if (strlen(type->GetNamespace())) {
callString += type->GetNamespace();
callString += "::";
}
callString += type->GetName();
callString += " @";
if (strlen(type->GetNamespace())) {
callString += type->GetNamespace();
callString += "::";
}
callString += type->GetName();
callString += "()";
return type->GetFactoryByDecl(callString.c_str());
}
bool StudioAPI::loadModule(Module& module) {
if (module.state != ModuleState::NotBuilt)
return false;
int err = 0;
module.state = ModuleState::Building;
for (const std::string& dependency : module.moduleInfo.module_requires) {
if (!module_id.contains(dependency)) {
DEER_CORE_ERROR("Failed to find dependency {} for module {}",
dependency.c_str(), module.moduleInfo.moduleName);
module.state = ModuleState::DependencyFailed;
return false;
}
Module& dependencyModule = modules[module_id[dependency]];
if (dependencyModule.state == ModuleState::DependencyFailed ||
dependencyModule.state == ModuleState::CompilationFailed) {
DEER_CORE_ERROR("Failed to load dependency {} for module {}, the dependency did not load correctly and caused a chain reaction",
dependency.c_str(), module.moduleInfo.moduleName.c_str());
module.state = ModuleState::DependencyFailed;
return false;
}
if (dependencyModule.state == ModuleState::Building) {
DEER_CORE_ERROR("Failed to load dependency {} for module {} due to loop",
dependency.c_str(), module.moduleInfo.moduleName.c_str());
module.state = ModuleState::DependencyFailed;
return false;
}
if (dependencyModule.state == ModuleState::NotBuilt) {
if (!loadModule(dependencyModule)) {
module.state = ModuleState::DependencyFailed;
return false;
}
}
}
DEER_CORE_TRACE("Loading module {}", module.moduleInfo.moduleName);
err = scriptBuilder.StartNewModule(scriptEngine, module.moduleInfo.moduleName.c_str());
if (err < 0) {
DEER_EDITOR_ENGINE_ERROR("Failed to init module for {0}", module.moduleInfo.moduleName.c_str());
module.state = ModuleState::CompilationFailed;
return false;
}
for (const auto& entry : fs::recursive_directory_iterator(module.moduleInfo.modulePath)) {
if (!entry.is_regular_file() || entry.path().extension() != ".as")
continue;
err = scriptBuilder.AddSectionFromFile(entry.path().string().c_str());
if (err < 0) {
DEER_EDITOR_ENGINE_ERROR("Failed loading script for module {0}\nscript: {1}", module.moduleInfo.moduleName.c_str(), entry.path().string().c_str());
module.state = ModuleState::CompilationFailed;
return false;
}
}
err = scriptBuilder.BuildModule();
asIScriptModule* as_module = scriptBuilder.GetModule();
if (err < 0) {
DEER_EDITOR_ENGINE_ERROR("Failed compiling module {}\nerror: {}", module.moduleInfo.moduleName.c_str(), Deer::StudioAPI::getAngelScriptReturnCodeString(err));
module.state = ModuleState::CompilationFailed;
return false;
}
module.state = ModuleState::Built;
module.extract(as_module);
return true;
}
void StudioAPI::loadModuleInfo(const Path& path) {
ModuleDescription desc;
std::ifstream is((path / "module.json").string());
if (!is.is_open()) {
DEER_CORE_ERROR("Cannot open module description: {}", (path / "module.json").string().c_str());
ModuleDescription desc;
desc.moduleName = path.stem().string();
desc.patchVersion = 1;
std::ofstream os((path / "module.json").string());
{
cereal::JSONOutputArchive archive(os);
serialize(archive, desc);
}
return;
}
std::string contents((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
std::stringstream ss(contents);
try {
cereal::JSONInputArchive archive(ss);
serialize(archive, desc);
if (desc.moduleName.empty()) {
DEER_CORE_ERROR("Module description missing 'name' field: {}", path.string().c_str());
return;
}
if (desc.patchVersion < 0) {
DEER_CORE_ERROR("Module description missing 'name' field: {}", path.string().c_str());
return;
}
} catch (const cereal::RapidJSONException& e) {
DEER_CORE_ERROR("Module description format error : {}, {}", path.string().c_str(), e.what());
return;
}
desc.modulePath = path.string();
if (module_id.contains(desc.moduleName)) {
DEER_CORE_ERROR("Module name duplicated {}", path.string().c_str());
return;
}
module_id[desc.moduleName] = modules.size();
modules.push_back({desc});
}
void StudioAPI::loadModules() {
const Path path = Path("Editor") / Path("Modules");
if (!fs::exists(path) || !fs::is_directory(path)) {
DEER_EDITOR_ENGINE_ERROR("Could not find folder {}", path.string().c_str());
return;
}
for (const auto& module : fs::directory_iterator(path)) {
if (module.path().extension() == ".disabled") {
DEER_CORE_WARN("Ignoring {}", module.path().stem().string().c_str());
continue;
}
loadModuleInfo(module.path());
}
for (Module& module : modules) {
if (module.state == ModuleState::NotBuilt) {
loadModule(module);
}
module.generatePredefined();
}
for (Module& module : modules) {
module.updateTypes();
}
}
} // namespace Deer

View File

@ -1,291 +0,0 @@
#include "DeerRender/Log.h"
#include "DeerStudio/AngelScriptEngine.h"
#include "angelscript.h"
#include <iso646.h>
#include <sstream>
#include <string>
#include <string_view>
#include <angelscript.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include "DeerRender/Tools/Path.h"
static std::stringstream stream;
static std::string str;
void printFuncList(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetFuncdefCount(); ++i) {
asITypeInfo* t = engine.GetFuncdefByIndex(i);
if (!t)
continue;
asIScriptFunction* func = t->GetFuncdefSignature();
if (!func || func->GetSubType())
continue;
std::string decl = func->GetDeclaration(true, true, true);
// Detect class-scoped funcdefs by presence of "::" in the declaration
size_t scopePos = decl.find("::");
if (scopePos != std::string::npos)
continue;
stream << "funcdef " << decl << ";\n";
}
}
void printEnumList(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetEnumCount(); ++i) {
const auto e = engine.GetEnumByIndex(i);
if (!e)
continue;
std::string_view ns = e->GetNamespace();
if (!ns.empty())
stream << "namespace " << ns << " {\n";
stream << "enum " << e->GetName() << " {\n";
for (int j = 0; j < e->GetEnumValueCount(); ++j) {
int value;
stream << "\t" << e->GetEnumValueByIndex(j, &value) << " = "
<< value;
if (j < e->GetEnumValueCount() - 1)
stream << ",";
stream << "\n";
}
stream << "}\n";
if (!ns.empty())
stream << "}\n\n";
}
}
void writeParameters(asIScriptFunction* function) {
for (int n = 0; n < function->GetParamCount(); n++) {
int typeId;
asDWORD flags;
const char* name;
const char* defaultArgument;
function->GetParam(n, &typeId, &flags, &name, &defaultArgument);
if (typeId == -1) {
stream << "?";
} else {
asITypeInfo* ti = function->GetEngine()->GetTypeInfoById(typeId);
if (ti && (ti->GetFlags() & asOBJ_FUNCDEF)) {
stream << ti->GetName();
} else {
const char* typeName = function->GetEngine()->GetTypeDeclaration(typeId, false);
stream << typeName;
}
}
if (flags & asTM_INREF)
stream << " &in ";
else if (flags & asTM_OUTREF)
stream << " &out ";
else if (flags & asTM_INOUTREF)
stream << " &inout ";
if (name) {
stream << " " << name;
}
if (n != function->GetParamCount() - 1)
stream << ", ";
}
}
void printClassTypeList(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetObjectTypeCount(); ++i) {
asITypeInfo* t = engine.GetObjectTypeByIndex(i);
if (!t)
continue;
std::string_view ns = t->GetNamespace();
if (!ns.empty())
stream << "namespace " << ns << " {\n";
stream << "class " << t->GetName();
if (std::string("any") == t->GetName())
stream << " ";
if (t->GetSubTypeCount() > 0) {
stream << "<";
for (int sub = 0; sub < t->GetSubTypeCount(); ++sub) {
if (sub > 0)
stream << ", ";
const auto st = t->GetSubType(sub);
stream << st->GetName();
}
stream << ">";
}
stream << " {\n";
for (int i = 0; i < t->GetChildFuncdefCount(); ++i) {
asITypeInfo* ftype = t->GetChildFuncdef(i);
asIScriptFunction* func = ftype->GetFuncdefSignature();
std::string decl = func->GetDeclaration(false, false, true);
stream << "\tfuncdef " << decl << ";\n";
}
for (int j = 0; j < t->GetFactoryCount(); ++j) {
asIScriptFunction* f = t->GetFactoryByIndex(j);
stream << "\t" << t->GetName() << "(";
writeParameters(f);
stream << ");\n";
}
for (int j = 0; j < t->GetBehaviourCount(); ++j) {
asEBehaviours behaviours;
const auto f = t->GetBehaviourByIndex(j, &behaviours);
if (behaviours == asBEHAVE_CONSTRUCT ||
behaviours == asBEHAVE_DESTRUCT ||
behaviours == asBEHAVE_FACTORY)
stream << "\t" << f->GetDeclaration(false, false, true)
<< ";\n";
}
for (int j = 0; j < t->GetMethodCount(); ++j) {
const auto m = t->GetMethodByIndex(j);
stream << "\t";
int methodReturnId = m->GetReturnTypeId();
if (methodReturnId == -1) {
stream << "? ";
} else {
stream << t->GetEngine()->GetTypeDeclaration(methodReturnId) << " ";
}
stream << m->GetName() << "(";
writeParameters(m);
stream << ")";
// stream << "\t" << m->GetDeclaration(false, false, true);
if (m->IsProperty())
stream << " property";
stream << ";\n";
}
for (int j = 0; j < t->GetPropertyCount(); ++j) {
stream << "\t" << t->GetPropertyDeclaration(j, false) << ";\n";
}
for (int j = 0; j < t->GetChildFuncdefCount(); ++j) {
stream
<< "\tfuncdef "
<< t->GetChildFuncdef(j)->GetFuncdefSignature()->GetDeclaration(
false)
<< ";\n";
}
stream << "}\n";
if (!ns.empty())
stream << "}\n\n";
}
}
void printGlobalFunctionList(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetGlobalFunctionCount(); ++i) {
const auto f = engine.GetGlobalFunctionByIndex(i);
std::string_view ns = f->GetNamespace();
if (!ns.empty())
stream << "namespace " << ns << " { ";
int methodReturnId = f->GetReturnTypeId();
if (methodReturnId == -1) {
stream << "? ";
} else {
stream << f->GetEngine()->GetTypeDeclaration(methodReturnId) << " ";
}
stream << f->GetName() << "(";
writeParameters(f);
stream << ")";
// stream << "\t" << m->GetDeclaration(false, false, true);
if (f->IsProperty())
stream << " property";
stream << ";";
if (!ns.empty())
stream << "\t}";
stream << "\n";
}
}
void printGlobalPropertyList(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetGlobalPropertyCount(); ++i) {
const char* name;
const char* ns0;
int type;
engine.GetGlobalPropertyByIndex(i, &name, &ns0, &type, nullptr, nullptr,
nullptr, nullptr);
std::string t = engine.GetTypeDeclaration(type, true);
if (t.empty())
continue;
std::string_view ns = ns0;
if (!ns.empty())
stream << "namespace " << ns << " { ";
stream << t << " " << name << ";";
if (!ns.empty())
stream << " }";
stream << "\n";
}
}
void printGlobalTypedef(const asIScriptEngine& engine) {
for (int i = 0; i < engine.GetTypedefCount(); ++i) {
const auto type = engine.GetTypedefByIndex(i);
if (!type)
continue;
std::string_view ns = type->GetNamespace();
if (!ns.empty())
stream << "namespace " << ns << " {\n";
stream << "typedef "
<< engine.GetTypeDeclaration(type->GetTypedefTypeId()) << " "
<< type->GetName() << ";\n";
if (!ns.empty())
stream << "}\n";
}
}
namespace Deer {
namespace StudioAPI {
void Module::generatePredefined() {
stream.clear();
stream.str("");
str.clear();
stream << "// This file is autogenerated\n";
printFuncList(*scriptEngine);
printEnumList(*scriptEngine);
printClassTypeList(*scriptEngine);
printGlobalFunctionList(*scriptEngine);
printGlobalPropertyList(*scriptEngine);
printGlobalTypedef(*scriptEngine);
Path path = Path(moduleInfo.modulePath) / "as.predefined";
std::ofstream predefinedFile(path);
std::string info = stream.str();
predefinedFile.write(info.c_str(), info.size());
predefinedFile.close();
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,58 +0,0 @@
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "angelscript.h"
#include "imgui.h"
namespace Deer {
namespace StudioAPI {
Panel::Panel(asITypeInfo* _info)
: Service(_info) {
renderFunction = type->GetMethodByDecl("void render()");
menuBarFunction = type->GetMethodByDecl("void menuBar()");
}
void Panel::updateTypes(asIScriptModule* typeInfo) {
Service::updateTypes(typeInfo);
renderFunction = type->GetMethodByDecl("void render()");
menuBarFunction = type->GetMethodByDecl("void menuBar()");
}
void Panel::render() {
// IMPLEMENT REMOVE PADDING
if (menuBarFunction) {
ImGui::Begin(type->GetName(), (bool*)0, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar()) {
AS_CHECK(scriptContext->Prepare(menuBarFunction));
AS_CHECK(scriptContext->SetObject(object));
AS_CHECK(scriptContext->Execute());
AS_CHECK(scriptContext->Unprepare());
ImGui::EndMenuBar();
}
} else {
ImGui::Begin(type->GetName());
}
// This is to make sure that right click activates the window
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) &&
(ImGui::IsMouseClicked(ImGuiMouseButton_Right) ||
ImGui::IsMouseClicked(ImGuiMouseButton_Middle))) {
ImGui::SetWindowFocus();
}
AS_CHECK(scriptContext->Prepare(renderFunction));
AS_CHECK(scriptContext->SetObject(object));
AS_CHECK(scriptContext->Execute());
AS_CHECK(scriptContext->Unprepare());
ImGui::End();
}
Panel::~Panel() {}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,298 +0,0 @@
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#include "angelscript.h"
#include "scriptbuilder.h"
#include <cstring>
#include <string>
#include <vector>
namespace Deer {
namespace StudioAPI {
void Service::init() {
asIScriptFunction* constructorFunction = getFactory(type);
if (!constructorFunction) {
DEER_CORE_ERROR("Error while initing {}", type->GetName());
return;
}
AS_CHECK(scriptContext->Prepare(constructorFunction));
AS_CHECK(scriptContext->Execute());
object = *(asIScriptObject**)scriptContext->GetAddressOfReturnValue();
if (!object) {
DEER_CORE_ERROR("Error while initing {}", type->GetName());
AS_CHECK(scriptContext->Unprepare());
return;
}
object->AddRef();
AS_CHECK(scriptContext->Unprepare());
for (Scope<ServiceExposedFunctionData>& exposedFunction : exposedFunctions) {
exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str());
exposedFunction->exposedObject = object;
}
if (!initFunction)
return;
AS_CHECK(scriptContext->Prepare(initFunction));
AS_CHECK(scriptContext->SetObject(object));
AS_CHECK(scriptContext->Execute());
AS_CHECK(scriptContext->Unprepare());
}
void Service::registerApiExpose() {
int functionCount = type->GetMethodCount();
for (int i = 0; i < functionCount; i++) {
asIScriptFunction* function = type->GetMethodByIndex(i);
bool containsExposeMetadata = false;
std::vector<std::string> metadata = scriptBuilder.GetMetadataForTypeMethod(type->GetTypeId(), function);
for (std::string& meta : metadata) {
if (meta == "Expose") {
containsExposeMetadata = true;
break;
}
}
if (!containsExposeMetadata)
continue;
registerExposedFunction(function);
}
}
void Service::registerExposedFunction(asIScriptFunction* function) {
asITypeInfo* returnType = scriptEngine->GetTypeInfoById(function->GetReturnTypeId());
if (returnType && returnType->GetModule()) {
DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type for return type", function->GetDeclaration());
return;
}
std::string declaration;
declaration = scriptEngine->GetTypeDeclaration(function->GetReturnTypeId(), false);
declaration += " ";
declaration += function->GetName();
declaration += "(";
int paramCount = function->GetParamCount();
for (int n = 0; n < paramCount; n++) {
int typeId;
asDWORD flags;
const char* name;
const char* defaultArgument;
function->GetParam(n, &typeId, &flags, &name, &defaultArgument);
asITypeInfo* paramType = scriptEngine->GetTypeInfoById(typeId);
if (paramType && paramType->GetModule()) {
DEER_CORE_ERROR("Error registering function {}, you can not register engine non specific type in parameter", function->GetDeclaration());
return;
}
const char* typeName = scriptEngine->GetTypeDeclaration(typeId, false);
declaration += typeName;
if (flags & asTM_INREF)
declaration += " in ";
else if (flags & asTM_OUTREF)
declaration += " out ";
else if (flags & asTM_INOUTREF)
declaration += " inout ";
if (name) {
declaration += " ";
declaration += name;
}
if (defaultArgument) {
declaration += "= ";
declaration += defaultArgument;
}
if (n != paramCount - 1)
declaration += ", ";
}
declaration += ")";
exposedFunctions.push_back(MakeScope<ServiceExposedFunctionData>());
ServiceExposedFunctionData* exposedFunctionData = exposedFunctions.back().get();
exposedFunctionData->exposedFunction = function;
exposedFunctionData->exposedFunctionName = function->GetName();
exposedFunctionData->exposedObject = object;
DEER_CORE_TRACE("Registering {}", declaration.c_str());
scriptEngine->RegisterGlobalFunction(declaration.c_str(), asFUNCTION(service_exposed_generic_call), asCALL_GENERIC, exposedFunctionData);
}
void service_exposed_generic_call(asIScriptGeneric* genericFun) {
AS_CHECK(scriptContext->PushState());
ServiceExposedFunctionData* data = (ServiceExposedFunctionData*)genericFun->GetAuxiliary();
AS_CHECK(scriptContext->Prepare(data->exposedFunction));
AS_CHECK(scriptContext->SetObject(data->exposedObject));
int argCount = genericFun->GetArgCount();
for (int i = 0; i < argCount; ++i) {
int typeId = genericFun->GetArgTypeId(i);
if (typeId & asTYPEID_OBJHANDLE) {
void* obj = genericFun->GetAddressOfArg(i);
AS_CHECK(scriptContext->SetArgAddress(i, obj));
} else if (typeId & asTYPEID_MASK_OBJECT) {
void* obj = genericFun->GetArgObject(i);
AS_CHECK(scriptContext->SetArgObject(i, obj));
} else {
switch (typeId) {
case asTYPEID_BOOL:
case asTYPEID_INT8:
case asTYPEID_UINT8:
AS_CHECK(scriptContext->SetArgByte(i, genericFun->GetArgByte(i)));
break;
case asTYPEID_INT16:
case asTYPEID_UINT16:
AS_CHECK(scriptContext->SetArgWord(i, genericFun->GetArgWord(i)));
break;
case asTYPEID_INT32:
case asTYPEID_UINT32:
AS_CHECK(scriptContext->SetArgDWord(i, genericFun->GetArgDWord(i)));
break;
case asTYPEID_INT64:
case asTYPEID_UINT64:
AS_CHECK(scriptContext->SetArgQWord(i, genericFun->GetArgQWord(i)));
break;
case asTYPEID_FLOAT:
AS_CHECK(scriptContext->SetArgFloat(i, genericFun->GetArgFloat(i)));
break;
case asTYPEID_DOUBLE:
AS_CHECK(scriptContext->SetArgDouble(i, genericFun->GetArgDouble(i)));
break;
default:
AS_CHECK(scriptContext->SetArgObject(i, genericFun->GetArgObject(i)));
break;
}
}
}
AS_CHECK(scriptContext->Execute());
int retTypeId = genericFun->GetReturnTypeId();
if (retTypeId == asTYPEID_VOID) {
} else if (retTypeId & asTYPEID_OBJHANDLE) {
void* obj = scriptContext->GetReturnObject();
genericFun->SetReturnObject(obj);
} else if (retTypeId & asTYPEID_MASK_OBJECT) {
void* obj = scriptContext->GetReturnObject();
genericFun->SetReturnObject(obj);
} else {
switch (retTypeId) {
case asTYPEID_BOOL:
case asTYPEID_INT8:
case asTYPEID_UINT8:
genericFun->SetReturnByte(scriptContext->GetReturnByte());
break;
case asTYPEID_INT16:
case asTYPEID_UINT16:
genericFun->SetReturnWord(scriptContext->GetReturnWord());
break;
case asTYPEID_INT32:
case asTYPEID_UINT32:
genericFun->SetReturnDWord(scriptContext->GetReturnDWord());
break;
case asTYPEID_INT64:
case asTYPEID_UINT64:
genericFun->SetReturnQWord(scriptContext->GetReturnQWord());
break;
case asTYPEID_FLOAT:
genericFun->SetReturnFloat(scriptContext->GetReturnFloat());
break;
case asTYPEID_DOUBLE:
genericFun->SetReturnDouble(scriptContext->GetReturnDouble());
break;
default:
// value types returned by value
genericFun->SetReturnObject(scriptContext->GetReturnObject());
break;
}
}
AS_CHECK(scriptContext->PopState());
}
void Service::updateTypes(asIScriptModule* module) {
type = module->GetTypeInfoByName(typeName.c_str());
updateFunction = type->GetMethodByDecl("void update()");
initFunction = type->GetMethodByDecl("void init()");
shutdownFunction = type->GetMethodByDecl("void shutdown()");
for (Scope<ServiceExposedFunctionData>& exposedFunction : exposedFunctions) {
exposedFunction->exposedFunction = type->GetMethodByName(exposedFunction->exposedFunctionName.c_str());
exposedFunction->exposedObject = object;
}
}
void Service::update() {
if (!updateFunction)
return;
AS_CHECK(scriptContext->Prepare(updateFunction));
AS_CHECK(scriptContext->SetObject(object));
AS_CHECK(scriptContext->Execute());
AS_CHECK(scriptContext->Unprepare());
}
void Service::shutdown() {
if (!shutdownFunction) {
if (object)
object->Release();
AS_CHECK(scriptContext->Unprepare());
return;
}
AS_CHECK(scriptContext->Prepare(shutdownFunction));
AS_CHECK(scriptContext->SetObject(object));
AS_CHECK(scriptContext->Execute());
if (object)
object->Release();
AS_CHECK(scriptContext->Unprepare());
}
Service::Service(asITypeInfo* _type)
: type(_type) {
typeName = _type->GetName();
updateFunction = type->GetMethodByDecl("void update()");
initFunction = type->GetMethodByDecl("void init()");
shutdownFunction = type->GetMethodByDecl("void shutdown()");
}
Service::~Service() {}
} // namespace StudioAPI
} // namespace Deer

View File

@ -38,7 +38,7 @@ namespace Deer {
.updateCallback = worldUpdate, .updateCallback = worldUpdate,
.updateFrequency = 60, .updateFrequency = 60,
.renderCallback = worldRender, .renderCallback = worldRender,
.renderFrequency = 144, .renderFrequency = 166,
}; };
mainWorld = Universe::createWorld(worldSettings); mainWorld = Universe::createWorld(worldSettings);
@ -56,6 +56,9 @@ namespace Deer {
void worldRender(World& world) { void worldRender(World& world) {
Engine::beginRender(); Engine::beginRender();
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = world.getRenderDeltaTime();
static bool opt_fullscreen = true; static bool opt_fullscreen = true;
static bool opt_padding = false; static bool opt_padding = false;
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
@ -102,6 +105,8 @@ namespace Deer {
StudioPanel::render(); StudioPanel::render();
ImGui::ShowDemoWindow();
ImGui::End(); ImGui::End();
Engine::endRender(); Engine::endRender();

View File

@ -1,38 +0,0 @@
#include "DeerStudio/StudioAPI/Engine.h"
#include "DeerStudio/Registers/Registers.h"
#include "DeerStudio/StudioAPI.h"
#include "DeerStudio/StudioAPI/Debug.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
void StudioAPI::registerEngineFunctions() {
asIScriptEngine* scriptEngine = engineRegistry->bind();
REGISTER_GLOBAL_FUNC(engine, "void print(const string&in text)", StudioAPI::print);
REGISTER_GLOBAL_FUNC(engine, "string getParent(const string&in path)", StudioAPI::getParentPath);
REGISTER_GLOBAL_FUNC(engine, "string getParentName(const string&in path)", StudioAPI::getParentPathName);
REGISTER_GLOBAL_FUNC(engine, "string getName(const string&in path)", StudioAPI::getPathName);
REGISTER_GLOBAL_FUNC(engine, "array<string>@ divide(const string&in path)", StudioAPI::dividePath_angelscript);
engineRegistry->unbind()
}
void StudioAPI::registerEngineStructs() {
asIScriptEngine* scriptEngine = engineRegistry->bindNoNamespace();
AS_RET_CHECK(scriptEngine->RegisterInterface("Panel"));
AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("Panel", "void render()"));
AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));
AS_CHECK(scriptEngine->RegisterFuncdef("void SimpleFunction()"));
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunction(any@)"));
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunction(any@, any@)"));
engineRegistry->unbind();
}
void StudioAPI::extractBaseTypes() {
asIScriptEngine* scriptEngine = engineRegistry->bindNoNamespace();
panelBaseType = scriptEngine->GetTypeInfoByDecl("Panel");
serviceBaseType = scriptEngine->GetTypeInfoByDecl("Service");
arrayStringBaseType = scriptEngine->GetTypeInfoByDecl("array<string>");
engineRegistry->unbind();
}
} // namespace Deer

View File

@ -1,111 +0,0 @@
#include "DeerStudio/StudioAPI/Entity.h"
#include "DeerStudio/Registers/Registers.h"
#include "DeerStudio/StudioAPI.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
namespace StudioAPI {
void registerTransformComponentFunctions();
void registerMeshComponentFunction();
void registerShaderComponentFunctions();
void registerComponentComponentFunctions();
} // namespace StudioAPI
void StudioAPI::registerEntityStructs() {
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("EntityChilds", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
entityRegistry->unbind();
}
void StudioAPI::registerEntityFunctions() {
registerTransformComponentFunctions();
registerMeshComponentFunction();
registerShaderComponentFunctions();
registerComponentComponentFunctions();
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "string get_name() const property", StudioAPI::EntityStruct, getName);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void set_name(string& in) property", StudioAPI::EntityStruct, setName);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "int get_id() const property", StudioAPI::EntityStruct, getId);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "Entity createChild(const string& in)", StudioAPI::EntityStruct, createChild);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool get_isRoot() const property", StudioAPI::EntityStruct, isRoot);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void destroy()", StudioAPI::EntityStruct, destroy);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool get_exists() const property", StudioAPI::EntityStruct, exists);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "Entity get_parent() property", StudioAPI::EntityStruct, getParent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void set_parent(Entity) property", StudioAPI::EntityStruct, setParent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool isDescendantOf(Entity)", StudioAPI::EntityStruct, isDescendantOf);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool opEquals(const Entity &in) const", StudioAPI::EntityStruct, opEquals);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "EntityChilds get_childs() const property", StudioAPI::EntityStruct, getSelf);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "TransformComponent get_transform() const property", StudioAPI::EntityStruct, getSelf);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "MeshComponent getMeshComponent()", StudioAPI::EntityStruct, getMeshComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "MeshComponent createMeshComponent()", StudioAPI::EntityStruct, createMeshComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasMeshComponent()", StudioAPI::EntityStruct, hasMeshComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeMeshComponent()", StudioAPI::EntityStruct, removeMeshComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "ShaderComponent getShaderComponent()", StudioAPI::EntityStruct, getShaderComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "ShaderComponent createShaderComponent()", StudioAPI::EntityStruct, createShaderComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasShaderComponent()", StudioAPI::EntityStruct, hasShaderComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeShaderComponent()", StudioAPI::EntityStruct, removeShaderComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "CameraComponent getCameraComponent()", StudioAPI::EntityStruct, getCameraComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "CameraComponent createCameraComponent()", StudioAPI::EntityStruct, createCameraComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasCameraComponent()", StudioAPI::EntityStruct, hasCameraComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeCameraComponent()", StudioAPI::EntityStruct, removeCameraComponent);
REGISTER_OBJECT_METHOD(scriptEngine, "EntityChilds", "int get_count() const property", StudioAPI::EntityChildArrayStruct, getChildCount);
REGISTER_OBJECT_METHOD(scriptEngine, "EntityChilds", "Entity opIndex(int) const", StudioAPI::EntityChildArrayStruct, getChild);
scriptEngine = entityRegistry->bind();
REGISTER_GLOBAL_FUNC(scriptEngine, "Entity getRoot()", StudioAPI::getRoot);
entityRegistry->unbind();
}
void StudioAPI::registerMeshComponentFunction() {
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "bool get_isActive() const property", StudioAPI::MeshComponentStruct, isActive);
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "bool get_hasMesh() const property", StudioAPI::MeshComponentStruct, hasMesh);
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void clear()", StudioAPI::MeshComponentStruct, clear);
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "GPUMesh get_meshResource() property", StudioAPI::MeshComponentStruct, getMesh);
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void set_meshResource(GPUMesh) property", StudioAPI::MeshComponentStruct, setMesh);
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void set_isActive(const bool) const property", StudioAPI::MeshComponentStruct, setActive);
entityRegistry->unbind();
}
void StudioAPI::registerTransformComponentFunctions() {
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_position() const property", StudioAPI::TransformComponentStruct, getPosition);
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_scale() const property", StudioAPI::TransformComponentStruct, getScale);
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_rotation() const property", StudioAPI::TransformComponentStruct, getRotation);
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_position(const vec3) property", StudioAPI::TransformComponentStruct, setPosition);
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_scale(const vec3) property", StudioAPI::TransformComponentStruct, setScale);
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_rotation(const vec3) property", StudioAPI::TransformComponentStruct, setRotation);
entityRegistry->unbind();
}
void StudioAPI::registerShaderComponentFunctions() {
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "bool get_hasShader() const property", StudioAPI::ShaderComponentStruct, hasShader);
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void clear()", StudioAPI::ShaderComponentStruct, clear);
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "Shader get_shader() const property", StudioAPI::ShaderComponentStruct, getShader);
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void set_shader(Shader) property", StudioAPI::ShaderComponentStruct, setShader);
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "Texture get_texture() const property", StudioAPI::ShaderComponentStruct, getTexture);
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void set_texture(Texture) property", StudioAPI::ShaderComponentStruct, setTexture);
entityRegistry->unbind();
}
void StudioAPI::registerComponentComponentFunctions() {
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_fov() const property", StudioAPI::CameraComponentStruct, getFov);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_aspectRatio() const property", StudioAPI::CameraComponentStruct, getAspectRation);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_nearZ() const property", StudioAPI::CameraComponentStruct, getNearZ);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_farZ() const property", StudioAPI::CameraComponentStruct, getFarZ);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_fov(float) property", StudioAPI::CameraComponentStruct, setFov);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_aspectRatio(float) property", StudioAPI::CameraComponentStruct, setAspectRation);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_nearZ(float) property", StudioAPI::CameraComponentStruct, setNearZ);
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_farZ(float) property", StudioAPI::CameraComponentStruct, setFarZ);
entityRegistry->unbind();
}
} // namespace Deer

View File

@ -1,25 +0,0 @@
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
#include "DeerStudio/Registers/Registers.h"
#include "DeerStudio/StudioAPI.h"
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
void registerEntityEnvironmentStructs();
void registerEntityEnvironmentFunctions();
void StudioAPI::registerEntityEnvironmentStructs() {
AS_CHECK(scriptEngine->RegisterObjectType("EntityEnvironment", sizeof(StudioAPI::EntityEnvironmentStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityEnvironmentStruct>() | asOBJ_APP_CLASS_ALLINTS));
}
void StudioAPI::registerEntityEnvironmentFunctions() {
scriptEngine->SetDefaultNamespace("Resource");
REGISTER_GLOBAL_FUNC("EntityEnvironment getMainEntityEnvironment()", StudioAPI::getMainEntityEnvironment);
REGISTER_GLOBAL_FUNC("EntityEnvironment createLoadEntityEnvironment(const string&in envId)", StudioAPI::createLoadEntityEnvironment);
scriptEngine->SetDefaultNamespace("");
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

View File

@ -1,21 +0,0 @@
#include "DeerStudio/StudioAPI/FrameBuffer.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
void AngelScriptEngine::registerFrameBufferStructs() {
AS_CHECK(scriptEngine->RegisterObjectType("FrameBuffer", sizeof(StudioAPI::FrameBufferStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::FrameBufferStruct>() | asOBJ_APP_CLASS_ALLINTS));
}
void AngelScriptEngine::registerFrameBufferFunctions() {
REGISTER_OBJECT_METHOD("FrameBuffer", "void clearRGBA(int, int, int, int)", StudioAPI::FrameBufferStruct, clearRGBA);
REGISTER_OBJECT_METHOD("FrameBuffer", "int get_height() const property", StudioAPI::FrameBufferStruct, getHeight);
REGISTER_OBJECT_METHOD("FrameBuffer", "void resize(int, int)", StudioAPI::FrameBufferStruct, resize);
REGISTER_OBJECT_METHOD("FrameBuffer", "string get_name() const property", StudioAPI::FrameBufferStruct, getName);
REGISTER_OBJECT_METHOD("FrameBuffer", "bool isValid()", StudioAPI::FrameBufferStruct, isValid);
REGISTER_EXT_OBJECT_CONSTRUCTOR("FrameBuffer", "void f()", StudioAPI::frameBuffer_constructor);
scriptEngine->SetDefaultNamespace("Resource");
REGISTER_GLOBAL_FUNC("FrameBuffer createLoadRGBA8FrameBuffer(const string&in, int width, int height, int samples = 4)", StudioAPI::createLoadRGBA8FrameBuffer);
scriptEngine->SetDefaultNamespace("");
}
} // namespace Deer

View File

@ -1,64 +0,0 @@
#include "DeerStudio/StudioAPI/Math.h"
#include "DeerStudio/Registers/Registers.h"
#include "DeerStudio/StudioAPI.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
void StudioAPI::registerMathStructs() {
asIScriptEngine* scriptEngine = mathRegistry->bindNoNamespace();
scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(StudioAPI::vec3_constructor), asCALL_CDECL_OBJLAST);
scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f(float, float = 0, float = 0)", asFUNCTION(StudioAPI::vec3_constructor_params), asCALL_CDECL_OBJLAST);
scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x));
scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y));
scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z));
scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS);
scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x));
scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y));
scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z));
scriptEngine->RegisterObjectProperty("quat", "float w", asOFFSET(glm::quat, w));
scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>());
scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position));
scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale));
scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation));
scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>());
scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov));
scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect));
scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ));
scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ));
scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>());
scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera));
scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform));
mathRegistry->unbind();
}
void StudioAPI::registerMathFunctions() {
asIScriptEngine* scriptEngine = mathRegistry->bindNoNamespace();
mathRegistry->bindNoNamespace();
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opAdd(const vec3 &in)", StudioAPI::vec3_add);
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opSub(const vec3 &in) const", StudioAPI::vec3_sub);
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opNeg() const", StudioAPI::vec3_neg);
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul(float) const", StudioAPI::vec3_mult);
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul_r(float) const", StudioAPI::vec3_mult);
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f()", StudioAPI::quat_construct);
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f(float, float, float, float)", StudioAPI::quat_constructFromValue);
REGISTER_EXT_OBJECT_DESTRUCTOR("quat", "void f()", StudioAPI::quat_destruct);
REGISTER_EXT_OBJECT_METHOD("quat", "quat opMul(const quat &in) const", StudioAPI::quat_multiply);
REGISTER_EXT_OBJECT_METHOD("quat", "vec3 getEuler() const", StudioAPI::quat_getEuler);
REGISTER_EXT_OBJECT_METHOD("quat", "void setEuler(vec3)", StudioAPI::quat_setEuler);
REGISTER_EXT_OBJECT_CONSTRUCTOR("Transform", "void f()", StudioAPI::transform_construct);
REGISTER_EXT_OBJECT_CONSTRUCTOR("Camera", "void f()", StudioAPI::camera_construct);
REGISTER_EXT_OBJECT_CONSTRUCTOR("WorldCamera", "void f()", StudioAPI::sceneCamera_Construct);
REGISTER_EXT_OBJECT_METHOD("Transform", "vec3 relative(vec3)", StudioAPI::transform_relative);
mathRegistry->unbind();
}
} // namespace Deer

View File

@ -1,41 +0,0 @@
#pragma once
#include "DeerStudio/StudioAPI.h"
#include "DeerStudio/StudioAPI/Resources.h"
namespace Deer {
namespace StudioAPI {
Scripting::Registry* engineRegistry = nullptr;
Scripting::Registry* uiRegistry = nullptr;
Scripting::Registry* entityRegistry = nullptr;
Scripting::Registry* resourceRegistry = nullptr;
Scripting::Registry* math = nullptr;
} // namespace StudioAPI
void StudioAPI::registerStudioAPI() {
uiRegistry = Scripting::createRegistry("UI");
entityRegistry = Scripting::createRegistry("Entity");
registerStructs();
registerFunctions();
}
void StudioAPI::registerStructs() {
registerMathStructs();
registerUIStructs();
registerResourceStructs();
registerEntityEnvironmentStructs();
registerEntityStructs();
registerEngineStructs();
registerFrameBufferStructs();
}
void StudioAPI::registerFunctions() {
registerUIFunctions();
registerMathFunctions();
registerResourceFunctions();
registerEntityEnvironmentFunctions();
registerEntityFunctions();
registerEngineFunctions();
registerFrameBufferFunctions();
}
} // namespace Deer

View File

@ -1,52 +0,0 @@
#pragma once
#include "angelscript.h"
#include "DeerStudio/AngelScriptEngine.h"
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
#define REGISTER_GLOBAL_FUNC(scriptEngine, funcdef, func) \
AS_CHECK(scriptEngine->RegisterGlobalFunction( \
funcdef, \
asFUNCTION(func), asCALL_CDECL))
#define REGISTER_OBJECT_METHOD(scriptEngine, clasdef, funcdef, clas, func) \
AS_CHECK(scriptEngine->RegisterObjectMethod( \
clasdef, funcdef, \
asMETHOD(clas, func), asCALL_THISCALL))
#define REGISTER_EXT_OBJECT_METHOD(scriptEngine, clasdef, funcdef, func) \
AS_CHECK(scriptEngine->RegisterObjectMethod( \
clasdef, funcdef, \
asFUNCTION(func), asCALL_CDECL_OBJLAST))
#define REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, clasdef, funcdef, func) \
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
clasdef, asBEHAVE_CONSTRUCT, funcdef, \
asFUNCTION(func), asCALL_CDECL_OBJLAST))
#define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
clasdef, asBEHAVE_DESTRUCT, funcdef, \
asFUNCTION(func), asCALL_CDECL_OBJLAST))
namespace Deer {
namespace StudioAPI {
void registerStructs();
void registerFunctions();
void registerUIFunctions();
void registerMathFunctions();
void registerResourceFunctions();
void registerEntityEnvironmentFunctions();
void registerEntityFunctions();
void registerEngineFunctions();
void registerFrameBufferFunctions();
void registerMathStructs();
void registerUIStructs();
void registerResourceStructs();
void registerEntityEnvironmentStructs();
void registerEntityStructs();
void registerEngineStructs();
void registerFrameBufferStructs();
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,45 +0,0 @@
#include "DeerStudio/StudioAPI/Resources.h"
#include "DeerRender/Resource.h"
namespace Deer {
namespace StudioAPI {
template <class T>
void registerResourceBasics(const char* objName) {
REGISTER_OBJECT_METHOD(objName, "bool isValid() const", StudioAPI::APIResource<T>, isValid);
REGISTER_OBJECT_METHOD(objName, "string get_name() const property", StudioAPI::APIResource<T>, getName);
REGISTER_OBJECT_METHOD(objName, "string get_path() const property", StudioAPI::APIResource<T>, getPath);
REGISTER_OBJECT_METHOD(objName, "int get_resourceId() const property", StudioAPI::APIResource<T>, getResourceId);
}
} // namespace StudioAPI
void StudioAPI::registerResourceStructs() {
scriptEngine->SetDefaultNamespace("");
AS_CHECK(scriptEngine->RegisterObjectType("GPUMesh", sizeof(StudioAPI::APIResource<GPUMesh>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<GPUMesh>>()));
AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(StudioAPI::APIResource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<Shader>>()));
AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(StudioAPI::APIResource<Texture>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<Shader>>()));
scriptEngine->SetDefaultNamespace("");
scriptEngine->RegisterEnum("ResourceType");
scriptEngine->RegisterEnumValue("ResourceType", "None", (int)StudioAPI::ResourceType::NONE);
scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)StudioAPI::ResourceType::MESH);
scriptEngine->RegisterEnumValue("ResourceType", "Shader", (int)StudioAPI::ResourceType::SHADER);
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)StudioAPI::ResourceType::TEXTURE);
}
void StudioAPI::registerResourceFunctions() {
registerResourceBasics<GPUMesh>("GPUMesh");
registerResourceBasics<Shader>("Shader");
registerResourceBasics<Texture>("Texture");
scriptEngine->SetDefaultNamespace("Resource");
REGISTER_GLOBAL_FUNC("GPUMesh loadGPUMesh(string&in path)", ResourceManager<GPUMesh>::loadResource<ResourceDataSource>);
REGISTER_GLOBAL_FUNC("Shader loadShader(string&in path)", ResourceManager<Shader>::loadResource<ResourceDataSource>);
REGISTER_GLOBAL_FUNC("Texture loadTexture(string&in path)", ResourceManager<Texture>::loadResource<ResourceDataSource>);
REGISTER_GLOBAL_FUNC("array<string>@ getResourceFolders(string&in path)", StudioAPI::getResourceFolders);
REGISTER_GLOBAL_FUNC("array<string>@ getResourceFiles(string&in path)", StudioAPI::getResourceFiles);
REGISTER_GLOBAL_FUNC("ResourceType getResourceType(string&in path)", StudioAPI::getResourceType);
scriptEngine->SetDefaultNamespace("");
}
} // namespace Deer

View File

@ -1,15 +0,0 @@
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
#include "DeerStudio/StudioAPI/Layout.h"
#include "DeerStudio/StudioAPI/Menu.h"
#include "DeerStudio/StudioAPI/Resources.h"
#include "DeerStudio/StudioAPI/UI.h"
#include "imgui.h"
namespace Deer {
void AngelScriptEngine::registerUIFunctions() {
}
void AngelScriptEngine::registerUIStructs() {
}
} // namespace Deer

View File

@ -0,0 +1,83 @@
#include "DeerStudio/StudioAPI.h"
#include "DeerRender/Mesh.h"
#include "DeerRender/Scripting.h"
#include "DeerRender/Shader.h"
#include "DeerRender/Texture.h"
#include "DeerStudio/EditorDataImporter.h"
#include "DeerStudio/EditorDataSource.h"
#include "DeerStudio/ResourceDataSource.h"
#include "angelscript.h"
#include "scriptany.h"
#include "scriptarray.h"
#include "scriptdictionary.h"
namespace Deer {
Resource<Texture> StudioAPI::getIcon(std::string& icon) {
Path iconPath = Path("Icons") / icon;
return ResourceManager<Texture>::loadResource<EditorDataSource>(iconPath);
}
ResourceType StudioAPI::getResourceType(std::string& dir) {
Path path(dir);
std::string extension = path.extension().string();
if (extension == ".obj" || extension == ".fbx" || extension == ".dae" ||
extension == ".3ds" || extension == ".ply" || extension == ".stl" ||
extension == ".glb" || extension == ".gltf") {
return ResourceType::MESH;
}
if (extension == ".glsl")
return ResourceType::SHADER;
if (extension == ".png")
return ResourceType::TEXTURE;
return ResourceType::NONE;
};
CScriptArray* StudioAPI::getResourceFolders(std::string& path_s) {
asITypeInfo* arrayString = Scripting::getScriptEngine()->GetTypeInfoByDecl("array<string>");
CScriptArray* array = CScriptArray::Create(arrayString);
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
try {
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
if (entry.is_directory()) {
std::string s = entry.path().lexically_relative("Resources").string();
array->Resize(array->GetSize() + 1);
array->SetValue(array->GetSize() - 1, &s);
}
}
} catch (const std::exception& e) {
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFolders(), {}", e.what());
}
return array;
}
CScriptArray* StudioAPI::getResourceFiles(std::string& path_s) {
asITypeInfo* arrayString = Scripting::getScriptEngine()->GetTypeInfoByDecl("array<string>");
CScriptArray* array = CScriptArray::Create(arrayString);
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
try {
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
if (entry.is_regular_file()) {
std::string s = entry.path().lexically_relative("Resources").string();
array->Resize(array->GetSize() + 1);
array->SetValue(array->GetSize() - 1, &s);
}
}
} catch (const std::exception& e) {
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFiles(), {}", e.what());
}
return array;
}
} // namespace Deer

View File

@ -1,60 +0,0 @@
#include "DeerRender/Engine.h"
#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;
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 = Engine::getMainWorld().entityEnvironment.get();
} 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

View File

@ -1,57 +0,0 @@
#include "DeerStudio/StudioAPI/FrameBuffer.h"
#include "DeerRender/FrameBuffer.h"
namespace Deer {
namespace StudioAPI {
int FrameBufferStruct::getWidth() {
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBufferId);
FrameBuffer& frameBuffer = frameBufferResource.getData();
return frameBuffer.getSpecification().width;
}
int FrameBufferStruct::getHeight() {
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBufferId);
FrameBuffer& frameBuffer = frameBufferResource.getData();
return frameBuffer.getSpecification().height;
}
void FrameBufferStruct::resize(int x, int y) {
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBufferId);
FrameBuffer& frameBuffer = frameBufferResource.getData();
frameBuffer.resize(x, y);
}
void FrameBufferStruct::clearRGBA(int r, int g, int b, int a) {
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBufferId);
FrameBuffer& frameBuffer = frameBufferResource.getData();
frameBuffer.bind();
frameBuffer.clear();
uint8_t clearColor[4]{(uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a};
frameBuffer.clearBuffer(0, &clearColor);
frameBuffer.unbind();
}
std::string FrameBufferStruct::getName() {
return Resource<FrameBuffer>::unsafeFromId(frameBufferId).getStorageId();
}
FrameBufferStruct createLoadRGBA8FrameBuffer(std::string& name, int sizeX, int sizeY, int samples) {
FrameBufferData fbd(sizeX, sizeY, samples, FrameBufferData::FrameBufferType::RGBA8);
Resource<FrameBuffer> frameBuffer = ResourceManager<FrameBuffer>::loadResourceFromData(fbd, name);
return FrameBufferStruct(frameBuffer.getResourceId());
}
void frameBuffer_constructor(FrameBufferHandleStruct* mem) {
new (mem) FrameBufferHandleStruct(0);
}
bool FrameBufferStruct::isValid() {
return frameBufferId >= 0 && frameBufferId < 100;
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,17 +0,0 @@
#include "DeerRender/Resource.h"
#include "DeerRender/Texture.h"
#include "DeerStudio/EditorDataSource.h"
#include "DeerStudio/StudioAPI/UI.h"
#include <unordered_map>
namespace Deer {
int StudioAPI::getIconId(const std::string& name) {
Resource<Texture> texture = ResourceManager<Texture>::loadResource<EditorDataSource>(name);
if (texture.isValid())
return texture.getData().getTextureID();
return 0;
}
} // namespace Deer

View File

@ -1,73 +0,0 @@
#include "DeerStudio/StudioAPI/Resources.h"
#include "DeerRender/Log.h"
#include "DeerStudio/AngelScriptEngine.h"
#include "angelscript.h"
#include "scriptarray.h"
#include "scriptstdstring.h"
#include <string>
namespace Deer {
namespace StudioAPI {
ResourceType getResourceType(std::string& dir) {
Path path(dir);
std::string extension = path.extension().string();
if (extension == ".obj" || extension == ".fbx" || extension == ".dae" ||
extension == ".3ds" || extension == ".ply" || extension == ".stl" ||
extension == ".glb" || extension == ".gltf" || extension == ".mtl") {
return ResourceType::MESH;
}
if (extension == ".glsl")
return ResourceType::SHADER;
if (extension == ".png")
return ResourceType::TEXTURE;
return ResourceType::NONE;
};
CScriptArray* getResourceFolders(std::string& path_s) {
CScriptArray* array = CScriptArray::Create(StudioAPI::arrayStringBaseType);
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
try {
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
if (entry.is_directory()) {
std::string s = entry.path().lexically_relative("Resources").string();
array->Resize(array->GetSize() + 1);
array->SetValue(array->GetSize() - 1, &s);
}
}
} catch (const std::exception& e) {
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFolders(), {}", e.what());
}
return array;
}
CScriptArray* getResourceFiles(std::string& path_s) {
CScriptArray* array = CScriptArray::Create(StudioAPI::arrayStringBaseType);
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
try {
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
if (entry.is_regular_file()) {
std::string s = entry.path().lexically_relative("Resources").string();
array->Resize(array->GetSize() + 1);
array->SetValue(array->GetSize() - 1, &s);
}
}
} catch (const std::exception& e) {
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFiles(), {}", e.what());
}
return array;
}
} // namespace StudioAPI
} // namespace Deer

View File

@ -1,6 +1,7 @@
#include "DeerStudio/StudioPanel.h" #include "DeerStudio/StudioPanel.h"
#include "DeerRender/Scripting.h" #include "DeerRender/Scripting.h"
#include "DeerRender/Tools/Memory.h" #include "DeerRender/Tools/Memory.h"
#include "DeerStudio/StudioScripting.h"
#include "imgui.h" #include "imgui.h"
namespace Deer { namespace Deer {
@ -13,6 +14,7 @@ namespace Deer {
} // namespace StudioPanel } // namespace StudioPanel
void StudioPanel::init(World* world) { void StudioPanel::init(World* world) {
StudioScripting::registerStudioScripting();
Scripting::registerInterface("Panel"); Scripting::registerInterface("Panel");
Scripting::registerInterfaceFunction("Panel", "onImGui", Scripting::EventType::void_event); Scripting::registerInterfaceFunction("Panel", "onImGui", Scripting::EventType::void_event);

View File

@ -0,0 +1,32 @@
#include "DeerStudio/StudioScripting.h"
#include "DeerRender/Scripting.h"
#include "DeerStudio/ResourceDataSource.h"
#include "DeerStudio/StudioAPI.h"
#include "DeerRender/Mesh.h"
#include "DeerRender/Shader.h"
#include "DeerRender/Texture.h"
#include "angelscript.h"
namespace Deer {
void StudioScripting::registerStudioScripting() {
asIScriptEngine* scriptEngine = Scripting::getScriptEngine();
scriptEngine->RegisterEnum("ResourceType");
scriptEngine->RegisterEnumValue("ResourceType", "None", (int)ResourceType::NONE);
scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH);
scriptEngine->RegisterEnumValue("ResourceType", "Shader", (int)ResourceType::SHADER);
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)ResourceType::TEXTURE);
scriptEngine->SetDefaultNamespace("StudioAPI");
scriptEngine->RegisterGlobalFunction("Texture loadIcon(string&in)", asFUNCTION(StudioAPI::getIcon), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("GPUMesh loadGPUMesh(string&in path)", asFUNCTION(ResourceManager<GPUMesh>::loadResource<ResourceDataSource>), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("Shader loadShader(string&in path)", asFUNCTION(ResourceManager<Shader>::loadResource<ResourceDataSource>), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("Texture loadTexture(string&in path)", asFUNCTION(ResourceManager<Texture>::loadResource<ResourceDataSource>), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("array<string>@ getResourceFolders(string&in path)", asFUNCTION(StudioAPI::getResourceFolders), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("array<string>@ getResourceFiles(string&in path)", asFUNCTION(StudioAPI::getResourceFiles), asCALL_CDECL);
scriptEngine->RegisterGlobalFunction("ResourceType getResourceType(string&in path)", asFUNCTION(StudioAPI::getResourceType), asCALL_CDECL);
scriptEngine->SetDefaultNamespace("");
}
} // namespace Deer

View File

@ -1,92 +1,61 @@
#include "imgui.h" #include "imgui.h"
void SetupImGuiStyle() {
void SetupImGuiStyle()
{
// Rest style by AaronBeardless from ImThemes // Rest style by AaronBeardless from ImThemes
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
style.Alpha = 1.0f; ImVec4* c = style.Colors;
style.DisabledAlpha = 0.5f;
style.WindowPadding = ImVec2(13.0f, 10.0f);
style.WindowRounding = 0.0f;
style.WindowBorderSize = 1.0f;
style.WindowMinSize = ImVec2(32.0f, 32.0f);
style.WindowTitleAlign = ImVec2(0.5f, 0.5f);
style.WindowMenuButtonPosition = ImGuiDir_Right;
style.ChildRounding = 3.0f;
style.ChildBorderSize = 1.0f;
style.PopupRounding = 5.0f;
style.PopupBorderSize = 1.0f;
style.FramePadding = ImVec2(8.0f, 8.1f);
style.FrameRounding = 2.0f;
style.FrameBorderSize = 0.0f;
style.ItemSpacing = ImVec2(3.0f, 3.0f);
style.ItemInnerSpacing = ImVec2(3.0f, 8.0f);
style.CellPadding = ImVec2(6.0f, 14.1f);
style.IndentSpacing = 20.0f;
style.ColumnsMinSpacing = 10.0f;
style.ScrollbarSize = 10.0f;
style.ScrollbarRounding = 2.0f;
style.GrabMinSize = 12.1f;
style.GrabRounding = 1.0f;
style.TabRounding = 2.0f;
style.TabBorderSize = 0.0f;
style.ColorButtonPosition = ImGuiDir_Right;
style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
style.SelectableTextAlign = ImVec2(0.0f, 0.0f);
style.Colors[ImGuiCol_Text] = ImVec4(0.98039216f, 0.98039216f, 0.98039216f, 1.0f); style.FramePadding.x = 10;
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.49803922f, 0.49803922f, 0.49803922f, 1.0f); style.FramePadding.y = 4;
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.09411765f, 0.09411765f, 0.09411765f, 1.0f); style.WindowPadding = ImVec2(10, 10);
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.15686275f, 0.15686275f, 0.15686275f, 1.0f); style.ItemSpacing = ImVec2(4, 4);
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.09411765f, 0.09411765f, 0.09411765f, 1.0f);
style.Colors[ImGuiCol_Border] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); // --- Backgrounds ---
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); c[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.11f, 0.12f, 1.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); c[ImGuiCol_ChildBg] = ImVec4(0.10f, 0.11f, 0.12f, 1.00f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); c[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.047058824f); c[ImGuiCol_MenuBarBg] = ImVec4(0.12f, 0.13f, 0.14f, 1.00f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.11764706f, 0.11764706f, 0.11764706f, 1.0f);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.15686275f, 0.15686275f, 0.15686275f, 1.0f); // --- Frames ---
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.11764706f, 0.11764706f, 0.11764706f, 1.0f); c[ImGuiCol_FrameBg] = ImVec4(0.18f, 0.19f, 0.20f, 1.00f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); c[ImGuiCol_FrameBgHovered] = ImVec4(0.22f, 0.24f, 0.26f, 1.00f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.10980392f); c[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.27f, 0.30f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(1.0f, 1.0f, 1.0f, 0.39215687f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.47058824f); // --- Titles ---
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.09803922f); c[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.10f, 0.11f, 1.00f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); c[ImGuiCol_TitleBgActive] = ImVec4(0.13f, 0.15f, 0.17f, 1.00f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.0f, 1.0f, 1.0f, 0.39215687f); c[ImGuiCol_TitleBgCollapsed] = ImVec4(0.09f, 0.10f, 0.11f, 1.00f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.3137255f);
style.Colors[ImGuiCol_Button] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); // --- Buttons (modern muted blue) ---
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); c[ImGuiCol_Button] = ImVec4(0.20f, 0.23f, 0.26f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.047058824f); c[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.31f, 0.36f, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); c[ImGuiCol_ButtonActive] = ImVec4(0.30f, 0.36f, 0.42f, 1.00f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.047058824f); // --- Headers / selection ---
style.Colors[ImGuiCol_Separator] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); c[ImGuiCol_Header] = ImVec4(0.22f, 0.27f, 0.32f, 1.00f);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); c[ImGuiCol_HeaderHovered] = ImVec4(0.28f, 0.34f, 0.40f, 1.00f);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); c[ImGuiCol_HeaderActive] = ImVec4(0.32f, 0.39f, 0.46f, 1.00f);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); // --- Tabs ---
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); c[ImGuiCol_Tab] = ImVec4(0.14f, 0.15f, 0.17f, 1.00f);
style.Colors[ImGuiCol_Tab] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); c[ImGuiCol_TabHovered] = ImVec4(0.28f, 0.33f, 0.39f, 1.00f);
style.Colors[ImGuiCol_TabHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); c[ImGuiCol_TabActive] = ImVec4(0.20f, 0.25f, 0.30f, 1.00f);
style.Colors[ImGuiCol_TabActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.3137255f); c[ImGuiCol_TabUnfocused] = ImVec4(0.14f, 0.15f, 0.17f, 1.00f);
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.0f, 0.0f, 0.0f, 0.15686275f); c[ImGuiCol_TabUnfocusedActive] = ImVec4(0.18f, 0.22f, 0.26f, 1.00f);
style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f);
style.Colors[ImGuiCol_PlotLines] = ImVec4(1.0f, 1.0f, 1.0f, 0.3529412f); // --- Scrollbars ---
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); c[ImGuiCol_ScrollbarBg] = ImVec4(0.11f, 0.12f, 0.13f, 1.00f);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.0f, 1.0f, 1.0f, 0.3529412f); c[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.28f, 0.32f, 1.00f);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); c[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.30f, 0.35f, 0.40f, 1.00f);
style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.15686275f, 0.15686275f, 0.15686275f, 1.0f); c[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.34f, 0.40f, 0.46f, 1.00f);
style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(1.0f, 1.0f, 1.0f, 0.3137255f);
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(1.0f, 1.0f, 1.0f, 0.19607843f); // --- Accents (VS Codestyle cyan-blue) ---
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); c[ImGuiCol_CheckMark] = ImVec4(0.38f, 0.55f, 0.75f, 1.00f);
style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.019607844f); c[ImGuiCol_SliderGrab] = ImVec4(0.38f, 0.55f, 0.75f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); c[ImGuiCol_SliderGrabActive] = ImVec4(0.45f, 0.65f, 0.85f, 1.00f);
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.16862746f, 0.23137255f, 0.5372549f, 1.0f);
style.Colors[ImGuiCol_NavHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // --- Text ---
style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.7f); c[ImGuiCol_Text] = ImVec4(0.88f, 0.88f, 0.88f, 1.00f);
style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.8f, 0.8f, 0.8f, 0.2f); c[ImGuiCol_TextDisabled] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f);
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.5647059f);
} }

View File

@ -1,21 +0,0 @@
class ActiveEntity : Service {
Entity entity;
[Expose]
Entity getActiveEntity() {
return entity;
}
[Expose]
void setActiveEntity(Entity ent) {
entity = ent;
}
void init() {
entity = Resource::getMainEntityEnvironment().getRootEntity();
}
[Expose]
void wtf() {
Engine::print("Exposed");
}
}

View File

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

View File

@ -1,40 +0,0 @@
class AddComponentRender {
Entity entity;
AddComponentRender(Entity _entity) {
entity = _entity;
}
void addComponentPopup() {
ImGui::titleCenter("\uf055 Add Component");
ImGui::separator();
ImGui::subMenu("Renderin ", SimpleFunction(this.addComponentRendering));
if (ImGui::menuItem("Script Component )) {
}
}
void addComponentRendering() {
if (entity.hasMeshComponent()) {
ImGui::menuItemDisabled("\uf248 Mesh Render Component");
} else {
if (ImGui::menuItem("\uf248 Mesh Render Component )) {
entity.createMeshComponent();
}
}
if (entity.hasShaderComponent()) {
ImGui::menuItemDisabled("\uf042 Shader Render Component");
} else {
if (ImGui::menuItem("\uf042 Shader Render Component )) {
entity.createShaderComponent();
}
}
if (entity.hasCameraComponent()) {
ImGui::menuItemDisabled("\uf030 Camera Component");
} else {
if (ImGui::menuItem("\uf030 Camera Component )) {
entity.createCameraComponent();
}
}
}
}

View File

@ -1,49 +0,0 @@
class CameraComponentRender {
Entity entity;
CameraComponentRender(Entity _entity) {
entity = _entity;
}
void render() {
if (!entity.hasCameraComponent())
return;
CameraComponent cameraComponent = entity.getCameraComponent();
float fov = cameraComponent.fov;
float aspect = cameraComponent.aspectRatio;
float nearZ = cameraComponent.nearZ;
float farZ = cameraComponent.farZ;
fov = ImGui::magicSlider("Fo ", f v, 0.1);
if (fov > 180)
fov = 180;
if (fov < 0)
fov = 0;
aspect = ImGui::magicSlider("Aspect Rati ", aspe t, 0.1);
if (aspect < 0.1)
aspect = 0.1;
nearZ = ImGui::magicSlider("Near ", nea Z, 0.1);
if (nearZ < 0)
nearZ = 0;
farZ = ImGui::magicSlider("Far ", fa Z, 0.1);
if (farZ < 0)
farZ = 0;
if (nearZ > farZ)
farZ = nearZ;
cameraComponent.fov = fov;
cameraComponent.aspectRatio = aspect;
cameraComponent.nearZ = nearZ;
cameraComponent.farZ = farZ;
}
void remove() {
if (ImGui::menuItem("Remove )) {
entity.removeCameraComponent();
}
}
}

View File

@ -1,64 +0,0 @@
class MeshComponentRender {
Entity entity;
MeshComponent meshComponent;
MeshComponentRender(Entity _entity) {
entity = _entity;
meshComponent = entity.getMeshComponent();
}
void render() {
if (!entity.hasMeshComponent())
return;
if (meshComponent.hasMesh) {
ImGui::drawIcon("object3d.pn ", 32);
} else {
ImGui::drawIcon("empty.pn ", 32);
}
ImGui::dragDropTarget("MES ", ReciverFunction(this.setMesh));
if (meshComponent.hasMesh) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
ImGui::titleCenterY(meshComponent.meshResource.na e, 32);
ImGui::dragDropTarget("MES ", ReciverFunction(this.setMesh));
}
ImGui::space( 0, 20);
if (ImGui::button("Clear )) {
meshComponent.clear();
}
ImGui::sameline();
ImGui::space( 0, 20);
ImGui::sameline();
if (meshComponent.hasMesh) {
meshComponent.isActive = ImGui::checkbox("Activ ", meshComponent.isActive);
} else {
ImGui::checkboxDisabled("Activ ", meshComponent.isActive);
}
}
void setMesh(any@ mesh_data) {
string mesh;
mesh_data.retrieve(mesh);
meshComponent.meshResource = Resource::loadGPUMesh(mesh);
}
void remove() {
if (ImGui::menuItem("Remove )) {
entity.removeMeshComponent();
}
}
void init() {
ActiveEntity::wtf();
}
}

View File

@ -1,69 +0,0 @@
class PropertiesPanel : Panel {
float slider = 0;
vec3 slid;
vec3 slid2;
void render() {
Entity entity = ActiveEntity::getActiveEntity();
// NAME
// Id:0 [+ add component]
ImGui::title("\uf1b + entity.name);
if (!entity.isRoot)
ImGui::contextItemPopup("##MenuOption ", SimpleFunction(this.renameEntityMenu));
ImGui::separator();
ImGui::textColor(0 5, 0 5, 0. f, "Id + entity.id);
// We don't want to change root options
if (entity.isRoot)
return;
ImGui::sameline();
if (ImGui::buttonEnd("\uf055 Add Component )) {
ImGui::openPopup("ADD_COMPONEN ", any(entity));
}
ImGui::space();
TransformPropertiesRender transformComponentRender(entity);
ImGui::componentNode("\uf0b2 Transform Componen ", SimpleFunction(transformComponentRender.renderTransformComponent));
if (entity.hasMeshComponent()) {
MeshComponentRender meshComponentRender(entity);
ImGui::componentNodeContextMenu("\uf248 Mesh Componen ", SimpleFunction(meshComponentRender.rende ), SimpleFunction(meshComponentRender.remove));
}
if (entity.hasShaderComponent()) {
ShaderComponentRender shaderComponentRender(entity);
ImGui::componentNodeContextMenu("\uf248 Shader Componen ", SimpleFunction(shaderComponentRender.rende ), SimpleFunction(shaderComponentRender.remove));
}
if (entity.hasCameraComponent()) {
CameraComponentRender cameraComponentRender(entity);
ImGui::componentNodeContextMenu("\uf030 Camera Componen ", SimpleFunction(cameraComponentRender.rende ), SimpleFunction(cameraComponentRender.remove));
}
ImGui::space();
ImGui::separator();
if (ImGui::buttonCenter("\uf055 Add Component##2 )) {
ImGui::openPopup("ADD_COMPONEN ", any(entity));
}
AddComponentRender addComponentRender(entity);
ImGui::simplePopup("ADD_COMPONEN ", SimpleFunction(addComponentRender.addComponentPopup));
ImGui::modalPopup("Rename entit ", SimpleFunction(this.renameEntityMenu));
}
void renameEntityMenu() {
Entity entity = ActiveEntity::getActiveEntity();
if (!entity.isRoot) {
if (ImGui::menuItem("Rename )) {
ImGui::openPopup("Rename entit ", any(entity));
}
}
}
}

View File

@ -1,75 +0,0 @@
class ShaderComponentRender {
Entity entity;
ShaderComponent shaderComponent;
ShaderComponentRender(Entity _entity) {
entity = _entity;
shaderComponent = entity.getShaderComponent();
}
void setShader(any@ shader_data) {
string shader;
shader_data.retrieve(shader);
shaderComponent.shader = Resource::loadShader(shader);
}
void setTexture(any@ texture_data) {
Texture texture;
texture_data.retrieve(texture);
Engine::print(texture.name);
shaderComponent.texture = texture;
Engine::print(shaderComponent.texture.name);
}
void render() {
if (!entity.hasShaderComponent())
return;
if (shaderComponent.hasShader) {
ImGui::drawIcon("shader.pn ", 32);
} else {
ImGui::drawIcon("empty.pn ", 32);
}
ImGui::dragDropTarget("SHADE ", ReciverFunction(this.setShader));
if (shaderComponent.hasShader) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
ImGui::titleCenterY(shaderComponent.shader.na e, 32);
ImGui::dragDropTarget("SHADE ", ReciverFunction(this.setShader));
}
ImGui::space();
if (shaderComponent.texture.isValid()) {
ImGui::drawIcon(shaderComponent.textu e, 32);
} else {
ImGui::drawIcon("empty.pn ", 32);
}
ImGui::dragDropTarget("TEXTUR ", ReciverFunction(this.setTexture));
if (shaderComponent.texture.isValid()) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
ImGui::titleCenterY(shaderComponent.texture.na e, 32);
ImGui::dragDropTarget("TEXTUR ", ReciverFunction(this.setTexture));
}
ImGui::space( 0, 20);
if (ImGui::button("Clear )) {
shaderComponent.clear();
}
}
void remove() {
if (ImGui::menuItem("Remove )) {
entity.removeShaderComponent();
}
}
}

View File

@ -1,19 +0,0 @@
class TransformPropertiesRender {
Entity entity;
TransformComponent transform;
TransformPropertiesRender(Entity _entity) {
entity = _entity;
transform = entity.transform;
}
void renderTransformComponent() {
vec3 position = transform.position;
vec3 scale = transform.scale;
vec3 rotation = transform.rotation;
transform.position = ImGui::magicSlider3("Posito ", positi n, 0.1);
transform.scale = ImGui::magicSlider3("Scal ", sca e, 0.1);
transform.rotation = ImGui::magicSlider3("Rotatio ", rotati n, 0.1);
}
}

View File

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

View File

@ -1,44 +0,0 @@
class RenderService : Service {
EntityEnvironment env;
WorldCamera sceneCamera;
MeshComponent meshC;
Entity child;
void init() {
env = Resource::createLoadEntityEnvironment("PreviewerEnv");
child = env.getRootEntity().createChild("Render");
meshC = child.createMeshComponent();
ShaderComponent shaderC = child.createShaderComponent();
shaderC.shader = Resource::loadShader("shader.glsl");
sceneCamera.transform.position.z = -3;
sceneCamera.transform.position.y = 1;
}
[Expose]
FrameBuffer renderMeshPreview(GPUMesh mesh) {
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
buffer.clearRGBA(0, 0, 0, 0);
meshC.meshResource = mesh;
child.transform.rotation = vec3(0, 0, 0);
env.render(buffer, sceneCamera);
return buffer;
}
[Expose]
FrameBuffer renderMeshPreview_fase(GPUMesh mesh, float fase) {
FrameBuffer buffer = Resource::createLoadRGBA8FrameBuffer(mesh.path, 128, 128, 4);
buffer.clearRGBA(0, 0, 0, 0);
meshC.meshResource = mesh;
child.transform.rotation = vec3(0, (1-(1/(1+fase * fase)))*45, 0);
env.render(buffer, sceneCamera);
return buffer;
}
}

View File

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

View File

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

View File

@ -1,92 +0,0 @@
class EntityTreeRender {
EntityTreeRender(Entity _entity) {
entity = _entity;
}
Entity entity;
bool isActiveEntity() {
return entity == ActiveEntity::getActiveEntity();
}
void renderEntity() {
string displayName = entity.name;
if (displayName == "") {
displayName = "-";
} else {
displayName = "\uf1b2 " + displayName;
}
displayName += "##" + entity.id;
if (entity.childs.count == 0) {
// END OF THE TREE
ImGui::treeNodeLeaf(displayNa e, isActiveEntity());
interaction();
} else {
// ADD ANOTHER NODE
bool opened = ImGui::treeNode(displayNa e, isActiveEntity ), SimpleFunction(this.renderChilds));
if (!opened) {
interaction();
}
}
}
void renderChilds() {
interaction();
for (int i = 0; i < entity.childs.count; i++) {
EntityTreeRender child(entity.childs[i]);
child.renderEntity();
}
}
void interaction() {
ImGui::dragDropSource("ENTIT ", any(entit ), entity.name);
ImGui::dragDropTarget("ENTIT ", ReciverFunction(this.entityDrop));
ImGui::contextItemPopup("POP_ENTIT _ + entity. d, SimpleFunction(this.renderContextMenu));
if (ImGui::isItemClicked( )) {
ActiveEntity::setActiveEntity(entity);
}
}
void entityDrop(any@ data) {
Entity data_entity;
data.retrieve(data_entity);
// You cant be the father of your father
if (data_entity.isRoot || data_entity.isDescendantOf(entity)) {
return;
}
data_entity.parent = entity;
}
void renderContextMenu() {
if (entity.isRoot) {
if (ImGui::menuItem("New Entity )) {
entity.createChild("node");
}
} else {
if (ImGui::menuItem("Add child )) {
entity.createChild("node");
}
if (ImGui::menuItem("Rename )) {
ImGui::openPopup("Rename entit ", any(entity));
}
if (ImGui::menuItem("Destroy )) {
entity.destroy();
}
}
}
}
class TreePanel : Panel {
void render() {
Entity root = Engine::getRoot();
EntityTreeRender rootTree(root);
ImGui::contextMenuPopup("Window popu ", SimpleFunction(rootTree.renderContextMenu));
rootTree.renderEntity();
}
}

View File

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

View File

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

View File

@ -0,0 +1,53 @@
class AddComponentRender {
Entity entity;
AddComponentRender(Entity _entity) {
entity = _entity;
}
void addComponentPopup() {
ImGui::textCenter("Add Component");
ImGui::separator();
ImGui::subMenu(
"Rendering",
SimpleFunction(this.addComponentRendering)
);
if (ImGui::menuItem("Script Component")) {
ImGui::closePopup();
}
}
void addComponentRendering() {
// Mesh
if (entity.hasComponent<MeshComponent>()) {
ImGui::menuItemDisabled("\uf248 Mesh Component");
} else {
if (ImGui::menuItem("\uf248 Mesh Component")) {
entity.addComponent<MeshComponent>();
ImGui::closePopup();
}
}
// Shader
if (entity.hasComponent<ShaderComponent>()) {
ImGui::menuItemDisabled("\uf042 Shader Component");
} else {
if (ImGui::menuItem("\uf042 Shader Component")) {
entity.addComponent<ShaderComponent>();
ImGui::closePopup();
}
}
// Camera
if (entity.hasComponent<CameraComponent>()) {
ImGui::menuItemDisabled("\uf030 Camera Component");
} else {
if (ImGui::menuItem("\uf030 Camera Component")) {
entity.addComponent<CameraComponent>();
ImGui::closePopup();
}
}
}
}

View File

@ -0,0 +1,43 @@
class CameraComponentRender {
Entity entity;
CameraComponent cameraComponent;
CameraComponentRender(Entity _entity) {
entity = _entity;
cameraComponent = entity.getComponent<CameraComponent>();
}
void render() {
if (!entity.hasComponent<CameraComponent>())
return;
float fov = cameraComponent.fov;
float aspect = cameraComponent.aspectRatio;
float nearZ = cameraComponent.nearZ;
float farZ = cameraComponent.farZ;
fov = ImGui::magicSlider("FOV", fov, 0.1f);
if (fov > 180.0f) fov = 180.0f;
if (fov < 1.0f) fov = 1.0f;
aspect = ImGui::magicSlider("Aspect Ratio", aspect, 0.1f);
if (aspect < 0.1f) aspect = 0.1f;
nearZ = ImGui::magicSlider("Near Z", nearZ, 0.1f);
if (nearZ < 0.001f) nearZ = 0.001f;
farZ = ImGui::magicSlider("Far Z", farZ, 0.1f);
if (farZ < nearZ) farZ = nearZ;
cameraComponent.set_fov(fov);
cameraComponent.set_aspectRatio(aspect);
cameraComponent.set_nearZ(nearZ);
cameraComponent.set_farZ(farZ);
}
void remove() {
if (ImGui::menuItem("Remove")) {
entity.removeComponent<CameraComponent>();
}
}
}

View File

@ -0,0 +1,64 @@
class MeshComponentRender {
Entity entity;
MeshComponent meshComponent;
MeshComponentRender(Entity _entity) {
entity = _entity;
meshComponent = entity.getComponent<MeshComponent>();
}
void render() {
if (!entity.hasComponent<MeshComponent>())
return;
// Mesh icon
if (meshComponent.hasMesh) {
ImGui::drawIcon(StudioAPI::loadIcon("object3d.png"), 32);
} else {
ImGui::drawIcon(StudioAPI::loadIcon("empty.png"), 32);
}
ImGui::dragDropTarget("MESH", ReciverFunction(this.setMesh));
if (meshComponent.hasMesh) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
GPUMesh mesh = meshComponent.get_meshResource();
ImGui::titleCenterY(mesh.name, 32);
ImGui::dragDropTarget("MESH", ReciverFunction(this.setMesh));
}
ImGui::space(0, 20);
if (ImGui::button("Clear")) {
meshComponent.clear();
}
ImGui::sameline();
ImGui::space(0, 20);
ImGui::sameline();
bool active = meshComponent.get_isActive();
if (meshComponent.get_hasMesh()) {
active = ImGui::checkbox("Active", active);
meshComponent.set_isActive(active);
} else {
ImGui::checkboxDisabled("Active", active);
}
}
void setMesh(any@ meshData) {
GPUMesh mesh;
if (meshData.retrieve(mesh)) {
meshComponent.meshResource = mesh;
}
}
void remove() {
if (ImGui::menuItem("Remove")) {
entity.removeComponent<MeshComponent>();
}
}
}

View File

@ -0,0 +1,134 @@
class PropertiesPanel : Panel {
void onImGui() {
Entity entity = ActiveEntity::getActiveEntity();
// NAME
ImGui::title("\uf1b2 " + entity.name);
if (!entity.isRoot) {
ImGui::sameline();
EntityNetworkBehaviour networkBehaviour = entity.networkBehaviour;
string networkBehaviourName;
if (networkBehaviour == EntityNetworkBehaviour::Parent) {
networkBehaviourName = "Parent";
}
if (networkBehaviour == EntityNetworkBehaviour::Client) {
networkBehaviourName = "Client";
}
if (networkBehaviour == EntityNetworkBehaviour::Server) {
networkBehaviourName = "Server";
}
ImGui::drawComboEnd("##Entity behaviour", networkBehaviourName, SimpleFunction(this.selectEntityBehaviour));
ImGui::contextItemPopup(
"##MenuOption",
SimpleFunction(this.renameEntityMenu)
);
}
ImGui::separator();
ImGui::textColor(0.5f, 0.5f, 0.5f, "Id: " + entity.id);
// Root entity cannot be modified
if (entity.isRoot)
return;
ImGui::sameline();
if (ImGui::buttonEnd("\uf0fe Add Component")) {
ImGui::openPopup("ADD_COMPONENT", any(entity));
}
ImGui::space();
TransformPropertiesRender transformComponent(entity);
ImGui::componentNode(
"\uf0b2 Transform Component",
SimpleFunction(transformComponent.render)
);
if (entity.hasComponent<MeshComponent>()) {
MeshComponentRender meshComponent(entity);
ImGui::componentNodeContextMenu(
"\uf248 Mesh Component",
SimpleFunction(meshComponent.render),
SimpleFunction(meshComponent.remove)
);
}
if (entity.hasComponent<ShaderComponent>()) {
ShaderComponentRender shaderRender(entity);
ImGui::componentNodeContextMenu(
"\uf248 Shader Component",
SimpleFunction(shaderRender.render),
SimpleFunction(shaderRender.remove)
);
}
if (entity.hasComponent<CameraComponent>()) {
CameraComponentRender cameraComponent(entity);
ImGui::componentNodeContextMenu(
"\uf030 Camera Component",
SimpleFunction(cameraComponent.render),
SimpleFunction(cameraComponent.remove)
);
}
ImGui::space();
ImGui::separator();
if (ImGui::buttonCenter("\uf0fe Add Component##2")) {
ImGui::openPopup("ADD_COMPONENT",
any(entity));
}
AddComponentRender addComponentRender(entity);
ImGui::simplePopup(
"ADD_COMPONENT",
SimpleFunction(addComponentRender.addComponentPopup)
);
ImGui::modalPopup(
"Rename entity",
SimpleFunction(this.renameEntityMenu)
);
}
void selectEntityBehaviour() {
Entity entity = ActiveEntity::getActiveEntity();
EntityNetworkBehaviour networkBehaviour = entity.networkBehaviour;
if (ImGui::drawComboItem("Parent", networkBehaviour == EntityNetworkBehaviour::Parent)) {
entity.networkBehaviour = EntityNetworkBehaviour::Parent;
}
if (ImGui::drawComboItem("Server", networkBehaviour == EntityNetworkBehaviour::Server)) {
entity.networkBehaviour = EntityNetworkBehaviour::Server;
}
if (ImGui::drawComboItem("Client", networkBehaviour == EntityNetworkBehaviour::Client)) {
entity.networkBehaviour = EntityNetworkBehaviour::Client;
}
}
void renameEntityMenu() {
Entity entity = ActiveEntity::getActiveEntity();
if (entity.isRoot)
return;
if (ImGui::menuItem("Rename entity")) {
ImGui::openPopup("Rename entity", any(entity));
}
}
}

View File

@ -0,0 +1,80 @@
class ShaderComponentRender {
Entity entity;
ShaderComponent shaderComponent;
ShaderComponentRender(Entity _entity) {
entity = _entity;
shaderComponent = entity.getComponent<ShaderComponent>();
}
void setShader(any@ shaderData) {
Shader shader;
if (shaderData.retrieve(shader)) {
shaderComponent.shader = shader;
}
}
void setTexture(any@ textureData) {
Texture texture;
if (textureData.retrieve(texture)) {
shaderComponent.texture = texture;
}
}
void render() {
if (!entity.hasComponent<ShaderComponent>())
return;
// Shader icon
if (shaderComponent.hasShader) {
ImGui::drawIcon(StudioAPI::loadIcon("shader.png"), 32);
} else {
ImGui::drawIcon(StudioAPI::loadIcon("empty.png"), 32);
}
ImGui::dragDropTarget("SHADER", ReciverFunction(this.setShader));
if (shaderComponent.hasShader) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
Shader shader = shaderComponent.shader;
ImGui::titleCenterY(shader.name, 32);
ImGui::dragDropTarget("SHADER", ReciverFunction(this.setShader));
}
ImGui::space();
// Texture icon
Texture texture = shaderComponent.texture;
if (texture.isValid()) {
ImGui::drawIcon(texture, 32);
} else {
ImGui::drawIcon(StudioAPI::loadIcon("empty.png"), 32);
}
ImGui::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
if (texture.isValid()) {
ImGui::sameline();
ImGui::space();
ImGui::sameline();
ImGui::titleCenterY(texture.name, 32);
ImGui::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture));
}
ImGui::space(0, 20);
if (ImGui::button("Clear")) {
shaderComponent.clear();
}
}
void remove() {
if (ImGui::menuItem("Remove")) {
entity.removeComponent<ShaderComponent>();
}
}
}

View File

@ -0,0 +1,23 @@
class TransformPropertiesRender {
Entity entity;
TransformComponent transform;
TransformPropertiesRender(Entity _entity) {
entity = _entity;
transform = entity.getComponent<TransformComponent>();
}
void render() {
vec3 position = transform.position;
vec3 scale = transform.scale;
vec3 rotation = transform.rotation;
position = ImGui::magicSlider3("Position", position, 0.1f);
scale = ImGui::magicSlider3("Scale", scale, 0.1f);
rotation = ImGui::magicSlider3("Rotation", rotation, 0.1f);
transform.set_position(position);
transform.set_scale(scale);
transform.set_rotation(rotation);
}
}

View File

@ -1,6 +1,5 @@
string selectedResource = "";
class ResourceExplorer : Panel { class ResourceExplorer : Panel {
string selectedResource = "";
string currentPath = ""; string currentPath = "";
array<string> subFolders; array<string> subFolders;
array<string> subFiles; array<string> subFiles;
@ -9,19 +8,20 @@ class ResourceExplorer : Panel {
dictionary meshFrameBuffer; dictionary meshFrameBuffer;
void init() { void onInit() {
print("hy");
setPath(""); setPath("");
} }
void setPath(string&in path) { void setPath(string&in path) {
meshFrameBuffer.deleteAll(); meshFrameBuffer.deleteAll();
currentPath = path; currentPath = path;
subFolders = Resource::getResourceFolders(path); subFolders = StudioAPI::getResourceFolders(path);
subFiles = Resource::getResourceFiles(path); subFiles = StudioAPI::getResourceFiles(path);
fase = 0; fase = 0;
} }
void render() { void onImGui() {
alreadyRendered = false; alreadyRendered = false;
renderMenuBar(); renderMenuBar();
ImGui::space(); ImGui::space();
@ -32,7 +32,8 @@ class ResourceExplorer : Panel {
// Render navigation folders // Render navigation folders
for (uint i = 0; i < subFolders.length(); i++) { for (uint i = 0; i < subFolders.length(); i++) {
if (ImGui::cartIconButton(Path::getName(subFolders[i ), "folder.pn ", 1 8, ImGui::getAvailableSiz X())) { Texture folder = StudioAPI::loadIcon("folder.png");
if (ImGui::cartIconButton(Path::getName(subFolders[i]), folder, 128, ImGui::getAvailableSizeX())) {
setPath(subFolders[i]); setPath(subFolders[i]);
} }
ImGui::nextColumn(); ImGui::nextColumn();
@ -44,62 +45,58 @@ class ResourceExplorer : Panel {
} }
void drawResource(string&in filename) { void drawResource(string&in filename) {
ResourceType resType = Resource::getResourceType(filename); ResourceType resType = StudioAPI::getResourceType(filename);
bool selected = filename == selectedResource; bool selected = filename == selectedResource;
if (resType == ResourceType::Mesh) { if (resType == ResourceType::Mesh) {
FrameBuffer frameBuffer; FrameBuffer frameBuffer;
//if (meshFrameBuffer.exists(filename)) { GPUMesh mesh = StudioAPI::loadGPUMesh(filename);
// frameBuffer = FrameBuffer(meshFrameBuffer[filename]); //frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase);
//
//} else {
// GPUMesh mesh = Resource::loadGPUMesh(filename);
// frameBuffer = renderMeshPreview(mesh);
// meshFrameBuffer[filename] = frameBuffer;
// alreadyRendered = true;
//}
GPUMesh mesh = Resource::loadGPUMesh(filename);
frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase);
meshFrameBuffer[filename] = frameBuffer; meshFrameBuffer[filename] = frameBuffer;
alreadyRendered = true; alreadyRendered = true;
if (ImGui::cartIconButton(Path::getName(filenam ), frameBuff r, 1 8, ImGui::getAvailableSiz X())) { Texture mesTexture = StudioAPI::loadIcon("mesh.png");
if (ImGui::cartIconButton(Path::getName(filename), mesTexture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename; selectedResource = filename;
} }
ImGui::dragDropSource("MES ", any(filenam ), filename);
ImGui::dragDropSource("MESH", any(mesh), filename);
ImGui::nextColumn(); ImGui::nextColumn();
return; return;
} }
if (resType == ResourceType::Shader) { if (resType == ResourceType::Shader) {
if (ImGui::cartIconButton(Path::getName(filenam ), "shader.pn ", 1 8, ImGui::getAvailableSiz X())) { Texture shaderTexture = StudioAPI::loadIcon("shader.png");
Shader shader = StudioAPI::loadShader(filename);
if (ImGui::cartIconButton(Path::getName(filename), shaderTexture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename; selectedResource = filename;
} }
ImGui::dragDropSource("SHADE ", any(filenam ), filename); ImGui::dragDropSource("SHADER", any(shader), filename);
ImGui::nextColumn(); ImGui::nextColumn();
return; return;
} }
if (resType == ResourceType::Texture) { if (resType == ResourceType::Texture) {
Texture texture = Resource::loadTexture(filename); Texture texture = StudioAPI::loadTexture(filename);
if (ImGui::cartIconButton(Path::getName(filenam ), "texture.pn ", 1 8, ImGui::getAvailableSiz X())) { if (ImGui::cartIconButton(Path::getName(filename), texture, 128, ImGui::getAvailableSizeX())) {
selectedResource = filename; selectedResource = filename;
} }
ImGui::dragDropSource("TEXTUR ", any(filenam ), filename); ImGui::dragDropSource("TEXTURE", any(texture), filename);
ImGui::nextColumn(); ImGui::nextColumn();
return; return;
} }
ImGui::cartIconButton(Path::getName(filenam ), "file.pn ", 1 8, ImGui::getAvailableSizeX()); Texture fileTexture = StudioAPI::loadIcon("file.png");
ImGui::cartIconButton(Path::getName(filename), fileTexture, 128, ImGui::getAvailableSizeX());
ImGui::nextColumn(); ImGui::nextColumn();
} }
void renderMenuBar() { void renderMenuBar() {
// If we select that path // If we select that path
if (ImGui::button("Resources )) { if (ImGui::button("Resources")) {
setPath(""); setPath("");
} }
array<string>@ paths = Path::divide(currentPath); array<string>@ paths = Path::divide(currentPath);
for (uint i = 0; i < paths.length(); i++) { for (uint i = 0; i < paths.length(); i++) {
ImGui::sameline(); ImGui::sameline();
@ -107,8 +104,7 @@ class ResourceExplorer : Panel {
ImGui::sameline(); ImGui::sameline();
// If we select that path // If we select that path
if (ImGui::button(paths[i )) { if (ImGui::button(paths[i])) {
// We obtain that pat // We obtain that pat
string changePath = ""; string changePath = "";
for (uint z = 0; z <= i; z++) { for (uint z = 0; z <= i; z++) {

View File

@ -1,101 +1,194 @@
class EntityTreeRender { class EntityNodeUI {
EntityTreeRender(Entity _entity) { Entity entity;
array<EntityNodeUI@> children;
TreePanel@ rootPanel;
string displayName;
vec3 networkColor;
EntityNetworkBehaviour initialNetworkBehaviour;
EntityNodeUI(Entity _entity, TreePanel@ _root) {
entity = _entity; entity = _entity;
@rootPanel = _root;
updateInfo();
buildChildren();
} }
Entity entity; // Updates cached info
bool isActiveEntity() { void updateInfo() {
displayName = entity.name;
if (displayName == "") displayName = "-"; else displayName = "\uf1b2 " + entity.name;
initialNetworkBehaviour = entity.networkBehaviour;
if (!entity.isValidNetworkBehaviour()) {
networkColor = vec3(1, 0.4f, 0.4f);
} else {
EntityNetworkBehaviour net = entity.getForcedNetworkBehaviour();
if (net == EntityNetworkBehaviour::Client) networkColor = vec3(0.6, 1, 0.7); else if (net == EntityNetworkBehaviour::Server) networkColor = vec3(0.6, 0.7, 1); else networkColor = vec3(1, 1, 1);
}
}
// Build persistent children nodes
void buildChildren() {
children.resize(0);
array<Entity>@ childEntities = entity.getChildrens();
for (uint i = 0; i < childEntities.length(); i++) {
if (rootPanel.networkBehaviourFilter != EntityNetworkBehaviour::Parent) {
EntityNetworkBehaviour entBeh = childEntities[i].getForcedNetworkBehaviour();
if (entBeh != EntityNetworkBehaviour::Parent && entBeh != rootPanel.networkBehaviourFilter)
continue;
}
EntityNodeUI@ child = @EntityNodeUI(childEntities[i], rootPanel);
children.insertLast(child);
}
}
bool isActive() {
return entity == ActiveEntity::getActiveEntity(); return entity == ActiveEntity::getActiveEntity();
} }
void renderEntity() { // Call each frame to render the node tree
string displayName = entity.name; void render() {
if (displayName == "") { bool opened = false;
displayName = "-"; if (children.length() == 0) {
ImGui::treeNodeLeaf("##" + entity.id, isActive());
renderInteraction();
} else { } else {
displayName = "\uf1b2 " + displayName; opened = ImGui::treeNode("##" + entity.id, isActive(), SimpleFunction(this.renderChildren));
} if (!opened) renderInteraction();
displayName += "##" + entity.id;
array<Entity>@ childs = entity.getChildrens();
if (childs.length() == 0) {
// END OF THE TREE
ImGui::treeNodeLeaf(displayName, isActiveEntity());
interaction();
} else {
// ADD ANOTHER NODE
bool opened = ImGui::treeNode(displayName, isActiveEntity(), SimpleFunction(this.renderChilds));
if (!opened) {
interaction();
}
}
}
void renderChilds() {
interaction();
array<Entity>@ childs = entity.getChildrens();
for (uint i = 0; i < childs.length(); i++) {
EntityTreeRender child(childs[i]);
child.renderEntity();
} }
} }
void interaction() { void renderChildren() {
renderInteraction();
if (!entity.exists) return;
for (uint i = 0; i < children.length(); i++) {
if (children[i].entity.exists) children[i].render();
}
}
void renderInteraction() {
// Drag and drop
ImGui::dragDropSource("ENTITY", any(entity), entity.name); ImGui::dragDropSource("ENTITY", any(entity), entity.name);
ImGui::dragDropTarget("ENTITY", ReciverFunction(this.entityDrop)); ImGui::dragDropTarget("ENTITY", ReciverFunction(this.entityDrop));
ImGui::contextItemPopup("POP_ENTITY_" + entity.id, SimpleFunction(this.renderContextMenu));
if (ImGui::isItemClicked(0)) { // Selection
if (ImGui::isItemClicked(0))
ActiveEntity::setActiveEntity(entity); ActiveEntity::setActiveEntity(entity);
// Context menu
ImGui::contextItemPopup("POP_ENTITY_" + entity.id, SimpleFunction(this.renderContextMenu));
ImGui::simplePopup("RENAME_ENTITY_" + entity.id, SimpleFunction(this.renameEntity));
if (!entity.exists) return;
// Network color and name
ImGui::sameline();
ImGui::textColor(networkColor.x, networkColor.y, networkColor.z, displayName);
if (initialNetworkBehaviour != entity.networkBehaviour) rootPanel.onInit();
if (initialNetworkBehaviour != EntityNetworkBehaviour::Parent) {
ImGui::sameline();
if (initialNetworkBehaviour != EntityNetworkBehaviour::Server)
ImGui::textEnd("\uf233 Client "); else
ImGui::textEnd("\uf233 Server ");
} }
} }
void entityDrop(any@ data) { void entityDrop(any@ data) {
Entity data_entity; Entity dropped;
data.retrieve(data_entity); data.retrieve(dropped);
if (dropped.isRoot || entity.isDescendantOf(dropped)) return;
// You cant be the father of your father dropped.parent = entity;
if (data_entity.isRoot || data_entity.isDescendantOf(entity)) { rootPanel.onInit();
return;
}
data_entity.parent = entity;
} }
void renderContextMenu() { void renderContextMenu() {
if (entity.isRoot) { if (entity.isRoot) {
if (ImGui::menuItem("New Entity")) { if (ImGui::menuItem("New Entity")) {
print("Child id : " + entity.id);
entity.createChild("node"); entity.createChild("node");
print("Child id : " + entity.id); rootPanel.onInit();
} }
} else { } else {
if (ImGui::menuItem("Add child")) { if (ImGui::menuItem("Add child")) {
print("Child id : " + entity.id);
entity.createChild("node"); entity.createChild("node");
rootPanel.onInit();
} }
if (ImGui::menuItem("Rename")) { if (ImGui::menuItem("Rename")) {
ImGui::openPopup("Rename entity", any(entity)); ImGui::openPopup("RENAME_ENTITY_" + entity.id, any(entity));
rootPanel.onInit();
}
if (ImGui::menuItem("Destroy")) {
if (ActiveEntity::entity == entity) ActiveEntity::setActiveEntity(World::getRoot());
entity.destroy();
rootPanel.onInit();
}
}
} }
if (ImGui::menuItem("Destroy")) { void renameEntity() {
entity.destroy(); string outName;
} if (ImGui::inputText("Entity name ", entity.name, outName)) entity.name = outName;
rootPanel.onInit();
} }
// Call when hierarchy changes
void refresh() {
updateInfo();
buildChildren();
} }
} }
class TreePanel : Panel { class TreePanel : Panel {
EntityNodeUI@ rootNode;
bool infoChanged = false;
EntityNetworkBehaviour networkBehaviourFilter = EntityNetworkBehaviour::Parent;
void onInit() { void onInit() {
print("Wtf2"); infoChanged = true;
}
void onMenuBar() {
if (ImGui::menuItem("Refresh")) {
infoChanged = true;
networkBehaviourFilter = EntityNetworkBehaviour::Parent;
}
string networkBehaviourFilterName;
if (networkBehaviourFilter == EntityNetworkBehaviour::Parent) networkBehaviourFilterName = "Server&Client"; else if (networkBehaviourFilter == EntityNetworkBehaviour::Server) networkBehaviourFilterName = "Server"; else networkBehaviourFilterName = "Client";
ImGui::drawComboEnd("##Filter", networkBehaviourFilterName, SimpleFunction(this.networkFilter));
}
void networkFilter() {
if (ImGui::drawComboItem("Server&Client", networkBehaviourFilter == EntityNetworkBehaviour::Parent)){
networkBehaviourFilter = EntityNetworkBehaviour::Parent;
infoChanged = true;
}
if (ImGui::drawComboItem("Server", networkBehaviourFilter == EntityNetworkBehaviour::Server)){
networkBehaviourFilter = EntityNetworkBehaviour::Server;
infoChanged = true;
}
if (ImGui::drawComboItem("Client", networkBehaviourFilter == EntityNetworkBehaviour::Client)){
networkBehaviourFilter = EntityNetworkBehaviour::Client;
infoChanged = true;
}
} }
void onImGui() { void onImGui() {
Entity root;
EntityTreeRender rootTree(root);
ImGui::contextMenuPopup("Window popup", SimpleFunction(rootTree.renderContextMenu)); if (infoChanged) {
rootTree.renderEntity(); Entity root = World::getRoot();
@rootNode = @EntityNodeUI(root, this);
infoChanged = false;
}
rootNode.render();
} }
} }

View File

@ -1,16 +1,19 @@
class ViewportPanel : Panel { class ViewportPanel : Panel {
FrameBuffer frameBuffer; FrameBuffer frameBuffer;
WorldCamera sceneCamera; WorldCamera sceneCamera;
EntityEnvironment env;
float pitch = 0; float pitch = 0;
float yaw = 0; float yaw = 0;
float vel = 0.02f;
void render() { void onImGui() {
if (!frameBuffer.isValid()) if (!frameBuffer.isValid())
return; return;
float vel = World::getRenderDeltaTime() * 3;
if (ImGui::isKeyDown(key::LeftShift))
vel *= 3;
int x = ImGui::getAvailableSizeX(); int x = ImGui::getAvailableSizeX();
int y = ImGui::getAvailableSizeY(); int y = ImGui::getAvailableSizeY();
@ -21,15 +24,15 @@ class ViewportPanel : Panel {
frameBuffer.clearRGBA(0, 0, 0, 255); frameBuffer.clearRGBA(0, 0, 0, 255);
sceneCamera.camera.aspect = float(x) / y; sceneCamera.camera.aspect = float(x) / y;
env.render(frameBuffer, sceneCamera); World::render(frameBuffer, sceneCamera);
ImGui::drawFrameBufferCentered(frameBuffer, x, y); ImGui::drawFrameBufferCentered(frameBuffer, x, y);
if (!ImGui::isPanelActive()) if (!ImGui::isPanelActive())
return; return;
if (ImGui::isMouseDragging(key::MouseRight) && !ImGui::isKeyDown(key::MouseMiddle)) { if (ImGui::isMouseDragging(key::MouseRight) && !ImGui::isKeyDown(key::MouseMiddle)) {
pitch += ImGui::getMouseDeltaY() * 0.1f; pitch += ImGui::getMouseDeltaY() * 0.1;
yaw += ImGui::getMouseDeltaX() * 0.1f; yaw += ImGui::getMouseDeltaX() * 0.1;
sceneCamera.transform.rotation.setEuler(vec3(pitch, yaw, 0)); sceneCamera.transform.rotation.setEuler(vec3(pitch, yaw, 0));
} }
@ -40,7 +43,7 @@ class ViewportPanel : Panel {
panDir.x -= ImGui::getMouseDeltaX(); panDir.x -= ImGui::getMouseDeltaX();
panDir.y += ImGui::getMouseDeltaY(); panDir.y += ImGui::getMouseDeltaY();
panDir = panDir * vel * 0.4f; panDir = panDir * 0.01f;
sceneCamera.transform.position = sceneCamera.transform.relative(panDir); sceneCamera.transform.position = sceneCamera.transform.relative(panDir);
} }
@ -51,6 +54,8 @@ class ViewportPanel : Panel {
if (ImGui::isKeyDown(key::S)) if (ImGui::isKeyDown(key::S))
relDir.z--; relDir.z--;
relDir.z += ImGui::getMouseWheel() * 100;
if (ImGui::isKeyDown(key::D)) if (ImGui::isKeyDown(key::D))
relDir.x++; relDir.x++;
if (ImGui::isKeyDown(key::A)) if (ImGui::isKeyDown(key::A))
@ -68,9 +73,8 @@ class ViewportPanel : Panel {
sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0); sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0);
} }
void init() { void onInit() {
frameBuffer = Resource::createLoadRGBA8FrameBuffer("MainFrameBuffer", 1000, 1000); frameBuffer = Resource::createFrameBuffer("MainFrameBuffer", 1000, 1000);
env = Resource::getMainEntityEnvironment();
sceneCamera.transform.position = vec3(0, 1, -2); sceneCamera.transform.position = vec3(0, 1, -2);
sceneCamera.camera.nearZ = 0.1; sceneCamera.camera.nearZ = 0.1;
@ -78,19 +82,21 @@ class ViewportPanel : Panel {
ImGui::disablePanelPadding(true); ImGui::disablePanelPadding(true);
} }
void menuBar() { void onMenuBar() {
if (ImGui::menuItem("Start")) { if (ImGui::menuItem("Start")) {
} }
if (ImGui::menuItem("Camera Props")) { if (ImGui::menuItem("Viewport")) {
ImGui::openPopup("ViewportCameraProps", any()); ImGui::openPopup("ViewportCameraProps", any());
} }
ImGui::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps)); ImGui::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps));
ImGui::textColor(0, 0.5f, 0,"" + ceil(1 / World::getRenderDeltaTime()));
} }
void viewportCameraProps() { void viewportCameraProps() {
sceneCamera.camera.fov = ImGui::slider("Fov", sceneCamera.camera.fov / 3.14f * 180, 10, 160) / 180 * 3.14f; sceneCamera.camera.fov = ImGui::slider("Fov", sceneCamera.camera.fov / 3.14f * 180, 10, 160) / 180 * 3.14f;
World::setRenderFrequency(ImGui::sliderInt("Render frequency", World::getRenderFrequency(), 10, 300));
} }
} }

View File

@ -9,11 +9,65 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][TreePanel] [Window][TreePanel]
Pos=0,34 Pos=0,26
Size=2560,1336 Size=569,925
Collapsed=0 Collapsed=0
DockId=0x0AC2E849,0 DockId=0x00000005,0
[Window][PropertiesPanel]
Pos=1872,26
Size=688,925
Collapsed=0
DockId=0x00000002,0
[Window][ResourceExplorer]
Pos=0,953
Size=2560,418
Collapsed=0
DockId=0x00000004,0
[Window][ViewportPanel]
Pos=571,26
Size=1299,925
Collapsed=0
DockId=0x00000006,0
[Window][Rename entity]
Pos=848,548
Size=306,133
Collapsed=0
[Window][RENAME_ENTITY_1]
Pos=755,542
Size=380,90
Collapsed=0
[Window][Dear ImGui Demo]
Pos=571,26
Size=1299,925
Collapsed=0
DockId=0x00000006,1
[Window][Dear ImGui Demo/ResizableChild_478B81A3]
IsChild=1
Size=1167,176
[Window][Dear ImGui Demo/Red_BEEF922B]
IsChild=1
Size=200,100
[Window][Dear ImGui Style Editor]
Pos=544,26
Size=1262,926
Collapsed=0
DockId=0x00000006,2
[Docking][Data] [Docking][Data]
DockSpace ID=0x0AC2E849 Window=0xD0388BC8 Pos=0,34 Size=2560,1336 CentralNode=1 Selected=0x16E3C1E7 DockSpace ID=0x0AC2E849 Window=0xD0388BC8 Pos=0,26 Size=2560,1345 Split=Y Selected=0x16E3C1E7
DockNode ID=0x00000003 Parent=0x0AC2E849 SizeRef=2560,926 Split=X
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=1230,1336 Split=X Selected=0x16E3C1E7
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=569,572 CentralNode=1 Selected=0x16E3C1E7
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=1299,572 Selected=0x5E5F7166
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=688,1336 Selected=0x9876A79B
DockNode ID=0x00000004 Parent=0x0AC2E849 SizeRef=2560,418 Selected=0x018A0F9B

0
make Normal file
View File