-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisibleSystem.cs
More file actions
48 lines (38 loc) · 1.36 KB
/
Copy pathVisibleSystem.cs
File metadata and controls
48 lines (38 loc) · 1.36 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
using Hexecs.Actors.Systems;
using Hexecs.Benchmarks.Map.Common.Positions;
using Hexecs.Benchmarks.Map.Terrains;
using Hexecs.Benchmarks.Map.Utils;
using Hexecs.Threading;
using Hexecs.Worlds;
namespace Hexecs.Benchmarks.Map.Common.Visibles;
internal sealed class VisibleSystem : UpdateSystem<Position>
{
private readonly Camera _camera;
private readonly int _tileSize;
private CameraViewport _currentViewport;
public VisibleSystem(ActorContext context, Camera camera, IParallelWorker parallelWorker, TerrainSettings settings)
: base(context, parallelWorker: parallelWorker)
{
_camera = camera;
_tileSize = settings.TileSize;
}
protected override bool BeforeUpdate(in WorldTime time)
{
var currentViewport = _camera.Viewport;
if (currentViewport.Equals(_currentViewport)) return false; // не обновляем, если камера не двигалась
_currentViewport = currentViewport;
return true;
}
protected override void Update(in ActorRef<Position> actor, in WorldTime time)
{
ref readonly var position = ref actor.Component1.World;
if (_currentViewport.Visible(position.X, position.Y, _tileSize, _tileSize))
{
actor.TryAdd(new Visible());
}
else
{
actor.Remove<Visible>();
}
}
}