Skip to content

Commit f688bb2

Browse files
committed
I made a simple change, but that increases significantly the performance of the simulator: collision tests are executed every two frames instead of every frame; it is worth to sacrifice a bit of precision to half the time consumption of collision tests, as the displacement of moving elements between one frame and the next one is minimal, so it does not deserve another bunch of tests.
1 parent da50991 commit f688bb2

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎app/public/js/runExperiment/simulator/layers/Ecosystem/Ecosystem.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ class Ecosystem {
2525
this.world = world;
2626
this.history = [];
2727

28+
this.#species = this.setUpSpecies(setUp.species);
29+
this.#foodWeb = this.setUpFoodWeb(setUp.foodWeb);
30+
2831
this.#organismBuilder = new OrganismBuilder(this);
2932
this.#mutator = new Mutator(this);
3033
this.#mutator.init(setUp.mutations);
3134

32-
this.#species = this.setUpSpecies(setUp.species);
33-
this.#foodWeb = this.setUpFoodWeb(setUp.foodWeb);
3435

3536
// WARNING: the methods to instance organisms depend on the existance of the agentTypes "Organism" and "Circle"
3637

@@ -40,8 +41,6 @@ class Ecosystem {
4041

4142
isSetUpValid(setUp){
4243

43-
console.log(setUp);
44-
4544
if(!setUp.species) return false;
4645
if(!setUp.foodWeb) return false;
4746

@@ -50,8 +49,6 @@ class Ecosystem {
5049

5150
setUpSpecies(species){
5251

53-
console.log(species);
54-
5552
Object.keys(species).forEach(specieName => {
5653

5754

‎app/public/js/runExperiment/simulator/layers/Ecosystem/Mutator.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Mutator {
99
}
1010

1111
init(mutationDetails){
12+
console.log(this.ecosystem);
1213
this.mutations = this.setUpMutations(mutationDetails);
1314
}
1415

@@ -17,7 +18,7 @@ class Mutator {
1718
if(!mutationDetails){
1819
return; // No mutations
1920
}
20-
21+
2122
var species = Object.keys(this.ecosystem.getAllSpecies());
2223
var mutations = {};
2324

‎app/public/js/runExperiment/simulator/services/Organism/Organism.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Organism extends Service{
2323

2424
execute(){
2525

26+
27+
if(this.world.frame % 2 == 0) return;
28+
2629
if(this.isGenerationOver === true){
2730

2831
if(this.hasNotifiedGenOver === false){

‎app/public/js/runExperiment/simulator/services/Organism/OrganismBehaviour.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class OrganismBehaviour extends Service{ // once set the targets of each organis
120120
}
121121

122122
spendEnergy(organism){
123-
organism.energy -= (organism.vel.x * organism.vel.x) + (organism.vel.y * organism.vel.y) + (organism.sensitivity * 1.5);
123+
organism.energy -= (organism.vel.x * organism.vel.x) + (organism.vel.y * organism.vel.y) + (organism.sensitivity * 1.5) * 2;
124124
if(organism.energy <= 0) this.#chief.world.notifyEvent('organismOutOfEnergy', { organism : organism });
125125

126126
}

‎app/public/js/runExperiment/simulator/services/Renderer.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Renderer extends Service{
1212
}
1313

1414
execute(){
15+
16+
if(this.world.frame % 2 == 0) return;
17+
1518
this.context.fillStyle = 'rgba(0,0,0,0.3)';
1619
this.context.fillRect(0,0,canvas.width,canvas.height);
1720

0 commit comments

Comments
 (0)