1use std::collections::HashSet;
2use crate::{prelude::*, map::{Map, MapClass}};
3
4pub struct Chain<F: Map, S: Map> {
6 pub first: F,
7 pub second: S,
8}
9
10impl<F: Map, S: Map> Chain<F, S> {
11 pub fn new(first: F, second: S) -> Self {
12 Self { first, second }
13 }
14}
15
16impl<F: Map, S: Map> Map for Chain<F, S> {}
17
18impl<F: Map, S: Map> Instance<MapClass> for Chain<F, S> {
19 fn source(cache: &mut HashSet<u64>) -> String {
20 if !cache.insert(Self::type_hash()) {
21 return String::new()
22 }
23 [
24 F::source(cache),
25 S::source(cache),
26 "#include <clay_core/map/chain.h>".to_string(),
27 format!(
28 "MAP_CHAIN({}, {}, {}, {}, {})",
29 Self::inst_name(),
30 F::inst_name(),
31 S::inst_name(),
32 F::size_int(),
33 F::size_float(),
34 ),
35 ].join("\n")
36 }
37 fn inst_name() -> String {
38 format!(
39 "__{}_{}_{:x}",
40 F::inst_name(),
41 S::inst_name(),
42 Self::type_hash(),
43 )
44 }
45}
46
47impl<F: Map, S: Map> Pack for Chain<F, S> {
48 fn size_int() -> usize {
49 F::size_int() + S::size_int()
50 }
51 fn size_float() -> usize {
52 F::size_float() + S::size_float()
53 }
54 fn pack_to(&self, buffer_int: &mut [i32], buffer_float: &mut [f32]) {
55 Packer::new(buffer_int, buffer_float)
56 .pack(&self.first)
57 .pack(&self.second);
58 }
59}