20 #ifndef ANTKEEPER_GAME_ANT_GENE_LOADER_HPP
21 #define ANTKEEPER_GAME_ANT_GENE_LOADER_HPP
42 std::uint32_t format_identifier{0};
43 ctx.
read32<std::endian::little>(
reinterpret_cast<std::byte*
>(&format_identifier), 1);
46 if (format_identifier != 0xaca79ff0)
52 std::uint16_t format_version{0};
53 ctx.
read16<std::endian::little>(
reinterpret_cast<std::byte*
>(&format_version), 1);
56 if (format_version != 1)
63 ctx.
read8(
reinterpret_cast<std::byte*
>(&gene_type), 1);
66 if (gene_type != gene.
type())
72 ctx.
read32<std::endian::little>(
reinterpret_cast<std::byte*
>(&gene.
name), 1);
75 std::uint8_t phene_count{0};
76 ctx.
read8(
reinterpret_cast<std::byte*
>(&phene_count), 1);
79 gene.
phenes.resize(phene_count);
82 for (
auto& phene: gene.
phenes)
85 std::uint8_t caste_flags{0};
86 ctx.
read8(
reinterpret_cast<std::byte*
>(&caste_flags), 1);
92 int caste_count = std::popcount(caste_flags);
99 for (std::uint8_t i = 0; i < 8; ++i)
101 const std::uint8_t caste_mask = 1 << i;
102 if (caste_flags & caste_mask)
105 if (--caste_count; !caste_count)
ant_caste_type
Ant caste types.
void load_ant_gene(ant_gene< T > &gene, resource_manager &resource_manager, deserialize_context &ctx, void(*load_phene)(T &, ::resource_manager &, deserialize_context &))
Loads an ant gene.
ant_gene_type
Ant gene types.
An exception of this type is thrown when an error occurs during deserialization.
Manages the loading, caching, and saving of resources.
hash::fnv1a32_t name
32-bit FNV-1a hash of gene name.
Ant gene with caste-specific phenes.
std::vector< T > phenes
Phene definitions.
constexpr ant_gene_type type() const noexcept override
Returns the ant gene type.
std::unordered_map< ant_caste_type, T * > phene_map
Map of ant caste types to phenes.
Provides access to a deserialization state.
std::size_t read16(std::byte *data, std::size_t count) noexcept(false)
Reads 16-bit (word) data.
std::size_t read32(std::byte *data, std::size_t count) noexcept(false)
Reads 32-bit (double word) data.
virtual std::size_t read8(std::byte *data, std::size_t count) noexcept(false)=0
Reads 8-bit (byte) data.