Added WIP Application class and adjustments to how ScriptStore destroys scripts (SpdLog errors)

This commit is contained in:
Kah Wei 2022-10-31 12:20:46 +08:00
parent 18093433fa
commit 5eaf2b55aa
6 changed files with 191 additions and 6 deletions

View File

@ -293,6 +293,10 @@ namespace SHADE
//Handle<SHVkRenderpass> GetRenderPass() const { return renderPass; } //Handle<SHVkRenderpass> GetRenderPass() const { return renderPass; }
/*-----------------------------------------------------------------------------*/
/* Getters */
/*-----------------------------------------------------------------------------*/
SHWindow* GetWindow() noexcept { return window; }
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -320,7 +324,7 @@ namespace SHADE
SHWindow* window = nullptr; SHWindow* window = nullptr;
// Middle End Resources // Middle End Resources
SHResourceHub resourceManager; SHResourceHub resourceManager;
SHMeshLibrary meshLibrary; SHMeshLibrary meshLibrary;
SHTextureLibrary texLibrary; SHTextureLibrary texLibrary;
SHSamplerCache samplerCache; SHSamplerCache samplerCache;

View File

@ -260,7 +260,7 @@ namespace SHADE
return wndHWND; return wndHWND;
} }
const WindowData SHWindow::GetWindowData() const WindowData SHWindow::GetWindowData() const
{ {
return wndData; return wndData;
} }

View File

@ -123,7 +123,7 @@ namespace SHADE
HWND GetHWND(); HWND GetHWND();
const WindowData GetWindowData(); const WindowData GetWindowData() const;
CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn); CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn);
void UnregisterWindowSizeCallback(CALLBACKID const& callbackid); void UnregisterWindowSizeCallback(CALLBACKID const& callbackid);

View File

@ -0,0 +1,100 @@
/************************************************************************************//*!
\file Application.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 31, 2022
\brief Contains the definitions of the functions in the static managed
Application 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 "Application.hxx"
// External Dependencies
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Graphics/Windowing/SHWindow.h"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
bool Application::IsPlaying::get()
{
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor)
return editor->editorState == SHEditor::State::PLAY
||
editor->editorState == SHEditor::State::PAUSE;
return true;
}
bool Application::IsPaused::get()
{
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor)
return editor->editorState == SHEditor::State::PAUSE;
return false;
}
int Application::WindowWidth::get()
{
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (gfxSystem)
{
const auto WND = gfxSystem->GetWindow();
return WND->GetWindowSize().first;
}
throw gcnew System::InvalidOperationException("Unable to get current window width!");
}
int Application::WindowHeight::get()
{
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (gfxSystem)
{
const auto WND = gfxSystem->GetWindow();
return WND->GetWindowSize().second;
}
throw gcnew System::InvalidOperationException("Unable to get current window height!");
}
bool Application::IsFullscreen::get()
{
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (gfxSystem)
{
const auto WND = gfxSystem->GetWindow();
return WND->GetWindowData().isFullscreen;
}
throw gcnew System::InvalidOperationException("Unable to get current window height!");
}
/*void Application::IsFullscreen::set(bool value)
{
return Pls::Window::SetFullScreen(value);
}*/
/*---------------------------------------------------------------------------------*/
/* Usage Functions */
/*---------------------------------------------------------------------------------*/
void Application::Quit()
{
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (gfxSystem)
{
auto WND = gfxSystem->GetWindow();
return WND->Close();
}
throw gcnew System::InvalidOperationException("Unable to quit!");
}
}

View File

@ -0,0 +1,77 @@
/************************************************************************************//*!
\file Application.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 31, 2022
\brief Contains the definitions of a managed static Application 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.
*//*************************************************************************************/
#pragma once
namespace SHADE
{
/// <summary>
/// Static class that contains useful properties for querying the state of the
/// engine.
/// </summary>
public ref class Application abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Whether or not the engine is playing. This will always be true on Publish.
/// On Debug/Release builds, this is true when the editor is in Play Mode. It
/// will also be true even if the editor is in Play Mode but is paused.
/// </summary>
static property bool IsPlaying
{
bool get();
}
/// <summary>
/// Whether or not the engine is in a paused state where script updates and
/// physics are not in play.
/// </summary>
static property bool IsPaused
{
bool get();
}
/// <summary>
/// Retrieves the designated width of the current window.
/// </summary>
static property int WindowWidth
{
int get();
}
/// <summary>
/// Retrieves the designated height of the current window.
/// </summary>
static property int WindowHeight
{
int get();
}
/// <summary>
/// Whether or not the application is currently in fullscreen mode or not.
/// </summary>
static property bool IsFullscreen
{
bool get();
// TODO: once implemented on SHADE_Engine
//void set(bool value);
}
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Marks the application to stop at the end of the current frame.
/// </summary>
static void Quit();
};
}

View File

@ -27,6 +27,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Script.hxx" #include "Script.hxx"
#include "Engine/Entity.hxx" #include "Engine/Entity.hxx"
#include "Serialisation/ReflectionUtilities.hxx" #include "Serialisation/ReflectionUtilities.hxx"
#include "Engine/Application.hxx"
namespace SHADE namespace SHADE
{ {
@ -372,8 +373,11 @@ namespace SHADE
// Clear the queue // Clear the queue
while (disposalQueue.Count > 0) while (disposalQueue.Count > 0)
{ {
Script^ script = disposalQueue.Dequeue(); Script^ script = disposalQueue.Dequeue();
script->OnDestroy(); if (Application::IsPlaying)
{
script->OnDestroy();
}
auto entity = script->Owner.GetEntity(); auto entity = script->Owner.GetEntity();
auto scriptList = scripts[script->Owner.GetEntity()]; auto scriptList = scripts[script->Owner.GetEntity()];
scriptList->Remove(script); scriptList->Remove(script);
@ -388,7 +392,7 @@ namespace SHADE
{ {
SAFE_NATIVE_CALL_BEGIN SAFE_NATIVE_CALL_BEGIN
// Run the deinit all scripts if needed // Run the deinit all scripts if needed
//if (Application::IsPlaying) if (Application::IsPlaying)
{ {
Debug::Log("Running OnDestroy() for scripts."); Debug::Log("Running OnDestroy() for scripts.");
for each (System::Collections::Generic::KeyValuePair<Entity, ScriptList^> entity in scripts) for each (System::Collections::Generic::KeyValuePair<Entity, ScriptList^> entity in scripts)