Skip to content

powerful and flexible Entity-Component-System (ECS) framework for game development and simulation projects

License

Notifications You must be signed in to change notification settings

mculpo/echo_ecs

Repository files navigation

Echo ECS - Echo Entity Component System (Echo ECS) Library (Simple and Accessible)

This is a straightforward and accessible C++ Entity Component System (ECS) library that provides an uncomplicated way to manage game entities, components, and systems. ECS is a widely-used design pattern in game development that simplifies the organization of game objects' data and logic, making it ideal for both beginners and experienced developers.

Contents

Introduction

The Entity Component System (ECS) architecture is commonly used in game development to structure game entities, their attributes (components), and the logic that operates on them (systems). This repository provides a user-friendly C++ implementation of an ECS framework, making it ideal for simple and accessible game development projects.

Entities, Components, and Systems

In ECS, entities, components, and systems play distinct roles in managing game data and behavior.

Entity

An entity is a fundamental object in the ECS architecture. It is essentially a container for components, representing a game object. Entities are lightweight and typically consist of an identifier and a collection of attached components.

All your entity class must inherit the ECS Entity

Component

A component represents a specific aspect or attribute of an entity. Components are designed to be small, reusable, and self-contained, focusing on a single piece of functionality or data. For example, you might have components for graphics, physics, or behavior.

All your components class must inherit the ECS Component

System

A system is responsible for processing entities and their associated components. Systems encapsulate the logic that operates on entities and their components. Each system typically focuses on a specific aspect of the game, such as rendering, collision detection, or AI behavior.

All your systems class must inherit the ECS System

ECSRegistry

The ECSRegistry class is the heart of this ECS library, providing methods for managing entities, components, and systems.

Features

  • Effortless Entity Management: Create, register, and remove game entities with simplicity in mind.
  • Component Attachment Made Easy: Attach components to entities and remove them without hassle.
  • Straightforward System Integration: Register systems to process entities and their components with ease.
  • Dynamic and Efficient: Offers flexibility and performance through a dynamic component-based architecture.
  • User-Friendly Type-Safe Operations: Utilizes C++ templates to ensure type safety when working with components, making it accessible for developers of all levels.

Getting Started

To use this ECS library in your project, follow these steps:

ECSRegistry Content

The code inside to ECSRegistry

	class ECSRegistry {
	public:
		std::vector<Entity> mEntities;
		std::unordered_map<size_t, std::vector<Component>> mComponents;
		std::vector<System> mSystems;
	};

Creating Entities

To create an entity, follow these steps:

#include "ecs.hpp"

ecs::ECSRegistry* registry = new ecs::ECSRegistry;
ecs::Entity* entity = new ecs::Entity();
ecs::RegisterEntity(registry->mEntities, *entity);
//or
ecs::Entity entity;
ecs::RegisterEntity(registry->mEntities, entity);

Attaching Components

To attach a component to an entity, follow these steps:

#include "ecs.hpp"
#include "TransformComponent.h" // Replace with your component class header

ecs::ECSRegistry* registry = new ecs::ECSRegistry;
ecs::Entity* entity = new ecs::Entity();

TransformComponent* component = new TransformComponent();

ecs::RegisterEntity(registry->mEntities, entity);
ecs::RegisterComponentToEntity(registry->mComponents ,entity, component);

Registering Systems

To register a system, follow these steps:

#include "ecs.hpp"
#include "YourSystem.h" // Replace with your system class header

ecs::ECSRegistry* registry = new ecs::ECSRegistry;
ecs::RegisterSystem(registry->mSystems, new YourSystem(1, 0));

Using Methods

Here are some examples of how to use methods provided by ECSRegistry:

RemoveSystem

Method to reserve capacity for a vector.

ecs::ECSRegistry* registry = new ecs::ECSRegistry;
ecs::ReserveVectorCapacity(registry->mEntities, 100);

ReserveMapCapacity

Method to reserve capacity for a map of vectors.

ecs::ECSRegistry* registry = new ecs::ECSRegistry;
ecs::ReserveMapCapacity<TransformComponent>(registry->mComponents, 100);

License

This project is licensed under the Apache-2.0 license.

About

powerful and flexible Entity-Component-System (ECS) framework for game development and simulation projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages