Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random world generator with non-uniform child cube depth #519

Open
IAmNotHanni opened this issue Jan 1, 2023 · 2 comments
Open

Random world generator with non-uniform child cube depth #519

IAmNotHanni opened this issue Jan 1, 2023 · 2 comments
Labels
diff:first issue good first issue to start contributing feat:octree octree, cube computations

Comments

@IAmNotHanni
Copy link
Member

IAmNotHanni commented Jan 1, 2023

Is your feature request related to a problem?

The current implementation of our random world generator is fine, but it creates only octrees which have uniform depth in all child cubes:

std::shared_ptr<Cube> create_random_world(const float size, const std::uint32_t max_depth,
                                          const glm::vec3 &pos, const std::optional<std::uint32_t> seed) {
    static std::random_device rd;
    std::mt19937 mt(seed ? *seed : rd());
    std::uniform_int_distribution<std::uint32_t> indent(0, 44);
    std::uniform_int_distribution<std::uint32_t> cube_type(0, 100);

    std::shared_ptr<Cube> cube = std::make_shared<Cube>(size, pos);
    cube->set_type(Cube::Type::OCTANT);
    std::function<void(const Cube &, std::uint32_t)> populate_cube = [&](const Cube &parent, std::uint32_t depth) {
        for (const auto &child : parent.get_children()) {
            if (depth != max_depth) {
                child->set_type(Cube::Type::OCTANT);
                populate_cube(*child, depth + 1);
                continue;
            }
            const auto ty = cube_type(mt);
            if (ty < 30) {
                child->set_type(Cube::Type::EMPTY);
                continue;
            }
            if (ty < 60) {
                child->set_type(Cube::Type::SOLID);
                continue;
            }
            if (ty < 100) {
                child->set_type(Cube::Type::NORMAL);
                for (int i = 0; i < 12; i++) {
                    child->set_indent(i, Indentation(indent(mt)));
                }
                continue;
            }
        }
    };
    populate_cube(*cube, 0);
    return cube;
}

An example can be seen in the following screenshot: The root cube is an octant, meaning that it has 8 child cubes. Each child itself is an octant as well, although some could be empty, solid, or normal cube types instead. The leaf cubes however are all either solid, empty, or normal cubes:

image

We should implement a random world generator where the decision to go deeper in the cube node hierarchy should be randomized as well. We should discuss if we want to keep both functions in cube.hpp though or if we want to make a separate header file just for that.

Description

create_random_world creates a random world which is nice for quick testing.

Alternatives

none

Affected Code

The octree code

Operating System

All operating systems

Additional Context

No response

@IAmNotHanni IAmNotHanni added diff:first issue good first issue to start contributing feat:octree octree, cube computations labels Jan 1, 2023
@IceflowRE
Copy link
Member

I would add a parameter probably.
Also this implementation was by choice so we have a maximum of cubes.

@IAmNotHanni
Copy link
Member Author

Good idea. This way we don't to write another additional method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diff:first issue good first issue to start contributing feat:octree octree, cube computations
Projects
None yet
Development

No branches or pull requests

2 participants