Entity.Set<T> Slowdown Monogame FPS
See original GitHub issueHello,
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>();
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:38 (17 by maintainers)
Top Results From Across the Web
The use of a fixed time step
So what is the best way to make my engine fast enough to hold a lot of entity (if fixed time step slow...
Read more >[SOLVED] MonoGame drastically drops FPS at higher ...
When I tried to set my resolution to 800x600 to get a hi-res snapshot, the frame rate dropped tremendously (it could barely reach...
Read more >My 3 year experience with MonoGame
1- MonoGame is slow: I develop on a 2011 iPhone 4, which quickly shows any performance issues. Simply drawing a full screen blank...
Read more >Is Updating Sprite/Entity Movement Using Framerate ...
So if frames run longer than that, the simulation is allowed to fall behind real-time, so the gameplay can slow down - hopefully...
Read more >Lag if update() takes longer than frametime
I've just started using monogame and fiddled around with the update method. I wanted to test what would happen should my update method...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nice that will help alot for faster writing, yeah i just changed it to public xD
Hey congrats on finishing the jam! Would love to look around your code but I think your repo is private.
To simplify usage, since the new release of Visual Studio last week I have been working on a source generator analyzer to be much more expressive and safe, basically instead of
You would be able to just declare
and the constructors and update override would be automatically generated for you with the correct EntitySet composition. (I will never finish a game haha)