diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f3572c..a8b55b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.7) + option(VERSION_STRING "Project version string" "0.0.0") project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX) diff --git a/src/game/ant/caste.hpp b/src/game/ant/caste.hpp index 737baf8..2c91040 100644 --- a/src/game/ant/caste.hpp +++ b/src/game/ant/caste.hpp @@ -20,75 +20,27 @@ #ifndef ANTKEEPER_GAME_ANT_CASTE_HPP #define ANTKEEPER_GAME_ANT_CASTE_HPP -#include "game/ant/caste-type.hpp" -#include "game/ant/trait/antennae.hpp" -#include "game/ant/trait/eyes.hpp" -#include "game/ant/trait/gaster.hpp" -#include "game/ant/trait/head.hpp" -#include "game/ant/trait/legs.hpp" -#include "game/ant/trait/mandibles.hpp" -#include "game/ant/trait/mesosoma.hpp" -#include "game/ant/trait/ocelli.hpp" -#include "game/ant/trait/pigmentation.hpp" -#include "game/ant/trait/sculpturing.hpp" -#include "game/ant/trait/size-variation.hpp" -#include "game/ant/trait/sting.hpp" -#include "game/ant/trait/waist.hpp" -#include "game/ant/trait/wings.hpp" -#include - namespace game { namespace ant { /** - * Ant caste description. + * Ant caste enumerations. + * + * @see https://www.antwiki.org/wiki/Caste_Terminology */ -struct caste +enum class caste { - /// Caste type. - caste_type type; - - /// Antennae description. - const trait::antennae* antennae; - - /// Eyes description. - const trait::eyes* eyes; - - /// Gaster description. - const trait::gaster* gaster; - - /// Head description. - const trait::head* head; - - /// Legs description. - const trait::legs* legs; - - /// Mandibles description. - const trait::mandibles* mandibles; - - /// Mesosoma description. - const trait::mesosoma* mesosoma; - - /// Ocelli description. - const trait::ocelli* ocelli; - - /// Pigmentation description. - const trait::pigmentation* pigmentation; - - /// Sculpturing description. - const trait::sculpturing* sculpturing; - - /// Size variation description. - const trait::size_variation* size_variation; + /// Queen caste type. + queen, - /// Sting description. - const trait::sting* sting; + /// Worker caste type. + worker, - /// Waist description. - const trait::waist* waist; + /// Soldier caste type. + soldier, - /// Wings description. - const trait::wings* wings; + /// Male caste type. + male }; } // namespace ant diff --git a/src/game/ant/cladogenesis.cpp b/src/game/ant/cladogenesis.cpp new file mode 100644 index 0000000..a4e661a --- /dev/null +++ b/src/game/ant/cladogenesis.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/cladogenesis.hpp" + +namespace game { +namespace ant { + +genome* cladogenesis(gene_pool& pool, std::random_device& rng) +{ + // Allocate genome + ant::genome* genome = new ant::genome(); + + // Randomly sample genes + genome->antennae = pool.antennae.sample(rng); + genome->body_size = pool.body_size.sample(rng); + genome->cocoon = pool.cocoon.sample(rng); + genome->diet = pool.diet.sample(rng); + genome->egg = pool.egg.sample(rng); + genome->eyes = pool.eyes.sample(rng); + genome->foraging_time = pool.foraging_time.sample(rng); + genome->founding_mode = pool.founding_mode.sample(rng); + genome->gaster = pool.gaster.sample(rng); + genome->head = pool.head.sample(rng); + genome->larva = pool.larva.sample(rng); + genome->legs = pool.legs.sample(rng); + genome->mandibles = pool.mandibles.sample(rng); + genome->mesosoma = pool.mesosoma.sample(rng); + genome->nest_site = pool.nest_site.sample(rng); + genome->ocelli = pool.ocelli.sample(rng); + genome->pigmentation = pool.pigmentation.sample(rng); + genome->pilosity = pool.pilosity.sample(rng); + genome->sculpturing = pool.sculpturing.sample(rng); + genome->sting = pool.sting.sample(rng); + genome->waist = pool.waist.sample(rng); + genome->wings = pool.wings.sample(rng); + + return genome; +} + +} // namespace ant +} // namespace game diff --git a/src/game/ant/cladogenesis.hpp b/src/game/ant/cladogenesis.hpp new file mode 100644 index 0000000..e7f5beb --- /dev/null +++ b/src/game/ant/cladogenesis.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_CLADOGENESIS_HPP +#define ANTKEEPER_GAME_ANT_CLADOGENESIS_HPP + +#include "game/ant/genome.hpp" +#include "game/ant/gene-pool.hpp" +#include + +namespace game { +namespace ant { + +/** + * Generates a genome from a gene pool. + * + * @param pool Gene pool. + * @param rng Random number generator. + * + * @return New genome. + */ +genome* cladogenesis(gene_pool& pool, std::random_device& rng); + +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_CLADOGENESIS_HPP diff --git a/src/game/ant/gene-frequency-table.hpp b/src/game/ant/gene-frequency-table.hpp new file mode 100644 index 0000000..7f7527b --- /dev/null +++ b/src/game/ant/gene-frequency-table.hpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_HPP +#define ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_HPP + +#include +#include + +namespace game { +namespace ant { + +/** + * Gene frequency table. + * + * @tparam T Gene type. + */ +template +struct gene_frequency_table +{ + /// Gene array. + std::vector genes; + + /// Gene discrete probability distribution. + std::discrete_distribution distribution; + + /** + * Samples a gene from the frequency table. + * + * @tparam Generator Uniform random bit generator type. + * + * @param g Uniform random bit generator object. + * + * @return Randomly sampled gene. + */ + template + const T* sample(Generator& g) + { + return genes[distribution(g)]; + } +}; + +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_HPP diff --git a/src/game/ant/gene-pool.hpp b/src/game/ant/gene-pool.hpp new file mode 100644 index 0000000..a2aa9da --- /dev/null +++ b/src/game/ant/gene-pool.hpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_POOL_HPP +#define ANTKEEPER_GAME_ANT_GENE_POOL_HPP + +#include "game/ant/gene-frequency-table.hpp" +#include "game/ant/gene/antennae.hpp" +#include "game/ant/gene/body-size.hpp" +#include "game/ant/gene/cocoon.hpp" +#include "game/ant/gene/diet.hpp" +#include "game/ant/gene/egg.hpp" +#include "game/ant/gene/eyes.hpp" +#include "game/ant/gene/foraging-time.hpp" +#include "game/ant/gene/founding-mode.hpp" +#include "game/ant/gene/gaster.hpp" +#include "game/ant/gene/head.hpp" +#include "game/ant/gene/larva.hpp" +#include "game/ant/gene/legs.hpp" +#include "game/ant/gene/mandibles.hpp" +#include "game/ant/gene/mesosoma.hpp" +#include "game/ant/gene/nest-site.hpp" +#include "game/ant/gene/ocelli.hpp" +#include "game/ant/gene/pigmentation.hpp" +#include "game/ant/gene/pilosity.hpp" +#include "game/ant/gene/sculpturing.hpp" +#include "game/ant/gene/sting.hpp" +#include "game/ant/gene/waist.hpp" +#include "game/ant/gene/wings.hpp" + +namespace game { +namespace ant { + +/** + * Pool of genes from which ant genomes can be generated. + */ +struct gene_pool +{ + /// Gene pool name. + std::string name; + + gene_frequency_table antennae; + gene_frequency_table body_size; + gene_frequency_table cocoon; + gene_frequency_table diet; + gene_frequency_table egg; + gene_frequency_table eyes; + gene_frequency_table foraging_time; + gene_frequency_table founding_mode; + gene_frequency_table gaster; + gene_frequency_table head; + gene_frequency_table larva; + gene_frequency_table legs; + gene_frequency_table mandibles; + gene_frequency_table mesosoma; + gene_frequency_table nest_site; + gene_frequency_table ocelli; + gene_frequency_table pigmentation; + gene_frequency_table pilosity; + gene_frequency_table sculpturing; + gene_frequency_table sting; + gene_frequency_table waist; + gene_frequency_table wings; +}; + +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_POOL_HPP diff --git a/src/game/ant/gene/antennae.hpp b/src/game/ant/gene/antennae.hpp new file mode 100644 index 0000000..a4ad033 --- /dev/null +++ b/src/game/ant/gene/antennae.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_ANTENNAE_HPP +#define ANTKEEPER_GAME_ANT_GENE_ANTENNAE_HPP + +#include "game/ant/phene/antennae.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic antennae gene. +typedef polyphenic_gene antennae; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_ANTENNAE_HPP diff --git a/src/game/ant/gene/body-size.hpp b/src/game/ant/gene/body-size.hpp new file mode 100644 index 0000000..12ea22c --- /dev/null +++ b/src/game/ant/gene/body-size.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_BODY_SIZE_HPP +#define ANTKEEPER_GAME_ANT_GENE_BODY_SIZE_HPP + +#include "game/ant/phene/body-size.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic body size gene. +typedef polyphenic_gene body_size; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_BODY_SIZE_HPP diff --git a/src/game/ant/trait/body-size.hpp b/src/game/ant/gene/cocoon.hpp similarity index 71% rename from src/game/ant/trait/body-size.hpp rename to src/game/ant/gene/cocoon.hpp index 7ba7d74..469b4bc 100644 --- a/src/game/ant/trait/body-size.hpp +++ b/src/game/ant/gene/cocoon.hpp @@ -17,24 +17,21 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_BODY_SIZE_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_BODY_SIZE_HPP +#ifndef ANTKEEPER_GAME_ANT_GENE_COCOON_HPP +#define ANTKEEPER_GAME_ANT_GENE_COCOON_HPP + +#include "game/ant/phene/cocoon.hpp" +#include "game/ant/gene/monophenic-gene.hpp" namespace game { namespace ant { -namespace trait { +namespace gene { -/** - * Ant body size description. - */ -struct body_size -{ - /// Mesosoma length (Weber's length) of a media worker, in centimeters. - float mesosoma_length; -}; +/// Monophenic cocoon gene. +typedef monophenic_gene cocoon; -} // namespace trait +} // namespace gene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_BODY_SIZE_HPP +#endif // ANTKEEPER_GAME_ANT_GENE_COCOON_HPP diff --git a/src/game/ant/gene/diet.hpp b/src/game/ant/gene/diet.hpp new file mode 100644 index 0000000..03856a5 --- /dev/null +++ b/src/game/ant/gene/diet.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_DIET_HPP +#define ANTKEEPER_GAME_ANT_GENE_DIET_HPP + +#include "game/ant/phene/diet.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic diet gene. +typedef monophenic_gene diet; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_DIET_HPP diff --git a/src/game/ant/gene/egg.hpp b/src/game/ant/gene/egg.hpp new file mode 100644 index 0000000..f3ffbd4 --- /dev/null +++ b/src/game/ant/gene/egg.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_EGG_HPP +#define ANTKEEPER_GAME_ANT_GENE_EGG_HPP + +#include "game/ant/phene/egg.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic egg gene. +typedef monophenic_gene egg; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_EGG_HPP diff --git a/src/game/ant/gene/eyes.hpp b/src/game/ant/gene/eyes.hpp new file mode 100644 index 0000000..394b8c9 --- /dev/null +++ b/src/game/ant/gene/eyes.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_EYES_HPP +#define ANTKEEPER_GAME_ANT_GENE_EYES_HPP + +#include "game/ant/phene/eyes.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic eyes gene. +typedef polyphenic_gene eyes; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_EYES_HPP diff --git a/src/game/ant/gene/foraging-time.hpp b/src/game/ant/gene/foraging-time.hpp new file mode 100644 index 0000000..a5be3ff --- /dev/null +++ b/src/game/ant/gene/foraging-time.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_FORAGING_TIME_HPP +#define ANTKEEPER_GAME_ANT_GENE_FORAGING_TIME_HPP + +#include "game/ant/phene/foraging-time.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic foraging time gene. +typedef monophenic_gene foraging_time; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_FORAGING_TIME_HPP diff --git a/src/game/ant/gene/founding-mode.hpp b/src/game/ant/gene/founding-mode.hpp new file mode 100644 index 0000000..1e11c90 --- /dev/null +++ b/src/game/ant/gene/founding-mode.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_FOUNDING_MODE_HPP +#define ANTKEEPER_GAME_ANT_GENE_FOUNDING_MODE_HPP + +#include "game/ant/phene/founding-mode.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic founding mode gene. +typedef monophenic_gene founding_mode; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_FOUNDING_MODE_HPP diff --git a/src/game/ant/gene/gaster.hpp b/src/game/ant/gene/gaster.hpp new file mode 100644 index 0000000..1b49d93 --- /dev/null +++ b/src/game/ant/gene/gaster.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_GASTER_HPP +#define ANTKEEPER_GAME_ANT_GENE_GASTER_HPP + +#include "game/ant/phene/gaster.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic gaster gene. +typedef polyphenic_gene gaster; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_GASTER_HPP diff --git a/src/game/ant/gene/head.hpp b/src/game/ant/gene/head.hpp new file mode 100644 index 0000000..db041b4 --- /dev/null +++ b/src/game/ant/gene/head.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_HEAD_HPP +#define ANTKEEPER_GAME_ANT_GENE_HEAD_HPP + +#include "game/ant/phene/head.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic head gene. +typedef polyphenic_gene head; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_HEAD_HPP diff --git a/src/game/ant/gene/larva.hpp b/src/game/ant/gene/larva.hpp new file mode 100644 index 0000000..fa3c669 --- /dev/null +++ b/src/game/ant/gene/larva.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_LARVA_HPP +#define ANTKEEPER_GAME_ANT_GENE_LARVA_HPP + +#include "game/ant/phene/larva.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic larva gene. +typedef monophenic_gene larva; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_LARVA_HPP diff --git a/src/game/ant/gene/legs.hpp b/src/game/ant/gene/legs.hpp new file mode 100644 index 0000000..5a1a66a --- /dev/null +++ b/src/game/ant/gene/legs.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_LEGS_HPP +#define ANTKEEPER_GAME_ANT_GENE_LEGS_HPP + +#include "game/ant/phene/legs.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic legs gene. +typedef polyphenic_gene legs; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_LEGS_HPP diff --git a/src/game/ant/trait/loader/antennae-loader.cpp b/src/game/ant/gene/loader/antennae-loader.cpp similarity index 52% rename from src/game/ant/trait/loader/antennae-loader.cpp rename to src/game/ant/gene/loader/antennae-loader.cpp index bcd15d1..520d5d5 100644 --- a/src/game/ant/trait/loader/antennae-loader.cpp +++ b/src/game/ant/gene/loader/antennae-loader.cpp @@ -17,45 +17,51 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/antennae.hpp" +#include "game/ant/gene/antennae.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_antennae_phene(phene::antennae& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.total_antennomere_count = 0; + phene.club_antennomere_count = 0; + + // Load antennae model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse total antennomere count + if (auto element = phene_element.find("total_antennomere_count"); element != phene_element.end()) + phene.total_antennomere_count = element->get(); + + // Parse club antennomere count + if (auto element = phene_element.find("club_antennomere_count"); element != phene_element.end()) + phene.club_antennomere_count = element->get(); +} + template <> -trait::antennae* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::antennae* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto antennae_element = data->find("antennae"); if (antennae_element == data->end()) - throw std::runtime_error("Invalid antennae trait."); + throw std::runtime_error("Invalid antennae gene."); - // Allocate and init antennae trait - trait::antennae* antennae = new trait::antennae(); - antennae->model = nullptr; - antennae->total_antennomere_count = 0; - antennae->club_antennomere_count = 0; - - // Load antennae model - auto model_element = antennae_element->find("model"); - if (model_element == antennae_element->end()) - throw std::runtime_error("Antennae trait doesn't specify antennae model."); - antennae->model = resource_manager->load(model_element->get()); + // Allocate gene + gene::antennae* antennae = new gene::antennae(); - // Parse total antennomere count - if (auto element = antennae_element->find("total_antennomere_count"); element != antennae_element->end()) - antennae->total_antennomere_count = element->get(); - - // Parse club antennomere count - if (auto element = antennae_element->find("club_antennomere_count"); element != antennae_element->end()) - antennae->club_antennomere_count = element->get(); + // Deserialize gene + gene::deserialize_gene(*antennae, &deserialize_antennae_phene, *antennae_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/gene/loader/body-size-loader.cpp b/src/game/ant/gene/loader/body-size-loader.cpp new file mode 100644 index 0000000..1529692 --- /dev/null +++ b/src/game/ant/gene/loader/body-size-loader.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/body-size.hpp" +#include + +using namespace game::ant; + +static void deserialize_body_size_phene(phene::body_size& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.min_mesosoma_length = 1.0f; + phene.max_mesosoma_length = 1.0f; + phene.mean_mesosoma_length = 1.0f; + + // Parse min mesosoma length + if (auto element = phene_element.find("min_mesosoma_length"); element != phene_element.end()) + phene.min_mesosoma_length = element->get(); + + // Parse max mesosoma length + if (auto element = phene_element.find("max_mesosoma_length"); element != phene_element.end()) + phene.max_mesosoma_length = element->get(); + + // Parse mean mesosoma length + if (auto element = phene_element.find("mean_mesosoma_length"); element != phene_element.end()) + phene.mean_mesosoma_length = element->get(); +} + +template <> +gene::body_size* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto body_size_element = data->find("body_size"); + if (body_size_element == data->end()) + throw std::runtime_error("Invalid body size gene."); + + // Allocate gene + gene::body_size* body_size = new gene::body_size(); + + // Deserialize gene + gene::deserialize_gene(*body_size, &deserialize_body_size_phene, *body_size_element, resource_manager); + + // Free JSON data + delete data; + + return body_size; +} diff --git a/src/game/ant/trait/loader/cocoon-loader.cpp b/src/game/ant/gene/loader/cocoon-loader.cpp similarity index 55% rename from src/game/ant/trait/loader/cocoon-loader.cpp rename to src/game/ant/gene/loader/cocoon-loader.cpp index 7a532db..f0e6641 100644 --- a/src/game/ant/trait/loader/cocoon-loader.cpp +++ b/src/game/ant/gene/loader/cocoon-loader.cpp @@ -17,43 +17,49 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/cocoon.hpp" +#include "game/ant/gene/cocoon.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_cocoon_phene(phene::cocoon& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.present = false; + phene.model = nullptr; + + // Parse cocoon present + if (auto element = phene_element.find("present"); element != phene_element.end()) + phene.present = element->get(); + + // Load cocoon model + if (phene.present) + { + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + } +} + template <> -trait::cocoon* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::cocoon* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto cocoon_element = data->find("cocoon"); if (cocoon_element == data->end()) - throw std::runtime_error("Invalid cocoon trait."); - - // Allocate and init cocoon trait - trait::cocoon* cocoon = new trait::cocoon(); - cocoon->present = false; - cocoon->model = nullptr; + throw std::runtime_error("Invalid cocoon gene."); - // Parse cocoon present - if (auto present_element = cocoon_element->find("present"); present_element != cocoon_element->end()) - cocoon->present = present_element->get(); + // Allocate gene + gene::cocoon* cocoon = new gene::cocoon(); - // Load cocoon model (if present) - if (cocoon->present) - { - auto model_element = cocoon_element->find("model"); - if (model_element == cocoon_element->end()) - throw std::runtime_error("Cocoon trait doesn't specify cocoon model."); - cocoon->model = resource_manager->load(model_element->get()); - } + // Deserialize gene + gene::deserialize_gene(*cocoon, &deserialize_cocoon_phene, *cocoon_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/egg-loader.cpp b/src/game/ant/gene/loader/egg-loader.cpp similarity index 61% rename from src/game/ant/trait/loader/egg-loader.cpp rename to src/game/ant/gene/loader/egg-loader.cpp index 005e82f..58fcd71 100644 --- a/src/game/ant/trait/loader/egg-loader.cpp +++ b/src/game/ant/gene/loader/egg-loader.cpp @@ -17,35 +17,41 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/egg.hpp" +#include "game/ant/gene/egg.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_egg_phene(phene::egg& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + + // Load egg model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); +} + template <> -trait::egg* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::egg* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto egg_element = data->find("egg"); if (egg_element == data->end()) - throw std::runtime_error("Invalid egg trait."); + throw std::runtime_error("Invalid egg gene."); - // Allocate and init egg trait - trait::egg* egg = new trait::egg(); - egg->model = nullptr; + // Allocate gene + gene::egg* egg = new gene::egg(); - // Load egg model - auto model_element = egg_element->find("model"); - if (model_element == egg_element->end()) - throw std::runtime_error("Egg trait doesn't specify egg model."); - egg->model = resource_manager->load(model_element->get()); + // Deserialize gene + gene::deserialize_gene(*egg, &deserialize_egg_phene, *egg_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/gene/loader/eyes-loader.cpp b/src/game/ant/gene/loader/eyes-loader.cpp new file mode 100644 index 0000000..9315e07 --- /dev/null +++ b/src/game/ant/gene/loader/eyes-loader.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/eyes.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_eyes_phene(phene::eyes& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.present = false; + phene.model = nullptr; + phene.length = 0.0f; + phene.width = 0.0f; + phene.height = 0.0f; + phene.ommatidia_count = 0; + + // Parse present + if (auto element = phene_element.find("present"); element != phene_element.end()) + phene.present = element->get(); + + if (phene.present) + { + // Load eyes model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse length + if (auto element = phene_element.find("length"); element != phene_element.end()) + phene.length = element->get(); + + // Parse width + if (auto element = phene_element.find("width"); element != phene_element.end()) + phene.width = element->get(); + + // Parse height + if (auto element = phene_element.find("height"); element != phene_element.end()) + phene.height = element->get(); + + // Parse ommatidia count + if (auto element = phene_element.find("ommatidia_count"); element != phene_element.end()) + phene.ommatidia_count = element->get(); + } +} + +template <> +gene::eyes* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto eyes_element = data->find("eyes"); + if (eyes_element == data->end()) + throw std::runtime_error("Invalid eyes gene."); + + // Allocate gene + gene::eyes* eyes = new gene::eyes(); + + // Deserialize gene + gene::deserialize_gene(*eyes, &deserialize_eyes_phene, *eyes_element, resource_manager); + + // Free JSON data + delete data; + + return eyes; +} diff --git a/src/game/ant/trait/loader/foraging-time-loader.cpp b/src/game/ant/gene/loader/foraging-time-loader.cpp similarity index 51% rename from src/game/ant/trait/loader/foraging-time-loader.cpp rename to src/game/ant/gene/loader/foraging-time-loader.cpp index 04b27fe..fdae7bf 100644 --- a/src/game/ant/trait/loader/foraging-time-loader.cpp +++ b/src/game/ant/gene/loader/foraging-time-loader.cpp @@ -17,35 +17,47 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/foraging-time.hpp" +#include "game/ant/gene/foraging-time.hpp" #include "math/angles.hpp" +#include "math/constants.hpp" #include using namespace game::ant; +static void deserialize_foraging_time_phene(phene::foraging_time& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.min_solar_altitude = -math::half_pi; + phene.max_solar_altitude = math::half_pi; + + // Parse min solar altitude + if (auto element = phene_element.find("min_solar_altitude"); element != phene_element.end()) + phene.min_solar_altitude = math::radians(element->get()); + + // Parse max solar altitude + if (auto element = phene_element.find("max_solar_altitude"); element != phene_element.end()) + phene.max_solar_altitude = math::radians(element->get()); +} + template <> -trait::foraging_time* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::foraging_time* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); + // Validate gene file auto foraging_time_element = data->find("foraging_time"); if (foraging_time_element == data->end()) - throw std::runtime_error("Invalid foraging time trait."); - - auto solar_altitude_element = foraging_time_element->find("solar_altitude"); - if (solar_altitude_element == foraging_time_element->end()) - throw std::runtime_error("Foraging time trait doesn't specify solar altitude."); + throw std::runtime_error("Invalid foraging time gene."); - if (!solar_altitude_element->is_array() || solar_altitude_element->size() != 2) - throw std::runtime_error("Foraging time trait solar altitude must contain two values."); + // Allocate gene + gene::foraging_time* foraging_time = new gene::foraging_time(); - trait::foraging_time* foraging_time = new trait::foraging_time(); - foraging_time->solar_altitude_min = math::radians(solar_altitude_element->front().get()); - foraging_time->solar_altitude_max = math::radians(solar_altitude_element->back().get()); + // Deserialize gene + gene::deserialize_gene(*foraging_time, &deserialize_foraging_time_phene, *foraging_time_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/gaster-loader.cpp b/src/game/ant/gene/loader/gaster-loader.cpp similarity index 57% rename from src/game/ant/trait/loader/gaster-loader.cpp rename to src/game/ant/gene/loader/gaster-loader.cpp index 3e1968e..1c783f9 100644 --- a/src/game/ant/trait/loader/gaster-loader.cpp +++ b/src/game/ant/gene/loader/gaster-loader.cpp @@ -17,40 +17,46 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/gaster.hpp" +#include "game/ant/gene/gaster.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_gaster_phene(phene::gaster& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.phragmosis = 0.0f; + + // Load gaster model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse phragmosis + if (auto element = phene_element.find("phragmosis"); element != phene_element.end()) + phene.phragmosis = element->get(); +} + template <> -trait::gaster* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::gaster* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto gaster_element = data->find("gaster"); if (gaster_element == data->end()) - throw std::runtime_error("Invalid gaster trait."); + throw std::runtime_error("Invalid gaster gene."); - // Allocate and init gaster trait - trait::gaster* gaster = new trait::gaster(); - gaster->model = nullptr; - gaster->phragmosis = 0.0; + // Allocate gene + gene::gaster* gaster = new gene::gaster(); - // Load gaster model - auto model_element = gaster_element->find("model"); - if (model_element == gaster_element->end()) - throw std::runtime_error("Gaster trait doesn't specify gaster model."); - gaster->model = resource_manager->load(model_element->get()); - - // Parse phragmosis - if (auto element = gaster_element->find("phragmosis"); element != gaster_element->end()) - gaster->phragmosis = element->get(); + // Deserialize gene + gene::deserialize_gene(*gaster, &deserialize_gaster_phene, *gaster_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/gene/loader/gene-loader.hpp b/src/game/ant/gene/loader/gene-loader.hpp new file mode 100644 index 0000000..829640a --- /dev/null +++ b/src/game/ant/gene/loader/gene-loader.hpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_GENE_LOADER_HPP +#define ANTKEEPER_GAME_ANT_GENE_GENE_LOADER_HPP + +#include "game/ant/gene/monophenic-gene.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" +#include "resources/json.hpp" +#include "resources/resource-manager.hpp" + +namespace game { +namespace ant { +namespace gene { + +/** + * Deserializes a gene. + * + * @tparam T Phene type. + * + * @param gene Gene to deserialize. + * @param deserialize_phene Phene deserialization function. + * @param gene_element JSON element containing a gene definition. + * @param resource_manager Resource manager pointer. + */ +/// @{ +template +void deserialize_gene(monophenic_gene& gene, void (*deserialize_phene)(T&, const json&, resource_manager*), const json& gene_element, resource_manager* resource_manager) +{ + // Read gene name + if (auto element = gene_element.find("name"); element != gene_element.end()) + gene.name = element->get(); + + // Deserialize phene + if (auto element = gene_element.find("phene"); element != gene_element.end()) + deserialize_phene(gene.phene, *element, resource_manager); +} + +template +void deserialize_gene(polyphenic_gene& gene, void (*deserialize_phene)(T&, const json&, resource_manager*), const json& gene_element, resource_manager* resource_manager) +{ + // Read gene name + if (auto element = gene_element.find("name"); element != gene_element.end()) + gene.name = element->get(); + + // Deserialize phenes + if (auto phenes_element = gene_element.find("phenes"); phenes_element != gene_element.end()) + { + if (auto element = phenes_element->find("female"); element != phenes_element->end()) + { + deserialize_phene(gene.phenes[caste::queen], *element, resource_manager); + deserialize_phene(gene.phenes[caste::worker], *element, resource_manager); + deserialize_phene(gene.phenes[caste::soldier], *element, resource_manager); + } + if (auto element = phenes_element->find("male"); element != phenes_element->end()) + deserialize_phene(gene.phenes[caste::male], *element, resource_manager); + if (auto element = phenes_element->find("queen"); element != phenes_element->end()) + deserialize_phene(gene.phenes[caste::queen], *element, resource_manager); + if (auto element = phenes_element->find("worker"); element != phenes_element->end()) + deserialize_phene(gene.phenes[caste::worker], *element, resource_manager); + if (auto element = phenes_element->find("soldier"); element != phenes_element->end()) + deserialize_phene(gene.phenes[caste::soldier], *element, resource_manager); + } +} +/// @} + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_GENE_LOADER_HPP diff --git a/src/game/ant/trait/loader/head-loader.cpp b/src/game/ant/gene/loader/head-loader.cpp similarity index 50% rename from src/game/ant/trait/loader/head-loader.cpp rename to src/game/ant/gene/loader/head-loader.cpp index 5c3f274..1a88677 100644 --- a/src/game/ant/trait/loader/head-loader.cpp +++ b/src/game/ant/gene/loader/head-loader.cpp @@ -17,50 +17,56 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/head.hpp" +#include "game/ant/gene/head.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_head_phene(phene::head& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.length = 0.0f; + phene.width = 0.0f; + phene.phragmosis = 0.0f; + + // Load head model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse length + if (auto element = phene_element.find("length"); element != phene_element.end()) + phene.length = element->get(); + + // Parse width + if (auto element = phene_element.find("width"); element != phene_element.end()) + phene.width = element->get(); + + // Parse phragmosis + if (auto element = phene_element.find("phragmosis"); element != phene_element.end()) + phene.phragmosis = element->get(); +} + template <> -trait::head* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::head* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto head_element = data->find("head"); if (head_element == data->end()) - throw std::runtime_error("Invalid head trait."); - - // Allocate and init head trait - trait::head* head = new trait::head(); - head->model = nullptr; - head->length = 0.0f; - head->width = 0.0f; - head->phragmosis = false; - - // Load model - auto model_element = head_element->find("model"); - if (model_element == head_element->end()) - throw std::runtime_error("Head trait doesn't specify head model."); - head->model = resource_manager->load(model_element->get()); + throw std::runtime_error("Invalid head gene."); - // Parse length - if (auto element = head_element->find("length"); element != head_element->end()) - head->length = element->get(); - - // Parse width - if (auto element = head_element->find("width"); element != head_element->end()) - head->width = element->get(); + // Allocate gene + gene::head* head = new gene::head(); - // Parse phragmosis - if (auto element = head_element->find("phragmosis"); element != head_element->end()) - head->phragmosis = element->get(); + // Deserialize gene + gene::deserialize_gene(*head, &deserialize_head_phene, *head_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/larva-loader.cpp b/src/game/ant/gene/loader/larva-loader.cpp similarity index 55% rename from src/game/ant/trait/loader/larva-loader.cpp rename to src/game/ant/gene/loader/larva-loader.cpp index 490c76a..467acd3 100644 --- a/src/game/ant/trait/loader/larva-loader.cpp +++ b/src/game/ant/gene/loader/larva-loader.cpp @@ -17,40 +17,46 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/larva.hpp" +#include "game/ant/gene/larva.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_larva_phene(phene::larva& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.instar_count = 0; + + // Load larva model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse instar count + if (auto element = phene_element.find("instar_count"); element != phene_element.end()) + phene.instar_count = element->get(); +} + template <> -trait::larva* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::larva* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto larva_element = data->find("larva"); if (larva_element == data->end()) - throw std::runtime_error("Invalid larva trait."); - - // Allocate and init larva trait - trait::larva* larva = new trait::larva(); - larva->model = nullptr; - larva->instars = 0; + throw std::runtime_error("Invalid larva gene."); - // Load model - auto model_element = larva_element->find("model"); - if (model_element == larva_element->end()) - throw std::runtime_error("Larva trait doesn't specify larva model."); - larva->model = resource_manager->load(model_element->get()); + // Allocate gene + gene::larva* larva = new gene::larva(); - // Parse instars - if (auto element = larva_element->find("instars"); element != larva_element->end()) - larva->instars = element->get(); + // Deserialize gene + gene::deserialize_gene(*larva, &deserialize_larva_phene, *larva_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/legs-loader.cpp b/src/game/ant/gene/loader/legs-loader.cpp similarity index 53% rename from src/game/ant/trait/loader/legs-loader.cpp rename to src/game/ant/gene/loader/legs-loader.cpp index 6a53019..9572921 100644 --- a/src/game/ant/trait/loader/legs-loader.cpp +++ b/src/game/ant/gene/loader/legs-loader.cpp @@ -17,45 +17,51 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/legs.hpp" +#include "game/ant/gene/legs.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_legs_phene(phene::legs& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.speed = 0.0f; + phene.grip = 0.0f; + + // Load legs model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse speed + if (auto element = phene_element.find("speed"); element != phene_element.end()) + phene.speed = element->get(); + + // Parse grip + if (auto element = phene_element.find("grip"); element != phene_element.end()) + phene.grip = element->get(); +} + template <> -trait::legs* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::legs* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto legs_element = data->find("legs"); if (legs_element == data->end()) - throw std::runtime_error("Invalid legs trait."); - - // Allocate and init legs trait - trait::legs* legs = new trait::legs(); - legs->model = nullptr; - legs->speed = 1.0f; - legs->grip = 1.0f; + throw std::runtime_error("Invalid legs gene."); - // Load model - auto model_element = legs_element->find("model"); - if (model_element == legs_element->end()) - throw std::runtime_error("Legs trait doesn't specify legs model."); - legs->model = resource_manager->load(model_element->get()); + // Allocate gene + gene::legs* legs = new gene::legs(); - // Parse speed - if (auto element = legs_element->find("speed"); element != legs_element->end()) - legs->speed = element->get(); - - // Parse grip - if (auto element = legs_element->find("grip"); element != legs_element->end()) - legs->grip = element->get(); + // Deserialize gene + gene::deserialize_gene(*legs, &deserialize_legs_phene, *legs_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/gene/loader/mandibles-loader.cpp b/src/game/ant/gene/loader/mandibles-loader.cpp new file mode 100644 index 0000000..744fa9c --- /dev/null +++ b/src/game/ant/gene/loader/mandibles-loader.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/mandibles.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_mandibles_phene(phene::mandibles& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.length = 0.0f; + phene.apical_dental_count = 0; + phene.basal_dental_count = 0; + + // Load mandibles model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse length + if (auto element = phene_element.find("length"); element != phene_element.end()) + phene.length = element->get(); + + // Parse apical dental count count + if (auto element = phene_element.find("apical_dental_count"); element != phene_element.end()) + phene.apical_dental_count = element->get(); + + // Parse basal dental count count + if (auto element = phene_element.find("basal_dental_count"); element != phene_element.end()) + phene.basal_dental_count = element->get(); +} + +template <> +gene::mandibles* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto mandibles_element = data->find("mandibles"); + if (mandibles_element == data->end()) + throw std::runtime_error("Invalid mandibles gene."); + + // Allocate gene + gene::mandibles* mandibles = new gene::mandibles(); + + // Deserialize gene + gene::deserialize_gene(*mandibles, &deserialize_mandibles_phene, *mandibles_element, resource_manager); + + // Free JSON data + delete data; + + return mandibles; +} diff --git a/src/game/ant/gene/loader/mesosoma-loader.cpp b/src/game/ant/gene/loader/mesosoma-loader.cpp new file mode 100644 index 0000000..9db624e --- /dev/null +++ b/src/game/ant/gene/loader/mesosoma-loader.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/mesosoma.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_mesosoma_phene(phene::mesosoma& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.pronotum_width = 0.0f; + phene.pronotum_spinescence = 0.0f; + phene.mesonotum_spinescence = 0.0f; + phene.propodeum_spinescence = 0.0f; + + // Load mesosoma model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse pronotum width + if (auto element = phene_element.find("pronotum_width"); element != phene_element.end()) + phene.pronotum_width = element->get(); + + // Parse pronotum spinescence + if (auto element = phene_element.find("pronotum_spinescence"); element != phene_element.end()) + phene.pronotum_spinescence = element->get(); + + // Parse mesonotum spinescence + if (auto element = phene_element.find("mesonotum_spinescence"); element != phene_element.end()) + phene.mesonotum_spinescence = element->get(); + + // Parse propodeum spinescence + if (auto element = phene_element.find("propodeum_spinescence"); element != phene_element.end()) + phene.propodeum_spinescence = element->get(); +} + +template <> +gene::mesosoma* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto mesosoma_element = data->find("mesosoma"); + if (mesosoma_element == data->end()) + throw std::runtime_error("Invalid mesosoma gene."); + + // Allocate gene + gene::mesosoma* mesosoma = new gene::mesosoma(); + + // Deserialize gene + gene::deserialize_gene(*mesosoma, &deserialize_mesosoma_phene, *mesosoma_element, resource_manager); + + // Free JSON data + delete data; + + return mesosoma; +} diff --git a/src/game/ant/gene/loader/ocelli-loader.cpp b/src/game/ant/gene/loader/ocelli-loader.cpp new file mode 100644 index 0000000..90f05b5 --- /dev/null +++ b/src/game/ant/gene/loader/ocelli-loader.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/ocelli.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_ocelli_phene(phene::ocelli& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.lateral_ocelli_present = false; + phene.median_ocellus_present = false; + phene.lateral_ocelli_model = nullptr; + phene.median_ocellus_model = nullptr; + phene.width = 0.0f; + phene.height = 0.0f; + + // Parse lateral ocelli present + if (auto element = phene_element.find("lateral_ocelli_present"); element != phene_element.end()) + phene.lateral_ocelli_present = element->get(); + + // Parse median ocelli present + if (auto element = phene_element.find("median_ocellus_present"); element != phene_element.end()) + phene.median_ocellus_present = element->get(); + + // Parse width + if (auto element = phene_element.find("width"); element != phene_element.end()) + phene.width = element->get(); + + // Parse height + if (auto element = phene_element.find("height"); element != phene_element.end()) + phene.height = element->get(); + + // Load lateral ocelli model, if present + if (phene.lateral_ocelli_present) + { + if (auto element = phene_element.find("lateral_ocelli_model"); element != phene_element.end()) + phene.lateral_ocelli_model = resource_manager->load(element->get()); + } + + // Load median ocellus model, if present + if (phene.median_ocellus_present) + { + if (auto element = phene_element.find("median_ocellus_model"); element != phene_element.end()) + phene.median_ocellus_model = resource_manager->load(element->get()); + } +} + +template <> +gene::ocelli* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto ocelli_element = data->find("ocelli"); + if (ocelli_element == data->end()) + throw std::runtime_error("Invalid ocelli gene."); + + // Allocate gene + gene::ocelli* ocelli = new gene::ocelli(); + + // Deserialize gene + gene::deserialize_gene(*ocelli, &deserialize_ocelli_phene, *ocelli_element, resource_manager); + + // Free JSON data + delete data; + + return ocelli; +} diff --git a/src/game/ant/trait/loader/pigmentation-loader.cpp b/src/game/ant/gene/loader/pigmentation-loader.cpp similarity index 57% rename from src/game/ant/trait/loader/pigmentation-loader.cpp rename to src/game/ant/gene/loader/pigmentation-loader.cpp index 829e3de..88c810d 100644 --- a/src/game/ant/trait/loader/pigmentation-loader.cpp +++ b/src/game/ant/gene/loader/pigmentation-loader.cpp @@ -17,34 +17,41 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/pigmentation.hpp" +#include "game/ant/gene/pigmentation.hpp" +#include "render/material.hpp" #include using namespace game::ant; +static void deserialize_pigmentation_phene(phene::pigmentation& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.material = nullptr; + + // Load pigmentation material + if (auto element = phene_element.find("material"); element != phene_element.end()) + phene.material = resource_manager->load(element->get()); +} + template <> -trait::pigmentation* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::pigmentation* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto pigmentation_element = data->find("pigmentation"); if (pigmentation_element == data->end()) - throw std::runtime_error("Invalid pigmentation trait."); + throw std::runtime_error("Invalid pigmentation gene."); - // Allocate and init pigmentation trait - trait::pigmentation* pigmentation = new trait::pigmentation(); - pigmentation->material = nullptr; + // Allocate gene + gene::pigmentation* pigmentation = new gene::pigmentation(); - // Load pigmentation material - auto material_element = pigmentation_element->find("material"); - if (material_element == pigmentation_element->end()) - throw std::runtime_error("Pigmentation trait doesn't specify pigmentation material."); - pigmentation->material = resource_manager->load(material_element->get()); + // Deserialize gene + gene::deserialize_gene(*pigmentation, &deserialize_pigmentation_phene, *pigmentation_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/pilosity-loader.cpp b/src/game/ant/gene/loader/pilosity-loader.cpp similarity index 60% rename from src/game/ant/trait/loader/pilosity-loader.cpp rename to src/game/ant/gene/loader/pilosity-loader.cpp index 38604a8..5b1aea8 100644 --- a/src/game/ant/trait/loader/pilosity-loader.cpp +++ b/src/game/ant/gene/loader/pilosity-loader.cpp @@ -17,32 +17,40 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/pilosity.hpp" +#include "game/ant/gene/pilosity.hpp" #include using namespace game::ant; +static void deserialize_pilosity_phene(phene::pilosity& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.density = 0.0f; + + // Parse density + if (auto element = phene_element.find("density"); element != phene_element.end()) + phene.density = element->get(); +} + template <> -trait::pilosity* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::pilosity* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto pilosity_element = data->find("pilosity"); if (pilosity_element == data->end()) - throw std::runtime_error("Invalid pilosity trait."); + throw std::runtime_error("Invalid pilosity gene."); - // Allocate and init pilosity trait - trait::pilosity* pilosity = new trait::pilosity(); - pilosity->density = 0.0f; + // Allocate gene + gene::pilosity* pilosity = new gene::pilosity(); - // Parse pilosity density - if (auto density_element = pilosity_element->find("density"); density_element != pilosity_element->end()) - pilosity->density = density_element->get(); + // Deserialize gene + gene::deserialize_gene(*pilosity, &deserialize_pilosity_phene, *pilosity_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/sculpturing-loader.cpp b/src/game/ant/gene/loader/sculpturing-loader.cpp similarity index 53% rename from src/game/ant/trait/loader/sculpturing-loader.cpp rename to src/game/ant/gene/loader/sculpturing-loader.cpp index 5c1e5bc..f611981 100644 --- a/src/game/ant/trait/loader/sculpturing-loader.cpp +++ b/src/game/ant/gene/loader/sculpturing-loader.cpp @@ -17,39 +17,46 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/sculpturing.hpp" +#include "game/ant/gene/sculpturing.hpp" #include "gl/texture-2d.hpp" #include using namespace game::ant; +static void deserialize_sculpturing_phene(phene::sculpturing& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.normal_map = nullptr; + phene.roughness = 0.0f; + + // Load normal map + if (auto element = phene_element.find("normal_map"); element != phene_element.end()) + phene.normal_map = resource_manager->load(element->get()); + + // Parse roughness + if (auto element = phene_element.find("roughness"); element != phene_element.end()) + phene.roughness = element->get(); +} + template <> -trait::sculpturing* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::sculpturing* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto sculpturing_element = data->find("sculpturing"); if (sculpturing_element == data->end()) - throw std::runtime_error("Invalid sculpturing trait."); - - // Allocate sculpturing trait - trait::sculpturing* sculpturing = new trait::sculpturing(); + throw std::runtime_error("Invalid sculpturing gene."); - // Load sculpturing normal map - auto normal_map_element = sculpturing_element->find("normal_map"); - if (normal_map_element == sculpturing_element->end()) - throw std::runtime_error("Sculpturing trait doesn't specify sculpturing normal map."); - sculpturing->normal_map = resource_manager->load(normal_map_element->get()); + // Allocate gene + gene::sculpturing* sculpturing = new gene::sculpturing(); - // Parse sculpturing roughness - sculpturing->roughness = 0.0f; - if (auto roughness_element = sculpturing_element->find("roughness"); roughness_element != sculpturing_element->end()) - sculpturing->roughness = roughness_element->get(); + // Deserialize gene + gene::deserialize_gene(*sculpturing, &deserialize_sculpturing_phene, *sculpturing_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/trait/loader/sting-loader.cpp b/src/game/ant/gene/loader/sting-loader.cpp similarity index 55% rename from src/game/ant/trait/loader/sting-loader.cpp rename to src/game/ant/gene/loader/sting-loader.cpp index 93d8da8..f83d83b 100644 --- a/src/game/ant/trait/loader/sting-loader.cpp +++ b/src/game/ant/gene/loader/sting-loader.cpp @@ -17,43 +17,49 @@ * along with Antkeeper source code. If not, see . */ +#include "game/ant/gene/loader/gene-loader.hpp" #include "resources/resource-loader.hpp" #include "resources/resource-manager.hpp" #include "resources/json.hpp" -#include "game/ant/trait/sting.hpp" +#include "game/ant/gene/sting.hpp" #include "render/model.hpp" #include using namespace game::ant; +static void deserialize_sting_phene(phene::sting& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.present = false; + phene.model = nullptr; + + // Parse present + if (auto element = phene_element.find("present"); element != phene_element.end()) + phene.present = element->get(); + + if (phene.present) + { + // Load sting model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + } +} + template <> -trait::sting* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +gene::sting* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) { // Load JSON data json* data = resource_loader::load(resource_manager, file, path); - // Validate trait file + // Validate gene file auto sting_element = data->find("sting"); if (sting_element == data->end()) - throw std::runtime_error("Invalid sting trait."); - - // Allocate and init sting trait - trait::sting* sting = new trait::sting(); - sting->present = false; - sting->model = nullptr; + throw std::runtime_error("Invalid sting gene."); - // Parse sting present - if (auto element = sting_element->find("present"); element != sting_element->end()) - sting->present = element->get(); + // Allocate gene + gene::sting* sting = new gene::sting(); - // Load sting model (if present) - if (sting->present) - { - auto model_element = sting_element->find("model"); - if (model_element == sting_element->end()) - throw std::runtime_error("Sting trait doesn't specify sting model."); - sting->model = resource_manager->load(model_element->get()); - } + // Deserialize gene + gene::deserialize_gene(*sting, &deserialize_sting_phene, *sting_element, resource_manager); // Free JSON data delete data; diff --git a/src/game/ant/gene/loader/waist-loader.cpp b/src/game/ant/gene/loader/waist-loader.cpp new file mode 100644 index 0000000..ca678cb --- /dev/null +++ b/src/game/ant/gene/loader/waist-loader.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/waist.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_waist_phene(phene::waist& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.model = nullptr; + phene.petiole_present = false; + phene.petiole_length = 0.0f; + phene.petiole_width = 0.0f; + phene.petiole_height = 0.0f; + phene.petiole_spinescence = 0.0f; + phene.postpetiole_present = false; + phene.postpetiole_length = 0.0f; + phene.postpetiole_width = 0.0f; + phene.postpetiole_height = 0.0f; + phene.postpetiole_spinescence = 0.0f; + + // Load waist model + if (auto element = phene_element.find("model"); element != phene_element.end()) + phene.model = resource_manager->load(element->get()); + + // Parse petiole present + if (auto element = phene_element.find("petiole_present"); element != phene_element.end()) + phene.petiole_present = element->get(); + + // Parse postpetiole present + if (auto element = phene_element.find("postpetiole_present"); element != phene_element.end()) + phene.postpetiole_present = element->get(); + + if (phene.petiole_present) + { + // Parse petiole length + if (auto element = phene_element.find("petiole_length"); element != phene_element.end()) + phene.petiole_length = element->get(); + + // Parse petiole width + if (auto element = phene_element.find("petiole_width"); element != phene_element.end()) + phene.petiole_width = element->get(); + + // Parse petiole height + if (auto element = phene_element.find("petiole_height"); element != phene_element.end()) + phene.petiole_height = element->get(); + + // Parse petiole spinescence + if (auto element = phene_element.find("petiole_spinescence"); element != phene_element.end()) + phene.petiole_spinescence = element->get(); + } + + if (phene.postpetiole_present) + { + // Parse postpetiole length + if (auto element = phene_element.find("postpetiole_length"); element != phene_element.end()) + phene.postpetiole_length = element->get(); + + // Parse postpetiole width + if (auto element = phene_element.find("postpetiole_width"); element != phene_element.end()) + phene.postpetiole_width = element->get(); + + // Parse postpetiole height + if (auto element = phene_element.find("postpetiole_height"); element != phene_element.end()) + phene.postpetiole_height = element->get(); + + // Parse postpetiole spinescence + if (auto element = phene_element.find("postpetiole_spinescence"); element != phene_element.end()) + phene.postpetiole_spinescence = element->get(); + } +} + +template <> +gene::waist* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto waist_element = data->find("waist"); + if (waist_element == data->end()) + throw std::runtime_error("Invalid waist gene."); + + // Allocate gene + gene::waist* waist = new gene::waist(); + + // Deserialize gene + gene::deserialize_gene(*waist, &deserialize_waist_phene, *waist_element, resource_manager); + + // Free JSON data + delete data; + + return waist; +} diff --git a/src/game/ant/gene/loader/wings-loader.cpp b/src/game/ant/gene/loader/wings-loader.cpp new file mode 100644 index 0000000..3e227a8 --- /dev/null +++ b/src/game/ant/gene/loader/wings-loader.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/gene/loader/gene-loader.hpp" +#include "resources/resource-loader.hpp" +#include "resources/resource-manager.hpp" +#include "resources/json.hpp" +#include "game/ant/gene/wings.hpp" +#include "render/model.hpp" +#include + +using namespace game::ant; + +static void deserialize_wings_phene(phene::wings& phene, const json& phene_element, resource_manager* resource_manager) +{ + phene.present = false; + phene.forewings_model = nullptr; + phene.hindwings_model = nullptr; + phene.forewing_length = 0.0f; + phene.forewing_width = 0.0f; + phene.forewing_venation = 0.0f; + phene.hindwing_length = 0.0f; + phene.hindwing_width = 0.0f; + phene.hindwing_venation = 0.0f; + + // Parse present + if (auto element = phene_element.find("present"); element != phene_element.end()) + phene.present = element->get(); + + if (phene.present) + { + // Load forewings model + if (auto element = phene_element.find("forewings_model"); element != phene_element.end()) + phene.forewings_model = resource_manager->load(element->get()); + + // Load hindwings model + if (auto element = phene_element.find("hindwings_model"); element != phene_element.end()) + phene.hindwings_model = resource_manager->load(element->get()); + + // Parse forewing length + if (auto element = phene_element.find("forewing_length"); element != phene_element.end()) + phene.forewing_length = element->get(); + + // Parse forewing width + if (auto element = phene_element.find("forewing_width"); element != phene_element.end()) + phene.forewing_width = element->get(); + + // Parse forewing venation + if (auto element = phene_element.find("forewing_venation"); element != phene_element.end()) + phene.forewing_venation = element->get(); + + // Parse hindwing length + if (auto element = phene_element.find("hindwing_length"); element != phene_element.end()) + phene.hindwing_length = element->get(); + + // Parse hindwing width + if (auto element = phene_element.find("hindwing_width"); element != phene_element.end()) + phene.hindwing_width = element->get(); + + // Parse hindwing venation + if (auto element = phene_element.find("hindwing_venation"); element != phene_element.end()) + phene.hindwing_venation = element->get(); + } +} + +template <> +gene::wings* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) +{ + // Load JSON data + json* data = resource_loader::load(resource_manager, file, path); + + // Validate gene file + auto wings_element = data->find("wings"); + if (wings_element == data->end()) + throw std::runtime_error("Invalid wings gene."); + + // Allocate gene + gene::wings* wings = new gene::wings(); + + // Deserialize gene + gene::deserialize_gene(*wings, &deserialize_wings_phene, *wings_element, resource_manager); + + // Free JSON data + delete data; + + return wings; +} diff --git a/src/game/ant/gene/mandibles.hpp b/src/game/ant/gene/mandibles.hpp new file mode 100644 index 0000000..514e435 --- /dev/null +++ b/src/game/ant/gene/mandibles.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_MANDIBLES_HPP +#define ANTKEEPER_GAME_ANT_GENE_MANDIBLES_HPP + +#include "game/ant/phene/mandibles.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic mandibles gene. +typedef polyphenic_gene mandibles; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_MANDIBLES_HPP diff --git a/src/game/ant/gene/mesosoma.hpp b/src/game/ant/gene/mesosoma.hpp new file mode 100644 index 0000000..ad0164c --- /dev/null +++ b/src/game/ant/gene/mesosoma.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_MESOSOMA_HPP +#define ANTKEEPER_GAME_ANT_GENE_MESOSOMA_HPP + +#include "game/ant/phene/mesosoma.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic mesosoma gene. +typedef polyphenic_gene mesosoma; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_MESOSOMA_HPP diff --git a/src/game/ant/caste-type.hpp b/src/game/ant/gene/monophenic-gene.hpp similarity index 69% rename from src/game/ant/caste-type.hpp rename to src/game/ant/gene/monophenic-gene.hpp index 85128b5..78f5789 100644 --- a/src/game/ant/caste-type.hpp +++ b/src/game/ant/gene/monophenic-gene.hpp @@ -17,33 +17,32 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_CASTE_TYPE_HPP -#define ANTKEEPER_GAME_ANT_CASTE_TYPE_HPP +#ifndef ANTKEEPER_GAME_ANT_GENE_MONOPHENIC_GENE_HPP +#define ANTKEEPER_GAME_ANT_GENE_MONOPHENIC_GENE_HPP + +#include namespace game { namespace ant { +namespace gene { /** - * Ant caste type enumerations + * Gene with a single phene. * - * @see https://www.antwiki.org/wiki/Caste_Terminology + * @tparam T Phene type. */ -enum class caste_type +template +struct monophenic_gene { - /// Queen caste type. - queen, - - /// Worker caste type. - worker, - - /// Soldier caste type. - soldier, + /// Gene name. + std::string name; - /// Male caste type. - male + /// Phene definition. + T phene; }; +} // namespace gene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_CASTE_TYPE_HPP +#endif // ANTKEEPER_GAME_ANT_GENE_MONOPHENIC_GENE_HPP diff --git a/src/game/ant/gene/nest-site.hpp b/src/game/ant/gene/nest-site.hpp new file mode 100644 index 0000000..5827279 --- /dev/null +++ b/src/game/ant/gene/nest-site.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_NEST_SITE_HPP +#define ANTKEEPER_GAME_ANT_GENE_NEST_SITE_HPP + +#include "game/ant/phene/nest-site.hpp" +#include "game/ant/gene/monophenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Monophenic nest site gene. +typedef monophenic_gene nest_site; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_NEST_SITE_HPP diff --git a/src/game/ant/gene/ocelli.hpp b/src/game/ant/gene/ocelli.hpp new file mode 100644 index 0000000..5cf0ed2 --- /dev/null +++ b/src/game/ant/gene/ocelli.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_OCELLI_HPP +#define ANTKEEPER_GAME_ANT_GENE_OCELLI_HPP + +#include "game/ant/phene/ocelli.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic ocelli gene. +typedef polyphenic_gene ocelli; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_OCELLI_HPP diff --git a/src/game/ant/gene/pigmentation.hpp b/src/game/ant/gene/pigmentation.hpp new file mode 100644 index 0000000..2f6bff7 --- /dev/null +++ b/src/game/ant/gene/pigmentation.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_PIGMENTATION_HPP +#define ANTKEEPER_GAME_ANT_GENE_PIGMENTATION_HPP + +#include "game/ant/phene/pigmentation.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic pigmentation gene. +typedef polyphenic_gene pigmentation; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_PIGMENTATION_HPP diff --git a/src/game/ant/gene/pilosity.hpp b/src/game/ant/gene/pilosity.hpp new file mode 100644 index 0000000..10fb130 --- /dev/null +++ b/src/game/ant/gene/pilosity.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_PILOSITY_HPP +#define ANTKEEPER_GAME_ANT_GENE_PILOSITY_HPP + +#include "game/ant/phene/pilosity.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic pilosity gene. +typedef polyphenic_gene pilosity; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_PILOSITY_HPP diff --git a/src/game/ant/gene/polyphenic-gene.hpp b/src/game/ant/gene/polyphenic-gene.hpp new file mode 100644 index 0000000..ed97881 --- /dev/null +++ b/src/game/ant/gene/polyphenic-gene.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_HPP +#define ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_HPP + +#include "game/ant/caste.hpp" +#include +#include + +namespace game { +namespace ant { +namespace gene { + +/** + * Gene with caste-specific phenes. + * + * @tparam T Phene type. + * + * @see https://en.wikipedia.org/wiki/Polyphenism + */ +template +struct polyphenic_gene +{ + /// Gene name. + std::string name; + + /// Caste-specific phene definitions. + std::unordered_map phenes; +}; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_HPP diff --git a/src/game/ant/gene/sculpturing.hpp b/src/game/ant/gene/sculpturing.hpp new file mode 100644 index 0000000..dc65112 --- /dev/null +++ b/src/game/ant/gene/sculpturing.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_SCULPTURING_HPP +#define ANTKEEPER_GAME_ANT_GENE_SCULPTURING_HPP + +#include "game/ant/phene/sculpturing.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic sculpturing gene. +typedef polyphenic_gene sculpturing; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_SCULPTURING_HPP diff --git a/src/game/ant/gene/sting.hpp b/src/game/ant/gene/sting.hpp new file mode 100644 index 0000000..b8b879f --- /dev/null +++ b/src/game/ant/gene/sting.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_STING_HPP +#define ANTKEEPER_GAME_ANT_GENE_STING_HPP + +#include "game/ant/phene/sting.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic sting gene. +typedef polyphenic_gene sting; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_STING_HPP diff --git a/src/game/ant/gene/waist.hpp b/src/game/ant/gene/waist.hpp new file mode 100644 index 0000000..ebdf1ed --- /dev/null +++ b/src/game/ant/gene/waist.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_WAIST_HPP +#define ANTKEEPER_GAME_ANT_GENE_WAIST_HPP + +#include "game/ant/phene/waist.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic waist gene. +typedef polyphenic_gene waist; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_WAIST_HPP diff --git a/src/game/ant/gene/wings.hpp b/src/game/ant/gene/wings.hpp new file mode 100644 index 0000000..ddb1739 --- /dev/null +++ b/src/game/ant/gene/wings.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENE_WINGS_HPP +#define ANTKEEPER_GAME_ANT_GENE_WINGS_HPP + +#include "game/ant/phene/wings.hpp" +#include "game/ant/gene/polyphenic-gene.hpp" + +namespace game { +namespace ant { +namespace gene { + +/// Polyphenic wings gene. +typedef polyphenic_gene wings; + +} // namespace gene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENE_WINGS_HPP diff --git a/src/game/ant/genome.cpp b/src/game/ant/genome.cpp new file mode 100644 index 0000000..b1bedae --- /dev/null +++ b/src/game/ant/genome.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/genome.hpp" + +namespace game { +namespace ant { + +genome::genome(): + antennae(nullptr), + body_size(nullptr), + cocoon(nullptr), + diet(nullptr), + egg(nullptr), + eyes(nullptr), + foraging_time(nullptr), + founding_mode(nullptr), + gaster(nullptr), + head(nullptr), + larva(nullptr), + legs(nullptr), + mandibles(nullptr), + mesosoma(nullptr), + nest_site(nullptr), + ocelli(nullptr), + pigmentation(nullptr), + pilosity(nullptr), + sculpturing(nullptr), + sting(nullptr), + waist(nullptr), + wings(nullptr) +{} + +} // namespace ant +} // namespace game diff --git a/src/game/ant/genome.hpp b/src/game/ant/genome.hpp new file mode 100644 index 0000000..6946177 --- /dev/null +++ b/src/game/ant/genome.hpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_GENOME_HPP +#define ANTKEEPER_GAME_ANT_GENOME_HPP + +#include "game/ant/gene/antennae.hpp" +#include "game/ant/gene/body-size.hpp" +#include "game/ant/gene/cocoon.hpp" +#include "game/ant/gene/diet.hpp" +#include "game/ant/gene/egg.hpp" +#include "game/ant/gene/eyes.hpp" +#include "game/ant/gene/foraging-time.hpp" +#include "game/ant/gene/founding-mode.hpp" +#include "game/ant/gene/gaster.hpp" +#include "game/ant/gene/head.hpp" +#include "game/ant/gene/larva.hpp" +#include "game/ant/gene/legs.hpp" +#include "game/ant/gene/mandibles.hpp" +#include "game/ant/gene/mesosoma.hpp" +#include "game/ant/gene/nest-site.hpp" +#include "game/ant/gene/ocelli.hpp" +#include "game/ant/gene/pigmentation.hpp" +#include "game/ant/gene/pilosity.hpp" +#include "game/ant/gene/sculpturing.hpp" +#include "game/ant/gene/sting.hpp" +#include "game/ant/gene/waist.hpp" +#include "game/ant/gene/wings.hpp" + +namespace game { +namespace ant { + +/** + * Complete set of ant genes. + */ +struct genome +{ + /// Constructs an empty genome. + genome(); + + const gene::antennae* antennae; + const gene::body_size* body_size; + const gene::cocoon* cocoon; + const gene::diet* diet; + const gene::egg* egg; + const gene::eyes* eyes; + const gene::foraging_time* foraging_time; + const gene::founding_mode* founding_mode; + const gene::gaster* gaster; + const gene::head* head; + const gene::larva* larva; + const gene::legs* legs; + const gene::mandibles* mandibles; + const gene::mesosoma* mesosoma; + const gene::nest_site* nest_site; + const gene::ocelli* ocelli; + const gene::pigmentation* pigmentation; + const gene::pilosity* pilosity; + const gene::sculpturing* sculpturing; + const gene::sting* sting; + const gene::waist* waist; + const gene::wings* wings; +}; + +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_GENOME_HPP diff --git a/src/game/ant/morphogenesis.cpp b/src/game/ant/morphogenesis.cpp index 4ac7974..88253b9 100644 --- a/src/game/ant/morphogenesis.cpp +++ b/src/game/ant/morphogenesis.cpp @@ -30,8 +30,8 @@ namespace ant { static render::material* build_exoskeleton_material ( - const ant::trait::pigmentation& pigmentation, - const ant::trait::sculpturing& sculpturing + const phene::pigmentation& pigmentation, + const phene::sculpturing& sculpturing ); static void reskin_vertices ( @@ -66,8 +66,8 @@ static render::model* build_model render::material* build_exoskeleton_material ( - const ant::trait::pigmentation& pigmentation, - const ant::trait::sculpturing& sculpturing + const phene::pigmentation& pigmentation, + const phene::sculpturing& sculpturing ) { // Allocate copy of pigmentation material @@ -96,34 +96,34 @@ render::material* build_exoskeleton_material return exoskeleton_material; } -render::model* morphogenesis(const ant::caste& caste) +render::model* morphogenesis(const phenome& phenome) { // Build exoskeleton material - render::material* exoskeleton_material = build_exoskeleton_material(*caste.pigmentation, *caste.sculpturing); + render::material* exoskeleton_material = build_exoskeleton_material(*phenome.pigmentation, *phenome.sculpturing); // Determine presence of optional parts - bool eyes_present = caste.eyes->present; - bool lateral_ocelli_present = caste.ocelli->lateral_ocelli_present; - bool median_ocellus_present = caste.ocelli->median_ocellus_present; - bool petiole_present = caste.waist->petiole_present; - bool postpetiole_present = caste.waist->postpetiole_present; - bool sting_present = caste.sting->present; - bool wings_present = caste.wings->present; + bool eyes_present = phenome.eyes->present; + bool lateral_ocelli_present = phenome.ocelli->lateral_ocelli_present; + bool median_ocellus_present = phenome.ocelli->median_ocellus_present; + bool petiole_present = phenome.waist->petiole_present; + bool postpetiole_present = phenome.waist->postpetiole_present; + bool sting_present = phenome.sting->present; + bool wings_present = phenome.wings->present; // Get body part models - render::model* antennae_model = caste.antennae->model; - render::model* eyes_model = caste.eyes->model; - render::model* forewings_model = caste.wings->forewings_model; - render::model* gaster_model = caste.gaster->model; - render::model* head_model = caste.head->model; - render::model* hindwings_model = caste.wings->hindwings_model; - render::model* lateral_ocelli_model = caste.ocelli->lateral_ocelli_model; - render::model* legs_model = caste.legs->model; - render::model* mandibles_model = caste.mandibles->model; - render::model* median_ocellus_model = caste.ocelli->median_ocellus_model; - render::model* mesosoma_model = caste.mesosoma->model; - render::model* sting_model = caste.sting->model; - render::model* waist_model = caste.waist->model; + render::model* antennae_model = phenome.antennae->model; + render::model* eyes_model = phenome.eyes->model; + render::model* forewings_model = phenome.wings->forewings_model; + render::model* gaster_model = phenome.gaster->model; + render::model* head_model = phenome.head->model; + render::model* hindwings_model = phenome.wings->hindwings_model; + render::model* lateral_ocelli_model = phenome.ocelli->lateral_ocelli_model; + render::model* legs_model = phenome.legs->model; + render::model* mandibles_model = phenome.mandibles->model; + render::model* median_ocellus_model = phenome.ocelli->median_ocellus_model; + render::model* mesosoma_model = phenome.mesosoma->model; + render::model* sting_model = phenome.sting->model; + render::model* waist_model = phenome.waist->model; // Get body part vertex buffers const gl::vertex_buffer* antennae_vbo = antennae_model->get_vertex_buffer(); diff --git a/src/game/ant/morphogenesis.hpp b/src/game/ant/morphogenesis.hpp index 1c30051..ee35591 100644 --- a/src/game/ant/morphogenesis.hpp +++ b/src/game/ant/morphogenesis.hpp @@ -20,20 +20,20 @@ #ifndef ANTKEEPER_GAME_ANT_MORPHOGENESIS_HPP #define ANTKEEPER_GAME_ANT_MORPHOGENESIS_HPP -#include "game/ant/caste.hpp" +#include "game/ant/phenome.hpp" #include "render/model.hpp" namespace game { namespace ant { /** - * Generates a 3D model of an ant. + * Generates a 3D model of an ant given its phenome. * - * @param caste Caste description. + * @param phenome Phenome of an ant. * - * @return 3D model of an ant. + * @return 3D model of the given phenome. */ -render::model* morphogenesis(const ant::caste& caste); +render::model* morphogenesis(const phenome& phenome); } // namespace ant } // namespace game diff --git a/src/game/ant/trait/antennae.hpp b/src/game/ant/phene/antennae.hpp similarity index 86% rename from src/game/ant/trait/antennae.hpp rename to src/game/ant/phene/antennae.hpp index 2e57cb0..c6e39ed 100644 --- a/src/game/ant/trait/antennae.hpp +++ b/src/game/ant/phene/antennae.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_ANTENNAE_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_ANTENNAE_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_ANTENNAE_HPP +#define ANTKEEPER_GAME_ANT_PHENE_ANTENNAE_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant antennae description. + * Ant antennae phene. * * @see https://www.antwiki.org/wiki/Character_States_for_Extant_Ant_Genera_of_the_Formicidae * @see https://www.antwiki.org/wiki/Morphological_Measurements @@ -44,8 +44,8 @@ struct antennae int club_antennomere_count; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_ANTENNAE_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_ANTENNAE_HPP diff --git a/src/game/ant/phene/body-size.hpp b/src/game/ant/phene/body-size.hpp new file mode 100644 index 0000000..b7b7ecf --- /dev/null +++ b/src/game/ant/phene/body-size.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_PHENE_BODY_SIZE_HPP +#define ANTKEEPER_GAME_ANT_PHENE_BODY_SIZE_HPP + +#include "render/model.hpp" + +namespace game { +namespace ant { +namespace phene { + +/** + * Ant body size phene. + * + * @see https://www.antwiki.org/wiki/Morphological_Measurements + */ +struct body_size +{ + /// Minimum mesosoma length (Weber's length), in centimeters. + float min_mesosoma_length; + + /// Maximum mesosoma length (Weber's length), in centimeters. + float max_mesosoma_length; + + /// Mean mesosoma length (Weber's length), in centimeters. + float mean_mesosoma_length; +}; + +} // namespace phene +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_PHENE_BODY_SIZE_HPP diff --git a/src/game/ant/trait/cocoon.hpp b/src/game/ant/phene/cocoon.hpp similarity index 84% rename from src/game/ant/trait/cocoon.hpp rename to src/game/ant/phene/cocoon.hpp index 6898732..da471b1 100644 --- a/src/game/ant/trait/cocoon.hpp +++ b/src/game/ant/phene/cocoon.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_COCOON_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_COCOON_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_COCOON_HPP +#define ANTKEEPER_GAME_ANT_PHENE_COCOON_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant cocoon description. + * Ant cocoon phene. */ struct cocoon { @@ -38,8 +38,8 @@ struct cocoon bool present; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_COCOON_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_COCOON_HPP diff --git a/src/game/ant/trait/diet.hpp b/src/game/ant/phene/diet.hpp similarity index 86% rename from src/game/ant/trait/diet.hpp rename to src/game/ant/phene/diet.hpp index a691a23..6a7d8cb 100644 --- a/src/game/ant/trait/diet.hpp +++ b/src/game/ant/phene/diet.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_DIET_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_DIET_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_DIET_HPP +#define ANTKEEPER_GAME_ANT_PHENE_DIET_HPP namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant diet description. + * Ant diet phene. */ struct diet { @@ -48,8 +48,8 @@ struct diet float carrion; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_DIET_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_DIET_HPP diff --git a/src/game/ant/trait/egg.hpp b/src/game/ant/phene/egg.hpp similarity index 83% rename from src/game/ant/trait/egg.hpp rename to src/game/ant/phene/egg.hpp index a34cd2a..857b64e 100644 --- a/src/game/ant/trait/egg.hpp +++ b/src/game/ant/phene/egg.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_EGG_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_EGG_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_EGG_HPP +#define ANTKEEPER_GAME_ANT_PHENE_EGG_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant egg description. + * Ant egg phene. */ struct egg { @@ -35,8 +35,8 @@ struct egg render::model* model; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_EGG_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_EGG_HPP diff --git a/src/game/ant/trait/eyes.hpp b/src/game/ant/phene/eyes.hpp similarity index 87% rename from src/game/ant/trait/eyes.hpp rename to src/game/ant/phene/eyes.hpp index 378e4a9..85bf675 100644 --- a/src/game/ant/trait/eyes.hpp +++ b/src/game/ant/phene/eyes.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_EYES_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_EYES_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_EYES_HPP +#define ANTKEEPER_GAME_ANT_PHENE_EYES_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant eyes description. + * Ant eyes phene. * * @see https://www.antwiki.org/wiki/Morphological_Measurements */ @@ -52,8 +52,8 @@ struct eyes int ommatidia_count; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_EYES_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_EYES_HPP diff --git a/src/game/ant/trait/foraging-time.hpp b/src/game/ant/phene/foraging-time.hpp similarity index 78% rename from src/game/ant/trait/foraging-time.hpp rename to src/game/ant/phene/foraging-time.hpp index 7abb08f..6cc8b13 100644 --- a/src/game/ant/trait/foraging-time.hpp +++ b/src/game/ant/phene/foraging-time.hpp @@ -17,29 +17,29 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_FORAGING_TIME_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_FORAGING_TIME_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_FORAGING_TIME_HPP +#define ANTKEEPER_GAME_ANT_PHENE_FORAGING_TIME_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant foraging time description. + * Ant foraging time phene. */ struct foraging_time { /// Minimum solar altitude at which foraging occurs. - float solar_altitude_min; + float min_solar_altitude; /// Maximum solar alttiude at which foraging occurs. - float solar_altitude_max; + float max_solar_altitude; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_FORAGING_TIME_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_FORAGING_TIME_HPP diff --git a/src/game/ant/trait/founding-mode.hpp b/src/game/ant/phene/founding-mode.hpp similarity index 84% rename from src/game/ant/trait/founding-mode.hpp rename to src/game/ant/phene/founding-mode.hpp index 7a86dcc..66faf56 100644 --- a/src/game/ant/trait/founding-mode.hpp +++ b/src/game/ant/phene/founding-mode.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_FOUNDING_MODE_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_FOUNDING_MODE_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_FOUNDING_MODE_HPP +#define ANTKEEPER_GAME_ANT_PHENE_FOUNDING_MODE_HPP namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Colony founding mode. + * Colony founding mode phene. * * @see https://www.antwiki.org/wiki/Colony_Foundation */ @@ -41,8 +41,8 @@ enum class founding_mode fission }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_FOUNDING_MODE_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_FOUNDING_MODE_HPP diff --git a/src/game/ant/trait/gaster.hpp b/src/game/ant/phene/gaster.hpp similarity index 84% rename from src/game/ant/trait/gaster.hpp rename to src/game/ant/phene/gaster.hpp index 66426d3..ff5580c 100644 --- a/src/game/ant/trait/gaster.hpp +++ b/src/game/ant/phene/gaster.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_GASTER_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_GASTER_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_GASTER_HPP +#define ANTKEEPER_GAME_ANT_PHENE_GASTER_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant gaster description. + * Ant gaster phene. * * @see https://antwiki.org/wiki/Phragmosis */ @@ -40,8 +40,8 @@ struct gaster float phragmosis; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_GASTER_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_GASTER_HPP diff --git a/src/game/ant/trait/head.hpp b/src/game/ant/phene/head.hpp similarity index 86% rename from src/game/ant/trait/head.hpp rename to src/game/ant/phene/head.hpp index b8a3bf6..fe09e43 100644 --- a/src/game/ant/trait/head.hpp +++ b/src/game/ant/phene/head.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_HEAD_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_HEAD_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_HEAD_HPP +#define ANTKEEPER_GAME_ANT_PHENE_HEAD_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant head description. + * Ant head phene. * * @see https://www.antwiki.org/wiki/Morphological_Measurements * @see https://antwiki.org/wiki/Phragmosis @@ -47,8 +47,8 @@ struct head float phragmosis; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_HEAD_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_HEAD_HPP diff --git a/src/game/ant/trait/larva.hpp b/src/game/ant/phene/larva.hpp similarity index 82% rename from src/game/ant/trait/larva.hpp rename to src/game/ant/phene/larva.hpp index c011d41..090dd59 100644 --- a/src/game/ant/trait/larva.hpp +++ b/src/game/ant/phene/larva.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_LARVA_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_LARVA_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_LARVA_HPP +#define ANTKEEPER_GAME_ANT_PHENE_LARVA_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant larva description. + * Ant larva phene. */ struct larva { @@ -35,11 +35,11 @@ struct larva render::model* model; /// Number of larval instars before pupation. - int instars; + int instar_count; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_LARVA_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_LARVA_HPP diff --git a/src/game/ant/trait/legs.hpp b/src/game/ant/phene/legs.hpp similarity index 85% rename from src/game/ant/trait/legs.hpp rename to src/game/ant/phene/legs.hpp index c8370bb..b94aa34 100644 --- a/src/game/ant/trait/legs.hpp +++ b/src/game/ant/phene/legs.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_LEGS_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_LEGS_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_LEGS_HPP +#define ANTKEEPER_GAME_ANT_PHENE_LEGS_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant legs description. + * Ant legs phene. * * @see https://www.antwiki.org/wiki/Morphological_Measurements */ @@ -43,8 +43,8 @@ struct legs float grip; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_LEGS_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_LEGS_HPP diff --git a/src/game/ant/trait/mandibles.hpp b/src/game/ant/phene/mandibles.hpp similarity index 87% rename from src/game/ant/trait/mandibles.hpp rename to src/game/ant/phene/mandibles.hpp index 2af2600..c60aadb 100644 --- a/src/game/ant/trait/mandibles.hpp +++ b/src/game/ant/phene/mandibles.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_MANDIBLES_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_MANDIBLES_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_MANDIBLES_HPP +#define ANTKEEPER_GAME_ANT_PHENE_MANDIBLES_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant mandibles description. + * Ant mandibles phene. * * @see https://www.antwiki.org/wiki/Character_States_for_Extant_Ant_Genera_of_the_Formicidae * @see https://www.antwiki.org/wiki/Morphological_and_Functional_Diversity_of_Ant_Mandibles @@ -48,8 +48,8 @@ struct mandibles int basal_dental_count; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_MANDIBLES_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_MANDIBLES_HPP diff --git a/src/game/ant/trait/mesosoma.hpp b/src/game/ant/phene/mesosoma.hpp similarity index 86% rename from src/game/ant/trait/mesosoma.hpp rename to src/game/ant/phene/mesosoma.hpp index 77efe14..7d4dc3f 100644 --- a/src/game/ant/trait/mesosoma.hpp +++ b/src/game/ant/phene/mesosoma.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_MESOSOMA_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_MESOSOMA_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_MESOSOMA_HPP +#define ANTKEEPER_GAME_ANT_PHENE_MESOSOMA_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant mesosoma description. + * Ant mesosoma phene. * * @see https://www.antwiki.org/wiki/Morphological_Measurements */ @@ -49,8 +49,8 @@ struct mesosoma float propodeum_spinescence; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_MESOSOMA_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_MESOSOMA_HPP diff --git a/src/game/ant/trait/nest-site.hpp b/src/game/ant/phene/nest-site.hpp similarity index 93% rename from src/game/ant/trait/nest-site.hpp rename to src/game/ant/phene/nest-site.hpp index 009fbd9..f1cd1b6 100644 --- a/src/game/ant/trait/nest-site.hpp +++ b/src/game/ant/phene/nest-site.hpp @@ -22,10 +22,10 @@ namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Colony nest site description. + * Colony nest site phene. */ enum class nest_site { @@ -33,7 +33,7 @@ enum class nest_site arboreal }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game diff --git a/src/game/ant/trait/ocelli.hpp b/src/game/ant/phene/ocelli.hpp similarity index 86% rename from src/game/ant/trait/ocelli.hpp rename to src/game/ant/phene/ocelli.hpp index 1f4d51f..ff13ec2 100644 --- a/src/game/ant/trait/ocelli.hpp +++ b/src/game/ant/phene/ocelli.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_OCELLI_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_OCELLI_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_OCELLI_HPP +#define ANTKEEPER_GAME_ANT_PHENE_OCELLI_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant ocelli description. + * Ant ocelli phene. */ struct ocelli { @@ -50,8 +50,8 @@ struct ocelli float height; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_OCELLI_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_OCELLI_HPP diff --git a/src/game/ant/trait/pigmentation.hpp b/src/game/ant/phene/pigmentation.hpp similarity index 81% rename from src/game/ant/trait/pigmentation.hpp rename to src/game/ant/phene/pigmentation.hpp index 374fe93..f95dd4a 100644 --- a/src/game/ant/trait/pigmentation.hpp +++ b/src/game/ant/phene/pigmentation.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_PIGMENTATION_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_PIGMENTATION_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_PIGMENTATION_HPP +#define ANTKEEPER_GAME_ANT_PHENE_PIGMENTATION_HPP #include "render/material.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant pigmentation description. + * Ant pigmentation phene. */ struct pigmentation { @@ -35,8 +35,8 @@ struct pigmentation render::material* material; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_PIGMENTATION_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_PIGMENTATION_HPP diff --git a/src/game/ant/trait/pilosity.hpp b/src/game/ant/phene/pilosity.hpp similarity index 81% rename from src/game/ant/trait/pilosity.hpp rename to src/game/ant/phene/pilosity.hpp index 8365b53..7aac5e6 100644 --- a/src/game/ant/trait/pilosity.hpp +++ b/src/game/ant/phene/pilosity.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_PILOSITY_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_PILOSITY_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_PILOSITY_HPP +#define ANTKEEPER_GAME_ANT_PHENE_PILOSITY_HPP namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant pilosity description. + * Ant pilosity phene. */ struct pilosity { @@ -33,8 +33,8 @@ struct pilosity float density; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_PILOSITY_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_PILOSITY_HPP diff --git a/src/game/ant/trait/sculpturing.hpp b/src/game/ant/phene/sculpturing.hpp similarity index 81% rename from src/game/ant/trait/sculpturing.hpp rename to src/game/ant/phene/sculpturing.hpp index c5b2102..66fee71 100644 --- a/src/game/ant/trait/sculpturing.hpp +++ b/src/game/ant/phene/sculpturing.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_SCULPTURING_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_SCULPTURING_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_SCULPTURING_HPP +#define ANTKEEPER_GAME_ANT_PHENE_SCULPTURING_HPP #include "gl/texture-2d.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant surface sculpturing description. + * Ant surface sculpturing phene. */ struct sculpturing { @@ -38,8 +38,8 @@ struct sculpturing gl::texture_2d* normal_map; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_SCULPTURING_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_SCULPTURING_HPP diff --git a/src/game/ant/trait/sting.hpp b/src/game/ant/phene/sting.hpp similarity index 86% rename from src/game/ant/trait/sting.hpp rename to src/game/ant/phene/sting.hpp index 9fec63f..cae720c 100644 --- a/src/game/ant/trait/sting.hpp +++ b/src/game/ant/phene/sting.hpp @@ -17,14 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_STING_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_STING_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_STING_HPP +#define ANTKEEPER_GAME_ANT_PHENE_STING_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** * Trait that describes the sting of an ant. @@ -38,8 +38,8 @@ struct sting render::model* model; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_STING_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_STING_HPP diff --git a/src/game/ant/trait/waist.hpp b/src/game/ant/phene/waist.hpp similarity index 91% rename from src/game/ant/trait/waist.hpp rename to src/game/ant/phene/waist.hpp index 3abce31..389c14d 100644 --- a/src/game/ant/trait/waist.hpp +++ b/src/game/ant/phene/waist.hpp @@ -17,14 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_WAIST_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_WAIST_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_WAIST_HPP +#define ANTKEEPER_GAME_ANT_PHENE_WAIST_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** * Trait that describes the waist (petiole plus postpetiole) of an ant. @@ -67,8 +67,8 @@ struct waist float postpetiole_spinescence; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_WAIST_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_WAIST_HPP diff --git a/src/game/ant/trait/wings.hpp b/src/game/ant/phene/wings.hpp similarity index 89% rename from src/game/ant/trait/wings.hpp rename to src/game/ant/phene/wings.hpp index 7879a20..c32e20a 100644 --- a/src/game/ant/trait/wings.hpp +++ b/src/game/ant/phene/wings.hpp @@ -17,17 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_TRAIT_WINGS_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_WINGS_HPP +#ifndef ANTKEEPER_GAME_ANT_PHENE_WINGS_HPP +#define ANTKEEPER_GAME_ANT_PHENE_WINGS_HPP #include "render/model.hpp" namespace game { namespace ant { -namespace trait { +namespace phene { /** - * Ant wings description. + * Ant wings phene. */ struct wings { @@ -59,8 +59,8 @@ struct wings float hindwing_venation; }; -} // namespace trait +} // namespace phene } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_TRAIT_WINGS_HPP +#endif // ANTKEEPER_GAME_ANT_PHENE_WINGS_HPP diff --git a/src/game/ant/phenome.cpp b/src/game/ant/phenome.cpp new file mode 100644 index 0000000..94386e9 --- /dev/null +++ b/src/game/ant/phenome.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "game/ant/phenome.hpp" + +namespace game { +namespace ant { + +phenome::phenome(const genome& genome, caste caste): + phenome() +{ + if (genome.antennae) + if (auto it = genome.antennae->phenes.find(caste); it != genome.antennae->phenes.end()) + antennae = &it->second; + if (genome.body_size) + if (auto it = genome.body_size->phenes.find(caste); it != genome.body_size->phenes.end()) + body_size = &it->second; + if (genome.cocoon) + cocoon = &genome.cocoon->phene; + if (genome.diet) + diet = &genome.diet->phene; + if (genome.egg) + egg = &genome.egg->phene; + if (genome.eyes) + if (auto it = genome.eyes->phenes.find(caste); it != genome.eyes->phenes.end()) + eyes = &it->second; + if (genome.foraging_time) + foraging_time = &genome.foraging_time->phene; + if (genome.founding_mode) + founding_mode = &genome.founding_mode->phene; + if (genome.gaster) + if (auto it = genome.gaster->phenes.find(caste); it != genome.gaster->phenes.end()) + gaster = &it->second; + if (genome.head) + if (auto it = genome.head->phenes.find(caste); it != genome.head->phenes.end()) + head = &it->second; + if (genome.larva) + larva = &genome.larva->phene; + if (genome.legs) + if (auto it = genome.legs->phenes.find(caste); it != genome.legs->phenes.end()) + legs = &it->second; + if (genome.mandibles) + if (auto it = genome.mandibles->phenes.find(caste); it != genome.mandibles->phenes.end()) + mandibles = &it->second; + if (genome.mesosoma) + if (auto it = genome.mesosoma->phenes.find(caste); it != genome.mesosoma->phenes.end()) + mesosoma = &it->second; + if (genome.nest_site) + nest_site = &genome.nest_site->phene; + if (genome.ocelli) + if (auto it = genome.ocelli->phenes.find(caste); it != genome.ocelli->phenes.end()) + ocelli = &it->second; + if (genome.pigmentation) + if (auto it = genome.pigmentation->phenes.find(caste); it != genome.pigmentation->phenes.end()) + pigmentation = &it->second; + if (genome.pilosity) + if (auto it = genome.pilosity->phenes.find(caste); it != genome.pilosity->phenes.end()) + pilosity = &it->second; + if (genome.sculpturing) + if (auto it = genome.sculpturing->phenes.find(caste); it != genome.sculpturing->phenes.end()) + sculpturing = &it->second; + if (genome.sting) + if (auto it = genome.sting->phenes.find(caste); it != genome.sting->phenes.end()) + sting = &it->second; + if (genome.waist) + if (auto it = genome.waist->phenes.find(caste); it != genome.waist->phenes.end()) + waist = &it->second; + if (genome.wings) + if (auto it = genome.wings->phenes.find(caste); it != genome.wings->phenes.end()) + wings = &it->second; +} + +phenome::phenome(): + antennae(nullptr), + body_size(nullptr), + cocoon(nullptr), + diet(nullptr), + egg(nullptr), + eyes(nullptr), + foraging_time(nullptr), + founding_mode(nullptr), + gaster(nullptr), + head(nullptr), + larva(nullptr), + legs(nullptr), + mandibles(nullptr), + mesosoma(nullptr), + nest_site(nullptr), + ocelli(nullptr), + pigmentation(nullptr), + pilosity(nullptr), + sculpturing(nullptr), + sting(nullptr), + waist(nullptr), + wings(nullptr) +{} + +} // namespace ant +} // namespace game diff --git a/src/game/ant/phenome.hpp b/src/game/ant/phenome.hpp new file mode 100644 index 0000000..27700a3 --- /dev/null +++ b/src/game/ant/phenome.hpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GAME_ANT_PHENOME_HPP +#define ANTKEEPER_GAME_ANT_PHENOME_HPP + +#include "game/ant/phene/antennae.hpp" +#include "game/ant/phene/body-size.hpp" +#include "game/ant/phene/cocoon.hpp" +#include "game/ant/phene/diet.hpp" +#include "game/ant/phene/egg.hpp" +#include "game/ant/phene/eyes.hpp" +#include "game/ant/phene/foraging-time.hpp" +#include "game/ant/phene/founding-mode.hpp" +#include "game/ant/phene/gaster.hpp" +#include "game/ant/phene/head.hpp" +#include "game/ant/phene/larva.hpp" +#include "game/ant/phene/legs.hpp" +#include "game/ant/phene/mandibles.hpp" +#include "game/ant/phene/mesosoma.hpp" +#include "game/ant/phene/nest-site.hpp" +#include "game/ant/phene/ocelli.hpp" +#include "game/ant/phene/pigmentation.hpp" +#include "game/ant/phene/pilosity.hpp" +#include "game/ant/phene/sculpturing.hpp" +#include "game/ant/phene/sting.hpp" +#include "game/ant/phene/waist.hpp" +#include "game/ant/phene/wings.hpp" +#include "game/ant/genome.hpp" +#include "game/ant/caste.hpp" + +namespace game { +namespace ant { + +/** + * Complete set of ant phenes. + */ +struct phenome +{ + /** + * Constructs a phenome for a given caste. + * + * @param genome Ant genome. + * @param caste Ant caste. + */ + phenome(const genome& genome, caste caste); + + /// Constructs an empty phenome. + phenome(); + + const phene::antennae* antennae; + const phene::body_size* body_size; + const phene::cocoon* cocoon; + const phene::diet* diet; + const phene::egg* egg; + const phene::eyes* eyes; + const phene::foraging_time* foraging_time; + const phene::founding_mode* founding_mode; + const phene::gaster* gaster; + const phene::head* head; + const phene::larva* larva; + const phene::legs* legs; + const phene::mandibles* mandibles; + const phene::mesosoma* mesosoma; + const phene::nest_site* nest_site; + const phene::ocelli* ocelli; + const phene::pigmentation* pigmentation; + const phene::pilosity* pilosity; + const phene::sculpturing* sculpturing; + const phene::sting* sting; + const phene::waist* waist; + const phene::wings* wings; +}; + +} // namespace ant +} // namespace game + +#endif // ANTKEEPER_GAME_ANT_PHENOME_HPP diff --git a/src/game/ant/species.hpp b/src/game/ant/species.hpp deleted file mode 100644 index 0ebcc1a..0000000 --- a/src/game/ant/species.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_GAME_ANT_SPECIES_HPP -#define ANTKEEPER_GAME_ANT_SPECIES_HPP - -#include "game/ant/caste.hpp" -#include "game/ant/trait/body-size.hpp" -#include "game/ant/trait/cocoon.hpp" -#include "game/ant/trait/diet.hpp" -#include "game/ant/trait/egg.hpp" -#include "game/ant/trait/foraging-time.hpp" -#include "game/ant/trait/larva.hpp" -#include "game/ant/trait/nest-site.hpp" -#include - -namespace game { -namespace ant { - -/** - * Ant species description. - */ -struct species -{ - /// Body size description. - const trait::body_size* body_size; - - /// Egg description. - const trait::egg* egg; - - /// Larva description. - const trait::larva* larva; - - /// Cocoon description. - const trait::cocoon* cocoon; - - /// Queen caste description. - std::optional queen_caste; - - /// Worker caste description. - std::optional worker_caste; - - /// Soldier caste description. - std::optional soldier_caste; - - /// Male caste description. - std::optional male_caste; - - /// Diet description. - const trait::diet* diet; - - /// Foraging time description. - const trait::foraging_time* foraging_time; - - /// Nest site description. - const trait::nest_site* nest_site; -}; - -} // namespace ant -} // namespace game - -#endif // ANTKEEPER_GAME_ANT_SPECIES_HPP diff --git a/src/game/ant/subcaste-type.hpp b/src/game/ant/subcaste.hpp similarity index 88% rename from src/game/ant/subcaste-type.hpp rename to src/game/ant/subcaste.hpp index 0c3f8fd..6a74765 100644 --- a/src/game/ant/subcaste-type.hpp +++ b/src/game/ant/subcaste.hpp @@ -17,14 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_GAME_ANT_SUBCASTE_TYPE_HPP -#define ANTKEEPER_GAME_ANT_SUBCASTE_TYPE_HPP +#ifndef ANTKEEPER_GAME_ANT_SUBCASTE_HPP +#define ANTKEEPER_GAME_ANT_SUBCASTE_HPP namespace game { namespace ant { /** - * Ant subcaste type enumerations. + * Ant subcaste enumerations. */ enum class subcaste { @@ -56,4 +56,4 @@ enum class subcaste } // namespace ant } // namespace game -#endif // ANTKEEPER_GAME_ANT_SUBCASTE_TYPE_HPP +#endif // ANTKEEPER_GAME_ANT_SUBCASTE_HPP diff --git a/src/game/ant/trait/loader/body-size-loader.cpp b/src/game/ant/trait/loader/body-size-loader.cpp deleted file mode 100644 index 6cdb5c0..0000000 --- a/src/game/ant/trait/loader/body-size-loader.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/body-size.hpp" -#include - -using namespace game::ant; - -template <> -trait::body_size* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto body_size_element = data->find("body_size"); - if (body_size_element == data->end()) - throw std::runtime_error("Invalid body size trait."); - - // Allocate and init body size trait - trait::body_size* body_size = new trait::body_size(); - body_size->mesosoma_length = 1.0f; - - // Parse mesosoma length - if (auto element = body_size_element->find("mesosoma_length"); element != body_size_element->end()) - body_size->mesosoma_length = element->get(); - - // Free JSON data - delete data; - - return body_size; -} diff --git a/src/game/ant/trait/loader/eyes-loader.cpp b/src/game/ant/trait/loader/eyes-loader.cpp deleted file mode 100644 index d89f0f1..0000000 --- a/src/game/ant/trait/loader/eyes-loader.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/eyes.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::eyes* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto eyes_element = data->find("eyes"); - if (eyes_element == data->end()) - throw std::runtime_error("Invalid eyes trait."); - - // Allocate and init eyes trait - trait::eyes* eyes = new trait::eyes(); - eyes->present = false; - eyes->model = nullptr; - eyes->length = 0.0f; - eyes->width = 0.0f; - eyes->height = 0.0f; - eyes->ommatidia_count = 0; - - // Parse eyes present - if (auto present_element = eyes_element->find("present"); present_element != eyes_element->end()) - eyes->present = present_element->get(); - - if (eyes->present) - { - // Load eyes model - auto model_element = eyes_element->find("model"); - if (model_element == eyes_element->end()) - throw std::runtime_error("Eyes trait doesn't specify eyes model."); - eyes->model = resource_manager->load(model_element->get()); - - // Parse length - if (auto element = eyes_element->find("length"); element != eyes_element->end()) - eyes->length = element->get(); - - // Parse width - if (auto element = eyes_element->find("width"); element != eyes_element->end()) - eyes->width = element->get(); - - // Parse height - if (auto element = eyes_element->find("height"); element != eyes_element->end()) - eyes->height = element->get(); - - // Parse ommatidia count - if (auto element = eyes_element->find("ommatidia_count"); element != eyes_element->end()) - eyes->ommatidia_count = element->get(); - } - - // Free JSON data - delete data; - - return eyes; -} diff --git a/src/game/ant/trait/loader/mandibles-loader.cpp b/src/game/ant/trait/loader/mandibles-loader.cpp deleted file mode 100644 index cecf43b..0000000 --- a/src/game/ant/trait/loader/mandibles-loader.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/mandibles.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::mandibles* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto mandibles_element = data->find("mandibles"); - if (mandibles_element == data->end()) - throw std::runtime_error("Invalid mandibles trait."); - - // Allocate and init mandibles trait - trait::mandibles* mandibles = new trait::mandibles(); - mandibles->model = nullptr; - mandibles->length = 0.0f; - mandibles->apical_dental_count = 0; - mandibles->basal_dental_count = 0; - - // Load model - auto model_element = mandibles_element->find("model"); - if (model_element == mandibles_element->end()) - throw std::runtime_error("Mandibles trait doesn't specify mandibles model."); - mandibles->model = resource_manager->load(model_element->get()); - - // Parse length - if (auto element = mandibles_element->find("length"); element != mandibles_element->end()) - mandibles->length = element->get(); - - // Parse apical dental count - if (auto element = mandibles_element->find("apical_dental_count"); element != mandibles_element->end()) - mandibles->apical_dental_count = element->get(); - - // Parse basal dental count - if (auto element = mandibles_element->find("basal_dental_count"); element != mandibles_element->end()) - mandibles->basal_dental_count = element->get(); - - // Free JSON data - delete data; - - return mandibles; -} diff --git a/src/game/ant/trait/loader/mesosoma-loader.cpp b/src/game/ant/trait/loader/mesosoma-loader.cpp deleted file mode 100644 index c4a7fba..0000000 --- a/src/game/ant/trait/loader/mesosoma-loader.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/mesosoma.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::mesosoma* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto mesosoma_element = data->find("mesosoma"); - if (mesosoma_element == data->end()) - throw std::runtime_error("Invalid mesosoma trait."); - - // Allocate and init mesosoma trait - trait::mesosoma* mesosoma = new trait::mesosoma(); - mesosoma->model = nullptr; - mesosoma->pronotum_width = 0.0f; - mesosoma->pronotum_spinescence = 0.0f; - mesosoma->mesonotum_spinescence = 0.0f; - mesosoma->propodeum_spinescence = 0.0f; - - // Load mesosoma model - auto model_element = mesosoma_element->find("model"); - if (model_element == mesosoma_element->end()) - throw std::runtime_error("Mesosoma trait doesn't specify mesosoma model."); - mesosoma->model = resource_manager->load(model_element->get()); - - // Parse pronotum width - if (auto element = mesosoma_element->find("pronotum_width"); element != mesosoma_element->end()) - mesosoma->pronotum_width = element->get(); - - // Parse pronotum spinescence - if (auto element = mesosoma_element->find("pronotum_spinescence"); element != mesosoma_element->end()) - mesosoma->pronotum_spinescence = element->get(); - - // Parse mesonotum spinescence - if (auto element = mesosoma_element->find("mesonotum_spinescence"); element != mesosoma_element->end()) - mesosoma->mesonotum_spinescence = element->get(); - - // Parse propodeum spinescence - if (auto element = mesosoma_element->find("propodeum_spinescence"); element != mesosoma_element->end()) - mesosoma->propodeum_spinescence = element->get(); - - // Free JSON data - delete data; - - return mesosoma; -} diff --git a/src/game/ant/trait/loader/ocelli-loader.cpp b/src/game/ant/trait/loader/ocelli-loader.cpp deleted file mode 100644 index 6b1b96d..0000000 --- a/src/game/ant/trait/loader/ocelli-loader.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/ocelli.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::ocelli* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto ocelli_element = data->find("ocelli"); - if (ocelli_element == data->end()) - throw std::runtime_error("Invalid ocelli trait."); - - // Allocate and init ocelli trait - trait::ocelli* ocelli = new trait::ocelli(); - ocelli->lateral_ocelli_model = nullptr; - ocelli->median_ocellus_model = nullptr; - ocelli->lateral_ocelli_present = false; - ocelli->median_ocellus_present = false; - ocelli->width = 0.0f; - ocelli->height = 0.0f; - - // Parse lateral ocelli present - if (auto element = ocelli_element->find("lateral_ocelli_present"); element != ocelli_element->end()) - ocelli->lateral_ocelli_present = element->get(); - - // Parse median ocellus present - if (auto element = ocelli_element->find("median_ocellus_present"); element != ocelli_element->end()) - ocelli->median_ocellus_present = element->get(); - - // Parse width - if (auto element = ocelli_element->find("width"); element != ocelli_element->end()) - ocelli->width = element->get(); - - // Parse height - if (auto element = ocelli_element->find("height"); element != ocelli_element->end()) - ocelli->height = element->get(); - - // Load lateral ocelli model, if present - if (ocelli->lateral_ocelli_present) - { - auto lateral_ocelli_model_element = ocelli_element->find("lateral_ocelli_model"); - if (lateral_ocelli_model_element == ocelli_element->end() || lateral_ocelli_model_element->is_null()) - throw std::runtime_error("Ocelli trait doesn't specify lateral ocelli model."); - - ocelli->lateral_ocelli_model = resource_manager->load(lateral_ocelli_model_element->get()); - } - - // Load median ocellus model, if present - if (ocelli->median_ocellus_present) - { - auto median_ocellus_model_element = ocelli_element->find("median_ocellus_model"); - if (median_ocellus_model_element == ocelli_element->end() || median_ocellus_model_element->is_null()) - throw std::runtime_error("Ocelli trait doesn't specify median ocellus model."); - - ocelli->median_ocellus_model = resource_manager->load(median_ocellus_model_element->get()); - } - - // Free JSON data - delete data; - - return ocelli; -} diff --git a/src/game/ant/trait/loader/waist-loader.cpp b/src/game/ant/trait/loader/waist-loader.cpp deleted file mode 100644 index 8f00d58..0000000 --- a/src/game/ant/trait/loader/waist-loader.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/waist.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::waist* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto waist_element = data->find("waist"); - if (waist_element == data->end()) - throw std::runtime_error("Invalid waist trait."); - - // Allocate and init waist trait - trait::waist* waist = new trait::waist(); - waist->model = nullptr; - waist->petiole_present = false; - waist->petiole_length = 0.0f; - waist->petiole_width = 0.0f; - waist->petiole_height = 0.0f; - waist->petiole_spinescence = 0.0f; - waist->postpetiole_present = false; - waist->postpetiole_length = 0.0f; - waist->postpetiole_width = 0.0f; - waist->postpetiole_height = 0.0f; - waist->postpetiole_spinescence = 0.0f; - - // Parse petiole present - if (auto element = waist_element->find("petiole_present"); element != waist_element->end()) - waist->petiole_present = element->get(); - - if (waist->petiole_present) - { - // Parse petiole properties - if (auto element = waist_element->find("petiole_length"); element != waist_element->end()) - waist->petiole_length = element->get(); - if (auto element = waist_element->find("petiole_width"); element != waist_element->end()) - waist->petiole_width = element->get(); - if (auto element = waist_element->find("petiole_height"); element != waist_element->end()) - waist->petiole_height = element->get(); - if (auto element = waist_element->find("petiole_spinescence"); element != waist_element->end()) - waist->petiole_spinescence = element->get(); - - // Parse postpetiole present - if (auto element = waist_element->find("postpetiole_present"); element != waist_element->end()) - waist->postpetiole_present = element->get(); - - if (waist->postpetiole_present) - { - // Parse postpetiole properties - if (auto element = waist_element->find("postpetiole_length"); element != waist_element->end()) - waist->postpetiole_length = element->get(); - if (auto element = waist_element->find("postpetiole_width"); element != waist_element->end()) - waist->postpetiole_width = element->get(); - if (auto element = waist_element->find("postpetiole_height"); element != waist_element->end()) - waist->postpetiole_height = element->get(); - if (auto element = waist_element->find("postpetiole_spinescence"); element != waist_element->end()) - waist->postpetiole_spinescence = element->get(); - } - - // Load waist model - auto model_element = waist_element->find("model"); - if (model_element == waist_element->end()) - throw std::runtime_error("Waist trait doesn't specify waist model."); - waist->model = resource_manager->load(model_element->get()); - } - - // Free JSON data - delete data; - - return waist; -} diff --git a/src/game/ant/trait/loader/wings-loader.cpp b/src/game/ant/trait/loader/wings-loader.cpp deleted file mode 100644 index 1b3f1b0..0000000 --- a/src/game/ant/trait/loader/wings-loader.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#include "resources/resource-loader.hpp" -#include "resources/resource-manager.hpp" -#include "resources/json.hpp" -#include "game/ant/trait/wings.hpp" -#include "render/model.hpp" -#include - -using namespace game::ant; - -template <> -trait::wings* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) -{ - // Load JSON data - json* data = resource_loader::load(resource_manager, file, path); - - // Validate trait file - auto wings_element = data->find("wings"); - if (wings_element == data->end()) - throw std::runtime_error("Invalid wings trait."); - - // Allocate and init wings trait - trait::wings* wings = new trait::wings(); - wings->forewings_model = nullptr; - wings->hindwings_model = nullptr; - wings->present = false; - wings->forewing_length = 0.0f; - wings->forewing_width = 0.0f; - wings->forewing_venation = 0.0f; - wings->hindwing_length = 0.0f; - wings->hindwing_width = 0.0f; - wings->hindwing_venation = 0.0f; - - // Parse wings present - if (auto present_element = wings_element->find("present"); present_element != wings_element->end()) - wings->present = present_element->get(); - - if (wings->present) - { - // Load forewings model - auto forewings_model_element = wings_element->find("forewings_model"); - if (forewings_model_element == wings_element->end()) - throw std::runtime_error("Wings trait doesn't specify forewings model."); - wings->forewings_model = resource_manager->load(forewings_model_element->get()); - - // Load hindwings model - auto hindwings_model_element = wings_element->find("hindwings_model"); - if (hindwings_model_element == wings_element->end()) - throw std::runtime_error("Wings trait doesn't specify hindwings model."); - wings->hindwings_model = resource_manager->load(hindwings_model_element->get()); - - // Parse forewing length - if (auto element = wings_element->find("forewing_length"); element != wings_element->end()) - wings->forewing_length = element->get(); - - // Parse forewing width - if (auto element = wings_element->find("forewing_width"); element != wings_element->end()) - wings->forewing_width = element->get(); - - // Parse forewing venation - if (auto element = wings_element->find("forewing_venation"); element != wings_element->end()) - wings->forewing_venation = element->get(); - - // Parse hindwing length - if (auto element = wings_element->find("hindwing_length"); element != wings_element->end()) - wings->hindwing_length = element->get(); - - // Parse hindwing width - if (auto element = wings_element->find("hindwing_width"); element != wings_element->end()) - wings->hindwing_width = element->get(); - - // Parse hindwing venation - if (auto element = wings_element->find("hindwing_venation"); element != wings_element->end()) - wings->hindwing_venation = element->get(); - } - - // Free JSON data - delete data; - - return wings; -} diff --git a/src/game/ant/trait/size-variation.hpp b/src/game/ant/trait/size-variation.hpp deleted file mode 100644 index 21bc2a6..0000000 --- a/src/game/ant/trait/size-variation.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2021 Christopher J. Howard - * - * This file is part of Antkeeper source code. - * - * Antkeeper source code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper source code. If not, see . - */ - -#ifndef ANTKEEPER_GAME_ANT_TRAIT_SIZE_VARIATION_HPP -#define ANTKEEPER_GAME_ANT_TRAIT_SIZE_VARIATION_HPP - -namespace game { -namespace ant { -namespace trait { - -/** - * Caste size variation description. - */ -struct size_variation -{ - /// Minimum size factor. - float min_size; - - /// Maximum size factor. - float max_size; - - /// Mean size factor. - float mean_size; -}; - -} // namespace trait -} // namespace ant -} // namespace game - -#endif // ANTKEEPER_GAME_ANT_TRAIT_SIZE_VARIATION_HPP diff --git a/src/game/load.cpp b/src/game/load.cpp index 052f90a..ce17205 100644 --- a/src/game/load.cpp +++ b/src/game/load.cpp @@ -29,7 +29,6 @@ #include "render/passes/ground-pass.hpp" #include "game/system/astronomy.hpp" #include "game/system/terrain.hpp" -#include "math/random.hpp" #include "math/noise/noise.hpp" #include "math/hash/hash.hpp" #include diff --git a/src/game/state/nest-selection.cpp b/src/game/state/nest-selection.cpp index 7c4163e..b76c52c 100644 --- a/src/game/state/nest-selection.cpp +++ b/src/game/state/nest-selection.cpp @@ -54,7 +54,8 @@ #include #include "game/ant/morphogenesis.hpp" -#include "game/ant/species.hpp" +#include "game/ant/phenome.hpp" +#include "game/ant/genome.hpp" using namespace game::ant; @@ -67,31 +68,30 @@ nest_selection::nest_selection(game::context& ctx): ctx.logger->push_task("Entering nest selection state"); - ctx.logger->push_task("Loading worker caste"); - - ant::species species; - ant::caste& worker_caste = *species.worker_caste; - worker_caste.type = ant::caste_type::worker; - - worker_caste.antennae = ctx.resource_manager->load("pogonomyrmex-female-antennae.dna"); - worker_caste.eyes = ctx.resource_manager->load("pogonomyrmex-eyes.dna"); - worker_caste.gaster = ctx.resource_manager->load("pogonomyrmex-worker-gaster.dna"); - worker_caste.head = ctx.resource_manager->load("pogonomyrmex-head.dna"); - worker_caste.legs = ctx.resource_manager->load("pogonomyrmex-legs.dna"); - worker_caste.mandibles = ctx.resource_manager->load("pogonomyrmex-mandibles.dna"); - worker_caste.mesosoma = ctx.resource_manager->load("pogonomyrmex-worker-mesosoma.dna"); - worker_caste.ocelli = ctx.resource_manager->load("ocelli-absent.dna"); - worker_caste.pigmentation = ctx.resource_manager->load("rust-pigmentation.dna"); - worker_caste.sculpturing = ctx.resource_manager->load("politus-sculpturing.dna"); - //worker_caste.size_variation = ctx.resource_manager->load(...); - worker_caste.sting = ctx.resource_manager->load("pogonomyrmex-sting.dna"); - worker_caste.waist = ctx.resource_manager->load("pogonomyrmex-waist.dna"); - worker_caste.wings = ctx.resource_manager->load("wings-absent.dna"); - - render::model* worker_model = ant::morphogenesis(worker_caste); + ctx.logger->push_task("Loading genome"); + ant::genome genome; + genome.antennae = ctx.resource_manager->load("pogonomyrmex-antennae.dna"); + genome.eyes = ctx.resource_manager->load("pogonomyrmex-eyes.dna"); + genome.gaster = ctx.resource_manager->load("pogonomyrmex-gaster.dna"); + genome.head = ctx.resource_manager->load("pogonomyrmex-head.dna"); + genome.legs = ctx.resource_manager->load("pogonomyrmex-legs.dna"); + genome.mandibles = ctx.resource_manager->load("pogonomyrmex-mandibles.dna"); + genome.mesosoma = ctx.resource_manager->load("pogonomyrmex-mesosoma.dna"); + genome.ocelli = ctx.resource_manager->load("ocelli-absent.dna"); + genome.pigmentation = ctx.resource_manager->load("rust-pigmentation.dna"); + genome.sculpturing = ctx.resource_manager->load("politus-sculpturing.dna"); + genome.sting = ctx.resource_manager->load("pogonomyrmex-sting.dna"); + genome.waist = ctx.resource_manager->load("pogonomyrmex-waist.dna"); + genome.wings = ctx.resource_manager->load("wings-absent.dna"); + ctx.logger->pop_task(EXIT_SUCCESS); + ctx.logger->push_task("Building worker phenome"); + ant::phenome worker_phenome = ant::phenome(genome, ant::caste::worker); ctx.logger->pop_task(EXIT_SUCCESS); + ctx.logger->push_task("Generating worker model"); + render::model* worker_model = ant::morphogenesis(worker_phenome); + ctx.logger->pop_task(EXIT_SUCCESS); // Create worker entity(s) entity::id worker_eid = ctx.entity_registry->create(); diff --git a/src/math/math.hpp b/src/math/math.hpp index 635231f..0494374 100644 --- a/src/math/math.hpp +++ b/src/math/math.hpp @@ -36,7 +36,6 @@ namespace math {} #include "math/constants.hpp" #include "math/quadrature.hpp" #include "math/interpolation.hpp" -#include "math/random.hpp" #include "math/map.hpp" #include "math/projection.hpp"