]> git.localhorst.tv Git - blobs.git/blob - src/creature/Genome.hpp
b14efc1a756396dd405906786eaffe7f1bc96fea
[blobs.git] / src / creature / Genome.hpp
1 #ifndef BLOBS_CREATURE_GENOME_HPP_
2 #define BLOBS_CREATURE_GENOME_HPP_
3
4 #include "../math/Distribution.hpp"
5 #include "../math/GaloisLFSR.hpp"
6 #include "../math/glm.hpp"
7
8 #include <vector>
9
10
11 namespace blobs {
12 namespace app {
13         struct Assets;
14 }
15 namespace creature {
16
17 class Creature;
18
19 struct Genome {
20
21         template<class T>
22         struct PropertySet {
23                 T age;
24                 T mass;
25                 T fertility;
26                 T highlight;
27         };
28         template<class T>
29         struct Properties {
30                 PropertySet<T> props[6];
31                 PropertySet<T> &Birth() noexcept { return props[0]; }
32                 const PropertySet<T> &Birth() const noexcept { return props[0]; }
33                 PropertySet<T> &Child() noexcept { return props[1]; }
34                 const PropertySet<T> &Child() const noexcept { return props[1]; }
35                 PropertySet<T> &Youth() noexcept { return props[2]; }
36                 const PropertySet<T> &Youth() const noexcept { return props[2]; }
37                 PropertySet<T> &Adult() noexcept { return props[3]; }
38                 const PropertySet<T> &Adult() const noexcept { return props[3]; }
39                 PropertySet<T> &Elder() noexcept { return props[4]; }
40                 const PropertySet<T> &Elder() const noexcept { return props[4]; }
41                 PropertySet<T> &Death() noexcept { return props[5]; }
42                 const PropertySet<T> &Death() const noexcept { return props[5]; }
43         };
44         Properties<math::Distribution> properties;
45
46
47         struct Composition {
48                 // which resource
49                 int resource;
50                 // how much contained in the body
51                 // relative value to determine average density
52                 math::Distribution mass;
53                 // how much to circulate
54                 math::Distribution intake;
55                 // how important for alive-being
56                 math::Distribution penalty;
57                 // how much off the mass may stay in the body
58                 math::Distribution growth;
59         };
60         std::vector<Composition> composition;
61
62         math::Distribution base_hue;
63         math::Distribution base_saturation;
64         math::Distribution base_lightness;
65
66         void Configure(Creature &) const;
67
68         static PropertySet<double> Instantiate(
69                 const PropertySet<math::Distribution> &p,
70                 math::GaloisLFSR &rand
71         ) noexcept {
72                 return {
73                         p.age.FakeNormal(rand.SNorm()),
74                         p.mass.FakeNormal(rand.SNorm()),
75                         p.fertility.FakeNormal(rand.SNorm()),
76                         glm::clamp(p.highlight.FakeNormal(rand.SNorm()), 0.0, 1.0)
77                 };
78         }
79
80         static Properties<double> Instantiate(
81                 const Properties<math::Distribution> &p,
82                 math::GaloisLFSR &rand
83         ) noexcept {
84                 return {
85                         Instantiate(p.props[0], rand),
86                         Instantiate(p.props[1], rand),
87                         Instantiate(p.props[2], rand),
88                         Instantiate(p.props[3], rand),
89                         Instantiate(p.props[4], rand),
90                         Instantiate(p.props[5], rand)
91                 };
92         }
93
94 };
95
96 }
97 }
98
99 #endif