<commit_before>package net.mostlyoriginal.game.system.detection;

import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.PackedComponent;
import com.artemis.PooledComponent;
import com.artemis.annotations.Wire;
import com.artemis.systems.EntityProcessingSystem;
import com.artemis.utils.EntityBuilder;
import com.artemis.utils.reflect.ClassReflection;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import net.mostlyoriginal.game.component.detection.OdbFeatureComponent;
import net.mostlyoriginal.game.component.detection.PackDetectionComponent;
import net.mostlyoriginal.game.component.detection.PoolDetectionComponent;

/**
 * Detect which odb weaving features have been applied.
 *
 * @author <NAME>
 */
@Wire
public class OdbFeatureDetectionSystem extends EntityProcessingSystem {

	public OdbFeatureDetectionSystem() {
		super(Aspect.getEmpty());
	}

	@Override
	protected void initialize() {
		super.initialize();

		OdbFeatureComponent features = new OdbFeatureComponent();
		Entity e = new EntityBuilder(world).with(features).build();

		// detect packing based on reflection.
		features.isPacked = isPackedWeavingEnabled();
		features.isPooled = isPooledWeavingEnabled();
		features.isHotspotOptimization = isHotspotOptimizationEnabled();

		Gdx.app.setLogLevel(Application.LOG_DEBUG);
		logState("Struct Emulation", features.isPacked);
		logState("Pooling", features.isPooled);
		logState("Hotspot Optimization", features.isHotspotOptimization);
	}

	private boolean isHotspotOptimizationEnabled() {
		// hotspot optimization replaces (amongst other steps) references to entityprocessingsystem with entitysystem.
		// so we can determine this optimization by EntityProcessingSystem missing from our system's hierarchy.
		return !ClassReflection.isAssignableFrom(EntityProcessingSystem.class, OdbFeatureDetectionSystem.class);
	}

	private boolean isPooledWeavingEnabled() {
		// pooled components will subclass PooledComponent.
		return ClassReflection.isAssignableFrom(PooledComponent.class, PoolDetectionComponent.class);
	}

	private boolean isPackedWeavingEnabled() {
		// packed components will subclass PackedComponent.
		return ClassReflection.isAssignableFrom(PackedComponent.class, PackDetectionComponent.class);
	}

	private void logState(final String feature, boolean state) {
		Gdx.app.log("OdbFeatureDetectionSystem", feature + " is " + (state ? "enabled" : "disabled"));
	}

	@Override
	protected void process(Entity e) {
		// do nothing.
	}
}<commit_msg>Quick hack to show feature as color (red/green).<commit_after>package net.mostlyoriginal.game.system.detection;

import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.PackedComponent;
import com.artemis.PooledComponent;
import com.artemis.annotations.Wire;
import com.artemis.systems.EntityProcessingSystem;
import com.artemis.utils.EntityBuilder;
import com.artemis.utils.reflect.ClassReflection;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import net.mostlyoriginal.game.component.detection.OdbFeatureComponent;
import net.mostlyoriginal.game.component.detection.PackDetectionComponent;
import net.mostlyoriginal.game.component.detection.PoolDetectionComponent;

/**
 * Detect which odb weaving features have been applied.
 *
 * @author <NAME>
 */
@Wire
public class OdbFeatureDetectionSystem extends EntityProcessingSystem {

	public OdbFeatureDetectionSystem() {
		super(Aspect.getAspectForAll(OdbFeatureComponent.class));
	}

	@Override
	protected void initialize() {
		super.initialize();

		OdbFeatureComponent features = new OdbFeatureComponent();
		Entity e = new EntityBuilder(world).with(features).build();

		// detect packing based on reflection.
		features.isPacked = isPackedWeavingEnabled();
		features.isPooled = isPooledWeavingEnabled();
		features.isHotspotOptimization = isHotspotOptimizationEnabled();

		Gdx.app.setLogLevel(Application.LOG_DEBUG);
		logState("Struct Emulation", features.isPacked);
		logState("Pooling", features.isPooled);
		logState("Hotspot Optimization", features.isHotspotOptimization);
	}

	private boolean isHotspotOptimizationEnabled() {
		// hotspot optimization replaces (amongst other steps) references to entityprocessingsystem with entitysystem.
		// so we can determine this optimization by EntityProcessingSystem missing from our system's hierarchy.
		return !ClassReflection.isAssignableFrom(EntityProcessingSystem.class, OdbFeatureDetectionSystem.class);
	}

	private boolean isPooledWeavingEnabled() {
		// pooled components will subclass PooledComponent.
		return ClassReflection.isAssignableFrom(PooledComponent.class, PoolDetectionComponent.class);
	}

	private boolean isPackedWeavingEnabled() {
		// packed components will subclass PackedComponent.
		return ClassReflection.isAssignableFrom(PackedComponent.class, PackDetectionComponent.class);
	}

	private void logState(final String feature, boolean state) {
		Gdx.app.log("OdbFeatureDetectionSystem", feature + " is " + (state ? "enabled" : "disabled"));
	}

	@Override
	protected void process(Entity e) {

		// just for quick debugging on macos.
		OdbFeatureComponent feature = e.getComponent(OdbFeatureComponent.class);
		Gdx.gl.glClearColor(feature.isPooled ? 0 : 1, feature.isPooled ? 1 : 0, 0.25f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	}
}
{'fraction_non_alphanumeric': 0.09560193812896012, 'fraction_numerical': 0.0022363026462914647, 'mean_word_length': 6.034076015727392, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7324180', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1497, 'n_words': 329}