Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/413880438407856128

I use Artemis and LibGDX. I have the following components two components which manipulate ana texture:

Than I have a System that requires the Texture and position component(Thats the minimum to draw a texture) and draw them to screen, but before itI render I check forif it has some possible extra components that maybe have for example a rotation component.

Maintenance I can create 5000 Entities with textures and ana small rotation animation. I know its veryI'm wondering about the efficiency of this method and how bad, that of a performance hit I create in methodwill get from creating a lot of new instances, but this is only for in the development and for a better "layout"method. Later I willI plan to optimize this.

Now my question, haveDoes anyone have a good idea as to how I can get a better performance, how from drawing textures?

How I can avoid tothe check for every component that the entity maybe has? I hope someone know a good idea.  

Thanks for reading :D

I use Artemis and LibGDX. I have following components two manipulate an texture:

Than I have a System that requires the Texture and position component(Thats the minimum to draw a texture) and draw them to screen, but before it check for components that maybe have for example a rotation component.

Maintenance I can create 5000 Entities with textures and an small rotation animation. I know its very bad, that I create in method a lot of new instances, but this is only for the development and for a better "layout". Later I will optimize this.

Now my question, have anyone a good idea how can get a better performance, how I can avoid to check for every component that the entity maybe has? I hope someone know a good idea. Thanks for reading :D

I use Artemis and LibGDX. I have the following two components which manipulate a texture:

Than I have a System that requires the Texture and position component(Thats the minimum to draw a texture) and draw them to screen, before I render I check if it has some possible extra components.

I can create 5000 Entities with textures and a small rotation animation. I'm wondering about the efficiency of this method and how bad of a performance hit I will get from creating a lot of instances in the method. I plan to optimize this.

Does anyone have a good idea as to how I can get better performance from drawing textures?

How I can avoid the check for every component that the entity has? 

Thanks for reading :D

Source Link
user2933016
  • 313
  • 4
  • 10

Entity System Texture Rendering Performance Java

I use Artemis and LibGDX. I have following components two manipulate an texture:

  • ComponentTexture // Stores the texture
  • ComponentSource // Define a region for the texture, that will only be shown
  • ComponentSize // The size of the texture
  • ComponentMirror // Stores wether you want to flup on x and y axe
  • ComponentOrigin // The origin of the texture
  • ComponentPosition // The position of the texture
  • ComponentRotation // Rotation of the texture
  • ComponentScale // The scale of the texture

Than I have a System that requires the Texture and position component(Thats the minimum to draw a texture) and draw them to screen, but before it check for components that maybe have for example a rotation component.

@Override protected void process(Entity entity) 
{
    final ComponentTexture  componentTexture    = mComponentTextureMapper.get(entity);
    final ComponentSource   componentSource     = mComponentSourceMapper.getSafe(entity);
    final ComponentSize     componentSize       = mComponentSizeMapper.getSafe(entity);
    final ComponentMirror   componentMirror     = mComponentMirrorMapper.getSafe(entity);
    final ComponentOrigin   componentOrigin     = mComponentOriginMapper.getSafe(entity);
    final ComponentPosition componentPosition   = mComponentPositionMapper.get(entity);
    final ComponentRotation componentRotation   = mComponentRotationMapper.getSafe(entity);
    final ComponentScale    componentScale      = mComponentScaleMapper.getSafe(entity);
    
    // Texture
    final Texture texture = componentTexture.getTexture();
    
    // Source
    final Rectangle source;
    if(componentSource == null)
    {
        source = new Rectangle(0, 0, texture.getWidth(), texture.getHeight());
    }
    else
    {
        source = componentSource.getSource();
    }
    
    // Size
    final Vector2 size;
    if(componentSize == null)
    {
        size = new Vector2(texture.getWidth(), texture.getHeight());
    }
    else
    {
        size = componentSize.getSize();
    }
    
    // Mirror
    final boolean mirrorX;
    final boolean mirrorY;
    if(componentMirror == null)
    {
        mirrorX = false;
        mirrorY = false;
    }
    else
    {
        mirrorX = componentMirror.isMirrorX();
        mirrorY = componentMirror.isMirrorY();
    }
    
    // Origin
    final Vector2 origin;
    if(componentOrigin == null)
    {
        origin = new Vector2(0, 0);
    }
    else
    {
        origin = componentOrigin.getOrigin();
    }
    
    // Position
    final Vector2 position = componentPosition.getPostion();
    
    // Rotation
    final float rotation;
    if(componentRotation == null)
    {
        rotation = 0;
    }
    else
    {
        rotation = componentRotation.getRotation();
    }
    
    // Scale
    final Vector2 scale;
    if(componentScale == null)
    {
        scale = new Vector2(1, 1);
    }
    else
    {
        scale = componentScale.getScale();
    }
    
    mSpriteBatch.draw(texture, position.x - origin.x, position.y - origin.y, origin.x, origin.y, size.x, size.y, scale.x, scale.y, rotation, (int) source.x, (int) source.y, (int) source.width, (int) source.height, mirrorX, mirrorY);
}

Maintenance I can create 5000 Entities with textures and an small rotation animation. I know its very bad, that I create in method a lot of new instances, but this is only for the development and for a better "layout". Later I will optimize this.

Now my question, have anyone a good idea how can get a better performance, how I can avoid to check for every component that the entity maybe has? I hope someone know a good idea. Thanks for reading :D