Pull CPing out of main_loop.cpp, refs #43

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2013-06-27 01:23:53 +02:00
parent 6d28f88601
commit cb60e64355
3 changed files with 137 additions and 78 deletions

View file

@ -150,6 +150,8 @@
#include "nel/gui/lua_manager.h"
#include "nel/gui/group_table.h"
#include "ping.h"
///////////
// USING //
@ -218,84 +220,6 @@ uint64 SimulatedServerTick = 0;
///////////
// CLASS //
///////////
/**
* Class to manage the ping computed with the database.
* \author Guillaume PUZIN
* \author Nevrax France
* \date 2003
*/
class CPing : public ICDBNode::IPropertyObserver
{
private:
uint32 _Ping;
bool _RdyToPing;
public:
// Constructor.
CPing() {_Ping = 0; _RdyToPing = true;}
// Destructor.
~CPing() {;}
// Add an observer on the database for the ping.
void init()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(pIM)
{
CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false);
if(pNodeLeaf)
{
ICDBNode::CTextId textId;
pNodeLeaf->addObserver(this, textId);
// nlwarning("CPing: cannot add the observer");
}
else
nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist.");
}
}
// Release the observer on the database for the ping.
void release()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(pIM)
{
CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false);
if(pNodeLeaf)
{
ICDBNode::CTextId textId;
pNodeLeaf->removeObserver(this, textId);
}
else
nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist.");
}
}
// Method called when the ping message is back.
virtual void update(ICDBNode* node)
{
CCDBNodeLeaf *leaf = safe_cast<CCDBNodeLeaf *>(node);
uint32 before = (uint32)leaf->getValue32();
uint32 current = (uint32)(0xFFFFFFFF & ryzomGetLocalTime());
if(before > current)
{
//nlwarning("DB PING Pb before '%u' after '%u'.", before, current);
if(ClientCfg.Check)
nlstop;
}
_Ping = current - before;
_RdyToPing = true;
}
// return the ping in ms.
uint32 getValue() {return _Ping;}
void rdyToPing(bool rdy) {_RdyToPing = rdy;}
bool rdyToPing() const {return _RdyToPing;}
};
/////////////
// GLOBALS //

View file

@ -0,0 +1,73 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ping.h"
#include "interface_v3/interface_manager.h"
#include "time_client.h"
using namespace NLMISC;
using namespace NLGUI;
void CPing::init()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(pIM)
{
CCDBNodeLeaf *pNodeLeaf = CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false);
if(pNodeLeaf)
{
ICDBNode::CTextId textId;
pNodeLeaf->addObserver(this, textId);
// nlwarning("CPing: cannot add the observer");
}
else
nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist.");
}
}
void CPing::release()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
if(pIM)
{
CCDBNodeLeaf *pNodeLeaf = CDBManager::getInstance()->getDbProp("SERVER:DEBUG_INFO:Ping", false);
if(pNodeLeaf)
{
ICDBNode::CTextId textId;
pNodeLeaf->removeObserver(this, textId);
}
else
nlwarning("CPing: 'SERVER:DEBUG_INFO:Ping' does not exist.");
}
}
void CPing::update(NLMISC::ICDBNode* node)
{
CCDBNodeLeaf *leaf = safe_cast<CCDBNodeLeaf *>(node);
uint32 before = (uint32)leaf->getValue32();
uint32 current = (uint32)(0xFFFFFFFF & ryzomGetLocalTime());
if(before > current)
{
//nlwarning("DB PING Pb before '%u' after '%u'.", before, current);
if(ClientCfg.Check)
nlstop;
}
_Ping = current - before;
_RdyToPing = true;
}
/* end of file */

View file

@ -0,0 +1,62 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CL_PING_H
#define CL_PING_H
#include <nel/misc/types_nl.h>
#include <nel/misc/cdb.h>
///////////
// CLASS //
///////////
/**
* Class to manage the ping computed with the database.
* \author Guillaume PUZIN
* \author Nevrax France
* \date 2003
*/
class CPing : public NLMISC::ICDBNode::IPropertyObserver
{
private:
uint32 _Ping;
bool _RdyToPing;
public:
// Constructor.
CPing() {_Ping = 0; _RdyToPing = true;}
// Destructor.
~CPing() {;}
// Add an observer on the database for the ping.
void init();
// Release the observer on the database for the ping.
void release();
// Method called when the ping message is back.
virtual void update(NLMISC::ICDBNode* node);
// return the ping in ms.
uint32 getValue() {return _Ping;}
void rdyToPing(bool rdy) {_RdyToPing = rdy;}
bool rdyToPing() const {return _RdyToPing;}
};
#endif // CL_PING_H
/* end of file */