/************************************ notify.c *************************/ #include #include #include "sdi.h" /* * Copyright 1987 by Mark Weiser. * Permission to reproduce and use in any manner whatsoever on Suns is granted * so long as this copyright and other identifying marks of authorship * in the code and the game remain intact and visible. Use of this code * in other products is reserved to me--I'm working on Mac and IBM versions. */ /* * notifier and timer specific code, including some input handling hacks. */ /* * Schedule things from input clients before timers. The effect * is to get all the input before starting to update the screen. */ Notify_value scheduler(n, clients) Notify_client *clients; { int i; for (i=0; i < n; i += 1) { if ( clients[i] == (Notify_client)launchcanvas || clients[i] == (Notify_client)citycanvas || clients[i] == (Notify_client)launchframe || clients[i] == (Notify_client)cityframe ) { notify_client(clients[i]); clients[i] = NOTIFY_CLIENT_NULL; } } for (i=0; i < n; i += 1) { if (clients[i] != NOTIFY_CLIENT_NULL) { notify_client(clients[i]); clients[i] = NOTIFY_CLIENT_NULL; } } return NOTIFY_DONE; } /* * Call procedure f in a little while. */ struct call_wrapper { /* Dynamically allocating a wrapper ensures unique notifier id's. */ void (*f)(); }; void do_with_delay(f, secs, usecs) void (*f)(); int secs, usecs; { Notify_value do_the_call(); struct call_wrapper *w; struct itimerval timer; /* Sigh, so much work just to wait a bit before starting up. */ timer.it_interval.tv_usec = 0; timer.it_interval.tv_sec = 0; timer.it_value.tv_usec = usecs; timer.it_value.tv_sec = secs; w = (struct call_wrapper *)calloc(sizeof(struct call_wrapper), 1); w->f = f; notify_set_itimer_func(w, do_the_call, ITIMER_REAL, &timer, NULL); } /* * Wrapper to make sure procedures from do_with_delay return good values * to the notifier. */ Notify_value do_the_call(w, which) struct call_wrapper *w; { (*(w->f))(); free(w); return NOTIFY_DONE; } /* Call this routine when we are suspended, and * we want to put off notification. The parameters * are those to notify_set_itimer_func. */ suspendor(func, me, which, when) Notify_value (*func)(); int *me, which; { struct itimerval timer; timer.it_interval.tv_usec = 0; timer.it_interval.tv_sec = 0; timer.it_value.tv_usec = 0; timer.it_value.tv_sec = when; notify_set_itimer_func(me, func, ITIMER_REAL, &timer, which); }