Stumbling about
This commit is contained in:
parent
bc6a3cd1c1
commit
a2f1e11af8
3 changed files with 41 additions and 33 deletions
|
@ -6,11 +6,11 @@ namespace simulation
|
|||
unsigned char x,
|
||||
unsigned char y,
|
||||
unsigned char z,
|
||||
SimulationGrid* grid)
|
||||
SimulationGrid grid)
|
||||
{
|
||||
if (x < grid->x_max && y < grid->y_max && z < grid->z_max)
|
||||
if (x < grid.x_max && y < grid.y_max && z < grid.z_max)
|
||||
{
|
||||
unsigned int offset = x + y * grid->x_max + z * (grid->y_max * grid->x_max);
|
||||
unsigned int offset = x + y * grid.x_max + z * (grid.y_max * grid.x_max);
|
||||
return offset;
|
||||
}
|
||||
return -1;
|
||||
|
@ -18,31 +18,30 @@ namespace simulation
|
|||
|
||||
void step(
|
||||
double millisecondsSinceLastStep,
|
||||
SimulationGrid* input,
|
||||
SimulationGrid* output)
|
||||
SimulationGrid grid)
|
||||
{
|
||||
for (unsigned char x = 0; x < input->x_max; x++)
|
||||
for (unsigned char x = 0; x < grid.x_max; x++)
|
||||
{
|
||||
for (unsigned char y = 0; y < input->y_max; y++)
|
||||
for (unsigned char y = 0; y < grid.y_max; y++)
|
||||
{
|
||||
for (unsigned char z = 0; z < input->z_max; z++)
|
||||
for (unsigned char z = 0; z < grid.z_max; z++)
|
||||
{
|
||||
unsigned int offset = getCellOffset(x, y, z, input);
|
||||
unsigned int material = input->cells[offset];
|
||||
unsigned int offset = getCellOffset(x, y, z, grid);
|
||||
unsigned int material = grid.in[offset];
|
||||
switch (material)
|
||||
{
|
||||
case WATER:
|
||||
if (y > 0)
|
||||
{
|
||||
unsigned int downOffset = getCellOffset(x, y - 1, z, input);
|
||||
unsigned int downOffset = getCellOffset(x, y - 1, z, grid);
|
||||
// Flow down if cell is empty
|
||||
if (output->cells[downOffset] == 0)
|
||||
if (grid.out[downOffset] == 0)
|
||||
{
|
||||
output->cells[downOffset] = material;
|
||||
grid.out[downOffset] = material;
|
||||
}
|
||||
}
|
||||
default:
|
||||
output->cells[offset] = material;
|
||||
grid.out[offset] = material;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue