Code cleanup and minor performance increase

This commit is contained in:
M.Rohmer
2022-03-06 17:28:33 +01:00
parent ccaf78dd43
commit 9ca64a3c41
2 changed files with 34 additions and 106 deletions
+15 -25
View File
@@ -18,6 +18,7 @@ namespace PropagationRemasteredBeta
const int DEFAULT_INFECTION_RATE = 20;
const int DEFAULT_CURE_TIME = 25;
//Only here for performance purposes
public SolidBrush SAIN_COLOR = new SolidBrush(Color.Green);
public SolidBrush INFECTED_COLOR = new SolidBrush(Color.Red);
public SolidBrush IMMUNE_COLOR = new SolidBrush(Color.Blue);
@@ -81,7 +82,6 @@ namespace PropagationRemasteredBeta
DeadCount = new List<int>();
SimulationDuration = -1;
}
public Terrain() : this(new Size(DEFAULT_SIZE, DEFAULT_SIZE), DEFAULT_INFECTED_PROPORTION, DEFAULT_IMMUNE_PROPORTION, DEFAULT_DEATH_RATE, DEFAULT_INFECTION_RATE, DEFAULT_CURE_TIME)
{
@@ -113,7 +113,7 @@ namespace PropagationRemasteredBeta
state = Human.IMMUNE;
}
}
Human tmp = new Human(new Point(width, height), state,new Size(1,1),SAIN_COLOR,INFECTED_COLOR,IMMUNE_COLOR,DEATH_COLOR);
Human tmp = new Human(new Point(width, height), state,SAIN_COLOR,INFECTED_COLOR,IMMUNE_COLOR,DEATH_COLOR);
Population[width, height] = tmp;
}
}
@@ -138,8 +138,7 @@ namespace PropagationRemasteredBeta
state = Human.IMMUNE;
}
Human tmp = new Human(new Point(width, height), state,new Size(1, 1), SAIN_COLOR, INFECTED_COLOR, IMMUNE_COLOR, DEATH_COLOR);
//Population[width, height] = new Human(new Point(width, height), state);
Human tmp = new Human(new Point(width, height), state, SAIN_COLOR, INFECTED_COLOR, IMMUNE_COLOR, DEATH_COLOR);
Population[width, height] = tmp;
}
}
@@ -195,17 +194,6 @@ namespace PropagationRemasteredBeta
}//);
}//);
/*
List<Human> filtered = PeopleToCheck.Distinct().ToList<Human>();
Parallel.ForEach(filtered,
target =>
{
Population[target.Position.X, target.Position.Y] = target.CheckInfection(InfectionRate,Rnd);
}
);
*/
//List<Human> filtered = PeopleToCheck.Distinct().ToList<Human>();
foreach (Human target in PeopleToCheck)
{
Population[target.Position.X,target.Position.Y] = target.CheckInfection(InfectionRate,Rnd);
@@ -224,10 +212,10 @@ namespace PropagationRemasteredBeta
//we check that it is not the first frame and by default we expect the first frame to be dominantly sain people
if (InfectedCount.Count() > 0)
{
int infecteds = InfectedCount[InfectedCount.Count() - 1];
int sain = SainCount[SainCount.Count() - 1];
int immune = ImmuneCount[ImmuneCount.Count() - 1];
int deaths = DeadCount[DeadCount.Count() - 1];
int infecteds = InfectedCount[InfectedCount.Count - 1];
int sain = SainCount[SainCount.Count - 1];
int immune = ImmuneCount[ImmuneCount.Count - 1];
int deaths = DeadCount[DeadCount.Count - 1];
if (infecteds > sain && infecteds > immune && infecteds > deaths)
{
@@ -247,24 +235,26 @@ namespace PropagationRemasteredBeta
}
//as Color object cannot be a constant we cannot use Human.SAIN_COLOR we need to use a fully constructed human
Human sample = new Human(new Point(-1, -1), Human.DEAD);
switch (dominantState)
{
case Human.SAIN:
gr.FillRectangle(sample.SAIN_COLOR, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
sample.State = Human.SAIN;
break;
case Human.IMMUNE:
gr.FillRectangle(sample.IMMUNE_COLOR, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
sample.State = Human.IMMUNE;
break;
case Human.INFECTED:
gr.FillRectangle(sample.INFECTED_COLOR, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
sample.State = Human.INFECTED;
break;
case Human.DEAD:
gr.FillRectangle(sample.DEATH_COLOR, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
sample.State = Human.DEAD;
break;
default:
gr.FillRectangle(sample.SAIN_COLOR, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
sample.State = Human.SAIN;
break;
}
gr.FillRectangle(sample.Sprite, new Rectangle(new Point(0, 0), new Size(Render.Width, Render.Height)));
for (int width = 0; width < TerrainSize.Width; width += 1)
{
@@ -274,7 +264,7 @@ namespace PropagationRemasteredBeta
if (individual.State != dominantState)
{
SolidBrush c = individual.Sprite;
gr.FillRectangle(c, new Rectangle(individual.Position, individual.HumanSize));
gr.FillRectangle(c, new Rectangle(individual.Position, new Size(1,1)));
DRAWED_ELEMENTS++;
}