Skip to content

Commit 2e9e9e2

Browse files
committed
refactor(GameApp): 优化服务器启动任务管理逻辑
将并发任务列表改为单一任务变量,简化启动流程 移除冗余代码并优化服务器类型匹配逻辑
1 parent d8be2ac commit 2e9e9e2

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

GameFrameX.StartUp/GameApp.cs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,7 @@ public static class GameApp
7373
/// </remarks>
7474
private static readonly Dictionary<Type, StartUpTagAttribute> StartUpTypes = new();
7575

76-
/// <summary>
77-
/// List of startup tasks for concurrent execution / 用于并发执行的启动任务列表
78-
/// </summary>
79-
/// <remarks>
80-
/// 此列表包含所有启动任务,用于并发启动多个服务器实例,
81-
/// 通过Task.WhenAll等待所有任务完成。
82-
/// </remarks>
83-
private static readonly List<Task> AppStartUpTasks = new List<Task>();
84-
// private static readonly List<IAppStartUp> AppStartUps = new();
76+
private static Task _launchTask;
8577

8678
/// <summary>
8779
/// Main entry point for starting the game application / 启动游戏应用程序的主入口点
@@ -228,7 +220,7 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
228220

229221
var sortedStartUpTypes = StartUpTypes.OrderBy(m => m.Value.Priority);
230222

231-
LogHelper.InfoConsole("----------------------------Start Starting The Server------------------------------");
223+
232224
var appSettings = GlobalSettings.GetSettings();
233225
if (serverType.IsNotNullOrWhiteSpace())
234226
{
@@ -253,32 +245,24 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
253245
{
254246
foreach (var keyValuePair in sortedStartUpTypes)
255247
{
256-
var isFind = false;
257-
258-
foreach (var appSetting in appSettings)
259-
{
260-
if (keyValuePair.Value.ServerType == appSetting.ServerType)
261-
{
262-
Launcher(args, keyValuePair, appSetting);
263-
isFind = true;
264-
break;
265-
}
266-
}
267-
268-
if (isFind == false)
248+
var appSetting = appSettings.FirstOrDefault(appSetting => keyValuePair.Value.ServerType == appSetting.ServerType);
249+
if (appSetting != null)
269250
{
270-
LogHelper.Warning($"If no startup configuration is found for the server type, it will start with the default configuration=>{keyValuePair.Value.ServerType}");
271-
Launcher(args, keyValuePair);
251+
Launcher(args, keyValuePair, appSetting);
272252
break;
273253
}
254+
255+
LogHelper.Warning($"If no startup configuration is found for the server type, it will start with the default configuration=>{keyValuePair.Value.ServerType}");
256+
Launcher(args, keyValuePair);
257+
break;
274258
}
275259
}
276260

277261
LogHelper.Info($"----------------------------The Startup Server Is Over------------------------------");
278-
// ApplicationPerformanceMonitorStart(serverType);
262+
279263
ConsoleHelper.ConsoleLogo();
280264

281-
await Task.WhenAll(AppStartUpTasks);
265+
await _launchTask;
282266
}
283267

284268
/// <summary>
@@ -293,9 +277,7 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
293277
/// </remarks>
294278
private static void Launcher(string[] args, KeyValuePair<Type, StartUpTagAttribute> keyValuePair, AppSetting appSetting = null)
295279
{
296-
var task = Start(args, keyValuePair.Key, keyValuePair.Value.ServerType, appSetting);
297-
// AppStartUps.Add(startUp);
298-
AppStartUpTasks.Add(task);
280+
_launchTask = Start(args, keyValuePair.Key, keyValuePair.Value.ServerType, appSetting);
299281
}
300282

301283
/// <summary>

0 commit comments

Comments
 (0)