|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I thought I'd share this little piece of code:
--- %< snip %< ---
#include "strings.inc"
#macro IFDEF(Name)
#local Test = concat("defined(",Name,")?yes:no");
(Parse_String(Test))
#end
#macro Set_Default_Value(_Name,_Value)
#if (!IFDEF(_Name))
#declare _Set_Default_Value_Temporary = _Value;
Parse_String(concat("#declare ",_Name," = _Set_Default_Value_Temporary;"))
#undef _Set_Default_Value_Temporary
#end
#end
--- %< snap %< ---
Using the second macro, you can set a default value for identifiers,
even if they do not exist, i.e. it's an replacement for the following
construct:
#ifndef (_Name) #declare _Name = _Value; #end
is the same as
Set_Default_Value("_Name",_Value);
(Please note the "" around the identifier's name!).
This does not really reduce the amount of typing or something like that,
but I like it because it's more readable (IMHO) and it's only meant to
be an illustration for similar, but more complicated macros.
BTW: The first macro can be used to check if an identifier whose name is
the content of the given string is defined, e.g.
#if (IFDEF("my_first_identifier"))
#debug "It does exist\n"
#end
Again, not really helpful for "standard" scenes, but very nice if you're
doing lots of things with Parse_String (which is propably the most
powerfull macro I've ever seen in SDL :)
HTH,
Florian
--
camera{look_at-y*10location<8,-3,-8>*10}#local a=0;#while(a<999)sphere{
#local _=.01*a-4.99;#local p=a*.01-5;#local c=.01*a-4.995;<sin(p*pi)*5p
*10pow(p,5)*.01>sin(c*c*c*.1)+1pigment{rgb 3}}#local a=a+1;#end
/******** http://www.torfbold.com ******** http://www.imp.org ********/
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Florian Brucker wrote:
The only small problem I can see with this is that strings would be odd.
Set_Default_Value ( "_Name0", 5 );
Set_Default_Value ( "_Name1", SomeLocalVar );
Set_Default_Value ( "_Name2", "\"Have a Nice Day\"" );
Might make the code *more* confusing when someone found this in your
include file.
-Shay
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Florian Brucker <tor### [at] torfboldcom> wrote:
> Parse_String (which is propably the most
> powerfull macro I've ever seen in SDL :)
Its problem is that it's just a hack which is very slow and inefficient
(and uses a temporary file which shouldn't really be necessary).
It's thus not a very good idea to use Parse_String in a tight loop
which is executed millions of times.
--
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> Its problem is that it's just a hack which is very slow and inefficient
> (and uses a temporary file which shouldn't really be necessary).
> It's thus not a very good idea to use Parse_String in a tight loop
> which is executed millions of times.
That's of course true. It's just that I like doing things with the SDL
which it was not developed to do. Because of some shortcomings on the
SDL side (no pointers/references, no chance to pass an uninitialized
identifier as a macro parameter, ...) you have to use hacks as those.
With some modifications to Parse_String it's also possible to
dynamically create macros, something I've used in some kind of extended
plugin mechanism.
But you're right, I would not use such things in a "normal" scene,
because it takes too long to parse and often gets complicated pretty fast.
Florian
--
camera{look_at-y*10location<8,-3,-8>*10}#local a=0;#while(a<999)sphere{
#local _=.01*a-4.99;#local p=a*.01-5;#local c=.01*a-4.995;<sin(p*pi)*5p
*10pow(p,5)*.01>sin(c*c*c*.1)+1pigment{rgb 3}}#local a=a+1;#end
/******** http://www.torfbold.com ******** http://www.imp.org ********/
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|