summaryrefslogtreecommitdiffstats
path: root/game/client
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-12 14:09:34 +0500
committeruntodesu <kirill@untode.su>2025-09-12 14:09:34 +0500
commit73cbcdd6e8c849e32abbf9757e603e6a6654e870 (patch)
tree136e1aef82a25c31552b8990952a7607cfd4708e /game/client
parente9076f22fe2a49d1cd8933e54b7b00c5dd943269 (diff)
downloadvoxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.tar.bz2
voxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.zip
Metaitems
Diffstat (limited to 'game/client')
-rw-r--r--game/client/experiments.cc9
-rw-r--r--game/client/game.cc4
-rw-r--r--game/client/gui/hotbar.cc19
-rw-r--r--game/client/gui/hotbar.hh9
-rw-r--r--game/client/gui/status_lines.cc4
-rw-r--r--game/client/gui/status_lines.hh2
-rw-r--r--game/client/session.cc4
7 files changed, 28 insertions, 23 deletions
diff --git a/game/client/experiments.cc b/game/client/experiments.cc
index b947012..8b0b526 100644
--- a/game/client/experiments.cc
+++ b/game/client/experiments.cc
@@ -73,9 +73,12 @@ void experiments::attack(void)
void experiments::interact(void)
{
- if(auto info = world::item_registry::find(gui::hotbar::slots[gui::hotbar::active_slot])) {
- if(info->place_voxel) {
- globals::dimension->set_voxel(info->place_voxel, world::player_target::coord + world::player_target::normal);
+ auto active_item = gui::hotbar::slots[gui::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);
+ return;
}
}
}
diff --git a/game/client/game.cc b/game/client/game.cc
index 257bd2d..d61ce84 100644
--- a/game/client/game.cc
+++ b/game/client/game.cc
@@ -412,8 +412,8 @@ void client_game::init_late(void)
world::voxel_atlas::generate_mipmaps();
- for(std::shared_ptr<world::ItemInfo>& info : world::item_registry::items) {
- info->cached_texture = resource::load<TextureGUI>(info->texture.c_str(), TEXTURE_GUI_LOAD_CLAMP_S | TEXTURE_GUI_LOAD_CLAMP_T);
+ for(auto& item : world::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();
diff --git a/game/client/gui/hotbar.cc b/game/client/gui/hotbar.cc
index 806d82b..e9458dd 100644
--- a/game/client/gui/hotbar.cc
+++ b/game/client/gui/hotbar.cc
@@ -25,7 +25,7 @@ constexpr static float SELECTOR_PADDING = 1.0f;
constexpr static float HOTBAR_PADDING = 2.0f;
unsigned int gui::hotbar::active_slot = 0U;
-item_id gui::hotbar::slots[HOTBAR_SIZE];
+std::array<const world::Item*, HOTBAR_SIZE> gui::hotbar::slots = {};
static config::KeyBind hotbar_keys[HOTBAR_SIZE];
@@ -40,14 +40,13 @@ static ImU32 get_color_alpha(ImGuiCol style_color, float alpha)
static void update_hotbar_item(void)
{
- if(gui::hotbar::slots[gui::hotbar::active_slot] == NULL_ITEM_ID) {
+ auto current_item = gui::hotbar::slots[gui::hotbar::active_slot];
+
+ if(current_item == nullptr) {
gui::status_lines::unset(gui::STATUS_HOTBAR);
- return;
}
-
- if(auto info = world::item_registry::find(gui::hotbar::slots[gui::hotbar::active_slot])) {
- gui::status_lines::set(gui::STATUS_HOTBAR, info->name, ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
- return;
+ else {
+ gui::status_lines::set(gui::STATUS_HOTBAR, current_item->get_name(), ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
}
}
@@ -154,9 +153,9 @@ void gui::hotbar::layout(void)
// Draw individual item textures in the hotbar
for(std::size_t i = 0; i < HOTBAR_SIZE; ++i) {
- const auto info = world::item_registry::find(gui::hotbar::slots[i]);
+ auto item = gui::hotbar::slots[i];
- if((info == nullptr) || (info->cached_texture == nullptr)) {
+ if((item == nullptr) || (item->get_cached_texture() == nullptr)) {
// There's either no item in the slot
// or the item doesn't have a texture
continue;
@@ -164,7 +163,7 @@ void gui::hotbar::layout(void)
const auto item_start = ImVec2(background_start.x + i * item_size + item_padding_a, background_start.y + item_padding_a);
const auto item_end = ImVec2(item_start.x + item_size - item_padding_b, item_start.y + item_size - item_padding_b);
- draw_list->AddImage(info->cached_texture->handle, item_start, item_end);
+ draw_list->AddImage(item->get_cached_texture()->handle, item_start, item_end);
}
}
diff --git a/game/client/gui/hotbar.hh b/game/client/gui/hotbar.hh
index 88ce791..223dbc9 100644
--- a/game/client/gui/hotbar.hh
+++ b/game/client/gui/hotbar.hh
@@ -1,16 +1,19 @@
#pragma once
-#include "shared/types.hh"
-
// 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
{
extern unsigned int active_slot;
-extern item_id slots[HOTBAR_SIZE];
+extern std::array<const world::Item*, HOTBAR_SIZE> slots;
} // namespace gui::hotbar
namespace gui::hotbar
diff --git a/game/client/gui/status_lines.cc b/game/client/gui/status_lines.cc
index d1a919a..c146478 100644
--- a/game/client/gui/status_lines.cc
+++ b/game/client/gui/status_lines.cc
@@ -65,11 +65,11 @@ void gui::status_lines::layout(void)
}
}
-void gui::status_lines::set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout)
+void gui::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);
- line_strings[line] = std::string(text);
+ line_strings[line] = text;
line_spawns[line] = globals::curtime;
line_fadeouts[line] = fadeout;
}
diff --git a/game/client/gui/status_lines.hh b/game/client/gui/status_lines.hh
index 7245d68..f694fd3 100644
--- a/game/client/gui/status_lines.hh
+++ b/game/client/gui/status_lines.hh
@@ -16,6 +16,6 @@ void layout(void);
namespace gui::status_lines
{
-void set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout);
+void set(unsigned int line, std::string_view text, const ImVec4& color, float fadeout);
void unset(unsigned int line);
} // namespace gui::status_lines
diff --git a/game/client/session.cc b/game/client/session.cc
index c33b4d9..907b789 100644
--- a/game/client/session.cc
+++ b/game/client/session.cc
@@ -127,7 +127,7 @@ static void on_voxel_set(const world::VoxelSetEvent& event)
// FIXME: should we also validate things here or wait for the server to do so
protocol::SetVoxel packet;
packet.vpos = coord::to_voxel(event.cpos, event.lpos);
- packet.voxel = event.voxel->get_id();
+ packet.voxel = event.voxel ? event.voxel->get_id() : NULL_VOXEL_ID;
protocol::send(session::peer, protocol::encode(packet));
}
@@ -286,7 +286,7 @@ void session::send_login_request(void)
protocol::LoginRequest packet;
packet.version = protocol::VERSION;
packet.voxel_registry_checksum = world::voxel_registry::get_checksum();
- packet.item_registry_checksum = world::item_registry::calculate_checksum();
+ packet.item_registry_checksum = world::item_registry::get_checksum();
packet.password_hash = server_password_hash;
packet.username = client_game::username.get();