-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGameEntry.cpp
More file actions
134 lines (113 loc) · 3.41 KB
/
Copy pathGameEntry.cpp
File metadata and controls
134 lines (113 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "EngineEntry.h"
#include <memory>
#include <iostream>
#include <clocale>
#include <filesystem>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#include "Application/Game.h"
#include "Application/ProjectSettings.h"
#include "Utils/CrashHandler.h"
#include "Utils/Logger.h"
#include "Utils/PathUtils.h"
#ifndef DLL_SEARCH_PATH
#define DLL_SEARCH_PATH "GameData"
#endif
namespace
{
void ConfigureWorkingDirectory(const char* executablePath)
{
if (!executablePath || executablePath[0] == '\0')
{
return;
}
std::filesystem::path inputPath(executablePath);
std::filesystem::path workingDir;
std::error_code ec;
if (std::filesystem::is_directory(inputPath, ec))
{
workingDir = inputPath;
}
else
{
workingDir = inputPath.parent_path();
}
if (!workingDir.empty())
{
std::error_code changeEc;
std::filesystem::current_path(workingDir, changeEc);
if (changeEc)
{
LogError("Failed to set working directory to '{}': {}", workingDir.string(), changeEc.message());
}
else
{
LogInfo("Working directory set to '{}'", workingDir.string());
}
}
}
}
static int GameEntryImpl(int argc, char* argv[], const char* executablePath)
{
std::unique_ptr<ApplicationBase> app;
ApplicationConfig config;
ProjectSettings::GetInstance().LoadInRuntime();
auto& settings = ProjectSettings::GetInstance();
PathUtils::Initialize(settings.GetAppName());
// 崩溃捕获与会话标记(运行时无恢复 UI,仅写 minidump 供玩家上报)
CrashHandler::Install(PathUtils::GetPersistentDataDir() / "CrashDumps");
CrashHandler::BeginSessionMarker(PathUtils::GetPersistentDataDir() / "game_session.lock");
#if defined(_WIN32) || defined(_WIN64)
if (!settings.IsConsoleEnabled())
{
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
::FreeConsole();
}
#endif
config.title = settings.GetAppName();
config.StartSceneGuid = settings.GetStartScene();
config.width = settings.GetTargetWidth();
config.height = settings.GetTargetHeight();
app = std::make_unique<Game>(config);
try
{
app->Run();
}
catch (const std::exception& e)
{
LogError("Application encountered a fatal error: {}", e.what());
#if defined(_WIN32) || defined(_WIN64)
MessageBoxA(NULL, e.what(), "Fatal Error", MB_OK | MB_ICONERROR);
#endif
return -1;
}
// 正常退出:清除会话标记
CrashHandler::EndSessionMarker();
return 0;
}
ENTRY_API int LumaEngine_Game_Entry(int argc, char* argv[], const char* currentExePath,
const char* androidPackageName)
{
#if defined(__ANDROID__)
PathUtils::InjectAndroidPackageName(androidPackageName ? androidPackageName : "");
#else
(void)androidPackageName;
#endif
std::string executablePath;
if (!currentExePath)
{
executablePath = GetExecutablePath();
}
else
{
executablePath = currentExePath;
}
ConfigureWorkingDirectory(executablePath.c_str());
LogInfo("Executable Path: {}", executablePath);
return GameEntryImpl(argc, argv, executablePath.c_str());
}