Files
o3de/Code/Legacy/CrySystem/System.h
T
Artur K 56904d1799 Cry Legacy: the Lessening (#5961)
* Generic Cleanup

Removals:

* Unused cvars,member variables and defines
* Windows media center edition support routines
* CSystem - removed debug_GetCallStackRaw/GetRootWindowMessageHandler/
UnloadDLL/ShutdownModuleLibraries

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix CryMessageBox return values in Windows build

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove named selection group and a few smaller unused functionalities

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager export functionality + 2 deprecated functions

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove object legacy freeze/hide support from ObjectManager

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager duplicate name dection, as well as object renaming

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove ObjectManager serialization and selection callbacks

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - remove MoveObjects/HitTestObject/EndEditParams and related members/functions

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove a bunch of unused clone related functionality + misc

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - misc removals

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* ObjectManager - more removals

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused object selection/retrieval in ObjectManager and LoadObjects in ObjectLoader

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove unused material layers mask support

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More CBaseObject cleanups.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove SubObj functions and IMouseCreateCallback

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused procedural floor management, helper scale and tags.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject - remove more unused methods.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Removals in multiple places.

CBaseObject - unused `OBJTYPE_DUMMY` flag removed, member `IsSameClass`
CObjectArchive removed unused methods/members
CObjectManager removed unused `Update` method

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More removals

IDisplayViewport - HitTestLine/GetGridStep/setHitcontext/
GetConstructionPlane
Unused Cry_Matrix44 template specializations.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* O3DE.exe Project-Centric "Open Editor" fix (#5852)

* The O3DE.exe Open Editor button now attempts to open the Editor in the
build directory of the project being opened.

If their is no Editor within the build directory of the Project, it uses
the Editor.exe in the current O3DE.exe executable directory if it exists

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Engine .gitignore now ignores the build directory if placed in the
AutomatedTesting project

Previously it was just ignoring a `[Bb]uild` directory if it was
directly within the engine root.
This change matches the behavior of the project templates.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Renamed the ProjectUtils GetEditorDirectory function to
GetEditorExecutablePath

Added a platform specific implementation for retrieving the path to the
Editor executable in the GetEditorExectuablePath function.

It first attempts to locate the Editor via checking the project build
directory for an Editor executable before falling back to checking the
binary directory of the currently running O3DE executable.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Correct the MacOS GetEditorExecutablePath to return the Editor path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Adding missing C++20 std::erase implementations (#5735)

There were already implementations for std::erase_if.
This adds the counterpart AZStd::erase versions

resolves #5734

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* More removals and refactors

`ShowMessage` and `CryMessageBox` return void now
Simplify code in `CSystem::WarningV`
Remove unused `CryGetTicksPerSec`
Remove unused WinBase functionality
Replace `nanosleep` call in WinBase with `std::this_thread::sleep_for`
Remove unused Win32Wrapper routines
Remove unused IFunctorBase.h and IEntityObjectListener.h
Fix VectorAndArray.cpp compilation
Use QMessageBox instead of CryMessageBox in the editor.
Remove empty ArchiveVars platform specific files

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Fix test code.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove an unused  function

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* CBaseObject and undo description removals.

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* A bunch of removals

* Remove IRenderNode
* Remove editor's KDTree
* Remove StatObjBus, InstanceStatObjEventBus::ReleaseData is redundant (
same functionality in the only available handler is triggered by
`OnCryEditorCloseScene`)
* Remove CExportManager::AddStatObj/AddMeshes/AddMesh,
IExportManager::ExportSingleStatObj
* Remove CIconManager/IIconManager::GetObject
* Remove CBaseObject::IntersectRayMesh
* Remove IIndexedMesh and related structs.
* Unused IUndoObject::GetDescription and all derived implementations.
* Unused CUndoBaseLibrary/CUndoBaseLibraryManager
* Unused Matrix34_tpl typedefs
* Legacy Xml classes cleanup

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* Remove unused `Vec3ToVector3D` helper

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

* fix - remove unused static variable

Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-11-29 11:21:06 -07:00

491 lines
16 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <ISystem.h>
#include <IRenderer.h>
#include <IWindowMessageHandler.h>
#include <CryVersion.h>
#include "CmdLine.h"
#include <AzFramework/Archive/ArchiveVars.h>
#include <LoadScreenBus.h>
#include <AzCore/Module/DynamicModuleHandle.h>
#include <AzCore/Math/Crc.h>
#include <CryCommon/TimeValue.h>
#include <list>
#include <map>
namespace AzFramework
{
class MissingAssetLogger;
}
struct IConsoleCmdArgs;
struct ICVar;
struct IFFont;
class CWatchdogThread;
#if defined(AZ_RESTRICTED_PLATFORM)
#undef AZ_RESTRICTED_SECTION
#define SYSTEM_H_SECTION_1 1
#define SYSTEM_H_SECTION_2 2
#define SYSTEM_H_SECTION_3 3
#define SYSTEM_H_SECTION_4 4
#endif
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION SYSTEM_H_SECTION_1
#include AZ_RESTRICTED_FILE(System_h)
#else
#if defined(WIN32) || defined(LINUX) || defined(APPLE)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_ALLOW_CREATE_BACKUP_LOG_FILE 1
#endif
//////////////////////////////////////////////////////////////////////////
#if defined(WIN32) || defined(APPLE) || defined(LINUX)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_DO_PREASSERT 1
#endif
#if defined(LINUX) || defined(APPLE)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_FORWARD_EXCEPTION_POINTERS 1
#endif
#if !defined(_WIN32)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_DEBUGCALLSTACK_SINGLETON 1
#endif
#if !defined(LINUX) && !defined(APPLE)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_DEBUGCALLSTACK_TRANSLATE 1
#endif
#if !defined(LINUX) && !defined(APPLE)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_DEBUGCALLSTACK_APPEND_MODULENAME 1
#endif
#if 1
#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_EXCLUDEUPDATE_ON_CONSOLE 0
#endif
#if defined(WIN32)
#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_MESSAGE_HANDLER 1
#endif
//////////////////////////////////////////////////////////////////////////
#endif
#ifdef WIN32
using WIN_HMODULE = void*;
#else
typedef void* WIN_HMODULE;
#endif
//forward declarations
namespace Audio
{
struct IAudioSystem;
struct IMusicSystem;
} // namespace Audio
#define PHSYICS_OBJECT_ENTITY 0
struct SSystemCVars
{
ICVar* sys_localization_folder;
int sys_float_exceptions;
int sys_no_crash_dialog;
int sys_no_error_report_window;
int sys_dump_aux_threads;
int sys_WER;
int sys_dump_type;
int sys_trackview;
float sys_update_profile_time;
int sys_MaxFPS;
float sys_maxTimeStepForMovieSystem;
int sys_report_files_not_found_in_paks = 0;
int sys_asserts;
int sys_error_debugbreak;
AZ::IO::ArchiveVars archiveVars;
};
extern SSystemCVars g_cvars;
class CSystem;
class AssetSystem;
/*
===========================================
The System interface Class
===========================================
*/
class CXConsole;
//////////////////////////////////////////////////////////////////////
//! ISystem implementation
class CSystem
: public ISystem
, public ILoadConfigurationEntrySink
, public ISystemEventListener
, public IWindowMessageHandler
, public CrySystemRequestBus::Handler
{
public:
CSystem(SharedEnvironmentInstance* pSharedEnvironment);
~CSystem();
static void OnLanguageCVarChanged(ICVar* language);
static void OnLocalizationFolderCVarChanged(ICVar* const pLocalizationFolder);
// adding CVAR to toggle assert verbosity level
static void OnAssertLevelCvarChanged(ICVar* pArgs);
static void SetAssertLevel(int _assertlevel);
static void OnLogLevelCvarChanged(ICVar* pArgs);
static void SetLogLevel(int _logLevel);
// interface ILoadConfigurationEntrySink ----------------------------------
void OnLoadConfigurationEntry(const char* szKey, const char* szValue, const char* szGroup) override;
// ISystemEventListener
void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override;
///////////////////////////////////////////////////////////////////////////
//! @name ISystem implementation
//@{
virtual bool Init(const SSystemInitParams& startupParams);
void Release() override;
SSystemGlobalEnvironment* GetGlobalEnvironment() override { return &m_env; }
bool UpdatePreTickBus(int updateFlags = 0, int nPauseMode = 0) override;
bool UpdatePostTickBus(int updateFlags = 0, int nPauseMode = 0) override;
bool UpdateLoadtime() override;
////////////////////////////////////////////////////////////////////////
// CrySystemRequestBus interface implementation
ISystem* GetCrySystem() override;
////////////////////////////////////////////////////////////////////////
void Relaunch(bool bRelaunch) override;
bool IsRelaunch() const override { return m_bRelaunch; };
void SerializingFile(int mode) override { m_iLoadingMode = mode; }
int IsSerializingFile() const override { return m_iLoadingMode; }
void Quit() override;
bool IsQuitting() const override;
void ShutdownFileSystem(); // used to cleanup any file resources, such as cache handle.
const char* GetUserName() override;
int GetApplicationInstance() override;
int GetApplicationLogInstance(const char* logFilePath) override;
AZ::IO::IArchive* GetIPak() override { return m_env.pCryPak; };
IConsole* GetIConsole() override { return m_env.pConsole; };
IRemoteConsole* GetIRemoteConsole() override;
IMovieSystem* GetIMovieSystem() override { return m_env.pMovieSystem; };
ICryFont* GetICryFont() override{ return m_env.pCryFont; }
ILog* GetILog() override{ return m_env.pLog; }
ICmdLine* GetICmdLine() override{ return m_pCmdLine; }
ILevelSystem* GetILevelSystem() override;
ISystemEventDispatcher* GetISystemEventDispatcher() override { return m_pSystemEventDispatcher; }
//////////////////////////////////////////////////////////////////////////
// retrieves the perlin noise singleton instance
CPNoise3* GetNoiseGen() override;
void DetectGameFolderAccessRights();
void ExecuteCommandLine(bool deferred=true) override;
void GetUpdateStats(SSystemUpdateStats& stats) override;
//////////////////////////////////////////////////////////////////////////
XmlNodeRef CreateXmlNode(const char* sNodeName = "", bool bReuseStrings = false, bool bIsProcessingInstruction = false) override;
XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false) override;
XmlNodeRef LoadXmlFromBuffer(const char* buffer, size_t size, bool bReuseStrings = false, bool bSuppressWarnings = false) override;
IXmlUtils* GetXmlUtils() override;
//////////////////////////////////////////////////////////////////////////
void IgnoreUpdates(bool bIgnore) override { m_bIgnoreUpdates = bIgnore; };
bool IsTestMode() const override { return m_bTestMode; }
//@}
void SleepIfNeeded();
void FatalError(const char* format, ...) override PRINTF_PARAMS(2, 3);
void ReportBug(const char* format, ...) override PRINTF_PARAMS(2, 3);
// Validator Warning.
void WarningV(EValidatorModule module, EValidatorSeverity severity, int flags, const char* file, const char* format, va_list args) override;
void Warning(EValidatorModule module, EValidatorSeverity severity, int flags, const char* file, const char* format, ...) override;
void ShowMessage(const char* text, const char* caption, unsigned int uType) override;
bool CheckLogVerbosity(int verbosity) override;
//! Return pointer to user defined callback.
ISystemUserCallback* GetUserCallback() const { return m_pUserCallback; };
//////////////////////////////////////////////////////////////////////////
void SaveConfiguration() override;
void LoadConfiguration(const char* sFilename, ILoadConfigurationEntrySink* pSink = nullptr, bool warnIfMissing = true) override;
ESystemConfigPlatform GetConfigPlatform() const override;
void SetConfigPlatform(ESystemConfigPlatform platform) override;
//////////////////////////////////////////////////////////////////////////
bool IsPaused() const override { return m_bPaused; };
ILocalizationManager* GetLocalizationManager() override;
void debug_GetCallStack(const char** pFunctions, int& nCount) override;
void debug_LogCallStack(int nMaxFuncs = 32, int nFlags = 0) override;
public:
#if !defined(RELEASE)
void SetVersionInfo(const char* const szVersion);
#endif
#if defined(WIN32)
friend LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif
void RegisterWindowMessageHandler(IWindowMessageHandler* pHandler) override;
void UnregisterWindowMessageHandler(IWindowMessageHandler* pHandler) override;
// IWindowMessageHandler
#if defined(WIN32)
bool HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult) override;
#endif
// ~IWindowMessageHandler
private:
// Release all resources.
void ShutDown();
//! @name Initialization routines
//@{
bool InitConsole();
bool InitFileSystem();
bool InitFileSystem_LoadEngineFolders(const SSystemInitParams& initParams);
bool InitAudioSystem(const SSystemInitParams& initParams);
//@}
//////////////////////////////////////////////////////////////////////////
// Helper functions.
//////////////////////////////////////////////////////////////////////////
void CreateSystemVars();
void CreateAudioVars();
void QueryVersionInfo();
void LogVersion();
void LogBuildInfo();
void SetDevMode(bool bEnable);
#ifndef _RELEASE
static void SystemVersionChanged(ICVar* pCVar);
#endif // #ifndef _RELEASE
void UpdateAudioSystems();
void AddCVarGroupDirectory(const AZStd::string& sPath) override;
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION SYSTEM_H_SECTION_3
#include AZ_RESTRICTED_FILE(System_h)
#elif defined(WIN32)
bool GetWinGameFolder(char* szMyDocumentsPath, int maxPathSize);
#endif
public:
void EnableFloatExceptions(int type);
// interface ISystem -------------------------------------------
bool IsDevMode() const override { return m_bInDevMode; }
// -------------------------------------------------------------
//! attaches the given variable to the given container;
//! recreates the variable if necessary
ICVar* attachVariable (const char* szVarName, int* pContainer, const char* szComment, int dwFlags = 0);
const CTimeValue& GetLastTickTime() const { return m_lastTickTime; }
private: // ------------------------------------------------------
// System environment.
SSystemGlobalEnvironment m_env;
bool m_bInitializedSuccessfully; //!< true if the system completed all initialization steps
bool m_bRelaunch; //!< relaunching the app or not (true beforerelaunch)
int m_iLoadingMode; //!< Game is loading w/o changing context (0 not, 1 quickloading, 2 full loading)
bool m_bTestMode; //!< If running in testing mode.
bool m_bEditor; //!< If running in Editor.
bool m_bNoCrashDialog;
bool m_bNoErrorReportWindow;
bool m_bPreviewMode; //!< If running in Preview mode.
bool m_bDedicatedServer; //!< If running as Dedicated server.
bool m_bIgnoreUpdates; //!< When set to true will ignore Update and Render calls,
bool m_bInDevMode; //!< Set to true if was in dev mode.
bool m_bGameFolderWritable; //!< True when verified that current game folder have write access.
CTimeValue m_lastTickTime;
//! system event dispatcher
ISystemEventDispatcher* m_pSystemEventDispatcher;
//! System to manage levels.
ILevelSystem* m_pLevelSystem;
// XML Utils interface.
class CXmlUtils* m_pXMLUtils;
int m_iApplicationInstance;
//! to hold the values stored in system.cfg
//! because editor uses it's own values,
//! and then saves them to file, overwriting the user's resolution.
int m_iHeight;
int m_iWidth;
int m_iColorBits;
// System console variables.
//////////////////////////////////////////////////////////////////////////
#if AZ_LOADSCREENCOMPONENT_ENABLED
ICVar* m_game_load_screen_uicanvas_path;
ICVar* m_level_load_screen_uicanvas_path;
ICVar* m_game_load_screen_sequence_to_auto_play;
ICVar* m_level_load_screen_sequence_to_auto_play;
ICVar* m_game_load_screen_sequence_fixed_fps;
ICVar* m_level_load_screen_sequence_fixed_fps;
ICVar* m_game_load_screen_max_fps;
ICVar* m_level_load_screen_max_fps;
ICVar* m_game_load_screen_minimum_time{};
ICVar* m_level_load_screen_minimum_time{};
#endif // if AZ_LOADSCREENCOMPONENT_ENABLED
ICVar* m_sysNoUpdate;
ICVar* m_svDedicatedMaxRate;
ICVar* m_sys_firstlaunch;
ICVar* m_sys_load_files_to_memory;
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION SYSTEM_H_SECTION_4
#include AZ_RESTRICTED_FILE(System_h)
#endif
ICVar* m_sys_audio_disable;
ICVar* m_gpu_particle_physics;
AZStd::string m_sSavedRDriver; //!< to restore the driver when quitting the dedicated server
//////////////////////////////////////////////////////////////////////////
//! User define callback for system events.
ISystemUserCallback* m_pUserCallback;
SFileVersion m_fileVersion;
SFileVersion m_productVersion;
SFileVersion m_buildVersion;
class CLocalizedStringsManager* m_pLocalizationManager;
ESystemConfigPlatform m_ConfigPlatform;
// Pause mode.
bool m_bPaused;
bool m_bNoUpdate;
bool m_executedCommandLine = false;
AZStd::unique_ptr<AzFramework::MissingAssetLogger> m_missingAssetLogger;
public:
//////////////////////////////////////////////////////////////////////////
// File version.
//////////////////////////////////////////////////////////////////////////
const SFileVersion& GetFileVersion() override;
const SFileVersion& GetProductVersion() override;
const SFileVersion& GetBuildVersion() override;
void OpenPlatformPaks();
void OpenLanguagePak(const char* sLanguage);
void OpenLanguageAudioPak(const char* sLanguage);
void GetLocalizedPath(const char* sLanguage, AZStd::string& sLocalizedPath);
void GetLocalizedAudioPath(const char* sLanguage, AZStd::string& sLocalizedPath);
void CloseLanguagePak(const char* sLanguage);
void CloseLanguageAudioPak(const char* sLanguage);
void UpdateMovieSystem(const int updateFlags, const float fFrameTime, const bool bPreUpdate);
//////////////////////////////////////////////////////////////////////////
// CryAssert and error related.
bool RegisterErrorObserver(IErrorObserver* errorObserver) override;
bool UnregisterErrorObserver(IErrorObserver* errorObserver) override;
void OnAssert(const char* condition, const char* message, const char* fileName, unsigned int fileLineNumber) override;
void OnFatalError(const char* message);
bool IsAssertDialogVisible() const override;
void SetAssertVisible(bool bAssertVisble) override;
//////////////////////////////////////////////////////////////////////////
void ClearErrorMessages() override
{
m_ErrorMessages.clear();
}
bool IsLoading()
{
return m_eRuntimeState == ESYSTEM_EVENT_LEVEL_LOAD_START_LOADINGSCREEN;
}
ESystemGlobalState GetSystemGlobalState() override;
void SetSystemGlobalState(ESystemGlobalState systemGlobalState) override;
#if !defined(_RELEASE)
bool IsSavingResourceList() const override { return (g_cvars.archiveVars.nSaveLevelResourceList != 0); }
#endif
private:
std::vector<IErrorObserver*> m_errorObservers;
ESystemGlobalState m_systemGlobalState;
static const char* GetSystemGlobalStateName(const ESystemGlobalState systemGlobalState);
public:
void InitLocalization();
protected: // -------------------------------------------------------------
CCmdLine* m_pCmdLine;
AZStd::string m_currentLanguageAudio;
AZStd::string m_systemConfigName; // computed from system_(hardwareplatform)_(assetsPlatform) - eg, system_android_android.cfg or system_windows_pc.cfg
std::vector< std::pair<CTimeValue, float> > m_updateTimes;
struct SErrorMessage
{
AZStd::string m_Message;
float m_fTimeToShow;
float m_Color[4];
bool m_HardFailure;
};
using TErrorMessages = std::list<SErrorMessage>;
TErrorMessages m_ErrorMessages;
bool m_bHasRenderedErrorMessage;
ESystemEvent m_eRuntimeState;
bool m_bIsAsserting;
std::vector<IWindowMessageHandler*> m_windowMessageHandlers;
bool m_initedOSAllocator = false;
bool m_initedSysAllocator = false;
};