R-Type 0.1
Loading...
Searching...
No Matches
Game engine

Main loop, ECS components and systems, scenes, event bus, entity factory, input mapping and backend concepts (lib/GameEngine). More...

Namespaces

namespace  rtk::factory
 Data driven entity creation.
 

Concepts

concept  rtk::Game
 Requirements for a type that GameEngine::run() can drive.
 
concept  rtk::SceneIdentifier
 Requirements for a type used to identify scenes, which must be an enum.
 
concept  rtk::Scene
 Requirements for a scene managed by rtk::SceneManager.
 
concept  rtk::ecs::concepts::IsAudioManager
 Requirements for the audio backend used by rtk::systems::AudioSystem.
 
concept  rtk::ecs::concepts::IsRenderWindow
 Requirements for the window backend used by the render and input systems.
 

Classes

struct  rtk::collision::Collision
 Pair of entities whose colliders overlap. More...
 
class  rtk::collision::CollisionBuffer
 Collisions detected during the current frame. More...
 
struct  component::AABBCollider
 Axis aligned bounding box used for collision detection. More...
 
struct  component::Animation
 Sprite sheet animation played by changing the texture rectangle. More...
 
struct  component::animationClip
 Sprite sheet frames played for one animation state. More...
 
struct  component::animator
 State machine that picks the Animation clip of an entity. More...
 
struct  component::Dead
 Tag marking an entity for destruction at the end of the frame. More...
 
struct  component::NetworkEntity
 Links a local entity to its replicated counterpart. More...
 
struct  component::Parallax
 Background layer that scrolls left and wraps around. More...
 
struct  component::SoundRequest
 Request to play a sound loaded in the audio manager. More...
 
struct  component::Transform
 Position, rotation and scale of an entity in world space. More...
 
struct  component::Velocity
 Linear speed of an entity. More...
 
struct  rtk::EngineContext
 Engine services handed to the game and its scenes. More...
 
class  busEvent
 Type indexed publish and subscribe event bus. More...
 
struct  rtype::events::ConnectedToServerEvent
 Published when the server accepted the handshake. More...
 
struct  rtype::events::ConnectionRejectedEvent
 Published when the server refused the handshake. More...
 
struct  rtype::events::SendPacketEvent
 Asks the network client to send raw bytes to the server. More...
 
struct  rtype::events::CreateEntityEvent
 Decoded CreateEntity message in world units. More...
 
class  rtk::factory::EntityFactory
 Builds entities from JSON blueprints and registered component builders. More...
 
class  rtk::GameEngine
 Owns the ECS world and runs the main loop of a game. More...
 
struct  rtk::InputState
 Player input sampled during the current frame. More...
 
struct  rtk::Input::AxisData
 Gamepad axis binding with its activation threshold. More...
 
struct  rtk::Input::InputBinding
 One physical control bound to an action. More...
 
class  rtk::Input::InputMapping
 Table binding up to four physical controls to each of 32 actions. More...
 
class  rtk::SceneManager< TSceneId, TDependency, TInput, TScenes >
 Holds the active scene and switches between a fixed set of scenes. More...
 
class  rtk::systems::AnimationSystem
 Advances sprite sheet animations and updates texture rectangles. More...
 
class  rtk::systems::AnimatorSystem
 Loads the clip of the current animator state into the Animation. More...
 
class  rtk::systems::AudioSystem< AudioType >
 Ticks the audio backend once per frame. More...
 
class  rtk::systems::ColliderSystem
 Detects overlapping colliders with a uniform spatial hash grid. More...
 
class  rtk::systems::DeathSystem
 Destroys every entity tagged with Dead. More...
 
class  rtk::systems::DebugCollisionSystem
 Draws collider outlines while the debug overlay is enabled. More...
 
class  rtk::systems::InputSystem< WindowType >
 Polls window events and turns bound controls into action bits. More...
 
class  rtk::systems::MovementSystem
 Moves entities according to their Velocity. More...
 
class  rtk::systems::ParallaxSystem
 Scrolls background layers and wraps them to loop endlessly. More...
 
class  rtk::ecs::concepts::Event
 Input query interface filled by the window backend. More...
 
struct  rtk::ecs::concepts::TextureRectU16
 Area of a texture, in texels. More...
 
struct  rtk::ecs::concepts::ColorRGBA8
 8-bit per channel color. More...
 
struct  rtk::ecs::concepts::SpriteData
 Everything the renderer needs to draw one sprite. More...
 
class  rtk::systems::RenderSystem< WindowType >
 Draws every entity that has a Transform and a SpriteData. More...
 
struct  utils::vec2
 Two dimensional vector of floats. More...
 

Typedefs

using rtk::ArchetypeID = std::uint16_t
 16-bit identifier of an entity blueprint, shared by client and server.
 

Enumerations

enum  Collider::CollisionLayer : std::uint32_t {
  Collider::Player = 1 << 0 , Collider::Enemy = 1 << 1 , Collider::PlayerProjectile = 1 << 2 , Collider::EnemyProjectile = 1 << 3 ,
  Collider::Environment = 1 << 4
}
 Bit flags naming the group a collider belongs to. More...
 
enum class  component::animState : uint8_t {
  animState::IDLE = 0 , animState::UP = 1 , animState::DOWN = 2 , animState::DIE = 3 ,
  animState::SHOOT = 4 , animState::COUNT = 5 , animState::NONE = 255
}
 Animation states an animator can switch between. More...
 
enum class  rtk::ecs::concepts::Key : uint16_t {
  Unknown = 0 , A , B , C ,
  D , E , F , G ,
  H , I , J , K ,
  L , M , N , O ,
  P , Q , R , S ,
  T , U , V , W ,
  X , Y , Z , Num0 ,
  Num1 , Num2 , Num3 , Num4 ,
  Num5 , Num6 , Num7 , Num8 ,
  Num9 , Escape , LControl , LShift ,
  LAlt , LSystem , RControl , RShift ,
  RAlt , RSystem , Menu , LBracket ,
  RBracket , Semicolon , Comma , Period ,
  Quote , Slash , Backslash , Tilde ,
  Equal , Hyphen , Space , Enter ,
  Backspace , Tab , PageUp , PageDown ,
  End , Home , Insert , Delete ,
  Add , Subtract , Multiply , Divide ,
  Left , Right , Up , Down ,
  Numpad0 , Numpad1 , Numpad2 , Numpad3 ,
  Numpad4 , Numpad5 , Numpad6 , Numpad7 ,
  Numpad8 , Numpad9 , F1 , F2 ,
  F3 , F4 , F5 , F6 ,
  F7 , F8 , F9 , F10 ,
  F11 , F12 , F13 , F14 ,
  F15 , KeyCount = 256
}
 Keyboard keys, mirroring the values of the graphical library.
 
enum class  rtk::ecs::concepts::MouseButton : uint16_t { Left = 0 , Right = 1 , Middle = 2 , ButtonCount = 3 }
 Mouse buttons.
 
enum class  rtk::ecs::concepts::GamepadButton : uint16_t {
  Unknown = 0 , A , B , X ,
  Y , Cross = A , Circle = B , Square = X ,
  Triangle = Y , L1 , R1 , L2 ,
  R2 , Select , Start , L3 ,
  R3 , DpadUp , DpadDown , DpadLeft ,
  DpadRight , Home , ButtonCount
}
 Gamepad buttons, with PlayStation style aliases.
 
enum class  rtk::ecs::concepts::GamepadAxis : uint16_t {
  LeftX = 0 , LeftY , RightX , RightY ,
  L2 , R2 , AxisCount
}
 Gamepad analog axes.
 

Functions

std::uint32_t component::stringToLayer (const std::string &name)
 Converts a layer name to its bit flag.
 
void component::aabbColliderFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds an AABBCollider to an entity from its blueprint data.
 
void component::animationFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds an Animation to an entity from its blueprint data.
 
animState component::stringToAnimState (const std::string &stateStr)
 Converts a state name to an animState.
 
void component::animatorFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds an animator to an entity from its blueprint data.
 
void component::deadFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &)
 Adds a Dead tag to an entity from its blueprint data.
 
void component::networkEntityFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds a NetworkEntity to an entity from its blueprint data.
 
void component::parallaxFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds a Parallax to an entity from its blueprint data.
 
void component::soundRequestFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds a SoundRequest to an entity from its blueprint data.
 
void component::transformFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds a Transform to an entity from its blueprint data.
 
void component::velocityFromJson (rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
 Adds a Velocity to an entity from its blueprint data.
 
constexpr ArchetypeID rtk::hashArchetype (std::string_view name) noexcept
 Hashes a blueprint name to its archetype id.
 

Detailed Description

Main loop, ECS components and systems, scenes, event bus, entity factory, input mapping and backend concepts (lib/GameEngine).

See Game engine for an overview.

Enumeration Type Documentation

◆ CollisionLayer

enum Collider::CollisionLayer : std::uint32_t

Bit flags naming the group a collider belongs to.

Enumerator
Player 

Player ships.

Enemy 

Bydos enemies.

PlayerProjectile 

Missiles fired by players.

EnemyProjectile 

Missiles fired by enemies.

Environment 

Stage walls and obstacles.

◆ animState

enum class component::animState : uint8_t
strong

Animation states an animator can switch between.

Enumerator
IDLE 

Default state.

UP 

Moving up.

DOWN 

Moving down.

DIE 

Dying.

SHOOT 

Shooting.

COUNT 

Number of states.

NONE 

No state, forces the next clip to load.

Function Documentation

◆ stringToLayer()

std::uint32_t component::stringToLayer ( const std::string & name)
inline

Converts a layer name to its bit flag.

Parameters
nameLayer name, such as Player or Environment.
Returns
The layer flag, or 0 if the name is unknown.

◆ aabbColliderFromJson()

void component::aabbColliderFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds an AABBCollider to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with size, offset, layer name and mask names.

◆ animationFromJson()

void component::animationFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds an Animation to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object whose keys match the Animation fields.

◆ stringToAnimState()

animState component::stringToAnimState ( const std::string & stateStr)
inline

Converts a state name to an animState.

Parameters
stateStrState name, such as UP or DIE.
Returns
The matching state, or IDLE if the name is unknown.

◆ animatorFromJson()

void component::animatorFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds an animator to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with currentState and a clips object per state.

◆ deadFromJson()

void component::deadFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json &  )
inline

Adds a Dead tag to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.

◆ networkEntityFromJson()

void component::networkEntityFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds a NetworkEntity to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with optional id and archetypeId fields.

◆ parallaxFromJson()

void component::parallaxFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds a Parallax to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with optional speedX and loopWidth fields.

◆ soundRequestFromJson()

void component::soundRequestFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds a SoundRequest to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with an optional soundId field.

◆ transformFromJson()

void component::transformFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds a Transform to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with position, rotation and scale.

◆ velocityFromJson()

void component::velocityFromJson ( rtk::ecs::Registry & reg,
std::size_t entity,
const nlohmann::json & data )
inline

Adds a Velocity to an entity from its blueprint data.

Parameters
regRegistry owning the entity.
entityTarget entity.
dataJSON object with optional x and y fields.

◆ hashArchetype()

ArchetypeID rtk::hashArchetype ( std::string_view name)
constexprnoexcept

Hashes a blueprint name to its archetype id.

Computes the 32-bit FNV-1a hash of the name and folds it to 16 bits with (hash >> 16) ^ (hash & 0xFFFF).

Parameters
nameBlueprint name.
Returns
The archetype id.