Пример #1
0
        protected override void OnStartRunning()
        {
            var mapData = _mapQuery.GetSingleton <MapData>();

            _console = new SimpleConsole(mapData.width, mapData.height);

            RenderUtility.AdjustCameraToConsole(_console);
        }
        protected override void OnStartRunning()
        {
            var mapEntity = GetSingletonEntity <MapTiles>();
            var mapData   = EntityManager.GetComponentData <MapData>(mapEntity);

            _console = new SimpleConsole(mapData.width, mapData.height);

            RenderUtility.AdjustCameraToConsole(_console);
        }
Пример #3
0
        IEnumerator VerifyCamera()
        {
            while (_consoleProxy != null && isActiveAndEnabled && Application.isPlaying)
            {
                RenderUtility.AdjustCameraToConsole(_consoleProxy, _camera);

                yield return(_waitTime);
            }
        }
Пример #4
0
        void Rebuild()
        {
            _console.Resize(_width, _height);

            // Only needs to be called if we're using "screen" effects in the console shader.
            //RenderUtility.UpdatePixelEffectData(_console);

            // Must be called any time the console is resized
            RenderUtility.AdjustCameraToConsole(_console);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var  mapData = GetSingleton <MapData>();
            int2 mapSize = new int2(mapData.width, mapData.height);

            if (mapData.width != _console.Width || mapData.height != _console.Height)
            {
                _console.Resize(mapData.width, mapData.height);
                RenderUtility.AdjustCameraToConsole(_console);
                return(inputDeps);
            }

            _console.ClearScreen();

            // Since we're iterating all tiles in the map we can probably benefit from using burst.
            // We can't use the console in a job since it's a managed object, so copy all tile data
            var tiles = _console.ReadAllTiles(Allocator.TempJob);

            Entities
            .ForEach((ref DynamicBuffer <MapTiles> map) =>
            {
                for (int i = 0; i < map.Length; ++i)
                {
                    Tile t    = new Tile();
                    t.bgColor = Color.black;
                    switch ((TileType)map[i])
                    {
                    case TileType.Floor:
                        t.fgColor = new Color(0.5f, 0.5f, 0.5f);
                        t.glyph   = ToCP437('.');
                        break;

                    case TileType.Wall:
                        t.fgColor = new Color(0, 1, 0);
                        t.glyph   = ToCP437('#');
                        break;
                    }

                    tiles[i] = t;
                }
            }).Run();

            _console.WriteAllTiles(tiles);

            tiles.Dispose();

            Entities
            .WithoutBurst()
            .WithAll <Player>()
            .ForEach((in Position pos) =>
            {
                int2 p = math.clamp(pos, 1, mapSize - 1);
                _console.Set(p.x, p.y, Color.yellow, Color.black, ToCP437('@'));
            }).Run();
Пример #6
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var mapEntity = _mapQuery.GetSingletonEntity();

            var mapData = _mapQuery.GetSingleton <MapData>();

            if (mapData.width != _console.Width || mapData.height != _console.Height)
            {
                _console.Resize(mapData.width, mapData.height);
                RenderUtility.AdjustCameraToConsole(_console);
                return(inputDeps);
            }

            var map = EntityManager.GetBuffer <MapTiles>(mapEntity);

            // The map has been resized but not yet updated
            if ((mapData.width * mapData.height) != map.Length)
            {
                return(inputDeps);
            }

            var playerEntity = _playerQuery.GetSingletonEntity();
            var view         = EntityManager.GetBuffer <TilesInView>(playerEntity);
            var memory       = EntityManager.GetBuffer <TilesInMemory>(playerEntity);

            _console.ClearScreen();

            Job
            .WithoutBurst()
            .WithCode(() =>
            {
                Color fg = default;
                Color bg = Color.black;
                char ch  = default;
                for (int x = 0; x < mapData.width; ++x)
                {
                    for (int y = 0; y < mapData.height; ++y)
                    {
                        int idx = y * mapData.width + x;
                        if (memory[idx])
                        {
                            var tile = (TileType)map[idx];
                            if (view[idx])
                            {
                                switch (tile)
                                {
                                case TileType.Floor:
                                    fg = new Color(0, .5f, .5f);
                                    ch = '.';
                                    break;

                                case TileType.Wall:
                                    fg = new Color(0, 1, 0);
                                    ch = '#';
                                    break;
                                }
                            }
                            else
                            {
                                fg = new Color(0.1f, .1f, 0.1f);
                                switch (tile)
                                {
                                case TileType.Floor:
                                    ch = '.';
                                    break;

                                case TileType.Wall:
                                    ch = '#';
                                    break;
                                }
                            }

                            _console.Set(x, y, fg, bg, ToCP437(ch));
                        }
                    }
                }
            }).Run();


            Entities
            .WithoutBurst()
            .ForEach((in Renderable render, in Position pos) =>
            {
                int2 p = math.clamp(pos, 1, mapData.Size - 1);
                if (view[p.y * mapData.width + p.x])
                {
                    _console.Set(p.x, p.y, render.fgColor, render.bgColor, render.glyph);
                }
            }).Run();
Пример #7
0
 protected override void OnStartRunning()
 {
     RenderUtility.AdjustCameraToConsole(_console);
 }
Пример #8
0
        protected override void OnUpdate()
        {
            var mapEntity = _mapQuery.GetSingletonEntity();

            var mapData = _mapQuery.GetSingleton <MapData>();

            if (mapData.width != _console.Width || mapData.height != _console.Height)
            {
                _console.Resize(mapData.width, mapData.height);
                RenderUtility.AdjustCameraToConsole(_console);
                return;
            }

            RenderUtility.AdjustCameraToConsole(_console);

            var map = EntityManager.GetBuffer <MapTiles>(mapEntity);

            // The map has been resized but not yet updated
            if ((mapData.width * mapData.height) != map.Length)
            {
                return;
            }

            if (_playerQuery.IsEmptyIgnoreFilter)
            {
                return;
            }

            // Since we're iterating all tiles in the map we can probably benefit from using burst.
            // We can't use the console in a job since it's a managed object, so we'll work directly with tiles
            var tiles = new NativeArray <Tile>(_console.CellCount, Allocator.Temp, NativeArrayOptions.ClearMemory);

            var playerEntity = _playerQuery.GetSingletonEntity();

            bool hasView   = EntityManager.HasComponent <TilesInView>(playerEntity);
            bool hasMemory = EntityManager.HasComponent <TilesInMemory>(playerEntity);

            _console.ClearScreen();

            if (!hasMemory && !hasView)
            {
                RenderEverything(map, tiles, mapData.Size);
            }
            else
            {
                if (hasMemory)
                {
                    var memory = EntityManager.GetBuffer <TilesInMemory>(playerEntity);
                    RenderMemory(map, memory, tiles, mapData.Size);
                }

                if (hasView)
                {
                    var view = EntityManager.GetBuffer <TilesInView>(playerEntity);
                    RenderView(map, view, tiles, mapData.Size);
                }
            }

            _console.WriteAllTiles(tiles);

            _console.Update();
            _console.Draw();
        }
Пример #9
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var mapEntity = _mapQuery.GetSingletonEntity();

            var mapData = _mapQuery.GetSingleton <MapData>();

            if (mapData.width != _console.Width || mapData.height != _console.Height)
            {
                _console.Resize(mapData.width, mapData.height);
                RenderUtility.AdjustCameraToConsole(_console);
                return(inputDeps);
            }


            var fovEntity = _fovQuery.GetSingletonEntity();
            var fovTiles  = EntityManager.GetBuffer <TilesInView>(fovEntity).AsNativeArray();
            var mapMemory = EntityManager.GetBuffer <TilesInMemory>(fovEntity);

            var map = EntityManager.GetBuffer <MapTiles>(mapEntity);

            _console.ClearScreen();

            Job.WithoutBurst().WithCode(() =>
            {
                for (int x = 0; x < mapData.width; ++x)
                {
                    for (int y = 0; y < mapData.height; ++y)
                    {
                        int idx = y * mapData.width + x;
                        if (mapMemory[idx])
                        {
                            switch ((TileType)map[idx])
                            {
                            case TileType.Floor:
                                _console.Set(x, y, new Color(0.1f, 0.1f, 0.1f), Color.black, ToCP437('.'));
                                break;

                            case TileType.Wall:
                                _console.Set(x, y, new Color(0.1f, .1f, 0.1f), Color.black, ToCP437('#'));
                                break;
                            }
                        }
                    }
                }
            }).Run();

            Job.WithoutBurst().WithCode(() =>
            {
                for (int i = 0; i < fovTiles.Length; ++i)
                {
                    var p   = fovTiles[i].value;
                    int idx = p.y * mapData.width + p.x;

                    switch ((TileType)map[idx])
                    {
                    case TileType.Floor:
                        _console.Set(p.x, p.y, new Color(0, 0.5f, 0.5f), Color.black, ToCP437('.'));
                        break;

                    case TileType.Wall:
                        _console.Set(p.x, p.y, new Color(0, 1, 0), Color.black, ToCP437('#'));
                        break;
                    }
                }
            }).Run();

            Entities
            .WithoutBurst()
            .WithAll <Player>()
            .ForEach((in Position pos) =>
            {
                int2 p = math.clamp(pos, 1, mapData.Size - 1);
                _console.Set(p.x, p.y, Color.yellow, Color.black, ToCP437('@'));
            }).Run();