I can see nothing wrong with using explicit loop in J in the context you
described. I suggest you translate java into j to get a working prototype
first.
On Aug 30, 2014 7:23 AM, "Neill Robson" <[email protected]> wrote:
> Hello to all on the forum! If any you happen to know Mr. (Henry) Rich, I'm
> one of his students.
>
> The most direct way to create a constantly updating screen in J is to run
> the relevant gl2 commands in a sys_timer verb, set to repeat at a certain
> interval by the window driver. However, for a video game with any more than
> rudimentary complexity, one would wish to separate "frames" (drawing the
> image to the screen) from "ticks" (computing the game logic). Preferably,
> ticks would happen at a constant rate per second, and then the remaining
> computation time would be spent rendering frames. In Java, that would be
> implemented somehow similar to this:
>
> long lastTime = System.nanoTime();
> double nsPerTick = 1000000000D / 60D;
> double delta = 0;
> while (running) {
> long now = System.nanoTime();
> // Determine how long it has been since the last tick
> delta += (now - lastTime) / nsPerTick;
> lastTime = now;
>
> // If more than 1/60th of a second has passed, tick for each
> 60th.
> while (delta >= 1) {
> ticks++;
> tick();
> delta -= 1;
> }
>
> render();
> }
>
> Of course, J is *much* different than Java in many respects. "While" loops
> are frowned upon in this situation, because functional languages get hung
> up in the while loop until it is "finished;" however, for video games this
> "hanging up" seems to be exactly what is needed (without the side effects
> of freezing the terminal, of course).
>
> I have been directed towards sockets for this sort of situation in the
> past, but I've never progressed far enough down that route to understand
> the gritty details of how to implement such a system.
>
> Would someone on the forum be able to guide me towards a solution? To
> restate the problem, I'm looking for the functional (J) equivalent of a
> "while" loop that repeats one function at a fixed rate and runs the other
> as frequently as the host machine safely allows.
>
> Thank you for your assistance, and apologies for the protracted & ugly Java
> example!
>
> --
> -Neill
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm