コード例 #1
0
 private void textBoxCommand_KeyDown(object sender, KeyEventArgs e)
 {
     if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
     {
         WriteOutputString(lblPrompt.Text + " " + textBoxCommand.Text + Environment.NewLine);
         _input.Enqueue(textBoxCommand.Text);
         AddToHistory(textBoxCommand.Text);
         textBoxCommand.Text = String.Empty;
         e.Handled           = true;
     }
     else if (e.KeyCode == Keys.Up)
     {
         if (_currHistory > 0)
         {
             _currHistory--;
             UpdateCommandFromHistory();
         }
         e.Handled = true;
     }
     else if (e.KeyCode == Keys.Down)
     {
         if (_currHistory < _history.Count - 1)
         {
             _currHistory++;
             UpdateCommandFromHistory();
         }
         e.Handled = true;
     }
 }
コード例 #2
0
        private void NetWork_onJoinRoom(string rid, bool result, bool isCreator, Dictionary <string, string[]> roomCache,
                                        string[] uids)
        {
            if (rid == null || !rid.Equals(this.roomId))
            {
                return;
            }
            if (result)
            {
                SetStates(VirtualManState.InRoom);
                if (isCreator)
                {
                    this.isControler = true;
                    //GameObject.Find("WorldRoot/SelectIpad").SetActive(true);
                }
                this.isCreator = isCreator;
                if (roomCache.ContainsKey(RoomCacheKey.RoomCacheKeyAnchor))
                {
                    // nothing todo
                }
                else if (isCreator)
                {
                    // nothing todo
                }
                if (!NetHelper.Instance.IsInSpectatorViewRoom && this.clientType != ClientType.SpectatorViewPc &&
                    this.clientType != ClientType.IOS)
                {
                    if (MrShareData._instance.FloorLocated)
                    {
                        SetStates(VirtualManState.FloorLoacted);
                    }
                    else
                    {
                        MrShareData._instance.needLocated = true;
                        SetStates(VirtualManState.FloorLocating);
                    }
                }
                OperationBean op = new OperationBean();
                op.op    = OperationBean.OpId.SelfJoinRoom;
                op.param = roomCache;
                operationQueue.Enqueue(op);


                if (uids != null)
                {
                    foreach (string uid in uids)
                    {
                        op       = new OperationBean();
                        op.op    = OperationBean.OpId.UserEnter;
                        op.param = uid;
                        operationQueue.Enqueue(op);
                    }
                }
            }
        }
コード例 #3
0
ファイル: ShowLog.cs プロジェクト: ChrisUnity/GEWaterFactory
    public void Log(string l)
    {
        LogOpBean bean = new LogOpBean();

        bean.op    = LogOpBean.OpId.ShowLog;
        bean.param = l;
        operationQueue.Enqueue(bean);
    }
コード例 #4
0
        public void onRecvAnimation(int animId, double time)
        {
            AnimBean a = new AnimBean();

            a.animId = animId;
            a.time   = time;

            animQueue.Enqueue(a);
        }
コード例 #5
0
        public void OnRecvRotation(Vector3 rotation, double time)
        {
            //Debug.Log("OnRecvRotation rot:" + rotation.ToString() + "time:" + time);
            RotBean pr = new RotBean();

            pr.rot  = rotation;
            pr.time = time;
            headRotationQueue.Enqueue(pr);
        }
コード例 #6
0
        public void OnRecvPosition(Vector3 position, double time)
        {
            if (Math.Abs(position.x) > 20 || Math.Abs(position.y) > 20 || Math.Abs(position.z) > 20)
            {
                return;
            }
            //Debug.Log("OnRecvPosition pos:" + position.ToString() + "time:" + time);
            PosBean pr = new PosBean();

            pr.pos  = position;
            pr.time = time;
            headPisitionQueue.Enqueue(pr);
        }
コード例 #7
0
        /// <summary>
        /// Override function called when a packet is input
        /// </summary>
        /// <param name="frame">The input frame</param>
        public override void Input(DataFrame frame)
        {
            EnsureThreadRunning();

            try
            {
                _input.Enqueue(frame);
            }
            catch (InvalidOperationException)
            { }
            catch (OperationCanceledException)
            { }
        }
コード例 #8
0
 /// <summary>
 /// Writes a frame to the input queue
 /// </summary>
 /// <param name="data">The frame, null on end of stream</param>
 public override void Write(DataFrame data)
 {
     try
     {
         _inputQueue.Enqueue(data);
     }
     catch (InvalidOperationException)
     {
         // Couldn't queue, leave as is
     }
     catch (OperationCanceledException)
     {
     }
 }
コード例 #9
0
        private void SocketReceive()
        {
            // try
            {
                m_RecvLength = 0;
                int readPos = 0;
                while (m_IsConnnected)
                {
                    int readLength = m_Socket.Receive(m_RecvBuffer, m_RecvLength, ByteArray.MSG_MAX_LEN - m_RecvLength, SocketFlags.None);
                    m_RecvLength += readLength;
                    while ((m_RecvLength - readPos) >= ByteArray.MSG_HEAD_LEN)
                    {
                        short val = BitConverter.ToInt16(m_RecvBuffer, readPos);
                        // 字节序转换?
                        if (val > (m_RecvLength - readPos))
                        {
                            break;
                        }
                        ByteArray bytes = m_BytesPool.Pop();
                        bytes.Reset();
                        bytes.CopyFromNet(m_RecvBuffer, readPos, (int)val);
                        bytes.ReadHead();
                        readPos += val;

                        m_MessageQueue.Enqueue(bytes);
                    }

                    // 将后面未接满的数据
                    if (readPos > ByteArray.MSG_MAX_LEN / 2 || m_RecvLength >= ByteArray.MSG_MAX_LEN)
                    {
                        Array.Copy(m_RecvBuffer, readPos, m_RecvBuffer, 0, m_RecvLength - readPos);
                        m_RecvLength -= readPos;
                        readPos       = 0;
                    }
                }
            }
            //catch(Exception e)
            //{
            // Console.WriteLine("Reveive thread abort!" + e.Message);
            // }
        }
コード例 #10
0
 public bool Send(Request request)
 {
     if (SendFromThread)
     {
         if (request is RequestAction)
         {
             callbackManager.SetRequestCallback(request as RequestAction);
         }
         sendingQueue.Enqueue(request);
         return(true);
     }
     if (IsConnected)
     {
         if (request is RequestAction)
         {
             callbackManager.SetRequestCallback(request as RequestAction);
         }
         webSocket.Send(request.ToString());
         return(true);
     }
     return(false);
 }
コード例 #11
0
 /// <summary>
 /// Enqueue a frame on the outbound queue
 /// </summary>
 /// <param name="frame">The frame</param>
 public void Enqueue(DataFrame frame)
 {
     _outputQueue.Enqueue(frame);
 }
コード例 #12
0
        public void TestPath(Vector3D destination, bool landing)
        {
            if (m_navSet.Settings_Current.DestinationChanged || m_prevMover != m_navSet.Settings_Current.NavigatorMover)
            {
                m_logger.debugLog("new destination: " + destination, Logger.severity.INFO);
                m_navSet.Settings_Task_NavWay.DestinationChanged = false;
                m_prevMover = m_navSet.Settings_Current.NavigatorMover;
                m_runId++;
                m_pathLow.Clear();
                ClearAltPath();
                m_pathState = PathState.Not_Running;
                m_planetCheckDest.Stop();
                m_planetCheckSpeed.Stop();
            }
            //else
            //	m_logger.debugLog("destination unchanged", "TestPath()");

            if (Globals.UpdateCount < m_nextRunPath)
            {
                return;
            }
            m_nextRunPath = Globals.UpdateCount + 10ul;

            if (m_pathLow.Count != 0)
            {
                m_logger.debugLog("path low is running");
                return;
            }

            m_navBlock        = m_navSet.Settings_Current.NavigationBlock;
            m_destination     = destination;
            m_ignoreAsteroid  = m_navSet.Settings_Current.IgnoreAsteroid;
            m_landing         = landing;
            m_canChangeCourse = m_navSet.Settings_Current.PathfinderCanChangeCourse;
            MyEntity destEntity = m_navSet.Settings_Current.DestinationEntity as MyEntity;

            m_logger.debugLog("DestinationEntity: " + m_navSet.Settings_Current.DestinationEntity.getBestName());
            byte runId = m_runId;

            const float minimumDistance = 100f;
            const float minDistSquared  = minimumDistance * minimumDistance;
            const float seconds         = 10f;
            const float distOverSeconds = minimumDistance / seconds;

            Vector3 displacement    = destination - m_navBlock.WorldPosition;
            float   distanceSquared = displacement.LengthSquared();
            float   testDistance;
            Vector3 move_direction = m_grid.Physics.LinearVelocity;
            float   speedSquared   = move_direction.LengthSquared();

            if (distanceSquared > minDistSquared)
            {
                // only look ahead 10 s / 100 m
                testDistance = speedSquared < distOverSeconds ? minimumDistance : (float)Math.Sqrt(speedSquared) * seconds;
                if (testDistance * testDistance < distanceSquared)
                {
                    Vector3 direction = displacement / (float)Math.Sqrt(distanceSquared);
                    destination = m_navBlock.WorldPosition + testDistance * direction;
                    m_logger.debugLog("moved destination: " + destination + ", distance: " + testDistance + ", direction: " + direction);
                }
            }
            else
            {
                m_logger.debugLog("using actual destination: " + destination);
            }

            m_pathHigh.Enqueue(() => TestPath(destination, destEntity, runId, isAlternate: false, tryAlternates: true));
            if (m_ignoreAsteroid)
            {
                m_planetCheckDest.Stop();
            }
            else
            {
                m_planetCheckDest.Start(destination - m_navBlock.WorldPosition);
            }

            // given velocity and distance, calculate destination
            if (speedSquared > 1f)
            {
                Vector3D moveDest = m_navBlock.WorldPosition + move_direction * LookAheadSpeed_Seconds;
                m_pathHigh.Enqueue(() => TestPath(moveDest, null, runId, isAlternate: false, tryAlternates: false, slowDown: true));
                if (m_ignoreAsteroid)
                {
                    m_planetCheckSpeed.Stop();
                }
                else
                {
                    m_planetCheckSpeed.Start(moveDest - m_navBlock.WorldPosition);
                }
            }
            else
            {
                m_navSet.Settings_Task_NavWay.SpeedMaxRelative = float.MaxValue;
                m_navSet.Settings_Task_NavWay.SpeedTarget      = float.MaxValue;
            }

            RunItem();
        }
コード例 #13
0
            /// <summary>
            /// Write the specified frame.
            /// </summary>
            /// <param name="frame">The frame to write.</param>
            public override void Write(DataFrame frame)
            {
                Uri currUri = null;
                var chunk   = frame.GetValue <HttpRequestDataChunk>().Clone();

                if (chunk.ChunkNumber == 0)
                {
                    int    error   = 0;
                    string message = null;

                    if (_currOutConn == null)
                    {
                        try
                        {
                            _logger.LogVerbose("Received new connection to {0}", chunk.Path);

                            currUri = new Uri(chunk.Path, UriKind.Absolute);

                            chunk.Path = currUri.PathAndQuery;

                            // Upgrade to at least version 1.0
                            if (chunk.Version.IsVersionUnknown)
                            {
                                chunk.Version = HttpVersion.Version10;
                            }

                            // Add a Connection: close header?
                            _currOutConn             = new ProxyConnection();
                            _currOutConn.DataAdapter = new HttpProxyDataAdapter(currUri, _cancellationSource.Token);

                            _currOutConn.Graph = ConnectClient(_currOutConn.DataAdapter);
                            if (_currOutConn.Graph == null)
                            {
                                _currOutConn.DataAdapter.Dispose();
                                error        = 404;
                                message      = "Not Found";
                                _currOutConn = null;
                            }
                            else
                            {
                                _currOutConn.ResponseReader = GetResponse(_currOutConn,
                                                                          currUri, chunk.Method.Equals("HEAD", StringComparison.OrdinalIgnoreCase));
                                _conns.Enqueue(_currOutConn);
                            }
                        }
                        catch (UriFormatException)
                        {
                            error   = 400;
                            message = "Bad Request";
                        }

                        if (error != 0)
                        {
                            ProxyConnection conn = new ProxyConnection();

                            conn.ResponseReader = new[] { BuildError(error, message, chunk.Method, chunk.Version) };
                            _conns.Enqueue(conn);
                        }
                    }
                }

                if (_currOutConn != null)
                {
                    DataWriter writer = new DataWriter(new DataAdapterToStream(_currOutConn.DataAdapter.Coupling));

                    chunk.WriteChunk(writer);

                    if (chunk.FinalChunk)
                    {
                        _currOutConn = null;
                    }
                }
                else
                {
                    // Do nothing
                }
            }
コード例 #14
0
 private void WebSocketOpened(object sender, EventArgs e)
 {
     connectionOpenEvent.Set(); // send signal about connection done
     ConnectionOpened.SafeInvoke(this);
     receivedQueue.Enqueue(Response.Open(Url));
 }
コード例 #15
0
ファイル: GeneratorDataAdapter.cs プロジェクト: wflk/canape
 /// <summary>
 /// Overridden write method
 /// </summary>
 /// <param name="data">The data frame to write</param>
 public override void Write(DataFrame data)
 {
     _inputQueue.Enqueue(data);
 }
コード例 #16
0
        /// <summary>
        /// Test a path between current position and destination.
        /// </summary>
        private void TestPath(Vector3D destination, MyEntity ignoreEntity, byte runId, bool isAlternate, bool tryAlternates, bool slowDown = false)
        {
            m_logger.debugLog("m_navBlock == null", Logger.severity.FATAL, condition: m_navBlock == null);

            if (runId != m_runId)
            {
                m_logger.debugLog("destination changed, abort", Logger.severity.DEBUG);
                return;
            }

            if (!lock_testPath.TryAcquireExclusive())
            {
                m_logger.debugLog("Already running, requeue (destination:" + destination + ", ignoreEntity: " + ignoreEntity.getBestName() + ", runId :" + runId
                                  + ", isAlternate: " + isAlternate + ", tryAlternates: " + tryAlternates + ", slowDown: " + slowDown + ")");
                LockedQueue <Action> queue = isAlternate ? m_pathLow : m_pathHigh;
                queue.Enqueue(() => TestPath(destination, ignoreEntity, runId, isAlternate, tryAlternates));
                return;
            }
            try
            {
                if (m_grid != m_navBlock.Grid)
                {
                    m_logger.debugLog("Grid has changed, from " + m_grid.getBestName() + " to " + m_navBlock.Grid.getBestName() + ", nav block: " + m_navBlock.Block.getBestName(), Logger.severity.WARNING);
                    return;
                }
                m_logger.debugLog("Running, (destination:" + destination + ", ignoreEntity: " + ignoreEntity.getBestName() + ", runId :" + runId
                                  + ", isAlternate: " + isAlternate + ", tryAlternates: " + tryAlternates + ", slowDown: " + slowDown + ")");

                MyEntity obstructing;
                Vector3? pointOfObstruction;

                if (!isAlternate && !m_ignoreAsteroid)
                {
                    if (slowDown)
                    {
                        if ((m_planetCheckSpeed.CurrentState & PlanetChecker.State.Blocked) != 0)
                        {
                            float speed = Vector3.Distance(m_planetCheckSpeed.ObstructionPoint, m_navBlock.WorldPosition) * 0.1f;
                            if (speed < 1f)
                            {
                                speed = 1f;
                            }
                            m_navSet.Settings_Task_NavWay.SpeedTarget = speed;
                            m_logger.debugLog("Path blocked by planet, set SpeedTarget to " + speed + ", obstructed by planet", Logger.severity.TRACE);
                            return;
                        }
                    }
                    else
                    {
                        if ((m_planetCheckDest.CurrentState & PlanetChecker.State.Blocked) != 0 &&
                            // planet checker is using an older displacement so verify that obstruction is closer than destination
                            Vector3D.DistanceSquared(m_navBlock.WorldPosition, m_planetCheckDest.ObstructionPoint) < Vector3D.DistanceSquared(m_navBlock.WorldPosition, destination))
                        {
                            m_logger.debugLog("path blocked by planet, to destination: " + (destination - m_navBlock.WorldPosition) + ", to obstruction: " + (m_planetCheckDest.ObstructionPoint - m_navBlock.WorldPosition));

                            if (m_pathState < PathState.Searching)
                            {
                                m_pathState = PathState.Searching;
                            }
                            obstructing = m_planetCheckDest.gravcomp;

                            Vector3 direction = Vector3.Normalize(m_navBlock.WorldPosition - obstructing.GetCentre());
                            pointOfObstruction = m_planetCheckDest.ObstructionPoint + direction * 1e3f;

                            float distance = Vector3.Distance(m_navBlock.WorldPosition, pointOfObstruction.Value);

                            MoveObstruction = obstructing;
                            m_pathHigh.Clear();
                            ClearAltPath();
                            if ((m_planetCheckDest.CurrentState & PlanetChecker.State.BlockedPath) != 0)
                            {
                                FindAlternate_AroundObstruction(pointOfObstruction.Value - m_navBlock.WorldPosition, new Vector3[] { direction }, 1e4f, runId);
                            }
                            else                             // blocked by gravity
                            {
                                FindAlternate_AroundObstruction(pointOfObstruction.Value - m_navBlock.WorldPosition, new Vector3[] { direction }, 1e6f, runId);
                            }
                            m_pathLow.Enqueue(() => {
                                if (m_altPath_AlternatesFound != 0)
                                {
                                    SetWaypoint();
                                }
                                RunItem();
                            });
                            m_pathLow.Enqueue(() => m_pathState = PathState.Path_Blocked);

                            return;
                        }
                    }
                }

                // for alternates, check that it can be better than current value
                if (isAlternate)
                {
                    float distToWaypointSquared = (float)Vector3D.DistanceSquared(m_navBlock.WorldPosition, destination);
                    if (distToWaypointSquared * WaypointDistanceBias * WaypointDistanceBias > m_altPath_PathValue * m_altPath_PathValue)
                    {
                        m_logger.debugLog("no point in checking alternate path, bias is too high", Logger.severity.TRACE);
                        m_logger.debugLog("no alternate, yet path value is set", Logger.severity.ERROR, condition: m_altPath_AlternatesFound == 0);
                        IncrementAlternatesFound();
                        return;
                    }
                }

                if (m_pathChecker.TestFast(m_navBlock, destination, m_ignoreAsteroid, ignoreEntity, m_landing))
                {
                    m_logger.debugLog("path is clear (fast)", Logger.severity.TRACE);
                    PathClear(ref destination, runId, isAlternate, slowDown);
                    return;
                }

                if (m_pathChecker.TestSlow(out obstructing, out pointOfObstruction))
                {
                    m_logger.debugLog("path is clear (slow)", Logger.severity.TRACE);
                    PathClear(ref destination, runId, isAlternate, slowDown);
                    return;
                }

                if (runId != m_runId)
                {
                    m_logger.debugLog("destination changed, abort", Logger.severity.DEBUG);
                    return;
                }

                if (slowDown)
                {
                    float speed = Vector3.Distance(pointOfObstruction.Value, m_navBlock.WorldPosition) * 0.1f;
                    if (speed < 1f)
                    {
                        speed = 1f;
                    }
                    IMyEntity destEntity = m_navSet.Settings_Current.DestinationEntity;
                    if (destEntity != null)
                    {
                        destEntity = destEntity.GetTopMostParent();
                    }
                    if (obstructing.GetTopMostParent() == destEntity)
                    {
                        m_navSet.Settings_Task_NavWay.SpeedMaxRelative = speed;
                        m_logger.debugLog("Set SpeedMaxRelative to " + speed + ", obstructing: " + obstructing.getBestName() + ", DestinationEntity: " + m_navSet.Settings_Current.DestinationEntity.getBestName(), Logger.severity.TRACE);
                    }
                    else
                    {
                        m_navSet.Settings_Task_NavWay.SpeedTarget = speed;
                        m_logger.debugLog("Set SpeedTarget to " + speed + ", obstructing: " + obstructing.getBestName() + ", DestinationEntity: " + m_navSet.Settings_Current.DestinationEntity.getBestName(), Logger.severity.TRACE);
                    }
                    return;
                }

                if (m_pathState < PathState.Searching)
                {
                    m_pathState = PathState.Searching;
                }

                m_logger.debugLog("path is blocked by " + obstructing.getBestName() + " at " + pointOfObstruction + ", ignoreEntity: " + ignoreEntity.getBestName(), isAlternate ? Logger.severity.TRACE : Logger.severity.DEBUG);
                m_logger.debugLog("grid: " + obstructing.GetTopMostParent().DisplayName, isAlternate ? Logger.severity.TRACE : Logger.severity.DEBUG, condition: obstructing is IMyCubeBlock);

                if (isAlternate && m_altPath_AlternatesFound != 0)
                {
                    IncrementAlternatesFound();
                }

                if (tryAlternates)
                {
                    //float angle = m_navSet.Settings_Current.DistanceAngle;
                    //if (angle > 0.1f && CanRotate)
                    //{
                    //	m_logger.debugLog("wait for rotation", "TestPath()");
                    //	return;
                    //}

                    if (m_navSet.Settings_Task_NavEngage.NavigatorMover != m_navSet.Settings_Current.NavigatorMover)
                    {
                        m_logger.debugLog("obstructed while flying to a waypoint, throwing it out and starting over", Logger.severity.DEBUG);
                        m_navSet.OnTaskComplete_NavWay();
                        return;
                    }

                    ClearAltPath();
                    MoveObstruction = obstructing;
                    TryAlternates(runId, pointOfObstruction.Value, obstructing);
                }
            }
            finally
            {
                lock_testPath.ReleaseExclusive();
                RunItem();
            }
        }
コード例 #17
0
        private void NetWork_onJoinRoom(string rid, bool result, bool isCreator, Dictionary <string, string[]> roomCache, string[] uids)
        {
            if (rid == null || !rid.Equals(this.roomId))
            {
                return;
            }
            if (result)
            {
                SetStates(SpectatorViewState.InRoom);

                this.isCreator = isCreator;

                if (isCreator)
                {
                    // locate floor
                    // export anchor after that
                    MrShareData._instance.needLocated = true;
                    WaittingForExportAnchor           = true;
                    SetStates(SpectatorViewState.LocatingFloor);
                }
                else
                {
                    if (roomCache != null)
                    {
                        if (roomCache.ContainsKey(RoomCacheKey.RoomCacheKeyAnchor) &&
                            clientType != ClientType.SpectatorViewPc &&
                            clientType != ClientType.IOS)
                        {
                            // do download anchor
                            SetStates(SpectatorViewState.AnchorDownloading);
                            string[] values;
                            roomCache.TryGetValue(RoomCacheKey.RoomCacheKeyAnchor, out values);
                            if (values.Length > 0)
                            {
                                this.anchorName = values[0];
                                OperationBean oper = new OperationBean();
                                oper.op    = OperationBean.OpId.DownAnchor;
                                oper.param = anchorName;

                                operationQueue.Enqueue(oper);
                            }
                        }

                        if (roomCache.ContainsKey(RoomCacheKey.RoomCacheKeyFloorY) &&
                            (clientType == ClientType.SpectatorViewPc ||
                             clientType == ClientType.IOS) || (clientType == ClientType.Hololens && !isCreator))
                        {
                            string[] values;
                            roomCache.TryGetValue(RoomCacheKey.RoomCacheKeyFloorY, out values);
                            if (values != null && values.Length > 0)
                            {
                                string sFloorY = values[0];
                                if (sFloorY != null)
                                {
                                    string[] strArr = sFloorY.Split(':');
                                    if (strArr.Length == 3)
                                    {
                                        _lerpStageWithFloor = float.Parse(strArr[1]);


                                        if (clientType == ClientType.IOS)
                                        {
                                            Vector3 v = new Vector3(float.Parse(strArr[0]), float.Parse(strArr[1]), float.Parse(strArr[2]));

                                            OperationBean opa = new OperationBean();
                                            opa.op    = OperationBean.OpId.ios_AdjustFloorLocate;
                                            opa.param = v;
                                            operationQueue.Enqueue(opa);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (roomCache != null && roomCache.ContainsKey(RoomCacheKey.RoomCacheKeyWaitingMarkerDetect))
                {
                    string[] values;
                    roomCache.TryGetValue(RoomCacheKey.RoomCacheKeyWaitingMarkerDetect, out values);
                    if (values.Length > 0)
                    {
                        string isWaitting = values[0];
                        if (isWaitting != null && isWaitting.Equals("true"))
                        {
                            isWaittingMarkerDetect = true;
                        }
                        else
                        {
                            isWaittingMarkerDetect = false;
                        }
                    }
                }
                OperationBean op = new OperationBean();
                op.op    = OperationBean.OpId.SelfJoinRoom;
                op.param = roomCache;

                operationQueue.Enqueue(op);

                if (uids != null)
                {
                    foreach (string uid in uids)
                    {
                        op       = new OperationBean();
                        op.op    = OperationBean.OpId.UserEnter;
                        op.param = uid;
                        operationQueue.Enqueue(op);
                    }
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Starts checking path against the geometry of the closest planet.
        /// </summary>
        /// <param name="displacement">Destination - current postion</param>
        private void Start(ref Vector3 displacement)
        {
            using (m_lock.AcquireExclusiveUsing())
            {
                if ((CurrentState & State.Running) != 0)
                {
                    return;
                }
                CurrentState |= State.Running;

                m_displacement = displacement;

                m_cells.Clear();

                Vector3D gridCentre = m_grid.GetCentre();
                double   distSq;
                gravcomp = MyPlanetExtensions.GetClosestPlanet(gridCentre, out distSq);

                if (gravcomp == null)
                {
                    //m_logger.debugLog("No planets found", "Start()", Logger.severity.TRACE);
                    CurrentState = State.Clear;
                    return;
                }

                if (distSq > gravcomp.MaximumRadius * gravcomp.MaximumRadius)
                {
                    //m_logger.debugLog("Outside maximum radius of closest planet", "Start()", Logger.severity.TRACE);

                    // gravity test
                    // TODO: it might be worthwhile to perform gravity test against multiple planets
                    Path.From = gridCentre;
                    Path.To   = gridCentre + displacement;

                    Vector3D closestPoint = Path.ClosestPoint(gravcomp.WorldMatrix.Translation);
                    if (closestPoint != Path.From && closestPoint != Path.To)
                    {
                        //float gravityAtClose = ClosestPlanet.GetGravityMultiplier(closestPoint) - MinGravityAvoid;
                        float gravityAtClose = gravComp.GetGravityMultiplier(closestPoint) - MinGravityAvoid;
                        //if (gravityAtClose > 0f && gravityAtClose > ClosestPlanet.GetGravityMultiplier(Path.From) && gravityAtClose > ClosestPlanet.GetGravityMultiplier(Path.To))
                        if (gravityAtClose > 0f && gravityAtClose > gravComp.GetGravityMultiplier(Path.From) && gravityAtClose > gravComp.GetGravityMultiplier(Path.To))
                        {
                            ObstructionPoint = closestPoint;
                            CurrentState     = State.BlockedGravity;
                            return;
                        }
                    }

                    CurrentState = State.Clear;
                    return;
                }

                Vector3 direction;
                Vector3.Normalize(ref displacement, out direction);
                direction = Vector3.Transform(direction, m_grid.WorldMatrixNormalizedInv.GetOrientation());

                GridCellCache.GetCellCache(m_grid).ForEach(cell => {
                    Vector3I rejected;
                    Vector3.Reject(cell, direction).ApplyOperation(x => (int)Math.Round(x), out rejected);

                    if (m_cellsUnique.Add(rejected))
                    {
                        m_cells.Enqueue(rejected);
                    }
                });

                m_cellsUnique.Clear();

                DoTests.Enqueue(TestPath);
            }
        }