I think the approach you took with all these threads is overly complicated for a game, you are making things more difficult for yourself this way. You are better off doing all the game logic/rendering in the same thread as others have suggested. For example, a way to model the behaviour you want (from the top of my head, so bear with me) is to give each type of vehicle a speed variable, a location %, a current grid x/y and a next grid x/y.
public class VehicleType {
private float topSpeed;
private float speedGain; // the power of the engine?
private String name;
...
}
public class VehicleInstance {
private VehicleType type;
private float currentSpeed;
private GridLocation currentLocation; // just something which holds x,y values on the grid
private GridLocation nextLocation;
private GridPath currentPath; // an arraylist of gridlocations maybe...
private float progress;
}
now you can calculate where your vehicle should be on the map. Say that vehiclespeed is in km/h and each tile is 5 by 5 km.
float previousUpdateTime;
float currentUpdateTime;
public static final long NANOSPERSECOND = 1000000000;
public static final int SPEEDTOCROSSTILEINONESECOND = 100; // speed in km/h to cross a single tile in one second
public static final float PROGRESSPERSECOND = (1.0f / SPEEDTOCROSSTILEINONESECOND) / NANOSPERSECOND; // tile progress per second per km/h
public void update() {
previousUpdateTime = currentUpdateTime;
currentUpdateTime = System.nanoTime();
float timeDelta = currentUpdateTime - previousUpdateTime;
for(VehicleInstance vehicle : vehicles) {
if(vehicle.currentSpeed < vehicle.type.topSpeed) {
vehicle.currentSpeed = vehicle.currentSpeed + vehicle.type.speedGain;
if(vehicle.currentSpeed > vehicle.type.topSpeed)
vehicle.currentSpeed = vehicle.type.topSpeed;
}
// progress is between 0.0f (start of tile) and 1.0f (end of tile)
vehicle.progress = vehicle.progress + ((PROGRESSPERSECOND * vehicle.currentSpeed) * timeDelta));
if(vehicle.progress > 1.0f) {
vehicle.progress -= 1.0f;
vehicle.currentLocation = vehicle.nextLocation;
vehicle.nextLocation = vehicle.currentPath.getNext();
}
}
}
something like this. you also have to add code for the vehicle to break and stuff. ;D Anyway, the speed calculations to update progress are correct. I tested it using MS Excel.