コード例 #1
0
        void MoveToTargetPosition()
        {
            if (this._visualArc)
            {
                long progress = FixedMath.Create(this.AliveTime) / 32;
                long height   = this.arcStartHeight + this.arcStartVerticalSpeed.Mul(progress) - Gravity.Mul(progress.Mul(progress));
                this.Position.z = height;
            }
            else
            {
                this.Position.z = FixedMath.MoveTowards(this.Position.z, TargetHeight, this.linearHeightSpeed);
            }

            LSProjectile.tempDirection = TargetPosition - this.Position.ToVector2d();
            if (LSProjectile.tempDirection.Dot(this.lastDirection.x, this.lastDirection.y) < 0L || tempDirection == Vector2d.zero)
            {
                this.Hit();
                //Debug.Log("asdf");
            }
            else
            {
                //Debug.Log("asdf2");
                LSProjectile.tempDirection.Normalize();
                Forward                     = tempDirection;
                this.lastDirection          = LSProjectile.tempDirection;
                LSProjectile.tempDirection *= this.speedPerFrame;
                this.Position.Add(LSProjectile.tempDirection.ToVector3d());
            }
        }
コード例 #2
0
        public void Simulate()
        {
            this.AliveTime++;

            if (this.AliveTime > this.MaxDuration)
            {
                ProjectileManager.EndProjectile(this);
                return;
            }
            switch (this.TargetingBehavior)
            {
            case TargetingType.Timed:
                this.CountDown--;
                if (this.CountDown == 0)
                {
                    this.Hit();
                }
                break;

            case TargetingType.Homing:
                if (this._visualArc)
                {
                    long progress = FixedMath.Create(this.AliveTime) / 32;
                    long height   = this.arcStartHeight + this.arcStartVerticalSpeed.Mul(progress) - Gravity.Mul(progress.Mul(progress));
                    this.Position.z = height;
                }
                else
                {
                    this.TargetHeight = this.Target.Body.HeightPos + Target.Body.Height / 2;
                    this.Position.z   = FixedMath.MoveTowards(this.Position.z, TargetHeight, this.linearHeightSpeed);
                }
                if (this.CheckCollision())
                {
                    this.TargetPosition = this.Target.Body._position;
                    this.Hit();
                }
                else
                {
                    LSProjectile.tempDirection = this.Target.Body._position - this.Position.ToVector2d();
                    if (LSProjectile.tempDirection.Dot(this.lastDirection.x, this.lastDirection.y) < 0L)
                    {
                        this.TargetPosition = this.Target.Body._position;
                        this.Hit();
                    }
                    else
                    {
                        LSProjectile.tempDirection.Normalize();
                        Forward                     = tempDirection;
                        this.lastDirection          = LSProjectile.tempDirection;
                        LSProjectile.tempDirection *= this.speedPerFrame;
                        this.Position.Add(LSProjectile.tempDirection.ToVector3d());
                    }
                }
                break;

            case TargetingType.Free:
                RaycastMove(this.Velocity);
                break;
            }
        }
コード例 #3
0
        public static int GenerateDeltaCount(int size)
        {
            long fixSize = FixedMath.Create(size);
            int  ret     = FixedMath.Mul(FixedMath.Mul(fixSize, fixSize), FixedMath.Pi).CeilToInt();

            return(ret);
        }
コード例 #4
0
        public static void FixedNumberAngle(string label, ref long Value)
        {
            double roundedDisplay = 0;

            roundedDisplay = Math.Round(Math.Asin(Value.ToDouble()) * RadToDeg, 2, MidpointRounding.AwayFromZero);
            Value          = FixedMath.Create(Math.Sin(DegToRad * EditorGUILayout.DoubleField(label, roundedDisplay)));
        }
コード例 #5
0
        public long GetHeight(int mapIndex, Vector2d position)
        {
            if (mapIndex >= Maps.Length)
            {
                return(this.HeightBounds.x);
            }
            HeightMap map        = Maps[mapIndex];
            long      normX      = (position.x - this._bottomLeft.x).Div(Interval);
            long      normY      = (position.y - this._bottomLeft.y).Div(Interval);
            int       gridX      = FixedMath.ToInt(normX);
            int       gridY      = FixedMath.ToInt(normY);
            long      fractionX  = (normX - FixedMath.Create(gridX));
            long      fractionY  = (normY - FixedMath.Create(gridY));
            long      baseHeight = map.GetHeight(gridX, gridY);

            int nextX = Mathf.Clamp(gridX + 1, 0, map.Map.Width);

            int nextY = Mathf.Clamp(gridY + 1, 0, map.Map.Height);

            //bilinear lerp
            long h1 = FixedMath.Lerp(baseHeight, map.GetHeight(nextX, gridY), fractionX);
            long h2 = FixedMath.Lerp(map.GetHeight(gridX, nextY), map.GetHeight(nextX, nextY), fractionX);

            return(FixedMath.Lerp(h1, h2, fractionY) + this.BonusHeight);
        }
コード例 #6
0
ファイル: FixedMath.cs プロジェクト: Fitcal/LockstepFramework
 /// <summary>
 /// Tries to parse string into fixed point number.
 /// </summary>
 /// <returns><c>true</c>, if parse was tried, <c>false</c> otherwise.</returns>
 /// <param name="s">S.</param>
 /// <param name="result">Result.</param>
 public static bool TryParse(string s, out long result)
 {
     string[] NewValues = s.Split('.');
     if (NewValues.Length <= 2)
     {
         long Whole;
         if (long.TryParse(NewValues[0], out Whole))
         {
             if (NewValues.Length == 1)
             {
                 result = Whole << SHIFT_AMOUNT;
                 return(true);
             }
             else
             {
                 long Numerator;
                 if (long.TryParse(NewValues[1], out Numerator))
                 {
                     int  fractionDigits = NewValues[1].Length;
                     long Denominator    = 1;
                     for (int i = 0; i < fractionDigits; i++)
                     {
                         Denominator *= 10;
                     }
                     result = (Whole << SHIFT_AMOUNT) + FixedMath.Create(Numerator, Denominator);
                     return(true);
                 }
             }
         }
     }
     result = 0;
     return(false);
 }
コード例 #7
0
 public void init(float x, float y, float halfx, float halfy)
 {
     m_Center.x = FixedMath.Create(x);
     m_Center.y = FixedMath.Create(y);
     m_Half.x   = FixedMath.Create(halfx);
     m_Half.y   = FixedMath.Create(halfy);
     setRotation((long)0);
 }
コード例 #8
0
 public void update(float x, float y, float halfx, float halfy)
 {
     m_Center.x = FixedMath.Create(x);
     m_Center.y = FixedMath.Create(y);
     m_Half.x   = FixedMath.Create(halfx);
     m_Half.y   = FixedMath.Create(halfy);
     init(m_Center, m_Half.x, m_Half.y);
 }
コード例 #9
0
        public static void FixedNumberField(string label, ref long Value, long max = 0)
        {
            var value = FixedMath.Create(EditorGUILayout.DoubleField(label, Math.Round(FixedMath.ToDouble(Value), 2, MidpointRounding.AwayFromZero)));

            if (max == 0 || value <= max)
            {
                Value = value;
            }
            else
            {
                Value = max;
            }
        }
コード例 #10
0
		protected override void OnLateInitialize()
		{
			long gridWidth = FixedMath.Create(GridManager.Width);
			long gridHeight = FixedMath.Create(GridManager.Height);
			long widthEdgeOffset = (gridWidth - _mapWidth) / 2;
			long heightEdgeOffset = (gridHeight - _mapHeight) / 2;
			Area gridArea = new Area(
				GridManager.OffsetX,
				GridManager.OffsetY,
				GridManager.OffsetX + gridWidth,
				GridManager.OffsetY + gridHeight
			);
			Area noBlockArea = new Area(
				gridArea.XCorner1 + widthEdgeOffset,
				gridArea.YCorner1 + heightEdgeOffset,
				gridArea.XCorner2 - widthEdgeOffset,
				gridArea.YCorner2 - heightEdgeOffset
			);

			//block top
			ManualBlocker.BlockArea(new Area(
				gridArea.XMin,
				noBlockArea.YMax,
				gridArea.XMax,
				gridArea.YMax
			));

			//block bottom
			ManualBlocker.BlockArea(new Area(
				gridArea.XMin,
				gridArea.YMin,
				gridArea.XMax,
				noBlockArea.YMin
			));

			//block right
			ManualBlocker.BlockArea(new Area(
				noBlockArea.XMax,
				noBlockArea.YMin,
				gridArea.XMax,
				noBlockArea.YMax
			));
			//block left
			ManualBlocker.BlockArea(new Area(
				gridArea.XMin,
				noBlockArea.YMin,
				noBlockArea.XMin,
				noBlockArea.XMax
			));

		}
コード例 #11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty angle      = property.FindPropertyRelative("_angle");
            SerializedProperty timescaled = property.FindPropertyRelative("_timescaled");
            double             scale      = LSEditorUtility.Scale(timescaled.boolValue);

            angle.doubleValue    = EditorGUILayout.DoubleField(label, angle.doubleValue * scale) / scale;
            timescaled.boolValue = EditorGUILayout.Toggle("Timescaled", timescaled.boolValue);

            double angleInRadians = angle.doubleValue * Math.PI / 180d;

            property.FindPropertyRelative("_cos").longValue = FixedMath.Create(Math.Cos(angleInRadians));
            property.FindPropertyRelative("_sin").longValue = FixedMath.Create(Math.Sin(angleInRadians));
        }
コード例 #12
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            double scale = ((FixedNumberAngleAttribute)this.attribute).Timescaled ? LockstepManager.FrameRate : 1;
            double angle = Math.Round(Math.Asin(property.longValue.ToDouble()) * RadToDeg, 2, MidpointRounding.AwayFromZero);

            angle = EditorGUI.DoubleField(position, label, angle * scale) / scale;
            double max = ((FixedNumberAngleAttribute)this.attribute).Max;

            if (max > 0 && angle > max)
            {
                angle = max;
            }
            property.longValue = FixedMath.Create(Math.Sin(DegToRad * angle));
        }
コード例 #13
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (!m_bArrived)
            {
                if (!m_bFindPath)
                {
                    m_MyPath.FastClear();
                    StartPos = new Vector2d(FixedMath.Create(transform.position.x), FixedMath.Create(transform.position.z));
                    EndPos   = new Vector2d(FixedMath.Create(m_Destination.x), FixedMath.Create(m_Destination.z));
                    if (m_Blocker)
                    {
                        m_Blocker.RemoveAllCoordinates();
                    }
                    ++m_SearchCount;
                    if (Pathfinder.FindPath(StartPos, EndPos, m_MyPath))
                    {
                        m_Index          = 0;
                        m_bFindPath      = true;
                        m_bArrivedMiddle = true;
                    }
                    else
                    {
                        m_bFindPath = false;
                        m_bArrived  = true;
                    }

                    if (m_Blocker)
                    {
                        m_Blocker.ReAddAllCoordinates();
                    }
                }
                if (m_bFindPath)
                {
                    if (m_Index < m_MyPath.Count)
                    {
                        if (m_bArrivedMiddle)
                        {
                            m_Target = m_MyPath[m_Index];
                            ++m_Index;
                            m_bArrivedMiddle = false;
                            m_TargetPos      = m_Target.ToVector3(transform.position.y);
                            transform.LookAt(m_TargetPos);
                            //GetComponent<Rigidbody>().velocity = transform.forward * 10;
                            m_CurDis  = Vector2.Distance(transform.position, m_TargetPos);
                            m_LastDis = m_CurDis + 1.0f;
                        }
                    }
                }
            }
        }
コード例 #14
0
        public static void SetField(string name, float value, FieldType fieldType)
        {
            SerializedProperty prop = GetProperty(name);

            switch (fieldType)
            {
            case FieldType.FixedNumber:
                prop.longValue = FixedMath.Create(value);
                break;

            case FieldType.Interval:
                prop.intValue = Mathf.RoundToInt(value * LockstepManager.FrameRate);
                break;

            case FieldType.Rate:
                prop.intValue = Mathf.RoundToInt((1 / value) * LockstepManager.FrameRate);
                break;
            }
            Apply();
        }
コード例 #15
0
        public short[,] Scan(int scanLayers)
        {
            int widthPeriods = Size.x.Div(Interval).CeilToInt();

            int heightPeriods = Size.y.Div(Interval).CeilToInt();

            short[,] heightMap = new short[widthPeriods, heightPeriods];


            Vector3 startPos = _bottomLeft.ToVector3(HeightBounds.y.ToFloat());
            Vector3 scanPos  = startPos;
            float   dist     = (HeightBounds.y - HeightBounds.x).ToFloat();

            float fRes = Interval.ToFloat();

            for (int x = 0; x < widthPeriods; x++)
            {
                scanPos.z = startPos.z;
                for (int y = 0; y < heightPeriods; y++)
                {
                    RaycastHit hit;
                    long       height;
                    if (Physics.Raycast(scanPos, Vector3.down, out hit, dist, scanLayers, QueryTriggerInteraction.UseGlobal))
                    {
                        height = FixedMath.Create(hit.point.y);
                    }
                    else
                    {
                        height = HeightBounds.x;
                    }

                    heightMap[x, y] = Compress(height);
                    scanPos.z      += fRes;
                }
                scanPos.x += fRes;
            }

            return(heightMap);
        }
コード例 #16
0
 public void setRotation(float rotation)
 {
     setRotation(FixedMath.Create(rotation));
 }
コード例 #17
0
 public static long GetRandomOne()
 {
     return(FixedMath.Create(GetRandom(), int.MaxValue));
 }
コード例 #18
0
 public Vector3d(int X, int Y, int Z)
 {
     this.x = FixedMath.Create(X);
     this.y = FixedMath.Create(Y);
     this.z = FixedMath.Create(Z);
 }
コード例 #19
0
 public Vector2dHeight(Vector3 vec3)
 {
     _x      = FixedMath.Create(vec3.x);
     _y      = FixedMath.Create(vec3.z);
     _height = vec3.y;
 }
コード例 #20
0
 public static void FixedNumberField(GUIContent content, ref long Value)
 {
     Value = FixedMath.Create(EditorGUILayout.DoubleField(content, Math.Round(FixedMath.ToDouble(Value), 2, MidpointRounding.AwayFromZero)));
 }
コード例 #21
0
        public static void DoubleField(Rect position, GUIContent label, ref long value, bool timescaled = false)
        {
            double scale = Scale(timescaled);

            value = FixedMath.Create(EditorGUI.DoubleField(position, label, value.ToDouble() * scale) / scale);
        }
コード例 #22
0
 public Vector2d(Vector3 vec)
 {
     this.x = FixedMath.Create(vec.x);
     this.y = FixedMath.Create(vec.z);
 }
コード例 #23
0
 public Vector2d(Vector2 vec2)
 {
     this.x = FixedMath.Create(vec2.x);
     this.y = FixedMath.Create(vec2.y);
 }
コード例 #24
0
 public long z; //Height
 public Vector3d(Vector3 vec3)
 {
     this.x = FixedMath.Create(vec3.x);
     this.y = FixedMath.Create(vec3.z);
     this.z = FixedMath.Create(vec3.y);
 }
コード例 #25
0
 public static long GetWorldY(int gridY)
 {
     return((FixedMath.Create(gridY + BoundY)) << AdditionalShiftSize);
 }
コード例 #26
0
 public static long GetRelativeY(long yPos)
 {
     return((yPos >> AdditionalShiftSize) - (FixedMath.Create(BoundY)));
 }
コード例 #27
0
 public GridSettings()
 {
     Init(256, 256, FixedMath.Create(-128), FixedMath.Create(-128), true);
 }
コード例 #28
0
 public Vector2d(float xFloat, float yFloat)
 {
     this.x = FixedMath.Create(xFloat);
     this.y = FixedMath.Create(yFloat);
 }
コード例 #29
0
 /// <summary>
 /// World pos to relative position on grid.
 /// </summary>
 /// <returns>The relative x.</returns>
 /// <param name="xPos">X position.</param>
 public static long GetRelativeX(long xPos)
 {
     return((xPos >> AdditionalShiftSize) - (FixedMath.Create(BoundX)));
 }
コード例 #30
0
 public Vector2d(double xDoub, double yDoub)
 {
     this.x = FixedMath.Create(xDoub);
     this.y = FixedMath.Create(yDoub);
 }