<commit_before>package gibber.systems;

import com.artemisx.Aspect;
import com.artemisx.ComponentMapper;
import com.artemisx.Entity;
import com.artemisx.EntitySystem;
import com.artemisx.utils.Bag;

import gibber.components.BounceCmp;
import gibber.components.PosCmp;
import gibber.components.RegionCmp;
import gibber.components.RenderCmp;
import gibber.components.TimedEffectCmp;
import gibber.components.TrailCmp;
import gibber.components.TraceCmp;
import gibber.managers.ContainerMgr;
import gibber.systems.EntityAssemblySys;

import utils.Geo;
import utils.Polygon;
import utils.Vec2;
import utils.Math2;

class TrailSys extends EntitySystem
{
    public function new() {
        super( Aspect.getAspectForAll( [PosCmp, BounceCmp, TrailCmp, TimedEffectCmp] ) );
    }

    override public function initialize() : Void {
        posMapper         = world.getMapper( PosCmp );
        timedEffectMapper = world.getMapper( TimedEffectCmp );
        trailMapper       = world.getMapper( TrailCmp );
        regionMapper      = world.getMapper( RegionCmp );
        bounceMapper      = world.getMapper( BounceCmp );
        entityAssembler   = world.getSystem( EntityAssemblySys );
        containerMgr      = world.getManager( ContainerMgr );
    }

    override public function processEntities( entities : Bag<Entity> ) : Void  {
        var e : Entity;
        var time : TimedEffectCmp;
        var trail : TrailCmp;
        var pos : PosCmp;
        var bounce : BounceCmp;
        var sector : Entity;

        for ( i in 0...actives.size ) {
            e   = actives.get( i );
            time = timedEffectMapper.get( e );
            trail = trailMapper.get( e );
            pos = posMapper.get( e );
            bounce = bounceMapper.get( e );
            sector = posMapper.get( e ).sector;

            switch( time.processState ) {
                case Process( _ ):
                    for ( e in containerMgr.getAllEntitiesOfContainer( sector ) ) {
                        if ( e.id == trail.playerId ) continue; //skip me
                        var p : Vec2 = posMapper.get( e ).pos;
                        if ( Geo.isPointInCircle( { center: p, radius: 10 }, pos.pos ) ) {
                            entityAssembler.createTrace( sector, Mass( p, 3 ) );
                        }
                    }

                    switch ( bounce.lastTouched ) {
                        case Edge( a, b, collisionPt ):
                            // create trace
                            var toA = a.sub( collisionPt ).normalize();
                            var toB = b.sub( collisionPt ).normalize();
                            var traceLen = 40.0;

                            var aa = collisionPt.add( toA.mul( traceLen / 2 ) );
                            var bb = collisionPt.add( toB.mul( traceLen / 2 ) );

                            // bb overshot
                            if ( b.sub( aa ).lengthsq() < bb.sub( aa ).lengthsq() ) bb = b;

                            // aa overshot
                            if ( a.sub( bb ).lengthsq() < aa.sub( bb ).lengthsq() ) aa = a;<commit_msg>make ping bounce back upon hitting entity<commit_after>package gibber.systems;

import com.artemisx.Aspect;
import com.artemisx.ComponentMapper;
import com.artemisx.Entity;
import com.artemisx.EntitySystem;
import com.artemisx.utils.Bag;

import gibber.components.BounceCmp;
import gibber.components.PosCmp;
import gibber.components.RegionCmp;
import gibber.components.RenderCmp;
import gibber.components.TimedEffectCmp;
import gibber.components.TrailCmp;
import gibber.components.TraceCmp;
import gibber.managers.ContainerMgr;
import gibber.systems.EntityAssemblySys;

import utils.Geo;
import utils.Polygon;
import utils.Vec2;
import utils.Math2;

class TrailSys extends EntitySystem
{
    public function new() {
        super( Aspect.getAspectForAll( [PosCmp, BounceCmp, TrailCmp, TimedEffectCmp] ) );
    }

    override public function initialize() : Void {
        posMapper         = world.getMapper( PosCmp );
        timedEffectMapper = world.getMapper( TimedEffectCmp );
        trailMapper       = world.getMapper( TrailCmp );
        regionMapper      = world.getMapper( RegionCmp );
        bounceMapper      = world.getMapper( BounceCmp );
        entityAssembler   = world.getSystem( EntityAssemblySys );
        containerMgr      = world.getManager( ContainerMgr );
    }

    override public function processEntities( entities : Bag<Entity> ) : Void  {
        var e : Entity;
        var time : TimedEffectCmp;
        var trail : TrailCmp;
        var pos : PosCmp;
        var bounce : BounceCmp;
        var sector : Entity;

        for ( i in 0...actives.size ) {
            e   = actives.get( i );
            time = timedEffectMapper.get( e );
            trail = trailMapper.get( e );
            pos = posMapper.get( e );
            bounce = bounceMapper.get( e );
            sector = posMapper.get( e ).sector;

            switch( time.processState ) {
                case Process( _ ):
                    for ( e in containerMgr.getAllEntitiesOfContainer( sector ) ) {
                        if ( e.id == trail.playerId ) continue; //skip me
                        var p : Vec2 = posMapper.get( e ).pos;
                        if ( Geo.isPointInCircle( { center: p, radius: 6 }, pos.pos ) ) {
                            entityAssembler.createTrace( sector, Mass( p, 3 ) );
                            // bounce back
                            pos.dp = pos.dp.mul( -1 );
                        }
                    }

                    switch ( bounce.lastTouched ) {
                        case Edge( a, b, collisionPt ):
                            // create trace
                            var toA = a.sub( collisionPt ).normalize();
                            var toB = b.sub( collisionPt ).normalize();
                            var traceLen = 40.0;

                            var aa = collisionPt.add( toA.mul( traceLen / 2 ) );
                            var bb = collisionPt.add( toB.mul( traceLen / 2 ) );

                            // bb overshot
                            if ( b.sub( aa ).lengthsq() < bb.sub( aa ).lengthsq() ) bb = b;

                            // aa overshot
                            if ( a.sub( bb ).lengthsq() < aa.sub( bb ).lengthsq() ) aa = a;
{'fraction_non_alphanumeric': 0.09822131276562254, 'fraction_numerical': 0.00377774279867779, 'mean_word_length': 1.6245353159851301, 'pattern_counts': {'":': 0, '<': 9, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6628692', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1757, 'n_words': 438}