Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@antv/g-ecs
Advanced tools
English | 简体中文
A typical ECS architecture(borrow from ecsy), we use Matcher
instead of Query
:
import { Container } from 'inversify';
import { Component, System, World, containerModule } from '@antv/g-ecs';
// create a container
const container = new Container();
// load ECS module
container.load(containerModule);
// create a world
const world = container.get(World);
// register components
class C1 extends Component {
static tag = 'c1';
p1: number;
}
class C2 extends Component {
static tag = 'c2';
}
class C3 extends Component {
static tag = 'c3';
}
world.registerComponent(C1).registerComponent(C2).registerComponent(C3);
// register systems
class S1 extends System {
static tag = 's1';
trigger() {
return new Matcher().allOf(C1);
}
execute(entities: Entity[]) {
entities.forEach((entity) => {
const c1 = entity.getComponent(C1);
c1.p1++;
});
}
}
world.registerSystem(S1);
// create an entity
const entity = world.createEntity();
entity.addComponent(C1, { p1: 2 }).addComponent(C2).addComponent(C3);
// make a loop
let lastTime = performance.now();
const run = () => {
const time = performance.now();
const delta = time - lastTime;
// run all the systems
world.execute(delta, time);
lastTime = time;
requestAnimationFrame(run);
};
run();
A world is the container of ECS. We get a world from container instead of creating it manually.
import { Container } from 'inversify';
import { World, containerModule } from '@antv/g-ecs';
// create a container
const container = new Container();
// load ECS module
container.load(containerModule);
// create a world
const world = container.get(World);
Create a new entity:
const entity = world.createEntity();
class C1 extends Component {
static tag = 'c1';
p1: number;
}
class C2 extends Component {
static tag = 'c2';
}
class C3 extends Component {
static tag = 'c3';
}
world.registerComponent(C1).registerComponent(C2).registerComponent(C3);
class S1 extends System {
static tag = 's1';
trigger() {
return new Matcher().allOf(C1);
}
execute(entities: Entity[]) {
entities.forEach((entity) => {
const c1 = entity.getComponent(C1);
c1.p1++;
});
}
}
world.registerSystem(S1);
We can add a component and its initial data to an entity:
entity.addComponent(C1, { p1: 2 }).addComponent(C2).addComponent(C3);
We can remove a component from an entity:
entity.removeComponent(C1);
FAQs
A simple ECS implement
The npm package @antv/g-ecs receives a total of 5 weekly downloads. As such, @antv/g-ecs popularity was classified as not popular.
We found that @antv/g-ecs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 40 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.