<commit_before>/**
 Copyright (C) 2013 by <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../../types/underscore/underscore.d.ts" />
/// <reference path="./scene.ts" />
/// <reference path="./sceneComponent.ts" />

// An object that may exist in a `Scene`, has a unique `id` and receives ticked updates.
module pow2 {

   export interface IObject {
      id:number;
      name:string;
   }

   /**
    * Basic component host object interface.  Exposes methods for adding/removing/searching
    * components that a host owns.
    */
   export interface ISceneComponentHost extends IObject {
      addComponent(component:ISceneComponent,silent?:boolean):boolean;
      removeComponent(component:ISceneComponent,silent?:boolean):boolean;

      syncComponents();

      findComponent(type:Function):ISceneComponent;
      findComponents(type:Function):ISceneComponent[];
   }

   export class SceneObject implements ISceneComponentHost {
      id:number = _.uniqueId();
      name:string;
      scene: Scene;
      world: IWorld;
      enabled:boolean;
      // The object point
      point:Point;
      // The render point that is interpolated between ticks.
      renderPoint:Point;
      _components:ISceneComponent[] = [];
      constructor(options?: any) {
         _.extend(this, _.defaults(options || {}), {
            point: new Point(0,0),
            enabled:true
         });
      }

      // Tick components.
      tick(elapsed: number) {
         if(!this.enabled){
            return;
         }
         _.each(this._components,(o:any) => {
            if(o.tick){
               o.tick(elapsed);
            }
         });
      }

      // Interpolate components.
      interpolateTick(elapsed: number) {
         if(!this.enabled){
            return;
         }
         _.each(this._components,(o:any) => {
            if(o.interpolateTick){
               o.interpolateTick(elapsed);
            }
         });
      }

      destroy() {
         if (this.scene) {
            this.scene.removeObject(this);
         }
      }

      // ISceneComponentHost implementation
      // -----------------------------------------------------------------------------

      findComponent(type:Function):ISceneComponent {
         return _.find(this._components,(comp:ISceneComponent) => {
            return comp instanceof type;
         });
      }
      findComponents(type:Function):ISceneComponent[] {
         return _.filter(this._components,(comp:ISceneComponent) => {
            return comp instanceof type;
         });
      }

      syncComponents(){
         _.each(this._components,(comp:ISceneComponent) => {
            comp.syncComponent();
         });
      }

      addComponent(component:ISceneComponent,silent:boolean=false):boolean {
         if(_.where(this._components,{id: component.id}).length > 0){
            throw new Error("Component added twice");<commit_msg>Disconnect object components when host is destroyed.<commit_after>/**
 Copyright (C) 2013 by <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../../types/underscore/underscore.d.ts" />
/// <reference path="./scene.ts" />
/// <reference path="./sceneComponent.ts" />

// An object that may exist in a `Scene`, has a unique `id` and receives ticked updates.
module pow2 {

   export interface IObject {
      id:number;
      name:string;
   }

   /**
    * Basic component host object interface.  Exposes methods for adding/removing/searching
    * components that a host owns.
    */
   export interface ISceneComponentHost extends IObject {
      addComponent(component:ISceneComponent,silent?:boolean):boolean;
      removeComponent(component:ISceneComponent,silent?:boolean):boolean;

      syncComponents();

      findComponent(type:Function):ISceneComponent;
      findComponents(type:Function):ISceneComponent[];
   }

   export class SceneObject implements ISceneComponentHost {
      id:number = _.uniqueId();
      name:string;
      scene: Scene;
      world: IWorld;
      enabled:boolean;
      // The object point
      point:Point;
      // The render point that is interpolated between ticks.
      renderPoint:Point;
      _components:ISceneComponent[] = [];
      constructor(options?: any) {
         _.extend(this, _.defaults(options || {}), {
            point: new Point(0,0),
            enabled:true
         });
      }

      // Tick components.
      tick(elapsed: number) {
         if(!this.enabled){
            return;
         }
         _.each(this._components,(o:any) => {
            if(o.tick){
               o.tick(elapsed);
            }
         });
      }

      // Interpolate components.
      interpolateTick(elapsed: number) {
         if(!this.enabled){
            return;
         }
         _.each(this._components,(o:any) => {
            if(o.interpolateTick){
               o.interpolateTick(elapsed);
            }
         });
      }

      destroy() {
         _.each(this._components,(o:ISceneComponent) => {
            o.disconnectComponent();
         });
         if (this.scene) {
            this.scene.removeObject(this);
         }
      }

      // ISceneComponentHost implementation
      // -----------------------------------------------------------------------------

      findComponent(type:Function):ISceneComponent {
         return _.find(this._components,(comp:ISceneComponent) => {
            return comp instanceof type;
         });
      }
      findComponents(type:Function):ISceneComponent[] {
         return _.filter(this._components,(comp:ISceneComponent) => {
            return comp instanceof type;
         });
      }

      syncComponents(){
         _.each(this._components,(comp:ISceneComponent) => {
            comp.syncComponent();
         });
      }

      addComponent(component:ISceneComponent,silent:boolean=false):boolean {
         if(_.where(this._components,{id: component.id}).length > 0){
            throw new Error("Component added twice");
{'fraction_non_alphanumeric': 0.1328180907399456, 'fraction_numerical': 0.0034349506225848005, 'mean_word_length': 2.1364452423698386, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '636343', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1788, 'n_words': 451}