コード例 #1
0
        private void UpdateView()
        {
            var newCoords = WorldModelHelper.GetChunkCoordsFromWorldPosition(_playerView.transform.position);

            if (newCoords.x == _lastPlayerCoords.x && newCoords.y == _lastPlayerCoords.y)
            {
                return;
            }

            //Remove unused data + view
            var watch = new Stopwatch();

            watch.Start();

            var removeDataCords   = GetDataCoords(newCoords, MapBoundsLookup.MapDataRemove, true);
            var removeRenderCords = GetRenderCoords(newCoords, MapBoundsLookup.ChunkRemove, true);

            WorldModel.RemoveData(removeDataCords);
            WorldRenderer.RemoveChunks(removeRenderCords, removeDataCords);

            //Create map data + queue chunk render for newly discovered chunks

            var dataCords   = GetDataCoords(newCoords, MapBoundsLookup.MapDataAdd);
            var renderCords = GetRenderCoords(newCoords, MapBoundsLookup.ChunkAdd);

            WorldModel.CreateChunkMaps(dataCords);
            WorldRenderer.RenderChunks(renderCords, dataCords);

            watch.Stop();

            Debug.LogWarning($"<color=\"aqua\">GameAppState.UpdateView() : watch.ElapsedMilliseconds: {watch.ElapsedMilliseconds}</color>");


            _lastPlayerCoords = newCoords;
        }
コード例 #2
0
        private void GenerateWorld(int2 playerPosition)
        {
            var dataCords   = GetDataCoords(playerPosition, MapBoundsLookup.DataGeneration);
            var renderCords = GetRenderCoords(playerPosition, MapBoundsLookup.RenderGeneration);

            Debug.LogWarning($"<color=\"aqua\">GameAppState.GenerateWorld() : RenderGeneration.Length: {MapBoundsLookup.RenderGeneration.Length}</color>");

            var dataWatch = new Stopwatch();

            dataWatch.Start();
            WorldModel.CreateChunkMaps(dataCords);
            dataWatch.Stop();
            Debug.LogWarning($"<color=\"aqua\">GameAppState.GenerateWorld() : dataWatch.ElapsedMilliseconds: {dataWatch.ElapsedMilliseconds}</color>");

            var renderChunksWatch = new Stopwatch();

            renderChunksWatch.Start();
            WorldRenderer.RenderChunks(renderCords, dataCords);
            renderChunksWatch.Stop();
            Debug.LogWarning($"<color=\"aqua\">GameAppState.GenerateWorld() : renderChunksWatch.ElapsedMilliseconds: {renderChunksWatch.ElapsedMilliseconds}</color>");

            _lastPlayerCoords = playerPosition;
        }