From 88c01588aa0830e219eaa62588839e4d1e2883ce Mon Sep 17 00:00:00 2001 From: untodesu Date: Wed, 25 Jun 2025 00:44:36 +0500 Subject: Clang-format the entire source code --- .clang-format | 103 ++++++++++++ core/aabb.cc | 41 +++-- core/aabb.hh | 20 +-- core/angles.hh | 20 +-- core/binfile.cc | 11 +- core/binfile.hh | 2 +- core/buffer.cc | 34 ++-- core/buffer.hh | 102 ++++++------ core/cmdline.cc | 31 ++-- core/cmdline.hh | 8 +- core/config.cc | 60 ++++--- core/config.hh | 40 ++--- core/constexpr.hh | 67 +++++--- core/crc64.cc | 331 +++++++++++++++++++++++++++++++-------- core/crc64.hh | 6 +- core/epoch.cc | 1 + core/floathacks.hh | 21 ++- core/image.cc | 37 +++-- core/image.hh | 2 +- core/macros.hh | 4 +- core/pch.hh | 2 +- core/randomizer.hh | 8 +- core/resource.hh | 2 +- core/strtools.cc | 31 ++-- core/strtools.hh | 8 +- core/vectors.hh | 16 +- game/client/background.cc | 1 + game/client/bother.cc | 19 ++- game/client/bother.hh | 2 +- game/client/camera.cc | 9 +- game/client/chat.cc | 31 ++-- game/client/chat.hh | 2 +- game/client/chunk_mesher.cc | 252 ++++++++++++++++++----------- game/client/chunk_quad.hh | 2 +- game/client/chunk_renderer.cc | 83 +++++----- game/client/chunk_visibility.cc | 25 +-- game/client/crosshair.cc | 3 +- game/client/direct_connection.cc | 22 ++- game/client/experiments.cc | 10 +- game/client/factory.cc | 7 +- game/client/factory.hh | 2 +- game/client/game.cc | 170 ++++++++++---------- game/client/gamepad.cc | 31 ++-- game/client/gamepad_axis.cc | 42 ++--- game/client/gamepad_axis.hh | 10 +- game/client/gamepad_button.cc | 59 ++++--- game/client/gamepad_button.hh | 8 +- game/client/glfw.hh | 4 +- game/client/globals.cc | 23 +-- game/client/globals.hh | 22 +-- game/client/gui_screen.hh | 14 +- game/client/hotbar.cc | 9 +- game/client/imdraw_ext.cc | 3 +- game/client/imdraw_ext.hh | 2 +- game/client/interpolation.cc | 1 + game/client/keybind.cc | 267 ++++++++++++++++--------------- game/client/keybind.hh | 6 +- game/client/language.cc | 25 +-- game/client/language.hh | 8 +- game/client/listener.cc | 5 +- game/client/main.cc | 79 +++++----- game/client/main_menu.cc | 46 ++++-- game/client/message_box.cc | 17 +- game/client/message_box.hh | 8 +- game/client/metrics.cc | 16 +- game/client/outline.cc | 45 ++++-- game/client/outline.hh | 4 +- game/client/play_menu.cc | 151 +++++++++++------- game/client/player_look.cc | 18 +-- game/client/player_move.cc | 70 +++++---- game/client/player_target.cc | 6 +- game/client/player_target.hh | 2 +- game/client/program.cc | 45 +++--- game/client/program.hh | 4 +- game/client/progress_bar.cc | 13 +- game/client/progress_bar.hh | 8 +- game/client/receive.cc | 40 ++--- game/client/scoreboard.cc | 118 +++++++------- game/client/screenshot.cc | 13 +- game/client/session.cc | 33 ++-- game/client/session.hh | 6 +- game/client/settings.cc | 215 +++++++++++++------------ game/client/settings.hh | 56 +++---- game/client/skybox.cc | 1 + game/client/sound.cc | 37 +++-- game/client/sound.hh | 8 +- game/client/sound_effect.cc | 28 ++-- game/client/sound_emitter.cc | 3 +- game/client/splash.cc | 23 +-- game/client/status_lines.cc | 13 +- game/client/status_lines.hh | 6 +- game/client/texture_gui.cc | 48 ++++-- game/client/texture_gui.hh | 12 +- game/client/toggles.cc | 43 ++--- game/client/toggles.hh | 12 +- game/client/voxel_anims.cc | 3 +- game/client/voxel_atlas.cc | 55 ++++--- game/client/voxel_atlas.hh | 4 +- game/client/voxel_sounds.cc | 5 +- game/client/window_title.cc | 7 +- game/server/chat.cc | 17 +- game/server/chat.hh | 8 +- game/server/game.cc | 3 +- game/server/globals.cc | 7 +- game/server/globals.hh | 6 +- game/server/main.cc | 10 +- game/server/overworld.cc | 59 +++---- game/server/overworld.hh | 20 +-- game/server/receive.cc | 22 +-- game/server/sessions.cc | 104 ++++++------ game/server/sessions.hh | 20 +-- game/server/status.cc | 3 +- game/server/universe.cc | 25 +-- game/server/universe.hh | 6 +- game/server/unloader.cc | 15 +- game/server/unloader.hh | 2 +- game/server/whitelist.cc | 16 +- game/server/whitelist.hh | 4 +- game/server/worldgen.cc | 17 +- game/server/worldgen.hh | 4 +- game/shared/chunk.cc | 25 +-- game/shared/chunk.hh | 14 +- game/shared/chunk_aabb.cc | 39 +++-- game/shared/chunk_aabb.hh | 18 +-- game/shared/collision.cc | 115 +++++++------- game/shared/collision.hh | 2 +- game/shared/coord.hh | 44 +++--- game/shared/dimension.cc | 58 ++++--- game/shared/dimension.hh | 46 +++--- game/shared/factory.cc | 11 +- game/shared/factory.hh | 2 +- game/shared/feature.cc | 5 +- game/shared/feature.hh | 4 +- game/shared/game.cc | 13 +- game/shared/game.hh | 2 +- game/shared/game_items.cc | 52 ++---- game/shared/game_voxels.cc | 115 +++++++------- game/shared/globals.cc | 1 + game/shared/gravity.cc | 3 +- game/shared/gravity.hh | 2 +- game/shared/item_registry.cc | 35 +++-- game/shared/item_registry.hh | 12 +- game/shared/protocol.cc | 77 ++++----- game/shared/protocol.hh | 66 ++++---- game/shared/ray_dda.cc | 28 ++-- game/shared/ray_dda.hh | 10 +- game/shared/splash.cc | 18 +-- game/shared/stasis.cc | 9 +- game/shared/stasis.hh | 2 +- game/shared/threading.cc | 20 +-- game/shared/threading.hh | 14 +- game/shared/transform.cc | 5 +- game/shared/transform.hh | 2 +- game/shared/types.hh | 4 +- game/shared/velocity.cc | 3 +- game/shared/velocity.hh | 2 +- game/shared/voxel_registry.cc | 42 +++-- game/shared/voxel_registry.hh | 102 ++++++------ game/shared/voxel_storage.cc | 11 +- game/shared/voxel_storage.hh | 4 +- 160 files changed, 2774 insertions(+), 2139 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b421ab3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,103 @@ +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true + BeforeLambdaBody: false + BeforeWhile: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +ColumnLimit: 180 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: false +DerivePointerAlignment: false +EmptyLineBeforeAccessModifier: LogicalBlock +FixNamespaceComments: true +ShortNamespaceLines: 0 +IndentCaseBlocks: true +IndentCaseLabels: true +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +LineEnding: CRLF +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Before +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++20 +UseCRLF: true +UseTab: Never diff --git a/core/aabb.cc b/core/aabb.cc index 48070fe..3661143 100644 --- a/core/aabb.cc +++ b/core/aabb.cc @@ -1,60 +1,57 @@ #include "core/pch.hh" + #include "core/aabb.hh" -AABB::AABB(const glm::fvec3 &min, const glm::fvec3 &max) +AABB::AABB(const glm::fvec3& min, const glm::fvec3& max) { set_bounds(min, max); } -void AABB::set_bounds(const glm::fvec3 &min, const glm::fvec3 &max) +void AABB::set_bounds(const glm::fvec3& min, const glm::fvec3& max) { this->min = min; this->max = max; } -void AABB::set_offset(const glm::fvec3 &base, const glm::fvec3 &size) +void AABB::set_offset(const glm::fvec3& base, const glm::fvec3& size) { this->min = base; this->max = base + size; } -bool AABB::contains(const glm::fvec3 &point) const +bool AABB::contains(const glm::fvec3& point) const { - if((point.x < min.x) || (point.x > max.x)) - return false; - if((point.y < min.y) || (point.y > max.y)) - return false; - if((point.z < min.z) || (point.z > max.z)) - return false; - return true; + auto result = true; + result = result && (point.x >= min.x) && (point.x <= max.x); + result = result && (point.y >= min.y) && (point.y <= max.y); + result = result && (point.z >= min.z) && (point.z <= max.z); + return result; } -bool AABB::intersect(const AABB &other_box) const +bool AABB::intersect(const AABB& other_box) const { - if((min.x >= other_box.max.x) || (max.x <= other_box.min.x)) - return false; - if((min.y >= other_box.max.y) || (max.y <= other_box.min.y)) - return false; - if((min.z >= other_box.max.z) || (max.z <= other_box.min.z)) - return false; - return true; + auto result = true; + result = result && (min.x < other_box.max.x) && (max.x > other_box.min.x); + result = result && (min.y < other_box.max.y) && (max.y > other_box.min.y); + result = result && (min.z < other_box.max.z) && (max.z > other_box.min.z); + return result; } -AABB AABB::combine_with(const AABB &other_box) const +AABB AABB::combine_with(const AABB& other_box) const { AABB result; result.set_bounds(min, other_box.max); return result; } -AABB AABB::multiply_with(const AABB &other_box) const +AABB AABB::multiply_with(const AABB& other_box) const { AABB result; result.set_bounds(other_box.min, max); return result; } -AABB AABB::push(const glm::fvec3 &vector) const +AABB AABB::push(const glm::fvec3& vector) const { AABB result; result.set_bounds(min + vector, max + vector); diff --git a/core/aabb.hh b/core/aabb.hh index 61193a4..127f90f 100644 --- a/core/aabb.hh +++ b/core/aabb.hh @@ -7,21 +7,21 @@ class AABB final { public: DECLARE_DEFAULT_CTOR(AABB); - explicit AABB(const glm::fvec3 &min, const glm::fvec3 &max); + explicit AABB(const glm::fvec3& min, const glm::fvec3& max); virtual ~AABB(void) = default; - void set_bounds(const glm::fvec3 &min, const glm::fvec3 &max); - void set_offset(const glm::fvec3 &base, const glm::fvec3 &size); + void set_bounds(const glm::fvec3& min, const glm::fvec3& max); + void set_offset(const glm::fvec3& base, const glm::fvec3& size); - const glm::fvec3 &get_min(void) const; - const glm::fvec3 &get_max(void) const; + const glm::fvec3& get_min(void) const; + const glm::fvec3& get_max(void) const; - bool contains(const glm::fvec3 &point) const; - bool intersect(const AABB &other_box) const; + bool contains(const glm::fvec3& point) const; + bool intersect(const AABB& other_box) const; - AABB combine_with(const AABB &other_box) const; - AABB multiply_with(const AABB &other_box) const; - AABB push(const glm::fvec3 &vector) const; + AABB combine_with(const AABB& other_box) const; + AABB multiply_with(const AABB& other_box) const; + AABB push(const glm::fvec3& vector) const; public: glm::fvec3 min; diff --git a/core/angles.hh b/core/angles.hh index 0d8e41d..98dc086 100644 --- a/core/angles.hh +++ b/core/angles.hh @@ -15,22 +15,24 @@ float wrap_360(float angle); namespace cxangles { -glm::fvec3 wrap_180(const glm::fvec3 &angles); -glm::fvec3 wrap_360(const glm::fvec3 &angles); +glm::fvec3 wrap_180(const glm::fvec3& angles); +glm::fvec3 wrap_360(const glm::fvec3& angles); } // namespace cxangles namespace cxangles { -void vectors(const glm::fvec3 &angles, glm::fvec3 &forward); -void vectors(const glm::fvec3 &angles, glm::fvec3 *forward, glm::fvec3 *right, glm::fvec3 *up); +void vectors(const glm::fvec3& angles, glm::fvec3& forward); +void vectors(const glm::fvec3& angles, glm::fvec3* forward, glm::fvec3* right, glm::fvec3* up); } // namespace cxangles inline float cxangles::wrap_180(float angle) { const auto result = std::fmod(angle + A180, A360); - if(result < 0.0f) + if(result < 0.0f) { return result + A180; + } + return result - A180; } @@ -39,7 +41,7 @@ inline float cxangles::wrap_360(float angle) return std::fmod(std::fmod(angle, A360) + A360, A360); } -inline glm::fvec3 cxangles::wrap_180(const glm::fvec3 &angles) +inline glm::fvec3 cxangles::wrap_180(const glm::fvec3& angles) { return glm::fvec3 { cxangles::wrap_180(angles.x), @@ -48,7 +50,7 @@ inline glm::fvec3 cxangles::wrap_180(const glm::fvec3 &angles) }; } -inline glm::fvec3 cxangles::wrap_360(const glm::fvec3 &angles) +inline glm::fvec3 cxangles::wrap_360(const glm::fvec3& angles) { return glm::fvec3 { cxangles::wrap_360(angles.x), @@ -57,7 +59,7 @@ inline glm::fvec3 cxangles::wrap_360(const glm::fvec3 &angles) }; } -inline void cxangles::vectors(const glm::fvec3 &angles, glm::fvec3 &forward) +inline void cxangles::vectors(const glm::fvec3& angles, glm::fvec3& forward) { const float cosp = std::cos(angles.x); const float cosy = std::cos(angles.y); @@ -69,7 +71,7 @@ inline void cxangles::vectors(const glm::fvec3 &angles, glm::fvec3 &forward) forward.z = cosp * cosy * (-1.0f); } -inline void cxangles::vectors(const glm::fvec3 &angles, glm::fvec3 *forward, glm::fvec3 *right, glm::fvec3 *up) +inline void cxangles::vectors(const glm::fvec3& angles, glm::fvec3* forward, glm::fvec3* right, glm::fvec3* up) { if(!forward && !right && !up) { // There's no point in figuring out diff --git a/core/binfile.cc b/core/binfile.cc index 34af3ca..aa39039 100644 --- a/core/binfile.cc +++ b/core/binfile.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/binfile.hh" #include "core/resource.hh" @@ -6,7 +7,7 @@ static emhash8::HashMap> resource_map; template<> -resource_ptr resource::load(const char *name, unsigned int flags) +resource_ptr resource::load(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -35,10 +36,12 @@ resource_ptr resource::load(const char *name, unsigned int fla template<> void resource::hard_cleanup(void) { - for(const auto &it : resource_map) { - if(it.second.use_count() > 1L) + for(const auto& it : resource_map) { + if(it.second.use_count() > 1L) { spdlog::warn("resource: zombie resource [BinFile] {} [use_count={}]", it.first, it.second.use_count()); - else spdlog::debug("resource: releasing [BinFile] {}", it.first); + } else { + spdlog::debug("resource: releasing [BinFile] {}", it.first); + } delete[] it.second->buffer; } diff --git a/core/binfile.hh b/core/binfile.hh index 1e2e6c3..21dab40 100644 --- a/core/binfile.hh +++ b/core/binfile.hh @@ -3,7 +3,7 @@ #pragma once struct BinFile final { - std::byte *buffer; + std::byte* buffer; std::size_t size; }; diff --git a/core/buffer.cc b/core/buffer.cc index 2d37c84..c6b67f9 100644 --- a/core/buffer.cc +++ b/core/buffer.cc @@ -1,19 +1,20 @@ #include "core/pch.hh" + #include "core/buffer.hh" #include "core/constexpr.hh" -ReadBuffer::ReadBuffer(const void *data, std::size_t size) +ReadBuffer::ReadBuffer(const void* data, std::size_t size) { reset(data, size); } -ReadBuffer::ReadBuffer(const ENetPacket *packet) +ReadBuffer::ReadBuffer(const ENetPacket* packet) { reset(packet); } -ReadBuffer::ReadBuffer(PHYSFS_File *file) +ReadBuffer::ReadBuffer(PHYSFS_File* file) { reset(file); } @@ -23,26 +24,26 @@ std::size_t ReadBuffer::size(void) const return m_vector.size(); } -const std::byte *ReadBuffer::data(void) const +const std::byte* ReadBuffer::data(void) const { return m_vector.data(); } -void ReadBuffer::reset(const void *data, std::size_t size) +void ReadBuffer::reset(const void* data, std::size_t size) { - auto bytes = reinterpret_cast(data); + auto bytes = reinterpret_cast(data); m_vector.assign(bytes, bytes + size); m_position = 0U; } -void ReadBuffer::reset(const ENetPacket *packet) +void ReadBuffer::reset(const ENetPacket* packet) { - auto bytes_ptr = reinterpret_cast(packet->data); + auto bytes_ptr = reinterpret_cast(packet->data); m_vector.assign(bytes_ptr, bytes_ptr + packet->dataLength); m_position = 0; } -void ReadBuffer::reset(PHYSFS_File *file) +void ReadBuffer::reset(PHYSFS_File* file) { m_vector.resize(PHYSFS_fileLength(file)); m_position = 0; @@ -124,8 +125,10 @@ std::string ReadBuffer::read_string(void) auto result = std::string(); for(std::size_t i = 0; i < size; ++i) { - if(m_position < m_vector.size()) + if(m_position < m_vector.size()) { result.push_back(static_cast(m_vector[m_position])); + } + m_position += 1U; } @@ -137,7 +140,7 @@ std::size_t WriteBuffer::size(void) const return m_vector.size(); } -const std::byte *WriteBuffer::data(void) const +const std::byte* WriteBuffer::data(void) const { return m_vector.data(); } @@ -178,16 +181,17 @@ void WriteBuffer::write_UI64(std::uint64_t value) m_vector.push_back(static_cast(UINT64_C(0xFF) & ((value & UINT64_C(0x00000000000000FF)) >> 0U))); } -void WriteBuffer::write_string(const std::string &value) +void WriteBuffer::write_string(const std::string& value) { const std::size_t size = cxpr::min(UINT16_MAX, value.size()); write_UI16(static_cast(size)); - for(std::size_t i = 0; i < size; m_vector.push_back(static_cast(value[i++]))); + for(std::size_t i = 0; i < size; m_vector.push_back(static_cast(value[i++]))) + ; } -PHYSFS_File *WriteBuffer::to_file(const char *path, bool append) const +PHYSFS_File* WriteBuffer::to_file(const char* path, bool append) const { if(auto file = (append ? PHYSFS_openAppend(path) : PHYSFS_openWrite(path))) { PHYSFS_writeBytes(file, m_vector.data(), m_vector.size()); @@ -197,7 +201,7 @@ PHYSFS_File *WriteBuffer::to_file(const char *path, bool append) const return nullptr; } -ENetPacket *WriteBuffer::to_packet(enet_uint32 flags) const +ENetPacket* WriteBuffer::to_packet(enet_uint32 flags) const { return enet_packet_create(m_vector.data(), m_vector.size(), flags); } diff --git a/core/buffer.hh b/core/buffer.hh index 5eb96e5..b63d0f5 100644 --- a/core/buffer.hh +++ b/core/buffer.hh @@ -6,17 +6,17 @@ class ReadBuffer final { public: explicit ReadBuffer(void) = default; - explicit ReadBuffer(const void *data, std::size_t size); - explicit ReadBuffer(const ENetPacket *packet); - explicit ReadBuffer(PHYSFS_File *file); + explicit ReadBuffer(const void* data, std::size_t size); + explicit ReadBuffer(const ENetPacket* packet); + explicit ReadBuffer(PHYSFS_File* file); virtual ~ReadBuffer(void) = default; std::size_t size(void) const; - const std::byte *data(void) const; + const std::byte* data(void) const; - void reset(const void *data, std::size_t size); - void reset(const ENetPacket *packet); - void reset(PHYSFS_File *file); + void reset(const void* data, std::size_t size); + void reset(const ENetPacket* packet); + void reset(PHYSFS_File* file); float read_FP32(void); std::uint8_t read_UI8(void); @@ -30,16 +30,16 @@ public: inline std::int32_t read_I32(void); inline std::int64_t read_I64(void); - inline ReadBuffer &operator>>(float &value); - inline ReadBuffer &operator>>(std::int8_t &value); - inline ReadBuffer &operator>>(std::int16_t &value); - inline ReadBuffer &operator>>(std::int32_t &value); - inline ReadBuffer &operator>>(std::int64_t &value); - inline ReadBuffer &operator>>(std::uint8_t &value); - inline ReadBuffer &operator>>(std::uint16_t &value); - inline ReadBuffer &operator>>(std::uint32_t &value); - inline ReadBuffer &operator>>(std::uint64_t &value); - inline ReadBuffer &operator>>(std::string &value); + inline ReadBuffer& operator>>(float& value); + inline ReadBuffer& operator>>(std::int8_t& value); + inline ReadBuffer& operator>>(std::int16_t& value); + inline ReadBuffer& operator>>(std::int32_t& value); + inline ReadBuffer& operator>>(std::int64_t& value); + inline ReadBuffer& operator>>(std::uint8_t& value); + inline ReadBuffer& operator>>(std::uint16_t& value); + inline ReadBuffer& operator>>(std::uint32_t& value); + inline ReadBuffer& operator>>(std::uint64_t& value); + inline ReadBuffer& operator>>(std::string& value); private: std::vector m_vector; @@ -52,7 +52,7 @@ public: virtual ~WriteBuffer(void) = default; std::size_t size(void) const; - const std::byte *data(void) const; + const std::byte* data(void) const; void reset(void); @@ -61,26 +61,26 @@ public: void write_UI16(std::uint16_t value); void write_UI32(std::uint32_t value); void write_UI64(std::uint64_t value); - void write_string(const std::string &value); + void write_string(const std::string& value); inline void write_I8(std::int8_t value); inline void write_I16(std::int16_t value); inline void write_I32(std::int32_t value); inline void write_I64(std::int64_t value); - inline WriteBuffer &operator<<(float value); - inline WriteBuffer &operator<<(std::int8_t value); - inline WriteBuffer &operator<<(std::int16_t value); - inline WriteBuffer &operator<<(std::int32_t value); - inline WriteBuffer &operator<<(std::int64_t value); - inline WriteBuffer &operator<<(std::uint8_t value); - inline WriteBuffer &operator<<(std::uint16_t value); - inline WriteBuffer &operator<<(std::uint32_t value); - inline WriteBuffer &operator<<(std::uint64_t value); - inline WriteBuffer &operator<<(const std::string &value); + inline WriteBuffer& operator<<(float value); + inline WriteBuffer& operator<<(std::int8_t value); + inline WriteBuffer& operator<<(std::int16_t value); + inline WriteBuffer& operator<<(std::int32_t value); + inline WriteBuffer& operator<<(std::int64_t value); + inline WriteBuffer& operator<<(std::uint8_t value); + inline WriteBuffer& operator<<(std::uint16_t value); + inline WriteBuffer& operator<<(std::uint32_t value); + inline WriteBuffer& operator<<(std::uint64_t value); + inline WriteBuffer& operator<<(const std::string& value); - PHYSFS_File *to_file(const char *path, bool append = false) const; - ENetPacket *to_packet(enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE) const; + PHYSFS_File* to_file(const char* path, bool append = false) const; + ENetPacket* to_packet(enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE) const; private: std::vector m_vector; @@ -106,61 +106,61 @@ inline std::int64_t ReadBuffer::read_I64(void) return static_cast(read_UI64()); } -inline ReadBuffer &ReadBuffer::operator>>(float &value) +inline ReadBuffer& ReadBuffer::operator>>(float& value) { value = read_FP32(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::int8_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::int8_t& value) { value = read_I8(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::int16_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::int16_t& value) { value = read_I16(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::int32_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::int32_t& value) { value = read_I32(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::int64_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::int64_t& value) { value = read_I64(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::uint8_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::uint8_t& value) { value = read_UI8(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::uint16_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::uint16_t& value) { value = read_UI16(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::uint32_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::uint32_t& value) { value = read_UI32(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::uint64_t &value) +inline ReadBuffer& ReadBuffer::operator>>(std::uint64_t& value) { value = read_UI64(); return *this; } -inline ReadBuffer &ReadBuffer::operator>>(std::string &value) +inline ReadBuffer& ReadBuffer::operator>>(std::string& value) { value = read_string(); return *this; @@ -191,61 +191,61 @@ inline void WriteBuffer::write_I64(std::int64_t value) write_UI64(static_cast(value)); } -inline WriteBuffer &WriteBuffer::operator<<(float value) +inline WriteBuffer& WriteBuffer::operator<<(float value) { write_FP32(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::int8_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::int8_t value) { write_I8(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::int16_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::int16_t value) { write_I16(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::int32_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::int32_t value) { write_I32(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::int64_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::int64_t value) { write_I64(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::uint8_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::uint8_t value) { write_UI8(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::uint16_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::uint16_t value) { write_UI16(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::uint32_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::uint32_t value) { write_UI32(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(std::uint64_t value) +inline WriteBuffer& WriteBuffer::operator<<(std::uint64_t value) { write_UI64(value); return *this; } -inline WriteBuffer &WriteBuffer::operator<<(const std::string &value) +inline WriteBuffer& WriteBuffer::operator<<(const std::string& value) { write_string(value); return *this; diff --git a/core/cmdline.cc b/core/cmdline.cc index 4cc7de0..c83f9e6 100644 --- a/core/cmdline.cc +++ b/core/cmdline.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/cmdline.hh" // Valid options always start with OPTION_PREFIX, can contain @@ -7,21 +8,24 @@ constexpr static char OPTION_PREFIX = '-'; static std::unordered_map options; -static inline bool is_option_string(const std::string &string) +static inline bool is_option_string(const std::string& string) { - if(string.find_last_of(OPTION_PREFIX) >= (string.size() - 1)) + if(string.find_last_of(OPTION_PREFIX) >= (string.size() - 1)) { return false; + } + return string[0] == OPTION_PREFIX; } -static inline std::string get_option(const std::string &string) +static inline std::string get_option(const std::string& string) { std::size_t i; - for(i = 0; string[i] == OPTION_PREFIX; ++i); + for(i = 0; string[i] == OPTION_PREFIX; ++i) + ; return std::string(string.cbegin() + i, string.cend()); } -void cmdline::create(int argc, char **argv) +void cmdline::create(int argc, char** argv) { for(int idx = 1; idx < argc; ++idx) { std::string string = argv[idx]; @@ -51,22 +55,27 @@ void cmdline::create(int argc, char **argv) } } -void cmdline::insert(const char *option, const char *argument) +void cmdline::insert(const char* option, const char* argument) { - if(argument == nullptr) + if(argument == nullptr) { options.insert_or_assign(option, std::string()); - else options.insert_or_assign(option, argument); + } else { + options.insert_or_assign(option, argument); + } } -const char *cmdline::get(const char *option, const char *fallback) +const char* cmdline::get(const char* option, const char* fallback) { auto it = options.find(option); - if(it == options.cend()) + + if(it == options.cend()) { return fallback; + } + return it->second.c_str(); } -bool cmdline::contains(const char *option) +bool cmdline::contains(const char* option) { return options.count(option); } diff --git a/core/cmdline.hh b/core/cmdline.hh index 8ccfaec..8441a44 100644 --- a/core/cmdline.hh +++ b/core/cmdline.hh @@ -4,10 +4,10 @@ namespace cmdline { -void create(int argc, char **argv); -void insert(const char *option, const char *argument = nullptr); -const char *get(const char *option, const char *fallback = nullptr); -bool contains(const char *option); +void create(int argc, char** argv); +void insert(const char* option, const char* argument = nullptr); +const char* get(const char* option, const char* fallback = nullptr); +bool contains(const char* option); } // namespace cmdline #endif /* CORE_CMDLINE_HH */ diff --git a/core/config.cc b/core/config.cc index 94a8c1b..52cd102 100644 --- a/core/config.cc +++ b/core/config.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/config.hh" #include "core/cmdline.hh" @@ -11,13 +12,13 @@ ConfigBoolean::ConfigBoolean(bool default_value) m_string = ConfigBoolean::to_string(default_value); } -void ConfigBoolean::set(const char *value) +void ConfigBoolean::set(const char* value) { m_value = ConfigBoolean::from_string(value); m_string = ConfigBoolean::to_string(m_value); } -const char *ConfigBoolean::get(void) const +const char* ConfigBoolean::get(void) const { return m_string.c_str(); } @@ -33,31 +34,35 @@ void ConfigBoolean::set_value(bool value) m_string = ConfigBoolean::to_string(m_value); } -const char *ConfigBoolean::to_string(bool value) +const char* ConfigBoolean::to_string(bool value) { - if(value) + if(value) { return "true"; - return "false"; + } else { + return "false"; + } } -bool ConfigBoolean::from_string(const char *value) +bool ConfigBoolean::from_string(const char* value) { - if(std::strcmp(value, "false") && !std::strcmp(value, "true")) + if(std::strcmp(value, "false") && !std::strcmp(value, "true")) { return true; - return false; + } else { + return false; + } } -ConfigString::ConfigString(const char *default_value) +ConfigString::ConfigString(const char* default_value) { m_value = default_value; } -void ConfigString::set(const char *value) +void ConfigString::set(const char* value) { m_value = value; } -const char *ConfigString::get(void) const +const char* ConfigString::get(void) const { return m_value.c_str(); } @@ -71,7 +76,7 @@ void Config::load_cmdline(void) } } -bool Config::load_file(const char *path) +bool Config::load_file(const char* path) { if(auto file = PHYSFS_openRead(path)) { auto source = std::string(PHYSFS_fileLength(file), char(0x00)); @@ -85,9 +90,11 @@ bool Config::load_file(const char *path) while(std::getline(stream, line)) { auto comment = line.find_first_of('#'); - if(comment == std::string::npos) + if(comment == std::string::npos) { kv_string = strtools::trim_whitespace(line); - else kv_string = strtools::trim_whitespace(line.substr(0, comment)); + } else { + kv_string = strtools::trim_whitespace(line.substr(0, comment)); + } if(strtools::is_whitespace(kv_string)) { // Ignore empty or commented out lines @@ -120,7 +127,7 @@ bool Config::load_file(const char *path) return false; } -bool Config::save_file(const char *path) const +bool Config::save_file(const char* path) const { std::ostringstream stream; @@ -129,7 +136,7 @@ bool Config::save_file(const char *path) const stream << "# Voxelius " << PROJECT_VERSION_STRING << " configuration file" << std::endl; stream << "# Generated at: " << std::put_time(std::gmtime(&curtime), "%Y-%m-%d %H:%M:%S %z") << std::endl << std::endl; - for(const auto &it : m_values) { + for(const auto& it : m_values) { stream << it.first << "="; stream << it.second->get(); stream << std::endl; @@ -145,7 +152,7 @@ bool Config::save_file(const char *path) const return false; } -bool Config::set_value(const char *name, const char *value) +bool Config::set_value(const char* name, const char* value) { auto kv_pair = m_values.find(name); @@ -157,23 +164,28 @@ bool Config::set_value(const char *name, const char *value) return false; } -const char *Config::get_value(const char *name) const +const char* Config::get_value(const char* name) const { auto kv_pair = m_values.find(name); - if(kv_pair != m_values.cend()) + if(kv_pair != m_values.cend()) { return kv_pair->second->get(); - return nullptr; + } else { + return nullptr; + } } -void Config::add_value(const char *name, IConfigValue &vref) +void Config::add_value(const char* name, IConfigValue& vref) { m_values.insert_or_assign(name, &vref); } -const IConfigValue *Config::find(const char *name) const +const IConfigValue* Config::find(const char* name) const { auto kv_pair = m_values.find(name); - if(kv_pair != m_values.cend()) + + if(kv_pair != m_values.cend()) { return kv_pair->second; - return nullptr; + } else { + return nullptr; + } } diff --git a/core/config.hh b/core/config.hh index ac9f08c..3df0870 100644 --- a/core/config.hh +++ b/core/config.hh @@ -5,8 +5,8 @@ class IConfigValue { public: virtual ~IConfigValue(void) = default; - virtual void set(const char *value) = 0; - virtual const char *get(void) const = 0; + virtual void set(const char* value) = 0; + virtual const char* get(void) const = 0; }; class ConfigBoolean final : public IConfigValue { @@ -14,8 +14,8 @@ public: explicit ConfigBoolean(bool default_value = false); virtual ~ConfigBoolean(void) = default; - virtual void set(const char *value) override; - virtual const char *get(void) const override; + virtual void set(const char* value) override; + virtual const char* get(void) const override; bool get_value(void) const; void set_value(bool value); @@ -25,8 +25,8 @@ private: std::string m_string; public: - static const char *to_string(bool value); - static bool from_string(const char *value); + static const char* to_string(bool value); + static bool from_string(const char* value); }; template @@ -38,8 +38,8 @@ public: explicit ConfigNumber(T default_value, T min_value, T max_value); virtual ~ConfigNumber(void) = default; - virtual void set(const char *value) override; - virtual const char *get(void) const override; + virtual void set(const char* value) override; + virtual const char* get(void) const override; T get_value(void) const; void set_value(T value); @@ -82,11 +82,11 @@ public: class ConfigString final : public IConfigValue { public: - explicit ConfigString(const char *default_value); + explicit ConfigString(const char* default_value); virtual ~ConfigString(void) = default; - virtual void set(const char *value) override; - virtual const char *get(void) const override; + virtual void set(const char* value) override; + virtual const char* get(void) const override; private: std::string m_value; @@ -98,18 +98,18 @@ public: virtual ~Config(void) = default; void load_cmdline(void); - bool load_file(const char *path); - bool save_file(const char *path) const; + bool load_file(const char* path); + bool save_file(const char* path) const; - bool set_value(const char *name, const char *value); - const char *get_value(const char *name) const; + bool set_value(const char* name, const char* value); + const char* get_value(const char* name) const; - void add_value(const char *name, IConfigValue &vref); + void add_value(const char* name, IConfigValue& vref); - const IConfigValue *find(const char *name) const; + const IConfigValue* find(const char* name) const; private: - std::unordered_map m_values; + std::unordered_map m_values; }; template @@ -131,7 +131,7 @@ inline ConfigNumber::ConfigNumber(T default_value, T min_value, T max_value) } template -inline void ConfigNumber::set(const char *value) +inline void ConfigNumber::set(const char* value) { std::istringstream(value) >> m_value; m_value = std::clamp(m_value, m_min_value, m_max_value); @@ -139,7 +139,7 @@ inline void ConfigNumber::set(const char *value) } template -inline const char *ConfigNumber::get(void) const +inline const char* ConfigNumber::get(void) const { return m_string.c_str(); } diff --git a/core/constexpr.hh b/core/constexpr.hh index 559f8d1..ce64060 100644 --- a/core/constexpr.hh +++ b/core/constexpr.hh @@ -7,7 +7,7 @@ namespace cxpr template constexpr static inline const T abs(const T x); template -constexpr static inline const std::size_t array_size(const T(&)[L]); +constexpr static inline const std::size_t array_size(const T (&)[L]); template constexpr static inline const T ceil(const F x); template @@ -41,13 +41,15 @@ constexpr static inline const T smoothstep(const T x, const T y, const F a); template constexpr static inline const T cxpr::abs(const T x) { - if(x < static_cast(0)) + if(x < static_cast(0)) { return -x; - return x; + } else { + return x; + } } template -constexpr static inline const std::size_t cxpr::array_size(const T(&)[L]) +constexpr static inline const std::size_t cxpr::array_size(const T (&)[L]) { return L; } @@ -59,9 +61,12 @@ constexpr static inline const T cxpr::ceil(const F x) static_assert(std::is_floating_point_v); const T ival = static_cast(x); - if(ival < x) + + if(ival < x) { return ival + static_cast(1); - return ival; + } else { + return ival; + } } template @@ -77,19 +82,24 @@ constexpr static inline const T cxpr::floor(const F x) static_assert(std::is_floating_point_v); const T ival = static_cast(x); - if(ival > x) + + if(ival > x) { return ival - static_cast(1); - return ival; + } else { + return ival; + } } template constexpr static inline const T cxpr::clamp(const T x, const T min, const T max) { - if(x < min) + if(x < min) { return min; - if(x > max) + } else if(x > max) { return max; - return x; + } else { + return x; + } } template @@ -103,25 +113,31 @@ constexpr static inline const T cxpr::lerp(const T x, const T y, const F a) template constexpr static inline const T cxpr::log2(const T x) { - if(x < 2) + if(x < 2) { return 0; - return cxpr::log2((x + 1) >> 1) + 1; + } else { + return cxpr::log2((x + 1) >> 1) + 1; + } } template constexpr static inline const T cxpr::max(const T x, const T y) { - if(x < y) + if(x < y) { return y; - return x; + } else { + return x; + } } template constexpr static inline const T cxpr::min(const T x, const T y) { - if(x > y) + if(x > y) { return y; - return x; + } else { + return x; + } } template @@ -129,10 +145,13 @@ constexpr static inline const T cxpr::mod_signed(const T x, const T m) { static_assert(std::is_signed_v); static_assert(std::is_integral_v); - const T result = static_cast(x % m); - if(result < T(0)) + auto result = static_cast(x % m); + + if(result < T(0)) { return result + m; - return result; + } else { + return result; + } } template @@ -159,11 +178,13 @@ constexpr static inline const bool cxpr::range(const T x, const T min, const T m template constexpr static inline const T cxpr::sign(const F x) { - if(x < F(0)) + if(x < F(0)) { return T(-1); - if(x > F(0)) + } else if(x > F(0)) { return T(+1); - return T(0); + } else { + return T(0); + } } template diff --git a/core/crc64.cc b/core/crc64.cc index dee88f3..c2ca53c 100644 --- a/core/crc64.cc +++ b/core/crc64.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/crc64.hh" // The lookup table for CRC64 checksum; this lookup @@ -7,87 +8,279 @@ // - Initial value: `0x0000000000000000` // - Final xor: `0x0000000000000000` // CRC Calculator: https://www.sunshine2k.de/coding/javascript/crc/crc_js.html -static const std::uint64_t crc_table[256] = { - 0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, - 0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, - 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, - 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4, - 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, - 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, - 0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, - 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, - 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B, - 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4, - 0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, - 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, - 0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, - 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B, - 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, - 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, - 0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, - 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645, - 0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, - 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB, - 0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, - 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, - 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, - 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14, - 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, - 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, - 0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, - 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425, - 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, - 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874, - 0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, - 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, - 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, - 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7, - 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, - 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, - 0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, - 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648, - 0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, - 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6, - 0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, - 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, - 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, - 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7, - 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, - 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, - 0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, - 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428, - 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, - 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288, - 0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, - 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, - 0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, - 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767, - 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, - 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, - 0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, - 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, - 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, - 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8, - 0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, - 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9, - 0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, - 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507, +constexpr static const std::uint64_t crc_table[256] = { + 0x0000000000000000, + 0x42F0E1EBA9EA3693, + 0x85E1C3D753D46D26, + 0xC711223CFA3E5BB5, + 0x493366450E42ECDF, + 0x0BC387AEA7A8DA4C, + 0xCCD2A5925D9681F9, + 0x8E224479F47CB76A, + 0x9266CC8A1C85D9BE, + 0xD0962D61B56FEF2D, + 0x17870F5D4F51B498, + 0x5577EEB6E6BB820B, + 0xDB55AACF12C73561, + 0x99A54B24BB2D03F2, + 0x5EB4691841135847, + 0x1C4488F3E8F96ED4, + 0x663D78FF90E185EF, + 0x24CD9914390BB37C, + 0xE3DCBB28C335E8C9, + 0xA12C5AC36ADFDE5A, + 0x2F0E1EBA9EA36930, + 0x6DFEFF5137495FA3, + 0xAAEFDD6DCD770416, + 0xE81F3C86649D3285, + 0xF45BB4758C645C51, + 0xB6AB559E258E6AC2, + 0x71BA77A2DFB03177, + 0x334A9649765A07E4, + 0xBD68D2308226B08E, + 0xFF9833DB2BCC861D, + 0x388911E7D1F2DDA8, + 0x7A79F00C7818EB3B, + 0xCC7AF1FF21C30BDE, + 0x8E8A101488293D4D, + 0x499B3228721766F8, + 0x0B6BD3C3DBFD506B, + 0x854997BA2F81E701, + 0xC7B97651866BD192, + 0x00A8546D7C558A27, + 0x4258B586D5BFBCB4, + 0x5E1C3D753D46D260, + 0x1CECDC9E94ACE4F3, + 0xDBFDFEA26E92BF46, + 0x990D1F49C77889D5, + 0x172F5B3033043EBF, + 0x55DFBADB9AEE082C, + 0x92CE98E760D05399, + 0xD03E790CC93A650A, + 0xAA478900B1228E31, + 0xE8B768EB18C8B8A2, + 0x2FA64AD7E2F6E317, + 0x6D56AB3C4B1CD584, + 0xE374EF45BF6062EE, + 0xA1840EAE168A547D, + 0x66952C92ECB40FC8, + 0x2465CD79455E395B, + 0x3821458AADA7578F, + 0x7AD1A461044D611C, + 0xBDC0865DFE733AA9, + 0xFF3067B657990C3A, + 0x711223CFA3E5BB50, + 0x33E2C2240A0F8DC3, + 0xF4F3E018F031D676, + 0xB60301F359DBE0E5, + 0xDA050215EA6C212F, + 0x98F5E3FE438617BC, + 0x5FE4C1C2B9B84C09, + 0x1D14202910527A9A, + 0x93366450E42ECDF0, + 0xD1C685BB4DC4FB63, + 0x16D7A787B7FAA0D6, + 0x5427466C1E109645, + 0x4863CE9FF6E9F891, + 0x0A932F745F03CE02, + 0xCD820D48A53D95B7, + 0x8F72ECA30CD7A324, + 0x0150A8DAF8AB144E, + 0x43A04931514122DD, + 0x84B16B0DAB7F7968, + 0xC6418AE602954FFB, + 0xBC387AEA7A8DA4C0, + 0xFEC89B01D3679253, + 0x39D9B93D2959C9E6, + 0x7B2958D680B3FF75, + 0xF50B1CAF74CF481F, + 0xB7FBFD44DD257E8C, + 0x70EADF78271B2539, + 0x321A3E938EF113AA, + 0x2E5EB66066087D7E, + 0x6CAE578BCFE24BED, + 0xABBF75B735DC1058, + 0xE94F945C9C3626CB, + 0x676DD025684A91A1, + 0x259D31CEC1A0A732, + 0xE28C13F23B9EFC87, + 0xA07CF2199274CA14, + 0x167FF3EACBAF2AF1, + 0x548F120162451C62, + 0x939E303D987B47D7, + 0xD16ED1D631917144, + 0x5F4C95AFC5EDC62E, + 0x1DBC74446C07F0BD, + 0xDAAD56789639AB08, + 0x985DB7933FD39D9B, + 0x84193F60D72AF34F, + 0xC6E9DE8B7EC0C5DC, + 0x01F8FCB784FE9E69, + 0x43081D5C2D14A8FA, + 0xCD2A5925D9681F90, + 0x8FDAB8CE70822903, + 0x48CB9AF28ABC72B6, + 0x0A3B7B1923564425, + 0x70428B155B4EAF1E, + 0x32B26AFEF2A4998D, + 0xF5A348C2089AC238, + 0xB753A929A170F4AB, + 0x3971ED50550C43C1, + 0x7B810CBBFCE67552, + 0xBC902E8706D82EE7, + 0xFE60CF6CAF321874, + 0xE224479F47CB76A0, + 0xA0D4A674EE214033, + 0x67C58448141F1B86, + 0x253565A3BDF52D15, + 0xAB1721DA49899A7F, + 0xE9E7C031E063ACEC, + 0x2EF6E20D1A5DF759, + 0x6C0603E6B3B7C1CA, + 0xF6FAE5C07D3274CD, + 0xB40A042BD4D8425E, + 0x731B26172EE619EB, + 0x31EBC7FC870C2F78, + 0xBFC9838573709812, + 0xFD39626EDA9AAE81, + 0x3A28405220A4F534, + 0x78D8A1B9894EC3A7, + 0x649C294A61B7AD73, + 0x266CC8A1C85D9BE0, + 0xE17DEA9D3263C055, + 0xA38D0B769B89F6C6, + 0x2DAF4F0F6FF541AC, + 0x6F5FAEE4C61F773F, + 0xA84E8CD83C212C8A, + 0xEABE6D3395CB1A19, + 0x90C79D3FEDD3F122, + 0xD2377CD44439C7B1, + 0x15265EE8BE079C04, + 0x57D6BF0317EDAA97, + 0xD9F4FB7AE3911DFD, + 0x9B041A914A7B2B6E, + 0x5C1538ADB04570DB, + 0x1EE5D94619AF4648, + 0x02A151B5F156289C, + 0x4051B05E58BC1E0F, + 0x87409262A28245BA, + 0xC5B073890B687329, + 0x4B9237F0FF14C443, + 0x0962D61B56FEF2D0, + 0xCE73F427ACC0A965, + 0x8C8315CC052A9FF6, + 0x3A80143F5CF17F13, + 0x7870F5D4F51B4980, + 0xBF61D7E80F251235, + 0xFD913603A6CF24A6, + 0x73B3727A52B393CC, + 0x31439391FB59A55F, + 0xF652B1AD0167FEEA, + 0xB4A25046A88DC879, + 0xA8E6D8B54074A6AD, + 0xEA16395EE99E903E, + 0x2D071B6213A0CB8B, + 0x6FF7FA89BA4AFD18, + 0xE1D5BEF04E364A72, + 0xA3255F1BE7DC7CE1, + 0x64347D271DE22754, + 0x26C49CCCB40811C7, + 0x5CBD6CC0CC10FAFC, + 0x1E4D8D2B65FACC6F, + 0xD95CAF179FC497DA, + 0x9BAC4EFC362EA149, + 0x158E0A85C2521623, + 0x577EEB6E6BB820B0, + 0x906FC95291867B05, + 0xD29F28B9386C4D96, + 0xCEDBA04AD0952342, + 0x8C2B41A1797F15D1, + 0x4B3A639D83414E64, + 0x09CA82762AAB78F7, + 0x87E8C60FDED7CF9D, + 0xC51827E4773DF90E, + 0x020905D88D03A2BB, + 0x40F9E43324E99428, + 0x2CFFE7D5975E55E2, + 0x6E0F063E3EB46371, + 0xA91E2402C48A38C4, + 0xEBEEC5E96D600E57, + 0x65CC8190991CB93D, + 0x273C607B30F68FAE, + 0xE02D4247CAC8D41B, + 0xA2DDA3AC6322E288, + 0xBE992B5F8BDB8C5C, + 0xFC69CAB42231BACF, + 0x3B78E888D80FE17A, + 0x7988096371E5D7E9, + 0xF7AA4D1A85996083, + 0xB55AACF12C735610, + 0x724B8ECDD64D0DA5, + 0x30BB6F267FA73B36, + 0x4AC29F2A07BFD00D, + 0x08327EC1AE55E69E, + 0xCF235CFD546BBD2B, + 0x8DD3BD16FD818BB8, + 0x03F1F96F09FD3CD2, + 0x41011884A0170A41, + 0x86103AB85A2951F4, + 0xC4E0DB53F3C36767, + 0xD8A453A01B3A09B3, + 0x9A54B24BB2D03F20, + 0x5D45907748EE6495, + 0x1FB5719CE1045206, + 0x919735E51578E56C, + 0xD367D40EBC92D3FF, + 0x1476F63246AC884A, + 0x568617D9EF46BED9, + 0xE085162AB69D5E3C, + 0xA275F7C11F7768AF, + 0x6564D5FDE549331A, + 0x279434164CA30589, + 0xA9B6706FB8DFB2E3, + 0xEB46918411358470, + 0x2C57B3B8EB0BDFC5, + 0x6EA7525342E1E956, + 0x72E3DAA0AA188782, + 0x30133B4B03F2B111, + 0xF7021977F9CCEAA4, + 0xB5F2F89C5026DC37, + 0x3BD0BCE5A45A6B5D, + 0x79205D0E0DB05DCE, + 0xBE317F32F78E067B, + 0xFCC19ED95E6430E8, + 0x86B86ED5267CDBD3, + 0xC4488F3E8F96ED40, + 0x0359AD0275A8B6F5, + 0x41A94CE9DC428066, + 0xCF8B0890283E370C, + 0x8D7BE97B81D4019F, + 0x4A6ACB477BEA5A2A, + 0x089A2AACD2006CB9, + 0x14DEA25F3AF9026D, + 0x562E43B4931334FE, + 0x913F6188692D6F4B, + 0xD3CF8063C0C759D8, + 0x5DEDC41A34BBEEB2, + 0x1F1D25F19D51D821, + 0xD80C07CD676F8394, + 0x9AFCE626CE85B507, }; -std::uint64_t crc64::get(const void *buffer, std::size_t size, std::uint64_t combine) +std::uint64_t crc64::get(const void* buffer, std::size_t size, std::uint64_t combine) { - auto data = reinterpret_cast(buffer); + auto data = reinterpret_cast(buffer); for(std::size_t i = 0; i < size; ++i) combine = crc_table[((combine >> 56) ^ data[i]) & 0xFF] ^ (combine << 8); return combine; } -std::uint64_t crc64::get(const std::vector &buffer, std::uint64_t combine) +std::uint64_t crc64::get(const std::vector& buffer, std::uint64_t combine) { return crc64::get(buffer.data(), buffer.size(), combine); } -std::uint64_t crc64::get(const std::string &buffer, std::uint64_t combine) +std::uint64_t crc64::get(const std::string& buffer, std::uint64_t combine) { return crc64::get(buffer.data(), buffer.size(), combine); } diff --git a/core/crc64.hh b/core/crc64.hh index 5528bc5..da4ad2c 100644 --- a/core/crc64.hh +++ b/core/crc64.hh @@ -4,9 +4,9 @@ namespace crc64 { -std::uint64_t get(const void *buffer, std::size_t size, std::uint64_t combine = UINT64_C(0)); -std::uint64_t get(const std::vector &buffer, std::uint64_t combine = UINT64_C(0)); -std::uint64_t get(const std::string &buffer, std::uint64_t combine = UINT64_C(0)); +std::uint64_t get(const void* buffer, std::size_t size, std::uint64_t combine = UINT64_C(0)); +std::uint64_t get(const std::vector& buffer, std::uint64_t combine = UINT64_C(0)); +std::uint64_t get(const std::string& buffer, std::uint64_t combine = UINT64_C(0)); } // namespace crc64 #endif /* CORE_CRC64_HH */ diff --git a/core/epoch.cc b/core/epoch.cc index 398b7fd..978eeb3 100644 --- a/core/epoch.cc +++ b/core/epoch.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/epoch.hh" std::uint64_t epoch::seconds(void) diff --git a/core/floathacks.hh b/core/floathacks.hh index 2c6a3e1..0796b10 100644 --- a/core/floathacks.hh +++ b/core/floathacks.hh @@ -14,17 +14,22 @@ static inline float floathacks::int32_to_float(const std::int32_t value) { static_assert(std::numeric_limits::is_iec559); static_assert(sizeof(std::int32_t) == sizeof(float)); - union { std::int32_t src; float dst; } hack; + union { + std::int32_t src; + float dst; + } hack; hack.src = value; return hack.dst; - } static inline float floathacks::uint32_to_float(const std::uint32_t value) { static_assert(std::numeric_limits::is_iec559); static_assert(sizeof(std::uint32_t) == sizeof(float)); - union { std::uint32_t src; float dst; } hack; + union { + std::uint32_t src; + float dst; + } hack; hack.src = value; return hack.dst; } @@ -33,7 +38,10 @@ static inline std::int32_t floathacks::float_to_int32(const float value) { static_assert(std::numeric_limits::is_iec559); static_assert(sizeof(std::int32_t) == sizeof(float)); - union { float src; std::int32_t dst; } hack; + union { + float src; + std::int32_t dst; + } hack; hack.src = value; return hack.dst; } @@ -42,7 +50,10 @@ static inline std::uint32_t floathacks::float_to_uint32(const float value) { static_assert(std::numeric_limits::is_iec559); static_assert(sizeof(std::uint32_t) == sizeof(float)); - union { float src; std::uint32_t dst; } hack; + union { + float src; + std::uint32_t dst; + } hack; hack.src = value; return hack.dst; } diff --git a/core/image.cc b/core/image.cc index 0c9add5..47a05b5 100644 --- a/core/image.cc +++ b/core/image.cc @@ -1,28 +1,29 @@ #include "core/pch.hh" + #include "core/image.hh" #include "core/resource.hh" static emhash8::HashMap> resource_map; -static int stbi_physfs_read(void *context, char *data, int size) +static int stbi_physfs_read(void* context, char* data, int size) { - return PHYSFS_readBytes(reinterpret_cast(context), data, size); + return PHYSFS_readBytes(reinterpret_cast(context), data, size); } -static void stbi_physfs_skip(void *context, int count) +static void stbi_physfs_skip(void* context, int count) { - auto file = reinterpret_cast(context); + auto file = reinterpret_cast(context); PHYSFS_seek(file, PHYSFS_tell(file) + count); } -static int stbi_physfs_eof(void *context) +static int stbi_physfs_eof(void* context) { - return PHYSFS_eof(reinterpret_cast(context)); + return PHYSFS_eof(reinterpret_cast(context)); } template<> -resource_ptr resource::load(const char *name, unsigned int flags) +resource_ptr resource::load(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -38,10 +39,12 @@ resource_ptr resource::load(const char *name, unsigned int flags) return nullptr; } - if(flags & IMAGE_LOAD_FLIP) + if(flags & IMAGE_LOAD_FLIP) { stbi_set_flip_vertically_on_load(true); - else stbi_set_flip_vertically_on_load(false); - + } else { + stbi_set_flip_vertically_on_load(false); + } + stbi_io_callbacks callbacks; callbacks.read = &stbi_physfs_read; callbacks.skip = &stbi_physfs_skip; @@ -49,9 +52,11 @@ resource_ptr resource::load(const char *name, unsigned int flags) auto new_resource = std::make_shared(); - if(flags & IMAGE_LOAD_GRAY) + if(flags & IMAGE_LOAD_GRAY) { new_resource->pixels = stbi_load_from_callbacks(&callbacks, file, &new_resource->size.x, &new_resource->size.y, nullptr, STBI_grey); - else new_resource->pixels = stbi_load_from_callbacks(&callbacks, file, &new_resource->size.x, &new_resource->size.y, nullptr, STBI_rgb_alpha); + } else { + new_resource->pixels = stbi_load_from_callbacks(&callbacks, file, &new_resource->size.x, &new_resource->size.y, nullptr, STBI_rgb_alpha); + } PHYSFS_close(file); @@ -72,10 +77,12 @@ resource_ptr resource::load(const char *name, unsigned int flags) template<> void resource::hard_cleanup(void) { - for(const auto &it : resource_map) { - if(it.second.use_count() > 1L) + for(const auto& it : resource_map) { + if(it.second.use_count() > 1L) { spdlog::warn("resource: zombie resource [Image] {} [use_count={}]", it.first, it.second.use_count()); - else spdlog::debug("resource: releasing [Image] {}", it.first); + } else { + spdlog::debug("resource: releasing [Image] {}", it.first); + } stbi_image_free(it.second->pixels); } diff --git a/core/image.hh b/core/image.hh index 0b13ba0..92d99be 100644 --- a/core/image.hh +++ b/core/image.hh @@ -6,7 +6,7 @@ constexpr static unsigned int IMAGE_LOAD_GRAY = 0x0001U; constexpr static unsigned int IMAGE_LOAD_FLIP = 0x0002U; struct Image final { - stbi_uc *pixels; + stbi_uc* pixels; glm::ivec2 size; }; diff --git a/core/macros.hh b/core/macros.hh index def52da..9042f49 100644 --- a/core/macros.hh +++ b/core/macros.hh @@ -2,6 +2,8 @@ #define CORE_MACROS_HH 1 #pragma once -#define DECLARE_DEFAULT_CTOR(type) public: type(void) = default +#define DECLARE_DEFAULT_CTOR(type) \ +public: \ + type(void) = default #endif /* CORE_MACROS_HH */ diff --git a/core/pch.hh b/core/pch.hh index 9bd9c43..75ed0f6 100644 --- a/core/pch.hh +++ b/core/pch.hh @@ -40,8 +40,8 @@ #include -#include #include +#include #include #include diff --git a/core/randomizer.hh b/core/randomizer.hh index 62bdf9b..b60b839 100644 --- a/core/randomizer.hh +++ b/core/randomizer.hh @@ -8,8 +8,8 @@ public: explicit Randomizer(void); explicit Randomizer(std::uint64_t seed); virtual ~Randomizer(void) = default; - void add(const T &value); - const T &get(void); + void add(const T& value); + const T& get(void); void clear(void); private: @@ -35,14 +35,14 @@ inline Randomizer::Randomizer(std::uint64_t seed) } template -inline void Randomizer::add(const T &value) +inline void Randomizer::add(const T& value) { m_vector.push_back(value); m_dist = std::uniform_int_distribution(0, m_vector.size() - 1); } template -inline const T &Randomizer::get(void) +inline const T& Randomizer::get(void) { return m_vector.at(m_dist(m_twister)); } diff --git a/core/resource.hh b/core/resource.hh index 6f73ca3..ab7b74f 100644 --- a/core/resource.hh +++ b/core/resource.hh @@ -8,7 +8,7 @@ using resource_ptr = std::shared_ptr; namespace resource { template -resource_ptr load(const char *name, unsigned int flags = 0U); +resource_ptr load(const char* name, unsigned int flags = 0U); template void hard_cleanup(void); template diff --git a/core/strtools.cc b/core/strtools.cc index ebb8f73..4edd86b 100644 --- a/core/strtools.cc +++ b/core/strtools.cc @@ -1,26 +1,29 @@ #include "core/pch.hh" + #include "core/strtools.hh" -constexpr static const char *WHITESPACE_CHARS = " \t\r\n"; +constexpr static const char* WHITESPACE_CHARS = " \t\r\n"; -bool strtools::is_whitespace(const std::string &string) +bool strtools::is_whitespace(const std::string& string) { - if(string.find_first_not_of(WHITESPACE_CHARS) == std::string::npos) + if(string.find_first_not_of(WHITESPACE_CHARS) == std::string::npos) { return true; - if((string.size() == 1) && string[0] == 0x00) + } else if((string.size() == 1) && string[0] == 0x00) { return true; - return string.empty(); + } else { + return string.empty(); + } } -std::string strtools::join(const std::vector &strings, const std::string &separator) +std::string strtools::join(const std::vector& strings, const std::string& separator) { std::ostringstream stream; - for(const std::string &str : strings) + for(const std::string& str : strings) stream << str << separator; return stream.str(); } -std::vector strtools::split(const std::string &string, const std::string &separator) +std::vector strtools::split(const std::string& string, const std::string& separator) { std::size_t pos = 0; std::size_t prev = 0; @@ -31,17 +34,21 @@ std::vector strtools::split(const std::string &string, const std::s prev = pos + separator.length(); } - if(prev <= string.length()) + if(prev <= string.length()) { result.push_back(string.substr(prev, string.length() - prev)); + } + return result; } -std::string strtools::trim_whitespace(const std::string &string) +std::string strtools::trim_whitespace(const std::string& string) { auto su = string.find_first_not_of(WHITESPACE_CHARS); auto sv = string.find_last_not_of(WHITESPACE_CHARS); - if(su == std::string::npos) + if(su == std::string::npos) { return std::string(); - return string.substr(su, sv - su + 1); + } else { + return string.substr(su, sv - su + 1); + } } diff --git a/core/strtools.hh b/core/strtools.hh index 0d2aaf8..1462978 100644 --- a/core/strtools.hh +++ b/core/strtools.hh @@ -4,18 +4,18 @@ namespace strtools { -bool is_whitespace(const std::string &string); +bool is_whitespace(const std::string& string); } // namespace strtools namespace strtools { -std::string join(const std::vector &strings, const std::string &separator); -std::vector split(const std::string &string, const std::string &separator); +std::string join(const std::vector& strings, const std::string& separator); +std::vector split(const std::string& string, const std::string& separator); } // namespace strtools namespace strtools { -std::string trim_whitespace(const std::string &string); +std::string trim_whitespace(const std::string& string); } // namespace strtools #endif /* CORE_STRTOOLS_HH */ diff --git a/core/vectors.hh b/core/vectors.hh index e6e185a..86263b7 100644 --- a/core/vectors.hh +++ b/core/vectors.hh @@ -9,38 +9,38 @@ namespace cxvectors { template -constexpr static inline const value_type length2(const glm::vec<2, value_type> &vector); +constexpr static inline const value_type length2(const glm::vec<2, value_type>& vector); template -constexpr static inline const value_type length2(const glm::vec<3, value_type> &vector); +constexpr static inline const value_type length2(const glm::vec<3, value_type>& vector); template -constexpr static inline const value_type distance2(const glm::vec<2, value_type> &vector_a, const glm::vec<2, value_type> &vector_b); +constexpr static inline const value_type distance2(const glm::vec<2, value_type>& vector_a, const glm::vec<2, value_type>& vector_b); template -constexpr static inline const value_type distance2(const glm::vec<3, value_type> &vector_a, const glm::vec<3, value_type> &vector_b); +constexpr static inline const value_type distance2(const glm::vec<3, value_type>& vector_a, const glm::vec<3, value_type>& vector_b); } // namespace cxvectors template -constexpr static inline const value_type cxvectors::length2(const glm::vec<2, value_type> &vector) +constexpr static inline const value_type cxvectors::length2(const glm::vec<2, value_type>& vector) { static_assert(std::is_arithmetic_v); return (vector.x * vector.x) + (vector.y * vector.y); } template -constexpr static inline const value_type cxvectors::length2(const glm::vec<3, value_type> &vector) +constexpr static inline const value_type cxvectors::length2(const glm::vec<3, value_type>& vector) { static_assert(std::is_arithmetic_v); return (vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z); } template -constexpr static inline const value_type cxvectors::distance2(const glm::vec<2, value_type> &vector_a, const glm::vec<2, value_type> &vector_b) +constexpr static inline const value_type cxvectors::distance2(const glm::vec<2, value_type>& vector_a, const glm::vec<2, value_type>& vector_b) { static_assert(std::is_arithmetic_v); return cxvectors::length2(vector_a - vector_b); } template -constexpr static inline const value_type cxvectors::distance2(const glm::vec<3, value_type> &vector_a, const glm::vec<3, value_type> &vector_b) +constexpr static inline const value_type cxvectors::distance2(const glm::vec<3, value_type>& vector_a, const glm::vec<3, value_type>& vector_b) { static_assert(std::is_arithmetic_v); return cxvectors::length2(vector_a - vector_b); diff --git a/game/client/background.cc b/game/client/background.cc index c7b4d86..415b63c 100644 --- a/game/client/background.cc +++ b/game/client/background.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/background.hh" #include "core/constexpr.hh" diff --git a/game/client/bother.cc b/game/client/bother.cc index 8ca247a..8bd7182 100644 --- a/game/client/bother.cc +++ b/game/client/bother.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/bother.hh" #include "shared/protocol.hh" @@ -14,12 +15,12 @@ struct BotherQueueItem final { std::uint16_t port; }; -static ENetHost *bother_host; +static ENetHost* bother_host; static entt::dispatcher bother_dispatcher; static std::unordered_set bother_set; static std::deque bother_queue; -static void on_status_response_packet(const protocol::StatusResponse &packet) +static void on_status_response_packet(const protocol::StatusResponse& packet) { auto identity = static_cast(reinterpret_cast(packet.peer->data)); @@ -60,20 +61,22 @@ void bother::update_late(void) // Figure out how much times we can call // enet_host_connect and reallistically succeed for(unsigned int i = 0U; i < bother_host->peerCount; ++i) { - if(bother_host->peers[i].state != ENET_PEER_STATE_DISCONNECTED) + if(bother_host->peers[i].state != ENET_PEER_STATE_DISCONNECTED) { continue; + } + free_peers += 1U; } for(unsigned int i = 0U; (i < free_peers) && bother_queue.size(); ++i) { - const auto &item = bother_queue.front(); + const auto& item = bother_queue.front(); ENetAddress address; enet_address_set_host(&address, item.hostname.c_str()); address.port = enet_uint16(item.port); if(auto peer = enet_host_connect(bother_host, &address, 1, 0)) { - peer->data = reinterpret_cast(static_cast(item.identity)); + peer->data = reinterpret_cast(static_cast(item.identity)); bother_set.insert(item.identity); enet_host_flush(bother_host); } @@ -114,14 +117,14 @@ void bother::update_late(void) } } -void bother::ping(unsigned int identity, const char *host, std::uint16_t port) +void bother::ping(unsigned int identity, const char* host, std::uint16_t port) { if(bother_set.count(identity)) { // Already in the process return; } - for(const auto &item : bother_queue) { + for(const auto& item : bother_queue) { if(item.identity == identity) { // Already in the queue return; @@ -152,7 +155,7 @@ void bother::cancel(unsigned int identity) } for(unsigned int i = 0U; i < bother_host->peerCount; ++i) { - if(bother_host->peers[i].data == reinterpret_cast(static_cast(identity))) { + if(bother_host->peers[i].data == reinterpret_cast(static_cast(identity))) { enet_peer_reset(&bother_host->peers[i]); break; } diff --git a/game/client/bother.hh b/game/client/bother.hh index 037126c..5fbf247 100644 --- a/game/client/bother.hh +++ b/game/client/bother.hh @@ -16,7 +16,7 @@ namespace bother void init(void); void deinit(void); void update_late(void); -void ping(unsigned int identity, const char *host, std::uint16_t port); +void ping(unsigned int identity, const char* host, std::uint16_t port); void cancel(unsigned int identity); } // namespace bother diff --git a/game/client/camera.cc b/game/client/camera.cc index 30ec581..51e85ff 100644 --- a/game/client/camera.cc +++ b/game/client/camera.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/camera.hh" #include "core/angles.hh" @@ -37,7 +38,7 @@ static void reset_camera(void) // Gracefully contributed by PQCraft himself in 2024 // making PlatinumSrc and Voxelius kind of related to each other -static glm::fmat4x4 platinumsrc_viewmatrix(const glm::fvec3 &position, const glm::fvec3 &angles) +static glm::fmat4x4 platinumsrc_viewmatrix(const glm::fvec3& position, const glm::fvec3& angles) { glm::fvec3 forward, up; cxangles::vectors(angles, &forward, nullptr, &up); @@ -78,9 +79,9 @@ void camera::update(void) return; } - const auto &head = globals::dimension->entities.get(globals::player); - const auto &transform = globals::dimension->entities.get(globals::player); - const auto &velocity = globals::dimension->entities.get(globals::player); + const auto& head = globals::dimension->entities.get(globals::player); + const auto& transform = globals::dimension->entities.get(globals::player); + const auto& velocity = globals::dimension->entities.get(globals::player); camera::angles = transform.angles + head.angles; camera::position_chunk = transform.chunk; diff --git a/game/client/chat.cc b/game/client/chat.cc index 8c0603c..e727974 100644 --- a/game/client/chat.cc +++ b/game/client/chat.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/chat.hh" #include "core/config.hh" @@ -15,8 +16,8 @@ #include "client/language.hh" #include "client/session.hh" #include "client/settings.hh" -#include "client/sound_effect.hh" #include "client/sound.hh" +#include "client/sound_effect.hh" constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration; constexpr static unsigned int MAX_HISTORY_SIZE = 128U; @@ -36,7 +37,7 @@ static bool needs_focus; static resource_ptr sfx_chat_message; -static void append_text_message(const std::string &sender, const std::string &text) +static void append_text_message(const std::string& sender, const std::string& text) { GuiChatMessage message; message.spawn = globals::curtime; @@ -49,7 +50,7 @@ static void append_text_message(const std::string &sender, const std::string &te } } -static void append_player_join(const std::string &sender) +static void append_player_join(const std::string& sender) { GuiChatMessage message; message.spawn = globals::curtime; @@ -62,7 +63,7 @@ static void append_player_join(const std::string &sender) } } -static void append_player_leave(const std::string &sender, const std::string &reason) +static void append_player_leave(const std::string& sender, const std::string& reason) { GuiChatMessage message; message.spawn = globals::curtime; @@ -75,25 +76,25 @@ static void append_player_leave(const std::string &sender, const std::string &re } } -static void on_chat_message_packet(const protocol::ChatMessage &packet) +static void on_chat_message_packet(const protocol::ChatMessage& packet) { if(packet.type == protocol::ChatMessage::TEXT_MESSAGE) { append_text_message(packet.sender, packet.message); return; } - + if(packet.type == protocol::ChatMessage::PLAYER_JOIN) { append_player_join(packet.sender); return; } - + if(packet.type == protocol::ChatMessage::PLAYER_LEAVE) { append_player_leave(packet.sender, packet.message); return; } } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if(event.action == GLFW_PRESS) { if((event.key == GLFW_KEY_ENTER) && (globals::gui_screen == GUI_CHAT)) { @@ -112,12 +113,12 @@ static void on_glfw_key(const GlfwKeyEvent &event) return; } - + if((event.key == GLFW_KEY_ESCAPE) && (globals::gui_screen == GUI_CHAT)) { globals::gui_screen = GUI_SCREEN_NONE; return; } - + if(key_chat.equals(event.key) && !globals::gui_screen) { globals::gui_screen = GUI_CHAT; needs_focus = true; @@ -142,7 +143,6 @@ void client_chat::init(void) void client_chat::init_late(void) { - } void client_chat::deinit(void) @@ -173,8 +173,8 @@ void client_chat::layout(void) return; } - auto &padding = ImGui::GetStyle().FramePadding; - auto &spacing = ImGui::GetStyle().ItemSpacing; + auto& padding = ImGui::GetStyle().FramePadding; + auto& spacing = ImGui::GetStyle().ItemSpacing; auto font = ImGui::GetFont(); auto draw_list = ImGui::GetWindowDrawList(); @@ -212,8 +212,7 @@ void client_chat::layout(void) if(globals::gui_screen == GUI_CHAT) { rect_alpha = 0.75f; text_alpha = 1.00f; - } - else { + } else { rect_alpha = 0.50f * fadeout; text_alpha = 1.00f * fadeout; } @@ -246,7 +245,7 @@ void client_chat::refresh_timings(void) } } -void client_chat::print(const std::string &text) +void client_chat::print(const std::string& text) { GuiChatMessage message = {}; message.spawn = globals::curtime; diff --git a/game/client/chat.hh b/game/client/chat.hh index 318f614..f2ee4de 100644 --- a/game/client/chat.hh +++ b/game/client/chat.hh @@ -15,7 +15,7 @@ namespace client_chat { void clear(void); void refresh_timings(void); -void print(const std::string &string); +void print(const std::string& string); } // namespace client_chat #endif /* CLIENT_CHAT_HH */ diff --git a/game/client/chunk_mesher.cc b/game/client/chunk_mesher.cc index 7e185f1..962997c 100644 --- a/game/client/chunk_mesher.cc +++ b/game/client/chunk_mesher.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/chunk_mesher.hh" #include "core/crc64.hh" @@ -18,19 +19,19 @@ using QuadBuilder = std::vector; using CachedChunkCoord = unsigned short; constexpr static CachedChunkCoord CPOS_ITSELF = 0x0000; -constexpr static CachedChunkCoord CPOS_NORTH = 0x0001; -constexpr static CachedChunkCoord CPOS_SOUTH = 0x0002; -constexpr static CachedChunkCoord CPOS_EAST = 0x0003; -constexpr static CachedChunkCoord CPOS_WEST = 0x0004; -constexpr static CachedChunkCoord CPOS_TOP = 0x0005; +constexpr static CachedChunkCoord CPOS_NORTH = 0x0001; +constexpr static CachedChunkCoord CPOS_SOUTH = 0x0002; +constexpr static CachedChunkCoord CPOS_EAST = 0x0003; +constexpr static CachedChunkCoord CPOS_WEST = 0x0004; +constexpr static CachedChunkCoord CPOS_TOP = 0x0005; constexpr static CachedChunkCoord CPOS_BOTTOM = 0x0006; constexpr static const size_t NUM_CACHED_CPOS = 7; -static const CachedChunkCoord get_cached_cpos(const chunk_pos &pivot, const chunk_pos &cpos) +static const CachedChunkCoord get_cached_cpos(const chunk_pos& pivot, const chunk_pos& cpos) { - static const CachedChunkCoord nx[3] = {CPOS_WEST, 0, CPOS_EAST}; - static const CachedChunkCoord ny[3] = {CPOS_BOTTOM, 0, CPOS_TOP}; - static const CachedChunkCoord nz[3] = {CPOS_NORTH, 0, CPOS_SOUTH}; + static const CachedChunkCoord nx[3] = { CPOS_WEST, 0, CPOS_EAST }; + static const CachedChunkCoord ny[3] = { CPOS_BOTTOM, 0, CPOS_TOP }; + static const CachedChunkCoord nz[3] = { CPOS_NORTH, 0, CPOS_SOUTH }; if(pivot != cpos) { chunk_pos delta = pivot - cpos; @@ -38,11 +39,13 @@ static const CachedChunkCoord get_cached_cpos(const chunk_pos &pivot, const chun delta[1] = cxpr::clamp(delta[1], -1, 1); delta[2] = cxpr::clamp(delta[2], -1, 1); - if(delta[0]) + if(delta[0]) { return nx[delta[0] + 1]; - if(delta[1]) + } else if(delta[1]) { return ny[delta[1] + 1]; - return nz[delta[2] + 1]; + } else { + return nz[delta[2] + 1]; + } } return CPOS_ITSELF; @@ -52,36 +55,46 @@ static voxel_facing get_facing(voxel_face face, voxel_type type) { if(type == voxel_type::CROSS) { switch(face) { - case voxel_face::CROSS_NESW: return voxel_facing::NESW; - case voxel_face::CROSS_NWSE: return voxel_facing::NWSE; - default: return voxel_facing::NORTH; + case voxel_face::CROSS_NESW: + return voxel_facing::NESW; + case voxel_face::CROSS_NWSE: + return voxel_facing::NWSE; + default: + return voxel_facing::NORTH; } } switch(face) { - case voxel_face::CUBE_NORTH: return voxel_facing::NORTH; - case voxel_face::CUBE_SOUTH: return voxel_facing::SOUTH; - case voxel_face::CUBE_EAST: return voxel_facing::EAST; - case voxel_face::CUBE_WEST: return voxel_facing::WEST; - case voxel_face::CUBE_TOP: return voxel_facing::UP; - case voxel_face::CUBE_BOTTOM: return voxel_facing::DOWN; - default: return voxel_facing::NORTH; + case voxel_face::CUBE_NORTH: + return voxel_facing::NORTH; + case voxel_face::CUBE_SOUTH: + return voxel_facing::SOUTH; + case voxel_face::CUBE_EAST: + return voxel_facing::EAST; + case voxel_face::CUBE_WEST: + return voxel_facing::WEST; + case voxel_face::CUBE_TOP: + return voxel_facing::UP; + case voxel_face::CUBE_BOTTOM: + return voxel_facing::DOWN; + default: + return voxel_facing::NORTH; } } class GL_MeshingTask final : public Task { public: - explicit GL_MeshingTask(entt::entity entity, const chunk_pos &cpos); + explicit GL_MeshingTask(entt::entity entity, const chunk_pos& cpos); virtual ~GL_MeshingTask(void) = default; virtual void process(void) override; virtual void finalize(void) override; private: - bool vis_test(voxel_id voxel, const VoxelInfo *info, const local_pos &lpos) const; - void push_quad_a(const VoxelInfo *info, const glm::fvec3 &pos, const glm::fvec2 &size, voxel_face face); - void push_quad_v(const VoxelInfo *info, const glm::fvec3 &pos, const glm::fvec2 &size, voxel_face face, std::size_t entropy); - void make_cube(voxel_id voxel, const VoxelInfo *info, const local_pos &lpos, voxel_vis vis, std::size_t entropy); - void cache_chunk(const chunk_pos &cpos); + bool vis_test(voxel_id voxel, const VoxelInfo* info, const local_pos& lpos) const; + void push_quad_a(const VoxelInfo* info, const glm::fvec3& pos, const glm::fvec2& size, voxel_face face); + void push_quad_v(const VoxelInfo* info, const glm::fvec3& pos, const glm::fvec2& size, voxel_face face, std::size_t entropy); + void make_cube(voxel_id voxel, const VoxelInfo* info, const local_pos& lpos, voxel_vis vis, std::size_t entropy); + void cache_chunk(const chunk_pos& cpos); private: std::array m_cache; @@ -91,7 +104,7 @@ private: chunk_pos m_cpos; }; -GL_MeshingTask::GL_MeshingTask(entt::entity entity, const chunk_pos &cpos) +GL_MeshingTask::GL_MeshingTask(entt::entity entity, const chunk_pos& cpos) { m_entity = entity; m_cpos = cpos; @@ -110,7 +123,7 @@ void GL_MeshingTask::process(void) m_quads_b.resize(voxel_atlas::plane_count()); m_quads_s.resize(voxel_atlas::plane_count()); - const auto &voxels = m_cache.at(CPOS_ITSELF); + const auto& voxels = m_cache.at(CPOS_ITSELF); for(std::size_t i = 0; i < CHUNK_VOLUME; ++i) { if(m_status == task_status::CANCELLED) { @@ -131,18 +144,30 @@ void GL_MeshingTask::process(void) } voxel_vis vis = 0; - if(vis_test(voxel, info, lpos + DIR_NORTH)) + + if(vis_test(voxel, info, lpos + DIR_NORTH)) { vis |= VIS_NORTH; - if(vis_test(voxel, info, lpos + DIR_SOUTH)) + } + + if(vis_test(voxel, info, lpos + DIR_SOUTH)) { vis |= VIS_SOUTH; - if(vis_test(voxel, info, lpos + DIR_EAST)) + } + + if(vis_test(voxel, info, lpos + DIR_EAST)) { vis |= VIS_EAST; - if(vis_test(voxel, info, lpos + DIR_WEST)) + } + + if(vis_test(voxel, info, lpos + DIR_WEST)) { vis |= VIS_WEST; - if(vis_test(voxel, info, lpos + DIR_UP)) + } + + if(vis_test(voxel, info, lpos + DIR_UP)) { vis |= VIS_UP; - if(vis_test(voxel, info, lpos + DIR_DOWN)) + } + + if(vis_test(voxel, info, lpos + DIR_DOWN)) { vis |= VIS_DOWN; + } const auto vpos = coord::to_voxel(m_cpos, lpos); const auto entropy_src = vpos[0] * vpos[1] * vpos[2]; @@ -161,7 +186,7 @@ void GL_MeshingTask::finalize(void) return; } - auto &component = globals::dimension->chunks.emplace_or_replace(m_entity); + auto& component = globals::dimension->chunks.emplace_or_replace(m_entity); const std::size_t plane_count_nb = m_quads_s.size(); const std::size_t plane_count_b = m_quads_b.size(); @@ -173,8 +198,8 @@ void GL_MeshingTask::finalize(void) component.quad_b.resize(plane_count_b); for(std::size_t plane = 0; plane < plane_count_nb; ++plane) { - QuadBuilder &builder = m_quads_s[plane]; - ChunkVBO &buffer = component.quad_nb[plane]; + QuadBuilder& builder = m_quads_s[plane]; + ChunkVBO& buffer = component.quad_nb[plane]; if(builder.empty()) { if(buffer.handle) { @@ -182,20 +207,21 @@ void GL_MeshingTask::finalize(void) buffer.handle = 0; buffer.size = 0; } - } - else { - if(!buffer.handle) + } else { + if(!buffer.handle) { glGenBuffers(1, &buffer.handle); + } + glBindBuffer(GL_ARRAY_BUFFER, buffer.handle); glBufferData(GL_ARRAY_BUFFER, sizeof(ChunkQuad) * builder.size(), builder.data(), GL_STATIC_DRAW); buffer.size = builder.size(); has_no_submeshes_nb = false; - } + } } for(std::size_t plane = 0; plane < plane_count_b; ++plane) { - QuadBuilder &builder = m_quads_b[plane]; - ChunkVBO &buffer = component.quad_b[plane]; + QuadBuilder& builder = m_quads_b[plane]; + ChunkVBO& buffer = component.quad_b[plane]; if(builder.empty()) { if(buffer.handle) { @@ -203,15 +229,16 @@ void GL_MeshingTask::finalize(void) buffer.handle = 0; buffer.size = 0; } - } - else { - if(!buffer.handle) + } else { + if(!buffer.handle) { glGenBuffers(1, &buffer.handle); + } + glBindBuffer(GL_ARRAY_BUFFER, buffer.handle); glBufferData(GL_ARRAY_BUFFER, sizeof(ChunkQuad) * builder.size(), builder.data(), GL_STATIC_DRAW); buffer.size = builder.size(); has_no_submeshes_b = false; - } + } } if(has_no_submeshes_b && has_no_submeshes_nb) { @@ -219,7 +246,7 @@ void GL_MeshingTask::finalize(void) } } -bool GL_MeshingTask::vis_test(voxel_id voxel, const VoxelInfo *info, const local_pos &lpos) const +bool GL_MeshingTask::vis_test(voxel_id voxel, const VoxelInfo* info, const local_pos& lpos) const { const auto pvpos = coord::to_voxel(m_cpos, lpos); const auto pcpos = coord::to_chunk(pvpos); @@ -227,71 +254,113 @@ bool GL_MeshingTask::vis_test(voxel_id voxel, const VoxelInfo *info, const local const auto index = coord::to_index(plpos); const auto cached_cpos = get_cached_cpos(m_cpos, pcpos); - const auto &voxels = m_cache.at(cached_cpos); + const auto& voxels = m_cache.at(cached_cpos); const auto neighbour = voxels[index]; - if(neighbour == NULL_VOXEL_ID) - return true; - if(neighbour == voxel) - return false; + bool result; - if(const VoxelInfo *neighbour_info = voxel_registry::find(neighbour)) { + if(neighbour == NULL_VOXEL_ID) { + result = true; + } else if(neighbour == voxel) { + result = false; + } else if(auto neighbour_info = voxel_registry::find(neighbour)) { if(neighbour_info->blending != info->blending) { // Voxel types that use blending are semi-transparent; // this means they're rendered using a different setup // and they must have visible faces with opaque voxels - return neighbour_info->blending; + result = neighbour_info->blending; + } else { + result = false; } + } else { + result = false; } - return false; + return result; } -void GL_MeshingTask::push_quad_a(const VoxelInfo *info, const glm::fvec3 &pos, const glm::fvec2 &size, voxel_face face) +void GL_MeshingTask::push_quad_a(const VoxelInfo* info, const glm::fvec3& pos, const glm::fvec2& size, voxel_face face) { const voxel_facing facing = get_facing(face, info->type); - const VoxelTexture &vtex = info->textures[static_cast(face)]; + const VoxelTexture& vtex = info->textures[static_cast(face)]; - if(info->blending) + if(info->blending) { m_quads_b[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset, vtex.paths.size())); - else m_quads_s[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset, vtex.paths.size())); + } else { + m_quads_s[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset, vtex.paths.size())); + } } -void GL_MeshingTask::push_quad_v(const VoxelInfo *info, const glm::fvec3 &pos, const glm::fvec2 &size, voxel_face face, std::size_t entropy) +void GL_MeshingTask::push_quad_v(const VoxelInfo* info, const glm::fvec3& pos, const glm::fvec2& size, voxel_face face, std::size_t entropy) { const voxel_facing facing = get_facing(face, info->type); - const VoxelTexture &vtex = info->textures[static_cast(face)]; + const VoxelTexture& vtex = info->textures[static_cast(face)]; const std::size_t entropy_mod = entropy % vtex.paths.size(); - if(info->blending) + if(info->blending) { m_quads_b[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset + entropy_mod, 0)); - else m_quads_s[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset + entropy_mod, 0)); + } else { + m_quads_s[vtex.cached_plane].push_back(make_chunk_quad(pos, size, facing, vtex.cached_offset + entropy_mod, 0)); + } } -void GL_MeshingTask::make_cube(voxel_id voxel, const VoxelInfo *info, const local_pos &lpos, voxel_vis vis, std::size_t entropy) +void GL_MeshingTask::make_cube(voxel_id voxel, const VoxelInfo* info, const local_pos& lpos, voxel_vis vis, std::size_t entropy) { const glm::fvec3 fpos = glm::fvec3(lpos); const glm::fvec2 fsize = glm::fvec2(1.0f, 1.0f); if(info->animated) { - if(vis & VIS_NORTH) push_quad_a(info, fpos, fsize, voxel_face::CUBE_NORTH); - if(vis & VIS_SOUTH) push_quad_a(info, fpos, fsize, voxel_face::CUBE_SOUTH); - if(vis & VIS_EAST) push_quad_a(info, fpos, fsize, voxel_face::CUBE_EAST); - if(vis & VIS_WEST) push_quad_a(info, fpos, fsize, voxel_face::CUBE_WEST); - if(vis & VIS_UP) push_quad_a(info, fpos, fsize, voxel_face::CUBE_TOP); - if(vis & VIS_DOWN) push_quad_a(info, fpos, fsize, voxel_face::CUBE_BOTTOM); - } - else { - if(vis & VIS_NORTH) push_quad_v(info, fpos, fsize, voxel_face::CUBE_NORTH, entropy); - if(vis & VIS_SOUTH) push_quad_v(info, fpos, fsize, voxel_face::CUBE_SOUTH, entropy); - if(vis & VIS_EAST) push_quad_v(info, fpos, fsize, voxel_face::CUBE_EAST, entropy); - if(vis & VIS_WEST) push_quad_v(info, fpos, fsize, voxel_face::CUBE_WEST, entropy); - if(vis & VIS_UP) push_quad_v(info, fpos, fsize, voxel_face::CUBE_TOP, entropy); - if(vis & VIS_DOWN) push_quad_v(info, fpos, fsize, voxel_face::CUBE_BOTTOM, entropy); + if(vis & VIS_NORTH) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_NORTH); + } + + if(vis & VIS_SOUTH) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_SOUTH); + } + + if(vis & VIS_EAST) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_EAST); + } + + if(vis & VIS_WEST) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_WEST); + } + + if(vis & VIS_UP) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_TOP); + } + + if(vis & VIS_DOWN) { + push_quad_a(info, fpos, fsize, voxel_face::CUBE_BOTTOM); + } + } else { + if(vis & VIS_NORTH) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_NORTH, entropy); + } + + if(vis & VIS_SOUTH) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_SOUTH, entropy); + } + + if(vis & VIS_EAST) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_EAST, entropy); + } + + if(vis & VIS_WEST) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_WEST, entropy); + } + + if(vis & VIS_UP) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_TOP, entropy); + } + + if(vis & VIS_DOWN) { + push_quad_v(info, fpos, fsize, voxel_face::CUBE_BOTTOM, entropy); + } } } -void GL_MeshingTask::cache_chunk(const chunk_pos &cpos) +void GL_MeshingTask::cache_chunk(const chunk_pos& cpos) { const auto index = get_cached_cpos(m_cpos, cpos); @@ -304,7 +373,7 @@ void GL_MeshingTask::cache_chunk(const chunk_pos &cpos) // Bogus internal flag component struct NeedsMeshingComponent final {}; -static void on_chunk_create(const ChunkCreateEvent &event) +static void on_chunk_create(const ChunkCreateEvent& event) { const std::array neighbours = { event.cpos + DIR_NORTH, @@ -317,15 +386,15 @@ static void on_chunk_create(const ChunkCreateEvent &event) globals::dimension->chunks.emplace_or_replace(event.chunk->get_entity()); - for(const chunk_pos &cpos : neighbours) { - if(const Chunk *chunk = globals::dimension->find_chunk(cpos)) { + for(const chunk_pos& cpos : neighbours) { + if(const Chunk* chunk = globals::dimension->find_chunk(cpos)) { globals::dimension->chunks.emplace_or_replace(chunk->get_entity()); continue; } } } -static void on_chunk_update(const ChunkUpdateEvent &event) +static void on_chunk_update(const ChunkUpdateEvent& event) { const std::array neighbours = { event.cpos + DIR_NORTH, @@ -338,15 +407,15 @@ static void on_chunk_update(const ChunkUpdateEvent &event) globals::dimension->chunks.emplace_or_replace(event.chunk->get_entity()); - for(const chunk_pos &cpos : neighbours) { - if(const Chunk *chunk = globals::dimension->find_chunk(cpos)) { + for(const chunk_pos& cpos : neighbours) { + if(const Chunk* chunk = globals::dimension->find_chunk(cpos)) { globals::dimension->chunks.emplace_or_replace(chunk->get_entity()); continue; } } } -static void on_voxel_set(const VoxelSetEvent &event) +static void on_voxel_set(const VoxelSetEvent& event) { globals::dimension->chunks.emplace_or_replace(event.chunk->get_entity()); @@ -367,8 +436,8 @@ static void on_voxel_set(const VoxelSetEvent &event) } } - for(const chunk_pos &cpos : neighbours) { - if(const Chunk *chunk = globals::dimension->find_chunk(cpos)) { + for(const chunk_pos& cpos : neighbours) { + if(const Chunk* chunk = globals::dimension->find_chunk(cpos)) { globals::dimension->chunks.emplace_or_replace(chunk->get_entity()); continue; } @@ -384,7 +453,6 @@ void chunk_mesher::init(void) void chunk_mesher::deinit(void) { - } void chunk_mesher::update(void) diff --git a/game/client/chunk_quad.hh b/game/client/chunk_quad.hh index 93fe904..1e34b31 100644 --- a/game/client/chunk_quad.hh +++ b/game/client/chunk_quad.hh @@ -10,7 +10,7 @@ // [1] FFFFTTTTTTTTTTTAAAAA------------ using ChunkQuad = std::array; -constexpr inline static ChunkQuad make_chunk_quad(const glm::fvec3 &position, const glm::fvec2 &size, voxel_facing facing, std::size_t texture, std::size_t frames) +constexpr inline static ChunkQuad make_chunk_quad(const glm::fvec3& position, const glm::fvec2& size, voxel_facing facing, std::size_t texture, std::size_t frames) { ChunkQuad result = {}; result[0] = 0x00000000; diff --git a/game/client/chunk_renderer.cc b/game/client/chunk_renderer.cc index 7282f4a..54239af 100644 --- a/game/client/chunk_renderer.cc +++ b/game/client/chunk_renderer.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/chunk_renderer.hh" #include "core/config.hh" @@ -87,9 +88,11 @@ void chunk_renderer::render(void) glDepthFunc(GL_LEQUAL); glLineWidth(1.0f); - if(toggles::get(TOGGLE_WIREFRAME)) + if(toggles::get(TOGGLE_WIREFRAME)) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } quad_program.set_variant_vert(WORLD_CURVATURE, client_game::world_curvature.get_value()); quad_program.set_variant_vert(WORLD_FOG, client_game::fog_mode.get_value()); @@ -115,10 +118,10 @@ void chunk_renderer::render(void) group.sort([](entt::entity ea, entt::entity eb) { const auto dir_a = globals::dimension->chunks.get(ea).cpos - camera::position_chunk; const auto dir_b = globals::dimension->chunks.get(eb).cpos - camera::position_chunk; - + const auto da = dir_a[0] * dir_a[0] + dir_a[1] * dir_a[1] + dir_a[2] * dir_a[2]; const auto db = dir_b[0] * dir_b[0] + dir_b[1] * dir_b[1] + dir_b[2] * dir_b[2]; - + return da > db; }); } @@ -143,52 +146,42 @@ void chunk_renderer::render(void) glFrontFace(GL_CCW); for(const auto [entity, chunk, mesh] : group.each()) { - if(plane_id >= mesh.quad_nb.size()) - continue; - if(!mesh.quad_nb[plane_id].handle) - continue; - if(!mesh.quad_nb[plane_id].size) - continue; - - const auto wpos = coord::to_fvec3(chunk.cpos - camera::position_chunk); - glUniform3fv(quad_program.uniforms[u_quad_world_position].location, 1, glm::value_ptr(wpos)); - - glBindBuffer(GL_ARRAY_BUFFER, mesh.quad_nb[plane_id].handle); - - glEnableVertexAttribArray(1); - glVertexAttribDivisor(1, 1); - glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, sizeof(ChunkQuad), nullptr); - - glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, mesh.quad_nb[plane_id].size); - - globals::num_drawcalls += 1; - globals::num_triangles += 2 * mesh.quad_nb[plane_id].size; + if(plane_id < mesh.quad_nb.size() && mesh.quad_nb[plane_id].handle && mesh.quad_nb[plane_id].size) { + const auto wpos = coord::to_fvec3(chunk.cpos - camera::position_chunk); + glUniform3fv(quad_program.uniforms[u_quad_world_position].location, 1, glm::value_ptr(wpos)); + + glBindBuffer(GL_ARRAY_BUFFER, mesh.quad_nb[plane_id].handle); + + glEnableVertexAttribArray(1); + glVertexAttribDivisor(1, 1); + glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, sizeof(ChunkQuad), nullptr); + + glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, mesh.quad_nb[plane_id].size); + + globals::num_drawcalls += 1; + globals::num_triangles += 2 * mesh.quad_nb[plane_id].size; + } } glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for(const auto [entity, chunk, mesh] : group.each()) { - if(plane_id >= mesh.quad_b.size()) - continue; - if(!mesh.quad_b[plane_id].handle) - continue; - if(!mesh.quad_b[plane_id].size) - continue; - - const auto wpos = coord::to_fvec3(chunk.cpos - camera::position_chunk); - glUniform3fv(quad_program.uniforms[u_quad_world_position].location, 1, glm::value_ptr(wpos)); - - glBindBuffer(GL_ARRAY_BUFFER, mesh.quad_b[plane_id].handle); - - glEnableVertexAttribArray(1); - glVertexAttribDivisor(1, 1); - glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, sizeof(ChunkQuad), nullptr); - - glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, mesh.quad_b[plane_id].size); - - globals::num_drawcalls += 1; - globals::num_triangles += 2 * mesh.quad_b[plane_id].size; + if(plane_id < mesh.quad_b.size() && mesh.quad_b[plane_id].handle && mesh.quad_b[plane_id].size) { + const auto wpos = coord::to_fvec3(chunk.cpos - camera::position_chunk); + glUniform3fv(quad_program.uniforms[u_quad_world_position].location, 1, glm::value_ptr(wpos)); + + glBindBuffer(GL_ARRAY_BUFFER, mesh.quad_b[plane_id].handle); + + glEnableVertexAttribArray(1); + glVertexAttribDivisor(1, 1); + glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, sizeof(ChunkQuad), nullptr); + + glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, mesh.quad_b[plane_id].size); + + globals::num_drawcalls += 1; + globals::num_triangles += 2 * mesh.quad_b[plane_id].size; + } } } diff --git a/game/client/chunk_visibility.cc b/game/client/chunk_visibility.cc index eb4a7b0..29e4a52 100644 --- a/game/client/chunk_visibility.cc +++ b/game/client/chunk_visibility.cc @@ -1,11 +1,12 @@ #include "client/pch.hh" + #include "client/chunk_visibility.hh" #include "core/config.hh" #include "core/vectors.hh" -#include "shared/chunk_aabb.hh" #include "shared/chunk.hh" +#include "shared/chunk_aabb.hh" #include "shared/dimension.hh" #include "shared/protocol.hh" @@ -28,16 +29,16 @@ static void update_requests(void) requests.clear(); for(auto cx = current_view_box.min.x; cx != current_view_box.max.x; cx += 1) - for(auto cy = current_view_box.min.y; cy != current_view_box.max.y; cy += 1) - for(auto cz = current_view_box.min.z; cz != current_view_box.max.z; cz += 1) { - auto cpos = chunk_pos(cx, cy, cz); + for(auto cy = current_view_box.min.y; cy != current_view_box.max.y; cy += 1) + for(auto cz = current_view_box.min.z; cz != current_view_box.max.z; cz += 1) { + auto cpos = chunk_pos(cx, cy, cz); - if(globals::dimension->find_chunk(cpos)) - continue; - requests.push_back(cpos); - } + if(!globals::dimension->find_chunk(cpos)) { + requests.push_back(cpos); + } + } - std::sort(requests.begin(), requests.end(), [](const chunk_pos &cpos_a, const chunk_pos &cpos_b) { + std::sort(requests.begin(), requests.end(), [](const chunk_pos& cpos_a, const chunk_pos& cpos_b) { auto da = cxvectors::distance2(cpos_a, camera::position_chunk); auto db = cxvectors::distance2(cpos_b, camera::position_chunk); return da > db; @@ -77,9 +78,9 @@ void chunk_visibility::update_late(void) auto view = globals::dimension->chunks.view(); for(const auto [entity, chunk] : view.each()) { - if(current_view_box.contains(chunk.cpos)) - continue; - globals::dimension->remove_chunk(entity); + if(!current_view_box.contains(chunk.cpos)) { + globals::dimension->remove_chunk(entity); + } } previous_view_box = current_view_box; diff --git a/game/client/crosshair.cc b/game/client/crosshair.cc index 9b3a37a..72ece45 100644 --- a/game/client/crosshair.cc +++ b/game/client/crosshair.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/crosshair.hh" #include "core/constexpr.hh" @@ -26,7 +27,7 @@ void crosshair::deinit(void) } void crosshair::layout(void) -{ +{ auto viewport = ImGui::GetMainViewport(); auto draw_list = ImGui::GetForegroundDrawList(); diff --git a/game/client/direct_connection.cc b/game/client/direct_connection.cc index 3f2bf73..b239371 100644 --- a/game/client/direct_connection.cc +++ b/game/client/direct_connection.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/direct_connection.hh" #include "core/config.hh" @@ -25,7 +26,7 @@ static std::string str_password; static std::string direct_hostname; static std::string direct_password; -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if((event.key == GLFW_KEY_ESCAPE) && (event.action == GLFW_PRESS)) { if(globals::gui_screen == GUI_DIRECT_CONNECTION) { @@ -35,7 +36,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) } } -static void on_language_set(const LanguageSetEvent &event) +static void on_language_set(const LanguageSetEvent& event) { str_title = language::resolve("direct_connection.title"); str_connect = language::resolve_gui("direct_connection.connect"); @@ -51,13 +52,17 @@ static void connect_to_server(void) std::string parsed_hostname; std::uint16_t parsed_port; - if(!parts[0].empty()) + if(!parts[0].empty()) { parsed_hostname = parts[0]; - else parsed_hostname = std::string("localhost"); + } else { + parsed_hostname = std::string("localhost"); + } - if(parts.size() >= 2) + if(parts.size() >= 2) { parsed_port = cxpr::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); - else parsed_port = protocol::PORT; + } else { + parsed_port = protocol::PORT; + } session::connect(parsed_hostname.c_str(), parsed_port, direct_password.c_str()); } @@ -119,8 +124,11 @@ void direct_connection::layout(void) ImGui::Dummy(ImVec2(0.0f, 4.0f * globals::gui_scale)); ImGui::BeginDisabled(strtools::is_whitespace(direct_hostname)); - if(ImGui::Button(str_connect.c_str(), ImVec2(avail_width, 0.0f))) + + if(ImGui::Button(str_connect.c_str(), ImVec2(avail_width, 0.0f))) { connect_to_server(); + } + ImGui::EndDisabled(); if(ImGui::Button(str_cancel.c_str(), ImVec2(avail_width, 0.0f))) { diff --git a/game/client/experiments.cc b/game/client/experiments.cc index 6c50ef4..70353b5 100644 --- a/game/client/experiments.cc +++ b/game/client/experiments.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/experiments.hh" #include "shared/dimension.hh" @@ -14,7 +15,7 @@ #include "client/session.hh" #include "client/status_lines.hh" -static void on_glfw_mouse_button(const GlfwMouseButtonEvent &event) +static void on_glfw_mouse_button(const GlfwMouseButtonEvent& event) { if(!globals::gui_screen && session::is_ingame()) { if((event.action == GLFW_PRESS) && (player_target::voxel != NULL_VOXEL_ID)) { @@ -51,17 +52,14 @@ void experiments::init_late(void) void experiments::deinit(void) { - } void experiments::update(void) { - } void experiments::update_late(void) { - } void experiments::attack(void) @@ -72,8 +70,8 @@ void experiments::attack(void) void experiments::interact(void) { if(auto info = item_registry::find(hotbar::slots[hotbar::active_slot])) { - if(info->place_voxel != NULL_VOXEL_ID) + if(info->place_voxel != NULL_VOXEL_ID) { globals::dimension->set_voxel(info->place_voxel, player_target::coord + player_target::normal); - return; + } } } diff --git a/game/client/factory.cc b/game/client/factory.cc index 5eca00c..4c1c24e 100644 --- a/game/client/factory.cc +++ b/game/client/factory.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/factory.hh" #include "shared/dimension.hh" @@ -9,15 +10,15 @@ #include "client/globals.hh" #include "client/sound_emitter.hh" -void client_factory::create_player(Dimension *dimension, entt::entity entity) +void client_factory::create_player(Dimension* dimension, entt::entity entity) { shared_factory::create_player(dimension, entity); - const auto &head = dimension->entities.get(entity); + const auto& head = dimension->entities.get(entity); dimension->entities.emplace_or_replace(entity, head); dimension->entities.emplace_or_replace(entity, head); - const auto &transform = dimension->entities.get(entity); + const auto& transform = dimension->entities.get(entity); dimension->entities.emplace_or_replace(entity, transform); dimension->entities.emplace_or_replace(entity, transform); diff --git a/game/client/factory.hh b/game/client/factory.hh index 4dec985..6f883c2 100644 --- a/game/client/factory.hh +++ b/game/client/factory.hh @@ -6,7 +6,7 @@ class Dimension; namespace client_factory { -void create_player(Dimension *dimension, entt::entity entity); +void create_player(Dimension* dimension, entt::entity entity); } // namespace client_factory #endif /* CLIENT_FACTORY_HH */ diff --git a/game/client/game.cc b/game/client/game.cc index d6d1886..6f68cf9 100644 --- a/game/client/game.cc +++ b/game/client/game.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/game.hh" #include "core/angles.hh" @@ -14,14 +15,12 @@ #include "shared/game_voxels.hh" #include "shared/gravity.hh" #include "shared/head.hh" -#include "shared/head.hh" #include "shared/item_registry.hh" #include "shared/player.hh" #include "shared/protocol.hh" #include "shared/ray_dda.hh" #include "shared/stasis.hh" #include "shared/transform.hh" -#include "shared/transform.hh" #include "shared/velocity.hh" #include "shared/voxel_registry.hh" @@ -60,8 +59,8 @@ #include "client/session.hh" #include "client/settings.hh" #include "client/skybox.hh" -#include "client/sound_emitter.hh" #include "client/sound.hh" +#include "client/sound_emitter.hh" #include "client/splash.hh" #include "client/status_lines.hh" #include "client/texture_gui.hh" @@ -85,7 +84,7 @@ static ConfigKeyBind hide_hud_toggle(GLFW_KEY_F1); static resource_ptr bin_unscii16; static resource_ptr bin_unscii8; -static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent &event) +static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent& event) { auto width_float = static_cast(event.size.x); auto height_float = static_cast(event.size.y); @@ -94,8 +93,8 @@ static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent &event) auto scale = cxpr::min(wscale, hscale); if(globals::gui_scale != scale) { - auto &io = ImGui::GetIO(); - auto &style = ImGui::GetStyle(); + auto& io = ImGui::GetIO(); + auto& style = ImGui::GetStyle(); ImFontConfig font_config; font_config.FontDataOwnedByAtlas = false; @@ -136,7 +135,6 @@ static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent &event) globals::gui_scale = scale; } - if(globals::world_fbo) { glDeleteRenderbuffers(1, &globals::world_fbo_depth); glDeleteTextures(1, &globals::world_fbo_color); @@ -166,7 +164,7 @@ static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent &event) } } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if(!globals::gui_keybind_ptr && hide_hud_toggle.equals(event.key) && (event.action == GLFW_PRESS)) { client_game::hide_hud = !client_game::hide_hud; @@ -237,7 +235,7 @@ void client_game::init(void) skybox::init(); - ImGuiStyle &style = ImGui::GetStyle(); + ImGuiStyle& style = ImGui::GetStyle(); // Black buttons on a dark background // may be harder to read than the text on them @@ -247,67 +245,67 @@ void client_game::init(void) // Rounding on elements looks cool but I am // aiming for a more or less blocky and // visually simple HiDPI-friendly UI style - style.TabRounding = 0.0f; - style.GrabRounding = 0.0f; - style.ChildRounding = 0.0f; - style.FrameRounding = 0.0f; - style.PopupRounding = 0.0f; - style.WindowRounding = 0.0f; + style.TabRounding = 0.0f; + style.GrabRounding = 0.0f; + style.ChildRounding = 0.0f; + style.FrameRounding = 0.0f; + style.PopupRounding = 0.0f; + style.WindowRounding = 0.0f; style.ScrollbarRounding = 0.0f; - style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - style.Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); - style.Colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); - style.Colors[ImGuiCol_Border] = ImVec4(0.79f, 0.79f, 0.79f, 0.50f); - style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.54f); - style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.36f, 0.36f, 0.36f, 0.40f); - style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.63f, 0.63f, 0.63f, 0.67f); - style.Colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); - style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); - style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); - style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); - style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - style.Colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.81f, 0.81f, 0.81f, 0.75f); - style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_Button] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - style.Colors[ImGuiCol_Header] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); - style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - style.Colors[ImGuiCol_Separator] = ImVec4(0.49f, 0.49f, 0.49f, 0.50f); - style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.56f, 0.56f, 0.56f, 0.78f); - style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.34f, 0.34f, 0.34f, 0.20f); - style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.57f, 0.57f, 0.57f, 0.67f); - style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.95f); - style.Colors[ImGuiCol_Tab] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); - style.Colors[ImGuiCol_TabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - style.Colors[ImGuiCol_TabActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); - style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.13f, 0.13f, 0.13f, 0.97f); - style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.44f, 0.44f, 0.44f, 1.00f); - style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.69f, 0.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.00f, 1.00f, 0.20f, 1.00f); - style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); - style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f); - style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); - style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); - style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); - style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.61f, 0.61f, 0.61f, 0.35f); - style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); - style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); - style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); + style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); + style.Colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); + style.Colors[ImGuiCol_Border] = ImVec4(0.79f, 0.79f, 0.79f, 0.50f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.54f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.36f, 0.36f, 0.36f, 0.40f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.63f, 0.63f, 0.63f, 0.67f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.81f, 0.81f, 0.81f, 0.75f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_Button] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + style.Colors[ImGuiCol_Header] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + style.Colors[ImGuiCol_Separator] = ImVec4(0.49f, 0.49f, 0.49f, 0.50f); + style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.56f, 0.56f, 0.56f, 0.78f); + style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.34f, 0.34f, 0.34f, 0.20f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.57f, 0.57f, 0.57f, 0.67f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.95f); + style.Colors[ImGuiCol_Tab] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f); + style.Colors[ImGuiCol_TabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + style.Colors[ImGuiCol_TabActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.13f, 0.13f, 0.13f, 0.97f); + style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.44f, 0.44f, 0.44f, 1.00f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.69f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.00f, 1.00f, 0.20f, 1.00f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f); + style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); + style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); + style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.61f, 0.61f, 0.61f, 0.35f); + style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); + style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); // Making my own Game UI for Source Engine // taught me one important thing: dimensions @@ -381,8 +379,8 @@ void client_game::init_late(void) // NOTE: this is very debug, early and a quite // conservative limit choice; there must be a better // way to make this limit way smaller than it currently is - for(const std::shared_ptr &info : voxel_registry::voxels) { - for(const VoxelTexture &vtex : info->textures) { + for(const std::shared_ptr& info : voxel_registry::voxels) { + for(const VoxelTexture& vtex : info->textures) { max_texture_count += vtex.paths.size(); } } @@ -390,14 +388,14 @@ void client_game::init_late(void) // UNDONE: asset packs for non-16x16 stuff voxel_atlas::create(16, 16, max_texture_count); - for(std::shared_ptr &info : voxel_registry::voxels) { - for(VoxelTexture &vtex : info->textures) { + for(std::shared_ptr& info : voxel_registry::voxels) { + for(VoxelTexture& vtex : info->textures) { if(auto strip = voxel_atlas::find_or_load(vtex.paths)) { vtex.cached_offset = strip->offset; vtex.cached_plane = strip->plane; continue; } - + spdlog::critical("client_gl: {}: failed to load atlas strips", info->name); std::terminate(); } @@ -405,7 +403,7 @@ void client_game::init_late(void) voxel_atlas::generate_mipmaps(); - for(std::shared_ptr &info : item_registry::items) { + for(std::shared_ptr& info : item_registry::items) { info->cached_texture = resource::load(info->texture.c_str(), TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T); } @@ -482,9 +480,9 @@ void client_game::fixed_update(void) void client_game::fixed_update_late(void) { if(session::is_ingame()) { - const auto &head = globals::dimension->entities.get(globals::player); - const auto &transform = globals::dimension->entities.get(globals::player); - const auto &velocity = globals::dimension->entities.get(globals::player); + const auto& head = globals::dimension->entities.get(globals::player); + const auto& transform = globals::dimension->entities.get(globals::player); + const auto& velocity = globals::dimension->entities.get(globals::player); protocol::EntityHead head_packet; head_packet.entity = entt::null; // ignored by server @@ -509,9 +507,11 @@ void client_game::fixed_update_late(void) void client_game::update(void) { if(session::is_ingame()) { - if(toggles::get(TOGGLE_PM_FLIGHT)) + if(toggles::get(TOGGLE_PM_FLIGHT)) { globals::dimension->entities.remove(globals::player); - else globals::dimension->entities.emplace_or_replace(globals::player); + } else { + globals::dimension->entities.emplace_or_replace(globals::player); + } } if(globals::sound_ctx) { @@ -568,10 +568,12 @@ void client_game::update_late(void) gamepad::update_late(); chunk_visibility::update_late(); - - if(client_game::vertical_sync.get_value()) + + if(client_game::vertical_sync.get_value()) { glfwSwapInterval(1); - else glfwSwapInterval(0); + } else { + glfwSwapInterval(0); + } } void client_game::render(void) @@ -602,11 +604,11 @@ void client_game::render(void) // Don't render ourselves continue; } - + glm::fvec3 forward; cxangles::vectors(transform.angles + head.angles, forward); forward *= 2.0f; - + glm::fvec3 hull_size = collision.aabb.max - collision.aabb.min; glm::fvec3 hull_fpos = transform.local + collision.aabb.min; glm::fvec3 look = transform.local + head.offset; diff --git a/game/client/gamepad.cc b/game/client/gamepad.cc index 9321d08..26411ba 100644 --- a/game/client/gamepad.cc +++ b/game/client/gamepad.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/gamepad.hh" #include "core/cmdline.hh" @@ -23,7 +24,7 @@ ConfigBoolean gamepad::active(false); GLFWgamepadstate gamepad::state; GLFWgamepadstate gamepad::last_state; -static void on_toggle_enable(const ToggleEnabledEvent &event) +static void on_toggle_enable(const ToggleEnabledEvent& event) { if(event.type == TOGGLE_USE_GAMEPAD) { gamepad::active.set_value(true); @@ -31,7 +32,7 @@ static void on_toggle_enable(const ToggleEnabledEvent &event) } } -static void on_toggle_disable(const ToggleDisabledEvent &event) +static void on_toggle_disable(const ToggleDisabledEvent& event) { if(event.type == TOGGLE_USE_GAMEPAD) { gamepad::active.set_value(false); @@ -39,15 +40,17 @@ static void on_toggle_disable(const ToggleDisabledEvent &event) } } -static void on_glfw_joystick_event(const GlfwJoystickEvent &event) +static void on_glfw_joystick_event(const GlfwJoystickEvent& event) { if((event.event_type == GLFW_CONNECTED) && glfwJoystickIsGamepad(event.joystick_id) && (active_gamepad_id == INVALID_GAMEPAD_ID)) { gamepad::available = true; active_gamepad_id = event.joystick_id; - for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f); - for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE); + for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) + ; + for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) + ; spdlog::info("gamepad: detected gamepad: {}", glfwGetGamepadName(event.joystick_id)); @@ -59,8 +62,10 @@ static void on_glfw_joystick_event(const GlfwJoystickEvent &event) active_gamepad_id = INVALID_GAMEPAD_ID; - for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f); - for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE); + for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) + ; + for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) + ; spdlog::warn("gamepad: disconnected"); @@ -97,8 +102,10 @@ void gamepad::init(void) active_gamepad_id = joystick; - for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f); - for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE); + for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) + ; + for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) + ; spdlog::info("gamepad: detected gamepad: {}", glfwGetGamepadName(joystick)); @@ -106,8 +113,10 @@ void gamepad::init(void) } } - for(int i = 0; i < NUM_AXES; gamepad::state.axes[i++] = 0.0f); - for(int i = 0; i < NUM_BUTTONS; gamepad::state.buttons[i++] = GLFW_RELEASE); + for(int i = 0; i < NUM_AXES; gamepad::state.axes[i++] = 0.0f) + ; + for(int i = 0; i < NUM_BUTTONS; gamepad::state.buttons[i++] = GLFW_RELEASE) + ; globals::dispatcher.sink().connect<&on_toggle_enable>(); globals::dispatcher.sink().connect<&on_toggle_disable>(); diff --git a/game/client/gamepad_axis.cc b/game/client/gamepad_axis.cc index dff0894..4d4d953 100644 --- a/game/client/gamepad_axis.cc +++ b/game/client/gamepad_axis.cc @@ -1,26 +1,29 @@ #include "client/pch.hh" + #include "client/gamepad_axis.hh" #include "core/constexpr.hh" #include "client/gamepad.hh" -constexpr static const char *UNKNOWN_AXIS_NAME = "UNKNOWN"; +constexpr static const char* UNKNOWN_AXIS_NAME = "UNKNOWN"; -static const std::pair axis_names[] = { - { GLFW_GAMEPAD_AXIS_LEFT_X, "LEFT_X" }, - { GLFW_GAMEPAD_AXIS_LEFT_Y, "LEFT_Y" }, - { GLFW_GAMEPAD_AXIS_RIGHT_X, "RIGHT_X" }, - { GLFW_GAMEPAD_AXIS_RIGHT_Y, "RIGHT_Y" }, - { GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, "LEFT_TRIG" }, - { GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, "RIGHT_TRIG" }, +static const std::pair axis_names[] = { + { GLFW_GAMEPAD_AXIS_LEFT_X, "LEFT_X" }, + { GLFW_GAMEPAD_AXIS_LEFT_Y, "LEFT_Y" }, + { GLFW_GAMEPAD_AXIS_RIGHT_X, "RIGHT_X" }, + { GLFW_GAMEPAD_AXIS_RIGHT_Y, "RIGHT_Y" }, + { GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, "LEFT_TRIG" }, + { GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, "RIGHT_TRIG" }, }; -static const char *get_axis_name(int axis) +static const char* get_axis_name(int axis) { - for(const auto &it : axis_names) { - if(it.first != axis) + for(const auto& it : axis_names) { + if(it.first != axis) { continue; + } + return it.second; } @@ -29,7 +32,6 @@ static const char *get_axis_name(int axis) ConfigGamepadAxis::ConfigGamepadAxis(void) : ConfigGamepadAxis(INVALID_GAMEPAD_AXIS, false) { - } ConfigGamepadAxis::ConfigGamepadAxis(int axis, bool inverted) @@ -40,18 +42,18 @@ ConfigGamepadAxis::ConfigGamepadAxis(int axis, bool inverted) m_full_string = fmt::format("{}:{}", m_name, m_inverted ? 1U : 0U); } -const char *ConfigGamepadAxis::get(void) const +const char* ConfigGamepadAxis::get(void) const { return m_full_string.c_str(); } -void ConfigGamepadAxis::set(const char *value) +void ConfigGamepadAxis::set(const char* value) { char new_name[64]; unsigned int new_invert; if(2 == std::sscanf(value, "%63[^:]:%u", new_name, &new_invert)) { - for(const auto &it : axis_names) { + for(const auto& it : axis_names) { if(!std::strcmp(it.second, new_name)) { m_inverted = new_invert; m_gamepad_axis = it.first; @@ -91,20 +93,22 @@ void ConfigGamepadAxis::set_inverted(bool inverted) m_full_string = fmt::format("{}:{}", m_name, m_inverted ? 1U : 0U); } -float ConfigGamepadAxis::get_value(const GLFWgamepadstate &state, float deadzone) const +float ConfigGamepadAxis::get_value(const GLFWgamepadstate& state, float deadzone) const { if(m_gamepad_axis <= cxpr::array_size(state.axes)) { auto value = state.axes[m_gamepad_axis]; - if(cxpr::abs(value) > deadzone) + + if(cxpr::abs(value) > deadzone) { return m_inverted ? -value : value; + } + return 0.0f; } return 0.0f; - } -const char *ConfigGamepadAxis::get_name(void) const +const char* ConfigGamepadAxis::get_name(void) const { return m_name; } diff --git a/game/client/gamepad_axis.hh b/game/client/gamepad_axis.hh index 6ffb86d..c0ed6ee 100644 --- a/game/client/gamepad_axis.hh +++ b/game/client/gamepad_axis.hh @@ -12,8 +12,8 @@ public: explicit ConfigGamepadAxis(int axis, bool inverted); virtual ~ConfigGamepadAxis(void) = default; - virtual const char *get(void) const override; - virtual void set(const char *value) override; + virtual const char* get(void) const override; + virtual void set(const char* value) override; int get_axis(void) const; void set_axis(int axis); @@ -21,19 +21,19 @@ public: bool is_inverted(void) const; void set_inverted(bool inverted); - float get_value(const GLFWgamepadstate &state, float deadzone = 0.0f) const; + float get_value(const GLFWgamepadstate& state, float deadzone = 0.0f) const; // Conventional get/set methods implemented by // this configuration value actually contain the // inversion flag. Since we're updating that flag // in the UI by means of a separate checkbox, we only need the name here - const char *get_name(void) const; + const char* get_name(void) const; private: bool m_inverted; int m_gamepad_axis; std::string m_full_string; - const char *m_name; + const char* m_name; }; #endif /* CLIENT_GAMEPAD_AXIS_HH */ diff --git a/game/client/gamepad_button.cc b/game/client/gamepad_button.cc index e22f7e7..c236054 100644 --- a/game/client/gamepad_button.cc +++ b/game/client/gamepad_button.cc @@ -1,36 +1,37 @@ #include "client/pch.hh" + #include "client/gamepad_button.hh" #include "core/constexpr.hh" #include "client/gamepad.hh" -constexpr static const char *UNKNOWN_BUTTON_NAME = "UNKNOWN"; - -static const std::pair button_names[] = { - { GLFW_GAMEPAD_BUTTON_A, "A" }, - { GLFW_GAMEPAD_BUTTON_B, "B" }, - { GLFW_GAMEPAD_BUTTON_X, "X" }, - { GLFW_GAMEPAD_BUTTON_Y, "Y" }, - { GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L_BUMP" }, - { GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R_BUMP" }, - { GLFW_GAMEPAD_BUTTON_BACK, "BACK" }, - { GLFW_GAMEPAD_BUTTON_START, "START" }, - { GLFW_GAMEPAD_BUTTON_GUIDE, "GUIDE" }, - { GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L_THUMB" }, - { GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R_THUMB" }, - { GLFW_GAMEPAD_BUTTON_DPAD_UP, "DPAD_UP" }, - { GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT" }, - { GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "DPAD_DOWN" }, - { GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "DPAD_LEFT" }, +constexpr static const char* UNKNOWN_BUTTON_NAME = "UNKNOWN"; + +static const std::pair button_names[] = { + { GLFW_GAMEPAD_BUTTON_A, "A" }, + { GLFW_GAMEPAD_BUTTON_B, "B" }, + { GLFW_GAMEPAD_BUTTON_X, "X" }, + { GLFW_GAMEPAD_BUTTON_Y, "Y" }, + { GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, "L_BUMP" }, + { GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, "R_BUMP" }, + { GLFW_GAMEPAD_BUTTON_BACK, "BACK" }, + { GLFW_GAMEPAD_BUTTON_START, "START" }, + { GLFW_GAMEPAD_BUTTON_GUIDE, "GUIDE" }, + { GLFW_GAMEPAD_BUTTON_LEFT_THUMB, "L_THUMB" }, + { GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, "R_THUMB" }, + { GLFW_GAMEPAD_BUTTON_DPAD_UP, "DPAD_UP" }, + { GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT" }, + { GLFW_GAMEPAD_BUTTON_DPAD_DOWN, "DPAD_DOWN" }, + { GLFW_GAMEPAD_BUTTON_DPAD_LEFT, "DPAD_LEFT" }, }; -static const char *get_button_name(int button) +static const char* get_button_name(int button) { - for(const auto &it : button_names) { - if(it.first != button) - continue; - return it.second; + for(const auto& it : button_names) { + if(it.first == button) { + return it.second; + } } return UNKNOWN_BUTTON_NAME; @@ -48,14 +49,14 @@ ConfigGamepadButton::ConfigGamepadButton(int button) m_name = get_button_name(button); } -const char *ConfigGamepadButton::get(void) const +const char* ConfigGamepadButton::get(void) const { return m_name; } -void ConfigGamepadButton::set(const char *value) +void ConfigGamepadButton::set(const char* value) { - for(const auto &it : button_names) { + for(const auto& it : button_names) { if(!std::strcmp(it.second, value)) { m_gamepad_button = it.first; m_name = it.second; @@ -83,9 +84,7 @@ bool ConfigGamepadButton::equals(int button) const return m_gamepad_button == button; } -bool ConfigGamepadButton::is_pressed(const GLFWgamepadstate &state) const +bool ConfigGamepadButton::is_pressed(const GLFWgamepadstate& state) const { - if((m_gamepad_button < cxpr::array_size(state.buttons)) && (state.buttons[m_gamepad_button] == GLFW_PRESS)) - return true; - return false; + return m_gamepad_button < cxpr::array_size(state.buttons) && state.buttons[m_gamepad_button] == GLFW_PRESS; } diff --git a/game/client/gamepad_button.hh b/game/client/gamepad_button.hh index d8f2ed7..04b3a41 100644 --- a/game/client/gamepad_button.hh +++ b/game/client/gamepad_button.hh @@ -12,18 +12,18 @@ public: explicit ConfigGamepadButton(int button); virtual ~ConfigGamepadButton(void) = default; - virtual const char *get(void) const override; - virtual void set(const char *value) override; + virtual const char* get(void) const override; + virtual void set(const char* value) override; int get_button(void) const; void set_button(int button); bool equals(int button) const; - bool is_pressed(const GLFWgamepadstate &state) const; + bool is_pressed(const GLFWgamepadstate& state) const; private: int m_gamepad_button; - const char *m_name; + const char* m_name; }; #endif /* CLIENT_GAMEPAD_BUTTON_HH */ diff --git a/game/client/glfw.hh b/game/client/glfw.hh index 5af514f..9cdf734 100644 --- a/game/client/glfw.hh +++ b/game/client/glfw.hh @@ -17,14 +17,14 @@ struct GlfwJoystickEvent final { }; struct GlfwKeyEvent final { - int key {GLFW_KEY_UNKNOWN}; + int key { GLFW_KEY_UNKNOWN }; int scancode; int action; int mods; }; struct GlfwMouseButtonEvent final { - int button {GLFW_KEY_UNKNOWN}; + int button { GLFW_KEY_UNKNOWN }; int action; int mods; }; diff --git a/game/client/globals.cc b/game/client/globals.cc index 071cf0a..6e00680 100644 --- a/game/client/globals.cc +++ b/game/client/globals.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/globals.hh" #include "core/config.hh" @@ -7,7 +8,7 @@ Config globals::client_config; -GLFWwindow *globals::window; +GLFWwindow* globals::window; float globals::window_frametime; float globals::window_frametime_avg; @@ -27,21 +28,21 @@ GLuint globals::world_fbo_depth; std::size_t globals::num_drawcalls; std::size_t globals::num_triangles; -ENetHost *globals::client_host; +ENetHost* globals::client_host; -Dimension *globals::dimension = nullptr; +Dimension* globals::dimension = nullptr; entt::entity globals::player; -ImFont *globals::font_debug; -ImFont *globals::font_default; -ImFont *globals::font_chat; +ImFont* globals::font_debug; +ImFont* globals::font_default; +ImFont* globals::font_chat; -ConfigKeyBind *globals::gui_keybind_ptr = nullptr; -ConfigGamepadAxis *globals::gui_gamepad_axis_ptr = nullptr; -ConfigGamepadButton *globals::gui_gamepad_button_ptr = nullptr; +ConfigKeyBind* globals::gui_keybind_ptr = nullptr; +ConfigGamepadAxis* globals::gui_gamepad_axis_ptr = nullptr; +ConfigGamepadButton* globals::gui_gamepad_button_ptr = nullptr; unsigned int globals::gui_scale = 0U; unsigned int globals::gui_screen = GUI_SCREEN_NONE; -ALCdevice *globals::sound_dev; -ALCcontext *globals::sound_ctx; +ALCdevice* globals::sound_dev; +ALCcontext* globals::sound_ctx; diff --git a/game/client/globals.hh b/game/client/globals.hh index 9423283..3fc2223 100644 --- a/game/client/globals.hh +++ b/game/client/globals.hh @@ -18,7 +18,7 @@ namespace globals { extern Config client_config; -extern GLFWwindow *window; +extern GLFWwindow* window; // Some gamesystems that aren't really // gameplay-oriented might still use client @@ -43,24 +43,24 @@ extern GLuint world_fbo_depth; extern std::size_t num_drawcalls; extern std::size_t num_triangles; -extern ENetHost *client_host; +extern ENetHost* client_host; -extern Dimension *dimension; +extern Dimension* dimension; extern entt::entity player; -extern ImFont *font_debug; -extern ImFont *font_default; -extern ImFont *font_chat; +extern ImFont* font_debug; +extern ImFont* font_default; +extern ImFont* font_chat; -extern ConfigKeyBind *gui_keybind_ptr; -extern ConfigGamepadAxis *gui_gamepad_axis_ptr; -extern ConfigGamepadButton *gui_gamepad_button_ptr; +extern ConfigKeyBind* gui_keybind_ptr; +extern ConfigGamepadAxis* gui_gamepad_axis_ptr; +extern ConfigGamepadButton* gui_gamepad_button_ptr; extern unsigned int gui_scale; extern unsigned int gui_screen; -extern ALCdevice *sound_dev; -extern ALCcontext *sound_ctx; +extern ALCdevice* sound_dev; +extern ALCcontext* sound_ctx; } // namespace globals #endif /* CLIENTOBALS_HH */ diff --git a/game/client/gui_screen.hh b/game/client/gui_screen.hh index 0ee7b44..edad116 100644 --- a/game/client/gui_screen.hh +++ b/game/client/gui_screen.hh @@ -2,13 +2,13 @@ #define CLIENT_GUI_SCREEN_HH 1 #pragma once -constexpr static unsigned int GUI_SCREEN_NONE = 0x0000U; -constexpr static unsigned int GUI_MAIN_MENU = 0x0001U; -constexpr static unsigned int GUI_PLAY_MENU = 0x0002U; -constexpr static unsigned int GUI_SETTINGS = 0x0003U; -constexpr static unsigned int GUI_PROGRESS_BAR = 0x0004U; -constexpr static unsigned int GUI_MESSAGE_BOX = 0x0005U; -constexpr static unsigned int GUI_CHAT = 0x0006U; +constexpr static unsigned int GUI_SCREEN_NONE = 0x0000U; +constexpr static unsigned int GUI_MAIN_MENU = 0x0001U; +constexpr static unsigned int GUI_PLAY_MENU = 0x0002U; +constexpr static unsigned int GUI_SETTINGS = 0x0003U; +constexpr static unsigned int GUI_PROGRESS_BAR = 0x0004U; +constexpr static unsigned int GUI_MESSAGE_BOX = 0x0005U; +constexpr static unsigned int GUI_CHAT = 0x0006U; constexpr static unsigned int GUI_DIRECT_CONNECTION = 0x0007U; #endif /* CLIENT_GUI_SCREEN_HH */ diff --git a/game/client/hotbar.cc b/game/client/hotbar.cc index a5f976c..a783347 100644 --- a/game/client/hotbar.cc +++ b/game/client/hotbar.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/hotbar.hh" #include "core/config.hh" @@ -28,7 +29,7 @@ static resource_ptr hotbar_selector; static ImU32 get_color_alpha(ImGuiCol style_color, float alpha) { - const auto &color = ImGui::GetStyleColorVec4(style_color); + const auto& color = ImGui::GetStyleColorVec4(style_color); return ImGui::GetColorU32(ImVec4(color.x, color.y, color.z, alpha)); } @@ -45,7 +46,7 @@ static void update_hotbar_item(void) } } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if((event.action == GLFW_PRESS) && !globals::gui_screen) { for(unsigned int i = 0U; i < HOTBAR_SIZE; ++i) { @@ -58,7 +59,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) } } -static void on_glfw_scroll(const GlfwScrollEvent &event) +static void on_glfw_scroll(const GlfwScrollEvent& event) { if(!globals::gui_screen) { if(event.dy < 0.0) { @@ -120,7 +121,7 @@ void hotbar::deinit(void) void hotbar::layout(void) { - auto &style = ImGui::GetStyle(); + auto& style = ImGui::GetStyle(); auto item_size = ITEM_SIZE * globals::gui_scale; auto hotbar_width = HOTBAR_SIZE * item_size; diff --git a/game/client/imdraw_ext.cc b/game/client/imdraw_ext.cc index 3423fb4..920063e 100644 --- a/game/client/imdraw_ext.cc +++ b/game/client/imdraw_ext.cc @@ -1,9 +1,10 @@ #include "client/pch.hh" + #include "client/imdraw_ext.hh" #include "client/globals.hh" -void imdraw_ext::text_shadow(const std::string &text, const ImVec2 &position, ImU32 text_color, ImU32 shadow_color, ImFont *font, ImDrawList *draw_list) +void imdraw_ext::text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, ImDrawList* draw_list) { const auto shadow_position = ImVec2(position.x + 0.5f * globals::gui_scale, position.y + 0.5f * globals::gui_scale); draw_list->AddText(font, font->FontSize, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size()); diff --git a/game/client/imdraw_ext.hh b/game/client/imdraw_ext.hh index 8d62d25..a73269e 100644 --- a/game/client/imdraw_ext.hh +++ b/game/client/imdraw_ext.hh @@ -4,7 +4,7 @@ namespace imdraw_ext { -void text_shadow(const std::string &text, const ImVec2 &position, ImU32 text_color, ImU32 shadow_color, ImFont *font, ImDrawList *draw_list); +void text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font, ImDrawList* draw_list); } // namespace imdraw_ext #endif /* CLIENT_IMDRAW_EXT_HH */ diff --git a/game/client/interpolation.cc b/game/client/interpolation.cc index 841d429..e820b62 100644 --- a/game/client/interpolation.cc +++ b/game/client/interpolation.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/interpolation.hh" #include "core/constexpr.hh" diff --git a/game/client/keybind.cc b/game/client/keybind.cc index 7df73ed..d47397d 100644 --- a/game/client/keybind.cc +++ b/game/client/keybind.cc @@ -1,141 +1,142 @@ #include "client/pch.hh" + #include "client/keybind.hh" #include "core/constexpr.hh" #include "client/const.hh" -constexpr static const char *UNKNOWN_KEY_NAME = "UNKNOWN"; +constexpr static const char* UNKNOWN_KEY_NAME = "UNKNOWN"; -static const std::pair key_names[] = { - { GLFW_KEY_SPACE, "SPACE" }, - { GLFW_KEY_APOSTROPHE, "'" }, - { GLFW_KEY_COMMA, "," }, - { GLFW_KEY_MINUS, "-" }, - { GLFW_KEY_PERIOD, "." }, - { GLFW_KEY_SLASH, "/" }, - { GLFW_KEY_0, "0" }, - { GLFW_KEY_1, "1" }, - { GLFW_KEY_2, "2" }, - { GLFW_KEY_3, "3" }, - { GLFW_KEY_4, "4" }, - { GLFW_KEY_5, "5" }, - { GLFW_KEY_6, "6" }, - { GLFW_KEY_7, "7" }, - { GLFW_KEY_8, "8" }, - { GLFW_KEY_9, "9" }, - { GLFW_KEY_SEMICOLON, ";" }, - { GLFW_KEY_EQUAL, "=" }, - { GLFW_KEY_A, "A" }, - { GLFW_KEY_B, "B" }, - { GLFW_KEY_C, "C" }, - { GLFW_KEY_D, "D" }, - { GLFW_KEY_E, "E" }, - { GLFW_KEY_F, "F" }, - { GLFW_KEY_G, "G" }, - { GLFW_KEY_H, "H" }, - { GLFW_KEY_I, "I" }, - { GLFW_KEY_J, "J" }, - { GLFW_KEY_K, "K" }, - { GLFW_KEY_L, "L" }, - { GLFW_KEY_M, "M" }, - { GLFW_KEY_N, "N" }, - { GLFW_KEY_O, "O" }, - { GLFW_KEY_P, "P" }, - { GLFW_KEY_Q, "Q" }, - { GLFW_KEY_R, "R" }, - { GLFW_KEY_S, "S" }, - { GLFW_KEY_T, "T" }, - { GLFW_KEY_U, "U" }, - { GLFW_KEY_V, "V" }, - { GLFW_KEY_W, "W" }, - { GLFW_KEY_X, "X" }, - { GLFW_KEY_Y, "Y" }, - { GLFW_KEY_Z, "Z" }, - { GLFW_KEY_LEFT_BRACKET, "[" }, - { GLFW_KEY_BACKSLASH, "\\" }, - { GLFW_KEY_RIGHT_BRACKET, "]" }, - { GLFW_KEY_GRAVE_ACCENT, "`" }, - { GLFW_KEY_WORLD_1, "WORLD_1" }, - { GLFW_KEY_WORLD_2, "WORLD_2" }, - { GLFW_KEY_ESCAPE, "ESCAPE" }, - { GLFW_KEY_ENTER, "ENTER" }, - { GLFW_KEY_TAB, "TAB" }, - { GLFW_KEY_BACKSPACE, "BACKSPACE" }, - { GLFW_KEY_INSERT, "INSERT" }, - { GLFW_KEY_DELETE, "DELETE" }, - { GLFW_KEY_RIGHT, "RIGHT" }, - { GLFW_KEY_LEFT, "LEFT" }, - { GLFW_KEY_DOWN, "DOWN" }, - { GLFW_KEY_UP, "UP" }, - { GLFW_KEY_PAGE_UP, "PAGE_UP" }, - { GLFW_KEY_PAGE_DOWN, "PAGE_DOWN" }, - { GLFW_KEY_HOME, "HOME" }, - { GLFW_KEY_END, "END" }, - { GLFW_KEY_CAPS_LOCK, "CAPS_LOCK" }, - { GLFW_KEY_SCROLL_LOCK, "SCROLL_LOCK" }, - { GLFW_KEY_NUM_LOCK, "NUM_LOCK" }, - { GLFW_KEY_PRINT_SCREEN, "PRINT_SCREEN" }, - { GLFW_KEY_PAUSE, "PAUSE" }, - { GLFW_KEY_F1, "F1" }, - { GLFW_KEY_F2, "F2" }, - { GLFW_KEY_F3, "F3" }, - { GLFW_KEY_F4, "F4" }, - { GLFW_KEY_F5, "F5" }, - { GLFW_KEY_F6, "F6" }, - { GLFW_KEY_F7, "F7" }, - { GLFW_KEY_F8, "F8" }, - { GLFW_KEY_F9, "F9" }, - { GLFW_KEY_F10, "F10" }, - { GLFW_KEY_F11, "F11" }, - { GLFW_KEY_F12, "F12" }, - { GLFW_KEY_F13, "F13" }, - { GLFW_KEY_F14, "F14" }, - { GLFW_KEY_F15, "F15" }, - { GLFW_KEY_F16, "F16" }, - { GLFW_KEY_F17, "F17" }, - { GLFW_KEY_F18, "F18" }, - { GLFW_KEY_F19, "F19" }, - { GLFW_KEY_F20, "F20" }, - { GLFW_KEY_F21, "F21" }, - { GLFW_KEY_F22, "F22" }, - { GLFW_KEY_F23, "F23" }, - { GLFW_KEY_F24, "F24" }, - { GLFW_KEY_F25, "F25" }, - { GLFW_KEY_KP_0, "KEYPAD_0" }, - { GLFW_KEY_KP_1, "KEYPAD_1" }, - { GLFW_KEY_KP_2, "KEYPAD_2" }, - { GLFW_KEY_KP_3, "KEYPAD_3" }, - { GLFW_KEY_KP_4, "KEYPAD_4" }, - { GLFW_KEY_KP_5, "KEYPAD_5" }, - { GLFW_KEY_KP_6, "KEYPAD_6" }, - { GLFW_KEY_KP_7, "KEYPAD_7" }, - { GLFW_KEY_KP_8, "KEYPAD_8" }, - { GLFW_KEY_KP_9, "KEYPAD_9" }, - { GLFW_KEY_KP_DECIMAL, "KEYPAD_POINT" }, - { GLFW_KEY_KP_DIVIDE, "KEYPAD_DIV" }, - { GLFW_KEY_KP_MULTIPLY, "KEYPAD_MUL" }, - { GLFW_KEY_KP_SUBTRACT, "KEYPAD_MINUS" }, - { GLFW_KEY_KP_ADD, "KEYPAD_PLUS" }, - { GLFW_KEY_KP_ENTER, "KEYPAD_ENTER" }, - { GLFW_KEY_KP_EQUAL, "KEYPAD_EQUAL" }, - { GLFW_KEY_LEFT_SHIFT, "LEFT_SHIFT" }, - { GLFW_KEY_LEFT_CONTROL, "LEFT_CTRL" }, - { GLFW_KEY_LEFT_ALT, "LEFT_ALT" }, - { GLFW_KEY_LEFT_SUPER, "LEFT_SUPER" }, - { GLFW_KEY_RIGHT_SHIFT, "RIGHT_SHIFT" }, - { GLFW_KEY_RIGHT_CONTROL, "RIGHT_CTRL" }, - { GLFW_KEY_RIGHT_ALT, "RIGHT_ALT" }, - { GLFW_KEY_RIGHT_SUPER, "RIGHT_SUPER" }, - { GLFW_KEY_MENU, "MENU" }, +static const std::pair key_names[] = { + { GLFW_KEY_SPACE, "SPACE" }, + { GLFW_KEY_APOSTROPHE, "'" }, + { GLFW_KEY_COMMA, "," }, + { GLFW_KEY_MINUS, "-" }, + { GLFW_KEY_PERIOD, "." }, + { GLFW_KEY_SLASH, "/" }, + { GLFW_KEY_0, "0" }, + { GLFW_KEY_1, "1" }, + { GLFW_KEY_2, "2" }, + { GLFW_KEY_3, "3" }, + { GLFW_KEY_4, "4" }, + { GLFW_KEY_5, "5" }, + { GLFW_KEY_6, "6" }, + { GLFW_KEY_7, "7" }, + { GLFW_KEY_8, "8" }, + { GLFW_KEY_9, "9" }, + { GLFW_KEY_SEMICOLON, ";" }, + { GLFW_KEY_EQUAL, "=" }, + { GLFW_KEY_A, "A" }, + { GLFW_KEY_B, "B" }, + { GLFW_KEY_C, "C" }, + { GLFW_KEY_D, "D" }, + { GLFW_KEY_E, "E" }, + { GLFW_KEY_F, "F" }, + { GLFW_KEY_G, "G" }, + { GLFW_KEY_H, "H" }, + { GLFW_KEY_I, "I" }, + { GLFW_KEY_J, "J" }, + { GLFW_KEY_K, "K" }, + { GLFW_KEY_L, "L" }, + { GLFW_KEY_M, "M" }, + { GLFW_KEY_N, "N" }, + { GLFW_KEY_O, "O" }, + { GLFW_KEY_P, "P" }, + { GLFW_KEY_Q, "Q" }, + { GLFW_KEY_R, "R" }, + { GLFW_KEY_S, "S" }, + { GLFW_KEY_T, "T" }, + { GLFW_KEY_U, "U" }, + { GLFW_KEY_V, "V" }, + { GLFW_KEY_W, "W" }, + { GLFW_KEY_X, "X" }, + { GLFW_KEY_Y, "Y" }, + { GLFW_KEY_Z, "Z" }, + { GLFW_KEY_LEFT_BRACKET, "[" }, + { GLFW_KEY_BACKSLASH, "\\" }, + { GLFW_KEY_RIGHT_BRACKET, "]" }, + { GLFW_KEY_GRAVE_ACCENT, "`" }, + { GLFW_KEY_WORLD_1, "WORLD_1" }, + { GLFW_KEY_WORLD_2, "WORLD_2" }, + { GLFW_KEY_ESCAPE, "ESCAPE" }, + { GLFW_KEY_ENTER, "ENTER" }, + { GLFW_KEY_TAB, "TAB" }, + { GLFW_KEY_BACKSPACE, "BACKSPACE" }, + { GLFW_KEY_INSERT, "INSERT" }, + { GLFW_KEY_DELETE, "DELETE" }, + { GLFW_KEY_RIGHT, "RIGHT" }, + { GLFW_KEY_LEFT, "LEFT" }, + { GLFW_KEY_DOWN, "DOWN" }, + { GLFW_KEY_UP, "UP" }, + { GLFW_KEY_PAGE_UP, "PAGE_UP" }, + { GLFW_KEY_PAGE_DOWN, "PAGE_DOWN" }, + { GLFW_KEY_HOME, "HOME" }, + { GLFW_KEY_END, "END" }, + { GLFW_KEY_CAPS_LOCK, "CAPS_LOCK" }, + { GLFW_KEY_SCROLL_LOCK, "SCROLL_LOCK" }, + { GLFW_KEY_NUM_LOCK, "NUM_LOCK" }, + { GLFW_KEY_PRINT_SCREEN, "PRINT_SCREEN" }, + { GLFW_KEY_PAUSE, "PAUSE" }, + { GLFW_KEY_F1, "F1" }, + { GLFW_KEY_F2, "F2" }, + { GLFW_KEY_F3, "F3" }, + { GLFW_KEY_F4, "F4" }, + { GLFW_KEY_F5, "F5" }, + { GLFW_KEY_F6, "F6" }, + { GLFW_KEY_F7, "F7" }, + { GLFW_KEY_F8, "F8" }, + { GLFW_KEY_F9, "F9" }, + { GLFW_KEY_F10, "F10" }, + { GLFW_KEY_F11, "F11" }, + { GLFW_KEY_F12, "F12" }, + { GLFW_KEY_F13, "F13" }, + { GLFW_KEY_F14, "F14" }, + { GLFW_KEY_F15, "F15" }, + { GLFW_KEY_F16, "F16" }, + { GLFW_KEY_F17, "F17" }, + { GLFW_KEY_F18, "F18" }, + { GLFW_KEY_F19, "F19" }, + { GLFW_KEY_F20, "F20" }, + { GLFW_KEY_F21, "F21" }, + { GLFW_KEY_F22, "F22" }, + { GLFW_KEY_F23, "F23" }, + { GLFW_KEY_F24, "F24" }, + { GLFW_KEY_F25, "F25" }, + { GLFW_KEY_KP_0, "KEYPAD_0" }, + { GLFW_KEY_KP_1, "KEYPAD_1" }, + { GLFW_KEY_KP_2, "KEYPAD_2" }, + { GLFW_KEY_KP_3, "KEYPAD_3" }, + { GLFW_KEY_KP_4, "KEYPAD_4" }, + { GLFW_KEY_KP_5, "KEYPAD_5" }, + { GLFW_KEY_KP_6, "KEYPAD_6" }, + { GLFW_KEY_KP_7, "KEYPAD_7" }, + { GLFW_KEY_KP_8, "KEYPAD_8" }, + { GLFW_KEY_KP_9, "KEYPAD_9" }, + { GLFW_KEY_KP_DECIMAL, "KEYPAD_POINT" }, + { GLFW_KEY_KP_DIVIDE, "KEYPAD_DIV" }, + { GLFW_KEY_KP_MULTIPLY, "KEYPAD_MUL" }, + { GLFW_KEY_KP_SUBTRACT, "KEYPAD_MINUS" }, + { GLFW_KEY_KP_ADD, "KEYPAD_PLUS" }, + { GLFW_KEY_KP_ENTER, "KEYPAD_ENTER" }, + { GLFW_KEY_KP_EQUAL, "KEYPAD_EQUAL" }, + { GLFW_KEY_LEFT_SHIFT, "LEFT_SHIFT" }, + { GLFW_KEY_LEFT_CONTROL, "LEFT_CTRL" }, + { GLFW_KEY_LEFT_ALT, "LEFT_ALT" }, + { GLFW_KEY_LEFT_SUPER, "LEFT_SUPER" }, + { GLFW_KEY_RIGHT_SHIFT, "RIGHT_SHIFT" }, + { GLFW_KEY_RIGHT_CONTROL, "RIGHT_CTRL" }, + { GLFW_KEY_RIGHT_ALT, "RIGHT_ALT" }, + { GLFW_KEY_RIGHT_SUPER, "RIGHT_SUPER" }, + { GLFW_KEY_MENU, "MENU" }, }; -static const char *get_key_name(int keycode) +static const char* get_key_name(int keycode) { - for(const auto &it : key_names) { - if(it.first != keycode) - continue; - return it.second; + for(const auto& it : key_names) { + if(it.first == keycode) { + return it.second; + } } return UNKNOWN_KEY_NAME; @@ -152,16 +153,15 @@ ConfigKeyBind::ConfigKeyBind(int default_value) if(default_value == DEBUG_KEY) { m_glfw_keycode = GLFW_KEY_UNKNOWN; m_name = UNKNOWN_KEY_NAME; - } - else { + } else { m_glfw_keycode = default_value; m_name = get_key_name(default_value); } } -void ConfigKeyBind::set(const char *value) +void ConfigKeyBind::set(const char* value) { - for(const auto &it : key_names) { + for(const auto& it : key_names) { if((it.first != DEBUG_KEY) && !std::strcmp(it.second, value)) { m_glfw_keycode = it.first; m_name = it.second; @@ -173,7 +173,7 @@ void ConfigKeyBind::set(const char *value) m_name = UNKNOWN_KEY_NAME; } -const char *ConfigKeyBind::get(void) const +const char* ConfigKeyBind::get(void) const { return m_name; } @@ -183,8 +183,7 @@ void ConfigKeyBind::set_key(int keycode) if(keycode == DEBUG_KEY) { m_glfw_keycode = GLFW_KEY_UNKNOWN; m_name = UNKNOWN_KEY_NAME; - } - else { + } else { m_glfw_keycode = keycode; m_name = get_key_name(keycode); } diff --git a/game/client/keybind.hh b/game/client/keybind.hh index d8e27a7..8cf3c3c 100644 --- a/game/client/keybind.hh +++ b/game/client/keybind.hh @@ -10,8 +10,8 @@ public: explicit ConfigKeyBind(int default_value); virtual ~ConfigKeyBind(void) = default; - virtual void set(const char *value) override; - virtual const char *get(void) const override; + virtual void set(const char* value) override; + virtual const char* get(void) const override; void set_key(int keycode); int get_key(void) const; @@ -19,7 +19,7 @@ public: bool equals(int keycode) const; private: - const char *m_name; + const char* m_name; int m_glfw_keycode; }; diff --git a/game/client/language.cc b/game/client/language.cc index 1b1f751..2d84996 100644 --- a/game/client/language.cc +++ b/game/client/language.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/language.hh" #include "core/config.hh" @@ -6,13 +7,13 @@ #include "client/globals.hh" #include "client/settings.hh" -constexpr static const char *DEFAULT_LANGUAGE = "en_US"; +constexpr static const char* DEFAULT_LANGUAGE = "en_US"; // Available languages are kept in a special manifest file which // is essentially a key-value map of semi-IETF-compliant language tags // and the language's endonym; after reading the manifest, the translation // system knows what language it can load and will act accordingly -constexpr static const char *MANIFEST_PATH = "lang/manifest.json"; +constexpr static const char* MANIFEST_PATH = "lang/manifest.json"; static LanguageManifest manifest; static LanguageIterator current_language; @@ -130,7 +131,7 @@ void language::set(LanguageIterator new_language) } language_map.clear(); - + for(size_t i = 0; i < count; ++i) { const auto key = json_object_get_name(json, i); const auto value = json_object_get_value_at(json, i); @@ -156,12 +157,14 @@ LanguageIterator language::get_current(void) return current_language; } -LanguageIterator language::find(const char *ietf) +LanguageIterator language::find(const char* ietf) { const auto it = ietf_map.find(ietf); - if(it != ietf_map.cend()) + if(it != ietf_map.cend()) { return it->second; - return manifest.cend(); + } else { + return manifest.cend(); + } } LanguageIterator language::cbegin(void) @@ -174,15 +177,17 @@ LanguageIterator language::cend(void) return manifest.cend(); } -const char *language::resolve(const char *key) +const char* language::resolve(const char* key) { const auto it = language_map.find(key); - if(it != language_map.cend()) + if(it != language_map.cend()) { return it->second.c_str(); - return key; + } else { + return key; + } } -std::string language::resolve_gui(const char *key) +std::string language::resolve_gui(const char* key) { // We need window tags to retain their hierarchy when a language // dynamically changes; ImGui allows to provide hidden unique identifiers diff --git a/game/client/language.hh b/game/client/language.hh index c9dfa84..680cd92 100644 --- a/game/client/language.hh +++ b/game/client/language.hh @@ -5,7 +5,7 @@ struct LanguageInfo final { std::string endonym; // Language's self-name std::string display; // Display for the settings GUI - std::string ietf; // Semi-compliant language abbreviation + std::string ietf; // Semi-compliant language abbreviation }; using LanguageManifest = std::vector; @@ -29,15 +29,15 @@ void set(LanguageIterator new_language); namespace language { LanguageIterator get_current(void); -LanguageIterator find(const char *ietf); +LanguageIterator find(const char* ietf); LanguageIterator cbegin(void); LanguageIterator cend(void); } // namespace language namespace language { -const char *resolve(const char *key); -std::string resolve_gui(const char *key); +const char* resolve(const char* key); +std::string resolve_gui(const char* key); } // namespace language #endif /* CLIENT_LANGUAGE_HH */ diff --git a/game/client/listener.cc b/game/client/listener.cc index f56c7d6..76a7bac 100644 --- a/game/client/listener.cc +++ b/game/client/listener.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/listener.hh" #include "core/config.hh" @@ -16,8 +17,8 @@ void listener::update(void) { if(session::is_ingame()) { - const auto &velocity = globals::dimension->entities.get(globals::player).value; - const auto &position = camera::position_local; + const auto& velocity = globals::dimension->entities.get(globals::player).value; + const auto& position = camera::position_local; alListener3f(AL_POSITION, position.x, position.y, position.z); alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z); diff --git a/game/client/main.cc b/game/client/main.cc index e7fdc3b..3ed28ea 100644 --- a/game/client/main.cc +++ b/game/client/main.cc @@ -26,22 +26,22 @@ extern "C" __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; extern "C" __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; #endif -static void on_glfw_error(int code, const char *message) +static void on_glfw_error(int code, const char* message) { spdlog::error("glfw: {}", message); } -static void on_glfw_char(GLFWwindow *window, unsigned int codepoint) +static void on_glfw_char(GLFWwindow* window, unsigned int codepoint) { ImGui_ImplGlfw_CharCallback(window, codepoint); } -static void on_glfw_cursor_enter(GLFWwindow *window, int entered) +static void on_glfw_cursor_enter(GLFWwindow* window, int entered) { ImGui_ImplGlfw_CursorEnterCallback(window, entered); } -static void on_glfw_cursor_pos(GLFWwindow *window, double xpos, double ypos) +static void on_glfw_cursor_pos(GLFWwindow* window, double xpos, double ypos) { GlfwCursorPosEvent event; event.pos.x = static_cast(xpos); @@ -51,7 +51,7 @@ static void on_glfw_cursor_pos(GLFWwindow *window, double xpos, double ypos) ImGui_ImplGlfw_CursorPosCallback(window, xpos, ypos); } -static void on_glfw_framebuffer_size(GLFWwindow *window, int width, int height) +static void on_glfw_framebuffer_size(GLFWwindow* window, int width, int height) { if(glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { // Don't do anything if the window was just @@ -59,7 +59,7 @@ static void on_glfw_framebuffer_size(GLFWwindow *window, int width, int height) // windows on WIN32 seem to be forced into 0x0 return; } - + globals::width = width; globals::height = height; globals::aspect = static_cast(width) / static_cast(height); @@ -71,7 +71,7 @@ static void on_glfw_framebuffer_size(GLFWwindow *window, int width, int height) globals::dispatcher.trigger(fb_event); } -static void on_glfw_key(GLFWwindow *window, int key, int scancode, int action, int mods) +static void on_glfw_key(GLFWwindow* window, int key, int scancode, int action, int mods) { GlfwKeyEvent event; event.key = key; @@ -91,12 +91,12 @@ static void on_glfw_joystick(int joystick_id, int event_type) globals::dispatcher.trigger(event); } -static void on_glfw_monitor_event(GLFWmonitor *monitor, int event) +static void on_glfw_monitor_event(GLFWmonitor* monitor, int event) { ImGui_ImplGlfw_MonitorCallback(monitor, event); } -static void on_glfw_mouse_button(GLFWwindow *window, int button, int action, int mods) +static void on_glfw_mouse_button(GLFWwindow* window, int button, int action, int mods) { GlfwMouseButtonEvent event; event.button = button; @@ -107,7 +107,7 @@ static void on_glfw_mouse_button(GLFWwindow *window, int button, int action, int ImGui_ImplGlfw_MouseButtonCallback(window, button, action, mods); } -static void on_glfw_scroll(GLFWwindow *window, double dx, double dy) +static void on_glfw_scroll(GLFWwindow* window, double dx, double dy) { GlfwScrollEvent event; event.dx = static_cast(dx); @@ -117,14 +117,14 @@ static void on_glfw_scroll(GLFWwindow *window, double dx, double dy) ImGui_ImplGlfw_ScrollCallback(window, dx, dy); } -static void on_glfw_window_focus(GLFWwindow *window, int focused) +static void on_glfw_window_focus(GLFWwindow* window, int focused) { ImGui_ImplGlfw_WindowFocusCallback(window, focused); } -static void GLAD_API_PTR on_opengl_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *param) +static void GLAD_API_PTR on_opengl_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* param) { - spdlog::info("opengl: {}", reinterpret_cast(message)); + spdlog::info("opengl: {}", reinterpret_cast(message)); } static void on_termination_signal(int) @@ -133,7 +133,7 @@ static void on_termination_signal(int) glfwSetWindowShouldClose(globals::window, true); } -int main(int argc, char **argv) +int main(int argc, char** argv) { cmdline::create(argc, argv); @@ -205,19 +205,17 @@ int main(int argc, char **argv) // information about buffer usage into the debug callback static const std::uint32_t ignore_nvidia_131185 = 131185; glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_OTHER, GL_DONT_CARE, 1, &ignore_nvidia_131185, GL_FALSE); - } - else { + } else { spdlog::warn("glad: nodebug command line parameter found"); spdlog::warn("glad: OpenGL errors will not be logged"); } - } - else { + } else { spdlog::warn("glad: KHR_debug extension not supported"); spdlog::warn("glad: OpenGL errors will not be logged"); } - spdlog::info("opengl: version: {}", reinterpret_cast(glGetString(GL_VERSION))); - spdlog::info("opengl: renderer: {}", reinterpret_cast(glGetString(GL_RENDERER))); + spdlog::info("opengl: version: {}", reinterpret_cast(glGetString(GL_VERSION))); + spdlog::info("opengl: renderer: {}", reinterpret_cast(glGetString(GL_RENDERER))); glDisable(GL_MULTISAMPLE); @@ -231,7 +229,7 @@ int main(int argc, char **argv) // constants. However, UI scale of 1 doesn't look that good, so the window size is // limited to a resolution that allows at least UI scale of 2 and is defined by MIN_WIDTH and MIN_HEIGHT. glfwSetWindowSizeLimits(globals::window, MIN_WIDTH, MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE); - + glfwSetCharCallback(globals::window, &on_glfw_char); glfwSetCursorEnterCallback(globals::window, &on_glfw_cursor_enter); glfwSetCursorPosCallback(globals::window, &on_glfw_cursor_pos); @@ -248,7 +246,7 @@ int main(int argc, char **argv) GLFWimage icon_image; icon_image.width = image->size.x; icon_image.height = image->size.y; - icon_image.pixels = reinterpret_cast(image->pixels); + icon_image.pixels = reinterpret_cast(image->pixels); glfwSetWindowIcon(globals::window, 1, &icon_image); } @@ -256,22 +254,19 @@ int main(int argc, char **argv) spdlog::warn("client: sound disabled [per command line]"); globals::sound_dev = nullptr; globals::sound_ctx = nullptr; - } - else { + } else { if(!saladLoadALdefault()) { spdlog::warn("client: sound disabled [openal loading failed]"); globals::sound_dev = nullptr; globals::sound_ctx = nullptr; - } - else { + } else { globals::sound_dev = alcOpenDevice(nullptr); if(globals::sound_dev == nullptr) { spdlog::warn("client: sound disabled [no device]"); globals::sound_ctx = nullptr; - } - else { - spdlog::info("sound: {}", reinterpret_cast(alcGetString(globals::sound_dev, ALC_DEVICE_SPECIFIER))); + } else { + spdlog::info("sound: {}", reinterpret_cast(alcGetString(globals::sound_dev, ALC_DEVICE_SPECIFIER))); globals::sound_ctx = alcCreateContext(globals::sound_dev, nullptr); @@ -279,8 +274,7 @@ int main(int argc, char **argv) spdlog::warn("client: sound disabled [context creation failed]"); alcCloseDevice(globals::sound_dev); globals::sound_dev = nullptr; - } - else { + } else { alcMakeContextCurrent(globals::sound_ctx); } } @@ -291,7 +285,7 @@ int main(int argc, char **argv) window_title::update(); - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableGamepad; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; @@ -344,13 +338,12 @@ int main(int argc, char **argv) if(globals::fixed_frametime_us == UINT64_MAX) { globals::fixed_framecount = 0; globals::fixed_accumulator = 0; - } - else { + } else { globals::fixed_accumulator += globals::window_frametime_us; globals::fixed_framecount = globals::fixed_accumulator / globals::fixed_frametime_us; globals::fixed_accumulator %= globals::fixed_frametime_us; } - + globals::num_drawcalls = 0; globals::num_triangles = 0; @@ -363,16 +356,16 @@ int main(int argc, char **argv) ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - + glDisable(GL_BLEND); - + glDisable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, globals::width, globals::height); - + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - + // Make sure there is no stray program object // being bound to the context. Usually third-party // overlay software (such as RivaTuner) injects itself @@ -406,7 +399,7 @@ int main(int argc, char **argv) resource::soft_cleanup(); resource::soft_cleanup(); - + resource::soft_cleanup(); resource::soft_cleanup(); @@ -414,13 +407,13 @@ int main(int argc, char **argv) } client_game::deinit(); - + resource::hard_cleanup(); resource::hard_cleanup(); resource::hard_cleanup(); resource::hard_cleanup(); - + spdlog::info("client: shutdown after {} frames", globals::window_framecount); spdlog::info("client: average framerate: {:.03f} FPS", 1.0f / globals::window_frametime_avg); spdlog::info("client: average frametime: {:.03f} ms", 1000.0f * globals::window_frametime_avg); @@ -429,7 +422,7 @@ int main(int argc, char **argv) ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - if(globals::sound_ctx){ + if(globals::sound_ctx) { alcMakeContextCurrent(nullptr); alcDestroyContext(globals::sound_ctx); alcCloseDevice(globals::sound_dev); diff --git a/game/client/main_menu.cc b/game/client/main_menu.cc index b1c9821..55a8021 100644 --- a/game/client/main_menu.cc +++ b/game/client/main_menu.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/main_menu.hh" #include "core/constexpr.hh" @@ -24,7 +25,7 @@ static std::string str_quit; static resource_ptr title; static float title_aspect; -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if(session::is_ingame() && (event.key == GLFW_KEY_ESCAPE) && (event.action == GLFW_PRESS)) { if(globals::gui_screen == GUI_SCREEN_NONE) { @@ -39,7 +40,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) } } -static void on_language_set(const LanguageSetEvent &event) +static void on_language_set(const LanguageSetEvent& event) { str_play = language::resolve_gui("main_menu.play"); str_resume = language::resolve_gui("main_menu.resume"); @@ -57,9 +58,11 @@ void main_menu::init(void) std::terminate(); } - if(title->size.x > title->size.y) + if(title->size.x > title->size.y) { title_aspect = static_cast(title->size.x) / static_cast(title->size.y); - else title_aspect = static_cast(title->size.y) / static_cast(title->size.x); + } else { + title_aspect = static_cast(title->size.y) / static_cast(title->size.x); + } globals::dispatcher.sink().connect<&on_glfw_key>(); globals::dispatcher.sink().connect<&on_language_set>(); @@ -84,8 +87,7 @@ void main_menu::layout(void) if(session::is_ingame()) { ImGui::Dummy(ImVec2(0.0f, 32.0f * globals::gui_scale)); - } - else { + } else { auto reference_height = 0.225f * window_size.y; auto image_width = cxpr::min(window_size.x, reference_height * title_aspect); auto image_height = image_width / title_aspect; @@ -100,20 +102,28 @@ void main_menu::layout(void) if(session::is_ingame()) { ImGui::SetCursorPosX(button_xpos); - if(ImGui::Button(str_resume.c_str(), ImVec2(button_width, 0.0f))) + + if(ImGui::Button(str_resume.c_str(), ImVec2(button_width, 0.0f))) { globals::gui_screen = GUI_SCREEN_NONE; + } + ImGui::Spacing(); - } - else { + } else { ImGui::SetCursorPosX(button_xpos); - if(ImGui::Button(str_play.c_str(), ImVec2(button_width, 0.0f))) + + if(ImGui::Button(str_play.c_str(), ImVec2(button_width, 0.0f))) { globals::gui_screen = GUI_PLAY_MENU; + } + ImGui::Spacing(); } ImGui::SetCursorPosX(button_xpos); - if(ImGui::Button(str_settings.c_str(), ImVec2(button_width, 0.0f))) + + if(ImGui::Button(str_settings.c_str(), ImVec2(button_width, 0.0f))) { globals::gui_screen = GUI_SETTINGS; + } + ImGui::Spacing(); if(session::is_ingame()) { @@ -126,17 +136,19 @@ void main_menu::layout(void) } ImGui::Spacing(); - } - else { + } else { ImGui::SetCursorPosX(button_xpos); - if(ImGui::Button(str_quit.c_str(), ImVec2(button_width, 0.0f))) + + if(ImGui::Button(str_quit.c_str(), ImVec2(button_width, 0.0f))) { glfwSetWindowShouldClose(globals::window, true); - ImGui::Spacing(); + } + + ImGui::Spacing(); } if(!session::is_ingame()) { - const auto &padding = ImGui::GetStyle().FramePadding; - const auto &spacing = ImGui::GetStyle().ItemSpacing; + const auto& padding = ImGui::GetStyle().FramePadding; + const auto& spacing = ImGui::GetStyle().ItemSpacing; ImGui::PushFont(globals::font_debug); ImGui::SetCursorScreenPos(ImVec2(padding.x + spacing.x, window_size.y - globals::font_debug->FontSize - padding.y - spacing.y)); diff --git a/game/client/message_box.cc b/game/client/message_box.cc index b79d67e..e103e80 100644 --- a/game/client/message_box.cc +++ b/game/client/message_box.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/message_box.hh" #include "client/globals.hh" @@ -34,7 +35,7 @@ void message_box::layout(void) if(ImGui::Begin("###UIProgress", nullptr, WINDOW_FLAGS)) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 1.0f * globals::gui_scale)); - + const float title_width = ImGui::CalcTextSize(str_title.c_str()).x; ImGui::SetCursorPosX(0.5f * (window_size.x - title_width)); ImGui::TextUnformatted(str_title.c_str()); @@ -49,14 +50,14 @@ void message_box::layout(void) ImGui::Dummy(ImVec2(0.0f, 32.0f * globals::gui_scale)); - for(const auto &button : buttons) { + for(const auto& button : buttons) { const float button_width = 0.8f * ImGui::CalcItemWidth(); ImGui::SetCursorPosX(0.5f * (window_size.x - button_width)); if(ImGui::Button(button.str_title.c_str(), ImVec2(button_width, 0.0f))) { - if(!button.action) - continue; - button.action(); + if(button.action) { + button.action(); + } } } @@ -73,17 +74,17 @@ void message_box::reset(void) buttons.clear(); } -void message_box::set_title(const char *title) +void message_box::set_title(const char* title) { str_title = language::resolve(title); } -void message_box::set_subtitle(const char *subtitle) +void message_box::set_subtitle(const char* subtitle) { str_subtitle = language::resolve(subtitle); } -void message_box::add_button(const char *text, const message_box_action &action) +void message_box::add_button(const char* text, const message_box_action& action) { Button button = {}; button.str_title = fmt::format("{}###MessageBox_Button{}", language::resolve(text), buttons.size()); diff --git a/game/client/message_box.hh b/game/client/message_box.hh index 6b50c71..7ea2466 100644 --- a/game/client/message_box.hh +++ b/game/client/message_box.hh @@ -2,7 +2,7 @@ #define CLIENT_MESSAGE_BOX_HH 1 #pragma once -using message_box_action = void(*)(void); +using message_box_action = void (*)(void); namespace message_box { @@ -13,9 +13,9 @@ void reset(void); namespace message_box { -void set_title(const char *title); -void set_subtitle(const char *subtitle); -void add_button(const char *text, const message_box_action &action); +void set_title(const char* title); +void set_subtitle(const char* subtitle); +void add_button(const char* text, const message_box_action& action); } // namespace message_box #endif /* CLIENT_MESSAGE_BOX_HH */ diff --git a/game/client/metrics.cc b/game/client/metrics.cc index 143efe5..3d3c2b4 100644 --- a/game/client/metrics.cc +++ b/game/client/metrics.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/metrics.hh" #include "core/feature.hh" @@ -64,18 +65,18 @@ void metrics::layout(void) position.y += y_step; // Draw OpenGL version string - auto r_version_line = fmt::format("GL_VERSION: {}", reinterpret_cast(r_version.c_str())); + auto r_version_line = fmt::format("GL_VERSION: {}", reinterpret_cast(r_version.c_str())); imdraw_ext::text_shadow(r_version_line, position, text_color, shadow_color, globals::font_debug, draw_list); position.y += y_step; // Draw OpenGL renderer string - auto r_renderer_line = fmt::format("GL_RENDERER: {}", reinterpret_cast(r_renderer.c_str())); + auto r_renderer_line = fmt::format("GL_RENDERER: {}", reinterpret_cast(r_renderer.c_str())); imdraw_ext::text_shadow(r_renderer_line, position, text_color, shadow_color, globals::font_debug, draw_list); position.y += 1.5f * y_step; - const auto &head = globals::dimension->entities.get(globals::player); - const auto &transform = globals::dimension->entities.get(globals::player); - const auto &velocity = globals::dimension->entities.get(globals::player); + const auto& head = globals::dimension->entities.get(globals::player); + const auto& transform = globals::dimension->entities.get(globals::player); + const auto& velocity = globals::dimension->entities.get(globals::player); // Draw player voxel position auto voxel_position = coord::to_voxel(transform.chunk, transform.local); @@ -84,9 +85,8 @@ void metrics::layout(void) position.y += y_step; // Draw player world position - auto world_line = fmt::format("world: [{} {} {}] [{:.03f} {:.03f} {:.03f}]", - transform.chunk.x, transform.chunk.y, transform.chunk.z, - transform.local.x, transform.local.y, transform.local.z); + auto world_line = fmt::format( + "world: [{} {} {}] [{:.03f} {:.03f} {:.03f}]", transform.chunk.x, transform.chunk.y, transform.chunk.z, transform.local.x, transform.local.y, transform.local.z); imdraw_ext::text_shadow(world_line, position, text_color, shadow_color, globals::font_debug, draw_list); position.y += y_step; diff --git a/game/client/outline.cc b/game/client/outline.cc index 9105c8c..31a6bd9 100644 --- a/game/client/outline.cc +++ b/game/client/outline.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/outline.hh" #include "core/config.hh" @@ -39,20 +40,32 @@ void outline::init(void) u_scale = program.add_uniform("u_Scale"); const glm::fvec3 cube_vertices[24] = { - glm::fvec3(0.0f, 0.0f, 0.0f), glm::fvec3(0.0f, 1.0f, 0.0f), - glm::fvec3(0.0f, 1.0f, 0.0f), glm::fvec3(1.0f, 1.0f, 0.0f), - glm::fvec3(1.0f, 1.0f, 0.0f), glm::fvec3(1.0f, 0.0f, 0.0f), - glm::fvec3(1.0f, 0.0f, 0.0f), glm::fvec3(0.0f, 0.0f, 0.0f), - - glm::fvec3(0.0f, 0.0f, 1.0f), glm::fvec3(0.0f, 1.0f, 1.0f), - glm::fvec3(0.0f, 1.0f, 1.0f), glm::fvec3(1.0f, 1.0f, 1.0f), - glm::fvec3(1.0f, 1.0f, 1.0f), glm::fvec3(1.0f, 0.0f, 1.0f), - glm::fvec3(1.0f, 0.0f, 1.0f), glm::fvec3(0.0f, 0.0f, 1.0f), - - glm::fvec3(0.0f, 0.0f, 0.0f), glm::fvec3(0.0f, 0.0f, 1.0f), - glm::fvec3(0.0f, 1.0f, 0.0f), glm::fvec3(0.0f, 1.0f, 1.0f), - glm::fvec3(1.0f, 0.0f, 0.0f), glm::fvec3(1.0f, 0.0f, 1.0f), - glm::fvec3(1.0f, 1.0f, 0.0f), glm::fvec3(1.0f, 1.0f, 1.0f), + glm::fvec3(0.0f, 0.0f, 0.0f), + glm::fvec3(0.0f, 1.0f, 0.0f), + glm::fvec3(0.0f, 1.0f, 0.0f), + glm::fvec3(1.0f, 1.0f, 0.0f), + glm::fvec3(1.0f, 1.0f, 0.0f), + glm::fvec3(1.0f, 0.0f, 0.0f), + glm::fvec3(1.0f, 0.0f, 0.0f), + glm::fvec3(0.0f, 0.0f, 0.0f), + + glm::fvec3(0.0f, 0.0f, 1.0f), + glm::fvec3(0.0f, 1.0f, 1.0f), + glm::fvec3(0.0f, 1.0f, 1.0f), + glm::fvec3(1.0f, 1.0f, 1.0f), + glm::fvec3(1.0f, 1.0f, 1.0f), + glm::fvec3(1.0f, 0.0f, 1.0f), + glm::fvec3(1.0f, 0.0f, 1.0f), + glm::fvec3(0.0f, 0.0f, 1.0f), + + glm::fvec3(0.0f, 0.0f, 0.0f), + glm::fvec3(0.0f, 0.0f, 1.0f), + glm::fvec3(0.0f, 1.0f, 0.0f), + glm::fvec3(0.0f, 1.0f, 1.0f), + glm::fvec3(1.0f, 0.0f, 0.0f), + glm::fvec3(1.0f, 0.0f, 1.0f), + glm::fvec3(1.0f, 1.0f, 0.0f), + glm::fvec3(1.0f, 1.0f, 1.0f), }; glGenBuffers(1, &cube_vbo); @@ -104,7 +117,7 @@ void outline::prepare(void) glVertexAttribDivisor(0, 0); } -void outline::cube(const chunk_pos &cpos, const glm::fvec3 &fpos, const glm::fvec3 &size, float thickness, const glm::fvec4 &color) +void outline::cube(const chunk_pos& cpos, const glm::fvec3& fpos, const glm::fvec3& size, float thickness, const glm::fvec4& color) { auto patch_cpos = cpos - camera::position_chunk; @@ -119,7 +132,7 @@ void outline::cube(const chunk_pos &cpos, const glm::fvec3 &fpos, const glm::fve glDrawArrays(GL_LINES, 0, 24); } -void outline::line(const chunk_pos &cpos, const glm::fvec3 &fpos, const glm::fvec3 &size, float thickness, const glm::fvec4 &color) +void outline::line(const chunk_pos& cpos, const glm::fvec3& fpos, const glm::fvec3& size, float thickness, const glm::fvec4& color) { auto patch_cpos = cpos - camera::position_chunk; diff --git a/game/client/outline.hh b/game/client/outline.hh index 7dc347c..a7789b2 100644 --- a/game/client/outline.hh +++ b/game/client/outline.hh @@ -13,8 +13,8 @@ void prepare(void); namespace outline { -void cube(const chunk_pos &cpos, const glm::fvec3 &fpos, const glm::fvec3 &size, float thickness, const glm::fvec4 &color); -void line(const chunk_pos &cpos, const glm::fvec3 &fpos, const glm::fvec3 &size, float thickness, const glm::fvec4 &color); +void cube(const chunk_pos& cpos, const glm::fvec3& fpos, const glm::fvec3& size, float thickness, const glm::fvec4& color); +void line(const chunk_pos& cpos, const glm::fvec3& fpos, const glm::fvec3& size, float thickness, const glm::fvec4& color); } // namespace outline #endif /* CLIENT_OUTLINE_HH */ diff --git a/game/client/play_menu.cc b/game/client/play_menu.cc index 7ded71a..e6b8d2c 100644 --- a/game/client/play_menu.cc +++ b/game/client/play_menu.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/play_menu.hh" #include "core/config.hh" @@ -16,9 +17,9 @@ #include "client/session.hh" constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration; -constexpr static const char *DEFAULT_SERVER_NAME = "Voxelius Server"; -constexpr static const char *SERVERS_TXT = "servers.txt"; -constexpr static const char *WARNING_TOAST = "[!]"; +constexpr static const char* DEFAULT_SERVER_NAME = "Voxelius Server"; +constexpr static const char* SERVERS_TXT = "servers.txt"; +constexpr static const char* WARNING_TOAST = "[!]"; constexpr static std::size_t MAX_SERVER_ITEM_NAME = 24; @@ -34,13 +35,13 @@ struct ServerStatusItem final { std::string password; std::string hostname; std::uint16_t port; - + // Things pulled from bother events std::uint32_t protocol_version; std::uint16_t num_players; std::uint16_t max_players; std::string motd; - + // Unique identifier that monotonically // grows with each new server added and // doesn't reset with each server removed @@ -70,23 +71,27 @@ static std::string input_hostname; static std::string input_password; static unsigned int next_identity; -static std::deque servers_deque; -static ServerStatusItem *selected_server; +static std::deque servers_deque; +static ServerStatusItem* selected_server; static bool editing_server; static bool adding_server; static bool needs_focus; -static void parse_hostname(ServerStatusItem *item, const std::string &hostname) +static void parse_hostname(ServerStatusItem* item, const std::string& hostname) { auto parts = strtools::split(hostname, ":"); - if(!parts[0].empty()) + if(!parts[0].empty()) { item->hostname = parts[0]; - else item->hostname = std::string("localhost"); + } else { + item->hostname = std::string("localhost"); + } - if(parts.size() >= 2) + if(parts.size() >= 2) { item->port = cxpr::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); - else item->port = protocol::PORT; + } else { + item->port = protocol::PORT; + } } static void add_new_server(void) @@ -116,9 +121,11 @@ static void edit_selected_server(void) { input_itemname = selected_server->name; - if(selected_server->port != protocol::PORT) + if(selected_server->port != protocol::PORT) { input_hostname = fmt::format("{}:{}", selected_server->hostname, selected_server->port); - else input_hostname = selected_server->hostname; + } else { + input_hostname = selected_server->hostname; + } input_password = selected_server->password; @@ -142,24 +149,26 @@ static void remove_selected_server(void) static void join_selected_server(void) { - if(session::peer) - return; - session::connect(selected_server->hostname.c_str(), selected_server->port, selected_server->password.c_str()); + if(!session::peer) { + session::connect(selected_server->hostname.c_str(), selected_server->port, selected_server->password.c_str()); + } } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if((event.key == GLFW_KEY_ESCAPE) && (event.action == GLFW_PRESS)) { if(globals::gui_screen == GUI_PLAY_MENU) { if(editing_server) { - if(adding_server) + if(adding_server) { remove_selected_server(); - input_itemname.clear(); - input_hostname.clear(); - input_password.clear(); - editing_server = false; - adding_server = false; - return; + } else { + input_itemname.clear(); + input_hostname.clear(); + input_password.clear(); + editing_server = false; + adding_server = false; + return; + } } globals::gui_screen = GUI_MAIN_MENU; @@ -169,7 +178,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) } } -static void on_language_set(const LanguageSetEvent &event) +static void on_language_set(const LanguageSetEvent& event) { str_tab_servers = language::resolve_gui("play_menu.tab.servers"); @@ -188,7 +197,7 @@ static void on_language_set(const LanguageSetEvent &event) str_outdated_server = language::resolve("play_menu.outdated_server"); } -static void on_bother_response(const BotherResponseEvent &event) +static void on_bother_response(const BotherResponseEvent& event) { for(auto item : servers_deque) { if(item->identity == event.identity) { @@ -198,8 +207,7 @@ static void on_bother_response(const BotherResponseEvent &event) item->max_players = UINT16_MAX; item->motd = str_status_fail; item->status = item_status::FAILURE; - } - else { + } else { item->protocol_version = event.protocol_version; item->num_players = event.num_players; item->max_players = event.max_players; @@ -212,16 +220,16 @@ static void on_bother_response(const BotherResponseEvent &event) } } -static void layout_server_item(ServerStatusItem *item) +static void layout_server_item(ServerStatusItem* item) { // Preserve the cursor at which we draw stuff - const ImVec2 &cursor = ImGui::GetCursorScreenPos(); - const ImVec2 &padding = ImGui::GetStyle().FramePadding; - const ImVec2 &spacing = ImGui::GetStyle().ItemSpacing; + const ImVec2& cursor = ImGui::GetCursorScreenPos(); + const ImVec2& padding = ImGui::GetStyle().FramePadding; + const ImVec2& spacing = ImGui::GetStyle().ItemSpacing; const float item_width = ImGui::GetContentRegionAvail().x; const float line_height = ImGui::GetTextLineHeightWithSpacing(); - const std::string sid = fmt::format("###play_menu.servers.{}", static_cast(item)); + const std::string sid = fmt::format("###play_menu.servers.{}", static_cast(item)); if(ImGui::Selectable(sid.c_str(), (item == selected_server), 0, ImVec2(0.0, 2.0f * (line_height + padding.y + spacing.y)))) { selected_server = item; editing_server = false; @@ -232,7 +240,7 @@ static void layout_server_item(ServerStatusItem *item) join_selected_server(); } - ImDrawList *draw_list = ImGui::GetWindowDrawList(); + ImDrawList* draw_list = ImGui::GetWindowDrawList(); if(item == selected_server) { const ImVec2 start = ImVec2(cursor.x, cursor.y); @@ -257,16 +265,20 @@ static void layout_server_item(ServerStatusItem *item) if(ImGui::IsMouseHoveringRect(warning_pos, warning_end)) { ImGui::BeginTooltip(); - if(item->protocol_version < protocol::VERSION) + + if(item->protocol_version < protocol::VERSION) { ImGui::TextUnformatted(str_outdated_server.c_str(), str_outdated_server.c_str() + str_outdated_server.size()); - else ImGui::TextUnformatted(str_outdated_client.c_str(), str_outdated_client.c_str() + str_outdated_client.size()); + } else { + ImGui::TextUnformatted(str_outdated_client.c_str(), str_outdated_client.c_str() + str_outdated_client.size()); + } + ImGui::EndTooltip(); } } } ImU32 motd_color = {}; - const std::string *motd_text; + const std::string* motd_text; switch(item->status) { case item_status::UNKNOWN: @@ -291,7 +303,7 @@ static void layout_server_item(ServerStatusItem *item) draw_list->AddText(motd_pos, motd_color, motd_text->c_str(), motd_text->c_str() + motd_text->size()); } -static void layout_server_edit(ServerStatusItem *item) +static void layout_server_edit(ServerStatusItem* item) { if(needs_focus) { ImGui::SetKeyboardFocusHere(); @@ -341,12 +353,14 @@ static void layout_server_edit(ServerStatusItem *item) static void layout_servers(void) { if(ImGui::BeginListBox("###play_menu.servers.listbox", ImVec2(-1.0f, -1.0f))) { - for(ServerStatusItem *item : servers_deque) { - if(editing_server && (item == selected_server)) + for(ServerStatusItem* item : servers_deque) { + if(editing_server && item == selected_server) { layout_server_edit(item); - else layout_server_item(item); + } else { + layout_server_item(item); + } } - + ImGui::EndListBox(); } } @@ -357,45 +371,60 @@ static void layout_servers_buttons(void) // Can only join when selected and not editing ImGui::BeginDisabled(!selected_server || editing_server); - if(ImGui::Button(str_join.c_str(), ImVec2(-0.50f * avail_width, 0.0f))) + + if(ImGui::Button(str_join.c_str(), ImVec2(-0.50f * avail_width, 0.0f))) { join_selected_server(); + } + ImGui::EndDisabled(); ImGui::SameLine(); // Can only connect directly when not editing anything ImGui::BeginDisabled(editing_server); - if(ImGui::Button(str_connect.c_str(), ImVec2(-1.00f, 0.0f))) + + if(ImGui::Button(str_connect.c_str(), ImVec2(-1.00f, 0.0f))) { globals::gui_screen = GUI_DIRECT_CONNECTION; + } + ImGui::EndDisabled(); // Can only add when not editing anything ImGui::BeginDisabled(editing_server); - if(ImGui::Button(str_add.c_str(), ImVec2(-0.75f * avail_width, 0.0f))) + + if(ImGui::Button(str_add.c_str(), ImVec2(-0.75f * avail_width, 0.0f))) { add_new_server(); + } + ImGui::EndDisabled(); ImGui::SameLine(); // Can only edit when selected and not editing ImGui::BeginDisabled(!selected_server || editing_server); - if(ImGui::Button(str_edit.c_str(), ImVec2(-0.50f * avail_width, 0.0f))) + + if(ImGui::Button(str_edit.c_str(), ImVec2(-0.50f * avail_width, 0.0f))) { edit_selected_server(); + } + ImGui::EndDisabled(); ImGui::SameLine(); // Can only remove when selected and not editing ImGui::BeginDisabled(!selected_server || editing_server); - if(ImGui::Button(str_remove.c_str(), ImVec2(-0.25f * avail_width, 0.0f))) + + if(ImGui::Button(str_remove.c_str(), ImVec2(-0.25f * avail_width, 0.0f))) { remove_selected_server(); + } + ImGui::EndDisabled(); ImGui::SameLine(); if(ImGui::Button(str_refresh.c_str(), ImVec2(-1.0f, 0.0f))) { - for(ServerStatusItem *item : servers_deque) { + for(ServerStatusItem* item : servers_deque) { if(item->status != item_status::PINGING) { - if(editing_server && (item == selected_server)) - continue; - item->status = item_status::UNKNOWN; - bother::cancel(item->identity); + if(!editing_server || item != selected_server) { + item->status = item_status::UNKNOWN; + bother::cancel(item->identity); + } } } } @@ -426,13 +455,17 @@ void play_menu::init(void) parse_hostname(item, parts[0]); - if(parts.size() >= 2) + if(parts.size() >= 2) { item->password = parts[1]; - else item->password = std::string(); + } else { + item->password = std::string(); + } - if(parts.size() >= 3) + if(parts.size() >= 3) { item->name = parts[2].substr(0, MAX_SERVER_ITEM_NAME); - else item->name = DEFAULT_SERVER_NAME; + } else { + item->name = DEFAULT_SERVER_NAME; + } servers_deque.push_back(item); } @@ -482,8 +515,10 @@ void play_menu::layout(void) } if(ImGui::BeginTabItem(str_tab_servers.c_str())) { - if(ImGui::BeginChild("###play_menu.servers.child", ImVec2(0.0f, -2.0f * ImGui::GetFrameHeightWithSpacing()))) + if(ImGui::BeginChild("###play_menu.servers.child", ImVec2(0.0f, -2.0f * ImGui::GetFrameHeightWithSpacing()))) { layout_servers(); + } + ImGui::EndChild(); layout_servers_buttons(); diff --git a/game/client/player_look.cc b/game/client/player_look.cc index 6bd7be7..e1e4c8e 100644 --- a/game/client/player_look.cc +++ b/game/client/player_look.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/player_look.hh" #include "core/angles.hh" @@ -8,9 +9,9 @@ #include "shared/head.hh" #include "client/const.hh" +#include "client/gamepad.hh" #include "client/gamepad_axis.hh" #include "client/gamepad_button.hh" -#include "client/gamepad.hh" #include "client/glfw.hh" #include "client/globals.hh" #include "client/keybind.hh" @@ -42,7 +43,7 @@ static glm::fvec2 last_cursor; static void add_angles(float pitch, float yaw) { if(session::is_ingame()) { - auto &head = globals::dimension->entities.get(globals::player); + auto& head = globals::dimension->entities.get(globals::player); head.angles[0] += pitch; head.angles[1] += yaw; @@ -57,7 +58,7 @@ static void add_angles(float pitch, float yaw) } } -static void on_glfw_cursor_pos(const GlfwCursorPosEvent &event) +static void on_glfw_cursor_pos(const GlfwCursorPosEvent& event) { if(gamepad::available && gamepad::active.get_value()) { // The player is assumed to be using @@ -65,7 +66,7 @@ static void on_glfw_cursor_pos(const GlfwCursorPosEvent &event) last_cursor = event.pos; return; } - + if(globals::gui_screen || !session::is_ingame()) { // UI is visible or we're not in-game last_cursor = event.pos; @@ -79,12 +80,10 @@ static void on_glfw_cursor_pos(const GlfwCursorPosEvent &event) last_cursor = event.pos; } -static void on_gamepad_button(const GamepadButtonEvent &event) +static void on_gamepad_button(const GamepadButtonEvent& event) { if(button_fastlook.equals(event.button)) { - if(event.action == GLFW_PRESS) - fastlook_enabled = true; - else fastlook_enabled = false; + fastlook_enabled = event.action == GLFW_PRESS; } } @@ -139,8 +138,7 @@ void player_look::update_late(void) if(!globals::gui_screen && session::is_ingame()) { glfwSetInputMode(globals::window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(globals::window, GLFW_RAW_MOUSE_MOTION, mouse_raw_input.get_value()); - } - else { + } else { glfwSetInputMode(globals::window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(globals::window, GLFW_RAW_MOUSE_MOTION, false); } diff --git a/game/client/player_move.cc b/game/client/player_move.cc index f17603a..6c61dba 100644 --- a/game/client/player_move.cc +++ b/game/client/player_move.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/player_move.hh" #include "core/angles.hh" @@ -12,9 +13,9 @@ #include "shared/velocity.hh" #include "client/const.hh" +#include "client/gamepad.hh" #include "client/gamepad_axis.hh" #include "client/gamepad_button.hh" -#include "client/gamepad.hh" #include "client/globals.hh" #include "client/gui_screen.hh" #include "client/keybind.hh" @@ -59,7 +60,7 @@ static std::uniform_real_distribution pitch_distrib; // Quake III's PM_Accelerate-ish function used for // conventional (gravity-affected non-flight) movement -static glm::fvec3 pm_accelerate(const glm::fvec3 &wishdir, const glm::fvec3 &velocity, float wishspeed, float accel) +static glm::fvec3 pm_accelerate(const glm::fvec3& wishdir, const glm::fvec3& velocity, float wishspeed, float accel) { auto current_speed = glm::dot(velocity, wishdir); auto add_speed = wishspeed - current_speed; @@ -78,13 +79,13 @@ static glm::fvec3 pm_accelerate(const glm::fvec3 &wishdir, const glm::fvec3 &vel } // Conventional movement - velocity update when not on the ground -static glm::fvec3 pm_air_move(const glm::fvec3 &wishdir, const glm::fvec3 &velocity) +static glm::fvec3 pm_air_move(const glm::fvec3& wishdir, const glm::fvec3& velocity) { return pm_accelerate(wishdir, velocity, PMOVE_ACCELERATION_AIR, PMOVE_MAX_SPEED_AIR); } // Conventional movement - velocity uodate when on the ground -static glm::fvec3 pm_ground_move(const glm::fvec3 &wishdir, const glm::fvec3 &velocity) +static glm::fvec3 pm_ground_move(const glm::fvec3& wishdir, const glm::fvec3& velocity) { if(auto speed = glm::length(velocity)) { auto speed_drop = speed * PMOVE_FRICTION_GROUND * globals::fixed_frametime; @@ -97,7 +98,7 @@ static glm::fvec3 pm_ground_move(const glm::fvec3 &wishdir, const glm::fvec3 &ve // A simpler minecraft-like acceleration model // used whenever the TOGGLE_PM_FLIGHT is enabled -static glm::fvec3 pm_flight_move(const glm::fvec3 &wishdir) +static glm::fvec3 pm_flight_move(const glm::fvec3& wishdir) { // FIXME: make it smoother return wishdir * PMOVE_MAX_SPEED_AIR; @@ -144,9 +145,9 @@ void player_move::init(void) void player_move::fixed_update(void) { - const auto &head = globals::dimension->entities.get(globals::player); - auto &transform = globals::dimension->entities.get(globals::player); - auto &velocity = globals::dimension->entities.get(globals::player); + const auto& head = globals::dimension->entities.get(globals::player); + auto& transform = globals::dimension->entities.get(globals::player); + auto& velocity = globals::dimension->entities.get(globals::player); // Interpolation - preserve current component states globals::dimension->entities.emplace_or_replace(globals::player, transform); @@ -174,17 +175,20 @@ void player_move::fixed_update(void) auto new_speed = glm::length(new_velocity); - if(new_speed > 0.01f) + if(new_speed > 0.01f) { footsteps_distance += globals::fixed_frametime * new_speed; - else footsteps_distance = 0.0f; + } else { + footsteps_distance = 0.0f; + } if(footsteps_distance >= PMOVE_FOOTSTEP_SIZE) { - if(auto effect = voxel_sounds::get_footsteps(grounded->surface)) + if(auto effect = voxel_sounds::get_footsteps(grounded->surface)) { sound::play_player(effect, false, pitch_distrib(pitch_random)); + } + footsteps_distance = 0.0f; } - } - else { + } else { auto new_velocity = pm_air_move(wishdir, velocity_horizontal); velocity.value.x = new_velocity.x; velocity.value.z = new_velocity.z; @@ -213,13 +217,11 @@ void player_move::fixed_update(void) // No considerable speed increase within // the precision we use to draw the speedometer status_lines::set(STATUS_DEBUG, new_speed_text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f), 1.0f); - } - else if(speed_change < 0.0f) { + } else if(speed_change < 0.0f) { // Speed change is negative, we are actively // slowing down; use the red color for the status line status_lines::set(STATUS_DEBUG, new_speed_text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f), 1.0f); - } - else { + } else { // Speed change is positive, we are actively // speeding up; use the green color for the status line status_lines::set(STATUS_DEBUG, new_speed_text, ImVec4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f); @@ -243,25 +245,39 @@ void player_move::update_late(void) } if(gamepad::available && gamepad::active.get_value()) { - if(button_move_down.is_pressed(gamepad::state)) + if(button_move_down.is_pressed(gamepad::state)) { movement_direction += DIR_DOWN; - if(button_move_up.is_pressed(gamepad::state)) + } + + if(button_move_up.is_pressed(gamepad::state)) { movement_direction += DIR_UP; + } + movement_direction.x += axis_move_sideways.get_value(gamepad::state, gamepad::deadzone.get_value()); movement_direction.z -= axis_move_forward.get_value(gamepad::state, gamepad::deadzone.get_value()); - } - else { - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_forward.get_key())) + } else { + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_forward.get_key())) { movement_direction += DIR_FORWARD; - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_back.get_key())) + } + + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_back.get_key())) { movement_direction += DIR_BACK; - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_left.get_key())) + } + + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_left.get_key())) { movement_direction += DIR_LEFT; - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_right.get_key())) + } + + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_right.get_key())) { movement_direction += DIR_RIGHT; - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_down.get_key())) + } + + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_down.get_key())) { movement_direction += DIR_DOWN; - if(GLFW_PRESS == glfwGetKey(globals::window, key_move_up.get_key())) + } + + if(GLFW_PRESS == glfwGetKey(globals::window, key_move_up.get_key())) { movement_direction += DIR_UP; + } } } diff --git a/game/client/player_target.cc b/game/client/player_target.cc index 0c91876..9c60c00 100644 --- a/game/client/player_target.cc +++ b/game/client/player_target.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/player_target.hh" #include "shared/coord.hh" @@ -16,7 +17,7 @@ constexpr static float MAX_REACH = 16.0f; voxel_id player_target::voxel; voxel_pos player_target::coord; voxel_pos player_target::normal; -const VoxelInfo *player_target::info; +const VoxelInfo* player_target::info; void player_target::init(void) { @@ -45,8 +46,7 @@ void player_target::update(void) player_target::normal = voxel_pos(); player_target::info = nullptr; } while(ray.distance < MAX_REACH); - } - else { + } else { player_target::voxel = NULL_VOXEL_ID; player_target::coord = voxel_pos(); player_target::normal = voxel_pos(); diff --git a/game/client/player_target.hh b/game/client/player_target.hh index c48bcf6..b60d1a5 100644 --- a/game/client/player_target.hh +++ b/game/client/player_target.hh @@ -9,7 +9,7 @@ namespace player_target extern voxel_id voxel; extern voxel_pos coord; extern voxel_pos normal; -extern const VoxelInfo *info; +extern const VoxelInfo* info; } // namespace player_target namespace player_target diff --git a/game/client/program.cc b/game/client/program.cc index 026571e..339cdf8 100644 --- a/game/client/program.cc +++ b/game/client/program.cc @@ -1,41 +1,43 @@ #include "client/pch.hh" + #include "client/program.hh" #include "core/strtools.hh" // This fills up the array of source lines and figures out // which lines are to be dynamically resolved as variant macros -static void parse_source(const char *source, std::vector &out_lines, std::vector &out_variants) +static void parse_source(const char* source, std::vector& out_lines, std::vector& out_variants) { std::string line; std::istringstream stream = std::istringstream(source); unsigned long line_number = 0UL; - + out_lines.clear(); out_variants.clear(); - + while(std::getline(stream, line)) { unsigned int macro_index = {}; char macro_name[128] = {}; - + if(std::sscanf(line.c_str(), " # pragma variant [ %u ] %127[^, \"\t\r\n]", ¯o_index, ¯o_name) == 2) { - if(out_variants.size() <= macro_index) + if(out_variants.size() <= macro_index) { out_variants.resize(macro_index + 1U); + } + out_variants[macro_index].name = macro_name; out_variants[macro_index].line = line_number; out_variants[macro_index].value = std::numeric_limits::max(); out_lines.push_back(std::string()); line_number += 1UL; - } - else { + } else { out_lines.push_back(line); line_number += 1UL; } } } -static GLuint compile_shader(const char *path, const char *source, GLenum shader_stage) +static GLuint compile_shader(const char* path, const char* source, GLenum shader_stage) { GLuint shader = glCreateShader(shader_stage); glShaderSource(shader, 1, &source, nullptr); @@ -63,7 +65,7 @@ static GLuint compile_shader(const char *path, const char *source, GLenum shader return shader; } -bool GL_Program::setup(const char *vpath, const char *fpath) +bool GL_Program::setup(const char* vpath, const char* fpath) { destroy(); @@ -109,9 +111,9 @@ bool GL_Program::update(void) return true; } - for(const auto ¯o : vert_variants) + for(const auto& macro : vert_variants) vert_source[macro.line] = fmt::format("#define {} {}", macro.name, macro.value); - for(const auto ¯o : frag_variants) + for(const auto& macro : frag_variants) frag_source[macro.line] = fmt::format("#define {} {}", macro.name, macro.value); const std::string vsource = strtools::join(vert_source, "\r\n"); @@ -121,7 +123,7 @@ bool GL_Program::update(void) GLuint frag = compile_shader(frag_path.c_str(), fsource.c_str(), GL_FRAGMENT_SHADER); if(!vert || !frag) { - //needs_update = false; + // needs_update = false; glDeleteShader(frag); glDeleteShader(vert); return false; @@ -150,12 +152,12 @@ bool GL_Program::update(void) glGetProgramiv(handle, GL_LINK_STATUS, &link_status); if(!link_status) { - //needs_update = false; + // needs_update = false; glDeleteProgram(handle); return false; } - for(auto &uniform : uniforms) { + for(auto& uniform : uniforms) { // NOTE: GL seems to silently ignore invalid uniform // locations (-1); should we write something into logs about this? uniform.location = glGetUniformLocation(handle, uniform.name.c_str()); @@ -167,9 +169,10 @@ bool GL_Program::update(void) void GL_Program::destroy(void) { - if(handle) + if(handle) { glDeleteProgram(handle); - handle = 0; + handle = 0; + } uniforms.clear(); @@ -184,14 +187,14 @@ void GL_Program::destroy(void) needs_update = false; } -std::size_t GL_Program::add_uniform(const char *name) +std::size_t GL_Program::add_uniform(const char* name) { for(std::size_t i = 0; i < uniforms.size(); ++i) { - if(uniforms[i].name.compare(name)) - continue; - return i; + if(!uniforms[i].name.compare(name)) { + return i; + } } - + const std::size_t index = uniforms.size(); uniforms.push_back(GL_Uniform()); uniforms[index].location = -1; diff --git a/game/client/program.hh b/game/client/program.hh index b5a0634..4d83e14 100644 --- a/game/client/program.hh +++ b/game/client/program.hh @@ -15,11 +15,11 @@ struct GL_Uniform final { class GL_Program final { public: - bool setup(const char *vpath, const char *fpath); + bool setup(const char* vpath, const char* fpath); void destroy(void); bool update(void); - std::size_t add_uniform(const char *name); + std::size_t add_uniform(const char* name); void set_variant_vert(unsigned int variant, unsigned int value); void set_variant_frag(unsigned int variant, unsigned int value); diff --git a/game/client/progress_bar.cc b/game/client/progress_bar.cc index 2e69055..104a5c9 100644 --- a/game/client/progress_bar.cc +++ b/game/client/progress_bar.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/progress_bar.hh" #include "core/constexpr.hh" @@ -43,13 +44,13 @@ void progress_bar::layout(void) const float spinner_width = 0.8f * ImGui::CalcItemWidth(); const float bar_width = spinner_width / static_cast(num_bars); const float bar_height = 0.5f * ImGui::GetFrameHeight(); - + const float base_xpos = window_start.x + 0.5f * (window_size.x - spinner_width) + 0.5f; const float base_ypos = window_start.y + cursor.y; const float phase = 2.0f * ImGui::GetTime(); - const ImVec4 &background = ImGui::GetStyleColorVec4(ImGuiCol_Button); - const ImVec4 &foreground = ImGui::GetStyleColorVec4(ImGuiCol_PlotHistogram); + const ImVec4& background = ImGui::GetStyleColorVec4(ImGuiCol_Button); + const ImVec4& foreground = ImGui::GetStyleColorVec4(ImGuiCol_PlotHistogram); for(std::size_t i = 0; i < num_bars; ++i) { const float sinval = std::sin(M_PI * static_cast(i) / static_cast(num_bars) - phase); @@ -60,7 +61,7 @@ void progress_bar::layout(void) color.y = cxpr::lerp(background.y, foreground.y, modifier); color.z = cxpr::lerp(background.z, foreground.z, modifier); color.w = cxpr::lerp(background.w, foreground.w, modifier); - + const ImVec2 start = ImVec2(base_xpos + bar_width * i, base_ypos); const ImVec2 end = ImVec2(start.x + bar_width, start.y + bar_height); ImGui::GetWindowDrawList()->AddRectFilled(start, end, ImGui::GetColorU32(color)); @@ -97,12 +98,12 @@ void progress_bar::reset(void) button_action = nullptr; } -void progress_bar::set_title(const char *title) +void progress_bar::set_title(const char* title) { str_title = language::resolve(title); } -void progress_bar::set_button(const char *text, const progress_bar_action &action) +void progress_bar::set_button(const char* text, const progress_bar_action& action) { str_button = fmt::format("{}###ProgressBar_Button", language::resolve(text)); button_action = action; diff --git a/game/client/progress_bar.hh b/game/client/progress_bar.hh index 1596a95..5375d3f 100644 --- a/game/client/progress_bar.hh +++ b/game/client/progress_bar.hh @@ -2,19 +2,19 @@ #define CLIENT_PROGRESS_BAR_HH 1 #pragma once -using progress_bar_action = void(*)(void); +using progress_bar_action = void (*)(void); namespace progress_bar { void init(void); void layout(void); -} // progress_bar +} // namespace progress_bar namespace progress_bar { void reset(void); -void set_title(const char *title); -void set_button(const char *text, const progress_bar_action &action); +void set_title(const char* title); +void set_button(const char* text, const progress_bar_action& action); } // namespace progress_bar #endif /* CLIENT_PROGRESS_BAR_HH */ diff --git a/game/client/receive.cc b/game/client/receive.cc index ab1cd62..57a76da 100644 --- a/game/client/receive.cc +++ b/game/client/receive.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/receive.hh" #include "shared/dimension.hh" @@ -17,7 +18,7 @@ #include "client/sound.hh" #include "client/window_title.hh" -static bool synchronize_entity_id(Dimension *dimension, entt::entity entity) +static bool synchronize_entity_id(Dimension* dimension, entt::entity entity) { if(dimension->entities.valid(entity)) { // Entity ID already exists @@ -32,8 +33,7 @@ static bool synchronize_entity_id(Dimension *dimension, entt::entity entity) } session::disconnect("protocol.entity_id_desync"); - spdlog::critical("receive: entity desync: network {} resolved as client {}", - static_cast(entity), static_cast(created)); + spdlog::critical("receive: entity desync: network {} resolved as client {}", static_cast(entity), static_cast(created)); message_box::reset(); message_box::set_title("disconnected.disconnected"); @@ -48,7 +48,7 @@ static bool synchronize_entity_id(Dimension *dimension, entt::entity entity) return false; } -static void on_dimension_info_packet(const protocol::DimensionInfo &packet) +static void on_dimension_info_packet(const protocol::DimensionInfo& packet) { if(session::peer) { if(globals::dimension) { @@ -61,7 +61,7 @@ static void on_dimension_info_packet(const protocol::DimensionInfo &packet) } } -static void on_chunk_voxels_packet(const protocol::ChunkVoxels &packet) +static void on_chunk_voxels_packet(const protocol::ChunkVoxels& packet) { if(session::peer && globals::dimension) { auto chunk = globals::dimension->create_chunk(packet.chunk); @@ -78,12 +78,12 @@ static void on_chunk_voxels_packet(const protocol::ChunkVoxels &packet) } } -static void on_entity_head_packet(const protocol::EntityHead &packet) +static void on_entity_head_packet(const protocol::EntityHead& packet) { if(session::peer && globals::dimension) { if(synchronize_entity_id(globals::dimension, packet.entity)) { - auto &component = globals::dimension->entities.get_or_emplace(packet.entity); - auto &prevcomp = globals::dimension->entities.get_or_emplace(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace(packet.entity); + auto& prevcomp = globals::dimension->entities.get_or_emplace(packet.entity); // Store the previous component state prevcomp.angles = component.angles; @@ -95,12 +95,12 @@ static void on_entity_head_packet(const protocol::EntityHead &packet) } } -static void on_entity_transform_packet(const protocol::EntityTransform &packet) +static void on_entity_transform_packet(const protocol::EntityTransform& packet) { if(session::peer && globals::dimension) { if(synchronize_entity_id(globals::dimension, packet.entity)) { - auto &component = globals::dimension->entities.get_or_emplace(packet.entity); - auto &prevcomp = globals::dimension->entities.get_or_emplace(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace(packet.entity); + auto& prevcomp = globals::dimension->entities.get_or_emplace(packet.entity); // Store the previous component state prevcomp.angles = component.angles; @@ -115,17 +115,17 @@ static void on_entity_transform_packet(const protocol::EntityTransform &packet) } } -static void on_entity_velocity_packet(const protocol::EntityVelocity &packet) +static void on_entity_velocity_packet(const protocol::EntityVelocity& packet) { if(session::peer && globals::dimension) { if(synchronize_entity_id(globals::dimension, packet.entity)) { - auto &component = globals::dimension->entities.get_or_emplace(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace(packet.entity); component.value = packet.value; } } } -static void on_entity_player_packet(const protocol::EntityPlayer &packet) +static void on_entity_player_packet(const protocol::EntityPlayer& packet) { if(session::peer && globals::dimension) { if(synchronize_entity_id(globals::dimension, packet.entity)) { @@ -134,7 +134,7 @@ static void on_entity_player_packet(const protocol::EntityPlayer &packet) } } -static void on_spawn_player_packet(const protocol::SpawnPlayer &packet) +static void on_spawn_player_packet(const protocol::SpawnPlayer& packet) { if(session::peer && globals::dimension) { if(synchronize_entity_id(globals::dimension, packet.entity)) { @@ -150,21 +150,23 @@ static void on_spawn_player_packet(const protocol::SpawnPlayer &packet) } } -static void on_remove_entity_packet(const protocol::RemoveEntity &packet) +static void on_remove_entity_packet(const protocol::RemoveEntity& packet) { if(globals::dimension) { - if(packet.entity == globals::player) + if(packet.entity == globals::player) { globals::player = entt::null; + } + globals::dimension->entities.destroy(packet.entity); } } -static void on_generic_sound_packet(const protocol::GenericSound &packet) +static void on_generic_sound_packet(const protocol::GenericSound& packet) { sound::play_generic(packet.sound.c_str(), packet.looping, packet.pitch); } -static void on_entity_sound_packet(const protocol::EntitySound &packet) +static void on_entity_sound_packet(const protocol::EntitySound& packet) { sound::play_entity(packet.entity, packet.sound.c_str(), packet.looping, packet.pitch); } diff --git a/game/client/scoreboard.cc b/game/client/scoreboard.cc index c000ae4..e39b56c 100644 --- a/game/client/scoreboard.cc +++ b/game/client/scoreboard.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/scoreboard.hh" #include "core/config.hh" @@ -18,7 +19,7 @@ static ConfigKeyBind list_key(GLFW_KEY_TAB); static std::vector usernames; static float max_username_size; -static void on_scoreboard_update_packet(const protocol::ScoreboardUpdate &packet) +static void on_scoreboard_update_packet(const protocol::ScoreboardUpdate& packet) { usernames = packet.names; max_username_size = 0.0f; @@ -35,69 +36,64 @@ void scoreboard::init(void) void scoreboard::layout(void) { - if(globals::gui_screen != GUI_SCREEN_NONE) - return; - if(!session::is_ingame()) - return; - if(glfwGetKey(globals::window, list_key.get_key()) != GLFW_PRESS) - return; - - const auto viewport = ImGui::GetMainViewport(); - const auto window_start = ImVec2(0.0f, 0.0f); - const auto window_size = ImVec2(viewport->Size.x, viewport->Size.y); - - ImGui::SetNextWindowPos(window_start); - ImGui::SetNextWindowSize(window_size); - - if(!ImGui::Begin("###chat", nullptr, WINDOW_FLAGS)) { - ImGui::End(); - return; - } + if(globals::gui_screen == GUI_SCREEN_NONE && session::is_ingame() && glfwGetKey(globals::window, list_key.get_key()) == GLFW_PRESS) { + const auto viewport = ImGui::GetMainViewport(); + const auto window_start = ImVec2(0.0f, 0.0f); + const auto window_size = ImVec2(viewport->Size.x, viewport->Size.y); - ImGui::PushFont(globals::font_chat); + ImGui::SetNextWindowPos(window_start); + ImGui::SetNextWindowSize(window_size); - const auto &padding = ImGui::GetStyle().FramePadding; - const auto &spacing = ImGui::GetStyle().ItemSpacing; - auto font = globals::font_chat; + if(!ImGui::Begin("###chat", nullptr, WINDOW_FLAGS)) { + ImGui::End(); + return; + } - // Figure out the maximum username size - for(const auto &username : usernames) { - const ImVec2 size = ImGui::CalcTextSize(username.c_str(), username.c_str() + username.size()); - - if(size.x <= max_username_size) - continue; - max_username_size = size.x; - } + ImGui::PushFont(globals::font_chat); - // Having a minimum size allows for - // generally better in-game visibility - const float true_size = cxpr::max(0.25f * window_size.x, max_username_size); - - // Figure out username rect dimensions - const float rect_start_x = 0.5f * window_size.x - 0.5f * true_size; - const float rect_start_y = 0.15f * window_size.y; - const float rect_size_x = 2.0f * padding.x + true_size; - const float rect_size_y = 2.0f * padding.y + font->FontSize; - - //const ImU32 border_col = ImGui::GetColorU32(ImGuiCol_Border, 1.00f); - const ImU32 rect_col = ImGui::GetColorU32(ImGuiCol_FrameBg, 0.80f); - const ImU32 text_col = ImGui::GetColorU32(ImGuiCol_Text, 1.00f); - - ImDrawList *draw_list = ImGui::GetWindowDrawList(); - - // Slightly space apart individual rows - const float row_step_y = rect_size_y + 0.5f * spacing.y; - - for(std::size_t i = 0; i < usernames.size(); ++i) { - const ImVec2 rect_a = ImVec2(rect_start_x, rect_start_y + i * row_step_y); - const ImVec2 rect_b = ImVec2(rect_a.x + rect_size_x, rect_a.y + rect_size_y); - const ImVec2 text_pos = ImVec2(rect_a.x + padding.x, rect_a.y + padding.y); - - //draw_list->AddRect(rect_a, rect_b, border_col, 0.0f, ImDrawFlags_None, globals::gui_scale); - draw_list->AddRectFilled(rect_a, rect_b, rect_col, 0.0f, ImDrawFlags_None); - draw_list->AddText(font, font->FontSize, text_pos, text_col, usernames[i].c_str(), usernames[i].c_str() + usernames[i].size()); - } + const auto& padding = ImGui::GetStyle().FramePadding; + const auto& spacing = ImGui::GetStyle().ItemSpacing; + auto font = globals::font_chat; + + // Figure out the maximum username size + for(const auto& username : usernames) { + const ImVec2 size = ImGui::CalcTextSize(username.c_str(), username.c_str() + username.size()); + + if(size.x > max_username_size) { + max_username_size = size.x; + } + } + + // Having a minimum size allows for + // generally better in-game visibility + const float true_size = cxpr::max(0.25f * window_size.x, max_username_size); - ImGui::PopFont(); - ImGui::End(); + // Figure out username rect dimensions + const float rect_start_x = 0.5f * window_size.x - 0.5f * true_size; + const float rect_start_y = 0.15f * window_size.y; + const float rect_size_x = 2.0f * padding.x + true_size; + const float rect_size_y = 2.0f * padding.y + font->FontSize; + + // const ImU32 border_col = ImGui::GetColorU32(ImGuiCol_Border, 1.00f); + const ImU32 rect_col = ImGui::GetColorU32(ImGuiCol_FrameBg, 0.80f); + const ImU32 text_col = ImGui::GetColorU32(ImGuiCol_Text, 1.00f); + + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + + // Slightly space apart individual rows + const float row_step_y = rect_size_y + 0.5f * spacing.y; + + for(std::size_t i = 0; i < usernames.size(); ++i) { + const ImVec2 rect_a = ImVec2(rect_start_x, rect_start_y + i * row_step_y); + const ImVec2 rect_b = ImVec2(rect_a.x + rect_size_x, rect_a.y + rect_size_y); + const ImVec2 text_pos = ImVec2(rect_a.x + padding.x, rect_a.y + padding.y); + + // draw_list->AddRect(rect_a, rect_b, border_col, 0.0f, ImDrawFlags_None, globals::gui_scale); + draw_list->AddRectFilled(rect_a, rect_b, rect_col, 0.0f, ImDrawFlags_None); + draw_list->AddText(font, font->FontSize, text_pos, text_col, usernames[i].c_str(), usernames[i].c_str() + usernames[i].size()); + } + + ImGui::PopFont(); + ImGui::End(); + } } diff --git a/game/client/screenshot.cc b/game/client/screenshot.cc index 5f2d91c..08b484b 100644 --- a/game/client/screenshot.cc +++ b/game/client/screenshot.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/screenshot.hh" #include "core/config.hh" @@ -14,14 +15,14 @@ static ConfigKeyBind screenshot_key(GLFW_KEY_F2); -static void stbi_png_physfs_callback(void *context, void *data, int size) +static void stbi_png_physfs_callback(void* context, void* data, int size) { - PHYSFS_writeBytes(reinterpret_cast(context), data, size); + PHYSFS_writeBytes(reinterpret_cast(context), data, size); } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { - if(!globals::gui_keybind_ptr && !toggles::is_sequence_await) { + if(!globals::gui_keybind_ptr && !toggles::is_sequence_await) { if(screenshot_key.equals(event.key) && (event.action == GLFW_PRESS)) { screenshot::take(); return; @@ -54,7 +55,7 @@ void screenshot::take(void) // alignment value of sorts that might result in a corrupted // image; we set GL_PACK_ALIGNMENT to 1, enabling byte-alignment glPixelStorei(GL_PACK_ALIGNMENT, 1); - + glReadPixels(0, 0, globals::width, globals::height, GL_RGB, GL_UNSIGNED_BYTE, pixels); // Restore the old pack alignment value @@ -71,7 +72,7 @@ void screenshot::take(void) stbi_write_png_to_func(&stbi_png_physfs_callback, file, globals::width, globals::height, 3, pixels, stride); spdlog::info("screenshot: wrote {}", filepath); - + client_chat::print(fmt::format("{} {}", language::resolve("chat.screenshot_message"), filename)); PHYSFS_close(file); diff --git a/game/client/session.cc b/game/client/session.cc index b5ed12a..dcf0ef2 100644 --- a/game/client/session.cc +++ b/game/client/session.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/session.hh" #include "core/config.hh" @@ -24,7 +25,7 @@ #include "client/progress_bar.hh" #include "client/window_title.hh" -ENetPeer *session::peer = nullptr; +ENetPeer* session::peer = nullptr; std::uint16_t session::client_index = UINT16_MAX; std::uint64_t session::client_identity = UINT64_MAX; @@ -37,7 +38,7 @@ static void set_fixed_tickrate(std::uint16_t tickrate) globals::fixed_accumulator = 0; } -static void on_login_response_packet(const protocol::LoginResponse &packet) +static void on_login_response_packet(const protocol::LoginResponse& packet) { spdlog::info("session: assigned client_index={}", packet.client_index); spdlog::info("session: assigned client_identity={}", packet.client_identity); @@ -51,7 +52,7 @@ static void on_login_response_packet(const protocol::LoginResponse &packet) progress_bar::set_title("connecting.loading_world"); } -static void on_disconnect_packet(const protocol::Disconnect &packet) +static void on_disconnect_packet(const protocol::Disconnect& packet) { enet_peer_disconnect(session::peer, 0); @@ -84,7 +85,7 @@ static void on_disconnect_packet(const protocol::Disconnect &packet) globals::gui_screen = GUI_MESSAGE_BOX; } -static void on_set_voxel_packet(const protocol::SetVoxel &packet) +static void on_set_voxel_packet(const protocol::SetVoxel& packet) { auto cpos = coord::to_chunk(packet.vpos); auto lpos = coord::to_local(packet.vpos); @@ -98,7 +99,7 @@ static void on_set_voxel_packet(const protocol::SetVoxel &packet) event.dimension = globals::dimension; event.chunk = chunk; event.cpos = cpos; - + // Send a generic ChunkUpdate event to shake // up the mesher; directly calling world::set_voxel // here would result in a networked feedback loop @@ -111,7 +112,7 @@ static void on_set_voxel_packet(const protocol::SetVoxel &packet) // NOTE: [session] is a good place for this since [receive] // handles entity data sent by the server and [session] handles // everything else network related that is not player movement -static void on_voxel_set(const VoxelSetEvent &event) +static void on_voxel_set(const VoxelSetEvent& event) { if(session::peer) { // Propagate changes to the server @@ -135,7 +136,7 @@ void session::init(void) globals::fixed_accumulator = 0; server_password_hash = UINT64_MAX; - + globals::dispatcher.sink().connect<&on_login_response_packet>(); globals::dispatcher.sink().connect<&on_disconnect_packet>(); globals::dispatcher.sink().connect<&on_set_voxel_packet>(); @@ -156,7 +157,7 @@ void session::invalidate(void) { if(session::peer) { enet_peer_reset(session::peer); - + message_box::reset(); message_box::set_title("disconnected.disconnected"); message_box::set_subtitle("enet.peer_connection_timeout"); @@ -185,12 +186,12 @@ void session::invalidate(void) globals::dimension = nullptr; } -void session::connect(const char *host, std::uint16_t port, const char *password) +void session::connect(const char* host, std::uint16_t port, const char* password) { ENetAddress address; enet_address_set_host(&address, host); address.port = port; - + session::peer = enet_host_connect(globals::client_host, &address, 1, 0); session::client_index = UINT16_MAX; session::client_identity = UINT64_MAX; @@ -242,7 +243,7 @@ void session::connect(const char *host, std::uint16_t port, const char *password globals::gui_screen = GUI_PROGRESS_BAR; } -void session::disconnect(const char *reason) +void session::disconnect(const char* reason) { if(session::peer) { protocol::Disconnect packet; @@ -267,7 +268,7 @@ void session::disconnect(const char *reason) delete globals::dimension; globals::player = entt::null; globals::dimension = nullptr; - + client_chat::clear(); } } @@ -282,7 +283,7 @@ void session::send_login_request(void) packet.username = client_game::username.get(); protocol::send(session::peer, protocol::encode(packet)); - + server_password_hash = UINT64_MAX; progress_bar::set_title("connecting.logging_in"); @@ -291,7 +292,9 @@ void session::send_login_request(void) bool session::is_ingame(void) { - if(globals::dimension) + if(globals::dimension) { return globals::dimension->entities.valid(globals::player); - return false; + } else { + return false; + } } diff --git a/game/client/session.hh b/game/client/session.hh index 3784dc7..051b57f 100644 --- a/game/client/session.hh +++ b/game/client/session.hh @@ -4,7 +4,7 @@ namespace session { -extern ENetPeer *peer; +extern ENetPeer* peer; extern std::uint16_t client_index; extern std::uint64_t client_identity; } // namespace session @@ -18,8 +18,8 @@ void invalidate(void); namespace session { -void connect(const char *hostname, std::uint16_t port, const char *password); -void disconnect(const char *reason); +void connect(const char* hostname, std::uint16_t port, const char* password); +void disconnect(const char* reason); void send_login_request(void); } // namespace session diff --git a/game/client/settings.cc b/game/client/settings.cc index 12ce96c..93fe475 100644 --- a/game/client/settings.cc +++ b/game/client/settings.cc @@ -1,13 +1,14 @@ #include "client/pch.hh" + #include "client/settings.hh" #include "core/config.hh" #include "core/constexpr.hh" #include "client/const.hh" +#include "client/gamepad.hh" #include "client/gamepad_axis.hh" #include "client/gamepad_button.hh" -#include "client/gamepad.hh" #include "client/glfw.hh" #include "client/globals.hh" #include "client/gui_screen.hh" @@ -18,19 +19,19 @@ constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | constexpr static unsigned int NUM_LOCATIONS = static_cast(settings_location::COUNT); enum class setting_type : unsigned int { - CHECKBOX = 0x0000U, ///< ConfigBoolean - INPUT_INT = 0x0001U, ///< ConfigNumber - INPUT_FLOAT = 0x0002U, ///< ConfigNumber - INPUT_UINT = 0x0003U, ///< ConfigNumber - INPUT_STRING = 0x0004U, ///< ConfigString - SLIDER_INT = 0x0005U, ///< ConfigNumber - SLIDER_FLOAT = 0x0006U, ///< ConfigNumber - SLIDER_UINT = 0x0007U, ///< ConfigNumber - STEPPER_INT = 0x0008U, ///< ConfigNumber - STEPPER_UINT = 0x0009U, ///< ConfigNumber - KEYBIND = 0x000AU, ///< ConfigKeyBind - GAMEPAD_AXIS = 0x000BU, ///< ConfigGamepadAxis - GAMEPAD_BUTTON = 0x000CU, ///< ConfigGamepadButton + CHECKBOX = 0x0000U, ///< ConfigBoolean + INPUT_INT = 0x0001U, ///< ConfigNumber + INPUT_FLOAT = 0x0002U, ///< ConfigNumber + INPUT_UINT = 0x0003U, ///< ConfigNumber + INPUT_STRING = 0x0004U, ///< ConfigString + SLIDER_INT = 0x0005U, ///< ConfigNumber + SLIDER_FLOAT = 0x0006U, ///< ConfigNumber + SLIDER_UINT = 0x0007U, ///< ConfigNumber + STEPPER_INT = 0x0008U, ///< ConfigNumber + STEPPER_UINT = 0x0009U, ///< ConfigNumber + KEYBIND = 0x000AU, ///< ConfigKeyBind + GAMEPAD_AXIS = 0x000BU, ///< ConfigGamepadAxis + GAMEPAD_BUTTON = 0x000CU, ///< ConfigGamepadButton LANGUAGE_SELECT = 0x000DU, ///< ConfigString internally }; @@ -65,7 +66,7 @@ public: void refresh_wids(void); public: - ConfigBoolean *value; + ConfigBoolean* value; std::string wids[2]; }; @@ -75,7 +76,7 @@ public: virtual void layout(void) const override; public: - ConfigInt *value; + ConfigInt* value; }; class SettingValue_InputFloat final : public SettingValueWID { @@ -85,7 +86,7 @@ public: public: std::string format; - ConfigFloat *value; + ConfigFloat* value; }; class SettingValue_InputUnsigned final : public SettingValueWID { @@ -94,7 +95,7 @@ public: virtual void layout(void) const override; public: - ConfigUnsigned *value; + ConfigUnsigned* value; }; class SettingValue_InputString final : public SettingValueWID { @@ -103,7 +104,7 @@ public: virtual void layout(void) const override; public: - ConfigString *value; + ConfigString* value; bool allow_whitespace; }; @@ -113,7 +114,7 @@ public: virtual void layout(void) const override; public: - ConfigInt *value; + ConfigInt* value; }; class SettingValue_SliderFloat final : public SettingValueWID { @@ -123,7 +124,7 @@ public: public: std::string format; - ConfigFloat *value; + ConfigFloat* value; }; class SettingValue_SliderUnsigned final : public SettingValueWID { @@ -132,7 +133,7 @@ public: virtual void layout(void) const override; public: - ConfigUnsigned *value; + ConfigUnsigned* value; }; class SettingValue_StepperInt final : public SettingValue { @@ -143,7 +144,7 @@ public: public: std::vector wids; - ConfigInt *value; + ConfigInt* value; }; class SettingValue_StepperUnsigned final : public SettingValue { @@ -154,7 +155,7 @@ public: public: std::vector wids; - ConfigUnsigned *value; + ConfigUnsigned* value; }; class SettingValue_KeyBind final : public SettingValue { @@ -165,7 +166,7 @@ public: public: std::string wids[2]; - ConfigKeyBind *value; + ConfigKeyBind* value; }; class SettingValue_GamepadAxis final : public SettingValue { @@ -177,7 +178,7 @@ public: public: std::string wids[2]; std::string wid_checkbox; - ConfigGamepadAxis *value; + ConfigGamepadAxis* value; }; class SettingValue_GamepadButton final : public SettingValue { @@ -188,7 +189,7 @@ public: public: std::string wids[2]; - ConfigGamepadButton *value; + ConfigGamepadButton* value; }; class SettingValue_Language final : public SettingValueWID { @@ -225,8 +226,8 @@ static std::string str_video_gui; static std::string str_sound_levels; -static std::vector values_all; -static std::vector values[NUM_LOCATIONS]; +static std::vector values_all; +static std::vector values[NUM_LOCATIONS]; void SettingValue::layout_tooltip(void) const { @@ -251,13 +252,13 @@ void SettingValue::layout_label(void) const void SettingValue_CheckBox::refresh_wids(void) { - wids[0] = fmt::format("{}###{}", str_checkbox_false, static_cast(value)); - wids[1] = fmt::format("{}###{}", str_checkbox_true, static_cast(value)); + wids[0] = fmt::format("{}###{}", str_checkbox_false, static_cast(value)); + wids[1] = fmt::format("{}###{}", str_checkbox_true, static_cast(value)); } void SettingValue_CheckBox::layout(void) const { - const auto &wid = value->get_value() ? wids[1] : wids[0]; + const auto& wid = value->get_value() ? wids[1] : wids[0]; if(ImGui::Button(wid.c_str(), ImVec2(ImGui::CalcItemWidth(), 0.0f))) { value->set_value(!value->get_value()); @@ -308,9 +309,11 @@ void SettingValue_InputString::layout(void) const ImGuiInputTextFlags flags; std::string current_value = value->get(); - if(allow_whitespace) + if(allow_whitespace) { flags = ImGuiInputTextFlags_AllowTabInput; - else flags = 0; + } else { + flags = 0; + } if(ImGui::InputText(wid.c_str(), ¤t_value, flags)) { value->set(current_value.c_str()); @@ -370,9 +373,11 @@ void SettingValue_StepperInt::layout(void) const current_value += 1; } - if(current_value > max_value) + if(current_value > max_value) { value->set_value(min_value); - else value->set_value(current_value); + } else { + value->set_value(current_value); + } layout_label(); layout_tooltip(); @@ -382,7 +387,7 @@ void SettingValue_StepperInt::refresh_wids(void) { for(std::size_t i = 0; i < wids.size(); ++i) { auto key = fmt::format("settings.value.{}.{}", name, i); - wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast(value)); + wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast(value)); } } @@ -398,9 +403,11 @@ void SettingValue_StepperUnsigned::layout(void) const current_value += 1U; } - if(current_value > max_value) + if(current_value > max_value) { value->set_value(min_value); - else value->set_value(current_value); + } else { + value->set_value(current_value); + } layout_label(); layout_tooltip(); @@ -410,17 +417,17 @@ void SettingValue_StepperUnsigned::refresh_wids(void) { for(std::size_t i = 0; i < wids.size(); ++i) { auto key = fmt::format("settings.value.{}.{}", name, i); - wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast(value)); + wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast(value)); } } void SettingValue_KeyBind::layout(void) const { const auto is_active = ((globals::gui_keybind_ptr == value) && !globals::gui_gamepad_axis_ptr && !globals::gui_gamepad_button_ptr); - const auto &wid = is_active ? wids[0] : wids[1]; + const auto& wid = is_active ? wids[0] : wids[1]; if(ImGui::Button(wid.c_str(), ImVec2(ImGui::CalcItemWidth(), 0.0f))) { - auto &io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; globals::gui_keybind_ptr = value; } @@ -430,18 +437,18 @@ void SettingValue_KeyBind::layout(void) const void SettingValue_KeyBind::refresh_wids(void) { - wids[0] = fmt::format("...###{}", static_cast(value)); - wids[1] = fmt::format("{}###{}", value->get(), static_cast(value)); + wids[0] = fmt::format("...###{}", static_cast(value)); + wids[1] = fmt::format("{}###{}", value->get(), static_cast(value)); } void SettingValue_GamepadAxis::layout(void) const { const auto is_active = ((globals::gui_gamepad_axis_ptr == value) && !globals::gui_keybind_ptr && !globals::gui_gamepad_button_ptr); - const auto &wid = is_active ? wids[0] : wids[1]; + const auto& wid = is_active ? wids[0] : wids[1]; auto is_inverted = value->is_inverted(); if(ImGui::Button(wid.c_str(), ImVec2(ImGui::CalcItemWidth() - ImGui::GetFrameHeight() - ImGui::GetStyle().ItemSpacing.x, 0.0f))) { - auto &io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; globals::gui_gamepad_axis_ptr = value; } @@ -464,18 +471,18 @@ void SettingValue_GamepadAxis::layout(void) const void SettingValue_GamepadAxis::refresh_wids(void) { - wids[0] = fmt::format("...###{}", static_cast(value)); - wids[1] = fmt::format("{}###{}", value->get_name(), static_cast(value)); - wid_checkbox = fmt::format("###CHECKBOX_{}", static_cast(value)); + wids[0] = fmt::format("...###{}", static_cast(value)); + wids[1] = fmt::format("{}###{}", value->get_name(), static_cast(value)); + wid_checkbox = fmt::format("###CHECKBOX_{}", static_cast(value)); } void SettingValue_GamepadButton::layout(void) const { const auto is_active = ((globals::gui_gamepad_button_ptr == value) && !globals::gui_keybind_ptr && !globals::gui_gamepad_axis_ptr); - const auto &wid = is_active ? wids[0] : wids[1]; + const auto& wid = is_active ? wids[0] : wids[1]; if(ImGui::Button(wid.c_str(), ImVec2(ImGui::CalcItemWidth(), 0.0f))) { - auto &io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; globals::gui_gamepad_button_ptr = value; } @@ -485,8 +492,8 @@ void SettingValue_GamepadButton::layout(void) const void SettingValue_GamepadButton::refresh_wids(void) { - wids[0] = fmt::format("...###{}", static_cast(value)); - wids[1] = fmt::format("{}###{}", value->get(), static_cast(value)); + wids[0] = fmt::format("...###{}", static_cast(value)); + wids[1] = fmt::format("{}###{}", value->get(), static_cast(value)); } void SettingValue_Language::layout(void) const @@ -510,32 +517,32 @@ void SettingValue_Language::layout(void) const static void refresh_input_wids(void) { - for(SettingValue *value : values_all) { + for(SettingValue* value : values_all) { if(value->type == setting_type::KEYBIND) { - auto keybind = static_cast(value); + auto keybind = static_cast(value); keybind->refresh_wids(); continue; } if(value->type == setting_type::GAMEPAD_AXIS) { - auto gamepad_axis = static_cast(value); + auto gamepad_axis = static_cast(value); gamepad_axis->refresh_wids(); continue; } if(value->type == setting_type::GAMEPAD_BUTTON) { - auto gamepad_button = static_cast(value); + auto gamepad_button = static_cast(value); gamepad_button->refresh_wids(); } } } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if((event.action == GLFW_PRESS) && (event.key != DEBUG_KEY)) { if(globals::gui_keybind_ptr || globals::gui_gamepad_axis_ptr || globals::gui_gamepad_button_ptr) { if(event.key == GLFW_KEY_ESCAPE) { - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; globals::gui_keybind_ptr = nullptr; @@ -545,7 +552,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) return; } - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; globals::gui_keybind_ptr->set_key(event.key); @@ -555,7 +562,7 @@ static void on_glfw_key(const GlfwKeyEvent &event) return; } - + if((event.key == GLFW_KEY_ESCAPE) && (globals::gui_screen == GUI_SETTINGS)) { globals::gui_screen = GUI_MAIN_MENU; return; @@ -563,10 +570,10 @@ static void on_glfw_key(const GlfwKeyEvent &event) } } -static void on_gamepad_axis(const GamepadAxisEvent &event) +static void on_gamepad_axis(const GamepadAxisEvent& event) { if(globals::gui_gamepad_axis_ptr) { - auto &io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; globals::gui_gamepad_axis_ptr->set_axis(event.axis); @@ -578,10 +585,10 @@ static void on_gamepad_axis(const GamepadAxisEvent &event) } } -static void on_gamepad_button(const GamepadButtonEvent &event) +static void on_gamepad_button(const GamepadButtonEvent& event) { if(globals::gui_gamepad_button_ptr) { - auto &io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; globals::gui_gamepad_button_ptr->set_button(event.button); @@ -593,7 +600,7 @@ static void on_gamepad_button(const GamepadButtonEvent &event) } } -static void on_language_set(const LanguageSetEvent &event) +static void on_language_set(const LanguageSetEvent& event) { str_checkbox_false = language::resolve("settings.checkbox.false"); str_checkbox_true = language::resolve("settings.checkbox.true"); @@ -602,7 +609,7 @@ static void on_language_set(const LanguageSetEvent &event) str_tab_input = language::resolve("settings.tab.input"); str_tab_video = language::resolve("settings.tab.video"); str_tab_sound = language::resolve("settings.tab.sound"); - + str_input_keyboard = language::resolve("settings.input.keyboard"); str_input_gamepad = language::resolve("settings.input.gamepad"); str_input_mouse = language::resolve("settings.input.mouse"); @@ -623,19 +630,19 @@ static void on_language_set(const LanguageSetEvent &event) str_sound_levels = language::resolve("settings.sound.levels"); - for(SettingValue *value : values_all) { + for(SettingValue* value : values_all) { if(value->type == setting_type::CHECKBOX) { - auto checkbox = static_cast(value); + auto checkbox = static_cast(value); checkbox->refresh_wids(); } if(value->type == setting_type::STEPPER_INT) { - auto stepper = static_cast(value); + auto stepper = static_cast(value); stepper->refresh_wids(); } if(value->type == setting_type::STEPPER_UINT) { - auto stepper = static_cast(value); + auto stepper = static_cast(value); stepper->refresh_wids(); } @@ -651,7 +658,7 @@ static void layout_values(settings_location location) { ImGui::PushItemWidth(ImGui::CalcItemWidth() * 0.70f); - for(const SettingValue *value : values[static_cast(location)]) { + for(const SettingValue* value : values[static_cast(location)]) { value->layout(); } @@ -660,8 +667,10 @@ static void layout_values(settings_location location) static void layout_general(void) { - if(ImGui::BeginChild("###settings.general.child")) + if(ImGui::BeginChild("###settings.general.child")) { layout_values(settings_location::GENERAL); + } + ImGui::EndChild(); } @@ -696,8 +705,10 @@ static void layout_input_gamepad(void) static void layout_input_mouse(void) { - if(ImGui::BeginChild("###settings.input.mouse.child")) + if(ImGui::BeginChild("###settings.input.mouse.child")) { layout_values(settings_location::MOUSE); + } + ImGui::EndChild(); } @@ -757,14 +768,11 @@ void settings::init(void) globals::dispatcher.sink().connect<&on_language_set>(); } - void settings::init_late(void) { for(std::size_t i = 0; i < NUM_LOCATIONS; ++i) { - std::sort(values[i].begin(), values[i].end(), [](const SettingValue *a, const SettingValue *b) { - if(a->priority < b->priority) - return true; - return false; + std::sort(values[i].begin(), values[i].end(), [](const SettingValue* a, const SettingValue* b) { + return a->priority < b->priority; }); } @@ -773,9 +781,10 @@ void settings::init_late(void) void settings::deinit(void) { - for(const SettingValue *value : values_all) + for(const SettingValue* value : values_all) delete value; - for(std::size_t i = 0; i < NUM_LOCATIONS; values[i++].clear()); + for(std::size_t i = 0; i < NUM_LOCATIONS; values[i++].clear()) + ; values_all.clear(); } @@ -831,7 +840,7 @@ void settings::layout(void) ImGui::End(); } -void settings::add_checkbox(int priority, ConfigBoolean &value, settings_location location, const char *name, bool tooltip) +void settings::add_checkbox(int priority, ConfigBoolean& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_CheckBox; setting_value->type = setting_type::CHECKBOX; @@ -846,7 +855,7 @@ void settings::add_checkbox(int priority, ConfigBoolean &value, settings_locatio values_all.push_back(setting_value); } -void settings::add_input(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip) +void settings::add_input(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_InputInt; setting_value->type = setting_type::INPUT_INT; @@ -855,13 +864,13 @@ void settings::add_input(int priority, ConfigInt &value, settings_location locat setting_value->value = &value; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_input(int priority, ConfigFloat &value, settings_location location, const char *name, bool tooltip, const char *format) +void settings::add_input(int priority, ConfigFloat& value, settings_location location, const char* name, bool tooltip, const char* format) { auto setting_value = new SettingValue_InputFloat; setting_value->type = setting_type::INPUT_FLOAT; @@ -870,13 +879,13 @@ void settings::add_input(int priority, ConfigFloat &value, settings_location loc setting_value->value = &value; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_input(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip) +void settings::add_input(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_InputUnsigned; setting_value->type = setting_type::INPUT_UINT; @@ -885,13 +894,13 @@ void settings::add_input(int priority, ConfigUnsigned &value, settings_location setting_value->value = &value; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_input(int priority, ConfigString &value, settings_location location, const char *name, bool tooltip, bool allow_whitespace) +void settings::add_input(int priority, ConfigString& value, settings_location location, const char* name, bool tooltip, bool allow_whitespace) { auto setting_value = new SettingValue_InputString; setting_value->type = setting_type::INPUT_STRING; @@ -901,13 +910,13 @@ void settings::add_input(int priority, ConfigString &value, settings_location lo setting_value->name = name; setting_value->allow_whitespace = allow_whitespace; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_slider(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip) +void settings::add_slider(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_SliderInt; setting_value->type = setting_type::SLIDER_INT; @@ -916,13 +925,13 @@ void settings::add_slider(int priority, ConfigInt &value, settings_location loca setting_value->value = &value; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_slider(int priority, ConfigFloat &value, settings_location location, const char *name, bool tooltip, const char *format) +void settings::add_slider(int priority, ConfigFloat& value, settings_location location, const char* name, bool tooltip, const char* format) { auto setting_value = new SettingValue_SliderFloat; setting_value->type = setting_type::SLIDER_FLOAT; @@ -932,13 +941,13 @@ void settings::add_slider(int priority, ConfigFloat &value, settings_location lo setting_value->name = name; setting_value->format = format; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_slider(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip) +void settings::add_slider(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_SliderUnsigned; setting_value->type = setting_type::SLIDER_UINT; @@ -947,13 +956,13 @@ void settings::add_slider(int priority, ConfigUnsigned &value, settings_location setting_value->value = &value; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value->value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); } -void settings::add_stepper(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip) +void settings::add_stepper(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_StepperInt; setting_value->type = setting_type::STEPPER_INT; @@ -969,7 +978,7 @@ void settings::add_stepper(int priority, ConfigInt &value, settings_location loc values_all.push_back(setting_value); } -void settings::add_stepper(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip) +void settings::add_stepper(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip) { auto setting_value = new SettingValue_StepperUnsigned; setting_value->type = setting_type::STEPPER_UINT; @@ -985,7 +994,7 @@ void settings::add_stepper(int priority, ConfigUnsigned &value, settings_locatio values_all.push_back(setting_value); } -void settings::add_keybind(int priority, ConfigKeyBind &value, settings_location location, const char *name) +void settings::add_keybind(int priority, ConfigKeyBind& value, settings_location location, const char* name) { auto setting_value = new SettingValue_KeyBind; setting_value->type = setting_type::KEYBIND; @@ -1000,7 +1009,7 @@ void settings::add_keybind(int priority, ConfigKeyBind &value, settings_location values_all.push_back(setting_value); } -void settings::add_gamepad_axis(int priority, ConfigGamepadAxis &value, settings_location location, const char *name) +void settings::add_gamepad_axis(int priority, ConfigGamepadAxis& value, settings_location location, const char* name) { auto setting_value = new SettingValue_GamepadAxis; setting_value->type = setting_type::GAMEPAD_AXIS; @@ -1015,7 +1024,7 @@ void settings::add_gamepad_axis(int priority, ConfigGamepadAxis &value, settings values_all.push_back(setting_value); } -void settings::add_gamepad_button(int priority, ConfigGamepadButton &value, settings_location location, const char *name) +void settings::add_gamepad_button(int priority, ConfigGamepadButton& value, settings_location location, const char* name) { auto setting_value = new SettingValue_GamepadButton; setting_value->type = setting_type::GAMEPAD_BUTTON; @@ -1030,7 +1039,7 @@ void settings::add_gamepad_button(int priority, ConfigGamepadButton &value, sett values_all.push_back(setting_value); } -void settings::add_language_select(int priority, settings_location location, const char *name) +void settings::add_language_select(int priority, settings_location location, const char* name) { auto setting_value = new SettingValue_Language; setting_value->type = setting_type::LANGUAGE_SELECT; @@ -1038,7 +1047,7 @@ void settings::add_language_select(int priority, settings_location location, con setting_value->has_tooltip = false; setting_value->name = name; - setting_value->wid = fmt::format("###{}", static_cast(setting_value)); + setting_value->wid = fmt::format("###{}", static_cast(setting_value)); values[static_cast(location)].push_back(setting_value); values_all.push_back(setting_value); diff --git a/game/client/settings.hh b/game/client/settings.hh index 2b9e553..4704a58 100644 --- a/game/client/settings.hh +++ b/game/client/settings.hh @@ -14,20 +14,20 @@ class ConfigGamepadAxis; class ConfigGamepadButton; enum class settings_location : unsigned int { - GENERAL = 0x0000U, - KEYBOARD_MOVEMENT = 0x0001U, - KEYBOARD_GAMEPLAY = 0x0002U, - KEYBOARD_MISC = 0x0003U, - GAMEPAD = 0x0004U, - GAMEPAD_MOVEMENT = 0x0005U, - GAMEPAD_GAMEPLAY = 0x0006U, - GAMEPAD_MISC = 0x0007U, - MOUSE = 0x0008U, - VIDEO = 0x0009U, - VIDEO_GUI = 0x000AU, - SOUND = 0x000BU, - SOUND_LEVELS = 0x000CU, - COUNT = 0x000DU, + GENERAL = 0x0000U, + KEYBOARD_MOVEMENT = 0x0001U, + KEYBOARD_GAMEPLAY = 0x0002U, + KEYBOARD_MISC = 0x0003U, + GAMEPAD = 0x0004U, + GAMEPAD_MOVEMENT = 0x0005U, + GAMEPAD_GAMEPLAY = 0x0006U, + GAMEPAD_MISC = 0x0007U, + MOUSE = 0x0008U, + VIDEO = 0x0009U, + VIDEO_GUI = 0x000AU, + SOUND = 0x000BU, + SOUND_LEVELS = 0x000CU, + COUNT = 0x000DU, }; namespace settings @@ -40,44 +40,44 @@ void layout(void); namespace settings { -void add_checkbox(int priority, ConfigBoolean &value, settings_location location, const char *name, bool tooltip); +void add_checkbox(int priority, ConfigBoolean& value, settings_location location, const char* name, bool tooltip); } // namespace settings namespace settings { -void add_input(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip); -void add_input(int priority, ConfigFloat &value, settings_location location, const char *name, bool tooltip, const char *format = "%.3f"); -void add_input(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip); -void add_input(int priority, ConfigString &value, settings_location location, const char *name, bool tooltip, bool allow_whitespace); +void add_input(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip); +void add_input(int priority, ConfigFloat& value, settings_location location, const char* name, bool tooltip, const char* format = "%.3f"); +void add_input(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip); +void add_input(int priority, ConfigString& value, settings_location location, const char* name, bool tooltip, bool allow_whitespace); } // namespace settings namespace settings { -void add_slider(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip); -void add_slider(int priority, ConfigFloat &value, settings_location location, const char *name, bool tooltip, const char *format = "%.3f"); -void add_slider(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip); +void add_slider(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip); +void add_slider(int priority, ConfigFloat& value, settings_location location, const char* name, bool tooltip, const char* format = "%.3f"); +void add_slider(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip); } // namespace settings namespace settings { -void add_stepper(int priority, ConfigInt &value, settings_location location, const char *name, bool tooltip); -void add_stepper(int priority, ConfigUnsigned &value, settings_location location, const char *name, bool tooltip); +void add_stepper(int priority, ConfigInt& value, settings_location location, const char* name, bool tooltip); +void add_stepper(int priority, ConfigUnsigned& value, settings_location location, const char* name, bool tooltip); } // namespace settings namespace settings { -void add_keybind(int priority, ConfigKeyBind &value, settings_location location, const char *name); +void add_keybind(int priority, ConfigKeyBind& value, settings_location location, const char* name); } // namespace settings namespace settings { -void add_gamepad_axis(int priority, ConfigGamepadAxis &value, settings_location location, const char *name); -void add_gamepad_button(int priority, ConfigGamepadButton &value, settings_location location, const char *name); +void add_gamepad_axis(int priority, ConfigGamepadAxis& value, settings_location location, const char* name); +void add_gamepad_button(int priority, ConfigGamepadButton& value, settings_location location, const char* name); } // namespace settings namespace settings { -void add_language_select(int priority, settings_location location, const char *name); +void add_language_select(int priority, settings_location location, const char* name); } // namespace settings #endif /* CLIENT_SETTINGS_HH */ diff --git a/game/client/skybox.cc b/game/client/skybox.cc index 9482127..8578f0e 100644 --- a/game/client/skybox.cc +++ b/game/client/skybox.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/skybox.hh" glm::fvec3 skybox::fog_color; diff --git a/game/client/sound.cc b/game/client/sound.cc index 2512a04..c3ea543 100644 --- a/game/client/sound.cc +++ b/game/client/sound.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/sound.hh" #include "core/config.hh" @@ -68,7 +69,6 @@ void sound::init(void) void sound::init_late(void) { - } void sound::deinit(void) @@ -82,7 +82,6 @@ void sound::deinit(void) alDeleteSources(1, &player_source); } - void sound::update(void) { auto effects_gain = cxpr::clamp(0.01f * sound::volume_effects.get_value(), 0.0f, 1.0f); @@ -93,32 +92,40 @@ void sound::update(void) alSourcef(ui_source, AL_GAIN, ui_gain); } -void sound::play_generic(const char *sound, bool looping, float pitch) +void sound::play_generic(const char* sound, bool looping, float pitch) { - if(sound) + if(sound) { sound::play_generic(resource::load(sound), looping, pitch); - else sound::play_generic(static_cast(nullptr), looping, pitch); + } else { + sound::play_generic(static_cast(nullptr), looping, pitch); + } } -void sound::play_entity(entt::entity entity, const char *sound, bool looping, float pitch) +void sound::play_entity(entt::entity entity, const char* sound, bool looping, float pitch) { - if(sound) + if(sound) { sound::play_entity(entity, resource::load(sound), looping, pitch); - else sound::play_entity(entity, static_cast(nullptr), looping, pitch); + } else { + sound::play_entity(entity, static_cast(nullptr), looping, pitch); + } } -void sound::play_player(const char *sound, bool looping, float pitch) +void sound::play_player(const char* sound, bool looping, float pitch) { - if(sound) + if(sound) { sound::play_player(resource::load(sound), looping, pitch); - else sound::play_player(static_cast(nullptr), looping, pitch); + } else { + sound::play_player(static_cast(nullptr), looping, pitch); + } } -void sound::play_ui(const char *sound, bool looping, float pitch) +void sound::play_ui(const char* sound, bool looping, float pitch) { - if(sound) + if(sound) { sound::play_ui(resource::load(sound), looping, pitch); - else sound::play_ui(static_cast(nullptr), looping, pitch); + } else { + sound::play_ui(static_cast(nullptr), looping, pitch); + } } void sound::play_generic(resource_ptr sound, bool looping, float pitch) @@ -169,7 +176,7 @@ void sound::play_player(resource_ptr sound, bool looping, float pit sfx_player = sound; - if(sfx_player) { + if(sfx_player) { alSourcei(player_source, AL_BUFFER, sfx_player->buffer); alSourcei(player_source, AL_LOOPING, looping); alSourcef(player_source, AL_PITCH, cxpr::clamp(pitch, MIN_PITCH, MAX_PITCH)); diff --git a/game/client/sound.hh b/game/client/sound.hh index 05ea39f..2701ae0 100644 --- a/game/client/sound.hh +++ b/game/client/sound.hh @@ -26,10 +26,10 @@ void update(void); namespace sound { -void play_generic(const char *sound, bool looping, float pitch); -void play_entity(entt::entity entity, const char *sound, bool looping, float pitch); -void play_player(const char *sound, bool looping, float pitch); -void play_ui(const char *sound, bool looping, float pitch); +void play_generic(const char* sound, bool looping, float pitch); +void play_entity(entt::entity entity, const char* sound, bool looping, float pitch); +void play_player(const char* sound, bool looping, float pitch); +void play_ui(const char* sound, bool looping, float pitch); } // namespace sound namespace sound diff --git a/game/client/sound_effect.cc b/game/client/sound_effect.cc index 4e01e8c..182f49d 100644 --- a/game/client/sound_effect.cc +++ b/game/client/sound_effect.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/sound_effect.hh" #include "core/resource.hh" @@ -7,20 +8,22 @@ static emhash8::HashMap> resource_map; -static std::size_t drwav_read_physfs(void *file, void *output, std::size_t count) +static std::size_t drwav_read_physfs(void* file, void* output, std::size_t count) { - return static_cast(PHYSFS_readBytes(reinterpret_cast(file), output, count)); + return static_cast(PHYSFS_readBytes(reinterpret_cast(file), output, count)); } -static drwav_bool32 drwav_seek_physfs(void *file, int offset, drwav_seek_origin origin) +static drwav_bool32 drwav_seek_physfs(void* file, int offset, drwav_seek_origin origin) { - if(origin == drwav_seek_origin_current) - return PHYSFS_seek(reinterpret_cast(file), PHYSFS_tell(reinterpret_cast(file)) + offset); - return PHYSFS_seek(reinterpret_cast(file), offset); + if(origin == drwav_seek_origin_current) { + return PHYSFS_seek(reinterpret_cast(file), PHYSFS_tell(reinterpret_cast(file)) + offset); + } else { + return PHYSFS_seek(reinterpret_cast(file), offset); + } } template<> -resource_ptr resource::load(const char *name, unsigned int flags) +resource_ptr resource::load(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -41,7 +44,6 @@ resource_ptr resource::load(const char *name, unsigned return nullptr; } - drwav wav_info; if(!drwav_init(&wav_info, &drwav_read_physfs, &drwav_seek_physfs, file, nullptr)) { @@ -58,7 +60,7 @@ resource_ptr resource::load(const char *name, unsigned } auto samples = new ALshort[wav_info.totalPCMFrameCount]; - auto count = drwav_read_pcm_frames_s16(&wav_info, wav_info.totalPCMFrameCount, reinterpret_cast(samples)); + auto count = drwav_read_pcm_frames_s16(&wav_info, wav_info.totalPCMFrameCount, reinterpret_cast(samples)); auto sample_rate = static_cast(wav_info.sampleRate); auto length = static_cast(count * sizeof(ALshort)); @@ -79,10 +81,12 @@ resource_ptr resource::load(const char *name, unsigned template<> void resource::hard_cleanup(void) { - for(const auto &it : resource_map) { - if(it.second.use_count() > 1L) + for(const auto& it : resource_map) { + if(it.second.use_count() > 1L) { spdlog::warn("resource: zombie resource [SoundEffect] {} [use_count={}]", it.first, it.second.use_count()); - else spdlog::debug("resource: releasing [SoundEffect] {}", it.first); + } else { + spdlog::debug("resource: releasing [SoundEffect] {}", it.first); + } alDeleteBuffers(1, &it.second->buffer); } diff --git a/game/client/sound_emitter.cc b/game/client/sound_emitter.cc index 441ca17..fd58c50 100644 --- a/game/client/sound_emitter.cc +++ b/game/client/sound_emitter.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/sound_emitter.hh" #include "core/config.hh" @@ -30,7 +31,7 @@ void SoundEmitterComponent::update(void) if(globals::dimension) { const auto view = globals::dimension->entities.view(); - const auto &pivot = camera::position_chunk; + const auto& pivot = camera::position_chunk; const auto gain = cxpr::clamp(sound::volume_effects.get_value() * 0.01f, 0.0f, 1.0f); for(const auto [entity, emitter] : view.each()) { diff --git a/game/client/splash.cc b/game/client/splash.cc index 1de1e93..96159d2 100644 --- a/game/client/splash.cc +++ b/game/client/splash.cc @@ -1,10 +1,11 @@ #include "client/pch.hh" + #include "client/splash.hh" #include "core/cmdline.hh" #include "core/constexpr.hh" -#include "core/feature.hh" #include "core/epoch.hh" +#include "core/feature.hh" #include "core/resource.hh" #include "client/glfw.hh" @@ -17,7 +18,7 @@ constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | constexpr static int SPLASH_COUNT = 4; constexpr static std::size_t DELAY_MICROSECONDS = 2000000; -constexpr static const char *SPLASH_PATH = "textures/gui/client_splash.png"; +constexpr static const char* SPLASH_PATH = "textures/gui/client_splash.png"; static resource_ptr texture; static float texture_aspect; @@ -26,17 +27,17 @@ static float texture_alpha; static std::uint64_t end_time; static std::string current_text; -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { end_time = UINT64_C(0); } -static void on_glfw_mouse_button(const GlfwMouseButtonEvent &event) +static void on_glfw_mouse_button(const GlfwMouseButtonEvent& event) { end_time = UINT64_C(0); } -static void on_glfw_scroll(const GlfwScrollEvent &event) +static void on_glfw_scroll(const GlfwScrollEvent& event) { end_time = UINT64_C(0); } @@ -58,9 +59,12 @@ void client_splash::init(void) texture_alpha = 0.0f; if(texture) { - if(texture->size.x > texture->size.y) + if(texture->size.x > texture->size.y) { texture_aspect = static_cast(texture->size.x) / static_cast(texture->size.y); - else texture_aspect = static_cast(texture->size.y) / static_cast(texture->size.x); + } else { + texture_aspect = static_cast(texture->size.y) / static_cast(texture->size.x); + } + texture_alpha = 1.0f; } } @@ -85,8 +89,9 @@ void client_splash::init_late(void) const std::uint64_t curtime = epoch::microseconds(); const std::uint64_t remains = end_time - curtime; - if(curtime >= end_time) + if(curtime >= end_time) { break; + } texture_alpha = cxpr::smoothstep(0.25f, 0.6f, static_cast(remains) / static_cast(DELAY_MICROSECONDS)); @@ -117,7 +122,7 @@ void client_splash::render(void) ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - + glDisable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, globals::width, globals::height); diff --git a/game/client/status_lines.cc b/game/client/status_lines.cc index f39ba6f..ea7293c 100644 --- a/game/client/status_lines.cc +++ b/game/client/status_lines.cc @@ -1,11 +1,12 @@ #include "client/pch.hh" + #include "client/status_lines.hh" #include "client/globals.hh" #include "client/imdraw_ext.hh" static float line_offsets[STATUS_COUNT]; -static ImFont *line_fonts[STATUS_COUNT]; +static ImFont* line_fonts[STATUS_COUNT]; static ImVec4 line_text_colors[STATUS_COUNT]; static ImVec4 line_shadow_colors[STATUS_COUNT]; @@ -40,8 +41,8 @@ void status_lines::layout(void) for(unsigned int i = 0U; i < STATUS_COUNT; ++i) { auto offset = line_offsets[i] * globals::gui_scale; - auto &text = line_strings[i]; - auto *font = line_fonts[i]; + auto& text = line_strings[i]; + auto* font = line_fonts[i]; auto size = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.size()); auto pos = ImVec2(0.5f * (viewport->Size.x - size.x), viewport->Size.y - offset); @@ -50,8 +51,8 @@ void status_lines::layout(void) auto fadeout = line_fadeouts[i]; auto alpha = std::exp(-1.0f * std::pow(1.0e-6f * static_cast(globals::curtime - spawn) / fadeout, 10.0f)); - auto &color = line_text_colors[i]; - auto &shadow = line_shadow_colors[i]; + auto& color = line_text_colors[i]; + auto& shadow = line_shadow_colors[i]; auto color_U32 = ImGui::GetColorU32(ImVec4(color.x, color.y, color.z, color.w * alpha)); auto shadow_U32 = ImGui::GetColorU32(ImVec4(shadow.x, shadow.y, shadow.z, color.w * alpha)); @@ -59,7 +60,7 @@ void status_lines::layout(void) } } -void status_lines::set(unsigned int line, const std::string &text, const ImVec4 &color, float fadeout) +void status_lines::set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout) { line_text_colors[line] = ImVec4(color.x, color.y, color.z, color.w); line_shadow_colors[line] = ImVec4(color.x * 0.1f, color.y * 0.1f, color.z * 0.1f, color.w); diff --git a/game/client/status_lines.hh b/game/client/status_lines.hh index 433eac9..c252a34 100644 --- a/game/client/status_lines.hh +++ b/game/client/status_lines.hh @@ -2,9 +2,9 @@ #define CLIENT_STATUS_LINES_HH 1 #pragma once -constexpr static unsigned int STATUS_DEBUG = 0x0000; // generic debug line +constexpr static unsigned int STATUS_DEBUG = 0x0000; // generic debug line constexpr static unsigned int STATUS_HOTBAR = 0x0001; // hotbar item line -constexpr static unsigned int STATUS_COUNT = 0x0002; +constexpr static unsigned int STATUS_COUNT = 0x0002; namespace status_lines { @@ -15,7 +15,7 @@ void layout(void); namespace status_lines { -void set(unsigned int line, const std::string &text, const ImVec4 &color, float fadeout); +void set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout); void unset(unsigned int line); } // namespace status_lines diff --git a/game/client/texture_gui.cc b/game/client/texture_gui.cc index 9253986..265f6c2 100644 --- a/game/client/texture_gui.cc +++ b/game/client/texture_gui.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/texture_gui.hh" #include "core/image.hh" @@ -7,7 +8,7 @@ static emhash8::HashMap> resource_map; template<> -resource_ptr resource::load(const char *name, unsigned int flags) +resource_ptr resource::load(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -16,10 +17,15 @@ resource_ptr resource::load(const char *name, unsigned i return it->second; } - unsigned int image_load_flags = 0U; - if(flags & TEXTURE_GUI_LOAD_VFLIP) image_load_flags |= IMAGE_LOAD_FLIP; - if(flags & TEXTURE_GUI_LOAD_GRAYSCALE) image_load_flags |= IMAGE_LOAD_GRAY; + + if(flags & TEXTURE_GUI_LOAD_VFLIP) { + image_load_flags |= IMAGE_LOAD_FLIP; + } + + if(flags & TEXTURE_GUI_LOAD_GRAYSCALE) { + image_load_flags |= IMAGE_LOAD_GRAY; + } if(auto image = resource::load(name, image_load_flags)) { GLuint gl_texture; @@ -28,27 +34,35 @@ resource_ptr resource::load(const char *name, unsigned i glBindTexture(GL_TEXTURE_2D, gl_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->size.x, image->size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); - if(flags & TEXTURE_GUI_LOAD_CLAMP_S) + if(flags & TEXTURE_GUI_LOAD_CLAMP_S) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } - if(flags & TEXTURE_GUI_LOAD_CLAMP_T) + if(flags & TEXTURE_GUI_LOAD_CLAMP_T) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } - if(flags & TEXTURE_GUI_LOAD_LINEAR_MAG) + if(flags & TEXTURE_GUI_LOAD_LINEAR_MAG) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } - if(flags & TEXTURE_GUI_LOAD_LINEAR_MIN) + if(flags & TEXTURE_GUI_LOAD_LINEAR_MIN) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } auto new_resource = std::make_shared(); new_resource->handle = static_cast(gl_texture); new_resource->size.x = image->size.x; new_resource->size.y = image->size.y; - + return resource_map.insert_or_assign(name, new_resource).first->second; } @@ -58,10 +72,12 @@ resource_ptr resource::load(const char *name, unsigned i template<> void resource::hard_cleanup(void) { - for(const auto &it : resource_map) { - if(it.second.use_count() > 1L) + for(const auto& it : resource_map) { + if(it.second.use_count() > 1L) { spdlog::warn("resource: zombie resource [TextureGUI] {} [use_count={}]", it.first, it.second.use_count()); - else spdlog::debug("resource: releasing [TextureGUI] {}", it.first); + } else { + spdlog::debug("resource: releasing [TextureGUI] {}", it.first); + } auto gl_texture = static_cast(it.second->handle); diff --git a/game/client/texture_gui.hh b/game/client/texture_gui.hh index 05102fb..97a91b4 100644 --- a/game/client/texture_gui.hh +++ b/game/client/texture_gui.hh @@ -2,12 +2,12 @@ #define CLIENT_TEXTURE2D_HH 1 #pragma once -constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_S = 0x0001; -constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_T = 0x0002; -constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MAG = 0x0004; -constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MIN = 0x0008; -constexpr static unsigned int TEXTURE_GUI_LOAD_VFLIP = 0x0010; -constexpr static unsigned int TEXTURE_GUI_LOAD_GRAYSCALE = 0x0020; +constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_S = 0x0001; +constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_T = 0x0002; +constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MAG = 0x0004; +constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MIN = 0x0008; +constexpr static unsigned int TEXTURE_GUI_LOAD_VFLIP = 0x0010; +constexpr static unsigned int TEXTURE_GUI_LOAD_GRAYSCALE = 0x0020; struct TextureGUI { ImTextureID handle; diff --git a/game/client/toggles.cc b/game/client/toggles.cc index 105b0d2..fff8f4d 100644 --- a/game/client/toggles.cc +++ b/game/client/toggles.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/toggles.hh" #include "core/config.hh" @@ -11,7 +12,7 @@ #include "client/language.hh" struct ToggleInfo final { - const char *description; + const char* description; int glfw_keycode; bool is_enabled; }; @@ -20,30 +21,31 @@ bool toggles::is_sequence_await = false; static ToggleInfo toggle_infos[TOGGLE_COUNT]; -static void print_toggle_state(const ToggleInfo &info) +static void print_toggle_state(const ToggleInfo& info) { if(info.description) { - if(info.is_enabled) + if(info.is_enabled) { client_chat::print(fmt::format("[toggles] {} ON", info.description)); - else client_chat::print(fmt::format("[toggles] {} OFF", info.description)); + } else { + client_chat::print(fmt::format("[toggles] {} OFF", info.description)); + } } } -static void toggle_value(ToggleInfo &info, toggle_type type) +static void toggle_value(ToggleInfo& info, toggle_type type) { if(info.is_enabled) { info.is_enabled = false; - globals::dispatcher.trigger(ToggleDisabledEvent {type}); - } - else { + globals::dispatcher.trigger(ToggleDisabledEvent { type }); + } else { info.is_enabled = true; - globals::dispatcher.trigger(ToggleEnabledEvent {type}); + globals::dispatcher.trigger(ToggleEnabledEvent { type }); } print_toggle_state(info); } -static void on_glfw_key(const GlfwKeyEvent &event) +static void on_glfw_key(const GlfwKeyEvent& event) { if(globals::gui_keybind_ptr) { // The UI keybind subsystem has the authority @@ -119,17 +121,21 @@ void toggles::init(void) void toggles::init_late(void) { for(toggle_type i = 0; i < TOGGLE_COUNT; ++i) { - if(toggle_infos[i].is_enabled) - globals::dispatcher.trigger(ToggleEnabledEvent {i}); - else globals::dispatcher.trigger(ToggleDisabledEvent {i}); + if(toggle_infos[i].is_enabled) { + globals::dispatcher.trigger(ToggleEnabledEvent { i }); + } else { + globals::dispatcher.trigger(ToggleDisabledEvent { i }); + } } } bool toggles::get(toggle_type type) { - if(type < TOGGLE_COUNT) + if(type < TOGGLE_COUNT) { return toggle_infos[type].is_enabled; - return false; + } else { + return false; + } } void toggles::set(toggle_type type, bool value) @@ -137,11 +143,10 @@ void toggles::set(toggle_type type, bool value) if(type < TOGGLE_COUNT) { if(value) { toggle_infos[type].is_enabled = true; - globals::dispatcher.trigger(ToggleEnabledEvent {type}); - } - else { + globals::dispatcher.trigger(ToggleEnabledEvent { type }); + } else { toggle_infos[type].is_enabled = false; - globals::dispatcher.trigger(ToggleDisabledEvent {type}); + globals::dispatcher.trigger(ToggleDisabledEvent { type }); } print_toggle_state(toggle_infos[type]); diff --git a/game/client/toggles.hh b/game/client/toggles.hh index d5b18c7..d892d33 100644 --- a/game/client/toggles.hh +++ b/game/client/toggles.hh @@ -3,13 +3,13 @@ #pragma once using toggle_type = unsigned int; -constexpr static toggle_type TOGGLE_WIREFRAME = 0x0000U; // Render things in wireframe mode -constexpr static toggle_type TOGGLE_FULLBRIGHT = 0x0001U; // Render things without lighting -constexpr static toggle_type TOGGLE_CHUNK_AABB = 0x0002U; // Render chunk bounding boxes -constexpr static toggle_type TOGGLE_METRICS_UI = 0x0003U; // Render debug metrics overlay +constexpr static toggle_type TOGGLE_WIREFRAME = 0x0000U; // Render things in wireframe mode +constexpr static toggle_type TOGGLE_FULLBRIGHT = 0x0001U; // Render things without lighting +constexpr static toggle_type TOGGLE_CHUNK_AABB = 0x0002U; // Render chunk bounding boxes +constexpr static toggle_type TOGGLE_METRICS_UI = 0x0003U; // Render debug metrics overlay constexpr static toggle_type TOGGLE_USE_GAMEPAD = 0x0004U; // Use gamepad for player movement -constexpr static toggle_type TOGGLE_PM_FLIGHT = 0x0005U; // Enable flight for player movement -constexpr static std::size_t TOGGLE_COUNT = 0x0006U; +constexpr static toggle_type TOGGLE_PM_FLIGHT = 0x0005U; // Enable flight for player movement +constexpr static std::size_t TOGGLE_COUNT = 0x0006U; struct ToggleEnabledEvent final { toggle_type type; diff --git a/game/client/voxel_anims.cc b/game/client/voxel_anims.cc index 3d3c3b6..4e0f168 100644 --- a/game/client/voxel_anims.cc +++ b/game/client/voxel_anims.cc @@ -1,8 +1,9 @@ #include "client/pch.hh" + #include "client/voxel_anims.hh" -#include "core/constexpr.hh" #include "core/config.hh" +#include "core/constexpr.hh" #include "client/globals.hh" diff --git a/game/client/voxel_atlas.cc b/game/client/voxel_atlas.cc index ffdd0e4..0ce872f 100644 --- a/game/client/voxel_atlas.cc +++ b/game/client/voxel_atlas.cc @@ -1,5 +1,5 @@ -// SPDX-License-Identifier: BSD-2-Clause #include "client/pch.hh" + #include "client/voxel_atlas.hh" #include "core/constexpr.hh" @@ -25,15 +25,15 @@ static std::vector planes; // textures (see the "default" texture part in VoxelInfoBuilder::build) // so there could either be six UNIQUE atlas strips or only one // https://crypto.stackexchange.com/questions/55162/best-way-to-hash-two-values-into-one -static std::size_t vector_hash(const std::vector &strings) +static std::size_t vector_hash(const std::vector& strings) { std::size_t source = 0; - for(const std::string &str : strings) + for(const std::string& str : strings) source += crc64::get(str); return crc64::get(&source, sizeof(source)); } -static void plane_setup(AtlasPlane &plane) +static void plane_setup(AtlasPlane& plane) { glGenTextures(1, &plane.gl_texture); glBindTexture(GL_TEXTURE_2D_ARRAY, plane.gl_texture); @@ -44,22 +44,25 @@ static void plane_setup(AtlasPlane &plane) glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); } -static AtlasStrip *plane_lookup(AtlasPlane &plane, std::size_t hash_value) +static AtlasStrip* plane_lookup(AtlasPlane& plane, std::size_t hash_value) { const auto it = plane.lookup.find(hash_value); - if(it != plane.lookup.cend()) + + if(it != plane.lookup.cend()) { return &plane.strips[it->second]; + } + return nullptr; } -static AtlasStrip *plane_new_strip(AtlasPlane &plane, const std::vector &paths, std::size_t hash_value) +static AtlasStrip* plane_new_strip(AtlasPlane& plane, const std::vector& paths, std::size_t hash_value) { AtlasStrip strip = {}; strip.offset = plane.layer_count; strip.plane = plane.plane_id; - + glBindTexture(GL_TEXTURE_2D_ARRAY, plane.gl_texture); - + for(std::size_t i = 0; i < paths.size(); ++i) { if(auto image = resource::load(paths[i].c_str(), IMAGE_LOAD_FLIP)) { if((image->size.x != atlas_width) || (image->size.y != atlas_height)) { @@ -71,7 +74,7 @@ static AtlasStrip *plane_new_strip(AtlasPlane &plane, const std::vectorsize.x, image->size.y, 1, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); } } - + plane.layer_count += paths.size(); const std::size_t index = plane.strips.size(); @@ -111,7 +114,7 @@ void voxel_atlas::create(int width, int height, std::size_t count) void voxel_atlas::destroy(void) { - for(const AtlasPlane &plane : planes) + for(const AtlasPlane& plane : planes) glDeleteTextures(1, &plane.gl_texture); atlas_width = 0; atlas_height = 0; @@ -125,45 +128,53 @@ std::size_t voxel_atlas::plane_count(void) GLuint voxel_atlas::plane_texture(std::size_t plane_id) { - if(plane_id < planes.size()) + if(plane_id < planes.size()) { return planes[plane_id].gl_texture; - return 0; + } else { + return 0; + } } void voxel_atlas::generate_mipmaps(void) { - for(const AtlasPlane &plane : planes) { + for(const AtlasPlane& plane : planes) { glBindTexture(GL_TEXTURE_2D_ARRAY, plane.gl_texture); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); } } -AtlasStrip *voxel_atlas::find_or_load(const std::vector &paths) +AtlasStrip* voxel_atlas::find_or_load(const std::vector& paths) { const std::size_t hash_value = vector_hash(paths); - for(AtlasPlane &plane : planes) { - if(AtlasStrip *strip = plane_lookup(plane, hash_value)) + for(AtlasPlane& plane : planes) { + if(AtlasStrip* strip = plane_lookup(plane, hash_value)) { return strip; + } + continue; } - for(AtlasPlane &plane : planes) { - if((plane.layer_count + paths.size()) <= plane.layer_count_max) + for(AtlasPlane& plane : planes) { + if((plane.layer_count + paths.size()) <= plane.layer_count_max) { return plane_new_strip(plane, paths, hash_value); + } + continue; } return nullptr; } -AtlasStrip *voxel_atlas::find(const std::vector &paths) +AtlasStrip* voxel_atlas::find(const std::vector& paths) { const std::size_t hash_value = vector_hash(paths); - for(AtlasPlane &plane : planes) { - if(AtlasStrip *strip = plane_lookup(plane, hash_value)) + for(AtlasPlane& plane : planes) { + if(AtlasStrip* strip = plane_lookup(plane, hash_value)) { return strip; + } + continue; } diff --git a/game/client/voxel_atlas.hh b/game/client/voxel_atlas.hh index 9435173..67036ca 100644 --- a/game/client/voxel_atlas.hh +++ b/game/client/voxel_atlas.hh @@ -22,8 +22,8 @@ void generate_mipmaps(void); namespace voxel_atlas { -AtlasStrip *find_or_load(const std::vector &paths); -AtlasStrip *find(const std::vector &paths); +AtlasStrip* find_or_load(const std::vector& paths); +AtlasStrip* find(const std::vector& paths); } // namespace voxel_atlas #endif /* CLIENT_VOXEL_ATLAS_HH */ diff --git a/game/client/voxel_sounds.cc b/game/client/voxel_sounds.cc index a18c130..fd02a8e 100644 --- a/game/client/voxel_sounds.cc +++ b/game/client/voxel_sounds.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/voxel_sounds.hh" #include "client/sound_effect.hh" @@ -8,7 +9,7 @@ constexpr static std::size_t NUM_SURFACES = static_cast(voxel_surfa static std::vector> footsteps_sounds[NUM_SURFACES]; static std::mt19937_64 randomizer; -static void add_footsteps_effect(voxel_surface surface, const char *name) +static void add_footsteps_effect(voxel_surface surface, const char* name) { if(auto effect = resource::load(name)) { auto surface_index = static_cast(surface); @@ -25,7 +26,7 @@ static resource_ptr get_footsteps_effect(voxel_surface surface) return nullptr; } - const auto &sounds = footsteps_sounds[surface_index]; + const auto& sounds = footsteps_sounds[surface_index]; if(sounds.empty()) { // No sounds for this surface diff --git a/game/client/window_title.cc b/game/client/window_title.cc index fc113c2..cfa25a3 100644 --- a/game/client/window_title.cc +++ b/game/client/window_title.cc @@ -1,4 +1,5 @@ #include "client/pch.hh" + #include "client/window_title.hh" #include "core/feature.hh" @@ -12,9 +13,11 @@ void window_title::update(void) { std::string title; - if(globals::sound_ctx && globals::sound_dev) + if(globals::sound_ctx && globals::sound_dev) { title = fmt::format("Voxelius {}: {}", PROJECT_VERSION_STRING, splash::get()); - else title = fmt::format("Voxelius {}: {} [NOSOUND]", PROJECT_VERSION_STRING, splash::get()); + } else { + title = fmt::format("Voxelius {}: {} [NOSOUND]", PROJECT_VERSION_STRING, splash::get()); + } glfwSetWindowTitle(globals::window, title.c_str()); } diff --git a/game/server/chat.cc b/game/server/chat.cc index 709d21b..1634c59 100644 --- a/game/server/chat.cc +++ b/game/server/chat.cc @@ -1,16 +1,19 @@ #include "server/pch.hh" + #include "server/chat.hh" #include "server/globals.hh" #include "server/sessions.hh" #include "shared/protocol.hh" -static void on_chat_message_packet(const protocol::ChatMessage &packet) +static void on_chat_message_packet(const protocol::ChatMessage& packet) { if(packet.type == protocol::ChatMessage::TEXT_MESSAGE) { - if(auto session = sessions::find(packet.peer)) + if(auto session = sessions::find(packet.peer)) { server_chat::broadcast(packet.message.c_str(), session->client_username.c_str()); - else server_chat::broadcast(packet.message.c_str(), packet.sender.c_str()); + } else { + server_chat::broadcast(packet.message.c_str(), packet.sender.c_str()); + } } } @@ -19,12 +22,12 @@ void server_chat::init(void) globals::dispatcher.sink().connect<&on_chat_message_packet>(); } -void server_chat::broadcast(const char *message) +void server_chat::broadcast(const char* message) { server_chat::broadcast(message, "server"); } -void server_chat::broadcast(const char *message, const char *sender) +void server_chat::broadcast(const char* message, const char* sender) { protocol::ChatMessage packet; packet.type = protocol::ChatMessage::TEXT_MESSAGE; @@ -36,12 +39,12 @@ void server_chat::broadcast(const char *message, const char *sender) spdlog::info("<{}> {}", sender, message); } -void server_chat::send(Session *session, const char *message) +void server_chat::send(Session* session, const char* message) { server_chat::send(session, message, "server"); } -void server_chat::send(Session *session, const char *message, const char *sender) +void server_chat::send(Session* session, const char* message, const char* sender) { protocol::ChatMessage packet; packet.type = protocol::ChatMessage::TEXT_MESSAGE; diff --git a/game/server/chat.hh b/game/server/chat.hh index 7efc7ff..2557290 100644 --- a/game/server/chat.hh +++ b/game/server/chat.hh @@ -7,10 +7,10 @@ struct Session; namespace server_chat { void init(void); -void broadcast(const char *message); -void broadcast(const char *message, const char *sender); -void send(Session *session, const char *message); -void send(Session *session, const char *message, const char *sender); +void broadcast(const char* message); +void broadcast(const char* message, const char* sender); +void send(Session* session, const char* message); +void send(Session* session, const char* message, const char* sender); } // namespace server_chat #endif /* SERVER_CHAT_HH */ diff --git a/game/server/game.cc b/game/server/game.cc index c6fc67f..978474c 100644 --- a/game/server/game.cc +++ b/game/server/game.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/game.hh" #include "core/cmdline.hh" @@ -75,7 +76,7 @@ void server_game::init_late(void) address.port = listen_port.get_value(); globals::server_host = enet_host_create(&address, sessions::max_players.get_value() + status_peers.get_value(), 1, 0, 0); - + if(!globals::server_host) { spdlog::critical("game: unable to setup an ENet host"); std::terminate(); diff --git a/game/server/globals.cc b/game/server/globals.cc index e0f50da..883588b 100644 --- a/game/server/globals.cc +++ b/game/server/globals.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/globals.hh" #include "core/config.hh" @@ -7,11 +8,11 @@ Config globals::server_config; -ENetHost *globals::server_host; +ENetHost* globals::server_host; bool globals::is_running; unsigned int globals::tickrate; std::uint64_t globals::tickrate_dt; -Dimension *globals::spawn_dimension; -std::unordered_map globals::dimensions; +Dimension* globals::spawn_dimension; +std::unordered_map globals::dimensions; diff --git a/game/server/globals.hh b/game/server/globals.hh index f2fc256..54f025a 100644 --- a/game/server/globals.hh +++ b/game/server/globals.hh @@ -12,14 +12,14 @@ namespace globals { extern Config server_config; -extern ENetHost *server_host; +extern ENetHost* server_host; extern bool is_running; extern unsigned int tickrate; extern std::uint64_t tickrate_dt; -extern Dimension *spawn_dimension; -extern std::unordered_map dimensions; +extern Dimension* spawn_dimension; +extern std::unordered_map dimensions; } // namespace globals #endif /* SERVER_GLOBALS_HH */ diff --git a/game/server/main.cc b/game/server/main.cc index 0eff05f..42e76f4 100644 --- a/game/server/main.cc +++ b/game/server/main.cc @@ -24,7 +24,7 @@ static void on_termination_signal(int) globals::is_running = false; } -int main(int argc, char **argv) +int main(int argc, char** argv) { cmdline::create(argc, argv); @@ -58,7 +58,7 @@ int main(int argc, char **argv) server_game::init_late(); std::uint64_t last_curtime = globals::curtime; - + while(globals::is_running) { globals::curtime = epoch::microseconds(); @@ -68,12 +68,12 @@ int main(int argc, char **argv) globals::fixed_frametime_avg *= 0.5f; last_curtime = globals::curtime; - + server_game::fixed_update(); server_game::fixed_update_late(); globals::dispatcher.update(); - + globals::fixed_framecount += 1; std::this_thread::sleep_for(std::chrono::microseconds(globals::tickrate_dt)); @@ -85,7 +85,7 @@ int main(int argc, char **argv) } server_game::deinit(); - + resource::hard_cleanup(); resource::hard_cleanup(); diff --git a/game/server/overworld.cc b/game/server/overworld.cc index 29bfd64..7021717 100644 --- a/game/server/overworld.cc +++ b/game/server/overworld.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/overworld.hh" #include "core/vectors.hh" @@ -8,7 +9,7 @@ #include "shared/voxel_storage.hh" // FIXME: load these from a file -static void compute_tree_feature(unsigned int height, Feature &feature, voxel_id log_voxel, voxel_id leaves_voxel) +static void compute_tree_feature(unsigned int height, Feature& feature, voxel_id log_voxel, voxel_id leaves_voxel) { // Ensure the tree height is too small height = cxpr::max(height, 4U); @@ -68,7 +69,7 @@ static void compute_tree_feature(unsigned int height, Feature &feature, voxel_id } } -Overworld::Overworld(const char *name) : Dimension(name, -30.0f) +Overworld::Overworld(const char* name) : Dimension(name, -30.0f) { m_bottommost_chunk.set_limits(-64, -4); m_terrain_variation.set_limits(16, 256); @@ -79,7 +80,7 @@ Overworld::Overworld(const char *name) : Dimension(name, -30.0f) compute_tree_feature(8U, m_feat_tree[3], game_voxels::oak_log, game_voxels::oak_leaves); } -void Overworld::init(Config &config) +void Overworld::init(Config& config) { m_terrain_variation.set_value(64); m_bottommost_chunk.set_value(-4); @@ -126,7 +127,7 @@ void Overworld::init_late(std::uint64_t global_seed) m_metamap.clear(); } -bool Overworld::generate(const chunk_pos &cpos, VoxelStorage &voxels) +bool Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels) { if(cpos.y <= m_bottommost_chunk.get_value()) { // If the player asks the generator @@ -157,14 +158,14 @@ bool Overworld::generate(const chunk_pos &cpos, VoxelStorage &voxels) return true; } -bool Overworld::is_inside_cave(const voxel_pos &vpos) +bool Overworld::is_inside_cave(const voxel_pos& vpos) { auto noise_a = fnlGetNoise3D(&m_fnl_caves_a, vpos.x, vpos.y * 2.0f, vpos.z); auto noise_b = fnlGetNoise3D(&m_fnl_caves_b, vpos.x, vpos.y * 2.0f, vpos.z); return (noise_a > 0.95f) && (noise_b > 0.85f); } -bool Overworld::is_inside_terrain(const voxel_pos &vpos) +bool Overworld::is_inside_terrain(const voxel_pos& vpos) { auto variation_noise = fnlGetNoise3D(&m_fnl_terrain, vpos.x, vpos.y, vpos.z); auto variation = m_terrain_variation.get_value() * (1.0f - (variation_noise * variation_noise)); @@ -172,7 +173,7 @@ bool Overworld::is_inside_terrain(const voxel_pos &vpos) return noise > 0.0f; } -const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz &cpos) +const Overworld_Metadata& Overworld::get_or_create_metadata(const chunk_pos_xz& cpos) { auto it = m_metamap.find(cpos); @@ -181,7 +182,7 @@ const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz & return it->second; } - auto &metadata = m_metamap.insert_or_assign(cpos, Overworld_Metadata()).first->second; + auto& metadata = m_metamap.insert_or_assign(cpos, Overworld_Metadata()).first->second; metadata.entropy.fill(std::numeric_limits::max()); metadata.heightmap.fill(std::numeric_limits::min()); @@ -219,7 +220,7 @@ const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz & auto lpos = local_pos((twister() % CHUNK_SIZE), (twister() % OW_NUM_TREES), (twister() % CHUNK_SIZE)); auto is_unique = true; - for(const auto &check_lpos : metadata.trees) { + for(const auto& check_lpos : metadata.trees) { if(cxvectors::distance2(check_lpos, lpos) <= 9) { is_unique = false; break; @@ -234,9 +235,9 @@ const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz & return metadata; } -void Overworld::generate_terrain(const chunk_pos &cpos, VoxelStorage &voxels) +void Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels) { - auto &metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); + auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); for(unsigned long i = 0; i < CHUNK_VOLUME; ++i) { @@ -260,9 +261,9 @@ void Overworld::generate_terrain(const chunk_pos &cpos, VoxelStorage &voxels) } } -void Overworld::generate_surface(const chunk_pos &cpos, VoxelStorage &voxels) +void Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& voxels) { - auto &metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); + auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); for(unsigned long i = 0; i < CHUNK_VOLUME; ++i) { @@ -289,31 +290,35 @@ void Overworld::generate_surface(const chunk_pos &cpos, VoxelStorage &voxels) auto d_index = coord::to_index(d_lpos); if(d_lpos.y >= CHUNK_SIZE) { - if(!is_inside_terrain(d_vpos)) + if(!is_inside_terrain(d_vpos)) { break; + } + depth += 1U; - } - else { - if(voxels[d_index] == NULL_VOXEL_ID) + } else { + if(voxels[d_index] == NULL_VOXEL_ID) { break; + } + depth += 1U; } } if(depth < 5U) { - if(depth == 0U) + if(depth == 0U) { voxels[i] = game_voxels::grass; - else voxels[i] = game_voxels::dirt; + } else { + voxels[i] = game_voxels::dirt; + } } } - } -void Overworld::generate_caves(const chunk_pos &cpos, VoxelStorage &voxels) +void Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxels) { - auto &metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); + auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); - + for(unsigned long i = 0U; i < CHUNK_VOLUME; ++i) { auto lpos = coord::to_local(i); auto vpos = coord::to_voxel(cpos, lpos); @@ -331,7 +336,7 @@ void Overworld::generate_caves(const chunk_pos &cpos, VoxelStorage &voxels) } } -void Overworld::generate_features(const chunk_pos &cpos, VoxelStorage &voxels) +void Overworld::generate_features(const chunk_pos& cpos, VoxelStorage& voxels) { const chunk_pos_xz tree_chunks[] = { chunk_pos_xz(cpos.x - 0, cpos.z - 1), @@ -346,10 +351,10 @@ void Overworld::generate_features(const chunk_pos &cpos, VoxelStorage &voxels) }; for(unsigned int i = 0U; i < cxpr::array_size(tree_chunks); ++i) { - const auto &cpos_xz = tree_chunks[i]; - const auto &metadata = get_or_create_metadata(cpos_xz); + const auto& cpos_xz = tree_chunks[i]; + const auto& metadata = get_or_create_metadata(cpos_xz); - for(const auto &tree_info : metadata.trees) { + for(const auto& tree_info : metadata.trees) { auto hdx = static_cast(tree_info.x + tree_info.z * CHUNK_SIZE); auto height = metadata.heightmap[hdx]; diff --git a/game/server/overworld.hh b/game/server/overworld.hh index 979e5a3..972a91d 100644 --- a/game/server/overworld.hh +++ b/game/server/overworld.hh @@ -18,26 +18,26 @@ struct Overworld_Metadata final { class Overworld final : public Dimension { public: - explicit Overworld(const char *name); + explicit Overworld(const char* name); virtual ~Overworld(void) = default; public: - virtual void init(Config &config) override; + virtual void init(Config& config) override; virtual void init_late(std::uint64_t global_seed) override; - virtual bool generate(const chunk_pos &cpos, VoxelStorage &voxels) override; + virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels) override; private: - bool is_inside_cave(const voxel_pos &vpos); - bool is_inside_terrain(const voxel_pos &vpos); + bool is_inside_cave(const voxel_pos& vpos); + bool is_inside_terrain(const voxel_pos& vpos); private: - const Overworld_Metadata &get_or_create_metadata(const chunk_pos_xz &cpos); + const Overworld_Metadata& get_or_create_metadata(const chunk_pos_xz& cpos); private: - void generate_terrain(const chunk_pos &cpos, VoxelStorage &voxels); - void generate_surface(const chunk_pos &cpos, VoxelStorage &voxels); - void generate_caves(const chunk_pos &cpos, VoxelStorage &voxels); - void generate_features(const chunk_pos &cpos, VoxelStorage &voxels); + void generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels); + void generate_surface(const chunk_pos& cpos, VoxelStorage& voxels); + void generate_caves(const chunk_pos& cpos, VoxelStorage& voxels); + void generate_features(const chunk_pos& cpos, VoxelStorage& voxels); private: ConfigInt m_terrain_variation; diff --git a/game/server/receive.cc b/game/server/receive.cc index 780ae53..7674122 100644 --- a/game/server/receive.cc +++ b/game/server/receive.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/receive.hh" #include "core/config.hh" @@ -18,11 +19,11 @@ #include "server/universe.hh" #include "server/worldgen.hh" -static void on_entity_transform_packet(const protocol::EntityTransform &packet) +static void on_entity_transform_packet(const protocol::EntityTransform& packet) { if(auto session = sessions::find(packet.peer)) { if(session->dimension && session->dimension->entities.valid(session->player_entity)) { - auto &component = session->dimension->entities.emplace_or_replace(session->player_entity); + auto& component = session->dimension->entities.emplace_or_replace(session->player_entity); component.angles = packet.angles; component.chunk = packet.chunk; component.local = packet.local; @@ -40,11 +41,11 @@ static void on_entity_transform_packet(const protocol::EntityTransform &packet) } } -static void on_entity_velocity_packet(const protocol::EntityVelocity &packet) +static void on_entity_velocity_packet(const protocol::EntityVelocity& packet) { if(auto session = sessions::find(packet.peer)) { if(session->dimension && session->dimension->entities.valid(session->player_entity)) { - auto &component = session->dimension->entities.emplace_or_replace(session->player_entity); + auto& component = session->dimension->entities.emplace_or_replace(session->player_entity); component.value = packet.value; protocol::EntityVelocity response; @@ -58,11 +59,11 @@ static void on_entity_velocity_packet(const protocol::EntityVelocity &packet) } } -static void on_entity_head_packet(const protocol::EntityHead &packet) +static void on_entity_head_packet(const protocol::EntityHead& packet) { if(auto session = sessions::find(packet.peer)) { if(session->dimension && session->dimension->entities.valid(session->player_entity)) { - auto &component = session->dimension->entities.emplace_or_replace(session->player_entity); + auto& component = session->dimension->entities.emplace_or_replace(session->player_entity); component.angles = packet.angles; protocol::EntityHead response; @@ -76,7 +77,7 @@ static void on_entity_head_packet(const protocol::EntityHead &packet) } } -static void on_set_voxel_packet(const protocol::SetVoxel &packet) +static void on_set_voxel_packet(const protocol::SetVoxel& packet) { if(auto session = sessions::find(packet.peer)) { if(session->dimension && !session->dimension->set_voxel(packet.voxel, packet.vpos)) { @@ -112,7 +113,7 @@ static void on_set_voxel_packet(const protocol::SetVoxel &packet) } } -static void on_request_chunk_packet(const protocol::RequestChunk &packet) +static void on_request_chunk_packet(const protocol::RequestChunk& packet) { if(auto session = sessions::find(packet.peer)) { if(!session->dimension || !session->dimension->entities.valid(session->player_entity)) { @@ -132,8 +133,7 @@ static void on_request_chunk_packet(const protocol::RequestChunk &packet) response.chunk = packet.cpos; response.voxels = chunk->get_voxels(); protocol::send(packet.peer, protocol::encode(response)); - } - else { + } else { worldgen::request_chunk(session, packet.cpos); } } @@ -141,7 +141,7 @@ static void on_request_chunk_packet(const protocol::RequestChunk &packet) } } -static void on_entity_sound_packet(const protocol::EntitySound &packet) +static void on_entity_sound_packet(const protocol::EntitySound& packet) { if(auto session = sessions::find(packet.peer)) { if(!session->dimension || !session->dimension->entities.valid(session->player_entity)) { diff --git a/game/server/sessions.cc b/game/server/sessions.cc index 58f12d4..a8745cb 100644 --- a/game/server/sessions.cc +++ b/game/server/sessions.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/sessions.hh" #include "core/config.hh" @@ -24,22 +25,22 @@ class DimensionListener final { public: - explicit DimensionListener(Dimension *dimension); - void on_destroy_entity(const entt::registry ®istry, entt::entity entity); + explicit DimensionListener(Dimension* dimension); + void on_destroy_entity(const entt::registry& registry, entt::entity entity); private: - Dimension *dimension; + Dimension* dimension; }; ConfigUnsigned sessions::max_players(8U, 1U, 128U); unsigned int sessions::num_players = 0U; -static emhash8::HashMap username_map; -static emhash8::HashMap identity_map; +static emhash8::HashMap username_map; +static emhash8::HashMap identity_map; static std::vector dimension_listeners; static std::vector sessions_vector; -static void on_login_request_packet(const protocol::LoginRequest &packet) +static void on_login_request_packet(const protocol::LoginRequest& packet) { if(packet.version > protocol::VERSION) { protocol::Disconnect response; @@ -95,15 +96,14 @@ static void on_login_request_packet(const protocol::LoginRequest &packet) protocol::send(packet.peer, protocol::encode(response)); return; } - } - else if(packet.password_hash != server_game::password_hash) { + } else if(packet.password_hash != server_game::password_hash) { protocol::Disconnect response; response.reason = "protocol.password_incorrect"; protocol::send(packet.peer, protocol::encode(response)); return; } - if(Session *session = sessions::create(packet.peer, packet.username.c_str())) { + if(Session* session = sessions::create(packet.peer, packet.username.c_str())) { protocol::LoginResponse response; response.client_index = session->client_index; response.client_identity = session->client_identity; @@ -114,9 +114,12 @@ static void on_login_request_packet(const protocol::LoginRequest &packet) dim_info.name = globals::spawn_dimension->get_name(); dim_info.gravity = globals::spawn_dimension->get_gravity(); protocol::send(packet.peer, protocol::encode(dim_info)); - - spdlog::info("sessions: {} [{}] logged in with client_index={} in {}", session->client_username, - session->client_identity, session->client_index, globals::spawn_dimension->get_name()); + + spdlog::info("sessions: {} [{}] logged in with client_index={} in {}", + session->client_username, + session->client_identity, + session->client_index, + globals::spawn_dimension->get_name()); // FIXME: only send entities that are present within the current // player's view bounding box; this also would mean we're not sending @@ -157,9 +160,9 @@ static void on_login_request_packet(const protocol::LoginRequest &packet) session->player_entity = globals::spawn_dimension->entities.create(); shared_factory::create_player(globals::spawn_dimension, session->player_entity); - const auto &head = globals::spawn_dimension->entities.get(session->player_entity); - const auto &transform = globals::spawn_dimension->entities.get(session->player_entity); - const auto &velocity = globals::spawn_dimension->entities.get(session->player_entity); + const auto& head = globals::spawn_dimension->entities.get(session->player_entity); + const auto& transform = globals::spawn_dimension->entities.get(session->player_entity); + const auto& velocity = globals::spawn_dimension->entities.get(session->player_entity); protocol::EntityHead head_packet; head_packet.entity = session->player_entity; @@ -209,14 +212,14 @@ static void on_login_request_packet(const protocol::LoginRequest &packet) protocol::send(packet.peer, protocol::encode(response)); } -static void on_disconnect_packet(const protocol::Disconnect &packet) +static void on_disconnect_packet(const protocol::Disconnect& packet) { - if(Session *session = sessions::find(packet.peer)) { + if(Session* session = sessions::find(packet.peer)) { protocol::ChatMessage message; message.type = protocol::ChatMessage::PLAYER_LEAVE; message.sender = session->client_username; message.message = packet.reason; - + protocol::broadcast(globals::server_host, protocol::encode(message), session->peer); spdlog::info("{} disconnected ({})", session->client_username, packet.reason); @@ -229,7 +232,7 @@ static void on_disconnect_packet(const protocol::Disconnect &packet) // NOTE: [sessions] is a good place for this since [receive] // handles entity data sent by players and [sessions] handles // everything else network related that is not player movement -static void on_voxel_set(const VoxelSetEvent &event) +static void on_voxel_set(const VoxelSetEvent& event) { protocol::SetVoxel packet; packet.vpos = coord::to_voxel(event.cpos, event.lpos); @@ -238,12 +241,12 @@ static void on_voxel_set(const VoxelSetEvent &event) protocol::broadcast(globals::server_host, protocol::encode(packet)); } -DimensionListener::DimensionListener(Dimension *dimension) +DimensionListener::DimensionListener(Dimension* dimension) { this->dimension = dimension; } -void DimensionListener::on_destroy_entity(const entt::registry ®istry, entt::entity entity) +void DimensionListener::on_destroy_entity(const entt::registry& registry, entt::entity entity) { protocol::RemoveEntity packet; packet.entity = entity; @@ -279,7 +282,7 @@ void sessions::init_late(void) void sessions::init_post_universe(void) { - for(auto &dimension : globals::dimensions) { + for(auto& dimension : globals::dimensions) { dimension_listeners.push_back(DimensionListener(dimension.second)); dimension.second->entities.on_destroy().connect<&DimensionListener::on_destroy_entity>(dimension_listeners.back()); } @@ -293,7 +296,7 @@ void sessions::deinit(void) dimension_listeners.clear(); } -Session *sessions::create(ENetPeer *peer, const char *client_username) +Session* sessions::create(ENetPeer* peer, const char* client_username) { for(unsigned int i = 0U; i < sessions::max_players.get_value(); ++i) { if(!sessions_vector[i].peer) { @@ -303,7 +306,7 @@ Session *sessions::create(ENetPeer *peer, const char *client_username) sessions_vector[i].client_identity = client_identity; sessions_vector[i].client_username = client_username; sessions_vector[i].player_entity = entt::null; - sessions_vector[i].peer = peer; + sessions_vector[i].peer = peer; username_map[client_username] = &sessions_vector[i]; identity_map[client_identity] = &sessions_vector[i]; @@ -319,48 +322,57 @@ Session *sessions::create(ENetPeer *peer, const char *client_username) return nullptr; } -Session *sessions::find(const char *client_username) +Session* sessions::find(const char* client_username) { const auto it = username_map.find(client_username); - if(it != username_map.cend()) + if(it != username_map.cend()) { return it->second; - return nullptr; + } else { + return nullptr; + } } -Session *sessions::find(std::uint16_t client_index) +Session* sessions::find(std::uint16_t client_index) { if(client_index < sessions_vector.size()) { - if(!sessions_vector[client_index].peer) + if(!sessions_vector[client_index].peer) { return nullptr; - return &sessions_vector[client_index]; + } else { + return &sessions_vector[client_index]; + } } return nullptr; } -Session *sessions::find(std::uint64_t client_identity) +Session* sessions::find(std::uint64_t client_identity) { const auto it = identity_map.find(client_identity); - if(it != identity_map.cend()) + + if(it != identity_map.cend()) { return it->second; - return nullptr; + } else { + return nullptr; + } } -Session *sessions::find(ENetPeer *peer) +Session* sessions::find(ENetPeer* peer) { - if(peer != nullptr) - return reinterpret_cast(peer->data); - return nullptr; + if(peer != nullptr) { + return reinterpret_cast(peer->data); + } else { + return nullptr; + } } -void sessions::destroy(Session *session) +void sessions::destroy(Session* session) { if(session) { if(session->peer) { // Make sure we don't leave a mark session->peer->data = nullptr; } - + if(session->dimension) { session->dimension->entities.destroy(session->player_entity); } @@ -378,18 +390,18 @@ void sessions::destroy(Session *session) } } -void sessions::broadcast(const Dimension *dimension, ENetPacket *packet) +void sessions::broadcast(const Dimension* dimension, ENetPacket* packet) { - for(const auto &session : sessions_vector) { + for(const auto& session : sessions_vector) { if(session.peer && (session.dimension == dimension)) { enet_peer_send(session.peer, protocol::CHANNEL, packet); } } } -void sessions::broadcast(const Dimension *dimension, ENetPacket *packet, ENetPeer *except) +void sessions::broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except) { - for(const auto &session : sessions_vector) { + for(const auto& session : sessions_vector) { if(session.peer && (session.peer != except)) { enet_peer_send(session.peer, protocol::CHANNEL, packet); } @@ -401,9 +413,9 @@ void sessions::refresh_scoreboard(void) protocol::ScoreboardUpdate packet; for(std::size_t i = 0; i < sessions::max_players.get_value(); ++i) { - if(!sessions_vector[i].peer) - continue; - packet.names.push_back(sessions_vector[i].client_username); + if(sessions_vector[i].peer) { + packet.names.push_back(sessions_vector[i].client_username); + } } protocol::broadcast(globals::server_host, protocol::encode(packet)); diff --git a/game/server/sessions.hh b/game/server/sessions.hh index cb31bd9..b9a6348 100644 --- a/game/server/sessions.hh +++ b/game/server/sessions.hh @@ -11,8 +11,8 @@ struct Session final { std::uint64_t client_identity; std::string client_username; entt::entity player_entity; - Dimension *dimension; - ENetPeer *peer; + Dimension* dimension; + ENetPeer* peer; }; namespace sessions @@ -31,18 +31,18 @@ void deinit(void); namespace sessions { -Session *create(ENetPeer *peer, const char *client_username); -Session *find(const char *client_username); -Session *find(std::uint16_t client_index); -Session *find(std::uint64_t client_identity); -Session *find(ENetPeer *peer); -void destroy(Session *session); +Session* create(ENetPeer* peer, const char* client_username); +Session* find(const char* client_username); +Session* find(std::uint16_t client_index); +Session* find(std::uint64_t client_identity); +Session* find(ENetPeer* peer); +void destroy(Session* session); } // namespace sessions namespace sessions { -void broadcast(const Dimension *dimension, ENetPacket *packet); -void broadcast(const Dimension *dimension, ENetPacket *packet, ENetPeer *except); +void broadcast(const Dimension* dimension, ENetPacket* packet); +void broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except); } // namespace sessions namespace sessions diff --git a/game/server/status.cc b/game/server/status.cc index e44a4f4..6b64719 100644 --- a/game/server/status.cc +++ b/game/server/status.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/status.hh" #include "core/config.hh" @@ -9,7 +10,7 @@ #include "server/globals.hh" #include "server/sessions.hh" -static void on_status_request_packet(const protocol::StatusRequest &packet) +static void on_status_request_packet(const protocol::StatusRequest& packet) { protocol::StatusResponse response; response.version = protocol::VERSION; diff --git a/game/server/universe.cc b/game/server/universe.cc index 22abaff..e7b8b0f 100644 --- a/game/server/universe.cc +++ b/game/server/universe.cc @@ -1,9 +1,10 @@ #include "server/pch.hh" + #include "server/universe.hh" +#include "core/buffer.hh" #include "core/config.hh" #include "core/epoch.hh" -#include "core/buffer.hh" #include "shared/chunk.hh" #include "shared/dimension.hh" @@ -25,9 +26,9 @@ static ConfigUnsigned64 universe_config_seed; static ConfigString universe_spawn_dimension("world"); static std::string universe_config_path; -static std::unordered_map metadata_map; +static std::unordered_map metadata_map; -static std::string make_chunk_filename(const DimensionMetadata *metadata, const chunk_pos &cpos) +static std::string make_chunk_filename(const DimensionMetadata* metadata, const chunk_pos& cpos) { const auto unsigned_x = static_cast(cpos.x); const auto unsigned_y = static_cast(cpos.y); @@ -35,7 +36,7 @@ static std::string make_chunk_filename(const DimensionMetadata *metadata, const return fmt::format("{}/{:08X}-{:08X}-{:08X}.zvox", metadata->zvox_dir, unsigned_x, unsigned_y, unsigned_z); } -static void add_new_dimension(Dimension *dimension) +static void add_new_dimension(Dimension* dimension) { if(globals::dimensions.count(dimension->get_name())) { spdlog::critical("universe: dimension named {} already exists", dimension->get_name()); @@ -57,10 +58,10 @@ static void add_new_dimension(Dimension *dimension) spdlog::critical("universe: {}: {}", metadata->zvox_dir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); std::terminate(); } - + globals::dimensions.insert_or_assign(dimension->get_name(), dimension); - - auto &mapped_metadata = metadata_map.insert_or_assign(dimension, metadata).first->second; + + auto& mapped_metadata = metadata_map.insert_or_assign(dimension, metadata).first->second; dimension->init(mapped_metadata->config); @@ -69,7 +70,7 @@ static void add_new_dimension(Dimension *dimension) dimension->init_late(universe_config_seed.get_value()); } -static void internal_save_chunk(const DimensionMetadata *metadata, const Dimension *dimension, const chunk_pos &cpos, const Chunk *chunk) +static void internal_save_chunk(const DimensionMetadata* metadata, const Dimension* dimension, const chunk_pos& cpos, const Chunk* chunk) { auto path = make_chunk_filename(metadata, cpos); @@ -140,14 +141,14 @@ void universe::deinit(void) universe::save_all_chunks(dimension.second); delete dimension.second; } - + globals::dimensions.clear(); globals::spawn_dimension = nullptr; universe_config.save_file(universe_config_path.c_str()); } -Chunk *universe::load_chunk(Dimension *dimension, const chunk_pos &cpos) +Chunk* universe::load_chunk(Dimension* dimension, const chunk_pos& cpos) { if(auto chunk = dimension->find_chunk(cpos)) { // Just return the existing chunk which is @@ -182,7 +183,7 @@ Chunk *universe::load_chunk(Dimension *dimension, const chunk_pos &cpos) return nullptr; } -void universe::save_chunk(Dimension *dimension, const chunk_pos &cpos) +void universe::save_chunk(Dimension* dimension, const chunk_pos& cpos) { auto metadata = metadata_map.find(dimension); @@ -197,7 +198,7 @@ void universe::save_chunk(Dimension *dimension, const chunk_pos &cpos) } } -void universe::save_all_chunks(Dimension *dimension) +void universe::save_all_chunks(Dimension* dimension) { auto group = dimension->chunks.group(entt::get); auto metadata = metadata_map.find(dimension); diff --git a/game/server/universe.hh b/game/server/universe.hh index 00c8b8d..2a16806 100644 --- a/game/server/universe.hh +++ b/game/server/universe.hh @@ -17,9 +17,9 @@ void deinit(void); namespace universe { -Chunk *load_chunk(Dimension *dimension, const chunk_pos &cpos); -void save_chunk(Dimension *dimension, const chunk_pos &cpos); -void save_all_chunks(Dimension *dimension); +Chunk* load_chunk(Dimension* dimension, const chunk_pos& cpos); +void save_chunk(Dimension* dimension, const chunk_pos& cpos); +void save_all_chunks(Dimension* dimension); } // namespace universe #endif /* SERVER_UNIVERSE_HH */ diff --git a/game/server/unloader.cc b/game/server/unloader.cc index fd838d0..f986a61 100644 --- a/game/server/unloader.cc +++ b/game/server/unloader.cc @@ -1,13 +1,13 @@ #include "server/pch.hh" + #include "server/unloader.hh" #include "core/config.hh" -#include "shared/chunk_aabb.hh" #include "shared/chunk.hh" +#include "shared/chunk_aabb.hh" #include "shared/dimension.hh" #include "shared/player.hh" -#include "shared/player.hh" #include "shared/transform.hh" #include "server/game.hh" @@ -15,12 +15,12 @@ #include "server/inhabited.hh" #include "server/universe.hh" -static void on_chunk_update(const ChunkUpdateEvent &event) +static void on_chunk_update(const ChunkUpdateEvent& event) { event.dimension->chunks.emplace_or_replace(event.chunk->get_entity()); } -static void on_voxel_set(const VoxelSetEvent &event) +static void on_voxel_set(const VoxelSetEvent& event) { event.dimension->chunks.emplace_or_replace(event.chunk->get_entity()); } @@ -33,10 +33,9 @@ void unloader::init(void) void unloader::init_late(void) { - } -void unloader::fixed_update_late(Dimension *dimension) +void unloader::fixed_update_late(Dimension* dimension) { auto group = dimension->entities.group(entt::get); auto boxes = std::vector(); @@ -47,14 +46,14 @@ void unloader::fixed_update_late(Dimension *dimension) aabb.max = transform.chunk + static_cast(server_game::view_distance.get_value()); boxes.push_back(aabb); } - + auto view = dimension->chunks.view(); auto chunk_in_view = false; for(const auto [entity, chunk] : view.each()) { chunk_in_view = false; - for(const auto &aabb : boxes) { + for(const auto& aabb : boxes) { if(aabb.contains(chunk.cpos)) { chunk_in_view = true; break; diff --git a/game/server/unloader.hh b/game/server/unloader.hh index d7a95da..414cdc4 100644 --- a/game/server/unloader.hh +++ b/game/server/unloader.hh @@ -8,7 +8,7 @@ namespace unloader { void init(void); void init_late(void); -void fixed_update_late(Dimension *dimension); +void fixed_update_late(Dimension* dimension); } // namespace unloader #endif /* SERVER_UNLOADER_HH */ diff --git a/game/server/whitelist.cc b/game/server/whitelist.cc index 4d9d394..6635122 100644 --- a/game/server/whitelist.cc +++ b/game/server/whitelist.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/whitelist.hh" #include "core/config.hh" @@ -8,7 +9,7 @@ #include "server/game.hh" #include "server/globals.hh" -constexpr static const char *DEFAULT_FILENAME = "whitelist.txt"; +constexpr static const char* DEFAULT_FILENAME = "whitelist.txt"; constexpr static char SEPARATOR_CHAR = ':'; ConfigBoolean whitelist::enabled(false); @@ -38,7 +39,7 @@ void whitelist::init_late(void) whitelist::filename.set(DEFAULT_FILENAME); } - PHYSFS_File *file = PHYSFS_openRead(whitelist::filename.get()); + PHYSFS_File* file = PHYSFS_openRead(whitelist::filename.get()); if(file == nullptr) { spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); @@ -61,8 +62,7 @@ void whitelist::init_late(void) // to the global server password; this allows easier adding // of guest accounts which can later be edited to use a better password whitelist_map[line] = server_game::password_hash; - } - else { + } else { const auto username = line.substr(0, location); const auto password = line.substr(location + 1); whitelist_map[username] = crc64::get(password); @@ -77,12 +77,12 @@ void whitelist::deinit(void) // UNDONE: implement saving } -bool whitelist::contains(const char *username) +bool whitelist::contains(const char* username) { return whitelist_map.contains(username); } -bool whitelist::matches(const char *username, std::uint64_t password_hash) +bool whitelist::matches(const char* username, std::uint64_t password_hash) { const auto it = whitelist_map.find(username); @@ -91,7 +91,5 @@ bool whitelist::matches(const char *username, std::uint64_t password_hash) return false; } - if(it->second == password_hash) - return true; - return false; + return it->second == password_hash; } diff --git a/game/server/whitelist.hh b/game/server/whitelist.hh index 6cbaa0b..fe7656b 100644 --- a/game/server/whitelist.hh +++ b/game/server/whitelist.hh @@ -20,8 +20,8 @@ void deinit(void); namespace whitelist { -bool contains(const char *username); -bool matches(const char *username, std::uint64_t password_hash); +bool contains(const char* username); +bool matches(const char* username, std::uint64_t password_hash); } // namespace whitelist #endif /* SERVER_WHITELIST_HH */ diff --git a/game/server/worldgen.cc b/game/server/worldgen.cc index ef3c11e..5c74d47 100644 --- a/game/server/worldgen.cc +++ b/game/server/worldgen.cc @@ -1,4 +1,5 @@ #include "server/pch.hh" + #include "server/worldgen.hh" #include "core/cmdline.hh" @@ -14,22 +15,22 @@ static bool aggressive_caching; -static emhash8::HashMap>> active_tasks; +static emhash8::HashMap>> active_tasks; class WorldgenTask final : public Task { public: - explicit WorldgenTask(Dimension *dimension, const chunk_pos &cpos); + explicit WorldgenTask(Dimension* dimension, const chunk_pos& cpos); virtual ~WorldgenTask(void) = default; virtual void process(void) override; virtual void finalize(void) override; private: - Dimension *m_dimension; + Dimension* m_dimension; VoxelStorage m_voxels; chunk_pos m_cpos; }; -WorldgenTask::WorldgenTask(Dimension *dimension, const chunk_pos &cpos) +WorldgenTask::WorldgenTask(Dimension* dimension, const chunk_pos& cpos) { m_dimension = dimension; m_voxels.fill(rand()); // trolling @@ -103,7 +104,7 @@ void worldgen::init(void) aggressive_caching = cmdline::contains("aggressive-caching"); } -bool worldgen::is_generating(Dimension *dimension, const chunk_pos &cpos) +bool worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos) { auto dim_tasks = active_tasks.find(dimension); @@ -122,19 +123,19 @@ bool worldgen::is_generating(Dimension *dimension, const chunk_pos &cpos) return true; } -void worldgen::request_chunk(Session *session, const chunk_pos &cpos) +void worldgen::request_chunk(Session* session, const chunk_pos& cpos) { if(session->dimension) { auto dim_tasks = active_tasks.find(session->dimension); if(dim_tasks == active_tasks.cend()) { - dim_tasks = active_tasks.emplace(session->dimension, emhash8::HashMap>()).first; + dim_tasks = active_tasks.emplace(session->dimension, emhash8::HashMap>()).first; } auto it = dim_tasks->second.find(cpos); if(it == dim_tasks->second.cend()) { - auto &sessions = dim_tasks->second.insert_or_assign(cpos, std::unordered_set()).first->second; + auto& sessions = dim_tasks->second.insert_or_assign(cpos, std::unordered_set()).first->second; sessions.insert(session); threading::submit(session->dimension, cpos); diff --git a/game/server/worldgen.hh b/game/server/worldgen.hh index 7fb08b9..b0127e5 100644 --- a/game/server/worldgen.hh +++ b/game/server/worldgen.hh @@ -14,8 +14,8 @@ void init(void); namespace worldgen { -bool is_generating(Dimension *dimension, const chunk_pos &cpos); -void request_chunk(Session *session, const chunk_pos &cpos); +bool is_generating(Dimension* dimension, const chunk_pos& cpos); +void request_chunk(Session* session, const chunk_pos& cpos); } // namespace worldgen #endif /* SERVER_WORLDGEN_HH */ diff --git a/game/shared/chunk.cc b/game/shared/chunk.cc index 17fdcc1..da798fa 100644 --- a/game/shared/chunk.cc +++ b/game/shared/chunk.cc @@ -1,9 +1,10 @@ #include "shared/pch.hh" + #include "shared/chunk.hh" #include "shared/coord.hh" -Chunk::Chunk(entt::entity entity, Dimension *dimension) +Chunk::Chunk(entt::entity entity, Dimension* dimension) { m_entity = entity; m_dimension = dimension; @@ -11,36 +12,38 @@ Chunk::Chunk(entt::entity entity, Dimension *dimension) m_biome = BIOME_VOID; } -voxel_id Chunk::get_voxel(const local_pos &lpos) const +voxel_id Chunk::get_voxel(const local_pos& lpos) const { return get_voxel(coord::to_index(lpos)); } voxel_id Chunk::get_voxel(const std::size_t index) const { - if(index >= CHUNK_VOLUME) + if(index >= CHUNK_VOLUME) { return NULL_VOXEL_ID; - return m_voxels[index]; + } else { + return m_voxels[index]; + } } -void Chunk::set_voxel(voxel_id voxel, const local_pos &lpos) +void Chunk::set_voxel(voxel_id voxel, const local_pos& lpos) { set_voxel(voxel, coord::to_index(lpos)); } void Chunk::set_voxel(voxel_id voxel, const std::size_t index) { - if(index >= CHUNK_VOLUME) - return; - m_voxels[index] = voxel; + if(index < CHUNK_VOLUME) { + m_voxels[index] = voxel; + } } -const VoxelStorage &Chunk::get_voxels(void) const +const VoxelStorage& Chunk::get_voxels(void) const { return m_voxels; } -void Chunk::set_voxels(const VoxelStorage &voxels) +void Chunk::set_voxels(const VoxelStorage& voxels) { m_voxels = voxels; } @@ -60,7 +63,7 @@ entt::entity Chunk::get_entity(void) const return m_entity; } -Dimension *Chunk::get_dimension(void) const +Dimension* Chunk::get_dimension(void) const { return m_dimension; } diff --git a/game/shared/chunk.hh b/game/shared/chunk.hh index 560d3a7..67bedae 100644 --- a/game/shared/chunk.hh +++ b/game/shared/chunk.hh @@ -11,27 +11,27 @@ class Dimension; class Chunk final { public: - explicit Chunk(entt::entity entity, Dimension *dimension); + explicit Chunk(entt::entity entity, Dimension* dimension); virtual ~Chunk(void) = default; - voxel_id get_voxel(const local_pos &lpos) const; + voxel_id get_voxel(const local_pos& lpos) const; voxel_id get_voxel(const std::size_t index) const; - void set_voxel(voxel_id voxel, const local_pos &lpos); + void set_voxel(voxel_id voxel, const local_pos& lpos); void set_voxel(voxel_id voxel, const std::size_t index); - const VoxelStorage &get_voxels(void) const; - void set_voxels(const VoxelStorage &voxels); + const VoxelStorage& get_voxels(void) const; + void set_voxels(const VoxelStorage& voxels); unsigned int get_biome(void) const; void set_biome(unsigned int biome); entt::entity get_entity(void) const; - Dimension *get_dimension(void) const; + Dimension* get_dimension(void) const; private: entt::entity m_entity; - Dimension *m_dimension; + Dimension* m_dimension; VoxelStorage m_voxels; unsigned int m_biome; }; diff --git a/game/shared/chunk_aabb.cc b/game/shared/chunk_aabb.cc index b4e5b82..5f23ea9 100644 --- a/game/shared/chunk_aabb.cc +++ b/game/shared/chunk_aabb.cc @@ -1,55 +1,52 @@ #include "shared/pch.hh" + #include "shared/chunk_aabb.hh" -void ChunkAABB::set_bounds(const chunk_pos &min, const chunk_pos &max) +void ChunkAABB::set_bounds(const chunk_pos& min, const chunk_pos& max) { this->min = min; this->max = max; } -void ChunkAABB::set_offset(const chunk_pos &base, const chunk_pos &size) +void ChunkAABB::set_offset(const chunk_pos& base, const chunk_pos& size) { this->min = base; this->max = base + size; } -bool ChunkAABB::contains(const chunk_pos &point) const +bool ChunkAABB::contains(const chunk_pos& point) const { - if((point.x < min.x) || (point.x > max.x)) - return false; - if((point.y < min.y) || (point.y > max.y)) - return false; - if((point.z < min.z) || (point.z > max.z)) - return false; - return true; + auto result = true; + result = result && (point.x >= min.x) && (point.x <= max.x); + result = result && (point.y >= min.y) && (point.y <= max.y); + result = result && (point.z >= min.z) && (point.z <= max.z); + return result; } -bool ChunkAABB::intersect(const ChunkAABB &other_box) const +bool ChunkAABB::intersect(const ChunkAABB& other_box) const { - if((min.x >= other_box.max.x) || (max.x <= other_box.min.x)) - return false; - if((min.y >= other_box.max.y) || (max.y <= other_box.min.y)) - return false; - if((min.z >= other_box.max.z) || (max.z <= other_box.min.z)) - return false; - return true; + auto result = true; + result = result && (min.x < other_box.max.x) && (max.x > other_box.min.x); + result = result && (min.y < other_box.max.y) && (max.y > other_box.min.y); + result = result && (min.z < other_box.max.z) && (max.z > other_box.min.z); + return result; } -ChunkAABB ChunkAABB::combine_with(const ChunkAABB &other_box) const +ChunkAABB ChunkAABB::combine_with(const ChunkAABB& other_box) const { ChunkAABB result; result.set_bounds(min, other_box.max); return result; } -ChunkAABB ChunkAABB::multiply_with(const ChunkAABB &other_box) const +ChunkAABB ChunkAABB::multiply_with(const ChunkAABB& other_box) const { ChunkAABB result; result.set_bounds(other_box.min, max); return result; } -ChunkAABB ChunkAABB::push(const chunk_pos &vector) const +ChunkAABB ChunkAABB::push(const chunk_pos& vector) const { ChunkAABB result; result.set_bounds(min + vector, max + vector); diff --git a/game/shared/chunk_aabb.hh b/game/shared/chunk_aabb.hh index 68b8701..e215f9a 100644 --- a/game/shared/chunk_aabb.hh +++ b/game/shared/chunk_aabb.hh @@ -9,18 +9,18 @@ public: explicit ChunkAABB(void) = default; virtual ~ChunkAABB(void) = default; - void set_bounds(const chunk_pos &min, const chunk_pos &max); - void set_offset(const chunk_pos &base, const chunk_pos &size); + void set_bounds(const chunk_pos& min, const chunk_pos& max); + void set_offset(const chunk_pos& base, const chunk_pos& size); - const chunk_pos &get_min(void) const; - const chunk_pos &get_max(void) const; + const chunk_pos& get_min(void) const; + const chunk_pos& get_max(void) const; - bool contains(const chunk_pos &point) const; - bool intersect(const ChunkAABB &other_box) const; + bool contains(const chunk_pos& point) const; + bool intersect(const ChunkAABB& other_box) const; - ChunkAABB combine_with(const ChunkAABB &other_box) const; - ChunkAABB multiply_with(const ChunkAABB &other_box) const; - ChunkAABB push(const chunk_pos &vector) const; + ChunkAABB combine_with(const ChunkAABB& other_box) const; + ChunkAABB multiply_with(const ChunkAABB& other_box) const; + ChunkAABB push(const chunk_pos& vector) const; public: chunk_pos min; diff --git a/game/shared/collision.cc b/game/shared/collision.cc index 0593fbb..af880ab 100644 --- a/game/shared/collision.cc +++ b/game/shared/collision.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/collision.hh" #include "core/constexpr.hh" @@ -12,12 +13,12 @@ #include "shared/velocity.hh" #include "shared/voxel_registry.hh" -static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &collision, TransformComponent &transform, VelocityComponent &velocity, voxel_surface &touch_surface) +static int vgrid_collide(const Dimension* dimension, int d, CollisionComponent& collision, TransformComponent& transform, VelocityComponent& velocity, voxel_surface& touch_surface) { const auto move = globals::fixed_frametime * velocity.value[d]; const auto move_sign = cxpr::sign(move); - const auto &ref_aabb = collision.aabb; + const auto& ref_aabb = collision.aabb; const auto current_aabb = ref_aabb.push(transform.local); auto next_aabb = AABB(current_aabb); @@ -46,8 +47,7 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent & ddir = local_pos::value_type(+1); dmin = lpos_min[d]; dmax = lpos_max[d]; - } - else { + } else { ddir = local_pos::value_type(-1); dmin = lpos_max[d]; dmax = lpos_min[d]; @@ -60,50 +60,50 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent & for(auto i = dmin; i != dmax; i += ddir) { for(auto j = lpos_min[u]; j < lpos_max[u]; ++j) - for(auto k = lpos_min[v]; k < lpos_max[v]; ++k) { - local_pos lpos; - lpos[d] = i; - lpos[u] = j; - lpos[v] = k; - - const auto vpos = coord::to_voxel(transform.chunk, lpos); - const auto info = voxel_registry::find(dimension->get_voxel(vpos)); - - if(info == nullptr) { - // Don't collide with something - // that we assume to be nothing - continue; - } - - AABB vbox; - vbox.min = glm::fvec3(lpos); - vbox.max = glm::fvec3(lpos) + 1.0f; - - if(!next_aabb.intersect(vbox)) { - // No intersection between the voxel - // and the entity's collision hull - continue; - } - - if(info->touch_type == voxel_touch::SOLID) { - // Solid touch type makes a collision - // response whenever it is encountered - velocity.value[d] = 0.0f; - touch_surface = info->surface; - return move_sign; + for(auto k = lpos_min[v]; k < lpos_max[v]; ++k) { + local_pos lpos; + lpos[d] = i; + lpos[u] = j; + lpos[v] = k; + + const auto vpos = coord::to_voxel(transform.chunk, lpos); + const auto info = voxel_registry::find(dimension->get_voxel(vpos)); + + if(info == nullptr) { + // Don't collide with something + // that we assume to be nothing + continue; + } + + AABB vbox; + vbox.min = glm::fvec3(lpos); + vbox.max = glm::fvec3(lpos) + 1.0f; + + if(!next_aabb.intersect(vbox)) { + // No intersection between the voxel + // and the entity's collision hull + continue; + } + + if(info->touch_type == voxel_touch::SOLID) { + // Solid touch type makes a collision + // response whenever it is encountered + velocity.value[d] = 0.0f; + touch_surface = info->surface; + return move_sign; + } + + // In case of other touch types, they + // are latched and the last ever touch + // type is then responded to + if(info->touch_type != voxel_touch::NOTHING) { + latch_touch = info->touch_type; + latch_values = info->touch_values; + latch_surface = info->surface; + latch_vbox = vbox; + continue; + } } - - // In case of other touch types, they - // are latched and the last ever touch - // type is then responded to - if(info->touch_type != voxel_touch::NOTHING) { - latch_touch = info->touch_type; - latch_values = info->touch_values; - latch_surface = info->surface; - latch_vbox = vbox; - continue; - } - } } if(latch_touch != voxel_touch::NOTHING) { @@ -111,10 +111,12 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent & const auto move_distance = cxpr::abs(current_aabb.min[d] - next_aabb.min[d]); const auto threshold = 2.0f * globals::fixed_frametime; - if(move_distance > threshold) + if(move_distance > threshold) { velocity.value[d] *= -latch_values[d]; - else velocity.value[d] = 0.0f; - + } else { + velocity.value[d] = 0.0f; + } + touch_surface = latch_surface; return move_sign; @@ -130,7 +132,7 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent & return 0; } -void CollisionComponent::fixed_update(Dimension *dimension) +void CollisionComponent::fixed_update(Dimension* dimension) { // FIXME: this isn't particularly accurate considering // some voxels might be passable and some other voxels @@ -148,11 +150,12 @@ void CollisionComponent::fixed_update(Dimension *dimension) auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface); if(dimension->entities.any_of(entity)) { - if(vertical_move == cxpr::sign(dimension->get_gravity())) - dimension->entities.emplace_or_replace(entity, GroundedComponent{surface}); - else dimension->entities.remove(entity); - } - else { + if(vertical_move == cxpr::sign(dimension->get_gravity())) { + dimension->entities.emplace_or_replace(entity, GroundedComponent { surface }); + } else { + dimension->entities.remove(entity); + } + } else { // The entity cannot be grounded because the component // setup of said entity should not let it comprehend the // concept of resting on the ground (it flies around) diff --git a/game/shared/collision.hh b/game/shared/collision.hh index 3e3643f..641a803 100644 --- a/game/shared/collision.hh +++ b/game/shared/collision.hh @@ -13,7 +13,7 @@ public: // NOTE: CollisionComponent::fixed_update must be called // before TransformComponent::fixed_update and VelocityComponent::fixed_update // because both transform and velocity may be updated internally - static void fixed_update(Dimension *dimension); + static void fixed_update(Dimension* dimension); }; #endif /* SHARED_COLLISION_HH */ diff --git a/game/shared/coord.hh b/game/shared/coord.hh index e51624f..4a11e60 100644 --- a/game/shared/coord.hh +++ b/game/shared/coord.hh @@ -7,41 +7,41 @@ namespace coord { -constexpr chunk_pos to_chunk(const voxel_pos &vpos); +constexpr chunk_pos to_chunk(const voxel_pos& vpos); } // namespace coord namespace coord { -constexpr local_pos to_local(const voxel_pos &vpos); -constexpr local_pos to_local(const glm::fvec3 &fvec); +constexpr local_pos to_local(const voxel_pos& vpos); +constexpr local_pos to_local(const glm::fvec3& fvec); constexpr local_pos to_local(std::size_t index); } // namespace coord namespace coord { -constexpr voxel_pos to_voxel(const chunk_pos &cpos, const local_pos &lpos); -constexpr voxel_pos to_voxel(const chunk_pos &cpos, const glm::fvec3 &fvec); +constexpr voxel_pos to_voxel(const chunk_pos& cpos, const local_pos& lpos); +constexpr voxel_pos to_voxel(const chunk_pos& cpos, const glm::fvec3& fvec); } // namespace coord namespace coord { -constexpr std::size_t to_index(const local_pos &lpos); +constexpr std::size_t to_index(const local_pos& lpos); } // namespace coord namespace coord { -constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const chunk_pos &cpos, const glm::fvec3 &fvec); -constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos); -constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos, const glm::fvec3 &fvec); +constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const chunk_pos& cpos, const glm::fvec3& fvec); +constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos); +constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos, const glm::fvec3& fvec); } // namespace coord namespace coord { -constexpr glm::fvec3 to_fvec3(const chunk_pos &cpos); -constexpr glm::fvec3 to_fvec3(const chunk_pos &cpos, const glm::fvec3 &fpos); +constexpr glm::fvec3 to_fvec3(const chunk_pos& cpos); +constexpr glm::fvec3 to_fvec3(const chunk_pos& cpos, const glm::fvec3& fpos); } // namespace coord -inline constexpr chunk_pos coord::to_chunk(const voxel_pos &vpos) +inline constexpr chunk_pos coord::to_chunk(const voxel_pos& vpos) { return chunk_pos { static_cast(vpos.x >> CHUNK_BITSHIFT), @@ -50,7 +50,7 @@ inline constexpr chunk_pos coord::to_chunk(const voxel_pos &vpos) }; } -inline constexpr local_pos coord::to_local(const voxel_pos &vpos) +inline constexpr local_pos coord::to_local(const voxel_pos& vpos) { return local_pos { static_cast(cxpr::mod_signed(vpos.x, CHUNK_SIZE)), @@ -59,7 +59,7 @@ inline constexpr local_pos coord::to_local(const voxel_pos &vpos) }; } -inline constexpr local_pos coord::to_local(const glm::fvec3 &fvec) +inline constexpr local_pos coord::to_local(const glm::fvec3& fvec) { return local_pos { static_cast(fvec.x), @@ -77,7 +77,7 @@ inline constexpr local_pos coord::to_local(std::size_t index) }; } -inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const local_pos &lpos) +inline constexpr voxel_pos coord::to_voxel(const chunk_pos& cpos, const local_pos& lpos) { return voxel_pos { lpos.x + (static_cast(cpos.x) << CHUNK_BITSHIFT), @@ -86,7 +86,7 @@ inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const local_po }; } -inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const glm::fvec3 &fvec) +inline constexpr voxel_pos coord::to_voxel(const chunk_pos& cpos, const glm::fvec3& fvec) { return voxel_pos { static_cast(fvec.x) + (static_cast(cpos.x) << CHUNK_BITSHIFT), @@ -95,12 +95,12 @@ inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const glm::fve }; } -inline constexpr std::size_t coord::to_index(const local_pos &lpos) +inline constexpr std::size_t coord::to_index(const local_pos& lpos) { return static_cast((lpos.y * CHUNK_SIZE + lpos.z) * CHUNK_SIZE + lpos.x); } -inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const chunk_pos &cpos, const glm::fvec3 &fvec) +inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const chunk_pos& cpos, const glm::fvec3& fvec) { return glm::fvec3 { static_cast((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) + fvec.x, @@ -109,7 +109,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons }; } -inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos) +inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos) { return glm::fvec3 { static_cast((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) - pivot_fvec.x, @@ -118,7 +118,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons }; } -inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos, const glm::fvec3 &fvec) +inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos, const glm::fvec3& fvec) { return glm::fvec3 { static_cast((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) + (fvec.x - pivot_fvec.x), @@ -127,7 +127,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons }; } -inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos) +inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos& cpos) { return glm::fvec3 { static_cast(cpos.x << CHUNK_BITSHIFT), @@ -136,7 +136,7 @@ inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos) }; } -inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos, const glm::fvec3 &fpos) +inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos& cpos, const glm::fvec3& fpos) { return glm::fvec3 { fpos.x + static_cast(cpos.x << CHUNK_BITSHIFT), diff --git a/game/shared/dimension.cc b/game/shared/dimension.cc index 2377214..a919dc4 100644 --- a/game/shared/dimension.cc +++ b/game/shared/dimension.cc @@ -1,11 +1,12 @@ #include "shared/pch.hh" + #include "shared/dimension.hh" +#include "shared/chunk.hh" #include "shared/coord.hh" #include "shared/globals.hh" -#include "shared/chunk.hh" -Dimension::Dimension(const char *name, float gravity) +Dimension::Dimension(const char* name, float gravity) { m_name = name; m_gravity = gravity; @@ -19,7 +20,7 @@ Dimension::~Dimension(void) chunks.clear(); } -const char *Dimension::get_name(void) const +const char* Dimension::get_name(void) const { return m_name.c_str(); } @@ -29,7 +30,7 @@ float Dimension::get_gravity(void) const return m_gravity; } -Chunk *Dimension::create_chunk(const chunk_pos &cpos) +Chunk* Dimension::create_chunk(const chunk_pos& cpos) { auto it = m_chunkmap.find(cpos); @@ -41,7 +42,7 @@ Chunk *Dimension::create_chunk(const chunk_pos &cpos) auto entity = chunks.create(); auto chunk = new Chunk(entity, this); - auto &component = chunks.emplace(entity); + auto& component = chunks.emplace(entity); component.chunk = chunk; component.cpos = cpos; @@ -55,31 +56,36 @@ Chunk *Dimension::create_chunk(const chunk_pos &cpos) return m_chunkmap.insert_or_assign(cpos, std::move(chunk)).first->second; } -Chunk *Dimension::find_chunk(entt::entity entity) const +Chunk* Dimension::find_chunk(entt::entity entity) const { - if(chunks.valid(entity)) + if(chunks.valid(entity)) { return chunks.get(entity).chunk; - return nullptr; + } else { + return nullptr; + } } -Chunk *Dimension::find_chunk(const chunk_pos &cpos) const +Chunk* Dimension::find_chunk(const chunk_pos& cpos) const { auto it = m_chunkmap.find(cpos); - if(it != m_chunkmap.cend()) + + if(it != m_chunkmap.cend()) { return it->second; - return nullptr; + } else { + return nullptr; + } } void Dimension::remove_chunk(entt::entity entity) { if(chunks.valid(entity)) { - auto &component = chunks.get(entity); + auto& component = chunks.get(entity); m_chunkmap.erase(component.cpos); chunks.destroy(entity); } } -void Dimension::remove_chunk(const chunk_pos &cpos) +void Dimension::remove_chunk(const chunk_pos& cpos) { auto it = m_chunkmap.find(cpos); @@ -89,26 +95,28 @@ void Dimension::remove_chunk(const chunk_pos &cpos) } } -void Dimension::remove_chunk(Chunk *chunk) +void Dimension::remove_chunk(Chunk* chunk) { if(chunk) { - const auto &component = chunks.get(chunk->get_entity()); + const auto& component = chunks.get(chunk->get_entity()); m_chunkmap.erase(component.cpos); chunks.destroy(chunk->get_entity()); } } -voxel_id Dimension::get_voxel(const voxel_pos &vpos) const +voxel_id Dimension::get_voxel(const voxel_pos& vpos) const { auto cpos = coord::to_chunk(vpos); auto lpos = coord::to_local(vpos); - - if(auto chunk = find_chunk(cpos)) + + if(auto chunk = find_chunk(cpos)) { return chunk->get_voxel(lpos); - return NULL_VOXEL_ID; + } else { + return NULL_VOXEL_ID; + } } -voxel_id Dimension::get_voxel(const chunk_pos &cpos, const local_pos &lpos) const +voxel_id Dimension::get_voxel(const chunk_pos& cpos, const local_pos& lpos) const { // This allows accessing get_voxel with negative // local coordinates that usually would result in an @@ -116,7 +124,7 @@ voxel_id Dimension::get_voxel(const chunk_pos &cpos, const local_pos &lpos) cons return get_voxel(coord::to_voxel(cpos, lpos)); } -bool Dimension::set_voxel(voxel_id voxel, const voxel_pos &vpos) +bool Dimension::set_voxel(voxel_id voxel, const voxel_pos& vpos) { auto cpos = coord::to_chunk(vpos); auto lpos = coord::to_local(vpos); @@ -139,7 +147,7 @@ bool Dimension::set_voxel(voxel_id voxel, const voxel_pos &vpos) return false; } -bool Dimension::set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos &lpos) +bool Dimension::set_voxel(voxel_id voxel, const chunk_pos& cpos, const local_pos& lpos) { // This allows accessing set_voxel with negative // local coordinates that usually would result in an @@ -147,17 +155,15 @@ bool Dimension::set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos return set_voxel(voxel, coord::to_voxel(cpos, lpos)); } -void Dimension::init(Config &config) +void Dimension::init(Config& config) { - } void Dimension::init_late(std::uint64_t global_seed) { - } -bool Dimension::generate(const chunk_pos &cpos, VoxelStorage &voxels) +bool Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels) { return false; } diff --git a/game/shared/dimension.hh b/game/shared/dimension.hh index 8806115..c609a14 100644 --- a/game/shared/dimension.hh +++ b/game/shared/dimension.hh @@ -14,32 +14,32 @@ using dimension_height_map = std::array; class Dimension { public: - explicit Dimension(const char *name, float gravity); + explicit Dimension(const char* name, float gravity); virtual ~Dimension(void); - const char *get_name(void) const; + const char* get_name(void) const; float get_gravity(void) const; public: - Chunk *create_chunk(const chunk_pos &cpos); - Chunk *find_chunk(entt::entity entity) const; - Chunk *find_chunk(const chunk_pos &cpos) const; + Chunk* create_chunk(const chunk_pos& cpos); + Chunk* find_chunk(entt::entity entity) const; + Chunk* find_chunk(const chunk_pos& cpos) const; void remove_chunk(entt::entity entity); - void remove_chunk(const chunk_pos &cpos); - void remove_chunk(Chunk *chunk); + void remove_chunk(const chunk_pos& cpos); + void remove_chunk(Chunk* chunk); public: - voxel_id get_voxel(const voxel_pos &vpos) const; - voxel_id get_voxel(const chunk_pos &cpos, const local_pos &lpos) const; + voxel_id get_voxel(const voxel_pos& vpos) const; + voxel_id get_voxel(const chunk_pos& cpos, const local_pos& lpos) const; - bool set_voxel(voxel_id voxel, const voxel_pos &vpos); - bool set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos &lpos); + bool set_voxel(voxel_id voxel, const voxel_pos& vpos); + bool set_voxel(voxel_id voxel, const chunk_pos& cpos, const local_pos& lpos); public: - virtual void init(Config &config); + virtual void init(Config& config); virtual void init_late(std::uint64_t global_seed); - virtual bool generate(const chunk_pos &cpos, VoxelStorage &voxels); + virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels); public: entt::registry chunks; @@ -47,39 +47,39 @@ public: private: std::string m_name; - emhash8::HashMap m_chunkmap; + emhash8::HashMap m_chunkmap; float m_gravity; }; struct ChunkComponent final { chunk_pos cpos; - Chunk *chunk; + Chunk* chunk; }; struct ChunkCreateEvent final { - Dimension *dimension; + Dimension* dimension; chunk_pos cpos; - Chunk *chunk; + Chunk* chunk; }; struct ChunkDestroyEvent final { - Dimension *dimension; + Dimension* dimension; chunk_pos cpos; - Chunk *chunk; + Chunk* chunk; }; struct ChunkUpdateEvent final { - Dimension *dimension; + Dimension* dimension; chunk_pos cpos; - Chunk *chunk; + Chunk* chunk; }; struct VoxelSetEvent final { - Dimension *dimension; + Dimension* dimension; chunk_pos cpos; local_pos lpos; voxel_id voxel; - Chunk *chunk; + Chunk* chunk; }; #endif /* SHARED_DIMENSION_HH */ diff --git a/game/shared/factory.cc b/game/shared/factory.cc index 34cc55c..ad65928 100644 --- a/game/shared/factory.cc +++ b/game/shared/factory.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/factory.hh" #include "shared/collision.hh" @@ -10,25 +11,25 @@ #include "shared/transform.hh" #include "shared/velocity.hh" -void shared_factory::create_player(Dimension *dimension, entt::entity entity) +void shared_factory::create_player(Dimension* dimension, entt::entity entity) { spdlog::debug("factory[{}]: assigning player components to {}", dimension->get_name(), static_cast(entity)); - auto &collision = dimension->entities.emplace_or_replace(entity); + auto& collision = dimension->entities.emplace_or_replace(entity); collision.aabb.min = glm::fvec3(-0.4f, -1.6f, -0.4f); collision.aabb.max = glm::fvec3(+0.4f, +0.2f, +0.4f); - auto &head = dimension->entities.emplace_or_replace(entity); + auto& head = dimension->entities.emplace_or_replace(entity); head.angles = glm::fvec3(0.0f, 0.0f, 0.0f); head.offset = glm::fvec3(0.0f, 0.0f, 0.0f); dimension->entities.emplace_or_replace(entity); - auto &transform = dimension->entities.emplace_or_replace(entity); + auto& transform = dimension->entities.emplace_or_replace(entity); transform.chunk = chunk_pos(0, 2, 0); transform.local = glm::fvec3(0.0f, 0.0f, 0.0f); transform.angles = glm::fvec3(0.0f, 0.0f, 0.0f); - auto &velocity = dimension->entities.emplace_or_replace(entity); + auto& velocity = dimension->entities.emplace_or_replace(entity); velocity.value = glm::fvec3(0.0f, 0.0f, 0.0f); } diff --git a/game/shared/factory.hh b/game/shared/factory.hh index 79df276..c3449dd 100644 --- a/game/shared/factory.hh +++ b/game/shared/factory.hh @@ -6,7 +6,7 @@ class Dimension; namespace shared_factory { -void create_player(Dimension *dimension, entt::entity entity); +void create_player(Dimension* dimension, entt::entity entity); } // namespace shared_factory #endif /* SHARED_FACTORY */ diff --git a/game/shared/feature.cc b/game/shared/feature.cc index 845bb40..eb6cceb 100644 --- a/game/shared/feature.cc +++ b/game/shared/feature.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/feature.hh" #include "shared/chunk.hh" @@ -6,7 +7,7 @@ #include "shared/dimension.hh" #include "shared/voxel_storage.hh" -void Feature::place(const voxel_pos &vpos, Dimension *dimension) const +void Feature::place(const voxel_pos& vpos, Dimension* dimension) const { for(const auto [rpos, voxel, overwrite] : (*this)) { auto it_vpos = vpos + rpos; @@ -28,7 +29,7 @@ void Feature::place(const voxel_pos &vpos, Dimension *dimension) const } } -void Feature::place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels) const +void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const { for(const auto [rpos, voxel, overwrite] : (*this)) { auto it_vpos = vpos + rpos; diff --git a/game/shared/feature.hh b/game/shared/feature.hh index b5cb262..306841e 100644 --- a/game/shared/feature.hh +++ b/game/shared/feature.hh @@ -13,8 +13,8 @@ public: virtual ~Feature(void) = default; public: - void place(const voxel_pos &vpos, Dimension *dimension) const; - void place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels) const; + void place(const voxel_pos& vpos, Dimension* dimension) const; + void place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const; }; #endif /* SHARED_FEATURE_HH */ diff --git a/game/shared/game.cc b/game/shared/game.cc index 22693eb..73de8b5 100644 --- a/game/shared/game.cc +++ b/game/shared/game.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/game.hh" #include "core/cmdline.hh" @@ -47,10 +48,10 @@ static std::filesystem::path get_userpath(void) return std::filesystem::current_path(); } -void shared_game::init(int argc, char **argv) +void shared_game::init(int argc, char** argv) { auto logger = spdlog::default_logger(); - auto &logger_sinks = logger->sinks(); + auto& logger_sinks = logger->sinks(); logger_sinks.clear(); logger_sinks.push_back(std::make_shared()); @@ -62,11 +63,13 @@ void shared_game::init(int argc, char **argv) constexpr auto default_loglevel = spdlog::level::trace; #endif - if(cmdline::contains("quiet")) + if(cmdline::contains("quiet")) { logger->set_level(spdlog::level::warn); - else if(cmdline::contains("verbose")) + } else if(cmdline::contains("verbose")) { logger->set_level(spdlog::level::trace); - else logger->set_level(default_loglevel); + } else { + logger->set_level(default_loglevel); + } logger->set_pattern("%H:%M:%S.%e %^[%L]%$ %v"); logger->flush(); diff --git a/game/shared/game.hh b/game/shared/game.hh index f274d25..59c5327 100644 --- a/game/shared/game.hh +++ b/game/shared/game.hh @@ -4,7 +4,7 @@ namespace shared_game { -void init(int argc, char **argv); +void init(int argc, char** argv); void deinit(void); } // namespace shared_game diff --git a/game/shared/game_items.cc b/game/shared/game_items.cc index dae286f..f2f1c0c 100644 --- a/game/shared/game_items.cc +++ b/game/shared/game_items.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/game_items.hh" #include "shared/game_voxels.hh" @@ -18,61 +19,32 @@ item_id game_items::mud = NULL_ITEM_ID; void game_items::populate(void) { // Stone; a hardened slate rock - game_items::stone = item_registry::construct("stone") - .set_texture("textures/item/stone.png") - .set_place_voxel(game_voxels::stone) - .build(); + game_items::stone = item_registry::construct("stone").set_texture("textures/item/stone.png").set_place_voxel(game_voxels::stone).build(); // Cobblestone; a bunch of small stones - game_items::cobblestone = item_registry::construct("cobblestone") - .set_texture("textures/item/cobblestone.png") - .set_place_voxel(game_voxels::cobblestone) - .build(); + game_items::cobblestone = item_registry::construct("cobblestone").set_texture("textures/item/cobblestone.png").set_place_voxel(game_voxels::cobblestone).build(); // Dirt; it's very dirty - game_items::dirt = item_registry::construct("dirt") - .set_texture("textures/item/dirt.png") - .set_place_voxel(game_voxels::dirt) - .build(); - + game_items::dirt = item_registry::construct("dirt").set_texture("textures/item/dirt.png").set_place_voxel(game_voxels::dirt).build(); + // Grass; literally just grassy dirt - game_items::grass = item_registry::construct("grass") - .set_texture("textures/item/grass.png") - .set_place_voxel(game_voxels::grass) - .build(); + game_items::grass = item_registry::construct("grass").set_texture("textures/item/grass.png").set_place_voxel(game_voxels::grass).build(); // Oak leaves; they're bushy! - game_items::oak_leaves = item_registry::construct("oak_leaves") - .set_texture("textures/item/oak_leaves.png") - .set_place_voxel(game_voxels::oak_leaves) - .build(); + game_items::oak_leaves = item_registry::construct("oak_leaves").set_texture("textures/item/oak_leaves.png").set_place_voxel(game_voxels::oak_leaves).build(); // Oak planks; watch for splinters! - game_items::oak_planks = item_registry::construct("oak_planks") - .set_texture("textures/item/oak_planks.png") - .set_place_voxel(game_voxels::oak_planks) - .build(); + game_items::oak_planks = item_registry::construct("oak_planks").set_texture("textures/item/oak_planks.png").set_place_voxel(game_voxels::oak_planks).build(); // Oak log; a big wad of wood - game_items::oak_log = item_registry::construct("oak_log") - .set_texture("textures/item/oak_log.png") - .set_place_voxel(game_voxels::oak_log) - .build(); + game_items::oak_log = item_registry::construct("oak_log").set_texture("textures/item/oak_log.png").set_place_voxel(game_voxels::oak_log).build(); // Glass; used for windowing - game_items::glass = item_registry::construct("glass") - .set_texture("textures/item/glass.png") - .set_place_voxel(game_voxels::glass) - .build(); + game_items::glass = item_registry::construct("glass").set_texture("textures/item/glass.png").set_place_voxel(game_voxels::glass).build(); // Slime; it's bouncy! - game_items::slime = item_registry::construct("slime") - .set_texture("textures/item/slime.png") - .set_place_voxel(game_voxels::slime) - .build(); + game_items::slime = item_registry::construct("slime").set_texture("textures/item/slime.png").set_place_voxel(game_voxels::slime).build(); // Mud; you sink in it! - game_items::mud = item_registry::construct("mud") - .set_texture("textures/item/mud.png") - .build(); + game_items::mud = item_registry::construct("mud").set_texture("textures/item/mud.png").build(); } diff --git a/game/shared/game_voxels.cc b/game/shared/game_voxels.cc index b72ded4..23c953b 100644 --- a/game/shared/game_voxels.cc +++ b/game/shared/game_voxels.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/game_voxels.hh" #include "shared/voxel_registry.hh" @@ -20,94 +21,88 @@ void game_voxels::populate(void) { // Stone; the backbone of the generated world game_voxels::stone = voxel_registry::construct("stone", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/stone_01.png") - .add_texture_default("textures/voxel/stone_02.png") - .add_texture_default("textures/voxel/stone_03.png") - .add_texture_default("textures/voxel/stone_04.png") - .set_surface(voxel_surface::STONE) - .build(); + .add_texture_default("textures/voxel/stone_01.png") + .add_texture_default("textures/voxel/stone_02.png") + .add_texture_default("textures/voxel/stone_03.png") + .add_texture_default("textures/voxel/stone_04.png") + .set_surface(voxel_surface::STONE) + .build(); // Cobblestone; should drop when a stone is broken, might also be present in surface features game_voxels::cobblestone = voxel_registry::construct("cobblestone", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/cobblestone_01.png") - .add_texture_default("textures/voxel/cobblestone_02.png") - .set_surface(voxel_surface::STONE) - .build(); + .add_texture_default("textures/voxel/cobblestone_01.png") + .add_texture_default("textures/voxel/cobblestone_02.png") + .set_surface(voxel_surface::STONE) + .build(); // Dirt with a grass layer on top; the top layer of plains biome game_voxels::grass = voxel_registry::construct("grass", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/grass_side_01.png") - .add_texture_default("textures/voxel/grass_side_02.png") - .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_01.png") - .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_02.png") - .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_03.png") - .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_04.png") - .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_01.png") - .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_02.png") - .set_surface(voxel_surface::GRASS) - .build(); + .add_texture_default("textures/voxel/grass_side_01.png") + .add_texture_default("textures/voxel/grass_side_02.png") + .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_01.png") + .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_02.png") + .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_03.png") + .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_04.png") + .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_01.png") + .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_02.png") + .set_surface(voxel_surface::GRASS) + .build(); // Dirt; the under-surface layer of some biomes game_voxels::dirt = voxel_registry::construct("dirt", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/dirt_01.png") - .add_texture_default("textures/voxel/dirt_02.png") - .add_texture_default("textures/voxel/dirt_03.png") - .add_texture_default("textures/voxel/dirt_04.png") - .set_surface(voxel_surface::DIRT) - .build(); + .add_texture_default("textures/voxel/dirt_01.png") + .add_texture_default("textures/voxel/dirt_02.png") + .add_texture_default("textures/voxel/dirt_03.png") + .add_texture_default("textures/voxel/dirt_04.png") + .set_surface(voxel_surface::DIRT) + .build(); // VTest; a test voxel to ensure animations work game_voxels::vtest = voxel_registry::construct("vtest", voxel_type::CUBE, true, false) - .add_texture_default("textures/voxel/vtest_F1.png") - .add_texture_default("textures/voxel/vtest_F2.png") - .add_texture_default("textures/voxel/vtest_F3.png") - .add_texture_default("textures/voxel/vtest_F4.png") - .build(); + .add_texture_default("textures/voxel/vtest_F1.png") + .add_texture_default("textures/voxel/vtest_F2.png") + .add_texture_default("textures/voxel/vtest_F3.png") + .add_texture_default("textures/voxel/vtest_F4.png") + .build(); // VTest-CK; a pure blue chromakey I used to make the game's logo - game_voxels::vtest_ck = voxel_registry::construct("vtest_ck", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/chromakey.png") - .build(); + game_voxels::vtest_ck = voxel_registry::construct("vtest_ck", voxel_type::CUBE, false, false).add_texture_default("textures/voxel/chromakey.png").build(); // Oak leaves; greenery. TODO: add trees as surface features - game_voxels::oak_leaves = voxel_registry::construct("oak_leaves", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/oak_leaves.png") - .set_surface(voxel_surface::GRASS) - .build(); + game_voxels::oak_leaves = + voxel_registry::construct("oak_leaves", voxel_type::CUBE, false, false).add_texture_default("textures/voxel/oak_leaves.png").set_surface(voxel_surface::GRASS).build(); // Oak planks; the thing that comes out of oak logs game_voxels::oak_planks = voxel_registry::construct("oak_planks", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/oak_planks_01.png") - .add_texture_default("textures/voxel/oak_planks_02.png") - .set_surface(voxel_surface::WOOD) - .build(); + .add_texture_default("textures/voxel/oak_planks_01.png") + .add_texture_default("textures/voxel/oak_planks_02.png") + .set_surface(voxel_surface::WOOD) + .build(); // Oak logs; greenery. TODO: add trees as surface features game_voxels::oak_log = voxel_registry::construct("oak_log", voxel_type::CUBE, false, false) - .add_texture_default("textures/voxel/oak_wood_01.png") - .add_texture_default("textures/voxel/oak_wood_02.png") - .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/oak_wood_top.png") - .add_texture(voxel_face::CUBE_TOP, "textures/voxel/oak_wood_top.png") - .set_surface(voxel_surface::WOOD) - .build(); + .add_texture_default("textures/voxel/oak_wood_01.png") + .add_texture_default("textures/voxel/oak_wood_02.png") + .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/oak_wood_top.png") + .add_texture(voxel_face::CUBE_TOP, "textures/voxel/oak_wood_top.png") + .set_surface(voxel_surface::WOOD) + .build(); // Glass; blend rendering test - game_voxels::glass = voxel_registry::construct("glass", voxel_type::CUBE, false, true) - .add_texture_default("textures/voxel/glass_01.png") - .set_surface(voxel_surface::GLASS) - .build(); + game_voxels::glass = + voxel_registry::construct("glass", voxel_type::CUBE, false, true).add_texture_default("textures/voxel/glass_01.png").set_surface(voxel_surface::GLASS).build(); // Slime; it's bouncy! game_voxels::slime = voxel_registry::construct("slime", voxel_type::CUBE, false, true) - .set_touch(voxel_touch::BOUNCE, glm::fvec3(0.00f, 0.60f, 0.00f)) - .add_texture_default("textures/voxel/slime_01.png") - .build(); + .set_touch(voxel_touch::BOUNCE, glm::fvec3(0.00f, 0.60f, 0.00f)) + .add_texture_default("textures/voxel/slime_01.png") + .build(); // Mud; you sink in it game_voxels::mud = voxel_registry::construct("mud", voxel_type::CUBE, false, false) - .set_touch(voxel_touch::SINK, glm::fvec3(0.50f, 0.75f, 0.50f)) - .add_texture_default("textures/voxel/mud_01.png") - .add_texture_default("textures/voxel/mud_02.png") - .set_surface(voxel_surface::DIRT) - .build(); + .set_touch(voxel_touch::SINK, glm::fvec3(0.50f, 0.75f, 0.50f)) + .add_texture_default("textures/voxel/mud_01.png") + .add_texture_default("textures/voxel/mud_02.png") + .set_surface(voxel_surface::DIRT) + .build(); } diff --git a/game/shared/globals.cc b/game/shared/globals.cc index 466398f..8552214 100644 --- a/game/shared/globals.cc +++ b/game/shared/globals.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/globals.hh" entt::dispatcher globals::dispatcher; diff --git a/game/shared/gravity.cc b/game/shared/gravity.cc index 66b6589..068f658 100644 --- a/game/shared/gravity.cc +++ b/game/shared/gravity.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/gravity.hh" #include "shared/dimension.hh" @@ -6,7 +7,7 @@ #include "shared/stasis.hh" #include "shared/velocity.hh" -void GravityComponent::fixed_update(Dimension *dimension) +void GravityComponent::fixed_update(Dimension* dimension) { auto fixed_acceleration = globals::fixed_frametime * dimension->get_gravity(); auto group = dimension->entities.group(entt::get, entt::exclude); diff --git a/game/shared/gravity.hh b/game/shared/gravity.hh index 06eeae7..53f51b7 100644 --- a/game/shared/gravity.hh +++ b/game/shared/gravity.hh @@ -6,7 +6,7 @@ class Dimension; struct GravityComponent final { public: - static void fixed_update(Dimension *dimension); + static void fixed_update(Dimension* dimension); }; #endif /* SHARED_GRAVITY_HH */ diff --git a/game/shared/item_registry.cc b/game/shared/item_registry.cc index 23dffdc..1263201 100644 --- a/game/shared/item_registry.cc +++ b/game/shared/item_registry.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/item_registry.hh" #include "core/crc64.hh" @@ -9,7 +10,7 @@ std::unordered_map item_registry::builders = {}; std::unordered_map item_registry::names = {}; std::vector> item_registry::items = {}; -ItemInfoBuilder::ItemInfoBuilder(const char *name) +ItemInfoBuilder::ItemInfoBuilder(const char* name) { prototype.name = name; prototype.texture = std::string(); @@ -17,14 +18,14 @@ ItemInfoBuilder::ItemInfoBuilder(const char *name) prototype.cached_texture = nullptr; } -ItemInfoBuilder &ItemInfoBuilder::set_texture(const char *texture) +ItemInfoBuilder& ItemInfoBuilder::set_texture(const char* texture) { prototype.texture = texture; prototype.cached_texture = nullptr; return *this; } -ItemInfoBuilder &ItemInfoBuilder::set_place_voxel(voxel_id place_voxel) +ItemInfoBuilder& ItemInfoBuilder::set_place_voxel(voxel_id place_voxel) { prototype.place_voxel = place_voxel; return *this; @@ -51,27 +52,35 @@ item_id ItemInfoBuilder::build(void) const return static_cast(item_registry::items.size()); } -ItemInfoBuilder &item_registry::construct(const char *name) +ItemInfoBuilder& item_registry::construct(const char* name) { const auto it = item_registry::builders.find(name); - if(it != item_registry::builders.cend()) + + if(it != item_registry::builders.cend()) { return it->second; - return item_registry::builders.emplace(name, ItemInfoBuilder(name)).first->second; + } else { + return item_registry::builders.emplace(name, ItemInfoBuilder(name)).first->second; + } } -ItemInfo *item_registry::find(const char *name) +ItemInfo* item_registry::find(const char* name) { const auto it = item_registry::names.find(name); - if(it != item_registry::names.cend()) + + if(it != item_registry::names.cend()) { return item_registry::find(it->second); - return nullptr; + } else { + return nullptr; + } } -ItemInfo *item_registry::find(const item_id item) +ItemInfo* item_registry::find(const item_id item) { - if((item != NULL_ITEM_ID) && (item <= item_registry::items.size())) + if((item != NULL_ITEM_ID) && (item <= item_registry::items.size())) { return item_registry::items[item - 1].get(); - return nullptr; + } else { + return nullptr; + } } void item_registry::purge(void) @@ -85,7 +94,7 @@ std::uint64_t item_registry::calcualte_checksum(void) { std::uint64_t result = 0; - for(const auto &info : item_registry::items) { + for(const auto& info : item_registry::items) { result = crc64::get(info->name, result); result += static_cast(info->place_voxel); } diff --git a/game/shared/item_registry.hh b/game/shared/item_registry.hh index 83b6053..17cff9f 100644 --- a/game/shared/item_registry.hh +++ b/game/shared/item_registry.hh @@ -21,12 +21,12 @@ struct ItemInfo final { class ItemInfoBuilder final { public: - explicit ItemInfoBuilder(const char *name); + explicit ItemInfoBuilder(const char* name); virtual ~ItemInfoBuilder(void) = default; public: - ItemInfoBuilder &set_texture(const char *texture); - ItemInfoBuilder &set_place_voxel(voxel_id place_voxel); + ItemInfoBuilder& set_texture(const char* texture); + ItemInfoBuilder& set_place_voxel(voxel_id place_voxel); public: item_id build(void) const; @@ -44,9 +44,9 @@ extern std::vector> items; namespace item_registry { -ItemInfoBuilder &construct(const char *name); -ItemInfo *find(const char *name); -ItemInfo *find(const item_id item); +ItemInfoBuilder& construct(const char* name); +ItemInfo* find(const char* name); +ItemInfo* find(const item_id item); } // namespace item_registry namespace item_registry diff --git a/game/shared/protocol.cc b/game/shared/protocol.cc index 3b32701..0e57fe4 100644 --- a/game/shared/protocol.cc +++ b/game/shared/protocol.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/protocol.hh" #include "core/buffer.hh" @@ -15,7 +16,7 @@ static ReadBuffer read_buffer; static WriteBuffer write_buffer; -ENetPacket *protocol::encode(const protocol::StatusRequest &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::StatusRequest& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::StatusRequest::ID); @@ -23,7 +24,7 @@ ENetPacket *protocol::encode(const protocol::StatusRequest &packet, enet_uint32 return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::StatusResponse &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::StatusResponse& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::StatusResponse::ID); @@ -34,7 +35,7 @@ ENetPacket *protocol::encode(const protocol::StatusResponse &packet, enet_uint32 return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::LoginRequest &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::LoginRequest& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::LoginRequest::ID); @@ -46,7 +47,7 @@ ENetPacket *protocol::encode(const protocol::LoginRequest &packet, enet_uint32 f return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::LoginResponse &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::LoginResponse& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::LoginResponse::ID); @@ -56,7 +57,7 @@ ENetPacket *protocol::encode(const protocol::LoginResponse &packet, enet_uint32 return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::Disconnect &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::Disconnect& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::Disconnect::ID); @@ -64,7 +65,7 @@ ENetPacket *protocol::encode(const protocol::Disconnect &packet, enet_uint32 fla return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::ChunkVoxels &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::ChunkVoxels& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::ChunkVoxels::ID); @@ -75,7 +76,7 @@ ENetPacket *protocol::encode(const protocol::ChunkVoxels &packet, enet_uint32 fl return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::EntityTransform &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::EntityTransform& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::EntityTransform::ID); @@ -92,7 +93,7 @@ ENetPacket *protocol::encode(const protocol::EntityTransform &packet, enet_uint3 return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::EntityHead &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::EntityHead& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::EntityHead::ID); @@ -103,7 +104,7 @@ ENetPacket *protocol::encode(const protocol::EntityHead &packet, enet_uint32 fla return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::EntityVelocity &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::EntityVelocity& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::EntityVelocity::ID); @@ -114,15 +115,15 @@ ENetPacket *protocol::encode(const protocol::EntityVelocity &packet, enet_uint32 return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::SpawnPlayer &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::SpawnPlayer& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::SpawnPlayer::ID); - write_buffer.write_UI64(static_cast(packet.entity)); + write_buffer.write_UI64(static_cast(packet.entity)); return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::ChatMessage &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::ChatMessage& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::ChatMessage::ID); @@ -132,7 +133,7 @@ ENetPacket *protocol::encode(const protocol::ChatMessage &packet, enet_uint32 fl return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::SetVoxel &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::SetVoxel& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::SetVoxel::ID); @@ -144,7 +145,7 @@ ENetPacket *protocol::encode(const protocol::SetVoxel &packet, enet_uint32 flags return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::RemoveEntity &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::RemoveEntity& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::RemoveEntity::ID); @@ -152,7 +153,7 @@ ENetPacket *protocol::encode(const protocol::RemoveEntity &packet, enet_uint32 f return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::EntityPlayer &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::EntityPlayer& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::EntityPlayer::ID); @@ -160,17 +161,17 @@ ENetPacket *protocol::encode(const protocol::EntityPlayer &packet, enet_uint32 f return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::ScoreboardUpdate &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::ScoreboardUpdate& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::ScoreboardUpdate::ID); write_buffer.write_UI16(static_cast(packet.names.size())); - for(const std::string &username : packet.names) + for(const std::string& username : packet.names) write_buffer.write_string(username.substr(0, protocol::MAX_USERNAME)); return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::RequestChunk &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::RequestChunk& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::RequestChunk::ID); @@ -180,7 +181,7 @@ ENetPacket *protocol::encode(const protocol::RequestChunk &packet, enet_uint32 f return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::GenericSound &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::GenericSound& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::GenericSound::ID); @@ -190,7 +191,7 @@ ENetPacket *protocol::encode(const protocol::GenericSound &packet, enet_uint32 f return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::EntitySound &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::EntitySound& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::EntitySound::ID); @@ -201,7 +202,7 @@ ENetPacket *protocol::encode(const protocol::EntitySound &packet, enet_uint32 fl return write_buffer.to_packet(flags); } -ENetPacket *protocol::encode(const protocol::DimensionInfo &packet, enet_uint32 flags) +ENetPacket* protocol::encode(const protocol::DimensionInfo& packet, enet_uint32 flags) { write_buffer.reset(); write_buffer.write_UI16(protocol::DimensionInfo::ID); @@ -210,34 +211,34 @@ ENetPacket *protocol::encode(const protocol::DimensionInfo &packet, enet_uint32 return write_buffer.to_packet(flags); } -void protocol::broadcast(ENetHost *host, ENetPacket *packet) +void protocol::broadcast(ENetHost* host, ENetPacket* packet) { if(packet) { enet_host_broadcast(host, protocol::CHANNEL, packet); } } -void protocol::broadcast(ENetHost *host, ENetPacket *packet, ENetPeer *except) +void protocol::broadcast(ENetHost* host, ENetPacket* packet, ENetPeer* except) { if(packet) { for(unsigned int i = 0U; i < host->peerCount; ++i) { if(host->peers[i].state == ENET_PEER_STATE_CONNECTED) { - if(&host->peers[i] == except) - continue; - enet_peer_send(&host->peers[i], protocol::CHANNEL, packet); + if(&host->peers[i] != except) { + enet_peer_send(&host->peers[i], protocol::CHANNEL, packet); + } } } } } -void protocol::send(ENetPeer *peer, ENetPacket *packet) +void protocol::send(ENetPeer* peer, ENetPacket* packet) { if(packet) { enet_peer_send(peer, protocol::CHANNEL, packet); } } -void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, ENetPeer *peer) +void protocol::decode(entt::dispatcher& dispatcher, const ENetPacket* packet, ENetPeer* peer) { read_buffer.reset(packet); @@ -260,9 +261,9 @@ void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, EN protocol::GenericSound generic_sound; protocol::EntitySound entity_sound; protocol::DimensionInfo dimension_info; - + auto id = read_buffer.read_UI16(); - + switch(id) { case protocol::StatusRequest::ID: status_request.peer = peer; @@ -405,14 +406,14 @@ void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, EN } } -ENetPacket *protocol::utils::make_disconnect(const char *reason, enet_uint32 flags) +ENetPacket* protocol::utils::make_disconnect(const char* reason, enet_uint32 flags) { protocol::Disconnect packet; packet.reason = std::string(reason); return protocol::encode(packet, flags); } -ENetPacket *protocol::utils::make_chat_message(const char *message, enet_uint32 flags) +ENetPacket* protocol::utils::make_chat_message(const char* message, enet_uint32 flags) { protocol::ChatMessage packet; packet.type = protocol::ChatMessage::TEXT_MESSAGE; @@ -420,7 +421,7 @@ ENetPacket *protocol::utils::make_chat_message(const char *message, enet_uint32 return protocol::encode(packet, flags); } -ENetPacket *protocol::utils::make_chunk_voxels(Dimension *dimension, entt::entity entity, enet_uint32 flags) +ENetPacket* protocol::utils::make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags) { if(auto component = dimension->chunks.try_get(entity)) { protocol::ChunkVoxels packet; @@ -432,7 +433,7 @@ ENetPacket *protocol::utils::make_chunk_voxels(Dimension *dimension, entt::entit return nullptr; } -ENetPacket *protocol::utils::make_entity_head(Dimension *dimension, entt::entity entity, enet_uint32 flags) +ENetPacket* protocol::utils::make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags) { if(auto component = dimension->entities.try_get(entity)) { protocol::EntityHead packet; @@ -444,7 +445,7 @@ ENetPacket *protocol::utils::make_entity_head(Dimension *dimension, entt::entity return nullptr; } -ENetPacket *protocol::utils::make_entity_transform(Dimension *dimension, entt::entity entity, enet_uint32 flags) +ENetPacket* protocol::utils::make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags) { if(auto component = dimension->entities.try_get(entity)) { protocol::EntityTransform packet; @@ -458,7 +459,7 @@ ENetPacket *protocol::utils::make_entity_transform(Dimension *dimension, entt::e return nullptr; } -ENetPacket *protocol::utils::make_entity_velocity(Dimension *dimension, entt::entity entity, enet_uint32 flags) +ENetPacket* protocol::utils::make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags) { if(auto component = dimension->entities.try_get(entity)) { protocol::EntityVelocity packet; @@ -470,7 +471,7 @@ ENetPacket *protocol::utils::make_entity_velocity(Dimension *dimension, entt::en return nullptr; } -ENetPacket *protocol::utils::make_entity_player(Dimension *dimension, entt::entity entity, enet_uint32 flags) +ENetPacket* protocol::utils::make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags) { if(dimension->entities.any_of(entity)) { protocol::EntityPlayer packet; @@ -481,7 +482,7 @@ ENetPacket *protocol::utils::make_entity_player(Dimension *dimension, entt::enti return nullptr; } -ENetPacket *protocol::utils::make_dimension_info(const Dimension *dimension) +ENetPacket* protocol::utils::make_dimension_info(const Dimension* dimension) { protocol::DimensionInfo packet; packet.name = dimension->get_name(); diff --git a/game/shared/protocol.hh b/game/shared/protocol.hh index 727ab1f..5b25628 100644 --- a/game/shared/protocol.hh +++ b/game/shared/protocol.hh @@ -23,7 +23,7 @@ template struct Base { constexpr static std::uint16_t ID = packet_id; virtual ~Base(void) = default; - ENetPeer *peer {nullptr}; + ENetPeer* peer { nullptr }; }; } // namespace protocol @@ -52,57 +52,57 @@ struct DimensionInfo; namespace protocol { -ENetPacket *encode(const StatusRequest &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const StatusResponse &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const LoginRequest &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const LoginResponse &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const Disconnect &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const ChunkVoxels &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const EntityTransform &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const EntityHead &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const EntityVelocity &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const SpawnPlayer &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const ChatMessage &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const SetVoxel &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const RemoveEntity &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const EntityPlayer &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const ScoreboardUpdate &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const RequestChunk &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const GenericSound &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const EntitySound &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *encode(const DimensionInfo &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const StatusRequest& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const StatusResponse& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const LoginRequest& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const LoginResponse& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const Disconnect& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const ChunkVoxels& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const EntityTransform& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const EntityHead& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const EntityVelocity& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const SpawnPlayer& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const ChatMessage& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const SetVoxel& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const RemoveEntity& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const EntityPlayer& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const ScoreboardUpdate& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const RequestChunk& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const GenericSound& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const EntitySound& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* encode(const DimensionInfo& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); } // namespace protocol namespace protocol { -void broadcast(ENetHost *host, ENetPacket *packet); -void broadcast(ENetHost *host, ENetPacket *packet, ENetPeer *except); -void send(ENetPeer *peer, ENetPacket *packet); +void broadcast(ENetHost* host, ENetPacket* packet); +void broadcast(ENetHost* host, ENetPacket* packet, ENetPeer* except); +void send(ENetPeer* peer, ENetPacket* packet); } // namespace protocol namespace protocol { -void decode(entt::dispatcher &dispatcher, const ENetPacket *packet, ENetPeer *peer); +void decode(entt::dispatcher& dispatcher, const ENetPacket* packet, ENetPeer* peer); } // namespace protocol namespace protocol::utils { -ENetPacket *make_disconnect(const char *reason, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *make_chat_message(const char *message, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_disconnect(const char* reason, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_chat_message(const char* message, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); } // namespace protocol::utils namespace protocol::utils { -ENetPacket *make_chunk_voxels(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); } // namespace protocol::utils namespace protocol::utils { -ENetPacket *make_entity_head(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *make_entity_transform(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *make_entity_velocity(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *make_entity_player(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); -ENetPacket *make_dimension_info(const Dimension *dimension); +ENetPacket* make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE); +ENetPacket* make_dimension_info(const Dimension* dimension); } // namespace protocol::utils struct protocol::StatusRequest final : public protocol::Base<0x0000> { @@ -162,7 +162,7 @@ struct protocol::SpawnPlayer final : public protocol::Base<0x0009> { struct protocol::ChatMessage final : public protocol::Base<0x000A> { constexpr static std::uint16_t TEXT_MESSAGE = 0x0000; - constexpr static std::uint16_t PLAYER_JOIN = 0x0001; + constexpr static std::uint16_t PLAYER_JOIN = 0x0001; constexpr static std::uint16_t PLAYER_LEAVE = 0x0002; std::uint16_t type; diff --git a/game/shared/ray_dda.cc b/game/shared/ray_dda.cc index 132d05a..3520817 100644 --- a/game/shared/ray_dda.cc +++ b/game/shared/ray_dda.cc @@ -1,20 +1,21 @@ #include "shared/pch.hh" + #include "shared/ray_dda.hh" #include "shared/coord.hh" #include "shared/dimension.hh" -RayDDA::RayDDA(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction) +RayDDA::RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction) { reset(dimension, start_chunk, start_fpos, direction); } -RayDDA::RayDDA(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction) +RayDDA::RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction) { reset(dimension, start_chunk, start_fpos, direction); } -void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction) +void RayDDA::reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction) { this->dimension = dimension; this->start_chunk = start_chunk; @@ -35,8 +36,7 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con if(direction.x < 0.0f) { this->side_dist.x = this->delta_dist.x * (start_fpos.x - lpos.x); this->vstep.x = voxel_pos::value_type(-1); - } - else { + } else { this->side_dist.x = this->delta_dist.x * (lpos.x + 1.0f - start_fpos.x); this->vstep.x = voxel_pos::value_type(+1); } @@ -44,8 +44,7 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con if(direction.y < 0.0f) { this->side_dist.y = this->delta_dist.y * (start_fpos.y - lpos.y); this->vstep.y = voxel_pos::value_type(-1); - } - else { + } else { this->side_dist.y = this->delta_dist.y * (lpos.y + 1.0f - start_fpos.y); this->vstep.y = voxel_pos::value_type(+1); } @@ -53,14 +52,13 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con if(direction.z < 0.0f) { this->side_dist.z = this->delta_dist.z * (start_fpos.z - lpos.z); this->vstep.z = voxel_pos::value_type(-1); - } - else { + } else { this->side_dist.z = this->delta_dist.z * (lpos.z + 1.0f - start_fpos.z); this->vstep.z = voxel_pos::value_type(+1); } } -void RayDDA::reset(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction) +void RayDDA::reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction) { reset(&dimension, start_chunk, start_fpos, direction); } @@ -73,22 +71,19 @@ voxel_id RayDDA::step(void) distance = side_dist.x; side_dist.x += delta_dist.x; vpos.x += vstep.x; - } - else { + } else { vnormal = voxel_pos(0, -vstep.y, 0); distance = side_dist.y; side_dist.y += delta_dist.y; vpos.y += vstep.y; } - } - else { + } else { if(side_dist.z < side_dist.y) { vnormal = voxel_pos(0, 0, -vstep.z); distance = side_dist.z; side_dist.z += delta_dist.z; vpos.z += vstep.z; - } - else { + } else { vnormal = voxel_pos(0, -vstep.y, 0); distance = side_dist.y; side_dist.y += delta_dist.y; @@ -99,4 +94,3 @@ voxel_id RayDDA::step(void) // This is slower than I want it to be return dimension->get_voxel(vpos); } - diff --git a/game/shared/ray_dda.hh b/game/shared/ray_dda.hh index 9b4374e..5378680 100644 --- a/game/shared/ray_dda.hh +++ b/game/shared/ray_dda.hh @@ -9,16 +9,16 @@ class Dimension; class RayDDA final { public: explicit RayDDA(void) = default; - explicit RayDDA(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction); - explicit RayDDA(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction); + explicit RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction); + explicit RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction); - void reset(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction); - void reset(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction); + void reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction); + void reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction); voxel_id step(void); public: - const Dimension *dimension; + const Dimension* dimension; chunk_pos start_chunk; glm::fvec3 start_fpos; glm::fvec3 direction; diff --git a/game/shared/splash.cc b/game/shared/splash.cc index 068c5c6..2381f7a 100644 --- a/game/shared/splash.cc +++ b/game/shared/splash.cc @@ -1,27 +1,28 @@ #include "shared/pch.hh" + #include "shared/splash.hh" -constexpr static const char *SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt"; -constexpr static const char *SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt"; +constexpr static const char* SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt"; +constexpr static const char* SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt"; constexpr static std::size_t SPLASH_SERVER_MAX_LENGTH = 32; static std::mt19937_64 splash_random; static std::vector splash_lines; -static std::string sanitize_line(const std::string &line) +static std::string sanitize_line(const std::string& line) { std::string result; for(auto chr : line) { - if((chr == '\r') || (chr == '\n')) - continue; - result.push_back(chr); + if(chr != '\r' && chr != '\n') { + result.push_back(chr); + } } return result; } -static void splash_init_filename(const char *filename) +static void splash_init_filename(const char* filename) { if(auto file = PHYSFS_openRead(filename)) { auto source = std::string(PHYSFS_fileLength(file), char(0x00)); @@ -34,8 +35,7 @@ static void splash_init_filename(const char *filename) while(std::getline(stream, line)) splash_lines.push_back(sanitize_line(line)); splash_random.seed(std::random_device()()); - } - else { + } else { splash_lines.push_back(fmt::format("{}: {}", filename, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))); splash_random.seed(std::random_device()()); } diff --git a/game/shared/stasis.cc b/game/shared/stasis.cc index 4e474af..462871d 100644 --- a/game/shared/stasis.cc +++ b/game/shared/stasis.cc @@ -1,16 +1,19 @@ #include "shared/pch.hh" + #include "shared/stasis.hh" #include "shared/dimension.hh" #include "shared/transform.hh" -void StasisComponent::fixed_update(Dimension *dimension) +void StasisComponent::fixed_update(Dimension* dimension) { auto view = dimension->entities.view(); for(auto [entity, transform] : view.each()) { - if(dimension->find_chunk(transform.chunk)) + if(dimension->find_chunk(transform.chunk)) { dimension->entities.remove(entity); - else dimension->entities.emplace_or_replace(entity); + } else { + dimension->entities.emplace_or_replace(entity); + } } } diff --git a/game/shared/stasis.hh b/game/shared/stasis.hh index 6a3e280..bd06d4e 100644 --- a/game/shared/stasis.hh +++ b/game/shared/stasis.hh @@ -8,7 +8,7 @@ class Dimension; // out of bounds in a specific dimension struct StasisComponent final { public: - static void fixed_update(Dimension *dimension); + static void fixed_update(Dimension* dimension); }; #endif /* SHARED_STASIS_HH */ diff --git a/game/shared/threading.cc b/game/shared/threading.cc index 71c30e1..ad496ee 100644 --- a/game/shared/threading.cc +++ b/game/shared/threading.cc @@ -1,15 +1,16 @@ #include "shared/pch.hh" + #include "shared/threading.hh" #include "core/cmdline.hh" #include "core/constexpr.hh" -constexpr static const char *DEFAULT_POOL_SIZE_ARG = "4"; +constexpr static const char* DEFAULT_POOL_SIZE_ARG = "4"; -static BS::light_thread_pool *thread_pool; -static std::deque task_deque; +static BS::light_thread_pool* thread_pool; +static std::deque task_deque; -static void task_process(Task *task) +static void task_process(Task* task) { task->set_status(task_status::PROCESSING); task->process(); @@ -41,11 +42,12 @@ void threading::init(void) // Use the maximum available number of concurrent // hardware threads provided by the implementation thread_pool_size = num_concurrent_threads; - } - else { - if(num_concurrent_threads) + } else { + if(num_concurrent_threads) { thread_pool_size = cxpr::clamp(std::strtoul(argument, nullptr, 10), 1U, num_concurrent_threads); - else thread_pool_size = cxpr::max(std::strtoul(argument, nullptr, 10), 1U); + } else { + thread_pool_size = cxpr::max(std::strtoul(argument, nullptr, 10), 1U); + } } spdlog::info("threading: using {} threads for pooling tasks", thread_pool_size); @@ -99,7 +101,7 @@ void threading::update(void) } } -void threading::detail::submit_new(Task *task) +void threading::detail::submit_new(Task* task) { task->set_status(task_status::ENQUEUED); diff --git a/game/shared/threading.hh b/game/shared/threading.hh index 083ccbf..bce4811 100644 --- a/game/shared/threading.hh +++ b/game/shared/threading.hh @@ -3,10 +3,10 @@ #pragma once enum class task_status : unsigned int { - ENQUEUED = 0x0000U, - PROCESSING = 0x0001U, - COMPLETED = 0x0002U, - CANCELLED = 0x0004U, + ENQUEUED = 0x0000U, + PROCESSING = 0x0001U, + COMPLETED = 0x0002U, + CANCELLED = 0x0004U, }; class Task { @@ -32,17 +32,17 @@ void update(void); namespace threading::detail { -void submit_new(Task *task); +void submit_new(Task* task); } // namespace threading::detail namespace threading { template -void submit(AT &&... args); +void submit(AT&&... args); } // namespace threading template -inline void threading::submit(AT &&... args) +inline void threading::submit(AT&&... args) { threading::detail::submit_new(new T(args...)); } diff --git a/game/shared/transform.cc b/game/shared/transform.cc index 6dc6126..f4b661c 100644 --- a/game/shared/transform.cc +++ b/game/shared/transform.cc @@ -1,10 +1,11 @@ #include "shared/pch.hh" + #include "shared/transform.hh" #include "shared/const.hh" #include "shared/dimension.hh" -constexpr inline static void update_component(unsigned int dim, TransformComponent &component) +constexpr inline static void update_component(unsigned int dim, TransformComponent& component) { if(component.local[dim] >= CHUNK_SIZE) { component.local[dim] -= CHUNK_SIZE; @@ -19,7 +20,7 @@ constexpr inline static void update_component(unsigned int dim, TransformCompone } } -void TransformComponent::fixed_update(Dimension *dimension) +void TransformComponent::fixed_update(Dimension* dimension) { auto view = dimension->entities.view(); diff --git a/game/shared/transform.hh b/game/shared/transform.hh index 0c0cc51..f9c5f47 100644 --- a/game/shared/transform.hh +++ b/game/shared/transform.hh @@ -15,7 +15,7 @@ public: // Updates TransformComponent values so that // the local translation field is always within // local coodrinates; [floating-point precision] - static void fixed_update(Dimension *dimension); + static void fixed_update(Dimension* dimension); }; // Client-side only - interpolated and previous transform diff --git a/game/shared/types.hh b/game/shared/types.hh index a107e54..85fbd19 100644 --- a/game/shared/types.hh +++ b/game/shared/types.hh @@ -20,7 +20,7 @@ using voxel_pos_xz = glm::vec<2, local_pos::value_type>; template<> struct std::hash final { - constexpr inline std::size_t operator()(const chunk_pos &cpos) const + constexpr inline std::size_t operator()(const chunk_pos& cpos) const { std::size_t value = 0; value ^= cpos.x * 73856093; @@ -32,7 +32,7 @@ struct std::hash final { template<> struct std::hash final { - constexpr inline std::size_t operator()(const chunk_pos_xz &cwpos) const + constexpr inline std::size_t operator()(const chunk_pos_xz& cwpos) const { std::size_t value = 0; value ^= cwpos.x * 73856093; diff --git a/game/shared/velocity.cc b/game/shared/velocity.cc index 6305363..329dc91 100644 --- a/game/shared/velocity.cc +++ b/game/shared/velocity.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/velocity.hh" #include "shared/dimension.hh" @@ -6,7 +7,7 @@ #include "shared/stasis.hh" #include "shared/transform.hh" -void VelocityComponent::fixed_update(Dimension *dimension) +void VelocityComponent::fixed_update(Dimension* dimension) { auto group = dimension->entities.group(entt::get, entt::exclude); diff --git a/game/shared/velocity.hh b/game/shared/velocity.hh index 9aafed1..45a2858 100644 --- a/game/shared/velocity.hh +++ b/game/shared/velocity.hh @@ -11,7 +11,7 @@ public: // Updates entities TransformComponent values // according to velocities multiplied by fixed_frametime. // NOTE: This system was previously called inertial - static void fixed_update(Dimension *dimension); + static void fixed_update(Dimension* dimension); }; #endif /* SHARED_VELOCITY_HH */ diff --git a/game/shared/voxel_registry.cc b/game/shared/voxel_registry.cc index ce6ee7f..cb3c724 100644 --- a/game/shared/voxel_registry.cc +++ b/game/shared/voxel_registry.cc @@ -1,4 +1,5 @@ #include "shared/pch.hh" + #include "shared/voxel_registry.hh" #include "core/crc64.hh" @@ -7,7 +8,7 @@ std::unordered_map voxel_registry::builders = {}; std::unordered_map voxel_registry::names = {}; std::vector> voxel_registry::voxels = {}; -VoxelInfoBuilder::VoxelInfoBuilder(const char *name, voxel_type type, bool animated, bool blending) +VoxelInfoBuilder::VoxelInfoBuilder(const char* name, voxel_type type, bool animated, bool blending) { prototype.name = name; prototype.type = type; @@ -44,27 +45,27 @@ VoxelInfoBuilder::VoxelInfoBuilder(const char *name, voxel_type type, bool anima prototype.item_pick = NULL_ITEM_ID; } -VoxelInfoBuilder &VoxelInfoBuilder::add_texture_default(const char *texture) +VoxelInfoBuilder& VoxelInfoBuilder::add_texture_default(const char* texture) { default_texture.paths.push_back(texture); return *this; } -VoxelInfoBuilder &VoxelInfoBuilder::add_texture(voxel_face face, const char *texture) +VoxelInfoBuilder& VoxelInfoBuilder::add_texture(voxel_face face, const char* texture) { const auto index = static_cast(face); prototype.textures[index].paths.push_back(texture); return *this; } -VoxelInfoBuilder &VoxelInfoBuilder::set_touch(voxel_touch type, const glm::fvec3 &values) +VoxelInfoBuilder& VoxelInfoBuilder::set_touch(voxel_touch type, const glm::fvec3& values) { prototype.touch_type = type; prototype.touch_values = values; return *this; } -VoxelInfoBuilder &VoxelInfoBuilder::set_surface(voxel_surface surface) +VoxelInfoBuilder& VoxelInfoBuilder::set_surface(voxel_surface surface) { prototype.surface = surface; return *this; @@ -113,8 +114,7 @@ voxel_id VoxelInfoBuilder::build(void) const new_info->textures[i].paths = default_texture.paths; new_info->textures[i].cached_offset = SIZE_MAX; new_info->textures[i].cached_plane = SIZE_MAX; - } - else { + } else { new_info->textures[i].paths = prototype.textures[i].paths; new_info->textures[i].cached_offset = SIZE_MAX; new_info->textures[i].cached_plane = SIZE_MAX; @@ -139,27 +139,35 @@ voxel_id VoxelInfoBuilder::build(void) const return new_info->base_voxel; } -VoxelInfoBuilder &voxel_registry::construct(const char *name, voxel_type type, bool animated, bool blending) +VoxelInfoBuilder& voxel_registry::construct(const char* name, voxel_type type, bool animated, bool blending) { const auto it = voxel_registry::builders.find(name); - if(it != voxel_registry::builders.cend()) + + if(it != voxel_registry::builders.cend()) { return it->second; - return voxel_registry::builders.emplace(name, VoxelInfoBuilder(name, type, animated, blending)).first->second; + } else { + return voxel_registry::builders.emplace(name, VoxelInfoBuilder(name, type, animated, blending)).first->second; + } } -VoxelInfo *voxel_registry::find(const char *name) +VoxelInfo* voxel_registry::find(const char* name) { const auto it = voxel_registry::names.find(name); - if(it != voxel_registry::names.cend()) + + if(it != voxel_registry::names.cend()) { return voxel_registry::find(it->second); - return nullptr; + } else { + return nullptr; + } } -VoxelInfo *voxel_registry::find(const voxel_id voxel) +VoxelInfo* voxel_registry::find(const voxel_id voxel) { - if((voxel != NULL_VOXEL_ID) && (voxel <= voxel_registry::voxels.size())) + if((voxel != NULL_VOXEL_ID) && (voxel <= voxel_registry::voxels.size())) { return voxel_registry::voxels[voxel - 1].get(); - return nullptr; + } else { + return nullptr; + } } void voxel_registry::purge(void) @@ -173,7 +181,7 @@ std::uint64_t voxel_registry::calcualte_checksum(void) { std::uint64_t result = 0; - for(const std::shared_ptr &info : voxel_registry::voxels) { + for(const std::shared_ptr& info : voxel_registry::voxels) { result = crc64::get(info->name, result); result += static_cast(info->type); result += static_cast(info->base_voxel); diff --git a/game/shared/voxel_registry.hh b/game/shared/voxel_registry.hh index b12bc68..5f7963f 100644 --- a/game/shared/voxel_registry.hh +++ b/game/shared/voxel_registry.hh @@ -5,70 +5,70 @@ #include "shared/types.hh" enum class voxel_face : unsigned short { - CUBE_NORTH = 0x0000, - CUBE_SOUTH = 0x0001, - CUBE_EAST = 0x0002, - CUBE_WEST = 0x0003, - CUBE_TOP = 0x0004, + CUBE_NORTH = 0x0000, + CUBE_SOUTH = 0x0001, + CUBE_EAST = 0x0002, + CUBE_WEST = 0x0003, + CUBE_TOP = 0x0004, CUBE_BOTTOM = 0x0005, - CUBE__NR = 0x0006, + CUBE__NR = 0x0006, - CROSS_NESW = 0x0000, - CROSS_NWSE = 0x0001, - CROSS__NR = 0x0002, + CROSS_NESW = 0x0000, + CROSS_NWSE = 0x0001, + CROSS__NR = 0x0002, }; enum class voxel_type : unsigned short { - CUBE = 0x0000, - CROSS = 0x0001, // TODO - MODEL = 0x0002, // TODO + CUBE = 0x0000, + CROSS = 0x0001, // TODO + MODEL = 0x0002, // TODO }; enum class voxel_facing : unsigned short { - NORTH = 0x0000, - SOUTH = 0x0001, - EAST = 0x0002, - WEST = 0x0003, - UP = 0x0004, - DOWN = 0x0005, - NESW = 0x0006, - NWSE = 0x0007, + NORTH = 0x0000, + SOUTH = 0x0001, + EAST = 0x0002, + WEST = 0x0003, + UP = 0x0004, + DOWN = 0x0005, + NESW = 0x0006, + NWSE = 0x0007, }; enum class voxel_touch : unsigned short { - SOLID = 0x0000, // The entity is stopped in its tracks - BOUNCE = 0x0001, // The entity bounces back with some energy loss - SINK = 0x0002, // The entity phases/sinks through the voxel - NOTHING = 0xFFFF, + SOLID = 0x0000, // The entity is stopped in its tracks + BOUNCE = 0x0001, // The entity bounces back with some energy loss + SINK = 0x0002, // The entity phases/sinks through the voxel + NOTHING = 0xFFFF, }; enum class voxel_surface : unsigned short { - DEFAULT = 0x0000, - STONE = 0x0001, - DIRT = 0x0002, - GLASS = 0x0003, - GRASS = 0x0004, - GRAVEL = 0x0005, - METAL = 0x0006, - SAND = 0x0007, - WOOD = 0x0008, - SLOSH = 0x0009, - COUNT = 0x000A, - UNKNOWN = 0xFFFF, + DEFAULT = 0x0000, + STONE = 0x0001, + DIRT = 0x0002, + GLASS = 0x0003, + GRASS = 0x0004, + GRAVEL = 0x0005, + METAL = 0x0006, + SAND = 0x0007, + WOOD = 0x0008, + SLOSH = 0x0009, + COUNT = 0x000A, + UNKNOWN = 0xFFFF, }; using voxel_vis = unsigned short; -constexpr static voxel_vis VIS_NORTH = 1 << static_cast(voxel_facing::NORTH); -constexpr static voxel_vis VIS_SOUTH = 1 << static_cast(voxel_facing::SOUTH); -constexpr static voxel_vis VIS_EAST = 1 << static_cast(voxel_facing::EAST); -constexpr static voxel_vis VIS_WEST = 1 << static_cast(voxel_facing::WEST); -constexpr static voxel_vis VIS_UP = 1 << static_cast(voxel_facing::UP); -constexpr static voxel_vis VIS_DOWN = 1 << static_cast(voxel_facing::DOWN); +constexpr static voxel_vis VIS_NORTH = 1 << static_cast(voxel_facing::NORTH); +constexpr static voxel_vis VIS_SOUTH = 1 << static_cast(voxel_facing::SOUTH); +constexpr static voxel_vis VIS_EAST = 1 << static_cast(voxel_facing::EAST); +constexpr static voxel_vis VIS_WEST = 1 << static_cast(voxel_facing::WEST); +constexpr static voxel_vis VIS_UP = 1 << static_cast(voxel_facing::UP); +constexpr static voxel_vis VIS_DOWN = 1 << static_cast(voxel_facing::DOWN); struct VoxelTexture final { std::vector paths; std::size_t cached_offset; // client-side only - std::size_t cached_plane; // client-side only + std::size_t cached_plane; // client-side only }; struct VoxelInfo final { @@ -100,14 +100,14 @@ struct VoxelInfo final { class VoxelInfoBuilder final { public: - explicit VoxelInfoBuilder(const char *name, voxel_type type, bool animated, bool blending); + explicit VoxelInfoBuilder(const char* name, voxel_type type, bool animated, bool blending); virtual ~VoxelInfoBuilder(void) = default; public: - VoxelInfoBuilder &add_texture_default(const char *texture); - VoxelInfoBuilder &add_texture(voxel_face face, const char *texture); - VoxelInfoBuilder &set_touch(voxel_touch type, const glm::fvec3 &values); - VoxelInfoBuilder &set_surface(voxel_surface surface); + VoxelInfoBuilder& add_texture_default(const char* texture); + VoxelInfoBuilder& add_texture(voxel_face face, const char* texture); + VoxelInfoBuilder& set_touch(voxel_touch type, const glm::fvec3& values); + VoxelInfoBuilder& set_surface(voxel_surface surface); public: voxel_id build(void) const; @@ -126,9 +126,9 @@ extern std::vector> voxels; namespace voxel_registry { -VoxelInfoBuilder &construct(const char *name, voxel_type type, bool animated, bool blending); -VoxelInfo *find(const char *name); -VoxelInfo *find(const voxel_id voxel); +VoxelInfoBuilder& construct(const char* name, voxel_type type, bool animated, bool blending); +VoxelInfo* find(const char* name); +VoxelInfo* find(const voxel_id voxel); } // namespace voxel_registry namespace voxel_registry diff --git a/game/shared/voxel_storage.cc b/game/shared/voxel_storage.cc index eb51347..f2c4d42 100644 --- a/game/shared/voxel_storage.cc +++ b/game/shared/voxel_storage.cc @@ -1,9 +1,10 @@ #include "shared/pch.hh" + #include "shared/voxel_storage.hh" #include "core/buffer.hh" -void VoxelStorage::serialize(WriteBuffer &buffer) const +void VoxelStorage::serialize(WriteBuffer& buffer) const { auto bound = mz_compressBound(sizeof(VoxelStorage)); auto zdata = std::vector(bound); @@ -22,17 +23,19 @@ void VoxelStorage::serialize(WriteBuffer &buffer) const buffer.write_UI64(bound); // Write all the compressed data into the buffer - for(std::size_t i = 0; i < bound; buffer.write_UI8(zdata[i++])); + for(std::size_t i = 0; i < bound; buffer.write_UI8(zdata[i++])) + ; } -void VoxelStorage::deserialize(ReadBuffer &buffer) +void VoxelStorage::deserialize(ReadBuffer& buffer) { auto size = static_cast(sizeof(VoxelStorage)); auto bound = static_cast(buffer.read_UI64()); auto zdata = std::vector(bound); // Read all the compressed data from the buffer - for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read_UI8()); + for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read_UI8()) + ; mz_uncompress(reinterpret_cast(data()), &size, zdata.data(), bound); diff --git a/game/shared/voxel_storage.hh b/game/shared/voxel_storage.hh index 08d234d..a31cf3e 100644 --- a/game/shared/voxel_storage.hh +++ b/game/shared/voxel_storage.hh @@ -11,8 +11,8 @@ class WriteBuffer; class VoxelStorage final : public std::array { public: using std::array::array; - void serialize(WriteBuffer &buffer) const; - void deserialize(ReadBuffer &buffer); + void serialize(WriteBuffer& buffer) const; + void deserialize(ReadBuffer& buffer); }; #endif /* SHARED_VOXEL_STORAGE_HH */ -- cgit