Example #1
0
        protected override void OnUpdate()
        {
            var mapEntity    = GetSingletonEntity <Map>();
            var mapStateData = new MapStateJobContext(this, mapEntity, false);

            var playerEntity = HasSingleton <Player>() ?
                               GetSingletonEntity <Player>() : Entity.Null;

            Dependency = new MonsterAIJob
            {
                MapStateData      = mapStateData,
                EnergyHandle      = GetComponentTypeHandle <Energy>(false),
                ROViewHandle      = GetBufferTypeHandle <MapViewBuffer>(true),
                EntityHandle      = GetEntityTypeHandle(),
                NameHandle        = GetComponentTypeHandle <Name>(true),
                AttackPowerHandle = GetComponentTypeHandle <AttackPower>(true),
                PosFromEntity     = GetComponentDataFromEntity <Position>(false),
                //PlayerPosition = PlayerPos,
                PlayerEntity = playerEntity,
                DefendBFE    = GetBufferFromEntity <CombatDefendBuffer>(false),
                RNG          = _rand,
                //PlayerData = playerPosData
            }.ScheduleSingle(_monstersQuery, Dependency);

            //PlayerPos.Dispose(Dependency);
        }
Example #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);
        }