1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation and appearing *
8 * in the file LICENSE.GPL included in the packaging of this file. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * General Public License for more details. *
15 ***************************************************************************/
17 #include <tairon/net/timer.h>
19 #include "ratemeasurer.h"
27 /* {{{ RateMeasurer::RateMeasurer(double) */
28 RateMeasurer::RateMeasurer(double p
) : period(p
)
30 lastTime
= (double) Tairon::Net::Timer::currentTime() / 1000;
31 startTime
= lastTime
- 1;
36 /* {{{ RateMeasurer::~RateMeasurer() */
37 RateMeasurer::~RateMeasurer()
42 /* {{{ RateMeasurer::update(unsigned int) */
43 void RateMeasurer::update(unsigned int amount
)
45 double t
= (double) Tairon::Net::Timer::currentTime() / 1000;
46 rate
= ((rate
* (lastTime
- startTime
)) + amount
) / (t
- startTime
);
48 if (startTime
< t
- period
)
49 startTime
= t
- period
;
55 }; // namespace Tairent
57 // vim: ai sw=4 ts=4 noet fdm=marker