コード例 #1
0
ファイル: FogOfWar.cs プロジェクト: canhdoan/Guildmaster
        void ProcessUnits(bool checkstopwatch)
        {
            // remove any invalid units
            FogOfWarUnit.registeredUnits.RemoveAll(u => u == null);

            double millisecondfrequency = 1000.0 / System.Diagnostics.Stopwatch.Frequency;

            for (; _currentUnitProcessing < FogOfWarUnit.registeredUnits.Count; ++_currentUnitProcessing)
            {
                if (!FogOfWarUnit.registeredUnits[_currentUnitProcessing].isActiveAndEnabled || FogOfWarUnit.registeredUnits[_currentUnitProcessing].team != team)
                {
                    continue;
                }

                FogOfWarShape shape = FogOfWarUnit.registeredUnits[_currentUnitProcessing].GetShape(this, physics, plane);
                if (multithreaded && updateAutomatically)
                {
                    _threadPool.Run(() => _drawer.Draw(shape));
                }
                else
                {
                    _drawer.Draw(shape);
                }

                // do the timer check here so that at least one unit will be processed!
                if (checkstopwatch && _stopwatch.ElapsedTicks * millisecondfrequency >= maxMillisecondsPerFrame)
                {
                    ++_currentUnitProcessing;
                    break;
                }
            }
        }
コード例 #2
0
        bool LineOfSightCanSee(FogOfWarShape shape, Vector2 offset, float fogradius)
        {
            if (shape.lineOfSight == null)
            {
                return(true);
            }

            float idx = FogOfWarUtils.ClockwiseAngle(Vector2.up, offset) * shape.lineOfSight.Length / 360.0f;

            if (idx < 0)
            {
                idx += shape.lineOfSight.Length;
            }

            // sampling
            float value;

            if (_map.filterMode == FilterMode.Point)
            {
                value = shape.lineOfSight[Mathf.RoundToInt(idx) % shape.lineOfSight.Length];
            }
            else
            {
                int idxlow  = Mathf.FloorToInt(idx);
                int idxhigh = (idxlow + 1) % shape.lineOfSight.Length;
                value = Mathf.LerpUnclamped(shape.lineOfSight[idxlow], shape.lineOfSight[idxhigh], idx % 1);
            }

            float dist = value * fogradius;

            return(offset.sqrMagnitude < dist * dist);
        }
コード例 #3
0
            public DrawInfo(FogOfWarMap map, FogOfWarShape shape, float xradius, float yradius)
            {
                // convert size to fog space
                fogForward   = shape.foward;
                forwardAngle = FogOfWarUtils.ClockwiseAngle(Vector2.up, fogForward) * Mathf.Deg2Rad;
                float   sin            = Mathf.Sin(-forwardAngle);
                float   cos            = Mathf.Cos(-forwardAngle);
                Vector2 relativeoffset = new Vector2(shape.offset.x * cos - shape.offset.y * sin, shape.offset.x * sin + shape.offset.y * cos);

                fogCenterPos = FogOfWarConversion.WorldToFog(FogOfWarConversion.WorldToFogPlane(shape.eyePosition, map.plane) + relativeoffset, map.offset, map.resolution, map.size);
                fogEyePos    = new Vector2i(FogOfWarConversion.WorldToFog(shape.eyePosition, map.plane, map.offset, map.resolution, map.size));

                // find ranges
                if (shape.visibleCells == null)
                {
                    xMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.x - xradius));
                    xMax = Mathf.Min(map.resolution.x - 1, Mathf.RoundToInt(fogCenterPos.x + xradius));
                    yMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.y - yradius));
                    yMax = Mathf.Min(map.resolution.y - 1, Mathf.RoundToInt(fogCenterPos.y + yradius));
                }
                else
                {
                    fogCenterPos = FogOfWarConversion.SnapToNearestFogPixel(fogCenterPos);
                    fogEyePos    = new Vector2i(FogOfWarConversion.SnapToNearestFogPixel(FogOfWarConversion.WorldToFog(shape.eyePosition, map.offset, map.resolution, map.size)));

                    Vector2i pos = new Vector2i(Mathf.RoundToInt(fogCenterPos.x), Mathf.RoundToInt(fogCenterPos.y));
                    Vector2i rad = new Vector2i(Mathf.RoundToInt(xradius), Mathf.RoundToInt(yradius));
                    xMin = Mathf.Max(0, Mathf.RoundToInt(pos.x - rad.x));
                    xMax = Mathf.Min(map.resolution.x - 1, Mathf.RoundToInt(pos.x + rad.x));
                    yMin = Mathf.Max(0, Mathf.RoundToInt(pos.y - rad.y));
                    yMax = Mathf.Min(map.resolution.y - 1, Mathf.RoundToInt(pos.y + rad.y));
                }
            }
コード例 #4
0
 public void Draw(FogOfWarShape shape)
 {
     if (shape is FogOfWarShapeCircle)
     {
         DrawCircle(shape as FogOfWarShapeCircle);
     }
     else if (shape is FogOfWarShapeBox)
     {
         DrawBox(shape as FogOfWarShapeBox);
     }
     else if (shape is FogOfWarShapeTexture)
     {
         DrawTexture(shape as FogOfWarShapeTexture);
     }
 }
コード例 #5
0
 void FillShape(FogOfWar fow, FogOfWarShape shape)
 {
     if (antiFlicker)
     {
         // snap to nearest fog pixel
         shape.eyePosition = FogOfWarConversion.SnapWorldPositionToNearestFogPixel(fow, FogOfWarConversion.WorldToFogPlane(_transform.position, fow.plane), fow.mapOffset, fow.mapResolution, fow.mapSize);
         shape.eyePosition = FogOfWarConversion.FogPlaneToWorld(shape.eyePosition.x, shape.eyePosition.y, _transform.position.y, fow.plane);
     }
     else
     {
         shape.eyePosition = _transform.position;
     }
     shape.foward = FogOfWarConversion.TransformFogPlaneForward(_transform, fow.plane);
     shape.offset = offset;
     shape.radius = radius;
 }
コード例 #6
0
        public FogOfWarShape GetShape(FogOfWar fow, FogOfWarPhysics physics, FogOfWarPlane plane)
        {
            FogOfWarShape shape = CreateShape(fow);

            if (shape == null)
            {
                return(null);
            }

            if (cellBased)
            {
                shape.lineOfSight  = null;
                shape.visibleCells = CalculateLineOfSightCells(fow, physics, shape.eyePosition);
            }
            else
            {
                shape.lineOfSight  = CalculateLineOfSight(physics, shape.eyePosition, plane);
                shape.visibleCells = null;
            }
            return(shape);
        }
コード例 #7
0
        bool LineOfSightCanSeeCell(FogOfWarShape shape, Vector2i offset)
        {
            if (shape.visibleCells == null)
            {
                return(true);
            }

            int radius = Mathf.RoundToInt(shape.radius);
            int width  = radius + radius + 1;

            offset.x += radius;
            if (offset.x < 0 || offset.x >= width)
            {
                return(true);
            }

            offset.y += radius;
            if (offset.y < 0 || offset.y >= width)
            {
                return(true);
            }

            return(shape.visibleCells[offset.y * width + offset.x]);
        }