/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Data/Samples/RTS/CppSource/RTSGame/RTSGame.cpp
96 строк
3 KB
Jan Krassnigg
Cleanup of ezWindow infrastructure (#1685)
14 окт 2025, 19:16
Не верифицирован
14 окт 2025, 19:16
495a1fe
Код
Авторство
О чём код?
#include <RTSGame/RTSGame.h> #include <Core/Input/InputManager.h> #include <Foundation/Configuration/Startup.h> #include <Foundation/Logging/Log.h> // this injects the C++ main() function EZ_APPLICATION_ENTRY_POINT(RTSGame); RTSGame::RTSGame() : ezGameApplication("RTS", nullptr) { } ezResult RTSGame::TryProjectFolder(ezStringView sPath) { ezStringBuilder sProjDir = sPath; sProjDir.MakeCleanPath(); ezStringBuilder sProjFile; sProjFile.SetPath(sProjDir, "ezProject"); if (sProjFile.IsAbsolutePath() && ezOSFile::ExistsFile(sProjFile)) { m_sAppProjectPath = sProjDir; return EZ_SUCCESS; } return EZ_FAILURE; } void RTSGame::DetermineProjectPath() { // IMPORTANT! // // The project path has to be set for the ezGameApplication to know where the main 'project' data directory is. // Without it, nothing will work (the game plugin won't be loaded etc). // // The path can be relative to the '>SDK' directory (the root folder where EZ is located). // It may also be absolute (though this isn't portable across machines). // Or it can be relative to ezOSFile::GetApplicationDirectory() (where the Game.exe is). // // If your project is inside the EZ directory, use a relative path from there. // If it is somewhere outside, you either need to use an absolute path or some other way to locate it. // // Note that in a final exported build the project folder is always merged with the EZ data folders into one package. // this path works for exported projects, because during export the project folder is always copied there ezStringBuilder sProjDir; if (ezFileSystem::ResolveSpecialDirectory(">sdk/Data/project", sProjDir).Succeeded()) { if (TryProjectFolder(sProjDir).Succeeded()) return; } #ifdef GAME_PROJECT_FOLDER // this absolute path will only work on the machine where the game is compiled, // but it works for projects that are located outside the ezEngine folder if (TryProjectFolder(EZ_PP_STRINGIFY(GAME_PROJECT_FOLDER)).Succeeded()) return; #endif // in other cases, try this relative path m_sAppProjectPath = "Data/Samples/RTS"; } ezUniquePtr<ezGameStateBase> RTSGame::CreateGameState() { // usually we should only have a single non-fallback gamestate which is automatically picked // but if necessary, we can override this here return SUPER::CreateGameState(); } ezResult RTSGame::BeforeCoreSystemsStartup() { ezStartup::AddApplicationTag("game"); EZ_SUCCEED_OR_RETURN(SUPER::BeforeCoreSystemsStartup()); DetermineProjectPath(); return EZ_SUCCESS; } void RTSGame::AfterCoreSystemsStartup() { ExecuteInitFunctions(); ezStartup::StartupHighLevelSystems(); // we need a game state to do anything // if no custom game state is available, ezFallbackGameState will be used // the game state is also responsible for either creating a world, or loading it // the ezFallbackGameState inspects the command line to figure out which scene to load ActivateGameState(nullptr, {}, ezTransform::MakeIdentity()); }