[ClientWorld] Teleportation and fast movement won't stop the world from loading. Fixes #50.

This commit is contained in:
Quentin Bazin 2020-02-24 18:53:21 +09:00
parent 040c8d5d07
commit 75f9bc6dbd
4 changed files with 14 additions and 11 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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)

View File

@ -26,6 +26,7 @@
#include <gk/resource/ResourceHandler.hpp>
#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;