diff options
Diffstat (limited to 'src/client/state')
| -rw-r--r-- | src/client/state/chunks.cc | 1 | ||||
| -rw-r--r-- | src/client/state/chunks.hh | 18 | ||||
| -rw-r--r-- | src/client/state/entities.cc | 1 | ||||
| -rw-r--r-- | src/client/state/entities.hh | 21 | ||||
| -rw-r--r-- | src/client/state/state.cc | 15 | ||||
| -rw-r--r-- | src/client/state/state.hh | 41 |
6 files changed, 97 insertions, 0 deletions
diff --git a/src/client/state/chunks.cc b/src/client/state/chunks.cc new file mode 100644 index 0000000..470c552 --- /dev/null +++ b/src/client/state/chunks.cc @@ -0,0 +1 @@ +#include "client/state/chunks.hh" diff --git a/src/client/state/chunks.hh b/src/client/state/chunks.hh new file mode 100644 index 0000000..e0d4d82 --- /dev/null +++ b/src/client/state/chunks.hh @@ -0,0 +1,18 @@ +#ifndef CLIENT_STATE_CHUNKS_HH_ +#define CLIENT_STATE_CHUNKS_HH_ + +#include <memory> +#include <unordered_map> + +#include "client/world/chunk.hh" + +namespace client { +namespace state { + +inline client::world::chunks_t chunks{4096, shared::world::chunk::hash, + shared::world::chunk::equal}; + +} // namespace state +} // namespace client + +#endif diff --git a/src/client/state/entities.cc b/src/client/state/entities.cc new file mode 100644 index 0000000..efb3533 --- /dev/null +++ b/src/client/state/entities.cc @@ -0,0 +1 @@ +#include "client/state/entities.hh" diff --git a/src/client/state/entities.hh b/src/client/state/entities.hh new file mode 100644 index 0000000..3c807b9 --- /dev/null +++ b/src/client/state/entities.hh @@ -0,0 +1,21 @@ +#ifndef CLIENT_STATE_ENTITIES_HH_ +#define CLIENT_STATE_ENTITIES_HH_ + +#include <memory> +#include <unordered_map> + +#include "client/entity/entity.hh" + +namespace client { + +using entities_t = std::unordered_map<shared::entity::index_t, + std::unique_ptr<client::entity>>; + +namespace state { + +inline entities_t entities; + +} // namespace state +} // namespace client + +#endif diff --git a/src/client/state/state.cc b/src/client/state/state.cc new file mode 100644 index 0000000..2423c9a --- /dev/null +++ b/src/client/state/state.cc @@ -0,0 +1,15 @@ +#include "client/state/state.hh" + +namespace client { +namespace state { + +shared::time_duration_t get_time_per_tick() noexcept { + return std::chrono::microseconds(1'000'000) / tickrate; +} + +bool has_initialised() noexcept { + return state::localplayer_index.has_value(); +} + +} // namespace state +} // namespace client diff --git a/src/client/state/state.hh b/src/client/state/state.hh new file mode 100644 index 0000000..cfbb440 --- /dev/null +++ b/src/client/state/state.hh @@ -0,0 +1,41 @@ +#ifndef CLIENT_STATE_STATE_HH_ +#define CLIENT_STATE_STATE_HH_ + +#include <optional> + +#include "shared/entity/entity.hh" +#include "shared/net/connection.hh" +#include "shared/shared.hh" + +namespace client { +namespace state { + +inline std::string_view address; +inline std::string_view port; +inline std::uint64_t seed; +inline std::size_t player_count; +inline std::size_t requested_chunk_count; +inline std::size_t networked_chunk_count; +inline std::int32_t draw_distance; +inline std::int32_t chunks_per_frame; +inline std::uint32_t tickrate; + +inline shared::tick_t tick; +inline float delta_ticks; // num ticks since the last tick, [0, inf) +shared::time_duration_t get_time_per_tick() noexcept; + +// Speed of the client's move ticks should be 1.0f but if we're too slow (or the +// server lags and we're too fast) this value should move to speed up the client +// somewhat gracefully. +inline float time_factor = 1.0f; + +inline shared::net::connection* connection = nullptr; + +// non-opt after init +inline std::optional<shared::entity::index_t> localplayer_index; +bool has_initialised() noexcept; + +} // namespace state +} // namespace client + +#endif |
