Example #1
0
        public double GetDensity(int X, int Y, int Z, ChunkProvider CP)
        {
            if (Y == 0)
                return Double.MaxValue;
            Perlin3D p3 = CP.P3D;

            double f = p3.Get (X, 1 / 64.0, Y, 1 / 128.0, Z, 1 / 64.0, 0.5, 8);
            f += 1 - ((Y + 20) / 128.0);

            return f;
        }
Example #2
0
        // server recieving entitymove means its a player moving
        public void OnEntityMovePacket(EntityMovePacket packet)
        {
            var player           = Server.GetPlayerByConnectionId(packet.ClientId);
            var originalPosition = new Position(player.Position.X, player.Position.Y);
            var distanceMoved    = PositionExtensions.GetDistance(player.Position, packet.To);
            var timeToMove       = Formulas.GetTimeToMoveBetweenTwoTiles(player.MoveSpeed);

            var now = GameThread.TIME_MS_NOW;

            // Player tryng to hack ?
            var isPassable = Server.Map.IsPassable(packet.To.X, packet.To.Y);

            if (distanceMoved > 1 || now < player.CanMoveAgainTime || !isPassable)
            {
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.Position
                });
                return;
            }

            // subtract the player latency for possibility of lag for a smoother movement
            player.CanMoveAgainTime = now + timeToMove - player.Tcp.Latency;

            var entityMoveEvent = new EntityMoveEvent()
            {
                To     = packet.To,
                Entity = player
            };

            Server.Events.Call(entityMoveEvent);

            // updating in database
            PlayerService.UpdatePlayerPosition(player.UID, player.Position.X, player.Position.Y);


            // update chunks for that player
            ChunkProvider.CheckChunks(player);
        }
Example #3
0
        private bool SaveData()
        {
            // This state should only be set it streaming is enabled
            Assert.IsTrue(EngineSettings.WorldConfig.Streaming);

            // If chunk was generated...
            if (m_completedStates.Check(ChunkState.Generate))
            {
                // ...  we need to wait until blueprints are generated and chunk is finalized
                if (!m_completedStates.Check(
                        ChunkState.FinalizeData
                        ))
                {
                    return(true);
                }
            }

            m_pendingStates       = m_pendingStates.Reset(CurrStateSaveData);
            m_completedStates     = m_completedStates.Reset(CurrStateSaveData);
            m_completedStatesSafe = m_completedStates;

            ChunkProvider      provider = (ChunkProvider)chunk.Map.ChunkProvider;
            SSerializeWorkItem workItem = new SSerializeWorkItem(
                this,
                provider.GetFilePathFromIndex(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z)
                );

            m_taskRunning = true;
            IOPoolManager.Add(
                new TaskPoolItem(
                    arg =>
            {
                SSerializeWorkItem item = (SSerializeWorkItem)arg;
                OnSaveData(item.StateManager, item.FilePath);
            },
                    workItem)
                );

            return(true);
        }
Example #4
0
        /// <summary>
        /// Sets the voxel data for a world position
        /// </summary>
        /// <param name="voxelData">The new voxel data</param>
        /// <param name="worldPosition">The world position of the voxel data</param>
        public void SetVoxelData(float voxelData, int3 worldPosition)
        {
            IEnumerable <int3> affectedChunkCoordinates = ChunkProvider.GetChunkCoordinatesContainingPoint(worldPosition, VoxelWorld.WorldSettings.ChunkSize);

            foreach (int3 chunkCoordinate in affectedChunkCoordinates)
            {
                if (!_chunks.ContainsKey(chunkCoordinate))
                {
                    continue;
                }

                if (TryGetVoxelDataChunk(chunkCoordinate, out VoxelDataVolume voxelDataVolume))
                {
                    int3 localPos = (worldPosition - chunkCoordinate * VoxelWorld.WorldSettings.ChunkSize).Mod(VoxelWorld.WorldSettings.ChunkSize + 1);
                    voxelDataVolume.SetVoxelData(voxelData, localPos.x, localPos.y, localPos.z);

                    if (VoxelWorld.ChunkStore.TryGetChunkAtCoordinate(chunkCoordinate, out Chunk chunk))
                    {
                        chunk.HasChanges = true;
                    }
                }
            }
        }
        protected override void PreBegin(GameContext context)
        {
            // Process a single texture block if the FPS is higher than 30.
            //if (context.GameTime.ElapsedGameTime.Milliseconds < 100)
            //{
            ChunkProvider.ProcessSingle();
            ChunkRenderer.ProcessSingle(context.GameTime, context);
            //}

            // Ensure we have an occluding sprite batch.
            if (FilteredFeatures.IsEnabled(Feature.IsometricOcclusion))
            {
                if (this.m_OccludingSpriteBatch == null)
                {
                    this.m_OccludingSpriteBatch = new OccludingSpriteBatch(context.Graphics.GraphicsDevice);
                }
                this.m_OccludingSpriteBatch.Begin(true);
            }
            else
            {
                context.Graphics.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1f, 0);
            }
        }