feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
45
src/core/System.js
Normal file
45
src/core/System.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Base System class for ECS architecture
|
||||
* Systems contain logic that operates on entities with specific components
|
||||
*/
|
||||
export class System {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.requiredComponents = [];
|
||||
this.priority = 0; // Lower priority runs first
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an entity matches this system's requirements
|
||||
*/
|
||||
matches(entity) {
|
||||
if (!entity.active) return false;
|
||||
return this.requiredComponents.every(componentType =>
|
||||
entity.hasComponent(componentType)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update method - override in subclasses
|
||||
*/
|
||||
update(deltaTime, entities) {
|
||||
// Filter entities that match this system's requirements
|
||||
const matchingEntities = entities.filter(entity => this.matches(entity));
|
||||
this.process(deltaTime, matchingEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process matching entities - override in subclasses
|
||||
*/
|
||||
process(_deltaTime, _entities) {
|
||||
// Override in subclasses
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when system is added to engine
|
||||
*/
|
||||
init(engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue