That said, if I was trying to adapt this algorithm to bytes, I would probably set the normal amount of water for a “full” block to 128 instead of 8. Since bytes have a much smaller number of possible values than floats, moving the baseline closer to the middle of the range gives you more flexibility and makes precision errors less visible.

I would also ignore differences of one or less because bytes don’t have enough precision to handle them.

Maybe something like that would work?

]]>void simulate_compression(){

int Flow = 0;

int MinFlow = 1;

int MaxSpeed=8;

int remaining_mass;

int[,,] mass = new int[16,16,16];;

int[,,] new_mass= new int[16,16,16];

//Calculate and apply flow for each block

for (int x = 0; x < 16; x++) {

for (int y = 0; y < 16; y++) {

for (int z = 0; z < 16; z++) {

mass [x, y, z] = thischunk.Fluids [x, y, z].water;

new_mass [x, y, z] = 0;

}

}

}

for (int x = 0; x < 16; x++) {

for (int y = 0; y < 16; y++) {

for (int z = 0; z < 16; z++) {

//Skip inert ground blocks

if (thischunk.blocks [x, y, z].GetBlockInfo ().watercapacity == 0) {

continue;

}

//Custom push-only flow

Flow = 0;

remaining_mass = mass [x,y,z];

if (remaining_mass MinFlow) {

// Flow = Mathf.FloorToInt(Flow* 0.5f); //leads to smoother flow

}

Flow = Mathf.Clamp (Flow, 0, Mathf.Min (MaxSpeed, remaining_mass));

new_mass [x, y, z] -= Flow;

new_mass [x, y – 1, z] += Flow;

remaining_mass -= Flow;

}

}

if (remaining_mass MinFlow) {

Flow = Mathf.RoundToInt(Flow* 0.5f); //leads to smoother flow

}

//Flow = Mathf.Clamp (Flow, 0, remaining_mass);

new_mass [x,y,z] -= Flow;

new_mass [x – 1,y,z] += Flow;

remaining_mass -= Flow;

}

}

if (remaining_mass MinFlow) {

Flow = Mathf.RoundToInt(Flow* 0.5f); //leads to smoother flow

}

//Flow = Mathf.Clamp (Flow, 0, remaining_mass);

new_mass [x,y,z] -= Flow;

new_mass [x,y,z – 1] += Flow;

remaining_mass -= Flow;

}

}

if (remaining_mass MinFlow) {

Flow = Mathf.RoundToInt(Flow* 0.5f); //leads to smoother flow

}

//Flow = Mathf.Clamp (Flow, 0, remaining_mass);

new_mass [x,y,z] -= Flow;

new_mass [x,y,z + 1] += Flow;

remaining_mass -= Flow;

}

}

if (remaining_mass MinFlow) {

Flow = Mathf.RoundToInt(Flow* 0.5f); //leads to smoother flow

}

//Flow = Mathf.Clamp (Flow, 0, remaining_mass);

new_mass [x,y,z] -= Flow;

new_mass [x + 1,y,z] += Flow;

remaining_mass -= Flow;

}

}

if (remaining_mass MinFlow) {

// Flow = Mathf.FloorToInt(Flow* 0.5f); //leads to smoother flow

}

Flow = Mathf.Clamp (Flow, 0, Mathf.Min (MaxSpeed, remaining_mass));

new_mass [x,y,z] -= Flow;

new_mass [x,y + 1,z] += Flow;

remaining_mass -= Flow;

}

}

}

}

}

//Copy the new mass values to the mass array

for (int x = 0; x < 16; x++) {

for (int y = 0; y < 16; y++) {

for (int z = 0; z < 16; z++) {

if (new_mass [x,y,z]<=0) {

thischunk.Fluids [x, y, z].water = 0;

continue;

}

thischunk.Fluids [x, y, z].water = (byte)new_mass [x,y,z];

}

}

}

}

//Returns the amount of water that should be in the bottom cell.

private int get_stable_state_b ( int total_mass ){

if ( total_mass <= 8 ){

return 8;

} else if ( total_mass < 2*MaxMass + MaxCompress ){

return Mathf.RoundToInt((MaxMass*MaxMass + total_mass*MaxCompress)/(MaxMass + MaxCompress));

} else {

return Mathf.RoundToInt(total_mass + MaxCompress)/2;

}

}

I can't get the water to level out because of the water next to it is only one less, and not less then one. anyideas how i could fix this problem.

a block holds 8 water normal and 255max(cause bytes)

Please help.

if x <= 1, all water goes to the lower cell * a = 0 * b = 1 if x > 1 & x < 2*MaxMass + MaxCompress, the lower cell should have MaxMass + (upper_cell/MaxMass) * MaxCompress b = MaxMass + (a/MaxMass)*MaxCompress a = x - b -> b = MaxMass + ((x - b)/MaxMass)*MaxCompress -> b = MaxMass + (x*MaxCompress - b*MaxCompress)/MaxMass b*MaxMass = MaxMass^2 + (x*MaxCompress - b*MaxCompress) b*(MaxMass + MaxCompress) = MaxMass*MaxMass + x*MaxCompress * b = (MaxMass*MaxMass + x*MaxCompress)/(MaxMass + MaxCompress) * a = x - b; if x >= 2 * MaxMass + MaxCompress, the lower cell should have upper+MaxCompress b = a + MaxCompress a = x - b -> b = x - b + MaxCompress -> 2b = x + MaxCompress -> * b = (x + MaxCompress)/2 * a = x - b]]>

Other than that, thanks this is exactly what I’ve been looking for.

]]>grill worn on the bottom of the bag on the market.

So congratulations to louis vuitton handbags designer Marc Jacobs backstage after

his louis vuitton handbags show on Wednesday, July 13, 2011 at 2223 North West Shore Boulevard

in Tampa at 6:39 pm.

In water_sim.pde lign 440 you used map_height instead of map_width.

]]>