]> git.localhorst.tv Git - blank.git/blob - src/client/InteractiveState.hpp
block sounds depending on block type
[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         ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
42
43         void OnEnter() override;
44
45         void Handle(const SDL_Event &) override;
46         void Update(int dt) override;
47         void Render(Viewport &) override;
48
49         void Handle(const Packet::SpawnEntity &);
50         void Handle(const Packet::DespawnEntity &);
51         void Handle(const Packet::EntityUpdate &);
52         void Handle(const Packet::PlayerCorrection &);
53         void Handle(const Packet::BlockUpdate &);
54
55         void SetAudio(bool) override;
56         void SetVideo(bool) override;
57         void SetHUD(bool) override;
58         void SetDebug(bool) override;
59         void Exit() override;
60
61 private:
62         /// flag entity as updated by given packet
63         /// returns false if the update should be ignored
64         bool UpdateEntity(std::uint32_t id, std::uint16_t seq);
65         /// drop update information or given entity
66         void ClearEntity(std::uint32_t id);
67
68 private:
69         MasterState &master;
70         WorldResources res;
71         SoundBank sounds;
72         WorldSave save;
73         World world;
74         Player &player;
75         HUD hud;
76         InteractiveManipulator manip;
77         NetworkedInput input;
78         Interface interface;
79         ChunkReceiver chunk_receiver;
80         ChunkRenderer chunk_renderer;
81         IntervalTimer loop_timer;
82
83         SkyBox sky;
84
85         struct UpdateStatus {
86                 std::uint16_t last_packet;
87                 int last_update;
88         };
89         std::map<std::uint32_t, UpdateStatus> update_status;
90
91 };
92
93 }
94 }
95
96 #endif