Skip to content

Components

Imagment edited this page Mar 27, 2025 · 3 revisions

Anyone can contribute to this wiki, so please feel free to correct any mistakes and add missing information! Silver C++ is a library for game development and anyone can use it and it is simple and easy to learn. Here, you will find information about the Silver C++ library.

Component

Overview

In Silver C++, a Component is an essential part of the entity-component system. It represents a modular piece of behavior that can be attached to an Actor. Components allow for a flexible way to structure game objects, enabling code reuse and better maintainability.

Constructors/Destructors

Constructor / Destructor Description
Component(Actor* parent) Creates a component with the specified parent.
virtual ~Component() Virtual destructor for proper cleanup.
virtual std::shared_ptr<Component> Clone() const = 0; Pure virtual function for cloning the component. Must be implemented in derived classes.

Member Variables

Name Type Description
parent Actor* Pointer to the actor that owns this component.

Usage

Components are meant to be inherited and extended to define new behaviors. For example:

class Transform : public Component {
public:
  Transform(Actor* parent) : Component(parent) {}
  void Update(float deltaTime) override {
    // Update transformation logic here
  }
  std::shared_ptr<Component> Clone() const override {
    return std::make_shared<Transform>(*this);
  }
};

Member Functions

Function Name Description
virtual void Update(float deltaTime) Pure virtual function to update the component every frame. Must be implemented in derived classes.
Actor* GetParent() const Returns the parent actor of the component.
void UnsafeSetParent(Actor* target) Sets the parent actor of the component. Should be used with caution.

Overview

Structure of the engine

Silver Mathematics

Components

Clone this wiki locally