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

Multiple worlds #17

Merged
merged 17 commits into from
Mar 15, 2024
Merged

Multiple worlds #17

merged 17 commits into from
Mar 15, 2024

Conversation

splashdust
Copy link
Owner

@splashdust splashdust commented Mar 10, 2024

Add support for multiple parallell world instances

Breaking changes:

Configuration is now supplied when adding the plugin

// First declare a config struct. It needs to derive `Resource`, `Clone` and `Default`
#[derive(Resource, Clone, Default)]
struct MyWorld;

// Then implement the `VoxelWorldConfig` trait for it:
impl VoxelWorldConfig for MyWorld {
    // All the trait methods have defaults, so you only need to add the ones you want to alter
    fn spawning_distance(&self) -> u32 {
       15
    }
}

Then when adding the plugin:

.add_plugins(VoxelWorldPlugin::with_config(MyWorld))

If you don't want to change any default config, you can simply do this:

.add_plugins(VoxelWorldPlugin::default())

Adding multiple worlds follows the same pattern. Just create different configuration structs and add a VoxelWorldPlugin for each.

.add_plugins(VoxelWorldPlugin::with_config(MyOtherWorld))

Each world instance can have it's own configuration and will keep track of it's own set of voxel data and chunks.

The VoxelWorld system param now needs a type parameter to specify which world instance you want to select

The configuration struct adds the config values and its type also acts as a marker for the world instance.

fn my_system(
  my_voxel_world: VoxelWorld<MyWorld>,
  my_other_voxel_world: VoxelWorld<MyOtherWorld>
) {
  // Set a voxel in `my_voxel_world`
  my_voxel_world.set_voxel(pos, WorldVoxel::Solid(voxel_type))

  // Set a voxel in `my_other_voxel_world`
  my_other_voxel_world.set_voxel(pos, WorldVoxel::Solid(voxel_type))
}

If you initialized the plugin with ::default(), you still need to explicitly specify the instance as DefaultWorld:

fn my_system(voxel_world: VoxelWorld<DefaultWorld>) { ... }

The VoxelWorldRaycast system param now also requires the same config type paramter as described above.

@splashdust splashdust marked this pull request as ready for review March 15, 2024 19:29
@splashdust splashdust merged commit 22e808e into main Mar 15, 2024
3 checks passed
@splashdust splashdust deleted the multiple_worlds branch March 15, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant