Skip to content

Commit

Permalink
[ClientWorld] Teleportation and fast movement won't stop the world fr…
Browse files Browse the repository at this point in the history
…om loading. Fixes #50.
  • Loading branch information
Unarelith committed Feb 24, 2020
1 parent 040c8d5 commit 75f9bc6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/include/world/ClientWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions client/source/network/ClientCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions client/source/states/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions client/source/world/ClientWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <gk/resource/ResourceHandler.hpp>

#include "ClientCommandHandler.hpp"
#include "ClientPlayer.hpp"
#include "ClientWorld.hpp"
#include "TextureAtlas.hpp"
#include "World.hpp"
Expand All @@ -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() ;) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 75f9bc6

Please sign in to comment.