<commit_before>/**
*
* s.Comm ---
* allows us to compartmentalize all interactions
* with the server to this class (s.Comm) --this class
* is the only place that holds the logic that allows
* the client to communicate with the server.
*
**/

s.Comm = new Class( {

    extend: s.EventEmitter,

    toString: "Comm",

    // makeTrigger is responsible for broadcasting all events

    // receieved from the server to the rest of the game.


    makeTrigger: function ( evt ) {
        var that = this;

        return function ( message ) {

            that.trigger.call( that, evt, message );

        };

    },


    destruct: function ( ) {

        // TODO: Send server some kind of destruct message?

    },


    construct: function ( options ) {

        //binding the game's context

        this.game = options.game;

        // Prepend http. Doing this so that you can customize the server before finalizing the string.

        options.server = 'http://' + options.server;

        this.player = options.player;

        this.delta = 0;

        this.ship = options.ship;

        this.pilot = options.pilot;

        this.room = options.room;

        var that = this;


        this.lastMessageTime = new Date( ).getTime( );

        // Create socket connection


        this.socket = io.connect( options.server );


        this.socket.on( 'join', this.makeTrigger( 'join' ) );

        this.socket.on( 'failed', function ( message ) {
            // try to reconnect
            that.connected( );
        } );

        this.socket.on( 'player list', this.makeTrigger( 'player list' ) );

        this.socket.on( 'leave', this.makeTrigger( 'leave' ) );

        this.socket.on( 'move', this.makeTrigger( 'move' ) );

        this.socket.on( 'killed', this.makeTrigger( 'killed' ));

        this.socket.on( 'fire', this.makeTrigger( 'fire' ));

        this.socket.on( 'hit', this.makeTrigger( 'hit' ));

        this.socket.on( 'sync', this.makeTrigger( 'sync'));

        this.socket.on( 'bot retrieval', this.makeTrigger( 'bot retrieval' ));

        this.socket.on( 'bot positions', this.makeTrigger( 'bot positions' ));

        this.game.hook( this.position );

        this.clockTick = this.clockTick.bind(this);

        this.timer = setInterval(this.clockTick,1000);

        this.time = 0;


    },

    connected: function ( ) {


        var time = new Date( ).getTime( );


        var shipPosition = this.game.player.getPositionPacket( );
        var packet = {
            room: this.room,

            evt: 'joined',

            name: this.pilot.name,

            time: time,

            pos: shipPosition.pos,

            rot: shipPosition.rot,

            aVeloc: shipPosition.aVeloc,

            lVeloc: shipPosition.lVeloc,

        };


        // Broadcast position

        this.socket.emit('join', packet );

    },


    position: function ( ) {
      if(this.lastPosition === undefined) {
        this.lastPosition = s.game.player.getPositionPacket( );
        this.lastTime = new Date().getTime();
      }
      var time = new Date( ).getTime( );
      var shipPosition = s.game.player.getPositionPacket( );
          shipPosition.lAccel = [];
          shipPosition.aAccel = [];
      var delta = function() {
        var results = {};
        var diff;
        var t_diff;
        for(var i = 0; i < 3; i++) {
          diff = shipPosition.lVeloc[i] - this.lastPosition.lVeloc[i];
          t_diff = time - this.lastTime;

          if(t_diff === 0 || isNaN(t_diff) ) {
            return "Invalid";
          } else {
            shipPosition.lAccel.push(diff/t_diff);
          }

          diff = shipPosition.aVeloc[i] - this.lastPosition.aVeloc[i];
          t_diff = time - this.lastTime;
          if(t_diff === 0 || isNaN(t_diff) ) {
            return "Invalid";
          } else {
            shipPosition.aAccel.push(diff/t_diff);
          }
        }
        return results;
      }();
      if(Math.abs(shipPosition.aAccel[0]) > 0.00015 ||
         Math.abs(shipPosition.aAccel[1]) > 0.00015 ||
         Math.abs(shipPosition.aAccel[2]) > 0.00015 ||
         Math.abs(shipPosition.lAccel[0]) > 0.00005 ||
         Math.abs(shipPosition.lAccel[1]) > 0.00005 ||
         Math.abs(shipPosition.lAccel[2]) > 0.00005 ) {
        var packet = {
          time: time,
          pos: shipPosition.pos,
          rot: shipPosition.rot,<commit_msg>eased up the threshold a little<commit_after>/**
*
* s.Comm ---
* allows us to compartmentalize all interactions
* with the server to this class (s.Comm) --this class
* is the only place that holds the logic that allows
* the client to communicate with the server.
*
**/

s.Comm = new Class( {

    extend: s.EventEmitter,

    toString: "Comm",

    // makeTrigger is responsible for broadcasting all events

    // receieved from the server to the rest of the game.


    makeTrigger: function ( evt ) {
        var that = this;

        return function ( message ) {

            that.trigger.call( that, evt, message );

        };

    },


    destruct: function ( ) {

        // TODO: Send server some kind of destruct message?

    },


    construct: function ( options ) {

        //binding the game's context

        this.game = options.game;

        // Prepend http. Doing this so that you can customize the server before finalizing the string.

        options.server = 'http://' + options.server;

        this.player = options.player;

        this.delta = 0;

        this.ship = options.ship;

        this.pilot = options.pilot;

        this.room = options.room;

        var that = this;


        this.lastMessageTime = new Date( ).getTime( );

        // Create socket connection


        this.socket = io.connect( options.server );


        this.socket.on( 'join', this.makeTrigger( 'join' ) );

        this.socket.on( 'failed', function ( message ) {
            // try to reconnect
            that.connected( );
        } );

        this.socket.on( 'player list', this.makeTrigger( 'player list' ) );

        this.socket.on( 'leave', this.makeTrigger( 'leave' ) );

        this.socket.on( 'move', this.makeTrigger( 'move' ) );

        this.socket.on( 'killed', this.makeTrigger( 'killed' ));

        this.socket.on( 'fire', this.makeTrigger( 'fire' ));

        this.socket.on( 'hit', this.makeTrigger( 'hit' ));

        this.socket.on( 'sync', this.makeTrigger( 'sync'));

        this.socket.on( 'bot retrieval', this.makeTrigger( 'bot retrieval' ));

        this.socket.on( 'bot positions', this.makeTrigger( 'bot positions' ));

        this.game.hook( this.position );

        this.clockTick = this.clockTick.bind(this);

        this.timer = setInterval(this.clockTick,1000);

        this.time = 0;


    },

    connected: function ( ) {


        var time = new Date( ).getTime( );


        var shipPosition = this.game.player.getPositionPacket( );
        var packet = {
            room: this.room,

            evt: 'joined',

            name: this.pilot.name,

            time: time,

            pos: shipPosition.pos,

            rot: shipPosition.rot,

            aVeloc: shipPosition.aVeloc,

            lVeloc: shipPosition.lVeloc,

        };


        // Broadcast position

        this.socket.emit('join', packet );

    },


    position: function ( ) {
      if(this.lastPosition === undefined) {
        this.lastPosition = s.game.player.getPositionPacket( );
        this.lastTime = new Date().getTime();
      }
      var time = new Date( ).getTime( );
      var shipPosition = s.game.player.getPositionPacket( );
          shipPosition.lAccel = [];
          shipPosition.aAccel = [];
      var delta = function() {
        var results = {};
        var diff;
        var t_diff;
        for(var i = 0; i < 3; i++) {
          diff = shipPosition.lVeloc[i] - this.lastPosition.lVeloc[i];
          t_diff = time - this.lastTime;

          if(t_diff === 0 || isNaN(t_diff) ) {
            return "Invalid";
          } else {
            shipPosition.lAccel.push(diff/t_diff);
          }

          diff = shipPosition.aVeloc[i] - this.lastPosition.aVeloc[i];
          t_diff = time - this.lastTime;
          if(t_diff === 0 || isNaN(t_diff) ) {
            return "Invalid";
          } else {
            shipPosition.aAccel.push(diff/t_diff);
          }
        }
        return results;
      }();
      if(Math.abs(shipPosition.aAccel[0]) > 0.00005 ||
         Math.abs(shipPosition.aAccel[1]) > 0.00005 ||
         Math.abs(shipPosition.aAccel[2]) > 0.00005 ||
         Math.abs(shipPosition.lAccel[0]) > 0.00005 ||
         Math.abs(shipPosition.lAccel[1]) > 0.00005 ||
         Math.abs(shipPosition.lAccel[2]) > 0.00005 ) {
        var packet = {
          time: time,
          pos: shipPosition.pos,
          rot: shipPosition.rot,
{'fraction_non_alphanumeric': 0.13301608882846136, 'fraction_numerical': 0.011783367323815998, 'mean_word_length': 1.867771280051982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '2241608', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2598, 'n_words': 618}