-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
# How Things Work? | ||
|
||
So, lets talk about how UWB works. | ||
So, lets talk about how UWB works internally. | ||
|
||
UWB is split into 3 sections: | ||
|
||
- Core (Unity side) | ||
- Shared (Glues the two sections together) | ||
- Engine (Externally ran process) | ||
|
||
All three sections are written in C#. As the engines are standalone applications, they use .NET 6, while the Unity side, is well... Unity. | ||
## The Three Sections | ||
|
||
## Core | ||
### Core | ||
|
||
The core is responsible for anything Unity related (such as handling getting Input or rendering to a <xref:UnityEngine.Texture>). It is provided as [standard custom UPM package](https://docs.unity3d.com/Manual/CustomPackages.html). | ||
The core is responsible for anything Unity related (such as handling getting Input, or rendering to a <xref:UnityEngine.Texture>). It is provided as [standard custom UPM package](https://docs.unity3d.com/Manual/CustomPackages.html). | ||
|
||
## Engine | ||
### Shared | ||
|
||
The engine is an external process that is responsible for taking the abstraction layer, and converting the calls to the calls that a web engine expects. This means that all that the core cares about is that the engine has support for the abstraction layer provided. | ||
The shared library provides the abstraction layer that is used by the two sides. | ||
|
||
Modern web engines are quite large (in binary size), and these binaries often have to be shipped with the engine them-selves, making them quite large as well. | ||
There is also a shared library for engines, which provides some shared functions that only engines need. | ||
|
||
## Shared | ||
### Engine | ||
|
||
The shared library provides the abstraction layer that is used by the two sides. | ||
The engine is an external process that the core starts up. The engine is what runs the actual web browser, and it is responsible for externally managing it outside of Unity. | ||
|
||
There is also a shared library for engines, which provides some shared functions that only engines need. | ||
Since the engine is an external process, it has it own set of application files. This application files get packaged into Unity packages that can also be installed via UPM. | ||
|
||
## Communication | ||
|
||
Ok, so we got the external engine process, and the core (Unity) process. We also have shared abstraction layer between the two. But how do these things talk to each other. Two different processes can't talk to each other, right? | ||
Ok, so we got the external engine process, and the core (Unity) process. We also have shared abstraction layer between the two. But how do these things talk to each other. | ||
|
||
Communication is done via [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call)s. We mainly uses RPCs instead of just directly writing data to a IPC pipe because using RPCs make programming and maintaining **a lot** easier. Under the hood, we use our own RPC library called [VoltRpc](https://github.com/Voltstro-Studios/VoltRpc). | ||
|
||
## Why not just run the web browser inside of Unity? | ||
|
||
Well technically you *could*, but there are two major issues: | ||
|
||
1. Modern web browsers run multiple processes them selves, with each process dedicated a task. They often launch these process from their own original application file. In the Unity editor that is essentially impossible, and with the Unity player it would mean having the overhead of Unity for every single sub-process. | ||
2. Most web browser are programmed with running one instance of them selves once, and if the browser needs to shutdown, then it probably means the user has requested to close the app. So the programmers making web browser under that assumption don't cleanup after native resources very well, since the OS will. With Unity, this a major issue. The Unity editor when changing play modes doesn't open and close, plus with Unity, the scene typically changes. This *probably* also wouldn't be an issue if [Unity could unload native binaries](https://docs.unity3d.com/Manual/PluginInspector.html). | ||
|
||
An example of this would be a project called [cef-unity-sample](https://github.com/aleab/cef-unity-sample). It runs CEF directly inside of Unity. It avoids the first point by running CEF in "Single Process mode", which is a now removed feature of CEF that allowed running CEF in a single process. But the second issue it suffers from, resulting in Unity crashing when reloading the scene in anyway. | ||
|
||
By running the web browser in a separate process, you avoid both issues. Yes it means having an entire second app ship with your Unity project, but you are already trying to run a web browser inside of Unity, so clearly resources are not your biggest concern. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters