Files
mcpe/source/world/level/levelgen/biome/BiomeSource.cpp
Brent a0f71c7b27 C++03 Support & Partial Xbox 360 Support (#37)
* WIP C++03 + Xbox 360 Support

* math.h & _USE_MATH_DEFINES on Level.hpp
Updated Xenon vcxproj file for new file structure.

* * Fix bad GUI scale setup.

* * Gui: Use ratios instead of hardcoded sub-1 floating point values, to make the mechanism more clear.

* Add Direct Connect Button and Screen (#30)

* Add Direct Connect Button and Screen

* Remove accidental extra build directories for wasm

* Add DirectConnectScreen.cpp to the CMake

* Use Hungarian coding style notation

* * Fix errors caused by #30

* * Improve the Chat Screen

* * Improve the DirectConnectScreen, among other things.

* * Update the game title once again.

* * Add build-wasm.bat.

* * Add info about compiling for wasm

* * Fix send to specific GUID actually broadcasting to everyone

* * Add command manager.

* * Add writeable configuration.

* * Allow dynamic screen size change on windows

* * Allow the same thing on the emscripten version.

* WIP C++03 + Xbox 360 Support

* Fixed a possible merging issue that broke RakNet?

* Additional Xbox 360 compatability fixes

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
Co-authored-by: ts <124226059+uniformization@users.noreply.github.com>
2023-08-07 15:48:52 +03:00

136 lines
3.1 KiB
C++

/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "BiomeSource.hpp"
#include "world/level/Level.hpp"
BiomeSource* BiomeSource::init()
{
field_4 = nullptr;
field_8 = nullptr;
field_C = nullptr;
field_10 = 0;
field_14 = 0;
field_18 = 0;
field_1C = 0;
field_20 = new Biome * [256];
m_pPerlinNoise[3] = nullptr;
return this;
}
BiomeSource::BiomeSource(Level* pLevel) :
m_Random1(pLevel->getSeed() * 9871),
m_Random2(pLevel->getSeed() * 39811),
m_Random3(pLevel->getSeed() * 543321)
{
init();
m_pPerlinNoise[0] = new PerlinNoise(&m_Random1, 4);
m_pPerlinNoise[1] = new PerlinNoise(&m_Random2, 4);
m_pPerlinNoise[2] = new PerlinNoise(&m_Random3, 2);
field_4 = new float[256];
}
Biome* BiomeSource::getBiome(ChunkPos& pos)
{
// @BUG: Shifting right by 4 instead of left. In Java Edition, a shift left by 4 is performed instead.
return getBiome(pos.x >> 4, pos.z >> 4);
}
Biome* BiomeSource::getBiome(int a, int b)
{
return *getBiomeBlock(a, b, 1, 1);
}
Biome** BiomeSource::getBiomeBlock(int a, int b, int c, int d)
{
return getBiomeBlock(field_20, a, b, c, d);
}
Biome** BiomeSource::getBiomeBlock(Biome** pBiomes, int a, int b, int c, int d)
{
field_4 = m_pPerlinNoise[0]->getRegion(field_4, a, b, c, c, 0.025f, 0.025f, 0.25f);
field_8 = m_pPerlinNoise[1]->getRegion(field_8, a, b, c, c, 0.05f, 0.05f, 0.3333f);
field_C = m_pPerlinNoise[2]->getRegion(field_C, a, b, c, c, 0.25f, 0.25f, 0.588f);
int index = 0;
for (int i = 0; i < c; i++)
{
for (int j = 0; j < d; j++)
{
float d = field_C[index] * 1.1f + 0.5f;
float d1 = 0.01f;
float d2 = 1.0f - d1;
float d3 = (field_4[index] * 0.15f + 0.7f) * d2 + d * d1;
d1 = 0.002f;
d2 = 1.0f - d1;
float d4 = (field_8[index] * 0.15f + 0.5f) * d2 + d * d1;
d3 = 1.0f - (1.0f - d3) * (1.0f - d3);
if (d3 < 0.0f) d3 = 0.0f;
if (d4 < 0.0f) d4 = 0.0f;
if (d3 > 1.0f) d3 = 1.0f;
if (d4 > 1.0f) d4 = 1.0f;
field_4[index] = d3;
field_8[index] = d4;
field_20[index++] = Biome::getBiome(d3, d4);
}
}
return field_20;
}
float* BiomeSource::getTemperatureBlock(int a, int b, int c, int d)
{
field_4 = m_pPerlinNoise[0]->getRegion(field_4, a, b, c, d, 0.025f, 0.025f, 0.25f);
field_C = m_pPerlinNoise[2]->getRegion(field_C, a, b, c, d, 0.25f, 0.25f, 0.588f);
int index = 0;
for (int i = 0; i < c; i++)
{
for (int j = 0; j < d; j++)
{
float d = field_C[index] * 1.1f + 0.5f;
float d1 = 0.01f;
float d2 = 1.0f - d1;
float d3 = (field_4[index] * 0.15f + 0.7f) * d2 + d * d1;
d3 = 1.0f - (1.0f - d3) * (1.0f - d3);
if (d3 < 0.0f)
d3 = 0.0f;
if (d3 > 1.0f)
d3 = 1.0f;
field_4[index++] = d3;
}
}
return field_4;
}
BiomeSource::~BiomeSource()
{
for (int i = 0; i < 3; i++)
if (m_pPerlinNoise[i])
delete m_pPerlinNoise[i];
if (field_4)
delete[] field_4;
if (field_8)
delete[] field_8;
if (field_C)
delete[] field_C;
if (field_20)
delete[] field_20;
}