@dcl/ecs

中文文档
7.33.0发布于 2026/11/06Apache-2.0TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 2.1万

Decentraland ECS

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Technical Overview
  4. Component Definition
  5. CRDT Implementation
  6. Network Entities
  7. Performance Features
  8. Development
  9. Documentation

@dcl/ecs

Core Entity Component System (ECS) package for Decentraland scenes. Implements a CRDT-based ECS architecture for networked scene state.

Installation

npm install @dcl/ecs

Usage

import { engine } from '@dcl/ecs'

// Create entity
const entity = engine.addEntity()

// Define and add component
const Health = engine.defineComponent(1, {
  current: Number,
  max: Number,
  regeneration: Number
})

Health.create(entity, {
  current: 100,
  max: 100,
  regeneration: 1
})

// Create system
engine.addSystem((dt: number) => {
  for (const [entity, health] of engine.mutableGroupOf(Health)) {
    if (health.current < health.max) {
      health.current = Math.min(health.max, health.current + health.regeneration * dt)
    }
  }
})

Technical Overview

Component Definition

Components are defined with a unique ID and a schema. The schema is used to:

  • Generate TypeScript types
  • Create binary serializers/deserializers
  • Set up CRDT operations

CRDT Implementation

The ECS uses CRDTs (Conflict-free Replicated Data Types) to enable deterministic state updates across multiple engine instances:

  • Component updates are CRDT operations with logical timestamps
  • Multiple engine instances can be synced by exchanging CRDT operations
  • Conflict resolution uses timestamps and entity IDs to ensure consistency
  • Binary transport format minimizes network overhead

Network Entities

For multiplayer scenes, the syncEntity method marks entities that should be synchronized across peers. In the background it creates a NetworkEntity and a SyncComponents components with all the info necessary to synchronise the entity through the network.

import { engine, NetworkEntity } from '@dcl/ecs'

// Create a networked entity
const foe = engine.addEntity()
NetworkEntity.create(foe)

// Components on this entity will be synced across peers
Health.create(foe, { current: 100, max: 100, regeneration: 1 })

Each peer maintains its own engine instance. When using NetworkEntity:

  • The owner peer can modify the entity's components
  • Other peers receive read-only replicas
  • Updates are propagated through the network transport layer using CRDT operations

Example transport message:

{
  entityId: number
  componentId: number
  timestamp: number
  data: Uint8Array // Serialized component data
}

Performance Features

  • Zero-allocation component iteration
  • Dirty state tracking for efficient updates
  • Binary serialization for network transport
  • Batched component operations

Development

# Build
make build

# Test
make test

# Clean and reinstall
make clean && make install

Documentation

版本与发布记录

@dcl/ecs 共发布 1,361 个版本,首次发布于 2022/05/06;过去 12 个月发布了 318 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.33.0latest2026/11/066 天前
7.32.1-42077145652.commit-f6053ef2026/11/066 天前
7.32.1-42074770886.commit-f6053ef2026/11/066 天前
7.32.1-41691874543.commit-3063788auth-server2026/11/047 天前
7.31.1-41669733463.commit-b1b1d792026/11/048 天前
7.32.02026/11/048 天前

其他发布通道:ci → 7.8.16,protocol-squad → 7.25.1-30828532396.commit-0c215c3,experimental → 7.27.1-34382248832.commit-ca3b679,experimental-bevy → 7.31.1-40604676255.commit-cb3ed84,experimental-bevy-auth-server → 7.31.1-40606969412.commit-24c05c3,auth-server → 7.32.1-41691874543.commit-3063788。

关于 @dcl/ecs 的常见问题

@dcl/ecs 是什么?

Decentraland ECS

如何安装 @dcl/ecs?

在项目目录运行 npm install @dcl/ecs,或使用 pnpm add / yarn add / bun add。

@dcl/ecs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dcl/ecs 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dcl/ecs 可以商用吗?

@dcl/ecs 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dcl/ecs 的下载量有多少?

根据 npm 官方下载统计,@dcl/ecs 在 2026/10/12 – 2026/11/10 这 30 天内被下载 20,698 次,日均约 690 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dcl/ecs 还在维护吗?

最新版本 7.33.0 发布于 2026/11/06(6 天前);至今共发布 1361 个版本,其中过去 12 个月发布了 318 个;首次发布于 2022/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。