|
|
Crash when setting a mesh
#408899
10/09/12 03:54
10/09/12 03:54
|
Joined: Aug 2011
Posts: 58 Colombia/Bogotá
wdakfenixx
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2011
Posts: 58
Colombia/Bogotá
|
So i'm trying to create a block world,(somewhat like minecraft), so iv'e created a function that change each block mesh according to the blocks surrounding it, so it wont have to take time trying to render triangles that are not visible, however,the function crash the engine when its excecuted,on a left mouse click, but the thing is that it seems to be random i.e., sometimes it works trhee times, but sometimes it doesn't works a single one, and crashes the engine istantly, i have no idea why, so i need help. Is there any way to solve it or a better way to do it? thanks in advance This is the function that i'm using
//xx,yy, and zz are the coordinates of the block
//MX,MY,MZ, are the size of the array in wich block info is stored
//entity[] is an array of 64 entities conatining all the meshes
//Ni Mesh index
function UpdateBlock(var xx,yy,zz)
{
var cn=0,Fa[6], Ni=0 ,i;
if(Block[xx][yy][zz] == 6)//6 means full and 3 means full and rendered
{
for(i=0;i<6;i++)Fa[i]=0;//Reset values
//Check if the Blocks arround are full(6||3) or empty(0),set the respective flag Fa[]
if(xx>0) if(Block[xx-1][yy][zz] != 6 && Block[xx-1][yy][zz] != 3){Fa[0]=1;cn=1;}
if(xx<MX)if(Block[xx+1][yy][zz] != 6 && Block[xx+1][yy][zz] != 3){Fa[1]=1;cn=1;}
if(yy>0) if(Block[xx][yy-1][zz] != 6 && Block[xx][yy-1][zz] != 3){Fa[2]=1;cn=1;}
if(yy<MY)if(Block[xx][yy+1][zz] != 6 && Block[xx][yy+1][zz] != 3){Fa[3]=1;cn=1;}
if(zz>0) if(Block[xx][yy][zz-1] != 6 && Block[xx][yy][zz-1] != 3){Fa[4]=1;cn=1;}
if(zz<MZ)if(Block[xx][yy][zz+1] != 6 && Block[xx][yy][zz+1] != 3){Fa[5]=1;cn=1;}
Ni=0;
//use all the flags(Fa[]) as if they were a single binary number
//and translate it into decimal system, in order to get the mesh index
for(i=0;i<6;i++)
if(Fa[i]!=0|(5-i)!=0)
Ni+= pow(Fa[i]*2,5-i);
//If at least one face is visible
if(cn==1)
{
//The block is full and has been rendered
Block[xx][yy][zz] = 3;
//Create the model
you=ent_create(CUBE_MDL,vector(xx*dbb,yy*dbb,zz*dbb),NULL);
//Set the apropiate mesh
ent_setmesh(you,ent_getmesh(entity[Ni],0,0),0,0);
}
}
}
Last edited by wdakfenixx; 10/09/12 03:55.
CAUTION :The content above could blow your mind
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|