Beispiel #1
0
        void RenderMapInView(BufferJobData <MapViewBuffer> viewData, TerminalJobContext termData)
        {
            var mapData       = new MapJobContext(this, GetSingletonEntity <Map>(), true);
            var tileAssetsCTX = new MapTileAssetsBufferJobContext(this, true);

            Job.WithReadOnly(mapData)
            .WithReadOnly(viewData)
            .WithCode(() =>
            {
                var map  = mapData.Grid;
                var term = termData.GetAccessor();
                var view = viewData.GetArray <bool>();

                var tileAssets = tileAssetsCTX.Tiles;

                if (view.Length == 0)
                {
                    return;
                }

                TerminalTile t = TerminalTile.Default;

                for (int i = 0; i < view.Length; ++i)
                {
                    if (view[i])
                    {
                        int tileType = (int)map[i];
                        t            = tileAssets[tileType];
                        term[i]      = t;
                    }
                }
            }).Schedule();
        }
Beispiel #2
0
        protected override void OnUpdate()
        {
            bool changed =
                //_addedActors.CalculateEntityCount() != 0 ||
                //_removedActors.CalculateEntityCount() != 0 ||
                !(_movedActors.IsEmpty &&
                  _mapChanged.IsEmpty);

            if (!changed)
            {
                return;
            }

            var mapEntity = GetSingletonEntity <Map>();
            var mapData   = new MapJobContext(this, mapEntity, true);
            var stateData = new MapStateJobContext(this,
                                                   mapEntity, false);

            // Update from map state
            Entities
            .WithReadOnly(mapData)
            .ForEach((ref DynamicBuffer <MapObstaclesBuffer> obstaclesBuffer,
                      ref DynamicBuffer <MapEntitiesBuffer> entitiesBuffer) =>
            {
                //Debug.Log("Clearing all map state, adding walls");
                var map = mapData.Grid;

                var obstacles = obstaclesBuffer.Reinterpret <bool>().AsNativeArray();

                for (int i = 0; i < obstacles.Length; ++i)
                {
                    obstacles[i] = map[i] == MapTileType.Wall;
                }

                //Clear entities too since we're rebuilding entities state
                // from path blocker entities next
                unsafe
                {
                    int stride = UnsafeUtility.SizeOf <Entity>();
                    UnsafeUtility.MemClear(entitiesBuffer.GetUnsafePtr(), entitiesBuffer.Length * stride);
                }
            }).Schedule();

            //Debug.Log($"Actors on map count: {_actorsOnMap.CalculateEntityCount()}");

            // Update from actor state
            Dependency = new UpdateFromPathBlockers
            {
                StateData    = stateData,
                EntityHandle = GetEntityTypeHandle(),
                PosHandle    = GetComponentTypeHandle <Position>(true)
            }.ScheduleSingle(_actorsOnMap, Dependency);
        }
Beispiel #3
0
        protected override void OnUpdate()
        {
            var mapEntity = GetSingletonEntity <Map>();
            var mapData   = new MapJobContext(this, mapEntity, true);

            Entities
            .WithChangeFilter <Movement>()
            .WithReadOnly(mapData)
            .ForEach((
                         ref Position position,
                         ref Movement movement) =>
            {
                //Debug.Log($"Moving from {position.Value} to {position + (int2)movement}");
                var map = mapData.Grid;

                int2 next = position + (int2)movement;

                if (map[next] == MapTileType.Floor)
                {
                    position += (int2)movement;
                }
                movement = int2.zero;
            }).Schedule();
        }