Exemple #1
0
        public void Run()
        {
            if (_bleedingStats.EntitiesCount <= 0)
            {
                throw new Exception("BleedingSystem was not init!");
            }

            BleedingStatsComponent stats = _bleedingStats.Components1[0];

            foreach (int i in _woundedPeds)
            {
                BleedingInfoComponent info    = _woundedPeds.Components1[i];
                WoundedComponent      wounded = _woundedPeds.Components2[i];
                int pedEntity = _woundedPeds.Entities[i];

                foreach (int woundEntity in wounded.WoundEntities)
                {
                    var baseBleeding = _ecsWorld.GetComponent <BaseBleedingComponent>(woundEntity);
                    if (baseBleeding == null)
                    {
                        continue;
                    }

                    float baseSeverity = baseBleeding.BaseBleeding;
                    if (baseSeverity <= 0)
                    {
                        continue;
                    }

                    int   bodyPartEntity = _woundedPeds.Components3[i].DamagedBodyPartEntity;
                    float bodyPartMult   = _ecsWorld.GetComponent <BleedingMultComponent>(bodyPartEntity).Multiplier;
                    float sevWithMult    = stats.BleedingMultiplier * bodyPartMult * baseSeverity;

                    float sevDeviation = sevWithMult * stats.BleedingDeviation;
                    sevDeviation = Random.NextFloat(-sevDeviation, sevDeviation);

                    float finalSeverity = sevWithMult + sevDeviation;

                    int bleedingEntity = _ecsWorld.CreateEntityWith(out BleedingComponent bleeding);
                    bleeding.Severity = finalSeverity;
#if DEBUG
                    _logger.MakeLog(
                        $"Created bleeding {woundEntity.GetEntityName(_ecsWorld)} for Entity ({pedEntity}). " +
                        $"Base severity {baseSeverity:0.00}; final severity {finalSeverity:0.00}");
#endif
                    info.BleedingEntities.Add(bleedingEntity);
                }

#if DEBUG
                _ecsWorld.ProcessDelayedUpdates();
                string bleedingList = "";
                foreach (int bleedEntity in info.BleedingEntities)
                {
                    bleedingList += $"{_ecsWorld.GetComponent<BleedingComponent>(bleedEntity).Severity:0.00} ";
                }

                _logger.MakeLog($"BleedingList: {bleedingList}");
#endif
            }
        }
        public void Run()
        {
            foreach (int i in _pedsToRemove)
            {
                PedBleedingInfoComponent info = _pedsToRemove.Components1[i];
                EcsEntity pedEntity           = _pedsToRemove.Entities[i];
                foreach (EcsEntity entity in info.BleedingEntities)
                {
                    _ecsWorld.RemoveEntity(entity);
                }

                _ecsWorld.RemoveComponent <PedBleedingInfoComponent>(pedEntity);
            }

            _ecsWorld.ProcessDelayedUpdates();

            foreach (int i in _healedEntities)
            {
                PedBleedingInfoComponent info = _healedEntities.Components1[i];
                foreach (EcsEntity bleedingEntity in info.BleedingEntities)
                {
                    if (!_ecsWorld.IsEntityExists(bleedingEntity))
                    {
                        continue;
                    }

                    _ecsWorld.RemoveEntity(bleedingEntity);
                }
            }
        }
Exemple #3
0
        public void Run()
        {
            if (_playerConfig.EntitiesCount <= 0)
            {
                throw new Exception("Player system was not init!");
            }

            var config = _playerConfig.Components1[0];

            foreach (int i in _playerPeds)
            {
                Ped ped    = _playerPeds.Components1[i].ThisPed;
                int entity = _playerPeds.Entities[i];
                if (Game.LocalPlayer.Character.Equals(ped))
                {
                    continue;
                }

                _ecsWorld.RemoveComponent <PlayerMarkComponent>(entity);
#if DEBUG
                _logger.MakeLog($"PlayerMark removed from ped {ped.Name(entity)}, 'cause different characters");
#endif
            }

            foreach (int i in _newPeds)
            {
                Ped ped    = _newPeds.Components1[i].ThisPed;
                int entity = _newPeds.Entities[i];
                if (!ped.IsLocalPlayer)
                {
                    continue;
                }

                if (config.PlayerEnabled)
                {
                    _ecsWorld.AddComponent <PlayerMarkComponent>(entity);
                    NativeFunction.Natives.SET_PLAYER_HEALTH_RECHARGE_MULTIPLIER(Game.LocalPlayer, 0f);
#if DEBUG
                    _logger.MakeLog($"Ped {ped.Name(entity)} was marked as player");
#endif
                }
                else
                {
                    _ecsWorld.RemoveComponent <NewPedMarkComponent>(entity);
#if DEBUG
                    _logger.MakeLog($"NewPedMark removed from ped {ped.Name(entity)}, 'cause player is disabled");
#endif
                }
            }

            _ecsWorld.ProcessDelayedUpdates();
            if (config.PlayerEnabled && _playerPeds.EntitiesCount <= 0)
            {
                _ecsWorld.CreateEntityWith <ForceCreateGswPedEvent>().TargetPed = Game.LocalPlayer.Character;
            }
        }
Exemple #4
0
        void LeoECS()
        {
            _world = new EcsWorld();
            JobMoveSystem.MinSpeed         = param.minSpeed;
            JobMoveSystem.MaxSpeed         = param.maxSpeed;
            JobMoveSystem.BoidScale        = boidScale;
            JobMoveSystem.WallScale        = param.wallScale * 0.5f;
            JobMoveSystem.WallDistance     = param.wallDistance;
            JobMoveSystem.WallWeight       = param.wallWeight;
            JobMoveSystem.NeighborFov      = MathFast.Cos(param.neighborFov * MathFast.Deg2Rad);
            JobMoveSystem.NeighborDistance = param.neighborDistance;
            JobMoveSystem.SeparationWeight = param.separationWeight;
            JobMoveSystem.AlignmentWeight  = param.alignmentWeight;
            JobMoveSystem.CohesionWeight   = param.cohesionWeight;
            JobMoveSystem.EntitiesCount    = boidCount;
            JobMoveSystem.NumBoidsPerJob   = boidCount / System.Environment.ProcessorCount;

            if (BoidsVisualisationSystem._nativeMatrices.IsCreated)
            {
                BoidsVisualisationSystem._nativeMatrices.Dispose();
            }
            BoidsVisualisationSystem._nativeMatrices = new NativeArray <Matrix4x4> (boidCount, Allocator.Persistent);
            BoidsVisualisationSystem._matrices       = new Matrix4x4[boidCount];

            var timeSystem = new TimeSystem();

            _systems = new EcsSystems(_world);
            _systems
            .Add(timeSystem)
            .Add(new BoidsSimulationSystem())
            .Add(new JobMoveSystem())
            .Add(new BoidsVisualisationSystem()
            {
                mesh = mesh, material = material, scale = boidScale
            })
            .Inject(timeSystem)
            .Initialize();
            var random = new RngXorShift(853);

            BoidEntityData.Create(boidCount);

            for (int i = 0; i < boidCount; ++i)
            {
                var initSpeed = param.initSpeed;
                //init them with these default values
                var boid = _world.CreateEntityWith <BoidEntityData> ();
                boid.id       = i;
                boid.Position = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                var vel = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                vel.Normalize();
                vel.Scale(initSpeed);
                boid.Velocity     = vel;
                boid.Acceleration = Float3.Zero;
            }
            _world.ProcessDelayedUpdates();
        }
        /// <summary>
        /// Closes registration for new systems, initialize all registered.
        /// </summary>
        public void Initialize()
        {
#if DEBUG
            if (_inited)
            {
                throw new Exception("EcsSystems instance already initialized.");
            }

            for (var i = 0; i < _runSystemsCount; i++)
            {
                DisabledInDebugSystems.Add(false);
            }

            _inited = true;
#endif
            for (var i = 0; i < _initSystemsCount; i++)
            {
                _initSystems[i].Initialize();
                _world.ProcessDelayedUpdates();
            }
        }
        void LeoECS()
        {
            _world = new EcsWorld();
            ThreadMoveSystem.MinSpeed         = param.minSpeed;
            ThreadMoveSystem.MaxSpeed         = param.maxSpeed;
            ThreadMoveSystem.BoidScale        = boidScale;
            ThreadMoveSystem.WallScale        = param.wallScale * 0.5f;
            ThreadMoveSystem.WallDistance     = param.wallDistance;
            ThreadMoveSystem.WallWeight       = param.wallWeight;
            ThreadMoveSystem.NeighborFov      = MathFast.Cos(param.neighborFov * MathFast.Deg2Rad);
            ThreadMoveSystem.NeighborDistance = param.neighborDistance;
            ThreadMoveSystem.SeparationWeight = param.separationWeight;
            ThreadMoveSystem.AlignmentWeight  = param.alignmentWeight;
            ThreadMoveSystem.CohesionWeight   = param.cohesionWeight;
            ThreadMoveSystem.Neighbours       = new BoidEntityData[boidCount][];
            for (int i = 0; i < boidCount; i++)
            {
                ThreadMoveSystem.Neighbours[i] = new BoidEntityData[boidCount];
            }

            BoidsVisualisationSystem2._matrices = new Matrix4x4[boidCount];

            var timeSystem = new TimeSystem();

            _systems = new EcsSystems(_world);
            _systems
            .Add(timeSystem)
            .Add(new BoidsSimulationSystem())
            .Add(new ThreadMoveSystem())
            .Add(new BoidsVisualisationSystem2()
            {
                mesh = mesh, material = material, scale = boidScale
            })
            // .Add (new BoidsVisualisationSystem () { mesh = mesh, material = material, scale = boidScale })
            .Inject(timeSystem)
            .Initialize();
            var random = new RngXorShift(853);

            for (int i = 0; i < boidCount; ++i)
            {
                var initSpeed = param.initSpeed;
                //init them with these default values
                var boid = _world.CreateEntityWith <BoidEntityData> ();
                boid.position = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                boid.velocity = new Float3(random.GetFloat(), random.GetFloat(), random.GetFloat());
                boid.velocity.Normalize();
                boid.velocity.Scale(initSpeed);
                boid.acceleration = Float3.Zero;
            }
            _world.ProcessDelayedUpdates();
        }
Exemple #7
0
        public void Swap(int2 lhvPos, int2 rhvPos)
        {
            var field = _state.StoneField;

            if (!field.InRange(lhvPos) || !field.InRange(rhvPos))
            {
                return;
            }

            var lhv = _state.StoneField.Get(lhvPos);
            var rhv = _state.StoneField.Get(rhvPos);

            if (lhv == null || rhv == null || lhv == rhv)
            {
                return;
            }

            _world.AddComponent <Swapping>(lhv.eid);
            _world.AddComponent <Swapping>(rhv.eid);
            _world.ProcessDelayedUpdates();
        }
        public void Run()
        {
            BleedingStatsComponent stats = _bleedingStats.Components1[0];

            foreach (int i in _wounded)
            {
                PedBleedingInfoComponent info            = _wounded.Components1[i];
                WoundedComponent         wounded         = _wounded.Components2[i];
                DamagedBodyPartComponent damagedBodyPart = _wounded.Components3[i];
                DamagedByWeaponComponent damagedByWeapon = _wounded.Components4[i];

                EcsEntity pedEntity = _wounded.Entities[i];
                foreach (EcsEntity woundEntity in wounded.WoundEntities)
                {
                    var baseBleeding = _ecsWorld.GetComponent <BaseBleedingComponent>(woundEntity);
                    if (baseBleeding == null)
                    {
                        continue;
                    }

                    float baseSeverity = baseBleeding.BaseBleeding;
                    if (baseSeverity <= 0)
                    {
                        continue;
                    }

                    EcsEntity bodyPartEntity = damagedBodyPart.DamagedBodyPartEntity;
                    float     bodyPartMult   = _ecsWorld.GetComponent <BleedingMultiplierComponent>(bodyPartEntity).Multiplier;
                    float     sevWithMult    = stats.BleedingMultiplier * bodyPartMult * baseSeverity;

                    float sevDeviation = sevWithMult * stats.BleedingDeviation;
                    sevDeviation = _random.NextFloat(-sevDeviation, sevDeviation);

                    float finalSeverity = sevWithMult + sevDeviation;

                    EcsEntity bleedingEntity = _ecsWorld.CreateEntityWith(out BleedingComponent bleeding);
                    bleeding.DamagedBoneId     = damagedBodyPart.DamagedBoneId;
                    bleeding.BodyPartEntity    = damagedBodyPart.DamagedBodyPartEntity;
                    bleeding.Severity          = finalSeverity;
                    bleeding.MotherWoundEntity = woundEntity;
                    bleeding.WeaponEntity      = damagedByWeapon.WeaponEntity;

#if DEBUG
                    _logger.MakeLog(
                        $"Created bleeding {woundEntity.GetEntityName()} on bone {bleeding.DamagedBoneId} for {pedEntity.GetEntityName()}. " +
                        $"Base severity {baseSeverity:0.00}; final severity {finalSeverity:0.00}");
#endif
                    info.BleedingEntities.Add(bleedingEntity);
                }

#if DEBUG
                _ecsWorld.ProcessDelayedUpdates();
                string bleedingList = "";
                foreach (EcsEntity bleedEntity in info.BleedingEntities)
                {
                    bleedingList += $"{_ecsWorld.GetComponent<BleedingComponent>(bleedEntity).Severity:0.00} ";
                }

                _logger.MakeLog($"BleedingList for {pedEntity.GetEntityName()}: {bleedingList}");
#endif
            }
        }
Exemple #9
0
        public void Run()
        {
            PlayerConfigComponent config = _playerConfig.Components1[0];

            foreach (int i in _playerPeds)
            {
                Ped       ped    = _playerPeds.Components1[i].ThisPed;
                EcsEntity entity = _playerPeds.Entities[i];
                if (Game.LocalPlayer.Character.Equals(ped))
                {
                    continue;
                }

                _ecsWorld.RemoveComponent <PlayerMarkComponent>(entity);
#if DEBUG
                _logger.MakeLog($"PlayerMark removed from ped {entity.GetEntityName()}, 'cause different characters");
#endif
            }

            foreach (int i in _newPeds)
            {
                Ped       ped    = _newPeds.Components1[i].ThisPed;
                EcsEntity entity = _newPeds.Entities[i];
                if (!ped.IsLocalPlayer)
                {
                    continue;
                }

                if (config.PlayerEnabled)
                {
                    MarkEntityAsPed(entity);
                }
                else
                {
                    _ecsWorld.RemoveComponent <NewPedMarkComponent>(entity);
#if DEBUG
                    _logger.MakeLog($"NewPedMark removed from ped {entity.GetEntityName()}, 'cause player is disabled");
#endif
                }
            }

            _ecsWorld.ProcessDelayedUpdates();
            if (config.PlayerEnabled && _playerPeds.IsEmpty())
            {
                Ped playerPed = Game.LocalPlayer.Character;
                GswWorldComponent gswWorld = _gswWorld.Components1[0];

                if (!gswWorld.PedsToEntityDict.TryGetValue(playerPed, out EcsEntity entity))
                {
#if DEBUG
                    _logger.MakeLog($"No players found! PlayerPed {playerPed.Model.Name} will force create!");
#endif
                    _ecsWorld.CreateEntityWith(out ForceCreateGswPedEvent forceCreateEvent);
                    forceCreateEvent.TargetPed = playerPed;
                    return;
                }

#if DEBUG
                _logger.MakeLog("Entity with Player Ped already exists and will be removed!");
#endif
                _ecsWorld.AddComponent <RemovedPedMarkComponent>(entity);
            }
        }