-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathLandscapePlugin.cs
More file actions
122 lines (99 loc) · 5.05 KB
/
Copy pathLandscapePlugin.cs
File metadata and controls
122 lines (99 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Arch.SystemGroups;
using Cysharp.Threading.Tasks;
using DCL.AssetsProvision;
using DCL.DebugUtilities;
using DCL.Landscape;
using DCL.Landscape.Config;
using DCL.Landscape.Settings;
using DCL.Landscape.Systems;
using DCL.MapRenderer.ComponentsFactory;
using ECS;
using ECS.Prioritization;
using GPUInstancerPro;
using System.Threading;
using DCL.Diagnostics;
using Unity.Collections;
using Unity.Mathematics;
using LandscapeDebugSystem = DCL.Landscape.Systems.LandscapeDebugSystem;
namespace DCL.PluginSystem.Global
{
using Landscape = global::Global.Dynamic.Landscapes.Landscape;
public class LandscapePlugin : IDCLGlobalPlugin<LandscapeSettings>
{
private readonly TerrainGenerator terrainGenerator;
private readonly WorldTerrainGenerator worldTerrainGenerator;
private readonly Landscape landscape;
private readonly IRealmData realmData;
private readonly IAssetsProvisioner assetsProvisioner;
private readonly IDebugContainerBuilder debugContainerBuilder;
private readonly MapRendererTextureContainer textureContainer;
private readonly bool enableLandscape;
private RealmPartitionSettingsAsset realmPartitionSettings;
private ProvidedAsset<LandscapeData> landscapeData;
private NativeParallelHashSet<int2> emptyParcels;
private NativeParallelHashSet<int2> ownedParcels;
private SatelliteFloor? floor;
// private IGPUIWrapper gpuiWrapper;
public LandscapePlugin(IRealmData realmData,
TerrainGenerator terrainGenerator,
WorldTerrainGenerator worldTerrainGenerator,
IAssetsProvisioner assetsProvisioner,
IDebugContainerBuilder debugContainerBuilder,
MapRendererTextureContainer textureContainer,
bool enableLandscape,
Landscape landscape)
{
this.realmData = realmData;
this.assetsProvisioner = assetsProvisioner;
this.debugContainerBuilder = debugContainerBuilder;
this.textureContainer = textureContainer;
this.enableLandscape = enableLandscape;
this.terrainGenerator = terrainGenerator;
this.worldTerrainGenerator = worldTerrainGenerator;
this.landscape = landscape;
// gpuiWrapper = new GPUIWrapper();
}
public void Dispose()
{
if (enableLandscape)
{
terrainGenerator.Dispose();
worldTerrainGenerator.Dispose();
}
}
public async UniTask InitializeAsync(LandscapeSettings settings, CancellationToken ct)
{
landscapeData = await assetsProvisioner.ProvideMainAssetAsync(settings.landscapeData, ct);
floor = new SatelliteFloor(realmData, landscapeData.Value);
if (!enableLandscape) return;
realmPartitionSettings = settings.realmPartitionSettings;
GPUIProfile treesProfile = landscapeData.Value.TreesProfile;
LandscapeAsset[] treePrototypes = landscapeData.Value.terrainData.treeAssets;
int[] treeRendererKeys = new int[treePrototypes.Length];
for (int prototypeIndex = 0; prototypeIndex < treePrototypes.Length; prototypeIndex++)
{
await UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, ct);
var result = await GPUICoreAPI.RegisterRenderer(landscape.Root,
treePrototypes[prototypeIndex].asset, treesProfile);
treeRendererKeys[prototypeIndex] = result.rendererKey;
ReportHub.Log(ReportCategory.LANDSCAPE, $"LandscapePlugin: Registered Renderer Key {treeRendererKeys[prototypeIndex]} for prototype {prototypeIndex} ({treePrototypes[prototypeIndex].asset.name})");
}
terrainGenerator.Initialize(landscapeData.Value.terrainData, treeRendererKeys, landscapeData.Value);
await worldTerrainGenerator.InitializeAsync(landscapeData.Value.worldsTerrainData,
treeRendererKeys, landscapeData.Value);
}
public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder, in GlobalPluginArguments arguments)
{
LandscapeSatelliteSystem.InjectToWorld(ref builder, textureContainer, floor);
if (!enableLandscape) return;
LandscapeDebugSystem.InjectToWorld(ref builder, debugContainerBuilder, floor,
realmPartitionSettings, landscape, landscapeData.Value);
//LandscapeTerrainCullingSystem.InjectToWorld(ref builder, landscapeData.Value, terrainGenerator);
LandscapeMiscCullingSystem.InjectToWorld(ref builder, landscapeData.Value, terrainGenerator);
//LandscapeCollidersCullingSystem.InjectToWorld(ref builder, terrainGenerator, scenesCache, loadingStatus);
RenderGroundSystem.InjectToWorld(ref builder, landscape, landscapeData.Value);
CollideTerrainSystem.InjectToWorld(ref builder, landscape, landscapeData.Value);
// gpuiWrapper.InjectDebugSystem(ref builder, debugContainerBuilder);
}
}
}