更新最新框架
This commit is contained in:
@@ -1,33 +1,32 @@
|
||||
using Fantasy;
|
||||
using Fantasy.ConfigTable;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.IdFactory;
|
||||
using Fantasy.Platform.Net;
|
||||
// ================================================================================
|
||||
// Fantasy.Net 服务器应用程序入口
|
||||
// ================================================================================
|
||||
// 本文件是 Fantasy.Net 分布式游戏服务器的主入口点
|
||||
//
|
||||
// 初始化流程:
|
||||
// 1. 强制加载引用程序集,触发 ModuleInitializer 执行
|
||||
// 2. 配置日志基础设施(NLog)
|
||||
// 3. 启动 Fantasy.Net 框架
|
||||
// ================================================================================
|
||||
|
||||
using Fantasy;
|
||||
using NBF.ConfigTable;
|
||||
|
||||
|
||||
// 设置ID生成规则
|
||||
IdFactoryHelper.Initialize(IdFactoryType.World);
|
||||
// // 获取配置文件
|
||||
// // 比如通过远程获取这个配置文件,这样可以多组服务器共享一套配置了
|
||||
// var machineConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/MachineConfigData.Json");
|
||||
// var processConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/ProcessConfigData.Json");
|
||||
// var worldConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/WorldConfigData.Json");
|
||||
// var sceneConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/Server/SceneConfigData.Json");
|
||||
// // 初始化配置文件
|
||||
// // 如果重复初始化方法会覆盖掉上一次的数据,非常适合热重载时使用
|
||||
// MachineConfigData.Initialize(machineConfigText);
|
||||
// ProcessConfigData.Initialize(processConfigText);
|
||||
// WorldConfigData.Initialize(worldConfigText);
|
||||
// SceneConfigData.Initialize(sceneConfigText);
|
||||
|
||||
//解析配置文件
|
||||
var gameConfigText = await FileHelper.GetTextByRelativePath("../../../Config/Json/configs.Json");
|
||||
ConfigTableHelper.Initialize(gameConfigText,NB.AssemblyHelper.Assemblies);
|
||||
|
||||
// 注册日志模块到框架
|
||||
// 开发者可以自己注册日志系统到框架,只要实现Fantasy.ILog接口就可以。
|
||||
// 这里用的是NLog日志系统注册到框架中。
|
||||
Log.Register(new Fantasy.NLog("Server"));
|
||||
|
||||
await Entry.Start(NB.AssemblyHelper.Assemblies);
|
||||
try
|
||||
{
|
||||
// 初始化引用的程序集,确保 ModuleInitializer 执行
|
||||
// .NET 采用延迟加载机制 - 仅当类型被引用时才加载程序集
|
||||
// 通过访问 AssemblyMarker 强制加载程序集并调用 ModuleInitializer
|
||||
// 注意:Native AOT 不存在延迟加载问题,所有程序集在编译时打包
|
||||
AssemblyHelper.Initialize();
|
||||
ConfigTableHelper.Initialize();
|
||||
// 配置 NLog 日志基础设施
|
||||
var logger = new Fantasy.NLog("Server");
|
||||
// 使用 NLog 日志系统启动 Fantasy.Net 框架
|
||||
await Fantasy.Platform.Net.Entry.Start(logger);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"服务器初始化过程中发生致命错误:{ex}");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user