<commit_before>package io.github.voidzombie.nhglib.runtime.ecs.systems.impl;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.systems.IteratingSystem;
import com.artemis.utils.IntBag;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.Bullet;
import com.badlogic.gdx.physics.bullet.DebugDrawer;
import com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher;
import com.badlogic.gdx.physics.bullet.collision.btDbvtBroadphase;
import com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration;
import com.badlogic.gdx.physics.bullet.dynamics.btConstraintSolver;
import com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver;
import com.badlogic.gdx.utils.Disposable;
import io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent;
import io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent;

/**
 * Created by <NAME> on 04/05/2017.
 */
public class PhysicsSystem extends IteratingSystem implements Disposable {
    private final static float TIME_STEP = 1f / 60f;

    private btDynamicsWorld dynamicsWorld;
    private btConstraintSolver constraintSolver;
    private btDefaultCollisionConfiguration collisionConfiguration;
    private btCollisionDispatcher collisionDispatcher;
    private btDbvtBroadphase dbvtBroadphase;

    private ComponentMapper<NodeComponent> nodeMapper;
    private ComponentMapper<RigidBodyComponent> rigidBodyMapper;

    public PhysicsSystem() {
        super(Aspect.all(RigidBodyComponent.class, NodeComponent.class));
        initPhysics();
    }

    @Override
    protected void process(int entityId) {
        NodeComponent nodeComponent = nodeMapper.get(entityId);
        RigidBodyComponent bodyComponent = rigidBodyMapper.get(entityId);

        if (!bodyComponent.isAdded()) {
            Matrix4 initialTransform = new Matrix4();

            Vector3 trn = nodeComponent.getTranslation();
            Vector3 scl = new Vector3(1, 1, 1);
            Quaternion rtn = nodeComponent.getRotationQuaternion();

            initialTransform.set(trn, rtn, scl);

            bodyComponent.addToWorld(dynamicsWorld, initialTransform);
        } else {
            nodeComponent.setTranslation(bodyComponent.getTranslation());
            nodeComponent.setRotation(bodyComponent.getRotation());
            nodeComponent.applyTransforms();
        }
    }

    @Override
    protected void end() {
        super.end();
        dynamicsWorld.stepSimulation(Gdx.graphics.getDeltaTime(),
                5,
                TIME_STEP);
    }

    @Override
    public void dispose() {
        IntBag entityIds = getEntityIds();
        for (int entity : entityIds.getData()) {
            RigidBodyComponent bodyComponent = rigidBodyMapper.get(entity);<commit_msg>- Working on PhysicsSystem<commit_after>package io.github.voidzombie.nhglib.runtime.ecs.systems.impl;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.systems.IteratingSystem;
import com.artemis.utils.IntBag;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.Bullet;
import com.badlogic.gdx.physics.bullet.DebugDrawer;
import com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher;
import com.badlogic.gdx.physics.bullet.collision.btDbvtBroadphase;
import com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration;
import com.badlogic.gdx.physics.bullet.dynamics.btConstraintSolver;
import com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver;
import com.badlogic.gdx.utils.Disposable;
import io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent;
import io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent;

/**
 * Created by <NAME> on 04/05/2017.
 */
public class PhysicsSystem extends IteratingSystem implements Disposable {
    private final static float TIME_STEP = 1f / 60f;

    private btDynamicsWorld dynamicsWorld;
    private btConstraintSolver constraintSolver;
    private btDefaultCollisionConfiguration collisionConfiguration;
    private btCollisionDispatcher collisionDispatcher;
    private btDbvtBroadphase dbvtBroadphase;

    private ComponentMapper<NodeComponent> nodeMapper;
    private ComponentMapper<RigidBodyComponent> rigidBodyMapper;

    public PhysicsSystem() {
        super(Aspect.all(RigidBodyComponent.class, NodeComponent.class));
        initPhysics();
    }

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

        dynamicsWorld.stepSimulation(Gdx.graphics.getDeltaTime(),
                5,
                TIME_STEP);
    }

    @Override
    protected void process(int entityId) {
        NodeComponent nodeComponent = nodeMapper.get(entityId);
        RigidBodyComponent bodyComponent = rigidBodyMapper.get(entityId);

        if (!bodyComponent.isAdded()) {
            Matrix4 initialTransform = new Matrix4();

            Vector3 trn = nodeComponent.getTranslation();
            Vector3 scl = new Vector3(1, 1, 1);
            Quaternion rtn = nodeComponent.getRotationQuaternion();

            initialTransform.set(trn, rtn, scl);

            bodyComponent.addToWorld(dynamicsWorld, initialTransform);
        } else {
            nodeComponent.setTranslation(bodyComponent.getTranslation());
            nodeComponent.setRotation(bodyComponent.getRotation());
            nodeComponent.applyTransforms();
        }
    }

    @Override
    protected void end() {
        super.end();
    }

    @Override
    public void dispose() {
        IntBag entityIds = getEntityIds();
        for (int entity : entityIds.getData()) {
            RigidBodyComponent bodyComponent = rigidBodyMapper.get(entity);
{'fraction_non_alphanumeric': 0.09211578442347673, 'fraction_numerical': 0.007036622421237806, 'mean_word_length': 3.8293436293436294, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4674241', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1787, 'n_words': 301}