2006-05-17 13:48:37 +00:00
|
|
|
#include "SecondLife.h"
|
|
|
|
|
|
2006-05-18 14:18:13 +00:00
|
|
|
SecondLife::SecondLife()
|
2006-05-17 13:48:37 +00:00
|
|
|
{
|
|
|
|
|
_protocol = new ProtocolManager();
|
2006-05-23 07:41:41 +00:00
|
|
|
_network = new Network(_protocol, this);
|
2006-05-18 14:18:13 +00:00
|
|
|
_running = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SecondLife::~SecondLife()
|
|
|
|
|
{
|
2006-05-27 02:42:28 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
std::cout << "SecondLife::~SecondLife() destructor called" << std::endl;
|
|
|
|
|
#endif
|
2006-05-17 13:48:37 +00:00
|
|
|
delete _protocol;
|
|
|
|
|
delete _network;
|
2006-05-18 14:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SecondLife::tick()
|
|
|
|
|
{
|
2006-06-01 08:09:12 +00:00
|
|
|
PacketPtr packet;
|
|
|
|
|
std::list<PacketPtr>* inbox = _network->inbox();
|
|
|
|
|
|
2006-05-25 22:20:56 +00:00
|
|
|
// When we get to stream handling, this function will build data stream
|
2006-05-18 14:18:13 +00:00
|
|
|
// classes and append new data, for sounds/images/animations/etc
|
|
|
|
|
|
2006-05-25 22:20:56 +00:00
|
|
|
// tick() will process all of the outstanding packets, building classes and
|
2006-05-18 14:18:13 +00:00
|
|
|
// firing callbacks as it goes
|
|
|
|
|
if (_network) {
|
2006-05-25 22:20:56 +00:00
|
|
|
while (inbox->size() > 0) {
|
2006-06-01 08:09:12 +00:00
|
|
|
boost::mutex::scoped_lock lock(_network->inboxMutex);
|
2006-05-25 22:20:56 +00:00
|
|
|
packet = inbox->front();
|
|
|
|
|
inbox->pop_front();
|
2006-06-01 08:09:12 +00:00
|
|
|
lock.unlock();
|
|
|
|
|
|
2006-05-18 14:18:13 +00:00
|
|
|
std::string command = packet->command();
|
|
|
|
|
|
2006-05-25 22:20:56 +00:00
|
|
|
std::map<std::string, callback>::iterator handler = _callbacks.find(command);
|
|
|
|
|
|
|
|
|
|
if (handler == _callbacks.end()) {
|
|
|
|
|
handler = _callbacks.find("Default");
|
|
|
|
|
|
|
|
|
|
if (handler != _callbacks.end()) {
|
2006-05-27 02:42:28 +00:00
|
|
|
(handler->second)(command, packet);
|
2006-05-25 22:20:56 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2006-05-27 02:42:28 +00:00
|
|
|
(handler->second)(command, packet);
|
2006-05-25 22:20:56 +00:00
|
|
|
}
|
2006-05-18 14:18:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-05-27 02:42:28 +00:00
|
|
|
|
2006-05-25 22:20:56 +00:00
|
|
|
// Sleep for 1000 nanoseconds
|
|
|
|
|
boost::xtime xt;
|
|
|
|
|
boost::xtime_get(&xt, boost::TIME_UTC);
|
|
|
|
|
xt.nsec += 1000;
|
|
|
|
|
boost::thread::sleep(xt);
|
2006-05-17 13:48:37 +00:00
|
|
|
}
|