Skip to content

Commit

Permalink
docs(engine): document and cleanup Hello Cubos sample
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoMendonc-a committed Sep 27, 2023
1 parent 3948aad commit 9b4d4ed
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 68 deletions.
1 change: 1 addition & 0 deletions docs/pages/3_examples/2_engine/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The following examples have fully documented tutorials on how to use the
multiple plugins of the engine:

- @subpage examples-engine-hello-cubos - @copybrief examples-engine-hello-cubos
- @subpage examples-engine-settings - @copybrief examples-engine-settings
- @subpage examples-engine-renderer - @copybrief examples-engine-renderer
- @subpage examples-engine-scene - @copybrief examples-engine-scene
3 changes: 2 additions & 1 deletion engine/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ macro(make_sample)

# Get the source files
set(sources "${CMAKE_CURRENT_SOURCE_DIR}/${MAKE_SAMPLE_DIR}/main.cpp")

foreach(source IN LISTS MAKE_SAMPLE_SOURCES)
list(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/${MAKE_SAMPLE_DIR}/${source}")
endforeach()
Expand All @@ -36,9 +37,9 @@ macro(make_sample)
endmacro()

# Add samples
make_sample(DIR "hello-cubos")
make_sample(DIR "settings")
make_sample(DIR "events")
make_sample(DIR "systems")
make_sample(DIR "input" ASSETS)
make_sample(DIR "assets/json" ASSETS)
make_sample(DIR "assets/bridge" ASSETS)
Expand Down
45 changes: 45 additions & 0 deletions engine/samples/hello-cubos/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cubos/engine/cubos.hpp>

/// [Hello Cubos]
void sayHelloCubos()
{
CUBOS_INFO("Hello CUBOS");
}
/// [Hello Cubos]

/// [Hello World]
void sayHello()
{
CUBOS_INFO("Hello");
}

void sayWorld()
{
CUBOS_INFO("World");
}
/// [Hello World]

int main()
{
/// [Engine]
cubos::engine::Cubos cubos;
/// [Engine]

/// [Tags]
cubos.tag("exampleTagA").before("exampleTagB");
cubos.startupTag("exampleTagB");
/// [Tags]

/// [Set Startup]
cubos.startupSystem(sayHelloCubos);
/// [Set Startup]

/// [Set Systems]
cubos.system(sayHello);
cubos.system(sayWorld);
/// [Set Systems]

/// [Run]
cubos.run();
/// [Run]
}
50 changes: 50 additions & 0 deletions engine/samples/hello-cubos/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Settings {#examples-engine-hello-cubos}

@brief Using @ref cubos::engine::Cubos to create a simple program.

This example shows the basics of how @ref cubos::engine::Cubos is used, by making a simple "Hello World" program.

The first thing we'll need to do is get the engine itself.

@snippet hello-cubos/main.cpp Engine

The @ref cubos::engine::Cubos class represents the engine.
We'll need it to add functionality to our program.

Let's start by defining what functionality we want to add.

@snippet hello-cubos/main.cpp Hello Cubos

This function simply prints `Hello CUBOS` to the console.
It uses one of CUBOS.'s logging macros.
You can find more about them @ref core\include\cubos\core\log.hpp "here".
However, this function is not currently called, so we'll need to tell CUBOS. that we want it to run.

@snippet hello-cubos/main.cpp Set Startup

Startup systems run only once when the engine is loaded.
Now let's make things more interesting.
Let's print `Hello World` every single frame.
And let's also split it over two different systems.

@snippet hello-cubos/main.cpp Hello World

Instead of using `startupSystem`, we'll use @ref cubos::engine::Cubos::system .
This means the systems will be called every cycle, instead of just once at startup.
However, we can't just do as we did for `sayHelloCubos` and call it a day.
We want `sayHello` to come before `sayWorld`, so we'll have to explicitly tell that to the engine, or else we risk having them in the wrong order.
To do that we use tags.
Let's create two tags, one for each system.

@snippet hello-cubos/main.cpp Tags

@ref cubos::engine::Cubos::tag creates a new tag, and @ref cubos::engine::TagBuilder::before makes any systems tagged with it come before systems tagged with the one given as parameter.
There's also a @ref cubos::engine::TagBuilder::after that has the inverse effect.
Now all we have to do is to assign these tags to our systems.
@note If we wanted to give these tags to a system running on startup, we'd have to use @ref cubos::engine::Cubos::startupTag instead.

@snippet hello-cubos/main.cpp Set Systems

With everything properly set up, all that remains is to run the engine.

@snippet hello-cubos/main.cpp Run
67 changes: 0 additions & 67 deletions engine/samples/systems/main.cpp

This file was deleted.

0 comments on commit 9b4d4ed

Please sign in to comment.