H
HalcyonFlux
Guest
I'm trying to develop a procedural engine that can change the terrain/weather on the fly. I'm currently using for loops in the draw and step event (nested loops, at that...I know ) What is another technique to prevent from having to call on for loops to access an array and draw it?
I'm considering using data structures, but I'm not sure how much better that would be with performance. I've also considered surface drawing, but I don't know if it's a good implementation if the variables are constantly changing.
If anybody has some ideas that would be excellent!
I'm considering using data structures, but I'm not sure how much better that would be with performance. I've also considered surface drawing, but I don't know if it's a good implementation if the variables are constantly changing.
If anybody has some ideas that would be excellent!
GML:
//change_terrain();
i=1; ii=1; //Offset by 1 to prevent array errors.
for(i=1;i-1<(room_width/xx);i+=1){
for(ii=1;ii-1<(room_height/yy);ii+=1){
if(terrain[i,ii]!=0){terrain[i,ii]=choose(terrain[i-1,ii-1],terrain[i-1,ii],terrain[i-1,ii+1],
terrain[i,ii-1],terrain[i,ii],terrain[i,ii+1],
terrain[i+1,ii-1],terrain[i+1,ii],terrain[i+1,ii+1])}
//I think this else statement is redundant but w/e.
else{terrain[i,ii]=choose(terrain[i-1,ii-1],terrain[i-1,ii],terrain[i-1,ii+1],
terrain[i,ii-1],terrain[i,ii],terrain[i,ii+1],
terrain[i+1,ii-1],terrain[i+1,ii],terrain[i+1,ii+1])}
}
}
}
GML:
//Create Event
i=0; //x coord
ii=0; //y coord
xx=16; //x width (i*xx)
yy=16; //y width (ii*yy)
//Init the terrain
for(i=0;i-1<=room_width/xx;i+=1){
for(ii=0;ii-1<=room_height/yy;ii+=1){
terrain[i,ii]=choose(0,1); //Choose between A or B. You can add weight to either side
}
}
//Change the terrain to add variety.
repeat(5){
change_terrain();
}
GML:
//Step Event
change_terrain();
GML:
//Draw Event
for(i=1;(i-1)<room_width/xx;i+=1){
for(ii=1;(ii-1)<room_height/yy;ii+=1){//((i/(room_width/xx)*255)+(ii/(room_height/yy)*255))/2
color1=make_color_hsv(i/(room_width/xx)*255,255,ii/(room_height/yy)*255);
color2=make_color_hsv(i/(room_width/xx)*255,255/2,ii/(room_height/yy)*255);
if(terrain[i,ii]=0){draw_set_blend_mode(bm_normal);
draw_rectangle_color((i-1)*xx,(ii-1)*yy,((i-1)*xx)+xx,((ii-1)*yy)+yy,c_black,c_black,c_black,c_black,false);}
if(terrain[i,ii]=1){draw_set_blend_mode(bm_add);
draw_rectangle_color((i-1)*xx,(ii-1)*yy,((i-1)*xx)+xx,((ii-1)*yy)+yy,color2,color2,color2,color2,false);}
}
}
draw_text(4,4,fps);
Last edited by a moderator: