Skip to content

Simple implementation of ECS game model. 简易的ecs框架实现(entity component system

Notifications You must be signed in to change notification settings

ActivePeter/paecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paecs

paecs

c++ implementation of ECS (Entity Component System)lib

c++的ecs库 (Entity Component System)

Background (背景)

When I'm writing a minecraft like game, I knows that ecs is a way to improve game performance. I'm writing this project not only for preparing for my minecraft project but also to improve my programming capability of c++ ---- it is the first complete and carefully designed c++ lib I'm writing.

在我写我类似于mc游戏--voxelfram的时候,我了解到ecs是一种提升遍历性能并解耦数据和操作的模式。写这个库的目的一方面是给我的voxelframe 用,一方面是提升我编写c++的能力,这也是我第一个完整且仔细设计过的c++库。

Features (特性)

  • Archtype Model,entities are divided by component combination. Data is in continuous array which makes seeking and iteration faster.

    archtype模型,实体(entity)被分为插件的组合,数据是存储在连续空间中的,这是ecs遍历和查找更快速的原因

  • Easy to add component and system

    易于添加 组件系统

    • Add sys Only need to write a func with needed prams, then register it to system

      只需要编写一个函数,参数包含需要访问到的组件,然后添加为系统即可

      void helloworld_sys(A &a)
      {
      }
      paecs::SysGroup systems;
      scene.addSys2Group(
              systems,
              helloworld_sys);
    • Call Sys by SysGroup

      systems.runAll();
    • Add Entity

      Only need to write a simple struct, then register it to component

      只需要写一个简单的结构体,然后添加为组件即可

      可以添加空插件也可以传入一个实例化的对象来配置初始参数

      支持优雅的链式调用

      struct A
      {
          int id;
          A(int id):id(id){}
      };
      struct B
      {
          int id;
          char testChar;
      };
      A a(1);
      scene.createEntity()
              .addComponent(a)
              .addEmptyComponent<B>();
    • Random Access/随机访问

      Input pointer to access entity by entityID

      输入指针然后访问entity对应组件的数据,

      EcsComp::Position3D *ecspos;
      if (App::getInstance().ecsPtr->randomAccessEntity(
          entityId,
          ecspos))
      {
          ecspos->x = pos.x;
          ecspos->y = pos.y;
          ecspos->z = pos.z;
      }
      cameraPtr->Position = pos;
    • Rigist singleton/注册单例资源

      ecs.scene->registSingleton<ContextId>(
          [this](ContextId& cid)
          {
              cid.id = this->context_id.id;
          });

Todo

  • easy to add sys and entity

    便捷注册 系统实体

  • random access

    随机访问

  • added SysGroup

    系统组概念

  • Rigist singleton

    注册单例资源

  • multiple threads

    多线程支持

About

Simple implementation of ECS game model. 简易的ecs框架实现(entity component system

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published