LastOliveGames / becsy

A multithreaded Entity Component System (ECS) for TypeScript and JavaScript, inspired by ECSY and bitecs.
MIT License
202 stars 17 forks source link

How to use dictionary and other reference type in the component? #11

Closed benzsuankularb closed 2 years ago

benzsuankularb commented 2 years ago

I want to use an array, map other reference types as a field in a component.

Which I think I should use @field.ref.

However, want to know a bit more about its behavior.

  1. Is updating the field like so will mark the component as changed?
    
    @component 
    export class MyComponent {
    @field.ref declare indexes: {[key: string]: Entity};
    }

let myComp = entity.write(MyComponent); myComp["newItem"] = entity2; myComp.indexes = myComp.indexes; // Mark the component as changed?



2. Will I going cause the problem with multi-threading by multiple systems trying to access and modify these ref type fields or referenced Entity?
pkaminski commented 2 years ago

We chatted about this on Discord: https://discord.com/channels/654487419407826945/821272559634481152/908375726535897108