ParseEngineConfig.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. // Original file Copyright Crytek GMBH or its affiliates, used under license.
  13. #pragma once
  14. #include "ISystem.h"
  15. #include <AzCore/base.h>
  16. #include <AzCore/IO/SystemFile.h>
  17. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  18. #include <AzCore/Utils/Utils.h>
  19. #include <AzFramework/Platform/PlatformDefaults.h>
  20. // any of the following tags can be present in the bootstrap.cfg
  21. // you can also prefix it with a platform.
  22. // so for example, you can specify remote_ip alone to specify it for all platforms
  23. // or you could specify android_remote_ip to change it for android only.
  24. // the instructions are executed in the order that they appear, so you can set the default
  25. // by using the non-platform-specific version, and then later on in the file you
  26. // can override specific platforms.
  27. #define CONFIG_KEY_FOR_REMOTEIP "remote_ip"
  28. #define CONFIG_KEY_FOR_REMOTEPORT "remote_port"
  29. #define CONFIG_KEY_FOR_GAMEFOLDER "sys_game_folder"
  30. #define CONFIG_KEY_FOR_REMOTEFILEIO "remote_filesystem"
  31. #define CONFIG_KEY_FOR_CONNECTTOREMOTE "connect_to_remote"
  32. #define CONFIG_KEY_WAIT_FOR_CONNECT "wait_for_connect"
  33. #define DEFAULT_GAMEDLL "EmptyTemplate"
  34. #define DEFAULT_GAMEFOLDER "EmptyTemplate"
  35. #define DEFAULT_REMOTEIP "127.0.0.1"
  36. #define DEFAULT_REMOTEPORT 45643
  37. #define CONFIG_KEY_FOR_ASSETS "assets"
  38. #define CONFIG_KEY_FOR_BRANCHTOKEN "assetProcessor_branch_token"
  39. //////////////////////////////////////////////////////////////////////////
  40. class CEngineConfig
  41. {
  42. public:
  43. string m_gameFolder; // folder only ("MyGame")
  44. string m_assetPlatform; // what platform folder assets are from if more than one is available or using VFS ("pc" / "es3")
  45. bool m_connectToRemote;
  46. bool m_remoteFileIO;
  47. bool m_waitForConnect;
  48. string m_remoteIP;
  49. int m_remotePort;
  50. string m_rootFolder; // The engine root folder
  51. string m_branchToken;
  52. CEngineConfig([[maybe_unused]] const char** sourcePaths = nullptr, [[maybe_unused]] size_t numSearchPaths = 0, [[maybe_unused]] size_t numLevelsUp = 3)
  53. : m_gameFolder(DEFAULT_GAMEFOLDER)
  54. , m_connectToRemote(false)
  55. , m_remoteFileIO(false)
  56. , m_remotePort(DEFAULT_REMOTEPORT)
  57. , m_waitForConnect(false)
  58. , m_remoteIP(DEFAULT_REMOTEIP)
  59. {
  60. m_assetPlatform = AzFramework::OSPlatformToDefaultAssetPlatform(AZ_TRAIT_OS_PLATFORM_CODENAME);
  61. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  62. {
  63. AZ::SettingsRegistryInterface::FixedValueString gameFolder;
  64. auto gameFolderKey = AZ::SettingsRegistryInterface::FixedValueString::format("%s/%s",
  65. AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey, CONFIG_KEY_FOR_GAMEFOLDER);
  66. if (settingsRegistry->Get(gameFolder, gameFolderKey))
  67. {
  68. m_gameFolder.assign(gameFolder.c_str(), gameFolder.size());
  69. }
  70. AZ::SettingsRegistryInterface::FixedValueString engineRoot;
  71. if (settingsRegistry->Get(engineRoot, AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder))
  72. {
  73. m_rootFolder.assign(engineRoot.c_str(), engineRoot.size());
  74. }
  75. }
  76. OnLoadSettings();
  77. }
  78. void CopyToStartupParams(SSystemInitParams& startupParams) const
  79. {
  80. startupParams.remoteFileIO = m_remoteFileIO;
  81. startupParams.remotePort = m_remotePort;
  82. startupParams.connectToRemote = m_connectToRemote;
  83. startupParams.waitForConnection = m_waitForConnect;
  84. azstrncpy(startupParams.remoteIP, sizeof(startupParams.remoteIP), m_remoteIP.c_str(), m_remoteIP.length() + 1); // +1 for the null terminator
  85. azstrncpy(startupParams.assetsPlatform, sizeof(startupParams.assetsPlatform), m_assetPlatform.c_str(), m_assetPlatform.length() + 1); // +1 for the null terminator
  86. azstrncpy(startupParams.rootPath, sizeof(startupParams.rootPath), m_rootFolder.c_str(), m_rootFolder.length() + 1); // +1 for the null terminator
  87. azstrncpy(startupParams.gameFolderName, sizeof(startupParams.gameFolderName), m_gameFolder.c_str(), m_gameFolder.length() + 1); // +1 for the null terminator
  88. azstrncpy(startupParams.branchToken, sizeof(startupParams.branchToken), m_branchToken.c_str(), m_branchToken.length() + 1); // +1 for the null terminator
  89. // compute assets path based on game folder name
  90. string gameFolderLower(m_gameFolder);
  91. gameFolderLower.MakeLower();
  92. azsnprintf(startupParams.assetsPath, sizeof(startupParams.assetsPath), "%s/%s", startupParams.rootPath, gameFolderLower.c_str());
  93. // compute where the cache should be located
  94. azsnprintf(startupParams.rootPathCache, sizeof(startupParams.rootPathCache), "%s/Cache/%s/%s", m_rootFolder.c_str(), m_gameFolder.c_str(), m_assetPlatform.c_str());
  95. azsnprintf(startupParams.assetsPathCache, sizeof(startupParams.assetsPathCache), "%s/%s", startupParams.rootPathCache, gameFolderLower.c_str());
  96. }
  97. protected:
  98. void OnLoadSettings()
  99. {
  100. auto settingsRegistry = AZ::SettingsRegistry::Get();
  101. if (settingsRegistry == nullptr)
  102. {
  103. AZ_Warning("ParseEngineConfig", false, "Attempting to load configuration data while SettingsRegistry does not exist");
  104. return;
  105. }
  106. AZ::SettingsRegistryInterface::FixedValueString settingsKeyPrefix = AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey;
  107. AZ::SettingsRegistryInterface::FixedValueString settingsValueString;
  108. AZ::s64 settingsValueInt{};
  109. if (AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueInt, settingsKeyPrefix, CONFIG_KEY_FOR_REMOTEFILEIO))
  110. {
  111. m_remoteFileIO = settingsValueInt != 0;
  112. }
  113. if (AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueInt, settingsKeyPrefix, CONFIG_KEY_WAIT_FOR_CONNECT))
  114. {
  115. m_waitForConnect = settingsValueInt != 0;
  116. }
  117. if (AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueInt, settingsKeyPrefix, CONFIG_KEY_FOR_CONNECTTOREMOTE))
  118. {
  119. m_connectToRemote = settingsValueInt != 0;
  120. }
  121. if (AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueInt, settingsKeyPrefix, CONFIG_KEY_FOR_REMOTEPORT))
  122. {
  123. m_remotePort = aznumeric_cast<AZ::u16>(settingsValueInt);
  124. }
  125. if (settingsValueString = {};
  126. AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueString, settingsKeyPrefix, CONFIG_KEY_FOR_REMOTEIP))
  127. {
  128. m_remoteIP.assign(settingsValueString.c_str(), settingsValueString.size());
  129. }
  130. if (settingsValueString = {};
  131. AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, settingsValueString, settingsKeyPrefix, CONFIG_KEY_FOR_ASSETS))
  132. {
  133. m_assetPlatform.assign(settingsValueString.c_str(), settingsValueString.size());
  134. }
  135. if (settingsValueString = {};
  136. settingsRegistry->Get(settingsValueString, settingsKeyPrefix + "/" + CONFIG_KEY_FOR_BRANCHTOKEN))
  137. {
  138. m_branchToken.assign(settingsValueString.c_str(), settingsValueString.size());
  139. }
  140. }
  141. };