package net.mgsx.game.plugins.ashley.systems;

import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.PooledEngine;

import net.mgsx.game.core.annotations.Editable;
import net.mgsx.game.core.annotations.EditableSystem;

@EditableSystem
public class AshleyProfilerSystem extends EntitySystem
{
	@Editable(realtime=true, readonly=true)
	public int entities;
	
	@Editable(realtime=true, readonly=true)
	public int systems;
	
	@Editable
	public void clearPools(){
		if(getEngine() instanceof PooledEngine)
		{
			PooledEngine engine = (PooledEngine)getEngine();
			engine.clearPools();
		}
	}
	
	public AshleyProfilerSystem() {
		super();
		setProcessing(false); // TODO config
	}
	
	@Override
	public void update(float deltaTime) {
		entities = getEngine().getEntities().size();
		systems = getEngine().getSystems().size();
	}
}

@@ -131,16 +131,56 @@
 dEngine;
+%0Aimport com.badlogic.gdx.math.MathUtils;
 %0A%0Aimport
@@ -274,16 +274,64 @@
 eSystem;
+%0Aimport net.mgsx.game.core.annotations.EnumType;
 %0A%0A@Edita
@@ -522,24 +522,311 @@
  systems;%0A%09%0A
+%09@Editable(realtime=true, readonly=true, type=EnumType.BYTES)%0A%09public float memory;%0A%09%0A%09@Editable(realtime=true, readonly=true, type=EnumType.BYTES)%0A%09public float memoryRate;%0A%09%0A%09private transient long prevMemory;%0A%09private transient long consumedMemory;%0A%09private transient float time;%0A%09%0A%09%0A
 %09@Editable%0A%09
@@ -1070,16 +1070,85 @@
 ig%0A%09%7D%0A%09%0A
+%09@Editable%0A%09public void forceGC()%7B%0A%09%09Runtime.getRuntime().gc();%0A%09%7D%0A%09%0A
 %09@Overri
@@ -1236,16 +1236,16 @@
 size();%0A
-
 %09%09system
@@ -1281,13 +1281,491 @@
 size();%0A
+%09%09%0A%09%09time += deltaTime;%0A%09%09%0A%09%09long currentMemoryUsage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();%0A%09%09long deltaMemory = currentMemoryUsage - prevMemory;%0A%09%09if(deltaMemory %3E 0)%7B%0A%09%09%09consumedMemory += currentMemoryUsage - prevMemory;%0A%09%09%09if(time %3E 0)%7B%0A%09%09%09%09memoryRate = consumedMemory / time;%0A%09%09%09%7D%0A%09%09%7Delse if(deltaMemory %3C 0)%7B%0A%09%09%09consumedMemory = 0;%0A%09%09%09time = 0;%0A%09%09%7D%0A%09%09prevMemory = currentMemoryUsage;%0A%09%09%0A%09%09%0A%09%09memory = MathUtils.floor(currentMemoryUsage);%0A
 %09%7D%0A%7D%0A

add basic memory monitoring