diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-07 18:35:32 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-07 18:35:32 +0100 |
commit | 80a1307e1e4c4f749d0d885c65c07b5508a73fac (patch) | |
tree | 7bc8a8c21262fa8d90dd938ccfc58971ca82c509 | |
parent | fdb4c99e139a264d4e15e6913a3756fc6cccb2f2 (diff) |
add update feature pages
-rw-r--r-- | src/doc/feature/script.dox | 42 | ||||
-rw-r--r-- | src/doc/feature/script_ecs.dox | 57 | ||||
-rw-r--r-- | src/doc/features.dox | 49 | ||||
-rw-r--r-- | src/doc/style.css | 27 |
4 files changed, 148 insertions, 27 deletions
diff --git a/src/doc/feature/script.dox b/src/doc/feature/script.dox index d25a63b..e3b5508 100644 --- a/src/doc/feature/script.dox +++ b/src/doc/feature/script.dox @@ -2,19 +2,14 @@ namespace crepe { /** -\defgroup feature_script Scripting +\defgroup feature_script Scripting basics \ingroup feature -\brief User-defined scripts for game objects +\brief Create a concrete Script and attach it to a GameObject Scripts can be used to implement game behavior, and allow arbitrary code to run as part of the game loop. Scripts are implemented as derivative classes of -Script, which are added to game objects using the BehaviorScript \ref Component -"component". - -\todo This section is incomplete: -- Utility functions to get components/events/etc inside script -- How to listen for events -- Extensions of script (keylistener) +Script, which are added to \ref GameObject "game objects" using the \ref +BehaviorScript \ref Component "component". \see Script \see BehaviorScript @@ -22,11 +17,14 @@ Script, which are added to game objects using the BehaviorScript \ref Component \par Example -First, define a class that inherits from Script. This class acts as an -interface, and has two functions (\ref Script::init "\c init()" and \ref -Script::update "\c update()"), which may be implemented (they are empty by -default). From now on, this derivative class will be referred to as a *concrete -script*. +\note This example assumes you already have a GameObject. If not, read +\"\ref feature_gameobject\" first. + +First, define a class (anywhere) that inherits from Script. The Script class +acts as an interface, and has two functions (\ref Script::init "\c init()" and +\ref Script::update "\c update()"), which *may* be implemented (they are empty +by default). From now on, this derivative class will be referred to as a +*concrete script*. ```cpp #include <crepe/api/Script.h> @@ -42,19 +40,23 @@ class MyScript : public crepe::Script { }; ``` -Concrete scripts can be instantiated and attached to \ref GameObject -"game objects" using the BehaviorScript \ref Component "component". +After defining a concrete script, it can be instantiated and attached to \ref +feature_gameobject "game objects" during \ref feature_scene +"scene initialization" using a BehaviorScript component: ```cpp using namespace crepe; -GameObject obj = component_manager.new_object("name"); +GameObject obj; -// create BehaviorScript instance +// Create a BehaviorScript component to hold MyScript BehaviorScript & behavior_script = obj.add_component<BehaviorScript>(); -// attach (and instantiate) MyScript to behavior_script + +// Instantiate (and attach) MyScript to behavior_script behavior_script.set_script<MyScript>(); +``` -// the above can also be done in a single call for convenience: +The above can also be done in a single call for convenience: +```cpp obj.add_component<BehaviorScript>().set_script<MyScript>(); ``` diff --git a/src/doc/feature/script_ecs.dox b/src/doc/feature/script_ecs.dox new file mode 100644 index 0000000..bbe1abc --- /dev/null +++ b/src/doc/feature/script_ecs.dox @@ -0,0 +1,57 @@ +// vim:ft=doxygen +namespace crepe { +/** + +\defgroup feature_script_ecs Using ECS inside Script +\ingroup feature +\brief Query the component manager inside a concrete Script + +Script provides several methods to request references to components during +runtime. These methods may be used in cases where it is either not practical or +impossible to manually pass the references required to implement a certain +behavior. + +\see Script +\see ComponentManager + +\par Example + +\note This example assumes you already have a concrete Script. If not, read +\"\ref feature_script\" first. + +The component manager can be queried for components inside Script using the +following methods: + +- For requesting components on the same GameObject as this Script instance: + - Script::get_component(): \copybrief Script::get_component + - Script::get_components(): \copybrief Script::get_components +- For requesting components in the current Scene: + - Script::get_components_by_id(): \copybrief Script::get_components_by_id + - Script::get_components_by_name(): \copybrief Script::get_components_by_name + - Script::get_components_by_tag(): \copybrief Script::get_components_by_tag + +```cpp +#include <crepe/util/Log.h> +#include <crepe/api/Script.h> +#include <crepe/api/Metadata.h> + +using namespace crepe; + +class MyScript : public Script { + void show_self() { + Metadata & own_metadata = get_component<Metadata>(); + Log::logf("My name is {}", own_metadata.name); + } + + void list_enemies() { + RefVector<Metadata> enemies = get_components_by_tag<Metadata>("enemy"); + Log::logf("There are {} enemies:", enemies.size()); + for (const Metadata & enemy : enemies) { + Log::logf("- {}", enemy.name); + } + } +}; +``` + +*/ +} diff --git a/src/doc/features.dox b/src/doc/features.dox index 21a040a..7d20ccb 100644 --- a/src/doc/features.dox +++ b/src/doc/features.dox @@ -3,8 +3,12 @@ \htmlonly <style> -table.memberdecls { display: none; } -ul { margin: 1ex 0pt; } +table.memberdecls, +.groupheader +{ display: none; } +ul, +li +{ margin: 1ex 0pt; } </style> \endhtmlonly @@ -14,15 +18,46 @@ ul { margin: 1ex 0pt; } This page lists engine features and contains usage instructions for each feature. -\par Features +- Basics + - \todo Hello world / engine initialization -- Scripting - - \ref feature_script \n\copybrief feature_script + - \todo Engine configuration options -- Game flow management +- Scenes - \ref feature_scene \n\copybrief feature_scene + - \todo Navigating between scenes -- Entity +- Input + - \todo Key/Mouse events (w/ Script) + +- Actors / game objects - \ref feature_gameobject \n\copybrief feature_gameobject +- \todo HUD + +- Animation + - \todo Animation using spritesheet + + - \todo Particle effects + +- Save data + - \todo SaveManager usage + +- Audio + - \todo Playing sound effects + + - \todo Adding background music to a scene + +- \todo AI + +- \todo Physics + +- Scripting + - \ref feature_script \n\copybrief feature_script + - \ref feature_script_ecs \n\copybrief feature_script_ecs + + - \todo Subscribing to *any* event inside Script + +- \todo Replay + */ diff --git a/src/doc/style.css b/src/doc/style.css index c12240c..efc669b 100644 --- a/src/doc/style.css +++ b/src/doc/style.css @@ -4,3 +4,30 @@ a[href="namespaces.html"] { display: none; } h2.groupheader { margin-top: revert; } + +dl { + padding: 4px 12px !important; + border-radius: 8px !important; + border: 0 !important; +} +dt { + margin-bottom: 0.5ex; +} + +a:hover { + text-decoration: revert !important; + background: unset !important; +} + +dl.section.see, +dl.section.user { + padding: 0 !important; + border-radius: 0 !important; + margin-top: 0; +} +dl.section.see dt, +dl.section.user dt { + font-size: 130%; + margin-bottom: 0.5ex; + margin-top: 1.5ex; +} |