summaryrefslogtreecommitdiffstats
path: root/game/shared
diff options
context:
space:
mode:
Diffstat (limited to 'game/shared')
-rw-r--r--game/shared/feature.cc16
-rw-r--r--game/shared/feature.hh6
-rw-r--r--game/shared/item_registry.cc14
-rw-r--r--game/shared/item_registry.hh5
-rw-r--r--game/shared/protocol.cc8
-rw-r--r--game/shared/protocol.hh4
-rw-r--r--game/shared/voxel_registry.cc2
-rw-r--r--game/shared/voxel_registry.hh2
8 files changed, 38 insertions, 19 deletions
diff --git a/game/shared/feature.cc b/game/shared/feature.cc
index 6f884b2..845bb40 100644
--- a/game/shared/feature.cc
+++ b/game/shared/feature.cc
@@ -6,10 +6,10 @@
#include "shared/dimension.hh"
#include "shared/voxel_storage.hh"
-void Feature::place(const voxel_pos &vpos, Dimension *dimension, bool overwrite) const
+void Feature::place(const voxel_pos &vpos, Dimension *dimension) const
{
- for(const auto &it : (*this)) {
- auto it_vpos = vpos + it.first;
+ for(const auto [rpos, voxel, overwrite] : (*this)) {
+ auto it_vpos = vpos + rpos;
auto it_cpos = coord::to_chunk(it_vpos);
if(auto chunk = dimension->create_chunk(it_cpos)) {
@@ -23,15 +23,15 @@ void Feature::place(const voxel_pos &vpos, Dimension *dimension, bool overwrite)
continue;
}
- chunk->set_voxel(it.second, it_index);
+ chunk->set_voxel(voxel, it_index);
}
}
}
-void Feature::place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels, bool overwrite) const
+void Feature::place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels) const
{
- for(const auto &it : (*this)) {
- auto it_vpos = vpos + it.first;
+ for(const auto [rpos, voxel, overwrite] : (*this)) {
+ auto it_vpos = vpos + rpos;
auto it_cpos = coord::to_chunk(it_vpos);
if(it_cpos == cpos) {
@@ -45,7 +45,7 @@ void Feature::place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &
continue;
}
- voxels[it_index] = it.second;
+ voxels[it_index] = voxel;
}
}
}
diff --git a/game/shared/feature.hh b/game/shared/feature.hh
index f5fe73b..b5cb262 100644
--- a/game/shared/feature.hh
+++ b/game/shared/feature.hh
@@ -7,14 +7,14 @@
class Dimension;
class VoxelStorage;
-class Feature final : public std::vector<std::pair<voxel_pos, voxel_id>> {
+class Feature final : public std::vector<std::tuple<voxel_pos, voxel_id, bool>> {
public:
explicit Feature(void) = default;
virtual ~Feature(void) = default;
public:
- void place(const voxel_pos &vpos, Dimension *dimension, bool overwrite = false) const;
- void place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels, bool overwrite = false) const;
+ void place(const voxel_pos &vpos, Dimension *dimension) const;
+ void place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels) const;
};
#endif /* SHARED_FEATURE_HH */
diff --git a/game/shared/item_registry.cc b/game/shared/item_registry.cc
index 02164bd..23dffdc 100644
--- a/game/shared/item_registry.cc
+++ b/game/shared/item_registry.cc
@@ -1,6 +1,8 @@
#include "shared/pch.hh"
#include "shared/item_registry.hh"
+#include "core/crc64.hh"
+
#include "shared/voxel_registry.hh"
std::unordered_map<std::string, ItemInfoBuilder> item_registry::builders = {};
@@ -78,3 +80,15 @@ void item_registry::purge(void)
item_registry::names.clear();
item_registry::items.clear();
}
+
+std::uint64_t item_registry::calcualte_checksum(void)
+{
+ std::uint64_t result = 0;
+
+ for(const auto &info : item_registry::items) {
+ result = crc64::get(info->name, result);
+ result += static_cast<std::uint64_t>(info->place_voxel);
+ }
+
+ return result;
+}
diff --git a/game/shared/item_registry.hh b/game/shared/item_registry.hh
index 7160b0b..83b6053 100644
--- a/game/shared/item_registry.hh
+++ b/game/shared/item_registry.hh
@@ -54,4 +54,9 @@ namespace item_registry
void purge(void);
} // namespace item_registry
+namespace item_registry
+{
+std::uint64_t calcualte_checksum(void);
+} // namespace item_registry
+
#endif /* SHARED_ITEM_REGISTRY_HH */
diff --git a/game/shared/protocol.cc b/game/shared/protocol.cc
index e2c79b5..3b32701 100644
--- a/game/shared/protocol.cc
+++ b/game/shared/protocol.cc
@@ -39,8 +39,8 @@ ENetPacket *protocol::encode(const protocol::LoginRequest &packet, enet_uint32 f
write_buffer.reset();
write_buffer.write_UI16(protocol::LoginRequest::ID);
write_buffer.write_UI32(packet.version);
- write_buffer.write_UI64(packet.voxel_def_checksum);
- write_buffer.write_UI64(packet.item_def_checksum);
+ write_buffer.write_UI64(packet.voxel_registry_checksum);
+ write_buffer.write_UI64(packet.item_registry_checksum);
write_buffer.write_UI64(packet.password_hash);
write_buffer.write_string(packet.username.substr(0, protocol::MAX_USERNAME));
return write_buffer.to_packet(flags);
@@ -280,8 +280,8 @@ void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, EN
case protocol::LoginRequest::ID:
login_request.peer = peer;
login_request.version = read_buffer.read_UI32();
- login_request.voxel_def_checksum = read_buffer.read_UI64();
- login_request.item_def_checksum = read_buffer.read_UI64();
+ login_request.voxel_registry_checksum = read_buffer.read_UI64();
+ login_request.item_registry_checksum = read_buffer.read_UI64();
login_request.password_hash = read_buffer.read_UI64();
login_request.username = read_buffer.read_string();
dispatcher.trigger(login_request);
diff --git a/game/shared/protocol.hh b/game/shared/protocol.hh
index 0b8b0f1..727ab1f 100644
--- a/game/shared/protocol.hh
+++ b/game/shared/protocol.hh
@@ -118,8 +118,8 @@ struct protocol::StatusResponse final : public protocol::Base<0x0001> {
struct protocol::LoginRequest final : public protocol::Base<0x0002> {
std::uint32_t version;
- std::uint64_t voxel_def_checksum;
- std::uint64_t item_def_checksum;
+ std::uint64_t voxel_registry_checksum;
+ std::uint64_t item_registry_checksum;
std::uint64_t password_hash;
std::string username;
};
diff --git a/game/shared/voxel_registry.cc b/game/shared/voxel_registry.cc
index dea7179..ce6ee7f 100644
--- a/game/shared/voxel_registry.cc
+++ b/game/shared/voxel_registry.cc
@@ -169,7 +169,7 @@ void voxel_registry::purge(void)
voxel_registry::voxels.clear();
}
-std::uint64_t voxel_registry::checksum(void)
+std::uint64_t voxel_registry::calcualte_checksum(void)
{
std::uint64_t result = 0;
diff --git a/game/shared/voxel_registry.hh b/game/shared/voxel_registry.hh
index 722cec1..b12bc68 100644
--- a/game/shared/voxel_registry.hh
+++ b/game/shared/voxel_registry.hh
@@ -138,7 +138,7 @@ void purge(void);
namespace voxel_registry
{
-std::uint64_t checksum(void);
+std::uint64_t calcualte_checksum(void);
} // namespace voxel_registry
#endif /* SHARED_VOXEL_REGISTRY_HH */