-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(engine): document and cleanup Hello Cubos sample
- Loading branch information
1 parent
3948aad
commit 9b4d4ed
Showing
5 changed files
with
98 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.