Fixed dimension change.
This commit is contained in:
parent
8ecd91715e
commit
fa194fd9e2
@ -241,8 +241,6 @@ mod:block {
|
||||
}
|
||||
|
||||
server:send_player_change_dimension(client.id, pos.x, pos.y, pos.z, dim, client)
|
||||
player:set_dimension(dim)
|
||||
-- player:set_position(pos.x, pos.y, pos.z)
|
||||
end,
|
||||
}
|
||||
|
||||
|
@ -303,10 +303,11 @@ void ClientCommandHandler::setupCallbacks() {
|
||||
|
||||
if (clientId == m_client.id()) {
|
||||
m_player.setDimension(dimension);
|
||||
m_player.setPosition(x, y, z);
|
||||
m_player.setPosition(x + 0.5, y + 0.5, z + 0.5);
|
||||
m_world.clear();
|
||||
m_world.changeDimension(dimension);
|
||||
m_entityMap.clear();
|
||||
sendPlayerChunkPosUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -163,10 +163,6 @@ void ClientPlayer::updatePosition(const ClientWorld &world) {
|
||||
}
|
||||
|
||||
void ClientPlayer::setPosition(double x, double y, double z) {
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
|
||||
Player::setPosition(x, y, z);
|
||||
|
||||
gk::Vector3f camPos = m_cameraLocalPos;
|
||||
|
@ -111,6 +111,8 @@ void ClientWorld::clear() {
|
||||
}
|
||||
|
||||
void ClientWorld::changeDimension(u16 dimensionID) {
|
||||
World::clearUpdateQueues();
|
||||
|
||||
const Dimension &dimension = Registry::getInstance().getDimension(dimensionID);
|
||||
m_dimension = &dimension;
|
||||
|
||||
|
@ -116,6 +116,17 @@ void World::setData(int x, int y, int z, u16 data) const {
|
||||
chunk->setData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), data);
|
||||
}
|
||||
|
||||
void World::clearUpdateQueues() {
|
||||
while (!m_chunkUpdateQueue.empty())
|
||||
m_chunkUpdateQueue.pop();
|
||||
|
||||
while (!m_chunkProcessQueue.empty())
|
||||
m_chunkProcessQueue.pop();
|
||||
|
||||
m_chunksToUpdate.clear();
|
||||
m_chunksToProcess.clear();
|
||||
}
|
||||
|
||||
// Please update 'docs/lua-api-cpp.md' if you change this
|
||||
void World::initUsertype(sol::state &lua) {
|
||||
lua.new_usertype<World>("World",
|
||||
|
@ -72,6 +72,9 @@ class World {
|
||||
|
||||
static bool isReloadRequested;
|
||||
|
||||
protected:
|
||||
void clearUpdateQueues();
|
||||
|
||||
private:
|
||||
std::set<Chunk *> m_chunksToUpdate;
|
||||
std::queue<Chunk *> m_chunkUpdateQueue;
|
||||
|
@ -140,20 +140,30 @@ void ServerCommandHandler::sendPlayerInvUpdate(u16 clientID, const ClientInfo *c
|
||||
}
|
||||
|
||||
void ServerCommandHandler::sendPlayerChangeDimension(u16 clientID, s32 x, s32 y, s32 z, u16 dimension, const ClientInfo *client) const {
|
||||
Network::Packet packet;
|
||||
packet << Network::Command::PlayerChangeDimension;
|
||||
packet << clientID << x << y << z << dimension;
|
||||
ServerPlayer *player = m_players.getPlayerFromClientID(clientID);
|
||||
if (player) {
|
||||
Network::Packet packet;
|
||||
packet << Network::Command::PlayerChangeDimension;
|
||||
packet << clientID << x << y << z << dimension;
|
||||
|
||||
if (!client)
|
||||
m_server.sendToAllClients(packet);
|
||||
if (client) {
|
||||
client->tcpSocket->send(packet);
|
||||
|
||||
// FIXME: sendPlayerChangeDimension shouldn't be exposed to Lua
|
||||
// Instead, there should be a changePlayerDimension function that sends
|
||||
// the packet above + the entities (instead of doing that here)
|
||||
// also, it should change player dimension and position accordingly
|
||||
m_worldController.getWorld(dimension).scene().sendEntities(*client);
|
||||
|
||||
player->setPosition(x + 0.5, y + 0.5, z + 0.5);
|
||||
player->setDimension(dimension);
|
||||
player->clearLoadedChunks();
|
||||
}
|
||||
else
|
||||
m_server.sendToAllClients(packet);
|
||||
}
|
||||
else
|
||||
client->tcpSocket->send(packet);
|
||||
|
||||
// FIXME: sendPlayerChangeDimension shouldn't be exposed to Lua
|
||||
// Instead, there should be a world.changePlayerDimension function that sends
|
||||
// the packet above + the entities (instead of doing that here)
|
||||
if (client)
|
||||
m_worldController.getWorld(dimension).scene().sendEntities(*client);
|
||||
gkError() << ("Failed to send dimension change for player " + std::to_string(clientID) + ": Player not found").c_str();
|
||||
}
|
||||
|
||||
void ServerCommandHandler::sendChatMessage(u16 clientID, const std::string &message, const ClientInfo *client) const {
|
||||
|
@ -177,6 +177,9 @@ void ServerWorld::processSendRequests() {
|
||||
// u64 chunksTooOld = 0;
|
||||
// u64 startQueueSize = m_chunkSendRequestQueue.size();
|
||||
|
||||
if (!m_chunkSendRequestQueue.empty())
|
||||
gkDebug() << "Processing send requests...";
|
||||
|
||||
u64 start = gk::GameClock::getInstance().getTicks(true);
|
||||
u64 now = start;
|
||||
while (/* now - start < 100 && */!m_chunkSendRequestQueue.empty()) {
|
||||
@ -251,8 +254,8 @@ void ServerWorld::processSendRequests() {
|
||||
now = gk::GameClock::getInstance().getTicks(true);
|
||||
}
|
||||
|
||||
if (m_dimension.id() == 0 && now - start > 0) {
|
||||
gkDebug() << "Took" << now - start << "ms"
|
||||
if (now - start > 0) {
|
||||
gkDebug() << "Done in" << now - start << "ms for dim" << m_dimension.id()
|
||||
<< "| Gen:" << chunksGenerated
|
||||
<< "| Sent:" << chunksSent;
|
||||
// << "| BTQ:" << chunksBackToQueue
|
||||
|
Loading…
x
Reference in New Issue
Block a user