Skip to content

Commit

Permalink
docs(engine): cleanup and remove irrelevant documentation from cars s…
Browse files Browse the repository at this point in the history
…ample
  • Loading branch information
fallenatlas committed Sep 9, 2023
1 parent 0f4734b commit 4d00b1a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion engine/samples/cars/components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <glm/glm.hpp>

/// [Car component]
struct [[cubos::component("car", VecStorage)]] Car
struct [[cubos::component("car")]] Car
{
glm::vec3 vel = {1.0f, 0.0f, 0.0f};
float angVel = 1.0f;
Expand Down
47 changes: 17 additions & 30 deletions engine/samples/cars/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,24 @@ struct Spawner
};
/// [Spawner resource]

/// [Set settings]
static void settingsSystem(Write<Settings> settings)
{
settings->setString("assets.io.path", SAMPLE_ASSETS_FOLDER);
}
/// [Set settings]

/// [Load, add materials and set pallete]
static void setPalleteSystem(Write<Assets> assets, Write<Renderer> renderer)
static void setPaletteAndCreateFloorSystem(Commands cmds, Write<Assets> assets, Write<Renderer> renderer)
{
/// [Load, add materials and set palette]
// Load the palette asset and add two colors to it.
auto palette = assets->write(PaletteAsset);
palette->add({{0.1F, 0.1F, 0.1F, 1.0F}});
palette->add({{0.9F, 0.9F, 0.9F, 1.0F}});
auto black = palette->add({{0.1F, 0.1F, 0.1F, 1.0F}});
auto white = palette->add({{0.9F, 0.9F, 0.9F, 1.0F}});

// Set the renderer's palette to the one we just modified.
(*renderer)->setPalette(*palette);
}
/// [Load, add materials and set pallete]

/// [Create and spawn floor]
static void spawnFloorSystem(Commands cmds, Write<Assets> assets)
{
// Get the materials previously added to the palette
auto palette = assets->read(PaletteAsset);
auto black = palette->find({{0.1F, 0.1F, 0.1F, 1.0F}});
auto white = palette->find({{0.9F, 0.9F, 0.9F, 1.0F}});
/// [Load, add materials and set palette]

/// [Create and spawn floor]
// Generate a new grid asset for the floor.
auto floorGrid = Grid({256, 1, 256});
for (int x = 0; x < 256; ++x)
Expand All @@ -78,8 +68,8 @@ static void spawnFloorSystem(Commands cmds, Write<Assets> assets)
.add(RenderableGrid{floorAsset, floorOffset})
.add(LocalToWorld{})
.add(Scale{4.0F});
/// [Create and spawn floor]
}
/// [Create and spawn floor]

/// [Spawn camera]
static void spawnCameraSystem(Commands cmds, Write<ActiveCameras> activeCameras)
Expand All @@ -106,8 +96,8 @@ static void spawnLightSystem(Commands cmds)
}
/// [Spawn light]

/// [Spawn system]
static void spawnSystem(Commands cmds, Write<Spawner> spawner, Read<DeltaTime> deltaTime, Read<Assets> assets)
/// [Spawn cars system]
static void spawnCarsSystem(Commands cmds, Write<Spawner> spawner, Read<DeltaTime> deltaTime, Read<Assets> assets)
{
spawner->timer += deltaTime->value;
if (spawner->timer >= 1.0F && spawner->y < 2)
Expand All @@ -123,7 +113,7 @@ static void spawnSystem(Commands cmds, Write<Spawner> spawner, Read<DeltaTime> d
.add(Rotation{});

spawner->timer = 0;
/// [Spawn system]
/// [Spawn cars system]
spawner->x += 1;
if (spawner->x == 2)
{
Expand All @@ -133,8 +123,8 @@ static void spawnSystem(Commands cmds, Write<Spawner> spawner, Read<DeltaTime> d
}
}

/// [Move system]
static void moveSystem(Query<Write<Car>, Write<Position>, Write<Rotation>> query, Read<DeltaTime> deltaTime)
/// [Move cars system]
static void moveCarsSystem(Query<Write<Car>, Write<Position>, Write<Rotation>> query, Read<DeltaTime> deltaTime)
{
for (auto [entity, car, position, rotation] : query)
{
Expand All @@ -145,14 +135,12 @@ static void moveSystem(Query<Write<Car>, Write<Position>, Write<Rotation>> query
rotation->quat = glm::angleAxis(deltaTime->value * car->angVel, glm::vec3(0.0F, 1.0F, 0.0F)) * rotation->quat;
}
}
/// [Move system]
/// [Move cars system]

int main(int argc, char** argv)
{
Cubos cubos{argc, argv};
/// [Adding the env settings plugin]
cubos.addPlugin(envSettingsPlugin);
/// [Adding the env settings plugin]

/// [Adding the render and voxels plugin]
cubos.addPlugin(rendererPlugin);
Expand All @@ -164,14 +152,13 @@ int main(int argc, char** argv)
cubos.addResource<Spawner>();
/// [Adding component and resource]

/// [Adding systems]
cubos.startupSystem(settingsSystem).tagged("cubos.settings");
cubos.startupSystem(setPalleteSystem).tagged("palette.set").after("cubos.renderer.init");
cubos.startupSystem(spawnFloorSystem).after("palette.set");
/// [Adding systems]
cubos.startupSystem(setPaletteAndCreateFloorSystem).after("cubos.renderer.init");
cubos.startupSystem(spawnCameraSystem);
cubos.startupSystem(spawnLightSystem);
cubos.system(spawnSystem);
cubos.system(moveSystem);
cubos.system(spawnCarsSystem);
cubos.system(moveCarsSystem);
/// [Adding systems]

cubos.run();
Expand Down
Binary file added engine/samples/cars/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 5 additions & 11 deletions engine/samples/cars/page.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# Cars {#examples-engine-cars}

@brief Sample that spawns multiple assets and updates them every frame.
@brief Loading voxel grids and rendering them.

This example shows how the @ref renderer-plugin plugin, @ref voxels-plugin plugin and @ref env-settings-plugin, can be used in a scene to spawn and move assets.
This example shows how the @ref renderer-plugin plugin and @ref voxels-plugin plugin, can be used to load and render voxel objects.

The first thing we're going to worry about is setting up the path for the assets we're going to use in our settings resource. In this example, the path is set in a macro defined in a CMakeLists.txt file but you can give it the path directly as a string.
![](cars/output.png)

@snippet cars/main.cpp Set settings

Alternatively, the path can be set from the command line arguments given when starting cubos. For this we need the @ref env-settings-plugin, included from the @ref engine/env_settings/plugin.hpp header.

@snippet cars/main.cpp Adding the env settings plugin

Each asset has an id through which we can get a handle to it. This id is specified in the .meta file associated to the asset.
Lets start by getting the assets we want to use. Each asset has an id through which we can get a handle to it. This id is specified in the .meta file associated to the asset.

@snippet cars/main.cpp Get handles to assets

Expand All @@ -24,7 +18,7 @@ We'll need to render and load assets.

In our assets folder we already have a palette, let's load it and give it some more colors.

@snippet cars/main.cpp Load, add materials and set pallete
@snippet cars/main.cpp Load, add materials and set palette

Now, let's give our scene a floor. To achieve this, we'll create a grid, assign one of the materials we added to the pallete to each voxel of that grid and then spawn it.

Expand Down

0 comments on commit 4d00b1a

Please sign in to comment.