Skip to main content
deleted 33 characters in body
Source Link
Markus
  • 163
  • 8

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible.

removed link, might be too much
Source Link
Markus
  • 163
  • 8

Within Stendhal RPGStendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.

Source Link
Markus
  • 163
  • 8

Within Stendhal RPG have something similar, we simulate real time by having turns with a short duration. The server works turn wise, each turn is 300 ms for us. Now if we have for example food that regenerates a player over time, we do not calculate how many ms till the next healing should happen. We count the number of turns, that need to pass till the next time the player gets healed.

To handle this there is a TurnNotifier, which checks each turn, what to do. What to do is defined in implementations of an interface TurnListener:

public class TurnNotifier { private final Map<Integer, Set<TurnListener>> register = new HashMap<Integer, Set<TurnListener>>(); public void onTurn(Integer turn) { Set<TurnListener> nowToHandle = register.remove(turn); for(TurnListener tl : nowToHandle) { tl.onTurnReached(turn); } } } 

The TurnListener looks sth like this:

public interface TurnListener { void onTurnReached(Integer turn); } 

With this concept you are able to abstract from actual time passed and whenever the TurnListener is called, you know, that enough time has passed to do what is necessary.

I don't think it is important to be as precise as possible. Just be as precise as necessary.