]> git.localhorst.tv Git - blank.git/blobdiff - src/server/ClientConnection.hpp
send updates less frequently on bad connections
[blank.git] / src / server / ClientConnection.hpp
index 2089dd17c8eec85a7acf7e6e7d3d930f03946a5f..16beccf7aecb100471185aca85cd684023e2d6c8 100644 (file)
@@ -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"
 
 #include <deque>
 #include <list>
+#include <memory>
 #include <SDL_net.h>
 #include <vector>
 
 
 namespace blank {
 
-class CompositeModel;
+class Model;
 
 namespace server {
 
@@ -49,15 +51,17 @@ public:
 
        void AttachPlayer(Player &);
        void DetachPlayer();
-       bool HasPlayer() const noexcept { return player; }
-       Entity &PlayerEntity() noexcept { return player->GetEntity(); }
-       const Entity &PlayerEntity() const noexcept { return player->GetEntity(); }
-       ChunkIndex &PlayerChunks() noexcept { return player->GetChunks(); }
-       const ChunkIndex &PlayerChunks() const noexcept { return player->GetChunks(); }
+       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 CompositeModel &) noexcept;
+       void SetPlayerModel(const Model &) noexcept;
        bool HasPlayerModel() const noexcept;
-       const CompositeModel &GetPlayerModel() const noexcept;
+       const Model &GetPlayerModel() const noexcept;
+
+       bool ChunkInRange(const glm::ivec3 &) const noexcept;
 
 private:
        struct SpawnStatus {
@@ -79,12 +83,15 @@ private:
        void On(const Packet::Login &) override;
        void On(const Packet::Part &) override;
        void On(const Packet::PlayerUpdate &) override;
+       void On(const Packet::Message &) override;
 
        bool CanSpawn(const Entity &) const noexcept;
        bool CanDespawn(const Entity &) const noexcept;
 
        void SendSpawn(SpawnStatus &);
        void SendDespawn(SpawnStatus &);
+       /// true if updates are pushed to the client this frame
+       bool SendingUpdates() const noexcept;
        void QueueUpdate(SpawnStatus &);
        void SendUpdates();
 
@@ -95,16 +102,18 @@ private:
 private:
        Server &server;
        Connection conn;
-       Player *player;
-       const CompositeModel *player_model;
+       std::unique_ptr<DirectInput> input;
+       const Model *player_model;
        std::list<SpawnStatus> spawns;
        unsigned int confirm_wait;
 
        std::vector<SpawnStatus *> 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<glm::ivec3> chunk_queue;