Beispiel #1
0
 /// <summary>
 /// Adds the chunk to the owning region.
 /// </summary>
 public void AddToWorld()
 {
     foreach (Entity e in entsToSpawn)
     {
         OwningRegion.SpawnEntity(e);
     }
     entsToSpawn.Clear();
     foreach (SyncScheduleItem s in fixesToRun)
     {
         s.MyAction.Invoke();
     }
     fixesToRun.Clear();
     if (Flags.HasFlag(ChunkFlags.ISCUSTOM))
     {
         return;
     }
     if (FCO != null)
     {
         return;
     }
     FCO = new FullChunkObject(WorldPosition.ToVector3() * CHUNK_SIZE, BlocksInternal);
     FCO.CollisionRules.Group = CollisionUtil.WorldSolid;
     OwningRegion.AddChunk(FCO);
     OwningRegion.AddCloudsToNewChunk(this);
     OwningRegion.NoticeChunkForUpperArea(WorldPosition);
     ChunkDetect();
     if (IsNew)
     {
         OwningRegion.PushNewChunkDetailsToUpperArea(this);
     }
     IsNew = false;
 }
Beispiel #2
0
 public void AddChunk(FullChunkObject mesh)
 {
     if (mesh == null)
     {
         return;
     }
     PhysicsWorld.Add(mesh);
 }
Beispiel #3
0
 public void LateSpawn()
 {
     if (FCO == null && BlocksInternal != null)
     {
         FCO = new FullChunkObject(WorldPosition.ToVector3() * CHUNK_SIZE, BlocksInternal);
         FCO.CollisionRules.Group = CollisionUtil.WorldSolid;
         OwningRegion.AddChunk(FCO);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Initializes the entire game.
        /// </summary>
        public static void Init()
        {
            FileHandler files = new FileHandler();

            files.Init();
            MaterialHelpers.Populate(files); // TODO: Non-static material helper data?!
            BlockShapeRegistry.Init();
            FullChunkObject.RegisterMe();
        }
Beispiel #5
0
 public void AddToWorld()
 {
     if (FCO == null && CSize == CHUNK_SIZE)
     {
         FCO = new FullChunkObject(WorldPosition.ToVector3() * CHUNK_SIZE, BlocksInternal);
         FCO.CollisionRules.Group = CollisionUtil.WorldSolid;
         OwningRegion.AddChunk(FCO);
         IsAdded = true;
     }
 }
Beispiel #6
0
 /// <summary>
 /// Sync only.
 /// </summary>
 public void UnloadSafely(Action callback = null)
 {
     SaveAsNeeded(callback);
     clearentities();
     if (FCO != null)
     {
         OwningRegion.RemoveChunkQuiet(FCO);
         FCO = null;
     }
     OwningRegion.RemoveCloudsFrom(this);
 }
Beispiel #7
0
 /// <summary>
 /// Safely unload the chunk.
 /// </summary>
 /// <param name="callback">Callback for when it's fully saved and unloaded.</param>
 public void UnloadSafely(Action callback = null)
 {
     SaveAsNeeded(callback);
     Clearentities();
     if (FCO != null)
     {
         OwningRegion.RemoveChunkQuiet(FCO);
         FCO = null;
     }
     OwningRegion.ForgetChunkForUpperArea(WorldPosition);
     OwningRegion.RemoveCloudsFrom(this);
 }
Beispiel #8
0
 public void RemoveChunkQuiet(FullChunkObject mesh)
 {
     if (mesh == null)
     {
         return;
     }
     if (TheServer.ShuttingDown)
     {
         return;
     }
     PhysicsWorld.Remove(mesh);
 }
Beispiel #9
0
 public void RemoveChunkQuiet(FullChunkObject mesh)
 {
     PhysicsWorld.Remove(mesh);
 }
Beispiel #10
0
 public void AddChunk(FullChunkObject mesh)
 {
     PhysicsWorld.Add(mesh);
 }
Beispiel #11
0
        public void UpdateForPacketFromServer(double gtt, long ID, Location pos, Location vel, bool _pup)
        {
            ServerLocation = pos;
            if (ServerFlags.HasFlag(YourStatusFlags.INSECURE_MOVEMENT))
            {
                return;
            }
            if (InVehicle)
            {
                return;
            }
            // TODO: big solid entities!
            double now = TheRegion.GlobalTickTimeLocal;

            if (TheClient.CVars.n_movemode.ValueI == 2)
            {
                // TODO: Remove outsider chunks!
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        for (int z = -1; z <= 1; z++)
                        {
                            Vector3i ch    = TheRegion.ChunkLocFor(pos) + new Vector3i(x, y, z);
                            Chunk    chunk = TheRegion.GetChunk(ch);
                            if (chunk == null)
                            {
                                continue;
                            }
                            if (!NMTWOMeshes.ContainsKey(ch))
                            {
                                if (chunk.FCO != null)
                                {
                                    FullChunkObject im = new FullChunkObject(chunk.FCO.Position, chunk.FCO.ChunkShape);
                                    NMTWOWorld.Add(im);
                                    NMTWOMeshes[ch] = im;
                                }
                            }
                        }
                    }
                }
                AddUIS();
                int    xf       = 0;
                double jumpback = gtt - lGTT;
                if (jumpback < 0)
                {
                    return;
                }
                double       target = TheRegion.GlobalTickTimeLocal - jumpback;
                UserInputSet past   = null;
                while (xf < Input.Length)
                {
                    UserInputSet uis = Input[xf];
                    if (uis.GlobalTimeLocal < target)
                    {
                        past = uis;
                        Input.Pop();
                        continue;
                    }
                    else if (xf == 0)
                    {
                        double mult = Math.Max(Math.Min(jumpback / TheClient.CVars.n_movement_adjustment.ValueD, 1.0), 0.01);
                        NMTWOSetPosition(uis.Position + (pos - uis.Position) * mult);
                        NMTWOSetVelocity(uis.Velocity + (vel - uis.Velocity) * mult);
                    }
                    xf++;
                    double delta;
                    if (xf < 2)
                    {
                        if (past == null)
                        {
                            continue;
                        }
                        delta = uis.GlobalTimeLocal - target;
                        SetBodyMovement(NMTWOCBody, past);
                    }
                    else
                    {
                        UserInputSet prev = Input[xf - 2];
                        delta = uis.GlobalTimeLocal - prev.GlobalTimeLocal;
                        SetBodyMovement(NMTWOCBody, prev);
                    }
                    SetMoveSpeed(NMTWOCBody, uis);
                    if (!_pup)
                    {
                        NMTWOTryToJump(uis);
                    }
                    lPT = uis.GlobalTimeLocal;
                    NMTWOWorld.Update((float)delta);
                    FlyForth(NMTWOCBody, uis, delta); // TODO: Entirely disregard NWTWOWorld if flying?
                }
                AddUIS();
                SetPosition(NMTWOGetPosition());
                SetVelocity(new Location(NMTWOCBody.Body.LinearVelocity));
                pup  = _pup;
                lGTT = gtt;
            }
            else
            {
                double   delta = lPT - now;
                Location dir   = pos - TheClient.Player.GetPosition();
                if (dir.LengthSquared() < TheClient.CVars.n_movement_maxdistance.ValueF * TheClient.CVars.n_movement_maxdistance.ValueF)
                {
                    SetPosition(GetPosition() + dir / Math.Max(TheClient.CVars.n_movement_adjustment.ValueF / delta, 1));
                    Location veldir = vel - GetVelocity();
                    SetVelocity(GetVelocity() + veldir / Math.Max(TheClient.CVars.n_movement_adjustment.ValueF / delta, 1));
                }
                else
                {
                    TheClient.Player.SetPosition(pos);
                    TheClient.Player.SetVelocity(vel);
                }
                lPT = now;
            }
        }