Skip to content

Commit

Permalink
Merge pull request #2 from xuri-ajiva/develop
Browse files Browse the repository at this point in the history
Merge for dependency_injection and spatial_acceleration and physics system
  • Loading branch information
xuri-ajiva authored Sep 19, 2023
2 parents 650c3bd + fef3d5e commit 388c205
Show file tree
Hide file tree
Showing 303 changed files with 7,240 additions and 4,693 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,36 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0'
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

- run: |
dotnet build ./src/ajiva/ajiva.csproj -c release
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
14 changes: 7 additions & 7 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Restore dependencies
working-directory: ./src/ajiva
working-directory: ./src/Ajiva.Application
run: dotnet restore
- name: Build
working-directory: ./src/ajiva
working-directory: ./src/Ajiva.Application
run: dotnet build --no-restore
- name: Test
working-directory: ./src/ajiva.Test
run: dotnet test --no-build --verbosity normal
working-directory: ./src/Ajiva.Test
run: dotnet test --verbosity normal
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "libs/ajiva-utils"]
path = libs/ajiva-utils
url = git@github.com:ajiva-group/ajiva-utils.git
[submodule "libs/SharpVk"]
path = libs/SharpVk
url = git@github.com:xuri02/SharpVk.git
[submodule "libs/GlmSharp"]
path = libs/GlmSharp
url = git@github.com:xuri02/GlmSharp.git
127 changes: 117 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,126 @@
Ajiva is a Game Engine based using Vulcan to render graphics. Its written in c# and uses the PInvoke method to call
native methods.

The engine uses a custom Event based Entity Component System (ECS) to handle interactions between all system. Event
based means, that e.g the Transform component will fire and event on change, using the IChangingObserver, the render
## Features

### Entity Component System (ECS)

The engine uses a custom Event based Entity Component System (ECS) to handle interactions between all system.
Event based means, that e.g the Transform component will fire and event on change, using the IChangingObserver, the render
system can react to this and update the Uniform Buffer.

## Dependencies
[Dependency graph](https://github.com/xuri02/ajiva/network/dependencies)
### Dependency Injection

Migrated to [Autofac](https://github.com/autofac/Autofac) for Dependency Injection.
In older versions the ECS was used to inject dependencies, but this made it overcomplicated and hard to maintain lifetimes for the dependencies, witch we need for later Scene loading / unloading.

### Entitys

Entitys are generated by a [Source Generator](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview) ([Ajiva.Generator](src/Ajiva.Generator)).
This works by Tagging a class with the [EntityComponent] Attribute and parsing the class for all components as parameters.

```csharp
[EntityComponent(typeof(Transform3d))]
public sealed partial class FpsCamera : IUpdate, IDisposable { ... }
```

The Generator will then generate a partial class implementing the IEntity interface and adding the components as properties.
Additionally the Generator will generate a Factory class for each Entity, with a fluent interface to configure the Entity.

<details>
<summary>Code</summary>

```csharp
public partial class FpsCamera : IEntity
{
public Guid Id { get; } = Guid.NewGuid();
public Transform3d Transform3d { get; protected set; }
public bool TryGetComponent<TComponent>([MaybeNullWhen(false)] out TComponent value) where TComponent : IComponent { ... }
public bool HasComponent<TComponent>() where TComponent : IComponent { ... }
public TComponent Get<TComponent>() where TComponent : IComponent { ... }
public FpsCamera Configure<TComponent>(Action<TComponent> configuration) where TComponent : IComponent { ... }
public IEnumerable<IComponent> GetComponents() { ... }
public IEnumerable<Type> GetComponentTypes() { ... }
protected FpsCamera() {}
internal static FpsCamera CreateEmpty() { return new(); }
}

public ref struct Creator {
public FpsCameraFactoryData FactoryData;
public Transform3d? Transform3d;
public FpsCamera Create() { ... }
public FpsCamera Finalize() { ... }
public FpsCamera.Creator With(Transform3d val) { Transform3d = val; return this; }
}
public partial record FpsCameraFactoryData(IComponentSystem<Transform3d> Transform3d, IEntityRegistry EntityRegistry) : FactoryData {
public FpsCamera.Creator Begin() => new() { FactoryData = this };
}
```

</details>

Last of all the Generator will generate a Extension for Autofac to register Factory in DI.
The usage of the Factory is as follows:

```csharp
var factory = this.container.Resolve<EntityFactory>() // get universal factory
var cube = factory.CreateCube()
.With(new Transform3d {
Position = Vector3.Zero,
Rotation = Vector3.Zero,
Scale = Vector3.One
})
.Finalize() // creates the Entity with all Specified Components all not specified Components will be resolved using autofac from corresponding ComponentSystems
.Configure<CollisionsComponent>(c => c.MeshId = MeshPrefab.Cube.MeshId)
.Configure<PhysicsComponent>(p => p.IsStatic = true);
```

### Bounding Boxes / Spatial Partitioning

Bounding Boxes are a Component that listens for updates on the Transform Component and updates the Bounding Box accordingly using a custom WorkerPool.
The Updated Bounding Box is stored in a Dynamic Octal Tree, witch is used for Spatial Partitioning.

The Dynamic Octal Tree is a custom implementation of a Octal Tree, witch is used to store the Bounding Boxes of all Entitys. It Dynamically Expands if a Entitys Bounding Box dose not lie within the current bounds of the Tree. This reduces the maximum depth of the Tree, but keeps all Entitys in leaf nodes beyond the maximum depth.

The Dynamic Octal Tree supports a debug visualization, witch pools debug boxes for each node and renders using the debug Bounding box Layer.

<details>
<summary>Image</summary>

![Octal Tree](img/SpatialPartitioning_Debug.png)
</details>

### Renderer

Overengineered Renderer, supports LayerSystems as `Ajiva3dLayerSystem` and `Ajiva2dLayerSystem` witch are used to render 3d and 2d Layers respectively. Currently we have `SolidMeshRenderLayer` and `DebugLayer` as 3d Layers and `Mesh2dRenderLayer` as 2d Layer. These Layers are Combined in the `AjivaLayerRenderer` 'blends' (color.w < .1) the output of the Layers together.

The 3d Renders use Instancing to render multiple Meshes at different positions in one draw call.

![Instancing](img/Instancing.png)
<details>
<summary>Debug</summary>

![Instancing_Debug](img/Instancing_Debug.png)
</details>


## Dependencies

[Dependency graph](https://github.com/xuri-ajiva/ajiva-vulcan/network/dependencies)

Located in [libs](libs) are some adjusted libraries

Located in [libs](libs) are some adjusted libraries
| name | Description | Author |
| :------- | :-------------------------------------------- | :---------------------------------------------------- |
| SharpVk | C#/.NET Bindings for the Vulkan API | [Andrew Armstrong](https://github.com/FacticiusVir) |
| Autofac | Dependency Injection Container | [Autofac](https://github.com/autofac/Autofac) |
| Serilog | Logging | [Serilog](https://github.com/serilog/serilog) |

| name | Description | Author | License |
|:-------------|:----------------------------------------------|:-------------------------------------------------------|:--------------------------------------------------------------------|
| ajiva-utils | a custom lib written by me | none # todo | [xuri](https://github.com/xuri02) |
| GlmSharp | C#/.NET math library for vectors and matrices | [Philip Trettner](https://github.com/Philip-Trettner) | [MIT License](https://github.com/xuri02/GlmSharp/blob/main/LICENSE) |
| SharpVk | C#/.NET Bindings for the Vulkan API | [Andrew Armstrong](https://github.com/FacticiusVir) | [MIT License](https://github.com/xuri02/SharpVk/blob/main/LICENSE) |
## Credits

This core is Inspired / Base On:

- FacticiusVir/[SharpVk-Samples](https://github.com/FacticiusVir/SharpVk-Samples)
- Pilzschaf/[OpenGLTutorial](https://github.com/Pilzschaf/OpenGLTutorial)
- OneLoneCoder/[Javidx9](https://github.com/OneLoneCoder/Javidx9/blob/master/PixelGameEngine/SmallerProjects/OneLoneCoder_PGE_QuadTree1.cpp)
- [Vulkan Tutorial.com](https://vulkan-tutorial.com/)
Binary file added img/Instancing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Instancing_Debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/SpatialPartitioning_Debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion libs/GlmSharp
Submodule GlmSharp deleted from df960f
2 changes: 1 addition & 1 deletion libs/SharpVk
1 change: 0 additions & 1 deletion libs/ajiva-utils
Submodule ajiva-utils deleted from 77b31e
22 changes: 0 additions & 22 deletions src/.run/ajiva-shaders.run.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/.run/shader-compile-2d.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<configuration default="false" name="shader-compile-2d" type="RunNativeExe" factoryName="Native Executable">
<option name="EXE_PATH" value="$PROJECT_DIR$/tools/spirv/glslangValidator.exe" />
<option name="PROGRAM_PARAMETERS" value=".\shader.frag .\shader.vert -V" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ajiva/Shaders/2d" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Ajiva/Shaders/2d" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<method v="2" />
</configuration>
</component>
</component>
4 changes: 2 additions & 2 deletions src/.run/shader-compile-3d.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<configuration default="false" name="shader-compile-3d" type="RunNativeExe" factoryName="Native Executable">
<option name="EXE_PATH" value="$PROJECT_DIR$/tools/spirv/glslangValidator.exe" />
<option name="PROGRAM_PARAMETERS" value=".\shader.frag .\shader.vert -V" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ajiva/Shaders/3d" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Ajiva/Shaders/3d" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<method v="2" />
</configuration>
</component>
</component>
4 changes: 4 additions & 0 deletions src/Ajiva.Application/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Assets/default.asset
Assets/default.asset.sha1.txt
Assets/**/*.spv
Logs
32 changes: 32 additions & 0 deletions src/Ajiva.Application/Ajiva.Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Ajiva.Ecs\Ajiva.Ecs.csproj" />
<!--<ProjectReference Include="..\Ajiva.Generator\Ajiva.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
-->
<ProjectReference Include="..\Ajiva\Ajiva.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="7.0.1" />
<PackageReference Include="Autofac.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
<PackageReference Include="Serilog.Extensions.Autofac.DependencyInjection" Version="5.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions src/Ajiva.Application/Ajiva.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"WindowConfig": {
"Width": 1600,
"Height": 1200,
"PosX": 200,
"PosY": 100
},
"ShaderConfig": {
"TEXTURE_SAMPLER_COUNT": 128
},
"CameraConfig": {
"Position": {
"X": -25.601406,
"Y": 19.519276,
"Z": -222.3893
},
"Rotation": {
"X": -9.900001,
"Y": -10.799999,
"Z": 0
},
"Zoom": 1,
"Near": 0.1,
"Far": 1000,
"Fov": 100,
"Speed": 0.1,
"Sensitivity": 0.1,
"AspectRatio": 1.3333334
},
"AssetPath": "Assets/default.asset"
}
Loading

0 comments on commit 388c205

Please sign in to comment.