Converted SHScriptEngine into a SHSystem
This commit is contained in:
parent
941f4a135f
commit
0f63ee10d0
|
@ -37,7 +37,7 @@ namespace Sandbox
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
||||||
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::SHGraphicsSystemRoutine>(1);
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::SHGraphicsSystemRoutine>(1);
|
||||||
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHScriptEngine>();
|
||||||
|
|
||||||
graphicsSystem->SetWindow(&window);
|
graphicsSystem->SetWindow(&window);
|
||||||
SDL_CreateWindowFrom(window.GetHWND());
|
SDL_CreateWindowFrom(window.GetHWND());
|
||||||
|
@ -47,9 +47,6 @@ namespace Sandbox
|
||||||
//SHADE::SHEditor::Initialize(window.GetHWND());
|
//SHADE::SHEditor::Initialize(window.GetHWND());
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set up scripting
|
|
||||||
SHADE::SHScriptEngine::Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBApplication::Update(void)
|
void SBApplication::Update(void)
|
||||||
|
@ -76,7 +73,6 @@ namespace Sandbox
|
||||||
|
|
||||||
void SBApplication::Exit(void)
|
void SBApplication::Exit(void)
|
||||||
{
|
{
|
||||||
SHADE::SHScriptEngine::Exit();
|
|
||||||
SHADE::SHSystemManager::Exit();
|
SHADE::SHSystemManager::Exit();
|
||||||
SDL_DestroyWindow(sdlWindow);
|
SDL_DestroyWindow(sdlWindow);
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
|
|
|
@ -26,25 +26,6 @@ namespace SHADE
|
||||||
/* Static Definitions */
|
/* Static Definitions */
|
||||||
/*--------------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------------*/
|
||||||
const std::string SHScriptEngine::DEFAULT_CSHARP_NAMESPACE = std::string("SHADE");
|
const std::string SHScriptEngine::DEFAULT_CSHARP_NAMESPACE = std::string("SHADE");
|
||||||
SHDotNetRuntime SHScriptEngine::dotNet { false };
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csEngineInit = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csEngineLoadScripts = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csEngineUnloadScripts = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csEngineReloadScripts = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csEngineExit = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csScriptsFrameSetUp = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csScriptsExecuteFixedUpdate = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csScriptsExecuteUpdate = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csScriptsExecuteLateUpdate = nullptr;
|
|
||||||
SHScriptEngine::CsFuncPtr SHScriptEngine::csScriptsFrameCleanUp = nullptr;
|
|
||||||
SHScriptEngine::CsScriptManipFuncPtr SHScriptEngine::csScriptsAdd = nullptr;
|
|
||||||
SHScriptEngine::CsScriptBasicFuncPtr SHScriptEngine::csScriptsRemoveAll = nullptr;
|
|
||||||
SHScriptEngine::CsScriptOptionalFuncPtr SHScriptEngine::csScriptsRemoveAllImmediately = nullptr;
|
|
||||||
SHScriptEngine::CsScriptSerialiseFuncPtr SHScriptEngine::csScriptsSerialise = nullptr;
|
|
||||||
SHScriptEngine::CsScriptDeserialiseFuncPtr SHScriptEngine::csScriptDeserialise = nullptr;
|
|
||||||
SHScriptEngine::CsScriptSerialiseYamlFuncPtr SHScriptEngine::csScriptsSerialiseYaml = nullptr;
|
|
||||||
SHScriptEngine::CsScriptSerialiseYamlFuncPtr SHScriptEngine::csScriptDeserialiseYaml = nullptr;
|
|
||||||
SHScriptEngine::CsScriptEditorFuncPtr SHScriptEngine::csEditorRenderScripts = nullptr;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Lifecycle Functions */
|
/* Lifecycle Functions */
|
||||||
|
@ -137,7 +118,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Script Serialisation Functions */
|
/* Script Serialisation Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
std::string SHScriptEngine::SerialiseScripts(const SHEntity& entity)
|
std::string SHScriptEngine::SerialiseScripts(const SHEntity& entity) const
|
||||||
{
|
{
|
||||||
// Create buffer needed to store serialised script data
|
// Create buffer needed to store serialised script data
|
||||||
constexpr int BUFFER_SIZE = 10240;
|
constexpr int BUFFER_SIZE = 10240;
|
||||||
|
@ -162,7 +143,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Script Serialisation Functions */
|
/* Script Serialisation Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
void SHScriptEngine::DeserialiseScript(const SHEntity& entity, const std::string& yaml)
|
void SHScriptEngine::DeserialiseScript(const SHEntity& entity, const std::string& yaml) const
|
||||||
{
|
{
|
||||||
csScriptDeserialise(entity.GetEID(), yaml.c_str());
|
csScriptDeserialise(entity.GetEID(), yaml.c_str());
|
||||||
}
|
}
|
||||||
|
@ -170,7 +151,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Script Editor Functions */
|
/* Script Editor Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
void SHScriptEngine::RenderScriptsInInspector(const SHEntity& entity)
|
void SHScriptEngine::RenderScriptsInInspector(const SHEntity& entity) const
|
||||||
{
|
{
|
||||||
csEditorRenderScripts(entity.GetEID());
|
csEditorRenderScripts(entity.GetEID());
|
||||||
}
|
}
|
||||||
|
@ -178,7 +159,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Static Utility Functions */
|
/* Static Utility Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
bool SHScriptEngine::BuildScriptAssembly(bool debug)
|
bool SHScriptEngine::BuildScriptAssembly(bool debug) const
|
||||||
{
|
{
|
||||||
constexpr std::string_view BUILD_LOG_PATH = "../Build.log";
|
constexpr std::string_view BUILD_LOG_PATH = "../Build.log";
|
||||||
|
|
||||||
|
@ -230,7 +211,7 @@ namespace SHADE
|
||||||
return BUILD_SUCCESS;
|
return BUILD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHScriptEngine::GenerateScriptsCsProjFile(const std::filesystem::path& path)
|
void SHScriptEngine::GenerateScriptsCsProjFile(const std::filesystem::path& path) const
|
||||||
{
|
{
|
||||||
// Sample
|
// Sample
|
||||||
static std::string_view FILE_CONTENTS =
|
static std::string_view FILE_CONTENTS =
|
||||||
|
|
|
@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "SHDotNetRuntime.h"
|
#include "SHDotNetRuntime.h"
|
||||||
#include "ECS_Base/SHECSMacros.h"
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
#include "ECS_Base/Entity/SHEntity.h"
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
|
#include "ECS_Base/System/SHSystem.h"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -26,13 +27,13 @@ namespace SHADE
|
||||||
/// Manages initialisation of the DotNetRuntime and interfacing with CLR code written
|
/// Manages initialisation of the DotNetRuntime and interfacing with CLR code written
|
||||||
/// and executed on .NET.
|
/// and executed on .NET.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class SH_API SHScriptEngine
|
class SH_API SHScriptEngine : public SHSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SHScriptEngine() = delete;
|
SHScriptEngine() = default;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Lifecycle Functions */
|
/* Lifecycle Functions */
|
||||||
|
@ -41,33 +42,33 @@ namespace SHADE
|
||||||
/// Initialises the DotNetRuntime and retrieves function pointers to all
|
/// Initialises the DotNetRuntime and retrieves function pointers to all
|
||||||
/// functions on the CLR used to interface with the engine.
|
/// functions on the CLR used to interface with the engine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void Init();
|
void Init() override;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the managed script assembly. Ensure this is only called after
|
/// Loads the managed script assembly. Ensure this is only called after
|
||||||
/// UnloadScriptAssembly() has been called.
|
/// UnloadScriptAssembly() has been called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void UnloadScriptAssembly();
|
void UnloadScriptAssembly();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unloads the managed script assembly.
|
/// Unloads the managed script assembly.
|
||||||
/// Take note that this will clear all existing scripts, ensure that the scene
|
/// Take note that this will clear all existing scripts, ensure that the scene
|
||||||
/// is saved before doing so.
|
/// is saved before doing so.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void LoadScriptAssembly();
|
void LoadScriptAssembly();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads the managed script assembly.
|
/// Reloads the managed script assembly.
|
||||||
/// Take note that this will clear all existing scripts, ensure that the scene
|
/// Take note that this will clear all existing scripts, ensure that the scene
|
||||||
/// is saved before doing so.
|
/// is saved before doing so.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void ReloadScriptAssembly();
|
void ReloadScriptAssembly();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the FixedUpdate()s of the Scripts that are attached to
|
/// Executes the FixedUpdate()s of the Scripts that are attached to
|
||||||
/// Entities.
|
/// Entities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void ExecuteFixedUpdates();
|
void ExecuteFixedUpdates();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shuts down the DotNetRuntime.
|
/// Shuts down the DotNetRuntime.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void Exit();
|
void Exit() override;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Script Manipulation Functions */
|
/* Script Manipulation Functions */
|
||||||
|
@ -84,14 +85,14 @@ namespace SHADE
|
||||||
/// True if successfully added. False otherwise with the error logged to the
|
/// True if successfully added. False otherwise with the error logged to the
|
||||||
/// console.
|
/// console.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
static bool AddScript(const SHEntity& entity, const std::string_view& scriptName);
|
bool AddScript(const SHEntity& entity, const std::string_view& scriptName);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes all Scripts attached to the specified Entity. Does not do anything
|
/// Removes all Scripts attached to the specified Entity. Does not do anything
|
||||||
/// if the specified Entity is invalid or does not have any Scripts
|
/// if the specified Entity is invalid or does not have any Scripts
|
||||||
/// attached.
|
/// attached.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entity">The entity to remove the scripts from.</param>
|
/// <param name="entity">The entity to remove the scripts from.</param>
|
||||||
static void RemoveAllScripts(const SHEntity& entity);
|
void RemoveAllScripts(const SHEntity& entity);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes all Scripts attached to the specified Entity. Unlike
|
/// Removes all Scripts attached to the specified Entity. Unlike
|
||||||
/// RemoveAllScripts(), this removes all the scripts immediately.
|
/// RemoveAllScripts(), this removes all the scripts immediately.
|
||||||
|
@ -103,7 +104,7 @@ namespace SHADE
|
||||||
/// Whether or not to call OnDestroy on the scripts. This is ignored if not in
|
/// Whether or not to call OnDestroy on the scripts. This is ignored if not in
|
||||||
/// play mode.
|
/// play mode.
|
||||||
/// </param>
|
/// </param>
|
||||||
static void RemoveAllScriptsImmediately(const SHEntity& entity, bool callOnDestroy);
|
void RemoveAllScriptsImmediately(const SHEntity& entity, bool callOnDestroy);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Script Serialisation Functions */
|
/* Script Serialisation Functions */
|
||||||
|
@ -116,7 +117,7 @@ namespace SHADE
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// String that represents the set of scripts attached to the specified Entity.
|
/// String that represents the set of scripts attached to the specified Entity.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
static std::string SerialiseScripts(const SHEntity& entity);
|
std::string SerialiseScripts(const SHEntity& entity) const;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the specified JSON string and creates a Script for the specified Entity
|
/// Loads the specified JSON string and creates a Script for the specified Entity
|
||||||
/// based on the specified JSON string.
|
/// based on the specified JSON string.
|
||||||
|
@ -125,7 +126,7 @@ namespace SHADE
|
||||||
/// <param name="yaml">
|
/// <param name="yaml">
|
||||||
/// The YAML string that represents the Script to load into the Entity.
|
/// The YAML string that represents the Script to load into the Entity.
|
||||||
/// </param>
|
/// </param>
|
||||||
static void DeserialiseScript(const SHEntity& entity, const std::string& yaml);
|
void DeserialiseScript(const SHEntity& entity, const std::string& yaml) const;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Script Editor Functions */
|
/* Script Editor Functions */
|
||||||
|
@ -138,7 +139,7 @@ namespace SHADE
|
||||||
/// rendering code.
|
/// rendering code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entity">The Entity to render the Scripts of.</param>
|
/// <param name="entity">The Entity to render the Scripts of.</param>
|
||||||
static void RenderScriptsInInspector(const SHEntity& entity);
|
void RenderScriptsInInspector(const SHEntity& entity) const;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Static Utility Functions */
|
/* Static Utility Functions */
|
||||||
|
@ -153,12 +154,12 @@ namespace SHADE
|
||||||
/// can be debugged.
|
/// can be debugged.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>Whether or not the build succeeded.</returns>
|
/// <returns>Whether or not the build succeeded.</returns>
|
||||||
static bool BuildScriptAssembly(bool debug = false);
|
bool BuildScriptAssembly(bool debug = false) const;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a .csproj file for editing and compiling the C# scripts.
|
/// Generates a .csproj file for editing and compiling the C# scripts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">File path to the generated file.</param>
|
/// <param name="path">File path to the generated file.</param>
|
||||||
static void GenerateScriptsCsProjFile(const std::filesystem::path& path);
|
void GenerateScriptsCsProjFile(const std::filesystem::path& path) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -183,29 +184,29 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
static SHDotNetRuntime dotNet;
|
SHDotNetRuntime dotNet { false };
|
||||||
// Function Pointers to CLR Code
|
// Function Pointers to CLR Code
|
||||||
// - Engine Lifecycle
|
// - Engine Lifecycle
|
||||||
static CsFuncPtr csEngineInit;
|
CsFuncPtr csEngineInit = nullptr;
|
||||||
static CsFuncPtr csEngineLoadScripts;
|
CsFuncPtr csEngineLoadScripts = nullptr;
|
||||||
static CsFuncPtr csEngineUnloadScripts;
|
CsFuncPtr csEngineUnloadScripts = nullptr;
|
||||||
static CsFuncPtr csEngineReloadScripts;
|
CsFuncPtr csEngineReloadScripts = nullptr;
|
||||||
static CsFuncPtr csEngineExit;
|
CsFuncPtr csEngineExit = nullptr;
|
||||||
// - Scripts Store
|
// - Scripts Store
|
||||||
static CsFuncPtr csScriptsFrameSetUp;
|
CsFuncPtr csScriptsFrameSetUp = nullptr;
|
||||||
static CsFuncPtr csScriptsExecuteFixedUpdate;
|
CsFuncPtr csScriptsExecuteFixedUpdate = nullptr;
|
||||||
static CsFuncPtr csScriptsExecuteUpdate;
|
CsFuncPtr csScriptsExecuteUpdate = nullptr;
|
||||||
static CsFuncPtr csScriptsExecuteLateUpdate;
|
CsFuncPtr csScriptsExecuteLateUpdate = nullptr;
|
||||||
static CsFuncPtr csScriptsFrameCleanUp;
|
CsFuncPtr csScriptsFrameCleanUp = nullptr;
|
||||||
static CsScriptManipFuncPtr csScriptsAdd;
|
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
||||||
static CsScriptBasicFuncPtr csScriptsRemoveAll;
|
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
|
||||||
static CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately;
|
CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr;
|
||||||
static CsScriptSerialiseFuncPtr csScriptsSerialise;
|
CsScriptSerialiseFuncPtr csScriptsSerialise = nullptr;
|
||||||
static CsScriptDeserialiseFuncPtr csScriptDeserialise;
|
CsScriptDeserialiseFuncPtr csScriptDeserialise = nullptr;
|
||||||
static CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml;
|
CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr;
|
||||||
static CsScriptSerialiseYamlFuncPtr csScriptDeserialiseYaml;
|
CsScriptSerialiseYamlFuncPtr csScriptDeserialiseYaml = nullptr;
|
||||||
// - Editor
|
// - Editor
|
||||||
static CsScriptEditorFuncPtr csEditorRenderScripts;
|
CsScriptEditorFuncPtr csEditorRenderScripts = nullptr;
|
||||||
// Delegates
|
// Delegates
|
||||||
/*ECS::EntityEvent::Delegate onEntityCreate;
|
/*ECS::EntityEvent::Delegate onEntityCreate;
|
||||||
ECS::EntityEvent::Delegate onEntityDestroy;*/
|
ECS::EntityEvent::Delegate onEntityDestroy;*/
|
||||||
|
@ -216,7 +217,7 @@ namespace SHADE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads all the function pointers to CLR code that we need to execute.
|
/// Loads all the function pointers to CLR code that we need to execute.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void loadFunctions();
|
void loadFunctions();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the file via the specified path that represents a build log of error
|
/// Reads the file via the specified path that represents a build log of error
|
||||||
/// and warning messages.
|
/// and warning messages.
|
||||||
|
|
Loading…
Reference in New Issue