Skip to content

3.1. New world

This section explains how to create a new SyncWorld object.

Choosing a distribution

First, let's choose the std::unitless distribution with double precision, as explained in getting started:

// Choosing the Std Unitless distribution, with double precision
#include <gustave/distribs/std/unitless/Gustave.hpp>

using G = gustave::distribs::std::unitless::Gustave<double>;

We'll also define some type aliases:

using World = G::Worlds::SyncWorld;
using Solver = World::Solver;

Configuring a world

A SyncWorld can be created with these helper functions:

[[nodiscard]]
static Solver newSolver() {
    auto const g = G::vector3(0.f, -10.f, 0.f); // gravity acceleration (metre/second²).
    auto const solverPrecision = 0.01; // precision of the force balancer (here 1%).
    return Solver{ Solver::Config{ g, solverPrecision } };
}

[[nodiscard]]
static World newWorld() {
    auto blockSize = G::vector3(1.f, 1.f, 1.f); // block dimension (cube with 1m edge).
    return World{ blockSize, newSolver() };
}

Explanation:

  • newSolver(): configures the solver used by the world. See Solver API: configure a solver for more details.
  • blockSize: the dimensions of the blocks. Here each block is a 1 metre wide cube.

Usage

Running this test code:

auto world = newWorld();

std::cout << "Tutorial: creating a new SyncWorld.\n\n";

std::cout << "- number of blocks = " << world.blocks().size() << '\n';
std::cout << "- number of structures = " << world.structures().size() << '\n';

Should give the following output:

Tutorial: creating a new SyncWorld.

- number of blocks = 0
- number of structures = 0

world.blocks() and world.structures() are forward ranges which can be used to inspect the content of our world. As expected for an empty world, they have a size of 0.