// Writes Chunk Header to headerBuffer
    private void InitializeHeader(Chunk c, int blockSize, int hpSize, int stateSize)
    {
        timeArray = globalTime.TimeHeader();

        headerBuffer[0] = BiomeHandler.BiomeToByte(c.biomeName);

        for (int i = 0; i < 7; i++)
        {
            headerBuffer[i + 1] = timeArray[i];
        }

        headerBuffer[8] = c.needsGeneration;

        headerBuffer[9]  = (byte)(blockSize >> 24);
        headerBuffer[10] = (byte)(blockSize >> 16);
        headerBuffer[11] = (byte)(blockSize >> 8);
        headerBuffer[12] = (byte)(blockSize);

        headerBuffer[13] = (byte)(hpSize >> 24);
        headerBuffer[14] = (byte)(hpSize >> 16);
        headerBuffer[15] = (byte)(hpSize >> 8);
        headerBuffer[16] = (byte)(hpSize);

        headerBuffer[17] = (byte)(stateSize >> 24);
        headerBuffer[18] = (byte)(stateSize >> 16);
        headerBuffer[19] = (byte)(stateSize >> 8);
        headerBuffer[20] = (byte)(stateSize);
    }
예제 #2
0
    // Start is called before the first frame update
    void Start()
    {
        this.renderDistance = World.renderDistance;

        regionHandler = new RegionFileHandler(renderDistance, newChunk);

        worldSeed = regionHandler.GetRealSeed();

        biomeHandler = new BiomeHandler(BiomeSeedFunction(worldSeed));

        this.worldGen = new WorldGenerator(worldSeed, BiomeSeedFunction(worldSeed), OffsetHashFunction(worldSeed), GenerationSeedFunction(worldSeed), biomeHandler, structHandler, this);

        // If character has been loaded
        if (regionHandler.playerFile.Length > 0)
        {
            player.position = regionHandler.LoadPlayer();
            PLAYERSPAWNED   = true;
        }

        int playerX = Mathf.FloorToInt(player.position.x / Chunk.chunkWidth);
        int playerZ = Mathf.FloorToInt(player.position.z / Chunk.chunkWidth);

        newChunk = new ChunkPos(playerX, playerZ);


        GetChunks(true);
    }
    // Loads a chunk information from RDF file using Pallete-based Decompression
    public void LoadChunk(Chunk c)
    {
        byte biome     = 0;
        byte gen       = 0;
        int  blockdata = 0;
        int  hpdata    = 0;
        int  statedata = 0;

        GetCorrectRegion(c.pos);

        ReadHeader(c.pos);
        InterpretHeader(ref biome, ref gen, ref blockdata, ref hpdata, ref statedata);

        c.biomeName       = BiomeHandler.ByteToBiome(biome);
        c.lastVisitedTime = globalTime.DateBytes(timeArray);
        c.needsGeneration = gen;

        this.pool[ConvertToRegion(c.pos)].file.Read(blockBuffer, 0, blockdata);
        this.pool[ConvertToRegion(c.pos)].file.Read(hpBuffer, 0, hpdata);
        this.pool[ConvertToRegion(c.pos)].file.Read(stateBuffer, 0, statedata);

        Compression.DecompressBlocks(c, blockBuffer);
        Compression.DecompressMetadataHP(c, hpBuffer);
        Compression.DecompressMetadataState(c, stateBuffer);
    }
    /*
     * BiomeHandler's main function
     * Used to assign a biome to a new chunk.
     * Play arround with the seed value in each of the 4 biome features to change the behaviour
     *      of the biome distribution.
     */
    public byte Assign(ChunkPos pos)
    {
        float currentAltitude    = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.ax + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.az + ((dispersionSeed * BiomeHandlerData.sx) % 1000));
        float currentHumidity    = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.bx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.bz + ((dispersionSeed * BiomeHandlerData.sy) % 1000));
        float currentTemperature = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.cx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.cz + ((dispersionSeed * BiomeHandlerData.sz) % 1000));
        float currentLightning   = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.dx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.dz + ((dispersionSeed * BiomeHandlerData.sw) % 1000));

        float lowestDistance = 99;
        byte  lowestBiome    = 255;
        float distance;

        float4 currentSettings = new float4(currentAltitude, currentHumidity, currentTemperature, currentLightning);

        for (byte s = 0; s < amountOfBiomes; s++)
        {
            distance = BiomeHandler.Distance(currentSettings, BiomeHandlerData.codeToStats[s]);

            if (distance <= lowestDistance)
            {
                lowestDistance = distance;
                lowestBiome    = s;
            }
        }
        return(lowestBiome);
    }
예제 #5
0
    // Loads the chunk into the Chunkloader
    private void LoadChunk()
    {
        if (toLoad.Count > 0)
        {
            int min;

            // Sets the current iteration amount
            if (3 <= toLoad.Count)
            {
                min = 3;
            }
            else
            {
                min = toLoad.Count;
            }

            for (int i = 0; i < min; i++)
            {
                byte[] data = toLoad[0];

                int headerSize = RegionFileHandler.chunkHeaderSize;

                ChunkPos cp = NetDecoder.ReadChunkPos(data, 1);

                // Prevention
                if (this.chunks.ContainsKey(cp))
                {
                    this.chunks[cp].Destroy();
                    this.chunks.Remove(cp);
                }


                int blockDataSize = NetDecoder.ReadInt(data, 9);
                int hpDataSize    = NetDecoder.ReadInt(data, 13);
                int stateDataSize = NetDecoder.ReadInt(data, 17);

                this.chunks[cp]           = new Chunk(cp, this.rend, this.blockBook, this);
                this.chunks[cp].biomeName = BiomeHandler.ByteToBiome(data[21]);

                Compression.DecompressBlocksClient(this.chunks[cp], data, initialPos: 21 + headerSize);
                Compression.DecompressMetadataHPClient(this.chunks[cp], data, initialPos: 21 + headerSize + blockDataSize);
                Compression.DecompressMetadataStateClient(this.chunks[cp], data, initialPos: 21 + headerSize + blockDataSize + hpDataSize);

                if (this.vfx.data.ContainsKey(cp))
                {
                    this.vfx.RemoveChunk(cp);
                }

                this.vfx.NewChunk(cp);

                if (!this.toDraw.Contains(cp))
                {
                    this.toDraw.Add(cp);
                }

                toLoad.RemoveAt(0);
                toLoadChunk.RemoveAt(0);
            }
        }
    }
예제 #6
0
    // Removes structs from dict that are not in recent biomes
    private void RemoveQueue()
    {
        byte biome;
        bool found = false;

        if (loadedBiomes.Count > this.maxBiomesActive)
        {
            biome = loadedBiomes[0];
            loadedBiomes.RemoveAt(0);

            // For every Struct in removed biome
            foreach (int s in BiomeHandler.GetBiomeStructs((BiomeCode)biome))
            {
                found = false;

                // For every biome in loaded biomes
                foreach (byte b in loadedBiomes)
                {
                    if (BiomeHandler.GetBiomeStructs((BiomeCode)b).Contains(s))
                    {
                        found = true;
                        break;
                    }
                }
                // Removes if not found
                if (!found)
                {
                    structs.Remove(s);
                }
            }
        }
    }
예제 #7
0
    private void InitWorld()
    {
        this.regionHandler = new RegionFileHandler(this);
        worldSeed          = regionHandler.GetRealSeed();
        biomeHandler       = new BiomeHandler();
        this.worldGen      = new WorldGenerator(worldSeed, biomeHandler, structHandler, this);
        biomeHandler.SetWorldGenerator(this.worldGen);

        print("Initializing World");

        // Sends the first player it's information
        PlayerData pdat      = this.regionHandler.LoadPlayer(this.server.firstConnectedID); // CHANGE TO OTHER ACCOUNTID
        Vector3    playerPos = pdat.GetPosition();
        Vector3    playerDir = pdat.GetDirection();

        pdat.SetOnline(true);

        this.regionHandler.InitDataFiles(new ChunkPos((int)(playerPos.x / Chunk.chunkWidth), (int)(playerPos.z / Chunk.chunkWidth)));

        HandleServerCommunication();
        NetMessage message = new NetMessage(NetCode.SENDSERVERINFO);

        message.SendServerInfo(playerPos.x, playerPos.y, playerPos.z, playerDir.x, playerDir.y, playerDir.z);
        this.server.Send(message.GetMessage(), message.size, this.server.firstConnectedID);
        this.INITIALIZEDWORLD = true;
        this.time.SetLock(false);
    }
예제 #8
0
    // Adds all Structs of a biome to the loadQueue
    public void LoadBiome(byte code)
    {
        if (!loadedBiomes.Contains(code))
        {
            loadedBiomes.Add(code);
            RemoveQueue();

            foreach (int structCode in BiomeHandler.GetBiomeStructs((BiomeCode)code))
            {
                if (loadQueue.Contains(structCode) || structs.ContainsKey(structCode))
                {
                    continue;
                }
                else
                {
                    loadQueue.Add(structCode);
                }
            }
        }
        else
        {
            loadedBiomes.Remove(code);
            loadedBiomes.Add(code);
        }
    }
예제 #9
0
 public void GenerateDesertStructures(ChunkLoader_Server cl, ChunkPos pos, ushort[] blockdata, ushort[] statedata, ushort[] hpdata)
 {
     foreach (int structCode in BiomeHandler.GetBiomeStructs(BiomeCode.DESERT))
     {
         if (structCode >= 9 && structCode <= 11) // Metal veins
         {
             wgen.GenerateStructures(pos, BiomeCode.DESERT, structCode, 9, blockdata, statedata, hpdata, range: true);
         }
     }
 }
예제 #10
0
 public void GenerateSnowyForestStructures(ChunkLoader_Server cl, ChunkPos pos, ushort[] blockdata, ushort[] statedata, ushort[] hpdata)
 {
     foreach (int structCode in BiomeHandler.GetBiomeStructs(BiomeCode.FOREST))
     {
         if (structCode == 1 || structCode == 2 || structCode == 8) // Trees
         {
             wgen.GenerateStructures(pos, BiomeCode.FOREST, structCode, 0, blockdata, statedata, hpdata);
         }
         else if (structCode == 3 || structCode == 4) // Dirt Piles
         {
             wgen.GenerateStructures(pos, BiomeCode.FOREST, structCode, 3, blockdata, statedata, hpdata, range: true);
         }
         else if (structCode >= 9 && structCode <= 11) // Metal veins
         {
             wgen.GenerateStructures(pos, BiomeCode.FOREST, structCode, 9, blockdata, statedata, hpdata, range: true);
         }
     }
 }
예제 #11
0
 public void GenerateGrassyHighlandsStructures(ChunkLoader_Server cl, ChunkPos pos, ushort[] blockdata, ushort[] statedata, ushort[] hpdata)
 {
     foreach (int structCode in BiomeHandler.GetBiomeStructs(BiomeCode.GRASSY_HIGHLANDS))
     {
         if (structCode == 2) // Tree
         {
             wgen.GenerateStructures(pos, BiomeCode.GRASSY_HIGHLANDS, structCode, 0, blockdata, statedata, hpdata);
         }
         else if (structCode == 3 || structCode == 4) // Dirt Piles
         {
             wgen.GenerateStructures(pos, BiomeCode.GRASSY_HIGHLANDS, structCode, 3, blockdata, statedata, hpdata, range: true);
         }
         else if (structCode == 5) // Boulder
         {
             wgen.GenerateStructures(pos, BiomeCode.GRASSY_HIGHLANDS, structCode, 1, blockdata, statedata, hpdata);
         }
         else if (structCode >= 9 && structCode <= 11) // Metal veins
         {
             wgen.GenerateStructures(pos, BiomeCode.GRASSY_HIGHLANDS, structCode, 9, blockdata, statedata, hpdata, range: true);
         }
     }
 }
예제 #12
0
    public void Cleanup(bool comesFromClient = false)
    {
        if (!comesFromClient)
        {
            this.message = new NetMessage(NetCode.DISCONNECT);
            this.client.Send(this.message.GetMessage(), this.message.size);
        }

        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        this.biomeHandler.Clear();
        this.biomeHandler          = null;
        this.structHandler         = null;
        this.mainControllerManager = null;
        this.volume       = null;
        this.rend         = null;
        this.playerEvents = null;
        this.time         = null;
        this.blockBook    = null;
        this.client       = null;
        ClearAllChunks();
        Destroy(this);
    }
예제 #13
0
        public override bool ChooseWaterStyle()
        {
            BiomeHandler modPlayer = Main.LocalPlayer.GetModPlayer <BiomeHandler>();

            return(modPlayer.ZoneJungleHoly || modPlayer.FountainJungleHoly);
        }
예제 #14
0
        public override bool ChooseWaterStyle()
        {
            BiomeHandler modPlayer = Main.LocalPlayer.GetModPlayer <BiomeHandler>();

            return(modPlayer.ZoneGlass || modPlayer.FountainVitric);
        }
예제 #15
0
        public override void Update(GameTime gameTime)
        {
            BiomeHandler player = Main.LocalPlayer.GetModPlayer <BiomeHandler>();

            Bootlegdust.ForEach(dust => dust.Update());
            Bootlegdust.RemoveAll(dust => dust.time <= 0);

            if (visible)
            {
                if (!(player.ZoneVoidPre || player.ZoneJungleCorrupt || player.ZoneJungleBloody || player.ZoneJungleHoly || player.ZoneOvergrow))
                {
                    state = 0;
                }

                if (state == (int)OverlayState.Rift)
                {
                    for (int k = 0; k <= Main.screenHeight; k++)
                    {
                        if (k % Main.rand.Next(3, 13) == 0 && Main.rand.Next(30) == 0)
                        {
                            VoidDust dus  = new VoidDust(ModContent.GetTexture("StarlightRiver/GUI/Fire"), new Vector2(-15, k), new Vector2(Main.rand.NextFloat(1, 2), 0));
                            VoidDust dus2 = new VoidDust(ModContent.GetTexture("StarlightRiver/GUI/Fire"), new Vector2(Main.screenWidth, k), new Vector2(-Main.rand.NextFloat(1, 2), 0));
                            Bootlegdust.Add(dus);
                            Bootlegdust.Add(dus2);
                        }
                    }
                }

                if (state == (int)OverlayState.CorruptJungle)
                {
                    for (int k = 0; k <= Main.screenWidth; k++)
                    {
                        if (k % Main.rand.Next(5, 15) == 0 && Main.rand.Next(1000) == 0)
                        {
                            EvilDust dus = new EvilDust(ModContent.GetTexture("StarlightRiver/GUI/Corrupt"), new Vector2(k, Main.screenHeight), new Vector2(0, -1.4f));
                            Bootlegdust.Add(dus);
                        }
                    }
                }

                if (state == (int)OverlayState.BloodyJungle)
                {
                    for (int k = 0; k <= Main.screenWidth; k++)
                    {
                        if (k % Main.rand.Next(5, 15) == 0 && Main.rand.Next(1500) == 0)
                        {
                            BloodDust dus = new BloodDust(ModContent.GetTexture("StarlightRiver/GUI/Blood"), new Vector2(k, 0), new Vector2(0, 2f));
                            Bootlegdust.Add(dus);
                        }
                    }
                }

                if (state == (int)OverlayState.HolyJungle)
                {
                    for (int k = 0; k <= Main.screenWidth; k++)
                    {
                        if (k % Main.rand.Next(20, 40) == 0 && Main.rand.Next(750) == 0)
                        {
                            HolyDust dus = new HolyDust(ModContent.GetTexture("StarlightRiver/GUI/Light"), new Vector2(k, Main.rand.Next(Main.screenHeight)), Vector2.Zero);
                            Bootlegdust.Add(dus);
                        }
                    }
                }

                /*if (state == (int)OverlayState.Overgrow)
                 * {
                 *  for (int k = 0; k <= Main.screenWidth; k++)
                 *  {
                 *      if (k % Main.rand.Next(20, 40) == 0 && Main.rand.Next(550) == 0)
                 *      {
                 *          HolyDust dus = new HolyDust(ModContent.GetTexture("StarlightRiver/GUI/Holy"), new Vector2(k, Main.rand.Next(Main.screenHeight)), Vector2.Zero);
                 *          Bootlegdust.Add(dus);
                 *      }
                 *  }
                 * }*/
            }
        }
예제 #16
0
    public BiomeType GetBiomeFromPos(int x, int y)
    {
        float heightValue = noiseMap[x, y];

        return(BiomeHandler.getBiomeFromHeight(biomes, heightValue));
    }