package net.mgsx.game.plugins.bullet.system;

import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.gdx.physics.bullet.DebugDrawer;
import com.badlogic.gdx.physics.bullet.linearmath.btIDebugDraw.DebugDrawModes;

import net.mgsx.game.core.EditorScreen;
import net.mgsx.game.core.GamePipeline;
import net.mgsx.game.core.annotations.EditableSystem;
import net.mgsx.game.core.annotations.Inject;

@EditableSystem(isDebug=true)
public class BulletWorldDebugSystem extends EntitySystem
{
	@Inject
	public BulletWorldSystem bulletWorldSystem;

	private DebugDrawer debugDrawer;
		
	private EditorScreen editor;
	
	public BulletWorldDebugSystem(EditorScreen editor) {
		super(GamePipeline.RENDER_OVER);
		this.editor = editor;
	}

	@Override
	public void update(float deltaTime)
	{
		if (debugDrawer == null) {
			bulletWorldSystem.collisionWorld.setDebugDrawer(debugDrawer = new DebugDrawer());
		}
		debugDrawer.setDebugMode(DebugDrawModes.DBG_DrawWireframe | DebugDrawModes.DBG_DrawAabb); // DebugDrawModes.DBG_DrawWireframe | DebugDrawModes.DBG_DrawFeaturesText | DebugDrawModes.DBG_DrawText | DebugDrawModes.DBG_DrawContactPoints);
		// debugDrawer.setShapeRenderer(getEngine().getSystem(DebugRenderSystem.class).shapeRenderer);
		debugDrawer.begin(editor.game.camera);
		bulletWorldSystem.collisionWorld.debugDrawWorld();
		debugDrawer.flushLines();
		debugDrawer.end();
	}
}

@@ -297,16 +297,64 @@
 peline;%0A
+import net.mgsx.game.core.annotations.Editable;%0A
 import n
@@ -659,16 +659,917 @@
 itor;%0A%09%0A
+    @Editable public boolean DBG_DrawWireframe = true;%0A    @Editable public boolean DBG_DrawAabb = true;%0A    @Editable public boolean DBG_DrawFeaturesText = false;%0A    @Editable public boolean DBG_DrawContactPoints = false;%0A    @Editable public boolean DBG_NoDeactivation = false;%0A    @Editable public boolean DBG_NoHelpText = false;%0A    @Editable public boolean DBG_DrawText = false;%0A    @Editable public boolean DBG_ProfileTimings = false;%0A    @Editable public boolean DBG_EnableSatComparison = false;%0A    @Editable public boolean DBG_DisableBulletLCP = false;%0A    @Editable public boolean DBG_EnableCCD = false;%0A    @Editable public boolean DBG_DrawConstraints = false;%0A    @Editable public boolean DBG_DrawConstraintLimits = false;%0A    @Editable public boolean DBG_FastWireframe = false;%0A    @Editable public boolean DBG_DrawNormals = false;%0A    @Editable public boolean DBG_DrawFrames = false;%0A%09%0A
 %09public 
@@ -1852,33 +1852,60 @@
 %7D%0A%09%09
-debugDrawer.setDebugMode(
+int mode = 0;%0A%09%09%0A%09    if(DBG_DrawWireframe) mode %7C= 
 Debu
@@ -1924,34 +1924,63 @@
 BG_DrawWireframe
+;%0A%09    if(DBG_DrawAabb) mode
  %7C
+=
  DebugDrawModes.
@@ -1995,48 +1995,123 @@
 Aabb
-); // DebugDrawModes.DBG_DrawWirefram
+;%0A%09    if(DBG_DrawFeaturesText) mode %7C= DebugDrawModes.DBG_DrawFeaturesText;%0A%09    if(DBG_DrawContactPoints) mod
 e %7C
+=
  Deb
@@ -2134,22 +2134,125 @@
 Draw
-FeaturesText
+ContactPoints;%0A%09    if(DBG_NoDeactivation) mode %7C= DebugDrawModes.DBG_NoDeactivation;%0A%09    if(DBG_NoHelpText) mode
  %7C
+=
  Deb
@@ -2267,24 +2267,48 @@
 des.DBG_
+NoHelpText;%0A%09    if(DBG_
 DrawText
  %7C Debug
@@ -2299,18 +2299,25 @@
 DrawText
+) mode
  %7C
+=
  DebugDr
@@ -2336,121 +2336,693 @@
 Draw
-ContactPoints);%0A%09%09// debugDrawer.setShapeRenderer(getEngine().getSystem(DebugRenderSystem.class).shapeRenderer
+Text;%0A%09    if(DBG_ProfileTimings) mode %7C= DebugDrawModes.DBG_ProfileTimings;%0A%09    if(DBG_EnableSatComparison) mode %7C= DebugDrawModes.DBG_EnableSatComparison;%0A%09    if(DBG_DisableBulletLCP) mode %7C= DebugDrawModes.DBG_DisableBulletLCP;%0A%09    if(DBG_EnableCCD) mode %7C= DebugDrawModes.DBG_EnableCCD;%0A%09    if(DBG_DrawConstraints) mode %7C= DebugDrawModes.DBG_DrawConstraints;%0A%09    if(DBG_DrawConstraintLimits) mode %7C= DebugDrawModes.DBG_DrawConstraintLimits;%0A%09    if(DBG_FastWireframe) mode %7C= DebugDrawModes.DBG_FastWireframe;%0A%09    if(DBG_DrawNormals) mode %7C= DebugDrawModes.DBG_DrawNormals;%0A%09    if(DBG_DrawFrames) mode %7C= DebugDrawModes.DBG_DrawFrames;%0A%09%09%0A%09%09debugDrawer.setDebugMode(mode
 );%0A
+%0A
 %09%09de

improve bullet debug system