JaimeGensler / thyseus

An archetypal Entity Component System, built entirely in Typescript
MIT License
74 stars 3 forks source link

[FEAT] Investigate `Thread<T>` proxies, transferable object API #68

Open JaimeGensler opened 10 months ago

JaimeGensler commented 10 months ago

Describe the problem this feature solves

Proxies may be a cleaner way to handle our threading solution - rather than passing a string name for the function, getting an object that's a proxy with those properties on it would be neat.

Our threading solution also needs some sort of way to handle transferable objects.

Describe the solution you'd like to see

Option 1 (Transferable Wrapper)

This is how threads.js handles this. If you want to transfer an object, you can wrap it in a Transfer() call - this call and how it works should be opaque.

function mySystem(thread: Thread<T>) {
  thread.myFunc(Thread.transfer(someTransferableObject));
}

For implementation, this could either be a wrapper that must be unwrapped by the proxy handler, or simply push a value into a local array.

Option 2 (Transferable Argument)

Add a final argument that accepts transferable objects.

function mySystem(thread: Thread<T>) {
  thread.myFunc(someTransferableObject, [someTransferableObject]);
}

Not sure how to differentiate between normal arguments and transfers in this case, though