mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 17:38:34 +02:00
renamed class to be more appropriate, added doxygen comments
This commit is contained in:
parent
266d57264b
commit
beec5f60d8
9 changed files with 80 additions and 64 deletions
|
@ -221,7 +221,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_audio(&_audioScope, STARTUP_JITTER_SAMPLES),
|
_audio(&_audioScope, STARTUP_JITTER_SAMPLES),
|
||||||
#endif
|
#endif
|
||||||
_stopNetworkReceiveThread(false),
|
_stopNetworkReceiveThread(false),
|
||||||
_voxelReceiver(this),
|
_voxelProcessor(this),
|
||||||
_voxelEditSender(this),
|
_voxelEditSender(this),
|
||||||
_packetCount(0),
|
_packetCount(0),
|
||||||
_packetsPerSecond(0),
|
_packetsPerSecond(0),
|
||||||
|
@ -374,7 +374,7 @@ void Application::initializeGL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create thread for parsing of voxel data independent of the main network and rendering threads
|
// create thread for parsing of voxel data independent of the main network and rendering threads
|
||||||
_voxelReceiver.initialize(_enableProcessVoxelsThread);
|
_voxelProcessor.initialize(_enableProcessVoxelsThread);
|
||||||
_voxelEditSender.initialize(_enableProcessVoxelsThread);
|
_voxelEditSender.initialize(_enableProcessVoxelsThread);
|
||||||
if (_enableProcessVoxelsThread) {
|
if (_enableProcessVoxelsThread) {
|
||||||
qDebug("Voxel parsing thread created.\n");
|
qDebug("Voxel parsing thread created.\n");
|
||||||
|
@ -1164,7 +1164,7 @@ void Application::terminate() {
|
||||||
pthread_join(_networkReceiveThread, NULL);
|
pthread_join(_networkReceiveThread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
_voxelReceiver.terminate();
|
_voxelProcessor.terminate();
|
||||||
_voxelEditSender.terminate();
|
_voxelEditSender.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2493,8 +2493,8 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
// parse voxel packets
|
// parse voxel packets
|
||||||
if (!_enableProcessVoxelsThread) {
|
if (!_enableProcessVoxelsThread) {
|
||||||
_voxelReceiver.process();
|
_voxelProcessor.threadRoutine();
|
||||||
_voxelEditSender.process();
|
_voxelEditSender.threadRoutine();
|
||||||
}
|
}
|
||||||
|
|
||||||
//loop through all the other avatars and simulate them...
|
//loop through all the other avatars and simulate them...
|
||||||
|
@ -3942,7 +3942,7 @@ void* Application::networkReceive(void* args) {
|
||||||
case PACKET_TYPE_VOXEL_STATS:
|
case PACKET_TYPE_VOXEL_STATS:
|
||||||
case PACKET_TYPE_ENVIRONMENT_DATA: {
|
case PACKET_TYPE_ENVIRONMENT_DATA: {
|
||||||
// add this packet to our list of voxel packets and process them on the voxel processing
|
// add this packet to our list of voxel packets and process them on the voxel processing
|
||||||
app->_voxelReceiver.queuePacket(senderAddress, app->_incomingPacket, bytesReceived);
|
app->_voxelProcessor.queuePacket(senderAddress, app->_incomingPacket, bytesReceived);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PACKET_TYPE_BULK_AVATAR_DATA:
|
case PACKET_TYPE_BULK_AVATAR_DATA:
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "ViewFrustum.h"
|
#include "ViewFrustum.h"
|
||||||
#include "VoxelFade.h"
|
#include "VoxelFade.h"
|
||||||
#include "VoxelEditPacketSender.h"
|
#include "VoxelEditPacketSender.h"
|
||||||
#include "VoxelPacketReceiver.h"
|
#include "VoxelPacketProcessor.h"
|
||||||
#include "VoxelSystem.h"
|
#include "VoxelSystem.h"
|
||||||
#include "Webcam.h"
|
#include "Webcam.h"
|
||||||
#include "PieMenu.h"
|
#include "PieMenu.h"
|
||||||
|
@ -75,7 +75,7 @@ static const float NODE_KILLED_BLUE = 0.0f;
|
||||||
class Application : public QApplication, public NodeListHook {
|
class Application : public QApplication, public NodeListHook {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class VoxelPacketReceiver;
|
friend class VoxelPacketProcessor;
|
||||||
friend class VoxelEditPacketSender;
|
friend class VoxelEditPacketSender;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -454,7 +454,7 @@ private:
|
||||||
bool _stopNetworkReceiveThread;
|
bool _stopNetworkReceiveThread;
|
||||||
|
|
||||||
bool _enableProcessVoxelsThread;
|
bool _enableProcessVoxelsThread;
|
||||||
VoxelPacketReceiver _voxelReceiver;
|
VoxelPacketProcessor _voxelProcessor;
|
||||||
VoxelEditPacketSender _voxelEditSender;
|
VoxelEditPacketSender _voxelEditSender;
|
||||||
|
|
||||||
unsigned char _incomingPacket[MAX_PACKET_SIZE];
|
unsigned char _incomingPacket[MAX_PACKET_SIZE];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// VoxelPacketReceiver.cpp
|
// VoxelPacketProcessor.cpp
|
||||||
// interface
|
// interface
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||||
|
@ -11,14 +11,14 @@
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "VoxelPacketReceiver.h"
|
#include "VoxelPacketProcessor.h"
|
||||||
|
|
||||||
VoxelPacketReceiver::VoxelPacketReceiver(Application* app) :
|
VoxelPacketProcessor::VoxelPacketProcessor(Application* app) :
|
||||||
_app(app) {
|
_app(app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelPacketReceiver::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
||||||
PerformanceWarning warn(_app->_renderPipelineWarnings->isChecked(),"processVoxelPacket()");
|
PerformanceWarning warn(_app->_renderPipelineWarnings->isChecked(),"VoxelPacketProcessor::processPacket()");
|
||||||
ssize_t messageLength = packetLength;
|
ssize_t messageLength = packetLength;
|
||||||
|
|
||||||
// check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
|
// check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// VoxelPacketReceiver.h
|
// VoxelPacketProcessor.h
|
||||||
// interface
|
// interface
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||||
|
@ -8,19 +8,19 @@
|
||||||
// Voxel Packet Receiver
|
// Voxel Packet Receiver
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef __shared__VoxelPacketReceiver__
|
#ifndef __shared__VoxelPacketProcessor__
|
||||||
#define __shared__VoxelPacketReceiver__
|
#define __shared__VoxelPacketProcessor__
|
||||||
|
|
||||||
#include <PacketReceiver.h>
|
#include <ReceivedPacketProcessor.h>
|
||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
|
|
||||||
class VoxelPacketReceiver : public PacketReceiver {
|
class VoxelPacketProcessor : public ReceivedPacketProcessor {
|
||||||
public:
|
public:
|
||||||
VoxelPacketReceiver(Application* app);
|
VoxelPacketProcessor(Application* app);
|
||||||
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Application* _app;
|
Application* _app;
|
||||||
};
|
};
|
||||||
#endif // __shared__VoxelPacketReceiver__
|
#endif // __shared__VoxelPacketProcessor__
|
|
@ -13,24 +13,28 @@
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
/// A basic generic "thread" class. Handles a single thread of control within the application. Can operate in non-threaded
|
||||||
|
/// mode but caller must regularly call threadRoutine() method.
|
||||||
class GenericThread {
|
class GenericThread {
|
||||||
public:
|
public:
|
||||||
GenericThread();
|
GenericThread();
|
||||||
virtual ~GenericThread();
|
virtual ~GenericThread();
|
||||||
|
|
||||||
// Call to start the thread
|
/// Call to start the thread.
|
||||||
void initialize(bool isThreaded);
|
/// \param bool isThreaded true by default. false for non-threaded mode and caller must call threadRoutine() regularly.
|
||||||
|
void initialize(bool isThreaded = true);
|
||||||
|
|
||||||
// override this function to do whatever your class actually does, return false to exit thread early
|
/// Call to stop the thread
|
||||||
virtual bool process() = 0;
|
|
||||||
|
|
||||||
// Call when you're ready to stop the thread
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
// If you're running in non-threaded mode, you must call this regularly
|
/// If you're running in non-threaded mode, you must call this regularly
|
||||||
void* threadRoutine();
|
void* threadRoutine();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Override this function to do whatever your class actually does, return false to exit thread early.
|
||||||
|
virtual bool process() = 0;
|
||||||
|
|
||||||
|
/// Locks all the resources of the thread.
|
||||||
void lock() { pthread_mutex_lock(&_mutex); }
|
void lock() { pthread_mutex_lock(&_mutex); }
|
||||||
void unlock() { pthread_mutex_unlock(&_mutex); }
|
void unlock() { pthread_mutex_unlock(&_mutex); }
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "NodeList.h" // for MAX_PACKET_SIZE
|
#include "NodeList.h" // for MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
||||||
class NetworkPacket {
|
class NetworkPacket {
|
||||||
public:
|
public:
|
||||||
NetworkPacket();
|
NetworkPacket();
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
//
|
|
||||||
// PacketReceiver.h
|
|
||||||
// shared
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Threaded or non-threaded packet receiver.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef __shared__PacketReceiver__
|
|
||||||
#define __shared__PacketReceiver__
|
|
||||||
|
|
||||||
#include "GenericThread.h"
|
|
||||||
#include "NetworkPacket.h"
|
|
||||||
|
|
||||||
class PacketReceiver : public GenericThread {
|
|
||||||
public:
|
|
||||||
// Call this when your network receive gets a packet
|
|
||||||
void queuePacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
|
||||||
|
|
||||||
// implement this to process the incoming packets
|
|
||||||
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) = 0;
|
|
||||||
|
|
||||||
virtual bool process();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<NetworkPacket> _packets;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __shared__PacketReceiver__
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// PacketReceiver.cpp
|
// ReceivedPacketProcessor.cpp
|
||||||
// shared
|
// shared
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||||
|
@ -8,16 +8,16 @@
|
||||||
// Threaded or non-threaded packet receiver.
|
// Threaded or non-threaded packet receiver.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "PacketReceiver.h"
|
#include "ReceivedPacketProcessor.h"
|
||||||
|
|
||||||
void PacketReceiver::queuePacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength) {
|
void ReceivedPacketProcessor::queuePacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength) {
|
||||||
NetworkPacket packet(address, packetData, packetLength);
|
NetworkPacket packet(address, packetData, packetLength);
|
||||||
lock();
|
lock();
|
||||||
_packets.push_back(packet);
|
_packets.push_back(packet);
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketReceiver::process() {
|
bool ReceivedPacketProcessor::process() {
|
||||||
while (_packets.size() > 0) {
|
while (_packets.size() > 0) {
|
||||||
NetworkPacket& packet = _packets.front();
|
NetworkPacket& packet = _packets.front();
|
||||||
processPacket(packet.getAddress(), packet.getData(), packet.getLength());
|
processPacket(packet.getAddress(), packet.getData(), packet.getLength());
|
43
libraries/shared/src/ReceivedPacketProcessor.h
Normal file
43
libraries/shared/src/ReceivedPacketProcessor.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// ReceivedPacketProcessor.h
|
||||||
|
// shared
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Threaded or non-threaded received packet processor.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __shared__ReceivedPacketProcessor__
|
||||||
|
#define __shared__ReceivedPacketProcessor__
|
||||||
|
|
||||||
|
#include "GenericThread.h"
|
||||||
|
#include "NetworkPacket.h"
|
||||||
|
|
||||||
|
/// Generalized threaded processor for handler received inbound packets.
|
||||||
|
class ReceivedPacketProcessor : public GenericThread {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Add packet from network receive thread to the processing queue.
|
||||||
|
/// \param sockaddr& senderAddress the address of the sender
|
||||||
|
/// \param packetData pointer to received data
|
||||||
|
/// \param ssize_t packetLength size of received data
|
||||||
|
/// \thread network receive thread
|
||||||
|
void queuePacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
||||||
|
|
||||||
|
/// Callback for processing of recieved packets. Implement this to process the incoming packets.
|
||||||
|
/// \param sockaddr& senderAddress the address of the sender
|
||||||
|
/// \param packetData pointer to received data
|
||||||
|
/// \param ssize_t packetLength size of received data
|
||||||
|
/// \thread "this" individual processing thread
|
||||||
|
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/// Implements generic processing behavior for this thread.
|
||||||
|
virtual bool process();
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<NetworkPacket> _packets;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __shared__PacketReceiver__
|
Loading…
Reference in a new issue