POV-Ray : Newsgroups : povray.general : #declaring pre-made macro for identical repeated use? : Re: #declaring pre-made macro for identical repeated use? Server Time
30 Jul 2024 02:29:00 EDT (-0400)
  Re: #declaring pre-made macro for identical repeated use?  
From: Tor Olav Kristensen
Date: 17 Dec 2009 13:05:01
Message: <web.4b2a71b230d097eaa049a19e0@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> Hi all.
>
> Let's say I've made a macro, and that I use it in the usual way in my scene (by
> invoking it numerous times with different variables.)  But let's say I also need
> to invoke the same macro hundreds of times *without* changing the variables (in
> a #while loop for example.) Forget for the moment what the macro actually does;
> I have a question about what would be the most computationally-efficient way to
> invoke the macro in such a case.
>
> Here's the way I would normally do it (this is a very simplistic example, just
> to illustrate the idea):
>
> #declare counter = 1;
> #while(counter <= 200)
> my_macro(1,2,3) // the same variables each time
> #declare counter = counter + 1;
> #end
>
> Would it be more efficient to instead pre-#declare the macro with those set
> variables, before using it in the #while loop? As in...
>
> #declare my_identical_macro = macro(1,2,3);
> Then using *that* in the #while loop. (Which does work, BTW.)
>
> When #pre-declared this way, is there just one 'instance' of the macro now
> (similar to calling a pre-#declared triangle mesh hundreds of times), making the
> process faster and more efficient? Or is the macro repeatedly computed anyway,
> like it normally would be?


I'm sorry but I am afraid that you are misunderstanding what is happening here.

There is no such concept/feature as predeclaration of macros in POV-Ray.

What is happening above is that the values or "items" that your macro generates
are assigned to your variable "my_identical_macro".

So "my_identical_macro" is now not a macro, it is just a variable that contains
what your macro "produced".

To see that it does not work the way you think, try this:
(It does not work.)


#macro Test(A)
  #debug concat("\n", str(A, 0, -1), "\n")
#end // macro Test

Test(123)
#declare Tist = Test(456)
Tist


--
Tor Olav
http://subcube.com


Post a reply to this message

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