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