Added WIP Application class and adjustments to how ScriptStore destroys scripts (SpdLog errors)
This commit is contained in:
parent
18093433fa
commit
5eaf2b55aa
|
@ -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:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -260,7 +260,7 @@ namespace SHADE
|
||||||
return wndHWND;
|
return wndHWND;
|
||||||
}
|
}
|
||||||
|
|
||||||
const WindowData SHWindow::GetWindowData()
|
const WindowData SHWindow::GetWindowData() const
|
||||||
{
|
{
|
||||||
return wndData;
|
return wndData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
};
|
||||||
|
}
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -373,7 +374,10 @@ namespace SHADE
|
||||||
while (disposalQueue.Count > 0)
|
while (disposalQueue.Count > 0)
|
||||||
{
|
{
|
||||||
Script^ script = disposalQueue.Dequeue();
|
Script^ script = disposalQueue.Dequeue();
|
||||||
|
if (Application::IsPlaying)
|
||||||
|
{
|
||||||
script->OnDestroy();
|
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)
|
||||||
|
|
Loading…
Reference in New Issue