(C++)  1.0.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Prefab.hh
1 #ifndef GRAIL_PREFAB_H
2 #define GRAIL_PREFAB_H
3 
4 #include <vector>
5 #include <memory>
6 #include <cassert>
7 #include <functional>
8 #include <string>
9 
10 #include "../GrailSystem/Blackboard.hh"
11 
12 namespace grail
13 {
14  using EntityBlackboardPair = std::pair<const class AIEntity*, Blackboard>;
15 
16  template <typename InstanceType, typename ContexType = EntityBlackboardPair, typename DataType = class AIEntity>
20  class Prefab final
21  {
22  public:
29  Prefab(std::string name,
30  std::function<std::vector<ContexType>(const DataType&)> contextProducer,
31  std::function<std::unique_ptr<InstanceType>(const ContexType&)> instanceProducer)
32  : name{name}, contextProducer{contextProducer}, instanceProducer{instanceProducer}
33  {
34  }
35 
36  Prefab(const Prefab& other) = default;
37  Prefab(Prefab&& other) = default;
38 
39  ~Prefab() = default;
40 
41  Prefab& operator = (const Prefab& other) = delete;
42  Prefab& operator = (Prefab&& other) = delete;
43 
44  std::vector<ContexType> ProduceContexts(const DataType& data) const
45  {
46  return contextProducer(data);
47  }
48 
49  std::unique_ptr<InstanceType> ProduceInstance(const ContexType& context) const
50  {
51  return instanceProducer(context);
52  }
53 
54  std::string GetName() const { return name; }
55 
56  private:
57  const std::string name = "";
58 
59  const std::function<std::vector<ContexType>(const DataType&)> contextProducer{};
60  const std::function<std::unique_ptr<InstanceType>(const ContexType&)> instanceProducer{};
61  };
62 }
63 #endif //GRAIL_PREFAB_H
The Prefab class - responsible for producing contexts and instances of data used by UtilityReasoner.
Definition: Prefab.hh:21
Prefab(std::string name, std::function< std::vector< ContexType >(const DataType &)> contextProducer, std::function< std::unique_ptr< InstanceType >(const ContexType &)> instanceProducer)
Prefab - Contructor.
Definition: Prefab.hh:29