VoxelSim/main.cpp

63 lines
1.7 KiB
C++
Raw Permalink Normal View History

2025-01-26 07:38:56 +01:00
#include <iostream>
#include <cstring>
#include "simulation.h"
2025-01-27 20:29:50 +01:00
void printGrid(simulation::SimulationGrid* grid)
2025-01-26 07:38:56 +01:00
{
2025-01-27 20:29:50 +01:00
std::cout << std::string(grid->x_max+2, '_') << std::endl;
for (unsigned char y = grid->y_max; y > 0; y--)
2025-01-26 07:38:56 +01:00
{
std::cout << "|";
2025-01-27 20:29:50 +01:00
for (unsigned char x = 0; x < grid->x_max; x++)
2025-01-26 07:38:56 +01:00
{
2025-01-27 20:29:50 +01:00
unsigned int offset = getCellOffset(x, y-1, 0, grid);
unsigned int material = grid->out[offset];
2025-01-26 07:38:56 +01:00
switch (material)
{
case simulation::VACUUM:
std::cout << " ";
break;
case simulation::WATER:
std::cout << "~";
break;
default:
std::cout << "?";
}
}
std::cout << "|" << std::endl;
}
2025-01-27 20:29:50 +01:00
std::cout << std::string(grid->x_max+2, '_') << std::endl;
2025-01-26 07:38:56 +01:00
}
2025-01-27 20:29:50 +01:00
void initGrid(simulation::SimulationGrid* grid) {
unsigned int offset = simulation::getCellOffset(0,2,0, grid);
grid->in[offset] = simulation::WATER;
2025-01-26 20:07:57 +01:00
}
int main() {
2025-01-26 07:38:56 +01:00
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));
2025-01-26 20:07:57 +01:00
simulation::SimulationGrid grid = {
inCells,
outCells,
xMax,
yMax,
zMax
2025-01-26 07:38:56 +01:00
};
2025-01-27 20:29:50 +01:00
initGrid(&grid);
2025-01-26 20:07:57 +01:00
for (int n=0; n< 2; n++) {
2025-01-27 20:29:50 +01:00
simulation::step(0, &grid);
printGrid(&grid);
prepareForNextStep(&grid);
2025-01-26 20:07:57 +01:00
}
2025-01-26 07:38:56 +01:00
std::free(inCells);
std::free(outCells);
return 0;
}