home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / global-one-water.swf / scripts / __Packages / PerformanceController.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  1.6 KB  |  68 lines

  1. class PerformanceController
  2. {
  3.    var aFrmTms;
  4.    static var nFA = 10;
  5.    var nLFT = 0;
  6.    var cdl = 3;
  7.    static var lf = 18;
  8.    static var uf = 29;
  9.    static var mdl = 3;
  10.    function PerformanceController()
  11.    {
  12.       this.aFrmTms = [];
  13.       this.nLFT = getTimer();
  14.    }
  15.    function onEnterFrame()
  16.    {
  17.       var _loc4_ = getTimer();
  18.       this.aFrmTms.push(_loc4_ - this.nLFT);
  19.       if(this.aFrmTms.length > PerformanceController.nFA)
  20.       {
  21.          var _loc3_ = 1000 / this.arrMean(this.aFrmTms);
  22.          _global.root.performanceDisplay.text = "fps=" + _loc3_ + "\n" + "detailLevel=" + this.cdl;
  23.          if(_loc3_ > PerformanceController.uf)
  24.          {
  25.             if(this.cdl < PerformanceController.mdl)
  26.             {
  27.                this.setDetailLvl(this.cdl + 1);
  28.             }
  29.          }
  30.          else if(_loc3_ < PerformanceController.lf)
  31.          {
  32.             if(this.cdl > 1)
  33.             {
  34.                this.setDetailLvl(this.cdl - 1);
  35.             }
  36.          }
  37.          this.aFrmTms.length = 0;
  38.       }
  39.       this.nLFT = _loc4_;
  40.    }
  41.    function arrMean(arr)
  42.    {
  43.       var _loc3_ = 0;
  44.       var _loc1_ = 0;
  45.       while(_loc1_ < arr.length)
  46.       {
  47.          _loc3_ += arr[_loc1_];
  48.          _loc1_ = _loc1_ + 1;
  49.       }
  50.       return _loc3_ / arr.length;
  51.    }
  52.    function setDetailLvl(l)
  53.    {
  54.       switch(l)
  55.       {
  56.          case 1:
  57.             _root._quality = "LOW";
  58.             break;
  59.          case 2:
  60.             _root._quality = "MEDIUM";
  61.             break;
  62.          case 3:
  63.             _root._quality = "HIGH";
  64.       }
  65.       this.cdl = l;
  66.    }
  67. }
  68.