Removed useless code.

This commit is contained in:
Quentin Bazin 2020-01-16 16:02:02 +09:00
parent f09dbcc8e6
commit 6315216e66
9 changed files with 4 additions and 46 deletions

View File

@ -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();

View File

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

View File

@ -40,8 +40,10 @@ ServerConnectState::ServerConnectState() {
std::cerr << "Error: Invalid server address." << std::endl;
}
auto &game = m_stateStack->push<GameState>(host, port);
m_stateStack->push<ServerLoadingState>(game);
m_stateStack->push<GameState>(host, port);
// auto &game = m_stateStack->push<GameState>(host, port);
// m_stateStack->push<ServerLoadingState>(game);
});
m_cancelButton.setText("Cancel");

View File

@ -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);
}

View File

@ -29,7 +29,6 @@ namespace Network {
// Chunk commands
ChunkData, // <TCP> [NetworkCommand][s32 cx, cy, cz][u32...] (from Server only)
ChunkRequest, // <TCP> [NetworkCommand][s32 cx, cy, cz] (from Client only)
// Player commands
PlayerPlaceBlock, // <TCP> [NetworkCommand][s32 x, y, z][u32 block] (from Client only)
@ -47,9 +46,6 @@ namespace Network {
// Registry commands
RegistryData, // <TCP> [NetworkCommand][Block block] (from Server only)
// World commands
WorldSent, // <TCP> [NetworkCommand] (from Server only)
};
std::string commandToString(Command command);

View File

@ -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];
}

View File

@ -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;

View File

@ -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;

View File

@ -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())