f

#### How make time go backward?

```I have made a program that simulate movements on a map (see http://28-feb-1=
986.blogspot.se/ ). It has a very simple organisation: the map and all obje=
cts are rebuilt in a BEGIN AGAIN loop, using a timer (MS@) that gives compu=
ter time in milliseconds. The time difference between the loopes is used fo=
r the kinematics (all velocities are constant) and the movements since last=

I use a simulation timer (SIMTIME@) to be able to pause and restart simulat=
ion time. When paused, the time difference is zero, so the objects is stopp=
ed automatically while the time is paused. When objects is standing still w=
hile simulation time is running, the velocity is calculated to be one pixel=
under the time the object don't move.=20

The simulation timer works as below. I would like to extend the functionali=
ty so that the simulation time could go faster, slower and even backwards, =
but I don't know if that is possible with this simple organization of the s=
imulation.

VARIABLE pausetime=20
VARIABLE stoptime=20
VARIABLE simpause=20

: init-simtime \ n --
TRUE simpause !
0 pausetime !
stoptime ! ;=20

: simtime@=20
simpause @=20
IF stoptime @ ELSE ms@ THEN=20
pausetime @ - ;=20

: starting
simpause @ 0=3D if exit then
FALSE simpause !
ms@ stoptime @ - pausetime +! ;

: stopping
simpause @ if exit then
TRUE simpause !
ms@ stoptime ! ;

``` 0  lehs
12/17/2016 9:40:57 PM comp.lang.forth  7147 articles. 0 followers. 3 Replies 910 Views Similar Articles

[PageSpeed] 52

```On Saturday, December 17, 2016 at 3:40:59 PM UTC-6, lehs wrote:
> I have made a program that simulate movements on a map (see http://28-feb=
-1986.blogspot.se/ ). It has a very simple organisation: the map and all ob=
jects are rebuilt in a BEGIN AGAIN loop, using a timer (MS@) that gives com=
puter time in milliseconds. The time difference between the loopes is used =
for the kinematics (all velocities are constant) and the movements since la=
>=20
....

variable growth
variable length
20 constant max-length
=20
: redraw ( -- )
page length @ 0 do ." =3D" loop ." >" ;
=20
: simulate ( -- )
begin
redraw
growth @ length +!
1000 ms
length @ 0 max-length within 0=3D until ;
=20
( -- )
: normal   2 growth ! ;
: faster   growth @ 2* growth ! ;
: slower   growth @ 2/ growth ! ;
: reverse  growth @ negate growth ! ;
=20
=20
\ normal speed
1 length ! normal simulate
=20
\ fast forward
1 length ! faster simulate
=20
\ slow motion
1 length ! normal slower simulate
=20
\ simulate in reverse
20 length ! normal faster faster reverse simulate

Simulates growth of a line across the string.

With threads and shared memory you could change growth
mid-simulation with a keypress, quite easily.
``` 0  Julian
12/17/2016 10:33:26 PM
```Den l=C3=B6rdag 17 december 2016 kl. 23:33:28 UTC+1 skrev Julian Fondren:
> On Saturday, December 17, 2016 at 3:40:59 PM UTC-6, lehs wrote:
> > I have made a program that simulate movements on a map (see http://28-f=
eb-1986.blogspot.se/ ). It has a very simple organisation: the map and all =
objects are rebuilt in a BEGIN AGAIN loop, using a timer (MS@) that gives c=
omputer time in milliseconds. The time difference between the loopes is use=
d for the kinematics (all velocities are constant) and the movements since =
> >=20
> ...
>=20
>   variable growth
>   variable length
>   20 constant max-length
>  =20
>   : redraw ( -- )
>     page length @ 0 do ." =3D" loop ." >" ;
>  =20
>   : simulate ( -- )
>     begin
>       redraw
>       growth @ length +!
>       1000 ms
>     length @ 0 max-length within 0=3D until ;
>  =20
>   ( -- )
>   : normal   2 growth ! ;
>   : faster   growth @ 2* growth ! ;
>   : slower   growth @ 2/ growth ! ;
>   : reverse  growth @ negate growth ! ;
>  =20
>  =20
>   \ normal speed
>   1 length ! normal simulate
>  =20
>   \ fast forward
>   1 length ! faster simulate
>  =20
>   \ slow motion
>   1 length ! normal slower simulate
>  =20
>   \ simulate in reverse
>   20 length ! normal faster faster reverse simulate
>=20
> Simulates growth of a line across the string.
>=20
> With threads and shared memory you could change growth
> mid-simulation with a keypress, quite easily.

Thanks for the idea, but I'm not sure how to use it in my program, which de=
pent on my simtime@.
``` 0  lehs
12/19/2016 10:20:08 AM
```Am Samstag, 17. Dezember 2016 22:40:59 UTC+1 schrieb lehs:
> The simulation timer works as below. I would like to extend the functiona=
lity
> so that the simulation time could go faster, slower and even backwards,

I assume that you need this functionality for algorithms like RRT-conncect =
which solves a problem from two directions. But running time backwards in a=
simulation will not work, because the game engine is called "forward simul=
ation". For testing out different solutions there must be used different si=
mulations which all running forward. "backward simulation" is only possibly=
with brute-force-techniques of a given forward simulation.

--=20 0  Manuel