Show:
Module: uid

Generate unique sequences of Numbers. Can be salted (up to 9999 salts) to generate differents ids.

To work properly, ECS needs to associate an unique id with each entity. But to preserve efficiency, the unique id must be a Number (more exactly a safe integer).

The basic implementation would be an incremented Number to generate a unique sequence, but this fails when several ecs instances are running and creating entities concurrently (e.g. in a multiplayer networked game). To work around this problem, ecs provide UIDGenerator class which allow you to salt your generated ids sequence. Two generators with different salts will NEVER generate the same ids.

Currently, there is a maxumum of 9999 salts and about 900719925473 uid per salt. These limits are hard-coded, but I plan to expose these settings in the future.

Table of Contents

Constructor

UIDGenerator
(
  • salt=0
)

Parameters:

  • [salt=0] Number optional

    The salt to use for this generator. Number between 0 and 9999 (inclusive).

Properties

salt

Number

The salt of this generator.

uidCount

Number

The counter used to generate unique sequence.