summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-12-26 14:50:33 +0500
committeruntodesu <kirill@untode.su>2025-12-26 14:50:33 +0500
commit6c2abde5c99a236453b795abaa6d7d70105e31f7 (patch)
treef085049b9615a7d03cca5de40adb6529d6c13e11 /src
parentf40d09cb8f712e87691af4912f3630d92d692779 (diff)
downloadvoxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.tar.bz2
voxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.zip
Just a big Ctrl+H refactoring
Diffstat (limited to 'src')
-rw-r--r--src/core/io/buffer.cc80
-rw-r--r--src/core/io/buffer.hh14
-rw-r--r--src/core/io/cmdline.cc12
-rw-r--r--src/core/io/cmdline.hh4
-rw-r--r--src/core/io/config_map.cc16
-rw-r--r--src/core/io/config_map.hh3
-rw-r--r--src/core/io/physfs.cc10
-rw-r--r--src/core/io/physfs.hh6
-rw-r--r--src/core/resource/image.cc2
-rw-r--r--src/core/threading.cc2
-rw-r--r--src/core/version.cc6
-rw-r--r--src/game/client/config/gamepad_axis.cc4
-rw-r--r--src/game/client/config/gamepad_button.cc4
-rw-r--r--src/game/client/const.hh8
-rw-r--r--src/game/client/entity/camera.cc69
-rw-r--r--src/game/client/entity/camera.hh12
-rw-r--r--src/game/client/entity/factory.cc18
-rw-r--r--src/game/client/entity/factory.hh9
-rw-r--r--src/game/client/entity/interpolation.cc7
-rw-r--r--src/game/client/entity/interpolation.hh4
-rw-r--r--src/game/client/entity/listener.cc12
-rw-r--r--src/game/client/entity/listener.hh4
-rw-r--r--src/game/client/entity/player_look.cc24
-rw-r--r--src/game/client/entity/player_look.hh4
-rw-r--r--src/game/client/entity/player_move.cc36
-rw-r--r--src/game/client/entity/player_move.hh4
-rw-r--r--src/game/client/entity/sound_emitter.cc14
-rw-r--r--src/game/client/entity/sound_emitter.hh3
-rw-r--r--src/game/client/experiments.cc30
-rw-r--r--src/game/client/game.cc350
-rw-r--r--src/game/client/globals.cc4
-rw-r--r--src/game/client/globals.hh10
-rw-r--r--src/game/client/gui/CMakeLists.txt8
-rw-r--r--src/game/client/gui/background.cc14
-rw-r--r--src/game/client/gui/background.hh4
-rw-r--r--src/game/client/gui/bother.cc12
-rw-r--r--src/game/client/gui/bother.hh7
-rw-r--r--src/game/client/gui/chat.cc30
-rw-r--r--src/game/client/gui/chat.hh8
-rw-r--r--src/game/client/gui/crosshair.cc6
-rw-r--r--src/game/client/gui/crosshair.hh4
-rw-r--r--src/game/client/gui/direct_connection.cc20
-rw-r--r--src/game/client/gui/direct_connection.hh4
-rw-r--r--src/game/client/gui/hotbar.cc54
-rw-r--r--src/game/client/gui/hotbar.hh17
-rw-r--r--src/game/client/gui/imdraw_ext.cc34
-rw-r--r--src/game/client/gui/imdraw_ext.hh17
-rw-r--r--src/game/client/gui/imutils_button.cc95
-rw-r--r--src/game/client/gui/imutils_button.hh14
-rw-r--r--src/game/client/gui/imutils_popup.cc56
-rw-r--r--src/game/client/gui/imutils_popup.hh11
-rw-r--r--src/game/client/gui/imutils_text.cc46
-rw-r--r--src/game/client/gui/imutils_text.hh9
-rw-r--r--src/game/client/gui/language.cc38
-rw-r--r--src/game/client/gui/language.hh19
-rw-r--r--src/game/client/gui/main_menu.cc190
-rw-r--r--src/game/client/gui/main_menu.hh4
-rw-r--r--src/game/client/gui/message_box.cc20
-rw-r--r--src/game/client/gui/message_box.hh11
-rw-r--r--src/game/client/gui/metrics.cc28
-rw-r--r--src/game/client/gui/metrics.hh4
-rw-r--r--src/game/client/gui/play_menu.cc65
-rw-r--r--src/game/client/gui/play_menu.hh4
-rw-r--r--src/game/client/gui/progress_bar.cc16
-rw-r--r--src/game/client/gui/progress_bar.hh11
-rw-r--r--src/game/client/gui/scoreboard.cc4
-rw-r--r--src/game/client/gui/scoreboard.hh4
-rw-r--r--src/game/client/gui/settings.cc434
-rw-r--r--src/game/client/gui/splash.cc32
-rw-r--r--src/game/client/gui/splash.hh4
-rw-r--r--src/game/client/gui/status_lines.cc38
-rw-r--r--src/game/client/gui/status_lines.hh11
-rw-r--r--src/game/client/gui/window_title.cc2
-rw-r--r--src/game/client/gui/window_title.hh4
-rw-r--r--src/game/client/io/gamepad.cc70
-rw-r--r--src/game/client/io/gamepad.hh14
-rw-r--r--src/game/client/io/glfw.hh3
-rw-r--r--src/game/client/main.cc26
-rw-r--r--src/game/client/program.cc4
-rw-r--r--src/game/client/receive.cc34
-rw-r--r--src/game/client/resource/sound_effect.cc2
-rw-r--r--src/game/client/screenshot.cc6
-rw-r--r--src/game/client/session.cc60
-rw-r--r--src/game/client/sound/sound.cc2
-rw-r--r--src/game/client/toggles.cc10
-rw-r--r--src/game/client/world/chunk_mesher.cc125
-rw-r--r--src/game/client/world/chunk_mesher.hh7
-rw-r--r--src/game/client/world/chunk_quad.hh6
-rw-r--r--src/game/client/world/chunk_renderer.cc32
-rw-r--r--src/game/client/world/chunk_renderer.hh4
-rw-r--r--src/game/client/world/chunk_vbo.hh3
-rw-r--r--src/game/client/world/chunk_visibility.cc14
-rw-r--r--src/game/client/world/chunk_visibility.hh4
-rw-r--r--src/game/client/world/outline.cc18
-rw-r--r--src/game/client/world/outline.hh8
-rw-r--r--src/game/client/world/player_target.cc48
-rw-r--r--src/game/client/world/player_target.hh8
-rw-r--r--src/game/client/world/skybox.cc6
-rw-r--r--src/game/client/world/skybox.hh8
-rw-r--r--src/game/client/world/voxel_anims.cc19
-rw-r--r--src/game/client/world/voxel_anims.hh8
-rw-r--r--src/game/client/world/voxel_atlas.cc22
-rw-r--r--src/game/client/world/voxel_atlas.hh15
-rw-r--r--src/game/client/world/voxel_sounds.cc18
-rw-r--r--src/game/client/world/voxel_sounds.hh8
-rw-r--r--src/game/server/game.cc32
-rw-r--r--src/game/server/globals.cc6
-rw-r--r--src/game/server/globals.hh12
-rw-r--r--src/game/server/main.cc2
-rw-r--r--src/game/server/receive.cc22
-rw-r--r--src/game/server/sessions.cc34
-rw-r--r--src/game/server/sessions.hh9
-rw-r--r--src/game/server/whitelist.cc2
-rw-r--r--src/game/server/world/inhabited.hh3
-rw-r--r--src/game/server/world/overworld.cc25
-rw-r--r--src/game/server/world/overworld.hh12
-rw-r--r--src/game/server/world/random_tick.cc4
-rw-r--r--src/game/server/world/random_tick.hh7
-rw-r--r--src/game/server/world/universe.cc35
-rw-r--r--src/game/server/world/universe.hh11
-rw-r--r--src/game/server/world/unloader.cc22
-rw-r--r--src/game/server/world/unloader.hh7
-rw-r--r--src/game/server/world/worldgen.cc20
-rw-r--r--src/game/server/world/worldgen.hh11
-rw-r--r--src/game/shared/entity/collision.cc32
-rw-r--r--src/game/shared/entity/collision.hh12
-rw-r--r--src/game/shared/entity/factory.cc12
-rw-r--r--src/game/shared/entity/factory.hh9
-rw-r--r--src/game/shared/entity/gravity.cc4
-rw-r--r--src/game/shared/entity/gravity.hh8
-rw-r--r--src/game/shared/entity/grounded.hh5
-rw-r--r--src/game/shared/entity/head.hh7
-rw-r--r--src/game/shared/entity/player.hh3
-rw-r--r--src/game/shared/entity/stasis.cc8
-rw-r--r--src/game/shared/entity/stasis.hh8
-rw-r--r--src/game/shared/entity/transform.cc6
-rw-r--r--src/game/shared/entity/transform.hh14
-rw-r--r--src/game/shared/entity/velocity.cc4
-rw-r--r--src/game/shared/entity/velocity.hh10
-rw-r--r--src/game/shared/game.cc18
-rw-r--r--src/game/shared/game_items.cc54
-rw-r--r--src/game/shared/game_items.hh21
-rw-r--r--src/game/shared/game_voxels.cc112
-rw-r--r--src/game/shared/game_voxels.hh25
-rw-r--r--src/game/shared/protocol.cc26
-rw-r--r--src/game/shared/protocol.hh17
-rw-r--r--src/game/shared/splash.cc2
-rw-r--r--src/game/shared/world/chunk.cc22
-rw-r--r--src/game/shared/world/chunk.hh6
-rw-r--r--src/game/shared/world/chunk_aabb.hh3
-rw-r--r--src/game/shared/world/dimension.cc34
-rw-r--r--src/game/shared/world/dimension.hh20
-rw-r--r--src/game/shared/world/feature.cc6
-rw-r--r--src/game/shared/world/feature.hh6
-rw-r--r--src/game/shared/world/item.cc16
-rw-r--r--src/game/shared/world/item.hh19
-rw-r--r--src/game/shared/world/item_registry.cc16
-rw-r--r--src/game/shared/world/item_registry.hh16
-rw-r--r--src/game/shared/world/ray_dda.cc14
-rw-r--r--src/game/shared/world/ray_dda.hh6
-rw-r--r--src/game/shared/world/voxel.cc44
-rw-r--r--src/game/shared/world/voxel.hh57
-rw-r--r--src/game/shared/world/voxel_registry.cc16
-rw-r--r--src/game/shared/world/voxel_registry.hh16
-rw-r--r--src/game/shared/world/voxel_storage.cc4
-rw-r--r--src/game/shared/world/voxel_storage.hh10
166 files changed, 1864 insertions, 1970 deletions
diff --git a/src/core/io/buffer.cc b/src/core/io/buffer.cc
index 0f781a0..d0fda49 100644
--- a/src/core/io/buffer.cc
+++ b/src/core/io/buffer.cc
@@ -4,43 +4,43 @@
#include "core/math/constexpr.hh"
-io::ReadBuffer::ReadBuffer(const ReadBuffer& other)
+ReadBuffer::ReadBuffer(const ReadBuffer& other)
{
reset(other.data(), other.size());
}
-io::ReadBuffer::ReadBuffer(const void* data, std::size_t size)
+ReadBuffer::ReadBuffer(const void* data, std::size_t size)
{
assert(data);
reset(data, size);
}
-io::ReadBuffer::ReadBuffer(const ENetPacket* packet)
+ReadBuffer::ReadBuffer(const ENetPacket* packet)
{
assert(packet);
reset(packet);
}
-io::ReadBuffer::ReadBuffer(PHYSFS_File* file)
+ReadBuffer::ReadBuffer(PHYSFS_File* file)
{
assert(file);
reset(file);
}
-std::size_t io::ReadBuffer::size(void) const
+std::size_t ReadBuffer::size(void) const
{
return m_vector.size();
}
-const std::byte* io::ReadBuffer::data(void) const
+const std::byte* ReadBuffer::data(void) const
{
return m_vector.data();
}
-void io::ReadBuffer::reset(const void* data, std::size_t size)
+void ReadBuffer::reset(const void* data, std::size_t size)
{
assert(data);
@@ -49,7 +49,7 @@ void io::ReadBuffer::reset(const void* data, std::size_t size)
m_position = 0U;
}
-void io::ReadBuffer::reset(const ENetPacket* packet)
+void ReadBuffer::reset(const ENetPacket* packet)
{
assert(packet);
@@ -58,7 +58,7 @@ void io::ReadBuffer::reset(const ENetPacket* packet)
m_position = 0;
}
-void io::ReadBuffer::reset(PHYSFS_File* file)
+void ReadBuffer::reset(PHYSFS_File* file)
{
assert(file);
@@ -70,7 +70,7 @@ void io::ReadBuffer::reset(PHYSFS_File* file)
}
template<>
-std::byte io::ReadBuffer::read<std::byte>(void)
+std::byte ReadBuffer::read<std::byte>(void)
{
if(m_position < m_vector.size()) {
auto result = m_vector[m_position];
@@ -83,7 +83,7 @@ std::byte io::ReadBuffer::read<std::byte>(void)
}
template<>
-std::uint8_t io::ReadBuffer::read<std::uint8_t>(void)
+std::uint8_t ReadBuffer::read<std::uint8_t>(void)
{
if((m_position + 1U) <= m_vector.size()) {
auto result = static_cast<std::uint8_t>(m_vector[m_position]);
@@ -96,7 +96,7 @@ std::uint8_t io::ReadBuffer::read<std::uint8_t>(void)
}
template<>
-std::uint16_t io::ReadBuffer::read<std::uint16_t>(void)
+std::uint16_t ReadBuffer::read<std::uint16_t>(void)
{
if((m_position + 2U) <= m_vector.size()) {
auto result = UINT16_C(0x0000);
@@ -111,7 +111,7 @@ std::uint16_t io::ReadBuffer::read<std::uint16_t>(void)
}
template<>
-std::uint32_t io::ReadBuffer::read<std::uint32_t>(void)
+std::uint32_t ReadBuffer::read<std::uint32_t>(void)
{
if((m_position + 4U) <= m_vector.size()) {
auto result = UINT32_C(0x00000000);
@@ -128,7 +128,7 @@ std::uint32_t io::ReadBuffer::read<std::uint32_t>(void)
}
template<>
-std::uint64_t io::ReadBuffer::read<std::uint64_t>(void)
+std::uint64_t ReadBuffer::read<std::uint64_t>(void)
{
if((m_position + 8U) <= m_vector.size()) {
auto result = UINT64_C(0x0000000000000000);
@@ -149,37 +149,37 @@ std::uint64_t io::ReadBuffer::read<std::uint64_t>(void)
}
template<>
-float io::ReadBuffer::read<float>(void)
+float ReadBuffer::read<float>(void)
{
return std::bit_cast<float>(read<std::uint32_t>());
}
template<>
-std::int8_t io::ReadBuffer::read<std::int8_t>(void)
+std::int8_t ReadBuffer::read<std::int8_t>(void)
{
return std::bit_cast<std::int8_t>(read<std::uint8_t>());
}
template<>
-std::int16_t io::ReadBuffer::read<std::int16_t>(void)
+std::int16_t ReadBuffer::read<std::int16_t>(void)
{
return std::bit_cast<std::int16_t>(read<std::uint16_t>());
}
template<>
-std::int32_t io::ReadBuffer::read<std::int32_t>(void)
+std::int32_t ReadBuffer::read<std::int32_t>(void)
{
return std::bit_cast<std::int32_t>(read<std::uint32_t>());
}
template<>
-std::int64_t io::ReadBuffer::read<std::int64_t>(void)
+std::int64_t ReadBuffer::read<std::int64_t>(void)
{
return std::bit_cast<std::int64_t>(read<std::uint64_t>());
}
template<>
-std::string io::ReadBuffer::read<std::string>(void)
+std::string ReadBuffer::read<std::string>(void)
{
std::string result;
result.resize(read<std::uint16_t>());
@@ -195,7 +195,7 @@ std::string io::ReadBuffer::read<std::string>(void)
return result;
}
-void io::ReadBuffer::read(void* buffer, std::size_t size)
+void ReadBuffer::read(void* buffer, std::size_t size)
{
auto bytes = reinterpret_cast<std::byte*>(buffer);
auto amount_to_read = std::min(size, m_vector.size() - m_position);
@@ -207,32 +207,32 @@ void io::ReadBuffer::read(void* buffer, std::size_t size)
m_position += size;
}
-io::WriteBuffer::WriteBuffer(const WriteBuffer& other)
+WriteBuffer::WriteBuffer(const WriteBuffer& other)
{
m_vector = other.m_vector;
}
-std::size_t io::WriteBuffer::size(void) const
+std::size_t WriteBuffer::size(void) const
{
return m_vector.size();
}
-const std::byte* io::WriteBuffer::data(void) const
+const std::byte* WriteBuffer::data(void) const
{
return m_vector.data();
}
-void io::WriteBuffer::reset(void)
+void WriteBuffer::reset(void)
{
m_vector.clear();
}
-void io::WriteBuffer::write(const WriteBuffer& other)
+void WriteBuffer::write(const WriteBuffer& other)
{
m_vector.insert(m_vector.end(), other.m_vector.begin(), other.m_vector.end());
}
-void io::WriteBuffer::write(const void* data, std::size_t size)
+void WriteBuffer::write(const void* data, std::size_t size)
{
assert(data);
@@ -241,26 +241,26 @@ void io::WriteBuffer::write(const void* data, std::size_t size)
}
template<>
-void io::WriteBuffer::write<std::byte>(const std::byte value)
+void WriteBuffer::write<std::byte>(const std::byte value)
{
m_vector.push_back(value);
}
template<>
-void io::WriteBuffer::write<std::uint8_t>(const std::uint8_t value)
+void WriteBuffer::write<std::uint8_t>(const std::uint8_t value)
{
m_vector.push_back(static_cast<std::byte>(value));
}
template<>
-void io::WriteBuffer::write<std::uint16_t>(const std::uint16_t value)
+void WriteBuffer::write<std::uint16_t>(const std::uint16_t value)
{
m_vector.push_back(static_cast<std::byte>(UINT16_C(0xFF) & ((value & UINT16_C(0xFF00)) >> 8U)));
m_vector.push_back(static_cast<std::byte>(UINT16_C(0xFF) & ((value & UINT16_C(0x00FF)) >> 0U)));
}
template<>
-void io::WriteBuffer::write<std::uint32_t>(const std::uint32_t value)
+void WriteBuffer::write<std::uint32_t>(const std::uint32_t value)
{
m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0xFF000000)) >> 24U)));
m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0x00FF0000)) >> 16U)));
@@ -269,7 +269,7 @@ void io::WriteBuffer::write<std::uint32_t>(const std::uint32_t value)
}
template<>
-void io::WriteBuffer::write<std::uint64_t>(const std::uint64_t value)
+void WriteBuffer::write<std::uint64_t>(const std::uint64_t value)
{
m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0xFF00000000000000)) >> 56U)));
m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x00FF000000000000)) >> 48U)));
@@ -282,37 +282,37 @@ void io::WriteBuffer::write<std::uint64_t>(const std::uint64_t value)
}
template<>
-void io::WriteBuffer::write(const float value)
+void WriteBuffer::write(const float value)
{
write(std::bit_cast<std::uint32_t>(value));
}
template<>
-void io::WriteBuffer::write(const std::int8_t value)
+void WriteBuffer::write(const std::int8_t value)
{
write(std::bit_cast<std::uint8_t>(value));
}
template<>
-void io::WriteBuffer::write(const std::int16_t value)
+void WriteBuffer::write(const std::int16_t value)
{
write(std::bit_cast<std::uint16_t>(value));
}
template<>
-void io::WriteBuffer::write(const std::int32_t value)
+void WriteBuffer::write(const std::int32_t value)
{
write(std::bit_cast<std::uint32_t>(value));
}
template<>
-void io::WriteBuffer::write(const std::int64_t value)
+void WriteBuffer::write(const std::int64_t value)
{
write(std::bit_cast<std::uint64_t>(value));
}
template<>
-void io::WriteBuffer::write<std::string_view>(const std::string_view value)
+void WriteBuffer::write<std::string_view>(const std::string_view value)
{
write<std::uint16_t>(static_cast<std::uint16_t>(value.size()));
@@ -321,7 +321,7 @@ void io::WriteBuffer::write<std::string_view>(const std::string_view value)
}
}
-PHYSFS_File* io::WriteBuffer::to_file(const std::string& path, bool append) const
+PHYSFS_File* WriteBuffer::to_file(const std::string& path, bool append) const
{
PHYSFS_File* file = nullptr;
@@ -339,7 +339,7 @@ PHYSFS_File* io::WriteBuffer::to_file(const std::string& path, bool append) cons
return file;
}
-ENetPacket* io::WriteBuffer::to_packet(enet_uint32 flags) const
+ENetPacket* WriteBuffer::to_packet(enet_uint32 flags) const
{
return enet_packet_create(m_vector.data(), m_vector.size(), flags);
}
diff --git a/src/core/io/buffer.hh b/src/core/io/buffer.hh
index 96a37b1..450a86f 100644
--- a/src/core/io/buffer.hh
+++ b/src/core/io/buffer.hh
@@ -1,5 +1,3 @@
-namespace io
-{
class ReadBuffer final {
public:
ReadBuffer(void) = default;
@@ -31,10 +29,7 @@ private:
std::vector<std::byte> m_vector;
std::size_t m_position;
};
-} // namespace io
-namespace io
-{
class WriteBuffer final {
public:
WriteBuffer(void) = default;
@@ -61,27 +56,26 @@ public:
private:
std::vector<std::byte> m_vector;
};
-} // namespace io
-constexpr void io::ReadBuffer::rewind(void)
+constexpr void ReadBuffer::rewind(void)
{
m_position = 0;
}
-constexpr bool io::ReadBuffer::is_ended(void) const
+constexpr bool ReadBuffer::is_ended(void) const
{
return m_position >= m_vector.size();
}
template<typename T>
-io::ReadBuffer& io::ReadBuffer::operator>>(T& value)
+ReadBuffer& ReadBuffer::operator>>(T& value)
{
value = read<T>();
return *this;
}
template<typename T>
-io::WriteBuffer& io::WriteBuffer::operator<<(const T value)
+WriteBuffer& WriteBuffer::operator<<(const T value)
{
write<T>(value);
return *this;
diff --git a/src/core/io/cmdline.cc b/src/core/io/cmdline.cc
index 7a00f37..d206cb8 100644
--- a/src/core/io/cmdline.cc
+++ b/src/core/io/cmdline.cc
@@ -27,7 +27,7 @@ static inline std::string get_option(const std::string& string)
return std::string(string.cbegin() + i, string.cend());
}
-void io::cmdline::create(int argc, char** argv)
+void cmdline::create(int argc, char** argv)
{
for(int idx = 1; idx < argc; ++idx) {
std::string string = argv[idx];
@@ -57,17 +57,17 @@ void io::cmdline::create(int argc, char** argv)
}
}
-void io::cmdline::insert(std::string_view option)
+void cmdline::insert(std::string_view option)
{
options.insert_or_assign(std::string(option), std::string());
}
-void io::cmdline::insert(std::string_view option, std::string_view argument)
+void cmdline::insert(std::string_view option, std::string_view argument)
{
options.insert_or_assign(std::string(option), std::string(argument));
}
-std::string_view io::cmdline::get(std::string_view option, std::string_view fallback)
+std::string_view cmdline::get(std::string_view option, std::string_view fallback)
{
auto it = options.find(std::string(option));
@@ -78,7 +78,7 @@ std::string_view io::cmdline::get(std::string_view option, std::string_view fall
return it->second;
}
-const char* io::cmdline::get_cstr(std::string_view option, const char* fallback)
+const char* cmdline::get_cstr(std::string_view option, const char* fallback)
{
auto it = options.find(std::string(option));
@@ -89,7 +89,7 @@ const char* io::cmdline::get_cstr(std::string_view option, const char* fallback)
return it->second.c_str();
}
-bool io::cmdline::contains(std::string_view option)
+bool cmdline::contains(std::string_view option)
{
return options.count(std::string(option));
}
diff --git a/src/core/io/cmdline.hh b/src/core/io/cmdline.hh
index e90433c..c0d6db2 100644
--- a/src/core/io/cmdline.hh
+++ b/src/core/io/cmdline.hh
@@ -1,6 +1,6 @@
#pragma once
-namespace io::cmdline
+namespace cmdline
{
void create(int argc, char** argv);
void insert(std::string_view option);
@@ -8,4 +8,4 @@ void insert(std::string_view option, std::string_view argument);
std::string_view get(std::string_view option, std::string_view fallback = "");
const char* get_cstr(std::string_view option, const char* fallback = nullptr);
bool contains(std::string_view option);
-} // namespace io::cmdline
+} // namespace cmdline
diff --git a/src/core/io/config_map.cc b/src/core/io/config_map.cc
index 57692a7..8634fd6 100644
--- a/src/core/io/config_map.cc
+++ b/src/core/io/config_map.cc
@@ -10,16 +10,16 @@
#include "core/version.hh"
-void io::ConfigMap::load_cmdline(void)
+void ConfigMap::load_cmdline(void)
{
for(auto it : m_values) {
- if(auto value = io::cmdline::get_cstr(it.first.c_str())) {
+ if(auto value = cmdline::get_cstr(it.first.c_str())) {
it.second->set(value);
}
}
}
-bool io::ConfigMap::load_file(std::string_view path)
+bool ConfigMap::load_file(std::string_view path)
{
if(auto file = PHYSFS_openRead(std::string(path).c_str())) {
auto source = std::string(PHYSFS_fileLength(file), char(0x00));
@@ -71,7 +71,7 @@ bool io::ConfigMap::load_file(std::string_view path)
return false;
}
-bool io::ConfigMap::save_file(std::string_view path) const
+bool ConfigMap::save_file(std::string_view path) const
{
std::ostringstream stream;
@@ -96,7 +96,7 @@ bool io::ConfigMap::save_file(std::string_view path) const
return false;
}
-bool io::ConfigMap::set_value(std::string_view name, std::string_view value)
+bool ConfigMap::set_value(std::string_view name, std::string_view value)
{
auto kv_pair = m_values.find(std::string(name));
@@ -108,7 +108,7 @@ bool io::ConfigMap::set_value(std::string_view name, std::string_view value)
return false;
}
-std::string_view io::ConfigMap::get_value(std::string_view name) const
+std::string_view ConfigMap::get_value(std::string_view name) const
{
auto kv_pair = m_values.find(std::string(name));
if(kv_pair != m_values.cend()) {
@@ -118,12 +118,12 @@ std::string_view io::ConfigMap::get_value(std::string_view name) const
return std::string_view();
}
-void io::ConfigMap::add_value(std::string_view name, config::IValue& vref)
+void ConfigMap::add_value(std::string_view name, config::IValue& vref)
{
m_values.insert_or_assign(std::string(name), &vref);
}
-const config::IValue* io::ConfigMap::find(std::string_view name) const
+const config::IValue* ConfigMap::find(std::string_view name) const
{
auto kv_pair = m_values.find(std::string(name));
diff --git a/src/core/io/config_map.hh b/src/core/io/config_map.hh
index b0cd579..898103b 100644
--- a/src/core/io/config_map.hh
+++ b/src/core/io/config_map.hh
@@ -5,8 +5,6 @@ namespace config
class IValue;
} // namespace config
-namespace io
-{
class ConfigMap final {
public:
ConfigMap(void) = default;
@@ -26,4 +24,3 @@ public:
private:
std::unordered_map<std::string, config::IValue*> m_values;
};
-} // namespace io
diff --git a/src/core/io/physfs.cc b/src/core/io/physfs.cc
index 1c36f88..b9fe91e 100644
--- a/src/core/io/physfs.cc
+++ b/src/core/io/physfs.cc
@@ -2,7 +2,7 @@
#include "core/io/physfs.hh"
-bool io::read_file(std::string_view path, std::vector<std::byte>& buffer)
+bool read_file(std::string_view path, std::vector<std::byte>& buffer)
{
auto file = PHYSFS_openRead(std::string(path).c_str());
@@ -20,7 +20,7 @@ bool io::read_file(std::string_view path, std::vector<std::byte>& buffer)
return true;
}
-bool io::read_file(std::string_view path, std::string& buffer)
+bool read_file(std::string_view path, std::string& buffer)
{
auto file = PHYSFS_openRead(std::string(path).c_str());
@@ -38,7 +38,7 @@ bool io::read_file(std::string_view path, std::string& buffer)
return true;
}
-bool io::write_file(std::string_view path, const std::vector<std::byte>& buffer)
+bool write_file(std::string_view path, const std::vector<std::byte>& buffer)
{
auto file = PHYSFS_openWrite(std::string(path).c_str());
@@ -53,7 +53,7 @@ bool io::write_file(std::string_view path, const std::vector<std::byte>& buffer)
return true;
}
-bool io::write_file(std::string_view path, const std::string& buffer)
+bool write_file(std::string_view path, const std::string& buffer)
{
auto file = PHYSFS_openWrite(std::string(path).c_str());
@@ -68,7 +68,7 @@ bool io::write_file(std::string_view path, const std::string& buffer)
return true;
}
-std::string_view io::physfs_error(void)
+std::string_view physfs_error(void)
{
auto error_code = PHYSFS_getLastErrorCode();
auto error_string = PHYSFS_getErrorByCode(error_code);
diff --git a/src/core/io/physfs.hh b/src/core/io/physfs.hh
index 01282ad..88f97de 100644
--- a/src/core/io/physfs.hh
+++ b/src/core/io/physfs.hh
@@ -1,14 +1,8 @@
#pragma once
-namespace io
-{
bool read_file(std::string_view path, std::vector<std::byte>& buffer);
bool read_file(std::string_view path, std::string& buffer);
bool write_file(std::string_view path, const std::vector<std::byte>& buffer);
bool write_file(std::string_view path, const std::string& buffer);
-} // namespace io
-namespace io
-{
std::string_view physfs_error(void);
-} // namespace io
diff --git a/src/core/resource/image.cc b/src/core/resource/image.cc
index 8ab98db..6a2109e 100644
--- a/src/core/resource/image.cc
+++ b/src/core/resource/image.cc
@@ -36,7 +36,7 @@ static const void* image_load_func(const char* name, std::uint32_t flags)
auto file = PHYSFS_openRead(name);
if(file == nullptr) {
- spdlog::error("image: {}: {}", name, io::physfs_error());
+ spdlog::error("image: {}: {}", name, physfs_error());
return nullptr;
}
diff --git a/src/core/threading.cc b/src/core/threading.cc
index 03c0e8e..a1ae305 100644
--- a/src/core/threading.cc
+++ b/src/core/threading.cc
@@ -35,7 +35,7 @@ void Task::set_status(task_status status)
void threading::init(void)
{
- auto argument = io::cmdline::get("threads", DEFAULT_POOL_SIZE_ARG);
+ auto argument = cmdline::get("threads", DEFAULT_POOL_SIZE_ARG);
auto num_concurrent_threads = std::thread::hardware_concurrency();
unsigned int thread_pool_size;
diff --git a/src/core/version.cc b/src/core/version.cc
index f508aa0..b03fc2a 100644
--- a/src/core/version.cc
+++ b/src/core/version.cc
@@ -8,8 +8,8 @@ const unsigned short version::minor = 0;
const unsigned short version::patch = 1;
// clang-format on
-const std::string_view version::commit = "d304b608";
-const std::string_view version::branch = "master";
+const std::string_view version::commit = "e5f6887e";
+const std::string_view version::branch = "restor";
const std::string_view version::triplet = "16.0.1";
-const std::string_view version::full = "16.0.1-d304b608";
+const std::string_view version::full = "16.0.1-e5f6887e";
diff --git a/src/game/client/config/gamepad_axis.cc b/src/game/client/config/gamepad_axis.cc
index c6f9e3d..4eb36a9 100644
--- a/src/game/client/config/gamepad_axis.cc
+++ b/src/game/client/config/gamepad_axis.cc
@@ -30,7 +30,7 @@ static std::string_view get_axis_name(int axis)
return UNKNOWN_AXIS_NAME;
}
-config::GamepadAxis::GamepadAxis(void) : GamepadAxis(io::INVALID_GAMEPAD_AXIS, false)
+config::GamepadAxis::GamepadAxis(void) : GamepadAxis(INVALID_GAMEPAD_AXIS, false)
{
}
@@ -66,7 +66,7 @@ void config::GamepadAxis::set(std::string_view value)
}
m_inverted = false;
- m_gamepad_axis = io::INVALID_GAMEPAD_AXIS;
+ m_gamepad_axis = INVALID_GAMEPAD_AXIS;
m_name = UNKNOWN_AXIS_NAME;
m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
}
diff --git a/src/game/client/config/gamepad_button.cc b/src/game/client/config/gamepad_button.cc
index 07e4457..d3f8a25 100644
--- a/src/game/client/config/gamepad_button.cc
+++ b/src/game/client/config/gamepad_button.cc
@@ -39,7 +39,7 @@ static std::string_view get_button_name(int button)
config::GamepadButton::GamepadButton(void)
{
- m_gamepad_button = io::INVALID_GAMEPAD_BUTTON;
+ m_gamepad_button = INVALID_GAMEPAD_BUTTON;
m_name = UNKNOWN_BUTTON_NAME;
}
@@ -64,7 +64,7 @@ void config::GamepadButton::set(std::string_view value)
}
}
- m_gamepad_button = io::INVALID_GAMEPAD_BUTTON;
+ m_gamepad_button = INVALID_GAMEPAD_BUTTON;
m_name = UNKNOWN_BUTTON_NAME;
}
diff --git a/src/game/client/const.hh b/src/game/client/const.hh
index 461b500..709c0a1 100644
--- a/src/game/client/const.hh
+++ b/src/game/client/const.hh
@@ -7,11 +7,11 @@
// use this key for conventional gameplay things
constexpr static int DEBUG_KEY = GLFW_KEY_F3;
-constexpr static int BASE_WIDTH = 320;
-constexpr static int BASE_HEIGHT = 240;
+constexpr static int BASE_WIDTH = 640;
+constexpr static int BASE_HEIGHT = 480;
-constexpr static int MIN_WIDTH = 2 * BASE_WIDTH;
-constexpr static int MIN_HEIGHT = 2 * BASE_HEIGHT;
+constexpr static int MIN_WIDTH = BASE_WIDTH;
+constexpr static int MIN_HEIGHT = BASE_HEIGHT;
constexpr static int DEFAULT_WIDTH = 720;
constexpr static int DEFAULT_HEIGHT = 480;
diff --git a/src/game/client/entity/camera.cc b/src/game/client/entity/camera.cc
index 3badd9d..2009066 100644
--- a/src/game/client/entity/camera.cc
+++ b/src/game/client/entity/camera.cc
@@ -23,23 +23,23 @@
#include "client/session.hh"
#include "client/toggles.hh"
-config::Float entity::camera::roll_angle(2.0f, 0.0f, 4.0f);
-config::Float entity::camera::vertical_fov(90.0f, 45.0f, 110.0f);
-config::Unsigned entity::camera::view_distance(16U, 4U, 32U);
+config::Float camera::roll_angle(2.0f, 0.0f, 4.0f);
+config::Float camera::vertical_fov(90.0f, 45.0f, 110.0f);
+config::Unsigned camera::view_distance(16U, 4U, 32U);
-glm::fvec3 entity::camera::angles;
-glm::fvec3 entity::camera::direction;
-glm::fmat4x4 entity::camera::matrix;
-chunk_pos entity::camera::position_chunk;
-glm::fvec3 entity::camera::position_local;
+glm::fvec3 camera::angles;
+glm::fvec3 camera::direction;
+glm::fmat4x4 camera::matrix;
+chunk_pos camera::position_chunk;
+glm::fvec3 camera::position_local;
static void reset_camera(void)
{
- entity::camera::angles = glm::fvec3(0.0f, 0.0f, 0.0f);
- entity::camera::direction = DIR_FORWARD<float>;
- entity::camera::matrix = glm::identity<glm::fmat4x4>();
- entity::camera::position_chunk = chunk_pos(0, 0, 0);
- entity::camera::position_local = glm::fvec3(0.0f, 0.0f, 0.0f);
+ camera::angles = glm::fvec3(0.0f, 0.0f, 0.0f);
+ camera::direction = DIR_FORWARD<float>;
+ camera::matrix = glm::identity<glm::fmat4x4>();
+ camera::position_chunk = chunk_pos(0, 0, 0);
+ camera::position_local = glm::fvec3(0.0f, 0.0f, 0.0f);
}
// Gracefully contributed by PQCraft himself in 2024
@@ -65,50 +65,49 @@ static glm::fmat4x4 platinumsrc_viewmatrix(const glm::fvec3& position, const glm
return result;
}
-void entity::camera::init(void)
+void camera::init(void)
{
- globals::client_config.add_value("camera.roll_angle", entity::camera::roll_angle);
- globals::client_config.add_value("camera.vertical_fov", entity::camera::vertical_fov);
- globals::client_config.add_value("camera.view_distance", entity::camera::view_distance);
+ globals::client_config.add_value("camera.roll_angle", camera::roll_angle);
+ globals::client_config.add_value("camera.vertical_fov", camera::vertical_fov);
+ globals::client_config.add_value("camera.view_distance", camera::view_distance);
- settings::add_slider(1, entity::camera::vertical_fov, settings_location::GENERAL, "camera.vertical_fov", true, "%.0f");
- settings::add_slider(0, entity::camera::view_distance, settings_location::VIDEO, "camera.view_distance", false);
- settings::add_slider(10, entity::camera::roll_angle, settings_location::VIDEO, "camera.roll_angle", true, "%.01f");
+ settings::add_slider(1, camera::vertical_fov, settings_location::GENERAL, "camera.vertical_fov", true, "%.0f");
+ settings::add_slider(0, camera::view_distance, settings_location::VIDEO, "camera.view_distance", false);
+ settings::add_slider(10, camera::roll_angle, settings_location::VIDEO, "camera.roll_angle", true, "%.01f");
reset_camera();
}
-void entity::camera::update(void)
+void camera::update(void)
{
if(!session::is_ingame()) {
reset_camera();
return;
}
- const auto& head = globals::dimension->entities.get<entity::client::HeadIntr>(globals::player);
- const auto& transform = globals::dimension->entities.get<entity::client::TransformIntr>(globals::player);
- const auto& velocity = globals::dimension->entities.get<entity::Velocity>(globals::player);
+ const auto& head = globals::dimension->entities.get<client::HeadIntr>(globals::player);
+ const auto& transform = globals::dimension->entities.get<client::TransformIntr>(globals::player);
+ const auto& velocity = globals::dimension->entities.get<Velocity>(globals::player);
- entity::camera::angles = transform.angles + head.angles;
- entity::camera::position_chunk = transform.chunk;
- entity::camera::position_local = transform.local + head.offset;
+ camera::angles = transform.angles + head.angles;
+ camera::position_chunk = transform.chunk;
+ camera::position_local = transform.local + head.offset;
glm::fvec3 right_vector, up_vector;
- math::vectors(entity::camera::angles, &entity::camera::direction, &right_vector, &up_vector);
+ math::vectors(camera::angles, &camera::direction, &right_vector, &up_vector);
- auto client_angles = entity::camera::angles;
+ auto client_angles = camera::angles;
if(!toggles::get(TOGGLE_PM_FLIGHT)) {
// Apply the quake-like view rolling
- client_angles[2] = math::radians(-entity::camera::roll_angle.get_value()
- * glm::dot(velocity.value / PMOVE_MAX_SPEED_GROUND, right_vector));
+ client_angles[2] = math::radians(-camera::roll_angle.get_value() * glm::dot(velocity.value / PMOVE_MAX_SPEED_GROUND, right_vector));
}
const auto z_near = 0.01f;
- const auto z_far = 1.25f * static_cast<float>(CHUNK_SIZE * entity::camera::view_distance.get_value());
+ const auto z_far = 1.25f * static_cast<float>(CHUNK_SIZE * camera::view_distance.get_value());
- auto proj = glm::perspective(math::radians(entity::camera::vertical_fov.get_value()), globals::aspect, z_near, z_far);
- auto view = platinumsrc_viewmatrix(entity::camera::position_local, client_angles);
+ auto proj = glm::perspective(math::radians(camera::vertical_fov.get_value()), globals::aspect, z_near, z_far);
+ auto view = platinumsrc_viewmatrix(camera::position_local, client_angles);
- entity::camera::matrix = proj * view;
+ camera::matrix = proj * view;
}
diff --git a/src/game/client/entity/camera.hh b/src/game/client/entity/camera.hh
index 67baf72..526bc91 100644
--- a/src/game/client/entity/camera.hh
+++ b/src/game/client/entity/camera.hh
@@ -8,24 +8,24 @@ class Float;
class Unsigned;
} // namespace config
-namespace entity::camera
+namespace camera
{
extern config::Float roll_angle;
extern config::Float vertical_fov;
extern config::Unsigned view_distance;
-} // namespace entity::camera
+} // namespace camera
-namespace entity::camera
+namespace camera
{
extern glm::fvec3 angles;
extern glm::fvec3 direction;
extern glm::fmat4x4 matrix;
extern chunk_pos position_chunk;
extern glm::fvec3 position_local;
-} // namespace entity::camera
+} // namespace camera
-namespace entity::camera
+namespace camera
{
void init(void);
void update(void);
-} // namespace entity::camera
+} // namespace camera
diff --git a/src/game/client/entity/factory.cc b/src/game/client/entity/factory.cc
index f6f6079..f4724c5 100644
--- a/src/game/client/entity/factory.cc
+++ b/src/game/client/entity/factory.cc
@@ -12,19 +12,19 @@
#include "client/globals.hh"
-void entity::client::create_player(world::Dimension* dimension, entt::entity entity)
+void client::create_player(Dimension* dimension, entt::entity entity)
{
- entity::shared::create_player(dimension, entity);
+ shared::create_player(dimension, entity);
- const auto& head = dimension->entities.get<entity::Head>(entity);
- dimension->entities.emplace_or_replace<entity::client::HeadIntr>(entity, head);
- dimension->entities.emplace_or_replace<entity::client::HeadPrev>(entity, head);
+ const auto& head = dimension->entities.get<Head>(entity);
+ dimension->entities.emplace_or_replace<client::HeadIntr>(entity, head);
+ dimension->entities.emplace_or_replace<client::HeadPrev>(entity, head);
- const auto& transform = dimension->entities.get<entity::Transform>(entity);
- dimension->entities.emplace_or_replace<entity::client::TransformIntr>(entity, transform);
- dimension->entities.emplace_or_replace<entity::client::TransformPrev>(entity, transform);
+ const auto& transform = dimension->entities.get<Transform>(entity);
+ dimension->entities.emplace_or_replace<client::TransformIntr>(entity, transform);
+ dimension->entities.emplace_or_replace<client::TransformPrev>(entity, transform);
if(globals::sound_ctx) {
- dimension->entities.emplace_or_replace<entity::SoundEmitter>(entity);
+ dimension->entities.emplace_or_replace<SoundEmitter>(entity);
}
}
diff --git a/src/game/client/entity/factory.hh b/src/game/client/entity/factory.hh
index 63e6e44..776a0b8 100644
--- a/src/game/client/entity/factory.hh
+++ b/src/game/client/entity/factory.hh
@@ -1,11 +1,8 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity::client
+namespace client
{
-void create_player(world::Dimension* dimension, entt::entity entity);
-} // namespace entity::client
+void create_player(Dimension* dimension, entt::entity entity);
+} // namespace client
diff --git a/src/game/client/entity/interpolation.cc b/src/game/client/entity/interpolation.cc
index a9a3349..69fd487 100644
--- a/src/game/client/entity/interpolation.cc
+++ b/src/game/client/entity/interpolation.cc
@@ -15,8 +15,7 @@
static void transform_interpolate(float alpha)
{
- auto group = globals::dimension->entities.group<entity::client::TransformIntr>(
- entt::get<entity::Transform, entity::client::TransformPrev>);
+ auto group = globals::dimension->entities.group<client::TransformIntr>(entt::get<Transform, client::TransformPrev>);
for(auto [entity, interp, current, previous] : group.each()) {
interp.angles[0] = glm::mix(previous.angles[0], current.angles[0], alpha);
@@ -41,7 +40,7 @@ static void transform_interpolate(float alpha)
static void head_interpolate(float alpha)
{
- auto group = globals::dimension->entities.group<entity::client::HeadIntr>(entt::get<entity::Head, entity::client::HeadPrev>);
+ auto group = globals::dimension->entities.group<client::HeadIntr>(entt::get<Head, client::HeadPrev>);
for(auto [entity, interp, current, previous] : group.each()) {
interp.angles[0] = glm::mix(previous.angles[0], current.angles[0], alpha);
@@ -54,7 +53,7 @@ static void head_interpolate(float alpha)
}
}
-void entity::interpolation::update(void)
+void interpolation::update(void)
{
if(globals::dimension) {
auto alpha = static_cast<float>(globals::fixed_accumulator) / static_cast<float>(globals::fixed_frametime_us);
diff --git a/src/game/client/entity/interpolation.hh b/src/game/client/entity/interpolation.hh
index 6935fe8..8fb0db1 100644
--- a/src/game/client/entity/interpolation.hh
+++ b/src/game/client/entity/interpolation.hh
@@ -1,6 +1,6 @@
#pragma once
-namespace entity::interpolation
+namespace interpolation
{
void update(void);
-} // namespace entity::interpolation
+} // namespace interpolation
diff --git a/src/game/client/entity/listener.cc b/src/game/client/entity/listener.cc
index a79e8a5..991f014 100644
--- a/src/game/client/entity/listener.cc
+++ b/src/game/client/entity/listener.cc
@@ -18,19 +18,19 @@
#include "client/globals.hh"
#include "client/session.hh"
-void entity::listener::update(void)
+void listener::update(void)
{
if(session::is_ingame()) {
- const auto& velocity = globals::dimension->entities.get<entity::Velocity>(globals::player).value;
- const auto& position = entity::camera::position_local;
+ const auto& velocity = globals::dimension->entities.get<Velocity>(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);
float orientation[6];
- orientation[0] = entity::camera::direction.x;
- orientation[1] = entity::camera::direction.y;
- orientation[2] = entity::camera::direction.z;
+ orientation[0] = camera::direction.x;
+ orientation[1] = camera::direction.y;
+ orientation[2] = camera::direction.z;
orientation[3] = DIR_UP<float>.x;
orientation[4] = DIR_UP<float>.y;
orientation[5] = DIR_UP<float>.z;
diff --git a/src/game/client/entity/listener.hh b/src/game/client/entity/listener.hh
index 594cde1..07d750f 100644
--- a/src/game/client/entity/listener.hh
+++ b/src/game/client/entity/listener.hh
@@ -1,6 +1,6 @@
#pragma once
-namespace entity::listener
+namespace listener
{
void update(void);
-} // namespace entity::listener
+} // namespace listener
diff --git a/src/game/client/entity/player_look.cc b/src/game/client/entity/player_look.cc
index 0752e78..ad0f40e 100644
--- a/src/game/client/entity/player_look.cc
+++ b/src/game/client/entity/player_look.cc
@@ -51,7 +51,7 @@ static glm::fvec2 last_cursor;
static void add_angles(float pitch, float yaw)
{
if(session::is_ingame()) {
- auto& head = globals::dimension->entities.get<entity::Head>(globals::player);
+ auto& head = globals::dimension->entities.get<Head>(globals::player);
head.angles[0] += pitch;
head.angles[1] += yaw;
@@ -62,13 +62,13 @@ static void add_angles(float pitch, float yaw)
// Re-assigning the previous state after the current
// state has been already modified is certainly a way
// to circumvent the interpolation applied to anything with a head
- globals::dimension->entities.emplace_or_replace<entity::client::HeadPrev>(globals::player, head);
+ globals::dimension->entities.emplace_or_replace<client::HeadPrev>(globals::player, head);
}
}
-static void on_glfw_cursor_pos(const io::GlfwCursorPosEvent& event)
+static void on_glfw_cursor_pos(const GlfwCursorPosEvent& event)
{
- if(io::gamepad::available && io::gamepad::active.get_value()) {
+ if(gamepad::available && gamepad::active.get_value()) {
// The player is assumed to be using
// a gamepad instead of mouse and keyboard
last_cursor = event.pos;
@@ -88,14 +88,14 @@ static void on_glfw_cursor_pos(const io::GlfwCursorPosEvent& event)
last_cursor = event.pos;
}
-static void on_gamepad_button(const io::GamepadButtonEvent& event)
+static void on_gamepad_button(const GamepadButtonEvent& event)
{
if(button_fastlook.equals(event.button)) {
fastlook_enabled = event.action == GLFW_PRESS;
}
}
-void entity::player_look::init(void)
+void player_look::init(void)
{
globals::client_config.add_value("player_look.mouse.raw_input", mouse_raw_input);
globals::client_config.add_value("player_look.mouse.sensitivity", mouse_sensitivity);
@@ -121,15 +121,15 @@ void entity::player_look::init(void)
last_cursor.x = 0.5f * static_cast<float>(globals::width);
last_cursor.y = 0.5f * static_cast<float>(globals::height);
- globals::dispatcher.sink<io::GlfwCursorPosEvent>().connect<&on_glfw_cursor_pos>();
- globals::dispatcher.sink<io::GamepadButtonEvent>().connect<&on_gamepad_button>();
+ globals::dispatcher.sink<GlfwCursorPosEvent>().connect<&on_glfw_cursor_pos>();
+ globals::dispatcher.sink<GamepadButtonEvent>().connect<&on_gamepad_button>();
}
-void entity::player_look::update_late(void)
+void player_look::update_late(void)
{
- if(io::gamepad::available && io::gamepad::active.get_value() && !globals::gui_screen) {
- auto pitch_value = axis_pitch.get_value(io::gamepad::state, io::gamepad::deadzone.get_value());
- auto yaw_value = axis_yaw.get_value(io::gamepad::state, io::gamepad::deadzone.get_value());
+ if(gamepad::available && gamepad::active.get_value() && !globals::gui_screen) {
+ auto pitch_value = axis_pitch.get_value(gamepad::state, gamepad::deadzone.get_value());
+ auto yaw_value = axis_yaw.get_value(gamepad::state, gamepad::deadzone.get_value());
if(fastlook_enabled) {
// Fastlook allows the camera to
diff --git a/src/game/client/entity/player_look.hh b/src/game/client/entity/player_look.hh
index 0ae18db..9d0f1dd 100644
--- a/src/game/client/entity/player_look.hh
+++ b/src/game/client/entity/player_look.hh
@@ -1,7 +1,7 @@
#pragma once
-namespace entity::player_look
+namespace player_look
{
void init(void);
void update_late(void);
-} // namespace entity::player_look
+} // namespace player_look
diff --git a/src/game/client/entity/player_move.cc b/src/game/client/entity/player_move.cc
index 4087b04..14d64cc 100644
--- a/src/game/client/entity/player_move.cc
+++ b/src/game/client/entity/player_move.cc
@@ -114,7 +114,7 @@ static glm::fvec3 pm_flight_move(const glm::fvec3& wishdir)
return wishdir * PMOVE_MAX_SPEED_AIR;
}
-void entity::player_move::init(void)
+void player_move::init(void)
{
movement_direction = ZERO_VEC3<float>;
@@ -153,14 +153,14 @@ void entity::player_move::init(void)
settings::add_checkbox(2, enable_speedometer, settings_location::VIDEO_GUI, "player_move.enable_speedometer", true);
}
-void entity::player_move::fixed_update(void)
+void player_move::fixed_update(void)
{
- const auto& head = globals::dimension->entities.get<entity::Head>(globals::player);
- auto& transform = globals::dimension->entities.get<entity::Transform>(globals::player);
- auto& velocity = globals::dimension->entities.get<entity::Velocity>(globals::player);
+ const auto& head = globals::dimension->entities.get<Head>(globals::player);
+ auto& transform = globals::dimension->entities.get<Transform>(globals::player);
+ auto& velocity = globals::dimension->entities.get<Velocity>(globals::player);
// Interpolation - preserve current component states
- globals::dimension->entities.emplace_or_replace<entity::client::TransformPrev>(globals::player, transform);
+ globals::dimension->entities.emplace_or_replace<client::TransformPrev>(globals::player, transform);
glm::fvec3 forward, right;
math::vectors(glm::fvec3(0.0f, head.angles[1], 0.0f), &forward, &right, nullptr);
@@ -175,7 +175,7 @@ void entity::player_move::fixed_update(void)
return;
}
- auto grounded = globals::dimension->entities.try_get<entity::Grounded>(globals::player);
+ auto grounded = globals::dimension->entities.try_get<Grounded>(globals::player);
auto velocity_horizontal = glm::fvec3(velocity.value.x, 0.0f, velocity.value.z);
if(grounded) {
@@ -193,7 +193,7 @@ void entity::player_move::fixed_update(void)
}
if(footsteps_distance >= PMOVE_FOOTSTEP_SIZE) {
- if(auto effect = world::voxel_sounds::get_footsteps(grounded->surface)) {
+ if(auto effect = voxel_sounds::get_footsteps(grounded->surface)) {
sound::play_player(effect, false, pitch_distrib(pitch_random));
}
@@ -228,27 +228,27 @@ void entity::player_move::fixed_update(void)
if(glm::abs(speed_change) < 0.01f) {
// No considerable speed increase within
// the precision we use to draw the speedometer
- gui::status_lines::set(gui::STATUS_DEBUG, new_speed_text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f), 1.0f);
+ 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) {
// Speed change is negative, we are actively
// slowing down; use the red color for the status line
- gui::status_lines::set(gui::STATUS_DEBUG, new_speed_text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
+ status_lines::set(STATUS_DEBUG, new_speed_text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
}
else {
// Speed change is positive, we are actively
// speeding up; use the green color for the status line
- gui::status_lines::set(gui::STATUS_DEBUG, new_speed_text, ImVec4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f);
+ status_lines::set(STATUS_DEBUG, new_speed_text, ImVec4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f);
}
}
- if(auto effect = world::voxel_sounds::get_footsteps(grounded->surface)) {
+ if(auto effect = voxel_sounds::get_footsteps(grounded->surface)) {
sound::play_player(effect, false, 1.0f);
}
}
}
-void entity::player_move::update_late(void)
+void player_move::update_late(void)
{
movement_direction = ZERO_VEC3<float>;
@@ -258,17 +258,17 @@ void entity::player_move::update_late(void)
return;
}
- if(io::gamepad::available && io::gamepad::active.get_value()) {
- if(button_move_down.is_pressed(io::gamepad::state)) {
+ if(gamepad::available && gamepad::active.get_value()) {
+ if(button_move_down.is_pressed(gamepad::state)) {
movement_direction += DIR_DOWN<float>;
}
- if(button_move_up.is_pressed(io::gamepad::state)) {
+ if(button_move_up.is_pressed(gamepad::state)) {
movement_direction += DIR_UP<float>;
}
- movement_direction.x += axis_move_sideways.get_value(io::gamepad::state, io::gamepad::deadzone.get_value());
- movement_direction.z -= axis_move_forward.get_value(io::gamepad::state, io::gamepad::deadzone.get_value());
+ 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())) {
diff --git a/src/game/client/entity/player_move.hh b/src/game/client/entity/player_move.hh
index 8c033cc..8516308 100644
--- a/src/game/client/entity/player_move.hh
+++ b/src/game/client/entity/player_move.hh
@@ -7,9 +7,9 @@ constexpr static float PMOVE_ACCELERATION_GROUND = 6.0f;
constexpr static float PMOVE_FRICTION_GROUND = 10.0f;
constexpr static float PMOVE_JUMP_FORCE = 0.275f;
-namespace entity::player_move
+namespace player_move
{
void init(void);
void fixed_update(void);
void update_late(void);
-} // namespace entity::player_move
+} // namespace player_move
diff --git a/src/game/client/entity/sound_emitter.cc b/src/game/client/entity/sound_emitter.cc
index 57909ec..79b5ab0 100644
--- a/src/game/client/entity/sound_emitter.cc
+++ b/src/game/client/entity/sound_emitter.cc
@@ -19,35 +19,35 @@
#include "client/globals.hh"
-entity::SoundEmitter::SoundEmitter(void)
+SoundEmitter::SoundEmitter(void)
{
alGenSources(1, &source);
sound = nullptr;
}
-entity::SoundEmitter::~SoundEmitter(void)
+SoundEmitter::~SoundEmitter(void)
{
alSourceStop(source);
alDeleteSources(1, &source);
}
-void entity::SoundEmitter::update(void)
+void SoundEmitter::update(void)
{
if(globals::dimension) {
- const auto view = globals::dimension->entities.view<entity::SoundEmitter>();
+ const auto view = globals::dimension->entities.view<SoundEmitter>();
- const auto& pivot = entity::camera::position_chunk;
+ const auto& pivot = camera::position_chunk;
const auto gain = glm::clamp(sound::volume_effects.get_value() * 0.01f, 0.0f, 1.0f);
for(const auto [entity, emitter] : view.each()) {
alSourcef(emitter.source, AL_GAIN, gain);
- if(const auto transform = globals::dimension->entities.try_get<entity::client::TransformIntr>(entity)) {
+ if(const auto transform = globals::dimension->entities.try_get<client::TransformIntr>(entity)) {
auto position = coord::to_relative(pivot, transform->chunk, transform->local);
alSource3f(emitter.source, AL_POSITION, position.x, position.y, position.z);
}
- if(const auto velocity = globals::dimension->entities.try_get<entity::Velocity>(entity)) {
+ if(const auto velocity = globals::dimension->entities.try_get<Velocity>(entity)) {
alSource3f(emitter.source, AL_VELOCITY, velocity->value.x, velocity->value.y, velocity->value.z);
}
diff --git a/src/game/client/entity/sound_emitter.hh b/src/game/client/entity/sound_emitter.hh
index 72a3f74..6bc0846 100644
--- a/src/game/client/entity/sound_emitter.hh
+++ b/src/game/client/entity/sound_emitter.hh
@@ -4,8 +4,6 @@
struct SoundEffect;
-namespace entity
-{
struct SoundEmitter final {
resource_ptr<SoundEffect> sound;
ALuint source;
@@ -17,4 +15,3 @@ public:
public:
static void update(void);
};
-} // namespace entity
diff --git a/src/game/client/experiments.cc b/src/game/client/experiments.cc
index eb415f7..4df6f1e 100644
--- a/src/game/client/experiments.cc
+++ b/src/game/client/experiments.cc
@@ -19,10 +19,10 @@
#include "client/globals.hh"
#include "client/session.hh"
-static void on_glfw_mouse_button(const io::GlfwMouseButtonEvent& event)
+static void on_glfw_mouse_button(const GlfwMouseButtonEvent& event)
{
if(!globals::gui_screen && session::is_ingame()) {
- if((event.action == GLFW_PRESS) && world::player_target::voxel) {
+ if((event.action == GLFW_PRESS) && player_target::voxel) {
if(event.button == GLFW_MOUSE_BUTTON_LEFT) {
experiments::attack();
return;
@@ -38,20 +38,20 @@ static void on_glfw_mouse_button(const io::GlfwMouseButtonEvent& event)
void experiments::init(void)
{
- globals::dispatcher.sink<io::GlfwMouseButtonEvent>().connect<&on_glfw_mouse_button>();
+ globals::dispatcher.sink<GlfwMouseButtonEvent>().connect<&on_glfw_mouse_button>();
}
void experiments::init_late(void)
{
- gui::hotbar::slots[0] = game_items::cobblestone;
- gui::hotbar::slots[1] = game_items::stone;
- gui::hotbar::slots[2] = game_items::dirt;
- gui::hotbar::slots[3] = game_items::grass;
- gui::hotbar::slots[4] = game_items::oak_leaves;
- gui::hotbar::slots[5] = game_items::oak_planks;
- gui::hotbar::slots[6] = game_items::oak_log;
- gui::hotbar::slots[7] = game_items::glass;
- gui::hotbar::slots[8] = game_items::slime;
+ hotbar::slots[0] = game_items::cobblestone;
+ hotbar::slots[1] = game_items::stone;
+ hotbar::slots[2] = game_items::dirt;
+ hotbar::slots[3] = game_items::grass;
+ hotbar::slots[4] = game_items::oak_leaves;
+ hotbar::slots[5] = game_items::oak_planks;
+ hotbar::slots[6] = game_items::oak_log;
+ hotbar::slots[7] = game_items::glass;
+ hotbar::slots[8] = game_items::slime;
}
void experiments::shutdown(void)
@@ -68,16 +68,16 @@ void experiments::update_late(void)
void experiments::attack(void)
{
- globals::dimension->set_voxel(nullptr, world::player_target::coord);
+ globals::dimension->set_voxel(nullptr, player_target::coord);
}
void experiments::interact(void)
{
- auto active_item = gui::hotbar::slots[gui::hotbar::active_slot];
+ auto active_item = hotbar::slots[hotbar::active_slot];
if(active_item) {
if(auto place_voxel = active_item->get_place_voxel()) {
- globals::dimension->set_voxel(place_voxel, world::player_target::coord + world::player_target::normal);
+ globals::dimension->set_voxel(place_voxel, player_target::coord + player_target::normal);
return;
}
}
diff --git a/src/game/client/game.cc b/src/game/client/game.cc
index 4b8ffc8..5a67b59 100644
--- a/src/game/client/game.cc
+++ b/src/game/client/game.cc
@@ -100,7 +100,7 @@ static ImFont* load_font(std::string_view path, float size, ImFontConfig& font_c
{
std::vector<std::byte> font;
- if(!io::read_file(path, font)) {
+ if(!read_file(path, font)) {
spdlog::error("{}: utils::read_file failed", path);
std::terminate();
}
@@ -116,7 +116,7 @@ static ImFont* load_font(std::string_view path, float size, ImFontConfig& font_c
return font_ptr;
}
-static void on_glfw_framebuffer_size(const io::GlfwFramebufferSizeEvent& event)
+static void on_glfw_framebuffer_size(const GlfwFramebufferSizeEvent& event)
{
if(globals::world_fbo) {
glDeleteRenderbuffers(1, &globals::world_fbo_depth);
@@ -147,7 +147,7 @@ static void on_glfw_framebuffer_size(const io::GlfwFramebufferSizeEvent& event)
}
}
-static void on_glfw_key(const io::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;
@@ -175,8 +175,8 @@ void client_game::init(void)
globals::font_unscii16 = load_font("fonts/unscii-16.ttf", 16.0f, font_config, ranges);
globals::font_unscii8 = load_font("fonts/unscii-8.ttf", 8.0f, font_config, ranges);
- gui::client_splash::init();
- gui::client_splash::render();
+ client_splash::init();
+ client_splash::render();
globals::client_config.add_value("game.streamer_mode", client_game::streamer_mode);
globals::client_config.add_value("game.vertical_sync", client_game::vertical_sync);
@@ -201,31 +201,31 @@ void client_game::init(void)
std::terminate();
}
- gui::language::init();
+ language::init();
session::init();
- entity::player_look::init();
- entity::player_move::init();
- world::player_target::init();
+ player_look::init();
+ player_move::init();
+ player_target::init();
- io::gamepad::init();
+ gamepad::init();
- entity::camera::init();
+ camera::init();
- world::voxel_anims::init();
+ voxel_anims::init();
- world::outline::init();
- world::chunk_mesher::init();
- world::chunk_renderer::init();
+ outline::init();
+ chunk_mesher::init();
+ chunk_renderer::init();
globals::world_fbo = 0;
globals::world_fbo_color = 0;
globals::world_fbo_depth = 0;
- world::voxel_sounds::init();
+ voxel_sounds::init();
- world::skybox::init();
+ skybox::init();
ImGuiStyle& style = ImGui::GetStyle();
@@ -237,94 +237,91 @@ 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.GrabRounding = 0.0f;
style.PopupRounding = 0.0f;
- style.WindowRounding = 0.0f;
style.ScrollbarRounding = 0.0f;
+ style.TabRounding = 0.0f;
+ style.WindowRounding = 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_Button] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
+ style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
+ style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
+ style.Colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
+ style.Colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.38f);
+ style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 1.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_FrameBgHovered] = ImVec4(0.36f, 0.36f, 0.36f, 0.40f);
+ style.Colors[ImGuiCol_Header] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f);
+ style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
+ style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
+ style.Colors[ImGuiCol_NavCursor] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
+ style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
+ style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
+ style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.00f, 0.00f, 0.00f, 0.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_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_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
+ style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.34f, 0.34f, 0.34f, 0.20f);
+ style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.95f);
+ style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.57f, 0.57f, 0.57f, 0.67f);
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_ScrollbarGrabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 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_SeparatorHovered] = ImVec4(0.56f, 0.56f, 0.56f, 0.78f);
+ 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_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_TabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
+ style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
+ style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 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_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_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_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
- // of UI elements must be calculated at semi-runtime
- // so there's simply no point for an INI file.
+ 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_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
+ style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.75f);
+
io.IniFilename = nullptr;
toggles::init();
- gui::background::init();
+ background::init();
- gui::scoreboard::init();
+ scoreboard::init();
- gui::client_chat::init();
+ client_chat::init();
- gui::bother::init();
+ bother::init();
- gui::main_menu::init();
- gui::play_menu::init();
- gui::progress_bar::init();
- gui::message_box::init();
- gui::direct_connection::init();
+ main_menu::init();
+ play_menu::init();
+ progress_bar::init();
+ message_box::init();
+ direct_connection::init();
- gui::crosshair::init();
- gui::hotbar::init();
- gui::metrics::init();
- gui::status_lines::init();
+ crosshair::init();
+ hotbar::init();
+ metrics::init();
+ status_lines::init();
screenshot::init();
@@ -342,8 +339,8 @@ void client_game::init(void)
experiments::init();
- globals::dispatcher.sink<io::GlfwFramebufferSizeEvent>().connect<&on_glfw_framebuffer_size>();
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwFramebufferSizeEvent>().connect<&on_glfw_framebuffer_size>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
}
void client_game::init_late(void)
@@ -354,13 +351,13 @@ void client_game::init_late(void)
sound::init_late();
}
- gui::language::init_late();
+ language::init_late();
settings::init_late();
- gui::client_chat::init_late();
+ client_chat::init_late();
- gui::status_lines::init_late();
+ status_lines::init_late();
game_voxels::populate();
game_items::populate();
@@ -371,35 +368,35 @@ 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 auto& voxel : world::voxel_registry::voxels) {
+ for(const auto& voxel : voxel_registry::voxels) {
max_texture_count += voxel->get_default_textures().size();
- max_texture_count += voxel->get_face_textures(world::VFACE_NORTH).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_SOUTH).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_EAST).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_WEST).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_TOP).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_BOTTOM).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_CROSS_NWSE).size();
- max_texture_count += voxel->get_face_textures(world::VFACE_CROSS_NESW).size();
+ max_texture_count += voxel->get_face_textures(VFACE_NORTH).size();
+ max_texture_count += voxel->get_face_textures(VFACE_SOUTH).size();
+ max_texture_count += voxel->get_face_textures(VFACE_EAST).size();
+ max_texture_count += voxel->get_face_textures(VFACE_WEST).size();
+ max_texture_count += voxel->get_face_textures(VFACE_TOP).size();
+ max_texture_count += voxel->get_face_textures(VFACE_BOTTOM).size();
+ max_texture_count += voxel->get_face_textures(VFACE_CROSS_NWSE).size();
+ max_texture_count += voxel->get_face_textures(VFACE_CROSS_NESW).size();
}
// UNDONE: asset packs for non-16x16 stuff
- world::voxel_atlas::create(16, 16, max_texture_count);
+ voxel_atlas::create(16, 16, max_texture_count);
- for(auto& voxel : world::voxel_registry::voxels) {
+ for(auto& voxel : voxel_registry::voxels) {
constexpr std::array faces = {
- world::VFACE_NORTH,
- world::VFACE_SOUTH,
- world::VFACE_EAST,
- world::VFACE_WEST,
- world::VFACE_TOP,
- world::VFACE_BOTTOM,
- world::VFACE_CROSS_NWSE,
- world::VFACE_CROSS_NESW,
+ VFACE_NORTH,
+ VFACE_SOUTH,
+ VFACE_EAST,
+ VFACE_WEST,
+ VFACE_TOP,
+ VFACE_BOTTOM,
+ VFACE_CROSS_NWSE,
+ VFACE_CROSS_NESW,
};
for(auto face : faces) {
- if(auto strip = world::voxel_atlas::find_or_load(voxel->get_face_textures(face))) {
+ if(auto strip = voxel_atlas::find_or_load(voxel->get_face_textures(face))) {
voxel->set_face_cache(face, strip->offset, strip->plane);
continue;
}
@@ -409,22 +406,22 @@ void client_game::init_late(void)
}
}
- world::voxel_atlas::generate_mipmaps();
+ voxel_atlas::generate_mipmaps();
- for(auto& item : world::item_registry::items) {
+ for(auto& item : item_registry::items) {
item->set_cached_texture(resource::load<TextureGUI>(item->get_texture(), TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T));
}
experiments::init_late();
- gui::client_splash::init_late();
+ client_splash::init_late();
- gui::window_title::update();
+ window_title::update();
}
void client_game::shutdown(void)
{
- world::voxel_sounds::shutdown();
+ voxel_sounds::shutdown();
experiments::shutdown();
@@ -434,60 +431,60 @@ void client_game::shutdown(void)
sound::shutdown();
}
- gui::hotbar::shutdown();
- gui::main_menu::shutdown();
- gui::play_menu::shutdown();
+ hotbar::shutdown();
+ main_menu::shutdown();
+ play_menu::shutdown();
- gui::bother::shutdown();
+ bother::shutdown();
- gui::client_chat::shutdown();
+ client_chat::shutdown();
- gui::background::shutdown();
+ background::shutdown();
- gui::crosshair::shutdown();
+ crosshair::shutdown();
delete globals::dimension;
globals::player = entt::null;
globals::dimension = nullptr;
- world::item_registry::purge();
- world::voxel_registry::purge();
+ item_registry::purge();
+ voxel_registry::purge();
- world::voxel_atlas::destroy();
+ voxel_atlas::destroy();
glDeleteRenderbuffers(1, &globals::world_fbo_depth);
glDeleteTextures(1, &globals::world_fbo_color);
glDeleteFramebuffers(1, &globals::world_fbo);
- world::outline::shutdown();
- world::chunk_renderer::shutdown();
- world::chunk_mesher::shutdown();
+ outline::shutdown();
+ chunk_renderer::shutdown();
+ chunk_mesher::shutdown();
enet_host_destroy(globals::client_host);
}
void client_game::fixed_update(void)
{
- entity::player_move::fixed_update();
+ player_move::fixed_update();
// Only update world simulation gamesystems
// if the player can actually observe all the
// changes these gamesystems cause visually
if(session::is_ingame()) {
- entity::Collision::fixed_update(globals::dimension);
- entity::Velocity::fixed_update(globals::dimension);
- entity::Transform::fixed_update(globals::dimension);
- entity::Gravity::fixed_update(globals::dimension);
- entity::Stasis::fixed_update(globals::dimension);
+ Collision::fixed_update(globals::dimension);
+ Velocity::fixed_update(globals::dimension);
+ Transform::fixed_update(globals::dimension);
+ Gravity::fixed_update(globals::dimension);
+ Stasis::fixed_update(globals::dimension);
}
}
void client_game::fixed_update_late(void)
{
if(session::is_ingame()) {
- const auto& head = globals::dimension->entities.get<entity::Head>(globals::player);
- const auto& transform = globals::dimension->entities.get<entity::Transform>(globals::player);
- const auto& velocity = globals::dimension->entities.get<entity::Velocity>(globals::player);
+ const auto& head = globals::dimension->entities.get<Head>(globals::player);
+ const auto& transform = globals::dimension->entities.get<Transform>(globals::player);
+ const auto& velocity = globals::dimension->entities.get<Velocity>(globals::player);
protocol::EntityHead head_packet;
head_packet.entity = entt::null; // ignored by server
@@ -513,49 +510,42 @@ void client_game::update(void)
{
if(session::is_ingame()) {
if(toggles::get(TOGGLE_PM_FLIGHT)) {
- globals::dimension->entities.remove<entity::Gravity>(globals::player);
+ globals::dimension->entities.remove<Gravity>(globals::player);
}
else {
- globals::dimension->entities.emplace_or_replace<entity::Gravity>(globals::player);
+ globals::dimension->entities.emplace_or_replace<Gravity>(globals::player);
}
}
if(globals::sound_ctx) {
sound::update();
- entity::listener::update();
+ listener::update();
- entity::SoundEmitter::update();
+ SoundEmitter::update();
}
- entity::interpolation::update();
+ interpolation::update();
- world::player_target::update();
+ player_target::update();
- entity::camera::update();
+ camera::update();
- world::voxel_anims::update();
+ voxel_anims::update();
- world::chunk_mesher::update();
+ chunk_mesher::update();
- gui::client_chat::update();
+ client_chat::update();
experiments::update();
- constexpr auto half_base_width = 0.5f * static_cast<float>(BASE_WIDTH);
- constexpr auto half_base_height = 0.5f * static_cast<float>(BASE_HEIGHT);
-
- auto twice_scale_x = static_cast<float>(globals::width) / half_base_width;
- auto twice_scale_y = static_cast<float>(globals::height) / half_base_height;
-
- auto scale_x = glm::max(1.0f, 0.5f * glm::floor(twice_scale_x));
- auto scale_y = glm::max(1.0f, 0.5f * glm::floor(twice_scale_y));
- auto scale_min = static_cast<unsigned int>(glm::ceil(glm::min(scale_x, scale_y)));
- auto scale_int = glm::max<unsigned int>(1U, (scale_min / 2U) * 2U);
+ auto scale_x = glm::max(1.0f, glm::floor(static_cast<float>(globals::width) / static_cast<float>(BASE_WIDTH)));
+ auto scale_y = glm::max(1.0f, glm::floor(static_cast<float>(globals::height) / static_cast<float>(BASE_HEIGHT)));
+ auto scale_min = glm::min(scale_x, scale_y);
auto& io = ImGui::GetIO();
- io.FontGlobalScale = scale_int;
- globals::gui_scale = scale_int;
+ io.FontGlobalScale = scale_min;
+ globals::gui_scale = scale_min;
}
void client_game::update_late(void)
@@ -577,18 +567,18 @@ void client_game::update_late(void)
}
}
- entity::player_look::update_late();
- entity::player_move::update_late();
+ player_look::update_late();
+ player_move::update_late();
- gui::play_menu::update_late();
+ play_menu::update_late();
- gui::bother::update_late();
+ bother::update_late();
experiments::update_late();
- io::gamepad::update_late();
+ gamepad::update_late();
- world::chunk_visibility::update_late();
+ chunk_visibility::update_late();
if(client_game::vertical_sync.get_value()) {
glfwSwapInterval(1);
@@ -602,22 +592,21 @@ void client_game::render(void)
{
glViewport(0, 0, globals::width, globals::height);
glBindFramebuffer(GL_FRAMEBUFFER, globals::world_fbo);
- glClearColor(world::skybox::fog_color.r, world::skybox::fog_color.g, world::skybox::fog_color.b, 1.000f);
+ glClearColor(skybox::fog_color.r, skybox::fog_color.g, skybox::fog_color.b, 1.000f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(globals::dimension) {
- world::chunk_renderer::render();
+ chunk_renderer::render();
}
glEnable(GL_DEPTH_TEST);
- world::player_target::render();
+ player_target::render();
if(globals::dimension) {
- auto group = globals::dimension->entities.group(
- entt::get<entity::Player, entity::Collision, entity::client::HeadIntr, entity::client::TransformIntr>);
+ auto group = globals::dimension->entities.group(entt::get<Player, Collision, client::HeadIntr, client::TransformIntr>);
- world::outline::prepare();
+ outline::prepare();
for(const auto [entity, collision, head, transform] : group.each()) {
if(entity == globals::player) {
@@ -633,8 +622,8 @@ void client_game::render(void)
glm::fvec3 hull_fpos = transform.local + collision.aabb.min;
glm::fvec3 look = transform.local + head.offset;
- world::outline::cube(transform.chunk, hull_fpos, hull_size, 1.0f, glm::fvec4(1.0f, 0.0f, 0.0f, 1.0f));
- world::outline::line(transform.chunk, look, forward, 1.0f, glm::fvec4(0.9f, 0.9f, 0.9f, 1.0f));
+ outline::cube(transform.chunk, hull_fpos, hull_size, 1.0f, glm::fvec4(1.0f, 0.0f, 0.0f, 1.0f));
+ outline::line(transform.chunk, look, forward, 1.0f, glm::fvec4(0.9f, 0.9f, 0.9f, 1.0f));
}
}
@@ -653,7 +642,7 @@ void client_game::render(void)
void client_game::layout(void)
{
if(!session::is_ingame()) {
- gui::background::layout();
+ background::layout();
}
if(!globals::gui_screen || (globals::gui_screen == GUI_CHAT)) {
@@ -661,47 +650,50 @@ void client_game::layout(void)
// This contains Minecraft-esque debug information
// about the hardware, world state and other
// things that might be uesful
- gui::metrics::layout();
+ metrics::layout();
}
}
if(session::is_ingame()) {
- gui::client_chat::layout();
- gui::scoreboard::layout();
+ client_chat::layout();
+ scoreboard::layout();
if(!globals::gui_screen && !client_game::hide_hud) {
- gui::hotbar::layout();
- gui::status_lines::layout();
- gui::crosshair::layout();
+ hotbar::layout();
+ status_lines::layout();
+ crosshair::layout();
}
}
if(globals::gui_screen) {
if(session::is_ingame() && (globals::gui_screen != GUI_CHAT)) {
- const float width_f = static_cast<float>(globals::width);
- const float height_f = static_cast<float>(globals::height);
- const ImU32 darken = ImGui::GetColorU32(ImVec4(0.00f, 0.00f, 0.00f, 0.75f));
- ImGui::GetBackgroundDrawList()->AddRectFilled(ImVec2(), ImVec2(width_f, height_f), darken);
+ auto width_f = static_cast<float>(globals::width);
+ auto height_f = static_cast<float>(globals::height);
+ auto darken = ImGui::GetColorU32(ImVec4(0.00f, 0.00f, 0.00f, 0.75f));
+ auto darker = ImGui::GetColorU32(ImVec4(0.00f, 0.00f, 0.00f, 0.95f));
+ auto draw_list = ImGui::GetBackgroundDrawList();
+
+ draw_list->AddRectFilledMultiColor({}, { width_f, height_f }, darker, darken, darken, darker);
}
switch(globals::gui_screen) {
case GUI_MAIN_MENU:
- gui::main_menu::layout();
+ main_menu::layout();
break;
case GUI_PLAY_MENU:
- gui::play_menu::layout();
+ play_menu::layout();
break;
case GUI_SETTINGS:
settings::layout();
break;
case GUI_PROGRESS_BAR:
- gui::progress_bar::layout();
+ progress_bar::layout();
break;
case GUI_MESSAGE_BOX:
- gui::message_box::layout();
+ message_box::layout();
break;
case GUI_DIRECT_CONNECTION:
- gui::direct_connection::layout();
+ direct_connection::layout();
break;
}
}
diff --git a/src/game/client/globals.cc b/src/game/client/globals.cc
index 1932675..85e5cd6 100644
--- a/src/game/client/globals.cc
+++ b/src/game/client/globals.cc
@@ -6,7 +6,7 @@
#include "client/gui/gui_screen.hh"
-io::ConfigMap globals::client_config;
+ConfigMap globals::client_config;
GLFWwindow* globals::window;
@@ -30,7 +30,7 @@ std::size_t globals::num_triangles;
ENetHost* globals::client_host;
-world::Dimension* globals::dimension = nullptr;
+Dimension* globals::dimension = nullptr;
entt::entity globals::player;
ImFont* globals::font_unscii16;
diff --git a/src/game/client/globals.hh b/src/game/client/globals.hh
index ba57a9e..a6c2de6 100644
--- a/src/game/client/globals.hh
+++ b/src/game/client/globals.hh
@@ -9,22 +9,16 @@ class GamepadAxis;
class GamepadButton;
} // namespace config
-namespace io
-{
class ConfigMap;
-} // namespace io
struct GLFWwindow;
struct ImFont;
-namespace world
-{
class Dimension;
-} // namespace world
namespace globals
{
-extern io::ConfigMap client_config;
+extern ConfigMap client_config;
extern GLFWwindow* window;
@@ -53,7 +47,7 @@ extern std::size_t num_triangles;
extern ENetHost* client_host;
-extern world::Dimension* dimension;
+extern Dimension* dimension;
extern entt::entity player;
extern ImFont* font_unscii16;
diff --git a/src/game/client/gui/CMakeLists.txt b/src/game/client/gui/CMakeLists.txt
index 46d64a1..e3d8b7a 100644
--- a/src/game/client/gui/CMakeLists.txt
+++ b/src/game/client/gui/CMakeLists.txt
@@ -12,8 +12,12 @@ target_sources(vclient PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/gui_screen.hh"
"${CMAKE_CURRENT_LIST_DIR}/hotbar.cc"
"${CMAKE_CURRENT_LIST_DIR}/hotbar.hh"
- "${CMAKE_CURRENT_LIST_DIR}/imdraw_ext.cc"
- "${CMAKE_CURRENT_LIST_DIR}/imdraw_ext.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_button.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_button.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_popup.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_popup.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_text.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/imutils_text.hh"
"${CMAKE_CURRENT_LIST_DIR}/language.cc"
"${CMAKE_CURRENT_LIST_DIR}/language.hh"
"${CMAKE_CURRENT_LIST_DIR}/main_menu.cc"
diff --git a/src/game/client/gui/background.cc b/src/game/client/gui/background.cc
index 50fef01..81fb764 100644
--- a/src/game/client/gui/background.cc
+++ b/src/game/client/gui/background.cc
@@ -12,9 +12,9 @@
static resource_ptr<TextureGUI> texture;
-void gui::background::init(void)
+void background::init(void)
{
- texture = resource::load<TextureGUI>("textures/gui/background.png", TEXTURE_GUI_LOAD_VFLIP);
+ texture = resource::load<TextureGUI>("textures/gui/background.png");
if(texture == nullptr) {
spdlog::critical("background: texture load failed");
@@ -22,18 +22,14 @@ void gui::background::init(void)
}
}
-void gui::background::shutdown(void)
+void background::shutdown(void)
{
texture = nullptr;
}
-void gui::background::layout(void)
+void background::layout(void)
{
auto viewport = ImGui::GetMainViewport();
auto draw_list = ImGui::GetBackgroundDrawList();
-
- auto scaled_width = 0.75f * static_cast<float>(globals::width / globals::gui_scale);
- auto scaled_height = 0.75f * static_cast<float>(globals::height / globals::gui_scale);
- auto scale_uv = ImVec2(scaled_width / static_cast<float>(texture->size.x), scaled_height / static_cast<float>(texture->size.y));
- draw_list->AddImage(texture->handle, ImVec2(0.0f, 0.0f), viewport->Size, ImVec2(0.0f, 0.0f), scale_uv);
+ draw_list->AddImage(texture->handle, {}, viewport->Size);
}
diff --git a/src/game/client/gui/background.hh b/src/game/client/gui/background.hh
index 5c72a3f..51497d1 100644
--- a/src/game/client/gui/background.hh
+++ b/src/game/client/gui/background.hh
@@ -1,8 +1,8 @@
#pragma once
-namespace gui::background
+namespace background
{
void init(void);
void shutdown(void);
void layout(void);
-} // namespace gui::background
+} // namespace background
diff --git a/src/game/client/gui/bother.cc b/src/game/client/gui/bother.cc
index a045284..7309bbc 100644
--- a/src/game/client/gui/bother.cc
+++ b/src/game/client/gui/bother.cc
@@ -28,7 +28,7 @@ static void on_status_response_packet(const protocol::StatusResponse& packet)
bother_set.erase(identity);
- gui::BotherResponseEvent event;
+ BotherResponseEvent event;
event.identity = identity;
event.is_server_unreachable = false;
event.num_players = packet.num_players;
@@ -42,7 +42,7 @@ static void on_status_response_packet(const protocol::StatusResponse& packet)
enet_peer_disconnect(packet.peer, protocol::CHANNEL);
}
-void gui::bother::init(void)
+void bother::init(void)
{
bother_host = enet_host_create(nullptr, BOTHER_PEERS, 1, 0, 0);
bother_dispatcher.clear();
@@ -51,14 +51,14 @@ void gui::bother::init(void)
bother_dispatcher.sink<protocol::StatusResponse>().connect<&on_status_response_packet>();
}
-void gui::bother::shutdown(void)
+void bother::shutdown(void)
{
enet_host_destroy(bother_host);
bother_dispatcher.clear();
bother_set.clear();
}
-void gui::bother::update_late(void)
+void bother::update_late(void)
{
unsigned int free_peers = 0U;
@@ -121,7 +121,7 @@ void gui::bother::update_late(void)
}
}
-void gui::bother::ping(unsigned int identity, std::string_view host, std::uint16_t port)
+void bother::ping(unsigned int identity, std::string_view host, std::uint16_t port)
{
if(bother_set.count(identity)) {
// Already in the process
@@ -143,7 +143,7 @@ void gui::bother::ping(unsigned int identity, std::string_view host, std::uint16
bother_queue.push_back(item);
}
-void gui::bother::cancel(unsigned int identity)
+void bother::cancel(unsigned int identity)
{
bother_set.erase(identity);
diff --git a/src/game/client/gui/bother.hh b/src/game/client/gui/bother.hh
index b0355ca..ed4f84f 100644
--- a/src/game/client/gui/bother.hh
+++ b/src/game/client/gui/bother.hh
@@ -1,7 +1,5 @@
#pragma once
-namespace gui
-{
struct BotherResponseEvent final {
unsigned int identity;
bool is_server_unreachable;
@@ -12,13 +10,12 @@ struct BotherResponseEvent final {
std::uint32_t game_version_patch;
std::string motd;
};
-} // namespace gui
-namespace gui::bother
+namespace bother
{
void init(void);
void shutdown(void);
void update_late(void);
void ping(unsigned int identity, std::string_view host, std::uint16_t port);
void cancel(unsigned int identity);
-} // namespace gui::bother
+} // namespace bother
diff --git a/src/game/client/gui/chat.cc b/src/game/client/gui/chat.cc
index 70a1668..76260af 100644
--- a/src/game/client/gui/chat.cc
+++ b/src/game/client/gui/chat.cc
@@ -16,7 +16,7 @@
#include "client/config/keybind.hh"
#include "client/gui/gui_screen.hh"
-#include "client/gui/imdraw_ext.hh"
+#include "client/gui/imutils_text.hh"
#include "client/gui/language.hh"
#include "client/gui/settings.hh"
@@ -65,7 +65,7 @@ static void append_player_join(const std::string& sender)
{
GuiChatMessage message;
message.spawn = globals::curtime;
- message.text = std::format("{} {}", sender, gui::language::resolve("chat.client_join"));
+ message.text = std::format("{} {}", sender, language::resolve("chat.client_join"));
message.color = ImGui::GetStyleColorVec4(ImGuiCol_DragDropTarget);
history.push_back(message);
@@ -78,7 +78,7 @@ static void append_player_leave(const std::string& sender, const std::string& re
{
GuiChatMessage message;
message.spawn = globals::curtime;
- message.text = std::format("{} {} ({})", sender, gui::language::resolve("chat.client_left"), gui::language::resolve(reason.c_str()));
+ message.text = std::format("{} {} ({})", sender, language::resolve("chat.client_left"), language::resolve(reason.c_str()));
message.color = ImGui::GetStyleColorVec4(ImGuiCol_DragDropTarget);
history.push_back(message);
@@ -105,7 +105,7 @@ static void on_chat_message_packet(const protocol::ChatMessage& packet)
}
}
-static void on_glfw_key(const io::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)) {
@@ -138,7 +138,7 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-void gui::client_chat::init(void)
+void client_chat::init(void)
{
globals::client_config.add_value("chat.key", key_chat);
globals::client_config.add_value("chat.history_size", history_size);
@@ -147,28 +147,28 @@ void gui::client_chat::init(void)
settings::add_slider(1, history_size, settings_location::VIDEO_GUI, "chat.history_size", false);
globals::dispatcher.sink<protocol::ChatMessage>().connect<&on_chat_message_packet>();
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
sfx_chat_message = resource::load<SoundEffect>("sounds/ui/chat_message.wav");
}
-void gui::client_chat::init_late(void)
+void client_chat::init_late(void)
{
}
-void gui::client_chat::shutdown(void)
+void client_chat::shutdown(void)
{
sfx_chat_message = nullptr;
}
-void gui::client_chat::update(void)
+void client_chat::update(void)
{
while(history.size() > history_size.get_value()) {
history.pop_front();
}
}
-void gui::client_chat::layout(void)
+void client_chat::layout(void)
{
auto viewport = ImGui::GetMainViewport();
auto window_start = ImVec2(0.0f, 0.0f);
@@ -177,7 +177,7 @@ void gui::client_chat::layout(void)
ImGui::SetNextWindowPos(window_start);
ImGui::SetNextWindowSize(window_size);
- ImGui::PushFont(globals::font_unscii16, 8.0f);
+ ImGui::PushFont(globals::font_unscii16, 16.0f);
if(!ImGui::Begin("###chat", nullptr, WINDOW_FLAGS)) {
ImGui::End();
@@ -235,7 +235,7 @@ void gui::client_chat::layout(void)
draw_list->AddRectFilled(rect_pos, rect_end, rect_col);
- imdraw_ext::text_shadow_w(it->text, text_pos, text_col, shadow_col, font, draw_list, 8.0f, window_size.x);
+ imutils::text_wr(draw_list, it->text, text_pos, text_col, shadow_col, font, window_size.x, ImGui::GetFontSize());
ypos -= rect_size.y;
}
@@ -245,12 +245,12 @@ void gui::client_chat::layout(void)
ImGui::PopFont();
}
-void gui::client_chat::clear(void)
+void client_chat::clear(void)
{
history.clear();
}
-void gui::client_chat::refresh_timings(void)
+void client_chat::refresh_timings(void)
{
for(auto it = history.begin(); it < history.end(); ++it) {
// Reset the spawn time so the fadeout timer
@@ -259,7 +259,7 @@ void gui::client_chat::refresh_timings(void)
}
}
-void gui::client_chat::print(const std::string& text)
+void client_chat::print(const std::string& text)
{
GuiChatMessage message = {};
message.spawn = globals::curtime;
diff --git a/src/game/client/gui/chat.hh b/src/game/client/gui/chat.hh
index 6a3ea33..91c3740 100644
--- a/src/game/client/gui/chat.hh
+++ b/src/game/client/gui/chat.hh
@@ -1,17 +1,17 @@
#pragma once
-namespace gui::client_chat
+namespace client_chat
{
void init(void);
void init_late(void);
void shutdown(void);
void update(void);
void layout(void);
-} // namespace gui::client_chat
+} // namespace client_chat
-namespace gui::client_chat
+namespace client_chat
{
void clear(void);
void refresh_timings(void);
void print(const std::string& string);
-} // namespace gui::client_chat
+} // namespace client_chat
diff --git a/src/game/client/gui/crosshair.cc b/src/game/client/gui/crosshair.cc
index 649602f..758a10b 100644
--- a/src/game/client/gui/crosshair.cc
+++ b/src/game/client/gui/crosshair.cc
@@ -13,7 +13,7 @@
static resource_ptr<TextureGUI> texture;
-void gui::crosshair::init(void)
+void crosshair::init(void)
{
texture = resource::load<TextureGUI>("textures/gui/hud_crosshair.png",
TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T | TEXTURE_GUI_LOAD_VFLIP);
@@ -24,12 +24,12 @@ void gui::crosshair::init(void)
}
}
-void gui::crosshair::shutdown(void)
+void crosshair::shutdown(void)
{
texture = nullptr;
}
-void gui::crosshair::layout(void)
+void crosshair::layout(void)
{
auto viewport = ImGui::GetMainViewport();
auto draw_list = ImGui::GetForegroundDrawList();
diff --git a/src/game/client/gui/crosshair.hh b/src/game/client/gui/crosshair.hh
index 589727e..6789e1e 100644
--- a/src/game/client/gui/crosshair.hh
+++ b/src/game/client/gui/crosshair.hh
@@ -1,8 +1,8 @@
#pragma once
-namespace gui::crosshair
+namespace crosshair
{
void init(void);
void shutdown(void);
void layout(void);
-} // namespace gui::crosshair
+} // namespace crosshair
diff --git a/src/game/client/gui/direct_connection.cc b/src/game/client/gui/direct_connection.cc
index 39ea2b5..d7cea64 100644
--- a/src/game/client/gui/direct_connection.cc
+++ b/src/game/client/gui/direct_connection.cc
@@ -29,7 +29,7 @@ static std::string str_password;
static std::string direct_hostname;
static std::string direct_password;
-static void on_glfw_key(const io::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) {
@@ -39,14 +39,14 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-static void on_language_set(const gui::LanguageSetEvent& event)
+static void on_language_set(const LanguageSetEvent& event)
{
- str_title = gui::language::resolve("direct_connection.title");
- str_connect = gui::language::resolve_gui("direct_connection.connect");
- str_cancel = gui::language::resolve_gui("direct_connection.cancel");
+ str_title = language::resolve("direct_connection.title");
+ str_connect = language::resolve_gui("direct_connection.connect");
+ str_cancel = language::resolve_gui("direct_connection.cancel");
- str_hostname = gui::language::resolve("direct_connection.hostname");
- str_password = gui::language::resolve("direct_connection.password");
+ str_hostname = language::resolve("direct_connection.hostname");
+ str_password = language::resolve("direct_connection.password");
}
static void connect_to_server(void)
@@ -72,13 +72,13 @@ static void connect_to_server(void)
session::connect(parsed_hostname.c_str(), parsed_port, direct_password.c_str());
}
-void gui::direct_connection::init(void)
+void direct_connection::init(void)
{
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
globals::dispatcher.sink<LanguageSetEvent>().connect<&on_language_set>();
}
-void gui::direct_connection::layout(void)
+void direct_connection::layout(void)
{
auto viewport = ImGui::GetMainViewport();
auto window_start = ImVec2(0.25f * viewport->Size.x, 0.20f * viewport->Size.y);
diff --git a/src/game/client/gui/direct_connection.hh b/src/game/client/gui/direct_connection.hh
index aa02d7c..0a09a3f 100644
--- a/src/game/client/gui/direct_connection.hh
+++ b/src/game/client/gui/direct_connection.hh
@@ -1,7 +1,7 @@
#pragma once
-namespace gui::direct_connection
+namespace direct_connection
{
void init(void);
void layout(void);
-} // namespace gui::direct_connection
+} // namespace direct_connection
diff --git a/src/game/client/gui/hotbar.cc b/src/game/client/gui/hotbar.cc
index 663f263..b38c368 100644
--- a/src/game/client/gui/hotbar.cc
+++ b/src/game/client/gui/hotbar.cc
@@ -19,13 +19,13 @@
#include "client/globals.hh"
-constexpr static float ITEM_SIZE = 20.0f;
-constexpr static float ITEM_PADDING = 2.0f;
-constexpr static float SELECTOR_PADDING = 1.0f;
-constexpr static float HOTBAR_PADDING = 2.0f;
+constexpr static float ITEM_SIZE = 40.0f;
+constexpr static float ITEM_PADDING = 4.0f;
+constexpr static float SELECTOR_PADDING = 2.0f;
+constexpr static float HOTBAR_PADDING = 4.0f;
-unsigned int gui::hotbar::active_slot = 0U;
-std::array<const world::Item*, HOTBAR_SIZE> gui::hotbar::slots = {};
+unsigned int hotbar::active_slot = 0U;
+std::array<const Item*, HOTBAR_SIZE> hotbar::slots = {};
static config::KeyBind hotbar_keys[HOTBAR_SIZE];
@@ -40,22 +40,22 @@ static ImU32 get_color_alpha(ImGuiCol style_color, float alpha)
static void update_hotbar_item(void)
{
- auto current_item = gui::hotbar::slots[gui::hotbar::active_slot];
+ auto current_item = hotbar::slots[hotbar::active_slot];
if(current_item == nullptr) {
- gui::status_lines::unset(gui::STATUS_HOTBAR);
+ status_lines::unset(STATUS_HOTBAR);
}
else {
- gui::status_lines::set(gui::STATUS_HOTBAR, current_item->get_name(), ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
+ status_lines::set(STATUS_HOTBAR, current_item->get_name(), ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
}
}
-static void on_glfw_key(const io::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) {
if(hotbar_keys[i].equals(event.key)) {
- gui::hotbar::active_slot = i;
+ hotbar::active_slot = i;
update_hotbar_item();
break;
}
@@ -63,22 +63,22 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-static void on_glfw_scroll(const io::GlfwScrollEvent& event)
+static void on_glfw_scroll(const GlfwScrollEvent& event)
{
if(!globals::gui_screen) {
if(event.dy < 0.0) {
- gui::hotbar::next_slot();
+ hotbar::next_slot();
return;
}
if(event.dy > 0.0) {
- gui::hotbar::prev_slot();
+ hotbar::prev_slot();
return;
}
}
}
-void gui::hotbar::init(void)
+void hotbar::init(void)
{
hotbar_keys[0].set_key(GLFW_KEY_1);
hotbar_keys[1].set_key(GLFW_KEY_2);
@@ -113,17 +113,17 @@ void gui::hotbar::init(void)
hotbar_background = resource::load<TextureGUI>("textures/gui/hud_hotbar.png", TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T);
hotbar_selector = resource::load<TextureGUI>("textures/gui/hud_selector.png", TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T);
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
- globals::dispatcher.sink<io::GlfwScrollEvent>().connect<&on_glfw_scroll>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwScrollEvent>().connect<&on_glfw_scroll>();
}
-void gui::hotbar::shutdown(void)
+void hotbar::shutdown(void)
{
hotbar_background = nullptr;
hotbar_selector = nullptr;
}
-void gui::hotbar::layout(void)
+void hotbar::layout(void)
{
auto& style = ImGui::GetStyle();
@@ -142,7 +142,7 @@ void gui::hotbar::layout(void)
// Draw the hotbar selector image
auto selector_padding_a = SELECTOR_PADDING * globals::gui_scale;
auto selector_padding_b = SELECTOR_PADDING * globals::gui_scale * 2.0f;
- auto selector_start = ImVec2(background_start.x + gui::hotbar::active_slot * item_size - selector_padding_a,
+ auto selector_start = ImVec2(background_start.x + hotbar::active_slot * item_size - selector_padding_a,
background_start.y - selector_padding_a);
auto selector_end = ImVec2(selector_start.x + item_size + selector_padding_b, selector_start.y + item_size + selector_padding_b);
draw_list->AddImage(hotbar_selector->handle, selector_start, selector_end);
@@ -153,7 +153,7 @@ void gui::hotbar::layout(void)
// Draw individual item textures in the hotbar
for(std::size_t i = 0; i < HOTBAR_SIZE; ++i) {
- auto item = gui::hotbar::slots[i];
+ auto item = hotbar::slots[i];
if((item == nullptr) || (item->get_cached_texture() == nullptr)) {
// There's either no item in the slot
@@ -167,16 +167,16 @@ void gui::hotbar::layout(void)
}
}
-void gui::hotbar::next_slot(void)
+void hotbar::next_slot(void)
{
- gui::hotbar::active_slot += 1U;
- gui::hotbar::active_slot %= HOTBAR_SIZE;
+ hotbar::active_slot += 1U;
+ hotbar::active_slot %= HOTBAR_SIZE;
update_hotbar_item();
}
-void gui::hotbar::prev_slot(void)
+void hotbar::prev_slot(void)
{
- gui::hotbar::active_slot += HOTBAR_SIZE - 1U;
- gui::hotbar::active_slot %= HOTBAR_SIZE;
+ hotbar::active_slot += HOTBAR_SIZE - 1U;
+ hotbar::active_slot %= HOTBAR_SIZE;
update_hotbar_item();
}
diff --git a/src/game/client/gui/hotbar.hh b/src/game/client/gui/hotbar.hh
index c529230..bba5e63 100644
--- a/src/game/client/gui/hotbar.hh
+++ b/src/game/client/gui/hotbar.hh
@@ -3,28 +3,25 @@
// TODO: design an inventory system and an item
// registry and integrate the hotbar into that system
-namespace world
-{
class Item;
-} // namespace world
constexpr static unsigned int HOTBAR_SIZE = 9U;
-namespace gui::hotbar
+namespace hotbar
{
extern unsigned int active_slot;
-extern std::array<const world::Item*, HOTBAR_SIZE> slots;
-} // namespace gui::hotbar
+extern std::array<const Item*, HOTBAR_SIZE> slots;
+} // namespace hotbar
-namespace gui::hotbar
+namespace hotbar
{
void init(void);
void shutdown(void);
void layout(void);
-} // namespace gui::hotbar
+} // namespace hotbar
-namespace gui::hotbar
+namespace hotbar
{
void next_slot(void);
void prev_slot(void);
-} // namespace gui::hotbar
+} // namespace hotbar
diff --git a/src/game/client/gui/imdraw_ext.cc b/src/game/client/gui/imdraw_ext.cc
deleted file mode 100644
index 4b44d5f..0000000
--- a/src/game/client/gui/imdraw_ext.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "client/pch.hh"
-
-#include "client/gui/imdraw_ext.hh"
-
-#include "client/globals.hh"
-
-void gui::imdraw_ext::text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list)
-{
- imdraw_ext::text_shadow(text, position, text_color, shadow_color, font, draw_list, font->LegacySize);
-}
-
-void gui::imdraw_ext::text_shadow(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list, float font_size)
-{
- const auto shadow_position = ImVec2(position.x + 0.5f * globals::gui_scale, position.y + 0.5f * globals::gui_scale);
- draw_list->AddText(font, globals::gui_scale * font_size, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size());
- draw_list->AddText(font, globals::gui_scale * font_size, position, text_color, text.c_str(), text.c_str() + text.size());
-}
-
-void gui::imdraw_ext::text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list, float wrap_width)
-{
- imdraw_ext::text_shadow_w(text, position, text_color, shadow_color, font, draw_list, font->LegacySize, wrap_width);
-}
-
-void gui::imdraw_ext::text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list, float font_size, float wrap_width)
-{
- const auto shadow_position = ImVec2(position.x + 0.5f * globals::gui_scale, position.y + 0.5f * globals::gui_scale);
- draw_list->AddText(font, globals::gui_scale * font_size, shadow_position, shadow_color, text.c_str(), text.c_str() + text.size(),
- wrap_width);
- draw_list->AddText(font, globals::gui_scale * font_size, position, text_color, text.c_str(), text.c_str() + text.size(), wrap_width);
-}
diff --git a/src/game/client/gui/imdraw_ext.hh b/src/game/client/gui/imdraw_ext.hh
deleted file mode 100644
index a7e1503..0000000
--- a/src/game/client/gui/imdraw_ext.hh
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-namespace gui::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,
- float font_size);
-} // namespace gui::imdraw_ext
-
-namespace gui::imdraw_ext
-{
-void text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list, float wrap_width);
-void text_shadow_w(const std::string& text, const ImVec2& position, ImU32 text_color, ImU32 shadow_color, ImFont* font,
- ImDrawList* draw_list, float font_size, float wrap_width);
-} // namespace gui::imdraw_ext
diff --git a/src/game/client/gui/imutils_button.cc b/src/game/client/gui/imutils_button.cc
new file mode 100644
index 0000000..2017e33
--- /dev/null
+++ b/src/game/client/gui/imutils_button.cc
@@ -0,0 +1,95 @@
+#include "client/pch.hh"
+
+#include "client/gui/imutils_button.hh"
+
+void imutils::button(const char* title, const ImVec2& size, void (*callback)(void))
+{
+ assert(title);
+ assert(callback);
+
+ if(ImGui::Button(title, size)) {
+ callback();
+ }
+}
+
+void imutils::button(const char* title, void (*callback)(void))
+{
+ assert(title);
+ assert(callback);
+
+ if(ImGui::Button(title)) {
+ callback();
+ }
+}
+
+bool imutils::selectable_button(const char* label, const ImVec2& size, bool value)
+{
+ assert(label);
+
+ auto value_changed = false;
+
+ if(value) {
+ ImVec4 button_color(0.750f, 0.750f, 0.750f, 1.000f);
+ ImGui::PushStyleColor(ImGuiCol_Button, button_color);
+ ImGui::PushStyleColor(ImGuiCol_ButtonActive, button_color);
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, button_color);
+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
+ }
+ else {
+ ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
+ }
+
+ if(ImGui::Button(label, size)) {
+ value_changed = true;
+ }
+
+ ImGui::PopStyleColor(value ? 4 : 1);
+
+ return value_changed;
+}
+
+bool imutils::toggle_button(const char* label, const ImVec2& size, bool& value)
+{
+ assert(label);
+
+ auto use_custom_color = !value;
+ auto value_changed = false;
+
+ if(use_custom_color) {
+ ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
+ }
+
+ if(ImGui::Button(label, size)) {
+ value_changed = true;
+ value = !value;
+ }
+
+ if(use_custom_color) {
+ ImGui::PopStyleColor();
+ }
+
+ return value_changed;
+}
+
+bool imutils::toggle_button(const char* label, bool& value)
+{
+ assert(label);
+
+ auto use_custom_color = !value;
+ auto value_changed = false;
+
+ if(use_custom_color) {
+ ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
+ }
+
+ if(ImGui::Button(label)) {
+ value_changed = true;
+ value = !value;
+ }
+
+ if(use_custom_color) {
+ ImGui::PopStyleColor();
+ }
+
+ return value_changed;
+}
diff --git a/src/game/client/gui/imutils_button.hh b/src/game/client/gui/imutils_button.hh
new file mode 100644
index 0000000..0c80694
--- /dev/null
+++ b/src/game/client/gui/imutils_button.hh
@@ -0,0 +1,14 @@
+#pragma once
+
+namespace imutils
+{
+void button(const char* title, const ImVec2& size, void (*callback)(void));
+void button(const char* title, void (*callback)(void));
+} // namespace imutils
+
+namespace imutils
+{
+bool selectable_button(const char* label, const ImVec2& size, bool value);
+bool toggle_button(const char* label, const ImVec2& size, bool& value);
+bool toggle_button(const char* label, bool& value);
+} // namespace imutils
diff --git a/src/game/client/gui/imutils_popup.cc b/src/game/client/gui/imutils_popup.cc
new file mode 100644
index 0000000..f97facb
--- /dev/null
+++ b/src/game/client/gui/imutils_popup.cc
@@ -0,0 +1,56 @@
+#include "client/pch.hh"
+
+#include "client/gui/imutils_popup.hh"
+
+#include "client/globals.hh"
+
+int imutils::popup(const std::string& title, const std::string& question, const std::string* choices, std::size_t num_choices,
+ float font_scale)
+{
+ assert(choices);
+ assert(num_choices);
+
+ int result = POPUP_WAIT;
+
+ ImGui::PushFont(globals::font_unscii16, globals::font_unscii16->LegacySize);
+
+ if(ImGui::BeginPopupModal(title.c_str(), nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) {
+ const auto viewport = ImGui::GetMainViewport();
+ const auto& viewport_size = viewport->Size;
+
+ ImVec2 popup_size(ImGui::GetWindowSize());
+ ImVec2 popup_pos(viewport_size.x * 0.5f - popup_size.x * 0.5f, viewport_size.y * 0.5f - popup_size.y * 0.5f);
+
+ ImGui::PushTextWrapPos(popup_size.x);
+ ImGui::TextUnformatted(question.c_str());
+ ImGui::PopTextWrapPos();
+
+ ImGui::NewLine();
+
+ auto& style = ImGui::GetStyle();
+ auto& spacing = style.ItemSpacing;
+ ImVec2 button_size(0.5f * (ImGui::CalcItemWidth() - spacing.x), 0.0f);
+
+ for(std::size_t i = 0; i < num_choices; ++i) {
+ if(ImGui::Button(choices[i].c_str(), button_size)) {
+ result = static_cast<int>(i);
+ ImGui::CloseCurrentPopup();
+ }
+
+ if((i + 1) % 2 == 1) {
+ ImGui::SameLine();
+ }
+ else if(i + 1 < num_choices) {
+ ImGui::Dummy(ImVec2(0.0, spacing.y));
+ }
+ }
+
+ ImGui::SetWindowPos(popup_pos, ImGuiCond_Always);
+
+ ImGui::EndPopup();
+ }
+
+ ImGui::PopFont();
+
+ return result;
+}
diff --git a/src/game/client/gui/imutils_popup.hh b/src/game/client/gui/imutils_popup.hh
new file mode 100644
index 0000000..1678f87
--- /dev/null
+++ b/src/game/client/gui/imutils_popup.hh
@@ -0,0 +1,11 @@
+#pragma once
+
+/// Returned by popup::show whenever the popup is opened
+/// but there is no user action yet, so the UI should wait
+constexpr static int POPUP_WAIT = -1;
+
+namespace imutils
+{
+int popup(const std::string& title, const std::string& question, const std::string* choices, std::size_t num_choices,
+ float font_scale = 1.75f);
+} // namespace imutils
diff --git a/src/game/client/gui/imutils_text.cc b/src/game/client/gui/imutils_text.cc
new file mode 100644
index 0000000..1058c7f
--- /dev/null
+++ b/src/game/client/gui/imutils_text.cc
@@ -0,0 +1,46 @@
+#include "client/pch.hh"
+
+#include "client/gui/imutils_text.hh"
+
+#include "client/globals.hh"
+
+void imutils::text_nw(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font)
+{
+ assert(list);
+ assert(font);
+
+ imutils::text_nw(list, text, pos, color, shadow, font, font->LegacySize);
+}
+
+void imutils::text_nw(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float size)
+{
+ assert(list);
+ assert(font);
+
+ auto shift = static_cast<float>(globals::gui_scale);
+ auto shadow_pos = ImVec2(pos.x + shift, pos.y + shift);
+
+ list->AddText(font, size, shadow_pos, shadow, text.data(), text.data() + text.size());
+ list->AddText(font, size, pos, color, text.data(), text.data() + text.size());
+}
+
+void imutils::text_wr(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float wrap)
+{
+ assert(list);
+ assert(font);
+
+ imutils::text_wr(list, text, pos, color, shadow, font, wrap, font->LegacySize);
+}
+
+void imutils::text_wr(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float wrap,
+ float size)
+{
+ assert(list);
+ assert(font);
+
+ auto shift = static_cast<float>(globals::gui_scale);
+ auto shadow_pos = ImVec2(pos.x + shift, pos.y + shift);
+
+ list->AddText(font, size, shadow_pos, shadow, text.data(), text.data() + text.size(), wrap);
+ list->AddText(font, size, pos, color, text.data(), text.data() + text.size(), wrap);
+}
diff --git a/src/game/client/gui/imutils_text.hh b/src/game/client/gui/imutils_text.hh
new file mode 100644
index 0000000..64d06a4
--- /dev/null
+++ b/src/game/client/gui/imutils_text.hh
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace imutils
+{
+void text_nw(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font);
+void text_nw(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float size);
+void text_wr(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float wrap);
+void text_wr(ImDrawList* list, std::string_view text, const ImVec2& pos, ImU32 color, ImU32 shadow, ImFont* font, float wrap, float size);
+} // namespace imutils
diff --git a/src/game/client/gui/language.cc b/src/game/client/gui/language.cc
index 0109ae6..8a2d8d1 100644
--- a/src/game/client/gui/language.cc
+++ b/src/game/client/gui/language.cc
@@ -19,20 +19,20 @@ constexpr static std::string_view DEFAULT_LANGUAGE = "en_US";
// system knows what language it can load and will act accordingly
constexpr static std::string_view MANIFEST_PATH = "lang/manifest.json";
-static gui::LanguageManifest manifest;
-static gui::LanguageIterator current_language;
+static LanguageManifest manifest;
+static LanguageIterator current_language;
static std::unordered_map<std::string, std::string> language_map;
-static std::unordered_map<std::string, gui::LanguageIterator> ietf_map;
+static std::unordered_map<std::string, LanguageIterator> ietf_map;
static config::String config_language(DEFAULT_LANGUAGE);
-static void send_language_event(gui::LanguageIterator new_language)
+static void send_language_event(LanguageIterator new_language)
{
- gui::LanguageSetEvent event;
+ LanguageSetEvent event;
event.new_language = new_language;
globals::dispatcher.trigger(event);
}
-void gui::language::init(void)
+void language::init(void)
{
globals::client_config.add_value("language", config_language);
@@ -41,7 +41,7 @@ void gui::language::init(void)
auto file = PHYSFS_openRead(std::string(MANIFEST_PATH).c_str());
if(file == nullptr) {
- spdlog::critical("language: {}: {}", MANIFEST_PATH, io::physfs_error());
+ spdlog::critical("language: {}: {}", MANIFEST_PATH, physfs_error());
std::terminate();
}
@@ -85,19 +85,19 @@ void gui::language::init(void)
current_language = manifest.cend();
}
-void gui::language::init_late(void)
+void language::init_late(void)
{
auto user_language = ietf_map.find(config_language.get_value());
if(user_language != ietf_map.cend()) {
- gui::language::set(user_language->second);
+ language::set(user_language->second);
return;
}
auto fallback = ietf_map.find(std::string(DEFAULT_LANGUAGE));
if(fallback != ietf_map.cend()) {
- gui::language::set(fallback->second);
+ language::set(fallback->second);
return;
}
@@ -106,7 +106,7 @@ void gui::language::init_late(void)
std::terminate();
}
-void gui::language::set(LanguageIterator new_language)
+void language::set(LanguageIterator new_language)
{
if(new_language != manifest.cend()) {
auto path = std::format("lang/lang.{}.json", new_language->ietf);
@@ -114,7 +114,7 @@ void gui::language::set(LanguageIterator new_language)
auto file = PHYSFS_openRead(path.c_str());
if(file == nullptr) {
- spdlog::warn("language: {}: {}", path, io::physfs_error());
+ spdlog::warn("language: {}: {}", path, physfs_error());
send_language_event(new_language);
return;
}
@@ -156,12 +156,12 @@ void gui::language::set(LanguageIterator new_language)
send_language_event(new_language);
}
-gui::LanguageIterator gui::language::get_current(void)
+LanguageIterator language::get_current(void)
{
return current_language;
}
-gui::LanguageIterator gui::language::find(std::string_view ietf)
+LanguageIterator language::find(std::string_view ietf)
{
const auto it = ietf_map.find(std::string(ietf));
if(it != ietf_map.cend()) {
@@ -172,17 +172,17 @@ gui::LanguageIterator gui::language::find(std::string_view ietf)
}
}
-gui::LanguageIterator gui::language::cbegin(void)
+LanguageIterator language::cbegin(void)
{
return manifest.cbegin();
}
-gui::LanguageIterator gui::language::cend(void)
+LanguageIterator language::cend(void)
{
return manifest.cend();
}
-std::string_view gui::language::resolve(std::string_view key)
+std::string_view language::resolve(std::string_view key)
{
const auto it = language_map.find(std::string(key));
@@ -193,10 +193,10 @@ std::string_view gui::language::resolve(std::string_view key)
return key;
}
-std::string gui::language::resolve_gui(std::string_view key)
+std::string language::resolve_gui(std::string_view key)
{
// We need window tags to retain their hierarchy when a language
// dynamically changes; ImGui allows to provide hidden unique identifiers
// to GUI primitives that have their name change dynamically, so we're using this
- return std::format("{}###{}", gui::language::resolve(key), key);
+ return std::format("{}###{}", language::resolve(key), key);
}
diff --git a/src/game/client/gui/language.hh b/src/game/client/gui/language.hh
index 90132d7..20c7520 100644
--- a/src/game/client/gui/language.hh
+++ b/src/game/client/gui/language.hh
@@ -1,7 +1,5 @@
#pragma once
-namespace gui
-{
struct LanguageInfo final {
std::string endonym; // Language's self-name
std::string display; // Display for the settings GUI
@@ -14,29 +12,28 @@ using LanguageIterator = LanguageManifest::const_iterator;
struct LanguageSetEvent final {
LanguageIterator new_language;
};
-} // namespace gui
-namespace gui::language
+namespace language
{
void init(void);
void init_late(void);
-} // namespace gui::language
+} // namespace language
-namespace gui::language
+namespace language
{
void set(LanguageIterator new_language);
-} // namespace gui::language
+} // namespace language
-namespace gui::language
+namespace language
{
LanguageIterator get_current(void);
LanguageIterator find(std::string_view ietf);
LanguageIterator cbegin(void);
LanguageIterator cend(void);
-} // namespace gui::language
+} // namespace language
-namespace gui::language
+namespace language
{
std::string_view resolve(std::string_view key);
std::string resolve_gui(std::string_view key);
-} // namespace gui::language
+} // namespace language
diff --git a/src/game/client/gui/main_menu.cc b/src/game/client/gui/main_menu.cc
index d60a507..d764449 100644
--- a/src/game/client/gui/main_menu.cc
+++ b/src/game/client/gui/main_menu.cc
@@ -9,6 +9,8 @@
#include "core/version.hh"
#include "client/gui/gui_screen.hh"
+#include "client/gui/imutils_button.hh"
+#include "client/gui/imutils_popup.hh"
#include "client/gui/language.hh"
#include "client/gui/window_title.hh"
@@ -19,18 +21,17 @@
#include "client/globals.hh"
#include "client/session.hh"
-constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration;
+static std::string str_button_play;
+static std::string str_button_resume;
+static std::string str_button_settings;
+static std::string str_button_disconnect;
+static std::string str_button_quit;
-static std::string str_play;
-static std::string str_resume;
-static std::string str_settings;
-static std::string str_leave;
-static std::string str_quit;
+static std::string str_quit_popup_title;
+static std::string str_quit_popup_question;
+static std::string str_quit_popup_choices[2];
-static resource_ptr<TextureGUI> title;
-static float title_aspect;
-
-static void on_glfw_key(const io::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) {
@@ -45,127 +46,106 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-static void on_language_set(const gui::LanguageSetEvent& event)
+static void on_language_set(const LanguageSetEvent& event)
{
- str_play = gui::language::resolve_gui("main_menu.play");
- str_resume = gui::language::resolve_gui("main_menu.resume");
- str_settings = gui::language::resolve("main_menu.settings");
- str_leave = gui::language::resolve("main_menu.leave");
- str_quit = gui::language::resolve("main_menu.quit");
+ str_button_play = language::resolve_gui("main_menu.button.play");
+ str_button_resume = language::resolve_gui("main_menu.button.resume");
+ str_button_settings = language::resolve("main_menu.button.settings");
+ str_button_disconnect = language::resolve("main_menu.button.disconnect");
+ str_button_quit = language::resolve("main_menu.button.quit");
+
+ str_quit_popup_title = language::resolve_gui("main_menu.quit_popup.title");
+ str_quit_popup_question = language::resolve("main_menu.quit_popup.question");
+ str_quit_popup_choices[0] = language::resolve_gui("main_menu.quit_popup.choice.yes");
+ str_quit_popup_choices[1] = language::resolve_gui("main_menu.quit_popup.choice.no");
}
-void gui::main_menu::init(void)
+void main_menu::init(void)
{
- title = resource::load<TextureGUI>("textures/gui/menu_title.png", TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T);
-
- if(title == nullptr) {
- spdlog::critical("main_menu: texture load failed");
- std::terminate();
- }
-
- 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);
- }
-
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
globals::dispatcher.sink<LanguageSetEvent>().connect<&on_language_set>();
}
-void gui::main_menu::shutdown(void)
+void main_menu::shutdown(void)
{
- title = nullptr;
+ // empty
}
-void gui::main_menu::layout(void)
+void main_menu::layout(void)
{
const auto viewport = ImGui::GetMainViewport();
- const auto window_start = ImVec2(0.0f, viewport->Size.y * 0.15f);
- const auto window_size = ImVec2(viewport->Size.x, viewport->Size.y);
+ const auto& viewport_size = viewport->Size;
- ImGui::SetNextWindowPos(window_start);
- ImGui::SetNextWindowSize(window_size);
+ ImVec2 margin(globals::gui_scale * 8.0f, globals::gui_scale * 8.0f);
+ ImVec2 control(globals::gui_scale * 256.0f, globals::gui_scale * 32.0f);
- if(ImGui::Begin("###main_menu", nullptr, WINDOW_FLAGS)) {
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 2.0f * globals::gui_scale));
+ ImGui::SetNextWindowPos({});
+ ImGui::SetNextWindowSize(viewport_size);
- if(session::is_ingame()) {
- ImGui::Dummy(ImVec2(0.0f, 32.0f * globals::gui_scale));
- }
- else {
- auto reference_height = 0.225f * window_size.y;
- auto image_width = glm::min(window_size.x, reference_height * title_aspect);
- auto image_height = image_width / title_aspect;
- ImGui::SetCursorPosX(0.5f * (window_size.x - image_width));
- ImGui::Image(title->handle, ImVec2(image_width, image_height));
- }
-
- ImGui::Dummy(ImVec2(0.0f, 24.0f * globals::gui_scale));
-
- const float button_width = 240.0f * globals::gui_scale;
- const float button_xpos = 0.5f * (window_size.x - button_width);
-
- if(session::is_ingame()) {
- ImGui::SetCursorPosX(button_xpos);
-
- if(ImGui::Button(str_resume.c_str(), ImVec2(button_width, 0.0f))) {
- globals::gui_screen = GUI_SCREEN_NONE;
- }
-
- ImGui::Spacing();
- }
- else {
- ImGui::SetCursorPosX(button_xpos);
+ ImGuiWindowFlags flags = 0U;
+ flags |= ImGuiWindowFlags_NoBackground;
+ flags |= ImGuiWindowFlags_NoDecoration;
- if(ImGui::Button(str_play.c_str(), ImVec2(button_width, 0.0f))) {
- globals::gui_screen = GUI_PLAY_MENU;
- }
-
- ImGui::Spacing();
- }
+ if(!ImGui::Begin("###gui::main_menu", nullptr, flags)) {
+ ImGui::End();
+ return;
+ }
- ImGui::SetCursorPosX(button_xpos);
+ ImGui::PushFont(globals::font_unscii16, 16.0f);
+ ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.000f, 0.000f, 0.000f, 0.000f));
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.500f, 0.500f, 0.500f, 0.125f));
+ ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.500f, 0.500f, 0.500f, 0.500f));
+ ImGui::PushStyleVarX(ImGuiStyleVar_FramePadding, 16.0f * globals::gui_scale);
+ ImGui::PushStyleVarX(ImGuiStyleVar_ButtonTextAlign, 0.0f);
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
- if(ImGui::Button(str_settings.c_str(), ImVec2(button_width, 0.0f))) {
- globals::gui_screen = GUI_SETTINGS;
- }
+ ImVec2 cursor_pos(margin.x, viewport_size.y - margin.y);
- ImGui::Spacing();
+ cursor_pos.y -= control.y * 1.5f;
+ ImGui::SetCursorPos(cursor_pos);
- if(session::is_ingame()) {
- ImGui::SetCursorPosX(button_xpos);
+ if(session::is_ingame()) {
+ imutils::button(str_button_disconnect.c_str(), control, [] {
+ session::disconnect("protocol.client_disconnect");
+ });
+ }
+ else {
+ imutils::button(str_button_quit.c_str(), control, [] {
+ ImGui::OpenPopup(str_quit_popup_title.c_str());
+ });
+ }
- if(ImGui::Button(str_leave.c_str(), ImVec2(button_width, 0.0f))) {
- session::disconnect("protocol.client_disconnect");
- globals::gui_screen = GUI_PLAY_MENU;
- gui::window_title::update();
- }
+ cursor_pos.y -= control.y;
+ ImGui::SetCursorPos(cursor_pos);
- ImGui::Spacing();
- }
- else {
- ImGui::SetCursorPosX(button_xpos);
+ imutils::button(str_button_settings.c_str(), control, [] {
+ globals::gui_screen = GUI_SETTINGS;
+ });
- if(ImGui::Button(str_quit.c_str(), ImVec2(button_width, 0.0f))) {
- glfwSetWindowShouldClose(globals::window, true);
- }
+ cursor_pos.y -= control.y * 1.5f;
+ ImGui::SetCursorPos(cursor_pos);
- ImGui::Spacing();
- }
-
- if(!session::is_ingame()) {
- const auto& padding = ImGui::GetStyle().FramePadding;
- const auto& spacing = ImGui::GetStyle().ItemSpacing;
+ if(session::is_ingame()) {
+ imutils::button(str_button_resume.c_str(), control, [] {
+ globals::gui_screen = GUI_SCREEN_NONE;
+ });
+ }
+ else {
+ imutils::button(str_button_play.c_str(), control, [] {
+ globals::gui_screen = GUI_PLAY_MENU;
+ });
+ }
- ImGui::PushFont(globals::font_unscii8, 4.0f);
- ImGui::SetCursorScreenPos(ImVec2(padding.x + spacing.x, window_size.y - ImGui::GetFontSize() - padding.y - spacing.y));
- ImGui::Text("Voxelius %*s", version::full.size(), version::full.data()); // string_view is not always null-terminated
- ImGui::PopFont();
- }
+ ImGui::PopStyleVar(3);
+ ImGui::PopStyleColor(3);
+ ImGui::PopFont();
- ImGui::PopStyleVar();
+ if(0 == imutils::popup(str_quit_popup_title, str_quit_popup_question, str_quit_popup_choices, 2)) {
+ // We don't really have a good way to
+ // pass "i want to quit" boolean to the main loop,
+ // so instead we just raise an external interrupt signal
+ // which handler latches an internal flag in the main loop
+ std::raise(SIGINT);
}
ImGui::End();
diff --git a/src/game/client/gui/main_menu.hh b/src/game/client/gui/main_menu.hh
index 205f078..b5333d4 100644
--- a/src/game/client/gui/main_menu.hh
+++ b/src/game/client/gui/main_menu.hh
@@ -1,8 +1,8 @@
#pragma once
-namespace gui::main_menu
+namespace main_menu
{
void init(void);
void shutdown(void);
void layout(void);
-} // namespace gui::main_menu
+} // namespace main_menu
diff --git a/src/game/client/gui/message_box.cc b/src/game/client/gui/message_box.cc
index 59e2d33..d97267a 100644
--- a/src/game/client/gui/message_box.cc
+++ b/src/game/client/gui/message_box.cc
@@ -10,7 +10,7 @@
constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration;
struct Button final {
- gui::message_box_action action;
+ message_box_action action;
std::string str_title;
};
@@ -18,14 +18,14 @@ static std::string str_title;
static std::string str_subtitle;
static std::vector<Button> buttons;
-void gui::message_box::init(void)
+void message_box::init(void)
{
str_title = std::string();
str_subtitle = std::string();
buttons.clear();
}
-void gui::message_box::layout(void)
+void message_box::layout(void)
{
const auto viewport = ImGui::GetMainViewport();
const auto window_start = ImVec2(0.0f, viewport->Size.y * 0.30f);
@@ -68,27 +68,27 @@ void gui::message_box::layout(void)
ImGui::End();
}
-void gui::message_box::reset(void)
+void message_box::reset(void)
{
str_title.clear();
str_subtitle.clear();
buttons.clear();
}
-void gui::message_box::set_title(std::string_view title)
+void message_box::set_title(std::string_view title)
{
- str_title = gui::language::resolve(title);
+ str_title = language::resolve(title);
}
-void gui::message_box::set_subtitle(std::string_view subtitle)
+void message_box::set_subtitle(std::string_view subtitle)
{
- str_subtitle = gui::language::resolve(subtitle);
+ str_subtitle = language::resolve(subtitle);
}
-void gui::message_box::add_button(std::string_view text, const message_box_action& action)
+void message_box::add_button(std::string_view text, const message_box_action& action)
{
Button button = {};
- button.str_title = std::format("{}###MessageBox_Button{}", gui::language::resolve(text), buttons.size());
+ button.str_title = std::format("{}###MessageBox_Button{}", language::resolve(text), buttons.size());
button.action = action;
buttons.push_back(button);
diff --git a/src/game/client/gui/message_box.hh b/src/game/client/gui/message_box.hh
index 74a6fbf..9da5358 100644
--- a/src/game/client/gui/message_box.hh
+++ b/src/game/client/gui/message_box.hh
@@ -1,20 +1,17 @@
#pragma once
-namespace gui
-{
using message_box_action = void (*)(void);
-} // namespace gui
-namespace gui::message_box
+namespace message_box
{
void init(void);
void layout(void);
void reset(void);
-} // namespace gui::message_box
+} // namespace message_box
-namespace gui::message_box
+namespace message_box
{
void set_title(std::string_view title);
void set_subtitle(std::string_view subtitle);
void add_button(std::string_view text, const message_box_action& action);
-} // namespace gui::message_box
+} // namespace message_box
diff --git a/src/game/client/gui/metrics.cc b/src/game/client/gui/metrics.cc
index bf46649..51b1ffa 100644
--- a/src/game/client/gui/metrics.cc
+++ b/src/game/client/gui/metrics.cc
@@ -15,7 +15,7 @@
#include "client/entity/camera.hh"
-#include "client/gui/imdraw_ext.hh"
+#include "client/gui/imutils_text.hh"
#include "client/game.hh"
#include "client/globals.hh"
@@ -27,13 +27,13 @@ constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground |
static std::basic_string<GLubyte> r_version;
static std::basic_string<GLubyte> r_renderer;
-void gui::metrics::init(void)
+void metrics::init(void)
{
r_version = std::basic_string<GLubyte>(glGetString(GL_VERSION));
r_renderer = std::basic_string<GLubyte>(glGetString(GL_RENDERER));
}
-void gui::metrics::layout(void)
+void metrics::layout(void)
{
if(!session::is_ingame()) {
// Sanity check; we are checking this
@@ -54,50 +54,50 @@ void gui::metrics::layout(void)
// Draw version
auto version_line = std::format("Voxelius {}", version::full);
- gui::imdraw_ext::text_shadow(version_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, version_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += 1.5f * y_step;
// Draw client-side window framerate metrics
auto window_framerate = 1.0f / globals::window_frametime_avg;
auto window_frametime = 1000.0f * globals::window_frametime_avg;
auto window_fps_line = std::format("{:.02f} FPS [{:.02f} ms]", window_framerate, window_frametime);
- gui::imdraw_ext::text_shadow(window_fps_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, window_fps_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
// Draw world rendering metrics
auto drawcall_line = std::format("World: {} DC / {} TRI", globals::num_drawcalls, globals::num_triangles);
- gui::imdraw_ext::text_shadow(drawcall_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, drawcall_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
// Draw OpenGL version string
auto r_version_line = std::format("GL_VERSION: {}", reinterpret_cast<const char*>(r_version.c_str()));
- gui::imdraw_ext::text_shadow(r_version_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, r_version_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
// Draw OpenGL renderer string
auto r_renderer_line = std::format("GL_RENDERER: {}", reinterpret_cast<const char*>(r_renderer.c_str()));
- gui::imdraw_ext::text_shadow(r_renderer_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, r_renderer_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += 1.5f * y_step;
- const auto& head = globals::dimension->entities.get<entity::Head>(globals::player);
- const auto& transform = globals::dimension->entities.get<entity::Transform>(globals::player);
- const auto& velocity = globals::dimension->entities.get<entity::Velocity>(globals::player);
+ const auto& head = globals::dimension->entities.get<Head>(globals::player);
+ const auto& transform = globals::dimension->entities.get<Transform>(globals::player);
+ const auto& velocity = globals::dimension->entities.get<Velocity>(globals::player);
// Draw player voxel position
auto voxel_position = coord::to_voxel(transform.chunk, transform.local);
auto voxel_line = std::format("voxel: [{} {} {}]", voxel_position.x, voxel_position.y, voxel_position.z);
- gui::imdraw_ext::text_shadow(voxel_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, voxel_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
// Draw player world position
auto world_line = std::format("world: [{} {} {}] [{:.03f} {:.03f} {:.03f}]", transform.chunk.x, transform.chunk.y, transform.chunk.z,
transform.local.x, transform.local.y, transform.local.z);
- gui::imdraw_ext::text_shadow(world_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, world_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
// Draw player look angles
auto angles = glm::degrees(transform.angles + head.angles);
auto angle_line = std::format("angle: [{: .03f} {: .03f} {: .03f}]", angles[0], angles[1], angles[2]);
- gui::imdraw_ext::text_shadow(angle_line, position, text_color, shadow_color, globals::font_unscii8, draw_list, font_size);
+ imutils::text_nw(draw_list, angle_line, position, text_color, shadow_color, globals::font_unscii8, font_size);
position.y += y_step;
}
diff --git a/src/game/client/gui/metrics.hh b/src/game/client/gui/metrics.hh
index 4898332..ab09c34 100644
--- a/src/game/client/gui/metrics.hh
+++ b/src/game/client/gui/metrics.hh
@@ -1,7 +1,7 @@
#pragma once
-namespace gui::metrics
+namespace metrics
{
void init(void);
void layout(void);
-} // namespace gui::metrics
+} // namespace metrics
diff --git a/src/game/client/gui/play_menu.cc b/src/game/client/gui/play_menu.cc
index 5b1ecde..ec263a7 100644
--- a/src/game/client/gui/play_menu.cc
+++ b/src/game/client/gui/play_menu.cc
@@ -146,7 +146,7 @@ static void edit_selected_server(void)
static void remove_selected_server(void)
{
- gui::bother::cancel(selected_server->identity);
+ bother::cancel(selected_server->identity);
for(auto it = servers_deque.cbegin(); it != servers_deque.cend(); ++it) {
if(selected_server == (*it)) {
@@ -165,7 +165,7 @@ static void join_selected_server(void)
}
}
-static void on_glfw_key(const io::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) {
@@ -173,14 +173,13 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
if(adding_server) {
remove_selected_server();
}
- else {
- input_itemname.clear();
- input_hostname.clear();
- input_password.clear();
- editing_server = false;
- adding_server = false;
- return;
- }
+
+ input_itemname.clear();
+ input_hostname.clear();
+ input_password.clear();
+ editing_server = false;
+ adding_server = false;
+ return;
}
globals::gui_screen = GUI_MAIN_MENU;
@@ -190,23 +189,23 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-static void on_language_set(const gui::LanguageSetEvent& event)
+static void on_language_set(const LanguageSetEvent& event)
{
- str_tab_servers = gui::language::resolve_gui("play_menu.tab.servers");
-
- str_join = gui::language::resolve_gui("play_menu.join");
- str_connect = gui::language::resolve_gui("play_menu.connect");
- str_add = gui::language::resolve_gui("play_menu.add");
- str_edit = gui::language::resolve_gui("play_menu.edit");
- str_remove = gui::language::resolve_gui("play_menu.remove");
- str_refresh = gui::language::resolve_gui("play_menu.refresh");
-
- str_status_init = gui::language::resolve("play_menu.status.init");
- str_status_ping = gui::language::resolve("play_menu.status.ping");
- str_status_fail = gui::language::resolve("play_menu.status.fail");
+ str_tab_servers = language::resolve_gui("play_menu.tab.servers");
+
+ str_join = language::resolve_gui("play_menu.join");
+ str_connect = language::resolve_gui("play_menu.connect");
+ str_add = language::resolve_gui("play_menu.add");
+ str_edit = language::resolve_gui("play_menu.edit");
+ str_remove = language::resolve_gui("play_menu.remove");
+ str_refresh = language::resolve_gui("play_menu.refresh");
+
+ str_status_init = language::resolve("play_menu.status.init");
+ str_status_ping = language::resolve("play_menu.status.ping");
+ str_status_fail = language::resolve("play_menu.status.fail");
}
-static void on_bother_response(const gui::BotherResponseEvent& event)
+static void on_bother_response(const BotherResponseEvent& event)
{
for(auto item : servers_deque) {
if(item->identity == event.identity) {
@@ -284,7 +283,7 @@ static void layout_server_item(ServerStatusItem* item)
version_color = ImGui::GetColorU32(ImGuiCol_PlotHistogram);
}
- ImGui::PushFont(globals::font_unscii8, 4.0f);
+ ImGui::PushFont(globals::font_unscii8, 8.0f);
std::string version_toast;
@@ -366,7 +365,7 @@ static void layout_server_edit(ServerStatusItem* item)
input_itemname.clear();
input_hostname.clear();
- gui::bother::cancel(item->identity);
+ bother::cancel(item->identity);
}
ImGui::EndDisabled();
@@ -461,14 +460,14 @@ static void layout_servers_buttons(void)
if(item->status != item_status::PINGING) {
if(!editing_server || item != selected_server) {
item->status = item_status::UNKNOWN;
- gui::bother::cancel(item->identity);
+ bother::cancel(item->identity);
}
}
}
}
}
-void gui::play_menu::init(void)
+void play_menu::init(void)
{
if(auto file = PHYSFS_openRead(std::string(SERVERS_TXT).c_str())) {
auto source = std::string(PHYSFS_fileLength(file), char(0x00));
@@ -513,12 +512,12 @@ void gui::play_menu::init(void)
}
}
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
globals::dispatcher.sink<LanguageSetEvent>().connect<&on_language_set>();
globals::dispatcher.sink<BotherResponseEvent>().connect<&on_bother_response>();
}
-void gui::play_menu::shutdown(void)
+void play_menu::shutdown(void)
{
std::ostringstream stream;
@@ -537,7 +536,7 @@ void gui::play_menu::shutdown(void)
servers_deque.clear();
}
-void gui::play_menu::layout(void)
+void play_menu::layout(void)
{
const auto viewport = ImGui::GetMainViewport();
const auto window_start = ImVec2(viewport->Size.x * 0.05f, viewport->Size.y * 0.05f);
@@ -582,11 +581,11 @@ void gui::play_menu::layout(void)
ImGui::End();
}
-void gui::play_menu::update_late(void)
+void play_menu::update_late(void)
{
for(auto item : servers_deque) {
if(item->status == item_status::UNKNOWN) {
- gui::bother::ping(item->identity, item->hostname.c_str(), item->port);
+ bother::ping(item->identity, item->hostname.c_str(), item->port);
item->status = item_status::PINGING;
continue;
}
diff --git a/src/game/client/gui/play_menu.hh b/src/game/client/gui/play_menu.hh
index 1b1f003..5069592 100644
--- a/src/game/client/gui/play_menu.hh
+++ b/src/game/client/gui/play_menu.hh
@@ -1,9 +1,9 @@
#pragma once
-namespace gui::play_menu
+namespace play_menu
{
void init(void);
void shutdown(void);
void layout(void);
void update_late(void);
-} // namespace gui::play_menu
+} // namespace play_menu
diff --git a/src/game/client/gui/progress_bar.cc b/src/game/client/gui/progress_bar.cc
index 1732f72..6cc7fae 100644
--- a/src/game/client/gui/progress_bar.cc
+++ b/src/game/client/gui/progress_bar.cc
@@ -12,16 +12,16 @@ constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground |
static std::string str_title;
static std::string str_button;
-static gui::progress_bar_action button_action;
+static progress_bar_action button_action;
-void gui::progress_bar::init(void)
+void progress_bar::init(void)
{
str_title = "Loading";
str_button = std::string();
button_action = nullptr;
}
-void gui::progress_bar::layout(void)
+void progress_bar::layout(void)
{
const auto viewport = ImGui::GetMainViewport();
const auto window_start = ImVec2(0.0f, viewport->Size.y * 0.30f);
@@ -92,20 +92,20 @@ void gui::progress_bar::layout(void)
ImGui::End();
}
-void gui::progress_bar::reset(void)
+void progress_bar::reset(void)
{
str_title.clear();
str_button.clear();
button_action = nullptr;
}
-void gui::progress_bar::set_title(std::string_view title)
+void progress_bar::set_title(std::string_view title)
{
- str_title = gui::language::resolve(title);
+ str_title = language::resolve(title);
}
-void gui::progress_bar::set_button(std::string_view text, const progress_bar_action& action)
+void progress_bar::set_button(std::string_view text, const progress_bar_action& action)
{
- str_button = std::format("{}###ProgressBar_Button", gui::language::resolve(text));
+ str_button = std::format("{}###ProgressBar_Button", language::resolve(text));
button_action = action;
}
diff --git a/src/game/client/gui/progress_bar.hh b/src/game/client/gui/progress_bar.hh
index 7a0581d..931cad0 100644
--- a/src/game/client/gui/progress_bar.hh
+++ b/src/game/client/gui/progress_bar.hh
@@ -1,19 +1,16 @@
#pragma once
-namespace gui
-{
using progress_bar_action = void (*)(void);
-} // namespace gui
-namespace gui::progress_bar
+namespace progress_bar
{
void init(void);
void layout(void);
-} // namespace gui::progress_bar
+} // namespace progress_bar
-namespace gui::progress_bar
+namespace progress_bar
{
void reset(void);
void set_title(std::string_view title);
void set_button(std::string_view text, const progress_bar_action& action);
-} // namespace gui::progress_bar
+} // namespace progress_bar
diff --git a/src/game/client/gui/scoreboard.cc b/src/game/client/gui/scoreboard.cc
index 4f14de8..efd2d6d 100644
--- a/src/game/client/gui/scoreboard.cc
+++ b/src/game/client/gui/scoreboard.cc
@@ -28,7 +28,7 @@ static void on_scoreboard_update_packet(const protocol::ScoreboardUpdate& packet
max_username_size = 0.0f;
}
-void gui::scoreboard::init(void)
+void scoreboard::init(void)
{
globals::client_config.add_value("scoreboard.key", list_key);
@@ -37,7 +37,7 @@ void gui::scoreboard::init(void)
globals::dispatcher.sink<protocol::ScoreboardUpdate>().connect<&on_scoreboard_update_packet>();
}
-void gui::scoreboard::layout(void)
+void scoreboard::layout(void)
{
if(globals::gui_screen == GUI_SCREEN_NONE && session::is_ingame() && glfwGetKey(globals::window, list_key.get_key()) == GLFW_PRESS) {
const auto viewport = ImGui::GetMainViewport();
diff --git a/src/game/client/gui/scoreboard.hh b/src/game/client/gui/scoreboard.hh
index 320e185..86f8088 100644
--- a/src/game/client/gui/scoreboard.hh
+++ b/src/game/client/gui/scoreboard.hh
@@ -1,7 +1,7 @@
#pragma once
-namespace gui::scoreboard
+namespace scoreboard
{
void init(void);
void layout(void);
-} // namespace gui::scoreboard
+} // namespace scoreboard
diff --git a/src/game/client/gui/settings.cc b/src/game/client/gui/settings.cc
index 70852b2..b456909 100644
--- a/src/game/client/gui/settings.cc
+++ b/src/game/client/gui/settings.cc
@@ -15,6 +15,7 @@
#include "client/config/keybind.hh"
#include "client/gui/gui_screen.hh"
+#include "client/gui/imutils_button.hh"
#include "client/gui/language.hh"
#include "client/io/gamepad.hh"
@@ -25,22 +26,33 @@
constexpr static ImGuiWindowFlags WINDOW_FLAGS = ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration;
constexpr static unsigned int NUM_LOCATIONS = static_cast<unsigned int>(settings_location::COUNT);
+constexpr static const char* TOOLTIP_TEXT = "[?]";
+
+enum class setting_type {
+ CHECKBOX, ///< config::Boolean
+ INPUT_INT, ///< config::Number<int>
+ INPUT_FLOAT, ///< config::Number<float>
+ INPUT_UINT, ///< config::Number<unsigned int>
+ INPUT_STRING, ///< config::String
+ SLIDER_INT, ///< config::Number<int>
+ SLIDER_FLOAT, ///< config::Number<float>
+ SLIDER_UINT, ///< config::Number<unsigned int>
+ STEPPER_INT, ///< config::Number<int>
+ STEPPER_UINT, ///< config::Number<unsigned int>
+ KEYBIND, ///< config::KeyBind
+ GAMEPAD_AXIS, ///< config::GamepadAxis
+ GAMEPAD_BUTTON, ///< config::GamepadButton
+ LANGUAGE_SELECT, ///< config::String internally
+};
-enum class setting_type : unsigned int {
- CHECKBOX = 0x0000U, ///< config::Boolean
- INPUT_INT = 0x0001U, ///< config::Number<int>
- INPUT_FLOAT = 0x0002U, ///< config::Number<float>
- INPUT_UINT = 0x0003U, ///< config::Number<unsigned int>
- INPUT_STRING = 0x0004U, ///< config::String
- SLIDER_INT = 0x0005U, ///< config::Number<int>
- SLIDER_FLOAT = 0x0006U, ///< config::Number<float>
- SLIDER_UINT = 0x0007U, ///< config::Number<unsigned int>
- STEPPER_INT = 0x0008U, ///< config::Number<int>
- STEPPER_UINT = 0x0009U, ///< config::Number<unsigned int>
- KEYBIND = 0x000AU, ///< config::KeyBind
- GAMEPAD_AXIS = 0x000BU, ///< config::GamepadAxis
- GAMEPAD_BUTTON = 0x000CU, ///< config::GamepadButton
- LANGUAGE_SELECT = 0x000DU, ///< config::String internally
+enum class gui_location {
+ GENERAL,
+ BINDINGS,
+ AUDIO,
+ VIDEO,
+ KEYBOARD,
+ MOUSE,
+ GAMEPAD,
};
class SettingValue {
@@ -206,42 +218,41 @@ public:
virtual void layout(void) const override;
};
-static std::string str_checkbox_false;
-static std::string str_checkbox_true;
+static std::string str_label_movement;
+static std::string str_label_gameplay;
+static std::string str_label_miscellaneous;
+static std::string str_label_gui;
+static std::string str_label_levels;
-static std::string str_tab_general;
-static std::string str_tab_input;
-static std::string str_tab_video;
-static std::string str_tab_sound;
+static std::string str_location_general;
+static std::string str_location_video;
+static std::string str_location_audio;
+static std::string str_location_keyboard;
+static std::string str_location_mouse;
+static std::string str_location_gamepad;
-static std::string str_input_keyboard;
-static std::string str_input_gamepad;
-static std::string str_input_mouse;
+static std::string str_separator_settings;
+static std::string str_separator_devices;
-static std::string str_keyboard_movement;
-static std::string str_keyboard_gameplay;
-static std::string str_keyboard_misc;
+static std::string str_checkbox_false;
+static std::string str_checkbox_true;
-static std::string str_gamepad_movement;
-static std::string str_gamepad_gameplay;
-static std::string str_gamepad_misc;
+static std::vector<std::shared_ptr<SettingValue>> values_all;
+static std::vector<std::shared_ptr<SettingValue>> values[NUM_LOCATIONS];
static std::string str_gamepad_axis_prefix;
static std::string str_gamepad_button_prefix;
static std::string str_gamepad_checkbox_tooltip;
-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 gui_location selected_location;
void SettingValue::layout_tooltip(void) const
{
if(has_tooltip) {
- ImGui::SameLine();
- ImGui::TextDisabled("[?]");
+ ImVec2 tooltip_size(ImGui::CalcTextSize(TOOLTIP_TEXT));
+
+ ImGui::SameLine(ImGui::GetWindowWidth() - tooltip_size.x - ImGui::GetStyle().WindowPadding.x);
+ ImGui::TextDisabled(TOOLTIP_TEXT);
if(ImGui::BeginItemTooltip()) {
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 16.0f);
@@ -397,7 +408,7 @@ void SettingValue_StepperInt::refresh_wids(void)
{
for(std::size_t i = 0; i < wids.size(); ++i) {
auto key = std::format("settings.value.{}.{}", name, i);
- wids[i] = std::format("{}###{}", gui::language::resolve(key.c_str()), static_cast<const void*>(value));
+ wids[i] = std::format("{}###{}", language::resolve(key.c_str()), static_cast<const void*>(value));
}
}
@@ -428,7 +439,7 @@ void SettingValue_StepperUnsigned::refresh_wids(void)
{
for(std::size_t i = 0; i < wids.size(); ++i) {
auto key = std::format("settings.value.{}.{}", name, i);
- wids[i] = std::format("{}###{}", gui::language::resolve(key.c_str()), static_cast<const void*>(value));
+ wids[i] = std::format("{}###{}", language::resolve(key.c_str()), static_cast<const void*>(value));
}
}
@@ -509,12 +520,12 @@ void SettingValue_GamepadButton::refresh_wids(void)
void SettingValue_Language::layout(void) const
{
- auto current_language = gui::language::get_current();
+ auto current_language = language::get_current();
if(ImGui::BeginCombo(wid.c_str(), current_language->endonym.c_str())) {
- for(auto it = gui::language::cbegin(); it != gui::language::cend(); ++it) {
+ for(auto it = language::cbegin(); it != language::cend(); ++it) {
if(ImGui::Selectable(it->display.c_str(), it == current_language)) {
- gui::language::set(it);
+ language::set(it);
continue;
}
}
@@ -528,27 +539,27 @@ void SettingValue_Language::layout(void) const
static void refresh_input_wids(void)
{
- for(SettingValue* value : values_all) {
+ for(auto& value : values_all) {
if(value->type == setting_type::KEYBIND) {
- auto keybind = static_cast<SettingValue_KeyBind*>(value);
+ auto keybind = std::static_pointer_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 = std::static_pointer_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 = std::static_pointer_cast<SettingValue_GamepadButton>(value);
gamepad_button->refresh_wids();
}
}
}
-static void on_glfw_key(const io::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) {
@@ -581,7 +592,7 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
}
}
-static void on_gamepad_axis(const io::GamepadAxisEvent& event)
+static void on_gamepad_axis(const GamepadAxisEvent& event)
{
if(globals::gui_gamepad_axis_ptr) {
auto& io = ImGui::GetIO();
@@ -596,7 +607,7 @@ static void on_gamepad_axis(const io::GamepadAxisEvent& event)
}
}
-static void on_gamepad_button(const io::GamepadButtonEvent& event)
+static void on_gamepad_button(const GamepadButtonEvent& event)
{
if(globals::gui_gamepad_button_ptr) {
auto& io = ImGui::GetIO();
@@ -611,56 +622,51 @@ static void on_gamepad_button(const io::GamepadButtonEvent& event)
}
}
-static void on_language_set(const gui::LanguageSetEvent& event)
+static void on_language_set(const LanguageSetEvent& event)
{
- str_checkbox_false = gui::language::resolve("settings.checkbox.false");
- str_checkbox_true = gui::language::resolve("settings.checkbox.true");
-
- str_tab_general = gui::language::resolve("settings.tab.general");
- str_tab_input = gui::language::resolve("settings.tab.input");
- str_tab_video = gui::language::resolve("settings.tab.video");
- str_tab_sound = gui::language::resolve("settings.tab.sound");
-
- str_input_keyboard = gui::language::resolve("settings.input.keyboard");
- str_input_gamepad = gui::language::resolve("settings.input.gamepad");
- str_input_mouse = gui::language::resolve("settings.input.mouse");
-
- str_keyboard_movement = gui::language::resolve("settings.keyboard.movement");
- str_keyboard_gameplay = gui::language::resolve("settings.keyboard.gameplay");
- str_keyboard_misc = gui::language::resolve("settings.keyboard.misc");
-
- str_gamepad_movement = gui::language::resolve("settings.gamepad.movement");
- str_gamepad_gameplay = gui::language::resolve("settings.gamepad.gameplay");
- str_gamepad_misc = gui::language::resolve("settings.gamepad.misc");
-
- str_gamepad_axis_prefix = gui::language::resolve("settings.gamepad.axis");
- str_gamepad_button_prefix = gui::language::resolve("settings.gamepad.button");
- str_gamepad_checkbox_tooltip = gui::language::resolve("settings.gamepad.checkbox_tooltip");
-
- str_video_gui = gui::language::resolve("settings.video.gui");
-
- str_sound_levels = gui::language::resolve("settings.sound.levels");
-
- for(SettingValue* value : values_all) {
+ str_label_movement = language::resolve("settings.label.movement");
+ str_label_gameplay = language::resolve("settings.label.gameplay");
+ str_label_miscellaneous = language::resolve("settings.label.miscellaneous");
+ str_label_gui = language::resolve("settings.label.gui");
+ str_label_levels = language::resolve("settings.label.levels");
+
+ str_location_general = language::resolve_gui("settings.location.general");
+ str_location_keyboard = language::resolve_gui("settings.location.keyboard");
+ str_location_mouse = language::resolve_gui("settings.location.mouse");
+ str_location_gamepad = language::resolve_gui("settings.location.gamepad");
+ str_location_video = language::resolve_gui("settings.location.video");
+ str_location_audio = language::resolve_gui("settings.location.audio");
+
+ str_separator_settings = language::resolve("settings.separator.settings");
+ str_separator_devices = language::resolve("settings.separator.devices");
+
+ str_checkbox_false = language::resolve("settings.checkbox.false");
+ str_checkbox_true = language::resolve("settings.checkbox.true");
+
+ str_gamepad_axis_prefix = language::resolve("settings.gamepad.axis");
+ str_gamepad_button_prefix = language::resolve("settings.gamepad.button");
+ str_gamepad_checkbox_tooltip = language::resolve("settings.gamepad.checkbox_tooltip");
+
+ for(auto value : values_all) {
if(value->type == setting_type::CHECKBOX) {
- auto checkbox = static_cast<SettingValue_CheckBox*>(value);
+ auto checkbox = std::static_pointer_cast<SettingValue_CheckBox>(value);
checkbox->refresh_wids();
}
if(value->type == setting_type::STEPPER_INT) {
- auto stepper = static_cast<SettingValue_StepperInt*>(value);
+ auto stepper = std::static_pointer_cast<SettingValue_StepperInt>(value);
stepper->refresh_wids();
}
if(value->type == setting_type::STEPPER_UINT) {
- auto stepper = static_cast<SettingValue_StepperUnsigned*>(value);
+ auto stepper = std::static_pointer_cast<SettingValue_StepperUnsigned>(value);
stepper->refresh_wids();
}
- value->title = gui::language::resolve(std::format("settings.value.{}", value->name).c_str());
+ value->title = language::resolve(std::format("settings.value.{}", value->name).c_str());
if(value->has_tooltip) {
- value->tooltip = gui::language::resolve(std::format("settings.tooltip.{}", value->name).c_str());
+ value->tooltip = language::resolve(std::format("settings.tooltip.{}", value->name).c_str());
}
}
}
@@ -669,120 +675,32 @@ static void layout_values(settings_location location)
{
ImGui::PushItemWidth(ImGui::CalcItemWidth() * 0.70f);
- for(const SettingValue* value : values[static_cast<unsigned int>(location)]) {
+ for(auto& value : values[static_cast<unsigned int>(location)]) {
value->layout();
}
ImGui::PopItemWidth();
}
-static void layout_general(void)
-{
- if(ImGui::BeginChild("###settings.general.child")) {
- layout_values(settings_location::GENERAL);
- }
-
- ImGui::EndChild();
-}
-
-static void layout_input_keyboard(void)
-{
- if(ImGui::BeginChild("###settings.input.keyboard.child")) {
- ImGui::SeparatorText(str_keyboard_movement.c_str());
- layout_values(settings_location::KEYBOARD_MOVEMENT);
- ImGui::SeparatorText(str_keyboard_gameplay.c_str());
- layout_values(settings_location::KEYBOARD_GAMEPLAY);
- ImGui::SeparatorText(str_keyboard_misc.c_str());
- layout_values(settings_location::KEYBOARD_MISC);
- }
-
- ImGui::EndChild();
-}
-
-static void layout_input_gamepad(void)
-{
- if(ImGui::BeginChild("###settings.input.gamepad.child")) {
- layout_values(settings_location::GAMEPAD);
- ImGui::SeparatorText(str_gamepad_movement.c_str());
- layout_values(settings_location::GAMEPAD_MOVEMENT);
- ImGui::SeparatorText(str_gamepad_gameplay.c_str());
- layout_values(settings_location::GAMEPAD_GAMEPLAY);
- ImGui::SeparatorText(str_gamepad_misc.c_str());
- layout_values(settings_location::GAMEPAD_MISC);
- }
-
- ImGui::EndChild();
-}
-
-static void layout_input_mouse(void)
-{
- if(ImGui::BeginChild("###settings.input.mouse.child")) {
- layout_values(settings_location::MOUSE);
- }
-
- ImGui::EndChild();
-}
-
-static void layout_input(void)
-{
- if(ImGui::BeginTabBar("###settings.input.tabs", ImGuiTabBarFlags_FittingPolicyResizeDown)) {
- if(ImGui::BeginTabItem(str_input_keyboard.c_str())) {
- layout_input_keyboard();
- ImGui::EndTabItem();
- }
-
- if(io::gamepad::available) {
- if(ImGui::BeginTabItem(str_input_gamepad.c_str())) {
- globals::gui_keybind_ptr = nullptr;
- layout_input_gamepad();
- ImGui::EndTabItem();
- }
- }
-
- if(ImGui::BeginTabItem(str_input_mouse.c_str())) {
- globals::gui_keybind_ptr = nullptr;
- layout_input_mouse();
- ImGui::EndTabItem();
- }
-
- ImGui::EndTabBar();
- }
-}
-
-static void layout_video(void)
-{
- if(ImGui::BeginChild("###settings.video.child")) {
- layout_values(settings_location::VIDEO);
- ImGui::SeparatorText(str_video_gui.c_str());
- layout_values(settings_location::VIDEO_GUI);
- }
-
- ImGui::EndChild();
-}
-
-static void layout_sound(void)
+static void layout_location_selectable(const std::string& label, gui_location target_location, const ImVec2& size)
{
- if(ImGui::BeginChild("###settings.sound.child")) {
- layout_values(settings_location::SOUND);
- ImGui::SeparatorText(str_sound_levels.c_str());
- layout_values(settings_location::SOUND_LEVELS);
+ if(imutils::selectable_button(label.c_str(), size, selected_location == target_location)) {
+ selected_location = target_location;
}
-
- ImGui::EndChild();
}
void settings::init(void)
{
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
- globals::dispatcher.sink<io::GamepadAxisEvent>().connect<&on_gamepad_axis>();
- globals::dispatcher.sink<io::GamepadButtonEvent>().connect<&on_gamepad_button>();
- globals::dispatcher.sink<gui::LanguageSetEvent>().connect<&on_language_set>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GamepadAxisEvent>().connect<&on_gamepad_axis>();
+ globals::dispatcher.sink<GamepadButtonEvent>().connect<&on_gamepad_button>();
+ 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) {
+ std::sort(values[i].begin(), values[i].end(), [](const auto& a, const auto& b) {
return a->priority < b->priority;
});
}
@@ -792,68 +710,122 @@ void settings::init_late(void)
void settings::shutdown(void)
{
- 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; ++i) {
+ values[i].clear();
+ }
+
values_all.clear();
}
void settings::layout(void)
{
- const ImGuiViewport* viewport = ImGui::GetMainViewport();
- const ImVec2 window_start = ImVec2(viewport->Size.x * 0.05f, viewport->Size.y * 0.05f);
- const ImVec2 window_size = ImVec2(viewport->Size.x * 0.90f, viewport->Size.y * 0.90f);
+ const auto viewport = ImGui::GetMainViewport();
+ auto window_start = ImVec2(viewport->Size.x * 0.025f, viewport->Size.y * 0.025f);
+ auto window_size = ImVec2(viewport->Size.x * 0.95f, viewport->Size.y * 0.95f);
ImGui::SetNextWindowPos(window_start);
ImGui::SetNextWindowSize(window_size);
- if(ImGui::Begin("###settings", nullptr, WINDOW_FLAGS)) {
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(3.0f * globals::gui_scale, 3.0f * globals::gui_scale));
+ ImGui::PushFont(globals::font_unscii16, 16.0f);
+ ImGui::PushStyleVarX(ImGuiStyleVar_FramePadding, 8.0f * globals::gui_scale);
+ ImGui::PushStyleVarY(ImGuiStyleVar_FramePadding, 3.2f * globals::gui_scale);
- if(ImGui::BeginTabBar("###settings.tabs", ImGuiTabBarFlags_FittingPolicyResizeDown)) {
- if(ImGui::TabItemButton("<<")) {
- globals::gui_screen = GUI_MAIN_MENU;
- globals::gui_keybind_ptr = nullptr;
- }
+ if(ImGui::Begin("###settings.window", nullptr, WINDOW_FLAGS)) {
+ auto sidebar_width = 0.25f * window_size.x;
+ auto draw_list = ImGui::GetWindowDrawList();
+ auto separator_color = ImGui::GetColorU32(ImGuiCol_Text);
- if(ImGui::BeginTabItem(str_tab_general.c_str())) {
- globals::gui_keybind_ptr = nullptr;
- layout_general();
- ImGui::EndTabItem();
- }
+ if(ImGui::BeginChild("###settings.window.sidebar", ImVec2(sidebar_width, -1.0f), 0, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
+ auto selectable_height = 24.0f * globals::gui_scale;
+ auto selectable_size = ImVec2(ImGui::GetContentRegionAvail().x, selectable_height);
- if(ImGui::BeginTabItem(str_tab_input.c_str())) {
- layout_input();
- ImGui::EndTabItem();
- }
+ ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.5f, 0.5f));
- if(ImGui::BeginTabItem(str_tab_video.c_str())) {
- globals::gui_keybind_ptr = nullptr;
- layout_video();
- ImGui::EndTabItem();
- }
+ ImGui::BeginDisabled(globals::gui_gamepad_axis_ptr || globals::gui_gamepad_button_ptr || globals::gui_keybind_ptr);
+
+ if(ImGui::Button("<<###settings.window.back", ImVec2(-1.0f, 0.0f))) {
+ globals::gui_screen = GUI_MAIN_MENU;
- if(globals::sound_ctx && globals::sound_dev) {
- if(ImGui::BeginTabItem(str_tab_sound.c_str())) {
+ if(globals::gui_keybind_ptr) {
+ globals::gui_keybind_ptr->set_key(GLFW_KEY_UNKNOWN);
globals::gui_keybind_ptr = nullptr;
- layout_sound();
- ImGui::EndTabItem();
}
}
- ImGui::EndTabBar();
+ ImGui::SeparatorText(str_separator_settings.c_str());
+ layout_location_selectable(str_location_general, gui_location::GENERAL, selectable_size);
+ layout_location_selectable(str_location_video, gui_location::VIDEO, selectable_size);
+ layout_location_selectable(str_location_audio, gui_location::AUDIO, selectable_size);
+
+ ImGui::SeparatorText(str_separator_devices.c_str());
+ layout_location_selectable(str_location_keyboard, gui_location::KEYBOARD, selectable_size);
+ layout_location_selectable(str_location_mouse, gui_location::MOUSE, selectable_size);
+ layout_location_selectable(str_location_gamepad, gui_location::GAMEPAD, selectable_size);
+
+ ImGui::EndDisabled();
+
+ ImGui::PopStyleVar();
}
- ImGui::PopStyleVar();
+ ImGui::EndChild();
+ ImGui::SameLine();
+
+ if(ImGui::BeginChild("###settings.window.contents", ImVec2(-1.0f, -1.0f), 0, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
+ switch(selected_location) {
+ case gui_location::GENERAL:
+ layout_values(settings_location::GENERAL);
+ break;
+
+ case gui_location::VIDEO:
+ layout_values(settings_location::VIDEO);
+ ImGui::SeparatorText(str_label_gui.c_str());
+ layout_values(settings_location::VIDEO_GUI);
+ break;
+
+ case gui_location::AUDIO:
+ ImGui::BeginDisabled(globals::sound_ctx == nullptr);
+ layout_values(settings_location::SOUND);
+ ImGui::SeparatorText(str_label_levels.c_str());
+ layout_values(settings_location::SOUND_LEVELS);
+ ImGui::EndDisabled();
+ break;
+
+ case gui_location::KEYBOARD:
+ ImGui::SeparatorText(str_label_movement.c_str());
+ layout_values(settings_location::KEYBOARD_MOVEMENT);
+ ImGui::SeparatorText(str_label_gameplay.c_str());
+ layout_values(settings_location::KEYBOARD_GAMEPLAY);
+ ImGui::SeparatorText(str_label_miscellaneous.c_str());
+ layout_values(settings_location::KEYBOARD_MISC);
+ break;
+
+ case gui_location::MOUSE:
+ layout_values(settings_location::MOUSE);
+ break;
+
+ case gui_location::GAMEPAD:
+ ImGui::SeparatorText(str_label_movement.c_str());
+ layout_values(settings_location::GAMEPAD_MOVEMENT);
+ ImGui::SeparatorText(str_label_gameplay.c_str());
+ layout_values(settings_location::GAMEPAD_GAMEPLAY);
+ ImGui::SeparatorText(str_label_miscellaneous.c_str());
+ layout_values(settings_location::GAMEPAD_MISC);
+ break;
+ }
+ }
+
+ ImGui::EndChild();
}
+ ImGui::PopStyleVar(2);
+ ImGui::PopFont();
+
ImGui::End();
}
void settings::add_checkbox(int priority, config::Boolean& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_CheckBox;
+ auto setting_value = std::make_shared<SettingValue_CheckBox>();
setting_value->type = setting_type::CHECKBOX;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -868,7 +840,7 @@ void settings::add_checkbox(int priority, config::Boolean& value, settings_locat
void settings::add_input(int priority, config::Int& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_InputInt;
+ auto setting_value = std::make_shared<SettingValue_InputInt>();
setting_value->type = setting_type::INPUT_INT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -884,7 +856,7 @@ void settings::add_input(int priority, config::Int& value, settings_location loc
void settings::add_input(int priority, config::Float& value, settings_location location, std::string_view name, bool tooltip,
std::string_view fmt)
{
- auto setting_value = new SettingValue_InputFloat;
+ auto setting_value = std::make_shared<SettingValue_InputFloat>();
setting_value->type = setting_type::INPUT_FLOAT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -900,7 +872,7 @@ void settings::add_input(int priority, config::Float& value, settings_location l
void settings::add_input(int priority, config::Unsigned& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_InputUnsigned;
+ auto setting_value = std::make_shared<SettingValue_InputUnsigned>();
setting_value->type = setting_type::INPUT_UINT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -916,7 +888,7 @@ void settings::add_input(int priority, config::Unsigned& value, settings_locatio
void settings::add_input(int priority, config::String& value, settings_location location, std::string_view name, bool tooltip,
bool allow_whitespace)
{
- auto setting_value = new SettingValue_InputString;
+ auto setting_value = std::make_shared<SettingValue_InputString>();
setting_value->type = setting_type::INPUT_STRING;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -932,7 +904,7 @@ void settings::add_input(int priority, config::String& value, settings_location
void settings::add_slider(int priority, config::Int& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_SliderInt;
+ auto setting_value = std::make_shared<SettingValue_SliderInt>();
setting_value->type = setting_type::SLIDER_INT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -948,7 +920,7 @@ void settings::add_slider(int priority, config::Int& value, settings_location lo
void settings::add_slider(int priority, config::Float& value, settings_location location, std::string_view name, bool tooltip,
std::string_view fmt)
{
- auto setting_value = new SettingValue_SliderFloat;
+ auto setting_value = std::make_shared<SettingValue_SliderFloat>();
setting_value->type = setting_type::SLIDER_FLOAT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -964,7 +936,7 @@ void settings::add_slider(int priority, config::Float& value, settings_location
void settings::add_slider(int priority, config::Unsigned& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_SliderUnsigned;
+ auto setting_value = std::make_shared<SettingValue_SliderUnsigned>();
setting_value->type = setting_type::SLIDER_UINT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -979,7 +951,7 @@ void settings::add_slider(int priority, config::Unsigned& value, settings_locati
void settings::add_stepper(int priority, config::Int& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_StepperInt;
+ auto setting_value = std::make_shared<SettingValue_StepperInt>();
setting_value->type = setting_type::STEPPER_INT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -995,7 +967,7 @@ void settings::add_stepper(int priority, config::Int& value, settings_location l
void settings::add_stepper(int priority, config::Unsigned& value, settings_location location, std::string_view name, bool tooltip)
{
- auto setting_value = new SettingValue_StepperUnsigned;
+ auto setting_value = std::make_shared<SettingValue_StepperUnsigned>();
setting_value->type = setting_type::STEPPER_UINT;
setting_value->priority = priority;
setting_value->has_tooltip = tooltip;
@@ -1011,7 +983,7 @@ void settings::add_stepper(int priority, config::Unsigned& value, settings_locat
void settings::add_keybind(int priority, config::KeyBind& value, settings_location location, std::string_view name)
{
- auto setting_value = new SettingValue_KeyBind;
+ auto setting_value = std::make_shared<SettingValue_KeyBind>();
setting_value->type = setting_type::KEYBIND;
setting_value->priority = priority;
setting_value->has_tooltip = false;
@@ -1026,7 +998,7 @@ void settings::add_keybind(int priority, config::KeyBind& value, settings_locati
void settings::add_gamepad_axis(int priority, config::GamepadAxis& value, settings_location location, std::string_view name)
{
- auto setting_value = new SettingValue_GamepadAxis;
+ auto setting_value = std::make_shared<SettingValue_GamepadAxis>();
setting_value->type = setting_type::GAMEPAD_AXIS;
setting_value->priority = priority;
setting_value->has_tooltip = false;
@@ -1041,7 +1013,7 @@ void settings::add_gamepad_axis(int priority, config::GamepadAxis& value, settin
void settings::add_gamepad_button(int priority, config::GamepadButton& value, settings_location location, std::string_view name)
{
- auto setting_value = new SettingValue_GamepadButton;
+ auto setting_value = std::make_shared<SettingValue_GamepadButton>();
setting_value->type = setting_type::GAMEPAD_BUTTON;
setting_value->priority = priority;
setting_value->has_tooltip = false;
@@ -1056,13 +1028,13 @@ void settings::add_gamepad_button(int priority, config::GamepadButton& value, se
void settings::add_language_select(int priority, settings_location location, std::string_view name)
{
- auto setting_value = new SettingValue_Language;
+ auto setting_value = std::make_shared<SettingValue_Language>();
setting_value->type = setting_type::LANGUAGE_SELECT;
setting_value->priority = priority;
setting_value->has_tooltip = false;
setting_value->name = name;
- setting_value->wid = std::format("###{}", static_cast<const void*>(setting_value));
+ setting_value->wid = std::format("###{}", static_cast<const void*>(setting_value.get()));
values[static_cast<unsigned int>(location)].push_back(setting_value);
values_all.push_back(setting_value);
diff --git a/src/game/client/gui/splash.cc b/src/game/client/gui/splash.cc
index fab3ad8..cb035e9 100644
--- a/src/game/client/gui/splash.cc
+++ b/src/game/client/gui/splash.cc
@@ -32,24 +32,24 @@ static float texture_alpha;
static std::uint64_t end_time;
static std::string current_text;
-static void on_glfw_key(const io::GlfwKeyEvent& event)
+static void on_glfw_key(const GlfwKeyEvent& event)
{
end_time = UINT64_C(0);
}
-static void on_glfw_mouse_button(const io::GlfwMouseButtonEvent& event)
+static void on_glfw_mouse_button(const GlfwMouseButtonEvent& event)
{
end_time = UINT64_C(0);
}
-static void on_glfw_scroll(const io::GlfwScrollEvent& event)
+static void on_glfw_scroll(const GlfwScrollEvent& event)
{
end_time = UINT64_C(0);
}
-void gui::client_splash::init(void)
+void client_splash::init(void)
{
- if(io::cmdline::contains("nosplash")) {
+ if(cmdline::contains("nosplash")) {
texture = nullptr;
texture_aspect = 0.0f;
texture_alpha = 0.0f;
@@ -74,7 +74,7 @@ void gui::client_splash::init(void)
}
}
-void gui::client_splash::init_late(void)
+void client_splash::init_late(void)
{
if(!texture) {
// We don't have to waste time
@@ -84,11 +84,11 @@ void gui::client_splash::init_late(void)
end_time = utils::unix_microseconds() + DELAY_MICROSECONDS;
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
- globals::dispatcher.sink<io::GlfwMouseButtonEvent>().connect<&on_glfw_mouse_button>();
- globals::dispatcher.sink<io::GlfwScrollEvent>().connect<&on_glfw_scroll>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwMouseButtonEvent>().connect<&on_glfw_mouse_button>();
+ globals::dispatcher.sink<GlfwScrollEvent>().connect<&on_glfw_scroll>();
- current_text = gui::language::resolve("splash.skip_prompt");
+ current_text = language::resolve("splash.skip_prompt");
while(!glfwWindowShouldClose(globals::window)) {
const std::uint64_t curtime = utils::unix_microseconds();
@@ -100,12 +100,12 @@ void gui::client_splash::init_late(void)
texture_alpha = glm::smoothstep(0.25f, 0.6f, static_cast<float>(remains) / static_cast<float>(DELAY_MICROSECONDS));
- gui::client_splash::render();
+ client_splash::render();
}
- globals::dispatcher.sink<io::GlfwKeyEvent>().disconnect<&on_glfw_key>();
- globals::dispatcher.sink<io::GlfwMouseButtonEvent>().disconnect<&on_glfw_mouse_button>();
- globals::dispatcher.sink<io::GlfwScrollEvent>().disconnect<&on_glfw_scroll>();
+ globals::dispatcher.sink<GlfwKeyEvent>().disconnect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwMouseButtonEvent>().disconnect<&on_glfw_mouse_button>();
+ globals::dispatcher.sink<GlfwScrollEvent>().disconnect<&on_glfw_scroll>();
texture = nullptr;
texture_aspect = 0.0f;
@@ -113,7 +113,7 @@ void gui::client_splash::init_late(void)
end_time = UINT64_C(0);
}
-void gui::client_splash::render(void)
+void client_splash::render(void)
{
if(!texture) {
// We don't have to waste time
@@ -152,7 +152,7 @@ void gui::client_splash::render(void)
const ImVec2 image_pos = ImVec2(image_x, image_y);
if(!current_text.empty()) {
- ImGui::PushFont(globals::font_unscii8, 16.0f);
+ ImGui::PushFont(globals::font_unscii8, 8.0f);
ImGui::SetCursorPos(ImVec2(16.0f, 16.0f));
ImGui::TextDisabled("%s", current_text.c_str());
ImGui::PopFont();
diff --git a/src/game/client/gui/splash.hh b/src/game/client/gui/splash.hh
index 3ce63e4..ca612fe 100644
--- a/src/game/client/gui/splash.hh
+++ b/src/game/client/gui/splash.hh
@@ -1,8 +1,8 @@
#pragma once
-namespace gui::client_splash
+namespace client_splash
{
void init(void);
void init_late(void);
void render(void);
-} // namespace gui::client_splash
+} // namespace client_splash
diff --git a/src/game/client/gui/status_lines.cc b/src/game/client/gui/status_lines.cc
index 74d0dbe..ce661a3 100644
--- a/src/game/client/gui/status_lines.cc
+++ b/src/game/client/gui/status_lines.cc
@@ -2,21 +2,21 @@
#include "client/gui/status_lines.hh"
-#include "client/gui/imdraw_ext.hh"
+#include "client/gui/imutils_text.hh"
#include "client/globals.hh"
-static float line_offsets[gui::STATUS_COUNT];
-static ImFont* line_fonts[gui::STATUS_COUNT];
-static float line_sizes[gui::STATUS_COUNT];
+static float line_offsets[STATUS_COUNT];
+static ImFont* line_fonts[STATUS_COUNT];
+static float line_sizes[STATUS_COUNT];
-static ImVec4 line_text_colors[gui::STATUS_COUNT];
-static ImVec4 line_shadow_colors[gui::STATUS_COUNT];
-static std::string line_strings[gui::STATUS_COUNT];
-static std::uint64_t line_spawns[gui::STATUS_COUNT];
-static float line_fadeouts[gui::STATUS_COUNT];
+static ImVec4 line_text_colors[STATUS_COUNT];
+static ImVec4 line_shadow_colors[STATUS_COUNT];
+static std::string line_strings[STATUS_COUNT];
+static std::uint64_t line_spawns[STATUS_COUNT];
+static float line_fadeouts[STATUS_COUNT];
-void gui::status_lines::init(void)
+void status_lines::init(void)
{
for(unsigned int i = 0U; i < STATUS_COUNT; ++i) {
line_text_colors[i] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
@@ -27,19 +27,19 @@ void gui::status_lines::init(void)
}
}
-void gui::status_lines::init_late(void)
+void status_lines::init_late(void)
{
- line_offsets[STATUS_DEBUG] = 64.0f;
- line_offsets[STATUS_HOTBAR] = 40.0f;
+ line_offsets[STATUS_DEBUG] = 128.0f;
+ line_offsets[STATUS_HOTBAR] = 80.0f;
}
-void gui::status_lines::layout(void)
+void status_lines::layout(void)
{
line_fonts[STATUS_DEBUG] = globals::font_unscii8;
- line_sizes[STATUS_DEBUG] = 4.0f;
+ line_sizes[STATUS_DEBUG] = 8.0f;
line_fonts[STATUS_HOTBAR] = globals::font_unscii16;
- line_sizes[STATUS_HOTBAR] = 8.0f;
+ line_sizes[STATUS_HOTBAR] = 16.0f;
auto viewport = ImGui::GetMainViewport();
auto draw_list = ImGui::GetForegroundDrawList();
@@ -61,11 +61,11 @@ void gui::status_lines::layout(void)
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));
- gui::imdraw_ext::text_shadow(text, pos, color_U32, shadow_U32, font, draw_list, line_sizes[i]);
+ imutils::text_nw(draw_list, text, pos, color_U32, shadow_U32, font, line_sizes[i] * globals::gui_scale);
}
}
-void gui::status_lines::set(unsigned int line, std::string_view text, const ImVec4& color, float fadeout)
+void status_lines::set(unsigned int line, std::string_view 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);
@@ -74,7 +74,7 @@ void gui::status_lines::set(unsigned int line, std::string_view text, const ImVe
line_fadeouts[line] = fadeout;
}
-void gui::status_lines::unset(unsigned int line)
+void status_lines::unset(unsigned int line)
{
line_text_colors[line] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
line_shadow_colors[line] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
diff --git a/src/game/client/gui/status_lines.hh b/src/game/client/gui/status_lines.hh
index 98cbde1..b921947 100644
--- a/src/game/client/gui/status_lines.hh
+++ b/src/game/client/gui/status_lines.hh
@@ -1,21 +1,18 @@
#pragma once
-namespace gui
-{
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;
-} // namespace gui
-namespace gui::status_lines
+namespace status_lines
{
void init(void);
void init_late(void);
void layout(void);
-} // namespace gui::status_lines
+} // namespace status_lines
-namespace gui::status_lines
+namespace status_lines
{
void set(unsigned int line, std::string_view text, const ImVec4& color, float fadeout);
void unset(unsigned int line);
-} // namespace gui::status_lines
+} // namespace status_lines
diff --git a/src/game/client/gui/window_title.cc b/src/game/client/gui/window_title.cc
index 787a7fa..b15f2c5 100644
--- a/src/game/client/gui/window_title.cc
+++ b/src/game/client/gui/window_title.cc
@@ -8,7 +8,7 @@
#include "client/globals.hh"
-void gui::window_title::update(void)
+void window_title::update(void)
{
glfwSetWindowTitle(globals::window, std::format("Voxelius {}: {}", version::triplet, splash::get()).c_str());
}
diff --git a/src/game/client/gui/window_title.hh b/src/game/client/gui/window_title.hh
index af1ab7c..544ed44 100644
--- a/src/game/client/gui/window_title.hh
+++ b/src/game/client/gui/window_title.hh
@@ -1,6 +1,6 @@
#pragma once
-namespace gui::window_title
+namespace window_title
{
void update(void);
-} // namespace gui::window_title
+} // namespace window_title
diff --git a/src/game/client/io/gamepad.cc b/src/game/client/io/gamepad.cc
index 3661769..2c99107 100644
--- a/src/game/client/io/gamepad.cc
+++ b/src/game/client/io/gamepad.cc
@@ -21,16 +21,16 @@ constexpr static float GAMEPAD_AXIS_EVENT_THRESHOLD = 0.5f;
static int active_gamepad_id;
-bool io::gamepad::available = false;
-config::Float io::gamepad::deadzone(0.00f, 0.00f, 0.66f);
-config::Boolean io::gamepad::active(false);
-GLFWgamepadstate io::gamepad::state;
-GLFWgamepadstate io::gamepad::last_state;
+bool gamepad::available = false;
+config::Float gamepad::deadzone(0.00f, 0.00f, 0.66f);
+config::Boolean gamepad::active(false);
+GLFWgamepadstate gamepad::state;
+GLFWgamepadstate gamepad::last_state;
static void on_toggle_enable(const ToggleEnabledEvent& event)
{
if(event.type == TOGGLE_USE_GAMEPAD) {
- io::gamepad::active.set_value(true);
+ gamepad::active.set_value(true);
return;
}
}
@@ -38,23 +38,23 @@ static void on_toggle_enable(const ToggleEnabledEvent& event)
static void on_toggle_disable(const ToggleDisabledEvent& event)
{
if(event.type == TOGGLE_USE_GAMEPAD) {
- io::gamepad::active.set_value(false);
+ gamepad::active.set_value(false);
return;
}
}
-static void on_glfw_joystick_event(const io::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)) {
- io::gamepad::available = true;
+ gamepad::available = true;
active_gamepad_id = event.joystick_id;
- for(int i = 0; i < NUM_AXES; io::gamepad::last_state.axes[i++] = 0.0f) {
+ for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) {
// empty
}
- for(int i = 0; i < NUM_BUTTONS; io::gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
+ for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
// empty
}
@@ -64,15 +64,15 @@ static void on_glfw_joystick_event(const io::GlfwJoystickEvent& event)
}
if((event.event_type == GLFW_DISCONNECTED) && (active_gamepad_id == event.joystick_id)) {
- io::gamepad::available = false;
+ gamepad::available = false;
active_gamepad_id = INVALID_GAMEPAD_ID;
- for(int i = 0; i < NUM_AXES; io::gamepad::last_state.axes[i++] = 0.0f) {
+ for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) {
// empty
}
- for(int i = 0; i < NUM_BUTTONS; io::gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
+ for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
// empty
}
@@ -82,19 +82,19 @@ static void on_glfw_joystick_event(const io::GlfwJoystickEvent& event)
}
}
-void io::gamepad::init(void)
+void gamepad::init(void)
{
- io::gamepad::available = false;
+ gamepad::available = false;
active_gamepad_id = INVALID_GAMEPAD_ID;
- globals::client_config.add_value("gamepad.deadzone", io::gamepad::deadzone);
- globals::client_config.add_value("gamepad.active", io::gamepad::active);
+ globals::client_config.add_value("gamepad.deadzone", gamepad::deadzone);
+ globals::client_config.add_value("gamepad.active", gamepad::active);
- settings::add_checkbox(0, io::gamepad::active, settings_location::GAMEPAD, "gamepad.active", true);
- settings::add_slider(1, io::gamepad::deadzone, settings_location::GAMEPAD, "gamepad.deadzone", true, "%.03f");
+ settings::add_checkbox(0, gamepad::active, settings_location::GAMEPAD, "gamepad.active", true);
+ settings::add_slider(1, gamepad::deadzone, settings_location::GAMEPAD, "gamepad.deadzone", true, "%.03f");
- auto mappings_path = io::cmdline::get_cstr("gpmap", "misc/gamecontrollerdb.txt");
+ auto mappings_path = cmdline::get_cstr("gpmap", "misc/gamecontrollerdb.txt");
auto mappings_file = PHYSFS_openRead(mappings_path);
if(mappings_file) {
@@ -107,15 +107,15 @@ void io::gamepad::init(void)
for(int joystick = 0; joystick <= GLFW_JOYSTICK_LAST; joystick += 1) {
if(glfwJoystickIsGamepad(joystick)) {
- io::gamepad::available = true;
+ gamepad::available = true;
active_gamepad_id = joystick;
- for(int i = 0; i < NUM_AXES; io::gamepad::last_state.axes[i++] = 0.0f) {
+ for(int i = 0; i < NUM_AXES; gamepad::last_state.axes[i++] = 0.0f) {
// empty
}
- for(int i = 0; i < NUM_BUTTONS; io::gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
+ for(int i = 0; i < NUM_BUTTONS; gamepad::last_state.buttons[i++] = GLFW_RELEASE) {
// empty
}
@@ -125,11 +125,11 @@ void io::gamepad::init(void)
}
}
- for(int i = 0; i < NUM_AXES; io::gamepad::state.axes[i++] = 0.0f) {
+ for(int i = 0; i < NUM_AXES; gamepad::state.axes[i++] = 0.0f) {
// empty
}
- for(int i = 0; i < NUM_BUTTONS; io::gamepad::state.buttons[i++] = GLFW_RELEASE) {
+ for(int i = 0; i < NUM_BUTTONS; gamepad::state.buttons[i++] = GLFW_RELEASE) {
// empty
}
@@ -138,17 +138,17 @@ void io::gamepad::init(void)
globals::dispatcher.sink<GlfwJoystickEvent>().connect<&on_glfw_joystick_event>();
}
-void io::gamepad::update_late(void)
+void gamepad::update_late(void)
{
if(active_gamepad_id == INVALID_GAMEPAD_ID) {
// No active gamepad found
return;
}
- if(glfwGetGamepadState(active_gamepad_id, &io::gamepad::state)) {
+ if(glfwGetGamepadState(active_gamepad_id, &gamepad::state)) {
for(int i = 0; i < NUM_AXES; ++i) {
- if((glm::abs(io::gamepad::state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)
- && (glm::abs(io::gamepad::last_state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)) {
+ if((glm::abs(gamepad::state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)
+ && (glm::abs(gamepad::last_state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)) {
GamepadAxisEvent event;
event.action = GLFW_PRESS;
event.axis = i;
@@ -156,8 +156,8 @@ void io::gamepad::update_late(void)
continue;
}
- if((glm::abs(io::gamepad::state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)
- && (glm::abs(io::gamepad::last_state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)) {
+ if((glm::abs(gamepad::state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)
+ && (glm::abs(gamepad::last_state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)) {
GamepadAxisEvent event;
event.action = GLFW_RELEASE;
event.axis = i;
@@ -167,17 +167,17 @@ void io::gamepad::update_late(void)
}
for(int i = 0; i < NUM_BUTTONS; ++i) {
- if(io::gamepad::state.buttons[i] == io::gamepad::last_state.buttons[i]) {
+ if(gamepad::state.buttons[i] == gamepad::last_state.buttons[i]) {
// Nothing happens
continue;
}
GamepadButtonEvent event;
- event.action = io::gamepad::state.buttons[i];
+ event.action = gamepad::state.buttons[i];
event.button = i;
globals::dispatcher.enqueue(event);
}
}
- io::gamepad::last_state = io::gamepad::state;
+ gamepad::last_state = gamepad::state;
}
diff --git a/src/game/client/io/gamepad.hh b/src/game/client/io/gamepad.hh
index 9c56894..5f76277 100644
--- a/src/game/client/io/gamepad.hh
+++ b/src/game/client/io/gamepad.hh
@@ -1,10 +1,7 @@
#pragma once
-namespace io
-{
constexpr static int INVALID_GAMEPAD_AXIS = INT_MAX;
constexpr static int INVALID_GAMEPAD_BUTTON = INT_MAX;
-} // namespace io
namespace config
{
@@ -14,23 +11,21 @@ class Float;
struct GLFWgamepadstate;
-namespace io::gamepad
+namespace gamepad
{
extern bool available;
extern config::Float deadzone;
extern config::Boolean active;
extern GLFWgamepadstate state;
extern GLFWgamepadstate last_state;
-} // namespace io::gamepad
+} // namespace gamepad
-namespace io::gamepad
+namespace gamepad
{
void init(void);
void update_late(void);
-} // namespace io::gamepad
+} // namespace gamepad
-namespace io
-{
// This simulates buttons using axes. When an axis
// value exceeds 1.5 times the deadzone, the event is
// queued with a GLFW_PRESS action, when it falls back
@@ -47,4 +42,3 @@ struct GamepadButtonEvent final {
int action;
int button;
};
-} // namespace io
diff --git a/src/game/client/io/glfw.hh b/src/game/client/io/glfw.hh
index cd6d882..ad445f9 100644
--- a/src/game/client/io/glfw.hh
+++ b/src/game/client/io/glfw.hh
@@ -1,7 +1,5 @@
#pragma once
-namespace io
-{
struct GlfwCursorPosEvent final {
glm::fvec2 pos;
};
@@ -33,4 +31,3 @@ struct GlfwScrollEvent final {
float dx;
float dy;
};
-} // namespace io
diff --git a/src/game/client/main.cc b/src/game/client/main.cc
index c96d4a4..32333db 100644
--- a/src/game/client/main.cc
+++ b/src/game/client/main.cc
@@ -47,7 +47,7 @@ static void on_glfw_cursor_enter(GLFWwindow* window, int entered)
static void on_glfw_cursor_pos(GLFWwindow* window, double xpos, double ypos)
{
- io::GlfwCursorPosEvent event;
+ GlfwCursorPosEvent event;
event.pos.x = static_cast<float>(xpos);
event.pos.y = static_cast<float>(ypos);
globals::dispatcher.trigger(event);
@@ -68,7 +68,7 @@ static void on_glfw_framebuffer_size(GLFWwindow* window, int width, int height)
globals::height = height;
globals::aspect = static_cast<float>(width) / static_cast<float>(height);
- io::GlfwFramebufferSizeEvent fb_event;
+ GlfwFramebufferSizeEvent fb_event;
fb_event.size.x = globals::width;
fb_event.size.y = globals::height;
fb_event.aspect = globals::aspect;
@@ -77,7 +77,7 @@ static void on_glfw_framebuffer_size(GLFWwindow* window, int width, int height)
static void on_glfw_key(GLFWwindow* window, int key, int scancode, int action, int mods)
{
- io::GlfwKeyEvent event;
+ GlfwKeyEvent event;
event.key = key;
event.scancode = scancode;
event.action = action;
@@ -89,7 +89,7 @@ static void on_glfw_key(GLFWwindow* window, int key, int scancode, int action, i
static void on_glfw_joystick(int joystick_id, int event_type)
{
- io::GlfwJoystickEvent event;
+ GlfwJoystickEvent event;
event.joystick_id = joystick_id;
event.event_type = event_type;
globals::dispatcher.trigger(event);
@@ -102,7 +102,7 @@ static void on_glfw_monitor_event(GLFWmonitor* monitor, int event)
static void on_glfw_mouse_button(GLFWwindow* window, int button, int action, int mods)
{
- io::GlfwMouseButtonEvent event;
+ GlfwMouseButtonEvent event;
event.button = button;
event.action = action;
event.mods = mods;
@@ -113,7 +113,7 @@ static void on_glfw_mouse_button(GLFWwindow* window, int button, int action, int
static void on_glfw_scroll(GLFWwindow* window, double dx, double dy)
{
- io::GlfwScrollEvent event;
+ GlfwScrollEvent event;
event.dx = static_cast<float>(dx);
event.dy = static_cast<float>(dy);
globals::dispatcher.trigger(event);
@@ -140,17 +140,17 @@ static void on_termination_signal(int)
int main(int argc, char** argv)
{
- io::cmdline::create(argc, argv);
+ cmdline::create(argc, argv);
#if defined(_WIN32)
#if defined(NDEBUG)
- if(GetConsoleWindow() && !io::cmdline::contains("debug")) {
+ if(GetConsoleWindow() && !cmdline::contains("debug")) {
// Hide the console window on release builds
// unless explicitly specified to preserve it instead
FreeConsole();
}
#else
- if(GetConsoleWindow() && io::cmdline::contains("nodebug")) {
+ if(GetConsoleWindow() && cmdline::contains("nodebug")) {
// Hide the console window on debug builds when
// explicitly specified by the user to hide it
FreeConsole();
@@ -201,7 +201,7 @@ int main(int argc, char** argv)
}
if(GLAD_GL_KHR_debug) {
- if(!io::cmdline::contains("nodebug")) {
+ if(!cmdline::contains("nodebug")) {
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(&on_opengl_message, nullptr);
@@ -261,7 +261,7 @@ int main(int argc, char** argv)
glfwSetWindowIcon(globals::window, 1, &icon_image);
}
- if(io::cmdline::contains("nosound")) {
+ if(cmdline::contains("nosound")) {
spdlog::warn("client: sound disabled [per command line]");
globals::sound_dev = nullptr;
globals::sound_ctx = nullptr;
@@ -298,7 +298,7 @@ int main(int argc, char** argv)
splash::init_client();
- gui::window_title::update();
+ window_title::update();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableGamepad;
@@ -319,7 +319,7 @@ int main(int argc, char** argv)
int vmode_width = DEFAULT_WIDTH;
int vmode_height = DEFAULT_HEIGHT;
- if(auto vmode = io::cmdline::get_cstr("mode")) {
+ if(auto vmode = cmdline::get_cstr("mode")) {
std::sscanf(vmode, "%dx%d", &vmode_width, &vmode_height);
vmode_height = glm::max(vmode_height, MIN_HEIGHT);
vmode_width = glm::max(vmode_width, MIN_WIDTH);
diff --git a/src/game/client/program.cc b/src/game/client/program.cc
index 88cbe28..37cc964 100644
--- a/src/game/client/program.cc
+++ b/src/game/client/program.cc
@@ -78,7 +78,7 @@ bool GL_Program::setup(std::string_view vpath, std::string_view fpath)
auto vfile = PHYSFS_openRead(vert_path.c_str());
if(vfile == nullptr) {
- spdlog::warn("gl_program: {}: {}", vpath, io::physfs_error());
+ spdlog::warn("gl_program: {}: {}", vpath, physfs_error());
return false;
}
@@ -89,7 +89,7 @@ bool GL_Program::setup(std::string_view vpath, std::string_view fpath)
auto ffile = PHYSFS_openRead(frag_path.c_str());
if(ffile == nullptr) {
- spdlog::warn("gl_program: {}: {}", fpath, io::physfs_error());
+ spdlog::warn("gl_program: {}: {}", fpath, physfs_error());
return false;
}
diff --git a/src/game/client/receive.cc b/src/game/client/receive.cc
index a253911..a6fdf8e 100644
--- a/src/game/client/receive.cc
+++ b/src/game/client/receive.cc
@@ -23,7 +23,7 @@
#include "client/globals.hh"
#include "client/session.hh"
-static bool synchronize_entity_id(world::Dimension* dimension, entt::entity entity)
+static bool synchronize_entity_id(Dimension* dimension, entt::entity entity)
{
if(dimension->entities.valid(entity)) {
// Entity ID already exists
@@ -41,12 +41,12 @@ static bool synchronize_entity_id(world::Dimension* dimension, entt::entity enti
spdlog::critical("receive: entity desync: network {} resolved as client {}", static_cast<std::uint64_t>(entity),
static_cast<std::uint64_t>(created));
- gui::message_box::reset();
- gui::message_box::set_title("disconnected.disconnected");
- gui::message_box::set_subtitle("protocol.entity_id_desync");
- gui::message_box::add_button("disconnected.back", [](void) {
+ message_box::reset();
+ message_box::set_title("disconnected.disconnected");
+ message_box::set_subtitle("protocol.entity_id_desync");
+ message_box::add_button("disconnected.back", [](void) {
globals::gui_screen = GUI_PLAY_MENU;
- gui::window_title::update();
+ window_title::update();
});
globals::gui_screen = GUI_MESSAGE_BOX;
@@ -63,7 +63,7 @@ static void on_dimension_info_packet(const protocol::DimensionInfo& packet)
globals::player = entt::null;
}
- globals::dimension = new world::Dimension(packet.name.c_str(), packet.gravity);
+ globals::dimension = new Dimension(packet.name.c_str(), packet.gravity);
}
}
@@ -73,7 +73,7 @@ static void on_chunk_voxels_packet(const protocol::ChunkVoxels& packet)
auto chunk = globals::dimension->create_chunk(packet.chunk);
chunk->set_voxels(packet.voxels);
- world::ChunkUpdateEvent event;
+ ChunkUpdateEvent event;
event.dimension = globals::dimension;
event.cpos = packet.chunk;
event.chunk = chunk;
@@ -88,8 +88,8 @@ 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<entity::Head>(packet.entity);
- auto& prevcomp = globals::dimension->entities.get_or_emplace<entity::client::HeadPrev>(packet.entity);
+ auto& component = globals::dimension->entities.get_or_emplace<Head>(packet.entity);
+ auto& prevcomp = globals::dimension->entities.get_or_emplace<client::HeadPrev>(packet.entity);
// Store the previous component state
prevcomp.angles = component.angles;
@@ -105,8 +105,8 @@ 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<entity::Transform>(packet.entity);
- auto& prevcomp = globals::dimension->entities.get_or_emplace<entity::client::TransformPrev>(packet.entity);
+ auto& component = globals::dimension->entities.get_or_emplace<Transform>(packet.entity);
+ auto& prevcomp = globals::dimension->entities.get_or_emplace<client::TransformPrev>(packet.entity);
// Store the previous component state
prevcomp.angles = component.angles;
@@ -125,7 +125,7 @@ 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<entity::Velocity>(packet.entity);
+ auto& component = globals::dimension->entities.get_or_emplace<Velocity>(packet.entity);
component.value = packet.value;
}
}
@@ -135,7 +135,7 @@ static void on_entity_player_packet(const protocol::EntityPlayer& packet)
{
if(session::peer && globals::dimension) {
if(synchronize_entity_id(globals::dimension, packet.entity)) {
- entity::client::create_player(globals::dimension, packet.entity);
+ client::create_player(globals::dimension, packet.entity);
}
}
}
@@ -144,14 +144,14 @@ static void on_spawn_player_packet(const protocol::SpawnPlayer& packet)
{
if(session::peer && globals::dimension) {
if(synchronize_entity_id(globals::dimension, packet.entity)) {
- entity::client::create_player(globals::dimension, packet.entity);
+ client::create_player(globals::dimension, packet.entity);
globals::player = packet.entity;
globals::gui_screen = GUI_SCREEN_NONE;
- gui::client_chat::refresh_timings();
+ client_chat::refresh_timings();
- gui::window_title::update();
+ window_title::update();
}
}
}
diff --git a/src/game/client/resource/sound_effect.cc b/src/game/client/resource/sound_effect.cc
index 5bbb949..4cc5b70 100644
--- a/src/game/client/resource/sound_effect.cc
+++ b/src/game/client/resource/sound_effect.cc
@@ -35,7 +35,7 @@ static const void* sound_effect_load_func(const char* name, std::uint32_t flags)
auto file = PHYSFS_openRead(name);
if(file == nullptr) {
- spdlog::warn("sfx: {}: {}", name, io::physfs_error());
+ spdlog::warn("sfx: {}: {}", name, physfs_error());
return nullptr;
}
diff --git a/src/game/client/screenshot.cc b/src/game/client/screenshot.cc
index 9b573ef..d704f47 100644
--- a/src/game/client/screenshot.cc
+++ b/src/game/client/screenshot.cc
@@ -24,7 +24,7 @@ static void stbi_png_physfs_callback(void* context, void* data, int size)
PHYSFS_writeBytes(reinterpret_cast<PHYSFS_File*>(context), data, size);
}
-static void on_glfw_key(const io::GlfwKeyEvent& event)
+static void on_glfw_key(const GlfwKeyEvent& event)
{
if(!globals::gui_keybind_ptr && !toggles::is_sequence_await) {
if(screenshot_key.equals(event.key) && (event.action == GLFW_PRESS)) {
@@ -40,7 +40,7 @@ void screenshot::init(void)
settings::add_keybind(0, screenshot_key, settings_location::KEYBOARD_MISC, "key.screenshot");
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
}
void screenshot::take(void)
@@ -77,7 +77,7 @@ void screenshot::take(void)
spdlog::info("screenshot: wrote {}", filepath);
- gui::client_chat::print(std::format("{} {}", gui::language::resolve("chat.screenshot_message"), filename));
+ client_chat::print(std::format("{} {}", language::resolve("chat.screenshot_message"), filename));
PHYSFS_close(file);
}
diff --git a/src/game/client/session.cc b/src/game/client/session.cc
index 36acfb4..94af475 100644
--- a/src/game/client/session.cc
+++ b/src/game/client/session.cc
@@ -57,7 +57,7 @@ static void on_login_response_packet(const protocol::LoginResponse& packet)
set_fixed_tickrate(packet.server_tickrate);
- gui::progress_bar::set_title("connecting.loading_world");
+ progress_bar::set_title("connecting.loading_world");
}
static void on_disconnect_packet(const protocol::Disconnect& packet)
@@ -66,7 +66,7 @@ static void on_disconnect_packet(const protocol::Disconnect& packet)
spdlog::info("session: disconnected: {}", packet.reason);
- gui::client_chat::clear();
+ client_chat::clear();
session::peer = nullptr;
session::client_index = UINT16_MAX;
@@ -82,12 +82,12 @@ static void on_disconnect_packet(const protocol::Disconnect& packet)
globals::player = entt::null;
globals::dimension = nullptr;
- gui::message_box::reset();
- gui::message_box::set_title("disconnected.disconnected");
- gui::message_box::set_subtitle(packet.reason.c_str());
- gui::message_box::add_button("disconnected.back", [](void) {
+ message_box::reset();
+ message_box::set_title("disconnected.disconnected");
+ message_box::set_subtitle(packet.reason.c_str());
+ message_box::add_button("disconnected.back", [](void) {
globals::gui_screen = GUI_PLAY_MENU;
- gui::window_title::update();
+ window_title::update();
});
globals::gui_screen = GUI_MESSAGE_BOX;
@@ -100,18 +100,18 @@ static void on_set_voxel_packet(const protocol::SetVoxel& packet)
auto index = coord::to_index(lpos);
if(auto chunk = globals::dimension->find_chunk(cpos)) {
- auto packet_voxel = world::voxel_registry::find(packet.voxel);
+ auto packet_voxel = voxel_registry::find(packet.voxel);
if(chunk->get_voxel(index) != packet_voxel) {
chunk->set_voxel(packet_voxel, index);
- world::ChunkUpdateEvent event;
+ ChunkUpdateEvent event;
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
+ // up the mesher; directly calling set_voxel
// here would result in a networked feedback loop
// caused by event handler below tripping
globals::dispatcher.trigger(event);
@@ -122,7 +122,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 world::VoxelSetEvent& event)
+static void on_voxel_set(const VoxelSetEvent& event)
{
if(session::peer) {
// Propagate changes to the server
@@ -151,7 +151,7 @@ void session::init(void)
globals::dispatcher.sink<protocol::Disconnect>().connect<&on_disconnect_packet>();
globals::dispatcher.sink<protocol::SetVoxel>().connect<&on_set_voxel_packet>();
- globals::dispatcher.sink<world::VoxelSetEvent>().connect<&on_voxel_set>();
+ globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>();
}
void session::shutdown(void)
@@ -168,18 +168,18 @@ void session::invalidate(void)
if(session::peer) {
enet_peer_reset(session::peer);
- gui::message_box::reset();
- gui::message_box::set_title("disconnected.disconnected");
- gui::message_box::set_subtitle("enet.peer_connection_timeout");
- gui::message_box::add_button("disconnected.back", [](void) {
+ message_box::reset();
+ message_box::set_title("disconnected.disconnected");
+ message_box::set_subtitle("enet.peer_connection_timeout");
+ message_box::add_button("disconnected.back", [](void) {
globals::gui_screen = GUI_PLAY_MENU;
- gui::window_title::update();
+ window_title::update();
});
globals::gui_screen = GUI_MESSAGE_BOX;
}
- gui::client_chat::clear();
+ client_chat::clear();
session::peer = nullptr;
session::client_index = UINT16_MAX;
@@ -215,12 +215,12 @@ void session::connect(std::string_view host, std::uint16_t port, std::string_vie
if(!session::peer) {
server_password_hash = UINT64_MAX;
- gui::message_box::reset();
- gui::message_box::set_title("disconnected.disconnected");
- gui::message_box::set_subtitle("enet.peer_connection_failed");
- gui::message_box::add_button("disconnected.back", [](void) {
+ message_box::reset();
+ message_box::set_title("disconnected.disconnected");
+ message_box::set_subtitle("enet.peer_connection_failed");
+ message_box::add_button("disconnected.back", [](void) {
globals::gui_screen = GUI_PLAY_MENU;
- gui::window_title::update();
+ window_title::update();
});
globals::gui_screen = GUI_MESSAGE_BOX;
@@ -228,9 +228,9 @@ void session::connect(std::string_view host, std::uint16_t port, std::string_vie
return;
}
- gui::progress_bar::reset();
- gui::progress_bar::set_title("connecting.connecting");
- gui::progress_bar::set_button("connecting.cancel_button", [](void) {
+ progress_bar::reset();
+ progress_bar::set_title("connecting.connecting");
+ progress_bar::set_button("connecting.cancel_button", [](void) {
enet_peer_disconnect(session::peer, 0);
session::peer = nullptr;
@@ -279,7 +279,7 @@ void session::disconnect(std::string_view reason)
globals::player = entt::null;
globals::dimension = nullptr;
- gui::client_chat::clear();
+ client_chat::clear();
}
}
@@ -287,8 +287,8 @@ void session::send_login_request(void)
{
protocol::LoginRequest packet;
packet.game_version_major = version::major;
- packet.voxel_registry_checksum = world::voxel_registry::get_checksum();
- packet.item_registry_checksum = world::item_registry::get_checksum();
+ packet.voxel_registry_checksum = voxel_registry::get_checksum();
+ packet.item_registry_checksum = item_registry::get_checksum();
packet.password_hash = server_password_hash;
packet.username = client_game::username.get();
packet.game_version_minor = version::minor;
@@ -298,7 +298,7 @@ void session::send_login_request(void)
server_password_hash = UINT64_MAX;
- gui::progress_bar::set_title("connecting.logging_in");
+ progress_bar::set_title("connecting.logging_in");
globals::gui_screen = GUI_PROGRESS_BAR;
}
diff --git a/src/game/client/sound/sound.cc b/src/game/client/sound/sound.cc
index 7dfe562..11c9286 100644
--- a/src/game/client/sound/sound.cc
+++ b/src/game/client/sound/sound.cc
@@ -157,7 +157,7 @@ void sound::play_generic(resource_ptr<SoundEffect> sound, bool looping, float pi
void sound::play_entity(entt::entity entity, resource_ptr<SoundEffect> sound, bool looping, float pitch)
{
if(globals::dimension && globals::dimension->entities.valid(entity)) {
- if(auto emitter = globals::dimension->entities.try_get<entity::SoundEmitter>(entity)) {
+ if(auto emitter = globals::dimension->entities.try_get<SoundEmitter>(entity)) {
alSourceRewind(emitter->source);
emitter->sound = sound;
diff --git a/src/game/client/toggles.cc b/src/game/client/toggles.cc
index 833e099..60b2f25 100644
--- a/src/game/client/toggles.cc
+++ b/src/game/client/toggles.cc
@@ -27,10 +27,10 @@ static void print_toggle_state(const ToggleInfo& info)
{
if(info.description.size()) {
if(info.is_enabled) {
- gui::client_chat::print(std::format("[toggles] {} ON", info.description));
+ client_chat::print(std::format("[toggles] {} ON", info.description));
}
else {
- gui::client_chat::print(std::format("[toggles] {} OFF", info.description));
+ client_chat::print(std::format("[toggles] {} OFF", info.description));
}
}
}
@@ -49,7 +49,7 @@ static void toggle_value(ToggleInfo& info, toggle_type type)
print_toggle_state(info);
}
-static void on_glfw_key(const io::GlfwKeyEvent& event)
+static void on_glfw_key(const GlfwKeyEvent& event)
{
if(globals::gui_keybind_ptr) {
// The UI keybind subsystem has the authority
@@ -76,7 +76,7 @@ static void on_glfw_key(const io::GlfwKeyEvent& event)
// This causes the language subsystem
// to re-parse the JSON file essentially
// causing the game to soft-reload language
- gui::language::set(gui::language::get_current());
+ language::set(language::get_current());
return;
}
@@ -115,7 +115,7 @@ void toggles::init(void)
toggle_infos[TOGGLE_PM_FLIGHT].glfw_keycode = GLFW_KEY_F;
toggle_infos[TOGGLE_PM_FLIGHT].is_enabled = false;
- globals::dispatcher.sink<io::GlfwKeyEvent>().connect<&on_glfw_key>();
+ globals::dispatcher.sink<GlfwKeyEvent>().connect<&on_glfw_key>();
}
void toggles::init_late(void)
diff --git a/src/game/client/world/chunk_mesher.cc b/src/game/client/world/chunk_mesher.cc
index 5e58760..47ef4cb 100644
--- a/src/game/client/world/chunk_mesher.cc
+++ b/src/game/client/world/chunk_mesher.cc
@@ -19,7 +19,7 @@
#include "client/globals.hh"
#include "client/session.hh"
-using QuadBuilder = std::vector<world::ChunkQuad>;
+using QuadBuilder = std::vector<ChunkQuad>;
using CachedChunkCoord = unsigned short;
constexpr static CachedChunkCoord CPOS_ITSELF = 0x0000;
@@ -65,14 +65,14 @@ public:
virtual void finalize(void) override;
private:
- bool vis_test(const world::Voxel* voxel, const local_pos& lpos) const;
- void push_quad_a(const world::Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, world::VoxelFace face);
- void push_quad_v(const world::Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, world::VoxelFace face, std::size_t entropy);
- void make_cube(const world::Voxel* voxel, const local_pos& lpos, world::VoxelVisBits vis, std::size_t entropy);
+ bool vis_test(const Voxel* voxel, const local_pos& lpos) const;
+ void push_quad_a(const Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, VoxelFace face);
+ void push_quad_v(const Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, VoxelFace face, std::size_t entropy);
+ void make_cube(const Voxel* voxel, const local_pos& lpos, VoxelVisBits vis, std::size_t entropy);
void cache_chunk(const chunk_pos& cpos);
private:
- std::array<world::VoxelStorage, NUM_CACHED_CPOS> m_cache;
+ std::array<VoxelStorage, NUM_CACHED_CPOS> m_cache;
std::vector<QuadBuilder> m_quads_b; // blending
std::vector<QuadBuilder> m_quads_s; // solid
entt::entity m_entity;
@@ -95,8 +95,8 @@ GL_MeshingTask::GL_MeshingTask(entt::entity entity, const chunk_pos& cpos)
void GL_MeshingTask::process(void)
{
- m_quads_b.resize(world::voxel_atlas::plane_count());
- m_quads_s.resize(world::voxel_atlas::plane_count());
+ m_quads_b.resize(voxel_atlas::plane_count());
+ m_quads_s.resize(voxel_atlas::plane_count());
const auto& voxels = m_cache.at(CPOS_ITSELF);
@@ -108,7 +108,7 @@ void GL_MeshingTask::process(void)
}
const auto lpos = coord::to_local(i);
- const auto voxel = world::voxel_registry::find(voxels[i]);
+ const auto voxel = voxel_registry::find(voxels[i]);
if(voxel == nullptr) {
// Either a NULL_VOXEL_ID or something went
@@ -119,27 +119,27 @@ void GL_MeshingTask::process(void)
unsigned int vis = 0U;
if(vis_test(voxel, lpos + DIR_NORTH<local_pos::value_type>)) {
- vis |= world::VVIS_NORTH;
+ vis |= VVIS_NORTH;
}
if(vis_test(voxel, lpos + DIR_SOUTH<local_pos::value_type>)) {
- vis |= world::VVIS_SOUTH;
+ vis |= VVIS_SOUTH;
}
if(vis_test(voxel, lpos + DIR_EAST<local_pos::value_type>)) {
- vis |= world::VVIS_EAST;
+ vis |= VVIS_EAST;
}
if(vis_test(voxel, lpos + DIR_WEST<local_pos::value_type>)) {
- vis |= world::VVIS_WEST;
+ vis |= VVIS_WEST;
}
if(vis_test(voxel, lpos + DIR_UP<local_pos::value_type>)) {
- vis |= world::VVIS_UP;
+ vis |= VVIS_UP;
}
if(vis_test(voxel, lpos + DIR_DOWN<local_pos::value_type>)) {
- vis |= world::VVIS_DOWN;
+ vis |= VVIS_DOWN;
}
const auto vpos = coord::to_voxel(m_cpos, lpos);
@@ -147,7 +147,7 @@ void GL_MeshingTask::process(void)
const auto entropy = math::crc64(&entropy_src, sizeof(entropy_src));
// FIXME: handle different voxel types
- make_cube(voxel, lpos, world::VoxelVisBits(vis), entropy);
+ make_cube(voxel, lpos, VoxelVisBits(vis), entropy);
}
}
@@ -159,7 +159,7 @@ void GL_MeshingTask::finalize(void)
return;
}
- auto& component = globals::dimension->chunks.emplace_or_replace<world::ChunkMesh>(m_entity);
+ auto& component = globals::dimension->chunks.emplace_or_replace<ChunkMesh>(m_entity);
const std::size_t plane_count_nb = m_quads_s.size();
const std::size_t plane_count_b = m_quads_b.size();
@@ -187,7 +187,7 @@ void GL_MeshingTask::finalize(void)
}
glBindBuffer(GL_ARRAY_BUFFER, buffer.handle);
- glBufferData(GL_ARRAY_BUFFER, sizeof(world::ChunkQuad) * builder.size(), builder.data(), GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(ChunkQuad) * builder.size(), builder.data(), GL_STATIC_DRAW);
buffer.size = builder.size();
has_no_submeshes_nb = false;
}
@@ -210,18 +210,18 @@ void GL_MeshingTask::finalize(void)
}
glBindBuffer(GL_ARRAY_BUFFER, buffer.handle);
- glBufferData(GL_ARRAY_BUFFER, sizeof(world::ChunkQuad) * builder.size(), builder.data(), GL_STATIC_DRAW);
+ 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) {
- globals::dimension->chunks.remove<world::ChunkMesh>(m_entity);
+ globals::dimension->chunks.remove<ChunkMesh>(m_entity);
}
}
-bool GL_MeshingTask::vis_test(const world::Voxel* voxel, const local_pos& lpos) const
+bool GL_MeshingTask::vis_test(const Voxel* voxel, const local_pos& lpos) const
{
const auto pvpos = coord::to_voxel(m_cpos, lpos);
const auto pcpos = coord::to_chunk(pvpos);
@@ -230,7 +230,7 @@ bool GL_MeshingTask::vis_test(const world::Voxel* voxel, const local_pos& lpos)
const auto cached_cpos = get_cached_cpos(m_cpos, pcpos);
const auto& voxels = m_cache.at(cached_cpos);
- const auto neighbour = world::voxel_registry::find(voxels[index]);
+ const auto neighbour = voxel_registry::find(voxels[index]);
bool result;
@@ -250,25 +250,24 @@ bool GL_MeshingTask::vis_test(const world::Voxel* voxel, const local_pos& lpos)
return result;
}
-void GL_MeshingTask::push_quad_a(const world::Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, world::VoxelFace face)
+void GL_MeshingTask::push_quad_a(const Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, VoxelFace face)
{
auto cached_offset = voxel->get_cached_face_offset(face);
auto cached_plane = voxel->get_cached_face_plane(face);
auto& textures = voxel->get_face_textures(face);
switch(voxel->get_render_mode()) {
- case world::VRENDER_OPAQUE:
+ case VRENDER_OPAQUE:
m_quads_s[cached_plane].push_back(make_chunk_quad(pos, size, face, cached_offset, textures.size()));
break;
- case world::VRENDER_BLEND:
+ case VRENDER_BLEND:
m_quads_b[cached_plane].push_back(make_chunk_quad(pos, size, face, cached_offset, textures.size()));
break;
}
}
-void GL_MeshingTask::push_quad_v(const world::Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, world::VoxelFace face,
- std::size_t entropy)
+void GL_MeshingTask::push_quad_v(const Voxel* voxel, const glm::fvec3& pos, const glm::fvec2& size, VoxelFace face, std::size_t entropy)
{
auto cached_offset = voxel->get_cached_face_offset(face);
auto cached_plane = voxel->get_cached_face_plane(face);
@@ -276,69 +275,69 @@ void GL_MeshingTask::push_quad_v(const world::Voxel* voxel, const glm::fvec3& po
auto index = entropy % textures.size();
switch(voxel->get_render_mode()) {
- case world::VRENDER_OPAQUE:
+ case VRENDER_OPAQUE:
m_quads_s[cached_plane].push_back(make_chunk_quad(pos, size, face, cached_offset + index, 0));
break;
- case world::VRENDER_BLEND:
+ case VRENDER_BLEND:
m_quads_b[cached_plane].push_back(make_chunk_quad(pos, size, face, cached_offset + index, 0));
break;
}
}
-void GL_MeshingTask::make_cube(const world::Voxel* voxel, const local_pos& lpos, world::VoxelVisBits vis, std::size_t entropy)
+void GL_MeshingTask::make_cube(const Voxel* voxel, const local_pos& lpos, VoxelVisBits vis, std::size_t entropy)
{
const glm::fvec3 fpos = glm::fvec3(lpos);
const glm::fvec2 fsize = glm::fvec2(1.0f, 1.0f);
if(voxel->is_animated()) {
- if(vis & world::VVIS_NORTH) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_NORTH);
+ if(vis & VVIS_NORTH) {
+ push_quad_a(voxel, fpos, fsize, VFACE_NORTH);
}
- if(vis & world::VVIS_SOUTH) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_SOUTH);
+ if(vis & VVIS_SOUTH) {
+ push_quad_a(voxel, fpos, fsize, VFACE_SOUTH);
}
- if(vis & world::VVIS_EAST) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_EAST);
+ if(vis & VVIS_EAST) {
+ push_quad_a(voxel, fpos, fsize, VFACE_EAST);
}
- if(vis & world::VVIS_WEST) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_WEST);
+ if(vis & VVIS_WEST) {
+ push_quad_a(voxel, fpos, fsize, VFACE_WEST);
}
- if(vis & world::VVIS_UP) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_TOP);
+ if(vis & VVIS_UP) {
+ push_quad_a(voxel, fpos, fsize, VFACE_TOP);
}
- if(vis & world::VVIS_DOWN) {
- push_quad_a(voxel, fpos, fsize, world::VFACE_BOTTOM);
+ if(vis & VVIS_DOWN) {
+ push_quad_a(voxel, fpos, fsize, VFACE_BOTTOM);
}
}
else {
- if(vis & world::VVIS_NORTH) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_NORTH, entropy);
+ if(vis & VVIS_NORTH) {
+ push_quad_v(voxel, fpos, fsize, VFACE_NORTH, entropy);
}
- if(vis & world::VVIS_SOUTH) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_SOUTH, entropy);
+ if(vis & VVIS_SOUTH) {
+ push_quad_v(voxel, fpos, fsize, VFACE_SOUTH, entropy);
}
- if(vis & world::VVIS_EAST) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_EAST, entropy);
+ if(vis & VVIS_EAST) {
+ push_quad_v(voxel, fpos, fsize, VFACE_EAST, entropy);
}
- if(vis & world::VVIS_WEST) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_WEST, entropy);
+ if(vis & VVIS_WEST) {
+ push_quad_v(voxel, fpos, fsize, VFACE_WEST, entropy);
}
- if(vis & world::VVIS_UP) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_TOP, entropy);
+ if(vis & VVIS_UP) {
+ push_quad_v(voxel, fpos, fsize, VFACE_TOP, entropy);
}
- if(vis & world::VVIS_DOWN) {
- push_quad_v(voxel, fpos, fsize, world::VFACE_BOTTOM, entropy);
+ if(vis & VVIS_DOWN) {
+ push_quad_v(voxel, fpos, fsize, VFACE_BOTTOM, entropy);
}
}
}
@@ -356,7 +355,7 @@ void GL_MeshingTask::cache_chunk(const chunk_pos& cpos)
// Bogus internal flag component
struct NeedsMeshingComponent final {};
-static void on_chunk_create(const world::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>,
@@ -370,14 +369,14 @@ static void on_chunk_create(const world::ChunkCreateEvent& event)
globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(event.chunk->get_entity());
for(const chunk_pos& cpos : neighbours) {
- if(const world::Chunk* chunk = globals::dimension->find_chunk(cpos)) {
+ 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 world::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>,
@@ -391,14 +390,14 @@ static void on_chunk_update(const world::ChunkUpdateEvent& event)
globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(event.chunk->get_entity());
for(const chunk_pos& cpos : neighbours) {
- if(const world::Chunk* chunk = globals::dimension->find_chunk(cpos)) {
+ 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 world::VoxelSetEvent& event)
+static void on_voxel_set(const VoxelSetEvent& event)
{
globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(event.chunk->get_entity());
@@ -420,25 +419,25 @@ static void on_voxel_set(const world::VoxelSetEvent& event)
}
for(const chunk_pos& cpos : neighbours) {
- if(const world::Chunk* chunk = globals::dimension->find_chunk(cpos)) {
+ if(const Chunk* chunk = globals::dimension->find_chunk(cpos)) {
globals::dimension->chunks.emplace_or_replace<NeedsMeshingComponent>(chunk->get_entity());
continue;
}
}
}
-void world::chunk_mesher::init(void)
+void chunk_mesher::init(void)
{
globals::dispatcher.sink<ChunkCreateEvent>().connect<&on_chunk_create>();
globals::dispatcher.sink<ChunkUpdateEvent>().connect<&on_chunk_update>();
globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>();
}
-void world::chunk_mesher::shutdown(void)
+void chunk_mesher::shutdown(void)
{
}
-void world::chunk_mesher::update(void)
+void chunk_mesher::update(void)
{
if(session::is_ingame()) {
const auto group = globals::dimension->chunks.group<NeedsMeshingComponent>(entt::get<ChunkComponent>);
diff --git a/src/game/client/world/chunk_mesher.hh b/src/game/client/world/chunk_mesher.hh
index cb0c7c5..d3ead5c 100644
--- a/src/game/client/world/chunk_mesher.hh
+++ b/src/game/client/world/chunk_mesher.hh
@@ -2,17 +2,14 @@
#include "client/world/chunk_vbo.hh"
-namespace world
-{
struct ChunkMesh final {
std::vector<ChunkVBO> quad_nb;
std::vector<ChunkVBO> quad_b;
};
-} // namespace world
-namespace world::chunk_mesher
+namespace chunk_mesher
{
void init(void);
void shutdown(void);
void update(void);
-} // namespace world::chunk_mesher
+} // namespace chunk_mesher
diff --git a/src/game/client/world/chunk_quad.hh b/src/game/client/world/chunk_quad.hh
index 01ed5f2..a28193a 100644
--- a/src/game/client/world/chunk_quad.hh
+++ b/src/game/client/world/chunk_quad.hh
@@ -4,15 +4,10 @@
#include "shared/world/voxel_registry.hh"
-namespace world
-{
// [0] XXXXXXXXYYYYYYYYZZZZZZZZWWWWHHHH
// [1] FFFFTTTTTTTTTTTAAAAA------------
using ChunkQuad = std::array<std::uint32_t, 2>;
-} // namespace world
-namespace world
-{
constexpr inline static ChunkQuad make_chunk_quad(const glm::fvec3& position, const glm::fvec2& size, VoxelFace face, std::size_t texture,
std::size_t frames)
{
@@ -38,4 +33,3 @@ constexpr inline static ChunkQuad make_chunk_quad(const glm::fvec3& position, co
return result;
}
-} // namespace world
diff --git a/src/game/client/world/chunk_renderer.cc b/src/game/client/world/chunk_renderer.cc
index 573d1b7..ea85eee 100644
--- a/src/game/client/world/chunk_renderer.cc
+++ b/src/game/client/world/chunk_renderer.cc
@@ -45,7 +45,7 @@ static std::size_t u_quad_textures;
static GLuint quad_vaobj;
static GLuint quad_vbo;
-void world::chunk_renderer::init(void)
+void chunk_renderer::init(void)
{
globals::client_config.add_value("chunk_renderer.depth_sort_chunks", depth_sort_chunks);
@@ -82,14 +82,14 @@ void world::chunk_renderer::init(void)
glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(glm::fvec3), nullptr);
}
-void world::chunk_renderer::shutdown(void)
+void chunk_renderer::shutdown(void)
{
glDeleteBuffers(1, &quad_vbo);
glDeleteVertexArrays(1, &quad_vaobj);
quad_program.destroy();
}
-void world::chunk_renderer::render(void)
+void chunk_renderer::render(void)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
@@ -115,17 +115,17 @@ void world::chunk_renderer::render(void)
GLuint timings[3];
timings[0] = static_cast<GLuint>(globals::window_frametime);
timings[1] = static_cast<GLuint>(globals::window_frametime_avg);
- timings[2] = static_cast<GLuint>(world::voxel_anims::frame);
+ timings[2] = static_cast<GLuint>(voxel_anims::frame);
- const auto group = globals::dimension->chunks.group<ChunkComponent>(entt::get<world::ChunkMesh>);
+ const auto group = globals::dimension->chunks.group<ChunkComponent>(entt::get<ChunkMesh>);
if(depth_sort_chunks.get_value()) {
// FIXME: speed! sorting every frame doesn't look
// like a good idea. Can we store the group elsewhere and
// still have all the up-to-date chunk things inside?
group.sort([](entt::entity ea, entt::entity eb) {
- const auto dir_a = globals::dimension->chunks.get<ChunkComponent>(ea).cpos - entity::camera::position_chunk;
- const auto dir_b = globals::dimension->chunks.get<ChunkComponent>(eb).cpos - entity::camera::position_chunk;
+ 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];
@@ -134,18 +134,18 @@ void world::chunk_renderer::render(void)
});
}
- for(std::size_t plane_id = 0; plane_id < world::voxel_atlas::plane_count(); ++plane_id) {
+ for(std::size_t plane_id = 0; plane_id < voxel_atlas::plane_count(); ++plane_id) {
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D_ARRAY, world::voxel_atlas::plane_texture(plane_id));
+ glBindTexture(GL_TEXTURE_2D_ARRAY, voxel_atlas::plane_texture(plane_id));
glBindVertexArray(quad_vaobj);
glUseProgram(quad_program.handle);
- glUniformMatrix4fv(quad_program.uniforms[u_quad_vproj_matrix].location, 1, false, glm::value_ptr(entity::camera::matrix));
+ glUniformMatrix4fv(quad_program.uniforms[u_quad_vproj_matrix].location, 1, false, glm::value_ptr(camera::matrix));
glUniform3uiv(quad_program.uniforms[u_quad_timings].location, 1, timings);
- glUniform4fv(quad_program.uniforms[u_quad_fog_color].location, 1, glm::value_ptr(world::skybox::fog_color));
+ glUniform4fv(quad_program.uniforms[u_quad_fog_color].location, 1, glm::value_ptr(skybox::fog_color));
glUniform1f(quad_program.uniforms[u_quad_view_distance].location,
- static_cast<GLfloat>(entity::camera::view_distance.get_value() * CHUNK_SIZE));
+ static_cast<GLfloat>(camera::view_distance.get_value() * CHUNK_SIZE));
glUniform1i(quad_program.uniforms[u_quad_textures].location, 0); // GL_TEXTURE0
glDisable(GL_BLEND);
@@ -156,7 +156,7 @@ void world::chunk_renderer::render(void)
for(const auto [entity, chunk, mesh] : group.each()) {
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 - entity::camera::position_chunk);
+ 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);
@@ -177,7 +177,7 @@ void world::chunk_renderer::render(void)
for(const auto [entity, chunk, mesh] : group.each()) {
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 - entity::camera::position_chunk);
+ 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);
@@ -195,11 +195,11 @@ void world::chunk_renderer::render(void)
}
if(toggles::get(TOGGLE_CHUNK_AABB)) {
- world::outline::prepare();
+ outline::prepare();
for(const auto [entity, chunk, mesh] : group.each()) {
const auto size = glm::fvec3(CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE);
- world::outline::cube(chunk.cpos, glm::fvec3(0.0f, 0.0f, 0.0f), size, 1.0f, glm::fvec4(1.0f, 1.0f, 0.0f, 1.0f));
+ outline::cube(chunk.cpos, glm::fvec3(0.0f, 0.0f, 0.0f), size, 1.0f, glm::fvec4(1.0f, 1.0f, 0.0f, 1.0f));
}
}
}
diff --git a/src/game/client/world/chunk_renderer.hh b/src/game/client/world/chunk_renderer.hh
index 2b73225..53272a4 100644
--- a/src/game/client/world/chunk_renderer.hh
+++ b/src/game/client/world/chunk_renderer.hh
@@ -1,8 +1,8 @@
#pragma once
-namespace world::chunk_renderer
+namespace chunk_renderer
{
void init(void);
void shutdown(void);
void render(void);
-} // namespace world::chunk_renderer
+} // namespace chunk_renderer
diff --git a/src/game/client/world/chunk_vbo.hh b/src/game/client/world/chunk_vbo.hh
index 175b34f..da8270e 100644
--- a/src/game/client/world/chunk_vbo.hh
+++ b/src/game/client/world/chunk_vbo.hh
@@ -1,7 +1,5 @@
#pragma once
-namespace world
-{
class ChunkVBO final {
public:
std::size_t size;
@@ -19,4 +17,3 @@ public:
}
}
};
-} // namespace world
diff --git a/src/game/client/world/chunk_visibility.cc b/src/game/client/world/chunk_visibility.cc
index 871c04b..5af2901 100644
--- a/src/game/client/world/chunk_visibility.cc
+++ b/src/game/client/world/chunk_visibility.cc
@@ -23,8 +23,8 @@
// we throttle the client's ever increasing itch for new chunks
constexpr static unsigned int MAX_CHUNKS_REQUESTS_PER_FRAME = 16U;
-static world::ChunkAABB current_view_box;
-static world::ChunkAABB previous_view_box;
+static ChunkAABB current_view_box;
+static ChunkAABB previous_view_box;
static std::vector<chunk_pos> requests;
static void update_requests(void)
@@ -42,16 +42,16 @@ static void update_requests(void)
}
std::sort(requests.begin(), requests.end(), [](const chunk_pos& cpos_a, const chunk_pos& cpos_b) {
- auto da = math::distance2(cpos_a, entity::camera::position_chunk);
- auto db = math::distance2(cpos_b, entity::camera::position_chunk);
+ auto da = math::distance2(cpos_a, camera::position_chunk);
+ auto db = math::distance2(cpos_b, camera::position_chunk);
return da > db;
});
}
-void world::chunk_visibility::update_late(void)
+void chunk_visibility::update_late(void)
{
- current_view_box.min = entity::camera::position_chunk - static_cast<chunk_pos::value_type>(entity::camera::view_distance.get_value());
- current_view_box.max = entity::camera::position_chunk + static_cast<chunk_pos::value_type>(entity::camera::view_distance.get_value());
+ current_view_box.min = camera::position_chunk - static_cast<chunk_pos::value_type>(camera::view_distance.get_value());
+ current_view_box.max = camera::position_chunk + static_cast<chunk_pos::value_type>(camera::view_distance.get_value());
if(!session::is_ingame()) {
// This makes sure the previous view box
diff --git a/src/game/client/world/chunk_visibility.hh b/src/game/client/world/chunk_visibility.hh
index 8d1f3cd..d0b4487 100644
--- a/src/game/client/world/chunk_visibility.hh
+++ b/src/game/client/world/chunk_visibility.hh
@@ -1,6 +1,6 @@
#pragma once
-namespace world::chunk_visibility
+namespace chunk_visibility
{
void update_late(void);
-} // namespace world::chunk_visibility
+} // namespace chunk_visibility
diff --git a/src/game/client/world/outline.cc b/src/game/client/world/outline.cc
index 763debf..d4980c2 100644
--- a/src/game/client/world/outline.cc
+++ b/src/game/client/world/outline.cc
@@ -28,7 +28,7 @@ static GLuint vaobj;
static GLuint cube_vbo;
static GLuint line_vbo;
-void world::outline::init(void)
+void outline::init(void)
{
if(!program.setup("shaders/outline.vert", "shaders/outline.frag")) {
spdlog::critical("outline: program setup failed");
@@ -90,7 +90,7 @@ void world::outline::init(void)
glVertexAttribDivisor(0, 0);
}
-void world::outline::shutdown(void)
+void outline::shutdown(void)
{
glDeleteVertexArrays(1, &vaobj);
glDeleteBuffers(1, &line_vbo);
@@ -98,7 +98,7 @@ void world::outline::shutdown(void)
program.destroy();
}
-void world::outline::prepare(void)
+void outline::prepare(void)
{
program.set_variant_vert(WORLD_CURVATURE, client_game::world_curvature.get_value());
@@ -111,17 +111,17 @@ void world::outline::prepare(void)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glUseProgram(program.handle);
- glUniformMatrix4fv(program.uniforms[u_vpmatrix].location, 1, false, glm::value_ptr(entity::camera::matrix));
- glUniform1f(program.uniforms[u_viewdist].location, static_cast<GLfloat>(CHUNK_SIZE * entity::camera::view_distance.get_value()));
+ glUniformMatrix4fv(program.uniforms[u_vpmatrix].location, 1, false, glm::value_ptr(camera::matrix));
+ glUniform1f(program.uniforms[u_viewdist].location, static_cast<GLfloat>(CHUNK_SIZE * camera::view_distance.get_value()));
glBindVertexArray(vaobj);
glEnableVertexAttribArray(0);
glVertexAttribDivisor(0, 0);
}
-void world::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 - entity::camera::position_chunk;
+ auto patch_cpos = cpos - camera::position_chunk;
glLineWidth(thickness);
@@ -134,9 +134,9 @@ void world::outline::cube(const chunk_pos& cpos, const glm::fvec3& fpos, const g
glDrawArrays(GL_LINES, 0, 24);
}
-void world::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 - entity::camera::position_chunk;
+ auto patch_cpos = cpos - camera::position_chunk;
glLineWidth(thickness);
diff --git a/src/game/client/world/outline.hh b/src/game/client/world/outline.hh
index 2456a32..8fdfdeb 100644
--- a/src/game/client/world/outline.hh
+++ b/src/game/client/world/outline.hh
@@ -2,15 +2,15 @@
#include "shared/types.hh"
-namespace world::outline
+namespace outline
{
void init(void);
void shutdown(void);
void prepare(void);
-} // namespace world::outline
+} // namespace outline
-namespace world::outline
+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);
-} // namespace world::outline
+} // namespace outline
diff --git a/src/game/client/world/player_target.cc b/src/game/client/world/player_target.cc
index 5969381..c8a7583 100644
--- a/src/game/client/world/player_target.cc
+++ b/src/game/client/world/player_target.cc
@@ -16,49 +16,49 @@
constexpr static float MAX_REACH = 16.0f;
-voxel_pos world::player_target::coord;
-voxel_pos world::player_target::normal;
-const world::Voxel* world::player_target::voxel;
+voxel_pos player_target::coord;
+voxel_pos player_target::normal;
+const Voxel* player_target::voxel;
-void world::player_target::init(void)
+void player_target::init(void)
{
- world::player_target::coord = voxel_pos();
- world::player_target::normal = voxel_pos();
- world::player_target::voxel = nullptr;
+ player_target::coord = voxel_pos();
+ player_target::normal = voxel_pos();
+ player_target::voxel = nullptr;
}
-void world::player_target::update(void)
+void player_target::update(void)
{
if(session::is_ingame()) {
- RayDDA ray(globals::dimension, entity::camera::position_chunk, entity::camera::position_local, entity::camera::direction);
+ RayDDA ray(globals::dimension, camera::position_chunk, camera::position_local, camera::direction);
do {
- world::player_target::voxel = ray.step();
+ player_target::voxel = ray.step();
- if(world::player_target::voxel) {
- world::player_target::coord = ray.vpos;
- world::player_target::normal = ray.vnormal;
+ if(player_target::voxel) {
+ player_target::coord = ray.vpos;
+ player_target::normal = ray.vnormal;
break;
}
- world::player_target::coord = voxel_pos();
- world::player_target::normal = voxel_pos();
+ player_target::coord = voxel_pos();
+ player_target::normal = voxel_pos();
} while(ray.distance < MAX_REACH);
}
else {
- world::player_target::voxel = nullptr;
- world::player_target::coord = voxel_pos();
- world::player_target::normal = voxel_pos();
+ player_target::voxel = nullptr;
+ player_target::coord = voxel_pos();
+ player_target::normal = voxel_pos();
}
}
-void world::player_target::render(void)
+void player_target::render(void)
{
- if(world::player_target::voxel && !client_game::hide_hud) {
- auto cpos = coord::to_chunk(world::player_target::coord);
- auto fpos = coord::to_local(world::player_target::coord);
+ if(player_target::voxel && !client_game::hide_hud) {
+ auto cpos = coord::to_chunk(player_target::coord);
+ auto fpos = coord::to_local(player_target::coord);
- world::outline::prepare();
- world::outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f));
+ outline::prepare();
+ outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f));
}
}
diff --git a/src/game/client/world/player_target.hh b/src/game/client/world/player_target.hh
index 175be02..2c8bd22 100644
--- a/src/game/client/world/player_target.hh
+++ b/src/game/client/world/player_target.hh
@@ -2,16 +2,16 @@
#include "shared/world/voxel_registry.hh"
-namespace world::player_target
+namespace player_target
{
extern voxel_pos coord;
extern voxel_pos normal;
extern const Voxel* voxel;
-} // namespace world::player_target
+} // namespace player_target
-namespace world::player_target
+namespace player_target
{
void init(void);
void update(void);
void render(void);
-} // namespace world::player_target
+} // namespace player_target
diff --git a/src/game/client/world/skybox.cc b/src/game/client/world/skybox.cc
index 5e52fa4..393c260 100644
--- a/src/game/client/world/skybox.cc
+++ b/src/game/client/world/skybox.cc
@@ -2,10 +2,10 @@
#include "client/world/skybox.hh"
-glm::fvec3 world::skybox::fog_color;
+glm::fvec3 skybox::fog_color;
-void world::skybox::init(void)
+void skybox::init(void)
{
// https://convertingcolors.com/hex-color-B1F3FF.html
- world::skybox::fog_color = glm::fvec3(0.690f, 0.950f, 1.000f);
+ skybox::fog_color = glm::fvec3(0.690f, 0.950f, 1.000f);
}
diff --git a/src/game/client/world/skybox.hh b/src/game/client/world/skybox.hh
index 40113cd..d90336a 100644
--- a/src/game/client/world/skybox.hh
+++ b/src/game/client/world/skybox.hh
@@ -1,11 +1,11 @@
#pragma once
-namespace world::skybox
+namespace skybox
{
extern glm::fvec3 fog_color;
-} // namespace world::skybox
+} // namespace skybox
-namespace world::skybox
+namespace skybox
{
void init(void);
-} // namespace world::skybox
+} // namespace skybox
diff --git a/src/game/client/world/voxel_anims.cc b/src/game/client/world/voxel_anims.cc
index 3d7cfd4..2286027 100644
--- a/src/game/client/world/voxel_anims.cc
+++ b/src/game/client/world/voxel_anims.cc
@@ -12,22 +12,21 @@
static config::Unsigned base_framerate(16U, 1U, 16U);
-std::uint64_t world::voxel_anims::nextframe = 0U;
-std::uint32_t world::voxel_anims::frame = 0U;
+std::uint64_t voxel_anims::nextframe = 0U;
+std::uint32_t voxel_anims::frame = 0U;
-void world::voxel_anims::init(void)
+void voxel_anims::init(void)
{
globals::client_config.add_value("voxel_anims.base_framerate", base_framerate);
- world::voxel_anims::nextframe = 0U;
- world::voxel_anims::frame = 0U;
+ voxel_anims::nextframe = 0U;
+ voxel_anims::frame = 0U;
}
-void world::voxel_anims::update(void)
+void voxel_anims::update(void)
{
- if(globals::curtime >= world::voxel_anims::nextframe) {
- world::voxel_anims::nextframe = globals::curtime
- + static_cast<std::uint64_t>(1000000.0 / static_cast<float>(base_framerate.get_value()));
- world::voxel_anims::frame += 1U;
+ if(globals::curtime >= voxel_anims::nextframe) {
+ voxel_anims::nextframe = globals::curtime + static_cast<std::uint64_t>(1000000.0 / static_cast<float>(base_framerate.get_value()));
+ voxel_anims::frame += 1U;
}
}
diff --git a/src/game/client/world/voxel_anims.hh b/src/game/client/world/voxel_anims.hh
index 0d8a0d0..63a4fc1 100644
--- a/src/game/client/world/voxel_anims.hh
+++ b/src/game/client/world/voxel_anims.hh
@@ -1,13 +1,13 @@
#pragma once
-namespace world::voxel_anims
+namespace voxel_anims
{
extern std::uint64_t nextframe;
extern std::uint32_t frame;
-} // namespace world::voxel_anims
+} // namespace voxel_anims
-namespace world::voxel_anims
+namespace voxel_anims
{
void init(void);
void update(void);
-} // namespace world::voxel_anims
+} // namespace voxel_anims
diff --git a/src/game/client/world/voxel_atlas.cc b/src/game/client/world/voxel_atlas.cc
index 4307dad..9762998 100644
--- a/src/game/client/world/voxel_atlas.cc
+++ b/src/game/client/world/voxel_atlas.cc
@@ -10,7 +10,7 @@
struct AtlasPlane final {
std::unordered_map<std::size_t, std::size_t> lookup;
- std::vector<world::AtlasStrip> strips;
+ std::vector<AtlasStrip> strips;
std::size_t layer_count_max;
std::size_t layer_count;
std::size_t plane_id;
@@ -46,7 +46,7 @@ static void plane_setup(AtlasPlane& plane)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
-static world::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);
@@ -57,9 +57,9 @@ static world::AtlasStrip* plane_lookup(AtlasPlane& plane, std::size_t hash_value
return nullptr;
}
-static world::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)
{
- world::AtlasStrip strip = {};
+ AtlasStrip strip = {};
strip.offset = plane.layer_count;
strip.plane = plane.plane_id;
@@ -86,7 +86,7 @@ static world::AtlasStrip* plane_new_strip(AtlasPlane& plane, const std::vector<s
return &plane.strips[index];
}
-void world::voxel_atlas::create(int width, int height, std::size_t count)
+void voxel_atlas::create(int width, int height, std::size_t count)
{
GLint max_plane_layers;
@@ -115,7 +115,7 @@ void world::voxel_atlas::create(int width, int height, std::size_t count)
spdlog::debug("voxel_atlas: max_plane_layers={}", max_plane_layers);
}
-void world::voxel_atlas::destroy(void)
+void voxel_atlas::destroy(void)
{
for(const AtlasPlane& plane : planes)
glDeleteTextures(1, &plane.gl_texture);
@@ -124,12 +124,12 @@ void world::voxel_atlas::destroy(void)
planes.clear();
}
-std::size_t world::voxel_atlas::plane_count(void)
+std::size_t voxel_atlas::plane_count(void)
{
return planes.size();
}
-GLuint world::voxel_atlas::plane_texture(std::size_t plane_id)
+GLuint voxel_atlas::plane_texture(std::size_t plane_id)
{
if(plane_id < planes.size()) {
return planes[plane_id].gl_texture;
@@ -139,7 +139,7 @@ GLuint world::voxel_atlas::plane_texture(std::size_t plane_id)
}
}
-void world::voxel_atlas::generate_mipmaps(void)
+void voxel_atlas::generate_mipmaps(void)
{
for(const AtlasPlane& plane : planes) {
glBindTexture(GL_TEXTURE_2D_ARRAY, plane.gl_texture);
@@ -147,7 +147,7 @@ void world::voxel_atlas::generate_mipmaps(void)
}
}
-world::AtlasStrip* world::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);
@@ -170,7 +170,7 @@ world::AtlasStrip* world::voxel_atlas::find_or_load(const std::vector<std::strin
return nullptr;
}
-world::AtlasStrip* world::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);
diff --git a/src/game/client/world/voxel_atlas.hh b/src/game/client/world/voxel_atlas.hh
index 70e8a1e..acfcfbd 100644
--- a/src/game/client/world/voxel_atlas.hh
+++ b/src/game/client/world/voxel_atlas.hh
@@ -1,28 +1,25 @@
#pragma once
-namespace world
-{
struct AtlasStrip final {
std::size_t offset;
std::size_t plane;
};
-} // namespace world
-namespace world::voxel_atlas
+namespace voxel_atlas
{
void create(int width, int height, std::size_t count);
void destroy(void);
-} // namespace world::voxel_atlas
+} // namespace voxel_atlas
-namespace world::voxel_atlas
+namespace voxel_atlas
{
std::size_t plane_count(void);
GLuint plane_texture(std::size_t plane_id);
void generate_mipmaps(void);
-} // namespace world::voxel_atlas
+} // namespace voxel_atlas
-namespace world::voxel_atlas
+namespace voxel_atlas
{
AtlasStrip* find_or_load(const std::vector<std::string>& paths);
AtlasStrip* find(const std::vector<std::string>& paths);
-} // namespace world::voxel_atlas
+} // namespace voxel_atlas
diff --git a/src/game/client/world/voxel_sounds.cc b/src/game/client/world/voxel_sounds.cc
index 42552f5..b60df94 100644
--- a/src/game/client/world/voxel_sounds.cc
+++ b/src/game/client/world/voxel_sounds.cc
@@ -4,21 +4,21 @@
#include "client/resource/sound_effect.hh"
-static std::vector<resource_ptr<SoundEffect>> footsteps_sounds[world::VMAT_COUNT];
+static std::vector<resource_ptr<SoundEffect>> footsteps_sounds[VMAT_COUNT];
static std::mt19937_64 randomizer;
-static void add_footsteps_effect(world::VoxelMaterial material, std::string_view name)
+static void add_footsteps_effect(VoxelMaterial material, std::string_view name)
{
if(auto effect = resource::load<SoundEffect>(name)) {
footsteps_sounds[material].push_back(effect);
}
}
-static resource_ptr<SoundEffect> get_footsteps_effect(world::VoxelMaterial material)
+static resource_ptr<SoundEffect> get_footsteps_effect(VoxelMaterial material)
{
auto surface_index = static_cast<std::size_t>(material);
- if(surface_index >= world::VMAT_COUNT) {
+ if(surface_index >= VMAT_COUNT) {
// Surface index out of range
return nullptr;
}
@@ -34,7 +34,7 @@ static resource_ptr<SoundEffect> get_footsteps_effect(world::VoxelMaterial mater
return sounds.at(dist(randomizer));
}
-void world::voxel_sounds::init(void)
+void voxel_sounds::init(void)
{
add_footsteps_effect(VMAT_DEFAULT, "sounds/surface/default1.wav");
add_footsteps_effect(VMAT_DEFAULT, "sounds/surface/default2.wav");
@@ -57,14 +57,14 @@ void world::voxel_sounds::init(void)
add_footsteps_effect(VMAT_WOOD, "sounds/surface/wood3.wav");
}
-void world::voxel_sounds::shutdown(void)
+void voxel_sounds::shutdown(void)
{
- for(std::size_t i = 0; i < world::VMAT_COUNT; ++i) {
+ for(std::size_t i = 0; i < VMAT_COUNT; ++i) {
footsteps_sounds[i].clear();
}
}
-resource_ptr<SoundEffect> world::voxel_sounds::get_footsteps(world::VoxelMaterial material)
+resource_ptr<SoundEffect> voxel_sounds::get_footsteps(VoxelMaterial material)
{
if(auto effect = get_footsteps_effect(material)) {
return effect;
@@ -77,7 +77,7 @@ resource_ptr<SoundEffect> world::voxel_sounds::get_footsteps(world::VoxelMateria
return nullptr;
}
-resource_ptr<SoundEffect> world::voxel_sounds::get_placebreak(world::VoxelMaterial material)
+resource_ptr<SoundEffect> voxel_sounds::get_placebreak(VoxelMaterial material)
{
return nullptr;
}
diff --git a/src/game/client/world/voxel_sounds.hh b/src/game/client/world/voxel_sounds.hh
index dc02cbd..1b14698 100644
--- a/src/game/client/world/voxel_sounds.hh
+++ b/src/game/client/world/voxel_sounds.hh
@@ -6,14 +6,14 @@
struct SoundEffect;
-namespace world::voxel_sounds
+namespace voxel_sounds
{
void init(void);
void shutdown(void);
-} // namespace world::voxel_sounds
+} // namespace voxel_sounds
-namespace world::voxel_sounds
+namespace voxel_sounds
{
resource_ptr<SoundEffect> get_footsteps(VoxelMaterial material);
resource_ptr<SoundEffect> get_placebreak(VoxelMaterial material);
-} // namespace world::voxel_sounds
+} // namespace voxel_sounds
diff --git a/src/game/server/game.cc b/src/game/server/game.cc
index 3a13690..deb7d68 100644
--- a/src/game/server/game.cc
+++ b/src/game/server/game.cc
@@ -66,12 +66,12 @@ void server_game::init(void)
server_chat::init();
server_recieve::init();
- world::worldgen::init();
+ worldgen::init();
- world::unloader::init();
- world::universe::init();
+ unloader::init();
+ universe::init();
- world::random_tick::init();
+ random_tick::init();
}
void server_game::init_late(void)
@@ -99,8 +99,8 @@ void server_game::init_late(void)
game_voxels::populate();
game_items::populate();
- world::unloader::init_late();
- world::universe::init_late();
+ unloader::init_late();
+ universe::init_late();
sessions::init_post_universe();
}
@@ -119,21 +119,21 @@ void server_game::shutdown(void)
enet_host_service(globals::server_host, nullptr, 500);
enet_host_destroy(globals::server_host);
- world::universe::shutdown();
+ universe::shutdown();
}
void server_game::fixed_update(void)
{
// FIXME: threading
for(auto dimension : globals::dimensions) {
- entity::Collision::fixed_update(dimension.second);
- entity::Velocity::fixed_update(dimension.second);
- entity::Transform::fixed_update(dimension.second);
- entity::Gravity::fixed_update(dimension.second);
- entity::Stasis::fixed_update(dimension.second);
-
- for(auto [entity, component] : dimension.second->chunks.view<world::ChunkComponent>().each()) {
- world::random_tick::tick(component.cpos, component.chunk);
+ Collision::fixed_update(dimension.second);
+ Velocity::fixed_update(dimension.second);
+ Transform::fixed_update(dimension.second);
+ Gravity::fixed_update(dimension.second);
+ Stasis::fixed_update(dimension.second);
+
+ for(auto [entity, component] : dimension.second->chunks.view<ChunkComponent>().each()) {
+ random_tick::tick(component.cpos, component.chunk);
}
}
}
@@ -158,6 +158,6 @@ void server_game::fixed_update_late(void)
// FIXME: threading
for(auto dimension : globals::dimensions) {
- world::unloader::fixed_update_late(dimension.second);
+ unloader::fixed_update_late(dimension.second);
}
}
diff --git a/src/game/server/globals.cc b/src/game/server/globals.cc
index 7d79e4d..12fce4a 100644
--- a/src/game/server/globals.cc
+++ b/src/game/server/globals.cc
@@ -6,7 +6,7 @@
#include "shared/protocol.hh"
-io::ConfigMap globals::server_config;
+ConfigMap globals::server_config;
ENetHost* globals::server_host;
@@ -14,5 +14,5 @@ bool globals::is_running;
unsigned int globals::tickrate;
std::uint64_t globals::tickrate_dt;
-world::Dimension* globals::spawn_dimension;
-std::unordered_map<std::string, world::Dimension*> globals::dimensions;
+Dimension* globals::spawn_dimension;
+std::unordered_map<std::string, Dimension*> globals::dimensions;
diff --git a/src/game/server/globals.hh b/src/game/server/globals.hh
index b684d3b..80e84bb 100644
--- a/src/game/server/globals.hh
+++ b/src/game/server/globals.hh
@@ -2,19 +2,13 @@
#include "shared/globals.hh"
-namespace io
-{
class ConfigMap;
-} // namespace io
-namespace world
-{
class Dimension;
-} // namespace world
namespace globals
{
-extern io::ConfigMap server_config;
+extern ConfigMap server_config;
extern ENetHost* server_host;
@@ -22,6 +16,6 @@ extern bool is_running;
extern unsigned int tickrate;
extern std::uint64_t tickrate_dt;
-extern world::Dimension* spawn_dimension;
-extern std::unordered_map<std::string, world::Dimension*> dimensions;
+extern Dimension* spawn_dimension;
+extern std::unordered_map<std::string, Dimension*> dimensions;
} // namespace globals
diff --git a/src/game/server/main.cc b/src/game/server/main.cc
index cf265a4..181145f 100644
--- a/src/game/server/main.cc
+++ b/src/game/server/main.cc
@@ -31,7 +31,7 @@ static void on_termination_signal(int)
int main(int argc, char** argv)
{
- io::cmdline::create(argc, argv);
+ cmdline::create(argc, argv);
shared_game::init(argc, argv, "voxelius-server.log");
diff --git a/src/game/server/receive.cc b/src/game/server/receive.cc
index b804450..a3ce14b 100644
--- a/src/game/server/receive.cc
+++ b/src/game/server/receive.cc
@@ -27,7 +27,7 @@ static void on_entity_transform_packet(const protocol::EntityTransform& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Transform>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Transform>(session->player_entity);
component.angles = packet.angles;
component.chunk = packet.chunk;
component.local = packet.local;
@@ -49,7 +49,7 @@ static void on_entity_velocity_packet(const protocol::EntityVelocity& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Velocity>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Velocity>(session->player_entity);
component.value = packet.value;
protocol::EntityVelocity response;
@@ -67,7 +67,7 @@ static void on_entity_head_packet(const protocol::EntityHead& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Head>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Head>(session->player_entity);
component.angles = packet.angles;
protocol::EntityHead response;
@@ -84,12 +84,12 @@ static void on_entity_head_packet(const protocol::EntityHead& packet)
static void on_set_voxel_packet(const protocol::SetVoxel& packet)
{
if(auto session = sessions::find(packet.peer)) {
- if(session->dimension && !session->dimension->set_voxel(world::voxel_registry::find(packet.voxel), packet.vpos)) {
+ if(session->dimension && !session->dimension->set_voxel(voxel_registry::find(packet.voxel), packet.vpos)) {
auto cpos = coord::to_chunk(packet.vpos);
auto lpos = coord::to_local(packet.vpos);
auto index = coord::to_index(lpos);
- if(world::worldgen::is_generating(session->dimension, cpos)) {
+ if(worldgen::is_generating(session->dimension, cpos)) {
// The chunk is currently being generated;
// ignore all requests from players to build there
return;
@@ -103,9 +103,9 @@ static void on_set_voxel_packet(const protocol::SetVoxel& packet)
return;
}
- chunk->set_voxel(world::voxel_registry::find(packet.voxel), index);
+ chunk->set_voxel(voxel_registry::find(packet.voxel), index);
- session->dimension->chunks.emplace_or_replace<world::Inhabited>(chunk->get_entity());
+ session->dimension->chunks.emplace_or_replace<Inhabited>(chunk->get_entity());
protocol::SetVoxel response;
response.vpos = packet.vpos;
@@ -126,20 +126,20 @@ static void on_request_chunk_packet(const protocol::RequestChunk& packet)
return;
}
- if(auto transform = session->dimension->entities.try_get<entity::Transform>(session->player_entity)) {
- world::ChunkAABB view_box;
+ if(auto transform = session->dimension->entities.try_get<Transform>(session->player_entity)) {
+ ChunkAABB view_box;
view_box.min = transform->chunk - static_cast<chunk_pos::value_type>(server_game::view_distance.get_value());
view_box.max = transform->chunk + static_cast<chunk_pos::value_type>(server_game::view_distance.get_value());
if(view_box.contains(packet.cpos)) {
- if(auto chunk = world::universe::load_chunk(session->dimension, packet.cpos)) {
+ if(auto chunk = universe::load_chunk(session->dimension, packet.cpos)) {
protocol::ChunkVoxels response;
response.chunk = packet.cpos;
response.voxels = chunk->get_voxels();
protocol::send(packet.peer, protocol::encode(response));
}
else {
- world::worldgen::request_chunk(session, packet.cpos);
+ worldgen::request_chunk(session, packet.cpos);
}
}
}
diff --git a/src/game/server/sessions.cc b/src/game/server/sessions.cc
index 3a63ae8..b161d55 100644
--- a/src/game/server/sessions.cc
+++ b/src/game/server/sessions.cc
@@ -34,11 +34,11 @@
class DimensionListener final {
public:
- explicit DimensionListener(world::Dimension* dimension);
+ explicit DimensionListener(Dimension* dimension);
void on_destroy_entity(const entt::registry& registry, entt::entity entity);
private:
- world::Dimension* dimension;
+ Dimension* dimension;
};
config::Unsigned sessions::max_players(8U, 1U, 128U);
@@ -85,14 +85,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
// FIXME: calculate voxel registry checksum ahead of time
// instead of figuring it out every time a new player connects
- if(packet.voxel_registry_checksum != world::voxel_registry::get_checksum()) {
+ if(packet.voxel_registry_checksum != voxel_registry::get_checksum()) {
protocol::Disconnect response;
response.reason = "protocol.voxel_registry_checksum";
protocol::send(packet.peer, protocol::encode(response));
return;
}
- if(packet.item_registry_checksum != world::item_registry::get_checksum()) {
+ if(packet.item_registry_checksum != item_registry::get_checksum()) {
protocol::Disconnect response;
response.reason = "protocol.item_registry_checksum";
protocol::send(packet.peer, protocol::encode(response));
@@ -151,14 +151,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
// anything here and just straight up spawing the player and await them
// to receive all the chunks and entites they feel like requesting
for(auto entity : globals::spawn_dimension->entities.view<entt::entity>()) {
- if(const auto head = globals::spawn_dimension->entities.try_get<entity::Head>(entity)) {
+ if(const auto head = globals::spawn_dimension->entities.try_get<Head>(entity)) {
protocol::EntityHead head_packet;
head_packet.entity = entity;
head_packet.angles = head->angles;
protocol::send(session->peer, protocol::encode(head_packet));
}
- if(const auto transform = globals::spawn_dimension->entities.try_get<entity::Transform>(entity)) {
+ if(const auto transform = globals::spawn_dimension->entities.try_get<Transform>(entity)) {
protocol::EntityTransform transform_packet;
transform_packet.entity = entity;
transform_packet.angles = transform->angles;
@@ -167,14 +167,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
protocol::send(session->peer, protocol::encode(transform_packet));
}
- if(const auto velocity = globals::spawn_dimension->entities.try_get<entity::Velocity>(entity)) {
+ if(const auto velocity = globals::spawn_dimension->entities.try_get<Velocity>(entity)) {
protocol::EntityVelocity velocity_packet;
velocity_packet.entity = entity;
velocity_packet.value = velocity->value;
protocol::send(session->peer, protocol::encode(velocity_packet));
}
- if(globals::spawn_dimension->entities.all_of<entity::Player>(entity)) {
+ if(globals::spawn_dimension->entities.all_of<Player>(entity)) {
protocol::EntityPlayer player_packet;
player_packet.entity = entity;
protocol::send(session->peer, protocol::encode(player_packet));
@@ -183,11 +183,11 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
session->dimension = globals::spawn_dimension;
session->player_entity = globals::spawn_dimension->entities.create();
- entity::shared::create_player(globals::spawn_dimension, session->player_entity);
+ shared::create_player(globals::spawn_dimension, session->player_entity);
- const auto& head = globals::spawn_dimension->entities.get<entity::Head>(session->player_entity);
- const auto& transform = globals::spawn_dimension->entities.get<entity::Transform>(session->player_entity);
- const auto& velocity = globals::spawn_dimension->entities.get<entity::Velocity>(session->player_entity);
+ const auto& head = globals::spawn_dimension->entities.get<Head>(session->player_entity);
+ const auto& transform = globals::spawn_dimension->entities.get<Transform>(session->player_entity);
+ const auto& velocity = globals::spawn_dimension->entities.get<Velocity>(session->player_entity);
protocol::EntityHead head_packet;
head_packet.entity = session->player_entity;
@@ -257,7 +257,7 @@ static void on_disconnect_packet(const protocol::Disconnect& packet)
// NOTE: [sessions] is a good place for this since [receive]
// handles entity data sent by players and [sessions] handles
// everything else network related that is not player movement
-static void on_voxel_set(const world::VoxelSetEvent& event)
+static void on_voxel_set(const VoxelSetEvent& event)
{
protocol::SetVoxel packet;
packet.vpos = coord::to_voxel(event.cpos, event.lpos);
@@ -266,7 +266,7 @@ static void on_voxel_set(const world::VoxelSetEvent& event)
protocol::broadcast(globals::server_host, protocol::encode(packet));
}
-DimensionListener::DimensionListener(world::Dimension* dimension)
+DimensionListener::DimensionListener(Dimension* dimension)
{
this->dimension = dimension;
}
@@ -286,7 +286,7 @@ void sessions::init(void)
globals::dispatcher.sink<protocol::LoginRequest>().connect<&on_login_request_packet>();
globals::dispatcher.sink<protocol::Disconnect>().connect<&on_disconnect_packet>();
- globals::dispatcher.sink<world::VoxelSetEvent>().connect<&on_voxel_set>();
+ globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>();
}
void sessions::init_late(void)
@@ -420,7 +420,7 @@ void sessions::destroy(Session* session)
}
}
-void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet)
+void sessions::broadcast(const Dimension* dimension, ENetPacket* packet)
{
for(const auto& session : sessions_vector) {
if(session.peer && (session.dimension == dimension)) {
@@ -429,7 +429,7 @@ void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet)
}
}
-void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet, ENetPeer* except)
+void sessions::broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except)
{
for(const auto& session : sessions_vector) {
if(session.peer && (session.peer != except)) {
diff --git a/src/game/server/sessions.hh b/src/game/server/sessions.hh
index 656b76d..4c64f80 100644
--- a/src/game/server/sessions.hh
+++ b/src/game/server/sessions.hh
@@ -1,9 +1,6 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
namespace config
{
@@ -15,7 +12,7 @@ struct Session final {
std::uint64_t client_identity;
std::string client_username;
entt::entity player_entity;
- world::Dimension* dimension;
+ Dimension* dimension;
ENetPeer* peer;
};
@@ -45,8 +42,8 @@ void destroy(Session* session);
namespace sessions
{
-void broadcast(const world::Dimension* dimension, ENetPacket* packet);
-void broadcast(const world::Dimension* dimension, ENetPacket* packet, ENetPeer* except);
+void broadcast(const Dimension* dimension, ENetPacket* packet);
+void broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except);
} // namespace sessions
namespace sessions
diff --git a/src/game/server/whitelist.cc b/src/game/server/whitelist.cc
index 3f1c413..555e5f3 100644
--- a/src/game/server/whitelist.cc
+++ b/src/game/server/whitelist.cc
@@ -48,7 +48,7 @@ void whitelist::init_late(void)
PHYSFS_File* file = PHYSFS_openRead(whitelist::filename.c_str());
if(file == nullptr) {
- spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), io::physfs_error());
+ spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), physfs_error());
whitelist::enabled.set_value(false);
return;
}
diff --git a/src/game/server/world/inhabited.hh b/src/game/server/world/inhabited.hh
index 57008e9..e4b2344 100644
--- a/src/game/server/world/inhabited.hh
+++ b/src/game/server/world/inhabited.hh
@@ -1,6 +1,3 @@
#pragma once
-namespace world
-{
struct Inhabited final {};
-} // namespace world
diff --git a/src/game/server/world/overworld.cc b/src/game/server/world/overworld.cc
index 1a558c1..b03311d 100644
--- a/src/game/server/world/overworld.cc
+++ b/src/game/server/world/overworld.cc
@@ -11,8 +11,7 @@
#include "shared/game_voxels.hh"
// FIXME: load these from a file
-static void compute_tree_feature(unsigned int height, world::Feature& feature, const world::Voxel* log_voxel,
- const world::Voxel* leaves_voxel)
+static void compute_tree_feature(unsigned int height, Feature& feature, const Voxel* log_voxel, const Voxel* leaves_voxel)
{
// Ensure the tree height is too small
height = glm::max<unsigned int>(height, 4U);
@@ -72,7 +71,7 @@ static void compute_tree_feature(unsigned int height, world::Feature& feature, c
}
}
-world::Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f)
+Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f)
{
m_bottommost_chunk.set_limits(-64, -4);
m_terrain_variation.set_limits(16, 256);
@@ -83,7 +82,7 @@ world::Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f)
compute_tree_feature(8U, m_feat_tree[3], game_voxels::oak_log, game_voxels::oak_leaves);
}
-void world::Overworld::init(io::ConfigMap& config)
+void Overworld::init(ConfigMap& config)
{
m_terrain_variation.set_value(64);
m_bottommost_chunk.set_value(-4);
@@ -92,7 +91,7 @@ void world::Overworld::init(io::ConfigMap& config)
config.add_value("overworld.bottommost_chunk", m_bottommost_chunk);
}
-void world::Overworld::init_late(std::uint64_t global_seed)
+void Overworld::init_late(std::uint64_t global_seed)
{
std::mt19937_64 twister(global_seed);
@@ -130,7 +129,7 @@ void world::Overworld::init_late(std::uint64_t global_seed)
m_metamap.clear();
}
-bool world::Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels)
+bool Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels)
{
if(cpos.y <= m_bottommost_chunk.get_value()) {
// If the player asks the generator
@@ -161,7 +160,7 @@ bool world::Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels)
return true;
}
-bool world::Overworld::is_inside_cave(const voxel_pos& vpos)
+bool Overworld::is_inside_cave(const voxel_pos& vpos)
{
auto vpos_x = static_cast<float>(vpos.x);
auto vpos_y = static_cast<float>(vpos.y) * 2.0f;
@@ -172,7 +171,7 @@ bool world::Overworld::is_inside_cave(const voxel_pos& vpos)
return (noise_a > 0.95f) && (noise_b > 0.85f);
}
-bool world::Overworld::is_inside_terrain(const voxel_pos& vpos)
+bool Overworld::is_inside_terrain(const voxel_pos& vpos)
{
auto vpos_x = static_cast<float>(vpos.x);
auto vpos_y = static_cast<float>(vpos.y);
@@ -184,7 +183,7 @@ bool world::Overworld::is_inside_terrain(const voxel_pos& vpos)
return noise > 0.0f;
}
-const world::Overworld_Metadata& world::Overworld::get_or_create_metadata(const chunk_pos_xz& cpos)
+const Overworld_Metadata& Overworld::get_or_create_metadata(const chunk_pos_xz& cpos)
{
auto it = m_metamap.find(cpos);
@@ -249,7 +248,7 @@ const world::Overworld_Metadata& world::Overworld::get_or_create_metadata(const
return metadata;
}
-void world::Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels)
+void Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels)
{
auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z));
auto variation = m_terrain_variation.get_value();
@@ -275,7 +274,7 @@ void world::Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& vox
}
}
-void world::Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& voxels)
+void Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& voxels)
{
auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z));
auto variation = m_terrain_variation.get_value();
@@ -330,7 +329,7 @@ void world::Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& vox
}
}
-void world::Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxels)
+void Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxels)
{
auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z));
auto variation = m_terrain_variation.get_value();
@@ -352,7 +351,7 @@ void world::Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxel
}
}
-void world::Overworld::generate_features(const chunk_pos& cpos, VoxelStorage& voxels)
+void Overworld::generate_features(const chunk_pos& cpos, VoxelStorage& voxels)
{
const chunk_pos_xz tree_chunks[] = {
chunk_pos_xz(cpos.x - 0, cpos.z - 1),
diff --git a/src/game/server/world/overworld.hh b/src/game/server/world/overworld.hh
index f3fc8cf..ef4bb54 100644
--- a/src/game/server/world/overworld.hh
+++ b/src/game/server/world/overworld.hh
@@ -11,24 +11,19 @@
constexpr static unsigned int OW_NUM_TREES = 4U;
-namespace world
-{
struct Overworld_Metadata final {
- world::dimension_entropy_map entropy;
- world::dimension_height_map heightmap;
+ dimension_entropy_map entropy;
+ dimension_height_map heightmap;
std::vector<local_pos> trees;
};
-} // namespace world
-namespace world
-{
class Overworld final : public Dimension {
public:
explicit Overworld(std::string_view name);
virtual ~Overworld(void) = default;
public:
- virtual void init(io::ConfigMap& config) override;
+ virtual void init(ConfigMap& config) override;
virtual void init_late(std::uint64_t global_seed) override;
virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels) override;
@@ -65,4 +60,3 @@ private:
private:
std::mutex m_mutex;
};
-} // namespace world
diff --git a/src/game/server/world/random_tick.cc b/src/game/server/world/random_tick.cc
index c5fa47c..8fdcfeb 100644
--- a/src/game/server/world/random_tick.cc
+++ b/src/game/server/world/random_tick.cc
@@ -17,14 +17,14 @@
static config::Int random_tick_speed(2, 1, 1000);
static std::mt19937_64 random_source;
-void world::random_tick::init(void)
+void random_tick::init(void)
{
globals::server_config.add_value("world.random_tick_speed", random_tick_speed);
random_source.seed(std::random_device {}());
}
-void world::random_tick::tick(const chunk_pos& cpos, Chunk* chunk)
+void random_tick::tick(const chunk_pos& cpos, Chunk* chunk)
{
assert(chunk);
diff --git a/src/game/server/world/random_tick.hh b/src/game/server/world/random_tick.hh
index 4ef1691..9c67dc4 100644
--- a/src/game/server/world/random_tick.hh
+++ b/src/game/server/world/random_tick.hh
@@ -2,13 +2,10 @@
#include "shared/types.hh"
-namespace world
-{
class Chunk;
-} // namespace world
-namespace world::random_tick
+namespace random_tick
{
void init(void);
void tick(const chunk_pos& cpos, Chunk* chunk);
-} // namespace world::random_tick
+} // namespace random_tick
diff --git a/src/game/server/world/universe.cc b/src/game/server/world/universe.cc
index 6d52951..defefc6 100644
--- a/src/game/server/world/universe.cc
+++ b/src/game/server/world/universe.cc
@@ -22,17 +22,17 @@
struct DimensionMetadata final {
std::string config_path;
std::string zvox_dir;
- io::ConfigMap config;
+ ConfigMap config;
};
static config::String universe_name("save");
-static io::ConfigMap universe_config;
+static ConfigMap universe_config;
static config::Unsigned64 universe_config_seed;
static config::String universe_spawn_dimension("world");
static std::string universe_config_path;
-static std::unordered_map<world::Dimension*, DimensionMetadata*> metadata_map;
+static std::unordered_map<Dimension*, DimensionMetadata*> metadata_map;
static std::string make_chunk_filename(const DimensionMetadata* metadata, const chunk_pos& cpos)
{
@@ -42,7 +42,7 @@ static std::string make_chunk_filename(const DimensionMetadata* metadata, const
return std::format("{}/{:08X}-{:08X}-{:08X}.zvox", metadata->zvox_dir, unsigned_x, unsigned_y, unsigned_z);
}
-static void add_new_dimension(world::Dimension* dimension)
+static void add_new_dimension(Dimension* dimension)
{
if(globals::dimensions.count(std::string(dimension->get_name()))) {
spdlog::critical("universe: dimension named {} already exists", dimension->get_name());
@@ -52,7 +52,7 @@ static void add_new_dimension(world::Dimension* dimension)
auto dimension_dir = std::format("{}/{}", universe_name.get(), dimension->get_name());
if(!PHYSFS_mkdir(dimension_dir.c_str())) {
- spdlog::critical("universe: {}: {}", dimension_dir, io::physfs_error());
+ spdlog::critical("universe: {}: {}", dimension_dir, physfs_error());
std::terminate();
}
@@ -61,7 +61,7 @@ static void add_new_dimension(world::Dimension* dimension)
metadata->zvox_dir = std::format("{}/chunk", dimension_dir);
if(!PHYSFS_mkdir(metadata->zvox_dir.c_str())) {
- spdlog::critical("universe: {}: {}", metadata->zvox_dir, io::physfs_error());
+ spdlog::critical("universe: {}: {}", metadata->zvox_dir, physfs_error());
std::terminate();
}
@@ -76,12 +76,11 @@ static void add_new_dimension(world::Dimension* dimension)
dimension->init_late(universe_config_seed.get_value());
}
-static void internal_save_chunk(const DimensionMetadata* metadata, const world::Dimension* dimension, const chunk_pos& cpos,
- const world::Chunk* chunk)
+static void internal_save_chunk(const DimensionMetadata* metadata, const Dimension* dimension, const chunk_pos& cpos, const Chunk* chunk)
{
auto path = make_chunk_filename(metadata, cpos);
- io::WriteBuffer buffer;
+ WriteBuffer buffer;
chunk->get_voxels().serialize(buffer);
if(auto file = buffer.to_file(path.c_str())) {
@@ -90,7 +89,7 @@ static void internal_save_chunk(const DimensionMetadata* metadata, const world::
}
}
-void world::universe::init(void)
+void universe::init(void)
{
// If the world is newly created, the seed will
// be chosed based on the current system's view on UNIX time
@@ -105,12 +104,12 @@ void world::universe::init(void)
universe_config.add_value("spawn_dimension", universe_spawn_dimension);
}
-void world::universe::init_late(void)
+void universe::init_late(void)
{
const auto universe_dir = std::string(universe_name.get());
if(!PHYSFS_mkdir(universe_dir.c_str())) {
- spdlog::critical("universe: {}: {}", universe_dir, io::physfs_error());
+ spdlog::critical("universe: {}: {}", universe_dir, physfs_error());
std::terminate();
}
@@ -135,7 +134,7 @@ void world::universe::init_late(void)
globals::spawn_dimension = spawn_dimension->second;
}
-void world::universe::shutdown(void)
+void universe::shutdown(void)
{
for(const auto metadata : metadata_map) {
metadata.second->config.save_file(metadata.second->config_path.c_str());
@@ -145,7 +144,7 @@ void world::universe::shutdown(void)
metadata_map.clear();
for(const auto dimension : globals::dimensions) {
- world::universe::save_all_chunks(dimension.second);
+ universe::save_all_chunks(dimension.second);
delete dimension.second;
}
@@ -155,7 +154,7 @@ void world::universe::shutdown(void)
universe_config.save_file(universe_config_path.c_str());
}
-world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos& cpos)
+Chunk* universe::load_chunk(Dimension* dimension, const chunk_pos& cpos)
{
if(auto chunk = dimension->find_chunk(cpos)) {
// Just return the existing chunk which is
@@ -173,7 +172,7 @@ world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos&
if(auto file = PHYSFS_openRead(make_chunk_filename(metadata->second, cpos).c_str())) {
VoxelStorage voxels;
- io::ReadBuffer buffer(file);
+ ReadBuffer buffer(file);
voxels.deserialize(buffer);
PHYSFS_close(file);
@@ -190,7 +189,7 @@ world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos&
return nullptr;
}
-void world::universe::save_chunk(Dimension* dimension, const chunk_pos& cpos)
+void universe::save_chunk(Dimension* dimension, const chunk_pos& cpos)
{
auto metadata = metadata_map.find(dimension);
@@ -205,7 +204,7 @@ void world::universe::save_chunk(Dimension* dimension, const chunk_pos& cpos)
}
}
-void world::universe::save_all_chunks(Dimension* dimension)
+void universe::save_all_chunks(Dimension* dimension)
{
auto group = dimension->chunks.group(entt::get<ChunkComponent, Inhabited>);
auto metadata = metadata_map.find(dimension);
diff --git a/src/game/server/world/universe.hh b/src/game/server/world/universe.hh
index e542eca..31d3721 100644
--- a/src/game/server/world/universe.hh
+++ b/src/game/server/world/universe.hh
@@ -2,24 +2,21 @@
#include "shared/types.hh"
-namespace world
-{
class Chunk;
class Dimension;
-} // namespace world
struct Session;
-namespace world::universe
+namespace universe
{
void init(void);
void init_late(void);
void shutdown(void);
-} // namespace world::universe
+} // namespace universe
-namespace world::universe
+namespace universe
{
Chunk* load_chunk(Dimension* dimension, const chunk_pos& cpos);
void save_chunk(Dimension* dimension, const chunk_pos& cpos);
void save_all_chunks(Dimension* dimension);
-} // namespace world::universe
+} // namespace universe
diff --git a/src/game/server/world/unloader.cc b/src/game/server/world/unloader.cc
index 4a3f4e1..5842b14 100644
--- a/src/game/server/world/unloader.cc
+++ b/src/game/server/world/unloader.cc
@@ -17,29 +17,29 @@
#include "server/game.hh"
#include "server/globals.hh"
-static void on_chunk_update(const world::ChunkUpdateEvent& event)
+static void on_chunk_update(const ChunkUpdateEvent& event)
{
- event.dimension->chunks.emplace_or_replace<world::Inhabited>(event.chunk->get_entity());
+ event.dimension->chunks.emplace_or_replace<Inhabited>(event.chunk->get_entity());
}
-static void on_voxel_set(const world::VoxelSetEvent& event)
+static void on_voxel_set(const VoxelSetEvent& event)
{
- event.dimension->chunks.emplace_or_replace<world::Inhabited>(event.chunk->get_entity());
+ event.dimension->chunks.emplace_or_replace<Inhabited>(event.chunk->get_entity());
}
-void world::unloader::init(void)
+void unloader::init(void)
{
- globals::dispatcher.sink<world::ChunkUpdateEvent>().connect<&on_chunk_update>();
- globals::dispatcher.sink<world::VoxelSetEvent>().connect<&on_voxel_set>();
+ globals::dispatcher.sink<ChunkUpdateEvent>().connect<&on_chunk_update>();
+ globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>();
}
-void world::unloader::init_late(void)
+void unloader::init_late(void)
{
}
-void world::unloader::fixed_update_late(Dimension* dimension)
+void unloader::fixed_update_late(Dimension* dimension)
{
- auto group = dimension->entities.group(entt::get<entity::Player, entity::Transform>);
+ auto group = dimension->entities.group(entt::get<Player, Transform>);
auto boxes = std::vector<ChunkAABB>();
for(const auto [entity, transform] : group.each()) {
@@ -70,7 +70,7 @@ void world::unloader::fixed_update_late(Dimension* dimension)
if(dimension->chunks.any_of<Inhabited>(entity)) {
// Only store inhabited chunks on disk
- world::universe::save_chunk(dimension, chunk.cpos);
+ universe::save_chunk(dimension, chunk.cpos);
}
dimension->remove_chunk(entity);
diff --git a/src/game/server/world/unloader.hh b/src/game/server/world/unloader.hh
index 9682de6..bf816bd 100644
--- a/src/game/server/world/unloader.hh
+++ b/src/game/server/world/unloader.hh
@@ -1,13 +1,10 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace world::unloader
+namespace unloader
{
void init(void);
void init_late(void);
void fixed_update_late(Dimension* dimension);
-} // namespace world::unloader
+} // namespace unloader
diff --git a/src/game/server/world/worldgen.cc b/src/game/server/world/worldgen.cc
index 8b02b52..c8c7ade 100644
--- a/src/game/server/world/worldgen.cc
+++ b/src/game/server/world/worldgen.cc
@@ -18,22 +18,22 @@
static bool aggressive_caching;
-static emhash8::HashMap<world::Dimension*, emhash8::HashMap<chunk_pos, std::unordered_set<Session*>>> active_tasks;
+static emhash8::HashMap<Dimension*, emhash8::HashMap<chunk_pos, std::unordered_set<Session*>>> active_tasks;
class WorldgenTask final : public Task {
public:
- explicit WorldgenTask(world::Dimension* dimension, const chunk_pos& cpos);
+ explicit WorldgenTask(Dimension* dimension, const chunk_pos& cpos);
virtual ~WorldgenTask(void) = default;
virtual void process(void) override;
virtual void finalize(void) override;
private:
- world::Dimension* m_dimension;
- world::VoxelStorage m_voxels;
+ Dimension* m_dimension;
+ VoxelStorage m_voxels;
chunk_pos m_cpos;
};
-WorldgenTask::WorldgenTask(world::Dimension* dimension, const chunk_pos& cpos)
+WorldgenTask::WorldgenTask(Dimension* dimension, const chunk_pos& cpos)
{
m_dimension = dimension;
m_voxels.fill(rand()); // trolling
@@ -75,7 +75,7 @@ void WorldgenTask::finalize(void)
// it so that it is saved regardles of whether it was
// modified by players or not. This isn't particularly
// good for server-side disk usage but it might improve performance
- m_dimension->chunks.emplace<world::Inhabited>(chunk->get_entity());
+ m_dimension->chunks.emplace<Inhabited>(chunk->get_entity());
}
protocol::ChunkVoxels response;
@@ -102,12 +102,12 @@ void WorldgenTask::finalize(void)
}
}
-void world::worldgen::init(void)
+void worldgen::init(void)
{
- aggressive_caching = io::cmdline::contains("aggressive-caching");
+ aggressive_caching = cmdline::contains("aggressive-caching");
}
-bool world::worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos)
+bool worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos)
{
auto dim_tasks = active_tasks.find(dimension);
@@ -126,7 +126,7 @@ bool world::worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos)
return true;
}
-void world::worldgen::request_chunk(Session* session, const chunk_pos& cpos)
+void worldgen::request_chunk(Session* session, const chunk_pos& cpos)
{
if(session->dimension) {
auto dim_tasks = active_tasks.find(session->dimension);
diff --git a/src/game/server/world/worldgen.hh b/src/game/server/world/worldgen.hh
index 30d7070..f991744 100644
--- a/src/game/server/world/worldgen.hh
+++ b/src/game/server/world/worldgen.hh
@@ -2,20 +2,17 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
-} // namespace world
struct Session;
-namespace world::worldgen
+namespace worldgen
{
void init(void);
-} // namespace world::worldgen
+} // namespace worldgen
-namespace world::worldgen
+namespace worldgen
{
bool is_generating(Dimension* dimension, const chunk_pos& cpos);
void request_chunk(Session* session, const chunk_pos& cpos);
-} // namespace world::worldgen
+} // namespace worldgen
diff --git a/src/game/shared/entity/collision.cc b/src/game/shared/entity/collision.cc
index bc9209b..af23047 100644
--- a/src/game/shared/entity/collision.cc
+++ b/src/game/shared/entity/collision.cc
@@ -15,8 +15,8 @@
#include "shared/coord.hh"
#include "shared/globals.hh"
-static int vgrid_collide(const world::Dimension* dimension, int d, entity::Collision& collision, entity::Transform& transform,
- entity::Velocity& velocity, world::VoxelMaterial& touch_surface)
+static int vgrid_collide(const Dimension* dimension, int d, Collision& collision, Transform& transform, Velocity& velocity,
+ VoxelMaterial& touch_surface)
{
const auto move = globals::fixed_frametime * velocity.value[d];
const auto move_sign = math::sign<int>(move);
@@ -57,9 +57,9 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
dmax = lpos_min[d];
}
- world::VoxelTouch latch_touch = world::VTOUCH_NONE;
+ VoxelTouch latch_touch = VTOUCH_NONE;
glm::fvec3 latch_values = glm::fvec3(0.0f, 0.0f, 0.0f);
- world::VoxelMaterial latch_surface = world::VMAT_UNKNOWN;
+ VoxelMaterial latch_surface = VMAT_UNKNOWN;
math::AABBf latch_vbox;
for(auto i = dmin; i != dmax; i += ddir) {
@@ -87,7 +87,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
continue;
}
- if(voxel->is_touch_type<world::VTOUCH_SOLID>()) {
+ if(voxel->is_touch_type<VTOUCH_SOLID>()) {
// Solid touch type makes a collision
// response whenever it is encountered
velocity.value[d] = 0.0f;
@@ -98,7 +98,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
// In case of other touch types, they
// are latched and the last ever touch
// type is then responded to
- if(voxel->get_touch_type() != world::VTOUCH_NONE) {
+ if(voxel->get_touch_type() != VTOUCH_NONE) {
latch_touch = voxel->get_touch_type();
latch_values = voxel->get_touch_values();
latch_surface = voxel->get_surface_material();
@@ -108,8 +108,8 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
}
}
- if(latch_touch != world::VTOUCH_NONE) {
- if(latch_touch == world::VTOUCH_BOUNCE) {
+ if(latch_touch != VTOUCH_NONE) {
+ if(latch_touch == VTOUCH_BOUNCE) {
const auto move_distance = glm::abs(current_aabb.min[d] - next_aabb.min[d]);
const auto threshold = 2.0f * globals::fixed_frametime;
@@ -125,7 +125,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
return move_sign;
}
- if(latch_touch == world::VTOUCH_SINK) {
+ if(latch_touch == VTOUCH_SINK) {
velocity.value[d] *= latch_values[d];
touch_surface = latch_surface;
return move_sign;
@@ -135,7 +135,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
return 0;
}
-void entity::Collision::fixed_update(world::Dimension* dimension)
+void Collision::fixed_update(Dimension* dimension)
{
// FIXME: this isn't particularly accurate considering
// some voxels might be passable and some other voxels
@@ -146,25 +146,25 @@ void entity::Collision::fixed_update(world::Dimension* dimension)
// we shouldn't treat all voxels as full cubes if we want
// to support slabs, stairs and non-full liquid voxels in the future
- auto group = dimension->entities.group<entity::Collision>(entt::get<entity::Transform, entity::Velocity>);
+ auto group = dimension->entities.group<Collision>(entt::get<Transform, Velocity>);
for(auto [entity, collision, transform, velocity] : group.each()) {
- auto surface = world::VMAT_UNKNOWN;
+ auto surface = VMAT_UNKNOWN;
auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface);
- if(dimension->entities.any_of<entity::Gravity>(entity)) {
+ if(dimension->entities.any_of<Gravity>(entity)) {
if(vertical_move == math::sign<int>(dimension->get_gravity())) {
- dimension->entities.emplace_or_replace<entity::Grounded>(entity, entity::Grounded { surface });
+ dimension->entities.emplace_or_replace<Grounded>(entity, Grounded { surface });
}
else {
- dimension->entities.remove<entity::Grounded>(entity);
+ dimension->entities.remove<Grounded>(entity);
}
}
else {
// The entity cannot be grounded because the component
// setup of said entity should not let it comprehend the
// concept of resting on the ground (it flies around)
- dimension->entities.remove<entity::Grounded>(entity);
+ dimension->entities.remove<Grounded>(entity);
}
vgrid_collide(dimension, 0, collision, transform, velocity, surface);
diff --git a/src/game/shared/entity/collision.hh b/src/game/shared/entity/collision.hh
index b37f409..34a648c 100644
--- a/src/game/shared/entity/collision.hh
+++ b/src/game/shared/entity/collision.hh
@@ -2,20 +2,14 @@
#include "core/math/aabb.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Collision final {
math::AABBf aabb;
public:
- // NOTE: entity::Collision::fixed_update must be called
- // before entity::Transform::fixed_update and entity::Velocity::fixed_update
+ // NOTE: Collision::fixed_update must be called
+ // before Transform::fixed_update and Velocity::fixed_update
// because both transform and velocity may be updated internally
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/factory.cc b/src/game/shared/entity/factory.cc
index 619a418..f2031df 100644
--- a/src/game/shared/entity/factory.cc
+++ b/src/game/shared/entity/factory.cc
@@ -13,25 +13,25 @@
#include "shared/globals.hh"
-void entity::shared::create_player(world::Dimension* dimension, entt::entity entity)
+void shared::create_player(Dimension* dimension, entt::entity entity)
{
spdlog::debug("factory[{}]: assigning player components to {}", dimension->get_name(), static_cast<std::uint64_t>(entity));
- auto& collision = dimension->entities.emplace_or_replace<entity::Collision>(entity);
+ auto& collision = dimension->entities.emplace_or_replace<Collision>(entity);
collision.aabb.min = glm::fvec3(-0.4f, -1.6f, -0.4f);
collision.aabb.max = glm::fvec3(+0.4f, +0.2f, +0.4f);
- auto& head = dimension->entities.emplace_or_replace<entity::Head>(entity);
+ auto& head = dimension->entities.emplace_or_replace<Head>(entity);
head.angles = glm::fvec3(0.0f, 0.0f, 0.0f);
head.offset = glm::fvec3(0.0f, 0.0f, 0.0f);
- dimension->entities.emplace_or_replace<entity::Player>(entity);
+ dimension->entities.emplace_or_replace<Player>(entity);
- auto& transform = dimension->entities.emplace_or_replace<entity::Transform>(entity);
+ auto& transform = dimension->entities.emplace_or_replace<Transform>(entity);
transform.chunk = chunk_pos(0, 2, 0);
transform.local = glm::fvec3(0.0f, 0.0f, 0.0f);
transform.angles = glm::fvec3(0.0f, 0.0f, 0.0f);
- auto& velocity = dimension->entities.emplace_or_replace<entity::Velocity>(entity);
+ auto& velocity = dimension->entities.emplace_or_replace<Velocity>(entity);
velocity.value = glm::fvec3(0.0f, 0.0f, 0.0f);
}
diff --git a/src/game/shared/entity/factory.hh b/src/game/shared/entity/factory.hh
index e709060..7c94136 100644
--- a/src/game/shared/entity/factory.hh
+++ b/src/game/shared/entity/factory.hh
@@ -1,11 +1,8 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity::shared
+namespace shared
{
-void create_player(world::Dimension* dimension, entt::entity entity);
-} // namespace entity::shared
+void create_player(Dimension* dimension, entt::entity entity);
+} // namespace shared
diff --git a/src/game/shared/entity/gravity.cc b/src/game/shared/entity/gravity.cc
index f1708aa..6a5145f 100644
--- a/src/game/shared/entity/gravity.cc
+++ b/src/game/shared/entity/gravity.cc
@@ -9,10 +9,10 @@
#include "shared/globals.hh"
-void entity::Gravity::fixed_update(world::Dimension* dimension)
+void Gravity::fixed_update(Dimension* dimension)
{
auto fixed_acceleration = globals::fixed_frametime * dimension->get_gravity();
- auto group = dimension->entities.group<entity::Gravity>(entt::get<entity::Velocity>, entt::exclude<entity::Stasis>);
+ auto group = dimension->entities.group<Gravity>(entt::get<Velocity>, entt::exclude<Stasis>);
for(auto [entity, velocity] : group.each()) {
velocity.value.y += fixed_acceleration;
diff --git a/src/game/shared/entity/gravity.hh b/src/game/shared/entity/gravity.hh
index 21f4582..38b3c9b 100644
--- a/src/game/shared/entity/gravity.hh
+++ b/src/game/shared/entity/gravity.hh
@@ -1,14 +1,8 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Gravity final {
public:
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/grounded.hh b/src/game/shared/entity/grounded.hh
index 6c33d1d..7307e79 100644
--- a/src/game/shared/entity/grounded.hh
+++ b/src/game/shared/entity/grounded.hh
@@ -2,11 +2,8 @@
#include "shared/world/voxel.hh"
-namespace entity
-{
// Assigned to entities which are grounded
// according to the collision and gravity system
struct Grounded final {
- world::VoxelMaterial surface;
+ VoxelMaterial surface;
};
-} // namespace entity
diff --git a/src/game/shared/entity/head.hh b/src/game/shared/entity/head.hh
index 3f5d6d1..9fa71d9 100644
--- a/src/game/shared/entity/head.hh
+++ b/src/game/shared/entity/head.hh
@@ -1,16 +1,13 @@
#pragma once
-namespace entity
-{
struct Head {
glm::fvec3 angles;
glm::fvec3 offset;
};
-} // namespace entity
-namespace entity::client
+namespace client
{
// Client-side only - interpolated and previous head
struct HeadIntr final : public Head {};
struct HeadPrev final : public Head {};
-} // namespace entity::client
+} // namespace client
diff --git a/src/game/shared/entity/player.hh b/src/game/shared/entity/player.hh
index 4bd0217..d7cd020 100644
--- a/src/game/shared/entity/player.hh
+++ b/src/game/shared/entity/player.hh
@@ -1,6 +1,3 @@
#pragma once
-namespace entity
-{
struct Player final {};
-} // namespace entity
diff --git a/src/game/shared/entity/stasis.cc b/src/game/shared/entity/stasis.cc
index 3b86294..0b8a0c8 100644
--- a/src/game/shared/entity/stasis.cc
+++ b/src/game/shared/entity/stasis.cc
@@ -6,16 +6,16 @@
#include "shared/world/dimension.hh"
-void entity::Stasis::fixed_update(world::Dimension* dimension)
+void Stasis::fixed_update(Dimension* dimension)
{
- auto view = dimension->entities.view<entity::Transform>();
+ auto view = dimension->entities.view<Transform>();
for(auto [entity, transform] : view.each()) {
if(dimension->find_chunk(transform.chunk)) {
- dimension->entities.remove<entity::Stasis>(entity);
+ dimension->entities.remove<Stasis>(entity);
}
else {
- dimension->entities.emplace_or_replace<entity::Stasis>(entity);
+ dimension->entities.emplace_or_replace<Stasis>(entity);
}
}
}
diff --git a/src/game/shared/entity/stasis.hh b/src/game/shared/entity/stasis.hh
index e6cb9e4..5adc592 100644
--- a/src/game/shared/entity/stasis.hh
+++ b/src/game/shared/entity/stasis.hh
@@ -1,16 +1,10 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
// Attached to entities with transform values
// out of bounds in a specific dimension
struct Stasis final {
public:
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/transform.cc b/src/game/shared/entity/transform.cc
index 379ddd5..cf09e2f 100644
--- a/src/game/shared/entity/transform.cc
+++ b/src/game/shared/entity/transform.cc
@@ -6,7 +6,7 @@
#include "shared/const.hh"
-constexpr inline static void update_component(unsigned int dim, entity::Transform& component)
+constexpr inline static void update_component(unsigned int dim, Transform& component)
{
if(component.local[dim] >= CHUNK_SIZE) {
component.local[dim] -= CHUNK_SIZE;
@@ -21,9 +21,9 @@ constexpr inline static void update_component(unsigned int dim, entity::Transfor
}
}
-void entity::Transform::fixed_update(world::Dimension* dimension)
+void Transform::fixed_update(Dimension* dimension)
{
- auto view = dimension->entities.view<entity::Transform>();
+ auto view = dimension->entities.view<Transform>();
for(auto [entity, transform] : view.each()) {
update_component(0U, transform);
diff --git a/src/game/shared/entity/transform.hh b/src/game/shared/entity/transform.hh
index 2b357f8..afbe9fa 100644
--- a/src/game/shared/entity/transform.hh
+++ b/src/game/shared/entity/transform.hh
@@ -2,29 +2,23 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Transform {
chunk_pos chunk;
glm::fvec3 local;
glm::fvec3 angles;
public:
- // Updates entity::Transform values so that
+ // Updates Transform values so that
// the local translation field is always within
// local coodrinates; [floating-point precision]
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
-namespace entity::client
+namespace client
{
// Client-side only - interpolated and previous transform
struct TransformIntr final : public Transform {};
struct TransformPrev final : public Transform {};
-} // namespace entity::client
+} // namespace client
diff --git a/src/game/shared/entity/velocity.cc b/src/game/shared/entity/velocity.cc
index 86df445..6fb8c80 100644
--- a/src/game/shared/entity/velocity.cc
+++ b/src/game/shared/entity/velocity.cc
@@ -9,9 +9,9 @@
#include "shared/globals.hh"
-void entity::Velocity::fixed_update(world::Dimension* dimension)
+void Velocity::fixed_update(Dimension* dimension)
{
- auto group = dimension->entities.group<entity::Velocity>(entt::get<entity::Transform>, entt::exclude<entity::Stasis>);
+ auto group = dimension->entities.group<Velocity>(entt::get<Transform>, entt::exclude<Stasis>);
for(auto [entity, velocity, transform] : group.each()) {
transform.local += velocity.value * globals::fixed_frametime;
diff --git a/src/game/shared/entity/velocity.hh b/src/game/shared/entity/velocity.hh
index c8a1c91..69fce9e 100644
--- a/src/game/shared/entity/velocity.hh
+++ b/src/game/shared/entity/velocity.hh
@@ -1,19 +1,13 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Velocity final {
glm::fvec3 value;
public:
- // Updates entities entity::Transform values
+ // Updates entities Transform values
// according to velocities multiplied by fixed_frametime.
// NOTE: This system was previously called inertial
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/game.cc b/src/game/shared/game.cc
index a3a724d..e839e6a 100644
--- a/src/game/shared/game.cc
+++ b/src/game/shared/game.cc
@@ -7,7 +7,7 @@
static std::filesystem::path get_gamepath(void)
{
- if(auto gamepath = io::cmdline::get_cstr("gamepath")) {
+ if(auto gamepath = cmdline::get_cstr("gamepath")) {
// Allow users and third-party launchers to override
// content location. Perhaps this would work to allow
// for a Minecraft-like versioning approach?
@@ -19,7 +19,7 @@ static std::filesystem::path get_gamepath(void)
static std::filesystem::path get_userpath(void)
{
- if(auto userpath = io::cmdline::get_cstr("userpath")) {
+ if(auto userpath = cmdline::get_cstr("userpath")) {
// Allow users and third-party launchers to override
// user data location. Perhaps this would work to allow
// for a Minecraft-like versioning approach?
@@ -67,10 +67,10 @@ void shared_game::init(int argc, char** argv, std::string_view logfile)
constexpr auto default_loglevel = spdlog::level::trace;
#endif
- if(io::cmdline::contains("quiet")) {
+ if(cmdline::contains("quiet")) {
logger->set_level(spdlog::level::warn);
}
- else if(io::cmdline::contains("verbose")) {
+ else if(cmdline::contains("verbose")) {
logger->set_level(spdlog::level::trace);
}
else {
@@ -81,7 +81,7 @@ void shared_game::init(int argc, char** argv, std::string_view logfile)
logger->flush();
if(!PHYSFS_init(argv[0])) {
- spdlog::critical("physfs: init failed: {}", io::physfs_error());
+ spdlog::critical("physfs: init failed: {}", physfs_error());
std::terminate();
}
@@ -96,17 +96,17 @@ void shared_game::init(int argc, char** argv, std::string_view logfile)
std::filesystem::create_directories(userpath, ignore_error);
if(!PHYSFS_mount(gamepath.string().c_str(), nullptr, false)) {
- spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), io::physfs_error());
+ spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), physfs_error());
std::terminate();
}
if(!PHYSFS_mount(userpath.string().c_str(), nullptr, false)) {
- spdlog::critical("physfs: mount {} failed: {}", userpath.string(), io::physfs_error());
+ spdlog::critical("physfs: mount {} failed: {}", userpath.string(), physfs_error());
std::terminate();
}
if(!PHYSFS_setWriteDir(userpath.string().c_str())) {
- spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), io::physfs_error());
+ spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), physfs_error());
std::terminate();
}
@@ -121,7 +121,7 @@ void shared_game::shutdown(void)
enet_deinitialize();
if(!PHYSFS_deinit()) {
- spdlog::critical("physfs: deinit failed: {}", io::physfs_error());
+ spdlog::critical("physfs: deinit failed: {}", physfs_error());
std::terminate();
}
}
diff --git a/src/game/shared/game_items.cc b/src/game/shared/game_items.cc
index e239063..73f7cef 100644
--- a/src/game/shared/game_items.cc
+++ b/src/game/shared/game_items.cc
@@ -6,60 +6,60 @@
#include "shared/game_voxels.hh"
-const world::Item* game_items::stone = nullptr;
-const world::Item* game_items::cobblestone = nullptr;
-const world::Item* game_items::dirt = nullptr;
-const world::Item* game_items::grass = nullptr;
-const world::Item* game_items::oak_leaves = nullptr;
-const world::Item* game_items::oak_planks = nullptr;
-const world::Item* game_items::oak_log = nullptr;
-const world::Item* game_items::glass = nullptr;
-const world::Item* game_items::slime = nullptr;
+const Item* game_items::stone = nullptr;
+const Item* game_items::cobblestone = nullptr;
+const Item* game_items::dirt = nullptr;
+const Item* game_items::grass = nullptr;
+const Item* game_items::oak_leaves = nullptr;
+const Item* game_items::oak_planks = nullptr;
+const Item* game_items::oak_log = nullptr;
+const Item* game_items::glass = nullptr;
+const Item* game_items::slime = nullptr;
void game_items::populate(void)
{
- auto stone_builder = world::ItemBuilder("stone");
+ auto stone_builder = ItemBuilder("stone");
stone_builder.set_texture("textures/item/stone.png");
stone_builder.set_place_voxel(game_voxels::stone);
- stone = world::item_registry::register_item(stone_builder);
+ stone = item_registry::register_item(stone_builder);
- auto cobblestone_builder = world::ItemBuilder("cobblestone");
+ auto cobblestone_builder = ItemBuilder("cobblestone");
cobblestone_builder.set_texture("textures/item/cobblestone.png");
cobblestone_builder.set_place_voxel(game_voxels::cobblestone);
- cobblestone = world::item_registry::register_item(cobblestone_builder);
+ cobblestone = item_registry::register_item(cobblestone_builder);
- auto dirt_builder = world::ItemBuilder("dirt");
+ auto dirt_builder = ItemBuilder("dirt");
dirt_builder.set_texture("textures/item/dirt.png");
dirt_builder.set_place_voxel(game_voxels::dirt);
- dirt = world::item_registry::register_item(dirt_builder);
+ dirt = item_registry::register_item(dirt_builder);
- auto grass_builder = world::ItemBuilder("grass");
+ auto grass_builder = ItemBuilder("grass");
grass_builder.set_texture("textures/item/grass.png");
grass_builder.set_place_voxel(game_voxels::grass);
- grass = world::item_registry::register_item(grass_builder);
+ grass = item_registry::register_item(grass_builder);
- auto oak_leaves_builder = world::ItemBuilder("oak_leaves");
+ auto oak_leaves_builder = ItemBuilder("oak_leaves");
oak_leaves_builder.set_texture("textures/item/oak_leaves.png");
oak_leaves_builder.set_place_voxel(game_voxels::oak_leaves);
- oak_leaves = world::item_registry::register_item(oak_leaves_builder);
+ oak_leaves = item_registry::register_item(oak_leaves_builder);
- auto oak_planks_builder = world::ItemBuilder("oak_planks");
+ auto oak_planks_builder = ItemBuilder("oak_planks");
oak_planks_builder.set_texture("textures/item/oak_planks.png");
oak_planks_builder.set_place_voxel(game_voxels::oak_planks);
- oak_planks = world::item_registry::register_item(oak_planks_builder);
+ oak_planks = item_registry::register_item(oak_planks_builder);
- auto oak_log_builder = world::ItemBuilder("oak_log");
+ auto oak_log_builder = ItemBuilder("oak_log");
oak_log_builder.set_texture("textures/item/oak_log.png");
oak_log_builder.set_place_voxel(game_voxels::oak_log);
- oak_log = world::item_registry::register_item(oak_log_builder);
+ oak_log = item_registry::register_item(oak_log_builder);
- auto glass_builder = world::ItemBuilder("glass");
+ auto glass_builder = ItemBuilder("glass");
glass_builder.set_texture("textures/item/glass.png");
glass_builder.set_place_voxel(game_voxels::glass);
- glass = world::item_registry::register_item(glass_builder);
+ glass = item_registry::register_item(glass_builder);
- auto slime_builder = world::ItemBuilder("slime");
+ auto slime_builder = ItemBuilder("slime");
slime_builder.set_texture("textures/item/slime.png");
slime_builder.set_place_voxel(game_voxels::slime);
- slime = world::item_registry::register_item(slime_builder);
+ slime = item_registry::register_item(slime_builder);
}
diff --git a/src/game/shared/game_items.hh b/src/game/shared/game_items.hh
index c9b3638..1170543 100644
--- a/src/game/shared/game_items.hh
+++ b/src/game/shared/game_items.hh
@@ -1,21 +1,18 @@
#pragma once
-namespace world
-{
class Item;
-} // namespace world
namespace game_items
{
-extern const world::Item* stone;
-extern const world::Item* cobblestone;
-extern const world::Item* dirt;
-extern const world::Item* grass;
-extern const world::Item* oak_leaves;
-extern const world::Item* oak_planks;
-extern const world::Item* oak_log;
-extern const world::Item* glass;
-extern const world::Item* slime;
+extern const Item* stone;
+extern const Item* cobblestone;
+extern const Item* dirt;
+extern const Item* grass;
+extern const Item* oak_leaves;
+extern const Item* oak_planks;
+extern const Item* oak_log;
+extern const Item* glass;
+extern const Item* slime;
} // namespace game_items
namespace game_items
diff --git a/src/game/shared/game_voxels.cc b/src/game/shared/game_voxels.cc
index c4c4ec3..010053a 100644
--- a/src/game/shared/game_voxels.cc
+++ b/src/game/shared/game_voxels.cc
@@ -7,19 +7,19 @@
#include "shared/const.hh"
-const world::Voxel* game_voxels::cobblestone = nullptr;
-const world::Voxel* game_voxels::dirt = nullptr;
-const world::Voxel* game_voxels::grass = nullptr;
-const world::Voxel* game_voxels::stone = nullptr;
-const world::Voxel* game_voxels::vtest = nullptr;
-const world::Voxel* game_voxels::vtest_ck = nullptr;
-const world::Voxel* game_voxels::oak_leaves = nullptr;
-const world::Voxel* game_voxels::oak_planks = nullptr;
-const world::Voxel* game_voxels::oak_log = nullptr;
-const world::Voxel* game_voxels::glass = nullptr;
-const world::Voxel* game_voxels::slime = nullptr;
-
-static void dirt_tick(world::Dimension* dimension, const voxel_pos& vpos)
+const Voxel* game_voxels::cobblestone = nullptr;
+const Voxel* game_voxels::dirt = nullptr;
+const Voxel* game_voxels::grass = nullptr;
+const Voxel* game_voxels::stone = nullptr;
+const Voxel* game_voxels::vtest = nullptr;
+const Voxel* game_voxels::vtest_ck = nullptr;
+const Voxel* game_voxels::oak_leaves = nullptr;
+const Voxel* game_voxels::oak_planks = nullptr;
+const Voxel* game_voxels::oak_log = nullptr;
+const Voxel* game_voxels::glass = nullptr;
+const Voxel* game_voxels::slime = nullptr;
+
+static void dirt_tick(Dimension* dimension, const voxel_pos& vpos)
{
auto grass_found = false;
auto air_above = false;
@@ -49,7 +49,7 @@ static void dirt_tick(world::Dimension* dimension, const voxel_pos& vpos)
auto above_vpos = vpos + voxel_pos(0, 1, 0);
auto above_voxel = dimension->get_voxel(above_vpos);
- if(above_voxel == nullptr || above_voxel->is_surface_material<world::VMAT_GLASS>()) {
+ if(above_voxel == nullptr || above_voxel->is_surface_material<VMAT_GLASS>()) {
air_above = true;
}
@@ -58,12 +58,12 @@ static void dirt_tick(world::Dimension* dimension, const voxel_pos& vpos)
}
}
-static void grass_tick(world::Dimension* dimension, const voxel_pos& vpos)
+static void grass_tick(Dimension* dimension, const voxel_pos& vpos)
{
auto above_vpos = vpos + voxel_pos(0, 1, 0);
auto above_voxel = dimension->get_voxel(above_vpos);
- if(above_voxel && !above_voxel->is_surface_material<world::VMAT_GLASS>()) {
+ if(above_voxel && !above_voxel->is_surface_material<VMAT_GLASS>()) {
// Decay into dirt if something is blocking airflow
dimension->set_voxel(game_voxels::dirt, vpos);
}
@@ -71,82 +71,82 @@ static void grass_tick(world::Dimension* dimension, const voxel_pos& vpos)
void game_voxels::populate(void)
{
- auto stone_builder = world::VoxelBuilder("stone");
+ auto stone_builder = VoxelBuilder("stone");
stone_builder.add_default_texture("textures/voxel/stone_01.png");
stone_builder.add_default_texture("textures/voxel/stone_02.png");
stone_builder.add_default_texture("textures/voxel/stone_03.png");
stone_builder.add_default_texture("textures/voxel/stone_04.png");
- stone = world::voxel_registry::register_voxel(stone_builder);
+ stone = voxel_registry::register_voxel(stone_builder);
- auto cobblestone_builder = world::VoxelBuilder("cobblestone");
+ auto cobblestone_builder = VoxelBuilder("cobblestone");
cobblestone_builder.add_default_texture("textures/voxel/cobblestone_01.png");
cobblestone_builder.add_default_texture("textures/voxel/cobblestone_02.png");
- cobblestone = world::voxel_registry::register_voxel(cobblestone_builder);
+ cobblestone = voxel_registry::register_voxel(cobblestone_builder);
- auto dirt_builder = world::VoxelBuilder("dirt");
+ auto dirt_builder = VoxelBuilder("dirt");
dirt_builder.add_default_texture("textures/voxel/dirt_01.png");
dirt_builder.add_default_texture("textures/voxel/dirt_02.png");
dirt_builder.add_default_texture("textures/voxel/dirt_03.png");
dirt_builder.add_default_texture("textures/voxel/dirt_04.png");
- dirt_builder.set_surface_material(world::VMAT_DIRT);
+ dirt_builder.set_surface_material(VMAT_DIRT);
dirt_builder.set_on_tick(&dirt_tick);
- dirt = world::voxel_registry::register_voxel(dirt_builder);
+ dirt = voxel_registry::register_voxel(dirt_builder);
- auto grass_builder = world::VoxelBuilder("grass");
+ auto grass_builder = VoxelBuilder("grass");
grass_builder.add_default_texture("textures/voxel/grass_side_01.png");
grass_builder.add_default_texture("textures/voxel/grass_side_02.png");
- grass_builder.add_face_texture(world::VFACE_BOTTOM, "textures/voxel/dirt_01.png");
- grass_builder.add_face_texture(world::VFACE_BOTTOM, "textures/voxel/dirt_02.png");
- grass_builder.add_face_texture(world::VFACE_BOTTOM, "textures/voxel/dirt_03.png");
- grass_builder.add_face_texture(world::VFACE_BOTTOM, "textures/voxel/dirt_04.png");
- grass_builder.add_face_texture(world::VFACE_TOP, "textures/voxel/grass_01.png");
- grass_builder.add_face_texture(world::VFACE_TOP, "textures/voxel/grass_02.png");
- grass_builder.set_surface_material(world::VMAT_GRASS);
+ grass_builder.add_face_texture(VFACE_BOTTOM, "textures/voxel/dirt_01.png");
+ grass_builder.add_face_texture(VFACE_BOTTOM, "textures/voxel/dirt_02.png");
+ grass_builder.add_face_texture(VFACE_BOTTOM, "textures/voxel/dirt_03.png");
+ grass_builder.add_face_texture(VFACE_BOTTOM, "textures/voxel/dirt_04.png");
+ grass_builder.add_face_texture(VFACE_TOP, "textures/voxel/grass_01.png");
+ grass_builder.add_face_texture(VFACE_TOP, "textures/voxel/grass_02.png");
+ grass_builder.set_surface_material(VMAT_GRASS);
grass_builder.set_on_tick(&grass_tick);
- grass = world::voxel_registry::register_voxel(grass_builder);
+ grass = voxel_registry::register_voxel(grass_builder);
- auto vtest_builder = world::VoxelBuilder("vtest");
+ auto vtest_builder = VoxelBuilder("vtest");
vtest_builder.add_default_texture("textures/voxel/vtest_F1.png");
vtest_builder.add_default_texture("textures/voxel/vtest_F2.png");
vtest_builder.add_default_texture("textures/voxel/vtest_F3.png");
vtest_builder.add_default_texture("textures/voxel/vtest_F4.png");
vtest_builder.set_animated(true);
- vtest = world::voxel_registry::register_voxel(vtest_builder);
+ vtest = voxel_registry::register_voxel(vtest_builder);
- auto vtest_ck_builder = world::VoxelBuilder("vtest_ck");
+ auto vtest_ck_builder = VoxelBuilder("vtest_ck");
vtest_ck_builder.add_default_texture("textures/voxel/chromakey.png");
- vtest_ck = world::voxel_registry::register_voxel(vtest_ck_builder);
+ vtest_ck = voxel_registry::register_voxel(vtest_ck_builder);
- auto oak_leaves_builder = world::VoxelBuilder("oak_leaves");
+ auto oak_leaves_builder = VoxelBuilder("oak_leaves");
oak_leaves_builder.add_default_texture("textures/voxel/oak_leaves.png");
- oak_leaves_builder.set_surface_material(world::VMAT_GRASS);
- oak_leaves = world::voxel_registry::register_voxel(oak_leaves_builder);
+ oak_leaves_builder.set_surface_material(VMAT_GRASS);
+ oak_leaves = voxel_registry::register_voxel(oak_leaves_builder);
- auto oak_planks_builder = world::VoxelBuilder("oak_planks");
+ auto oak_planks_builder = VoxelBuilder("oak_planks");
oak_planks_builder.add_default_texture("textures/voxel/oak_planks_01.png");
oak_planks_builder.add_default_texture("textures/voxel/oak_planks_02.png");
- oak_planks_builder.set_surface_material(world::VMAT_WOOD);
- oak_planks = world::voxel_registry::register_voxel(oak_planks_builder);
+ oak_planks_builder.set_surface_material(VMAT_WOOD);
+ oak_planks = voxel_registry::register_voxel(oak_planks_builder);
- auto oak_log_builder = world::VoxelBuilder("oak_log");
+ auto oak_log_builder = VoxelBuilder("oak_log");
oak_log_builder.add_default_texture("textures/voxel/oak_wood_01.png");
oak_log_builder.add_default_texture("textures/voxel/oak_wood_02.png");
- oak_log_builder.add_face_texture(world::VFACE_BOTTOM, "textures/voxel/oak_wood_top.png");
- oak_log_builder.add_face_texture(world::VFACE_TOP, "textures/voxel/oak_wood_top.png");
- oak_log_builder.set_surface_material(world::VMAT_WOOD);
- oak_log = world::voxel_registry::register_voxel(oak_log_builder);
+ oak_log_builder.add_face_texture(VFACE_BOTTOM, "textures/voxel/oak_wood_top.png");
+ oak_log_builder.add_face_texture(VFACE_TOP, "textures/voxel/oak_wood_top.png");
+ oak_log_builder.set_surface_material(VMAT_WOOD);
+ oak_log = voxel_registry::register_voxel(oak_log_builder);
- auto glass_builder = world::VoxelBuilder("glass");
+ auto glass_builder = VoxelBuilder("glass");
glass_builder.add_default_texture("textures/voxel/glass_01.png");
- glass_builder.set_render_mode(world::VRENDER_BLEND);
- glass_builder.set_surface_material(world::VMAT_GLASS);
- glass = world::voxel_registry::register_voxel(glass_builder);
+ glass_builder.set_render_mode(VRENDER_BLEND);
+ glass_builder.set_surface_material(VMAT_GLASS);
+ glass = voxel_registry::register_voxel(glass_builder);
- auto slime_builder = world::VoxelBuilder("slime");
+ auto slime_builder = VoxelBuilder("slime");
slime_builder.add_default_texture("textures/voxel/slime_01.png");
- slime_builder.set_render_mode(world::VRENDER_BLEND);
- slime_builder.set_surface_material(world::VMAT_SLOSH);
- slime_builder.set_touch_type(world::VTOUCH_BOUNCE);
+ slime_builder.set_render_mode(VRENDER_BLEND);
+ slime_builder.set_surface_material(VMAT_SLOSH);
+ slime_builder.set_touch_type(VTOUCH_BOUNCE);
slime_builder.set_touch_values({ 0.00f, 0.60f, 0.00f });
- slime = world::voxel_registry::register_voxel(slime_builder);
+ slime = voxel_registry::register_voxel(slime_builder);
}
diff --git a/src/game/shared/game_voxels.hh b/src/game/shared/game_voxels.hh
index a8d155f..f46385c 100644
--- a/src/game/shared/game_voxels.hh
+++ b/src/game/shared/game_voxels.hh
@@ -1,23 +1,20 @@
#pragma once
-namespace world
-{
class Voxel;
-} // namespace world
namespace game_voxels
{
-extern const world::Voxel* cobblestone;
-extern const world::Voxel* dirt;
-extern const world::Voxel* grass;
-extern const world::Voxel* stone;
-extern const world::Voxel* vtest;
-extern const world::Voxel* vtest_ck;
-extern const world::Voxel* oak_leaves;
-extern const world::Voxel* oak_planks;
-extern const world::Voxel* oak_log;
-extern const world::Voxel* glass;
-extern const world::Voxel* slime;
+extern const Voxel* cobblestone;
+extern const Voxel* dirt;
+extern const Voxel* grass;
+extern const Voxel* stone;
+extern const Voxel* vtest;
+extern const Voxel* vtest_ck;
+extern const Voxel* oak_leaves;
+extern const Voxel* oak_planks;
+extern const Voxel* oak_log;
+extern const Voxel* glass;
+extern const Voxel* slime;
} // namespace game_voxels
namespace game_voxels
diff --git a/src/game/shared/protocol.cc b/src/game/shared/protocol.cc
index 4c0c894..d274955 100644
--- a/src/game/shared/protocol.cc
+++ b/src/game/shared/protocol.cc
@@ -14,8 +14,8 @@
#include "shared/globals.hh"
-static io::ReadBuffer read_buffer;
-static io::WriteBuffer write_buffer;
+static ReadBuffer read_buffer;
+static WriteBuffer write_buffer;
ENetPacket* protocol::encode(const protocol::StatusRequest& packet, enet_uint32 flags)
{
@@ -448,9 +448,9 @@ ENetPacket* protocol::utils::make_chat_message(std::string_view message, enet_ui
return protocol::encode(packet, flags);
}
-ENetPacket* protocol::utils::make_chunk_voxels(world::Dimension* dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
- if(auto component = dimension->chunks.try_get<world::ChunkComponent>(entity)) {
+ if(auto component = dimension->chunks.try_get<ChunkComponent>(entity)) {
protocol::ChunkVoxels packet;
packet.chunk = component->cpos;
packet.voxels = component->chunk->get_voxels();
@@ -460,9 +460,9 @@ ENetPacket* protocol::utils::make_chunk_voxels(world::Dimension* dimension, entt
return nullptr;
}
-ENetPacket* protocol::utils::make_entity_head(world::Dimension* dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
- if(auto component = dimension->entities.try_get<entity::Head>(entity)) {
+ if(auto component = dimension->entities.try_get<Head>(entity)) {
protocol::EntityHead packet;
packet.entity = entity;
packet.angles = component->angles;
@@ -472,9 +472,9 @@ ENetPacket* protocol::utils::make_entity_head(world::Dimension* dimension, entt:
return nullptr;
}
-ENetPacket* protocol::utils::make_entity_transform(world::Dimension* dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
- if(auto component = dimension->entities.try_get<entity::Transform>(entity)) {
+ if(auto component = dimension->entities.try_get<Transform>(entity)) {
protocol::EntityTransform packet;
packet.entity = entity;
packet.chunk = component->chunk;
@@ -486,9 +486,9 @@ ENetPacket* protocol::utils::make_entity_transform(world::Dimension* dimension,
return nullptr;
}
-ENetPacket* protocol::utils::make_entity_velocity(world::Dimension* dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
- if(auto component = dimension->entities.try_get<entity::Velocity>(entity)) {
+ if(auto component = dimension->entities.try_get<Velocity>(entity)) {
protocol::EntityVelocity packet;
packet.entity = entity;
packet.value = component->value;
@@ -498,9 +498,9 @@ ENetPacket* protocol::utils::make_entity_velocity(world::Dimension* dimension, e
return nullptr;
}
-ENetPacket* protocol::utils::make_entity_player(world::Dimension* dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
- if(dimension->entities.any_of<entity::Player>(entity)) {
+ if(dimension->entities.any_of<Player>(entity)) {
protocol::EntityPlayer packet;
packet.entity = entity;
return protocol::encode(packet, flags);
@@ -509,7 +509,7 @@ ENetPacket* protocol::utils::make_entity_player(world::Dimension* dimension, ent
return nullptr;
}
-ENetPacket* protocol::utils::make_dimension_info(const world::Dimension* dimension)
+ENetPacket* protocol::utils::make_dimension_info(const Dimension* dimension)
{
protocol::DimensionInfo packet;
packet.name = dimension->get_name();
diff --git a/src/game/shared/protocol.hh b/src/game/shared/protocol.hh
index b222342..2582406 100644
--- a/src/game/shared/protocol.hh
+++ b/src/game/shared/protocol.hh
@@ -2,10 +2,7 @@
#include "shared/world/chunk.hh"
-namespace world
-{
class Dimension;
-} // namespace world
namespace protocol
{
@@ -93,16 +90,16 @@ ENetPacket* make_chat_message(std::string_view message, enet_uint32 flags = ENET
namespace protocol::utils
{
-ENetPacket* make_chunk_voxels(world::Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
} // namespace protocol::utils
namespace protocol::utils
{
-ENetPacket* make_entity_head(world::Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket* make_entity_transform(world::Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket* make_entity_velocity(world::Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket* make_entity_player(world::Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket* make_dimension_info(const world::Dimension* dimension);
+ENetPacket* make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_dimension_info(const Dimension* dimension);
} // namespace protocol::utils
struct protocol::StatusRequest final : public protocol::Base<0x0000> {
@@ -140,7 +137,7 @@ struct protocol::Disconnect final : public protocol::Base<0x0004> {
struct protocol::ChunkVoxels final : public protocol::Base<0x0005> {
chunk_pos chunk;
- world::VoxelStorage voxels;
+ VoxelStorage voxels;
};
struct protocol::EntityTransform final : public protocol::Base<0x0006> {
diff --git a/src/game/shared/splash.cc b/src/game/shared/splash.cc
index 4568779..86ed0d0 100644
--- a/src/game/shared/splash.cc
+++ b/src/game/shared/splash.cc
@@ -39,7 +39,7 @@ static void splash_init_filename(std::string_view filename)
splash_random.seed(std::random_device()());
}
else {
- splash_lines.push_back(std::format("{}: {}", filename, io::physfs_error()));
+ splash_lines.push_back(std::format("{}: {}", filename, physfs_error()));
splash_random.seed(std::random_device()());
}
}
diff --git a/src/game/shared/world/chunk.cc b/src/game/shared/world/chunk.cc
index e2d60cb..10da80e 100644
--- a/src/game/shared/world/chunk.cc
+++ b/src/game/shared/world/chunk.cc
@@ -6,7 +6,7 @@
#include "shared/coord.hh"
-world::Chunk::Chunk(entt::entity entity, Dimension* dimension)
+Chunk::Chunk(entt::entity entity, Dimension* dimension)
{
m_entity = entity;
m_dimension = dimension;
@@ -14,12 +14,12 @@ world::Chunk::Chunk(entt::entity entity, Dimension* dimension)
m_biome = BIOME_VOID;
}
-const world::Voxel* world::Chunk::get_voxel(const local_pos& lpos) const
+const Voxel* Chunk::get_voxel(const local_pos& lpos) const
{
return get_voxel(coord::to_index(lpos));
}
-const world::Voxel* world::Chunk::get_voxel(const std::size_t index) const
+const Voxel* Chunk::get_voxel(const std::size_t index) const
{
if(index >= CHUNK_VOLUME) {
return nullptr;
@@ -28,12 +28,12 @@ const world::Voxel* world::Chunk::get_voxel(const std::size_t index) const
return voxel_registry::find(m_voxels[index]);
}
-void world::Chunk::set_voxel(const Voxel* voxel, const local_pos& lpos)
+void Chunk::set_voxel(const Voxel* voxel, const local_pos& lpos)
{
set_voxel(voxel, coord::to_index(lpos));
}
-void world::Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
+void Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
{
if(index < CHUNK_VOLUME) {
m_voxels[index] = voxel ? voxel->get_id() : NULL_VOXEL_ID;
@@ -41,32 +41,32 @@ void world::Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
}
}
-const world::VoxelStorage& world::Chunk::get_voxels(void) const
+const VoxelStorage& Chunk::get_voxels(void) const
{
return m_voxels;
}
-void world::Chunk::set_voxels(const VoxelStorage& voxels)
+void Chunk::set_voxels(const VoxelStorage& voxels)
{
m_voxels = voxels;
}
-unsigned int world::Chunk::get_biome(void) const
+unsigned int Chunk::get_biome(void) const
{
return m_biome;
}
-void world::Chunk::set_biome(unsigned int biome)
+void Chunk::set_biome(unsigned int biome)
{
m_biome = biome;
}
-entt::entity world::Chunk::get_entity(void) const
+entt::entity Chunk::get_entity(void) const
{
return m_entity;
}
-world::Dimension* world::Chunk::get_dimension(void) const
+Dimension* Chunk::get_dimension(void) const
{
return m_dimension;
}
diff --git a/src/game/shared/world/chunk.hh b/src/game/shared/world/chunk.hh
index 7518127..f8e38b4 100644
--- a/src/game/shared/world/chunk.hh
+++ b/src/game/shared/world/chunk.hh
@@ -6,14 +6,9 @@
constexpr static unsigned int BIOME_VOID = 0U;
-namespace world
-{
class Dimension;
class Voxel;
-} // namespace world
-namespace world
-{
class Chunk final {
public:
explicit Chunk(entt::entity entity, Dimension* dimension);
@@ -40,4 +35,3 @@ private:
VoxelStorage m_voxels;
unsigned int m_biome;
};
-} // namespace world
diff --git a/src/game/shared/world/chunk_aabb.hh b/src/game/shared/world/chunk_aabb.hh
index f07d3e1..0f8851c 100644
--- a/src/game/shared/world/chunk_aabb.hh
+++ b/src/game/shared/world/chunk_aabb.hh
@@ -4,7 +4,4 @@
#include "shared/types.hh"
-namespace world
-{
using ChunkAABB = math::AABB<chunk_pos::value_type>;
-} // namespace world
diff --git a/src/game/shared/world/dimension.cc b/src/game/shared/world/dimension.cc
index 0088753..84ca539 100644
--- a/src/game/shared/world/dimension.cc
+++ b/src/game/shared/world/dimension.cc
@@ -8,13 +8,13 @@
#include "shared/coord.hh"
#include "shared/globals.hh"
-world::Dimension::Dimension(std::string_view name, float gravity)
+Dimension::Dimension(std::string_view name, float gravity)
{
m_name = name;
m_gravity = gravity;
}
-world::Dimension::~Dimension(void)
+Dimension::~Dimension(void)
{
for(const auto it : m_chunkmap)
delete it.second;
@@ -22,17 +22,17 @@ world::Dimension::~Dimension(void)
chunks.clear();
}
-std::string_view world::Dimension::get_name(void) const
+std::string_view Dimension::get_name(void) const
{
return m_name;
}
-float world::Dimension::get_gravity(void) const
+float Dimension::get_gravity(void) const
{
return m_gravity;
}
-world::Chunk* world::Dimension::create_chunk(const chunk_pos& cpos)
+Chunk* Dimension::create_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -58,7 +58,7 @@ world::Chunk* world::Dimension::create_chunk(const chunk_pos& cpos)
return m_chunkmap.insert_or_assign(cpos, std::move(chunk)).first->second;
}
-world::Chunk* world::Dimension::find_chunk(entt::entity entity) const
+Chunk* Dimension::find_chunk(entt::entity entity) const
{
if(chunks.valid(entity)) {
return chunks.get<ChunkComponent>(entity).chunk;
@@ -68,7 +68,7 @@ world::Chunk* world::Dimension::find_chunk(entt::entity entity) const
}
}
-world::Chunk* world::Dimension::find_chunk(const chunk_pos& cpos) const
+Chunk* Dimension::find_chunk(const chunk_pos& cpos) const
{
auto it = m_chunkmap.find(cpos);
@@ -80,7 +80,7 @@ world::Chunk* world::Dimension::find_chunk(const chunk_pos& cpos) const
}
}
-void world::Dimension::remove_chunk(entt::entity entity)
+void Dimension::remove_chunk(entt::entity entity)
{
if(chunks.valid(entity)) {
auto& component = chunks.get<ChunkComponent>(entity);
@@ -89,7 +89,7 @@ void world::Dimension::remove_chunk(entt::entity entity)
}
}
-void world::Dimension::remove_chunk(const chunk_pos& cpos)
+void Dimension::remove_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -99,7 +99,7 @@ void world::Dimension::remove_chunk(const chunk_pos& cpos)
}
}
-void world::Dimension::remove_chunk(Chunk* chunk)
+void Dimension::remove_chunk(Chunk* chunk)
{
if(chunk) {
const auto& component = chunks.get<ChunkComponent>(chunk->get_entity());
@@ -108,7 +108,7 @@ void world::Dimension::remove_chunk(Chunk* chunk)
}
}
-const world::Voxel* world::Dimension::get_voxel(const voxel_pos& vpos) const
+const Voxel* Dimension::get_voxel(const voxel_pos& vpos) const
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
@@ -120,7 +120,7 @@ const world::Voxel* world::Dimension::get_voxel(const voxel_pos& vpos) const
return nullptr;
}
-const world::Voxel* world::Dimension::get_voxel(const chunk_pos& cpos, const local_pos& lpos) const
+const Voxel* Dimension::get_voxel(const chunk_pos& cpos, const local_pos& lpos) const
{
// This allows accessing get_voxel with negative
// local coordinates that usually would result in an
@@ -128,7 +128,7 @@ const world::Voxel* world::Dimension::get_voxel(const chunk_pos& cpos, const loc
return get_voxel(coord::to_voxel(cpos, lpos));
}
-bool world::Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
+bool Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
@@ -165,7 +165,7 @@ bool world::Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
return false;
}
-bool world::Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos)
+bool Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos)
{
// This allows accessing set_voxel with negative
// local coordinates that usually would result in an
@@ -173,15 +173,15 @@ bool world::Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, cons
return set_voxel(voxel, coord::to_voxel(cpos, lpos));
}
-void world::Dimension::init(io::ConfigMap& config)
+void Dimension::init(ConfigMap& config)
{
}
-void world::Dimension::init_late(std::uint64_t global_seed)
+void Dimension::init_late(std::uint64_t global_seed)
{
}
-bool world::Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels)
+bool Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels)
{
return false;
}
diff --git a/src/game/shared/world/dimension.hh b/src/game/shared/world/dimension.hh
index 6549bf6..b57640a 100644
--- a/src/game/shared/world/dimension.hh
+++ b/src/game/shared/world/dimension.hh
@@ -3,26 +3,15 @@
#include "shared/const.hh"
#include "shared/types.hh"
-namespace io
-{
class ConfigMap;
-} // namespace io
-namespace world
-{
class Chunk;
class Voxel;
class VoxelStorage;
-} // namespace world
-namespace world
-{
using dimension_entropy_map = std::array<std::uint64_t, CHUNK_AREA>;
using dimension_height_map = std::array<voxel_pos::value_type, CHUNK_AREA>;
-} // namespace world
-namespace world
-{
class Dimension {
public:
explicit Dimension(std::string_view name, float gravity);
@@ -48,7 +37,7 @@ public:
bool set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos);
public:
- virtual void init(io::ConfigMap& config);
+ virtual void init(ConfigMap& config);
virtual void init_late(std::uint64_t global_seed);
virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels);
@@ -61,18 +50,12 @@ private:
emhash8::HashMap<chunk_pos, Chunk*> m_chunkmap;
float m_gravity;
};
-} // namespace world
-namespace world
-{
struct ChunkComponent final {
chunk_pos cpos;
Chunk* chunk;
};
-} // namespace world
-namespace world
-{
struct ChunkCreateEvent final {
Dimension* dimension;
chunk_pos cpos;
@@ -98,4 +81,3 @@ struct VoxelSetEvent final {
local_pos lpos;
Chunk* chunk;
};
-} // namespace world
diff --git a/src/game/shared/world/feature.cc b/src/game/shared/world/feature.cc
index 2468473..3974082 100644
--- a/src/game/shared/world/feature.cc
+++ b/src/game/shared/world/feature.cc
@@ -8,7 +8,7 @@
#include "shared/coord.hh"
-void world::Feature::place(const voxel_pos& vpos, Dimension* dimension) const
+void Feature::place(const voxel_pos& vpos, Dimension* dimension) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
@@ -30,7 +30,7 @@ void world::Feature::place(const voxel_pos& vpos, Dimension* dimension) const
}
}
-void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const
+void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
@@ -52,7 +52,7 @@ void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk&
}
}
-void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const
+void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
diff --git a/src/game/shared/world/feature.hh b/src/game/shared/world/feature.hh
index 0d28b20..b80869d 100644
--- a/src/game/shared/world/feature.hh
+++ b/src/game/shared/world/feature.hh
@@ -2,16 +2,11 @@
#include "shared/types.hh"
-namespace world
-{
class Chunk;
class Dimension;
class Voxel;
class VoxelStorage;
-} // namespace world
-namespace world
-{
class Feature final : public std::vector<std::tuple<voxel_pos, const Voxel*, bool>> {
public:
Feature(void) = default;
@@ -22,4 +17,3 @@ public:
void place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const;
void place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const;
};
-} // namespace world
diff --git a/src/game/shared/world/item.cc b/src/game/shared/world/item.cc
index 5e60609..bc1546a 100644
--- a/src/game/shared/world/item.cc
+++ b/src/game/shared/world/item.cc
@@ -6,17 +6,17 @@
#include "shared/world/voxel.hh"
-world::Item::Item(const Item& source, item_id id) noexcept : Item(source)
+Item::Item(const Item& source, item_id id) noexcept : Item(source)
{
m_id = id;
}
-void world::Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
+void Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
{
m_cached_texture = std::move(texture);
}
-std::uint64_t world::Item::get_checksum(std::uint64_t combine) const
+std::uint64_t Item::get_checksum(std::uint64_t combine) const
{
combine = math::crc64(m_name.data(), m_name.size(), combine);
combine = math::crc64(m_texture.data(), m_texture.size(), combine);
@@ -27,29 +27,29 @@ std::uint64_t world::Item::get_checksum(std::uint64_t combine) const
return combine;
}
-world::ItemBuilder::ItemBuilder(std::string_view name)
+ItemBuilder::ItemBuilder(std::string_view name)
{
set_name(name);
}
-void world::ItemBuilder::set_name(std::string_view name)
+void ItemBuilder::set_name(std::string_view name)
{
assert(name.size());
m_name = name;
}
-void world::ItemBuilder::set_texture(std::string_view texture)
+void ItemBuilder::set_texture(std::string_view texture)
{
m_texture = texture;
}
-void world::ItemBuilder::set_place_voxel(const Voxel* place_voxel)
+void ItemBuilder::set_place_voxel(const Voxel* place_voxel)
{
m_place_voxel = place_voxel;
}
-std::unique_ptr<world::Item> world::ItemBuilder::build(item_id id) const
+std::unique_ptr<Item> ItemBuilder::build(item_id id) const
{
return std::make_unique<Item>(*this, id);
}
diff --git a/src/game/shared/world/item.hh b/src/game/shared/world/item.hh
index ffa7f5c..bcec37a 100644
--- a/src/game/shared/world/item.hh
+++ b/src/game/shared/world/item.hh
@@ -9,13 +9,8 @@
// anywhere else in the shared and server code
struct TextureGUI;
-namespace world
-{
class Voxel;
-} // namespace world
-namespace world
-{
class Item {
public:
Item(void) = default;
@@ -41,10 +36,7 @@ protected:
mutable resource_ptr<TextureGUI> m_cached_texture; // Client-side only
};
-} // namespace world
-namespace world
-{
class ItemBuilder final : public Item {
public:
explicit ItemBuilder(std::string_view name);
@@ -56,29 +48,28 @@ public:
std::unique_ptr<Item> build(item_id id) const;
};
-} // namespace world
-constexpr std::string_view world::Item::get_name(void) const noexcept
+constexpr std::string_view Item::get_name(void) const noexcept
{
return m_name;
}
-constexpr item_id world::Item::get_id(void) const noexcept
+constexpr item_id Item::get_id(void) const noexcept
{
return m_id;
}
-constexpr std::string_view world::Item::get_texture(void) const noexcept
+constexpr std::string_view Item::get_texture(void) const noexcept
{
return m_texture;
}
-constexpr const world::Voxel* world::Item::get_place_voxel(void) const noexcept
+constexpr const Voxel* Item::get_place_voxel(void) const noexcept
{
return m_place_voxel;
}
-constexpr resource_ptr<TextureGUI>& world::Item::get_cached_texture(void) const noexcept
+constexpr resource_ptr<TextureGUI>& Item::get_cached_texture(void) const noexcept
{
return m_cached_texture;
}
diff --git a/src/game/shared/world/item_registry.cc b/src/game/shared/world/item_registry.cc
index d89abe9..c7d8d9b 100644
--- a/src/game/shared/world/item_registry.cc
+++ b/src/game/shared/world/item_registry.cc
@@ -7,19 +7,19 @@
#include "shared/world/voxel_registry.hh"
static std::uint64_t registry_checksum = 0U;
-std::unordered_map<std::string, item_id> world::item_registry::names = {};
-std::vector<std::unique_ptr<world::Item>> world::item_registry::items = {};
+std::unordered_map<std::string, item_id> item_registry::names = {};
+std::vector<std::unique_ptr<Item>> item_registry::items = {};
static void recalculate_checksum(void)
{
registry_checksum = 0U;
- for(const auto& item : world::item_registry::items) {
+ for(const auto& item : item_registry::items) {
registry_checksum = item->get_checksum(registry_checksum);
}
}
-world::Item* world::item_registry::register_item(const ItemBuilder& builder)
+Item* item_registry::register_item(const ItemBuilder& builder)
{
assert(builder.get_name().size());
assert(nullptr == find(builder.get_name()));
@@ -35,7 +35,7 @@ world::Item* world::item_registry::register_item(const ItemBuilder& builder)
return items.back().get();
}
-world::Item* world::item_registry::find(std::string_view name)
+Item* item_registry::find(std::string_view name)
{
const auto it = names.find(std::string(name));
@@ -46,7 +46,7 @@ world::Item* world::item_registry::find(std::string_view name)
return items[it->second - 1].get();
}
-world::Item* world::item_registry::find(const item_id item)
+Item* item_registry::find(const item_id item)
{
if(item == NULL_ITEM_ID || item > items.size()) {
return nullptr;
@@ -55,14 +55,14 @@ world::Item* world::item_registry::find(const item_id item)
return items[item - 1].get();
}
-void world::item_registry::purge(void)
+void item_registry::purge(void)
{
registry_checksum = 0U;
items.clear();
names.clear();
}
-std::uint64_t world::item_registry::get_checksum(void)
+std::uint64_t item_registry::get_checksum(void)
{
return registry_checksum;
}
diff --git a/src/game/shared/world/item_registry.hh b/src/game/shared/world/item_registry.hh
index a841a2d..f8fe641 100644
--- a/src/game/shared/world/item_registry.hh
+++ b/src/game/shared/world/item_registry.hh
@@ -2,25 +2,25 @@
#include "shared/world/item.hh"
-namespace world::item_registry
+namespace item_registry
{
extern std::unordered_map<std::string, item_id> names;
extern std::vector<std::unique_ptr<Item>> items;
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
Item* register_item(const ItemBuilder& builder);
Item* find(std::string_view name);
Item* find(const item_id item);
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
void purge(void);
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
std::uint64_t get_checksum(void);
-} // namespace world::item_registry
+} // namespace item_registry
diff --git a/src/game/shared/world/ray_dda.cc b/src/game/shared/world/ray_dda.cc
index d6383b9..5dbf82e 100644
--- a/src/game/shared/world/ray_dda.cc
+++ b/src/game/shared/world/ray_dda.cc
@@ -6,20 +6,17 @@
#include "shared/coord.hh"
-world::RayDDA::RayDDA(const world::Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+RayDDA::RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(dimension, start_chunk, start_fpos, direction);
}
-world::RayDDA::RayDDA(const world::Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+RayDDA::RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(dimension, start_chunk, start_fpos, direction);
}
-void world::RayDDA::reset(const world::Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+void RayDDA::reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
this->dimension = dimension;
this->start_chunk = start_chunk;
@@ -65,13 +62,12 @@ void world::RayDDA::reset(const world::Dimension* dimension, const chunk_pos& st
}
}
-void world::RayDDA::reset(const world::Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+void RayDDA::reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(&dimension, start_chunk, start_fpos, direction);
}
-const world::Voxel* world::RayDDA::step(void)
+const Voxel* RayDDA::step(void)
{
if(side_dist.x < side_dist.z) {
if(side_dist.x < side_dist.y) {
diff --git a/src/game/shared/world/ray_dda.hh b/src/game/shared/world/ray_dda.hh
index 0f548ba..72f746e 100644
--- a/src/game/shared/world/ray_dda.hh
+++ b/src/game/shared/world/ray_dda.hh
@@ -2,14 +2,9 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
class Voxel;
-} // namespace world
-namespace world
-{
class RayDDA final {
public:
RayDDA(void) = default;
@@ -35,4 +30,3 @@ public:
voxel_pos vnormal;
voxel_pos vpos;
};
-} // namespace world
diff --git a/src/game/shared/world/voxel.cc b/src/game/shared/world/voxel.cc
index 21fe62c..4f47c2d 100644
--- a/src/game/shared/world/voxel.cc
+++ b/src/game/shared/world/voxel.cc
@@ -6,33 +6,33 @@
#include "shared/world/dimension.hh"
-world::Voxel::Voxel(const Voxel& source, voxel_id id) noexcept : Voxel(source)
+Voxel::Voxel(const Voxel& source, voxel_id id) noexcept : Voxel(source)
{
m_id = id;
}
-void world::Voxel::on_place(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_place(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_place) {
m_on_place(dimension, vpos);
}
}
-void world::Voxel::on_remove(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_remove(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_remove) {
m_on_remove(dimension, vpos);
}
}
-void world::Voxel::on_tick(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_tick(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_tick) {
m_on_tick(dimension, vpos);
}
}
-std::size_t world::Voxel::get_random_texture_index(VoxelFace face, const voxel_pos& vpos) const
+std::size_t Voxel::get_random_texture_index(VoxelFace face, const voxel_pos& vpos) const
{
const auto& textures = get_face_textures(face);
@@ -46,7 +46,7 @@ std::size_t world::Voxel::get_random_texture_index(VoxelFace face, const voxel_p
return static_cast<std::size_t>(hash % textures.size());
}
-void world::Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_t plane)
+void Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_t plane)
{
assert(face < m_cached_face_offsets.size());
assert(face < m_cached_face_planes.size());
@@ -55,7 +55,7 @@ void world::Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_
m_cached_face_planes[face] = plane;
}
-std::uint64_t world::Voxel::get_checksum(std::uint64_t combine) const
+std::uint64_t Voxel::get_checksum(std::uint64_t combine) const
{
combine = math::crc64(m_name.data(), m_name.size(), combine);
combine += static_cast<std::uint64_t>(m_shape);
@@ -63,76 +63,76 @@ std::uint64_t world::Voxel::get_checksum(std::uint64_t combine) const
return combine;
}
-world::VoxelBuilder::VoxelBuilder(std::string_view name)
+VoxelBuilder::VoxelBuilder(std::string_view name)
{
set_name(name);
}
-void world::VoxelBuilder::set_on_place(VoxelOnPlaceFunc func) noexcept
+void VoxelBuilder::set_on_place(VoxelOnPlaceFunc func) noexcept
{
m_on_place = std::move(func);
}
-void world::VoxelBuilder::set_on_remove(VoxelOnRemoveFunc func) noexcept
+void VoxelBuilder::set_on_remove(VoxelOnRemoveFunc func) noexcept
{
m_on_remove = std::move(func);
}
-void world::VoxelBuilder::set_on_tick(VoxelOnTickFunc func) noexcept
+void VoxelBuilder::set_on_tick(VoxelOnTickFunc func) noexcept
{
m_on_tick = std::move(func);
}
-void world::VoxelBuilder::set_name(std::string_view name) noexcept
+void VoxelBuilder::set_name(std::string_view name) noexcept
{
assert(name.size());
m_name = name;
}
-void world::VoxelBuilder::set_render_mode(VoxelRender mode) noexcept
+void VoxelBuilder::set_render_mode(VoxelRender mode) noexcept
{
m_render_mode = mode;
}
-void world::VoxelBuilder::set_shape(VoxelShape shape) noexcept
+void VoxelBuilder::set_shape(VoxelShape shape) noexcept
{
m_shape = shape;
}
-void world::VoxelBuilder::set_animated(bool animated) noexcept
+void VoxelBuilder::set_animated(bool animated) noexcept
{
m_animated = animated;
}
-void world::VoxelBuilder::set_touch_type(VoxelTouch type) noexcept
+void VoxelBuilder::set_touch_type(VoxelTouch type) noexcept
{
m_touch_type = type;
}
-void world::VoxelBuilder::set_touch_values(const glm::fvec3& values) noexcept
+void VoxelBuilder::set_touch_values(const glm::fvec3& values) noexcept
{
m_touch_values = values;
}
-void world::VoxelBuilder::set_surface_material(VoxelMaterial material) noexcept
+void VoxelBuilder::set_surface_material(VoxelMaterial material) noexcept
{
m_surface_material = material;
}
-void world::VoxelBuilder::set_collision(const math::AABBf& box) noexcept
+void VoxelBuilder::set_collision(const math::AABBf& box) noexcept
{
m_collision = box;
}
-void world::VoxelBuilder::add_default_texture(std::string_view path)
+void VoxelBuilder::add_default_texture(std::string_view path)
{
assert(path.size());
m_default_textures.emplace_back(path);
}
-void world::VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path)
+void VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path)
{
assert(face < m_face_textures.size());
assert(path.size());
@@ -140,7 +140,7 @@ void world::VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path
m_face_textures[face].emplace_back(path);
}
-std::unique_ptr<world::Voxel> world::VoxelBuilder::build(voxel_id id) const
+std::unique_ptr<Voxel> VoxelBuilder::build(voxel_id id) const
{
assert(m_name.size());
assert(id);
diff --git a/src/game/shared/world/voxel.hh b/src/game/shared/world/voxel.hh
index 6013962..0a8c4a3 100644
--- a/src/game/shared/world/voxel.hh
+++ b/src/game/shared/world/voxel.hh
@@ -4,13 +4,8 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace world
-{
enum VoxelRender : unsigned int {
VRENDER_NONE = 0U, ///< The voxel is not rendered at all
VRENDER_OPAQUE, ///< The voxel is fully opaque
@@ -65,17 +60,11 @@ enum VoxelVisBits : unsigned int {
VVIS_UP = 1U << VFACE_TOP, ///< Positive Y
VVIS_DOWN = 1U << VFACE_BOTTOM, ///< Negative Y
};
-} // namespace world
-namespace world
-{
using VoxelOnPlaceFunc = std::function<void(Dimension*, const voxel_pos&)>;
using VoxelOnRemoveFunc = std::function<void(Dimension*, const voxel_pos&)>;
using VoxelOnTickFunc = std::function<void(Dimension*, const voxel_pos&)>;
-} // namespace world
-namespace world
-{
class Voxel {
public:
Voxel(void) = default;
@@ -154,10 +143,7 @@ protected:
VoxelOnRemoveFunc m_on_remove;
VoxelOnTickFunc m_on_tick;
};
-} // namespace world
-namespace world
-{
class VoxelBuilder final : public Voxel {
public:
VoxelBuilder(void) = default;
@@ -184,59 +170,58 @@ public:
std::unique_ptr<Voxel> build(voxel_id id) const;
};
-} // namespace world
-constexpr std::string_view world::Voxel::get_name(void) const noexcept
+constexpr std::string_view Voxel::get_name(void) const noexcept
{
return m_name;
}
-constexpr voxel_id world::Voxel::get_id(void) const noexcept
+constexpr voxel_id Voxel::get_id(void) const noexcept
{
return m_id;
}
-constexpr world::VoxelRender world::Voxel::get_render_mode(void) const noexcept
+constexpr VoxelRender Voxel::get_render_mode(void) const noexcept
{
return m_render_mode;
}
-constexpr world::VoxelShape world::Voxel::get_shape(void) const noexcept
+constexpr VoxelShape Voxel::get_shape(void) const noexcept
{
return m_shape;
}
-constexpr bool world::Voxel::is_animated(void) const noexcept
+constexpr bool Voxel::is_animated(void) const noexcept
{
return m_animated;
}
-constexpr world::VoxelTouch world::Voxel::get_touch_type(void) const noexcept
+constexpr VoxelTouch Voxel::get_touch_type(void) const noexcept
{
return m_touch_type;
}
-constexpr const glm::fvec3& world::Voxel::get_touch_values(void) const noexcept
+constexpr const glm::fvec3& Voxel::get_touch_values(void) const noexcept
{
return m_touch_values;
}
-constexpr world::VoxelMaterial world::Voxel::get_surface_material(void) const noexcept
+constexpr VoxelMaterial Voxel::get_surface_material(void) const noexcept
{
return m_surface_material;
}
-constexpr const math::AABBf& world::Voxel::get_collision(void) const noexcept
+constexpr const math::AABBf& Voxel::get_collision(void) const noexcept
{
return m_collision;
}
-constexpr const std::vector<std::string>& world::Voxel::get_default_textures(void) const noexcept
+constexpr const std::vector<std::string>& Voxel::get_default_textures(void) const noexcept
{
return m_default_textures;
}
-constexpr const std::vector<std::string>& world::Voxel::get_face_textures(VoxelFace face) const noexcept
+constexpr const std::vector<std::string>& Voxel::get_face_textures(VoxelFace face) const noexcept
{
assert(face <= m_face_textures.size());
@@ -247,40 +232,40 @@ constexpr const std::vector<std::string>& world::Voxel::get_face_textures(VoxelF
return m_face_textures[face];
}
-constexpr std::size_t world::Voxel::get_cached_face_offset(VoxelFace face) const noexcept
+constexpr std::size_t Voxel::get_cached_face_offset(VoxelFace face) const noexcept
{
assert(face <= m_cached_face_offsets.size());
return m_cached_face_offsets[face];
}
-constexpr std::size_t world::Voxel::get_cached_face_plane(VoxelFace face) const noexcept
+constexpr std::size_t Voxel::get_cached_face_plane(VoxelFace face) const noexcept
{
assert(face <= m_cached_face_planes.size());
return m_cached_face_planes[face];
}
-template<world::VoxelRender RenderMode>
-constexpr bool world::Voxel::is_render_mode(void) const noexcept
+template<VoxelRender RenderMode>
+constexpr bool Voxel::is_render_mode(void) const noexcept
{
return m_render_mode == RenderMode;
}
-template<world::VoxelShape Shape>
-constexpr bool world::Voxel::is_shape(void) const noexcept
+template<VoxelShape Shape>
+constexpr bool Voxel::is_shape(void) const noexcept
{
return m_shape == Shape;
}
-template<world::VoxelTouch TouchType>
-constexpr bool world::Voxel::is_touch_type(void) const noexcept
+template<VoxelTouch TouchType>
+constexpr bool Voxel::is_touch_type(void) const noexcept
{
return m_touch_type == TouchType;
}
-template<world::VoxelMaterial Material>
-constexpr bool world::Voxel::is_surface_material(void) const noexcept
+template<VoxelMaterial Material>
+constexpr bool Voxel::is_surface_material(void) const noexcept
{
return m_surface_material == Material;
}
diff --git a/src/game/shared/world/voxel_registry.cc b/src/game/shared/world/voxel_registry.cc
index fae83fa..f950a4d 100644
--- a/src/game/shared/world/voxel_registry.cc
+++ b/src/game/shared/world/voxel_registry.cc
@@ -3,19 +3,19 @@
#include "shared/world/voxel_registry.hh"
static std::uint64_t registry_checksum = 0U;
-emhash8::HashMap<std::string, voxel_id> world::voxel_registry::names;
-std::vector<std::unique_ptr<world::Voxel>> world::voxel_registry::voxels;
+emhash8::HashMap<std::string, voxel_id> voxel_registry::names;
+std::vector<std::unique_ptr<Voxel>> voxel_registry::voxels;
static void recalculate_checksum(void)
{
registry_checksum = 0U;
- for(const auto& voxel : world::voxel_registry::voxels) {
+ for(const auto& voxel : voxel_registry::voxels) {
registry_checksum = voxel->get_checksum(registry_checksum);
}
}
-world::Voxel* world::voxel_registry::register_voxel(const VoxelBuilder& builder)
+Voxel* voxel_registry::register_voxel(const VoxelBuilder& builder)
{
assert(builder.get_name().size());
assert(nullptr == find(builder.get_name()));
@@ -31,7 +31,7 @@ world::Voxel* world::voxel_registry::register_voxel(const VoxelBuilder& builder)
return voxels.back().get();
}
-world::Voxel* world::voxel_registry::find(std::string_view name)
+Voxel* voxel_registry::find(std::string_view name)
{
const auto it = names.find(std::string(name));
@@ -42,7 +42,7 @@ world::Voxel* world::voxel_registry::find(std::string_view name)
return voxels[it->second - 1].get();
}
-world::Voxel* world::voxel_registry::find(voxel_id id)
+Voxel* voxel_registry::find(voxel_id id)
{
if(id == NULL_VOXEL_ID || id > voxels.size()) {
return nullptr;
@@ -51,14 +51,14 @@ world::Voxel* world::voxel_registry::find(voxel_id id)
return voxels[id - 1].get();
}
-void world::voxel_registry::purge(void)
+void voxel_registry::purge(void)
{
registry_checksum = 0U;
voxels.clear();
names.clear();
}
-std::uint64_t world::voxel_registry::get_checksum(void)
+std::uint64_t voxel_registry::get_checksum(void)
{
return registry_checksum;
}
diff --git a/src/game/shared/world/voxel_registry.hh b/src/game/shared/world/voxel_registry.hh
index a1e0eee..5dbaf50 100644
--- a/src/game/shared/world/voxel_registry.hh
+++ b/src/game/shared/world/voxel_registry.hh
@@ -2,25 +2,25 @@
#include "shared/world/voxel.hh"
-namespace world::voxel_registry
+namespace voxel_registry
{
extern emhash8::HashMap<std::string, voxel_id> names;
extern std::vector<std::unique_ptr<Voxel>> voxels;
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
Voxel* register_voxel(const VoxelBuilder& builder);
Voxel* find(std::string_view name);
Voxel* find(voxel_id id);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
void purge(void);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
std::uint64_t get_checksum(void);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
diff --git a/src/game/shared/world/voxel_storage.cc b/src/game/shared/world/voxel_storage.cc
index 68e261c..43ca116 100644
--- a/src/game/shared/world/voxel_storage.cc
+++ b/src/game/shared/world/voxel_storage.cc
@@ -4,7 +4,7 @@
#include "core/io/buffer.hh"
-void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const
+void VoxelStorage::serialize(WriteBuffer& buffer) const
{
auto bound = mz_compressBound(sizeof(VoxelStorage));
auto zdata = std::vector<unsigned char>(bound);
@@ -28,7 +28,7 @@ void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const
}
}
-void world::VoxelStorage::deserialize(io::ReadBuffer& buffer)
+void VoxelStorage::deserialize(ReadBuffer& buffer)
{
auto size = static_cast<mz_ulong>(sizeof(VoxelStorage));
auto bound = static_cast<mz_ulong>(buffer.read<std::uint64_t>());
diff --git a/src/game/shared/world/voxel_storage.hh b/src/game/shared/world/voxel_storage.hh
index ac7f03d..ef427b3 100644
--- a/src/game/shared/world/voxel_storage.hh
+++ b/src/game/shared/world/voxel_storage.hh
@@ -3,18 +3,12 @@
#include "shared/const.hh"
#include "shared/types.hh"
-namespace io
-{
class ReadBuffer;
class WriteBuffer;
-} // namespace io
-namespace world
-{
class VoxelStorage final : public std::array<voxel_id, CHUNK_VOLUME> {
public:
using std::array<voxel_id, CHUNK_VOLUME>::array;
- void serialize(io::WriteBuffer& buffer) const;
- void deserialize(io::ReadBuffer& buffer);
+ void serialize(WriteBuffer& buffer) const;
+ void deserialize(ReadBuffer& buffer);
};
-} // namespace world