Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how systems are defined and organized #7

Open
2 of 3 tasks
richardbiely opened this issue Oct 26, 2023 · 0 comments
Open
2 of 3 tasks

Improve how systems are defined and organized #7

richardbiely opened this issue Oct 26, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@richardbiely
Copy link
Owner

richardbiely commented Oct 26, 2023

Current version:
System is a virtual class with overridden member functions. Systems are managed by SystemManager. They are not connected. On the outside this looks very similar to what DOTS does.

class PositionSystem final: public ecs::System {
  static constexpr float dt = 0.01f;
	ecs::Query m_q;

public:
	void OnCreated() override {
		m_q = world().query().all<Position&, Velocity>();
	}

	void OnUpdate() override {
		m_q.each([](Position& p, const Velocity& v) {
			p.x += v.x * dt;
			p.y += v.y * dt;
			p.z += v.z * dt;
		});
	}
};

ecs::SystemManager sm(w);
sm.add<PositionSystem>();
sm.add<OtherSystem>();
...
sm.update(); // run all systems once

Proposed version:
Systems are entities with a System component attached. Maybe even inheriting from Query (so they are cached). This gives us a lot of flexibility. Enabling the system = enabling the entity. Systems can be queried (e.g. disable all systems that do this-and-that easily).
Organized into stages. Stages can be user defined, probably implemented as components. In order for the grouping to work correctly, relationship support would come handy.

auto s = w.system()
        .stage<LateUpdate>() // optional, if not used, the system goes to the default stage
	.all<Position&, Velocity>()
	.any<Rotation>()
	.OnCreated([](ecs::Query& q) { // event when created
	})
	.OnStopped([](ecs::Query& q) { // event when stopped
		...
	})
       // other events
        ...
       // function to run every update (equivalent to ecs::query::each)
	.OnUpdate([](Position& p, const Velocity& v) {
		p.x += v.x * dt;
		p.y += v.y * dt;
		p.z += v.z * dt;
	})
	.commit();

Necessary:

  • support for entity naming
  • entity sorting/grouping
  • entity relationship support
@richardbiely richardbiely added the enhancement New feature or request label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant