Unravel Engine C++ Reference
Loading...
Searching...
No Matches
batch_key.cpp
Go to the documentation of this file.
1#include "batch_key.h"
2#include "mesh.h"
3#include "material.h"
4#include <base/hash.hpp>
5#include <sstream>
6
7namespace unravel
8{
9
10batch_key::batch_key(std::shared_ptr<mesh> mesh_ptr,
11 std::shared_ptr<material> material_ptr,
12 uint32_t lod_index,
13 uint32_t submesh_index)
14 : mesh_ptr(std::move(mesh_ptr))
15 , material_ptr(std::move(material_ptr))
16 , lod_index(lod_index)
17 , submesh_index(submesh_index)
18{
19}
20
22 const asset_handle<material>& material_handle,
23 uint32_t lod_index,
24 uint32_t submesh_index)
25 : mesh_ptr(mesh_handle.get())
26 , material_ptr(material_handle.get())
27 , lod_index(lod_index)
28 , submesh_index(submesh_index)
29{
30}
31
32auto batch_key::hash() const noexcept -> size_t
33{
34 // Use hash_combine utility to combine all key components
35 size_t seed = 0;
36 utils::hash_combine(seed, mesh_ptr.get());
40
41 return seed;
42}
43
44auto batch_key::is_valid() const -> bool
45{
46 return mesh_ptr && material_ptr;
47}
48
49auto batch_key::to_string() const -> std::string
50{
51 std::ostringstream oss;
52 oss << "batch_key{";
53 oss << "mesh=" << static_cast<const void*>(mesh_ptr.get());
54 oss << ", material=" << static_cast<const void*>(material_ptr.get());
55 oss << ", lod=" << lod_index;
56 oss << ", submesh=" << submesh_index;
57 oss << "}";
58 return oss.str();
59}
60
61} // namespace unravel
Hash specialization for batch_key to enable use in std::unordered_map.
void hash_combine(std::size_t &seed, const T &v)
Definition hash.hpp:8
Represents a handle to an asset, providing access and management functions.
batch_key()=default
Default constructor.
auto hash() const noexcept -> size_t
Generate hash value for this batch key.
Definition batch_key.cpp:32
auto to_string() const -> std::string
Convert batch key to string for debugging.
Definition batch_key.cpp:49
auto is_valid() const -> bool
Check if this batch key is valid.
Definition batch_key.cpp:44
std::shared_ptr< material > material_ptr
Shared pointer to the material.
Definition batch_key.h:27
uint32_t lod_index
Level of detail index.
Definition batch_key.h:30
std::shared_ptr< mesh > mesh_ptr
Shared pointer to the mesh geometry.
Definition batch_key.h:24
uint32_t submesh_index
Submesh index within the mesh.
Definition batch_key.h:33