feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) + game logic (GameFix/GameDAL/ServerData) + network layer (NetWorkMessage) + data layer (ObjectModel) + utilities (MrWu/Core/Config/CloudAPI/dll) + adapters (zyxAdapter/base) .NET 8.0 C# solution, 16 projects, 958 source files
This commit is contained in:
30
Core/Core.csproj
Normal file
30
Core/Core.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<RootNamespace>Core</RootNamespace>
|
||||
<AssemblyName>Core</AssemblyName>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
39
Core/Pool/IReference.cs
Normal file
39
Core/Pool/IReference.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
namespace Server.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 引用池对象
|
||||
/// </summary>
|
||||
public interface IReference : IDisposable
|
||||
{
|
||||
bool IsFromPool
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
long ReferenceId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Reference : IReference
|
||||
{
|
||||
public bool IsFromPool
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public long ReferenceId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
59
Core/Pool/ReferencePool.Pool.cs
Normal file
59
Core/Pool/ReferencePool.Pool.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server.Core
|
||||
{
|
||||
public static partial class ReferencePool
|
||||
{
|
||||
private class Pool
|
||||
{
|
||||
private readonly Type objectType;
|
||||
|
||||
private readonly int MaxCapacity;
|
||||
|
||||
public int NumItems;
|
||||
|
||||
private readonly ConcurrentQueue<IReference> _items = new ConcurrentQueue<IReference>();
|
||||
|
||||
private IReference FastItem;
|
||||
|
||||
public Pool(Type objectType, int maxCapacity)
|
||||
{
|
||||
this.objectType = objectType;
|
||||
MaxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
public object Get()
|
||||
{
|
||||
IReference item = FastItem;
|
||||
if (item == null || Interlocked.CompareExchange(ref FastItem,null,item) != item)
|
||||
{
|
||||
if (_items.TryDequeue(out item))
|
||||
{
|
||||
Interlocked.Decrement(ref NumItems);
|
||||
return item;
|
||||
}
|
||||
|
||||
return Activator.CreateInstance(this.objectType);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Return(IReference obj)
|
||||
{
|
||||
if (FastItem != null || Interlocked.CompareExchange(ref FastItem,obj,null) != null)
|
||||
{
|
||||
if (Interlocked.Increment(ref NumItems) <= MaxCapacity)
|
||||
{
|
||||
_items.Enqueue(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
Interlocked.Decrement(ref NumItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Core/Pool/ReferencePool.cs
Normal file
91
Core/Pool/ReferencePool.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server.Core
|
||||
{
|
||||
public static partial class ReferencePool
|
||||
{
|
||||
private static ConcurrentDictionary<Type, Pool> objPool = new ConcurrentDictionary<Type, Pool>();
|
||||
|
||||
private static readonly Func<Type, Pool> AddPoolFunc = type => new Pool(type, 100);
|
||||
|
||||
public static T Fetch<T>(bool isFromPool = true) where T : IReference
|
||||
{
|
||||
return (T)Fetch(typeof(T),isFromPool);
|
||||
}
|
||||
|
||||
private static long refreshId = long.MinValue;
|
||||
|
||||
public static long GetRefreshId()
|
||||
{
|
||||
return Interlocked.Increment(ref refreshId);
|
||||
}
|
||||
|
||||
public static object Fetch(Type type, bool isFromPool = true)
|
||||
{
|
||||
if (!isFromPool)
|
||||
{
|
||||
return Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
//Debug.Log($"ReferencePool Fetch {type}");
|
||||
|
||||
Pool pool = GetPool(type);
|
||||
object obj = pool.Get();
|
||||
|
||||
if (obj is IReference p)
|
||||
{
|
||||
p.IsFromPool = true;
|
||||
p.ReferenceId = GetRefreshId();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void Recycle(IReference p)
|
||||
{
|
||||
if (!p.IsFromPool)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止多次入池
|
||||
p.IsFromPool = false;
|
||||
//p.Dispose();
|
||||
|
||||
Type type = p.GetType();
|
||||
//Debug.Log($"ReferencePool Recycle {type}");
|
||||
Pool pool = GetPool(type);
|
||||
pool.Return(p);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static Pool GetPool(Type type)
|
||||
{
|
||||
return objPool.GetOrAdd(type, AddPoolFunc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取对象池中的所有对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Type[] GetPoolTypes()
|
||||
{
|
||||
return objPool.Keys.ToArray();
|
||||
}
|
||||
|
||||
public static int GetPoolCnt(Type type)
|
||||
{
|
||||
Pool pool = GetPool(type);
|
||||
if (pool != null)
|
||||
{
|
||||
return pool.NumItems;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Core/Properties/AssemblyInfo.cs
Normal file
35
Core/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Core")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Core")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("300E6AE7-80E4-483A-A5F0-D43BA7630522")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user