Launcher.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/PlatformDef.h> // for AZ_COMMAND_LINE_LEN
  10. #include <AzCore/Debug/Trace.h>
  11. #include <AzCore/IO/SystemFile.h>
  12. #include <AzCore/Memory/Memory.h>
  13. #include <CryCommon/platform.h>
  14. struct IOutputPrintSink;
  15. #define COMMAND_LINE_ARG_COUNT_LIMIT (AZ_COMMAND_LINE_LEN+1) / 2 // Assume that the limit to how many arguments we can maintain is the max buffer size divided by 2
  16. // to account for an argument and a spec in between each argument (with the worse case scenario being
  17. namespace O3DELauncher
  18. {
  19. struct PlatformMainInfo
  20. {
  21. typedef bool (*ResourceLimitUpdater)();
  22. typedef void (*OnPostApplicationStart)();
  23. PlatformMainInfo() = default;
  24. //! Copy the command line into a buffer as is or reconstruct a
  25. //! quoted version of the command line from the arg c/v. The
  26. //! internal buffer is fixed to \ref AZ_COMMAND_LINE_LEN meaning
  27. //! this call can fail if the command line exceeds that length
  28. bool CopyCommandLine(int argc, char** argv);
  29. bool AddArgument(const char* arg);
  30. char m_commandLine[AZ_COMMAND_LINE_LEN] = { 0 };
  31. size_t m_commandLineLen = 0;
  32. //! Keep static sized arrays to manage and provide the main arguments (argc, argv)
  33. char m_commandLineArgBuffer[AZ_COMMAND_LINE_LEN] = { 0 };
  34. size_t m_nextCommandLineArgInsertPoint = 0;
  35. int m_argC = 0;
  36. char* m_argV[COMMAND_LINE_ARG_COUNT_LIMIT] = { nullptr };
  37. ResourceLimitUpdater m_updateResourceLimits = nullptr; //!< callback for updating system resources, if necessary
  38. OnPostApplicationStart m_onPostAppStart = nullptr; //!< callback notifying the platform specific entry point that AzGameFramework::GameApplication::Start has been called
  39. const char* m_appResourcesPath = "."; //!< Path to the device specific assets, default is equivalent to blank path in ParseEngineConfig
  40. const char* m_appWriteStoragePath = nullptr; //!< Path to writeable storage if different than assets path, used to override userPath and logPath
  41. const char* m_additionalVfsResolution = nullptr; //!< additional things to check if VFS is not working for the desired platform
  42. void* m_window = nullptr; //!< maps to \ref SSystemInitParams::hWnd
  43. void* m_instance = nullptr; //!< maps to \ref SSystemInitParams::hInstance
  44. IOutputPrintSink* m_printSink = nullptr; //!< maps to \ref SSystemInitParams::pPrintSync
  45. };
  46. enum class ReturnCode : unsigned char
  47. {
  48. Success = 0,
  49. ErrExePath, //!< Failed to get the executable path
  50. ErrCommandLine, //!< Failed to copy the command line
  51. ErrValidation, //!< Failed to validate secret
  52. ErrResourceLimit, //!< Failed to increase unix resource limits
  53. ErrAppDescriptor, //!< Failed to locate the application descriptor file
  54. ErrCrySystemLib, //!< Failed to load required CrySystem library
  55. ErrCrySystemInterface, //!< Failed to create the CrySystem interface
  56. ErrCryEnvironment, //!< Failed to initialize the CryEngine environment
  57. ErrAssetProccessor, //!< Failed to connect to the asset processor
  58. ErrUnitTestFailure, //!< In Unit Test mode, one or more of the unit tests failed.
  59. ErrUnitTestNotSupported,//!< In Unit Test mode is not supported in its current configuration
  60. };
  61. const char* GetReturnCodeString(ReturnCode code);
  62. //! The main entry point for all O3DE launchers
  63. ReturnCode Run(const PlatformMainInfo& mainInfo = PlatformMainInfo());
  64. //////////////////////////////////////////////////////////////////////////
  65. // The following functions are defined by launcher project
  66. //////////////////////////////////////////////////////////////////////////
  67. //! This function returns the name of the project
  68. AZStd::string_view GetProjectName();
  69. //! This function returns the path of the project as known by the build system
  70. AZStd::string_view GetProjectPath();
  71. //! This function returns the build system target name
  72. AZStd::string_view GetBuildTargetName();
  73. //! This function returns whether its the Generic launcher or not (for Script-Only mode)
  74. bool IsGenericLauncher();
  75. //////////////////////////////////////////////////////////////////////////
  76. // The following functions are defined per launcher type (e.g. Client/Server/Unified)
  77. //////////////////////////////////////////////////////////////////////////
  78. //! Indicates if it should wait for a connection to the AssetProcessor (will attempt to open it if true)
  79. bool WaitForAssetProcessorConnect();
  80. //! Indicates if it is a dedicated server
  81. bool IsDedicatedServer();
  82. //! Gets the name of the log file to use
  83. const char* GetLogFilename();
  84. //! Returns the SettingsRegistry specialization tag
  85. //! that can be used to load settings for the specific launcher
  86. const char* GetLauncherTypeSpecialization();
  87. }