[comp.sys.mac.programmer] INITs and Animation...

kmork@ulrik.uio.no (Knut Mork) (05/03/91)

I have two questions:

1) How can I really smooth animation of multiple objects on the screen? (
se prev. msg) I've tried all sorts of methods, and none seem to work quite
right!

2) I'm trying to patch a piece of code into the VBL manager with an INIT so
I have this piece of code running in the background (like screensavers do).
Unfortunately, the code goes away with the rest of the INIT, and I can't
get it to stay in memory.  Can anyone help me?

--Knut Mork, kmork@ulrik.uio.no
-- 
| /  |\  /|   Knut Mork
|/   | \/ |   "The Master"
|\   |    |   aka Duthyn, Kaiser Knut, TRAP-R-JON-1, Forian
| \  |    |   kmork@ulrik.uio.no

stevec@Apple.COM (Steve Christensen) (05/04/91)

kmork@ulrik.uio.no (Knut Mork) writes:
>I have two questions:
>
>1) How can I really smooth animation of multiple objects on the screen? (
>se prev. msg) I've tried all sorts of methods, and none seem to work quite
>right!

I don't know.

>2) I'm trying to patch a piece of code into the VBL manager with an INIT so
>I have this piece of code running in the background (like screensavers do).
>Unfortunately, the code goes away with the rest of the INIT, and I can't
>get it to stay in memory.  Can anyone help me?

Your INIT is a resource, and so when the INIT file is closed, it's purged from
memory.  You can get the code to hang around in one of two ways:

1) Copy the part of the INIT that you want to remain resident into a non-
relocatable block in the system heap, and install the copy.

2) Set the resource attributes on your INIT resource to "system heap", then
call DetachResource(handleToMyINIT) to make the Resource Manager forget about
it.

Method (2) is also used when you want other kinds of resources to hang around
as well (like if you had some pictures or strings, etc.).  Just be aware that
you can't use GetResource() to find them after you detach them, so save the
handles to the resources...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen			Never hit a man with glasses.
  stevec@apple.com			Hit him with a baseball bat.

peirce@outpost.UUCP (Michael Peirce) (05/04/91)

In article <1991May3.155215.4115@ulrik.uio.no>, kmork@ulrik.uio.no (Knut Mork) writes:
>
> 2) I'm trying to patch a piece of code into the VBL manager with an INIT so
> I have this piece of code running in the background (like screensavers do).
> Unfortunately, the code goes away with the rest of the INIT, and I can't
> get it to stay in memory.  Can anyone help me?

One way is to load a standalone code resource into the system
heap, detach it from the resource manager and pass it's address as
a completion routine to something (like the time manager for example).

	SetZone(SystemZone);
	codeH := Get1Resource('ExCo',kExampleCodeResourceID);
	DetachResource(codeH);
	HNoPurge(codeH); {is this needed?}
	HLock(codeH);
	SetZone(ApplicZone);

...later...

	someParameterBlock.ioCompletion := codeH^;

...and do an asynchronous operation...


Other people like to keep the code in the INIT and detach the INIT
itself.  I prefer a seperate resource so the actual INIT code doesn't
have to take up space in the heap.

Oh yes, of you use the above technique make sure that the routine
you want called is the first routine in the resource.

-- michael

--  Michael Peirce         --   outpost!peirce@claris.com
--  Peirce Software        --   Suite 301, 719 Hibiscus Place
--  Macintosh Programming  --   San Jose, California 95117
--           & Consulting  --   (408) 244-6554, AppleLink: PEIRCE