From 6315216e662d0a8d19927d9e535720c5fd051c04 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Thu, 16 Jan 2020 16:02:02 +0900 Subject: [PATCH] Removed useless code. --- client/include/network/ClientCommandHandler.hpp | 1 - client/source/network/ClientCommandHandler.cpp | 7 ------- client/source/states/ServerConnectState.cpp | 6 ++++-- client/source/states/ServerLoadingState.cpp | 4 ---- common/include/network/Network.hpp | 4 ---- common/source/network/Network.cpp | 3 --- server/include/world/ServerWorld.hpp | 1 - server/source/network/ServerCommandHandler.cpp | 12 ------------ server/source/world/ServerWorld.cpp | 12 ------------ 9 files changed, 4 insertions(+), 46 deletions(-) diff --git a/client/include/network/ClientCommandHandler.hpp b/client/include/network/ClientCommandHandler.hpp index 9564943a..dcbf63de 100644 --- a/client/include/network/ClientCommandHandler.hpp +++ b/client/include/network/ClientCommandHandler.hpp @@ -37,7 +37,6 @@ class ClientCommandHandler { void sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block); void sendBlockActivated(const glm::vec4 &selectedBlock); void sendBlockInvUpdate(Inventory &inventory); - void sendChunkRequest(s32 chunkX, s32 chunkY, s32 chunkZ); void setupCallbacks(); diff --git a/client/source/network/ClientCommandHandler.cpp b/client/source/network/ClientCommandHandler.cpp index 424fe525..e0b6910a 100644 --- a/client/source/network/ClientCommandHandler.cpp +++ b/client/source/network/ClientCommandHandler.cpp @@ -73,13 +73,6 @@ void ClientCommandHandler::sendBlockInvUpdate(Inventory &inventory) { m_client.send(packet); } -void ClientCommandHandler::sendChunkRequest(s32 chunkX, s32 chunkY, s32 chunkZ) { - sf::Packet packet; - packet << Network::Command::ChunkRequest; - packet << chunkX << chunkY << chunkZ; - m_client.send(packet); -} - void ClientCommandHandler::setupCallbacks() { m_client.setCommandCallback(Network::Command::RegistryData, [this](sf::Packet &packet) { Registry::getInstance().deserialize(packet); diff --git a/client/source/states/ServerConnectState.cpp b/client/source/states/ServerConnectState.cpp index 8fe52593..0fd09758 100644 --- a/client/source/states/ServerConnectState.cpp +++ b/client/source/states/ServerConnectState.cpp @@ -40,8 +40,10 @@ ServerConnectState::ServerConnectState() { std::cerr << "Error: Invalid server address." << std::endl; } - auto &game = m_stateStack->push(host, port); - m_stateStack->push(game); + m_stateStack->push(host, port); + + // auto &game = m_stateStack->push(host, port); + // m_stateStack->push(game); }); m_cancelButton.setText("Cancel"); diff --git a/client/source/states/ServerLoadingState.cpp b/client/source/states/ServerLoadingState.cpp index 9b43826b..173ca020 100644 --- a/client/source/states/ServerLoadingState.cpp +++ b/client/source/states/ServerLoadingState.cpp @@ -37,10 +37,6 @@ ServerLoadingState::ServerLoadingState(GameState &game) : m_game(game) { m_textShadow.setColor(gk::Color{70, 70, 70, 255}); m_textShadow.setPosition(m_text.getPosition().x + 6, m_text.getPosition().y + 6); - m_game.client().setCommandCallback(Network::Command::WorldSent, [this] (sf::Packet &) { - m_isWorldSent = true; - }); - gk::Mouse::setCursorVisible(true); gk::Mouse::setCursorGrabbed(false); } diff --git a/common/include/network/Network.hpp b/common/include/network/Network.hpp index 9e807ae5..4069e27a 100644 --- a/common/include/network/Network.hpp +++ b/common/include/network/Network.hpp @@ -29,7 +29,6 @@ namespace Network { // Chunk commands ChunkData, // [NetworkCommand][s32 cx, cy, cz][u32...] (from Server only) - ChunkRequest, // [NetworkCommand][s32 cx, cy, cz] (from Client only) // Player commands PlayerPlaceBlock, // [NetworkCommand][s32 x, y, z][u32 block] (from Client only) @@ -47,9 +46,6 @@ namespace Network { // Registry commands RegistryData, // [NetworkCommand][Block block] (from Server only) - - // World commands - WorldSent, // [NetworkCommand] (from Server only) }; std::string commandToString(Command command); diff --git a/common/source/network/Network.cpp b/common/source/network/Network.cpp index 6a83e4fc..19abe645 100644 --- a/common/source/network/Network.cpp +++ b/common/source/network/Network.cpp @@ -27,7 +27,6 @@ std::string Network::commandToString(Network::Command command) { {Network::Command::KeyState, "KeyState"}, {Network::Command::ChunkData, "ChunkData"}, - {Network::Command::ChunkRequest, "ChunkRequest"}, {Network::Command::PlayerPlaceBlock, "PlayerPlaceBlock"}, {Network::Command::PlayerDigBlock, "PlayerDigBlock"}, @@ -42,8 +41,6 @@ std::string Network::commandToString(Network::Command command) { {Network::Command::BlockDataUpdate, "BlockDataUpdate"}, {Network::Command::RegistryData, "RegistryData"}, - - {Network::Command::WorldSent, "WorldSent"}, }; return commandNames[command]; } diff --git a/server/include/world/ServerWorld.hpp b/server/include/world/ServerWorld.hpp index 13561260..e1ffad9d 100644 --- a/server/include/world/ServerWorld.hpp +++ b/server/include/world/ServerWorld.hpp @@ -31,7 +31,6 @@ class ServerWorld : public World { void sendSpawnData(Client &client, ServerPlayer &player); void sendChunkData(Client &client, ServerChunk *chunk); - void sendRequestedData(Client &client, int cx, int cy, int cz); Chunk *getChunk(int cx, int cy, int cz) const override; diff --git a/server/source/network/ServerCommandHandler.cpp b/server/source/network/ServerCommandHandler.cpp index 30494a5a..0359c43f 100644 --- a/server/source/network/ServerCommandHandler.cpp +++ b/server/source/network/ServerCommandHandler.cpp @@ -53,21 +53,9 @@ void ServerCommandHandler::setupCallbacks() { spawnPacket << m_spawnPosition.x << m_spawnPosition.y << m_spawnPosition.z; m_server.sendToAllClients(spawnPacket); - // FIXME: Temporarily useless - // sf::Packet worldSentPacket; - // worldSentPacket << Network::Command::WorldSent; - // client.tcpSocket->send(worldSentPacket); - m_world.sendSpawnData(client, player); }); - m_server.setCommandCallback(Network::Command::ChunkRequest, [this](Client &client, sf::Packet &packet) { - s32 cx, cy, cz; - packet >> cx >> cy >> cz; - - m_world.sendRequestedData(client, cx, cy, cz); - }); - m_server.setCommandCallback(Network::Command::PlayerInvUpdate, [this](Client &client, sf::Packet &packet) { u16 clientId; packet >> clientId; diff --git a/server/source/world/ServerWorld.cpp b/server/source/world/ServerWorld.cpp index d658a435..86177746 100644 --- a/server/source/world/ServerWorld.cpp +++ b/server/source/world/ServerWorld.cpp @@ -136,18 +136,6 @@ void ServerWorld::sendChunkData(Client &client, ServerChunk *chunk) { std::cout << "Chunk at (" << chunk->x() << ", " << chunk->y() << ", " << chunk->z() << ") sent to client" << std::endl; } -void ServerWorld::sendRequestedData(Client &client, int cx, int cy, int cz) { - std::cout << "Chunk at (" << cx << ", " << cy << ", " << cz << ") requested" << std::endl; - - Chunk *chunk = getChunk(cx, cy, cz); - if (!chunk) { - auto it = m_chunks.emplace(gk::Vector3i(cx, cy, cz), new ServerChunk(cx, cy, cz)); - chunk = it.first->second.get(); - } - - sendChunkData(client, (ServerChunk *)chunk); -} - Chunk *ServerWorld::getChunk(int cx, int cy, int cz) const { auto it = m_chunks.find({cx, cy, cz}); if (it == m_chunks.end())