├── Hive.Network.Tests ├── Usings.cs ├── Messages │ ├── HeartBeatMessage.cs │ ├── ReconnectMessage.cs │ ├── ClientCanTransmitMessage.cs │ ├── SignOutMessage.cs │ ├── SigninMessage.cs │ ├── CountTestMessage.cs │ ├── ServerBroadcastTestMessage.cs │ ├── ServerRedirectTestMessage2.cs │ ├── ServerRedirectTestMessage1.cs │ ├── ClientStartTransmitMessage.cs │ ├── ServerRegistrationMessage.cs │ └── BidirectionalPacket │ │ ├── C2STestPacket.cs │ │ └── S2CTestPacket.cs ├── ECS │ ├── TestSystem.cs │ ├── EntityTest.cs │ └── SystemManagerTest.cs └── ServiceProviderHelper.cs ├── Unity.Mathematics ├── Unity.Mathematics.TestProject │ ├── Assets │ │ └── Editor │ │ │ └── file │ └── ProjectSettings │ │ ├── ProjectVersion.txt │ │ ├── ClusterInputManager.asset │ │ ├── PresetManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── XRSettings.asset │ │ ├── TimeManager.asset │ │ ├── VFXManager.asset │ │ ├── AudioManager.asset │ │ ├── TagManager.asset │ │ ├── UnityConnectSettings.asset │ │ ├── EditorSettings.asset │ │ ├── DynamicsManager.asset │ │ ├── NavMeshAreas.asset │ │ └── Physics2DSettings.asset ├── src │ ├── ValidationExceptions.json │ ├── Unity.Mathematics │ │ ├── Unity.Mathematics.asmdef │ │ ├── PropertyAttributes.cs │ │ ├── Il2CppEagerStaticClassConstructionAttribute.cs │ │ ├── Noise │ │ │ ├── README │ │ │ └── LICENSE │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ ├── Tests │ │ ├── Unity.Mathematics.Tests.asmdef │ │ ├── TestCompilerAttribute.cs │ │ ├── packages.config │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ ├── Unity.Mathematics.Editor │ │ ├── Unity.Mathematics.Editor.asmdef │ │ └── QuaternionDrawer.cs │ ├── package.json │ ├── .npmignore │ ├── LICENSE.md │ ├── Unity.Mathematics.PerformanceTests │ │ ├── Unity.Mathematics.PerformanceTests.asmdef │ │ └── Properties │ │ │ └── AssemblyInfo.cs │ └── Unity.Mathematics.CodeGen~ │ │ └── Properties │ │ └── AssemblyInfo.cs ├── .gitattributes ├── LICENSE.md ├── .editorconfig └── Tools │ └── CI │ └── get_unity_launcher.py ├── Hive.Network.Abstractions ├── readme.md ├── Session │ ├── EventHandlers.cs │ ├── IConnector.cs │ ├── ISession.cs │ └── IAcceptor.cs ├── GatewayServer │ ├── ISecureStreamProvider.cs │ ├── ILoadBalancer.cs │ └── IGatewayServer.cs ├── EventArgs │ └── LoadBalancerInitializedEventArgs.cs ├── Hive.Network.Abstractions.csproj └── SessionId.cs ├── Hive.Server.App ├── IService.cs ├── ServiceAddress.cs ├── Program.cs ├── Hive.Server.App.csproj ├── TestService.cs └── ServiceManager.cs ├── Hive.Common.ECS ├── Events │ └── EntityCreate.cs ├── Entity │ ├── WorldEntity.cs │ ├── RootEntity.cs │ ├── IObjectEntity.cs │ ├── ObjectEntity.cs │ ├── IEntity.cs │ ├── PositionalEntity.cs │ └── Entity.cs ├── Component │ ├── IEntityComponent.cs │ └── RefAction.cs ├── IBelongECSArch.cs ├── System │ ├── Phases │ │ ├── IAwakeSystem.cs │ │ ├── IDestorySystem.cs │ │ ├── IFrameUpdateSystem.cs │ │ └── ILogicUpdateSystem.cs │ ├── ISystem.cs │ └── PhaseInterfaceType.cs ├── Compositor │ ├── ICompositor.cs │ └── AbstractCompositor.cs ├── ICanManageEntity.cs ├── IECSArch.cs ├── Attributes │ └── System │ │ ├── ExecuteAfter.cs │ │ └── ExecuteBefore.cs ├── EntityDepthComparer.cs ├── Hive.Common.ECS.csproj └── ECSArch.cs ├── Hive.Server.Actor ├── ActorService.cs ├── ActorRef.cs ├── ITestActorService.cs ├── ActorSystem.cs ├── Hive.Server.Actor.csproj └── Class1.cs ├── Hive.Application.Test ├── ClientServiceTest.cs ├── Hive.Application.Test.csproj ├── DummySession.cs └── ServiceProviderHelper.cs ├── Hive.Server.Cluster ├── RSC │ ├── ReflectionCaller.cs │ ├── ICodeGenRSCExecutor.cs │ ├── CodeGenExecutor.cs │ └── CodeGenCaller.cs ├── ServiceAgent.cs ├── Messages │ ├── ErrorCode.cs │ ├── ActorHeartBeat.cs │ ├── QueryService.cs │ └── NodeLoginReq.cs ├── NodeAgent.cs ├── CentralizedManagerServiceOptions.cs ├── CentralizedNodeServiceOptions.cs └── Hive.Server.Cluster.csproj ├── .gitmodules ├── Hive.Server.Common.Application ├── MessageHandlerAttribute.cs ├── TestApplication.cs ├── Hive.Server.Common.Application.csproj └── MessageHandlerBinderProvider.cs ├── Hive.Server.Shared ├── Messages │ ├── HostOffline.cs │ ├── HostHeartBeat.cs │ └── HostOnline.cs └── Hive.Server.Shared.csproj ├── Hive.Codec.Abstractions ├── ICustomCodecProvider.cs ├── IPacketCodec.cs ├── ICustomPacketCodec.cs ├── Hive.Codec.Abstractions.csproj ├── IPacketIdMapper.cs └── IPacketPrefixResolver.cs ├── .idea └── .idea.Hive.Framework │ └── .idea │ ├── encodings.xml │ ├── indexLayout.xml │ ├── vcs.xml │ └── .gitignore ├── Hive.Common.Shared ├── SyncOptions.cs ├── Helpers │ ├── BufferWriterExtensions.cs │ ├── ArraySegmentExtensions.cs │ ├── RandomHelper.cs │ ├── NetworkHelper.cs │ └── MemoryHelper.cs ├── Hive.Common.Shared.csproj ├── Attributes │ └── AbstractIgnoreExceptionAttribute.cs └── Collections │ ├── MultiDictionary.cs │ └── MultiHashSetDictionary.cs ├── Hive.Both.Messages ├── C2S │ └── CSHeartBeat.cs ├── S2C │ └── SCHeartBeat.cs └── Hive.Both.Messages.csproj ├── Hive.Server.Common.Application.Generator ├── AnalyzerReleases.Shipped.md ├── AnalyzerReleases.Unshipped.md └── Hive.Server.Common.Application.Generator.csproj ├── Directory.Build.props ├── Hive.Network.Quic ├── QuicNetworkSettings.cs ├── QuicAcceptorOptions.cs ├── QuicConnectorOptions.cs ├── Hive.Network.Quic.csproj └── QuicCertHelper.cs ├── Hive.Benchmark ├── Program.cs └── Hive.Benchmark.csproj ├── Hive.Server.Abstractions ├── IClusterNodeService.cs ├── IRemoteServiceCallExecutor.cs ├── IClientService.cs ├── IRemoteServiceCaller.cs ├── ClientHandle.cs ├── Hive.Server.Abstractions.csproj ├── ServiceAddress.cs ├── ServiceKey.cs ├── ClusterNodeId.cs ├── ClientId.cs └── ClusterNodeInfo.cs ├── Hive.Server.Default ├── Messages │ ├── HeartBeatMessage.cs │ ├── ReconnectMessage.cs │ ├── ClientCanTransmitMessage.cs │ ├── SigninMessage.cs │ ├── SignOutMessage.cs │ ├── CountTestMessage.cs │ ├── ServerBroadcastTestMessage.cs │ ├── ServerRedirectTestMessage2.cs │ ├── ServerRedirectTestMessage1.cs │ ├── ClientStartTransmitMessage.cs │ └── ServerRegistrationMessage.cs ├── ClientServiceOptions.cs ├── AppBuilder.cs └── Hive.Server.Default.csproj ├── Hive.Both.General ├── Dispatchers │ ├── DispatchHandler.cs │ ├── ResultContext.cs │ ├── MessageContext.cs │ ├── DispatcherExtensions.cs │ ├── IDispatcher.cs │ └── HandlerId.cs ├── Channels │ ├── MessageChannelExtensions.cs │ ├── IMessageChannel.cs │ ├── IServerMessageChannel.cs │ ├── MessageChannel.cs │ └── ServerMessageChannel.cs └── Hive.Both.General.csproj ├── Hive.DataSync.Shared ├── Attributes │ ├── SyncPropertyAttribute.cs │ ├── SyncObjectAttribute.cs │ ├── SyncOptionAttribute.cs │ ├── CustomSerializerAttribute.cs │ └── SetSyncIntervalAttribute.cs ├── Hive.DataSync.Shared.csproj └── ObjectSyncPacket │ ├── AbstractObjectSyncPacket.cs │ ├── UInt64SyncPacket.cs │ ├── CharSyncPacket.cs │ ├── Int32SyncPacket.cs │ ├── Int64SyncPacket.cs │ ├── Int16SyncPacket.cs │ ├── UInt32SyncPacket.cs │ ├── SingleSyncPacket.cs │ ├── BooleanSyncPacket.cs │ ├── DoubleSyncPacket.cs │ └── UInt16SyncPacket.cs ├── Hive.Network.Shared ├── SessionManagerOptions.cs ├── RecycleMemoryStreamManagerHolder.cs ├── Helpers │ ├── NetworkAddressHelper.cs │ └── SocketHelper.cs ├── NetworkSettings.cs ├── Hive.Network.Shared.csproj └── HandShake │ ├── HandShakePacket.cs │ └── SocketHandShaker.cs ├── Hive.Codec.Shared ├── DefaultCustomCodecProvider.cs ├── PacketIdMapperOptions.cs ├── MessageDefineAttribute.cs ├── Hive.Codec.Shared.csproj ├── Helpers │ └── TypeHashUtil.cs └── AbstractPacketCodec.cs ├── Hive.Framework.sln.DotSettings ├── Hive.DataSync.Abstractions ├── Interfaces │ ├── ISyncPacket.cs │ └── ISyncObject.cs ├── IDataSynchronizer.cs └── Hive.DataSync.Abstractions.csproj ├── Hive.Server.Common.Abstract ├── IServerApplication.cs ├── Hive.Server.Common.Abstract.csproj └── IServer.cs ├── Hive.Network.Udp ├── Hive.Network.Udp.csproj ├── UdpSession.cs └── UdpServerSession.cs ├── Hive.DataSync └── Hive.DataSync.csproj ├── Hive.Network.Tcp ├── Hive.Network.Tcp.csproj └── TcpConnector.cs ├── .github ├── dependabot.yml └── workflows │ └── dotnet.yml ├── Hive.DataSync.SourceGen.Tests ├── Hive.DataSync.SourceGen.Tests.csproj └── Class1.cs ├── Hive.Network.Kcp └── Hive.Network.Kcp.csproj ├── Hive.Codec.MemoryPack ├── Hive.Codec.MemoryPack.csproj └── MemoryPackPacketCodec.cs ├── Hive.DataSync.SourceGen ├── Hive.DataSync.SourceGen.csproj └── Helpers │ ├── TypeSymbolHelper.cs │ └── NamespaceHelper.cs ├── Hive.Codec.Bson ├── Hive.Codec.Bson.csproj └── BsonPacketCodec.cs ├── Hive.Codec.Protobuf ├── Hive.Codec.Protobuf.csproj └── ProtoBufPacketCodec.cs ├── LICENSE.txt └── README.md /Hive.Network.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using NUnit.Framework; -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/Assets/Editor/file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Hive.Network.Abstractions/readme.md: -------------------------------------------------------------------------------- 1 | 2 | Session 会话 3 | 4 | 转发如何实现 5 | -------------------------------------------------------------------------------- /Hive.Server.App/IService.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.App; 2 | 3 | public interface IService 4 | { 5 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Events/EntityCreate.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS.Events; 2 | 3 | public class EntityCreate 4 | { 5 | } -------------------------------------------------------------------------------- /Hive.Server.Actor/ActorService.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Actor; 2 | 3 | public class ActorService 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /Hive.Application.Test/ClientServiceTest.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Application.Test; 2 | 3 | public class ClientServiceTest 4 | { 5 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/ValidationExceptions.json: -------------------------------------------------------------------------------- 1 | { 2 | "ErrorExceptions": [ 3 | ], 4 | "WarningExceptions": [] 5 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/WorldEntity.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS.Entity; 2 | 3 | public sealed class WorldEntity : Entity 4 | { 5 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Component/IEntityComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS.Component; 2 | 3 | public interface IEntityComponent 4 | { 5 | } -------------------------------------------------------------------------------- /Hive.Server.App/ServiceAddress.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.App; 2 | 3 | public record struct ServiceAddress(int HostId, string ServiceName); -------------------------------------------------------------------------------- /Hive.Server.Cluster/RSC/ReflectionCaller.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Cluster.RSC; 2 | 3 | public class ReflectionCaller 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/Unity.Mathematics.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.Mathematics", 3 | "allowUnsafeCode": true 4 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/IBelongECSArch.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS; 2 | 3 | public interface IBelongToECSArch 4 | { 5 | IECSArch Arch { get; } 6 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/ServiceAgent.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | 3 | namespace Hive.Server.Cluster; 4 | 5 | public struct ServiceAgent 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Common/Unity.Mathematics"] 2 | path = Common/Unity.Mathematics 3 | url = https://github.com/Corona-Studio/Unity.Mathematics.git 4 | -------------------------------------------------------------------------------- /Hive.Server.Actor/ActorRef.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Actor; 2 | 3 | public class ActorRef 4 | { 5 | void Tell(T message) 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2019.3.0f6 2 | m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf) 3 | -------------------------------------------------------------------------------- /Hive.Server.Common.Application/MessageHandlerAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Common.Application; 2 | 3 | public class MessageHandlerAttribute : Attribute 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /Hive.Server.Shared/Messages/HostOffline.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | 3 | namespace Hive.Server.Shared.Messages; 4 | 5 | [MemoryPackable] 6 | public partial class HostOffline 7 | { 8 | } -------------------------------------------------------------------------------- /Hive.Server.Shared/Messages/HostHeartBeat.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | 3 | namespace Hive.Server.Shared.Messages; 4 | 5 | [MemoryPackable] 6 | public partial class HostHeartBeat 7 | { 8 | } -------------------------------------------------------------------------------- /Hive.Server.Actor/ITestActorService.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Actor; 2 | 3 | public interface ITestActorService 4 | { 5 | void UseCase(); 6 | 7 | Task TestRequest(int param); 8 | } -------------------------------------------------------------------------------- /Hive.Server.Actor/ActorSystem.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Actor; 2 | 3 | public class ActorSystem 4 | { 5 | T ActorOf(string actorRef = null) 6 | { 7 | return default; 8 | } 9 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/Messages/ErrorCode.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | 3 | namespace Hive.Server.Cluster.Messages; 4 | 5 | public enum ErrorCode 6 | { 7 | Ok = 0, 8 | NodeAlreadyExists = 10001, 9 | } -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/ICustomCodecProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Codec.Abstractions 2 | { 3 | public interface ICustomCodecProvider 4 | { 5 | ICustomPacketCodec? GetPacketCodec(PacketId id); 6 | } 7 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/System/Phases/IAwakeSystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.System.Phases; 4 | 5 | public interface IAwakeSystem : ISystem 6 | { 7 | void OnAwake(IEntity entity); 8 | } -------------------------------------------------------------------------------- /.idea/.idea.Hive.Framework/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Hive.Common.Shared/SyncOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.Shared 2 | { 3 | public enum SyncOptions 4 | { 5 | None, 6 | ClientOnly, 7 | ServerOnly, 8 | AllSession 9 | } 10 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/Session/EventHandlers.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | 3 | namespace Hive.Network.Abstractions.Session; 4 | 5 | public delegate void SessionReceivedHandler(ISession session, ReadOnlySequence buffer); -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /Hive.Both.Messages/C2S/CSHeartBeat.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Shared; 2 | using MemoryPack; 3 | 4 | namespace Hive.Both.Messages.C2S; 5 | 6 | [MessageDefine] 7 | [MemoryPackable] 8 | public partial class CSHeartBeat 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Both.Messages/S2C/SCHeartBeat.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Shared; 2 | using MemoryPack; 3 | 4 | namespace Hive.Both.Messages.S2C; 5 | 6 | [MessageDefine] 7 | [MemoryPackable] 8 | public partial class SCHeartBeat 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Compositor/ICompositor.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.Compositor; 4 | 5 | public interface ICompositor 6 | { 7 | public ObjectEntity Composite(long id, IEntity parent); 8 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/System/Phases/IDestorySystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.System.Phases; 4 | 5 | public interface IDestroySystem : ISystem 6 | { 7 | void OnDestroy(IEntity entity); 8 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/RSC/ICodeGenRSCExecutor.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Cluster.RSC; 2 | 3 | public interface ICodeGenRSCExecutor 4 | { 5 | void Execute(string methodName, Stream serializedArguments, Stream serializedResult); 6 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Application.Generator/AnalyzerReleases.Shipped.md: -------------------------------------------------------------------------------- 1 | ; Shipped analyzer releases 2 | ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md 3 | 4 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.25.4.15 4 | $(AssemblyVersion) 5 | $(AssemblyVersion) 6 | 7 | -------------------------------------------------------------------------------- /Hive.Common.ECS/System/Phases/IFrameUpdateSystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.System.Phases; 4 | 5 | public interface IFrameUpdateSystem : ISystem 6 | { 7 | void OnFrameUpdate(IEntity entity); 8 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/System/Phases/ILogicUpdateSystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.System.Phases; 4 | 5 | public interface ILogicUpdateSystem : ISystem 6 | { 7 | void OnLogicUpdate(IEntity entity); 8 | } -------------------------------------------------------------------------------- /Hive.Network.Quic/QuicNetworkSettings.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Network.Quic; 4 | 5 | public static class QuicNetworkSettings 6 | { 7 | public static readonly IPEndPoint FallBackEndPoint = new(IPAddress.Any, 0); 8 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/HeartBeatMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class HeartBeatMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ReconnectMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ReconnectMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Benchmark/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | 3 | namespace Hive.Benchmark; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | BenchmarkRunner.Run(); 10 | } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/GatewayServer/ISecureStreamProvider.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Hive.Network.Abstractions.GatewayServer; 4 | 5 | public interface ISecureStreamProvider 6 | { 7 | Stream GetSecuredStream(Stream stream); 8 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/IClusterNodeService.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public interface IClusterNodeService 4 | { 5 | ClusterNodeId NodeId { get; } 6 | 7 | ServiceAddress QueryService(ServiceKey serviceKey); 8 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/HeartBeatMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class HeartBeatMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ReconnectMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ReconnectMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/DispatchHandler.cs: -------------------------------------------------------------------------------- 1 | using Hive.Network.Abstractions.Session; 2 | 3 | namespace Hive.Both.General.Dispatchers 4 | { 5 | public delegate void DispatchHandler(IDispatcher dispatcher, ISession session, T message); 6 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/RootEntity.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS.Entity; 2 | 3 | public sealed class RootEntity : Entity 4 | { 5 | public RootEntity(IECSArch arch) 6 | { 7 | ECSArch = arch; 8 | Parent = null; 9 | } 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ClientCanTransmitMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ClientCanTransmitMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/NodeAgent.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Server.Cluster; 4 | 5 | public struct NodeAgent 6 | { 7 | public string NodeName; 8 | public IPEndPoint NodeEndPoint; 9 | public ServiceAgent[] Services; 10 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_DefaultPresets: {} 8 | -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Attributes/SyncPropertyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.DataSync.Shared.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Field)] 6 | public sealed class SyncPropertyAttribute : Attribute 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/Messages/ActorHeartBeat.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Shared; 2 | using MemoryPack; 3 | 4 | namespace Hive.Server.Cluster.Messages; 5 | 6 | [MemoryPackable] 7 | [MessageDefine] 8 | public partial class ActorHeartBeat 9 | { 10 | 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ClientCanTransmitMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ClientCanTransmitMessage 9 | { 10 | } -------------------------------------------------------------------------------- /Hive.Network.Shared/SessionManagerOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Network.Shared 4 | { 5 | public sealed class SessionManagerOptions 6 | { 7 | public IPEndPoint ListenEndPoint { get; set; } = new(IPAddress.Any, 0); 8 | } 9 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/CentralizedManagerServiceOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Cluster; 2 | 3 | public class CentralizedManagerServiceOptions 4 | { 5 | public string ListenAddress { get; set; } = "0.0.0.0"; 6 | public int ListenPort { get; set; } = 11452; 7 | } -------------------------------------------------------------------------------- /.idea/.idea.Hive.Framework/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/IObjectEntity.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Compositor; 2 | 3 | namespace Hive.Common.ECS.Entity; 4 | 5 | public interface IObjectEntity 6 | { 7 | public ICompositor Compositor { get; } 8 | 9 | public WorldEntity WorldEntity { get; } 10 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/IRemoteServiceCallExecutor.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public interface IRemoteServiceCallExecutor 4 | { 5 | void OnCall(ServiceAddress serviceAddress, string methodName, Stream serializedArguments, Stream serializedResult); 6 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | m_configObjects: {} 9 | -------------------------------------------------------------------------------- /Hive.Network.Shared/RecycleMemoryStreamManagerHolder.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IO; 2 | 3 | namespace Hive.Network.Shared 4 | { 5 | public static class RecycleMemoryStreamManagerHolder 6 | { 7 | public static RecyclableMemoryStreamManager Shared { get; } = new(); 8 | } 9 | } -------------------------------------------------------------------------------- /Unity.Mathematics/.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behavior to automatically normalize line endings. 2 | * text=auto 3 | 4 | # shell files should always be LF 5 | *.sh text eol=lf 6 | 7 | # Unity files 8 | *.asset text eol=lf 9 | *.meta text eol=lf 10 | *.asmdef text eol=lf 11 | -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/XRSettings.asset: -------------------------------------------------------------------------------- 1 | { 2 | "m_SettingKeys": [ 3 | "VR Device Disabled", 4 | "VR Device User Alert" 5 | ], 6 | "m_SettingValues": [ 7 | "False", 8 | "False" 9 | ] 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/SignOutMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class SignOutMessage 9 | { 10 | [ProtoMember(1)] public int Id { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/SigninMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class SigninMessage 9 | { 10 | [ProtoMember(1)] public int Id { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/ClientServiceOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Server.Default; 4 | 5 | public class ClientServiceOptions 6 | { 7 | public int HeartBeatTimeout { get; set; } = 10_000; 8 | public IPEndPoint EndPoint { get; set; } = new(IPAddress.Any, 0); 9 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/SigninMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class SigninMessage 9 | { 10 | [ProtoMember(1)] public int Id { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/SignOutMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class SignOutMessage 9 | { 10 | [ProtoMember(1)] public int Id { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/ObjectEntity.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Compositor; 2 | 3 | namespace Hive.Common.ECS.Entity; 4 | 5 | public class ObjectEntity : Entity, IObjectEntity 6 | { 7 | public ICompositor Compositor { get; init; } 8 | public WorldEntity? WorldEntity { get; internal set; } 9 | } -------------------------------------------------------------------------------- /Hive.Network.Quic/QuicAcceptorOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Quic; 2 | using System.Runtime.Versioning; 3 | 4 | namespace Hive.Network.Quic; 5 | 6 | [RequiresPreviewFeatures] 7 | public class QuicAcceptorOptions 8 | { 9 | public QuicListenerOptions? QuicListenerOptions { get; set; } 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/CountTestMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class CountTestMessage 9 | { 10 | [ProtoMember(1)] public int Adder { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/CountTestMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class CountTestMessage 9 | { 10 | [ProtoMember(1)] public int Adder { get; set; } 11 | } -------------------------------------------------------------------------------- /.idea/.idea.Hive.Framework/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Hive.Server.Abstractions/IClientService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Hosting; 2 | 3 | namespace Hive.Server.Abstractions; 4 | 5 | public interface IClientService : IHostedService 6 | { 7 | ClientHandle? GetClientHandle(ClientId clientId); 8 | 9 | void KickClient(ClientId clientId); 10 | } -------------------------------------------------------------------------------- /Hive.Server.Actor/Hive.Server.Actor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Hive.Codec.Shared/DefaultCustomCodecProvider.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Abstractions; 2 | 3 | namespace Hive.Codec.Shared; 4 | 5 | public class DefaultCustomCodecProvider : ICustomCodecProvider 6 | { 7 | public ICustomPacketCodec? GetPacketCodec(PacketId id) 8 | { 9 | return null; 10 | } 11 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/System/ISystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.System; 4 | 5 | public interface ISystem 6 | { 7 | bool EntityFilter(IEntity entity) 8 | { 9 | return true; 10 | } 11 | 12 | void Execute(IEntity entity) 13 | { 14 | } 15 | } -------------------------------------------------------------------------------- /Hive.Network.Quic/QuicConnectorOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Quic; 2 | using System.Runtime.Versioning; 3 | 4 | namespace Hive.Network.Quic; 5 | 6 | [RequiresPreviewFeatures] 7 | public class QuicConnectorOptions 8 | { 9 | public QuicClientConnectionOptions? ClientConnectionOptions { get; set; } 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ServerBroadcastTestMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerBroadcastTestMessage 9 | { 10 | [ProtoMember(1)] public int Number { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ServerRedirectTestMessage2.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRedirectTestMessage2 9 | { 10 | [ProtoMember(1)] public int Value { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/CentralizedNodeServiceOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Cluster; 2 | 3 | public class CentralizedNodeServiceOptions 4 | { 5 | public string ManagerAddress { get; set; } = "0.0.0.0"; 6 | public int ManagerPort { get; set; } = 11452; 7 | public int HeartBeatInterval { get; set; } = 1000; 8 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ServerBroadcastTestMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerBroadcastTestMessage 9 | { 10 | [ProtoMember(1)] public int Number { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ServerRedirectTestMessage2.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRedirectTestMessage2 9 | { 10 | [ProtoMember(1)] public int Value { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ServerRedirectTestMessage1.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRedirectTestMessage1 9 | { 10 | [ProtoMember(1)] public string? Content { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ServerRedirectTestMessage1.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRedirectTestMessage1 9 | { 10 | [ProtoMember(1)] public string? Content { get; set; } 11 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.33333334 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /Hive.Common.ECS/ICanManageEntity.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Compositor; 2 | using Hive.Common.ECS.Entity; 3 | 4 | namespace Hive.Common.ECS; 5 | 6 | public interface ICanManageEntity 7 | { 8 | void Instantiate(IEntity? parent = null) where TCompositor : ICompositor; 9 | void Destroy(IEntity entity); 10 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ClientStartTransmitMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ClientStartTransmitMessage 9 | { 10 | [ProtoMember(1)] public ushort[] RedirectPacketIds { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/ServerRegistrationMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRegistrationMessage 9 | { 10 | [ProtoMember(1)] public ushort[] PackagesToReceive { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ClientStartTransmitMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ClientStartTransmitMessage 9 | { 10 | [ProtoMember(1)] public ushort[] RedirectPacketIds { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Messages/ServerRegistrationMessage.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Server.Default.Messages; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class ServerRegistrationMessage 9 | { 10 | [ProtoMember(1)] public ushort[] PackagesToReceive { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/BidirectionalPacket/C2STestPacket.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages.BidirectionalPacket; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class C2STestPacket 9 | { 10 | [ProtoMember(1)] public int RandomNumber { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/Messages/BidirectionalPacket/S2CTestPacket.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | using ProtoBuf; 3 | 4 | namespace Hive.Network.Tests.Messages.BidirectionalPacket; 5 | 6 | [ProtoContract] 7 | [MemoryPackable] 8 | public partial class S2CTestPacket 9 | { 10 | [ProtoMember(1)] public int ReversedRandomNumber { get; set; } 11 | } -------------------------------------------------------------------------------- /Hive.Server.Shared/Messages/HostOnline.cs: -------------------------------------------------------------------------------- 1 | using MemoryPack; 2 | 3 | namespace Hive.Server.Shared.Messages; 4 | 5 | [MemoryPackable] 6 | public partial class HostOnline 7 | { 8 | public List Services = new(); 9 | } 10 | 11 | [MemoryPackable] 12 | public partial struct ServiceInfo 13 | { 14 | public string ServiceName; 15 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/IECSArch.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Component; 2 | using Hive.Common.ECS.Entity; 3 | using Hive.Common.ECS.System; 4 | 5 | namespace Hive.Common.ECS; 6 | 7 | public interface IECSArch 8 | { 9 | EntityManager EntityManager { get; } 10 | ComponentManager ComponentManager { get; } 11 | SystemManager SystemManager { get; } 12 | } -------------------------------------------------------------------------------- /Hive.Codec.Shared/PacketIdMapperOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hive.Codec.Shared; 5 | 6 | public class PacketIdMapperOptions 7 | { 8 | public HashSet RegisteredPackets { get; } = []; 9 | 10 | public void Register() 11 | { 12 | RegisteredPackets.Add(typeof(T)); 13 | } 14 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Tests/Unity.Mathematics.Tests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.Mathematics.Tests", 3 | "optionalUnityReferences": [ 4 | "TestAssemblies" 5 | ], 6 | "references": [ 7 | "Unity.Mathematics" 8 | ], 9 | "includePlatforms": [ 10 | "Editor" 11 | ], 12 | "allowUnsafeCode": true 13 | } 14 | -------------------------------------------------------------------------------- /Hive.Server.Cluster/RSC/CodeGenExecutor.cs: -------------------------------------------------------------------------------- 1 | using Hive.Server.Abstractions; 2 | 3 | namespace Hive.Server.Cluster.RSC; 4 | 5 | public class CodeGenExecutor : IRemoteServiceCallExecutor 6 | { 7 | public void OnCall(ServiceAddress serviceAddress, string methodName, Stream serializedArguments, Stream serializedResult) 8 | { 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics.Editor/Unity.Mathematics.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.Mathematics.Editor", 3 | "references": [ 4 | "Unity.Mathematics" 5 | ], 6 | "optionalUnityReferences": [], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": true 12 | } -------------------------------------------------------------------------------- /Hive.Server.Actor/Class1.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Actor; 2 | 3 | public class Class1 4 | { 5 | // ActorSystem _actorSystem = ActorSystem.Create("Hive"); 6 | // ActorRef _actorRef = _actorSystem.ActorOf("ActorRef"); 7 | // Call 8 | // _actorRef.Tell(new ActorMessage()); 9 | public void UseCase() 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/Session/IConnector.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace Hive.Network.Abstractions.Session; 6 | 7 | public interface IConnector where TSession : ISession 8 | { 9 | ValueTask ConnectAsync(IPEndPoint remoteEndPoint, CancellationToken token = default); 10 | } -------------------------------------------------------------------------------- /.idea/.idea.Hive.Framework/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /modules.xml 6 | /contentModel.xml 7 | /projectSettingsUpdater.xml 8 | /.idea.Hive.Framework.iml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/IPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | using System.IO; 3 | 4 | namespace Hive.Codec.Abstractions 5 | { 6 | /// 7 | /// 封包编解码器接口 8 | /// 9 | public interface IPacketCodec 10 | { 11 | int Encode(T message, Stream stream); 12 | object? Decode(ReadOnlySequence buffer); 13 | } 14 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/IRemoteServiceCaller.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public interface IRemoteServiceCaller 4 | { 5 | void Call(ServiceAddress serviceAddress, string methodName, Stream serializedArguments, Action serializedResult); 6 | 7 | Task CallAsync(ServiceAddress serviceAddress, string methodName, Stream serializedArguments); 8 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Helpers/BufferWriterExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | 4 | namespace Hive.Common.Shared.Helpers 5 | { 6 | public static class BufferWriterExtensions 7 | { 8 | public static void WriteGuid(this IBufferWriter writer, Guid val) 9 | { 10 | writer.Write(val.ToByteArray()); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Application.Generator/AnalyzerReleases.Unshipped.md: -------------------------------------------------------------------------------- 1 | ; Unshipped analyzer release 2 | ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md 3 | 4 | ### New Rules 5 | 6 | Rule ID | Category | Severity | Notes 7 | --------|----------|----------|------- 8 | Hive0001 | Hive | Error | AppMessageHandlerBinderGen -------------------------------------------------------------------------------- /Hive.Common.ECS/Attributes/System/ExecuteAfter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Common.ECS.Attributes.System; 4 | 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class ExecuteAfter : Attribute 7 | { 8 | public ExecuteAfter(Type systemType) 9 | { 10 | SystemType = systemType; 11 | } 12 | 13 | public Type SystemType { get; } 14 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Attributes/System/ExecuteBefore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Common.ECS.Attributes.System; 4 | 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class ExecuteBefore : Attribute 7 | { 8 | public ExecuteBefore(Type systemType) 9 | { 10 | SystemType = systemType; 11 | } 12 | 13 | public Type SystemType { get; } 14 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.unity.mathematics", 3 | "displayName": "Mathematics", 4 | "version": "1.3.0", 5 | "unity": "2018.3", 6 | "description": "Unity's C# SIMD math library providing vector types and math functions with a shader like syntax.", 7 | "keywords": [ 8 | "unity" 9 | ], 10 | "dependencies": { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace Hive.Common.ECS.Entity; 4 | 5 | public interface IEntity 6 | { 7 | IECSArch ECSArch { get; } 8 | string Name { get; set; } 9 | int Depth { get; } 10 | ReadOnlyCollection Children { get; } 11 | 12 | public IEntity Parent { get; set; } 13 | public long InstanceId { get; init; } 14 | } -------------------------------------------------------------------------------- /Hive.Framework.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True -------------------------------------------------------------------------------- /Hive.Network.Abstractions/GatewayServer/ILoadBalancer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Hive.Network.Abstractions.Session; 3 | 4 | namespace Hive.Network.Abstractions.GatewayServer; 5 | 6 | public interface ILoadBalancer 7 | { 8 | ISession Get(); 9 | IReadOnlyList GetAll(); 10 | 11 | void Add(ISession session); 12 | bool Remove(ISession session); 13 | 14 | void Clear(); 15 | } -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/ICustomPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.IO; 4 | 5 | namespace Hive.Codec.Abstractions 6 | { 7 | /// 8 | /// 自定义封包编解码器接口 9 | /// 10 | public interface ICustomPacketCodec 11 | { 12 | int EncodeBody(T message, Stream stream); 13 | 14 | object DecodeBody(ReadOnlySequence buffer, Type type); 15 | } 16 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Hive.DataSync.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | $(MSBuildProjectName.Replace(" ", "_")) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_StripUpdateShader: {fileID: 0} 10 | m_RenderPipeSettingsPath: 11 | m_FixedTimeStep: 0.016666668 12 | m_MaxDeltaTime: 0.05 13 | -------------------------------------------------------------------------------- /Hive.Codec.Shared/MessageDefineAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Codec.Shared; 4 | 5 | public class MessageDefineAttribute : Attribute 6 | { 7 | /// 8 | /// 消息类型定义 9 | /// 10 | public MessageDefineType Type { get; } 11 | } 12 | 13 | [Flags] 14 | public enum MessageDefineType : byte 15 | { 16 | ClientToServer, 17 | ServerToClient, 18 | ServerToServer, 19 | ClientToClient 20 | } -------------------------------------------------------------------------------- /Hive.DataSync.Abstractions/Interfaces/ISyncPacket.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.Shared; 2 | 3 | namespace Hive.DataSync.Abstractions.Interfaces 4 | { 5 | public interface ISyncPacket 6 | { 7 | string PropertyName { get; } 8 | ushort ObjectSyncId { get; } 9 | SyncOptions SyncOptions { get; } 10 | } 11 | 12 | public interface ISyncPacket : ISyncPacket 13 | { 14 | T NewValue { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Attributes/SyncObjectAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.DataSync.Shared.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public sealed class SyncObjectAttribute : Attribute 7 | { 8 | public SyncObjectAttribute(ushort objectSyncId) 9 | { 10 | ObjectSyncId = objectSyncId; 11 | } 12 | 13 | public ushort ObjectSyncId { get; } 14 | } 15 | } -------------------------------------------------------------------------------- /Hive.DataSync.Abstractions/Interfaces/ISyncObject.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hive.DataSync.Abstractions.Interfaces 4 | { 5 | public interface ISyncObject 6 | { 7 | ushort ObjectSyncId { get; } 8 | 9 | void PerformUpdate(ISyncPacket infoBase); 10 | IEnumerable GetPendingChanges(); 11 | void NotifyPropertyChanged(string propertyName, ISyncPacket syncPacket); 12 | } 13 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Abstract/IServerApplication.cs: -------------------------------------------------------------------------------- 1 | using Hive.Both.General.Dispatchers; 2 | using Hive.Network.Abstractions.Session; 3 | 4 | namespace Hive.Server.Common.Abstract; 5 | 6 | public interface IServerApplication 7 | { 8 | Task OnStartAsync(IAcceptor acceptor, IDispatcher dispatcher,CancellationToken stoppingToken); 9 | 10 | void OnSessionCreated(ISession session); 11 | 12 | void OnSessionClosed(ISession session); 13 | } -------------------------------------------------------------------------------- /Hive.Server.App/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace Hive.Server.App; 5 | 6 | public static class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | var builder = Host.CreateApplicationBuilder(args); 11 | builder.Services.AddHostedService(); 12 | var host = builder.Build(); 13 | host.Run(); 14 | } 15 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/.npmignore: -------------------------------------------------------------------------------- 1 | packages 2 | artifacts/** 3 | build/** 4 | Documentation/ApiDocs/** 5 | .DS_Store 6 | .npmrc 7 | .npmignore 8 | .gitignore 9 | QAReport.md 10 | QAReport.md.meta 11 | Unity.Mathematics.CodeGen* 12 | Unity.Mathematics.PerformanceTests* 13 | *.sln* 14 | *.db* 15 | **/*.csproj* 16 | **/packages.config* 17 | **/bin 18 | **/obj 19 | 20 | upm-ci~/** 21 | .Editor/** 22 | .yamato/** 23 | *.zip* 24 | TestRunnerOptions.json 25 | .idea/** -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/Hive.Codec.Abstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Hive.DataSync.Abstractions/IDataSynchronizer.cs: -------------------------------------------------------------------------------- 1 | using Hive.DataSync.Abstractions.Interfaces; 2 | 3 | namespace Hive.DataSync.Abstractions 4 | { 5 | public interface IDataSynchronizer 6 | { 7 | void Start(); 8 | void Stop(); 9 | 10 | void AddSync(T syncObject); 11 | void RemoveSync(T syncObject); 12 | void RemoveSync(ushort objectSyncId); 13 | 14 | void PerformSync(ISyncPacket syncPacket); 15 | } 16 | } -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/ResultContext.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Both.General.Dispatchers 2 | { 3 | public readonly struct ResultContext 4 | { 5 | public readonly T Message; 6 | 7 | public ResultContext(T message) 8 | { 9 | Message = message; 10 | } 11 | 12 | public static implicit operator ResultContext(T message) 13 | { 14 | return new ResultContext(message); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/IPacketIdMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Codec.Abstractions 4 | { 5 | /// 6 | /// 封包 类型 / ID 映射器 7 | /// 8 | public interface IPacketIdMapper 9 | { 10 | void Register(); 11 | void Register(Type type); 12 | void Register(Type type, out PacketId id); 13 | 14 | PacketId GetPacketId(Type type); 15 | Type GetPacketType(PacketId id); 16 | } 17 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Attributes/SyncOptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hive.Common.Shared; 3 | 4 | namespace Hive.DataSync.Shared.Attributes 5 | { 6 | [AttributeUsage(AttributeTargets.Field)] 7 | public sealed class SyncOptionAttribute : Attribute 8 | { 9 | public SyncOptionAttribute(SyncOptions syncOption) 10 | { 11 | SyncOption = syncOption; 12 | } 13 | 14 | public SyncOptions SyncOption { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /Unity.Mathematics/LICENSE.md: -------------------------------------------------------------------------------- 1 | com.unity.mathematics copyright © 2023 Unity Technologies ApS 2 | 3 | Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license). 4 | Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. 5 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/LICENSE.md: -------------------------------------------------------------------------------- 1 | com.unity.mathematics copyright © 2023 Unity Technologies ApS 2 | 3 | Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license). 4 | Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. -------------------------------------------------------------------------------- /Hive.Common.ECS/EntityDepthComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Hive.Common.ECS.Entity; 3 | 4 | namespace Hive.Common.ECS; 5 | 6 | internal class EntityDepthComparer : IComparer 7 | { 8 | public int Compare(IEntity x, IEntity y) 9 | { 10 | if (ReferenceEquals(x, y)) return 0; 11 | if (ReferenceEquals(null, y)) return 1; 12 | if (ReferenceEquals(null, x)) return -1; 13 | return x.Depth.CompareTo(y.Depth); 14 | } 15 | } -------------------------------------------------------------------------------- /Hive.Network.Quic/Hive.Network.Quic.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Hive.Common.Shared/Hive.Common.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | 9 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/PropertyAttributes.cs: -------------------------------------------------------------------------------- 1 | namespace Unity.Mathematics 2 | { 3 | /// 4 | /// Used by property drawers when vectors should be post normalized. 5 | /// 6 | public class PostNormalizeAttribute : UnityEngine.PropertyAttribute {} 7 | 8 | /// 9 | /// Used by property drawers when vectors should not be normalized. 10 | /// 11 | public class DoNotNormalizeAttribute : UnityEngine.PropertyAttribute {} 12 | } 13 | -------------------------------------------------------------------------------- /Hive.Common.ECS/Component/RefAction.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Common.ECS.Component; 2 | 3 | public delegate void RefAction(ref T component); 4 | 5 | public delegate void RefAction(ref T1 arg1, ref T2 arg2); 6 | 7 | public delegate void RefAction(ref T1 arg1, ref T2 arg2, ref T3 arg3); 8 | 9 | public delegate void RefAction(ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4); 10 | 11 | public delegate void RefAction(ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5); -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ClientHandle.cs: -------------------------------------------------------------------------------- 1 | using Hive.Network.Abstractions; 2 | using Hive.Network.Abstractions.Session; 3 | 4 | namespace Hive.Server.Abstractions; 5 | 6 | public class ClientHandle 7 | { 8 | public ClientHandle(ClientId id, ISession session) 9 | { 10 | Id = id; 11 | Session = session; 12 | } 13 | 14 | public ClientId Id { get; } 15 | public ISession Session { get; } 16 | 17 | public SessionId SessionId => Session.Id; 18 | public long LastHeartBeatTimeUtc { get; set; } 19 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Helpers/ArraySegmentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Common.Shared.Helpers 4 | { 5 | public static class ArraySegmentExtensions 6 | { 7 | public static ArraySegment Shift(this ArraySegment segment, int amount) 8 | { 9 | if (segment.Array == null) 10 | throw new ArgumentNullException(nameof(segment.Array)); 11 | 12 | return new ArraySegment(segment.Array, segment.Offset + amount, segment.Count - amount); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/Messages/QueryService.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using Hive.Codec.Shared; 3 | using MemoryPack; 4 | 5 | namespace Hive.Server.Cluster.Messages; 6 | 7 | [MemoryPackable] 8 | [MessageDefine] 9 | public partial class QueryServiceReq 10 | { 11 | public string ServiceName; 12 | } 13 | 14 | 15 | [MemoryPackable] 16 | [MessageDefine] 17 | public partial class QueryServiceResp 18 | { 19 | public int NodeId; 20 | public string ServiceName; 21 | public string ServiceAddress; 22 | public int ServicePort; 23 | } 24 | -------------------------------------------------------------------------------- /Hive.Network.Tests/ECS/TestSystem.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | using Hive.Common.ECS.System.Phases; 3 | 4 | namespace Hive.Network.Tests.ECS; 5 | 6 | public class TestSystem : IAwakeSystem, ILogicUpdateSystem 7 | { 8 | public bool EntityFilter(IEntity entity) 9 | { 10 | if (entity is ObjectEntity) return true; 11 | 12 | return false; 13 | } 14 | 15 | void IAwakeSystem.OnAwake(IEntity entity) 16 | { 17 | } 18 | 19 | void ILogicUpdateSystem.OnLogicUpdate(IEntity entity) 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /Hive.Network.Udp/Hive.Network.Udp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | enable 5 | $(MSBuildProjectName.Replace(" ", "_")) 6 | 10 7 | netstandard2.1 8 | $(MSBuildProjectName) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Hive.DataSync/Hive.DataSync.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | preview 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Hive.Network.Tcp/Hive.Network.Tcp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | $(MSBuildProjectName) 8 | latest 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Hive.Server.Common.Abstract/Hive.Server.Common.Abstract.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Hive.Server.Default/AppBuilder.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Abstractions; 2 | using Hive.Codec.MemoryPack; 3 | using Hive.Network.Tcp; 4 | using Hive.Server.Abstractions; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace Hive.Server.Default; 8 | 9 | public static class AppBuilder 10 | { 11 | public static void ConfigureServices(IServiceCollection services) 12 | { 13 | services.AddSingleton(); 14 | services.AddSingleton>(); 15 | } 16 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /Hive.DataSync.Abstractions/Hive.DataSync.Abstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Volume: 1 8 | Rolloff Scale: 1 9 | Doppler Factor: 1 10 | Default Speaker Mode: 2 11 | m_SampleRate: 0 12 | m_DSPBufferSize: 1024 13 | m_VirtualVoiceCount: 512 14 | m_RealVoiceCount: 32 15 | m_SpatializerPlugin: 16 | m_AmbisonicDecoderPlugin: 17 | m_DisableAudio: 0 18 | m_VirtualizeEffects: 1 19 | m_RequestedDSPBufferSize: 0 20 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/Il2CppEagerStaticClassConstructionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Unity.IL2CPP.CompilerServices 4 | { 5 | /// 6 | /// This is used to indicate to IL2CPP that the static constructors should be executed eagerly at startup 7 | /// rather than lazily at runtime. 8 | /// 9 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] 10 | internal class Il2CppEagerStaticClassConstructionAttribute : Attribute 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/RSC/CodeGenCaller.cs: -------------------------------------------------------------------------------- 1 | using Hive.Server.Abstractions; 2 | 3 | namespace Hive.Server.Cluster.RSC; 4 | 5 | public class CodeGenCaller : IRemoteServiceCaller 6 | { 7 | public void Call(ServiceAddress serviceAddress, string methodName, Stream serializedArguments, Action serializedResult) 8 | { 9 | throw new NotImplementedException(); 10 | } 11 | 12 | public Task CallAsync(ServiceAddress serviceAddress, string methodName, Stream serializedArguments) 13 | { 14 | throw new NotImplementedException(); 15 | } 16 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Helpers/RandomHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hive.Common.Shared.Helpers 5 | { 6 | public static class RandomHelper 7 | { 8 | private static readonly Random Random = new(); 9 | 10 | public static T RandomSelect(this IList list) 11 | { 12 | return list[Random.Next(list.Count)]; 13 | } 14 | 15 | public static T RandomSelect(this IReadOnlyList list) 16 | { 17 | return list[Random.Next(list.Count)]; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/EventArgs/LoadBalancerInitializedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using Hive.Network.Abstractions.GatewayServer; 2 | using Hive.Network.Abstractions.Session; 3 | 4 | namespace Hive.Network.Abstractions.EventArgs; 5 | 6 | public class LoadBalancerInitializedEventArgs : System.EventArgs 7 | { 8 | public LoadBalancerInitializedEventArgs(ILoadBalancer loadBalancer, ISession session) 9 | { 10 | LoadBalancer = loadBalancer; 11 | Session = session; 12 | } 13 | 14 | public ILoadBalancer LoadBalancer { get; } 15 | public ISession Session { get; } 16 | } -------------------------------------------------------------------------------- /Hive.Benchmark/Hive.Benchmark.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | Exe 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Hive.DataSync.SourceGen.Tests/Hive.DataSync.SourceGen.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | preview 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Hive.Network.Kcp/Hive.Network.Kcp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | latest 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/MessageContext.cs: -------------------------------------------------------------------------------- 1 | using Hive.Network.Abstractions.Session; 2 | 3 | namespace Hive.Both.General.Dispatchers 4 | { 5 | public readonly struct MessageContext 6 | { 7 | public readonly ISession FromSession; 8 | public readonly IDispatcher Dispatcher; 9 | public readonly T Message; 10 | 11 | public MessageContext(ISession fromSession, IDispatcher dispatcher, T message) 12 | { 13 | FromSession = fromSession; 14 | Message = message; 15 | Dispatcher = dispatcher; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/Hive.Server.Abstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Hive.Network.Shared/Helpers/NetworkAddressHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Network.Shared.Helpers 4 | { 5 | public static class NetworkAddressHelper 6 | { 7 | public static IPEndPoint ToIpEndPoint(string addressWithPort) 8 | { 9 | var arr = addressWithPort.Split(':'); 10 | var address = arr[0]; 11 | var port = ushort.TryParse(arr[1], out var outPort) ? outPort : 0; 12 | 13 | var ip = IPAddress.Parse(address); 14 | var endPoint = new IPEndPoint(ip, port); 15 | 16 | return endPoint; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Tests/TestCompilerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | using NUnit.Framework.Interfaces; 4 | 5 | namespace Burst.Compiler.IL.Tests 6 | { 7 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 8 | public class WindowsOnlyAttribute : Attribute 9 | { 10 | public WindowsOnlyAttribute(string reason) 11 | { 12 | } 13 | } 14 | 15 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)] 16 | public sealed class TestCompilerAttribute : TestCaseAttribute, ITestBuilder 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Hive.Both.Messages/Hive.Both.Messages.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Hive.Codec.MemoryPack/Hive.Codec.MemoryPack.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ServiceAddress.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Server.Abstractions; 4 | 5 | public struct ServiceAddress 6 | { 7 | public string ServiceName; 8 | public ClusterNodeInfo NodeInfo; 9 | 10 | public bool IsInSameNode(ClusterNodeId nodeId) 11 | { 12 | return NodeInfo.NodeId.Equals(nodeId); 13 | } 14 | 15 | public bool IsInSameMachine(ClusterNodeInfo nodeInfo) 16 | { 17 | if (nodeInfo.Equals(NodeInfo)) 18 | { 19 | return true; 20 | } 21 | 22 | return nodeInfo.MachineId == NodeInfo.MachineId; 23 | } 24 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Application/TestApplication.cs: -------------------------------------------------------------------------------- 1 | using Hive.Both.General.Dispatchers; 2 | using Hive.Both.Messages.C2S; 3 | using Hive.Both.Messages.S2C; 4 | 5 | namespace Hive.Server.Common.Application; 6 | 7 | public class TestApplication : ServerApplicationBase 8 | { 9 | public TestApplication(IServiceProvider serviceProvider) : base(serviceProvider) 10 | { 11 | 12 | } 13 | 14 | 15 | [MessageHandler] 16 | 17 | public async ValueTask> HelloHandler(CSHeartBeat request) 18 | { 19 | return new ResultContext(new SCHeartBeat()); 20 | } 21 | } -------------------------------------------------------------------------------- /Hive.Codec.Shared/Hive.Codec.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics.Editor/QuaternionDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | 3 | namespace Unity.Mathematics.Editor 4 | { 5 | [CustomPropertyDrawer(typeof(quaternion))] 6 | class QuaternionDrawer : PostNormalizedVectorDrawer 7 | { 8 | protected override SerializedProperty GetVectorProperty(SerializedProperty property) 9 | { 10 | return property.FindPropertyRelative("value"); 11 | } 12 | 13 | protected override double4 Normalize(double4 value) 14 | { 15 | return math.normalizesafe(new quaternion((float4)value)).value; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 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 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /Hive.Common.Shared/Attributes/AbstractIgnoreExceptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Common.Shared.Attributes 4 | { 5 | public abstract class AbstractIgnoreExceptionAttribute : Attribute 6 | { 7 | protected readonly Type ExceptionType; 8 | 9 | public AbstractIgnoreExceptionAttribute(Type exceptionType) 10 | { 11 | if (!exceptionType.IsSubclassOf(typeof(Exception))) 12 | throw new ArgumentException("ExceptionType must be a type of Exception"); 13 | 14 | ExceptionType = exceptionType; 15 | } 16 | 17 | public abstract bool IsMatch(Exception exception); 18 | } 19 | } -------------------------------------------------------------------------------- /Hive.DataSync.SourceGen/Hive.DataSync.SourceGen.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | preview 6 | true 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Attributes/CustomSerializerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hive.DataSync.Shared.ObjectSyncPacket; 3 | 4 | namespace Hive.DataSync.Shared.Attributes 5 | { 6 | [AttributeUsage(AttributeTargets.Field)] 7 | public sealed class CustomSerializerAttribute : Attribute 8 | { 9 | public CustomSerializerAttribute(Type type) 10 | { 11 | if (!type.IsSubclassOf(typeof(AbstractObjectSyncPacket))) 12 | throw new ArgumentException($"Type {type} is not a subclass of {nameof(AbstractObjectSyncPacket)}"); 13 | 14 | Type = type; 15 | } 16 | 17 | public Type Type { get; } 18 | } 19 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/Hive.Network.Abstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | latest 5 | netstandard2.1 6 | enable 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | PACKET_ID_INT 9 | $(MSBuildProjectName) 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Hive.Network.Shared/NetworkSettings.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Network.Shared 2 | { 3 | public static class NetworkSettings 4 | { 5 | public const int MaxMessageSize = 1024 * 1024 * 10; 6 | public const int DefaultBufferSize = 40960; 7 | public const int DefaultSocketBufferSize = 8192 * 4; 8 | public const int PacketHeaderLength = sizeof(ushort) + sizeof(uint); // 包头长度2Byte 9 | 10 | public const int PacketLengthOffset = 0; 11 | public const int SessionIdOffset = 2; 12 | public const int PacketBodyOffset = 6; 13 | 14 | public const int HandshakeSessionId = 0x114514; 15 | 16 | public const int MaxHeartBeatTimeout = 10000; 17 | } 18 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics.PerformanceTests/Unity.Mathematics.PerformanceTests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.Mathematics.PerformanceTests", 3 | "references": [ 4 | "Unity.Mathematics", 5 | "Unity.PerformanceTesting", 6 | "Unity.Burst" 7 | ], 8 | "includePlatforms": [ 9 | "Editor" 10 | ], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": true, 13 | "overrideReferences": true, 14 | "precompiledReferences": [ 15 | "nunit.framework.dll" 16 | ], 17 | "autoReferenced": true, 18 | "defineConstraints": [ 19 | "UNITY_INCLUDE_TESTS" 20 | ], 21 | "versionDefines": [], 22 | "noEngineReferences": false 23 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Hive.Common.ECS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | latest 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/DispatcherExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hive.Network.Abstractions.Session; 2 | 3 | namespace Hive.Both.General.Dispatchers 4 | { 5 | public static class DispatcherExtensions 6 | { 7 | public static void BindTo(this ISession session, IDispatcher dispatcher) 8 | { 9 | session.OnMessageReceived += dispatcher.Dispatch; 10 | } 11 | 12 | public static void BindTo(this IAcceptor acceptor, IDispatcher dispatcher) 13 | { 14 | acceptor.OnSessionCreated += (_, _, session) => { session.OnMessageReceived += dispatcher.Dispatch; }; 15 | 16 | acceptor.OnSessionClosed += (_, _, session) => { session.OnMessageReceived -= dispatcher.Dispatch; }; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Hive.Server.Shared/Hive.Server.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Hive.Both.General/Channels/MessageChannelExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hive.Both.General.Dispatchers; 2 | using Hive.Network.Abstractions.Session; 3 | 4 | namespace Hive.Both.General.Channels 5 | { 6 | public static class MessageChannelExtensions 7 | { 8 | public static IServerMessageChannel CreateServerChannel( 9 | this IDispatcher dispatcher) 10 | { 11 | return new ServerMessageChannel(dispatcher); 12 | } 13 | 14 | public static IMessageChannel CreateChannel(this IDispatcher dispatcher, 15 | ISession session) 16 | { 17 | return new MessageChannel(session, dispatcher); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/Attributes/SetSyncIntervalAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.DataSync.Shared.Attributes 4 | { 5 | /// 6 | /// 用于指示数据同步器的同步间隔,最低值为 5ms 7 | /// 默认值为 100ms 8 | /// 9 | [AttributeUsage(AttributeTargets.Class)] 10 | public sealed class SetSyncIntervalAttribute : Attribute 11 | { 12 | /// 13 | /// 更新间隔,毫秒为单位 14 | /// 15 | /// 16 | public SetSyncIntervalAttribute(double syncInterval) 17 | { 18 | SyncInterval = TimeSpan.FromMilliseconds(syncInterval < 5 ? 5 : syncInterval); 19 | } 20 | 21 | public TimeSpan SyncInterval { get; } 22 | } 23 | } -------------------------------------------------------------------------------- /Hive.Codec.Bson/Hive.Codec.Bson.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | True 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Hive.Codec.Shared/Helpers/TypeHashUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | using System.Text; 4 | using Hive.Codec.Abstractions; 5 | 6 | namespace Hive.Codec.Shared.Helpers; 7 | 8 | public static class TypeHashUtil 9 | { 10 | private const ushort HashMod = 65521; // 小于 65535 的质数 11 | 12 | public static PacketId GetTypeHash(Type type) 13 | { 14 | var typeName = type.FullName; 15 | 16 | if (typeName == null) 17 | throw new ArgumentException($"Failed to register type {type}"); 18 | 19 | using var md5 = MD5.Create(); 20 | var hashCode = BitConverter.ToUInt64(md5.ComputeHash(Encoding.ASCII.GetBytes(typeName))); 21 | var id = (ushort)(hashCode % HashMod); 22 | 23 | return id; 24 | } 25 | } -------------------------------------------------------------------------------- /Hive.Codec.Protobuf/Hive.Codec.Protobuf.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | $(MSBuildProjectName.Replace(" ", "_")) 7 | False 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Hive.Server.App/Hive.Server.App.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net10.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Hive.Server.Common.Application.Generator/Hive.Server.Common.Application.Generator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | false 6 | disable 7 | Hive.Server.Common.Application.SourceGen 8 | true 9 | latest 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/Noise/README: -------------------------------------------------------------------------------- 1 | These files contain noise functions that are compatible with all 2 | current versions of GLSL (1.20 and up), and all you need to use them 3 | is provided in the source file. There is no external data, and no 4 | setup procedure. Just cut and paste and call the function. 5 | 6 | GLSL has a very rudimentary linker, so some helper functions are 7 | included in several of the files with the same name. If you want to 8 | use more than one of these functions in the same shader, you may run 9 | into problems with redefinition of the functions mod289() and permute(). 10 | If that happens, just delete any superfluous definitions. 11 | 12 | ----- 13 | 14 | Source: https://github.com/ashima/webgl-noise 15 | Changes: 16 | - 10 April 2018, Unity Technologies, Ported to HPC# 17 | -------------------------------------------------------------------------------- /Hive.Both.General/Hive.Both.General.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | disable 5 | enable 6 | latest 7 | netstandard2.1;net10.0 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ServiceKey.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public struct ServiceKey : IEquatable, IEqualityComparer 4 | { 5 | public string ServiceName; 6 | 7 | public bool Equals(ServiceKey other) 8 | { 9 | return ServiceName == other.ServiceName; 10 | } 11 | 12 | public override bool Equals(object? obj) 13 | { 14 | return obj is ServiceKey other && Equals(other); 15 | } 16 | 17 | public override int GetHashCode() 18 | { 19 | return ServiceName.GetHashCode(); 20 | } 21 | 22 | public bool Equals(ServiceKey x, ServiceKey y) 23 | { 24 | return x.ServiceName == y.ServiceName; 25 | } 26 | 27 | public int GetHashCode(ServiceKey obj) 28 | { 29 | return obj.ServiceName.GetHashCode(); 30 | } 31 | } -------------------------------------------------------------------------------- /Unity.Mathematics/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome:http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # All Files 7 | [*] 8 | charset = utf-8 9 | indent_style = space 10 | indent_size = 4 11 | insert_final_newline = false 12 | trim_trailing_whitespace = true 13 | 14 | # Solution Files 15 | [*.sln] 16 | indent_style = tab 17 | 18 | # XML Project Files 19 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 20 | indent_size = 2 21 | 22 | # Configuration Files 23 | [*.{json,xml,yml,config,props,targets,nuspec,resx,ruleset}] 24 | indent_size = 2 25 | 26 | # Markdown Files 27 | [*.md] 28 | trim_trailing_whitespace = false 29 | 30 | # Web Files 31 | [*.{htm,html,js,ts,css,scss,less}] 32 | indent_size = 2 33 | insert_final_newline = true 34 | 35 | # Bash Files 36 | [*.sh] 37 | end_of_line = lf 38 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET 5 | 6 | on: 7 | push: 8 | branches: [ "data-sync" ] 9 | pull_request: 10 | branches: [ "data-sync" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: windows-latest 16 | 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v3 20 | with: 21 | fetch-depth: 0 22 | submodules: recursive 23 | 24 | - name: Setup .NET 25 | uses: actions/setup-dotnet@v3 26 | with: 27 | dotnet-version: 9.0.x 28 | - name: Restore dependencies 29 | run: dotnet restore 30 | - name: Build 31 | run: dotnet build --no-restore 32 | - name: Test 33 | run: dotnet test --no-build --verbosity normal 34 | -------------------------------------------------------------------------------- /Hive.Codec.Abstractions/IPacketPrefixResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hive.Codec.Abstractions 4 | { 5 | /// 6 | /// 封包前缀解析器 7 | /// 该抽象用于解析介于封包长度段和负载段之间的数据,这些数据通常是由网关注入的 8 | /// 示例: [长度 | 前缀 1 | 前缀 2 | ... | 前缀 n | 负载] 9 | /// 10 | public interface IPacketPrefixResolver 11 | { 12 | /// 13 | /// 解析封包前缀 14 | /// 15 | /// 完整数据 [长度 | 前缀 1 | 前缀 2 | ... | 前缀 n | 负载] 16 | /// 17 | /// 当前索引位置,传入索引的引用 18 | /// 您需要在解析完对应的前缀数据段之后,更新 index 的值。 19 | /// 例如,您读取了一个长度为 2 的前缀,在跳出当前方法前,请将 index + 2 20 | /// 21 | /// 22 | object Resolve(ReadOnlySpan data, ref int index); 23 | } 24 | } -------------------------------------------------------------------------------- /Hive.Codec.Protobuf/ProtoBufPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.IO; 4 | using CommunityToolkit.HighPerformance; 5 | using Hive.Codec.Abstractions; 6 | using Hive.Codec.Shared; 7 | using ProtoBuf.Meta; 8 | 9 | namespace Hive.Codec.Protobuf; 10 | 11 | public class ProtoBufPacketCodec( 12 | IPacketIdMapper packetIdMapper, 13 | ICustomCodecProvider customCodecProvider) 14 | : AbstractPacketCodec(packetIdMapper, customCodecProvider) 15 | { 16 | protected override int EncodeBody(T message, Stream stream) 17 | { 18 | return (int)RuntimeTypeModel.Default.Serialize(stream, message); 19 | } 20 | 21 | protected override object DecodeBody(ReadOnlySequence buffer, Type type) 22 | { 23 | using var stream = buffer.AsStream(); 24 | return RuntimeTypeModel.Default.Deserialize(stream, null, type); 25 | } 26 | } -------------------------------------------------------------------------------- /Hive.DataSync.SourceGen/Helpers/TypeSymbolHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.CodeAnalysis; 4 | 5 | namespace Hive.DataSync.SourceGen.Helpers; 6 | 7 | internal static class TypeSymbolHelper 8 | { 9 | internal static INamedTypeSymbol GetTypeSymbolForType(Type type, SemanticModel semanticModel) 10 | { 11 | if (!type.IsConstructedGenericType) return semanticModel.Compilation.GetTypeByMetadataName(type.FullName); 12 | 13 | // get all typeInfo's for the Type arguments 14 | var typeArgumentsTypeInfos = type.GenericTypeArguments.Select(a => GetTypeSymbolForType(a, semanticModel)); 15 | 16 | var openType = type.GetGenericTypeDefinition(); 17 | var typeSymbol = semanticModel.Compilation.GetTypeByMetadataName(openType.FullName); 18 | return typeSymbol.Construct(typeArgumentsTypeInfos.ToArray()); 19 | } 20 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Compositor/AbstractCompositor.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Common.ECS.Compositor; 4 | 5 | public abstract class AbstractCompositor : ICompositor where T : ObjectEntity, new() 6 | { 7 | ObjectEntity ICompositor.Composite(long id, IEntity parent) 8 | { 9 | var worldEntity = parent switch 10 | { 11 | WorldEntity entity => entity, 12 | ObjectEntity parentObjectEntity => parentObjectEntity.WorldEntity, 13 | _ => null 14 | }; 15 | 16 | 17 | var objectEntity = new T 18 | { 19 | InstanceId = id, 20 | Compositor = this, 21 | WorldEntity = worldEntity, 22 | Parent = parent 23 | }; 24 | 25 | Composite(objectEntity); 26 | return objectEntity; 27 | } 28 | 29 | protected abstract void Composite(T entity); 30 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Application/Hive.Server.Common.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Hive.Server.Cluster/Messages/NodeLoginReq.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Shared; 2 | using Hive.Server.Abstractions; 3 | using MemoryPack; 4 | 5 | namespace Hive.Server.Cluster.Messages; 6 | 7 | [MemoryPackable] 8 | [MessageDefine] 9 | public partial class NodeLoginReq 10 | { 11 | public string Signature; 12 | 13 | public string PublicKey; 14 | 15 | public string MachineId; 16 | 17 | public List Services; 18 | } 19 | 20 | 21 | [MemoryPackable] 22 | [MessageDefine] 23 | public partial class NodeLoginResp 24 | { 25 | public ErrorCode ErrorCode; 26 | 27 | public string Signature; 28 | 29 | public string PublicKey; 30 | 31 | public int NodeId; 32 | 33 | public NodeLoginResp(ErrorCode errorCode, string signature, string publicKey) 34 | { 35 | ErrorCode = errorCode; 36 | Signature = signature; 37 | PublicKey = publicKey; 38 | } 39 | } -------------------------------------------------------------------------------- /Hive.Server.App/TestService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Hosting; 2 | using Microsoft.Extensions.Logging; 3 | 4 | namespace Hive.Server.App; 5 | 6 | public class TestService : BackgroundService 7 | { 8 | private readonly ILogger _logger; 9 | 10 | public TestService(ILogger logger) 11 | { 12 | _logger = logger; 13 | } 14 | 15 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 16 | { 17 | while (!stoppingToken.IsCancellationRequested) 18 | { 19 | _logger.LogRunningTime(DateTimeOffset.Now); 20 | await Task.Delay(1_000, stoppingToken); 21 | } 22 | } 23 | } 24 | 25 | internal static partial class TestServiceLoggers 26 | { 27 | [LoggerMessage(LogLevel.Information, "Worker running at: {Time}")] 28 | public static partial void LogRunningTime(this ILogger logger, DateTimeOffset time); 29 | } -------------------------------------------------------------------------------- /Hive.Server.Cluster/Hive.Server.Cluster.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Hive.Codec.Bson/BsonPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.IO; 4 | using CommunityToolkit.HighPerformance; 5 | using Hive.Codec.Abstractions; 6 | using Hive.Codec.Shared; 7 | using MongoDB.Bson.IO; 8 | using MongoDB.Bson.Serialization; 9 | 10 | namespace Hive.Codec.Bson; 11 | 12 | public class BsonPacketCodec( 13 | IPacketIdMapper packetIdMapper, 14 | ICustomCodecProvider customCodecProvider) 15 | : AbstractPacketCodec(packetIdMapper, customCodecProvider) 16 | { 17 | protected override int EncodeBody(T message, Stream stream) 18 | { 19 | var bsonWriter = new BsonBinaryWriter(stream); 20 | BsonSerializer.Serialize(bsonWriter, message); 21 | return (int)bsonWriter.Position; 22 | } 23 | 24 | protected override object? DecodeBody(ReadOnlySequence buffer, Type type) 25 | { 26 | using var ms = buffer.AsStream(); 27 | 28 | return BsonSerializer.Deserialize(ms, type); 29 | } 30 | } -------------------------------------------------------------------------------- /Hive.Application.Test/Hive.Application.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Hive.Network.Abstractions/GatewayServer/IGatewayServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Hive.Codec.Abstractions; 4 | using Hive.Network.Abstractions.EventArgs; 5 | using Hive.Network.Abstractions.Session; 6 | 7 | namespace Hive.Network.Abstractions.GatewayServer; 8 | 9 | /// 10 | /// 表示一个网关服务器 11 | /// 12 | /// 会话类型,通常为具体协议的实现 13 | public interface IGatewayServer : IDisposable where TSession : ISession 14 | { 15 | IPacketCodec PacketCodec { get; } 16 | IAcceptor Acceptor { get; } 17 | ILoadBalancer LoadBalancer { get; } 18 | ISecureStreamProvider SecureStreamProvider { get; } 19 | 20 | Func LoadBalancerGetter { get; } 21 | 22 | bool ServerInitialized { get; } 23 | event EventHandler? OnLoadBalancerInitialized; 24 | 25 | void StartServer(CancellationToken token); 26 | void StopServer(CancellationToken token); 27 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Abstract/IServer.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Server.Common.Abstract; 4 | 5 | public interface IServer : IDisposable 6 | { 7 | /// 8 | /// Start the server with an application. 9 | /// 10 | /// Indicates which acceptor service to get from the container. 11 | /// The IP endpoint to listen on. 12 | /// The application to host. 13 | /// Indicates if the server startup should be aborted. 14 | Task StartAsync(string key, IPEndPoint ipEndPoint, IServerApplication app, CancellationToken stoppingToken); 15 | 16 | /// 17 | /// Stop processing requests and shut down the server, gracefully if possible. 18 | /// 19 | /// Indicates if the graceful shutdown should be aborted. 20 | Task StopAsync(CancellationToken cancellationToken); 21 | } -------------------------------------------------------------------------------- /Hive.Network.Shared/Hive.Network.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 5 | netstandard2.1 6 | enable 7 | $(MSBuildProjectName.Replace(" ", "_")) 8 | $(MSBuildProjectName) 9 | disable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 0 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /Hive.Codec.MemoryPack/MemoryPackPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Abstractions; 2 | using Hive.Codec.Shared; 3 | using MemoryPack; 4 | using System.Buffers; 5 | 6 | namespace Hive.Codec.MemoryPack; 7 | 8 | public class MemoryPackPacketCodec( 9 | IPacketIdMapper packetIdMapper, 10 | ICustomCodecProvider customCodecProvider) 11 | : AbstractPacketCodec(packetIdMapper, customCodecProvider) 12 | { 13 | protected override int EncodeBody(T message, Stream stream) 14 | { 15 | if (stream is IBufferWriter bufferWriter) 16 | { 17 | var position = stream.Position; 18 | 19 | MemoryPackSerializer.Serialize(bufferWriter, message); 20 | 21 | return (int)(stream.Position - position); 22 | } 23 | 24 | var bytes = MemoryPackSerializer.Serialize(message).AsSpan(); 25 | 26 | stream.Write(bytes); 27 | 28 | return bytes.Length; 29 | } 30 | 31 | protected override object? DecodeBody(ReadOnlySequence buffer, Type type) 32 | { 33 | return MemoryPackSerializer.Deserialize(type, buffer); 34 | } 35 | } -------------------------------------------------------------------------------- /Hive.Application.Test/DummySession.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using Hive.Network.Abstractions; 3 | using Hive.Network.Abstractions.Session; 4 | 5 | namespace Hive.Application.Test; 6 | 7 | public class DummySession : ISession 8 | { 9 | public SessionId Id { get; } 10 | public IPEndPoint? LocalEndPoint { get; } 11 | public IPEndPoint? RemoteEndPoint { get; } 12 | public long LastHeartBeatTime { get; } 13 | 14 | public event SessionReceivedHandler? OnMessageReceived; 15 | 16 | public Task StartAsync(CancellationToken token) 17 | { 18 | throw new NotImplementedException(); 19 | } 20 | 21 | public ValueTask SendAsync(Stream ms, CancellationToken token = default) 22 | { 23 | OnSend?.Invoke(ms); 24 | return default; 25 | } 26 | 27 | public event Action? OnSend; 28 | public ValueTask TrySendAsync(Stream ms, CancellationToken token = default) 29 | { 30 | OnSend?.Invoke(ms); 31 | return new ValueTask(true); 32 | } 33 | 34 | public void Close() 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | } -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/IDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Hive.Network.Abstractions.Session; 6 | 7 | namespace Hive.Both.General.Dispatchers 8 | { 9 | public interface IDispatcher 10 | { 11 | void Dispatch(ISession session, ReadOnlySequence buffer); 12 | 13 | void Dispatch(ISession session, T message) where T : class; 14 | void Dispatch(ISession session, Type type, object message); 15 | 16 | HandlerId AddHandler(Action> handler, TaskScheduler? scheduler = null); 17 | 18 | bool RemoveHandler(Action> handler); 19 | bool RemoveHandler(HandlerId id); 20 | 21 | Task HandleOnce(ISession session, CancellationToken cancellationToken = default); 22 | 23 | Task SendAndListenOnce(ISession session, TReq message, 24 | CancellationToken cancellationToken = default); 25 | 26 | ValueTask SendAsync(ISession session, T message, CancellationToken cancellationToken = default); 27 | } 28 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ClusterNodeId.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public struct ClusterNodeId : IEquatable, IEqualityComparer 4 | { 5 | public int Id; 6 | 7 | public ClusterNodeId(int id) 8 | { 9 | Id = id; 10 | } 11 | 12 | public bool Equals(ClusterNodeId other) 13 | { 14 | return Id == other.Id; 15 | } 16 | 17 | public override bool Equals(object? obj) 18 | { 19 | return obj is ClusterNodeId other && Equals(other); 20 | } 21 | 22 | public override int GetHashCode() 23 | { 24 | return Id; 25 | } 26 | 27 | public bool Equals(ClusterNodeId x, ClusterNodeId y) 28 | { 29 | return x.Id == y.Id; 30 | } 31 | 32 | public int GetHashCode(ClusterNodeId obj) 33 | { 34 | return obj.Id; 35 | } 36 | 37 | public static bool operator ==(ClusterNodeId left, ClusterNodeId right) 38 | { 39 | return left.Equals(right); 40 | } 41 | 42 | public static bool operator !=(ClusterNodeId left, ClusterNodeId right) 43 | { 44 | return !(left == right); 45 | } 46 | } -------------------------------------------------------------------------------- /Hive.Network.Abstractions/Session/ISession.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Net; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Hive.Network.Abstractions.Session; 7 | 8 | /// 9 | /// 代表一个连接,可以是服务端之间的连接,也可以是客户端之间的连接 10 | /// 包含了连接的基本信息,以及收发数据的方法 11 | /// 12 | public interface ISession 13 | { 14 | public SessionId Id { get; } 15 | 16 | IPEndPoint? LocalEndPoint { get; } 17 | IPEndPoint? RemoteEndPoint { get; } 18 | 19 | /// 20 | /// 收到数据后的回调,不需要IO,无需异步。 21 | /// 拿到后立刻处理,否则数据会被回收。 22 | /// 如果要缓存,必须复制一份数据 23 | /// 24 | event SessionReceivedHandler OnMessageReceived; 25 | 26 | public Task StartAsync(CancellationToken token); 27 | 28 | ValueTask SendAsync(Stream ms, CancellationToken token = default); 29 | 30 | /// 31 | /// 发送数据 32 | /// 33 | /// 34 | /// 35 | /// 36 | ValueTask TrySendAsync(Stream ms, CancellationToken token = default); 37 | 38 | void Close(); 39 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/Noise/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 by Ashima Arts (Simplex noise) 2 | Copyright (C) 2011-2016 by Stefan Gustavson (Classic noise and others) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Hive.Both.General/Channels/IMessageChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Hive.Both.General.Channels 7 | { 8 | public interface IMessageChannel 9 | { 10 | ValueTask ReadAsync(CancellationToken token = default); 11 | ValueTask WriteAsync(object message); 12 | } 13 | 14 | public interface IMessageChannel : IMessageChannel 15 | { 16 | async ValueTask IMessageChannel.ReadAsync(CancellationToken token) 17 | { 18 | return await ReadAsync(token) ?? default; 19 | } 20 | 21 | ValueTask IMessageChannel.WriteAsync(object message) 22 | { 23 | return WriteAsync((TWrite)message); 24 | } 25 | 26 | new ValueTask ReadAsync(CancellationToken token = default); 27 | ValueTask WriteAsync(TWrite message); 28 | 29 | async IAsyncEnumerable GetAsyncEnumerable([EnumeratorCancellation] CancellationToken cancellationToken) 30 | { 31 | while (!cancellationToken.IsCancellationRequested) yield return await ReadAsync(cancellationToken); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Hive.Network.Shared/Helpers/SocketHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Runtime.InteropServices; 5 | using System.Threading.Tasks; 6 | 7 | namespace Hive.Network.Shared.Helpers 8 | { 9 | public static class SocketHelper 10 | { 11 | public static void PatchSocket(this Socket socket) 12 | { 13 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 14 | { 15 | var IOC_IN = 0x80000000; 16 | uint IOC_VENDOR = 0x18000000; 17 | var SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; 18 | socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null); 19 | } 20 | } 21 | 22 | public static async ValueTask RawSendTo(this Socket socket, byte[] data, EndPoint to) 23 | { 24 | var sentLen = 0; 25 | 26 | // 将分配的 Conv 返回给客户端 27 | while (sentLen < data.Length) 28 | { 29 | var sent = await socket.SendToAsync( 30 | new ArraySegment(data[sentLen..]), 31 | SocketFlags.None, 32 | to); 33 | 34 | sentLen += sent; 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/ServiceProviderHelper.cs: -------------------------------------------------------------------------------- 1 | using Hive.Codec.Abstractions; 2 | using Hive.Network.Abstractions.Session; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace Hive.Network.Tests; 7 | 8 | public static class ServiceProviderHelper 9 | { 10 | public static IServiceProvider GetServiceProvider( 11 | Action? serviceCollectionSetter = null) 12 | where TAcceptor : class, IAcceptor 13 | where TConnector : class, IConnector 14 | where TSession : class, ISession 15 | where TCodec : class, IPacketCodec 16 | { 17 | var services = new ServiceCollection(); 18 | 19 | services.AddLogging(builder => 20 | { 21 | builder.AddConsole(); 22 | builder.SetMinimumLevel(LogLevel.Trace); 23 | }); 24 | services.AddSingleton(); 25 | services.AddTransient(); 26 | services.AddSingleton, TAcceptor>(); 27 | services.AddSingleton, TConnector>(); 28 | 29 | serviceCollectionSetter?.Invoke(services); 30 | 31 | return services.BuildServiceProvider(); 32 | } 33 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/AbstractObjectSyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hive.Common.Shared; 3 | using Hive.DataSync.Abstractions.Interfaces; 4 | 5 | namespace Hive.DataSync.Shared.ObjectSyncPacket 6 | { 7 | public abstract class AbstractObjectSyncPacket 8 | { 9 | public AbstractObjectSyncPacket( 10 | string propertyName, 11 | ushort objectSyncId, 12 | SyncOptions syncOptions) 13 | { 14 | PropertyName = propertyName; 15 | ObjectSyncId = objectSyncId; 16 | SyncOptions = syncOptions; 17 | } 18 | 19 | public string PropertyName { get; } 20 | public ushort ObjectSyncId { get; } 21 | public SyncOptions SyncOptions { get; } 22 | 23 | public abstract ReadOnlyMemory Serialize(); 24 | } 25 | 26 | public abstract class AbstractObjectSyncPacket : AbstractObjectSyncPacket, ISyncPacket 27 | { 28 | protected AbstractObjectSyncPacket( 29 | ushort objectSyncId, 30 | string propertyName, 31 | SyncOptions syncOptions, 32 | T newValue) : base(propertyName, objectSyncId, syncOptions) 33 | { 34 | NewValue = newValue; 35 | } 36 | 37 | public T NewValue { get; } 38 | } 39 | } -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ClientId.cs: -------------------------------------------------------------------------------- 1 | namespace Hive.Server.Abstractions; 2 | 3 | public struct ClientId : IEquatable, IEqualityComparer 4 | { 5 | #if PACKET_ID_LONG 6 | public long Id; 7 | 8 | public static implicit operator long(SessionId packetId) 9 | { 10 | return packetId.Id; 11 | } 12 | 13 | public static implicit operator SessionId(long packetId) 14 | { 15 | return new SessionId() { Id = packetId }; 16 | } 17 | #else 18 | public int Id; 19 | 20 | public static implicit operator int(ClientId packetId) 21 | { 22 | return packetId.Id; 23 | } 24 | 25 | public static implicit operator ClientId(int packetId) 26 | { 27 | return new ClientId { Id = packetId }; 28 | } 29 | #endif 30 | public bool Equals(ClientId other) 31 | { 32 | return Id == other.Id; 33 | } 34 | 35 | public override bool Equals(object? obj) 36 | { 37 | return obj is ClientId other && Equals(other); 38 | } 39 | 40 | public override int GetHashCode() 41 | { 42 | return Id; 43 | } 44 | 45 | public bool Equals(ClientId x, ClientId y) 46 | { 47 | return x.Id == y.Id; 48 | } 49 | 50 | public int GetHashCode(ClientId obj) 51 | { 52 | return obj.Id; 53 | } 54 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 9 7 | m_ExternalVersionControlSupport: Hidden Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 0 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 0 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 1 30 | m_AssetPipelineMode: 1 31 | m_CacheServerMode: 0 32 | m_CacheServerEndpoint: 33 | m_CacheServerNamespacePrefix: default 34 | m_CacheServerEnableDownload: 1 35 | m_CacheServerEnableUpload: 1 36 | -------------------------------------------------------------------------------- /Hive.Server.Abstractions/ClusterNodeInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Hive.Server.Abstractions; 4 | 5 | public struct ClusterNodeInfo: IEquatable 6 | { 7 | public readonly ClusterNodeId NodeId { get; } 8 | private readonly IPEndPoint NodeEndPoint { get; } 9 | public readonly string MachineId { get; } 10 | public readonly ServiceKey[] ServiceKeys { get; } 11 | public DateTime LastHeartBeatTime { get; set; } 12 | 13 | public ClusterNodeInfo(ClusterNodeId nodeId, IPEndPoint nodeEndPoint, string machineId, ServiceKey[] serviceKeys) 14 | { 15 | NodeId = nodeId; 16 | NodeEndPoint = nodeEndPoint; 17 | MachineId = machineId; 18 | ServiceKeys = serviceKeys; 19 | } 20 | 21 | public bool Equals(ClusterNodeInfo other) 22 | { 23 | return NodeId.Equals(other.NodeId); 24 | } 25 | 26 | public override bool Equals(object? obj) 27 | { 28 | return obj is ClusterNodeInfo other && Equals(other); 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return NodeId.GetHashCode(); 34 | } 35 | 36 | public static bool operator ==(ClusterNodeInfo left, ClusterNodeInfo right) 37 | { 38 | return left.Equals(right); 39 | } 40 | 41 | public static bool operator !=(ClusterNodeInfo left, ClusterNodeInfo right) 42 | { 43 | return !(left == right); 44 | } 45 | } -------------------------------------------------------------------------------- /Hive.Both.General/Dispatchers/HandlerId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hive.Both.General.Dispatchers 5 | { 6 | public readonly struct HandlerId : IEquatable, IEqualityComparer 7 | { 8 | public readonly int Id; 9 | 10 | public HandlerId(int id) 11 | { 12 | Id = id; 13 | } 14 | 15 | public bool Equals(HandlerId other) 16 | { 17 | return Id == other.Id; 18 | } 19 | 20 | public override bool Equals(object? obj) 21 | { 22 | return obj is HandlerId other && Equals(other); 23 | } 24 | 25 | public override int GetHashCode() 26 | { 27 | return Id; 28 | } 29 | 30 | public bool Equals(HandlerId x, HandlerId y) 31 | { 32 | return x.Id == y.Id; 33 | } 34 | 35 | public int GetHashCode(HandlerId obj) 36 | { 37 | return obj.Id; 38 | } 39 | 40 | public static bool operator ==(HandlerId left, HandlerId right) 41 | { 42 | return left.Equals(right); 43 | } 44 | 45 | public static bool operator !=(HandlerId left, HandlerId right) 46 | { 47 | return !(left == right); 48 | } 49 | 50 | public override string ToString() 51 | { 52 | return $"(HandleId){Id.ToString()}"; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 13 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0.1 18 | m_ClothInterCollisionStiffness: 0.2 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 0 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ClothGravity: {x: 0, y: -9.81, z: 0} 26 | m_ContactPairsMode: 0 27 | m_BroadphaseType: 0 28 | m_WorldBounds: 29 | m_Center: {x: 0, y: 0, z: 0} 30 | m_Extent: {x: 250, y: 250, z: 250} 31 | m_WorldSubdivisions: 8 32 | m_FrictionType: 0 33 | m_EnableEnhancedDeterminism: 0 34 | m_EnableUnifiedHeightmaps: 1 35 | m_SolverType: 0 36 | m_DefaultMaxAngularSpeed: 50 37 | -------------------------------------------------------------------------------- /Hive.Network.Abstractions/SessionId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hive.Network.Abstractions; 5 | 6 | public struct SessionId : IEquatable, IEqualityComparer 7 | { 8 | #if PACKET_ID_INT 9 | public int Id; 10 | public static int Size => sizeof(int); 11 | 12 | public static implicit operator int(SessionId packetId) 13 | { 14 | return packetId.Id; 15 | } 16 | 17 | public static implicit operator SessionId(int packetId) 18 | { 19 | return new SessionId { Id = packetId }; 20 | } 21 | 22 | public static SessionId FromSpan(ReadOnlySpan span) 23 | { 24 | return new SessionId 25 | { 26 | Id = BitConverter.ToInt32(span) 27 | }; 28 | } 29 | #endif 30 | public readonly bool Equals(SessionId other) 31 | { 32 | return Id == other.Id; 33 | } 34 | 35 | public readonly override bool Equals(object? obj) 36 | { 37 | return obj is SessionId other && Equals(other); 38 | } 39 | 40 | public readonly override int GetHashCode() 41 | { 42 | return Id; 43 | } 44 | 45 | public readonly bool Equals(SessionId x, SessionId y) 46 | { 47 | return x.Id == y.Id; 48 | } 49 | 50 | public readonly int GetHashCode(SessionId obj) 51 | { 52 | return obj.Id; 53 | } 54 | 55 | public readonly override string ToString() 56 | { 57 | return Id.ToString(); 58 | } 59 | } -------------------------------------------------------------------------------- /Hive.Server.Default/Hive.Server.Default.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers; buildtransitive 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Hive.Both.General/Channels/IServerMessageChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Hive.Network.Abstractions.Session; 6 | 7 | namespace Hive.Both.General.Channels 8 | { 9 | public interface IServerMessageChannel 10 | { 11 | ValueTask<(ISession session, object? message)> ReadAsync(CancellationToken token = default); 12 | ValueTask WriteAsync(ISession session, object message); 13 | } 14 | 15 | public interface IServerMessageChannel : IServerMessageChannel 16 | { 17 | async ValueTask<(ISession session, object? message)> IServerMessageChannel.ReadAsync(CancellationToken token) 18 | { 19 | return await ReadAsync(token); 20 | } 21 | 22 | ValueTask IServerMessageChannel.WriteAsync(ISession session, object message) 23 | { 24 | return WriteAsync(session, (TWrite)message); 25 | } 26 | 27 | new ValueTask<(ISession session, TRead message)> ReadAsync(CancellationToken token = default); 28 | ValueTask WriteAsync(ISession session, TWrite message); 29 | 30 | async IAsyncEnumerable<(ISession session, TRead message)> GetAsyncEnumerable( 31 | [EnumeratorCancellation] CancellationToken cancellationToken) 32 | { 33 | while (!cancellationToken.IsCancellationRequested) yield return await ReadAsync(cancellationToken); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hive.Framework [![.NET](https://github.com/Corona-Studio/Hive.Framework/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Corona-Studio/Hive.Framework/actions/workflows/dotnet.yml) 2 | 3 | 蜂巢,一个开源的游戏服务器框架,旨在提供高性能、高扩展性、高度自由的游戏后端服务器的开发流程。(包括一个官方示例实现) 4 | 5 | image 6 | 7 | ## 项目简介 8 | 9 | + BenchmarksAndTests 10 | - Hive.Benchmark: Hive 库性能测试项目 11 | - Hive.Networking.Tests: 网络库单元测试项目 12 | + Codecs 13 | - Hive.Framework.Codec.Abstractions: 编解码器规范抽象,使用该库开发自定义的编解码器 14 | - Hive.Common.Codec.Bson: 基于 Bson 的官方解码器实现 15 | - Hive.Common.Codec.MemoryPack: 基于 MemoryPack 的官方解码器实现 16 | - Hive.Framework.Codec.Protobuf: 基于 ProtoBuf 的官方解码器实现 17 | - Hive.Common.Codec.Shared: 编解码器共用资源 18 | + Common 19 | - Hive.Common.ECS: Hive 官方的基于 ECS 规范实现的服务框架 20 | - Hive.Common.Shared: 共用库,用于存放通用的方法和对象实现 21 | + Networking 22 | - Hive.Framework.Networking.Abstractions: 网络库规范抽象,使用该库开发自定义的网络实现 23 | - Hive.Framework.Networking.Kcp: 基于 KCP 的官方网络库实现 24 | - Hive.Framework.Networking.Quic: 基于 QUIC 的官方网络库实现 25 | - Hive.Framework.Networking.Shared: 网络库共享项目,用于存放网络库的默认抽象和共用方法,使用该库开发自定义的网络实现 26 | - Hive.Framework.Networking.Tcp: 基于 TCP 的官方网络库实现 27 | - Hive.Framework.Networking.Udp: 基于 UDP 的官方网络库实现 28 | + DataSync 29 | - Hive.DataSync: 数据同步器的默认实现 30 | - Hive.DataSync.Abstraction: 数据同步其规范抽象,使用该库开发自定义的同步器实现 31 | - Hive.DataSync.Shared: 共用库,用于存放通用的方法和对象实现 32 | - Hive.DataSync.SourceGen: 为默认实现提供的原生成器库,用来帮助为同步对象生成相对应的属性和方法 33 | -------------------------------------------------------------------------------- /Hive.Network.Udp/UdpSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Hive.Network.Shared.Session; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace Hive.Network.Udp 9 | { 10 | /// 11 | /// 基于 Socket 的 UDP 传输层实现 12 | /// 13 | public class UdpSession : AbstractSession 14 | { 15 | public UdpSession( 16 | int sessionId, 17 | IPEndPoint remoteEndPoint, 18 | IPEndPoint localEndPoint, 19 | ILogger logger) 20 | : base(sessionId, logger) 21 | { 22 | LocalEndPoint = localEndPoint; 23 | RemoteEndPoint = remoteEndPoint; 24 | } 25 | 26 | public override IPEndPoint LocalEndPoint { get; } 27 | 28 | public override IPEndPoint RemoteEndPoint { get; } 29 | 30 | public override bool CanSend => IsConnected; 31 | 32 | public override bool CanReceive => IsConnected; 33 | 34 | public override ValueTask SendOnce(ArraySegment data, CancellationToken token) 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | 39 | public override ValueTask ReceiveOnce(ArraySegment buffer, CancellationToken token) 40 | { 41 | throw new NotImplementedException(); 42 | } 43 | 44 | public override void Close() 45 | { 46 | base.Close(); 47 | 48 | IsConnected = false; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Tools/CI/get_unity_launcher.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | import utils 5 | 6 | artifactory_api_url = "https://artifactory.eu-cph-1.unityops.net" 7 | artifactory_api_repository = "core-automation" 8 | artifactory_download_url = "https://bfartifactory.bf.unity3d.com/artifactory/ie-generic-core-automation" 9 | bokken_artifactory_cache_url = "http://172.28.214.140/" 10 | build_version = '2018.2.*&latest=true' 11 | 12 | def download_unity_launcher(type): 13 | if not os.path.exists(".tmp"): 14 | os.mkdir(".tmp") 15 | download_url = artifactory_download_url 16 | if 'USE_UBERBUCKET' in os.environ: 17 | download_url = bokken_artifactory_cache_url 18 | utils.download_url("%s/tools/unity-launcher/UnityLauncher.%s.zip" % (download_url, type), 19 | ".tmp/UnityLauncher.%s.zip" % type) 20 | 21 | 22 | def extract_unity_launcher(type): 23 | utils.extract_zip(".tmp/UnityLauncher.%s.zip" % type, 24 | ".UnityLauncher.%s" % type) 25 | current_os = utils.get_current_os() 26 | if current_os == "macOS": 27 | os.chmod('.UnityLauncher.{0}/osx.10.12-x64/publish/UnityLauncher.{0}'.format(type), 0755) 28 | elif current_os == "linux": 29 | os.chmod('.UnityLauncher.{0}/linux-x64/publish/UnityLauncher.{0}'.format(type), 0755) 30 | 31 | 32 | def prepare_unity_launcher(run_type): 33 | 34 | download_unity_launcher(run_type) 35 | extract_unity_launcher(run_type) 36 | 37 | def main(): 38 | prepare_unity_launcher("Editor") 39 | return 40 | 41 | 42 | if __name__ == "__main__": 43 | main() 44 | -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics.PerformanceTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Unity.Mathematics.PerformanceTests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Unity.Mathematics.PerformanceTests")] 12 | [assembly: AssemblyCopyright("Copyright © 2019")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("C3FE0F99-88C7-4E54-96A0-B65A591B7020")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Unity.Mathematics/src/Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #if !UNITY_DOTSPLAYER 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("Unity.Mathematics.Tests")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("Unity.Mathematics.Tests")] 14 | [assembly: AssemblyCopyright("Copyright © 2017")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("2e7c74d3-42f1-482f-8bb7-e199d9e3b412")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("1.0.0.0")] 37 | [assembly: AssemblyFileVersion("1.0.0.0")] 38 | #endif -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics.CodeGen~/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | 9 | [assembly: AssemblyTitle("Unity.Mathematics.CodeGen")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("Unity.Mathematics.CodeGen")] 14 | [assembly: AssemblyCopyright("Copyright © 2017")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | 22 | [assembly: ComVisible(false)] 23 | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM 25 | 26 | [assembly: Guid("293EBCD6-CACD-4DA8-A518-FBC629268C0F")] 27 | 28 | // Version information for an assembly consists of the following four values: 29 | // 30 | // Major Version 31 | // Minor Version 32 | // Build Number 33 | // Revision 34 | // 35 | // You can specify all the values or you can default the Build and Revision Numbers 36 | // by using the '*' as shown below: 37 | // [assembly: AssemblyVersion("1.0.*")] 38 | 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Hive.Both.General/Channels/MessageChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Channels; 4 | using System.Threading.Tasks; 5 | using Hive.Both.General.Dispatchers; 6 | using Hive.Network.Abstractions.Session; 7 | 8 | namespace Hive.Both.General.Channels 9 | { 10 | public class MessageChannel : IMessageChannel 11 | { 12 | private readonly Channel _channel = Channel.CreateUnbounded(); 13 | private readonly IDispatcher _dispatcher; 14 | private readonly ISession _session; 15 | 16 | public MessageChannel(ISession session, IDispatcher dispatcher) 17 | { 18 | _session = session; 19 | _dispatcher = dispatcher; 20 | dispatcher.AddHandler(OnReceive); 21 | } 22 | 23 | public ValueTask ReadAsync(CancellationToken token = default) 24 | { 25 | return _channel.Reader.ReadAsync(token); 26 | } 27 | 28 | public ValueTask WriteAsync(TWrite message) 29 | { 30 | return _dispatcher.SendAsync(_session, message); 31 | } 32 | 33 | private void OnReceive(MessageContext context) 34 | { 35 | if (!_channel.Writer.TryWrite(context.Message)) 36 | { 37 | } 38 | } 39 | 40 | ~MessageChannel() 41 | { 42 | try 43 | { 44 | _dispatcher.RemoveHandler(OnReceive); 45 | } 46 | catch (ObjectDisposedException) 47 | { 48 | // Ignore 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Hive.Both.General/Channels/ServerMessageChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Channels; 4 | using System.Threading.Tasks; 5 | using Hive.Both.General.Dispatchers; 6 | using Hive.Network.Abstractions.Session; 7 | 8 | namespace Hive.Both.General.Channels 9 | { 10 | public class ServerMessageChannel : IServerMessageChannel 11 | { 12 | private readonly Channel<(ISession, TRead)> _channel = Channel.CreateUnbounded<(ISession, TRead)>(); 13 | private readonly IDispatcher _dispatcher; 14 | 15 | public ServerMessageChannel(IDispatcher dispatcher) 16 | { 17 | _dispatcher = dispatcher; 18 | _dispatcher.AddHandler(OnReceive); 19 | } 20 | 21 | public ValueTask<(ISession session, TRead message)> ReadAsync(CancellationToken token = default) 22 | { 23 | return _channel.Reader.ReadAsync(token); 24 | } 25 | 26 | public ValueTask WriteAsync(ISession session, TWrite message) 27 | { 28 | return _dispatcher.SendAsync(session, message); 29 | } 30 | 31 | private void OnReceive(MessageContext context) 32 | { 33 | if (!_channel.Writer.TryWrite((context.FromSession, context.Message))) 34 | { 35 | } 36 | } 37 | 38 | ~ServerMessageChannel() 39 | { 40 | try 41 | { 42 | _dispatcher.RemoveHandler(OnReceive); 43 | } 44 | catch (ObjectDisposedException) 45 | { 46 | // Ignore 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.Server.Common.Application/MessageHandlerBinderProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace Hive.Server.Common.Application; 4 | 5 | 6 | public class ChannelHandlerBinderAttribute : Attribute 7 | { 8 | public ChannelHandlerBinderAttribute(Type type) 9 | { 10 | Type = type; 11 | } 12 | 13 | public Type Type { get; } 14 | } 15 | public static class MessageHandlerBinderProvider 16 | { 17 | private static readonly Dictionary BinderCache; 18 | static MessageHandlerBinderProvider() 19 | { 20 | BinderCache = new Dictionary(); 21 | var assemblies = AppDomain.CurrentDomain.GetAssemblies(); 22 | foreach (var assembly in assemblies) 23 | { 24 | foreach (var type in assembly.GetTypes()) 25 | { 26 | var attribute = type.GetCustomAttribute(); 27 | if (attribute != null) 28 | { 29 | if (Activator.CreateInstance(type) is IMessageHandlerBinder binder) 30 | { 31 | BinderCache.Add(attribute.Type,binder); 32 | } 33 | } 34 | } 35 | } 36 | } 37 | public static IMessageHandlerBinder GetHandlerBinder(Type type) 38 | { 39 | lock (BinderCache) 40 | { 41 | if (BinderCache.TryGetValue(type, out var binder)) 42 | { 43 | return binder; 44 | } 45 | throw new InvalidOperationException($"No binder found for type {type}, It should be generated by code generator."); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /Hive.Common.Shared/Helpers/NetworkHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.NetworkInformation; 5 | 6 | namespace Hive.Common.Shared.Helpers 7 | { 8 | public static class NetworkHelper 9 | { 10 | private static readonly Random Random = new((int)DateTime.Now.Ticks); 11 | 12 | /// 13 | /// 获取操作系统已用的端口号 14 | /// 15 | /// 16 | public static HashSet PortIsUsed() 17 | { 18 | //获取本地计算机的网络连接和通信统计数据的信息 19 | var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); 20 | 21 | //返回本地计算机上的所有Tcp监听程序 22 | var ipsTCP = ipGlobalProperties.GetActiveTcpListeners(); 23 | 24 | //返回本地计算机上的所有UDP监听程序 25 | var ipsUDP = ipGlobalProperties.GetActiveUdpListeners(); 26 | 27 | //返回本地计算机上的Internet协议版本4(IPV4 传输控制协议(TCP)连接的信息。 28 | var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); 29 | 30 | var allPorts = ipsTCP.Select(ep => ep.Port).ToList(); 31 | allPorts.AddRange(ipsUDP.Select(ep => ep.Port)); 32 | allPorts.AddRange(tcpConnInfoArray.Select(conn => conn.LocalEndPoint.Port)); 33 | 34 | return new HashSet(allPorts); 35 | } 36 | 37 | public static int GetRandomPort() 38 | { 39 | var hasUsedPort = PortIsUsed(); 40 | var port = 0; 41 | var isRandomOk = true; 42 | 43 | while (isRandomOk) 44 | { 45 | port = Random.Next(1024, 65535); 46 | isRandomOk = hasUsedPort.Contains(port); 47 | } 48 | 49 | return port; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Unity.Mathematics/src/Unity.Mathematics/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using System.Runtime.InteropServices; 3 | 4 | #if !UNITY_DOTSPLAYER 5 | using System.Reflection; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | 11 | [assembly: AssemblyTitle("Unity.Mathematics")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("Unity.Mathematics")] 16 | [assembly: AssemblyCopyright("Copyright © 2017")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | 28 | [assembly: Guid("19810344-7387-4155-935F-BDD5CC61F0BF")] 29 | 30 | // Version information for an assembly consists of the following four values: 31 | // 32 | // Major Version 33 | // Minor Version 34 | // Build Number 35 | // Revision 36 | // 37 | // You can specify all the values or you can default the Build and Revision Numbers 38 | // by using the '*' as shown below: 39 | // [assembly: AssemblyVersion("1.0.*")] 40 | 41 | [assembly: AssemblyVersion("1.0.0.0")] 42 | [assembly: AssemblyFileVersion("1.0.0.0")] 43 | #endif 44 | 45 | [assembly: InternalsVisibleTo("Unity.Mathematics.Tests")] 46 | [assembly: InternalsVisibleTo("Unity.Mathematics.PerformanceTests")] 47 | [assembly: InternalsVisibleTo("btests")] -------------------------------------------------------------------------------- /Hive.Network.Abstractions/Session/IAcceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Hive.Network.Abstractions.Session; 8 | 9 | public interface IAcceptor : IDisposable 10 | { 11 | event Func OnSessionCreateAsync; 12 | 13 | event Action OnSessionCreated; 14 | 15 | /// 16 | /// 连接意外关闭时触发,主动关闭时不会触发 17 | /// 18 | event Action OnSessionClosed; 19 | 20 | ISession? GetSession(SessionId sessionId); 21 | Task SetupAsync(IPEndPoint listenEndPoint, CancellationToken token); 22 | Task StartAcceptLoop(CancellationToken token); 23 | Task TryCloseAsync(CancellationToken token); 24 | ValueTask TryDoOnceAcceptAsync(CancellationToken token); 25 | 26 | ValueTask TrySendToAsync(SessionId sessionId, MemoryStream buffer, CancellationToken token = default); 27 | ValueTask SendToAsync(SessionId sessionId, MemoryStream buffer, CancellationToken token = default); 28 | } 29 | 30 | /// 31 | /// 代表一个接入连接接收器 32 | /// 33 | public interface IAcceptor : IAcceptor where TSession : ISession 34 | { 35 | bool IsValid { get; } 36 | 37 | /// 38 | /// True if the acceptor is running in a separate thread and managed by itself. 39 | /// 40 | bool IsSelfRunning { get; } 41 | 42 | new event Func OnSessionCreateAsync; 43 | 44 | new event Action OnSessionCreated; 45 | 46 | /// 47 | /// 连接意外关闭时触发,主动关闭时不会触发 48 | /// 49 | new event Action OnSessionClosed; 50 | 51 | new TSession? GetSession(SessionId sessionId); 52 | } -------------------------------------------------------------------------------- /Hive.Codec.Shared/AbstractPacketCodec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Buffers; 3 | using System.IO; 4 | using Hive.Codec.Abstractions; 5 | 6 | namespace Hive.Codec.Shared; 7 | 8 | public abstract class AbstractPacketCodec : IPacketCodec 9 | { 10 | private readonly ICustomCodecProvider _customCodecProvider; 11 | private readonly IPacketIdMapper _packetIdMapper; 12 | 13 | protected AbstractPacketCodec(IPacketIdMapper packetIdMapper, ICustomCodecProvider customCodecProvider) 14 | { 15 | _packetIdMapper = packetIdMapper; 16 | _customCodecProvider = customCodecProvider; 17 | } 18 | 19 | public int Encode(T message, Stream writer) 20 | { 21 | var id = _packetIdMapper.GetPacketId(typeof(T)); 22 | 23 | Span buffer = stackalloc byte[PacketId.Size]; 24 | id.WriteTo(buffer); 25 | 26 | writer.Write(buffer); 27 | 28 | var packetCodec = _customCodecProvider.GetPacketCodec(id); 29 | var bodyLength = packetCodec?.EncodeBody(message, writer) ?? EncodeBody(message, writer); 30 | 31 | return PacketId.Size + bodyLength; 32 | } 33 | 34 | public object? Decode(ReadOnlySequence buffer) 35 | { 36 | if (buffer.Length < PacketId.Size) 37 | throw new InvalidDataException($"Invalid packet id size: {buffer.Length}"); 38 | 39 | var packetId = PacketId.From(buffer); 40 | var type = _packetIdMapper.GetPacketType(packetId); 41 | var packetCodec = _customCodecProvider.GetPacketCodec(packetId); 42 | var bodySlice = buffer.Slice(PacketId.Size); 43 | 44 | return packetCodec != null 45 | ? packetCodec.DecodeBody(bodySlice, type) 46 | : DecodeBody(bodySlice, type); 47 | } 48 | 49 | protected abstract int EncodeBody(T message, Stream stream); 50 | 51 | protected abstract object? DecodeBody(ReadOnlySequence buffer, Type type); 52 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/PositionalEntity.cs: -------------------------------------------------------------------------------- 1 | using Unity.Mathematics; 2 | 3 | namespace Hive.Common.ECS.Entity; 4 | 5 | public sealed class PositionalEntity : ObjectEntity 6 | { 7 | private float4x4 _localMatrix; 8 | private float4x4 _worldMatrix; 9 | 10 | public float4x4 WorldMatrix 11 | { 12 | get => _worldMatrix; 13 | set 14 | { 15 | _worldMatrix = value; 16 | UpdateLocalMatrix(); 17 | UpdateChildrenWorldMatrix(); 18 | } 19 | } 20 | 21 | public float4x4 LocalMatrix 22 | { 23 | get => _localMatrix; 24 | set 25 | { 26 | _localMatrix = value; 27 | UpdateWorldMatrix(); 28 | } 29 | } 30 | 31 | public override IEntity Parent 32 | { 33 | get => parent; 34 | set 35 | { 36 | base.Parent = value; 37 | UpdateLocalMatrix(); 38 | } 39 | } 40 | 41 | private void UpdateWorldMatrix() 42 | { 43 | if (parent is PositionalEntity positionalParent) 44 | _worldMatrix = positionalParent.WorldMatrix * _localMatrix; 45 | else 46 | _worldMatrix = _localMatrix; 47 | 48 | UpdateChildrenWorldMatrix(); 49 | } 50 | 51 | private void UpdateChildrenWorldMatrix() 52 | { 53 | // ReSharper disable once ForCanBeConvertedToForeach 54 | for (var i = 0; i < Children.Count; i++) 55 | { 56 | var child = Children[i]; 57 | if (child is PositionalEntity positionalEntity) 58 | positionalEntity.UpdateWorldMatrix(); 59 | } 60 | } 61 | 62 | private void UpdateLocalMatrix() 63 | { 64 | if (parent is PositionalEntity positionalParent) 65 | _localMatrix = math.inverse(positionalParent._worldMatrix) * _worldMatrix; 66 | else 67 | _localMatrix = _worldMatrix; 68 | } 69 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/ECS/EntityTest.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Entity; 2 | 3 | namespace Hive.Network.Tests.ECS; 4 | 5 | public class EntityTest 6 | { 7 | [Test] 8 | [Author("Leon")] 9 | [Description("测试Entity的层序遍历")] 10 | public void TestEntityBfsEnumerator() 11 | { 12 | IEntity root = new RootEntity(null) { InstanceId = 0 }; 13 | var world = new WorldEntity { InstanceId = 1 }; 14 | world.Parent = root; 15 | new ObjectEntity { InstanceId = 2 }.Parent = world; 16 | new ObjectEntity { InstanceId = 3 }.Parent = world; 17 | new ObjectEntity { InstanceId = 4 }.Parent = world; 18 | new ObjectEntity { InstanceId = 5 }.Parent = world; 19 | 20 | new ObjectEntity { InstanceId = 6 }.Parent = world.Children[1]; 21 | new ObjectEntity { InstanceId = 7 }.Parent = world.Children[1]; 22 | new ObjectEntity { InstanceId = 8 }.Parent = world.Children[1]; 23 | 24 | new ObjectEntity { InstanceId = 9 }.Parent = world.Children[3]; 25 | new ObjectEntity { InstanceId = 10 }.Parent = world.Children[3]; 26 | new ObjectEntity { InstanceId = 11 }.Parent = world.Children[3]; 27 | 28 | new ObjectEntity { InstanceId = 12 }.Parent = world.Children[1].Children[1]; 29 | new ObjectEntity { InstanceId = 13 }.Parent = world.Children[1].Children[1]; 30 | new ObjectEntity { InstanceId = 14 }.Parent = world.Children[1].Children[1]; 31 | 32 | var correctResult = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; 33 | 34 | var curIndex = 0; 35 | foreach (var entity in root.GetBFSEnumerator()) 36 | { 37 | if (entity.InstanceId != correctResult[curIndex]) Assert.Fail(); 38 | 39 | Console.WriteLine(entity.InstanceId); 40 | curIndex++; 41 | } 42 | 43 | if (curIndex < correctResult.Length) 44 | Assert.Fail(); 45 | 46 | Assert.Pass(); 47 | } 48 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Collections/MultiDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hive.Common.Shared.Collections 5 | { 6 | public class MultiDictionary : Dictionary> 7 | { 8 | /// 9 | /// 返回内部的list 10 | /// 11 | /// 12 | /// 13 | public new List? this[TK t] 14 | { 15 | get 16 | { 17 | TryGetValue(t, out var list); 18 | return list; 19 | } 20 | } 21 | 22 | public void Add(TK t, TV k) 23 | { 24 | TryGetValue(t, out var list); 25 | if (list == null) 26 | { 27 | list = new List(); 28 | base[t] = list; 29 | } 30 | 31 | list.Add(k); 32 | } 33 | 34 | public bool Remove(TK t, TV k) 35 | { 36 | TryGetValue(t, out var list); 37 | if (list == null || !list.Remove(k)) 38 | return false; 39 | 40 | if (list.Count == 0) 41 | Remove(t); 42 | 43 | return true; 44 | } 45 | 46 | /// 47 | /// 不返回内部的list,copy一份出来 48 | /// 49 | /// 50 | /// 51 | public TV[] GetAll(TK t) 52 | { 53 | TryGetValue(t, out var list); 54 | return list == null ? Array.Empty() : list.ToArray(); 55 | } 56 | 57 | public TV? GetOne(TK t) 58 | { 59 | TryGetValue(t, out var list); 60 | return list?.Count > 0 ? list[0] : default; 61 | } 62 | 63 | public bool Contains(TK t, TV k) 64 | { 65 | TryGetValue(t, out var list); 66 | return list != null && list.Contains(k); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Hive.Network.Udp/UdpServerSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Hive.Network.Shared; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace Hive.Network.Udp 9 | { 10 | /// 11 | /// 基于 Socket 的 UDP 传输层实现 12 | /// 13 | public sealed class UdpServerSession : UdpSession 14 | { 15 | public UdpServerSession( 16 | int sessionId, 17 | IPEndPoint remoteEndPoint, 18 | IPEndPoint localEndPoint, 19 | ILogger logger) 20 | : base(sessionId, remoteEndPoint, localEndPoint, logger) 21 | { 22 | } 23 | 24 | public event Func, IPEndPoint, CancellationToken, ValueTask>? OnSendAsync; 25 | 26 | public override ValueTask SendOnce(ArraySegment data, CancellationToken token) 27 | { 28 | if (!IsConnected) 29 | return new ValueTask(0); 30 | 31 | return OnSendAsync?.Invoke(data, RemoteEndPoint, token) ?? new ValueTask(0); 32 | } 33 | 34 | internal async ValueTask OnReceivedAsync(Memory memory, CancellationToken token) 35 | { 36 | if (!IsConnected) return; 37 | if (ReceivePipe == null) 38 | throw new NullReferenceException(nameof(ReceivePipe)); 39 | 40 | var buffer = ReceivePipe.Writer.GetMemory(NetworkSettings.DefaultBufferSize); 41 | 42 | memory.Span.CopyTo(buffer.Span); 43 | ReceivePipe.Writer.Advance(memory.Length); 44 | 45 | var flushResult = await ReceivePipe.Writer.FlushAsync(token); 46 | 47 | if (flushResult.IsCompleted) 48 | IsConnected = false; 49 | } 50 | 51 | public override ValueTask ReceiveOnce(ArraySegment buffer, CancellationToken token) 52 | { 53 | return new ValueTask(0); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/UInt64SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class UInt64SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public UInt64SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | ulong newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | var totalLength = sizeof(ushort) + sizeof(ulong) + propertyNameMemory.Length; 23 | var result = new Memory(new byte[totalLength]); 24 | 25 | var index = 0; 26 | 27 | BitConverter.TryWriteBytes( 28 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 29 | ObjectSyncId); 30 | BitConverter.TryWriteBytes( 31 | result.Span.SliceAndIncrement(ref index, sizeof(ulong)), 32 | NewValue); 33 | propertyNameMemory 34 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 35 | 36 | return result; 37 | } 38 | 39 | public static UInt64SyncPacket Deserialize(ReadOnlyMemory memory) 40 | { 41 | var index = 0; 42 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 43 | var newValue = BitConverter.ToUInt64(memory.Span.SliceAndIncrement(ref index, sizeof(ulong))); 44 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 45 | 46 | return new UInt64SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Hive.DataSync.SourceGen/Helpers/NamespaceHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Hive.DataSync.SourceGen.Helpers; 4 | 5 | public static class NamespaceHelper 6 | { 7 | public static string GetNamespace(BaseTypeDeclarationSyntax syntax) 8 | { 9 | // If we don't have a namespace at all we'll return an empty string 10 | // This accounts for the "default namespace" case 11 | var nameSpace = string.Empty; 12 | 13 | // Get the containing syntax node for the type declaration 14 | // (could be a nested type, for example) 15 | var potentialNamespaceParent = syntax.Parent; 16 | 17 | // Keep moving "out" of nested classes etc until we get to a namespace 18 | // or until we run out of parents 19 | while (potentialNamespaceParent != null && 20 | potentialNamespaceParent is not NamespaceDeclarationSyntax 21 | && potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax) 22 | potentialNamespaceParent = potentialNamespaceParent.Parent; 23 | 24 | // Build up the final namespace by looping until we no longer have a namespace declaration 25 | if (potentialNamespaceParent is BaseNamespaceDeclarationSyntax namespaceParent) 26 | { 27 | // We have a namespace. Use that as the type 28 | nameSpace = namespaceParent.Name.ToString(); 29 | 30 | // Keep moving "out" of the namespace declarations until we 31 | // run out of nested namespace declarations 32 | while (true) 33 | { 34 | if (namespaceParent.Parent is not NamespaceDeclarationSyntax parent) break; 35 | 36 | // Add the outer namespace as a prefix to the final namespace 37 | nameSpace = $"{namespaceParent.Name}.{nameSpace}"; 38 | namespaceParent = parent; 39 | } 40 | } 41 | 42 | // return the final namespace 43 | return nameSpace; 44 | } 45 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/Entity/Entity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | 5 | namespace Hive.Common.ECS.Entity; 6 | 7 | public class Entity : IEntity 8 | { 9 | //private readonly MultiDictionary _componentMap = new(); 10 | 11 | private static readonly ReadOnlyCollection EmptyChildrenCollection = new(Array.Empty()); 12 | 13 | private List? _children; 14 | private ReadOnlyCollection? _readOnlyChildrenCollection; 15 | protected IEntity parent; 16 | 17 | internal Entity() 18 | { 19 | } 20 | 21 | public IECSArch ECSArch { get; protected set; } 22 | public string Name { get; set; } = string.Empty; 23 | public int Depth { get; private set; } 24 | 25 | public ReadOnlyCollection Children 26 | { 27 | get 28 | { 29 | if (_children == null) 30 | return EmptyChildrenCollection; 31 | 32 | return _readOnlyChildrenCollection ??= new ReadOnlyCollection(_children); 33 | } 34 | } 35 | 36 | public virtual IEntity? Parent 37 | { 38 | get => parent; 39 | set 40 | { 41 | if (parent == value) return; 42 | 43 | if (parent is Entity entityParent) 44 | entityParent.RemoveChildren(this); 45 | 46 | parent = value; 47 | 48 | if (parent is Entity newEntityParent) newEntityParent.AddChildren(this); 49 | 50 | Depth = parent == null ? 0 : parent.Depth + 1; 51 | if (parent != null) 52 | ECSArch = parent.ECSArch; 53 | } 54 | } 55 | 56 | public long InstanceId { get; init; } 57 | 58 | protected virtual void AddChildren(IEntity entity) 59 | { 60 | _children ??= new List(); 61 | 62 | _children.Add(entity); 63 | } 64 | 65 | protected virtual void RemoveChildren(IEntity entity) 66 | { 67 | _children?.Remove(entity); 68 | } 69 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/CharSyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class CharSyncPacket : AbstractObjectSyncPacket 9 | { 10 | public CharSyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | char newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(char) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(char)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static CharSyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToChar(memory.Span.SliceAndIncrement(ref index, sizeof(char))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new CharSyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/Int32SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class Int32SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public Int32SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | int newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(int) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(int)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static Int32SyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToInt32(memory.Span.SliceAndIncrement(ref index, sizeof(int))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new Int32SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/Int64SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class Int64SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public Int64SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | long newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(long) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(long)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static Int64SyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToInt64(memory.Span.SliceAndIncrement(ref index, sizeof(long))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new Int64SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/System/PhaseInterfaceType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Hive.Common.ECS.System.Phases; 4 | 5 | namespace Hive.Common.ECS.System; 6 | 7 | public struct PhaseInterfaceType 8 | { 9 | public static readonly PhaseInterfaceType AwakeInterfaceType = typeof(IAwakeSystem); 10 | public static readonly PhaseInterfaceType LogicUpdateInterfaceType = typeof(ILogicUpdateSystem); 11 | public static readonly PhaseInterfaceType FrameUpdateInterfaceType = typeof(IFrameUpdateSystem); 12 | public static readonly PhaseInterfaceType DestroyInterfaceType = typeof(IDestroySystem); 13 | 14 | public static readonly Dictionary PhaseToInterfaceTypeDict = new() 15 | { 16 | { SystemPhase.Awake, AwakeInterfaceType }, 17 | { SystemPhase.LogicUpdate, LogicUpdateInterfaceType }, 18 | { SystemPhase.FrameUpdate, FrameUpdateInterfaceType }, 19 | { SystemPhase.Destroy, DestroyInterfaceType } 20 | }; 21 | 22 | public static PhaseInterfaceType GetInterfaceBySystemPhase(SystemPhase phase) 23 | { 24 | return PhaseToInterfaceTypeDict[phase]; 25 | } 26 | 27 | public static IEnumerable AllInterfaceTypes => PhaseToInterfaceTypeDict.Values; 28 | 29 | public Type type; 30 | 31 | public PhaseInterfaceType(Type type) 32 | { 33 | this.type = type; 34 | } 35 | 36 | public static implicit operator PhaseInterfaceType(Type type) 37 | { 38 | return new PhaseInterfaceType(type); 39 | } 40 | 41 | public bool Equals(PhaseInterfaceType other) 42 | { 43 | return type == other.type; 44 | } 45 | 46 | public override bool Equals(object? obj) 47 | { 48 | return obj is PhaseInterfaceType other && Equals(other); 49 | } 50 | 51 | public override int GetHashCode() 52 | { 53 | return type != null ? type.GetHashCode() : 0; 54 | } 55 | } 56 | 57 | public enum SystemPhase 58 | { 59 | Awake, 60 | LogicUpdate, 61 | FrameUpdate, 62 | Destroy 63 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/Int16SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class Int16SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public Int16SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | short newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(short) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(short)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static Int16SyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToInt16(memory.Span.SliceAndIncrement(ref index, sizeof(short))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new Int16SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/UInt32SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class UInt32SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public UInt32SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | uint newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(uint) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(uint)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static UInt32SyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToUInt32(memory.Span.SliceAndIncrement(ref index, sizeof(uint))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new UInt32SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.Network.Tests/ECS/SystemManagerTest.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.ECS.Attributes.System; 2 | using Hive.Common.ECS.Entity; 3 | using Hive.Common.ECS.System; 4 | using Hive.Common.ECS.System.Phases; 5 | 6 | namespace Hive.Network.Tests.ECS; 7 | 8 | public class SystemManagerTest 9 | { 10 | // A Test behaves as an ordinary method 11 | [Test] 12 | public void TestExecutionOrderComputation() 13 | { 14 | var systemManager = new SystemManager(null); 15 | var systems = new IAwakeSystem[] 16 | { 17 | new TestSystem1(), 18 | new TestSystem2(), 19 | new TestSystem3(), 20 | new TestSystem4() 21 | }; 22 | 23 | foreach (var system in systems) systemManager.RegisterSystem(system); 24 | 25 | systemManager.RecomputeExecutionOrder(); 26 | 27 | var orderedExecutionSequence = systemManager.GetOrderedExecutionSequence(typeof(IAwakeSystem)).ToList(); 28 | 29 | var indexOfSystem = 30 | orderedExecutionSequence.ToDictionary(warp => warp.System, warp => orderedExecutionSequence.IndexOf(warp)); 31 | 32 | Assert.That(indexOfSystem[systems[3]] > indexOfSystem[systems[1]] && 33 | indexOfSystem[systems[3]] < indexOfSystem[systems[2]]); 34 | } 35 | 36 | private class TestSystem1 : IAwakeSystem 37 | { 38 | public void OnAwake(IEntity entity) 39 | { 40 | } 41 | } 42 | 43 | [ExecuteBefore(typeof(TestSystem3))] 44 | private class TestSystem2 : IAwakeSystem 45 | { 46 | public void OnAwake(IEntity entity) 47 | { 48 | } 49 | } 50 | 51 | [ExecuteAfter(typeof(TestSystem2))] 52 | private class TestSystem3 : IAwakeSystem 53 | { 54 | public void OnAwake(IEntity entity) 55 | { 56 | } 57 | } 58 | 59 | [ExecuteBefore(typeof(TestSystem3))] 60 | [ExecuteAfter(typeof(TestSystem2))] 61 | private class TestSystem4 : IAwakeSystem 62 | { 63 | public void OnAwake(IEntity entity) 64 | { 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Helpers/MemoryHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace Hive.Common.Shared.Helpers 5 | { 6 | public static class MemoryHelper 7 | { 8 | public static Span SliceAndIncrement(this Span span, ref int index, int length) 9 | { 10 | var result = span.Slice(index, length); 11 | 12 | index += length; 13 | 14 | return result; 15 | } 16 | 17 | public static ReadOnlySpan SliceAndIncrement(this ReadOnlySpan span, ref int index, int length) 18 | { 19 | var result = span.Slice(index, length); 20 | 21 | index += length; 22 | 23 | return result; 24 | } 25 | 26 | public static Memory SliceAndIncrement(this Memory span, ref int index, int length) 27 | { 28 | var result = span.Slice(index, length); 29 | 30 | index += length; 31 | 32 | return result; 33 | } 34 | 35 | public static Memory Copy(this Memory old) 36 | { 37 | var result = new Memory(new T[old.Length]); 38 | 39 | old.CopyTo(result); 40 | 41 | return result; 42 | } 43 | 44 | public static ReadOnlyMemory Copy(this ReadOnlyMemory old) 45 | { 46 | var result = new Memory(new T[old.Length]); 47 | 48 | old.CopyTo(result); 49 | 50 | return result; 51 | } 52 | 53 | public static ReadOnlyMemory CombineMemory(params ReadOnlyMemory[] memories) 54 | { 55 | var totalSize = memories.Sum(m => m.Length); 56 | var result = new Memory(new byte[totalSize]); 57 | 58 | var index = 0; 59 | 60 | foreach (var memory in memories) 61 | { 62 | if (memory.IsEmpty) continue; 63 | memory.Span.CopyTo(result.Span.SliceAndIncrement(ref index, memory.Length)); 64 | } 65 | 66 | return result; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/SingleSyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class SingleSyncPacket : AbstractObjectSyncPacket 9 | { 10 | public SingleSyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | float newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(float) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(float)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static SingleSyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToSingle(memory.Span.SliceAndIncrement(ref index, sizeof(float))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new SingleSyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/BooleanSyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class BooleanSyncPacket : AbstractObjectSyncPacket 9 | { 10 | public BooleanSyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | bool newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(bool) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(bool)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static BooleanSyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToBoolean(memory.Span.SliceAndIncrement(ref index, sizeof(bool))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new BooleanSyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/DoubleSyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class DoubleSyncPacket : AbstractObjectSyncPacket 9 | { 10 | public DoubleSyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | double newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(double) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(double)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static DoubleSyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToDouble(memory.Span.SliceAndIncrement(ref index, sizeof(double))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new DoubleSyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.DataSync.Shared/ObjectSyncPacket/UInt16SyncPacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | 6 | namespace Hive.DataSync.Shared.ObjectSyncPacket 7 | { 8 | public class UInt16SyncPacket : AbstractObjectSyncPacket 9 | { 10 | public UInt16SyncPacket( 11 | ushort objectSyncId, 12 | string propertyName, 13 | SyncOptions syncOptions, 14 | ushort newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 15 | { 16 | } 17 | 18 | public override ReadOnlyMemory Serialize() 19 | { 20 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 21 | 22 | // [OBJ_SYNC_ID (2) | NEW_VAL | PROPERTY_NAME] 23 | var totalLength = sizeof(ushort) + sizeof(ushort) + propertyNameMemory.Length; 24 | var result = new Memory(new byte[totalLength]); 25 | 26 | var index = 0; 27 | 28 | BitConverter.TryWriteBytes( 29 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 30 | ObjectSyncId); 31 | BitConverter.TryWriteBytes( 32 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 33 | NewValue); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static UInt16SyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new UInt16SyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Hive.Common.ECS/ECSArch.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Hive.Common.ECS.Component; 3 | using Hive.Common.ECS.Compositor; 4 | using Hive.Common.ECS.Entity; 5 | using Hive.Common.ECS.System; 6 | 7 | namespace Hive.Common.ECS; 8 | 9 | // ReSharper disable once InconsistentNaming 10 | public class ECSCore : IECSArch 11 | { 12 | public ECSCore() 13 | { 14 | SystemManager = new SystemManager(this); 15 | EntityManager = new EntityManager(this); 16 | ComponentManager = new ComponentManager(this); 17 | } 18 | 19 | public SystemManager SystemManager { get; } 20 | public EntityManager EntityManager { get; } 21 | public ComponentManager ComponentManager { get; } 22 | 23 | public void Instantiate(IEntity? parent = null) where TCompositor : ICompositor 24 | { 25 | EntityManager.Instantiate(parent); 26 | } 27 | 28 | public void Destroy(IEntity entity) 29 | { 30 | EntityManager.Destroy(entity); 31 | } 32 | 33 | public void AddSystem() where T : ISystem, new() 34 | { 35 | var system = new T(); 36 | AddSystem(system); 37 | } 38 | 39 | public void AddSystem(T system) where T : ISystem 40 | { 41 | SystemManager.RegisterSystem(system); 42 | } 43 | 44 | public void LastUpdate() 45 | { 46 | SystemManager.ExecuteSystems(SystemPhase.Awake, EntityManager.GetEntityReadyToAwake().ToList()); 47 | EntityManager.ApplyAwake(); 48 | } 49 | 50 | public void LastPostLateUpdate() 51 | { 52 | SystemManager.ExecuteSystems(SystemPhase.Destroy, EntityManager.GetEntityReadyToDestroy().ToList()); 53 | EntityManager.ApplyDestroy(); 54 | EntityManager.UpdateBfsEnumerateList(); 55 | } 56 | 57 | public void FixedUpdate() 58 | { 59 | SystemManager.ExecuteSystems(SystemPhase.LogicUpdate, EntityManager.EntityBfsEnumerateList); 60 | } 61 | 62 | public void Update() 63 | { 64 | SystemManager.ExecuteSystems(SystemPhase.FrameUpdate, EntityManager.EntityBfsEnumerateList); 65 | } 66 | } -------------------------------------------------------------------------------- /Hive.Application.Test/ServiceProviderHelper.cs: -------------------------------------------------------------------------------- 1 | using Hive.Application.Test.TestMessage; 2 | using Hive.Both.General.Dispatchers; 3 | using Hive.Codec.Abstractions; 4 | using Hive.Codec.Shared; 5 | using Hive.Network.Abstractions.Session; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace Hive.Application.Test; 10 | 11 | public static class ServiceProviderHelper 12 | { 13 | public static void BuildSession(this ServiceCollection services) 14 | where TAcceptor : class, IAcceptor 15 | where TConnector : class, IConnector 16 | where TSession : class, ISession 17 | where TCodec : class, IPacketCodec 18 | { 19 | services.AddSingleton(); 20 | services.AddSingleton(); 21 | services.AddSingleton(); 22 | services.AddTransient(); 23 | services.AddSingleton, TAcceptor>(); 24 | services.AddSingleton, TConnector>(); 25 | } 26 | 27 | public static IServiceProvider GetServiceProvider() 28 | where TAcceptor : class, IAcceptor 29 | where TConnector : class, IConnector 30 | where TSession : class, ISession 31 | where TCodec : class, IPacketCodec 32 | { 33 | var services = new ServiceCollection(); 34 | 35 | services.AddLogging(builder => 36 | { 37 | builder.AddConsole(); 38 | builder.SetMinimumLevel(LogLevel.Trace); 39 | }); 40 | 41 | services.BuildSession(); 42 | 43 | services.AddSingleton(); 44 | 45 | services.Configure(options => 46 | { 47 | options.Register(); 48 | }); 49 | 50 | return services.BuildServiceProvider(); 51 | } 52 | } -------------------------------------------------------------------------------- /Hive.Server.App/ServiceManager.cs: -------------------------------------------------------------------------------- 1 | using Hive.Common.Shared.Collections; 2 | 3 | namespace Hive.Server.App; 4 | 5 | public class ServiceManager 6 | { 7 | private readonly ReaderWriterLockSlim _lock = new(); 8 | private Dictionary Services { get; } = new(); 9 | private MultiHashSetDictionary HostToServiceNames { get; } = new(); 10 | 11 | public bool AddService(ServiceAddress serviceAddress) 12 | { 13 | if (!_lock.TryEnterWriteLock(1000)) return false; 14 | 15 | try 16 | { 17 | if (Services.TryAdd(serviceAddress.ServiceName, serviceAddress)) 18 | { 19 | HostToServiceNames.Add(serviceAddress.HostId, serviceAddress.ServiceName); 20 | return true; 21 | } 22 | } 23 | finally 24 | { 25 | _lock.ExitWriteLock(); 26 | } 27 | 28 | return false; 29 | } 30 | 31 | public bool RemoveService(string serviceName) 32 | { 33 | if (!_lock.TryEnterWriteLock(1000)) return false; 34 | try 35 | { 36 | Services.Remove(serviceName); 37 | } 38 | finally 39 | { 40 | _lock.ExitWriteLock(); 41 | } 42 | 43 | return true; 44 | } 45 | 46 | public bool RemoveServiceOfHost(int hostId) 47 | { 48 | if (_lock.TryEnterUpgradeableReadLock(1000)) 49 | try 50 | { 51 | var serviceNames = HostToServiceNames[hostId]; 52 | if (serviceNames == null) return false; 53 | 54 | if (!_lock.TryEnterWriteLock(1000)) return false; 55 | 56 | try 57 | { 58 | foreach (var name in serviceNames) Services.Remove(name); 59 | 60 | return true; 61 | } 62 | finally 63 | { 64 | _lock.ExitWriteLock(); 65 | } 66 | } 67 | finally 68 | { 69 | _lock.ExitUpgradeableReadLock(); 70 | } 71 | 72 | return false; 73 | } 74 | } -------------------------------------------------------------------------------- /Hive.Network.Shared/HandShake/HandShakePacket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hive.Network.Abstractions; 3 | 4 | namespace Hive.Network.Shared.HandShake 5 | { 6 | public struct HandShakePacket 7 | { 8 | public static int Size => 12 + SessionId.Size; 9 | public int Syn; 10 | public int State; 11 | public SessionId SessionId; 12 | 13 | public readonly void WriteTo(Span span) 14 | { 15 | BitConverter.TryWriteBytes(span[..], 0x1140403); 16 | BitConverter.TryWriteBytes(span[4..], Syn); 17 | BitConverter.TryWriteBytes(span[8..], State); 18 | BitConverter.TryWriteBytes(span[12..], SessionId); 19 | } 20 | 21 | public readonly bool IsHeaderValid(Span span) 22 | { 23 | return BitConverter.ToInt32(span[4..]) == 0x1140403; 24 | } 25 | 26 | public readonly bool IsServerFinished() 27 | { 28 | return State == 2; 29 | } 30 | 31 | public readonly bool IsClientFinished() 32 | { 33 | return State == 3; 34 | } 35 | 36 | public readonly bool IsResponseOf(HandShakePacket packet) 37 | { 38 | return Syn == packet.Syn + 1 && State == packet.State + 1; 39 | } 40 | 41 | public HandShakePacket CreateFinal(SessionId sessionId) 42 | { 43 | return new HandShakePacket 44 | { 45 | Syn = Syn + 1, 46 | State = 3, 47 | SessionId = sessionId 48 | }; 49 | } 50 | 51 | public HandShakePacket Next() 52 | { 53 | return new HandShakePacket 54 | { 55 | Syn = Syn + 1, 56 | State = State + 1 57 | }; 58 | } 59 | 60 | public static HandShakePacket ReadFrom(ReadOnlySpan span) 61 | { 62 | return new HandShakePacket 63 | { 64 | Syn = BitConverter.ToInt32(span[4..]), 65 | State = BitConverter.ToInt32(span[8..]), 66 | SessionId = SessionId.FromSpan(span[12..]) 67 | }; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /Hive.Common.Shared/Collections/MultiHashSetDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Hive.Common.Shared.Collections 5 | { 6 | public class MultiHashSetDictionary : Dictionary> 7 | { 8 | /// 9 | /// 返回内部的list 10 | /// 11 | /// 12 | /// 13 | public new HashSet? this[TK t] 14 | { 15 | get 16 | { 17 | TryGetValue(t, out var list); 18 | return list; 19 | } 20 | } 21 | 22 | public void Add(TK key, TV value) 23 | { 24 | TryGetValue(key, out var list); 25 | if (list == null) 26 | { 27 | list = new HashSet(); 28 | base[key] = list; 29 | } 30 | 31 | list.Add(value); 32 | } 33 | 34 | public bool Remove(TK t, TV k) 35 | { 36 | TryGetValue(t, out var list); 37 | if (list == null || !list.Remove(k)) 38 | return false; 39 | 40 | if (list.Count == 0) 41 | Remove(t); 42 | 43 | return true; 44 | } 45 | 46 | /// 47 | /// 不返回内部的list,copy一份出来 48 | /// 49 | /// 50 | /// 51 | /// True if it is not empty 52 | public bool GetAll(TK key, List outList) 53 | { 54 | TryGetValue(key, out var set); 55 | outList.Clear(); 56 | 57 | if (set == null) return false; 58 | 59 | outList.AddRange(set); 60 | return true; 61 | } 62 | 63 | public TV? GetOne(TK t) 64 | { 65 | TryGetValue(t, out var list); 66 | return list != null ? list.FirstOrDefault() : default; 67 | } 68 | 69 | public bool Contains(TK key, TV value) 70 | { 71 | TryGetValue(key, out var set); 72 | return set != null && set.Contains(value); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /Hive.DataSync.SourceGen.Tests/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Hive.Common.Shared; 4 | using Hive.Common.Shared.Helpers; 5 | using Hive.DataSync.Shared.Attributes; 6 | using Hive.DataSync.Shared.ObjectSyncPacket; 7 | 8 | namespace Hive.DataSync.SourceGen.Tests; 9 | 10 | public class GuidSyncPacket : AbstractObjectSyncPacket 11 | { 12 | public GuidSyncPacket( 13 | ushort objectSyncId, 14 | string propertyName, 15 | SyncOptions syncOptions, 16 | Guid newValue) : base(objectSyncId, propertyName, syncOptions, newValue) 17 | { 18 | } 19 | 20 | public override ReadOnlyMemory Serialize() 21 | { 22 | var propertyNameMemory = Encoding.UTF8.GetBytes(PropertyName).AsSpan(); 23 | 24 | var totalLength = sizeof(ushort) + 16 + propertyNameMemory.Length; 25 | var result = new Memory(new byte[totalLength]); 26 | 27 | var index = 0; 28 | 29 | BitConverter.TryWriteBytes( 30 | result.Span.SliceAndIncrement(ref index, sizeof(ushort)), 31 | ObjectSyncId); 32 | NewValue.ToByteArray().AsSpan() 33 | .CopyTo(result.Span.SliceAndIncrement(ref index, 16)); 34 | propertyNameMemory 35 | .CopyTo(result.Span.SliceAndIncrement(ref index, propertyNameMemory.Length)); 36 | 37 | return result; 38 | } 39 | 40 | public static AbstractObjectSyncPacket Deserialize(ReadOnlyMemory memory) 41 | { 42 | var index = 0; 43 | var objectSyncId = BitConverter.ToUInt16(memory.Span.SliceAndIncrement(ref index, sizeof(ushort))); 44 | var newValue = new Guid(memory.Span.SliceAndIncrement(ref index, 16)); 45 | var propertyName = Encoding.UTF8.GetString(memory.Span[index..]); 46 | 47 | return new GuidSyncPacket(objectSyncId, propertyName, SyncOptions.None, newValue); 48 | } 49 | } 50 | 51 | [SyncObject(1)] 52 | [SetSyncInterval(100)] 53 | public class Class1 54 | { 55 | [SyncProperty] [SyncOption(SyncOptions.AllSession)] [CustomSerializer(typeof(GuidSyncPacket))] 56 | private Guid _guidTest; 57 | 58 | [SyncProperty] [SyncOption(SyncOptions.ServerOnly)] 59 | private int _in; 60 | 61 | [SyncProperty] private double _test; 62 | } -------------------------------------------------------------------------------- /Hive.Network.Shared/HandShake/SocketHandShaker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Threading.Tasks; 5 | 6 | namespace Hive.Network.Shared.HandShake 7 | { 8 | public static class SocketHandShaker 9 | { 10 | public static async ValueTask HandShakeWith(this Socket socket, EndPoint remoteEndPoint) 11 | { 12 | var buffer = new byte[NetworkSettings.PacketBodyOffset + HandShakePacket.Size]; 13 | var segment = new ArraySegment(buffer, 0, NetworkSettings.PacketBodyOffset + HandShakePacket.Size); 14 | var syn = new Random(DateTimeOffset.Now.Millisecond).Next(); 15 | 16 | var shakeFirst = new HandShakePacket 17 | { 18 | Syn = syn 19 | }; 20 | var length = HandShakePacket.Size + NetworkSettings.PacketBodyOffset; 21 | BitConverter.TryWriteBytes(segment.AsSpan(), length); 22 | BitConverter.TryWriteBytes(segment.AsSpan()[NetworkSettings.SessionIdOffset..], 23 | NetworkSettings.HandshakeSessionId); 24 | 25 | shakeFirst.WriteTo(segment.AsSpan()[NetworkSettings.PacketBodyOffset..]); 26 | 27 | await socket.SendToAsync(segment, SocketFlags.None, remoteEndPoint); 28 | await socket.ReceiveFromAsync(segment, SocketFlags.None, remoteEndPoint); 29 | 30 | var responseFirst = HandShakePacket.ReadFrom(segment.AsSpan()[NetworkSettings.PacketBodyOffset..]); 31 | if (!responseFirst.IsResponseOf(shakeFirst)) return null; 32 | 33 | var secondShake = responseFirst.Next(); 34 | secondShake.WriteTo(buffer.AsSpan()[NetworkSettings.PacketBodyOffset..]); 35 | 36 | await socket.SendToAsync(segment, SocketFlags.None, remoteEndPoint); 37 | await socket.ReceiveFromAsync(segment, SocketFlags.None, remoteEndPoint); 38 | 39 | var secondResponse = HandShakePacket.ReadFrom(segment.AsSpan()[NetworkSettings.PacketBodyOffset..]); 40 | if (!secondResponse.IsResponseOf(secondShake) || 41 | !secondResponse.IsClientFinished()) 42 | return null; 43 | 44 | return secondResponse; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Hive.Network.Tcp/TcpConnector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Hive.Network.Abstractions.Session; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Hive.Network.Tcp; 11 | 12 | public class TcpConnector : IConnector 13 | { 14 | private readonly ILogger _logger; 15 | private readonly IServiceProvider _serviceProvider; 16 | private int _currentSessionId; 17 | 18 | public TcpConnector( 19 | ILogger logger, 20 | IServiceProvider serviceProvider) 21 | { 22 | _logger = logger; 23 | _serviceProvider = serviceProvider; 24 | } 25 | 26 | public async ValueTask ConnectAsync(IPEndPoint remoteEndPoint, CancellationToken token = default) 27 | { 28 | var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); 29 | await using var registration = token.Register(() => 30 | { 31 | try { socket.Close(); } catch { /* Ignore */ } 32 | }); 33 | 34 | try 35 | { 36 | await socket.ConnectAsync(remoteEndPoint); 37 | 38 | return ActivatorUtilities.CreateInstance(_serviceProvider, GetNextSessionId(), socket); 39 | } 40 | catch (ObjectDisposedException) when (token.IsCancellationRequested) 41 | { 42 | throw new OperationCanceledException(token); 43 | } 44 | catch (SocketException e) 45 | { 46 | _logger.LogConnectFailed(e, remoteEndPoint); 47 | return null; 48 | } 49 | catch (Exception e) 50 | { 51 | _logger.LogConnectFailed(e, remoteEndPoint); 52 | throw; 53 | } 54 | } 55 | 56 | public int GetNextSessionId() 57 | { 58 | return Interlocked.Increment(ref _currentSessionId); 59 | } 60 | } 61 | 62 | internal static partial class TcpConnectorLoggers 63 | { 64 | [LoggerMessage(LogLevel.Error, "[TCP_CONN] Connect to {RemoteEndPoint} failed")] 65 | public static partial void LogConnectFailed(this ILogger logger, Exception ex, IPEndPoint remoteEndPoint); 66 | } -------------------------------------------------------------------------------- /Unity.Mathematics/Unity.Mathematics.TestProject/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_JobOptions: 23 | serializedVersion: 2 24 | useMultithreading: 0 25 | useConsistencySorting: 0 26 | m_InterpolationPosesPerJob: 100 27 | m_NewContactsPerJob: 30 28 | m_CollideContactsPerJob: 100 29 | m_ClearFlagsPerJob: 200 30 | m_ClearBodyForcesPerJob: 200 31 | m_SyncDiscreteFixturesPerJob: 50 32 | m_SyncContinuousFixturesPerJob: 50 33 | m_FindNearestContactsPerJob: 100 34 | m_UpdateTriggerContactsPerJob: 100 35 | m_IslandSolverCostThreshold: 100 36 | m_IslandSolverBodyCostScale: 1 37 | m_IslandSolverContactCostScale: 10 38 | m_IslandSolverJointCostScale: 10 39 | m_IslandSolverBodiesPerJob: 50 40 | m_IslandSolverContactsPerJob: 50 41 | m_AutoSimulation: 1 42 | m_QueriesHitTriggers: 1 43 | m_QueriesStartInColliders: 1 44 | m_CallbacksOnDisable: 1 45 | m_ReuseCollisionCallbacks: 0 46 | m_AutoSyncTransforms: 0 47 | m_AlwaysShowColliders: 0 48 | m_ShowColliderSleep: 1 49 | m_ShowColliderContacts: 0 50 | m_ShowColliderAABB: 0 51 | m_ContactArrowScale: 0.2 52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 57 | -------------------------------------------------------------------------------- /Hive.Network.Quic/QuicCertHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | using System.Security.Cryptography.X509Certificates; 3 | 4 | namespace Hive.Network.Quic; 5 | 6 | public static class QuicCertHelper 7 | { 8 | public static X509Certificate2 GenerateTestCertificate() 9 | { 10 | X509Certificate2? cert = null; 11 | var store = new X509Store("KestrelWebTransportCertificates", StoreLocation.CurrentUser); 12 | store.Open(OpenFlags.ReadWrite); 13 | if (store.Certificates.Count > 0) 14 | { 15 | cert = store.Certificates[^1]; 16 | 17 | // rotate key after it expires 18 | if (DateTime.Parse(cert.GetExpirationDateString(), null) < DateTimeOffset.UtcNow) cert = null; 19 | } 20 | 21 | if (cert == null) 22 | { 23 | // generate a new cert 24 | var now = DateTimeOffset.UtcNow; 25 | SubjectAlternativeNameBuilder sanBuilder = new(); 26 | sanBuilder.AddDnsName("localhost"); 27 | using var ec = ECDsa.Create(ECCurve.NamedCurves.nistP256); 28 | CertificateRequest req = new("CN=localhost", ec, HashAlgorithmName.SHA256); 29 | // Adds purpose 30 | req.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection 31 | { 32 | new("1.3.6.1.5.5.7.3.1") // serverAuth 33 | }, false)); 34 | // Adds usage 35 | req.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, false)); 36 | // Adds subject alternate names 37 | req.CertificateExtensions.Add(sanBuilder.Build()); 38 | // Sign 39 | using var 40 | crt = req.CreateSelfSigned(now, 41 | now.AddDays(14)); // 14 days is the max duration of a certificate for this 42 | cert = new X509Certificate2(crt.Export(X509ContentType.Pfx)); 43 | 44 | // Save 45 | store.Add(cert); 46 | } 47 | 48 | store.Close(); 49 | 50 | // var hash = SHA256.HashData(cert.RawData); 51 | // var certStr = Convert.ToBase64String(hash); 52 | // Console.WriteLine($"\n\n\n\n\nCertificate: {certStr}\n\n\n\n"); // <-- you will need to put this output into the JS API call to allow the connection 53 | 54 | return cert; 55 | } 56 | } --------------------------------------------------------------------------------