JobHandle ProcessViewEntities(bool mapRegenerated, DynamicBuffer <MapTiles> map, MapData mapData, JobHandle inputDeps)
        {
            // Process Entities with only a view and no memory
            return(Entities
                   .WithReadOnly(map)
                   .WithChangeFilter <Position>()
                   .WithNone <TilesInMemory>()
                   .ForEach((ref DynamicBuffer <TilesInView> view, in Position pos, in ViewRange range) =>
            {
                if (view.Length != map.Length || mapRegenerated)
                {
                    view.ResizeUninitialized(map.Length);
                }

                // Always reset view before rebuilding
                for (int i = 0; i < view.Length; ++i)
                {
                    view[i] = false;
                }

                var visibility = new VisibilityMap(
                    mapData.width,
                    mapData.height,
                    map.Reinterpret <TileType>().AsNativeArray(),
                    view.Reinterpret <bool>().AsNativeArray()
                    );

                FOV.Compute(pos, range, visibility);
            }).Schedule(inputDeps));
Ejemplo n.º 2
0
    public void ViewshedContainsNoDuplicates()
    {
        var map = new TestMap(20, 20, Allocator.TempJob,
                              new int2(1, 1),
                              new int2(2, 1));

        FOV.Compute(0, 5, map);

        var points = map.visiblePoints;

        Assert.AreEqual(points.Length, points.ToArray().Distinct().ToArray().Length);

        map.Dispose();
    }
Ejemplo n.º 3
0
    public void TestFOV()
    {
        var map = new TestMap(20, 20, Allocator.TempJob,
                              new int2(1, 1),
                              new int2(2, 1));

        FOV.Compute(0, 5, map);

        var points = map.visiblePoints;

        Assert.False(points.Contains(new int2(3, 3)));
        Assert.True(points.Contains(new int2(2, 1)));
        //Assert.True(points.Contains(new int2(1, 1)));

        map.Dispose();
    }
Ejemplo n.º 4
0
        private void Update()
        {
            var fovPos = WorldToConsolePos(transform.position);

            _testMap.visiblePoints.Clear();
            //var points = FOV.GetVisiblePoints(fovPos, _range, _testMap, Allocator.Temp).ToNativeArray();
            FOV.Compute(fovPos, _range, _testMap);

            _console.ClearScreen();

            foreach (var p in _testMap.visiblePoints)
            {
                char ch = _testMap.IsOpaque(p) ? '#' : '.';
                _console.Set(p.x, p.y, Color.white, Color.black, CodePage437.ToCP437(ch));
            }
        }
Ejemplo n.º 5
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (_FOVQuery.CalculateEntityCount() == 0)
            {
                return(inputDeps);
            }

            var mapEntity = _mapQuery.GetSingletonEntity();
            var map       = EntityManager.GetBuffer <MapTiles>(mapEntity);
            var mapData   = EntityManager.GetComponentData <MapData>(mapEntity);

            var fovEntity = _FOVQuery.GetSingletonEntity();

            int2 origin = EntityManager.GetComponentData <Position>(fovEntity);
            int  range  = EntityManager.GetComponentData <FOVRange>(fovEntity);
            DynamicBuffer <TilesInView> fovTiles = EntityManager.GetBuffer <TilesInView>(fovEntity);

            var visibilityMap = new VisibilityMap(
                mapData.width, mapData.height,
                map.Reinterpret <TileType>().AsNativeArray(),
                Allocator.TempJob);

            inputDeps = Job.WithCode(() =>
            {
                FOV.Compute(origin, range, visibilityMap);

                fovTiles.Clear();

                var visibleTiles = visibilityMap.visibleTiles;

                for (int i = 0; i < visibleTiles.Length; ++i)
                {
                    fovTiles.Add(visibleTiles[i]);
                }
            }).Schedule(inputDeps);

            visibilityMap.Dispose(inputDeps);

            return(inputDeps);
        }
Ejemplo n.º 6
0
 public void Execute()
 {
     FOV.Compute(origin, range, map);
 }
Ejemplo n.º 7
0
 public void Execute()
 {
     FOV.Compute(Origin, Range, Map);
 }