Time remainder after OnUpdateGameTime

Post » Wed Jan 07, 2015 4:27 am

I need help with function that would:

  • calculate real number of updates that "happened" after OnUpdateGameTime that was delayed by fast travelling or waiting
  • increase the 'counter' variable by number of updates
  • then re- RegisterForSingleUpdateGameTime using time remainder from previous update

Example: update timer = 1.5 and fast travelling takes 10 in game hours: about 6.6 updates should happen.

What I have in mind currently, but hope someone will find better solution:

Float fUpdateTimerInt iCounter ;this variable increases by 1 every full updateEvent OnUpdateGameTime()    Int numUpdates = ???     Float fTimeRemainder = ???    iCounter += numUpdates        ;cant be too precise because it would keep     ;re-registering for tiny values due to script lag    If fTimeRemainder > 0.1        ;register using "fTimeRemainder" value    Else       ;ignore time remainder and register using default "fUpdateTimer" value     EndIf    RegisterForSingleUpdateGameTime(^read above)EndEvent

Thanks in advance!

User avatar
Mimi BC
 
Posts: 3282
Joined: Sat Oct 07, 2006 10:30 pm

Post » Wed Jan 07, 2015 9:59 am

Something like this?

Float fPreviousUpdateFloat fUpdateTime = 1.5Float fMinimumUpdateTime = 0.1Int iCounterEvent OnSomeEvent() ;The first time that you register for an update	fPreviousUpdate = Utility.GetCurrentGameTime()	RegisterForSingleUpdateGameTime(fUpdateTimer)EndEventEvent OnUpdateGameTime()	Float fCurrentTime = Utility.GetCurrentGameTime()	Float fNumUpdates = (fCurrentTime - fPreviousUpdate) * 24 / fUpdateTimer	Int iNumUpdates = Math.Floor(fNumUpdates)	If(iNumUpdates > 0)		iCounter += 1 * iNumUpdates        Else                iCounter += 1	EndIf	fPreviousUpdate = fCurrentTime	Float fRemainingTime = fUpdateTime * (1.0 - (fNumUpdates - (iNumUpdates as Float)))	If(fRemainingTime > fMinimumUpdateTime)		RegisterForSingleUpdateGameTime(fRemainingTime)	Else		RegisterForSingleUpdateGameTime(fMinimumUpdateTime)	EndIfEndEvent

EDIT: I probably missed a special case or made a mistake, since I'm a bit tired as I write this.

User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm


Return to V - Skyrim