Beispiel #1
0
        // starts the match
        public void Start(ReturnCallback rc)
        {
            // a disposable Xml document for creating nodes in
            // TODO: this is really bad practice
            XmlDocument doc = new XmlDocument();

            // get all the enemy player ID data each player needs
            List <XmlElement>[] playerIds = new List <XmlElement> [players.Length];
            // build all the arrays
            for (int i = 0; i < players.Length; i++)
            {
                playerIds[i] = new List <XmlElement>();
            }
            // TODO: this whole ID collecting section might be better served in the game manager, I'm not sure
            // populate all the arrays with player id's
            // ...from other players
            for (int i = 0; i < players.Length; i++)
            {
                XmlElement e = players[i].GetPlayerIDs(doc);
                for (int j = (i + 1) % players.Length; j != i; j = (j + 1) % players.Length)
                {
                    playerIds[j].Add(e);
                }
            }
            // send all the players all the ids and get them started
            XmlElement[] laneIds = gameManager.GetLaneIDs(doc);
            for (int i = 0; i < players.Length; i++)
            {
                players[i].Start(playerIds[i].ToArray(), laneIds, i);
            }
            returnCallback = rc;
            // start the first turn;
            EndDeployPhase();
        }
Beispiel #2
0
        /// <summary>
        /// Adds a new possible switch from fromStateID to toStateID.
        /// If there is no preexisting from/toStateID they will be added.
        /// If given switchCondition is null, this does nothing.
        /// The switchCallback can be null without problems.
        /// </summary>
        public void AddPossibleSwitch(T fromStateID, T toStateID, ReturnCallback <bool> switchCondition, Callback <T, T> switchCallback = null)
        {
            //	No condition to utilize the switchCallback means we shouldn't even have an entry
            if (switchCondition == null)
            {
                return;
            }

            //	Add missing fromState
            if (!_ourStates.ContainsKey(fromStateID))
            {
                _ourStates.Add(fromStateID, new State());
            }
            //	Add missing toState
            if (!_ourStates.ContainsKey(toStateID))
            {
                _ourStates.Add(toStateID, new State());
            }

            //	Add missing fromState's possible toState switch
            if (!_ourStates[fromStateID].possibleSwitches.ContainsKey(toStateID))
            {
                _ourStates[fromStateID].possibleSwitches.Add(toStateID, new StateSwitch());
            }

            _ourStates[fromStateID].possibleSwitches[toStateID].SwitchCondition = switchCondition;

            if (switchCallback != null)
            {
                _ourStates[fromStateID].possibleSwitches[toStateID].SwitchCallback = switchCallback;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Import a file asynchronously from a given byte array as source.
        /// </summary>
        /// <remarks>
        /// This method must be used as a coroutine. Failure to do so whould result in no import whatsoever. In particular,
        /// for successful import, the returned iterator must be itered over until it's end.
        ///
        /// The file name is used mainly to determine wich importer to use based on the extension,
        /// as well as for logging and error reporting purposes.
        /// </remarks>
        /// <param name="filename">The name of the file to import.</param>
        /// <param name="data">The array containg the data to import.</param>
        /// <param name="return_callback">The callback that will be called on import completion.</param>
        /// <param name="progress_callback">The callback that will be called periodically during import to notify current progress.</param>
        /// <returns>An iterator to use in a coroutine.</returns>
        public IEnumerator Import(string filename, byte[] data, ReturnCallback return_callback, Module.ProgressCallback progress_callback = null)
        {
            if (isDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            Module.ProgressCallback progress1 = null;
            Module.ProgressCallback progress2 = null;

            if (progress_callback != null)
            {
                progress1 = p => progress_callback(p * (1f - unityLoadingPercentage));
                progress2 = p => progress_callback(p * unityLoadingPercentage + (1f - unityLoadingPercentage));
            }

            string extension = Path.GetExtension(filename).Remove(0, 1).ToLower();

            Module.IImporter module;

            if (extensionHandler.TryGetValue(extension, out module))
            {
                return(Import(result => module.ImportFromBytes(filename, data, result, progress1), filename, return_callback, progress2));
            }
            else
            {
                Debug.LogErrorFormat("Unsupported format with extension '{0}'. No importer is registered for this format.", extension);
            }

            return(null);
        }
Beispiel #4
0
 // starts the match with asynchronous receiving
 public void AsyncStart(ReturnCallback rc)
 {
     Start(rc);
     foreach (PlayerManager pm in players)
     {
         pm.StartAsyncReceive();
     }
 }
Beispiel #5
0

        
Beispiel #6
0
    public bool CloseCamera(int cameraId, CMS_GUID guid, ReturnCallback CallbackFunction)
    {
        NetworkMsgAnalysis.GetInstance().CloseCameraCallback = CallbackFunction;
        ALLST_GENERIC stHeader = new ALLST_GENERIC((UInt16)CmdNum.CTOS_CLOSECAMERA_MSG, Marshal.SizeOf(typeof(int)) + Marshal.SizeOf(typeof(CMS_GUID)));

        byte[] msg      = new byte[m_iHeaderLen + stHeader.iMessageLen];
        byte[] b_header = StructToBytes(stHeader);
        byte[] b_id     = StructToBytes(cameraId);
        byte[] b_guid   = StructToBytes(guid);
        Buffer.BlockCopy(b_header, 0, msg, 0, m_iHeaderLen);
        Buffer.BlockCopy(b_guid, 0, msg, m_iHeaderLen, b_guid.Length);
        Buffer.BlockCopy(b_id, 0, msg, m_iHeaderLen + b_guid.Length, b_id.Length);
        return(Send(msg));
    }
Beispiel #7
0
    public bool GotoPresetPosition(int cameraId, CMS_GUID guid, UInt16 index, ReturnCallback CallbackFunction)
    {
        NetworkMsgAnalysis.GetInstance().GotoPresetPosCallback = CallbackFunction;
        ALLST_GENERIC            stHeader = new ALLST_GENERIC((UInt16)CmdNum.CTOS_GOTOPREPOSITION_MSG, Marshal.SizeOf(typeof(CTOS_GTOPREPOSITION_INFO)));
        CTOS_GTOPREPOSITION_INFO info     = new CTOS_GTOPREPOSITION_INFO();

        info.cameraId   = cameraId;
        info.camareGuid = guid;
        info.index      = index;
        byte[] msg      = new byte[m_iHeaderLen + stHeader.iMessageLen];
        byte[] b_header = StructToBytes(stHeader);
        byte[] b_info   = StructToBytes(info);
        Buffer.BlockCopy(b_header, 0, msg, 0, m_iHeaderLen);
        Buffer.BlockCopy(b_info, 0, msg, m_iHeaderLen, b_info.Length);
        return(Send(msg));
    }
Beispiel #8
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 public void Execute <T1>(Action <T1> taskDelegate, ReturnCallback returnDelegate, T1 p1)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1);
 }
Beispiel #9
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 public void Execute(Action taskDelegate, ReturnCallback returnDelegate)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate);
 }
Beispiel #10
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <typeparam name="T3">The type of the 3.</typeparam>
 /// <typeparam name="T4">The type of the 4.</typeparam>
 /// <typeparam name="T5">The type of the 5.</typeparam>
 /// <typeparam name="T6">The type of the 6.</typeparam>
 /// <typeparam name="T7">The type of the 7.</typeparam>
 /// <typeparam name="T8">The type of the 8.</typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <param name="p3">The p3.</param>
 /// <param name="p4">The p4.</param>
 /// <param name="p5">The p5.</param>
 /// <param name="p6">The p6.</param>
 /// <param name="p7">The p7.</param>
 /// <param name="p8">The p8.</param>
 public void Execute <T1, T2, T3, T4, T5, T6, T7, T8, TResult>(Func <T1, T2, T3, T4, T5, T6, T7, T8, TResult> taskDelegate, ReturnCallback <TResult> returnDelegate, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1, p2, p3, p4, p5, p6, p7, p8);
 }
Beispiel #11
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <typeparam name="T3">The type of the 3.</typeparam>
 /// <typeparam name="T4">The type of the 4.</typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <param name="p3">The p3.</param>
 /// <param name="p4">The p4.</param>
 public void Execute <T1, T2, T3, T4, TResult>(Func <T1, T2, T3, T4, TResult> taskDelegate, ReturnCallback <TResult> returnDelegate, T1 p1, T2 p2, T3 p3, T4 p4)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1, p2, p3, p4);
 }
Beispiel #12
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 public void Execute <T1, TResult>(Func <T1, TResult> taskDelegate, ReturnCallback <TResult> returnDelegate, T1 p1)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1);
 }
Beispiel #13
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <typeparam name="T3">The type of the 3.</typeparam>
 /// <typeparam name="T4">The type of the 4.</typeparam>
 /// <typeparam name="T5">The type of the 5.</typeparam>
 /// <typeparam name="T6">The type of the 6.</typeparam>
 /// <typeparam name="T7">The type of the 7.</typeparam>
 /// <typeparam name="T8">The type of the 8.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <param name="p3">The p3.</param>
 /// <param name="p4">The p4.</param>
 /// <param name="p5">The p5.</param>
 /// <param name="p6">The p6.</param>
 /// <param name="p7">The p7.</param>
 /// <param name="p8">The p8.</param>
 public void Execute <T1, T2, T3, T4, T5, T6, T7, T8>(Action <T1, T2, T3, T4, T5, T6, T7, T8> taskDelegate, ReturnCallback returnDelegate, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1, p2, p3, p4, p5, p6, p7, p8);
 }
Beispiel #14
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <typeparam name="T3">The type of the 3.</typeparam>
 /// <typeparam name="T4">The type of the 4.</typeparam>
 /// <typeparam name="T5">The type of the 5.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <param name="p3">The p3.</param>
 /// <param name="p4">The p4.</param>
 /// <param name="p5">The p5.</param>
 public void Execute <T1, T2, T3, T4, T5>(Action <T1, T2, T3, T4, T5> taskDelegate, ReturnCallback returnDelegate, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1, p2, p3, p4, p5);
 }
 public SecureFunction(RemoteFunction <T> _func)
 {
     func = _func;
     func.ReturnCallback += (f, r, i) => ReturnCallback?.Invoke(this, r, i);
 }
Beispiel #16
0
        private IEnumerator Import(Func <Module.ImporterReturnCallback, IEnumerator> importer, string filename, ReturnCallback return_callback, Module.ProgressCallback progress_callback = null)
        {
            bool waiting;

            do
            {
                lock (this)
                {
                    if (importing)
                    {
                        waiting = true;
                    }
                    else
                    {
                        importing = true;

                        waiting = false;
                    }
                }

                if (waiting)
                {
                    yield return(null);
                }
            }while(waiting);

            if (importer != null)
            {
                int   refresh_rate       = Screen.currentResolution.refreshRate;
                float max_frame_duration = 1000.0f * 0.75f * (1.0f / (float)(refresh_rate >= 20 ? refresh_rate : 60));                  // In milliseconds. Use only 75% of the available time to avoid missing vsync events

                // Create timer to break the code that must be executed in unity thread into chunks that will fit into the required target framerate
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

                DateTime start = DateTime.Now;

                Type.Scene scene = null;

                // Import data
                IEnumerator it = importer(s => scene = s);

                while (it.MoveNext())
                {
                    yield return(it.Current);
                }

                if (scene != null)
                {
                    // Convert data to Unity format
                    it = scene.ToUnity(progress_callback);

                    timer.Start();

                    // Split code executed in unity thread into chunks that allow to maintain targeted framerate,
                    // without loosing unnecessary time by yielding every time possible (because 1 yield <=> 1 frame)
                    while (it.MoveNext())
                    {
                        if (timer.ElapsedMilliseconds >= max_frame_duration)
                        {
                            yield return(null);

                            timer.Reset();
                            timer.Start();
                        }
                    }

                    DateTime end = DateTime.Now;

                    // Add diagnostic info
                    if (scene.UnityRoot != null)
                    {
                        int vertices_loaded = 0;
                        int faces_loaded    = 0;

                        foreach (Type.Mesh mesh in scene.meshes)
                        {
                            vertices_loaded += mesh.VerticesCount;
                            faces_loaded    += mesh.FacesCount;
                        }

                        scene.UnityRoot.AddComponent <Info>().Init(filename, end.Subtract(start), vertices_loaded, faces_loaded, scene.IdMapping.Id2Go);
                    }

                    if (return_callback != null)
                    {
                        return_callback(scene.UnityRoot);
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Import of '{0}' failed.", filename);
                }
            }
            else
            {
                Debug.LogError("Invalid null importer.");
            }

            // Ready to accept new imports
            lock (this)
            {
                importing = false;
            }
        }
Beispiel #17
0
 public void Return(object obj)
 {
     ReturnObject = obj;
     AutoResetEvent.Set();
     ReturnCallback?.Invoke(obj);
 }
Beispiel #18
0
    public bool SetPTZControl(int cameraId, CMS_GUID guid, PTZOperation nCtrlType, UInt16 nSpeedX, UInt16 nSpeedY, UInt16 nSpeedZ, int nPreset, ReturnCallback CallbackFunction)
    {
        NetworkMsgAnalysis.GetInstance().SetPTZCtrlCallback = CallbackFunction;
        CTOS_PTZ_INFO PTZinfo = new CTOS_PTZ_INFO();

        PTZinfo.cameraId   = cameraId;
        PTZinfo.camareGuid = guid;
        PTZinfo.type       = (UInt16)nCtrlType;
        PTZinfo.speedX     = nSpeedX;
        PTZinfo.speedY     = nSpeedY;
        PTZinfo.speedZ     = nSpeedZ;
        PTZinfo.nPreset    = nPreset;
        ALLST_GENERIC stHeader = new ALLST_GENERIC((UInt16)CmdNum.CTOS_SETPTZCTRL_MSG, Marshal.SizeOf(typeof(CTOS_PTZ_INFO)));

        byte[] msg       = new byte[m_iHeaderLen + stHeader.iMessageLen];
        byte[] b_header  = StructToBytes(stHeader);
        byte[] b_PTZinfo = StructToBytes(PTZinfo);
        Buffer.BlockCopy(b_header, 0, msg, 0, m_iHeaderLen);
        Buffer.BlockCopy(b_PTZinfo, 0, msg, m_iHeaderLen, b_PTZinfo.Length);
        return(Send(msg));
    }
Beispiel #19
0
 /// <summary>
 /// Executes the specified task delegate.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <typeparam name="T3">The type of the 3.</typeparam>
 /// <param name="taskDelegate">The task delegate.</param>
 /// <param name="returnDelegate">The return delegate.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <param name="p3">The p3.</param>
 public void Execute <T1, T2, T3>(Action <T1, T2, T3> taskDelegate, ReturnCallback returnDelegate, T1 p1, T2 p2, T3 p3)
 {
     Execute((Delegate)taskDelegate, (Delegate)returnDelegate, p1, p2, p3);
 }
Beispiel #20
0
    public bool loginToCMS(string name, string passwd, string ip, UInt16 port, UInt16 Protocol, ReturnCallback CallbackFunction)
    {
        NetworkMsgAnalysis.GetInstance().UserLoginCallback = CallbackFunction;
        CTOS_CLIENTLOGIN st = new CTOS_CLIENTLOGIN(name, passwd, ip, port, Protocol);

        ALLST_GENERIC stHeader = new ALLST_GENERIC((UInt16)CmdNum.CTOS_CLIENTLOGIN_MSG, (Int32)Marshal.SizeOf(st));

        byte[] all = new byte[m_iHeaderLen + stHeader.iMessageLen];

        byte[] data1 = StructToBytes(stHeader);
        byte[] data2 = StructToBytes(st);

        Buffer.BlockCopy(data1, 0, all, 0, m_iHeaderLen);
        Buffer.BlockCopy(data2, 0, all, m_iHeaderLen, (int)stHeader.iMessageLen);

        return(Send(all));
    }