]> git.localhorst.tv Git - blank.git/blob - src/client/InteractiveState.hpp
store shapes in models rather than meshes
[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 "../model/ShapeRegistry.hpp"
13 #include "../model/Skeletons.hpp"
14 #include "../net/Packet.hpp"
15 #include "../ui/HUD.hpp"
16 #include "../ui/InteractiveManipulator.hpp"
17 #include "../ui/Interface.hpp"
18 #include "../world/BlockTypeRegistry.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
37 public:
38         explicit InteractiveState(MasterState &, std::uint32_t player_id);
39
40         World &GetWorld() noexcept { return world; }
41         Player &GetPlayer() noexcept { return player; }
42         ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
43         Skeletons &GetSkeletons() noexcept { return skeletons; }
44
45         void OnEnter() override;
46
47         void Handle(const SDL_Event &) override;
48         void Update(int dt) override;
49         void Render(Viewport &) override;
50
51         void Handle(const Packet::SpawnEntity &);
52         void Handle(const Packet::DespawnEntity &);
53         void Handle(const Packet::EntityUpdate &);
54         void Handle(const Packet::PlayerCorrection &);
55         void Handle(const Packet::BlockUpdate &);
56
57         void SetAudio(bool) override;
58         void SetVideo(bool) override;
59         void SetHUD(bool) override;
60         void SetDebug(bool) override;
61         void Exit() override;
62
63 private:
64         /// flag entity as updated by given packet
65         /// returns false if the update should be ignored
66         bool UpdateEntity(std::uint32_t id, std::uint16_t seq);
67         /// drop update information or given entity
68         void ClearEntity(std::uint32_t id);
69
70 private:
71         MasterState &master;
72         ShapeRegistry shapes;
73         BlockTypeRegistry block_types;
74         WorldSave save;
75         World world;
76         Player &player;
77         HUD hud;
78         InteractiveManipulator manip;
79         NetworkedInput input;
80         Interface interface;
81         ChunkReceiver chunk_receiver;
82         ChunkRenderer chunk_renderer;
83         Skeletons skeletons;
84         IntervalTimer loop_timer;
85
86         SkyBox sky;
87
88         std::vector<float> tex_map;
89
90         struct UpdateStatus {
91                 std::uint16_t last_packet;
92                 int last_update;
93         };
94         std::map<std::uint32_t, UpdateStatus> update_status;
95
96 };
97
98 }
99 }
100
101 #endif