[Node] Optimize code
This commit is contained in:
parent
3a9d4231bb
commit
8a1936347f
@ -110,6 +110,7 @@ namespace Components
|
||||
|
||||
static Utils::Time::Interval interval;
|
||||
if (!force && !interval.elapsed(1min)) return;
|
||||
interval.update();
|
||||
|
||||
Proto::Node::List list;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define NODE_HALFLIFE 3min
|
||||
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
|
||||
#define NODE_REQUEST_LIMIT 3
|
||||
|
||||
namespace Components
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define SESSION_TIMEOUT 10s
|
||||
#define SESSION_TIMEOUT (10 * 1000) //10s
|
||||
#define SESSION_MAX_RETRIES 3
|
||||
#define SESSION_REQUEST_LIMIT 3
|
||||
|
||||
|
@ -14,14 +14,29 @@ namespace Utils
|
||||
return ((std::chrono::high_resolution_clock::now() - this->lastPoint) >= nsecs);
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::duration Point::diff(Point point)
|
||||
Point::Point() : lastPoint(Game::Sys_Milliseconds())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Point::update()
|
||||
{
|
||||
this->lastPoint = Game::Sys_Milliseconds();
|
||||
}
|
||||
|
||||
int Point::diff(Point point)
|
||||
{
|
||||
return point.lastPoint - this->lastPoint;
|
||||
}
|
||||
|
||||
bool Point::after(Point point)
|
||||
{
|
||||
return this->diff(point).count() < 0;
|
||||
return this->diff(point) < 0;
|
||||
}
|
||||
|
||||
bool Point::elapsed(int milliseconds)
|
||||
{
|
||||
return (Game::Sys_Milliseconds() - this->lastPoint) >= milliseconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,18 @@ namespace Utils
|
||||
bool elapsed(std::chrono::nanoseconds nsecs);
|
||||
};
|
||||
|
||||
class Point : public Interval
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point() : Interval() {}
|
||||
Point();
|
||||
|
||||
std::chrono::high_resolution_clock::duration diff(Point point);
|
||||
void update();
|
||||
int diff(Point point);
|
||||
bool after(Point point);
|
||||
bool elapsed(int milliseconds);
|
||||
|
||||
private:
|
||||
int lastPoint;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user