Skip to content

Commit

Permalink
Merge pull request #302 from stride3d/master
Browse files Browse the repository at this point in the history
Initiating deployment of latest docs updates to staging
  • Loading branch information
VaclavElias authored Jun 19, 2024
2 parents 99f994b + c6ce3b1 commit 1c9db4a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 7 deletions.
4 changes: 2 additions & 2 deletions en/manual/audio/custom-audio-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="badge text-bg-success">Programmer</span>

You can generate audio using your own mechanism. To do this, create a subclass of [DynamicSoundSource](xref:Stride.Audio.DynamicSoundSource).
For an example of how to implement this, see the [CompressedSoundSource` source code](https://github.com/SiliconStudio/stride/blob/master-1.8/sources/engine/Stride.Audio/CompressedSoundSource.cs).
For an example of how to implement this, see the [CompressedSoundSource` source code](https://github.com/Stride3d/stride/blob/master/sources/engine/Stride.Audio/CompressedSoundSource.cs).

## Example code

Expand All @@ -23,4 +23,4 @@ myCustomInstance.Play();
```

## See also
* [Global audio settings](global-audio-settings.md)
* [Global audio settings](global-audio-settings.md)
94 changes: 94 additions & 0 deletions en/manual/engine/entity-component-system/flexible-processing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Flexible Processing

This document expects the reader to be familiar with ECS, please take a look at [usage](usage.md) first.

Handling components through [`EntityProcessor`](xref:Stride.Engine.EntityProcessor) may be too rigid in some cases, when the components
you're trying to process cannot share the same base implementation for example.

[`Stride.Engine.FlexibleProcessing.IComponent<TProcessor, TThis>`](xref:Stride.Engine.FlexibleProcessing.IComponent`2)
provides similar features to [`EntityProcessor`](xref:Stride.Engine.EntityProcessor) while being more flexible on the component type,
this document covers some of the usage of this particular interface.

The `IComponent` interface requires to type parameters,
- `TProcessor` which is your processor's type.
- And `TThis` which is your component's type.

While that last type may seem redundant, it is required to ensure your processor and
your implemented type are compatible.

A summarised example satisfying those type constraint would look like so:
```cs
public class MyComponent : StartupScript, IComponent<MyComponent.MyProcessor, MyComponent>
{
public class MyProcessor : IProcessor
{
public List<MyComponent> Components = new();

public void SystemAdded(IServiceRegistry registryParam) { }
public void SystemRemoved() { }

public void OnComponentAdded(MyComponent item) => Components.Add(item);
public void OnComponentRemoved(MyComponent item) => Components.Remove(item);
}
}
```

The main difference compared to [`EntityProcessor`](xref:Stride.Engine.EntityProcessor)
is that [`IComponent`](xref:Stride.Engine.FlexibleProcessing.IComponent`2) is not limited to concrete types, your processor may operate on interfaces as well;
```cs
// Here, declaring the interface, which will be the type received by the processor
public interface IInteractable : IComponent<IInteractable.ShapeProcessor, IInteractable>
{
void Interact();
public class InteractableProcessor : IProcessor
{
// Process each IInteractable here
// Omitted method implementation for brievety
}
}

// Now any component implementing IInteractable will be processed by the ShapeProcessor
public class Button : StartupScript, IInteractable
{
public void Interact(){}
}
public class Character : SyncScript, IInteractable
{
public void Interact(){}
public override void Update(){}
}
```

## Updating Processors
[`Processors`](xref:Stride.Engine.FlexibleProcessing.IComponent`2) do not receive any updates by default, you have to implement the [`IUpdateProcessor`](xref:Stride.Engine.FlexibleProcessing.IUpdateProcessor) or [`IDrawProcessor`](xref:Stride.Engine.FlexibleProcessing.IDrawProcessor)
interface to receive them:
```cs
public interface ISpecialTick : IComponent<ISpecialTick.Processor, ISpecialTick>
{
void Tick();

public class Processor : IProcessor, IUpdateProcessor
{
public List<ISpecialTick> Components = new();

public void SystemAdded(IServiceRegistry registryParam) { }
public void SystemRemoved() { }

public void OnComponentAdded(ISpecialTick item) => Components.Add(item);
public void OnComponentRemoved(ISpecialTick item) => Components.Remove(item);

// The execution order of this Update, smaller values execute first compared to other IComponent Processors
public int Order => 0;

public void Update(GameTime gameTime)
{
foreach (var comp in Components)
comp.Tick();
}
}
}
```

## Performance
While it is more flexible, processing components as interfaces instead of concrete class may introduce some overhead.
If the system you're writing is performance critical you should look into strategies to elide or reduce virtual calls in your hot path.
1 change: 1 addition & 0 deletions en/manual/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ These pages contain information about how to use Stride, an open-source C# game
## Latest documentation

### Recent updates
- <span class="badge text-bg-info">New</span> [ECS - Flexible Processing](engine/entity-component-system/flexible-processing.md) - Description and example of the Flexible Processing system
- <span class="badge text-bg-info">Updated</span> [Linux - Setup and requirements](platforms/linux/setup-and-requirements.md) - Fedora OS option added
- <span class="badge text-bg-success">New</span> [Scripts - Serialization](scripts/serialization.md) - Explanation of serialization
- <span class="badge text-bg-info">Updated</span> [Scripts - Public properties and fields](scripts/public-properties-and-fields.md) - Content improvements and additions
Expand Down
7 changes: 5 additions & 2 deletions en/manual/platforms/linux/setup-and-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You need the following packages:
* [FreeType](#freetype)
* [OpenAL](#openal)
* [SDL2](#sdl2)
* [Latest .NET](https://dotnet.microsoft.com/en-us/download)
* [FreeImage](#freeimage)

## FreeType

Expand Down Expand Up @@ -85,9 +85,11 @@ sudo dnf install SDL2-devel
sudo pacman -S sdl2
```

---

## FreeImage

FreeImage is battle-tested library for loading and saving popular image file formats like BMP, PNG, JPEG etc. The minimum required version is 3.18 and can be installed via:
[FreeImage](https://freeimage.sourceforge.io/) is battle-tested library for loading and saving popular image file formats like BMP, PNG, JPEG etc. The minimum required version is 3.18 and can be installed via:


### [Debian / Ubuntu](#tab/freeimage-ubuntu)
Expand All @@ -108,6 +110,7 @@ sudo dnf install freeimage-devel
sudo pacman -S freeimage
```

---

## See also

Expand Down
6 changes: 3 additions & 3 deletions en/manual/requirements/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ To develop projects with Stride, you need:
(2) RAM requirements vary depending on your project:
* Developing simple 2D applications doesn't require much RAM.
* Developing 3D games with lots of assets requires larger amounts of RAM.
(3) .NET SDK is being downloaded with the Stride installer

(3) .NET SDK is being downloaded with the Stride installer.

## Mobile development requirements

Expand All @@ -30,7 +30,7 @@ To develop for mobile platforms, you also need:
| Android | Xamarin <small class="text-secondary">[see (4)]</small>
| iOS | Mac computer, Xamarin <small class="text-secondary">[see (4)]</small>

(4) Xamarin is included with Visual Studio installations. For instructions about how to install Xamarin with Visual Studio, see [this MSDN page](https://docs.microsoft.com/en-us/visualstudio/cross-platform/setup-and-install).
(4) Xamarin is included with Visual Studio installations. For instructions on installing Xamarin with Visual Studio, see [this MSDN page](https://docs.microsoft.com/en-us/visualstudio/cross-platform/setup-and-install).

## Running Stride Games

Expand Down
2 changes: 2 additions & 0 deletions en/manual/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ items:
href: engine/entity-component-system/usage.md
- name: Manage entities
href: engine/entity-component-system/managing-entities.md
- name: Flexible processing
href: engine/entity-component-system/flexible-processing.md
- name: File system
href: engine/file-system.md
- name: Build pipeline
Expand Down

0 comments on commit 1c9db4a

Please sign in to comment.