Beispiel #1
0
    public void GetChunk_Cmd(SocketUser user, Data data)
    {
        User userInst = (User)user.User;

        int  chunkX        = BitConverter.ToInt32(data.Buffer, 0);
        int  chunkY        = BitConverter.ToInt32(data.Buffer, 4);
        int  chunkZ        = BitConverter.ToInt32(data.Buffer, 8);
        int  lod_Version   = BitConverter.ToInt32(data.Buffer, 12);
        bool has_heightmap = BitConverter.ToBoolean(data.Buffer, 16);

        Vector3Int chunkCord = new Vector3Int(chunkX, chunkY, chunkZ);
        Vector2Int Region    = VoxelConversions.ChunkToRegion(chunkCord);

        Region region = Regions.LoadORCreate(Region);

        Logger.Log("User {0} requested {1}.", userInst.Name, chunkCord);

        if (region.ChunkExists(chunkCord))
        {
            Column col = region.GetColumn(user.User, chunkCord, (LOD_Mode)lod_Version);
            if (col.Max_Mode < (LOD_Mode)lod_Version)
            {
                Logger.Log("Requesting chunk update: " + DebugTimer.Elapsed());
                RequestChunkGen(chunkCord, region, (LOD_Mode)lod_Version, userInst, has_heightmap);
            }
            else
            {
                Logger.Log("Transmitting chunk: " + DebugTimer.Elapsed());
                userInst.TransmitColumn(col, has_heightmap);
            }
        }
        else
        {
            Logger.Log("Requesting new chunk: " + DebugTimer.Elapsed());
            RequestChunkGen(chunkCord, region, (LOD_Mode)lod_Version, userInst, has_heightmap);
        }
    }