diff options
Diffstat (limited to 'game/client')
74 files changed, 1368 insertions, 1132 deletions
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<unsigned int> bother_set; static std::deque<BotherQueueItem> 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<unsigned int>(reinterpret_cast<std::uintptr_t>(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<void *>(static_cast<std::uintptr_t>(item.identity)); + peer->data = reinterpret_cast<void*>(static_cast<std::uintptr_t>(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<void *>(static_cast<std::uintptr_t>(identity))) { + if(bother_host->peers[i].data == reinterpret_cast<void*>(static_cast<std::uintptr_t>(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<HeadComponentIntr>(globals::player); - const auto &transform = globals::dimension->entities.get<TransformComponentIntr>(globals::player); - const auto &velocity = globals::dimension->entities.get<VelocityComponent>(globals::player); + const auto& head = globals::dimension->entities.get<HeadComponentIntr>(globals::player); + const auto& transform = globals::dimension->entities.get<TransformComponentIntr>(globals::player); + const auto& velocity = globals::dimension->entities.get<VelocityComponent>(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<SoundEffect> 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<ChunkQuad>; 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<std::int64_t>(delta[1], -1, 1); delta[2] = cxpr::clamp<std::int64_t>(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<VoxelStorage, NUM_CACHED_CPOS> 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<local_pos::value_type>)) + + if(vis_test(voxel, info, lpos + DIR_NORTH<local_pos::value_type>)) { vis |= VIS_NORTH; - if(vis_test(voxel, info, lpos + DIR_SOUTH<local_pos::value_type>)) + } + + if(vis_test(voxel, info, lpos + DIR_SOUTH<local_pos::value_type>)) { vis |= VIS_SOUTH; - if(vis_test(voxel, info, lpos + DIR_EAST<local_pos::value_type>)) + } + + if(vis_test(voxel, info, lpos + DIR_EAST<local_pos::value_type>)) { vis |= VIS_EAST; - if(vis_test(voxel, info, lpos + DIR_WEST<local_pos::value_type>)) + } + + if(vis_test(voxel, info, lpos + DIR_WEST<local_pos::value_type>)) { vis |= VIS_WEST; - if(vis_test(voxel, info, lpos + DIR_UP<local_pos::value_type>)) + } + + if(vis_test(voxel, info, lpos + DIR_UP<local_pos::value_type>)) { vis |= VIS_UP; - if(vis_test(voxel, info, lpos + DIR_DOWN<local_pos::value_type>)) + } + + if(vis_test(voxel, info, lpos + DIR_DOWN<local_pos::value_type>)) { 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<ChunkMeshComponent>(m_entity); + auto& component = globals::dimension->chunks.emplace_or_replace<ChunkMeshComponent>(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<std::size_t>(face)]; + const VoxelTexture& vtex = info->textures[static_cast<std::size_t>(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<std::size_t>(face)]; + const VoxelTexture& vtex = info->textures[static_cast<std::size_t>(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<chunk_pos, 6> neighbours = { event.cpos + DIR_NORTH<chunk_pos::value_type>, @@ -317,15 +386,15 @@ static void on_chunk_create(const ChunkCreateEvent &event) globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(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<NeedsMeshingComponent>(chunk->get_entity()); continue; } } } -static void on_chunk_update(const ChunkUpdateEvent &event) +static void on_chunk_update(const ChunkUpdateEvent& event) { const std::array<chunk_pos, 6> neighbours = { event.cpos + DIR_NORTH<chunk_pos::value_type>, @@ -338,15 +407,15 @@ static void on_chunk_update(const ChunkUpdateEvent &event) globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(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<NeedsMeshingComponent>(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<NeedsMeshingComponent>(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<NeedsMeshingComponent>(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<std::uint32_t, 2>; -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<ChunkComponent>(ea).cpos - camera::position_chunk; const auto dir_b = globals::dimension->chunks.get<ChunkComponent>(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<ChunkComponent>(); 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<std::uint16_t>(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<HeadComponent>(entity); + const auto& head = dimension->entities.get<HeadComponent>(entity); dimension->entities.emplace_or_replace<HeadComponentIntr>(entity, head); dimension->entities.emplace_or_replace<HeadComponentPrev>(entity, head); - const auto &transform = dimension->entities.get<TransformComponent>(entity); + const auto& transform = dimension->entities.get<TransformComponent>(entity); dimension->entities.emplace_or_replace<TransformComponentIntr>(entity, transform); dimension->entities.emplace_or_replace<TransformComponentPrev>(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<BinFile> bin_unscii16; static resource_ptr<BinFile> 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<float>(event.size.x); auto height_float = static_cast<float>(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<VoxelInfo> &info : voxel_registry::voxels) { - for(const VoxelTexture &vtex : info->textures) { + for(const std::shared_ptr<VoxelInfo>& 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<VoxelInfo> &info : voxel_registry::voxels) { - for(VoxelTexture &vtex : info->textures) { + for(std::shared_ptr<VoxelInfo>& 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<ItemInfo> &info : item_registry::items) { + for(std::shared_ptr<ItemInfo>& info : item_registry::items) { info->cached_texture = resource::load<TextureGUI>(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<HeadComponent>(globals::player); - const auto &transform = globals::dimension->entities.get<TransformComponent>(globals::player); - const auto &velocity = globals::dimension->entities.get<VelocityComponent>(globals::player); + const auto& head = globals::dimension->entities.get<HeadComponent>(globals::player); + const auto& transform = globals::dimension->entities.get<TransformComponent>(globals::player); + const auto& velocity = globals::dimension->entities.get<VelocityComponent>(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<GravityComponent>(globals::player); - else globals::dimension->entities.emplace_or_replace<GravityComponent>(globals::player); + } else { + globals::dimension->entities.emplace_or_replace<GravityComponent>(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<ToggleEnabledEvent>().connect<&on_toggle_enable>(); globals::dispatcher.sink<ToggleDisabledEvent>().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<int, const char *> 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<int, const char*> 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<int, const char *> 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<int, const char*> 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<TextureGUI> 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<int, const char *> 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<int, const char*> 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<LanguageInfo>; @@ -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<VelocityComponent>(globals::player).value; - const auto &position = camera::position_local; + const auto& velocity = globals::dimension->entities.get<VelocityComponent>(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<float>(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<float>(width) / static_cast<float>(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<float>(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<const char *>(message)); + spdlog::info("opengl: {}", reinterpret_cast<const char*>(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<const char *>(glGetString(GL_VERSION))); - spdlog::info("opengl: renderer: {}", reinterpret_cast<const char *>(glGetString(GL_RENDERER))); + spdlog::info("opengl: version: {}", reinterpret_cast<const char*>(glGetString(GL_VERSION))); + spdlog::info("opengl: renderer: {}", reinterpret_cast<const char*>(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<unsigned char *>(image->pixels); + icon_image.pixels = reinterpret_cast<unsigned char*>(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<const char *>(alcGetString(globals::sound_dev, ALC_DEVICE_SPECIFIER))); + } else { + spdlog::info("sound: {}", reinterpret_cast<const char*>(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<BinFile>(); resource::soft_cleanup<Image>(); - + resource::soft_cleanup<SoundEffect>(); resource::soft_cleanup<TextureGUI>(); @@ -414,13 +407,13 @@ int main(int argc, char **argv) } client_game::deinit(); - + resource::hard_cleanup<BinFile>(); resource::hard_cleanup<Image>(); resource::hard_cleanup<SoundEffect>(); resource::hard_cleanup<TextureGUI>(); - + 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<TextureGUI> 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<float>(title->size.x) / static_cast<float>(title->size.y); - else title_aspect = static_cast<float>(title->size.y) / static_cast<float>(title->size.x); + } else { + title_aspect = static_cast<float>(title->size.y) / static_cast<float>(title->size.x); + } globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>(); globals::dispatcher.sink<LanguageSetEvent>().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<const char *>(r_version.c_str())); + auto r_version_line = fmt::format("GL_VERSION: {}", reinterpret_cast<const char*>(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<const char *>(r_renderer.c_str())); + auto r_renderer_line = fmt::format("GL_RENDERER: {}", reinterpret_cast<const char*>(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<HeadComponent>(globals::player); - const auto &transform = globals::dimension->entities.get<TransformComponent>(globals::player); - const auto &velocity = globals::dimension->entities.get<VelocityComponent>(globals::player); + const auto& head = globals::dimension->entities.get<HeadComponent>(globals::player); + const auto& transform = globals::dimension->entities.get<TransformComponent>(globals::player); + const auto& velocity = globals::dimension->entities.get<VelocityComponent>(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<ServerStatusItem *> servers_deque; -static ServerStatusItem *selected_server; +static std::deque<ServerStatusItem*> 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<std::uint16_t>(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<void *>(item)); + const std::string sid = fmt::format("###play_menu.servers.{}", static_cast<void*>(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<HeadComponent>(globals::player); + auto& head = globals::dimension->entities.get<HeadComponent>(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<float> 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<HeadComponent>(globals::player); - auto &transform = globals::dimension->entities.get<TransformComponent>(globals::player); - auto &velocity = globals::dimension->entities.get<VelocityComponent>(globals::player); + const auto& head = globals::dimension->entities.get<HeadComponent>(globals::player); + auto& transform = globals::dimension->entities.get<TransformComponent>(globals::player); + auto& velocity = globals::dimension->entities.get<VelocityComponent>(globals::player); // Interpolation - preserve current component states globals::dimension->entities.emplace_or_replace<TransformComponentPrev>(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<float>; - if(button_move_up.is_pressed(gamepad::state)) + } + + if(button_move_up.is_pressed(gamepad::state)) { movement_direction += DIR_UP<float>; + } + 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<float>; - 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<float>; - 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<float>; - 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<float>; - 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<float>; - 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<float>; + } } } 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<std::string> &out_lines, std::vector<GL_VariedMacro> &out_variants) +static void parse_source(const char* source, std::vector<std::string>& out_lines, std::vector<GL_VariedMacro>& 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<unsigned int>::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<float>(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<float>(i) / static_cast<float>(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<std::uint64_t>(entity), static_cast<std::uint64_t>(created)); + spdlog::critical("receive: entity desync: network {} resolved as client {}", static_cast<std::uint64_t>(entity), static_cast<std::uint64_t>(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<HeadComponent>(packet.entity); - auto &prevcomp = globals::dimension->entities.get_or_emplace<HeadComponentPrev>(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace<HeadComponent>(packet.entity); + auto& prevcomp = globals::dimension->entities.get_or_emplace<HeadComponentPrev>(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<TransformComponent>(packet.entity); - auto &prevcomp = globals::dimension->entities.get_or_emplace<TransformComponentPrev>(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace<TransformComponent>(packet.entity); + auto& prevcomp = globals::dimension->entities.get_or_emplace<TransformComponentPrev>(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<VelocityComponent>(packet.entity); + auto& component = globals::dimension->entities.get_or_emplace<VelocityComponent>(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<std::string> 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<float>(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<float>(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<PHYSFS_File *>(context), data, size); + PHYSFS_writeBytes(reinterpret_cast<PHYSFS_File*>(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<protocol::LoginResponse>().connect<&on_login_response_packet>(); globals::dispatcher.sink<protocol::Disconnect>().connect<&on_disconnect_packet>(); globals::dispatcher.sink<protocol::SetVoxel>().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<unsigned int>(settings_location::COUNT); enum class setting_type : unsigned int { - CHECKBOX = 0x0000U, ///< ConfigBoolean - INPUT_INT = 0x0001U, ///< ConfigNumber<int> - INPUT_FLOAT = 0x0002U, ///< ConfigNumber<float> - INPUT_UINT = 0x0003U, ///< ConfigNumber<unsigned int> - INPUT_STRING = 0x0004U, ///< ConfigString - SLIDER_INT = 0x0005U, ///< ConfigNumber<int> - SLIDER_FLOAT = 0x0006U, ///< ConfigNumber<float> - SLIDER_UINT = 0x0007U, ///< ConfigNumber<unsigned int> - STEPPER_INT = 0x0008U, ///< ConfigNumber<int> - STEPPER_UINT = 0x0009U, ///< ConfigNumber<unsigned int> - KEYBIND = 0x000AU, ///< ConfigKeyBind - GAMEPAD_AXIS = 0x000BU, ///< ConfigGamepadAxis - GAMEPAD_BUTTON = 0x000CU, ///< ConfigGamepadButton + CHECKBOX = 0x0000U, ///< ConfigBoolean + INPUT_INT = 0x0001U, ///< ConfigNumber<int> + INPUT_FLOAT = 0x0002U, ///< ConfigNumber<float> + INPUT_UINT = 0x0003U, ///< ConfigNumber<unsigned int> + INPUT_STRING = 0x0004U, ///< ConfigString + SLIDER_INT = 0x0005U, ///< ConfigNumber<int> + SLIDER_FLOAT = 0x0006U, ///< ConfigNumber<float> + SLIDER_UINT = 0x0007U, ///< ConfigNumber<unsigned int> + STEPPER_INT = 0x0008U, ///< ConfigNumber<int> + STEPPER_UINT = 0x0009U, ///< ConfigNumber<unsigned int> + 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<std::string> wids; - ConfigInt *value; + ConfigInt* value; }; class SettingValue_StepperUnsigned final : public SettingValue { @@ -154,7 +155,7 @@ public: public: std::vector<std::string> 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<SettingValue *> values_all; -static std::vector<SettingValue *> values[NUM_LOCATIONS]; +static std::vector<SettingValue*> values_all; +static std::vector<SettingValue*> 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<void *>(value)); - wids[1] = fmt::format("{}###{}", str_checkbox_true, static_cast<void *>(value)); + wids[0] = fmt::format("{}###{}", str_checkbox_false, static_cast<void*>(value)); + wids[1] = fmt::format("{}###{}", str_checkbox_true, static_cast<void*>(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<const void *>(value)); + wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast<const void*>(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<const void *>(value)); + wids[i] = fmt::format("{}###{}", language::resolve(key.c_str()), static_cast<const void*>(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<const void *>(value)); - wids[1] = fmt::format("{}###{}", value->get(), static_cast<const void *>(value)); + wids[0] = fmt::format("...###{}", static_cast<const void*>(value)); + wids[1] = fmt::format("{}###{}", value->get(), static_cast<const void*>(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<const void *>(value)); - wids[1] = fmt::format("{}###{}", value->get_name(), static_cast<const void *>(value)); - wid_checkbox = fmt::format("###CHECKBOX_{}", static_cast<const void *>(value)); + wids[0] = fmt::format("...###{}", static_cast<const void*>(value)); + wids[1] = fmt::format("{}###{}", value->get_name(), static_cast<const void*>(value)); + wid_checkbox = fmt::format("###CHECKBOX_{}", static_cast<const void*>(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<const void *>(value)); - wids[1] = fmt::format("{}###{}", value->get(), static_cast<const void *>(value)); + wids[0] = fmt::format("...###{}", static_cast<const void*>(value)); + wids[1] = fmt::format("{}###{}", value->get(), static_cast<const void*>(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<SettingValue_KeyBind *>(value); + auto keybind = static_cast<SettingValue_KeyBind*>(value); keybind->refresh_wids(); continue; } if(value->type == setting_type::GAMEPAD_AXIS) { - auto gamepad_axis = static_cast<SettingValue_GamepadAxis *>(value); + auto gamepad_axis = static_cast<SettingValue_GamepadAxis*>(value); gamepad_axis->refresh_wids(); continue; } if(value->type == setting_type::GAMEPAD_BUTTON) { - auto gamepad_button = static_cast<SettingValue_GamepadButton *>(value); + auto gamepad_button = static_cast<SettingValue_GamepadButton*>(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<SettingValue_CheckBox *>(value); + auto checkbox = static_cast<SettingValue_CheckBox*>(value); checkbox->refresh_wids(); } if(value->type == setting_type::STEPPER_INT) { - auto stepper = static_cast<SettingValue_StepperInt *>(value); + auto stepper = static_cast<SettingValue_StepperInt*>(value); stepper->refresh_wids(); } if(value->type == setting_type::STEPPER_UINT) { - auto stepper = static_cast<SettingValue_StepperUnsigned *>(value); + auto stepper = static_cast<SettingValue_StepperUnsigned*>(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<unsigned int>(location)]) { + for(const SettingValue* value : values[static_cast<unsigned int>(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<LanguageSetEvent>().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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value->value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value->value)); values[static_cast<unsigned int>(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<const void *>(setting_value)); + setting_value->wid = fmt::format("###{}", static_cast<const void*>(setting_value)); values[static_cast<unsigned int>(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<SoundEffect>(sound), looping, pitch); - else sound::play_generic(static_cast<const char *>(nullptr), looping, pitch); + } else { + sound::play_generic(static_cast<const char*>(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<SoundEffect>(sound), looping, pitch); - else sound::play_entity(entity, static_cast<const char *>(nullptr), looping, pitch); + } else { + sound::play_entity(entity, static_cast<const char*>(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<SoundEffect>(sound), looping, pitch); - else sound::play_player(static_cast<const char *>(nullptr), looping, pitch); + } else { + sound::play_player(static_cast<const char*>(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<SoundEffect>(sound), looping, pitch); - else sound::play_ui(static_cast<const char *>(nullptr), looping, pitch); + } else { + sound::play_ui(static_cast<const char*>(nullptr), looping, pitch); + } } void sound::play_generic(resource_ptr<SoundEffect> sound, bool looping, float pitch) @@ -169,7 +176,7 @@ void sound::play_player(resource_ptr<SoundEffect> 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<std::string, resource_ptr<SoundEffect>> 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<std::size_t>(PHYSFS_readBytes(reinterpret_cast<PHYSFS_File *>(file), output, count)); + return static_cast<std::size_t>(PHYSFS_readBytes(reinterpret_cast<PHYSFS_File*>(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<PHYSFS_File *>(file), PHYSFS_tell(reinterpret_cast<PHYSFS_File *>(file)) + offset); - return PHYSFS_seek(reinterpret_cast<PHYSFS_File *>(file), offset); + if(origin == drwav_seek_origin_current) { + return PHYSFS_seek(reinterpret_cast<PHYSFS_File*>(file), PHYSFS_tell(reinterpret_cast<PHYSFS_File*>(file)) + offset); + } else { + return PHYSFS_seek(reinterpret_cast<PHYSFS_File*>(file), offset); + } } template<> -resource_ptr<SoundEffect> resource::load<SoundEffect>(const char *name, unsigned int flags) +resource_ptr<SoundEffect> resource::load<SoundEffect>(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -41,7 +44,6 @@ resource_ptr<SoundEffect> resource::load<SoundEffect>(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<SoundEffect> resource::load<SoundEffect>(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<drwav_int16 *>(samples)); + auto count = drwav_read_pcm_frames_s16(&wav_info, wav_info.totalPCMFrameCount, reinterpret_cast<drwav_int16*>(samples)); auto sample_rate = static_cast<ALsizei>(wav_info.sampleRate); auto length = static_cast<ALsizei>(count * sizeof(ALshort)); @@ -79,10 +81,12 @@ resource_ptr<SoundEffect> resource::load<SoundEffect>(const char *name, unsigned template<> void resource::hard_cleanup<SoundEffect>(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<SoundEmitterComponent>(); - 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<TextureGUI> 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<float>(texture->size.x) / static_cast<float>(texture->size.y); - else texture_aspect = static_cast<float>(texture->size.y) / static_cast<float>(texture->size.x); + } else { + texture_aspect = static_cast<float>(texture->size.y) / static_cast<float>(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<float>(remains) / static_cast<float>(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<float>(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<std::string, resource_ptr<TextureGUI>> resource_map; template<> -resource_ptr<TextureGUI> resource::load<TextureGUI>(const char *name, unsigned int flags) +resource_ptr<TextureGUI> resource::load<TextureGUI>(const char* name, unsigned int flags) { auto it = resource_map.find(name); @@ -16,10 +17,15 @@ resource_ptr<TextureGUI> resource::load<TextureGUI>(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<Image>(name, image_load_flags)) { GLuint gl_texture; @@ -28,27 +34,35 @@ resource_ptr<TextureGUI> resource::load<TextureGUI>(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<TextureGUI>(); new_resource->handle = static_cast<ImTextureID>(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<TextureGUI> resource::load<TextureGUI>(const char *name, unsigned i template<> void resource::hard_cleanup<TextureGUI>(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<GLuint>(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<AtlasPlane> 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<std::string> &strings) +static std::size_t vector_hash(const std::vector<std::string>& 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<std::string> &paths, std::size_t hash_value) +static AtlasStrip* plane_new_strip(AtlasPlane& plane, const std::vector<std::string>& 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<Image>(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::vector<std::str glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, offset, image->size.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<std::string> &paths) +AtlasStrip* voxel_atlas::find_or_load(const std::vector<std::string>& 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<std::string> &paths) +AtlasStrip* voxel_atlas::find(const std::vector<std::string>& 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<std::string> &paths); -AtlasStrip *find(const std::vector<std::string> &paths); +AtlasStrip* find_or_load(const std::vector<std::string>& paths); +AtlasStrip* find(const std::vector<std::string>& 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<std::size_t>(voxel_surfa static std::vector<resource_ptr<SoundEffect>> 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<SoundEffect>(name)) { auto surface_index = static_cast<std::size_t>(surface); @@ -25,7 +26,7 @@ static resource_ptr<SoundEffect> 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()); } |
