<commit_before>package io.github.voidzombie.nhglib.runtime.ecs.components.physics;

import com.artemis.Component;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.collision.btCollisionShape;
import com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btRigidBody;
import com.badlogic.gdx.utils.Disposable;
import io.github.voidzombie.nhglib.physics.MotionState;

/**
 * Created by <NAME> on 03/05/2017.
 */
public class RigidBodyComponent extends Component implements Disposable {
    private boolean added;
    private boolean collisionFiltering;

    private short group;
    private short mask;

    private btRigidBody body;
    private MotionState motionState;
    private btCollisionShape collisionShape;
    private btRigidBody.btRigidBodyConstructionInfo constructionInfo;

    @Override
    public void dispose() {
        if (body != null) {
            body.dispose();
        }

        if (motionState != null) {
            motionState.dispose();
        }

        if (collisionShape != null) {
            collisionShape.dispose();
        }

        if (constructionInfo != null) {
            constructionInfo.dispose();
        }
    }

    public void build(btCollisionShape collisionShape, float mass) {
        build(collisionShape, mass, 0.5f, 0f, (short) -1, new short[]{});
    }

    public void build(btCollisionShape collisionShape, float mass, float friction, float restitution, short group, short[] masks) {
        this.collisionShape = collisionShape;
        constructionInfo = getConstructionInfo(collisionShape, mass);

        if (constructionInfo != null) {
            motionState = new MotionState();

            body = new btRigidBody(constructionInfo);
            body.setSleepingThresholds(1f / 1000f, 1f / 1000f);
            body.setFriction(friction);
            body.setRestitution(restitution);

            collisionFiltering = true;

            if (group != -1) {
                this.group = (short) (1 << group);
            } else {
                collisionFiltering = false;
            }

            if (masks.length > 0) {
                this.mask = masks[0];

                for (int i = 1; i < masks.length; i++) {
                    short mask = masks[i];
                    this.mask |= mask;
                }
            } else {
                collisionFiltering = false;
            }
        }
    }

    public void addToWorld(btDynamicsWorld world, Matrix4 transform) {
        if (body != null && !body.isInWorld()) {
            setTransform(transform);
            body.setMotionState(motionState);

            if (collisionFiltering) {<commit_msg>- implemented collision filtering (fix 3)<commit_after>package io.github.voidzombie.nhglib.runtime.ecs.components.physics;

import com.artemis.Component;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.collision.btCollisionShape;
import com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btRigidBody;
import com.badlogic.gdx.utils.Disposable;
import io.github.voidzombie.nhglib.physics.MotionState;

/**
 * Created by <NAME> on 03/05/2017.
 */
public class RigidBodyComponent extends Component implements Disposable {
    private boolean added;
    private boolean collisionFiltering;

    private short group;
    private short mask;

    private btRigidBody body;
    private MotionState motionState;
    private btCollisionShape collisionShape;
    private btRigidBody.btRigidBodyConstructionInfo constructionInfo;

    @Override
    public void dispose() {
        if (body != null) {
            body.dispose();
        }

        if (motionState != null) {
            motionState.dispose();
        }

        if (collisionShape != null) {
            collisionShape.dispose();
        }

        if (constructionInfo != null) {
            constructionInfo.dispose();
        }
    }

    public void build(btCollisionShape collisionShape, float mass) {
        build(collisionShape, mass, 0.5f, 0f, (short) -1, new short[]{});
    }

    public void build(btCollisionShape collisionShape, float mass, float friction, float restitution, short group, short[] masks) {
        this.collisionShape = collisionShape;
        constructionInfo = getConstructionInfo(collisionShape, mass);

        if (constructionInfo != null) {
            motionState = new MotionState();

            body = new btRigidBody(constructionInfo);
            body.setSleepingThresholds(1f / 1000f, 1f / 1000f);
            body.setFriction(friction);
            body.setRestitution(restitution);

            collisionFiltering = true;

            if (group != -1) {
                this.group = (short) (1 << group);
            } else {
                collisionFiltering = false;
            }

            if (masks.length > 0) {
                if (masks[0] != -1) {
                    this.mask = (short) (1 << masks[0]);
                } else {
                    this.mask = 0;
                }

                for (int i = 1; i < masks.length; i++) {
                    this.mask |= (short) (1 << masks[i]);
                }
            } else {
                collisionFiltering = false;
            }
        }
    }

    public void addToWorld(btDynamicsWorld world, Matrix4 transform) {
        if (body != null && !body.isInWorld()) {
            setTransform(transform);
            body.setMotionState(motionState);

            if (collisionFiltering) {
{'fraction_non_alphanumeric': 0.10162672730453035, 'fraction_numerical': 0.011544516354731502, 'mean_word_length': 2.1819699499165277, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '1924374', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1586, 'n_words': 352}