Move sendPingPackets

This commit is contained in:
Atlante45 2015-09-24 18:48:26 +02:00
parent e74df484cc
commit 77a7814854
4 changed files with 34 additions and 39 deletions

View file

@ -163,22 +163,6 @@ extern "C" {
}
#endif
enum CustomEventTypes {
Lambda = QEvent::User + 1
};
class LambdaEvent : public QEvent {
std::function<void()> _fun;
public:
LambdaEvent(const std::function<void()> & fun) :
QEvent(static_cast<QEvent::Type>(Lambda)), _fun(fun) {
}
LambdaEvent(std::function<void()> && fun) :
QEvent(static_cast<QEvent::Type>(Lambda)), _fun(fun) {
}
void call() { _fun(); }
};
using namespace std;
static QTimer* locationUpdateTimer = NULL;
@ -239,6 +223,22 @@ public:
};
#endif
enum CustomEventTypes {
Lambda = QEvent::User + 1
};
class LambdaEvent : public QEvent {
std::function<void()> _fun;
public:
LambdaEvent(const std::function<void()> & fun) :
QEvent(static_cast<QEvent::Type>(Lambda)), _fun(fun) {
}
LambdaEvent(std::function<void()> && fun) :
QEvent(static_cast<QEvent::Type>(Lambda)), _fun(fun) {
}
void call() { _fun(); }
};
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message);
@ -2090,29 +2090,10 @@ bool Application::acceptSnapshot(const QString& urlString) {
return true;
}
void Application::sendPingPackets() {
auto nodeList = DependencyManager::get<NodeList>();
nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool {
switch (node->getType()) {
case NodeType::AvatarMixer:
case NodeType::AudioMixer:
case NodeType::EntityServer:
case NodeType::AssetServer:
return true;
default:
return false;
}
}, [nodeList](const SharedNodePointer& node) {
nodeList->sendPacket(nodeList->constructPingPacket(), *node);
});
}
// Every second, check the frame rates and other stuff
void Application::checkFPS() {
if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
sendPingPackets();
DependencyManager::get<NodeList>()->sendPingPackets();
}
float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f;
@ -3804,7 +3785,6 @@ void Application::clearDomainOctreeDetails() {
// reset the model renderer
_entities.clear();
}
void Application::domainChanged(const QString& domainHostname) {

View file

@ -464,8 +464,6 @@ private slots:
private:
void resetCameras(Camera& camera, const glm::uvec2& size);
void sendPingPackets();
void initDisplay();
void init();

View file

@ -661,6 +661,22 @@ void LimitedNodeList::sendSTUNRequest() {
_nodeSocket.writeDatagram(stunRequestPacket, sizeof(stunRequestPacket), _stunSockAddr);
}
void LimitedNodeList::sendPingPackets() {
eachMatchingNode([](const SharedNodePointer& node)->bool {
switch (node->getType()) {
case NodeType::AvatarMixer:
case NodeType::AudioMixer:
case NodeType::EntityServer:
case NodeType::AssetServer:
return true;
default:
return false;
}
}, [&](const SharedNodePointer& node) {
sendPacket(constructPingPacket(), *node);
});
}
void LimitedNodeList::processSTUNResponse(std::unique_ptr<udt::BasePacket> packet) {
// check the cookie to make sure this is actually a STUN response
// and read the first attribute and make sure it is a XOR_MAPPED_ADDRESS

View file

@ -230,6 +230,7 @@ public slots:
void startSTUNPublicSocketUpdate();
virtual void sendSTUNRequest();
void sendPingPackets();
void killNodeWithUUID(const QUuid& nodeUUID);