I'm working on optimizing a little java program I made for Christmas. I was testing the amount of time it takes to run the methods and one of them, Snow_AI, is taking 1234567 nano seconds to run. the Snow_AI method:
public void Snow_AI() {
int Wind_Speed = Rnd.nextInt(7) - 3;
if (CurrentGlodalWind + Wind_Speed < 10 && CurrentGlodalWind + Wind_Speed > -10) {
CurrentGlodalWind += Wind_Speed;
}
for (int S = 0; S < SnwInf.length; S++) {
if (SnwInf[S] != null) {
if (SnwInf[S].X < Main.Screen.width) {
SnwInf[S].Vel_X = CurrentGlodalWind + (Rnd.nextInt(5) - 2);
}
}
}
}
This code isn't the issues.
The issues is with the counter method:
public boolean Count() {
if (CreateCnt > CreateTime) {
CreateCnt = 0;
return true;
} else {
CreateCnt = CreateCnt + 1;
}
return false;
}
This is how I'm making the calls:
if (Snw.Count()) {
Snw.Snow_AI();
}
when I move the timing calls inside the If statement it changed the time to run to less than 5000. Anyone know why the counter method is causing this to happen?
Aucun commentaire:
Enregistrer un commentaire