[ServerWorld] Fixed #115.

This commit is contained in:
Quentin Bazin 2020-06-19 00:45:52 +02:00
parent 0542b8de66
commit bfe48f64da
3 changed files with 13 additions and 7 deletions

View File

@ -29,6 +29,7 @@
#include "Dimension.hpp"
#include "EngineConfig.hpp"
#include "Network.hpp"
#include "PlayerList.hpp"
#include "Server.hpp"
#include "ServerCommandHandler.hpp"
#include "ServerConfig.hpp"
@ -47,7 +48,8 @@ void ServerWorld::update() {
if (it.second->isInitialized() && !it.second->isSent()) {
for (auto &client : m_server->server().info().clients())
sendChunkData(client, *it.second.get());
if (m_players.getPlayer(client.id)->dimension() == m_dimension.id())
sendChunkData(client, *it.second.get());
// gkDebug() << "Chunk updated at" << it.second->x() << it.second->y() << it.second->z();
}

View File

@ -49,7 +49,7 @@ class ServerWorld : public World {
public:
ServerWorld(PlayerList &players, const Dimension &dimension, gk::GameClock &clock)
: m_dimension(dimension), m_terrainGenerator(dimension), m_clock(clock), m_scene(players) {}
: m_players(players), m_dimension(dimension), m_terrainGenerator(dimension), m_clock(clock), m_scene(players) {}
void update();
@ -74,6 +74,8 @@ class ServerWorld : public World {
static void initUsertype(sol::state &lua);
private:
PlayerList &m_players;
const Dimension &m_dimension;
ChunkMap m_chunks;

View File

@ -47,7 +47,7 @@ void WorldController::update() {
}
void WorldController::load(const std::string &name) {
// std::cout << "Loading '" + name + "'..." << std::endl;
gkDebug() << ("Loading '" + name + "'...").c_str();
std::ifstream file(name + ".dat", std::ofstream::binary);
@ -68,7 +68,7 @@ void WorldController::load(const std::string &name) {
unsigned int chunkCount;
save >> chunkCount;
// std::cout << "Dimension " << world.dimension().id() << " chunk count: " << chunkCount << std::endl;
gkDebug() << "Loading dimension" << world.dimension().id() << "| Chunk count:" << chunkCount;
for (unsigned int i = 0 ; i < chunkCount ; ++i) {
int cx, cy, cz;
@ -95,11 +95,11 @@ void WorldController::load(const std::string &name) {
}
}
// std::cout << "Loading done." << std::endl;
gkDebug() << "Loading done.";
}
void WorldController::save(const std::string &name) {
// std::cout << "Saving '" << name << "'..." << std::endl;
gkDebug() << ("Saving '" + name + "'...").c_str();
std::ofstream file(name + ".dat", std::ofstream::binary | std::ofstream::trunc);
@ -126,11 +126,13 @@ void WorldController::save(const std::string &name) {
++chunkCount;
}
// std::cout << "Saving dimension " << world.dimension().id() << ". Chunk count: " << chunkCount << std::endl;
gkDebug() << "Saving dimension" << world.dimension().id() << "| Chunk count:" << chunkCount;
save << chunkCount;
save.append(chunks.getData(), chunks.getDataSize());
}
file.write((const char *)save.getData(), save.getDataSize());
gkDebug() << "Saving done.";
}