@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_ANT_CLADOGENESIS_HPP | |||||
#define ANTKEEPER_GAME_ANT_CLADOGENESIS_HPP | |||||
#include "game/ant/genome.hpp" | |||||
#include "game/ant/gene-pool.hpp" | |||||
#include <random> | |||||
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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_HPP | |||||
#define ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_HPP | |||||
#include <random> | |||||
#include <vector> | |||||
namespace game { | |||||
namespace ant { | |||||
/** | |||||
* Gene frequency table. | |||||
* | |||||
* @tparam T Gene type. | |||||
*/ | |||||
template <class T> | |||||
struct gene_frequency_table | |||||
{ | |||||
/// Gene array. | |||||
std::vector<const T*> genes; | |||||
/// Gene discrete probability distribution. | |||||
std::discrete_distribution<std::size_t> 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 <class Generator> | |||||
const T* sample(Generator& g) | |||||
{ | |||||
return genes[distribution(g)]; | |||||
} | |||||
}; | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_FREQUENCY_TABLE_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<gene::antennae> antennae; | |||||
gene_frequency_table<gene::body_size> body_size; | |||||
gene_frequency_table<gene::cocoon> cocoon; | |||||
gene_frequency_table<gene::diet> diet; | |||||
gene_frequency_table<gene::egg> egg; | |||||
gene_frequency_table<gene::eyes> eyes; | |||||
gene_frequency_table<gene::foraging_time> foraging_time; | |||||
gene_frequency_table<gene::founding_mode> founding_mode; | |||||
gene_frequency_table<gene::gaster> gaster; | |||||
gene_frequency_table<gene::head> head; | |||||
gene_frequency_table<gene::larva> larva; | |||||
gene_frequency_table<gene::legs> legs; | |||||
gene_frequency_table<gene::mandibles> mandibles; | |||||
gene_frequency_table<gene::mesosoma> mesosoma; | |||||
gene_frequency_table<gene::nest_site> nest_site; | |||||
gene_frequency_table<gene::ocelli> ocelli; | |||||
gene_frequency_table<gene::pigmentation> pigmentation; | |||||
gene_frequency_table<gene::pilosity> pilosity; | |||||
gene_frequency_table<gene::sculpturing> sculpturing; | |||||
gene_frequency_table<gene::sting> sting; | |||||
gene_frequency_table<gene::waist> waist; | |||||
gene_frequency_table<gene::wings> wings; | |||||
}; | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_POOL_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::antennae> antennae; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::body_size> body_size; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::diet> diet; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::egg> egg; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::eyes> eyes; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::foraging_time> foraging_time; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::founding_mode> founding_mode; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::gaster> gaster; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::head> head; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::larva> larva; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::legs> legs; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_LEGS_HPP |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<float>(); | |||||
// Parse max mesosoma length | |||||
if (auto element = phene_element.find("max_mesosoma_length"); element != phene_element.end()) | |||||
phene.max_mesosoma_length = element->get<float>(); | |||||
// Parse mean mesosoma length | |||||
if (auto element = phene_element.find("mean_mesosoma_length"); element != phene_element.end()) | |||||
phene.mean_mesosoma_length = element->get<float>(); | |||||
} | |||||
template <> | |||||
gene::body_size* resource_loader<gene::body_size>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<bool>(); | |||||
if (phene.present) | |||||
{ | |||||
// Load eyes model | |||||
if (auto element = phene_element.find("model"); element != phene_element.end()) | |||||
phene.model = resource_manager->load<render::model>(element->get<std::string>()); | |||||
// Parse length | |||||
if (auto element = phene_element.find("length"); element != phene_element.end()) | |||||
phene.length = element->get<float>(); | |||||
// Parse width | |||||
if (auto element = phene_element.find("width"); element != phene_element.end()) | |||||
phene.width = element->get<float>(); | |||||
// Parse height | |||||
if (auto element = phene_element.find("height"); element != phene_element.end()) | |||||
phene.height = element->get<float>(); | |||||
// Parse ommatidia count | |||||
if (auto element = phene_element.find("ommatidia_count"); element != phene_element.end()) | |||||
phene.ommatidia_count = element->get<int>(); | |||||
} | |||||
} | |||||
template <> | |||||
gene::eyes* resource_loader<gene::eyes>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <class T> | |||||
void deserialize_gene(monophenic_gene<T>& 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<std::string>(); | |||||
// Deserialize phene | |||||
if (auto element = gene_element.find("phene"); element != gene_element.end()) | |||||
deserialize_phene(gene.phene, *element, resource_manager); | |||||
} | |||||
template <class T> | |||||
void deserialize_gene(polyphenic_gene<T>& 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<std::string>(); | |||||
// 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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<render::model>(element->get<std::string>()); | |||||
// Parse length | |||||
if (auto element = phene_element.find("length"); element != phene_element.end()) | |||||
phene.length = element->get<float>(); | |||||
// Parse apical dental count count | |||||
if (auto element = phene_element.find("apical_dental_count"); element != phene_element.end()) | |||||
phene.apical_dental_count = element->get<int>(); | |||||
// Parse basal dental count count | |||||
if (auto element = phene_element.find("basal_dental_count"); element != phene_element.end()) | |||||
phene.basal_dental_count = element->get<int>(); | |||||
} | |||||
template <> | |||||
gene::mandibles* resource_loader<gene::mandibles>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<render::model>(element->get<std::string>()); | |||||
// Parse pronotum width | |||||
if (auto element = phene_element.find("pronotum_width"); element != phene_element.end()) | |||||
phene.pronotum_width = element->get<float>(); | |||||
// Parse pronotum spinescence | |||||
if (auto element = phene_element.find("pronotum_spinescence"); element != phene_element.end()) | |||||
phene.pronotum_spinescence = element->get<float>(); | |||||
// Parse mesonotum spinescence | |||||
if (auto element = phene_element.find("mesonotum_spinescence"); element != phene_element.end()) | |||||
phene.mesonotum_spinescence = element->get<float>(); | |||||
// Parse propodeum spinescence | |||||
if (auto element = phene_element.find("propodeum_spinescence"); element != phene_element.end()) | |||||
phene.propodeum_spinescence = element->get<float>(); | |||||
} | |||||
template <> | |||||
gene::mesosoma* resource_loader<gene::mesosoma>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<bool>(); | |||||
// Parse median ocelli present | |||||
if (auto element = phene_element.find("median_ocellus_present"); element != phene_element.end()) | |||||
phene.median_ocellus_present = element->get<bool>(); | |||||
// Parse width | |||||
if (auto element = phene_element.find("width"); element != phene_element.end()) | |||||
phene.width = element->get<float>(); | |||||
// Parse height | |||||
if (auto element = phene_element.find("height"); element != phene_element.end()) | |||||
phene.height = element->get<float>(); | |||||
// 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<render::model>(element->get<std::string>()); | |||||
} | |||||
// 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<render::model>(element->get<std::string>()); | |||||
} | |||||
} | |||||
template <> | |||||
gene::ocelli* resource_loader<gene::ocelli>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<render::model>(element->get<std::string>()); | |||||
// Parse petiole present | |||||
if (auto element = phene_element.find("petiole_present"); element != phene_element.end()) | |||||
phene.petiole_present = element->get<bool>(); | |||||
// Parse postpetiole present | |||||
if (auto element = phene_element.find("postpetiole_present"); element != phene_element.end()) | |||||
phene.postpetiole_present = element->get<bool>(); | |||||
if (phene.petiole_present) | |||||
{ | |||||
// Parse petiole length | |||||
if (auto element = phene_element.find("petiole_length"); element != phene_element.end()) | |||||
phene.petiole_length = element->get<float>(); | |||||
// Parse petiole width | |||||
if (auto element = phene_element.find("petiole_width"); element != phene_element.end()) | |||||
phene.petiole_width = element->get<float>(); | |||||
// Parse petiole height | |||||
if (auto element = phene_element.find("petiole_height"); element != phene_element.end()) | |||||
phene.petiole_height = element->get<float>(); | |||||
// Parse petiole spinescence | |||||
if (auto element = phene_element.find("petiole_spinescence"); element != phene_element.end()) | |||||
phene.petiole_spinescence = element->get<float>(); | |||||
} | |||||
if (phene.postpetiole_present) | |||||
{ | |||||
// Parse postpetiole length | |||||
if (auto element = phene_element.find("postpetiole_length"); element != phene_element.end()) | |||||
phene.postpetiole_length = element->get<float>(); | |||||
// Parse postpetiole width | |||||
if (auto element = phene_element.find("postpetiole_width"); element != phene_element.end()) | |||||
phene.postpetiole_width = element->get<float>(); | |||||
// Parse postpetiole height | |||||
if (auto element = phene_element.find("postpetiole_height"); element != phene_element.end()) | |||||
phene.postpetiole_height = element->get<float>(); | |||||
// Parse postpetiole spinescence | |||||
if (auto element = phene_element.find("postpetiole_spinescence"); element != phene_element.end()) | |||||
phene.postpetiole_spinescence = element->get<float>(); | |||||
} | |||||
} | |||||
template <> | |||||
gene::waist* resource_loader<gene::waist>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
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<bool>(); | |||||
if (phene.present) | |||||
{ | |||||
// Load forewings model | |||||
if (auto element = phene_element.find("forewings_model"); element != phene_element.end()) | |||||
phene.forewings_model = resource_manager->load<render::model>(element->get<std::string>()); | |||||
// Load hindwings model | |||||
if (auto element = phene_element.find("hindwings_model"); element != phene_element.end()) | |||||
phene.hindwings_model = resource_manager->load<render::model>(element->get<std::string>()); | |||||
// Parse forewing length | |||||
if (auto element = phene_element.find("forewing_length"); element != phene_element.end()) | |||||
phene.forewing_length = element->get<float>(); | |||||
// Parse forewing width | |||||
if (auto element = phene_element.find("forewing_width"); element != phene_element.end()) | |||||
phene.forewing_width = element->get<float>(); | |||||
// Parse forewing venation | |||||
if (auto element = phene_element.find("forewing_venation"); element != phene_element.end()) | |||||
phene.forewing_venation = element->get<float>(); | |||||
// Parse hindwing length | |||||
if (auto element = phene_element.find("hindwing_length"); element != phene_element.end()) | |||||
phene.hindwing_length = element->get<float>(); | |||||
// Parse hindwing width | |||||
if (auto element = phene_element.find("hindwing_width"); element != phene_element.end()) | |||||
phene.hindwing_width = element->get<float>(); | |||||
// Parse hindwing venation | |||||
if (auto element = phene_element.find("hindwing_venation"); element != phene_element.end()) | |||||
phene.hindwing_venation = element->get<float>(); | |||||
} | |||||
} | |||||
template <> | |||||
gene::wings* resource_loader<gene::wings>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::mandibles> mandibles; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::mesosoma> mesosoma; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::nest_site> nest_site; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::ocelli> ocelli; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::pigmentation> pigmentation; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::pilosity> pilosity; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_PILOSITY_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_HPP | |||||
#define ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_HPP | |||||
#include "game/ant/caste.hpp" | |||||
#include <string> | |||||
#include <unordered_map> | |||||
namespace game { | |||||
namespace ant { | |||||
namespace gene { | |||||
/** | |||||
* Gene with caste-specific phenes. | |||||
* | |||||
* @tparam T Phene type. | |||||
* | |||||
* @see https://en.wikipedia.org/wiki/Polyphenism | |||||
*/ | |||||
template <class T> | |||||
struct polyphenic_gene | |||||
{ | |||||
/// Gene name. | |||||
std::string name; | |||||
/// Caste-specific phene definitions. | |||||
std::unordered_map<caste, T> phenes; | |||||
}; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_POLYPHENIC_GENE_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::sculpturing> sculpturing; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::sting> sting; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::waist> waist; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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<phene::wings> wings; | |||||
} // namespace gene | |||||
} // namespace ant | |||||
} // namespace game | |||||
#endif // ANTKEEPER_GAME_ANT_GENE_WINGS_HPP |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <optional> | |||||
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<caste> queen_caste; | |||||
/// Worker caste description. | |||||
std::optional<caste> worker_caste; | |||||
/// Soldier caste description. | |||||
std::optional<caste> soldier_caste; | |||||
/// Male caste description. | |||||
std::optional<caste> 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 |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "resources/resource-loader.hpp" | |||||
#include "resources/resource-manager.hpp" | |||||
#include "resources/json.hpp" | |||||
#include "game/ant/trait/body-size.hpp" | |||||
#include <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::body_size* resource_loader<trait::body_size>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<float>(); | |||||
// Free JSON data | |||||
delete data; | |||||
return body_size; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::eyes* resource_loader<trait::eyes>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<bool>(); | |||||
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<render::model>(model_element->get<std::string>()); | |||||
// Parse length | |||||
if (auto element = eyes_element->find("length"); element != eyes_element->end()) | |||||
eyes->length = element->get<float>(); | |||||
// Parse width | |||||
if (auto element = eyes_element->find("width"); element != eyes_element->end()) | |||||
eyes->width = element->get<float>(); | |||||
// Parse height | |||||
if (auto element = eyes_element->find("height"); element != eyes_element->end()) | |||||
eyes->height = element->get<float>(); | |||||
// Parse ommatidia count | |||||
if (auto element = eyes_element->find("ommatidia_count"); element != eyes_element->end()) | |||||
eyes->ommatidia_count = element->get<int>(); | |||||
} | |||||
// Free JSON data | |||||
delete data; | |||||
return eyes; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::mandibles* resource_loader<trait::mandibles>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<render::model>(model_element->get<std::string>()); | |||||
// Parse length | |||||
if (auto element = mandibles_element->find("length"); element != mandibles_element->end()) | |||||
mandibles->length = element->get<float>(); | |||||
// Parse apical dental count | |||||
if (auto element = mandibles_element->find("apical_dental_count"); element != mandibles_element->end()) | |||||
mandibles->apical_dental_count = element->get<int>(); | |||||
// Parse basal dental count | |||||
if (auto element = mandibles_element->find("basal_dental_count"); element != mandibles_element->end()) | |||||
mandibles->basal_dental_count = element->get<int>(); | |||||
// Free JSON data | |||||
delete data; | |||||
return mandibles; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::mesosoma* resource_loader<trait::mesosoma>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<render::model>(model_element->get<std::string>()); | |||||
// Parse pronotum width | |||||
if (auto element = mesosoma_element->find("pronotum_width"); element != mesosoma_element->end()) | |||||
mesosoma->pronotum_width = element->get<float>(); | |||||
// Parse pronotum spinescence | |||||
if (auto element = mesosoma_element->find("pronotum_spinescence"); element != mesosoma_element->end()) | |||||
mesosoma->pronotum_spinescence = element->get<float>(); | |||||
// Parse mesonotum spinescence | |||||
if (auto element = mesosoma_element->find("mesonotum_spinescence"); element != mesosoma_element->end()) | |||||
mesosoma->mesonotum_spinescence = element->get<float>(); | |||||
// Parse propodeum spinescence | |||||
if (auto element = mesosoma_element->find("propodeum_spinescence"); element != mesosoma_element->end()) | |||||
mesosoma->propodeum_spinescence = element->get<float>(); | |||||
// Free JSON data | |||||
delete data; | |||||
return mesosoma; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::ocelli* resource_loader<trait::ocelli>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<bool>(); | |||||
// Parse median ocellus present | |||||
if (auto element = ocelli_element->find("median_ocellus_present"); element != ocelli_element->end()) | |||||
ocelli->median_ocellus_present = element->get<bool>(); | |||||
// Parse width | |||||
if (auto element = ocelli_element->find("width"); element != ocelli_element->end()) | |||||
ocelli->width = element->get<float>(); | |||||
// Parse height | |||||
if (auto element = ocelli_element->find("height"); element != ocelli_element->end()) | |||||
ocelli->height = element->get<float>(); | |||||
// 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<render::model>(lateral_ocelli_model_element->get<std::string>()); | |||||
} | |||||
// 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<render::model>(median_ocellus_model_element->get<std::string>()); | |||||
} | |||||
// Free JSON data | |||||
delete data; | |||||
return ocelli; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::waist* resource_loader<trait::waist>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<bool>(); | |||||
if (waist->petiole_present) | |||||
{ | |||||
// Parse petiole properties | |||||
if (auto element = waist_element->find("petiole_length"); element != waist_element->end()) | |||||
waist->petiole_length = element->get<float>(); | |||||
if (auto element = waist_element->find("petiole_width"); element != waist_element->end()) | |||||
waist->petiole_width = element->get<float>(); | |||||
if (auto element = waist_element->find("petiole_height"); element != waist_element->end()) | |||||
waist->petiole_height = element->get<float>(); | |||||
if (auto element = waist_element->find("petiole_spinescence"); element != waist_element->end()) | |||||
waist->petiole_spinescence = element->get<float>(); | |||||
// Parse postpetiole present | |||||
if (auto element = waist_element->find("postpetiole_present"); element != waist_element->end()) | |||||
waist->postpetiole_present = element->get<bool>(); | |||||
if (waist->postpetiole_present) | |||||
{ | |||||
// Parse postpetiole properties | |||||
if (auto element = waist_element->find("postpetiole_length"); element != waist_element->end()) | |||||
waist->postpetiole_length = element->get<float>(); | |||||
if (auto element = waist_element->find("postpetiole_width"); element != waist_element->end()) | |||||
waist->postpetiole_width = element->get<float>(); | |||||
if (auto element = waist_element->find("postpetiole_height"); element != waist_element->end()) | |||||
waist->postpetiole_height = element->get<float>(); | |||||
if (auto element = waist_element->find("postpetiole_spinescence"); element != waist_element->end()) | |||||
waist->postpetiole_spinescence = element->get<float>(); | |||||
} | |||||
// 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<render::model>(model_element->get<std::string>()); | |||||
} | |||||
// Free JSON data | |||||
delete data; | |||||
return waist; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 <stdexcept> | |||||
using namespace game::ant; | |||||
template <> | |||||
trait::wings* resource_loader<trait::wings>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path) | |||||
{ | |||||
// Load JSON data | |||||
json* data = resource_loader<json>::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<bool>(); | |||||
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<render::model>(forewings_model_element->get<std::string>()); | |||||
// 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<render::model>(hindwings_model_element->get<std::string>()); | |||||
// Parse forewing length | |||||
if (auto element = wings_element->find("forewing_length"); element != wings_element->end()) | |||||
wings->forewing_length = element->get<float>(); | |||||
// Parse forewing width | |||||
if (auto element = wings_element->find("forewing_width"); element != wings_element->end()) | |||||
wings->forewing_width = element->get<float>(); | |||||
// Parse forewing venation | |||||
if (auto element = wings_element->find("forewing_venation"); element != wings_element->end()) | |||||
wings->forewing_venation = element->get<float>(); | |||||
// Parse hindwing length | |||||
if (auto element = wings_element->find("hindwing_length"); element != wings_element->end()) | |||||
wings->hindwing_length = element->get<float>(); | |||||
// Parse hindwing width | |||||
if (auto element = wings_element->find("hindwing_width"); element != wings_element->end()) | |||||
wings->hindwing_width = element->get<float>(); | |||||
// Parse hindwing venation | |||||
if (auto element = wings_element->find("hindwing_venation"); element != wings_element->end()) | |||||
wings->hindwing_venation = element->get<float>(); | |||||
} | |||||
// Free JSON data | |||||
delete data; | |||||
return wings; | |||||
} |
@ -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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#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 |