private static void AppendActorCreationMessage(INetworkMessageOut message, INetworkedActor localActor)
        {
            var actorLocation = localActor.GetLocation();

            message.Write(localActor.Id);
            message.Write(actorLocation.X);
            message.Write(actorLocation.Y);
            message.Write(CompatibilityManager.GetHashCode(localActor.GetType().Name));

            if (localActor.ReplicateProperties)
            {
                localActor.Serialize(message);
            }
        }
        private void LoadRemoteMethods(Assembly actorsAssembly)
        {
            var networkedActorType          = typeof(INetworkedActor);
            var clientCallableAttributeType = typeof(RemoteCallableAttribute);

            foreach (var actorType in actorsAssembly.GetTypes().Where(t => t.GetInterfaces().Contains(networkedActorType)))
            {
                foreach (var methodInfo in actorType.GetMethods().Where(m => m.GetCustomAttribute(clientCallableAttributeType) != null))
                {
                    var methodName = methodInfo.Name;
                    var methodKey  = CompatibilityManager.GetHashCode(methodName);

                    if (!_remoteMethods.ContainsKey(methodKey))
                    {
                        _remoteMethods.Add(methodKey, methodName);
                    }
                }
            }
        }
        public void AddActorRemoteMethodCall(int actorRemoteId, string methodName, bool reliable, object[] parameters)
        {
            var hashedMethodName = CompatibilityManager.GetHashCode(methodName);

            var methodCall = new CallMethod(actorRemoteId, hashedMethodName, reliable, parameters);

            if (!_methodCalls.ContainsKey(actorRemoteId))
            {
                _methodCalls.Add(actorRemoteId, new Dictionary <int, CallMethod>(1));
            }

            if (_methodCalls[actorRemoteId].ContainsKey(hashedMethodName))
            {
                _methodCalls[actorRemoteId][hashedMethodName] = methodCall;
            }
            else
            {
                _methodCalls[actorRemoteId].Add(hashedMethodName, methodCall);
            }
        }
Esempio n. 4
0
 public NetworkPeerGameClient() : base(1, typeof(NetworkPeerGameClient).Assembly)
 {
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(Bar)), typeof(Bar));
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(Ball)), typeof(Ball));
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(GameState)), typeof(GameState));
 }