Notice that we don't include the None type in the trait, as it doesn't correspond to a bit.
intmain()
+{
+usingcubos::core::reflection::reflect;
+
+constauto&permissionsType=reflect<Permissions>();
+CUBOS_ASSERT(permissionsType.has<MaskTrait>());
+
+constauto&mask=permissionsType.get<MaskTrait>();
+CUBOS_ASSERT(mask.contains("Read"));
+CUBOS_ASSERT(mask.contains("Write"));
+CUBOS_ASSERT(mask.contains("Execute"));
+CUBOS_ASSERT(!mask.contains("None"));
+
+autop=Permissions::Read|Permissions::Write;
+CUBOS_ASSERT(mask.view(&p).test("Read"));
+CUBOS_ASSERT(mask.view(&p).test("Write"));
+CUBOS_ASSERT(!mask.view(&p).test("Execute"));
+
+for(constauto&b:mask)
+{
+CUBOS_INFO("Type has bit {}",b.name());
+}
+
+for(constauto&b:mask.view(&p))
+{
+CUBOS_INFO("Value has bit {} set",b.name());
+}
+
+return0;
+}
// Type has bit "Read"
+// Type has bit "Write"
+// Type has bit "Execute"
+// Value has bit "Read" set
+// Value has bit "Write" set
+
+
+
+
+
+
+
+
+
+
+
Tab / T to search, Esc to close
+
…
+
+
+
+
+
+
Search for symbols, directories, files, pages or
+ modules. You can omit any prefix from the symbol or file path; adding a
+ : or / suffix lists all members of given symbol or
+ directory.
+
Use ↓
+ / ↑ to navigate through the list,
+ Enter to go.
+ Tab autocompletes common prefix, you can
+ copy a link to the result using ⌘
+ L while ⌘
+ M produces a Markdown link.
There are two types of bindings: actions and axes. An action is an input that only has two states: pressed or not pressed. This would be most keys on a keyboard. An axe is an input that has a numeric value. For example, the joysticks on a controller can go from -1 to 1, depending on how much they are tilt in which direction. Using axes can also be useful for keys with symetric behaviour. For example, in this sample, w sets the vertical axe to 1, while s sets it to -1.
To define an action or an axe, you simply have to add it to the respective list, giving it a name. The very first action in the file is called next-showcase. Then, if it's an action, you simply have to define which keys trigger it. You can also define key combinations by using a -. To check which strings map to which keys, you check the keyToString function implementation on this file.
Now that we have our bindings file, let's get our application to do something with it. The first thing we're going to need is a reference to the bindings asset. For the purposes of this sample we can simply use an hardcoded reference to the asset.
To utilize the bindings, loading them is essential. This can be accomplished by establishing a startup systems which reads from the asset and sets the required bindings.
cubos.startupSystem("load and set the Input Bindings")
+}
There are two types of bindings: actions and axes. An action is an input that only has two states: pressed or not pressed. This would be most keys on a keyboard. An axe is an input that has a numeric value. For example, the joysticks on a controller can go from -1 to 1, depending on how much they are tilt in which direction. Using axes can also be useful for keys with symmetric behaviour. For example, in this sample, W sets the vertical axe to 1, while S sets it to -1.
To define an action or an axe, you simply have to add it to the respective list, giving it a name. The very first action in the file is called next-showcase. Then, if it's an action, you simply have to define which keys trigger it. You can also define key combinations by using a -. To check which strings map to which keys, you check the names of the variants of the enums Key and Modifier on this file.
Now that we have our bindings file, let's get our application to do something with it. The first thing we're going to need is a reference to the bindings asset. For the purposes of this sample we can simply use an hardcoded reference to the asset.
To utilize the bindings, loading them is essential. This can be accomplished by establishing a startup systems which reads from the asset and sets the required bindings.
cubos.startupSystem("load and set the Input Bindings").tagged("cubos.assets").call([](constAssets&assets,Input&input){autobindings=assets.read<InputBindings>(BindingsAsset);
@@ -198,7 +183,7 @@
{CUBOS_INFO("Shift");}
-}
Getting modified input (such as with a CTRL or a SHIFT hold) is no different from getting non-modified input, just make sure the binding for it is defined in the Bindings asset.
Getting modified input (such as with a Control or a Shift hold) is no different from getting non-modified input, just make sure the binding for it is defined in the Bindings asset.
Reading mouse buttons is also supported, just bind them to an action, and then call Input::pressed as usual. To check which strings map to which buttons, you check the mouseButtonToString function implementation on this file.
+}
Reading mouse buttons is also supported, just bind them to an action, and then call Input::pressed as usual. To check which strings map to which buttons, you check the names of the variants of the enum MouseButton on this file.
This file imports the asset with id cd007ba2-ee0d-44fd-bf36-85c829dbe66f, which is the scene we looked at in the previous file, under the name sub1. It then imports the very same scene again, but this time with the name sub2 instead. This effectively instantiates the entities of the previous scene twice in this new scene, each with their names prefixed with either sub1. or sub2.
Also take a look at the DistanceTo relation: it is a symmetric relation, so it doesn't make a different whether wwe put it in sub.root or sub2.root. Since DistanceTo is a relation which holds data, instead of only specifying the target, as we do with OwnedBy, we write a JSON object with a key, "value".
Under entities, we can override the entities in the sub-scenes to edit components or add new ones. For example, by referencing sub1.root we are making local changes to the root entity of that instance of the subscene. The result of the changes we make to both sub1.root and sub2.root is that the owner of these entities will be set to be the main entity.
Now that we have our scene file, let's get our application to load it. The first thing we're going to need is a reference to the scene asset. For the purposes of this sample we can simply use an hardcoded reference to the asset.
Then we'll need a system that spawns that scene. To do this we simply get the Scene object from the asset, and then spawn its entities. Commands::spawn will create in the world a copy of every entity defined in the scene's blueprint. It won't remove the entities already there, so if you want to close a scene, you'll have to do it yourself.
cubos.startupSystem("spawn the scene")
+}
This file imports the asset with id cd007ba2-ee0d-44fd-bf36-85c829dbe66f, which is the scene we looked at in the previous file, under the name sub1. It then imports the very same scene again, but this time with the name sub2 instead. This effectively instantiates the entities of the previous scene twice in this new scene, each with their names prefixed with either sub1. or sub2.
Also take a look at the DistanceTo relation: it is a symmetric relation, so it doesn't make a different whether wwe put it in sub.root or sub2.root. Since DistanceTo is a relation which holds data, instead of only specifying the target, as we do with OwnedBy, we write a JSON object with a key, "value".
Under entities, we can override the entities in the sub-scenes to edit components or add new ones. For example, by referencing sub1.root we are making local changes to the root entity of that instance of the subscene. The result of the changes we make to both sub1.root and sub2.root is that the owner of these entities will be set to be the main entity.
Now that we have our scene file, let's get our application to load it. The first thing we're going to need is a reference to the scene asset. For the purposes of this sample we can simply use an hardcoded reference to the asset.
Then we'll need a system that spawns that scene. To do this we simply get the Scene object from the asset, and then spawn its entities. Commands::spawn will create in the world a copy of every entity defined in the scene's blueprint. It won't remove the entities already there, so if you want to close a scene, you'll have to do it yourself.
cubos.startupSystem("spawn the scene").tagged("spawn").tagged("cubos.assets").call([](Commandscommands,constAssets&assets){autosceneRead=assets.read(SceneAsset);
-commands.spawn(sceneRead->blueprint,true);
+commands.spawn(sceneRead->blueprint);});
In this case, we'll run this system at startup, since we want to spawn it a single time. Since it's a startup system, we'll have to tag it with cubos.assets to make sure it runs only after the scene bridge has been registered. On a real game, you could have, for example, a scene for an enemy which you spawn multiple times, instead of just once at startup.
cubos.startupSystem("print the scene").after("spawn").call([](Query<Entity,constNum&>numQuery,Query<constOwnedBy&,Entity>ownedByQuery,
diff --git a/docs-preview/pr-954/files.html b/docs-preview/pr-954/files.html
index 648ca7cb4..d3b91178d 100644
--- a/docs-preview/pr-954/files.html
+++ b/docs-preview/pr-954/files.html
@@ -231,7 +231,9 @@
Search for symbols, directories, files, pages or
+ modules. You can omit any prefix from the symbol or file path; adding a
+ : or / suffix lists all members of given symbol or
+ directory.
+
Use ↓
+ / ↑ to navigate through the list,
+ Enter to go.
+ Tab autocompletes common prefix, you can
+ copy a link to the result using ⌘
+ L while ⌘
+ M produces a Markdown link.
This plugins exists to reduce coupling between plugins. For example, a plugin which allows selecting entities through a ImGui window only needs to depend on this plugin, instead of having to know about all the plugins which care about it. The same applies in the other direction.
This plugins exists to reduce coupling between plugins. For example, a plugin which allows selecting entities through a ImGui window only needs to depend on this plugin, instead of having to know about all the plugins which care about it. The same applies in the other direction.
Search for symbols, directories, files, pages or
+ modules. You can omit any prefix from the symbol or file path; adding a
+ : or / suffix lists all members of given symbol or
+ directory.
+
Use ↓
+ / ↑ to navigate through the list,
+ Enter to go.
+ Tab autocompletes common prefix, you can
+ copy a link to the result using ⌘
+ L while ⌘
+ M produces a Markdown link.