コード例 #1
0
        internal void EntIntersectSelector(KeyValuePair <MyEntity, EntIntersectInfo> pair)
        {
            var entInfo = pair.Value;
            var webent  = pair.Key;

            if (entInfo == null || webent == null || webent.MarkedForClose)
            {
                return;
            }
            var relation = entInfo.Relation;

            var tick      = Session.Instance.Tick;
            var entCenter = webent.PositionComp.WorldVolume.Center;

            if (entInfo.LastTick != tick)
            {
                return;
            }
            entInfo.RefreshNow = false;

            switch (relation)
            {
            case Ent.EnemyPlayer:
            {
                PlayerIntersect(webent);
                return;
            }

            case Ent.EnemyInside:
            {
                if (!CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                {
                    entInfo.RefreshNow      = true;
                    entInfo.EnemySafeInside = false;
                }
                return;
            }

            case Ent.NobodyGrid:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent NobodyGrid: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                GridIntersect(webent);
                return;
            }

            case Ent.EnemyGrid:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent LargeEnemyGrid: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                GridIntersect(webent);
                return;
            }

            case Ent.Shielded:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent Shielded: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                ShieldIntersect(webent);
                return;
            }

            case Ent.Floater:
            {
                if (!_isServer || webent.MarkedForClose)
                {
                    return;
                }
                if (CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                {
                    var floater = Session.Instance.FloaterPool.Get();
                    floater.Init(webent, this);
                    Session.Instance.ThreadEvents.Enqueue(floater);
                }
                return;
            }

            case Ent.Other:
            {
                if (!_isServer)
                {
                    return;
                }
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent Other: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                if (webent.MarkedForClose || !webent.InScene)
                {
                    return;
                }
                var meteor = webent as IMyMeteor;
                if (meteor != null)
                {
                    if (CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                    {
                        var meteorEvent = Session.Instance.MeteorPool.Get();
                        meteorEvent.Init(meteor, this);
                        Session.Instance.ThreadEvents.Enqueue(meteorEvent);
                    }
                }
                else
                {
                    var predictedHit = CustomCollision.FutureIntersect(this, webent, DetectionMatrix, DetectMatrixOutsideInv);
                    if (predictedHit)
                    {
                        var missileEvent = Session.Instance.MissilePool.Get();
                        missileEvent.Init(webent, this);
                        Session.Instance.ThreadEvents.Enqueue(missileEvent);
                    }
                }
                return;
            }

            default:
                return;
            }
        }
コード例 #2
0
        internal void MonitorRefreshTasks(int x, ref List <MyEntity> monitorList, bool reInforce, ref bool newSub)
        {
            var s = _workData.ShieldList[x];

            if (reInforce)
            {
                var newMode = !s.ReInforcedShield;
                if (!newMode)
                {
                    return;
                }

                HashSet <MyCubeGrid> subs;
                lock (s.SubLock)
                {
                    subs = SetMyCubeGridPool.Get();
                    subs.UnionWith(s.ShieldComp.SubGrids);
                }
                foreach (var sub in subs)
                {
                    if (!_globalEntTmp.ContainsKey(sub))
                    {
                        newSub = true;
                    }
                    _entRefreshQueue.Enqueue(sub);
                    if (!s.WasPaused)
                    {
                        _globalEntTmp[sub] = _workData.Tick;
                    }
                }
                subs.Clear();
                SetMyCubeGridPool.Return(subs);

                s.ReInforcedShield    = true;
                s.TicksWithNoActivity = 0;
                s.LastWokenTick       = _workData.Tick;
                s.Asleep = false;
            }
            else
            {
                var newMode = false;
                if (s.ReInforcedShield)
                {
                    HashSet <MyCubeGrid> subs;
                    lock (s.SubLock)
                    {
                        subs = SetMyCubeGridPool.Get();
                        subs.UnionWith(s.ShieldComp.SubGrids);
                    }
                    foreach (var sub in subs)
                    {
                        _entRefreshQueue.Enqueue(sub);
                        if (!s.WasPaused)
                        {
                            _globalEntTmp[sub] = _workData.Tick;
                        }
                    }
                    subs.Clear();
                    SetMyCubeGridPool.Return(subs);

                    //if (Enforced.Debug >= 2) Log.Line($"found Reinforce");
                    s.ReInforcedShield    = false;
                    s.TicksWithNoActivity = 0;
                    s.LastWokenTick       = _workData.Tick;
                    s.Asleep = false;
                    newMode  = true;
                }

                if (!newMode)
                {
                    var foundNewEnt   = false;
                    var disableVoxels = Enforced.DisableVoxelSupport == 1 || s.ShieldComp.Modulator == null || s.ShieldComp.Modulator.ModSet.Settings.ModulateVoxels;
                    MyGamePruningStructure.GetTopmostEntitiesInBox(ref s.WebBox, monitorList);
                    if (!s.WasPaused)
                    {
                        foreach (var ent in monitorList)
                        {
                            var voxel = ent as MyVoxelBase;
                            if (ent == null || ent.MarkedForClose || (voxel == null && (ent.Physics == null || ent.Physics.IsPhantom || ent.DefinitionId == null)) || (!s.GridIsMobile && voxel != null) || (disableVoxels && voxel != null) || (voxel != null && voxel != voxel.RootVoxel))
                            {
                                continue;
                            }

                            if (ent is IMyFloatingObject || ent is IMyEngineerToolBase || !s.WebSphere.Intersects(ent.PositionComp.WorldVolume))
                            {
                                continue;
                            }

                            if (CustomCollision.NewObbPointsInShield(ent, s.DetectMatrixOutsideInv) > 0)
                            {
                                if (!_globalEntTmp.ContainsKey(ent))
                                {
                                    foundNewEnt = true;
                                    s.Asleep    = false;
                                }

                                _globalEntTmp[ent] = _workData.Tick;
                            }
                            s.NewEntByShield = foundNewEnt;
                        }
                    }
                    else
                    {
                        s.NewEntByShield = false;
                    }

                    if (!s.NewEntByShield)
                    {
                        var foundPlayer = false;
                        foreach (var player in Players.Values)
                        {
                            var character = player.Character;
                            if (character == null)
                            {
                                continue;
                            }

                            if (Vector3D.DistanceSquared(character.PositionComp.WorldMatrixRef.Translation, s.DetectionCenter) < SyncDistSqr)
                            {
                                foundPlayer = true;
                                break;
                            }
                        }
                        s.PlayerByShield = foundPlayer;
                    }
                    if (!s.PlayerByShield)
                    {
                        s.MoverByShield = false;
                        var newMover = false;

                        var moverList = ListMyEntityPool.Get();
                        MyGamePruningStructure.GetTopMostEntitiesInBox(ref s.ShieldBox3K, moverList, MyEntityQueryType.Dynamic);
                        for (int i = 0; i < moverList.Count; i++)
                        {
                            var ent = moverList[i];

                            var meteor = ent as IMyMeteor;
                            if (meteor != null)
                            {
                                if (CustomCollision.FutureIntersect(s, ent, s.DetectMatrixOutside, s.DetectMatrixOutsideInv))
                                {
                                    if (Enforced.Debug >= 2)
                                    {
                                        Log.Line($"[Future Intersecting Meteor] distance from shieldCenter: {Vector3D.Distance(s.DetectionCenter, ent.WorldMatrix.Translation)} - waking:");
                                    }
                                    newMover = true;
                                    break;
                                }
                                continue;
                            }

                            if (!(ent.Physics == null || ent.Physics.IsPhantom || ent is MyCubeGrid || ent is IMyCharacter))
                            {
                                continue;
                            }
                            var entPos = ent.PositionComp.WorldAABB.Center;

                            var keyFound = s.EntsByMe.ContainsKey(ent);
                            if (keyFound)
                            {
                                if (!s.EntsByMe[ent].Pos.Equals(entPos, 1e-3))
                                {
                                    MoverInfo moverInfo;
                                    s.EntsByMe.TryRemove(ent, out moverInfo);
                                    s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick));
                                    if (moverInfo.CreationTick == _workData.Tick - 1)
                                    {
                                        if (Enforced.Debug >= 3 && s.WasPaused)
                                        {
                                            Log.Line($"[Moved] Ent:{ent.DebugName} - howMuch:{Vector3D.Distance(entPos, s.EntsByMe[ent].Pos)} - ShieldId [{s.Shield.EntityId}]");
                                        }
                                        newMover = true;
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                if (Enforced.Debug >= 3)
                                {
                                    Log.Line($"[NewMover] Ent:{ent.DebugName} - ShieldId [{s.Shield.EntityId}]");
                                }
                                s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick));
                            }
                        }
                        moverList.Clear();
                        ListMyEntityPool.Return(moverList);

                        s.MoverByShield = newMover;
                    }

                    if (_workData.Tick < s.LastWokenTick + 400)
                    {
                        s.Asleep = false;
                        return;
                    }
                }

                if (s.EntCleanUpTime)
                {
                    s.EntCleanUpTime = false;
                    if (!s.EntsByMe.IsEmpty)
                    {
                        var entsByMeTmp = new List <KeyValuePair <MyEntity, MoverInfo> >();
                        entsByMeTmp.AddRange(s.EntsByMe.Where(info => !info.Key.InScene || _workData.Tick - info.Value.CreationTick > EntMaxTickAge));
                        for (int i = 0; i < entsByMeTmp.Count; i++)
                        {
                            MoverInfo mInfo;
                            s.EntsByMe.TryRemove(entsByMeTmp[i].Key, out mInfo);
                        }
                    }
                }
            }
        }
コード例 #3
0
        internal void EntIntersectSelector(KeyValuePair <MyEntity, EntIntersectInfo> pair)
        {
            var entInfo = pair.Value;
            var webent  = pair.Key;

            if (entInfo == null || webent == null || webent.MarkedForClose)
            {
                return;
            }
            var relation = entInfo.Relation;

            var tick      = Session.Instance.Tick;
            var entCenter = webent.PositionComp.WorldVolume.Center;

            if (entInfo.LastTick != tick)
            {
                return;
            }
            if (entInfo.RefreshNow && (relation == Ent.NobodyGrid || relation == Ent.EnemyGrid))
            {
                entInfo.CacheBlockList.Clear();
                var grid = webent as MyCubeGrid;
                if (grid != null)
                {
                    var checkSphere = WebSphere;
                    checkSphere.Radius += 7.5;
                    GetBlocksInsideSphereFast(grid, ref checkSphere, true, entInfo.CacheBlockList);
                }
            }
            entInfo.RefreshNow = false;

            switch (relation)
            {
            case Ent.EnemyPlayer:
            {
                PlayerIntersect(webent);
                return;
            }

            case Ent.EnemyInside:
            {
                if (!CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                {
                    entInfo.RefreshNow      = true;
                    entInfo.EnemySafeInside = false;
                }
                return;
            }

            case Ent.NobodyGrid:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent NobodyGrid: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                GridIntersect(webent);
                return;
            }

            case Ent.EnemyGrid:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent LargeEnemyGrid: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                GridIntersect(webent);
                return;
            }

            case Ent.Shielded:
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent Shielded: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                ShieldIntersect(webent);
                return;
            }

            case Ent.Floater:
            {
                if (!_isServer || webent.MarkedForClose)
                {
                    return;
                }
                if (CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                {
                    Session.Instance.ThreadEvents.Enqueue(new FloaterThreadEvent(webent, this));
                }
                return;
            }

            case Ent.Other:
            {
                if (!_isServer)
                {
                    return;
                }
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Ent Other: {webent.DebugName} - ShieldId [{Shield.EntityId}]");
                }
                if (webent.MarkedForClose || !webent.InScene)
                {
                    return;
                }
                var meteor = webent as IMyMeteor;
                if (meteor != null)
                {
                    if (CustomCollision.PointInShield(entCenter, DetectMatrixOutsideInv))
                    {
                        Session.Instance.ThreadEvents.Enqueue(new MeteorDmgThreadEvent(meteor, this));
                    }
                }
                else
                {
                    var predictedHit = CustomCollision.FutureIntersect(this, webent, DetectionMatrix, DetectMatrixOutsideInv);
                    if (predictedHit)
                    {
                        Session.Instance.ThreadEvents.Enqueue(new MissileThreadEvent(webent, this));
                    }
                }
                return;
            }

            default:
                return;
            }
        }