|
| 1 | +/** |
| 2 | +* @project: Overload |
| 3 | +* @author: Overload Tech. |
| 4 | +* @licence: MIT |
| 5 | +*/ |
| 6 | + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <string> |
| 10 | +#include <vector> |
| 11 | + |
| 12 | +#include <OvCore/Scripting/Common/EScriptingLanguage.h> |
| 13 | + |
| 14 | +namespace OvCore::ECS::Components |
| 15 | +{ |
| 16 | + class Behaviour; |
| 17 | + class CPhysicalObject; |
| 18 | +} |
| 19 | + |
| 20 | +namespace OvCore::Scripting |
| 21 | +{ |
| 22 | + /** |
| 23 | + * Interface for any scripting backend to implement. |
| 24 | + * This class defines the necessary methods that a scripting engine should provide |
| 25 | + * to interact with the engine's components and handle various lifecycle events. |
| 26 | + */ |
| 27 | + template<EScriptingLanguage Language, class Context> |
| 28 | + class TScriptEngine |
| 29 | + { |
| 30 | + public: |
| 31 | + /** |
| 32 | + * Constructor of the generic script engine |
| 33 | + */ |
| 34 | + TScriptEngine(); |
| 35 | + |
| 36 | + /** |
| 37 | + * Destructor of the generic script engine (virtual to allow polymorphism) |
| 38 | + */ |
| 39 | + virtual ~TScriptEngine(); |
| 40 | + |
| 41 | + /** |
| 42 | + * Defines the root location of the script folder |
| 43 | + * @param p_rootFolder |
| 44 | + */ |
| 45 | + void SetScriptRootFolder(const std::string& p_rootFolder); |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns a list of valid extensions for scripts. |
| 49 | + */ |
| 50 | + std::vector<std::string> GetValidExtensions(); |
| 51 | + |
| 52 | + /** |
| 53 | + * Returns the content for a default script |
| 54 | + * @param p_name Name of the class or object represented by this script |
| 55 | + */ |
| 56 | + std::string GetDefaultScriptContent(const std::string& p_name); |
| 57 | + |
| 58 | + /** |
| 59 | + * Returns the extension for a default script |
| 60 | + */ |
| 61 | + std::string GetDefaultExtension(); |
| 62 | + |
| 63 | + /** |
| 64 | + * Adds a behaviour to the scripting engine. |
| 65 | + * @param p_toAdd The behaviour to add. |
| 66 | + */ |
| 67 | + void AddBehaviour(OvCore::ECS::Components::Behaviour& p_toAdd); |
| 68 | + |
| 69 | + /** |
| 70 | + * Removes a behaviour from the scripting engine. |
| 71 | + * @param p_toRemove The behaviour to remove. |
| 72 | + */ |
| 73 | + void RemoveBehaviour(OvCore::ECS::Components::Behaviour& p_toRemove); |
| 74 | + |
| 75 | + /** |
| 76 | + * Reloads the scripting engine. |
| 77 | + */ |
| 78 | + void Reload(); |
| 79 | + |
| 80 | + /** |
| 81 | + * Checks if the scripting engine is in a good state. |
| 82 | + * @return True if the engine is okay, false otherwise. |
| 83 | + */ |
| 84 | + bool IsOk() const; |
| 85 | + |
| 86 | + /** |
| 87 | + * Called when a behaviour is awakened. |
| 88 | + * @param p_target The target behaviour. |
| 89 | + */ |
| 90 | + void OnAwake(OvCore::ECS::Components::Behaviour& p_target); |
| 91 | + |
| 92 | + /** |
| 93 | + * Called when a behaviour starts. |
| 94 | + * @param p_target The target behaviour. |
| 95 | + */ |
| 96 | + void OnStart(OvCore::ECS::Components::Behaviour& p_target); |
| 97 | + |
| 98 | + /** |
| 99 | + * Called when a behaviour is enabled. |
| 100 | + * @param p_target The target behaviour. |
| 101 | + */ |
| 102 | + void OnEnable(OvCore::ECS::Components::Behaviour& p_target); |
| 103 | + |
| 104 | + /** |
| 105 | + * Called when a behaviour is disabled. |
| 106 | + * @param p_target The target behaviour. |
| 107 | + */ |
| 108 | + void OnDisable(OvCore::ECS::Components::Behaviour& p_target); |
| 109 | + |
| 110 | + /** |
| 111 | + * Called when a behaviour is destroyed. |
| 112 | + * @param p_target The target behaviour. |
| 113 | + */ |
| 114 | + void OnDestroy(OvCore::ECS::Components::Behaviour& p_target); |
| 115 | + |
| 116 | + /** |
| 117 | + * Called every frame to update a behaviour. |
| 118 | + * @param p_target The target behaviour. |
| 119 | + * @param p_deltaTime The time elapsed since the last frame. |
| 120 | + */ |
| 121 | + void OnUpdate(OvCore::ECS::Components::Behaviour& p_target, float p_deltaTime); |
| 122 | + |
| 123 | + /** |
| 124 | + * Called every physics frame to update a behaviour. |
| 125 | + * @param p_target The target behaviour. |
| 126 | + * @param p_deltaTime The time elapsed since the last physics frame. |
| 127 | + */ |
| 128 | + void OnFixedUpdate(OvCore::ECS::Components::Behaviour& p_target, float p_deltaTime); |
| 129 | + |
| 130 | + /** |
| 131 | + * Called every frame after OnUpdate to perform late updates on a behaviour. |
| 132 | + * @param p_target The target behaviour. |
| 133 | + * @param p_deltaTime The time elapsed since the last frame. |
| 134 | + */ |
| 135 | + void OnLateUpdate(OvCore::ECS::Components::Behaviour& p_target, float p_deltaTime); |
| 136 | + |
| 137 | + /** |
| 138 | + * Called when a behaviour's owner enters a collision with another physical object. |
| 139 | + * @param p_target The target behaviour. |
| 140 | + * @param p_otherObject The other physical object involved in the collision. |
| 141 | + */ |
| 142 | + void OnCollisionEnter(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 143 | + |
| 144 | + /** |
| 145 | + * Called when a behaviour's owner stays in collision with another physical object. |
| 146 | + * @param p_target The target behaviour. |
| 147 | + * @param p_otherObject The other physical object involved in the collision. |
| 148 | + */ |
| 149 | + void OnCollisionStay(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 150 | + |
| 151 | + /** |
| 152 | + * Called when a behaviour's owner exits a collision with another physical object. |
| 153 | + * @param p_target The target behaviour. |
| 154 | + * @param p_otherObject The other physical object involved in the collision. |
| 155 | + */ |
| 156 | + void OnCollisionExit(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 157 | + |
| 158 | + /** |
| 159 | + * Called when a behaviour's owner enters a trigger with another physical object. |
| 160 | + * @param p_target The target behaviour. |
| 161 | + * @param p_otherObject The other physical object involved in the trigger. |
| 162 | + */ |
| 163 | + void OnTriggerEnter(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 164 | + |
| 165 | + /** |
| 166 | + * Called when a behaviour's owner stays in a trigger with another physical object. |
| 167 | + * @param p_target The target behaviour. |
| 168 | + * @param p_otherObject The other physical object involved in the trigger. |
| 169 | + */ |
| 170 | + void OnTriggerStay(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 171 | + |
| 172 | + /** |
| 173 | + * Called when a behaviour's owner exits a trigger with another physical object. |
| 174 | + * @param p_target The target behaviour. |
| 175 | + * @param p_otherObject The other physical object involved in the trigger. |
| 176 | + */ |
| 177 | + void OnTriggerExit(OvCore::ECS::Components::Behaviour& p_target, OvCore::ECS::Components::CPhysicalObject& p_otherObject); |
| 178 | + |
| 179 | + protected: |
| 180 | + Context m_context; |
| 181 | + }; |
| 182 | +} |
0 commit comments