summaryrefslogtreecommitdiffstats
path: root/game/shared/world/item.cc
blob: 5e606091c6bddc47d698d3c15a1f56cf6d175bda (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
#include "shared/pch.hh"

#include "shared/world/item.hh"

#include "core/math/crc64.hh"

#include "shared/world/voxel.hh"

world::Item::Item(const Item& source, item_id id) noexcept : Item(source)
{
    m_id = id;
}

void world::Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
{
    m_cached_texture = std::move(texture);
}

std::uint64_t world::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;
}

world::ItemBuilder::ItemBuilder(std::string_view name)
{
    set_name(name);
}

void world::ItemBuilder::set_name(std::string_view name)
{
    assert(name.size());

    m_name = name;
}

void world::ItemBuilder::set_texture(std::string_view texture)
{
    m_texture = texture;
}

void world::ItemBuilder::set_place_voxel(const Voxel* place_voxel)
{
    m_place_voxel = place_voxel;
}

std::unique_ptr<world::Item> world::ItemBuilder::build(item_id id) const
{
    return std::make_unique<Item>(*this, id);
}