summaryrefslogtreecommitdiffstats
path: root/src/game/shared/item_registry.hh
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
committeruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
commit6cd00aacfa22fed6a54a9b812f6b069ad16feec0 (patch)
treeb77f4e665da3dd235cdb01e7e6ea78c1c02ecf2e /src/game/shared/item_registry.hh
parentf440914e1ae453768d09383f332bc7844e0a700e (diff)
downloadvoxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.tar.bz2
voxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.zip
Move game sources into src subdirectory
Diffstat (limited to 'src/game/shared/item_registry.hh')
-rw-r--r--src/game/shared/item_registry.hh62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/game/shared/item_registry.hh b/src/game/shared/item_registry.hh
new file mode 100644
index 0000000..17cff9f
--- /dev/null
+++ b/src/game/shared/item_registry.hh
@@ -0,0 +1,62 @@
+#ifndef SHARED_ITEM_REGISTRY_HH
+#define SHARED_ITEM_REGISTRY_HH 1
+#pragma once
+
+#include "core/resource.hh"
+
+#include "shared/types.hh"
+
+// This resource is only defined client-side and
+// resource_ptr<TextureGUI> should remain set to null
+// anywhere else in the shared and server code
+struct TextureGUI;
+
+struct ItemInfo final {
+ std::string name;
+ std::string texture;
+ voxel_id place_voxel;
+
+ resource_ptr<TextureGUI> cached_texture; // Client-side only
+};
+
+class ItemInfoBuilder final {
+public:
+ explicit ItemInfoBuilder(const char* name);
+ virtual ~ItemInfoBuilder(void) = default;
+
+public:
+ ItemInfoBuilder& set_texture(const char* texture);
+ ItemInfoBuilder& set_place_voxel(voxel_id place_voxel);
+
+public:
+ item_id build(void) const;
+
+private:
+ ItemInfo prototype;
+};
+
+namespace item_registry
+{
+extern std::unordered_map<std::string, ItemInfoBuilder> builders;
+extern std::unordered_map<std::string, item_id> names;
+extern std::vector<std::shared_ptr<ItemInfo>> items;
+} // namespace item_registry
+
+namespace item_registry
+{
+ItemInfoBuilder& construct(const char* name);
+ItemInfo* find(const char* name);
+ItemInfo* find(const item_id item);
+} // namespace item_registry
+
+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 */