54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include <iostream>
|
|
#include <cstring>
|
|
#include "simulation.h"
|
|
|
|
void printGrid(simulation::SimulationGrid* grid)
|
|
{
|
|
std::cout << std::string(grid->x_max+2, '_') << std::endl;
|
|
for (unsigned char y = grid->y_max; y > 0; y--)
|
|
{
|
|
std::cout << "|";
|
|
for (unsigned char x = 0; x < grid->x_max; x++)
|
|
{
|
|
unsigned int offset = simulation::getCellOffset(x, y-1, 0, grid);
|
|
unsigned int material = grid->cells[offset];
|
|
switch (material)
|
|
{
|
|
case simulation::VACUUM:
|
|
std::cout << " ";
|
|
break;
|
|
case simulation::WATER:
|
|
std::cout << "~";
|
|
break;
|
|
default:
|
|
std::cout << "?";
|
|
}
|
|
}
|
|
std::cout << "|" << std::endl;
|
|
}
|
|
std::cout << std::string(grid->x_max+2, '_') << std::endl;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
unsigned char xMax = 50;
|
|
unsigned char yMax = 20;
|
|
unsigned char zMax = 1;
|
|
size_t bufferSizeInBytes = sizeof(unsigned int) * xMax * yMax * zMax;
|
|
auto inCells = static_cast<unsigned int*>(std::malloc(bufferSizeInBytes));
|
|
std::memset(inCells, 0, bufferSizeInBytes);
|
|
auto outCells = static_cast<unsigned int*>(std::malloc(bufferSizeInBytes));
|
|
simulation::SimulationGrid inGrid = {
|
|
inCells, xMax, yMax, zMax
|
|
};
|
|
simulation::SimulationGrid outGrid = {
|
|
outCells, xMax, yMax, zMax
|
|
};
|
|
|
|
step(0, &inGrid, &outGrid);
|
|
|
|
printGrid(&outGrid);
|
|
std::free(inCells);
|
|
std::free(outCells);
|
|
return 0;
|
|
}
|