X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fserver%2FClientConnection.hpp;h=57a34e49339a965655a170758a82603558bc6155;hb=73d4dd2d78eda1e2f8889d1913a97a60cec86876;hp=2f03e67eca5bea2315b3b24602fa4f825e220ff7;hpb=38a4cffc0b6aa58e49d24c06aad7bee14cb6515d;p=blank.git diff --git a/src/server/ClientConnection.hpp b/src/server/ClientConnection.hpp index 2f03e67..57a34e4 100644 --- a/src/server/ClientConnection.hpp +++ b/src/server/ClientConnection.hpp @@ -4,6 +4,7 @@ #include "ChunkTransmitter.hpp" #include "Server.hpp" #include "../app/IntervalTimer.hpp" +#include "../ui/DirectInput.hpp" #include "../net/Connection.hpp" #include "../net/ConnectionHandler.hpp" #include "../world/EntityState.hpp" @@ -11,11 +12,15 @@ #include #include +#include #include #include namespace blank { + +class Model; + namespace server { class Server; @@ -41,16 +46,22 @@ public: } /// send the previously prepared packet std::uint16_t Send(); - /// send the previously prepared packet of non-default length + /// send the previously prepared packet of given payload length std::uint16_t Send(std::size_t len); - void AttachPlayer(const Player &); + void AttachPlayer(Player &); void DetachPlayer(); - bool HasPlayer() const noexcept { return player.entity; } - Entity &PlayerEntity() noexcept { return *player.entity; } - const Entity &PlayerEntity() const noexcept { return *player.entity; } - ChunkIndex &PlayerChunks() noexcept { return *player.chunks; } - const ChunkIndex &PlayerChunks() const noexcept { return *player.chunks; } + bool HasPlayer() const noexcept { return !!input; } + Entity &PlayerEntity() noexcept { return input->GetPlayer().GetEntity(); } + const Entity &PlayerEntity() const noexcept { return input->GetPlayer().GetEntity(); } + ChunkIndex &PlayerChunks() noexcept { return input->GetPlayer().GetChunks(); } + const ChunkIndex &PlayerChunks() const noexcept { return input->GetPlayer().GetChunks(); } + + void SetPlayerModel(const Model &) noexcept; + bool HasPlayerModel() const noexcept; + const Model &GetPlayerModel() const noexcept; + + bool ChunkInRange(const glm::ivec3 &) const noexcept; private: struct SpawnStatus { @@ -72,12 +83,17 @@ private: void On(const Packet::Login &) override; void On(const Packet::Part &) override; void On(const Packet::PlayerUpdate &) override; + void On(const Packet::ChunkBegin &) override; + void On(const Packet::Message &) override; + void CheckEntities(); bool CanSpawn(const Entity &) const noexcept; bool CanDespawn(const Entity &) const noexcept; void SendSpawn(SpawnStatus &); void SendDespawn(SpawnStatus &); + /// true if entity updates are pushed to the client this frame + bool SendingUpdates() const noexcept; void QueueUpdate(SpawnStatus &); void SendUpdates(); @@ -88,19 +104,23 @@ private: private: Server &server; Connection conn; - Player player; + std::unique_ptr input; + const Model *player_model; std::list spawns; unsigned int confirm_wait; std::vector entity_updates; + unsigned int entity_updates_skipped; EntityState player_update_state; std::uint16_t player_update_pack; - IntervalTimer player_update_timer; + CoarseTimer player_update_timer; + std::uint8_t old_actions; ChunkTransmitter transmitter; std::deque chunk_queue; glm::ivec3 old_base; + unsigned int chunk_blocks_skipped; };