[ServerWorld] Chunks are now sent correctly.
This commit is contained in:
parent
8bd9e860dc
commit
4fe4b60aea
@ -36,7 +36,7 @@ u8 ServerConfig::maxPlayers = 5;
|
||||
u16 ServerConfig::maxItemStackSize = 64;
|
||||
|
||||
// World
|
||||
u8 ServerConfig::renderDistance = 1;
|
||||
u8 ServerConfig::renderDistance = 5;
|
||||
|
||||
// Mod-defined options
|
||||
std::unordered_map<std::string, sol::object> ServerConfig::options;
|
||||
|
@ -60,6 +60,8 @@ class ServerPlayer : public Player {
|
||||
public:
|
||||
gk::Vector3i lastChunkUpdate{0, 0, 0}; // FIXME
|
||||
|
||||
std::unordered_set<gk::Vector3i> sentChunks; // Cleared every tick
|
||||
|
||||
private:
|
||||
ClientInfo *m_client = nullptr;
|
||||
|
||||
|
@ -51,6 +51,8 @@ void ServerWorld::update(bool doTick) {
|
||||
{
|
||||
for (auto &it : m_players) {
|
||||
if (it.second.isReady() && it.second.dimension() == m_dimension.id()) {
|
||||
it.second.sentChunks.clear();
|
||||
|
||||
gk::Vector3i currentChunk = it.second.getCurrentChunk();
|
||||
if (!it.second.isChunkLoaded(currentChunk) || it.second.lastChunkUpdate != currentChunk) {
|
||||
m_chunksToSend.emplace(std::make_pair(currentChunk, std::ref(it.second)));
|
||||
@ -67,9 +69,11 @@ void ServerWorld::update(bool doTick) {
|
||||
|
||||
while (!m_chunksToSend.empty()) {
|
||||
auto &[chunkPos, player] = m_chunksToSend.front();
|
||||
if (!player.isChunkLoaded(chunkPos)) {
|
||||
sendRequestedData(*player.client(), chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
player.addLoadedChunk(chunkPos);
|
||||
if (player.sentChunks.find(chunkPos) == player.sentChunks.end()) {
|
||||
if (!player.isChunkLoaded(chunkPos)) {
|
||||
sendRequestedData(*player.client(), chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
player.addLoadedChunk(chunkPos);
|
||||
}
|
||||
|
||||
gk::Vector3i playerChunkPos = player.getCurrentChunk();
|
||||
if ((playerChunkPos - chunkPos).length() < ServerConfig::renderDistance) {
|
||||
@ -80,6 +84,8 @@ void ServerWorld::update(bool doTick) {
|
||||
addChunkToSend(chunkPos, 0, 0, 1, player);
|
||||
addChunkToSend(chunkPos, 0, 0, -1, player);
|
||||
}
|
||||
|
||||
player.sentChunks.emplace(chunkPos);
|
||||
}
|
||||
|
||||
m_chunksToSend.pop();
|
||||
|
Loading…
x
Reference in New Issue
Block a user