Skip to content

Commit 6d7caa6

Browse files
MartinFillonExeloo
andauthored
docs: document registry and setup auto push for docs (#159)
* docs(ecs): document ecs and design choices * docs(ecs): setup sphinx for ecs documentation * docs(ecs): start connecting typescript to sphinx * docs(ecs): finish cpp side of documentation * docs: setup new doc system * docs(actions): setup push-docs actions to synchronize documentation * docs: setup auto push of generated documentation for ecs * docs(usage): replace template with cli mention and delete template example * ci: update push-docs workflow to monitor specific documentation paths --------- Co-authored-by: Exelo <exelo.corp@gmail.com>
1 parent 2a2237a commit 6d7caa6

29 files changed

Lines changed: 521 additions & 477 deletions

.github/workflows/push-docs.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: synchronize-docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "docs/**"
9+
- "packages/ecs-lib/docs/**"
10+
- "packages/ecs-lib/wasm/**"
11+
workflow_dispatch:
12+
13+
jobs:
14+
synchronize:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout engine
18+
uses: actions/checkout@v5
19+
with:
20+
path: engine
21+
22+
- name: Checkout docs
23+
uses: actions/checkout@v5
24+
with:
25+
path: docs
26+
repository: nanoforge-dev/docs
27+
token: ${{ secrets.ACTIONS_KEY }}
28+
29+
- name: setup git
30+
run: |
31+
git config --global user.name "github-actions[bot]"
32+
git config --global user.email "username@users.noreply.github.com"
33+
34+
- name: setup registry code documentation
35+
run: |
36+
apt install doxygen -y
37+
cd engine/packages/ecs-lib/docs
38+
doxygen Doxyfile
39+
cd -
40+
cp engine/packages/ecs-lib/docs engine/docs/registry/api
41+
42+
- name: synchronize docs
43+
run: |
44+
mkdir -p docs/engine
45+
cp engine/docs/. -r docs/engine
46+
cd docs
47+
git add .
48+
git commit -m "chore(engine): updating docs"
49+
git push origin main

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Nanoforge Documentation](https://github.com/NanoForge-dev/docs/actions/workflows/deploy.yml/badge.svg)](https://github.com/NanoForge-dev/docs/actions/workflows/deploy.yml)
2+
13
# Engine
24

35
This repository contains the full engine for NanoForge.
@@ -20,6 +22,10 @@ This is the full nanoforge engine including all the default libraries.
2022

2123
In order to manage this project we use (pnpm)[https://pnpm.io/]
2224

25+
## Documentation
26+
27+
The full documentation can be found at: [https://nanoforge-dev.github.io/docs/engine](https://nanoforge-dev.github.io/docs/engine)
28+
2329
## Installing dependencies
2430

2531
To install dependencies run:

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Doxyfile

docs/Introduction.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Documentation
2+
=============
3+
4+
The documentation for the engine is seperated between the different libraries of the engine.
5+
Then everything is packed up and put into this site. The documentation is handled on the engine repository and then automatically pushed.
6+
7+
This documentation is written in restructured text in order for it to be easier to operate with. We use sphinx to generate the relevant generated documentation.

docs/how_to_use.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Introduction to using the Engine
2+
================================
3+
4+
Whether you work on this engine as a devlopper or you wanna use this
5+
engine you gonna want to have a test project. This is a walkthrough on
6+
how to setup a basic project
7+
8+
As a devlopper on the engine
9+
----------------------------
10+
11+
As a devlopper you want to be able to use your changes in your project.
12+
Therefore it is recommended to use the provided `cli <https://github.com/NanoForge-dev/CLI>`__
13+
14+
As a user
15+
---------
16+
17+
As a user you can either use the template and change the dependencies
18+
location. Or you can create a project and add the nanoforge
19+
dependencies. Note that it is recommended to use bun as a package
20+
manager.

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Engine
2+
======
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
registry
8+
documentation.rst
9+
how_to_use.rst
10+
11+
In this doc you will find both the how to use and why use this engine as well as its library.
12+
To understand how to use this engine please refer to :doc:`/how_to_use`

docs/registry/index.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Writing Web Assembly
2+
====================
3+
4+
Code Splitting
5+
--------------
6+
7+
When writing Web Assembly modules, it's important to consider code
8+
splitting for readability and maintainability. We try to split binding
9+
and code logic into separate files where possible. This helps keep the
10+
codebase organized and makes it easier to navigate.
11+
12+
For example, in the ECS package, the binding logic is in ``.cpp`` files,
13+
while the core logic resides in ``.hpp`` files. This separation allows
14+
developers to focus on either the binding or the logic without being
15+
overwhelmed by both at the same time.
16+
17+
Documentation
18+
-------------
19+
20+
When documenting Web Assembly modules, we follow a similar approach to
21+
C++ documentation. We use Doxygen-style comments to provide clear and
22+
concise explanations of classes, methods, and parameters. This
23+
documentation is crucial for developers who will be using or maintaining
24+
the Web Assembly modules, as it provides necessary context and usage
25+
information.
26+
27+
Logging
28+
-------
29+
30+
Logging in Web Assembly is costly memory-wise due to the interaction
31+
between C++ and JavaScript. Therefore, we recommend to log from the
32+
JavaScript side whenever possible. If logging from C++ is necessary, be
33+
aware of the potential performance implications and memory leaks. Web
34+
assembly vm is memory limited, so excessive logging will lead to
35+
out-of-memory errors.

0 commit comments

Comments
 (0)