private void InitServerState()
    {
        if (flyingDirection == Vector2.zero)
        {
            Debug.LogWarning($"{gameObject.name} move direction unclear");
            serverState.Direction = Vector2.up;
        }
        else
        {
            serverState.Direction = Vector2Int.RoundToInt(flyingDirection);
        }
        initialPosition = Vector3Int.RoundToInt(new Vector3(transform.position.x, transform.position.y, 0));
        var child         = transform.GetChild(0);
        var childPosition = Vector3Int.CeilToInt(new Vector3(child.transform.position.x, child.transform.position.y, 0));

        pivot = initialPosition - childPosition;
        Debug.Log($"Calculated pivot {pivot} for {gameObject.name}");

        serverState.Speed       = 1f;
        serverState.Position    = initialPosition;
        serverState.Orientation = Orientation.Up;
        serverTargetState       = serverState;

        clientState       = serverState;
        clientTargetState = serverState;
    }
Beispiel #2
0
        private void DropDownItems()
        {
            State = MatrixState.NONE;

            var current = first;

            while (current != null)
            {
                var bottom    = current;
                int rowKilled = 0;
                while (bottom != null)
                {
                    var marker = bottom;
                    while (marker != null && !marker.Visible && marker.Top != null && marker.Top.Visible)
                    {
                        SwapV(marker, marker.Top);
                        rowKilled++;
                        State = MatrixState.DROP_DOWN;
                    }

                    bottom = bottom.Bottom;
                }

                while (current.Top != null)
                {
                    current = current.Top;
                }

                current = current.Right;
            }
        }
Beispiel #3
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState       = newState;
        clientTargetState = newState;

        if (!StateInit)
        {
            StateInit = true;
        }

        if (!Equals(oldState.Orientation, newState.Orientation))
        {
            OnRotate.Invoke(oldState.Orientation, newState.Orientation);

            //This is ok for occasional state changes like beginning of rot:
            gameObject.BroadcastMessage("MatrixMoveStartRotation", null, SendMessageOptions.DontRequireReceiver);
            monitorOnRot = true;
        }
        if (!oldState.IsMoving && newState.IsMoving)
        {
            OnStart.Invoke();
        }
        if (oldState.IsMoving && !newState.IsMoving)
        {
            OnStop.Invoke();
        }
        if ((int)oldState.Speed != (int)newState.Speed)
        {
            OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }
    }
Beispiel #4
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState       = newState;
        clientTargetState = newState;

        if (!StateInit)
        {
            StateInit = true;
        }

        if (!Equals(oldState.Orientation, newState.Orientation))
        {
            OnRotate.Invoke(oldState.Orientation, newState.Orientation);
        }
        if (!oldState.IsMoving && newState.IsMoving)
        {
            OnStart.Invoke();
        }
        if (oldState.IsMoving && !newState.IsMoving)
        {
            OnStop.Invoke();
        }
        if ((int)oldState.Speed != (int)newState.Speed)
        {
            OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }
    }
Beispiel #5
0
    /// Convert local matrix coordinates to world position. Keeps offsets in mind (+ rotation and pivot if MatrixMove is present)
    public static Vector3 LocalToWorld(Vector3 localPos, MatrixInfo matrix, MatrixState state = default(MatrixState))
    {
        //Invalid matrix info provided
        if (matrix.Equals(MatrixInfo.Invalid) || localPos == TransformState.HiddenPos)
        {
            return(TransformState.HiddenPos);
        }

//		return matrix.MetaTileMap.LocalToWorld( localPos );

        if (!matrix.MatrixMove)
        {
            return(localPos + matrix.Offset);
        }

        if (state.Equals(default(MatrixState)))
        {
            state = matrix.MatrixMove.ClientState;
        }

        Vector3 unpivotedPos   = localPos - matrix.MatrixMove.Pivot;                                        //localPos - localPivot
        Vector3 rotatedPos     = state.FacingOffsetFromInitial(matrix.MatrixMove).Quaternion *unpivotedPos; //unpivotedPos rotated by N degrees
        Vector3 rotatedPivoted = rotatedPos + matrix.MatrixMove.Pivot + matrix.GetOffset(state);            //adding back localPivot and applying localToWorldOffset

        return(rotatedPivoted);
    }
 /// Called when MatrixMoveMessage is received
 public void UpdateClientState(MatrixState newState)
 {
     if (!Equals(clientState.Orientation, newState.Orientation))
     {
         onRotation?.Invoke(clientState.Orientation, newState.Orientation);
     }
     clientState       = newState;
     clientTargetState = newState;
 }
    private void TryNotifyPlayers()
    {
        if (ServerPositionsMatch)
        {
//				When serverState reaches its planned destination,
//				embrace all other updates like changed speed and rotation
            serverState = serverTargetState;
            NotifyPlayers();
        }
    }
Beispiel #8
0
    //이동이 끝나고 다시 이동 버튼을 키는 함수
    public void UIAnimationIn()
    {
        PlayerCtrl pc = player.GetComponent <PlayerCtrl>();

        MatrixState[] states = new MatrixState[4];
        states[0] = pc.pos.GetNorthState();
        states[1] = pc.pos.GetEastState();
        states[2] = pc.pos.GetSouthState();
        states[3] = pc.pos.GetWestState();


        //크리스탈과 ufo 방향을 초기화
        crystalDirection = -1;
        UFODirection     = -1;

        //갈수 있는 곳이면 버튼을 키기
        for (int i = 0; i < 4; i++)
        {
            Debug.Log(states[i]);

            if (states[i] == MatrixState.CAN)
            {
                moveButtons[i].interactable = true;
                fadeinAnim[i].Play();
            }
            if (states[i] == MatrixState.CRYSTAL)
            {
                crystalDirection = i;
            }
            if (states[i] == MatrixState.UFO)
            {
                UFODirection = i;
            }
        }



        if (crystalDirection != -1 && PlayerMgr.Instance.item == PlayerItem.EMPTY)//크리스탈 옆에 있고 크리스탈을 안갖고 있다면

        {
            GameObject.FindGameObjectWithTag("CANVASOVERLAY").SendMessage("ChangeMineButtonState", true,
                                                                          SendMessageOptions.DontRequireReceiver);
        }

        if (UFODirection != -1 && (PlayerMgr.Instance.item == PlayerItem.BLUECRYSTAL ||
                                   PlayerMgr.Instance.item == PlayerItem.REDCRYSTAL))//UFO가 옆에 있고 크리스탈을 갖고 있다면

        {
            GameObject.FindGameObjectWithTag("CANVASOVERLAY").SendMessage("ChangeDropButtonState", true,
                                                                          SendMessageOptions.DontRequireReceiver);
        }


        GameMgr.Instance.NonClickPanel.SetActive(false);
    }
Beispiel #9
0
    public static MatrixMoveMessage SendToAll(GameObject matrix, MatrixState state)
    {
        var msg = new MatrixMoveMessage
        {
            Matrix = matrix != null?matrix.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            State  = state,
        };

        msg.SendToAll();
        return(msg);
    }
Beispiel #10
0
        public static NetMessage SendToAll(GameObject matrix, MatrixState state)
        {
            var msg = new NetMessage
            {
                Matrix = matrix != null?matrix.GetComponent <NetworkedMatrix>().MatrixSync.netId : NetId.Invalid,
                State  = state,
            };

            SendToAll(msg);
            return(msg);
        }
Beispiel #11
0
 private void TryNotifyPlayers()
 {
     if (ServerPositionsMatch)
     {
         //				When serverState reaches its planned destination,
         //				embrace all other updates like changed speed and rotation
         serverState = serverTargetState;
         Logger.LogTraceFormat("{0} setting server state from target state {1}", Category.Shuttles, this, serverState);
         NotifyPlayers();
     }
 }
 public Vector3Int GetOffset(MatrixState state = default(MatrixState))
 {
     if (!MatrixMove)
     {
         return(InitialOffset);
     }
     if (state.Equals(default(MatrixState)))
     {
         state = MatrixMove.ClientState;
     }
     return(InitialOffset + (Vector3Int.RoundToInt(state.Position) - MatrixMove.InitialPos));
 }
Beispiel #13
0
    private void InitServerState()
    {
        if (flyingDirection == Vector2.zero)
        {
            Logger.LogWarning($"{gameObject.name} move direction unclear", Category.Matrix);
            serverState.Direction = Orientation.Up;
        }
        else
        {
            serverState.Direction = Orientation.From(Vector2Int.RoundToInt(flyingDirection));
        }

        Vector3Int initialPositionInt =
            Vector3Int.RoundToInt(new Vector3(transform.position.x, transform.position.y, 0));

        initialPosition = initialPositionInt;
        InitialPos      = initialPosition.RoundToInt();
        //initialOrientation = Orientation.From( serverState.Direction );
        serverState.initialOrientation = serverState.Direction;

        var child = transform.GetChild(0);

        MatrixInfo = MatrixManager.Get(child.gameObject);
        var childPosition = Vector3Int.CeilToInt(new Vector3(child.transform.position.x, child.transform.position.y, 0));

        pivot = initialPosition - childPosition;
        Pivot = pivot.RoundToInt();

        Logger.LogTraceFormat("{0}: pivot={1} initialPos={2}, initialOrientation={3}", Category.Matrix, gameObject.name,
                              pivot, initialPositionInt, serverState.initialOrientation);
        serverState.Speed       = 1f;
        serverState.Position    = initialPosition;
        serverState.orientation = serverState.initialOrientation;
        serverTargetState       = serverState;

        clientState       = serverState;
        clientTargetState = serverState;
        if (SensorPositions == null)
        {
            CollisionSensor[] sensors = GetComponentsInChildren <CollisionSensor>();
            if (sensors.Length == 0)
            {
                SensorPositions = new Vector3Int[0];
                return;
            }

            SensorPositions = sensors.Select(sensor => Vector3Int.RoundToInt(sensor.transform.localPosition)).ToArray();

            Logger.Log($"Initialized sensors at {string.Join(",", SensorPositions)}," +
                       $" direction is {State.Direction}", Category.Matrix);
        }
    }
Beispiel #14
0
    public Vector3Int GetOffset(MatrixState state = default(MatrixState))
    {
        if (!MatrixMove || !MatrixMove.IsMoving)
        {
            return(CachedOffset);
        }

        if (state.Equals(default(MatrixState)))
        {
            state = MatrixMove.ClientState;
        }

        CachedOffset = initialOffset + (state.Position.RoundToInt() - MatrixMove.InitialPos);
        return(CachedOffset);
    }
        public GraphicsDevice(IntPtr target)
        {
            context = OpenGLContext.GetContext();

            context.Samples = 4;
            // Create context using platform specific methods
            context.CreateContext(target, IntPtr.Zero, null);
            //GL.InitGeneral(context);
            //foreach (var str in GL.GetSupportedExtensions())
            //Console.WriteLine(str);

            modelview_matrix  = new MatrixState();
            projection_matrix = new MatrixState();
            texture_matrix    = new MatrixState();
            normal_matrix     = new MatrixState();

            var err = GL.glGetError();

            GL.InitGL_1_2(context);
            GL.InitGL_1_3(context);
            GL.InitGL_1_4(context);
            GL.InitGL_1_5(context);
            GL.InitGL_2_0(context);
            GL.InitGL_2_1(context);
            GL.InitGL_3_0(context);
            GL.InitGL_3_1(context);
            GL.InitGL_3_2(context);
            GL.InitFramebuffers(context);
            GL.InitVertexArrayObjects(context);
            var sp = GL.GetSupportedExtensions();

            if (sp.Contains("GL_AMD_debug_output"))
            {
                GL.InitDebugOutputAMD(context);
                GL.glDebugMessageCallbackAMD(new OpenGL.OpenGL.DebugProc(DebugProcecure), IntPtr.Zero);
                GL.glDebugMessageEnableAMD(0, 0, 0, new int[] { }, GL.boolean.TRUE);
            }

            err = GL.glGetError();

            GL.glEnable(GL.Const.GL_TEXTURE_2D);

            state       = new OpenGLState(this);
            state.Blend = true;
            state.BlendFunction(Blend.SrcAlpha, Blend.OneMinusSrcAlpha);
            state.Culling   = true;
            state.DepthTest = true;
        }
Beispiel #16
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState       = newState;
        clientTargetState = newState;

        if (!Equals(oldState.orientation, newState.orientation) || !ReceivedInitialRotation)
        {
            if (!ReceivedInitialRotation)
            {
                //this is the first state, so set initial rotation based on offset from initial position
                previousRotation          = newState.RotationOffset;
                performingInitialRotation = true;
            }
            else
            {
                //update based on offset from old state
                previousRotation = oldState.orientation.OffsetTo(newState.orientation);
            }
            OnRotateStart.Invoke(previousRotation, !ReceivedInitialRotation);

            //This is ok for occasional state changes like beginning of rot:
            gameObject.BroadcastMessage("MatrixMoveStartRotation", null, SendMessageOptions.DontRequireReceiver);
            monitorOnRot = true;
        }

        if (!ReceivedInitialRotation)
        {
            ReceivedInitialRotation = true;
        }

        if (!oldState.IsMoving && newState.IsMoving)
        {
            OnStart.Invoke();
        }

        if (oldState.IsMoving && !newState.IsMoving)
        {
            OnStop.Invoke();
        }

        if ((int)oldState.Speed != (int)newState.Speed)
        {
            OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }
    }
        public void PopMatrix()
        {
            MatrixState state = matrixState[matrixMode];

            unsafe
            {
#if FIXEDSTACK
                float *m = state.Stack.Pop();
                vgLoadMatrix(m);
#else
                float[] m = state.Stack.Pop();
                fixed(float *p = m)
                {
                    vgLoadMatrix(p);
                }
#endif
            }
        }
Beispiel #18
0
        private void CreateNewItems()
        {
            State = MatrixState.NONE;

            var current = first;

            while (current != null)
            {
                var top = current;

                while (top != null && !top.Visible)
                {
                    top.NewLife();
                    State = MatrixState.CREATE;
                    top   = top.Bottom;
                }

                current = current.Right;
            }
        }
Beispiel #19
0
    public Vector3Int GetOffset(MatrixState state = default(MatrixState))
    {
        if (!MatrixMove)
        {
            return(InitialOffset);
        }

        if (state.Equals(default(MatrixState)))
        {
            state = MatrixMove.ClientState;
        }

        if (cachedPosition != state.Position)
        {
            //if we moved, update cached offset
            cachedPosition = state.Position;
            CachedOffset   = initialOffset + (state.Position.RoundToInt() - MatrixMove.InitialPosition);
        }

        return(CachedOffset);
    }
 /// Called when MatrixMoveMessage is received
 public void UpdateClientState(MatrixState newState)
 {
     if (!Equals(clientState.Orientation, newState.Orientation))
     {
         OnRotate.Invoke(clientState.Orientation, newState.Orientation);
     }
     if (!clientState.IsMoving && newState.IsMoving)
     {
         OnStart.Invoke();
     }
     if (clientState.IsMoving && !newState.IsMoving)
     {
         OnStop.Invoke();
     }
     if ((int)clientState.Speed != (int)newState.Speed)
     {
         OnSpeedChange.Invoke(clientState.Speed, newState.Speed);
     }
     clientState       = newState;
     clientTargetState = newState;
 }
        public void PushMatrix()
        {
            MatrixState state = matrixState[matrixMode];

            unsafe
            {
#if FIXEDSTACK
                float *m = stackalloc float[9];
                vgGetMatrix(m);
                state.Stack.Push(m);
#else
                float[] m = new float[9];
                fixed(float *p = m)
                {
                    vgGetMatrix(p);
                }

                state.Stack.Push(m);
#endif
            }
        }
Beispiel #22
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState       = newState;
        clientTargetState = newState;
        Logger.LogTraceFormat("{0} setting client / client target state from message {1}", Category.Matrix, this, newState);


        if (!Equals(oldState.FacingDirection, newState.FacingDirection))
        {
            if (!receivedInitialState && !pendingInitialRotation)
            {
                pendingInitialRotation = true;
            }
            inProgressRotation = oldState.FacingDirection.OffsetTo(newState.FacingDirection);
            Logger.LogTraceFormat("{0} starting rotation progress to {1}", Category.Matrix, this, newState.FacingDirection);
            MatrixMoveEvents.OnRotate.Invoke(new MatrixRotationInfo(this, inProgressRotation.Value, NetworkSide.Client, RotationEvent.Start));
        }

        if (!oldState.IsMoving && newState.IsMoving)
        {
            MatrixMoveEvents.OnStartMovementClient.Invoke();
        }

        if (oldState.IsMoving && !newState.IsMoving)
        {
            MatrixMoveEvents.OnStopMovementClient.Invoke();
        }

        if ((int)oldState.Speed != (int)newState.Speed)
        {
            MatrixMoveEvents.OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }

        if (!receivedInitialState && !pendingInitialRotation)
        {
            receivedInitialState = true;
        }
    }
Beispiel #23
0
    //현재 맵 매트릭스의 한칸한칸의 정보를 불러오는 함수, 갈수 있는 곳이면 true를 반환
    public bool GetMatrixState(Position pos, out MatrixState state)
    {
        if (pos.R >= 30 || pos.R < 0 || pos.C >= 30 || pos.C < 0)
        {
            state = MatrixState.OUT;
            return(false);
        }

        switch (mapMatrix[pos.R, pos.C])
        {
        case MatrixState.CAN:
            state = MatrixState.CAN;
            return(true);

        case MatrixState.CRYSTAL:
            state = MatrixState.CRYSTAL;
            return(false);

        case MatrixState.UFO:
            state = MatrixState.UFO;
            return(false);

        case MatrixState.PLAYER:
            state = MatrixState.PLAYER;
            return(false);

        case MatrixState.AI:
            state = MatrixState.AI;
            return(false);

        case MatrixState.OUT:
            state = MatrixState.OUT;
            return(false);

        default:
            state = MatrixState.ERROR;
            return(false);
        }
    }
    /// Convert local matrix coordinates to world position. Keeps offsets in mind (+ rotation and pivot if MatrixMove is present)
    public static Vector3 LocalToWorld(Vector3 localPos, MatrixInfo matrix, MatrixState state = default(MatrixState))
    {
        //Invalid matrix info provided
        if (matrix.Equals(MatrixInfo.Invalid))
        {
            return(TransformState.HiddenPos);
        }
        if (!matrix.MatrixMove)
        {
            return(localPos + matrix.Offset);
        }

        if (state.Equals(default(MatrixState)))
        {
            state = matrix.MatrixMove.ClientState;
        }

        Vector3 unpivotedPos   = localPos - matrix.MatrixMove.Pivot;                             //localPos - localPivot
        Vector3 rotatedPos     = state.Orientation.Euler * unpivotedPos;                         //unpivotedPos rotated by N degrees
        Vector3 rotatedPivoted = rotatedPos + matrix.MatrixMove.Pivot + matrix.GetOffset(state); //adding back localPivot and applying localToWorldOffset

        return(rotatedPivoted);
    }
 public DestroyState(Matrix matrix, MatrixState oldState) : base(matrix)
 {
     this.oldState = oldState;
 }
Beispiel #26
0
 /// Convert local matrix coordinates to world position. Keeps offsets in mind (+ rotation and pivot if MatrixMove is present)
 public static Vector3Int LocalToWorldInt(Vector3 localPos, MatrixInfo matrix, MatrixState state = default(MatrixState))
 {
     return(Vector3Int.RoundToInt(LocalToWorld(localPos, matrix, state)));
 }
Beispiel #27
0
        public GraphicsDevice(IntPtr target)
        {
            context = OpenGLContext.GetContext();

            context.Samples = 4;
            // Create context using platform specific methods
            context.CreateContext(target, IntPtr.Zero, null);
            //GL.InitGeneral(context);
            //foreach (var str in GL.GetSupportedExtensions())
                //Console.WriteLine(str);

            modelview_matrix = new MatrixState();
            projection_matrix = new MatrixState();
            texture_matrix = new MatrixState();
            normal_matrix = new MatrixState();

            var err = GL.glGetError();
            GL.InitGL_1_2(context);
            GL.InitGL_1_3(context);
            GL.InitGL_1_4(context);
            GL.InitGL_1_5(context);
            GL.InitGL_2_0(context);
            GL.InitGL_2_1(context);
            GL.InitGL_3_0(context);
            GL.InitGL_3_1(context);
            GL.InitGL_3_2(context);
            GL.InitFramebuffers(context);
            GL.InitVertexArrayObjects(context);
            var sp = GL.GetSupportedExtensions();
            if (sp.Contains("GL_AMD_debug_output"))
            {
                GL.InitDebugOutputAMD(context);
                GL.glDebugMessageCallbackAMD(new OpenGL.OpenGL.DebugProc(DebugProcecure), IntPtr.Zero);
                GL.glDebugMessageEnableAMD(0, 0, 0, new int[] { }, GL.boolean.TRUE);
            }

            err = GL.glGetError();

            GL.glEnable(GL.Const.GL_TEXTURE_2D);

            state = new OpenGLState(this);
            state.Blend = true;
            state.BlendFunction(Blend.SrcAlpha, Blend.OneMinusSrcAlpha);
            state.Culling = true;
            state.DepthTest = true;
        }
Beispiel #28
0
 public bool Equals(MatrixState other)
 {
     return(Position.Equals(other.Position) && orientation.Equals(other.orientation));
 }
Beispiel #29
0
    private void InitServerState()
    {
        serverState.FlyingDirection = InitialFacing;
        serverState.FacingDirection = InitialFacing;
        Logger.LogTraceFormat("{0} server initial facing / flying {1}", Category.Shuttles, this, InitialFacing);

        Vector3Int initialPositionInt =
            Vector3Int.RoundToInt(new Vector3(transform.position.x, transform.position.y, 0));

        SyncInitialPosition(initialPosition, initialPositionInt);

        var child         = transform.GetChild(0);
        var childPosition = Vector3Int.CeilToInt(new Vector3(child.transform.position.x, child.transform.position.y, 0));

        SyncPivot(pivot, initialPosition - childPosition);

        Logger.LogTraceFormat("{0}: pivot={1} initialPos={2}", Category.Shuttles, gameObject.name,
                              pivot, initialPositionInt);
        serverState.Speed    = 1f;
        serverState.Position = initialPosition;
        serverTargetState    = serverState;
        clientState          = serverState;

        RecheckThrusters();
        if (thrusters.Count > 0)
        {
            foreach (var thruster in thrusters)
            {
                var integrity = thruster.GetComponent <Integrity>();
                if (integrity)
                {
                    integrity.OnWillDestroyServer.AddListener(destructionInfo =>
                    {
                        if (thrusters.Contains(thruster))
                        {
                            thrusters.Remove(thruster);
                        }

                        if (thrusters.Count == 0 && IsMovingServer)
                        {
                            StartCoroutine(StopWithDelay(1f));
                        }
                    });
                }
            }
        }

        if (SensorPositions == null)
        {
            CollisionSensor[] sensors = GetComponentsInChildren <CollisionSensor>();
            if (sensors.Length == 0)
            {
                SensorPositions = new Vector3Int[0];
                return;
            }

            SensorPositions = sensors.Select(sensor => Vector3Int.RoundToInt(sensor.transform.localPosition)).ToArray();

            Logger.Log($"Initialized sensors at {string.Join(",", SensorPositions)}," +
                       $" direction is {ServerState.FlyingDirection}", Category.Shuttles);
        }

        if (RotationSensors == null)
        {
            RotationCollisionSensor[] sensors = GetComponentsInChildren <RotationCollisionSensor>();
            if (sensors.Length == 0)
            {
                RotationSensors = new GameObject[0];
                return;
            }

            if (rotationSensorContainerObject == null)
            {
                rotationSensorContainerObject = sensors[0].transform.parent.gameObject;
            }

            RotationSensors = sensors.Select(sensor => sensor.gameObject).ToArray();
        }

        IEnumerator StopWithDelay(float delay)
        {
            SetSpeed(ServerState.Speed / 2);
            yield return(WaitFor.Seconds(delay));

            Logger.LogFormat("{0}: Stopping due to missing thrusters!", Category.Shuttles, matrix.name);
            StopMovement();
        }
    }
Beispiel #30
0
    /// Called when MatrixMoveMessage is received
    public void UpdateClientState(MatrixState newState)
    {
        var oldState = clientState;

        clientState = newState;
        matrix.MetaTileMap.GlobalCachedBounds = null;
        Logger.LogTraceFormat("{0} setting client / client target state from message {1}", Category.Shuttles, this, newState);


        if (!Equals(oldState.FacingDirection, newState.FacingDirection))
        {
            if (!receivedInitialState && !pendingInitialRotation)
            {
                pendingInitialRotation = true;
            }
            inProgressRotation = oldState.FacingDirection.OffsetTo(newState.FacingDirection);
            Logger.LogTraceFormat("{0} starting rotation progress to {1}", Category.Shuttles, this, newState.FacingDirection);
            MatrixMoveEvents.OnRotate.Invoke(new MatrixRotationInfo(this, inProgressRotation.Value, NetworkSide.Client, RotationEvent.Start));
        }

        if (rcsModeActive)
        {
            // enable engines for clients that aren't using RCS
            if (clientState.IsMoving && !oldState.IsMoving && rcsMovementStartPosition != Vector2Int.RoundToInt(clientState.Position))
            {
                OrientationEnum releativeDirection = GetReleativeOrientation(clientState.FacingDirection.AsEnum(), clientState.FlyingDirection.AsEnum());
                StartCoroutine(ClientRCSCoroutine(releativeDirection, clientState.FlyingDirection, false));
            }

            // don't teleport player back to start point
            Vector2Int roundedPosition = Vector2Int.RoundToInt(clientState.Position);
            if (roundedPosition == rcsMovementStartPosition)
            {
                clientState.FlyingDirection = oldState.FlyingDirection;
                clientState.Position        = oldState.Position;
                clientState.Speed           = oldState.Speed;
                clientState.IsMoving        = oldState.IsMoving;

                canClientUseRcs = true;
            }
            else if (roundedPosition == rcsMovementTargetPosition)
            {
                clientState.Position = new Vector3(rcsMovementTargetPosition.x, rcsMovementTargetPosition.y, clientState.Position.z);
                canClientUseRcs      = true;
            }
            // else - player is teleported to server position
            else
            {
                canClientUseRcs = true;
            }
        }

        if (!oldState.IsMoving && newState.IsMoving)
        {
            MatrixMoveEvents.OnStartMovementClient.Invoke();
        }

        if (oldState.IsMoving && !newState.IsMoving)
        {
            MatrixMoveEvents.OnStopMovementClient.Invoke();
        }

        if ((int)oldState.Speed != (int)newState.Speed)
        {
            MatrixMoveEvents.OnSpeedChange.Invoke(oldState.Speed, newState.Speed);
        }

        if (!receivedInitialState && !pendingInitialRotation)
        {
            receivedInitialState = true;
        }
    }
Beispiel #31
0
        public static NetMessage Send(NetworkConnection recipient, GameObject matrix, MatrixState state)
        {
            var msg = new NetMessage
            {
                Matrix = matrix != null?matrix.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
                State  = state,
            };

            SendTo(recipient, msg);
            return(msg);
        }