]> git.localhorst.tv Git - blank.git/blob - src/client/InteractiveState.hpp
fix comment handling in TokenStreamReader
[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/ChatState.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 OnResume() override;
47         void OnPause() override;
48
49         void OnFocus() override;
50         void OnBlur() override;
51
52         void Handle(const SDL_Event &) override;
53         void Update(int dt) override;
54         void Render(Viewport &) override;
55
56         void Handle(const Packet::SpawnEntity &);
57         void Handle(const Packet::DespawnEntity &);
58         void Handle(const Packet::EntityUpdate &);
59         void Handle(const Packet::PlayerCorrection &);
60         void Handle(const Packet::BlockUpdate &);
61         void Handle(const Packet::Message &);
62
63         void SetAudio(bool) override;
64         void SetVideo(bool) override;
65         void SetHUD(bool) override;
66         void SetDebug(bool) override;
67         void NextCamera() override;
68         void Exit() override;
69
70         void OnLineSubmit(const std::string &) override;
71
72 private:
73         /// flag entity as updated by given packet
74         /// returns false if the update should be ignored
75         bool UpdateEntity(std::uint32_t id, std::uint16_t seq);
76         /// drop update information or given entity
77         void ClearEntity(std::uint32_t id);
78
79 private:
80         MasterState &master;
81         WorldResources res;
82         SoundBank sounds;
83         WorldSave save;
84         World world;
85         Player &player;
86         HUD hud;
87         InteractiveManipulator manip;
88         NetworkedInput input;
89         Interface interface;
90         ChunkReceiver chunk_receiver;
91         ChunkRenderer chunk_renderer;
92         CoarseTimer loop_timer;
93         CoarseTimer stat_timer;
94
95         SkyBox sky;
96
97         struct UpdateStatus {
98                 std::uint16_t last_packet;
99                 int last_update;
100         };
101         std::map<std::uint32_t, UpdateStatus> update_status;
102
103         ChatState chat;
104
105         int time_skipped;
106         unsigned int packets_skipped;
107
108 };
109
110 }
111 }
112
113 #endif