Skip to content

Commit

Permalink
[ServerWorld] Fixed #115.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jun 18, 2020
1 parent 0542b8d commit bfe48f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion source/server/world/ServerWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion source/server/world/ServerWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions source/server/world/WorldController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

Expand All @@ -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.";
}

0 comments on commit bfe48f6

Please sign in to comment.