Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!athena.mit.edu!bjaspan From: bjaspan@athena.mit.edu (Barr3y Jaspan) Newsgroups: comp.windows.x Subject: Re: Question about XCopyArea Keywords: XSun (is there a way around this?) Message-ID: <1990Feb16.010419.2462@athena.mit.edu> Date: 16 Feb 90 01:04:19 GMT References: <401@ai.etl.army.mil> Sender: news@athena.mit.edu (News system) Reply-To: bjaspan@athena.mit.edu (Barr3y Jaspan) Distribution: na Organization: Massachusetts Institute of Technology Lines: 52 In article <401@ai.etl.army.mil>, anneb@ai.etl.army.mil (Anne Brink) writes: > Hi there, fellow X-types. I need your help. > > I'm working on a graphics application in X, and I need a fast copy routine for > pixmaps. I'm calling it several zillion times in the space of oh, a few > minutes, and it takes over the entire machine. Right now, I have the code > looping forever, with 5-7 XCopyArea() calls followed by a mouse click check > in each iteration.... It sounds like the problem you are having is that the XCopyArea requests get to the server faster than it can possibly deal with them, so they get queued. When you click a mouse button, it also goes on the queue and isn't handled until all the XCopyAreas are. I am finishing up a Xlib video game that does some very similar hosing of the server.. basically, each "tick" every object in the game is told to move, and every object that actually moves does two XCopyAreas (one to erase itself, one to draw itself in the new position.) This results in zillions of calls to XCopyArea. There are three things that I am doing to prevent the problems you are having (most of these are based on ideas I stole from someone else here.. :-) 1) A "tick" is a certain, defined length of time (currently 14000 microseconds in my game). At the beginning of each tick (at the top each move loop) I call MarkTime which uses gettimeofday() and stores the tv_usec field. At the end of each loop, I call WaitRemainerOfTick which calls gettimeofday again and sleeps for 14000 - start_time (where start_time is the tv_usec) field saved earlier. The makes the program run smoothly without the speed fluctuations that would otherwise be caused by forcing the X server to run at full tilt. (I just ignore the overhead of all these calls to gettimeofday(). An X program such as this is so I/O bound that computrons come for free.) 2) At the end of *EVERY* move loop (at the end of each tick) I call XFlush.. this makes sure all of the events I've generated actually get to the server (since events are guaranteed to get there until XFlush or XNextEvent or a similar function is called). 3) Every 20 ticks I call XSync(dpy, True). The "true" means my program actually waits until the X server has processed *all* the events I've sent it. Basically, these three things make sure the program stays more or less synchronized with the X server, which prevents the problem of mouse events taking 20 seconds to get processed. Hope this helps.. Barry Jaspan, MIT-Project Athena bjaspan@athena.mit.edu