From 458e0005690ea9d579588a0a12368fc2c2c9a93a Mon Sep 17 00:00:00 2001 From: untodesu Date: Tue, 1 Jul 2025 03:08:39 +0500 Subject: I hyper-focued on refactoring again - I put a cool-sounding "we are number one" remix on repeat and straight up grinded the entire repository to a better state until 03:09 AM. I guess I have something wrong in my brain that makes me do this shit --- game/shared/world/item_registry.hh | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 game/shared/world/item_registry.hh (limited to 'game/shared/world/item_registry.hh') diff --git a/game/shared/world/item_registry.hh b/game/shared/world/item_registry.hh new file mode 100644 index 0000000..7cf3bd8 --- /dev/null +++ b/game/shared/world/item_registry.hh @@ -0,0 +1,68 @@ +#ifndef SHARED_ITEM_REGISTRY_HH +#define SHARED_ITEM_REGISTRY_HH 1 +#pragma once + +#include "core/resource/resource.hh" + +#include "shared/types.hh" + +// This resource is only defined client-side and +// resource_ptr should remain set to null +// anywhere else in the shared and server code +struct TextureGUI; + +namespace world +{ +struct ItemInfo final { + std::string name; + std::string texture; + voxel_id place_voxel; + + resource_ptr cached_texture; // Client-side only +}; +} // namespace world + +namespace world +{ +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 world + +namespace world::item_registry +{ +extern std::unordered_map builders; +extern std::unordered_map names; +extern std::vector> items; +} // namespace world::item_registry + +namespace world::item_registry +{ +ItemInfoBuilder& construct(const char* name); +ItemInfo* find(const char* name); +ItemInfo* find(const item_id item); +} // namespace world::item_registry + +namespace world::item_registry +{ +void purge(void); +} // namespace world::item_registry + +namespace world::item_registry +{ +std::uint64_t calcualte_checksum(void); +} // namespace world::item_registry + +#endif // SHARED_ITEM_REGISTRY_HH -- cgit