]> git.localhorst.tv Git - blank.git/blob - src/client/InteractiveState.hpp
49c54745f8f88c57b94af1b52d6a7f72fb12fd68
[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 "../audio/SoundBank.hpp"
11 #include "../graphics/SkyBox.hpp"
12 #include "../io/WorldSave.hpp"
13 #include "../net/Packet.hpp"
14 #include "../shared/WorldResources.hpp"
15 #include "../ui/HUD.hpp"
16 #include "../ui/InteractiveManipulator.hpp"
17 #include "../ui/Interface.hpp"
18 #include "../world/ChunkRenderer.hpp"
19 #include "../world/EntityState.hpp"
20 #include "../world/Player.hpp"
21 #include "../world/World.hpp"
22
23
24 namespace blank {
25
26 class Environment;
27
28 namespace client {
29
30 class MasterState;
31
32 class InteractiveState
33 : public State
34 , public ClientController {
35
36 public:
37         explicit InteractiveState(MasterState &, std::uint32_t player_id);
38
39         World &GetWorld() noexcept { return world; }
40         Player &GetPlayer() noexcept { return player; }
41         PlayerController &GetPlayerController() noexcept { return input; }
42         ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
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 Handle(const Packet::SpawnEntity &);
51         void Handle(const Packet::DespawnEntity &);
52         void Handle(const Packet::EntityUpdate &);
53         void Handle(const Packet::PlayerCorrection &);
54         void Handle(const Packet::BlockUpdate &);
55
56         void SetAudio(bool) override;
57         void SetVideo(bool) override;
58         void SetHUD(bool) override;
59         void SetDebug(bool) override;
60         void Exit() 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         MasterState &master;
71         WorldResources res;
72         SoundBank sounds;
73         WorldSave save;
74         World world;
75         Player &player;
76         HUD hud;
77         InteractiveManipulator manip;
78         NetworkedInput input;
79         Interface interface;
80         ChunkReceiver chunk_receiver;
81         ChunkRenderer chunk_renderer;
82         IntervalTimer loop_timer;
83
84         SkyBox sky;
85
86         struct UpdateStatus {
87                 std::uint16_t last_packet;
88                 int last_update;
89         };
90         std::map<std::uint32_t, UpdateStatus> update_status;
91
92 };
93
94 }
95 }
96
97 #endif