Skip to main content

wowlab_engine_domain/rotation/buffer/dense/
offsets.rs

1use wowlab_types::{
2    combat::ResourceType,
3    sim::{AuraKey, AuraOn, AuraProjectionKey, FastMap, IntMap, SpellIdx},
4};
5
6use crate::rotation::buffer::{ByteOffset, DescriptorId};
7
8#[derive(Clone, Debug)]
9pub struct SlotMaps<V> {
10    pub cooldowns: IntMap<SpellIdx, V>,
11    pub auras: FastMap<AuraKey, V>,
12    pub aura_projections: FastMap<AuraProjectionKey, V>,
13    pub resources: FastMap<ResourceType, V>,
14    pub spells: IntMap<SpellIdx, V>,
15    pub talents: FastMap<String, V>,
16    pub hero_trees: FastMap<String, V>,
17    pub items: FastMap<String, V>,
18    pub swings: FastMap<String, V>,
19    pub history: IntMap<SpellIdx, V>,
20    pub equipment: FastMap<String, V>,
21    pub set_bonuses: FastMap<String, V>,
22    pub units: FastMap<String, V>,
23    pub weapon_imbues: FastMap<String, V>,
24}
25
26impl<V> Default for SlotMaps<V> {
27    fn default() -> Self {
28        Self {
29            cooldowns: IntMap::default(),
30            auras: FastMap::default(),
31            aura_projections: FastMap::default(),
32            resources: FastMap::default(),
33            spells: IntMap::default(),
34            talents: FastMap::default(),
35            hero_trees: FastMap::default(),
36            items: FastMap::default(),
37            swings: FastMap::default(),
38            history: IntMap::default(),
39            equipment: FastMap::default(),
40            set_bonuses: FastMap::default(),
41            units: FastMap::default(),
42            weapon_imbues: FastMap::default(),
43        }
44    }
45}
46
47impl SlotMaps<usize> {
48    pub(crate) fn into_byte_offsets(self) -> SlotMaps<ByteOffset> {
49        fn convert<K, S>(
50            map: std::collections::HashMap<K, usize, S>,
51        ) -> std::collections::HashMap<K, ByteOffset, S>
52        where
53            K: Eq + std::hash::Hash,
54            S: std::hash::BuildHasher + Default,
55        {
56            map.into_iter()
57                .map(|(key, offset)| (key, ByteOffset::new(offset)))
58                .collect()
59        }
60
61        SlotMaps {
62            cooldowns: convert(self.cooldowns),
63            auras: convert(self.auras),
64            aura_projections: convert(self.aura_projections),
65            resources: convert(self.resources),
66            spells: convert(self.spells),
67            talents: convert(self.talents),
68            hero_trees: convert(self.hero_trees),
69            items: convert(self.items),
70            swings: convert(self.swings),
71            history: convert(self.history),
72            equipment: convert(self.equipment),
73            set_bonuses: convert(self.set_bonuses),
74            units: convert(self.units),
75            weapon_imbues: convert(self.weapon_imbues),
76        }
77    }
78}
79
80/// Maps slot types and keys to their byte offsets within the dense buffer.
81#[derive(Clone, Debug)]
82pub struct BufferOffsets {
83    pub slots: SlotMaps<ByteOffset>,
84    pub player: ByteOffset,
85    pub combat: ByteOffset,
86    pub pet: ByteOffset,
87    pub standalone: FastMap<DescriptorId, ByteOffset>,
88}
89
90impl BufferOffsets {
91    #[inline]
92    #[must_use]
93    pub fn aura_offset(&self, aura: wowlab_types::sim::AuraIdx, on: AuraOn) -> Option<ByteOffset> {
94        self.slots
95            .aura_projections
96            .get(&AuraProjectionKey::new(aura, on))
97            .copied()
98    }
99}