Alright, Here is the code and maybe I can explain what is supposed to happen.
void Generate_Grid ( int Mult )
{
int X;
int Y;
int Z;
int CurBlock = 0;
for (X = 0; X < Mult; X++)
{
for (Y = 0; Y < Mult; Y++)
{
for (Z = 0; Z < Mult; Z++)
{
myBlocks[CurBlock].SetupPosition ( X, Y, Z );
myBlocks[CurBlock].Create ( );
CurBlock++;
}
}
}
}
That creates a grid of 1x1 blocks with any given multiplier I specify, so if its 10, there will be 10x10x10 blocks etc..
int CheckBlock ( int BlockNum, int Mult, int MinBlock, int MaxBlock )
{
int Result = 0;
int LeftNum = BlockNum-Mult;
int RightNum = BlockNum+Mult;
int FrontNum = BlockNum+1;
int BackNum = BlockNum-1;
int AboveNum = BlockNum + (Mult*Mult);
int BelowNum = BlockNum - (Mult*Mult);
/*if ( LeftNum >= MinBlock && LeftNum <= MaxBlock &&
RightNum >= MinBlock && RightNum <= MaxBlock &&
FrontNum >= MinBlock && FrontNum <= MaxBlock &&
BackNum >= MinBlock && BackNum <= MaxBlock &&
AboveNum >= MinBlock && AboveNum <= MaxBlock &&
BelowNum >= MinBlock && BelowNum <= MaxBlock )
{
Result = 1;*/
bool LeftUsed = myBlocks[LeftNum].CheckUsed ( );
bool RightUsed = myBlocks[RightNum].CheckUsed ( );
bool FrontUsed = myBlocks[FrontNum].CheckUsed ( );
bool BackUsed = myBlocks[BackNum].CheckUsed ( );
bool AboveUsed = myBlocks[AboveNum].CheckUsed ( );
bool BelowUsed = myBlocks[BelowNum].CheckUsed ( );
if ( LeftUsed == true && RightUsed == true &&
FrontUsed == true && BackUsed == true &&
AboveUsed == true && BelowUsed == true )
{
Result = 2;
myBlocks[BlockNum].Hide ( );
}
//}
return Result;
}
That will look at any one block I specify, figure out the surrounding 6 blocks, above below left right front back, if all 6 blocks are present it should hide the middle block since you wouldnt be able to see it, sort of a culling system since everything is in a grid. and it does so like this
for (int i = 0; i < 1000; i++)
{
int res = CheckBlock ( i, 10, 1000, 2000 );
if ( res == 0 )
{
a++;
} else if ( res == 1 )
{
b++;
} else if ( res == 2 )
{
c++;
}
}
The a,b,c is just for my debug purposes to see exactly how many blocks it hides, skips, and if it just bypasses the entire thing.
The issue here is that in the figuring of the surrounding blocks it isnt doing it right, see attached screenshot...
if it origionally creates a 10x10x10 grid of squares the inside 8x8x8 squares should get hidden which will stil appear to the user that there is a large solid 10x10x10 grid of blocks when really there isnt, this greatly improves performance...if it only worked properly.
if this section isnt commented out in the function that checks if it should hide or not the entire thing skips every block it checks, the purpose of the commented out code is so that you don't try and access say myBlocks[-10].
/*if ( LeftNum >= MinBlock && LeftNum <= MaxBlock &&
RightNum >= MinBlock && RightNum <= MaxBlock &&
FrontNum >= MinBlock && FrontNum <= MaxBlock &&
BackNum >= MinBlock && BackNum <= MaxBlock &&
AboveNum >= MinBlock && AboveNum <= MaxBlock &&
BelowNum >= MinBlock && BelowNum <= MaxBlock )
{
Result = 1;*
I MUST be doing SOMETHING wrong but i just cannot find what that is, if there is anyone that could give this a onceover that would be GREATLY appreciated as I cannot move further without this thx thx
Add me to your MSN!