fixed species tracking bug
This commit is contained in:
@@ -18,7 +18,6 @@ const FossilRecord = {
|
||||
},
|
||||
|
||||
addSpecies: function(org, ancestor) {
|
||||
// console.log("Adding Species")
|
||||
var new_species = new Species(org.anatomy, ancestor, this.env.total_ticks);
|
||||
this.extant_species.push(new_species);
|
||||
org.species = new_species;
|
||||
@@ -26,7 +25,6 @@ const FossilRecord = {
|
||||
},
|
||||
|
||||
addSpeciesObj: function(species) {
|
||||
// console.log("Adding Species")
|
||||
this.extant_species.push(species);
|
||||
return species;
|
||||
},
|
||||
@@ -38,6 +36,9 @@ const FossilRecord = {
|
||||
var s = this.extant_species[i];
|
||||
if (s == species) {
|
||||
this.extant_species.splice(i, 1);
|
||||
species.ancestor = undefined; // garbage collect dead species
|
||||
// if (species.ancestor)
|
||||
// species.ancestor.ancestor = undefined;
|
||||
if (species.cumulative_pop < this.min_pop) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
const CellStates = require("../Organism/Cell/CellStates");
|
||||
let FossilRecord = undefined; // workaround to a circular dependency problem
|
||||
const getFossilRecord = () => {
|
||||
if (!FossilRecord)
|
||||
FossilRecord = require("./FossilRecord");
|
||||
return FossilRecord;
|
||||
}
|
||||
|
||||
class Species {
|
||||
constructor(anatomy, ancestor, start_tick) {
|
||||
this.anatomy = anatomy;
|
||||
// this.ancestor = ancestor; // garbage collect ancestors to avoid memory problems
|
||||
this.ancestor = ancestor; // eventually need to garbage collect ancestors to avoid memory problems
|
||||
this.population = 1;
|
||||
this.cumulative_pop = 1;
|
||||
this.start_tick = start_tick;
|
||||
@@ -33,8 +39,7 @@ class Species {
|
||||
this.population--;
|
||||
if (this.population <= 0) {
|
||||
this.extinct = true;
|
||||
const FossilRecord = require("./FossilRecord");
|
||||
FossilRecord.fossilize(this);
|
||||
getFossilRecord().fossilize(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user