blob: 207e9da1eb3fd51ed1b8f816aae81e78ff66626f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2025 Kirill Dmitrievich
// File: item.cc
// Description: Item metadata
#include "shared/pch.hh"
#include "shared/world/item.hh"
#include "core/math/crc64.hh"
#include "shared/world/voxel.hh"
Item::Item(const Item& source, item_id id) noexcept : Item(source)
{
m_id = id;
}
void Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
{
m_cached_texture = std::move(texture);
}
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);
std::uint32_t id = m_place_voxel ? m_place_voxel->get_id() : NULL_VOXEL_ID;
combine = math::crc64(&id, sizeof(id), combine);
return combine;
}
ItemBuilder::ItemBuilder(std::string_view name)
{
set_name(name);
}
void ItemBuilder::set_name(std::string_view name)
{
assert(name.size());
m_name = name;
}
void ItemBuilder::set_texture(std::string_view texture)
{
m_texture = texture;
}
void ItemBuilder::set_place_voxel(const Voxel* place_voxel)
{
m_place_voxel = place_voxel;
}
std::unique_ptr<Item> ItemBuilder::build(item_id id) const
{
return std::make_unique<Item>(*this, id);
}
|