00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #ifndef UTIL_FPS_LIMITER_H 00028 #define UTIL_FPS_LIMITER_H 00029 00030 00031 //#include <vector> 00032 //#include <PVLE/Util/TracedException.h> 00033 #include <PVLE/Export.h> 00034 #include <PVLE/Util/Util.h> 00035 00036 namespace Util { 00037 00043 class PVLE_EXPORT FPSLimiter { 00044 public: 00045 FPSLimiter(UINT nbFrameTypes = 1); 00046 00048 void frame(double time, UINT type=0) { 00049 ASSERT(type < nbFrameTypes); 00050 lastFrame[type] = time; 00051 } 00052 00054 bool testFrameNeeded(double time, UINT type=0); 00055 00057 bool frameNeeded(double time, UINT type=0) { 00058 bool res = testFrameNeeded(time, type); 00059 if (res) frame(time, type); 00060 return res; 00061 } 00062 00064 void operator()(double time) const; 00065 00067 void setMinDelay(double delay, UINT type=0) { 00068 ASSERT(type < nbFrameTypes); 00069 minDelay[type] = delay; 00070 } 00073 void setMaxFPS(double fps, UINT type=0) { 00074 ASSERT(type < nbFrameTypes); 00075 minDelay[type] = fps<=0 ? -1 : 1./fps; 00076 } 00077 00078 protected: 00079 const UINT nbFrameTypes; 00080 double * lastFrame; 00081 double * minDelay; 00082 //double lastFrame[nbFrameTypes]; ///< Time of last frame for each type. 00083 //double minDelay[nbFrameTypes]; ///< Minimum time between two frames, for each type, or <=0 for unlimited. 00084 }; 00085 00086 00087 } // namespace Util 00088 00089 #endif // UTIL_FPS_LIMITER_H