DefaultEcs: Entity.Set Slowdown Monogame FPS
Hello,
i have trouble to find the solutions for the following Problem:
If i add this Line of Code my Fps go from 3000 to 60 in Monogame tiles[tile + j].Set<Show>();
I have 3 Systems,
the first one Update my Tiles i want to draw if they are inside of my View:
protected override void Update(float elaspedTime, ref Map component)
{
ReadOnlySpan<Entity> tiles = mapTiles.GetEntities();
Camera cameraData = camera.Get<Camera>();
var tilesizex = 32;
var tilesizey = 8;
var XMapZeichnen = new Point((int)cameraData.VisibleArea.X / tilesizex, (int)(cameraData.VisibleArea.X + cameraData.VisibleArea.Width) / tilesizex);
if (XMapZeichnen.X < 0) XMapZeichnen.X = 0;
if (XMapZeichnen.Y > component.Size.X) XMapZeichnen.Y = component.Size.X;
var YMapZeichnen = new Point((int)cameraData.VisibleArea.Y / tilesizey, (int)(cameraData.VisibleArea.Y + cameraData.VisibleArea.Height) / tilesizey);
if (YMapZeichnen.X < 0) YMapZeichnen.X = 0;
if (YMapZeichnen.Y > component.Size.Y) YMapZeichnen.Y = component.Size.Y;
for (int i = YMapZeichnen.X; i < YMapZeichnen.Y; i++)
{
var tile = i * component.Size.X;
for (int j = XMapZeichnen.X; j < XMapZeichnen.Y; j++)
{
tiles[tile + j].Set<Show>();
}
}
}
And my DrawSystem:
[With(typeof(MapTile), typeof(MapTextureShared), typeof(Show))]
public sealed class DrawMapSystem : AEntitySystem<float>
{
private readonly SpriteBatch _batch;
private readonly TileProperty[] _tilePropertys;
private readonly World _world;
public DrawMapSystem(SpriteBatch batch, World world)
: base(world)
{
_batch = batch;
_tilePropertys = world.GetAllComponents<TileProperty>().ToArray();
_world = world;
}
protected override void Update(float elaspedTime, in Entity entity)
{
ref MapTile mapTile = ref entity.Get<MapTile>();
ref MapTextureShared mapTextureShared = ref entity.Get<MapTextureShared>();
_batch.Draw(mapTextureShared.TextureSheet, mapTile.Position, _tilePropertys[mapTile.ID].Source, Color.White);
}
protected override void PreUpdate(float state)
{
_batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _world.GetAllComponents<Camera>()[0].Transform);
}
protected override void PostUpdate(float state)
{
_batch.End();
}
}
And one of the Start of the new Update Cycle to do the following:
[With(typeof(Show))]
public sealed class ShowSystem : AEntitySystem<float>
{
public ShowSystem(World world)
: base(world)
{
}
protected override void Update(float elaspedTime, in Entity entity)
{
entity.Remove<Show>();
}
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 38 (17 by maintainers)
Nice that will help alot for faster writing, yeah i just changed it to public xD