Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!caen!kuhub.cc.ukans.edu!2fmlcalls From: 2fmlcalls@kuhub.cc.ukans.edu Newsgroups: comp.sys.mac.programmer Subject: Re: Optimizing animation processing speed Message-ID: <1991May18.015511.30893@kuhub.cc.ukans.edu> Date: 18 May 91 06:55:10 GMT References: <1776@babcock.cerc.wvu.wvnet.edu> Organization: University of Kansas Academic Computing Services Lines: 40 In article <1776@babcock.cerc.wvu.wvnet.edu>, vrm@blackwater.cerc.wvu.wvnet.edu (Vasile R. Montan) writes: > all please suggest places where I could speed things up? > > In this animation, I am moving icons around on the screen. I > have two offscreen bitmaps. The first offscreen contains the > background art, which is slow to draw; this way, I only have to > draw it once. I continually CopyBits this whole bitmap into > the second bitmap. I draw the icons the second bitmap, then > copyBits the second bitmap onto the screen. This whole process > happens every event loop. (Slow as this sounds, I have reason > to believe that this is actually not the big time-consumer.) > --Kurisuto > un020070@vaxa.wvnet.edu I'm inclined to believe this is the entire time-consumer (well, not *entire* :)). You obviously have defined a rect for your PlotIcon() routine. Once the icon appears on the screen (your first 'frame' of animation), then it is the only portion of your background which needs replacing (as that is the only portion of the background that was lost from your PlotIcon()). Therefore, keep track of an oldRect. Then rather than CopyBits()ing the whole screen, just replace the background where the icon *was*. I doubt you want flicker, so try this in your loop: plotRect --> oldRect move plotRect to new position UnionRect(plotRect, oldRect, unionOfTwoRect) CopyBits(backgroundOffscreen, intermediateOffscreen, unionOfTwoRect, unionOfTwoRect, srcCopy, nil) set your intermediateOffscreen to be the active port PlotIcon(plotRect, yourIcon) CopyBits(intermediateScreen, onscreenWindow, unionOfTwoRect, unionOfTwoRect, srcCopy, nil); Hows that for a mish-mash of code and algorithm? I made some variable-name assumptions (for clarity I hope). Also, shouldn't really use nil for CopyBits() to the screen (use the visRgn). If you try this out, let me know what speed increase you get. john calhoun