Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
A high performance lightweight ECS with a plugin ecosystem.
See TECHNICAL.md for details on performance and the internals of this library.
import { World, System, Component, StateComponent, Types, Not, Modified } from 'hecs'
import { Object3D } from './types'
class Model extends Component {
static props = {
type: Types.Text,
}
}
class Mesh extends StateComponent {
static props = {
value: Object3D,
}
}
class ModelSystem extends System {
static queries = {
added: [Model, Not(Mesh)],
modified: [Modified(Model), Mesh],
removed: [Not(Model), Mesh],
}
update() {
this.queries.added.forEach(entity => {
const model = entity.get(Model)
const object3d = getModel(model.type)
entity.add(Mesh, { value: object3d })
})
this.queries.modified.forEach(entity => {
entity.remove(Mesh)
const model = entity.get(Model)
const object3d = getModel(model.type)
entity.add(Mesh, { value: object3d })
})
this.queries.removed.forEach(entity => {
const object3d = entity.get(Mesh).value
object3d.dispose()
entity.remove(Mesh)
})
}
}
const world = new World({
systems: [ModelSystem],
components: [Model, Mesh]
})
world.entities.create().add(Model, { type: 'basketball' }).activate()
function update() {
world.update()
requestAnimationFrame(update)
}
update()
import { World } from 'hecs'
import CorePlugin from 'hecs-plugin-core'
import MySystem from './MySystem'
import MyComponent from './MyComponent'
const world = new World({
plugins: [CorePlugin],
systems: [MySystem],
components: [MyComponent]
})
world.update()
const basketball = world.entities.create()
basketball.add(Model, { path: 'basketball.glb' })
const model = basketball.get(Model)
If you use queries that need to know when components are modified you will need to mark them as modified.
const model = basketball.get(Model)
model.path = 'basketball-2.glb'
model.modified()
basketball.remove(Model)
Entities are inactive by default and are not simulated in world queries until they are activated:
basketball.activate()
If you want to remove an entity from the world but still keep it around, use deactivate. When deactivated, all Components are temporarily removed except StateComponents, so that System queries can still process and deallocate any resources. Once all StateComponents are removed the enitity is completely removed from all queries.
basketball.deactivate()
If you want to completely remove an entity, use destroy. All Components are removed except StateComponents so that System queries can still process and deallocate resources. Once all StateComponents are removed the entity is completely destroyed.
basketball.destroy()
import { Component, Types } from 'hecs'
export class Model extends Component {
static props = {
path: Types.Text
}
}
LocalComponents work exactly the same as Components except they are ignored when calling
world.toJSON()
or entity.toJSON()
. LocalComponents should be used in a network
environment when the data doesn't need to be synced between other servers or clients.
import { LocalComponent } from 'hecs'
import { Axis } from './types'
export class Input extends LocalComponent {
static props = {
axis: Types.Axis2D
}
}
StateComponents work the same as regular Components but are kept around after an entity is deactivated or destroyed, so that Systems can process or deallocate resources.
import { StateComponent } from 'hecs'
import { Object3D } from './types'
export class Mesh extends StateComponent {
static props = {
value: Types.Object3D
}
}
import { System, Not, Changed } from 'hecs'
import { Mesh } from './components'
export class ModelSystem extends System {
static queries = {
added: [Model, Not(Mesh)],
modified: [Modified(Model), Mesh],
removed: [Not(Model), Mesh],
}
update() {
this.queries.added.forEach(entity => {
const model = entity.get(Model)
const object3d = getModel(model.type)
entity.add(Mesh, { value: object3d })
})
this.queries.modified.forEach(entity => {
entity.remove(Mesh)
const model = entity.get(Model)
const object3d = getModel(model.type)
entity.add(Mesh, { value: object3d })
})
this.queries.removed.forEach(entity => {
const object3d = entity.get(Mesh).value
object3d.dispose()
entity.remove(Mesh)
})
}
}
Plugins are a collection of things such as Systems and Components that you can use in your world, or compose with other plugins.
The Plugin options are exactly the same as when instantiating a new World:
import { createPlugin } from 'hecs'
export default createPlugin({
name: 'my-plugin',
plugins: [],
systems: [],
components: [],
decorate(world) {}
})
name: The name of your plugin, used for debugging purposes.
plugins: A plugin can depend on other plugins. If two plugins depend on the same plugin it will only be registered once.
systems: An array of Systems to add to the world.
components: An array of Components to register.
decorate: A function that provides the world instance. Useful for constructing shared services, eg scenes.
FAQs
A high performance ECS with a plugin ecosystem
The npm package hecs receives a total of 1 weekly downloads. As such, hecs popularity was classified as not popular.
We found that hecs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.