@lastolivegames/becsy
Advanced tools
Comparing version 0.10.7 to 0.10.8
### Upcoming | ||
### 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.10.6, 0.10.7 | ||
### 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.10.6, 0.10.7, 0.10.8 | ||
- Fixed a lot of entity ref bugs. | ||
@@ -5,0 +5,0 @@ - Improved reporting of internal errors. |
{ | ||
"name": "@lastolivegames/becsy", | ||
"type": "module", | ||
"version": "0.10.7", | ||
"version": "0.10.8", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "test": "jest --config jestconfig.json --detectOpenHandles", |
@@ -17,2 +17,4 @@ import {EMPTY_ARRAY, Type} from './type'; | ||
export type ComponentId = number & {__componentIdBrand: symbol}; | ||
export type ComponentStorage = 'sparse' | 'packed' | 'compact'; | ||
@@ -50,3 +52,3 @@ | ||
*/ | ||
id?: number; | ||
id?: ComponentId; | ||
@@ -67,3 +69,3 @@ __binding?: Binding<C>; | ||
internallyIndexed = false; | ||
entityId = 0; | ||
entityId = 0 as EntityId; | ||
index = 0; | ||
@@ -94,7 +96,6 @@ readonly initDefault: (component: any) => void; | ||
fields | ||
.filter(field => field.default !== EMPTY_ARRAY) | ||
.map(field => | ||
`component.${field.name} = values.${field.name} === undefined ? | ||
${JSON.stringify(field.default)} : values.${field.name};` | ||
) | ||
.map(field => ` | ||
component.${field.name} = values.${field.name} === undefined ? | ||
${JSON.stringify(field.default)} : values.${field.name}; | ||
`) | ||
.join('\n') | ||
@@ -318,3 +319,3 @@ ) as (component: any, values: any) => void; | ||
export function assimilateComponentType<C>( | ||
typeId: number, type: ComponentType<C>, dispatcher: Dispatcher | ||
typeId: ComponentId, type: ComponentType<C>, dispatcher: Dispatcher | ||
): void { | ||
@@ -321,0 +322,0 @@ const fields = gatherFields(type); |
@@ -5,3 +5,3 @@ import type {ComponentStorage, ComponentType} from './component'; | ||
import {Log, LogPointer} from './datatypes/log'; | ||
import {RunState, System, SystemBox, SystemType} from './system'; | ||
import {RunState, System, SystemBox, SystemId, SystemType} from './system'; | ||
import {Registry} from './registry'; | ||
@@ -167,3 +167,3 @@ import {Stats} from './stats'; | ||
const system = new SystemClass(); | ||
system.id = i + 1; // 0 is reserved for the callback system | ||
system.id = (i + 1) as SystemId; // 0 is reserved for the callback system | ||
box = new SystemBox(system, this); | ||
@@ -185,3 +185,3 @@ systems.push(box); | ||
this.userCallbackSystem = new CallbackSystem(); | ||
this.userCallbackSystem.id = 0; | ||
this.userCallbackSystem.id = 0 as SystemId; | ||
const box = new SystemBox(this.userCallbackSystem, this); | ||
@@ -188,0 +188,0 @@ box.rwMasks.read = undefined; |
@@ -6,3 +6,3 @@ import {checkTypeDefined, ComponentType, initComponent} from './component'; | ||
export type EntityId = number; | ||
export type EntityId = number & {__entityIdBrand: symbol}; | ||
export type ReadWriteMasks = {read?: number[], write?: number[]}; | ||
@@ -9,0 +9,0 @@ |
@@ -41,3 +41,3 @@ import {checkTypeDefined, ComponentType} from './component'; | ||
constructor( | ||
private readonly targetEntityId: number, private readonly selector: Selector, | ||
private readonly targetEntityId: EntityId, private readonly selector: Selector, | ||
private readonly dispatcher: Dispatcher | ||
@@ -359,5 +359,5 @@ ) { | ||
const entryPart1 = log[i], entryPart2 = log[i + 1]; | ||
const sourceId = entryPart1 & ENTITY_ID_MASK; | ||
const sourceId = (entryPart1 & ENTITY_ID_MASK) as EntityId; | ||
const sourceTypeId = entryPart1 >>> ENTITY_ID_BITS; | ||
const targetId = entryPart2 & ENTITY_ID_MASK; | ||
const targetId = (entryPart2 & ENTITY_ID_MASK) as EntityId; | ||
const sourceSeq = (entryPart2 >>> ENTITY_ID_BITS) & (MAX_NUM_FIELDS - 1); | ||
@@ -364,0 +364,0 @@ const action: Action = entryPart2 & ACTION_MASK; |
@@ -1,2 +0,2 @@ | ||
import {ComponentType, assimilateComponentType, defineAndAllocateComponentType} from './component'; | ||
import {ComponentType, assimilateComponentType, defineAndAllocateComponentType, ComponentId} from './component'; | ||
import {Log, LogPointer} from './datatypes/log'; | ||
@@ -16,3 +16,3 @@ import {SharedAtomicPool, Uint32Pool, UnsharedPool} from './datatypes/intpool'; | ||
private readonly spares: Entity[] = []; | ||
private readonly temporarilyBorrowedIds: number[] = []; | ||
private readonly temporarilyBorrowedIds: EntityId[] = []; | ||
@@ -24,3 +24,3 @@ constructor(private readonly registry: Registry, maxEntities: number) { | ||
borrow(id: number): Entity { | ||
borrow(id: EntityId): Entity { | ||
this.borrowCounts[id] += 1; | ||
@@ -35,3 +35,3 @@ let entity = this.borrowed[id]; | ||
borrowTemporarily(id: number): Entity { | ||
borrowTemporarily(id: EntityId): Entity { | ||
const entity = this.borrow(id); | ||
@@ -47,3 +47,3 @@ this.temporarilyBorrowedIds.push(id); | ||
return(id: number): void { | ||
return(id: EntityId): void { | ||
DEBUG: { | ||
@@ -108,3 +108,5 @@ if (!this.borrowCounts[id]) { | ||
// Two-phase init, so components can have dependencies on each other's fields. | ||
for (const type of this.types) assimilateComponentType(componentId++, type, this.dispatcher); | ||
for (const type of this.types) { | ||
assimilateComponentType(componentId++ as ComponentId, type, this.dispatcher); | ||
} | ||
for (const type of this.types) defineAndAllocateComponentType(type); | ||
@@ -120,3 +122,3 @@ DEBUG: { | ||
createEntity(initialComponents: (ComponentType<any> | Record<string, unknown>)[]): Entity { | ||
const id = this.entityIdPool.take(); | ||
const id = this.entityIdPool.take() as EntityId; | ||
this.setShape(id, this.Alive); | ||
@@ -157,3 +159,3 @@ const entity = this.pool.borrowTemporarily(id); | ||
const entry = log[i]; | ||
const entityId = entry & ENTITY_ID_MASK; | ||
const entityId = (entry & ENTITY_ID_MASK) as EntityId; | ||
const componentId = (entry >>> ENTITY_ID_BITS) & COMPONENT_ID_MASK; | ||
@@ -160,0 +162,0 @@ const type = this.types[componentId]; |
import type {LogPointer} from './datatypes/log'; | ||
import type {Dispatcher} from './dispatcher'; | ||
import type {Entity, ReadWriteMasks} from './entity'; | ||
import type {Entity, EntityId, ReadWriteMasks} from './entity'; | ||
import {COMPONENT_ID_MASK, ENTITY_ID_BITS, ENTITY_ID_MASK} from './consts'; | ||
@@ -24,3 +24,5 @@ import type {World} from './world'; // eslint-disable-line @typescript-eslint/no-unused-vars | ||
export type SystemId = number & {__systemIdBrand: symbol}; | ||
export enum RunState { | ||
@@ -81,3 +83,3 @@ RUNNING, STOPPED | ||
*/ | ||
id: number; | ||
id: SystemId; | ||
@@ -455,3 +457,3 @@ /** | ||
const entry = log[i]; | ||
const entityId = entry & ENTITY_ID_MASK; | ||
const entityId = (entry & ENTITY_ID_MASK) as EntityId; | ||
if (!queries) { | ||
@@ -496,3 +498,3 @@ const typeId = (entry >>> ENTITY_ID_BITS) & COMPONENT_ID_MASK; | ||
const entry = log[i]; | ||
const entityId = entry & ENTITY_ID_MASK; | ||
const entityId = (entry & ENTITY_ID_MASK) as EntityId; | ||
if (!queries) { | ||
@@ -539,3 +541,3 @@ const typeId = (entry >>> ENTITY_ID_BITS) & COMPONENT_ID_MASK; | ||
for (const query of this.shapeQueries) query.clearProcessedEntities(); | ||
for (let id = 0; id < this.dispatcher.maxEntities; id++) { | ||
for (let id = 0 as EntityId; id < this.dispatcher.maxEntities; id++) { | ||
if (registry.hasShape(id, Alive, false)) { | ||
@@ -542,0 +544,0 @@ for (const query of this.shapeQueries) query.handleShapeUpdate(id); |
@@ -416,6 +416,6 @@ import type {TypedArray, TypedArrayConstructor} from './buffers'; | ||
if (data[binding.index] === -1) return; | ||
DEBUG: if ((data[binding.index] & STALE_REF_BIT) !== 0 !== final) { | ||
throw new InternalError('Wrong ref stale state'); | ||
} | ||
const id = data[binding.index] & ENTITY_ID_MASK; | ||
const stale = (data[binding.index] & STALE_REF_BIT) !== 0; | ||
if (stale && !final) return; | ||
DEBUG: if (!stale && final) throw new InternalError('Wrong ref stale state'); | ||
const id = (data[binding.index] & ENTITY_ID_MASK) as EntityId; | ||
const targetIdGiven = targetId !== undefined; | ||
@@ -425,3 +425,3 @@ if (targetIdGiven && id !== targetId) return; | ||
indexer.trackRefChange( | ||
binding.entityId, binding.type, field.seq, undefined, id, -1, !final, final); | ||
binding.entityId, binding.type, field.seq, undefined, id, -1 as EntityId, !final, final); | ||
}; | ||
@@ -435,3 +435,3 @@ | ||
if (id === -1 || (id & STALE_REF_BIT) && !registry.includeRecentlyDeleted) return; | ||
return pool.borrowTemporarily(id & ENTITY_ID_MASK); | ||
return pool.borrowTemporarily((id & ENTITY_ID_MASK) as EntityId); | ||
}, | ||
@@ -443,6 +443,6 @@ set(this: C, value: Entity | undefined | null): void { | ||
} | ||
let oldId = data[binding.index]; | ||
if (oldId !== -1) oldId &= ENTITY_ID_MASK; | ||
let oldId = data[binding.index] as EntityId; | ||
if (oldId !== -1) oldId = (oldId & ENTITY_ID_MASK) as EntityId; | ||
const stale = oldId !== -1 && !!(data[binding.index] & STALE_REF_BIT); | ||
const newId = value?.__id ?? -1; | ||
const newId = (value?.__id ?? -1) as EntityId; | ||
if (oldId === newId && !stale) return; | ||
@@ -461,3 +461,3 @@ data[binding.index] = newId; | ||
if (id === -1 || (id & STALE_REF_BIT) && !registry.includeRecentlyDeleted) return; | ||
return pool.borrowTemporarily(id & ENTITY_ID_MASK); | ||
return pool.borrowTemporarily((id & ENTITY_ID_MASK) as EntityId); | ||
}, | ||
@@ -483,6 +483,6 @@ set(this: C, value: Entity | undefined | null): void { | ||
if (data[binding.index] === -1) return; | ||
DEBUG: if ((data[binding.index] & STALE_REF_BIT) !== 0 !== final) { | ||
throw new InternalError('Wrong ref stale state'); | ||
} | ||
const id = data[binding.index] & ENTITY_ID_MASK; | ||
const stale = (data[binding.index] & STALE_REF_BIT) !== 0; | ||
if (stale && !final) return; | ||
DEBUG: if (!stale && final) throw new InternalError('Wrong ref stale state'); | ||
const id = (data[binding.index] & ENTITY_ID_MASK) as EntityId; | ||
const targetIdGiven = targetId !== undefined; | ||
@@ -492,3 +492,3 @@ if (targetIdGiven && id !== targetId) return; | ||
indexer.trackRefChange( | ||
binding.entityId, binding.type, field.seq, undefined, id, -1, !final, final); | ||
binding.entityId, binding.type, field.seq, undefined, id, -1 as EntityId, !final, final); | ||
}; | ||
@@ -502,3 +502,3 @@ | ||
if (id === -1 || (id & STALE_REF_BIT) && !registry.includeRecentlyDeleted) return; | ||
return pool.borrowTemporarily(id & ENTITY_ID_MASK); | ||
return pool.borrowTemporarily((id & ENTITY_ID_MASK) as EntityId); | ||
}, | ||
@@ -510,6 +510,6 @@ set(this: C, value: Entity | undefined | null): void { | ||
} | ||
let oldId = data[binding.index]; | ||
if (oldId !== -1) oldId &= ENTITY_ID_MASK; | ||
let oldId = data[binding.index] as EntityId; | ||
if (oldId !== -1) oldId = (oldId & ENTITY_ID_MASK) as EntityId; | ||
const stale = oldId !== -1 && !!(data[binding.index] & STALE_REF_BIT); | ||
const newId = value?.__id ?? -1; | ||
const newId = (value?.__id ?? -1) as EntityId; | ||
if (oldId === newId && !stale) return; | ||
@@ -528,3 +528,3 @@ data[binding.index] = newId; | ||
if (id === -1 || (id & STALE_REF_BIT) && !registry.includeRecentlyDeleted) return; | ||
return pool.borrowTemporarily(id & ENTITY_ID_MASK); | ||
return pool.borrowTemporarily((id & ENTITY_ID_MASK) as EntityId); | ||
}, | ||
@@ -531,0 +531,0 @@ set(this: C, value: Entity | undefined | null): void { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4685026
37855