1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18package com.replica.replicaisland; 19 20public class FrameRateWatcherComponent extends GameComponent { 21 private RenderComponent mRenderComponent; 22 private DrawableObject mDrawable; 23 private float mMaxFrameTime = 1.0f / 30.0f; 24 25 public FrameRateWatcherComponent() { 26 super(); 27 setPhase(GameComponent.ComponentPhases.THINK.ordinal()); 28 } 29 30 @Override 31 public void reset() { 32 mRenderComponent = null; 33 mDrawable = null; 34 } 35 36 @Override 37 public void update(float timeDelta, BaseObject parent) { 38 if (mRenderComponent != null && mDrawable != null) { 39 if (timeDelta > mMaxFrameTime) { 40 mRenderComponent.setDrawable(mDrawable); 41 } else { 42 mRenderComponent.setDrawable(null); 43 } 44 } 45 } 46 47 public void setup(RenderComponent render, DrawableObject drawable) { 48 mRenderComponent = render; 49 mDrawable = drawable; 50 } 51} 52