[Node] Optimize code

This commit is contained in:
momo5502 2017-06-26 23:23:08 +02:00
parent 3a9d4231bb
commit 8a1936347f
5 changed files with 28 additions and 7 deletions

View File

@ -110,6 +110,7 @@ namespace Components
static Utils::Time::Interval interval;
if (!force && !interval.elapsed(1min)) return;
interval.update();
Proto::Node::List list;

View File

@ -1,6 +1,6 @@
#pragma once
#define NODE_HALFLIFE 3min
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
#define NODE_REQUEST_LIMIT 3
namespace Components

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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;
};
}
}