mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +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),
|
||||
#endif
|
||||
_stopNetworkReceiveThread(false),
|
||||
_voxelReceiver(this),
|
||||
_voxelProcessor(this),
|
||||
_voxelEditSender(this),
|
||||
_packetCount(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
|
||||
_voxelReceiver.initialize(_enableProcessVoxelsThread);
|
||||
_voxelProcessor.initialize(_enableProcessVoxelsThread);
|
||||
_voxelEditSender.initialize(_enableProcessVoxelsThread);
|
||||
if (_enableProcessVoxelsThread) {
|
||||
qDebug("Voxel parsing thread created.\n");
|
||||
|
@ -1164,7 +1164,7 @@ void Application::terminate() {
|
|||
pthread_join(_networkReceiveThread, NULL);
|
||||
}
|
||||
|
||||
_voxelReceiver.terminate();
|
||||
_voxelProcessor.terminate();
|
||||
_voxelEditSender.terminate();
|
||||
}
|
||||
|
||||
|
@ -2493,8 +2493,8 @@ void Application::update(float deltaTime) {
|
|||
|
||||
// parse voxel packets
|
||||
if (!_enableProcessVoxelsThread) {
|
||||
_voxelReceiver.process();
|
||||
_voxelEditSender.process();
|
||||
_voxelProcessor.threadRoutine();
|
||||
_voxelEditSender.threadRoutine();
|
||||
}
|
||||
|
||||
//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_ENVIRONMENT_DATA: {
|
||||
// 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;
|
||||
}
|
||||
case PACKET_TYPE_BULK_AVATAR_DATA:
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include "ViewFrustum.h"
|
||||
#include "VoxelFade.h"
|
||||
#include "VoxelEditPacketSender.h"
|
||||
#include "VoxelPacketReceiver.h"
|
||||
#include "VoxelPacketProcessor.h"
|
||||
#include "VoxelSystem.h"
|
||||
#include "Webcam.h"
|
||||
#include "PieMenu.h"
|
||||
|
@ -75,7 +75,7 @@ static const float NODE_KILLED_BLUE = 0.0f;
|
|||
class Application : public QApplication, public NodeListHook {
|
||||
Q_OBJECT
|
||||
|
||||
friend class VoxelPacketReceiver;
|
||||
friend class VoxelPacketProcessor;
|
||||
friend class VoxelEditPacketSender;
|
||||
|
||||
public:
|
||||
|
@ -454,7 +454,7 @@ private:
|
|||
bool _stopNetworkReceiveThread;
|
||||
|
||||
bool _enableProcessVoxelsThread;
|
||||
VoxelPacketReceiver _voxelReceiver;
|
||||
VoxelPacketProcessor _voxelProcessor;
|
||||
VoxelEditPacketSender _voxelEditSender;
|
||||
|
||||
unsigned char _incomingPacket[MAX_PACKET_SIZE];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// VoxelPacketReceiver.cpp
|
||||
// VoxelPacketProcessor.cpp
|
||||
// interface
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
|
@ -11,14 +11,14 @@
|
|||
#include <PerfStat.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "VoxelPacketReceiver.h"
|
||||
#include "VoxelPacketProcessor.h"
|
||||
|
||||
VoxelPacketReceiver::VoxelPacketReceiver(Application* app) :
|
||||
VoxelPacketProcessor::VoxelPacketProcessor(Application* app) :
|
||||
_app(app) {
|
||||
}
|
||||
|
||||
void VoxelPacketReceiver::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
||||
PerformanceWarning warn(_app->_renderPipelineWarnings->isChecked(),"processVoxelPacket()");
|
||||
void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
||||
PerformanceWarning warn(_app->_renderPipelineWarnings->isChecked(),"VoxelPacketProcessor::processPacket()");
|
||||
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
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// VoxelPacketReceiver.h
|
||||
// VoxelPacketProcessor.h
|
||||
// interface
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
|
@ -8,19 +8,19 @@
|
|||
// Voxel Packet Receiver
|
||||
//
|
||||
|
||||
#ifndef __shared__VoxelPacketReceiver__
|
||||
#define __shared__VoxelPacketReceiver__
|
||||
#ifndef __shared__VoxelPacketProcessor__
|
||||
#define __shared__VoxelPacketProcessor__
|
||||
|
||||
#include <PacketReceiver.h>
|
||||
#include <ReceivedPacketProcessor.h>
|
||||
|
||||
class Application;
|
||||
|
||||
class VoxelPacketReceiver : public PacketReceiver {
|
||||
class VoxelPacketProcessor : public ReceivedPacketProcessor {
|
||||
public:
|
||||
VoxelPacketReceiver(Application* app);
|
||||
VoxelPacketProcessor(Application* app);
|
||||
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
||||
|
||||
private:
|
||||
Application* _app;
|
||||
};
|
||||
#endif // __shared__VoxelPacketReceiver__
|
||||
#endif // __shared__VoxelPacketProcessor__
|
|
@ -13,24 +13,28 @@
|
|||
|
||||
#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 {
|
||||
public:
|
||||
GenericThread();
|
||||
virtual ~GenericThread();
|
||||
|
||||
// Call to start the thread
|
||||
void initialize(bool isThreaded);
|
||||
/// Call to start the thread.
|
||||
/// \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
|
||||
virtual bool process() = 0;
|
||||
|
||||
// Call when you're ready to stop the thread
|
||||
/// Call to stop the thread
|
||||
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();
|
||||
|
||||
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 unlock() { pthread_mutex_unlock(&_mutex); }
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "NodeList.h" // for MAX_PACKET_SIZE
|
||||
|
||||
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
||||
class NetworkPacket {
|
||||
public:
|
||||
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
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
|
@ -8,16 +8,16 @@
|
|||
// 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);
|
||||
lock();
|
||||
_packets.push_back(packet);
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool PacketReceiver::process() {
|
||||
bool ReceivedPacketProcessor::process() {
|
||||
while (_packets.size() > 0) {
|
||||
NetworkPacket& packet = _packets.front();
|
||||
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