Commits

Bart van Strien committed 0cef18e

Add love.timer.getAverageDelta (issue #570) and constify love.timer.sleep

  • Participants
  • Parent commits 402233b

Comments (0)

Files changed (6)

   * Added blend mode "none".
   * Added SpriteBatch:isEmpty and SpriteBatch:isFull.
   * Added support for extern Images in Shaders when drawing graphics primitives.
+  * Added love.timer.getAverageDelta.
   * OPTIONAL: Added support for GME.
 
   * Fixed crashes with font drawing on some ATI cards.

src/modules/timer/Timer.h

 	 * usually 1ms.
 	 * @param seconds The number of seconds to sleep for.
 	 **/
-	virtual void sleep(double seconds) = 0;
+	virtual void sleep(double seconds) const = 0;
 
 	/**
 	 * Gets the time between the last two frames, assuming step is called
 	 * @return The "current" FPS.
 	 **/
 	virtual int getFPS() const = 0;
+	virtual double getAverageDelta() const = 0;
 
 	/**
 	 * Gets the amount of time since the program started. Only useful for timing

src/modules/timer/sdl/Timer.cpp

 	: currTime(0)
 	, prevFpsUpdate(0)
 	, fps(0)
+	, averageDelta(0)
 	, fpsUpdateFrequency(1)
 	, frames(0)
 	, dt(0)
 	if (timeSinceLast > fpsUpdateFrequency)
 	{
 		fps = int((frames/timeSinceLast) + 0.5);
+		averageDelta = timeSinceLast/frames;
 		prevFpsUpdate = currTime;
 		frames = 0;
 	}
 }
 
-void Timer::sleep(double seconds)
+void Timer::sleep(double seconds) const
 {
 	if (seconds > 0)
 		delay((int)(seconds*1000));
 	return fps;
 }
 
+double Timer::getAverageDelta() const
+{
+	return averageDelta;
+}
+
 double Timer::getTime() const
 {
 	return SDL_GetTicks()/1000.0;

src/modules/timer/sdl/Timer.h

 
 	const char *getName() const;
 	void step();
-	void sleep(double seconds);
+	void sleep(double seconds) const;
 	double getDelta() const;
 	int getFPS() const;
+	double getAverageDelta() const;
 	double getTime() const;
 	double getMicroTime() const;
 
 
 	// Updated with a certain frequency.
 	int fps;
+	double averageDelta;
 
 	// The frequency by which to update the FPS.
 	double fpsUpdateFrequency;

src/modules/timer/wrap_Timer.cpp

 	return 1;
 }
 
+int w_getAverageDelta(lua_State *L)
+{
+	lua_pushnumber(L, instance->getAverageDelta());
+	return 1;
+}
+
 int w_sleep(lua_State *L)
 {
 	instance->sleep((float) luaL_checknumber(L, 1));
 	{ "step", w_step },
 	{ "getDelta", w_getDelta },
 	{ "getFPS", w_getFPS },
+	{ "getAverageDelta", w_getAverageDelta },
 	{ "sleep", w_sleep },
 	{ "getTime", w_getTime },
 	{ "getMicroTime", w_getMicroTime },

src/modules/timer/wrap_Timer.h

 int w_step(lua_State *L);
 int w_getDelta(lua_State *L);
 int w_getFPS(lua_State *L);
+int w_getAverageDelta(lua_State *L);
 int w_sleep(lua_State *L);
 int w_getTime(lua_State *L);
 int w_getMicroTime(lua_State *L);