Rudimentary gravity

This commit is contained in:
Johan Maasing 2025-01-27 20:29:50 +01:00
parent a2f1e11af8
commit d6b3be83d5
3 changed files with 56 additions and 32 deletions

View file

@ -2,16 +2,16 @@
#include <cstring>
#include "simulation.h"
void printGrid(simulation::SimulationGrid grid)
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 << 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++)
for (unsigned char x = 0; x < grid->x_max; x++)
{
unsigned int offset = simulation::getCellOffset(x, y-1, 0, grid);
unsigned int material = grid.out[offset];
unsigned int offset = getCellOffset(x, y-1, 0, grid);
unsigned int material = grid->out[offset];
switch (material)
{
case simulation::VACUUM:
@ -26,12 +26,12 @@ void printGrid(simulation::SimulationGrid grid)
}
std::cout << "|" << std::endl;
}
std::cout << std::string(grid.x_max+2, '_') << std::endl;
std::cout << std::string(grid->x_max+2, '_') << std::endl;
}
void initGrid(simulation::SimulationGrid grid) {
unsigned int offset = simulation::getCellOffset(0,1,0, grid);
grid.in[offset] = simulation::WATER;
void initGrid(simulation::SimulationGrid* grid) {
unsigned int offset = simulation::getCellOffset(0,2,0, grid);
grid->in[offset] = simulation::WATER;
}
int main() {
@ -50,11 +50,11 @@ int main() {
zMax
};
initGrid(grid);
step(0, grid);
initGrid(&grid);
for (int n=0; n< 2; n++) {
printGrid(grid);
simulation::step(0, &grid);
printGrid(&grid);
prepareForNextStep(&grid);
}
std::free(inCells);
std::free(outCells);