]> git.localhorst.tv Git - blank.git/blob - src/client/InteractiveState.hpp
dc84199c6be49025b35fe42a1feb1e6248d5bd8d
[blank.git] / src / client / InteractiveState.hpp
1 #ifndef BLANK_CLIENT_INTERACTIVESTATE_HPP_
2 #define BLANK_CLIENT_INTERACTIVESTATE_HPP_
3
4 #include "../app/State.hpp"
5 #include "../ui/ClientController.hpp"
6
7 #include "ChunkReceiver.hpp"
8 #include "NetworkedInput.hpp"
9 #include "../app/ChatState.hpp"
10 #include "../app/IntervalTimer.hpp"
11 #include "../audio/SoundBank.hpp"
12 #include "../graphics/SkyBox.hpp"
13 #include "../io/WorldSave.hpp"
14 #include "../net/Packet.hpp"
15 #include "../shared/WorldResources.hpp"
16 #include "../ui/HUD.hpp"
17 #include "../ui/InteractiveManipulator.hpp"
18 #include "../ui/Interface.hpp"
19 #include "../world/ChunkRenderer.hpp"
20 #include "../world/EntityState.hpp"
21 #include "../world/Player.hpp"
22 #include "../world/World.hpp"
23
24
25 namespace blank {
26
27 class Environment;
28
29 namespace client {
30
31 class MasterState;
32
33 class InteractiveState
34 : public State
35 , public ClientController
36 , public ChatState::Responder {
37
38 public:
39         explicit InteractiveState(MasterState &, std::uint32_t player_id);
40
41         World &GetWorld() noexcept { return world; }
42         Player &GetPlayer() noexcept { return player; }
43         PlayerController &GetPlayerController() noexcept { return input; }
44         ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
45
46         void OnEnter() override;
47
48         void Handle(const SDL_Event &) override;
49         void Update(int dt) override;
50         void Render(Viewport &) override;
51
52         void Handle(const Packet::SpawnEntity &);
53         void Handle(const Packet::DespawnEntity &);
54         void Handle(const Packet::EntityUpdate &);
55         void Handle(const Packet::PlayerCorrection &);
56         void Handle(const Packet::BlockUpdate &);
57         void Handle(const Packet::Message &);
58
59         void SetAudio(bool) override;
60         void SetVideo(bool) override;
61         void SetHUD(bool) override;
62         void SetDebug(bool) override;
63         void Exit() override;
64
65         void OnLineSubmit(const std::string &) override;
66
67 private:
68         /// flag entity as updated by given packet
69         /// returns false if the update should be ignored
70         bool UpdateEntity(std::uint32_t id, std::uint16_t seq);
71         /// drop update information or given entity
72         void ClearEntity(std::uint32_t id);
73
74 private:
75         MasterState &master;
76         WorldResources res;
77         SoundBank sounds;
78         WorldSave save;
79         World world;
80         Player &player;
81         HUD hud;
82         InteractiveManipulator manip;
83         NetworkedInput input;
84         Interface interface;
85         ChunkReceiver chunk_receiver;
86         ChunkRenderer chunk_renderer;
87         IntervalTimer loop_timer;
88
89         SkyBox sky;
90
91         struct UpdateStatus {
92                 std::uint16_t last_packet;
93                 int last_update;
94         };
95         std::map<std::uint32_t, UpdateStatus> update_status;
96
97         ChatState chat;
98
99 };
100
101 }
102 }
103
104 #endif