I'm not certain how the semaphore removes the need to call "HP auto recover" every second, thousands of times over a sleep period [...]
There's no reason to count the in-game time in seconds unless it's a puzzle game, and also no reason to have a tick time at 1 second ; both are too fast. Ideally it should be something around 1 in-game minute every 10 seconds, therefore 1 in-game hour every 10 minutes of play.
As for the call to the healing routine, since it should start by validating that there's something to do, it's a question of micro seconds. Therefore, even if there's only 1 health point left when the player go to sleep, it would at max take one or two seconds to process the healing when the MC is asleep ; less than 10 if the health is constantly damaged by some poison.
unless you are saying that during a "sleeping" period the HP recover is called less but with greater effect,
With greater effect, obviously, but not less often. This said, I missed your use of a so low time division.
or you are saying the tick should decouple from game time, and game time should progress more rapidly during sleep.
It's what I said in my first comment. During sleep the time past (almost) instantly because of the lower value for the tick.
For a realtime game, the time mechanism should be put in a thread(-like) ; CoffeeScript's intervals are a good enough substitute for threads. And, globally speaking, it should looks like that :
Code:
if ++actualTick != tickTrigger
end there
actualTick = 0
time++
// This part have too many possible implementations, it's only one of the many
call of the generic processing routines (the healing process by example)
for each entry in cronTable
if --entryCounter == 0
call entryCallBack
clear the entry
With
tickTrigger
being lower when the MC is sleeping and anytime there's an explicit or implicit time skipping.
The effective value of
tickTrigger
depend of the frequency at which the time routine is called, as well as the time needed for the basis processing ; CoffeeScript having timer expressed on milliseconds, but being relatively slow you should probably not goes bellow to 100 as value for
tickTrigger
.
As for
cronTable
it's a basic structure with a
code reference, and
counter set at the delay before the said
code reference should be proceeded.
I'm not certain how you envision using semaphores would solve this situation while maintaining the possibility of either outcome.
As I said, I missed your low time unit, what probably not helped. But you also clearly missed the point in my initial answer.
Code:
if ++actualTick != tickTrigger
end there
actualTick = 0
time++
HealMC
PoisonEffect
PoisonEvolution
It will works exactly in the same way whatever the value of
tickTrigger
; and therefore whatever if the MC is sleeping or not. Every
time unit, the natural healing process will give back some HP to the MC, and right after that, the poison will remove some HP to the MC. In the same time, the poison will continue to evolve every
time unit, and kick out once it will reach the condition for that.
The only difference being that the lower is the value of
tickTrigger
, the faster it will happen. Therefore, during time skipping, 8 hours will be proceeded in few seconds.
I think the trouble comes b/c you are applying the normal concept of ticks to my game time concept. In a normal game, it makes no sense to "skip" ticks since everything relies on ticks.
[...]
The system I've designed is there to meet the problem that other games do not encounter: how do you compress a days worth, or even a months worth, or ongoing crons into a reasonable UX.
Hmm. I wasn't ready to discover that the Fallout and The Elder Scrolls series, to name only the most famous, aren't normal games, and in fact not even games :/
Not only it make sense to skip time in those games, but they also encounter this "problem", including the poison damage during the skipping period. And it happen that they deal with it the way I said.