-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerrainDrawSystem.cs
More file actions
57 lines (48 loc) · 1.67 KB
/
Copy pathTerrainDrawSystem.cs
File metadata and controls
57 lines (48 loc) · 1.67 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
using Hexecs.Actors.Systems;
using Hexecs.Benchmarks.Map.Common.Positions;
using Hexecs.Benchmarks.Map.Common.Visibles;
using Hexecs.Benchmarks.Map.Utils;
using Hexecs.Worlds;
using Microsoft.Xna.Framework.Graphics;
namespace Hexecs.Benchmarks.Map.Terrains;
internal sealed class TerrainDrawSystem : DrawSystem<Position, Terrain>
{
private readonly Camera _camera;
private readonly TerrainSpriteAtlas _spriteAtlas;
private readonly SpriteBatch _spriteBatch;
public TerrainDrawSystem(
Camera camera,
ActorContext context,
GraphicsDevice graphicsDevice,
TerrainSpriteAtlas spriteAtlas)
: base(context, constraint => constraint.Include<Visible>())
{
_camera = camera;
_spriteAtlas = spriteAtlas;
_spriteBatch = new SpriteBatch(graphicsDevice);
}
protected override bool BeforeDraw(in WorldTime time)
{
_spriteBatch.Begin(
transformMatrix: _camera.TransformationMatrix,
samplerState: SamplerState.PointClamp,
blendState: BlendState.AlphaBlend);
return true;
}
protected override void Draw(in ActorRef<Position, Terrain> actor, in WorldTime time)
{
ref readonly var terrain = ref actor.Component2;
ref readonly var texture = ref _spriteAtlas.GetSprite(in terrain);
ref readonly var worldPosition = ref actor.Component1.World;
texture.Draw(_spriteBatch, new Vector2(worldPosition.X, worldPosition.Y));
}
protected override void AfterDraw(in WorldTime time)
{
_spriteBatch.End();
}
public override void Dispose()
{
_spriteBatch.Dispose();
base.Dispose();
}
}