예제 #1
0
        /// <summary>
        /// Ticks the physics entity, doing nothing at all.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.LoadedChunks.ContainsKey(cpos))
            {
                TheRegion.LoadChunk(cpos);
            }
        }
예제 #2
0
 public bool TryChunk(Vector3i cworldPos, int posMult, Chunk chi = null) // TODO: Efficiency?
 {
     if (pkick)
     {
         return(false);
     }
     if (!ChunksAwareOf.ContainsKey(cworldPos) || ChunksAwareOf[cworldPos].LOD > posMult) // TODO: Efficiency - TryGetValue?
     {
         double dist  = (cworldPos.ToLocation() * Chunk.CHUNK_SIZE - LoadRelPos).LengthSquared();
         bool   async = chi == null && dist > (Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * 2 * 2);
         if (async)
         {
             TheRegion.LoadChunk_Background(cworldPos, (chn) =>
             {
                 if (!pkick && chn != null)
                 {
                     ChunkNetwork.SendPacket(new ChunkInfoPacketOut(chn, posMult));
                 }
             });
         }
         else
         {
             Chunk chk = chi != null ? chi : TheRegion.LoadChunk(cworldPos);
             ChunkNetwork.SendPacket(new ChunkInfoPacketOut(chk, posMult));
         }
         ChunksAwareOf.Remove(cworldPos);
         ChunksAwareOf.Add(cworldPos, new ChunkAwarenessInfo()
         {
             ChunkPos = cworldPos, LOD = posMult
         });
         return(true);
     }
     return(false);
 }
예제 #3
0
        /// <summary>
        /// Ticks the physics entity.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.TryFindChunk(cpos, out Chunk _)) // TODO: is this really needed every tick?
            {
                TheRegion.LoadChunk(cpos);
            }
            if (!GenBlockShadow)// TODO: and world config allows trackables
            {
                if (TheRegion.GetEntitiesInRadius(GetPosition(), 1.5f, EntityType.SMASHER_PRIMTIVE).Count == 0)
                {
                    // TODO: 5 * 60 -> world config
                    TheRegion.SpawnEntity(new SmasherPrimitiveEntity(TheRegion, Math.Min((float)GetScaleEstimate(), 2f), TheRegion.TheWorld.GlobalTickTime + (5 * 60))
                    {
                        Position = GetPosition()
                    });
                }
            }
            // TODO: More genericish
            if (TheRegion.Generator is SphereGeneratorCore)
            {
                Location pos   = new Location(Body.Position);
                double   scale = TheRegion.TheWorld.GeneratorScale;
                Location gravDir;
                if (pos.LengthSquared() > scale * scale)
                {
                    gravDir = new Location(scale / pos.X, scale / pos.Y, scale / pos.Z);
                }
                else
                {
                    gravDir = pos / scale;
                }
                SetGravity(gravDir * (-TheRegion.GravityStrength));
            }
        }
예제 #4
0
        /// <summary>
        /// Ticks the physics entity.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.LoadedChunks.ContainsKey(cpos)) // TODO: is this really needed every tick?
            {
                TheRegion.LoadChunk(cpos);
            }
            // TODO: More genericish
            if (TheRegion.Generator is SphereGeneratorCore)
            {
                Location pos   = new Location(Body.Position);
                double   scale = TheRegion.TheWorld.GeneratorScale;
                Location gravDir;
                if (pos.LengthSquared() > scale * scale)
                {
                    gravDir = new Location(scale / pos.X, scale / pos.Y, scale / pos.Z);
                }
                else
                {
                    gravDir = pos / scale;
                }
                SetGravity(gravDir * (-TheRegion.GravityStrength));
            }
        }
예제 #5
0
        public override void Tick()
        {
            if (TheRegion.IsVisible(GetPosition()))
            {
                bool sme = false;
                SetVelocity(GetVelocity() * 0.99f + Gravity * TheRegion.Delta);
                if (GetVelocity().LengthSquared() > 0)
                {
                    CollisionResult cr  = TheRegion.Collision.CuboidLineTrace(Scale, GetPosition(), GetPosition() + GetVelocity() * TheRegion.Delta, FilterHandle);
                    Location        vel = GetVelocity();
                    if (cr.Hit && Collide != null)
                    {
                        Collide(this, new CollisionEventArgs(cr));
                    }
                    if (!IsSpawned || Removed)
                    {
                        return;
                    }
                    if (vel == GetVelocity())
                    {
                        SetVelocity((cr.Position - GetPosition()) / TheRegion.Delta);
                    }
                    SetPosition(cr.Position);
                    // TODO: Timer
                    if (network)
                    {
                        sme = true;
                    }
                    netdeltat = 2;
                }
                else
                {
                    netdeltat += TheRegion.Delta;
                    if (netdeltat > 2.0)
                    {
                        netdeltat -= 2.0;
                        sme        = true;
                    }
                }
                Location pos = GetPosition();
                PrimitiveEntityUpdatePacketOut primupd = sme ? new PrimitiveEntityUpdatePacketOut(this) : null;
                foreach (PlayerEntity player in TheRegion.Players)
                {
                    bool shouldseec = player.ShouldSeePosition(pos);
                    bool shouldseel = player.ShouldSeePositionPreviously(lPos);
                    if (shouldseec && !shouldseel)
                    {
                        player.Network.SendPacket(GetSpawnPacket());
                    }
                    if (shouldseel && !shouldseec)
                    {
                        player.Network.SendPacket(new DespawnEntityPacketOut(EID));
                    }
                    if (sme && shouldseec)
                    {
                        player.Network.SendPacket(primupd);
                    }
                }
            }
            lPos = GetPosition();
            Vector3i cpos = TheRegion.ChunkLocFor(lPos);

            if (CanSave && !TheRegion.TryFindChunk(cpos, out Chunk _))
            {
                TheRegion.LoadChunk(cpos);
            }
        }