Web Assembly ECS Interface #15
Locked
robertlong
started this conversation in
Ideas
Replies: 3 comments 1 reply
-
needless to say i'm down! where should we start? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Saw this on Twitter today. Could be an interesting way to simplify implementations. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This work is now happening in the omi-wasm-group. If you'd like to get involved, go there to get our current meeting times and participate in the GitHub discussions! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Web Assembly ECS Interface
Web Assembly is a perfect runtime environment for sandboxing User Generated Content (UGC) scripts for interactive virtual worlds. It is portable with mature runtime libraries being written in a number of different languages. It is battle-tested, in web browsers, internet-scale web infrastructure, and many more production environments. And it has near-native performance which is incredibly important for realtime games.
The Entity Component System (ECS) pattern has been in use in AAA games for some time now and has in recent years made it's way into publicly available game engines. In it's most basic form, ECS consists of Entities, Components, and Systems. Entities are identifiers that represent unique objects in a simulation, Components store data associated with an entity, and Systems iteratively process entities and their components usually through queries which keep track of entities with or without a set of components.
I'd like to propose the development of a standard Web Assembly ECS interface. I believe that the data-oriented design pattern from ECS can avoid performance costs in the interface layer and mitigate potential security issues by relying on simple shared-memory patterns and few function definitions, rather than a huge set of interface functions.
Requirements
The interface design should meet the following requirements:
Security
These WebAssembly scripts will be untrusted UGC. The interface and runtime requirements must be defined to prevent against malicious script authors.
Possible security issues include:
Performance
UGC scripts whether malicious or not can be expensive and use up valuable system resources needed for the rest of the simulation. Efforts must be made to isolate scripts to different threads and avoid blocking the main simulation threads. System execution time and memory resources can also be limited and shut down if exceeded.
Possible Design Considerations
Memory Access
WebAssembly modules may expose their heap to the runtime and expose simple functions for running systems that mutate that memory. The component data can then be copied from this heap into the runtime's component storage or vice versa. A set of read/write bitmasks can be used to determine if the memory should be copied into/out of the WebAssembly heap.
Runtime Functions
While ECS implementations do not have many functions themselves, outside of adding/removing entities/components, they often use functions in Systems with access to IO, graphics apis, networking, etc. Ideally the WebAssembly ECS Interface can avoid these functions entirely and expose functionality purely through component data, however this method of defining APIs is asynchronous. There may be synchronous APIs that need to be exposed to make writing systems simple and efficient. Identifying these functions and determining if there are extensible methods for exposing new functions will be an important design decison.
Next Steps
I'd like to start by experimenting with this concept inside Third Room. If you are interested in working on this project, inside of Third Room or as a more general library, please respond below. I'm looking for help drafting the API spec, thinking through design/security decisions, and implementing a prototype.
Beta Was this translation helpful? Give feedback.
All reactions