Method used for new speed tests:
placing "return(random(200));" in different places of my get_height function

Quote:

var get_height(var Px, var Py, int SW, CONTACT* c1)
{
//P = point that we want the height of (x,y,0)
//SW = vertex number of terrain ent closest towards the lower left corner of the square
//c1 = pointer to our terrain vertex info

VECTOR P;

VECTOR Triangle[3];
VECTOR temp_vec;
ANGLE temp_ang;
VECTOR Director[2];

VECTOR formula;
var ind_term;

//1

//TRANSFORM SKIN PIXEL COORDS TO LOCAL ENT COORD SYSTEM
vec_set(P,vector(Px,Py,0));
P.x-= 256;
P.y = 256-P.y;

//2

//retrieve first point of containing triangle (base corner)
Triangle[0].x=(c1.v)[SW].x;
Triangle[0].y=(c1.v)[SW].z;
Triangle[0].z=(c1.v)[SW].y;

//3

//retrieve second point of containing triangle (diagonal to base)
Triangle[1].x=(c1.v)[SW-32].x;
Triangle[1].y=(c1.v)[SW-32].z;
Triangle[1].z=(c1.v)[SW-32].y;

//4

//determine third point of containing triangle (varying point)
vec_set (temp_vec, P);
//5
vec_sub (temp_vec,Triangle[0].x);
//6
vec_to_angle (temp_ang.pan,temp_vec);

//7

//retrieve third point of containing triangle (varying point)
if(temp_ang.pan>45)
{
Triangle[2].x = (c1.v)[SW-33].x;
Triangle[2].y = (c1.v)[SW-33].z;
Triangle[2].z = (c1.v)[SW-33].y;

}
else
{
Triangle[2].x = (c1.v)[SW+1].x;
Triangle[2].y = (c1.v)[SW+1].z;
Triangle[2].z = (c1.v)[SW+1].y;

}

//8

//calculate the triangle's plane normal for the formula coeficients
vec_set(Director[0],Triangle[1]);
vec_sub(Director[0],Triangle[0]);
vec_set(Director[1],Triangle[2]);
vec_sub(Director[1],Triangle[0]);
//9
vec_cross(formula,Director[0],Director[1]);
//10
//set the independant term of the formula
ind_term=(-1*formula.x*Triangle[0].x)+(-1*formula.y*Triangle[0].y)+(-1*formula.z*Triangle[0].z);
//11
//calculate our point's height plugging our values into the formula
P.z=(-1*((formula.x*P.x)+(formula.y*P.y)+ind_term))/formula.z;
//12
return(P.z);
//NONE
}


1- 5.4 secs
2- 6.2 secs
3- 7.9 secs
4- 9.5 secs
5- 9.9 secs
6- 10.1 secs
7- 16.3 secs
8- 18.1 secs
9- 20.7 secs
10- 21.6 secs
11- 22.7 secs
12- 24.0 secs
NONE- 22.7 secs

EDIT: I was doing some other speed tests centered around get_height while you answered since the first test pointed to this function being the problem that slows everything down. After seeing the results of these tests it seems that this is the problem... Don't know hot to optimize it though... Any suggestions?

Last edited by Carlos3DGS; 11/05/11 13:41.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1