diff --git a/client/include/world/ClientWorld.hpp b/client/include/world/ClientWorld.hpp index 9bdf117bf..89861c2b3 100644 --- a/client/include/world/ClientWorld.hpp +++ b/client/include/world/ClientWorld.hpp @@ -38,9 +38,9 @@ class ClientWorld : public World, public gk::Drawable { public: ClientWorld(); - void init(float playerX, float playerY, float playerZ); void update(); void sendChunkRequests(); + void checkPlayerChunk(double playerX, double playerY, double playerZ); void receiveChunkData(sf::Packet &packet); void removeChunk(ChunkMap::iterator &it); diff --git a/client/source/network/ClientCommandHandler.cpp b/client/source/network/ClientCommandHandler.cpp index 6af9be5b7..44945c06f 100644 --- a/client/source/network/ClientCommandHandler.cpp +++ b/client/source/network/ClientCommandHandler.cpp @@ -160,8 +160,6 @@ void ClientCommandHandler::setupCallbacks() { m_playerBoxes.at(clientId).setPosition(pos.x, pos.y, pos.z); m_playerBoxes.at(clientId).setClientID(clientId); } - - m_world.init(pos.x, pos.y, pos.z); }); m_client.setCommandCallback(Network::Command::BlockGUIData, [this](sf::Packet &packet) { diff --git a/client/source/states/GameState.cpp b/client/source/states/GameState.cpp index ef1745cea..7e0453d55 100644 --- a/client/source/states/GameState.cpp +++ b/client/source/states/GameState.cpp @@ -118,6 +118,7 @@ void GameState::onEvent(const SDL_Event &event) { } void GameState::update() { + m_world.checkPlayerChunk(m_player.x(), m_player.y(), m_player.z()); m_world.update(); if (m_camera.getFieldOfView() != Config::cameraFOV) diff --git a/client/source/world/ClientWorld.cpp b/client/source/world/ClientWorld.cpp index 2698d19a9..ab8a285bf 100644 --- a/client/source/world/ClientWorld.cpp +++ b/client/source/world/ClientWorld.cpp @@ -26,6 +26,7 @@ #include #include "ClientCommandHandler.hpp" +#include "ClientPlayer.hpp" #include "ClientWorld.hpp" #include "TextureAtlas.hpp" #include "World.hpp" @@ -35,14 +36,6 @@ ClientWorld::ClientWorld() : { } -void ClientWorld::init(float playerX, float playerY, float playerZ) { - int pcx = std::floor(playerX / CHUNK_WIDTH); - int pcy = std::floor(playerY / CHUNK_DEPTH); - int pcz = std::floor(playerZ / CHUNK_HEIGHT); - - m_chunks.emplace(gk::Vector3i{pcx, pcy, pcz}, new ClientChunk(pcx, pcy, pcz, *this, m_textureAtlas)); -} - void ClientWorld::update() { // Update loaded chunks for (auto it = m_chunks.begin() ; it != m_chunks.end() ;) { @@ -81,6 +74,17 @@ void ClientWorld::sendChunkRequests() { } } +void ClientWorld::checkPlayerChunk(double playerX, double playerY, double playerZ) { + int pcx = std::floor(playerX / CHUNK_WIDTH); + int pcy = std::floor(playerY / CHUNK_DEPTH); + int pcz = std::floor(playerZ / CHUNK_HEIGHT); + + ClientChunk *chunk = (ClientChunk *)getChunk(pcx, pcy, pcz); + if (!chunk) { + m_chunks.emplace(gk::Vector3i{pcx, pcy, pcz}, new ClientChunk(pcx, pcy, pcz, *this, m_textureAtlas)); + } +} + void ClientWorld::receiveChunkData(sf::Packet &packet) { s32 cx, cy, cz; packet >> cx >> cy >> cz;