예제 #1
0
        /// <summary>
        /// Gets the number of a method
        /// </summary>
        /// <param name="Node">The node to look this up for</param>
        /// <param name="MethodNumber">The name of the method</param>
        /// <param name="Parameters">The parameters you intend to send to the method</param>
        /// <returns>The MethodInfo or -1 if it is not found</returns>
        public static int GetMethodNumber(Node Node, string Method, params object[] Parameters)
        {
            Type nodeType = Node.GetType();

            if (!NumberedMethodInfoCache.ContainsKey(nodeType))
            {
                NumberedMethodInfoCache.Add(nodeType, new List <MethodInfo>(nodeType.GetAllMethods()));
            }

            MethodInfo info = GetMethodInfo(Node, Method, Parameters);

            if (info != null)
            {
                List <MethodInfo> methodInfos = NumberedMethodInfoCache[nodeType];
                for (int i = 0; i < methodInfos.Count; i++)
                {
                    if (methodInfos[i].Equals(info))
                    {
                        return(i);
                    }
                }
            }

            MDLog.Warn(LOG_CAT, $"Method number could not be found for {nodeType.ToString()}#{Method}({GetParametersAsString(Parameters)})");
            return(-1);
        }
예제 #2
0
        /// <summary>
        /// Register a command, with custom help text that can be displayed in the console
        /// </summary>
        /// <param name="Instance">The instance to register for</param>
        /// <param name="Method">The method to register</param>
        /// <param name="HelpText">Help text to show in console</param>
        /// <param name="DefaultParams">Default parameters</param>
        public static void RegisterCommand(object Instance, MethodInfo Method, string HelpText,
                                           object[] DefaultParams = null)
        {
            if (Method == null)
            {
                return;
            }

            if (_commandMap == null)
            {
                _commandMap = new Dictionary <string, CommandInfo>();
            }

            string MethodName = Method.Name.ToLower();

            if (_commandMap.ContainsKey(MethodName))
            {
                MDLog.Warn(LOG_CAT, $"Command with name [{Method.Name}] is already registered, it will be replaced");
            }

            CommandInfo NewCommand;

            NewCommand.HelpText    = HelpText;
            NewCommand.Instance    = Instance;
            NewCommand.Method      = Method;
            NewCommand.DefaultArgs = DefaultParams;

            _commandMap[MethodName] = NewCommand;
        }
예제 #3
0
        /// <summary>
        /// Called when an input event happens
        /// </summary>
        /// <param name="Event">The event</param>
        public void OnInputEvent(InputEvent Event)
        {
            MDInputType OldInputType = LastInputType;

            switch (Event)
            {
            case InputEventKey _:
            case InputEventMouse _:
                LastInputType = MDInputType.MouseAndKeyboard;
                break;

            case InputEventJoypadButton _:
            case InputEventJoypadMotion _:
                LastInputType = MDInputType.JoyPad;
                break;

            case InputEventScreenTouch _:
            case InputEventGesture _:
                LastInputType = MDInputType.Touch;
                break;

            default:
                MDLog.Warn(LOG_CAT, $"Unknown Input Event Type: {Event.AsText()}");
                break;
            }

            if (OldInputType != LastInputType)
            {
                OnInputTypeChanged(OldInputType, LastInputType);
            }
        }
예제 #4
0
        private static PackedScene LoadPackedScene(String path)
        {
            String full_path = path;

            if (!ResourceLoader.Exists(full_path))
            {
                MDLog.Warn(LOG_CAT, $"Can't find: {full_path}");
            }
            return((PackedScene)ResourceLoader.Load(full_path));
        }
예제 #5
0
        /// <summary> Returns the ping for the given peer or -1 if the peer does not exist.</summary>
        public int GetPlayerPing(int PeerId)
        {
            if (PeerSynchInfo.ContainsKey(PeerId))
            {
                return(PeerSynchInfo[PeerId].Ping);
            }

            MDLog.Warn(LOG_CAT, $"Requested ping for peer [{PeerId}] that doesn't exist in list");
            return(-1);
        }
예제 #6
0
        /// <summary> Returns the estimated OS.GetTicksMsec for the given peer or 0 if the peer does not exist.</summary>
        public uint GetPlayerTicksMsec(int PeerId)
        {
            if (PeerSynchInfo.ContainsKey(PeerId))
            {
                return(Convert.ToUInt32(OS.GetTicksMsec() + PeerSynchInfo[PeerId].TickMSecOffset));
            }

            MDLog.Warn(LOG_CAT, $"Requested OS.GetTicksMsec for peer [{PeerId}] that doesn't exist in list");
            return(0);
        }
 /// <summary>
 /// Add a new id/key pair to our map
 /// </summary>
 /// <param name="id">The ID to add</param>
 /// <param name="key">The key to add</param>
 public void AddNetworkKeyIdPair(uint id, string key)
 {
     if (NetworkIDToKeyMap.ContainsKey(id) == false)
     {
         NetworkIDToKeyMap.Add(id, key);
         KeyToNetworkIdMap.Add(key, id);
     }
     else
     {
         MDLog.Warn(LOG_CAT, $"Tried to add key {key} for id {id} but it already has key {NetworkIDToKeyMap[id]}");
     }
 }
예제 #8
0
        private void ClockedCall(uint Tick, ClockedRemoteCall.TypeOfCall Type, string NodePath, string Method,
                                 MDRemoteMode Mode, params object[] Parameters)
        {
            Node Target = GetNodeOrNull(NodePath);

            if (Target == null)
            {
                MDLog.Warn(LOG_CAT, $"Could not find target [{NodePath}] for ClockedRpcCall.");
                return;
            }
            MDLog.Trace(LOG_CAT, $"Got clocked call {Method} on {NodePath} with parameters ({MDStatics.GetParametersAsString(Parameters)})");
            ClockedRemoteCall RemoteCall = new ClockedRemoteCall(Tick, Type, WeakRef(Target), Method, Mode, Multiplayer.GetRpcSenderId(), Parameters);

            // Check if we should already invoke this (if the time has already passed)
            if (!RemoteCall.Invoke(GameClock.GetRemoteTick()))
            {
                ClockedRemoteCallList.Add(RemoteCall);
            }
        }
예제 #9
0
        /// Returns true once we have invoked or if we can't invoke
        public bool Invoke(uint Tick)
        {
            if (this.Tick > Tick)
            {
                return(false);
            }

            if (Node.GetRef() == null)
            {
                MDLog.Warn(LOG_CAT, "Node no longer exists for call");
                return(true);
            }

            Node Target = Node.GetRef() as Node;

            switch (Mode)
            {
            case MDRemoteMode.Master:
            case MDRemoteMode.MasterSync:
                if (Target.IsNetworkMaster())
                {
                    DoCall(Target);
                }

                break;

            case MDRemoteMode.PuppetSync:
            case MDRemoteMode.Puppet:
                if (!Target.IsNetworkMaster())
                {
                    DoCall(Target);
                }

                break;

            case MDRemoteMode.Remote:
            case MDRemoteMode.RemoteSync:
                DoCall(Target);
                break;
            }

            return(true);
        }