POV-Ray : Newsgroups : povray.binaries.animations : Uberpov persistent feature for animation of big scene : Re: Uberpov persistent feature for animation of big scene Server Time: 26 Feb 2021 22:22:05 GMT
  Re: Uberpov persistent feature for animation of big scene  
From: clipka
Date: 7 Jan 2018 23:57:17
Am 07.01.2018 um 21:09 schrieb Kenneth:
> clipka <ano### [at] anonymousorg> wrote:
>>
>> Take a look at the following macro, and compare it to your code:
>>
>>     #macro MyMacro()
>>       #ifndef(FOO)
>>       #declare FOO =
>>         union {
>>           #local TEX_1 = texture{...}
>>           #local MY_BOX = box{0,1}
>>           object{MY_BOX texture{TEX_1}
>>           ...
>>         }
>>       #end
>>       object{FOO}
>>     #end
>>
>> Note how this assembles a union from local variables (which "die" each
>> time the end of the macro is reached), and assigns the resulting object
>> to a global variable, which will still be "alive" if the macro is
>> invoked again later.
>>
> 
> I never realized that a macro's result-- object(FOO)-- was a global variable
> that remained 'alive' in a scene once the macro was invoked. Is that
> specifically because #ifndef is used here? (Actually, I'm guessing that it has
> nothing to do with #ifndef.)

Nonono...

The first time the macro is invoked, `FOO` isn't defined yet, so the
`#ifndef(FOO)` block is entered, which contains a `#declare FOO`
statement. That statement defines a global variable named `FOO` that
sticks around even after the macro is long gone.

The `object{FOO}` is just an example statement to do _something_ with
that variable.

The second time the macro is invoked, `FOO` is already defined (because
it still sticks around from the last macro invocation), and the
`#ifndef(FOO)` block is skipped.

The `object{FOO}` again is just an example statement to do _something_
with that variable. Note that this time around it isn't using an object
created during the macro invocation itself, but rather re-uses the
object created during the first macro invocation.


The variable `FOO` persists across macro invocations regardless of
whether the `object{FOO}` statement is present or not. But without that
statement the variable would never actually be used for anything.


Post a reply to this message

Copyright 2003-2008 Persistence of Vision Raytracer Pty. Ltd.