Discard special cases for general implementation:
Instead of checking instance of veh, use the abstract method getMaxSpeed() with a given factor. This should reduce redundant checks (Wasted CPU cycles). Thus, run is a tiny bit faster.
This commit is contained in:
parent
612c00a3f1
commit
7ffbe689bc
@ -520,10 +520,7 @@ public class MakkahCity {
|
|||||||
if (!vehicle.isArrivedToDest()) {
|
if (!vehicle.isArrivedToDest()) {
|
||||||
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
|
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
|
||||||
vehicle.getCurrentLocation()+1000,vehicle)) ;
|
vehicle.getCurrentLocation()+1000,vehicle)) ;
|
||||||
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor );
|
vehicle.move(vehicle.getMaxSpeed()* factor);
|
||||||
else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
|
|
||||||
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
|
|
||||||
else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user