POV-Ray : Newsgroups : povray.unofficial.patches : New feature idea Server Time
2 Sep 2024 00:12:54 EDT (-0400)
  New feature idea (Message 1 to 4 of 4)  
From: Warp
Subject: New feature idea
Date: 3 Oct 2000 05:39:48
Message: <39d9a963@news.povray.org>
How hard would it be to implement this feature:

  If an identifier appears in the script with a certain syntax, eg:

`identifier` or $identifier$ or #identifier# or whatever,

then that expression is substituted with the value of the identifier and
then parsing is continued exactly as if that value had been written
explicitly in that place.
  For example (supposing that we use for example the $$ notation) this:

#declare MyIdentifier = "Another"
#declare $MyIdentifier$ = 5;
#declare Something$Another$ = <1,2,3>;

would be parsed exactly as if we had written:

#declare MyIdentifier = "Another"
#declare Another = 5;
#declare Something5 = <1,2,3>;


  Why I propose this?
  There is a discussion in povray.general (IIRC) about how to avoid unnecessary
parsing of include files that are #included more than once.
  I thought that perhaps a macro could be done to automatize the ignoring
of repeated. This macro could be used like:

import("myinclude.inc")

which would #include "myinclude.inc" only if it wasn't included before.

  It's not easy to implement this macro with the current povray script.
Perhaps simulating some dynamic array and searching that array could be
done, but that's hard to do and very slow when there are lots of includes.
  Then I thought about the feature I propose here. The macro could be done
like:

#macro import(file)
  #local ID = strreplace(file, ".", "_");
  #ifndef(_INCLUDED_$ID_)
    #declare _INCLUDED_$ID$_
    #include file
  #end
#end

  (Note also the need for a 'strreplace' function or macro...)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Disnel
Subject: Re: New feature idea
Date: 6 Oct 2000 05:26:50
Message: <39DD9BB8.BBAD889D@hlavacek-partner.cz>
Dirty trick is to add filter before POV parser, but connected to it
(with access to parser's namespace).

With includes you have good idea. I tried this:

#declare Include="colors.inc"

#include Include

sphere {
   <0, 0, 0>, 1
   texture {
     pigment {color Red}
     finish {ambient 1}
   }
}

and it works. Thus import macro can get string as its parameter.

Disnel

Warp wrote:
> 
>   How hard would it be to implement this feature:
> 
>   If an identifier appears in the script with a certain syntax, eg:
> 
> `identifier` or $identifier$ or #identifier# or whatever,
> 
> then that expression is substituted with the value of the identifier and
> then parsing is continued exactly as if that value had been written
> explicitly in that place.
>   For example (supposing that we use for example the $$ notation) this:
> 
> #declare MyIdentifier = "Another"
> #declare $MyIdentifier$ = 5;
> #declare Something$Another$ = <1,2,3>;
> 
> would be parsed exactly as if we had written:
> 
> #declare MyIdentifier = "Another"
> #declare Another = 5;
> #declare Something5 = <1,2,3>;
> 
>   Why I propose this?
>   There is a discussion in povray.general (IIRC) about how to avoid unnecessary
> parsing of include files that are #included more than once.
>   I thought that perhaps a macro could be done to automatize the ignoring
> of repeated. This macro could be used like:
> 
> import("myinclude.inc")
> 
> which would #include "myinclude.inc" only if it wasn't included before.
> 
>   It's not easy to implement this macro with the current povray script.
> Perhaps simulating some dynamic array and searching that array could be
> done, but that's hard to do and very slow when there are lots of includes.
>   Then I thought about the feature I propose here. The macro could be done
> like:
> 
> #macro import(file)
>   #local ID = strreplace(file, ".", "_");
>   #ifndef(_INCLUDED_$ID_)
>     #declare _INCLUDED_$ID$_
>     #include file
>   #end
> #end
> 
>   (Note also the need for a 'strreplace' function or macro...)
> 
> --
> main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
> ):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Nathan Kopp
Subject: Re: New feature idea
Date: 7 Oct 2000 00:39:01
Message: <39dea8e5$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote...
>   I thought that perhaps a macro could be done to automatize the ignoring
> of repeated. This macro could be used like:
>
> import("myinclude.inc")
>
> which would #include "myinclude.inc" only if it wasn't included before.
>
>   It's not easy to implement this macro with the current povray script.

It's not that hard.  Here it is with comments.  I don't think it would be
too slow, either.  You've got to do the string comparisons somewhere, either
when you do token comparisons to find the identifier in the identifiers
table or when you search through the array like in this macro.

-Nathan

================

#macro Import(File)
  // uncomment this to be case insensitive
  //#local File=strupr(File)

  // set up some variables
  #ifndef(ImportFileList)
    // we only keep track of a limited number of includes
    #declare MaxImportFiles=50;
    #declare ImportFileList=array[MaxImportFiles]
    #declare NumImportsUsed=0;
  #end

  // look through the list to see if we've already
  // included it
  #local I=0;
  #local Found=0;
  #while(I<NumImportsUsed & Found=0)
    #if(strcmp(ImportFileList[I],File)=0)
      #local Found=1;
    #else
      #local I=I+1;
    #end
  #end

  // if we didn't find it, let's include it
  #if(Found=0)
    // but first let's make a note that we are including
    // it so we won't import it again
    // if we've gone over the max, just don't bother
    // (it will get re-included)
    #if(NumImportsUsed<MaxImportFiles)
      #declare ImportFileList[NumImportsUsed]=File
      #declare NumImportsUsed=NumImportsUsed+1;
    #end

    // now do the include
    #include File
  #end
#end


Post a reply to this message

From: Warp
Subject: Re: New feature idea
Date: 9 Oct 2000 06:51:08
Message: <39e1a31c@news.povray.org>
There are only two problems here: It limits the amount of includes
and it reads through a long array each time (although I don't know how
povray handles identifiers, but I suppose it's faster than searching in
an array).
  But you are right, it should work for most cases.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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