Skip to content

Commit

Permalink
Remove non-infinite terrain
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed May 14, 2017
1 parent 73d4593 commit ecc3892
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 82 deletions.
6 changes: 6 additions & 0 deletions Source/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ namespace Display
"HopsonCraft - 'V4.0'",
sf::Style::Fullscreen,
settings);
/*
window = std::make_unique<sf::RenderWindow>(sf::VideoMode{1280, 720},
"HopsonCraft - 'V4.0'",
sf::Style::Default,
settings);
*/
glewInit();
glViewport(0, 0, get().getSize().x, get().getSize().y);

Expand Down
2 changes: 1 addition & 1 deletion Source/Player/Player_Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Player::input()
void Player::keyBoardInput ()
{
Vector3 change;
float speed = 0.35;
float speed = 0.15;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
{
speed *= 10;
Expand Down
5 changes: 0 additions & 5 deletions Source/States/SMain_Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ namespace State
std::vector<Noise::Data> { nSmooth, nNormal, nMountains, nWater, nHilly},
settings.noiseData));

m_playMenu.addComponent(std::make_unique<GUI::Toggle_Option_Button<bool>>("Infinite Terrain",
std::vector<std::string> { "No", "Yes" },
std::vector<bool> { false, true },
settings.isInfiniteTerrain));

m_playMenu.addComponent(std::make_unique<GUI::Toggle_Option_Button<bool>>("Experimental Mode",
std::vector<std::string> { "Off", "On" },
std::vector<bool> { false, true },
Expand Down
18 changes: 5 additions & 13 deletions Source/States/SPlaying.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ namespace State
initHUD();
initPause();

m_quady.position = getCenterPosition();

m_player.position = getCenterPosition();
m_quady.position = getCenterPosition();
m_player.position = getCenterPosition();

Display::get().setFramerateLimit(1000);
}
Expand Down Expand Up @@ -61,14 +60,7 @@ namespace State
{
return;
}

m_player.input();

if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
{
m_player.position = getCenterPosition();
}

editBlockInput();
}

Expand Down Expand Up @@ -184,13 +176,13 @@ namespace State

Vector3 Playing::getCenterPosition()
{
int32_t centre = (m_world.getWorldSettings().worldSize * CHUNK_SIZE) / 2;
int32_t centre = 20000;

return
{
centre + 0.5,
centre,
m_world.getHeightAt({centre, 0, centre}) + 3,
centre + 0.5
centre
};
}

Expand Down
8 changes: 4 additions & 4 deletions Source/World/Generators/Chunk_Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace

Biome getBiome(int val)
{
if (val > 180)
if (val > 240)
{
return Mountains;
}
else if (Maths::inRange(val, 145, 180))
else if (Maths::inRange(val, 180, 240))
{
return Forest;
}
else if (Maths::inRange(val, 120, 145))
else if (Maths::inRange(val, 120, 180))
{
return Grassland;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ Chunk_Generator::Chunk_Generator(const World_Settings& worldSettings)
m_noiseGenerator.setNoiseFunction (worldSettings.noiseData);

m_biomeNoise.setSeed (worldSettings.seed);
m_biomeNoise.setNoiseFunction ({6, 150, 0.5, 450});
m_biomeNoise.setNoiseFunction ({7, 150, 0.52, 450});
}

void Chunk_Generator::reset()
Expand Down
20 changes: 1 addition & 19 deletions Source/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ World::World(const World_Settings& worldSettings, const Camera& camera)
, m_chunks (*this)
, m_pCamera (&camera)
{
//Just loads a few chunks in the centre. This causes the world to open instantly,
//while having player at correct height
int32_t centre = getWorldSettings().worldSize / 2;
int32_t centre = 20000;
int size = 2;
for (int x = -size ; x <= size; x++)
{
Expand Down Expand Up @@ -93,22 +91,6 @@ void World::checkPlayerBounds(Player& player)
{
player.position.z = 0.2;
}

if (m_worldSettings.isInfiniteTerrain)
{
return;
}
else
{
if (player.position.x + 0.2 > m_worldSettings.worldSize * CHUNK_SIZE - 0.2 )
{
player.position.x = m_worldSettings.worldSize * CHUNK_SIZE - 0.3;
}
if (player.position.z + 0.2 > m_worldSettings.worldSize * CHUNK_SIZE - 0.2 )
{
player.position.z = m_worldSettings.worldSize * CHUNK_SIZE - 0.3;
}
}
}

void World::qSetBlock(const Vector3& position, CBlock block)
Expand Down
64 changes: 25 additions & 39 deletions Source/World/World_Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,13 @@ void World::generateWorld(const Camera& camera)
for (int i = 0; i < m_loadingDistance; i++)
{
m_deleteMutex.unlock();
if (m_worldSettings.isInfiniteTerrain)
{
area.minPoint = {m_cameraPosition.x - i,
m_cameraPosition.y - i};

area.maxPoint = {m_cameraPosition.x + i,
m_cameraPosition.y + i};
}
else
{
int32_t minDis = m_worldSettings.worldSize / 2 - m_loadingDistance;
int32_t maxDis = m_worldSettings.worldSize / 2 + m_loadingDistance;

area.minPoint = {minDis,
minDis};
area.minPoint = {m_cameraPosition.x - i,
m_cameraPosition.y - i};

area.maxPoint = {maxDis,
maxDis};
area.maxPoint = {m_cameraPosition.x + i,
m_cameraPosition.y + i};

}
m_deleteMutex.lock();
for (int32_t x = area.minPoint.x; x < area.maxPoint.x; x++)
{
Expand Down Expand Up @@ -89,35 +76,34 @@ void World::generateWorld(const Camera& camera)
{
m_loadingDistance++;
}
if (m_worldSettings.isInfiniteTerrain)
{
Area bounds;
bounds.minPoint = { m_cameraPosition.x - m_worldSettings.worldSize / 2 - 1,
m_cameraPosition.y - m_worldSettings.worldSize / 2 - 1};

bounds.maxPoint = { m_cameraPosition.x + m_worldSettings.worldSize / 2 + 1,
m_cameraPosition.y + m_worldSettings.worldSize / 2 + 1};
Area bounds;
bounds.minPoint = { m_cameraPosition.x - m_worldSettings.worldSize / 2 - 1,
m_cameraPosition.y - m_worldSettings.worldSize / 2 - 1};

for(auto& chunk : m_chunks.getChunks())
bounds.maxPoint = { m_cameraPosition.x + m_worldSettings.worldSize / 2 + 1,
m_cameraPosition.y + m_worldSettings.worldSize / 2 + 1};

for(auto& chunk : m_chunks.getChunks())
{
Chunk::Full_Chunk& c = chunk.second;
auto location = c.getPosition();

//Check bounds
if (location.x <= bounds.minPoint.x ||
location.x >= bounds.maxPoint.x ||
location.y <= bounds.minPoint.z ||
location.y >= bounds.maxPoint.z)
{
Chunk::Full_Chunk& c = chunk.second;
auto location = c.getPosition();

//Check bounds
if (location.x <= bounds.minPoint.x ||
location.x >= bounds.maxPoint.x ||
location.y <= bounds.minPoint.z ||
location.y >= bounds.maxPoint.z)
//If the chunk is outside of the bounds of the render distance, then add the position of it into a delete vector
if (!c.hasDeleteFlag)
{
//If the chunk is outside of the bounds of the render distance, then add the position of it into a delete vector
if (!c.hasDeleteFlag)
{
c.hasDeleteFlag = true;
m_deleteChunks.push_back(location);
}
c.hasDeleteFlag = true;
m_deleteChunks.push_back(location);
}
}
}


m_deleteMutex.unlock();
}
1 change: 0 additions & 1 deletion Source/World/World_Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct World_Settings
Noise::Data noiseData;
int32_t worldSize;
float seed;
bool isInfiniteTerrain = false;
bool isSuperFlat = false;
bool isExperimentalMode = false;
};
Expand Down

0 comments on commit ecc3892

Please sign in to comment.