...
 
Commits (2)
......@@ -344,7 +344,7 @@ simulateHandlingWithObject startLoc object objectLoc alarmLoc status user
>>| autoMove startLoc objectLoc shipShortestPath user myStatusMap myUserActorMap
>>= \objectReached -> if objectReached (pickupObject objectLoc object user myUserActorMap inventoryInSectionShare
>>| autoMove objectLoc alarmLoc shipShortestPath user myStatusMap myUserActorMap
>>= \targetReached -> if targetReached (waitForTimer 1
>>= \targetReached -> if targetReached (waitForTimer False 1
>>| useObject alarmLoc object user myUserActorMap inventoryInSectionShare
>>= \used -> if used (setAlarm user (alarmLoc, NormalStatus) myStatusMap @! True)
(return False))
......
......@@ -599,7 +599,7 @@ autoMove thisSection target pathFun user shipStatusShare userToActorShare
>>- \hopLocks -> get sharedGraph
>>- \graph -> case pathFun thisSection target statusMap exitLocks hopLocks graph of
Just (path=:[nextSection:_], _)
= waitForTimer 1
= waitForTimer False 1
>-| move roomCoord nextSection user
>-| addLog user "" ("Has moved to Section " <+++ nextSection)
>-| autoMove nextSection target pathFun user shipStatusShare userToActorShare
......
......@@ -71,7 +71,7 @@ where f [] = []
| otherwise = [a : f as]
doTaskPeriodically :: Int (Task a) -> Task a | iTask a
doTaskPeriodically period task = forever (waitForTimer period >>| task)
doTaskPeriodically period task = forever (waitForTimer False period >>| task)
doTaskPeriodicallyUntilPause :: Int (Task a) -> Task () | iTask a
doTaskPeriodicallyUntilPause period task
......
......@@ -143,12 +143,13 @@ waitForDateTime :: !DateTime -> Task DateTime
* Task completes after specified amount of time has passed
* since the creation of the task.
*
* @param Whether to show a UI with the current date and time
* @param The time to wait (in seconds before the task should complete
*
* @return The time the timer went off
*
*/
waitForTimer :: !Int -> Task DateTime
waitForTimer :: !Bool !Int -> Task DateTime
/**
......
......@@ -10,6 +10,8 @@ import iTasks.SDS.Combinators.Common
import iTasks.SDS.Sources.System
from iTasks.Internal.Task import mkInstantTask
import iTasks.Internal.IWorld
import iTasks.Internal.TaskEval
import iTasks.Internal.Util
import iTasks.UI.Definition
import iTasks.UI.Editor
import iTasks.UI.Editor.Controls
......@@ -233,11 +235,27 @@ waitForDateTime datetime
= Title "Wait for date and time" @>> Hint ("Wait until " +++ toString datetime) @>> viewSharedInformation [] currentDateTime
>>* [OnValue (ifValue (\now -> datetime < now) return)]
waitForTimer :: !Int -> Task DateTime
waitForTimer interval =
waitForDateTimeWithoutFeedback :: !DateTime -> Task DateTime
waitForDateTimeWithoutFeedback datetime =
localDateTimeToTimestamp datetime >>- \timestamp ->
let
timespec = timestampToSpec timestamp
param = {start=timespec,interval={tv_sec=1,tv_nsec=0}}
in
Task (eval param) >>*
[OnValue (ifValue ((<=) timespec) \_ -> get currentDateTime)]
where
eval _ DestroyEvent _ iworld
= (DestroyedResult, iworld)
eval param event {taskId,lastEval} iworld
# (Ok (ReadingDone now),iworld) = readRegister taskId (sdsFocus param iworldTimespec) iworld
= (ValueResult (Value now False) (mkTaskEvalInfo lastEval) (mkUIIfReset event (ui UIEmpty)) (Task (eval param)), iworld)
waitForTimer :: !Bool !Int -> Task DateTime
waitForTimer updateUI interval =
get currentTimestamp >>- \(Timestamp now) ->
timestampToLocalDateTime (Timestamp (now + interval)) >>- \endTime ->
waitForDateTime endTime
timestampToLocalDateTime (Timestamp (now + interval)) >>-
if updateUI waitForDateTime waitForDateTimeWithoutFeedback
dateTimeStampedShare :: !(sds p b (DateTime,c)) -> SDSLens p b c | gText{|*|}, TC p & TC b & TC c & RWShared sds
dateTimeStampedShare sds
......
......@@ -101,7 +101,7 @@ iworldTimespecNextFire now reg {start,interval}
# start = toI start
interval = toI interval
reg = toI reg
passed = reg - start
passed = max (zero - interval) (reg - start)
= toT (start + ((passed / interval + one) * interval))
where
toI x = toInteger x.tv_sec * toInteger 1000000000 + toInteger x.tv_nsec
......