lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I wish the other systems were designed like this, but they are not. (Plan9 where are you?)

Coming from game development experience, almost all our systems do have the "step" / "update" / "frameAdvance" way of doing the things. It's good and bad - some systems expect to be called right on time, others if called at anytime would require some kind of time delta or such (not big deal).

And for non-realtime UI (where updates usually happen due to user interaction), the "frame advance" way would suck more power, so it would suck on mobile devices. Yet even then certain frameworks can wait for user event to happen, and then all "frame advancement's" are called - SDL, glfw and others can do it. But then again, it might be harder to integrate with real-time redraws that should happen every 100ms or so.

On 11/14/2011 10:24 AM, Rebel Neurofog wrote:
On Mon, Nov 14, 2011 at 8:31 PM, Stefan Reich
<stefan.reich.maker.of.eye@googlemail.com>  wrote:
Yeah, actually I just found the step function in Iup. Minutes after
typing the mail...

OK, so calling the step functions with some small sleep inbetween
(100ms or some such) might basically do the trick. I'll do some more
experimentation and report how it works.


This may work for. Sometimes it's the only way depending on underlying
libraries.
Although really good practice usually looks like following (this is an
abstract of course):

Display *dpy = open_and_do_some_stuff ();
int display_fd = ConnectionNumber (dpy);
someconnection_t *connection = open_connection ();
int socket_fd = someconnection_get_socket_fd (connection);

fd_set read_fdset;
FD_ZERO (&read_fdset);
FD_ZERO (&write_fdset);
FD_SET (display_fd,&read_fdset);
FD_SET (socket_fd,&read_fdset);
int fd_top = MAX (socket_fd, display_fd) + 1;

int ret;
while ((ret = pselect (fd_top,&read_fdset, NULL, NULL,&some_timeout,
NULL)) != 0) {
     if (ret == -1) {
         /* Handle error */
     }
     if (ret>  0) {
         /* Got input from X-server or from network socket */
     }
     /* We may do some periodical work here */
}

We've got no user input or network delay here and still our process
don't eat CPU time.
This works fine with X-server. But I don't know much about other systems.