|
| 1 | +Registry |
| 2 | +======== |
| 3 | + |
| 4 | +.. toctree:: |
| 5 | + :maxdepth: 2 |
| 6 | + |
| 7 | + writing_web_assembly.rst |
| 8 | + |
| 9 | +The registry class is written in C++ and exposed to WebAssembly using |
| 10 | +Emscripten. This choice was made to leverage the performance benefits of |
| 11 | +C++ for managing entities and components in an ECS architecture. |
| 12 | +Emscripten allows us to compile C++ code into WebAssembly, which can |
| 13 | +then be used in web applications, providing a bridge between |
| 14 | +high-performance C++ code and JavaScript. |
| 15 | + |
| 16 | +Design Choices |
| 17 | +-------------- |
| 18 | + |
| 19 | +This design makes some trade-offs between performance and ease of use. A |
| 20 | +pure C++ ECS would have been easier to use but having to bind it as us |
| 21 | +make choices that impact usability. |
| 22 | + |
| 23 | +Const Correctness |
| 24 | +~~~~~~~~~~~~~~~~~ |
| 25 | + |
| 26 | +In a regular C++ ECS, const correctness is a given, but when exposing |
| 27 | +C++ to WebAssembly, as in C++ we can force constant of return values. |
| 28 | +But in WebAssembly, the concept of const correctness does not directly |
| 29 | +translate to JavaScript. Therefore, methods that would typically return |
| 30 | +const references in C++ may return non-const references or copies when |
| 31 | +exposed to WebAssembly. We deciced to keep the const correctness in the |
| 32 | +C++ code to maintain clarity and intent within the C++ domain, even if |
| 33 | +it doesn't fully carry over to the WebAssembly interface. |
| 34 | + |
| 35 | +Error Handling |
| 36 | +~~~~~~~~~~~~~~ |
| 37 | + |
| 38 | +Any thrown exceptions in C++ will result in a runtime error in |
| 39 | +JavaScript. The problem with this approach is that the error messages |
| 40 | +may not be as descriptive or user-friendly as native JavaScript errors. |
| 41 | +As every error thrown in C++ will be caught as a generic runtime error |
| 42 | +in JavaScript, it can make debugging more challenging. To mitigate this, |
| 43 | +we recommend thorough testing and validation within the C++ code to |
| 44 | +catch potential issues before they propagate to the WebAssembly layer. |
0 commit comments