diff --git a/Deer/Include/DeerCore/Components.h b/Deer/Include/DeerCore/Components.h index df4f6ac..cbab432 100755 --- a/Deer/Include/DeerCore/Components.h +++ b/Deer/Include/DeerCore/Components.h @@ -18,10 +18,16 @@ namespace Deer { class ComponentScriptInstance; + enum class EntityNetworkBehaviour : uint32_t { + PARENT = 0, + SERVER = 1 << 0, + CLIENT = 1 << 1 + }; struct TagComponent { std::string tag; uint32_t entityUID; + EntityNetworkBehaviour networkBehaviour = EntityNetworkBehaviour::PARENT; TagComponent() = default; TagComponent(const TagComponent&) = default; @@ -75,9 +81,9 @@ namespace Deer { glm::vec3 scale = glm::vec3(1.0f); glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f); - TransformComponent() = default; + TransformComponent() {} TransformComponent(glm::vec3 _position) : position(_position) {} - TransformComponent(const TransformComponent&) = default; + TransformComponent(const TransformComponent&) {} inline const glm::vec3 getEulerAngles() { return glm::degrees(glm::eulerAngles(rotation)); diff --git a/Deer/Include/DeerCore/EntityEnviroment.h b/Deer/Include/DeerCore/EntityEnviroment.h index cff33f5..6267ab7 100755 --- a/Deer/Include/DeerCore/EntityEnviroment.h +++ b/Deer/Include/DeerCore/EntityEnviroment.h @@ -82,6 +82,9 @@ namespace Deer { Entity& getParent() const; inline uint32_t getParentId() const { return parentId; } + EntityNetworkBehaviour getForcedNetworkBehaviour(); + bool isValidNetworkBehaviour(EntityNetworkBehaviour nb = EntityNetworkBehaviour::PARENT); + // TODO, enable transfer entitys from difrent environments void setParent(Entity& parent); bool isDescendantOf(Entity& parent) const; diff --git a/Deer/Include/DeerCore/World.h b/Deer/Include/DeerCore/World.h index 0a57493..e4fa4ba 100755 --- a/Deer/Include/DeerCore/World.h +++ b/Deer/Include/DeerCore/World.h @@ -42,10 +42,18 @@ namespace Deer { WorldState getExecutionState(); Scope entityEnvironment; + const WorldSettings& getWorldSettings() { return worldSettings; } +#ifdef DEER_RENDER + inline float getRenderDeltaTime() { return renderDeltaTime; } + void setRenderFrequency(int); +#endif private: std::atomic executingState; WorldSettings worldSettings; +#ifdef DEER_RENDER + float renderDeltaTime; +#endif }; // namespace World } // namespace Deer diff --git a/Deer/Include/DeerRender/Components.h b/Deer/Include/DeerRender/Components.h index f10e57a..ce22d55 100755 --- a/Deer/Include/DeerRender/Components.h +++ b/Deer/Include/DeerRender/Components.h @@ -31,8 +31,8 @@ namespace Deer { }; struct CameraComponent { - CameraComponent() = default; - CameraComponent(const CameraComponent&) = default; + CameraComponent() {} + CameraComponent(const CameraComponent&) {} float fov = glm::radians(50.0f); float aspect = 16 / 9; diff --git a/Deer/src/DeerCore/Scripting/Helpers.h b/Deer/src/DeerCore/Scripting/Helpers.h index c7b539c..b9249c4 100644 --- a/Deer/src/DeerCore/Scripting/Helpers.h +++ b/Deer/src/DeerCore/Scripting/Helpers.h @@ -33,6 +33,12 @@ namespace Deer { 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)) + #define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \ AS_CHECK(scriptEngine->RegisterObjectBehaviour( \ clasdef, asBEHAVE_DESTRUCT, funcdef, \ diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp index 329857e..c83d9ff 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp +++ b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp @@ -21,11 +21,6 @@ namespace Deer { asIScriptContext* context = asGetActiveContext(); 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); } @@ -33,11 +28,6 @@ namespace Deer { asIScriptContext* context = asGetActiveContext(); 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(); } @@ -46,11 +36,6 @@ namespace Deer { asIScriptContext* context = asGetActiveContext(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); - if (handle.environmentId == 0) { - return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent(); - } - - // Implement entity reference of other environments return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent(); } @@ -82,6 +67,22 @@ namespace Deer { getContextEntity(handle).destroy(); } + int Scripting::entity_getNetworkBehaviour(EntityHandle& handle) { + return (int)getContextEntityComponent(handle).networkBehaviour; + } + + void Scripting::entity_setNetworkBehaviour(int value, EntityHandle& handle) { + getContextEntityComponent(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) { Entity& entity = getContextEntity(handle); @@ -92,7 +93,7 @@ namespace Deer { size_t childCount = relationship.getChildCount(); 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->SetValue(array->GetSize() - 1, &entity); @@ -107,7 +108,7 @@ namespace Deer { child.setParent(self); child.getComponent().tag = childName; - return EntityHandle(child.getId(), handle.environmentId); + return EntityHandle(child.getId()); } void Scripting::entity_setParent(EntityHandle other_handle, EntityHandle& self_handle) { @@ -118,7 +119,7 @@ namespace Deer { } 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) { @@ -129,7 +130,7 @@ namespace Deer { } 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) { @@ -254,4 +255,6 @@ namespace Deer { void Scripting::constructEntityStruct(void* memory) { new (memory) EntityHandle(); } + + void Scripting::destructEntityStruct(void* memory) {} } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h index ff5b293..1f42a73 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h +++ b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h @@ -11,10 +11,8 @@ namespace Deer { class EntityEnvironment; struct EntityHandle { - uint32_t entityId = 0; - uint32_t environmentId = 0; - - EntityHandle(uint32_t _id = 0, uint32_t _env = 0) : entityId(_id), environmentId(_env) {} + uint32_t entityId; + EntityHandle(uint32_t _id = 0) : entityId(_id) {} }; namespace Scripting { @@ -34,6 +32,11 @@ namespace Deer { void entity_destroy(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&); void entity_setParent(EntityHandle, EntityHandle&); EntityHandle entity_getParent(EntityHandle&); @@ -55,5 +58,6 @@ namespace Deer { void transform_setRotation(glm::vec3, EntityHandle&); void constructEntityStruct(void* memory); + void destructEntityStruct(void* memory); } // namespace Scripting } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/InternalFunctions.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/InternalFunctions.cpp index 019a82c..9e97d8a 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/InternalFunctions.cpp +++ b/Deer/src/DeerCore/Scripting/InternalAPI/InternalFunctions.cpp @@ -5,13 +5,13 @@ namespace Deer { void Scripting::errorCallback_angelscript(const asSMessageInfo* msg, void* param) { 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) { - 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) { - 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 { - 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); } } diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/Math.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/Math.cpp index 7fcafa6..06443c5 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/Math.cpp +++ b/Deer/src/DeerCore/Scripting/InternalAPI/Math.cpp @@ -3,6 +3,10 @@ namespace Deer { namespace Scripting { + void vec3_constructor(void* mem) { + new (mem) glm::vec3(); + } + void vec3_constructor_params(float x, float y, float z, void* mem) { new (mem) glm::vec3(x, y, z); } diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp index 6b8b124..ef3f487 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp +++ b/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp @@ -2,6 +2,6 @@ namespace Deer { EntityHandle Scripting::getRoot() { - return EntityHandle(0, 0); + return EntityHandle(); } } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp b/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp index 8105805..1a380a1 100644 --- a/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp +++ b/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp @@ -1,3 +1,4 @@ +#include "DeerCore/Components.h" #include "DeerCore/Scripting/Helpers.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", "array@ 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()", entity_getGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T addComponent()", entity_addGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "void removeComponent()", entity_removeGenericComponent); @@ -44,11 +50,16 @@ namespace Deer { } void Scripting::registerEntityStructs() { - AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); - AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); + AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); + AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Entity", "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 diff --git a/Deer/src/DeerCore/Scripting/Registry/MathRegistry.cpp b/Deer/src/DeerCore/Scripting/Registry/MathRegistry.cpp index 690ff5f..39cc4ae 100644 --- a/Deer/src/DeerCore/Scripting/Registry/MathRegistry.cpp +++ b/Deer/src/DeerCore/Scripting/Registry/MathRegistry.cpp @@ -13,13 +13,14 @@ namespace Deer { } // namespace Scripting void Scripting::registerMathStructs() { - scriptEngine->RegisterObjectType("vec3", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS); + scriptEngine->RegisterObjectType("vec3", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_MORE_CONSTRUCTORS); 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)); - 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() | asOBJ_APP_CLASS_ALLFLOATS); + scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_MORE_CONSTRUCTORS); 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)); @@ -27,20 +28,20 @@ namespace Deer { REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f()", quat_construct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f(float, float, float, float)", quat_constructFromValue); - scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits()); + scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR); scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position)); scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale)); scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Transform", "void f()", transform_construct); - scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits()); + scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR); 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)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Camera", "void f()", camera_construct); - scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits()); + scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CONSTRUCTOR); scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera)); scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "WorldCamera", "void f()", sceneCamera_Construct); diff --git a/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp b/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp index f9bdf56..6b78792 100644 --- a/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp +++ b/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp @@ -183,7 +183,7 @@ namespace Deer { asIScriptFunction* function = system->environmentFunctions[eventIndex]; if (!function) - return; + continue; environment->context->Prepare(function); environment->context->SetObject(systemInstances[i]); diff --git a/Deer/src/DeerCore/Scripting/ScriptSystem.cpp b/Deer/src/DeerCore/Scripting/ScriptSystem.cpp index 2638615..43d62c0 100644 --- a/Deer/src/DeerCore/Scripting/ScriptSystem.cpp +++ b/Deer/src/DeerCore/Scripting/ScriptSystem.cpp @@ -8,6 +8,7 @@ #include "scriptbuilder.h" #include "scriptdictionary.h" #include "scripthandle.h" +#include "scriptmath.h" #include "scriptstdstring.h" #include @@ -25,6 +26,7 @@ namespace Deer { void registerResources(); void registerEntity_Render(); void registerImGui(); + void registerWorld_Render(); #endif }; // namespace Scripting @@ -40,15 +42,17 @@ namespace Deer { RegisterScriptAny(scriptEngine); RegisterScriptArray(scriptEngine, true); RegisterScriptDictionary(scriptEngine); + RegisterScriptMath(scriptEngine); registerMath(); registerEngine(); registerEntity(); + registerWorld(); #ifdef DEER_RENDER registerResources(); registerEntity_Render(); - registerWorld(); registerImGui(); + registerWorld_Render(); #endif } diff --git a/Deer/src/DeerCore/World/Entity.cpp b/Deer/src/DeerCore/World/Entity.cpp index 21cf1a0..84a0a43 100755 --- a/Deer/src/DeerCore/World/Entity.cpp +++ b/Deer/src/DeerCore/World/Entity.cpp @@ -63,6 +63,37 @@ namespace Deer { parentId = parent.getId(); } + EntityNetworkBehaviour Entity::getForcedNetworkBehaviour() { + if (entId == 0) + return EntityNetworkBehaviour::PARENT; + + TagComponent& tag = getComponent(); + + 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(); + 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 { DEER_CORE_ASSERT(isValid(), "Entity is not valid"); if (getId() == parent.getId()) diff --git a/Deer/src/DeerRender/Core/Engine.cpp b/Deer/src/DeerRender/Core/Engine.cpp index d7f58ab..a38b42b 100644 --- a/Deer/src/DeerRender/Core/Engine.cpp +++ b/Deer/src/DeerRender/Core/Engine.cpp @@ -88,8 +88,6 @@ namespace Deer { RenderCommand::setClearColor({0.2f, 0.2f, 0.3f, 1.0f}); RenderCommand::clear(); - ImGuiIO& io = ImGui::GetIO(); - io.DeltaTime = 1.0f / 60; ImGuiLayer::begin(); } diff --git a/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp b/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp index ab317d4..3c43fa2 100644 --- a/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp +++ b/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp @@ -25,13 +25,18 @@ namespace Deer { 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 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); // Checkboxes 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); + // 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 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); @@ -62,18 +67,13 @@ namespace Deer { REGISTER_GLOBAL_FUNC(scriptEngine, "void space()", Scripting::space); REGISTER_GLOBAL_FUNC(scriptEngine, "void space(int x, int y = 10)", Scripting::space_params); - // Drawing - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBuffer(FrameBuffer, int, int)", Scripting::drawFrameBuffer); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBufferCentered(FrameBuffer, int, int)", Scripting::drawFrameBufferCentered); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(const string& in, int)", Scripting::drawIcon); - 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); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(Texture texture, int)", Scripting::drawIconCentered); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(Texture texture, int)", Scripting::drawIconHighlight); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(Texture texture, int)", Scripting::drawIconCenteredHighlight); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(Texture texture, int)", Scripting::drawIcon_resource); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(Texture texture, int)", Scripting::drawIconCentered_resource); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(Texture texture, int)", Scripting::drawIconHighlight_resource); - REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(Texture texture, int)", Scripting::drawIconCenteredHighlight_resource); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBuffer(FrameBuffer texture, int, int)", Scripting::drawFrameBuffer); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBufferCentered(FrameBuffer texture, int, int)", Scripting::drawFrameBufferCentered); // Input state 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 getMouseDeltaX()", Scripting::getMouseDeltaX); REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaY()", Scripting::getMouseDeltaY); + REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseWheel()", Scripting::getMouseWheel); // Panel & layout co(scriptEngine, trol REGISTER_GLOBAL_FUNC(scriptEngine, "bool isPanelActive()", Scripting::isPanelActive); diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/Entity.cpp b/Deer/src/DeerRender/Scripting/InternalAPI/Entity.cpp index 9e3da62..e29f636 100644 --- a/Deer/src/DeerRender/Scripting/InternalAPI/Entity.cpp +++ b/Deer/src/DeerRender/Scripting/InternalAPI/Entity.cpp @@ -10,11 +10,6 @@ namespace Deer { asIScriptContext* context = asGetActiveContext(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); - if (handle.environmentId == 0) { - return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent(); - } - - // Implement entity reference of other environments return environmentData->world->entityEnvironment->getEntity(handle.entityId).getComponent(); } diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp index a57a68b..8ee46a5 100644 --- a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp +++ b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp @@ -80,10 +80,8 @@ namespace Deer { else sizeX = ImGui::GetContentRegionAvail().x; - float textWidth = - ImGui::CalcTextSize(txt.c_str(), nullptr, false).x; - float padding = - (sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2); + float textWidth = ImGui::CalcTextSize(txt.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth - ImGui::GetStyle().FramePadding.x * 2); if (padding > 0.0f) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); @@ -91,7 +89,28 @@ namespace Deer { 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, int iconSize, int width) { + if (!texture.isValid()) { + ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture"); + return false; + } + ImGui::BeginGroup(); int offset = 16; @@ -119,7 +138,6 @@ namespace Deer { p.x + (itemWidth - iconSize) * 0.5f, p.y + 2.0f + offset); - Resource texture = ResourceManager::getResource(icon); dl->AddImage( (ImTextureID)texture.getData().getTextureID(), iconPos, @@ -235,31 +253,20 @@ namespace Deer { ImGui::Text("%s", msg.c_str()); } - void drawIcon(std::string& name, int size) { - Resource texture = ResourceManager::getResource(name); - + void drawIcon(Resource texture, int size) { + 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)); } - void drawIcon_resource(Resource texture, int size) { - int iconId = texture.getData().getTextureID(); - ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0)); - } - void drawIconHighlight_resource(Resource 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 = ResourceManager::getResource(name); - int iconId = texture.getData().getTextureID(); - - if (iconId < 0) { - DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + void drawIconHighlight(Resource texture, int size) { + if (!texture.isValid()) { + ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture"); return; } - - 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)); + 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)); } void drawFrameBuffer(Resource frameBufferResource, int sizeX, int sizeY) { @@ -292,30 +299,11 @@ namespace Deer { ImVec2(0, 1), ImVec2(1, 0)); } - void drawIconCentered_resource(Resource 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); - - drawIcon_resource(texture, size); - } - - void drawIconCentered(std::string& name, int size) { - Resource texture = ResourceManager::getResource(name); - int iconId = texture.getData().getTextureID(); - if (iconId < 0) { - DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + void drawIconCentered(Resource texture, int size) { + if (!texture.isValid()) { + ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture"); return; } - float sizeX; if (ImGui::GetColumnsCount() > 1) sizeX = ImGui::GetColumnWidth(-1); @@ -328,32 +316,14 @@ namespace Deer { if (padding > 0.0f) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); - drawIcon(name, size); - } - void drawIconCenteredHighlight_resource(Resource 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); + drawIcon(texture, size); } - void drawIconCenteredHighlight(std::string& name, int size) { - Resource texture = ResourceManager::getResource(name); - int iconId = texture.getData().getTextureID(); - if (iconId < 0) { - DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + void drawIconCenteredHighlight(Resource texture, int size) { + if (!texture.isValid()) { + ImGui::TextColored(ImVec4(0.5, 0, 0, 1), "Invalid texture"); return; } - float sizeX; if (ImGui::GetColumnsCount() > 1) sizeX = ImGui::GetColumnWidth(-1); @@ -366,7 +336,7 @@ namespace Deer { if (padding > 0.0f) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); - drawIconHighlight(name, size); + drawIconHighlight(texture, size); } bool isItemClicked(int mouse) { return ImGui::IsItemClicked(mouse); } @@ -616,6 +586,11 @@ namespace Deer { return io.MouseDelta.y; } + float getMouseWheel() { + ImGuiIO& io = ImGui::GetIO(); + return io.MouseWheel; + } + float getMouseDragDeltaX() { return ImGui::GetMouseDragDelta().x; } float getMouseDragDeltaY() { return ImGui::GetMouseDragDelta().y; } @@ -717,6 +692,59 @@ namespace Deer { 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) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); @@ -884,7 +912,6 @@ namespace Deer { asIScriptContext* scriptContext = asGetActiveContext(); if (scriptContext->PushState() == asSUCCESS) { AS_CHECK(scriptContext->Prepare(func)); - AS_CHECK(scriptContext->SetArgObject(0, MenuContext::payload)); AS_CHECK(scriptContext->Execute()); scriptContext->PopState(); } else { diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.h b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.h index 2706b2f..35d65f8 100644 --- a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.h +++ b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.h @@ -31,19 +31,16 @@ namespace Deer { bool buttonCenter(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 icon, int iconSize, int width); bool cartIconButton_frameBuffer(const std::string& label, Resource frameBuffer, int iconSize, int width); - // Icons - void drawIcon(std::string& iconId, int size); - void drawIconCentered(std::string& iconId, int size); - void drawIconHighlight(std::string& iconId, int size); - void drawIconCenteredHighlight(std::string& iconId, int size); + void drawIcon(Resource texture, int size); + void drawIconCentered(Resource texture, int size); + void drawIconHighlight(Resource texture, int size); + void drawIconCenteredHighlight(Resource texture, int size); - void drawIcon_resource(Resource texture, int size); - void drawIconCentered_resource(Resource texture, int size); - void drawIconHighlight_resource(Resource texture, int size); - void drawIconCenteredHighlight_resource(Resource texture, int size); + void drawFrameBuffer(Resource frameBuffer, int sizeX, int sizeY); + void drawFrameBufferCentered(Resource frameBuffer, int sizeX, int sizeY); int getIconId(const std::string& name); @@ -89,14 +86,15 @@ namespace Deer { float getMouseDragDeltaY(); float getMouseDeltaX(); 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 isKeyPressed(int); - // Rendering helpers - void drawFrameBuffer(Resource frameBuffer, int sizeX, int sizeY); - void drawFrameBufferCentered(Resource frameBuffer, int sizeX, int sizeY); - void automaticColumns(int pixelSize); void columns(int); void nextColumn(); diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/World.cpp b/Deer/src/DeerRender/Scripting/InternalAPI/World.cpp new file mode 100644 index 0000000..e9ce822 --- /dev/null +++ b/Deer/src/DeerRender/Scripting/InternalAPI/World.cpp @@ -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, 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 \ No newline at end of file diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/World.h b/Deer/src/DeerRender/Scripting/InternalAPI/World.h new file mode 100644 index 0000000..6a3d72e --- /dev/null +++ b/Deer/src/DeerRender/Scripting/InternalAPI/World.h @@ -0,0 +1,12 @@ +#pragma once +#include "DeerRender/World.h" +#include "Resources.h" + +namespace Deer { + namespace Scripting { + void world_render(Resource, WorldCamera); + float getRenderDeltaTime(); + void setRenderFrequency(int); + int getRenderFrequency(); + } // namespace Scripting +} // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerRender/Scripting/ResourcesRegistry.cpp b/Deer/src/DeerRender/Scripting/ResourcesRegistry.cpp index 1d5b4bf..bb91b2b 100644 --- a/Deer/src/DeerRender/Scripting/ResourcesRegistry.cpp +++ b/Deer/src/DeerRender/Scripting/ResourcesRegistry.cpp @@ -31,12 +31,6 @@ namespace Deer { AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(Resource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(Resource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); AS_CHECK(scriptEngine->RegisterObjectType("FrameBuffer", sizeof(Resource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); - - 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&); int frameBuffer_getHeight(Resource&); diff --git a/Deer/src/DeerRender/Scripting/WorldRegistry.cpp b/Deer/src/DeerRender/Scripting/WorldRegistry.cpp new file mode 100644 index 0000000..c207c23 --- /dev/null +++ b/Deer/src/DeerRender/Scripting/WorldRegistry.cpp @@ -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 diff --git a/Deer/src/DeerRender/World/World.cpp b/Deer/src/DeerRender/World/World.cpp index 0e10be1..bfd8818 100755 --- a/Deer/src/DeerRender/World/World.cpp +++ b/Deer/src/DeerRender/World/World.cpp @@ -13,18 +13,19 @@ namespace Deer { if (worldSettings.updateFrequency == 0) return; - auto previousTime = std::chrono::high_resolution_clock::now(); + auto previousTime = std::chrono::steady_clock::now(); double accumulatedUpdateTime = 0.0; double accumulatedRenderTime = 0.0; double targetUpdateTime = 1.0f / worldSettings.updateFrequency; double targetRenderTime = 0; - if (worldSettings.renderFrequency > 0) - targetRenderTime = 1.0f / worldSettings.renderFrequency; 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 deltaTime = currentTime - previousTime; previousTime = currentTime; @@ -33,17 +34,16 @@ namespace Deer { while (accumulatedUpdateTime >= targetUpdateTime) { accumulatedUpdateTime -= targetUpdateTime; - worldSettings.updateCallback(*this); } if (targetRenderTime > 0 && accumulatedRenderTime >= targetRenderTime) { + renderDeltaTime = accumulatedRenderTime; worldSettings.renderCallback(*this); - while (accumulatedRenderTime >= targetRenderTime) - accumulatedRenderTime -= targetRenderTime; + accumulatedRenderTime = 0; } - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + std::this_thread::sleep_for(std::chrono::microseconds(1)); } if (executingState == WorldState::DestroyQueued) @@ -52,4 +52,9 @@ namespace Deer { executingState = WorldState::Stopped; } + void World::setRenderFrequency(int freq) { + if (freq < 1) + return; + worldSettings.renderFrequency = freq; + } } // namespace Deer diff --git a/Deer/src/Plattform/Linux/LinuxWindow.cpp b/Deer/src/Plattform/Linux/LinuxWindow.cpp index 798515b..d5c2d70 100755 --- a/Deer/src/Plattform/Linux/LinuxWindow.cpp +++ b/Deer/src/Plattform/Linux/LinuxWindow.cpp @@ -35,7 +35,8 @@ namespace Deer { m_renderContext = new OpenGLContext(m_window); m_renderContext->init(); - setVSync(true); + setVSync(false); + glfwSetWindowUserPointer(m_window, &m_data); // Set GLFW callback diff --git a/DeerStudio/headers/DeerStudio/StudioAPI.h b/DeerStudio/headers/DeerStudio/StudioAPI.h new file mode 100644 index 0000000..d860a8d --- /dev/null +++ b/DeerStudio/headers/DeerStudio/StudioAPI.h @@ -0,0 +1,29 @@ +#pragma once +#include "DeerRender/Resource.h" +#include + +class CScriptArray; +class CScriptDictionary; +namespace Deer { + class Texture; + + enum class ResourceType : int { + NONE = 0, + MESH = 1, + SHADER = 2, + TEXTURE = 3 + }; + + namespace StudioAPI { + Resource 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 \ No newline at end of file diff --git a/DeerStudio/headers/DeerStudio/StudioAPI/Resources.h b/DeerStudio/headers/DeerStudio/StudioAPI/Resources.h deleted file mode 100644 index 6302d34..0000000 --- a/DeerStudio/headers/DeerStudio/StudioAPI/Resources.h +++ /dev/null @@ -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 -#include - -namespace Deer { - namespace StudioAPI { - template - class APIResource : public Resource { - public: - std::string getPath() const { return ResourceManager::getStorageId(*this); } - std::string getName() const { return Path(ResourceManager::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 \ No newline at end of file diff --git a/DeerStudio/headers/DeerStudio/StudioAPI/UI.h b/DeerStudio/headers/DeerStudio/StudioAPI/UI.h index abf658e..5c100ef 100644 --- a/DeerStudio/headers/DeerStudio/StudioAPI/UI.h +++ b/DeerStudio/headers/DeerStudio/StudioAPI/UI.h @@ -102,6 +102,7 @@ namespace Deer { bool componentNode(std::string&, asIScriptFunction*); bool componentNodeContextMenu(std::string&, asIScriptFunction*, asIScriptFunction*); + void treeNodeLeaf(std::string&, bool); bool treeNode(std::string&, bool, asIScriptFunction&); diff --git a/DeerStudio/headers/DeerStudio/StudioScripting.h b/DeerStudio/headers/DeerStudio/StudioScripting.h new file mode 100644 index 0000000..07f04d8 --- /dev/null +++ b/DeerStudio/headers/DeerStudio/StudioScripting.h @@ -0,0 +1,7 @@ +#pragma once + +namespace Deer { + namespace StudioScripting { + void registerStudioScripting(); + } +} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/AngelScriptEngine.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/AngelScriptEngine.cpp.disabled deleted file mode 100644 index a73a4b1..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/AngelScriptEngine.cpp.disabled +++ /dev/null @@ -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 modules; - std::unordered_map 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.cpp.disabled deleted file mode 100644 index 2f3669f..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.cpp.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.h.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.h.disabled deleted file mode 100644 index f6c9ec5..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ErrorHandle.h.disabled +++ /dev/null @@ -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; \ - } \ - } diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp.disabled deleted file mode 100644 index cfc71d1..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Module.cpp.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleDescriptorSerializer.h.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleDescriptorSerializer.h.disabled deleted file mode 100644 index 1fe2ce2..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleDescriptorSerializer.h.disabled +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "DeerStudio/AngelScriptEngine.h" -#include -#include - -namespace Deer { - namespace StudioAPI { - template - 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp.disabled deleted file mode 100644 index b3910eb..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModuleLoading.cpp.disabled +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include - -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(is)), - std::istreambuf_iterator()); - 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModulePredefinedGenerator.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/ModulePredefinedGenerator.cpp.disabled deleted file mode 100644 index dd7fb7f..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/ModulePredefinedGenerator.cpp.disabled +++ /dev/null @@ -1,291 +0,0 @@ -#include "DeerRender/Log.h" -#include "DeerStudio/AngelScriptEngine.h" -#include "angelscript.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp.disabled deleted file mode 100644 index 43fad87..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Panel.cpp.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp.disabled b/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp.disabled deleted file mode 100644 index 4aac3b7..0000000 --- a/DeerStudio/src/DeerStudio/AngelScriptEngine/Service.cpp.disabled +++ /dev/null @@ -1,298 +0,0 @@ -#include "DeerStudio/AngelScriptEngine.h" -#include "DeerStudio/AngelScriptEngine/ErrorHandle.h" - -#include "angelscript.h" -#include "scriptbuilder.h" -#include -#include -#include - -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& 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 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* 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& 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index d2d887d..fbd1e6f 100644 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -38,7 +38,7 @@ namespace Deer { .updateCallback = worldUpdate, .updateFrequency = 60, .renderCallback = worldRender, - .renderFrequency = 144, + .renderFrequency = 166, }; mainWorld = Universe::createWorld(worldSettings); @@ -56,6 +56,9 @@ namespace Deer { void worldRender(World& world) { Engine::beginRender(); + ImGuiIO& io = ImGui::GetIO(); + io.DeltaTime = world.getRenderDeltaTime(); + static bool opt_fullscreen = true; static bool opt_padding = false; static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; @@ -102,6 +105,8 @@ namespace Deer { StudioPanel::render(); + ImGui::ShowDemoWindow(); + ImGui::End(); Engine::endRender(); diff --git a/DeerStudio/src/DeerStudio/Registers/Engine.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Engine.cpp.disabled deleted file mode 100644 index f3c7363..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Engine.cpp.disabled +++ /dev/null @@ -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@ 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"); - engineRegistry->unbind(); - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/Entity.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Entity.cpp.disabled deleted file mode 100644 index d3834d0..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Entity.cpp.disabled +++ /dev/null @@ -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() | asOBJ_APP_CLASS_ALLINTS)); - AS_CHECK(scriptEngine->RegisterObjectType("EntityChilds", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); - AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); - AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); - AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS)); - AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | 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 diff --git a/DeerStudio/src/DeerStudio/Registers/Environment.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Environment.cpp.disabled deleted file mode 100644 index dded69a..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Environment.cpp.disabled +++ /dev/null @@ -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() | 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/FrameBuffer.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/FrameBuffer.cpp.disabled deleted file mode 100644 index 10aab63..0000000 --- a/DeerStudio/src/DeerStudio/Registers/FrameBuffer.cpp.disabled +++ /dev/null @@ -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() | 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/Math.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Math.cpp.disabled deleted file mode 100644 index a7649fb..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Math.cpp.disabled +++ /dev/null @@ -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() | 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()); - 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()); - 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()); - 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 diff --git a/DeerStudio/src/DeerStudio/Registers/Registers.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Registers.cpp.disabled deleted file mode 100644 index 09ae256..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Registers.cpp.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/Registers.h.disabled b/DeerStudio/src/DeerStudio/Registers/Registers.h.disabled deleted file mode 100644 index e7790f2..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Registers.h.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/Resource.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/Resource.cpp.disabled deleted file mode 100644 index 58be286..0000000 --- a/DeerStudio/src/DeerStudio/Registers/Resource.cpp.disabled +++ /dev/null @@ -1,45 +0,0 @@ -#include "DeerStudio/StudioAPI/Resources.h" - -#include "DeerRender/Resource.h" - -namespace Deer { - namespace StudioAPI { - template - void registerResourceBasics(const char* objName) { - REGISTER_OBJECT_METHOD(objName, "bool isValid() const", StudioAPI::APIResource, isValid); - REGISTER_OBJECT_METHOD(objName, "string get_name() const property", StudioAPI::APIResource, getName); - REGISTER_OBJECT_METHOD(objName, "string get_path() const property", StudioAPI::APIResource, getPath); - REGISTER_OBJECT_METHOD(objName, "int get_resourceId() const property", StudioAPI::APIResource, getResourceId); - } - } // namespace StudioAPI - - void StudioAPI::registerResourceStructs() { - scriptEngine->SetDefaultNamespace(""); - AS_CHECK(scriptEngine->RegisterObjectType("GPUMesh", sizeof(StudioAPI::APIResource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); - AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(StudioAPI::APIResource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); - AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(StudioAPI::APIResource), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits>())); - 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"); - registerResourceBasics("Shader"); - registerResourceBasics("Texture"); - - scriptEngine->SetDefaultNamespace("Resource"); - REGISTER_GLOBAL_FUNC("GPUMesh loadGPUMesh(string&in path)", ResourceManager::loadResource); - REGISTER_GLOBAL_FUNC("Shader loadShader(string&in path)", ResourceManager::loadResource); - REGISTER_GLOBAL_FUNC("Texture loadTexture(string&in path)", ResourceManager::loadResource); - - REGISTER_GLOBAL_FUNC("array@ getResourceFolders(string&in path)", StudioAPI::getResourceFolders); - REGISTER_GLOBAL_FUNC("array@ getResourceFiles(string&in path)", StudioAPI::getResourceFiles); - REGISTER_GLOBAL_FUNC("ResourceType getResourceType(string&in path)", StudioAPI::getResourceType); - scriptEngine->SetDefaultNamespace(""); - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled deleted file mode 100644 index 4693062..0000000 --- a/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled +++ /dev/null @@ -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioAPI.cpp b/DeerStudio/src/DeerStudio/StudioAPI.cpp new file mode 100644 index 0000000..2f2457f --- /dev/null +++ b/DeerStudio/src/DeerStudio/StudioAPI.cpp @@ -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 StudioAPI::getIcon(std::string& icon) { + Path iconPath = Path("Icons") / icon; + return ResourceManager::loadResource(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"); + 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"); + 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioAPI/EntityEnvironment.cpp.disabled b/DeerStudio/src/DeerStudio/StudioAPI/EntityEnvironment.cpp.disabled deleted file mode 100644 index 718e584..0000000 --- a/DeerStudio/src/DeerStudio/StudioAPI/EntityEnvironment.cpp.disabled +++ /dev/null @@ -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 - -namespace Deer { - namespace StudioAPI { - // The first element has to allways point to the main scene env - std::vector environments; - - void EntityEnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, WorldCamera& sc) { - Resource frameBufferResource = Resource::unsafeFromId(frameBuffer_handle.frameBufferId); - FrameBuffer& frameBuffer = frameBufferResource.getData(); - - EntityEnvironment* envPtr = nullptr; - if (environmentId < 0) { - envPtr = Engine::getMainWorld().entityEnvironment.get(); - } else { - Resource environmentResource = Resource::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 environmentResource = ResourceManager::loadResourceFromData(envData, envId); - - return EntityEnvironmentHandleStruct(environmentResource.getResourceId()); - } - } // namespace StudioAPI -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioAPI/FrameBuffer.cpp.disabled b/DeerStudio/src/DeerStudio/StudioAPI/FrameBuffer.cpp.disabled deleted file mode 100644 index 59f4159..0000000 --- a/DeerStudio/src/DeerStudio/StudioAPI/FrameBuffer.cpp.disabled +++ /dev/null @@ -1,57 +0,0 @@ -#include "DeerStudio/StudioAPI/FrameBuffer.h" -#include "DeerRender/FrameBuffer.h" - -namespace Deer { - namespace StudioAPI { - - int FrameBufferStruct::getWidth() { - Resource frameBufferResource = Resource::unsafeFromId(frameBufferId); - FrameBuffer& frameBuffer = frameBufferResource.getData(); - return frameBuffer.getSpecification().width; - } - - int FrameBufferStruct::getHeight() { - Resource frameBufferResource = Resource::unsafeFromId(frameBufferId); - FrameBuffer& frameBuffer = frameBufferResource.getData(); - return frameBuffer.getSpecification().height; - } - - void FrameBufferStruct::resize(int x, int y) { - Resource frameBufferResource = Resource::unsafeFromId(frameBufferId); - FrameBuffer& frameBuffer = frameBufferResource.getData(); - - frameBuffer.resize(x, y); - } - - void FrameBufferStruct::clearRGBA(int r, int g, int b, int a) { - - Resource frameBufferResource = Resource::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::unsafeFromId(frameBufferId).getStorageId(); - } - - FrameBufferStruct createLoadRGBA8FrameBuffer(std::string& name, int sizeX, int sizeY, int samples) { - FrameBufferData fbd(sizeX, sizeY, samples, FrameBufferData::FrameBufferType::RGBA8); - Resource frameBuffer = ResourceManager::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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioAPI/IconManagment.cpp.disabled b/DeerStudio/src/DeerStudio/StudioAPI/IconManagment.cpp.disabled deleted file mode 100644 index 0b5fdf3..0000000 --- a/DeerStudio/src/DeerStudio/StudioAPI/IconManagment.cpp.disabled +++ /dev/null @@ -1,17 +0,0 @@ -#include "DeerRender/Resource.h" -#include "DeerRender/Texture.h" -#include "DeerStudio/EditorDataSource.h" -#include "DeerStudio/StudioAPI/UI.h" - -#include - -namespace Deer { - int StudioAPI::getIconId(const std::string& name) { - Resource texture = ResourceManager::loadResource(name); - - if (texture.isValid()) - return texture.getData().getTextureID(); - - return 0; - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioAPI/Resources.cpp.disabled b/DeerStudio/src/DeerStudio/StudioAPI/Resources.cpp.disabled deleted file mode 100644 index fe10669..0000000 --- a/DeerStudio/src/DeerStudio/StudioAPI/Resources.cpp.disabled +++ /dev/null @@ -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 - -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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioPanel.cpp b/DeerStudio/src/DeerStudio/StudioPanel.cpp index 0dd6cd2..20e5d1d 100644 --- a/DeerStudio/src/DeerStudio/StudioPanel.cpp +++ b/DeerStudio/src/DeerStudio/StudioPanel.cpp @@ -1,6 +1,7 @@ #include "DeerStudio/StudioPanel.h" #include "DeerRender/Scripting.h" #include "DeerRender/Tools/Memory.h" +#include "DeerStudio/StudioScripting.h" #include "imgui.h" namespace Deer { @@ -13,6 +14,7 @@ namespace Deer { } // namespace StudioPanel void StudioPanel::init(World* world) { + StudioScripting::registerStudioScripting(); Scripting::registerInterface("Panel"); Scripting::registerInterfaceFunction("Panel", "onImGui", Scripting::EventType::void_event); diff --git a/DeerStudio/src/DeerStudio/StudioScripting.cpp b/DeerStudio/src/DeerStudio/StudioScripting.cpp new file mode 100644 index 0000000..5c9e34c --- /dev/null +++ b/DeerStudio/src/DeerStudio/StudioScripting.cpp @@ -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::loadResource), asCALL_CDECL); + scriptEngine->RegisterGlobalFunction("Shader loadShader(string&in path)", asFUNCTION(ResourceManager::loadResource), asCALL_CDECL); + scriptEngine->RegisterGlobalFunction("Texture loadTexture(string&in path)", asFUNCTION(ResourceManager::loadResource), asCALL_CDECL); + + scriptEngine->RegisterGlobalFunction("array@ getResourceFolders(string&in path)", asFUNCTION(StudioAPI::getResourceFolders), asCALL_CDECL); + scriptEngine->RegisterGlobalFunction("array@ 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 \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Style.cpp b/DeerStudio/src/DeerStudio/Style.cpp index 8ea7de4..b5b7b8e 100644 --- a/DeerStudio/src/DeerStudio/Style.cpp +++ b/DeerStudio/src/DeerStudio/Style.cpp @@ -1,92 +1,61 @@ #include "imgui.h" - -void SetupImGuiStyle() -{ +void SetupImGuiStyle() { // Rest style by AaronBeardless from ImThemes ImGuiStyle& style = ImGui::GetStyle(); - - style.Alpha = 1.0f; - 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.Colors[ImGuiCol_TextDisabled] = ImVec4(0.49803922f, 0.49803922f, 0.49803922f, 1.0f); - style.Colors[ImGuiCol_WindowBg] = ImVec4(0.09411765f, 0.09411765f, 0.09411765f, 1.0f); - style.Colors[ImGuiCol_ChildBg] = ImVec4(0.15686275f, 0.15686275f, 0.15686275f, 1.0f); - 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); - style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); - style.Colors[ImGuiCol_FrameBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); - style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); - style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.047058824f); - 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); - style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.11764706f, 0.11764706f, 0.11764706f, 1.0f); - style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); - style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.10980392f); - 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); - style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.09803922f); - style.Colors[ImGuiCol_CheckMark] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - style.Colors[ImGuiCol_SliderGrab] = ImVec4(1.0f, 1.0f, 1.0f, 0.39215687f); - 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); - style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); - style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.0f, 0.0f, 0.0f, 0.047058824f); - style.Colors[ImGuiCol_Header] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); - 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); - style.Colors[ImGuiCol_Separator] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); - style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); - style.Colors[ImGuiCol_SeparatorActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); - 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); - style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.23529412f); - style.Colors[ImGuiCol_Tab] = ImVec4(1.0f, 1.0f, 1.0f, 0.09803922f); - style.Colors[ImGuiCol_TabHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.15686275f); - style.Colors[ImGuiCol_TabActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.3137255f); - style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.0f, 0.0f, 0.0f, 0.15686275f); - 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); - style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.0f, 1.0f, 1.0f, 0.3529412f); - style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.15686275f, 0.15686275f, 0.15686275f, 1.0f); - 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); - style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); - style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.019607844f); - style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - 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); - style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.7f); - style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.8f, 0.8f, 0.8f, 0.2f); - style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.5647059f); + + ImVec4* c = style.Colors; + + style.FramePadding.x = 10; + style.FramePadding.y = 4; + style.WindowPadding = ImVec2(10, 10); + style.ItemSpacing = ImVec2(4, 4); + + // --- Backgrounds --- + c[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.11f, 0.12f, 1.00f); + c[ImGuiCol_ChildBg] = ImVec4(0.10f, 0.11f, 0.12f, 1.00f); + c[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f); + c[ImGuiCol_MenuBarBg] = ImVec4(0.12f, 0.13f, 0.14f, 1.00f); + + // --- Frames --- + c[ImGuiCol_FrameBg] = ImVec4(0.18f, 0.19f, 0.20f, 1.00f); + c[ImGuiCol_FrameBgHovered] = ImVec4(0.22f, 0.24f, 0.26f, 1.00f); + c[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.27f, 0.30f, 1.00f); + + // --- Titles --- + c[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.10f, 0.11f, 1.00f); + c[ImGuiCol_TitleBgActive] = ImVec4(0.13f, 0.15f, 0.17f, 1.00f); + c[ImGuiCol_TitleBgCollapsed] = ImVec4(0.09f, 0.10f, 0.11f, 1.00f); + + // --- Buttons (modern muted blue) --- + c[ImGuiCol_Button] = ImVec4(0.20f, 0.23f, 0.26f, 1.00f); + c[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.31f, 0.36f, 1.00f); + c[ImGuiCol_ButtonActive] = ImVec4(0.30f, 0.36f, 0.42f, 1.00f); + + // --- Headers / selection --- + c[ImGuiCol_Header] = ImVec4(0.22f, 0.27f, 0.32f, 1.00f); + c[ImGuiCol_HeaderHovered] = ImVec4(0.28f, 0.34f, 0.40f, 1.00f); + c[ImGuiCol_HeaderActive] = ImVec4(0.32f, 0.39f, 0.46f, 1.00f); + + // --- Tabs --- + c[ImGuiCol_Tab] = ImVec4(0.14f, 0.15f, 0.17f, 1.00f); + c[ImGuiCol_TabHovered] = ImVec4(0.28f, 0.33f, 0.39f, 1.00f); + c[ImGuiCol_TabActive] = ImVec4(0.20f, 0.25f, 0.30f, 1.00f); + c[ImGuiCol_TabUnfocused] = ImVec4(0.14f, 0.15f, 0.17f, 1.00f); + c[ImGuiCol_TabUnfocusedActive] = ImVec4(0.18f, 0.22f, 0.26f, 1.00f); + + // --- Scrollbars --- + c[ImGuiCol_ScrollbarBg] = ImVec4(0.11f, 0.12f, 0.13f, 1.00f); + c[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.28f, 0.32f, 1.00f); + c[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.30f, 0.35f, 0.40f, 1.00f); + c[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.34f, 0.40f, 0.46f, 1.00f); + + // --- Accents (VS Code–style cyan-blue) --- + c[ImGuiCol_CheckMark] = ImVec4(0.38f, 0.55f, 0.75f, 1.00f); + c[ImGuiCol_SliderGrab] = ImVec4(0.38f, 0.55f, 0.75f, 1.00f); + c[ImGuiCol_SliderGrabActive] = ImVec4(0.45f, 0.65f, 0.85f, 1.00f); + + // --- Text --- + c[ImGuiCol_Text] = ImVec4(0.88f, 0.88f, 0.88f, 1.00f); + c[ImGuiCol_TextDisabled] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); } \ No newline at end of file diff --git a/Editor/Modules/ActiveEntity/ActiveEntity.as b/Editor/Modules/ActiveEntity/ActiveEntity.as deleted file mode 100644 index b6fc700..0000000 --- a/Editor/Modules/ActiveEntity/ActiveEntity.as +++ /dev/null @@ -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"); - } -} diff --git a/Editor/Modules/ActiveEntity/module.json b/Editor/Modules/ActiveEntity/module.json deleted file mode 100644 index 8ab3307..0000000 --- a/Editor/Modules/ActiveEntity/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "patch": 1, - "name": "ActiveEntity", - "requires": [] -} diff --git a/Editor/Modules/EntityManipulation/AddComponent.as b/Editor/Modules/EntityManipulation/AddComponent.as deleted file mode 100644 index 2b29ffd..0000000 --- a/Editor/Modules/EntityManipulation/AddComponent.as +++ /dev/null @@ -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(); - } - } - } -} diff --git a/Editor/Modules/EntityManipulation/CameraProperties.as b/Editor/Modules/EntityManipulation/CameraProperties.as deleted file mode 100644 index 513a63a..0000000 --- a/Editor/Modules/EntityManipulation/CameraProperties.as +++ /dev/null @@ -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(); - } - } - -} diff --git a/Editor/Modules/EntityManipulation/MeshProperties.as b/Editor/Modules/EntityManipulation/MeshProperties.as deleted file mode 100644 index d7a06be..0000000 --- a/Editor/Modules/EntityManipulation/MeshProperties.as +++ /dev/null @@ -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(); - } -} diff --git a/Editor/Modules/EntityManipulation/PropertiesPannel.as b/Editor/Modules/EntityManipulation/PropertiesPannel.as deleted file mode 100644 index 9f38279..0000000 --- a/Editor/Modules/EntityManipulation/PropertiesPannel.as +++ /dev/null @@ -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)); - } - } - } - -} diff --git a/Editor/Modules/EntityManipulation/ShaderProperties.as b/Editor/Modules/EntityManipulation/ShaderProperties.as deleted file mode 100644 index d626f8d..0000000 --- a/Editor/Modules/EntityManipulation/ShaderProperties.as +++ /dev/null @@ -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(); - } - } - -} diff --git a/Editor/Modules/EntityManipulation/TransformProperties.as b/Editor/Modules/EntityManipulation/TransformProperties.as deleted file mode 100644 index 96bff7d..0000000 --- a/Editor/Modules/EntityManipulation/TransformProperties.as +++ /dev/null @@ -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); - } -} diff --git a/Editor/Modules/EntityManipulation/module.json b/Editor/Modules/EntityManipulation/module.json deleted file mode 100644 index 067e357..0000000 --- a/Editor/Modules/EntityManipulation/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "EntityManipulation", - "patch": 1, - "requires": ["ActiveEntity"] -} \ No newline at end of file diff --git a/Editor/Modules/Previewer/MeshPreview.as b/Editor/Modules/Previewer/MeshPreview.as deleted file mode 100644 index 3637813..0000000 --- a/Editor/Modules/Previewer/MeshPreview.as +++ /dev/null @@ -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; - } -} diff --git a/Editor/Modules/Previewer/module.json b/Editor/Modules/Previewer/module.json deleted file mode 100644 index 7d50c9d..0000000 --- a/Editor/Modules/Previewer/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "patch": 1, - "name": "Previewer", - "requires": [] -} diff --git a/Editor/Modules/ResourceExplorer/module.json b/Editor/Modules/ResourceExplorer/module.json deleted file mode 100644 index 6666d44..0000000 --- a/Editor/Modules/ResourceExplorer/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "patch": 1, - "name": "ResourceExplorer", - "requires": ["Previewer"] -} diff --git a/Editor/Modules/TreeExplorer/Tree.as b/Editor/Modules/TreeExplorer/Tree.as deleted file mode 100644 index 292a281..0000000 --- a/Editor/Modules/TreeExplorer/Tree.as +++ /dev/null @@ -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(); - } -} diff --git a/Editor/Modules/TreeExplorer/module.json b/Editor/Modules/TreeExplorer/module.json deleted file mode 100644 index 2d50a45..0000000 --- a/Editor/Modules/TreeExplorer/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "patch": 1, - "name": "TreeExplorer", - "requires": ["ActiveEntity"] -} diff --git a/Editor/Modules/Viewport/module.json b/Editor/Modules/Viewport/module.json deleted file mode 100644 index 26b8f5e..0000000 --- a/Editor/Modules/Viewport/module.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "patch": 1, - "name": "Viewport", - "requires": ["Previewer"] -} diff --git a/Editor/Scripts/EntityManipulation/AddComponent.as b/Editor/Scripts/EntityManipulation/AddComponent.as new file mode 100644 index 0000000..686fc9f --- /dev/null +++ b/Editor/Scripts/EntityManipulation/AddComponent.as @@ -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()) { + ImGui::menuItemDisabled("\uf248 Mesh Component"); + } else { + if (ImGui::menuItem("\uf248 Mesh Component")) { + entity.addComponent(); + ImGui::closePopup(); + } + } + + // Shader + if (entity.hasComponent()) { + ImGui::menuItemDisabled("\uf042 Shader Component"); + } else { + if (ImGui::menuItem("\uf042 Shader Component")) { + entity.addComponent(); + ImGui::closePopup(); + } + } + + // Camera + if (entity.hasComponent()) { + ImGui::menuItemDisabled("\uf030 Camera Component"); + } else { + if (ImGui::menuItem("\uf030 Camera Component")) { + entity.addComponent(); + ImGui::closePopup(); + } + } + } +} diff --git a/Editor/Scripts/EntityManipulation/CameraProperties.as b/Editor/Scripts/EntityManipulation/CameraProperties.as new file mode 100644 index 0000000..a1b342e --- /dev/null +++ b/Editor/Scripts/EntityManipulation/CameraProperties.as @@ -0,0 +1,43 @@ +class CameraComponentRender { + Entity entity; + CameraComponent cameraComponent; + + CameraComponentRender(Entity _entity) { + entity = _entity; + cameraComponent = entity.getComponent(); + } + + void render() { + if (!entity.hasComponent()) + 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(); + } + } +} diff --git a/Editor/Scripts/EntityManipulation/MeshProperties.as b/Editor/Scripts/EntityManipulation/MeshProperties.as new file mode 100644 index 0000000..fc78f48 --- /dev/null +++ b/Editor/Scripts/EntityManipulation/MeshProperties.as @@ -0,0 +1,64 @@ +class MeshComponentRender { + Entity entity; + MeshComponent meshComponent; + + MeshComponentRender(Entity _entity) { + entity = _entity; + meshComponent = entity.getComponent(); + } + + void render() { + if (!entity.hasComponent()) + 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(); + } + } +} diff --git a/Editor/Scripts/EntityManipulation/PropertiesPannel.as b/Editor/Scripts/EntityManipulation/PropertiesPannel.as new file mode 100644 index 0000000..0569e48 --- /dev/null +++ b/Editor/Scripts/EntityManipulation/PropertiesPannel.as @@ -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()) { + MeshComponentRender meshComponent(entity); + + ImGui::componentNodeContextMenu( + "\uf248 Mesh Component", + SimpleFunction(meshComponent.render), + SimpleFunction(meshComponent.remove) + ); + + } + + if (entity.hasComponent()) { + ShaderComponentRender shaderRender(entity); + + ImGui::componentNodeContextMenu( + "\uf248 Shader Component", + SimpleFunction(shaderRender.render), + SimpleFunction(shaderRender.remove) + ); + } + + if (entity.hasComponent()) { + 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)); + } + } + +} diff --git a/Editor/Scripts/EntityManipulation/ShaderProperties.as b/Editor/Scripts/EntityManipulation/ShaderProperties.as new file mode 100644 index 0000000..0cc071a --- /dev/null +++ b/Editor/Scripts/EntityManipulation/ShaderProperties.as @@ -0,0 +1,80 @@ +class ShaderComponentRender { + Entity entity; + ShaderComponent shaderComponent; + + ShaderComponentRender(Entity _entity) { + entity = _entity; + shaderComponent = entity.getComponent(); + } + + 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()) + 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(); + } + } +} diff --git a/Editor/Scripts/EntityManipulation/TransformRender.as b/Editor/Scripts/EntityManipulation/TransformRender.as new file mode 100644 index 0000000..7c62096 --- /dev/null +++ b/Editor/Scripts/EntityManipulation/TransformRender.as @@ -0,0 +1,23 @@ +class TransformPropertiesRender { + Entity entity; + TransformComponent transform; + + TransformPropertiesRender(Entity _entity) { + entity = _entity; + transform = entity.getComponent(); + } + + 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); + } +} diff --git a/Editor/Modules/ResourceExplorer/ResourceExplorer.as b/Editor/Scripts/ResourceExplorer/ResourceExplorer.as similarity index 53% rename from Editor/Modules/ResourceExplorer/ResourceExplorer.as rename to Editor/Scripts/ResourceExplorer/ResourceExplorer.as index 8d161aa..ea077a8 100644 --- a/Editor/Modules/ResourceExplorer/ResourceExplorer.as +++ b/Editor/Scripts/ResourceExplorer/ResourceExplorer.as @@ -1,6 +1,5 @@ -string selectedResource = ""; - class ResourceExplorer : Panel { + string selectedResource = ""; string currentPath = ""; array subFolders; array subFiles; @@ -9,19 +8,20 @@ class ResourceExplorer : Panel { dictionary meshFrameBuffer; - void init() { + void onInit() { + print("hy"); setPath(""); } void setPath(string&in path) { meshFrameBuffer.deleteAll(); currentPath = path; - subFolders = Resource::getResourceFolders(path); - subFiles = Resource::getResourceFiles(path); + subFolders = StudioAPI::getResourceFolders(path); + subFiles = StudioAPI::getResourceFiles(path); fase = 0; } - void render() { + void onImGui() { alreadyRendered = false; renderMenuBar(); ImGui::space(); @@ -32,91 +32,87 @@ class ResourceExplorer : Panel { // Render navigation folders 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]); } ImGui::nextColumn(); } - for (uint i = 0; i < subFiles.length(); i++) { + for ( uint i = 0; i < subFiles.length(); i++) { drawResource(subFiles[i]); } } void drawResource(string&in filename) { - ResourceType resType = Resource::getResourceType(filename); + ResourceType resType = StudioAPI::getResourceType(filename); bool selected = filename == selectedResource; if (resType == ResourceType::Mesh) { FrameBuffer frameBuffer; - //if (meshFrameBuffer.exists(filename)) { - // frameBuffer = FrameBuffer(meshFrameBuffer[filename]); -// - //} else { - // GPUMesh mesh = Resource::loadGPUMesh(filename); - // frameBuffer = renderMeshPreview(mesh); - // meshFrameBuffer[filename] = frameBuffer; - // alreadyRendered = true; - //} + GPUMesh mesh = StudioAPI::loadGPUMesh(filename); + //frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase); + meshFrameBuffer[filename] = frameBuffer; + alreadyRendered = true; - GPUMesh mesh = Resource::loadGPUMesh(filename); - frameBuffer = Previewer::renderMeshPreview_fase(mesh, fase); - meshFrameBuffer[filename] = frameBuffer; - 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; } - ImGui::dragDropSource("MES ", any(filenam ), filename); + + ImGui::dragDropSource("MESH", any(mesh), filename); ImGui::nextColumn(); return; } 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; } - ImGui::dragDropSource("SHADE ", any(filenam ), filename); + ImGui::dragDropSource("SHADER", any(shader), filename); ImGui::nextColumn(); return; } if (resType == ResourceType::Texture) { - Texture texture = Resource::loadTexture(filename); - if (ImGui::cartIconButton(Path::getName(filenam ), "texture.pn ", 1 8, ImGui::getAvailableSiz X())) { + Texture texture = StudioAPI::loadTexture(filename); + if (ImGui::cartIconButton(Path::getName(filename), texture, 128, ImGui::getAvailableSizeX())) { selectedResource = filename; } - ImGui::dragDropSource("TEXTUR ", any(filenam ), filename); + ImGui::dragDropSource("TEXTURE", any(texture), filename); ImGui::nextColumn(); 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(); } void renderMenuBar() { - // If we select that path - if (ImGui::button("Resources )) { + // If we select that path + if (ImGui::button("Resources")) { setPath(""); } + array@ paths = Path::divide(currentPath); for (uint i = 0; i < paths.length(); i++) { ImGui::sameline(); ImGui::text("/"); ImGui::sameline(); - // If we select that path - if (ImGui::button(paths[i )) { - - // We obtain that pat + // If we select that path + if (ImGui::button(paths[i])) { + // We obtain that pat string changePath = ""; for (uint z = 0; z <= i; z++) { if (z != 0) changePath += "/"; changePath += paths[z]; } - + setPath(changePath); } } diff --git a/Editor/Scripts/TreeExplorer/Tree.as b/Editor/Scripts/TreeExplorer/Tree.as index 85c0562..d068d22 100644 --- a/Editor/Scripts/TreeExplorer/Tree.as +++ b/Editor/Scripts/TreeExplorer/Tree.as @@ -1,101 +1,194 @@ -class EntityTreeRender { - EntityTreeRender(Entity _entity) { - entity = _entity; - } - +class EntityNodeUI { Entity entity; - bool isActiveEntity() { + array children; + TreePanel@ rootPanel; + + string displayName; + vec3 networkColor; + EntityNetworkBehaviour initialNetworkBehaviour; + + EntityNodeUI(Entity _entity, TreePanel@ _root) { + entity = _entity; + @rootPanel = _root; + + updateInfo(); + buildChildren(); + } + + // Updates cached info + 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@ 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(); } - - void renderEntity() { - string displayName = entity.name; - if (displayName == "") { - displayName = "-"; - } else { - displayName = "\uf1b2 " + displayName; - } - displayName += "##" + entity.id; - array@ childs = entity.getChildrens(); - if (childs.length() == 0) { - // END OF THE TREE - ImGui::treeNodeLeaf(displayName, isActiveEntity()); - interaction(); + // Call each frame to render the node tree + void render() { + bool opened = false; + if (children.length() == 0) { + ImGui::treeNodeLeaf("##" + entity.id, isActive()); + renderInteraction(); } else { - // ADD ANOTHER NODE - bool opened = ImGui::treeNode(displayName, isActiveEntity(), SimpleFunction(this.renderChilds)); - if (!opened) { - interaction(); - } + opened = ImGui::treeNode("##" + entity.id, isActive(), SimpleFunction(this.renderChildren)); + if (!opened) renderInteraction(); } } - void renderChilds() { - interaction(); - array@ childs = entity.getChildrens(); - for (uint i = 0; i < childs.length(); i++) { - EntityTreeRender child(childs[i]); - child.renderEntity(); + void renderChildren() { + renderInteraction(); + if (!entity.exists) return; + for (uint i = 0; i < children.length(); i++) { + if (children[i].entity.exists) children[i].render(); } } - void interaction() { + void renderInteraction() { + + // Drag and drop ImGui::dragDropSource("ENTITY", any(entity), entity.name); 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); + + // 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) { - 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; + Entity dropped; + data.retrieve(dropped); + if (dropped.isRoot || entity.isDescendantOf(dropped)) return; + dropped.parent = entity; + rootPanel.onInit(); } void renderContextMenu() { if (entity.isRoot) { if (ImGui::menuItem("New Entity")) { - print("Child id : " + entity.id); entity.createChild("node"); - print("Child id : " + entity.id); + rootPanel.onInit(); } } else { if (ImGui::menuItem("Add child")) { - print("Child id : " + entity.id); entity.createChild("node"); + rootPanel.onInit(); } - 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(); } } } + + void renameEntity() { + 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 { + EntityNodeUI@ rootNode; + bool infoChanged = false; + EntityNetworkBehaviour networkBehaviourFilter = EntityNetworkBehaviour::Parent; + 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() { - Entity root; - EntityTreeRender rootTree(root); - ImGui::contextMenuPopup("Window popup", SimpleFunction(rootTree.renderContextMenu)); - rootTree.renderEntity(); + if (infoChanged) { + Entity root = World::getRoot(); + @rootNode = @EntityNodeUI(root, this); + + infoChanged = false; + } + + rootNode.render(); } } diff --git a/Editor/Modules/Viewport/Viewport.as b/Editor/Scripts/Viewport/Viewport.as similarity index 75% rename from Editor/Modules/Viewport/Viewport.as rename to Editor/Scripts/Viewport/Viewport.as index 3c33366..b715fb6 100644 --- a/Editor/Modules/Viewport/Viewport.as +++ b/Editor/Scripts/Viewport/Viewport.as @@ -1,16 +1,19 @@ class ViewportPanel : Panel { FrameBuffer frameBuffer; WorldCamera sceneCamera; - EntityEnvironment env; float pitch = 0; float yaw = 0; - float vel = 0.02f; - void render() { + void onImGui() { if (!frameBuffer.isValid()) return; + float vel = World::getRenderDeltaTime() * 3; + + if (ImGui::isKeyDown(key::LeftShift)) + vel *= 3; + int x = ImGui::getAvailableSizeX(); int y = ImGui::getAvailableSizeY(); @@ -21,15 +24,15 @@ class ViewportPanel : Panel { frameBuffer.clearRGBA(0, 0, 0, 255); sceneCamera.camera.aspect = float(x) / y; - env.render(frameBuffer, sceneCamera); + World::render(frameBuffer, sceneCamera); ImGui::drawFrameBufferCentered(frameBuffer, x, y); if (!ImGui::isPanelActive()) return; if (ImGui::isMouseDragging(key::MouseRight) && !ImGui::isKeyDown(key::MouseMiddle)) { - pitch += ImGui::getMouseDeltaY() * 0.1f; - yaw += ImGui::getMouseDeltaX() * 0.1f; + pitch += ImGui::getMouseDeltaY() * 0.1; + yaw += ImGui::getMouseDeltaX() * 0.1; sceneCamera.transform.rotation.setEuler(vec3(pitch, yaw, 0)); } @@ -40,7 +43,7 @@ class ViewportPanel : Panel { panDir.x -= ImGui::getMouseDeltaX(); panDir.y += ImGui::getMouseDeltaY(); - panDir = panDir * vel * 0.4f; + panDir = panDir * 0.01f; sceneCamera.transform.position = sceneCamera.transform.relative(panDir); } @@ -51,6 +54,8 @@ class ViewportPanel : Panel { if (ImGui::isKeyDown(key::S)) relDir.z--; + relDir.z += ImGui::getMouseWheel() * 100; + if (ImGui::isKeyDown(key::D)) relDir.x++; if (ImGui::isKeyDown(key::A)) @@ -68,9 +73,8 @@ class ViewportPanel : Panel { sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0); } - void init() { - frameBuffer = Resource::createLoadRGBA8FrameBuffer("MainFrameBuffer", 1000, 1000); - env = Resource::getMainEntityEnvironment(); + void onInit() { + frameBuffer = Resource::createFrameBuffer("MainFrameBuffer", 1000, 1000); sceneCamera.transform.position = vec3(0, 1, -2); sceneCamera.camera.nearZ = 0.1; @@ -78,19 +82,21 @@ class ViewportPanel : Panel { ImGui::disablePanelPadding(true); } - void menuBar() { + void onMenuBar() { if (ImGui::menuItem("Start")) { } - if (ImGui::menuItem("Camera Props")) { + if (ImGui::menuItem("Viewport")) { ImGui::openPopup("ViewportCameraProps", any()); } - + ImGui::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps)); + ImGui::textColor(0, 0.5f, 0,"" + ceil(1 / World::getRenderDeltaTime())); } void viewportCameraProps() { 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)); } } diff --git a/imgui.ini b/imgui.ini index 2d3fd47..9c2d509 100644 --- a/imgui.ini +++ b/imgui.ini @@ -9,11 +9,65 @@ Size=400,400 Collapsed=0 [Window][TreePanel] -Pos=0,34 -Size=2560,1336 +Pos=0,26 +Size=569,925 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] -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 diff --git a/make b/make new file mode 100644 index 0000000..e69de29