|
![](/i/fill.gif) |
Hi. Im trying to code a macro that creates a heightfield uning some sort of
recursive algorithm. I've searched the internet for a suitable algorithm
that I could convert to SDL (suitable=simple enough for me to understand).
A came across something named the Diamond-Square Algorithm (aka Midpoint
Displacement Algorithm). I got the general idea of the algorithm and
started to convert it to the SDL. I now have a file containing the code,
its still not finished, it is very inefficient, but I think the main things
are done.
The problem is...it doesnt work.
Here's the code:
//BEGIN CODE
#macro tilenum(num)
#while (num<0 & num>Size)
#if(num>Size)
(num-Size)
#end
#if(num<Size)
(num+Size)
#end
#end
#end
#macro Diamond(Sub_Size,Point_X,Point_Z)
#declare Array[Point_X][Point_Z]=(
(Array[tilenum(Point_X-(Sub_Size/2))][tilenum(Point_Z-(Sub_Size/2))])+
(Array[tilenum(Point_X+(Sub_Size/2))][tilenum(Point_Z-(Sub_Size/2))])+
(Array[tilenum(Point_X+(Sub_Size/2))][tilenum(Point_Z+(Sub_Size/2))])+
(Array[tilenum(Point_X-(Sub_Size/2))][tilenum(Point_Z+(Sub_Size/2))])
)
/4+
(rand(Rand)*(RandVal*2)-RandVal);
#end
#macro Square(Sub_Size,Point_X,Point_Z)
#declare Array[Point_X][Point_Z]=(
(Array[Point_X][tilenum(Point_Z-(Sub_Size/2))])+
(Array[tilenum(Point_X+(Sub_Size/2))][Point_Z])+
(Array[Point_X][tilenum(Point_Z-(Sub_Size/2))])+
(Array[tilenum(Point_X-(Sub_Size/2))][Point_Z])
)
/4+
(rand(Rand)*(RandVal*2)-RandVal);
#end
#macro MainLoop(Sub_Size)
#declare N1=0;
#declare N2=0;
#while (N2<Size)
#declare D_X=N1+(Sub_Size/2);
#declare D_Z=N2+(Sub_Size/2);
Diamond(Sub_Size,D_X,D_Z)
Square(Sub_Size,D_X,D_Z-(Sub_Size/2))
Square(Sub_Size,D_X+(Sub_Size/2),D_Z)
Square(Sub_Size,D_X,D_Z+(Sub_Size/2))
Square(Sub_Size,D_X-(Sub_Size/2),D_Z)
#declare N1=N1+Sub_Size;
#if (N1>=Size)
#declare N1=0;
#declare N2=N2+Sub_Size;
#end
#end
#declare RandVal=RandVal/2;
#declare Int_Val=Int_Val+1;
#if(Int_Val<=Int)
MainLoop(Sub_Size/2)
#end
#end
#macro FractalTerrain(Size,BaseHeight,Seed,Int,RandVal)
#declare Array=array[Size+1][Size+1]
#declare Array[0][0]=BaseHeight;
#declare Array[0][Size]=BaseHeight;
#declare Array[Size][0]=BaseHeight;
#declare Array[Size][Size]=BaseHeight;
#declare Rand=seed(Seed);
#declare Size=Size;
#declare RandVal=RandVal;
#declare Int=0;
MainLoop(Size)
#end
FractalTerrain(4,1,1,2,1)
//END CODE
I get the error "Parse Error: Expected 'numeric expression', ] found
instead"
Cant you use a macro when reffering to arrays?
Any comment on this would be appreciated.
Oh, I almost forgot to thank Thorsten, Shay and Mike for the help with the
"function macro" (long time ago).
It turned out quite good, thanks.
/The Ugly
Post a reply to this message
|
![](/i/fill.gif) |