diff --git a/engine/samples/cars/components.hpp b/engine/samples/cars/components.hpp index 845b324e0..a8b385c42 100644 --- a/engine/samples/cars/components.hpp +++ b/engine/samples/cars/components.hpp @@ -3,7 +3,7 @@ #include /// [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; diff --git a/engine/samples/cars/main.cpp b/engine/samples/cars/main.cpp index b442eec30..e4007be0d 100644 --- a/engine/samples/cars/main.cpp +++ b/engine/samples/cars/main.cpp @@ -31,34 +31,24 @@ struct Spawner }; /// [Spawner resource] -/// [Set settings] static void settingsSystem(Write settings) { settings->setString("assets.io.path", SAMPLE_ASSETS_FOLDER); } -/// [Set settings] -/// [Load, add materials and set pallete] -static void setPalleteSystem(Write assets, Write renderer) +static void setPaletteAndCreateFloorSystem(Commands cmds, Write assets, Write 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) -{ - // 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) @@ -78,8 +68,8 @@ static void spawnFloorSystem(Commands cmds, Write 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) @@ -106,8 +96,8 @@ static void spawnLightSystem(Commands cmds) } /// [Spawn light] -/// [Spawn system] -static void spawnSystem(Commands cmds, Write spawner, Read deltaTime, Read assets) +/// [Spawn cars system] +static void spawnCarsSystem(Commands cmds, Write spawner, Read deltaTime, Read assets) { spawner->timer += deltaTime->value; if (spawner->timer >= 1.0F && spawner->y < 2) @@ -123,7 +113,7 @@ static void spawnSystem(Commands cmds, Write spawner, Read d .add(Rotation{}); spawner->timer = 0; - /// [Spawn system] + /// [Spawn cars system] spawner->x += 1; if (spawner->x == 2) { @@ -133,8 +123,8 @@ static void spawnSystem(Commands cmds, Write spawner, Read d } } -/// [Move system] -static void moveSystem(Query, Write, Write> query, Read deltaTime) +/// [Move cars system] +static void moveCarsSystem(Query, Write, Write> query, Read deltaTime) { for (auto [entity, car, position, rotation] : query) { @@ -145,14 +135,12 @@ static void moveSystem(Query, Write, Write> 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); @@ -164,14 +152,13 @@ int main(int argc, char** argv) cubos.addResource(); /// [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(); diff --git a/engine/samples/cars/output.png b/engine/samples/cars/output.png new file mode 100644 index 000000000..abfb29918 Binary files /dev/null and b/engine/samples/cars/output.png differ diff --git a/engine/samples/cars/page.md b/engine/samples/cars/page.md index 3238f9d52..ebb1be312 100644 --- a/engine/samples/cars/page.md +++ b/engine/samples/cars/page.md @@ -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 @@ -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.