diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index f4102067..6b67dbce 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -106,6 +106,7 @@ namespace Sandbox SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 4a73342e..827f45a2 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -379,6 +379,12 @@ namespace SHADE DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", "ExecuteLateUpdate" + ); + csScriptsExecuteDrawGizmos = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", + "ExecuteOnDrawGizmos" ); csScriptsExecutePhysicsEvents = dotNet.GetFunctionPtr ( diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 9ddd617a..7d83606e 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -55,6 +55,12 @@ namespace SHADE LateUpdateRoutine(); void Execute(double dt) noexcept override final; }; + class SH_API GizmosDrawRoutine final : public SHSystemRoutine + { + public: + GizmosDrawRoutine(); + void Execute(double dt) noexcept override final; + }; class SH_API FrameCleanUpRoutine final : public SHSystemRoutine { public: @@ -250,6 +256,7 @@ namespace SHADE CsFuncPtr csScriptsExecuteFixedUpdate = nullptr; CsFuncPtr csScriptsExecuteUpdate = nullptr; CsFuncPtr csScriptsExecuteLateUpdate = nullptr; + CsFuncPtr csScriptsExecuteDrawGizmos = nullptr; CsFuncPtr csScriptsExecutePhysicsEvents = nullptr; CsFuncPtr csScriptsFrameCleanUp = nullptr; CsScriptManipFuncPtr csScriptsAdd = nullptr; diff --git a/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp b/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp index a2981c06..699776ca 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp @@ -50,6 +50,17 @@ namespace SHADE reinterpret_cast(system)->csScriptsExecuteLateUpdate(); } + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - GizmosDrawRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHScriptEngine::GizmosDrawRoutine::GizmosDrawRoutine() + : SHSystemRoutine("Script Engine Gizmos Draw", true) + {} + void SHScriptEngine::GizmosDrawRoutine::Execute(double dt) noexcept + { + reinterpret_cast(system)->csScriptsExecuteDrawGizmos(); + } + /*-----------------------------------------------------------------------------------*/ /* System Routine Functions - FrameCleanUpRoutine */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Components/Light.cxx b/SHADE_Managed/src/Components/Light.cxx new file mode 100644 index 00000000..a220c79a --- /dev/null +++ b/SHADE_Managed/src/Components/Light.cxx @@ -0,0 +1,79 @@ +/************************************************************************************//*! +\file Light.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the functions of the managed Light class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Light.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Light::Light(Entity entity) + : Component(entity) + {} + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + Vector3 Light::Position::get() + { + return Convert::ToCLI(GetNativeComponent()->GetPosition()); + } + void Light::Position::set(Vector3 value) + { + GetNativeComponent()->SetPosition(Convert::ToNative(value)); + } + Light::Type Light::LightType::get() + { + return static_cast(GetNativeComponent()->GetType()); + } + void Light::LightType::set(Light::Type value) + { + GetNativeComponent()->SetType(static_cast(value)); + } + Vector3 Light::Direction::get() + { + return Convert::ToCLI(GetNativeComponent()->GetDirection()); + } + void Light::Direction::set(Vector3 value) + { + GetNativeComponent()->SetDirection(Convert::ToNative(value)); + } + Color Light::Color::get() + { + return Convert::ToCLI(SHColour(GetNativeComponent()->GetColor())); + } + void Light::Color::set(SHADE::Color value) + { + GetNativeComponent()->SetColor(Convert::ToNative(value)); + } + System::UInt32 Light::CullingMask::get() + { + return GetNativeComponent()->GetCullingMask(); + } + void Light::CullingMask::set(System::UInt32 value) + { + GetNativeComponent()->SetCullingMask(value); + } + float Light::Strength::get() + { + return GetNativeComponent()->GetStrength(); + } + void Light::Strength::set(float value) + { + GetNativeComponent()->SetStrength(value); + } +} diff --git a/SHADE_Managed/src/Components/Light.hxx b/SHADE_Managed/src/Components/Light.hxx new file mode 100644 index 00000000..9abb05d5 --- /dev/null +++ b/SHADE_Managed/src/Components/Light.hxx @@ -0,0 +1,125 @@ +/************************************************************************************//*! +\file Light.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the managed Light class with the declaration + of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +// External Dependencies +#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHLightComponent. + /// + public ref class Light : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a Light Component that represents a native Light component tied to + /// the specified Entity. + /// + /// Entity that this Component will be tied to. + Light(Entity entity); + + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ + /// + /// Supported types of the Light Component. + /// + enum class Type + { + /// + /// Light applied uniformly across the scene at a specified direction. + /// + Directional, + /// + /// Light that originates from a certain point in all directions. + /// Not implemented yet. + /// + Point, + /// + /// Light that originates from a certain point within a angle. + /// Not implemented yet. + /// + Spot, + /// + /// Light applied to all objects. Has no source point. + /// + Ambient + }; + + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Position of the light. Only works for Point Light (unimplemented). + /// + [System::ObsoleteAttribute("Not implemented yet.", true)] + property Vector3 Position + { + Vector3 get(); + void set(Vector3 val); + } + /// + /// Type of lighting that this Light component will apply onto the scene. + /// + property Type LightType + { + Type get(); + void set(Type val); + } + /// + /// Direction of the light. Only applicable for Directional Lights. + /// + property Vector3 Direction + { + Vector3 get(); + void set(Vector3 val); + } + /// + /// Colour of the Light. + /// + property SHADE::Color Color + { + SHADE::Color get(); + void set(SHADE::Color val); + } + /// + /// Culling mask that is used to control what types of Materials would be + /// affected by this Light. + /// + property System::UInt32 CullingMask + { + System::UInt32 get(); + void set(System::UInt32 val); + } + /// + /// Intensity of the Light + /// + property float Strength + { + float get(); + void set(float val); + } + }; +} + diff --git a/SHADE_Managed/src/Engine/ECS.cxx b/SHADE_Managed/src/Engine/ECS.cxx index 3da39394..00c3c182 100644 --- a/SHADE_Managed/src/Engine/ECS.cxx +++ b/SHADE_Managed/src/Engine/ECS.cxx @@ -22,8 +22,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "ECS_Base/Managers/SHEntityManager.h" #include "Math/Transform/SHTransformComponent.h" -#include "Physics\Components\SHColliderComponent.h" -#include "Physics\Components\SHRigidBodyComponent.h" +#include "Physics/Components/SHColliderComponent.h" +#include "Physics/Components/SHRigidBodyComponent.h" #include "Scene/SHSceneManager.h" #include "Scene/SHSceneGraph.h" #include "Tools/SHLog.h" @@ -31,10 +31,11 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" #include "Components/Transform.hxx" -#include "Components\RigidBody.hxx" -#include "Components\Collider.hxx" +#include "Components/RigidBody.hxx" +#include "Components/Collider.hxx" #include "Components/Camera.hxx" #include "Components/CameraArm.hxx" +#include "Components/Light.hxx" namespace SHADE { @@ -252,6 +253,7 @@ namespace SHADE componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); + componentMap.Add(createComponentSet()); } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Graphics/Color.hxx b/SHADE_Managed/src/Graphics/Color.hxx index d6a46216..64152394 100644 --- a/SHADE_Managed/src/Graphics/Color.hxx +++ b/SHADE_Managed/src/Graphics/Color.hxx @@ -25,95 +25,85 @@ namespace SHADE { public: /*-----------------------------------------------------------------------------*/ - /* Type Definitions */ + /* Properties */ /*-----------------------------------------------------------------------------*/ /// - /// A static class that contains a set of default Colors. + /// Pure black. /// - ref class Defaults abstract sealed + static property Color Black { - public: - /*-------------------------------------------------------------------------*/ - /* Properties */ - /*-------------------------------------------------------------------------*/ - /// - /// Pure black. - /// - static property Color Black - { - Color get() { return Color(0.0f, 0.0f, 0.0f); } - } - /// - /// Light Gray, lighter than gray. - /// - static property Color LightGray - { - Color get() { return Color(0.827451f, 0.827451f, 0.827451f); } - } - /// - /// Gray, halfway between black and white. - /// - static property Color Gray - { - Color get() { return Color(0.5f, 0.5f, 0.5f); } - } - /// - /// Dark Gray, darker than gray. - /// - static property Color DarkGray - { - Color get() { return Color(0.622f, 0.622f, 0.622f); } - } - /// - /// Pure white. - /// - static property Color White - { - Color get() { return Color(1.0f, 1.0f, 1.0f); } - } - /// - /// Pure red. - /// - static property Color Red - { - Color get() { return Color(1.0f, 0.0f, 0.0f); } - } - /// - /// Pure green. - /// - static property Color Green - { - Color get() { return Color(0.0f, 1.0f, 0.0f); } - } - /// - /// Pure blue. - /// - static property Color Blue - { - Color get() { return Color(0.0f, 0.0f, 1.0f); } - } - /// - /// Pure cyan, mix of pure green and blue. - /// - static property Color Cyan - { - Color get() { return Color(0.0f, 1.0f, 1.0f); } - } - /// - /// Pure magenta, mix of pure red and blue. - /// - static property Color Magenta - { - Color get() { return Color(1.0f, 0.0f, 1.0f); } - } - /// - /// Pure yellow, mix of pure red and green. - /// - static property Color Yellow - { - Color get() { return Color(1.0f, 1.0f, 0.0f); } - } - }; + Color get() { return Color(0.0f, 0.0f, 0.0f); } + } + /// + /// Light Gray, lighter than gray. + /// + static property Color LightGray + { + Color get() { return Color(0.827451f, 0.827451f, 0.827451f); } + } + /// + /// Gray, halfway between black and white. + /// + static property Color Gray + { + Color get() { return Color(0.5f, 0.5f, 0.5f); } + } + /// + /// Dark Gray, darker than gray. + /// + static property Color DarkGray + { + Color get() { return Color(0.622f, 0.622f, 0.622f); } + } + /// + /// Pure white. + /// + static property Color White + { + Color get() { return Color(1.0f, 1.0f, 1.0f); } + } + /// + /// Pure red. + /// + static property Color Red + { + Color get() { return Color(1.0f, 0.0f, 0.0f); } + } + /// + /// Pure green. + /// + static property Color Green + { + Color get() { return Color(0.0f, 1.0f, 0.0f); } + } + /// + /// Pure blue. + /// + static property Color Blue + { + Color get() { return Color(0.0f, 0.0f, 1.0f); } + } + /// + /// Pure cyan, mix of pure green and blue. + /// + static property Color Cyan + { + Color get() { return Color(0.0f, 1.0f, 1.0f); } + } + /// + /// Pure magenta, mix of pure red and blue. + /// + static property Color Magenta + { + Color get() { return Color(1.0f, 0.0f, 1.0f); } + } + /// + /// Pure yellow, mix of pure red and green. + /// + static property Color Yellow + { + Color get() { return Color(1.0f, 1.0f, 0.0f); } + } /*-----------------------------------------------------------------------------*/ /* Constructors */ diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index e476d69d..bd6d7bef 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -140,6 +140,13 @@ namespace SHADE lateUpdate(); SAFE_NATIVE_CALL_END(this) } + void Script::OnDrawGizmos() + { + SAFE_NATIVE_CALL_BEGIN + OnGizmosDrawOverriden = true; + onDrawGizmos(); + SAFE_NATIVE_CALL_END(this) + } void Script::OnDestroy() { SAFE_NATIVE_CALL_BEGIN @@ -194,6 +201,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Script::Script(GameObject gameObj) : owner { gameObj } + , OnGizmosDrawOverriden { false } {} /*---------------------------------------------------------------------------------*/ @@ -210,6 +218,10 @@ namespace SHADE void Script::fixedUpdate() {} void Script::update() {} void Script::lateUpdate() {} + void Script::onDrawGizmos() + { + OnGizmosDrawOverriden = false; + } void Script::onDestroy() {} /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index afeaa8a0..bbe36784 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -164,6 +164,14 @@ namespace SHADE static operator bool(Script^ s); internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// If true, the OnGizmosDraw function was overridden. + /// + bool OnGizmosDrawOverriden; + /*-----------------------------------------------------------------------------*/ /* "All-Time" Lifecycle Functions */ /*-----------------------------------------------------------------------------*/ @@ -208,6 +216,11 @@ namespace SHADE /// void LateUpdate(); /// + /// Used to call onDrawGizmos(). This should be called just before rendering + /// the scene. This will only be called when working in the editor. + /// + void OnDrawGizmos(); + /// /// Used to call onDestroy(). This should be called at the end of the frame /// where the attached GameObject or this script is destroyed directly or /// indirectly due to destruction of the owner. @@ -308,6 +321,10 @@ namespace SHADE /// virtual void lateUpdate(); /// + /// Called every frame just before rendering but only if working in the editor. + /// + virtual void onDrawGizmos(); + /// /// Called just before the end of the frame where the attached GameObject or /// this script is destroyed directly or indirectly due to destruction of the /// owner. diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 407d0fa8..a90b4f12 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -478,6 +478,24 @@ namespace SHADE SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") } + void ScriptStore::ExecuteOnDrawGizmos() + { + SAFE_NATIVE_CALL_BEGIN + for each (System::Collections::Generic::KeyValuePair entity in scripts) + { + // Check active state + if (!isEntityActive(entity.Key)) + continue; + + // Update each script + for each (Script^ script in entity.Value) + { + script->OnDrawGizmos(); + } + } + SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") + } + void ScriptStore::ExecuteCollisionFunctions() { SAFE_NATIVE_CALL_BEGIN diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index a4c6e824..c151392f 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -234,6 +234,10 @@ namespace SHADE /// static void ExecuteLateUpdate(); /// + /// Executes OnDrawGizmos() for all scripts. + /// + static void ExecuteOnDrawGizmos(); + /// /// Executes OnCollision*() and OnTrigger*() for all scripts. /// static void ExecuteCollisionFunctions(); diff --git a/SHADE_Managed/src/Utility/Convert.cxx b/SHADE_Managed/src/Utility/Convert.cxx index 1d89569f..3b1f0f38 100644 --- a/SHADE_Managed/src/Utility/Convert.cxx +++ b/SHADE_Managed/src/Utility/Convert.cxx @@ -72,6 +72,16 @@ namespace SHADE return Ray(ToCLI(vec.position), ToCLI(vec.direction)); } + SHColour Convert::ToNative(Color col) + { + return SHColour(col.r, col.g, col.b, col.a); + } + + Color Convert::ToCLI(const SHColour& vec) + { + return Color(vec.x, vec.y, vec.z, vec.w); + } + /*---------------------------------------------------------------------------------*/ /* String Conversions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Utility/Convert.hxx b/SHADE_Managed/src/Utility/Convert.hxx index d3dca740..666b5062 100644 --- a/SHADE_Managed/src/Utility/Convert.hxx +++ b/SHADE_Managed/src/Utility/Convert.hxx @@ -29,6 +29,8 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Quaternion.hxx" #include "Math/Ray.hxx" #include "Engine/GenericHandle.hxx" +#include "Math/SHColour.h" +#include "Graphics/Color.hxx" namespace SHADE { @@ -104,6 +106,17 @@ namespace SHADE /// The native Vector2 to convert from. /// Managed copy of a native Vector2. static Ray ToCLI(const SHRay& vec); + /// Converts from a managed Color to a native Colour. + /// + /// The managed Color to convert from. + /// Native copy of a managed Color. + static SHColour ToNative(Color col); + /// + /// Converts from a native Colour to a managed Color. + /// + /// The native Colour to convert from. + /// Managed copy of a native Colour. + static Color ToCLI(const SHColour& vec); /*-----------------------------------------------------------------------------*/ /* String Conversions */