]> git.localhorst.tv Git - blank.git/blob - src/client/MasterState.hpp
move server and client stuff around
[blank.git] / src / client / MasterState.hpp
1 #ifndef BLANK_CLIENT_CLIENTSTATE_HPP_
2 #define BLANK_CLIENT_CLIENTSTATE_HPP_
3
4 #include "Client.hpp"
5 #include "InitialState.hpp"
6 #include "InteractiveState.hpp"
7 #include "../app/State.hpp"
8 #include "../net/ConnectionHandler.hpp"
9
10 #include <map>
11 #include <memory>
12
13
14 namespace blank {
15
16 class Environment;
17
18 namespace client {
19
20 class InteractiveState;
21
22 class MasterState
23 : public State
24 , public ConnectionHandler {
25
26 public:
27         MasterState(
28                 Environment &,
29                 const World::Config &,
30                 const Interface::Config &,
31                 const Client::Config &
32         );
33
34         Client &GetClient() noexcept { return client; }
35         Environment &GetEnv() noexcept { return env; }
36
37         World::Config &GetWorldConf() noexcept { return world_conf; }
38         const World::Config &GetWorldConf() const noexcept { return world_conf; }
39         const Interface::Config &GetInterfaceConf() const noexcept { return intf_conf; }
40         const Client::Config &GetClientConf() const noexcept { return client_conf; }
41
42         void Quit();
43
44         void OnEnter() override;
45
46         void Handle(const SDL_Event &) override;
47         void Update(int dt) override;
48         void Render(Viewport &) override;
49
50         void OnPacketLost(std::uint16_t) override;
51         void OnTimeout() override;
52
53         void On(const Packet::Join &) override;
54         void On(const Packet::Part &) override;
55         void On(const Packet::SpawnEntity &) override;
56         void On(const Packet::DespawnEntity &) override;
57         void On(const Packet::EntityUpdate &) override;
58         void On(const Packet::PlayerCorrection &) override;
59         void On(const Packet::ChunkBegin &) override;
60         void On(const Packet::ChunkData &) override;
61
62 private:
63         /// flag entity as updated by given packet
64         /// returns false if the update should be ignored
65         bool UpdateEntity(std::uint32_t id, std::uint16_t seq);
66         /// drop update information or given entity
67         void ClearEntity(std::uint32_t id);
68
69 private:
70         Environment &env;
71         World::Config world_conf;
72         const Interface::Config &intf_conf;
73         const Client::Config &client_conf;
74         std::unique_ptr<InteractiveState> state;
75         Client client;
76
77         InitialState init_state;
78
79         int login_packet;
80
81         struct UpdateStatus {
82                 std::uint16_t last_packet;
83                 int last_update;
84         };
85         std::map<std::uint32_t, UpdateStatus> update_status;
86         IntervalTimer update_timer;
87
88 };
89
90 }
91 }
92
93 #endif