From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/client/state/chunks.cc | 1 + src/client/state/chunks.hh | 18 ++++++++++++++++++ src/client/state/entities.cc | 1 + src/client/state/entities.hh | 21 +++++++++++++++++++++ src/client/state/state.cc | 15 +++++++++++++++ src/client/state/state.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 src/client/state/chunks.cc create mode 100644 src/client/state/chunks.hh create mode 100644 src/client/state/entities.cc create mode 100644 src/client/state/entities.hh create mode 100644 src/client/state/state.cc create mode 100644 src/client/state/state.hh (limited to 'src/client/state') 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 +#include + +#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 +#include + +#include "client/entity/entity.hh" + +namespace client { + +using entities_t = std::unordered_map>; + +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 + +#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 localplayer_index; +bool has_initialised() noexcept; + +} // namespace state +} // namespace client + +#endif -- cgit v1.2.3