public void DoAfterInit()
        {
            for (int i = 0; i < gridInfo.tileMaps.Length; i++)
            {
                var tilemap = gridInfo.tileMaps[i];
                if (tilemap.isTagMap)
                {
                    continue;
                }
                var tilemapMin  = tilemap.min;
                var tilemapSize = tilemap.size;
                mapDataMin.x = LMath.Min(mapDataMin.x, tilemapMin.x);
                mapDataMin.y = LMath.Min(mapDataMin.y, tilemapMin.y);
                mapDataMax.x = LMath.Max(mapDataMax.y, tilemapMin.x + tilemapSize.x);
                mapDataMax.y = LMath.Max(mapDataMax.y, tilemapMin.y + tilemapSize.y);
            }

            mapDataSize = (mapDataMax - mapDataMin) + LVector2Int.one;
            mapDataIds  = new ushort[mapDataSize.x, mapDataSize.y];
            for (int x = 0; x < mapDataSize.x; x++)
            {
                for (int y = 0; y < mapDataSize.y; y++)
                {
                    var pos = new Vector2Int(mapDataMin.x + x, mapDataMin.y + y);
                    mapDataIds[x, y] = RawPos2TileId(pos, true);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="o">射线起点</param>
        /// <param name="d">射线终点</param>
        /// <param name="min">矩形的左下角坐标</param>
        /// <param name="max">矩形的右上角坐标</param>
        /// <param name="tmin">返回距离</param>
        /// <returns></returns>
        public static bool TestRayAABB(LVector2 o, LVector2 d, LVector2 min, LVector2 max, out LFloat tmin)
        {
            tmin = LFloat.zero;
            LFloat tmax = LFloat.FLT_MAX;

            for (int i = 0; i < 2; i++)
            {
                if (LMath.Abs(d[i]) < LFloat.EPSILON)
                {
                    if (o[i] < min[i] || o[i] > max[i])
                    {
                        return(false);
                    }
                }
                else
                {
                    LFloat ood = LFloat.one / d[i];
                    LFloat t1  = (min[i] - o[i]) * ood;
                    LFloat t2  = (max[i] - o[i]) * ood;
                    if (t1 > t2)
                    {
                        var temp = t1;
                        t1 = t2;
                        t2 = temp;
                    }
                    tmin = LMath.Max(tmin, t1);
                    tmax = LMath.Min(tmax, t2);
                    if (tmin > tmax)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        private void UpdatePingVal(float deltaTime)
        {
            _pingTimer += deltaTime;
            if (_pingTimer > 0.5f)
            {
                _pingTimer = 0;
                DelayVal   = (int)(_delays.Sum() / LMath.Max(_delays.Count, 1));
                _delays.Clear();
                PingVal = (int)(_pings.Sum() / LMath.Max(_pings.Count, 1));
                _pings.Clear();

                if (_minPing < _historyMinPing && _simulatorService._gameStartTimestampMs != -1)
                {
                    _historyMinPing = _minPing;
#if UNITY_EDITOR
                    Debug.LogWarning(
                        $"Recalc _gameStartTimestampMs {_simulatorService._gameStartTimestampMs} _guessServerStartTimestamp:{_guessServerStartTimestamp}");
#endif
                    _simulatorService._gameStartTimestampMs = LMath.Min(_guessServerStartTimestamp,
                                                                        _simulatorService._gameStartTimestampMs);
                }

                _minPing = Int64.MaxValue;
                _maxPing = Int64.MinValue;
            }
        }
Esempio n. 4
0
        public void Execute()
        {
            foreach (var entity in _moveRequest.GetEntities())
            {
                var deltaTime = _gameStateService.DeltaTime;
                var mover     = entity.move;
                var dir       = entity.dir.value;
                var pos       = entity.pos.value;
                var moveSpd   = mover.moveSpd;

                //can move 判定
                var dirVec       = DirUtil.GetDirLVec(dir);
                var moveDist     = (moveSpd * deltaTime);
                var fTargetHead  = pos + (TankUtil.TANK_HALF_LEN + moveDist) * dirVec;
                var fPreviewHead = pos + (TankUtil.TANK_HALF_LEN + TankUtil.FORWARD_HEAD_DIST) * dirVec;

                LFloat maxMoveDist = moveSpd * deltaTime;
                var    headPos     = pos + (TankUtil.TANK_HALF_LEN) * dirVec;
                var    dist        = _gameCollisionService.GetMaxMoveDist(dir, headPos, fTargetHead);
                var    dist2       = _gameCollisionService.GetMaxMoveDist(dir, headPos, fPreviewHead);
                maxMoveDist = LMath.Max(LFloat.zero, LMath.Min(maxMoveDist, dist, dist2));

                var diffPos = maxMoveDist * dirVec;
                pos = pos + diffPos;
                entity.pos.value = pos;
            }
        }
Esempio n. 5
0
 public void DoAfterInit()
 {
     for (int i = 0; i < this.gridInfo.tileMaps.Length; i++)
     {
         TileInfos tileInfos = this.gridInfo.tileMaps[i];
         bool      isTagMap  = tileInfos.isTagMap;
         if (!isTagMap)
         {
             LVector2Int min  = tileInfos.min;
             LVector2Int size = tileInfos.size;
             this.mapDataMin.x = LMath.Min(this.mapDataMin.x, min.x);
             this.mapDataMin.y = LMath.Min(this.mapDataMin.y, min.y);
             this.mapDataMax.x = LMath.Max(this.mapDataMax.y, min.x + size.x);
             this.mapDataMax.y = LMath.Max(this.mapDataMax.y, min.y + size.y);
         }
     }
     this.mapDataSize = this.mapDataMax - this.mapDataMin + LVector2Int.one;
     this.mapDataIds  = new ushort[this.mapDataSize.x, this.mapDataSize.y];
     for (int j = 0; j < this.mapDataSize.x; j++)
     {
         for (int k = 0; k < this.mapDataSize.y; k++)
         {
             LVector2Int pos = new LVector2Int(mapDataMin.x + j, mapDataMin.y + k);
             this.mapDataIds[j, k] = this.RawPos2TileId(pos, false);
         }
     }
 }
Esempio n. 6
0
 public void CheckAndSendHashCodes()
 {
     if (cmdBuffer.nextTickToCheck > firstHashTick)
     {
         var count = LMath.Min(allHashCodes.Count, (int)(cmdBuffer.nextTickToCheck - firstHashTick),
                               (480 / 8));
         if (count > 0)
         {
             _networkService.SendHashCodes(firstHashTick, allHashCodes, 0, count);
             firstHashTick = firstHashTick + count;
             allHashCodes.RemoveRange(0, count);
         }
     }
 }
Esempio n. 7
0
 public void CheckAndSendHashCodes()
 {
     //only sends the hashCodes whose FrameInputs was checked
     if (_cmdBuffer.NextTickToCheck > _firstHashTick)
     {
         var count = LMath.Min(_allHashCodes.Count, (int)(_cmdBuffer.NextTickToCheck - _firstHashTick),
                               (480 / 4));
         if (count > 0)
         {
             _networkService.SendHashCodes(_firstHashTick, _allHashCodes, 0, count);
             _firstHashTick = _firstHashTick + count;
             _allHashCodes.RemoveRange(0, count);
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 向目标角度旋转
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="maxDegreesDelta"></param>
        /// <returns></returns>
        public static LQuaternion RotateTowards(LQuaternion from, LQuaternion to, LFloat maxDegreesDelta)
        {
            LFloat      num    = LQuaternion.Angle(from, to);
            LQuaternion result = new LQuaternion();

            if (num == 0)
            {
                result = to;
            }
            else
            {
                LFloat t = LMath.Min(LFloat.one, maxDegreesDelta / num);
                result = LQuaternion.SlerpUnclamped(from, to, t);
            }

            return(result);
        }
        public void JumpTo(int tick)
        {
            if (tick + 1 == _world.Tick || tick == _world.Tick)
            {
                return;
            }
            tick = LMath.Min(tick, _videoFrames.frames.Length - 1);
            var time = LTime.realtimeSinceStartupMS + 0.05f;

            if (!_isInitVideo)
            {
                _constStateService.IsVideoLoading = true;
                while (_world.Tick < _videoFrames.frames.Length)
                {
                    var sFrame = _videoFrames.frames[_world.Tick];
                    Simulate(sFrame, true);
                    if (LTime.realtimeSinceStartupMS > time)
                    {
                        EventHelper.Trigger(EEvent.VideoLoadProgress, _world.Tick * 1.0f / _videoFrames.frames.Length);
                        return;
                    }
                }

                _constStateService.IsVideoLoading = false;
                EventHelper.Trigger(EEvent.VideoLoadDone);
                _isInitVideo = true;
            }

            if (_world.Tick > tick)
            {
                RollbackTo(tick, _videoFrames.frames.Length, false);
            }

            while (_world.Tick <= tick)
            {
                var sFrame = _videoFrames.frames[_world.Tick];
                Simulate(sFrame, false);
            }

            _viewService.RebindAllEntities();
            _timestampOnLastJumpToMs = LTime.realtimeSinceStartupMS;
            _tickOnLastJumpTo        = tick;
        }
Esempio n. 10
0
        public void JumpTo(int tick)
        {
            bool flag = tick + 1 == this._world.Tick || tick == this._world.Tick;

            if (!flag)
            {
                tick = LMath.Min(tick, this._videoFrames.frames.Length - 1);
                float num   = (float)LTime.realtimeSinceStartupMS + 0.05f;
                bool  flag2 = !this._isInitVideo;
                if (flag2)
                {
                    this._globalStateService.IsVideoLoading = true;
                    while (this._world.Tick < this._videoFrames.frames.Length)
                    {
                        ServerFrame frame = this._videoFrames.frames[this._world.Tick];
                        this.Simulate(frame, true);
                        bool flag3 = (float)LTime.realtimeSinceStartupMS > num;
                        if (flag3)
                        {
                            EventHelper.Trigger(EEvent.VideoLoadProgress, (float)this._world.Tick * 1f / (float)this._videoFrames.frames.Length);
                            return;
                        }
                    }
                    this._globalStateService.IsVideoLoading = false;
                    EventHelper.Trigger(EEvent.VideoLoadDone, null);
                    this._isInitVideo = true;
                }
                bool flag4 = this._world.Tick > tick;
                if (flag4)
                {
                    this.RollbackTo(tick, this._videoFrames.frames.Length, false);
                }
                while (this._world.Tick <= tick)
                {
                    ServerFrame frame2 = this._videoFrames.frames[this._world.Tick];
                    this.Simulate(frame2, false);
                }
                this._viewService.RebindAllEntities();
                this._timestampOnLastJumpToMs = LTime.realtimeSinceStartupMS;
                this._tickOnLastJumpTo        = tick;
            }
        }
Esempio n. 11
0
        // Token: 0x060000C9 RID: 201 RVA: 0x00005514 File Offset: 0x00003714
        public void CheckAndSendHashCodes()
        {
            bool flag = this._cmdBuffer.NextTickToCheck > this._firstHashTick;

            if (flag)
            {
                int num = LMath.Min(new int[]
                {
                    this._allHashCodes.Count,
                    this._cmdBuffer.NextTickToCheck - this._firstHashTick,
                    120
                });
                bool flag2 = num > 0;
                if (flag2)
                {
                    this._networkService.SendHashCodes(this._firstHashTick, this._allHashCodes, 0, num);
                    this._firstHashTick += num;
                    this._allHashCodes.RemoveRange(0, num);
                }
            }
        }
Esempio n. 12
0
        private void UpdatePingVal(float deltaTime)
        {
            this._pingTimer += deltaTime;
            bool flag = this._pingTimer > 0.5f;

            if (flag)
            {
                this._pingTimer = 0f;
                this.DelayVal   = (int)(this._delays.Sum() / (long)LMath.Max(this._delays.Count, 1));
                this._delays.Clear();
                this.PingVal = (int)(this._pings.Sum() / (long)LMath.Max(this._pings.Count, 1));
                this._pings.Clear();
                bool flag2 = this._minPing < this._historyMinPing && this._simulatorService._gameStartTimestampMs != -1L;
                if (flag2)
                {
                    this._historyMinPing = this._minPing;
                    Debug.LogWarning(string.Format("Recalc _gameStartTimestampMs {0} _guessServerStartTimestamp:{1}", this._simulatorService._gameStartTimestampMs, this._guessServerStartTimestamp), Array.Empty <object>());
                    this._simulatorService._gameStartTimestampMs = LMath.Min(this._guessServerStartTimestamp, this._simulatorService._gameStartTimestampMs);
                }
                this._minPing = long.MaxValue;
                this._maxPing = long.MinValue;
            }
        }
Esempio n. 13
0
        /// <summary>
        ///  判定点是否在多边形内
        /// https://stackoverflow.com/questions/217578/how-can-i-determine-whether-a-2d-point-is-within-a-polygon
        /// </summary>
        public static bool IsPointInPolygon(LVector2 p, LVector2[] polygon)
        {
            var minX = polygon[0]._x;
            var maxX = polygon[0]._x;
            var minY = polygon[0]._y;
            var maxY = polygon[0]._y;

            for (int i = 1; i < polygon.Length; i++)
            {
                LVector2 q = polygon[i];
                minX = LMath.Min(q._x, minX);
                maxX = LMath.Max(q._x, maxX);
                minY = LMath.Min(q._y, minY);
                maxY = LMath.Max(q._y, maxY);
            }

            if (p._x < minX || p._x > maxX || p._y < minY || p._y > maxY)
            {
                return(false);
            }

// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
            bool inside = false;

            for (int i = 0, j = polygon.Length - 1; i < polygon.Length; j = i++)
            {
                if ((polygon[i]._y > p._y) != (polygon[j]._y > p._y) &&
                    p._x < (polygon[j]._x - polygon[i]._x) * (p._y - polygon[i]._y) /
                    (polygon[j]._y - polygon[i]._y) +
                    polygon[i]._x)
                {
                    inside = !inside;
                }
            }

            return(inside);
        }
Esempio n. 14
0
        /// <summary>
        /// 夹角大小
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static LFloat Angle(LQuaternion a, LQuaternion b)
        {
            LFloat single = Dot(a, b);

            return(LMath.Acos(LMath.Min(LMath.Abs(single), LFloat.one)) * 2 * (180 / LMath.PI));
        }