keep a pointer to owning agent in AgentData

This commit is contained in:
Stephen Birarda 2013-05-24 11:24:21 -07:00
parent a3f30970d6
commit 36892da488
12 changed files with 28 additions and 13 deletions

View file

@ -47,7 +47,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *
void attachAvatarDataToAgent(Agent *newAgent) { void attachAvatarDataToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new AvatarData()); newAgent->setLinkedData(new AvatarData(newAgent));
} }
} }

View file

@ -71,7 +71,7 @@ void *receiveAgentData(void *args) {
void createAvatarDataForAgent(Agent* agent) { void createAvatarDataForAgent(Agent* agent) {
if (!agent->getLinkedData()) { if (!agent->getLinkedData()) {
agent->setLinkedData(new AvatarData()); agent->setLinkedData(new AvatarData(agent));
} }
} }
@ -95,7 +95,7 @@ int main(int argc, const char* argv[]) {
pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL); pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL);
// create an AvatarData object, "eve" // create an AvatarData object, "eve"
AvatarData eve; AvatarData eve(NULL);
// move eve away from the origin // move eve away from the origin
// pick a random point inside a 10x10 grid // pick a random point inside a 10x10 grid

View file

@ -128,7 +128,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_viewFrustumOffsetDistance(25.0), _viewFrustumOffsetDistance(25.0),
_viewFrustumOffsetUp(0.0), _viewFrustumOffsetUp(0.0),
_audioScope(256, 200, true), _audioScope(256, 200, true),
_myAvatar(true), _myAvatar(NULL, true),
_manualFirstPerson(false), _manualFirstPerson(false),
_mouseX(0), _mouseX(0),
_mouseY(0), _mouseY(0),
@ -2098,9 +2098,9 @@ QAction* Application::checkedVoxelModeAction() const {
return 0; return 0;
} }
void Application::attachNewHeadToAgent(Agent *newAgent) { void Application::attachNewHeadToAgent(Agent* newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Avatar(false)); newAgent->setLinkedData(new Avatar(newAgent, false));
} }
} }

View file

@ -69,7 +69,8 @@ bool usingBigSphereCollisionTest = true;
float chatMessageScale = 0.0015; float chatMessageScale = 0.0015;
float chatMessageHeight = 0.10; float chatMessageHeight = 0.10;
Avatar::Avatar(bool isMine) : Avatar::Avatar(Agent* owningAgent, bool isMine) :
AvatarData(owningAgent),
_isMine(isMine), _isMine(isMine),
_TEST_bigSphereRadius(0.4f), _TEST_bigSphereRadius(0.4f),
_TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f), _TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f),

View file

@ -76,7 +76,7 @@ enum AvatarJointID
class Avatar : public AvatarData { class Avatar : public AvatarData {
public: public:
Avatar(bool isMine); Avatar(Agent* owningAgent, bool isMine);
~Avatar(); ~Avatar();
void reset(); void reset();

View file

@ -44,7 +44,7 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- .
10,11,15, 10,15,14, // Y+ 10,11,15, 10,15,14, // Y+
4,5,6, 4,6,7 }; // Z+ . 4,5,6, 4,6,7 }; // Z+ .
VoxelSystem::VoxelSystem() { VoxelSystem::VoxelSystem() : AgentData(NULL) {
_voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0; _voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0;
_writeRenderFullVBO = true; _writeRenderFullVBO = true;
_readRenderFullVBO = true; _readRenderFullVBO = true;

View file

@ -13,6 +13,7 @@
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"
AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) : AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
AgentData(NULL),
_ringBufferLengthSamples(ringSamples), _ringBufferLengthSamples(ringSamples),
_bufferLengthSamples(bufferSamples), _bufferLengthSamples(bufferSamples),
_endOfLastWrite(NULL), _endOfLastWrite(NULL),
@ -20,7 +21,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
_shouldBeAddedToMix(false), _shouldBeAddedToMix(false),
_shouldLoopbackForAgent(false), _shouldLoopbackForAgent(false),
_streamIdentifier() _streamIdentifier()
{ {
_buffer = new int16_t[_ringBufferLengthSamples]; _buffer = new int16_t[_ringBufferLengthSamples];
_nextOutput = _buffer; _nextOutput = _buffer;
}; };

View file

@ -31,7 +31,8 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo
return sizeof(uint16_t); return sizeof(uint16_t);
} }
AvatarData::AvatarData() : AvatarData::AvatarData(Agent* owningAgent) :
AgentData(owningAgent),
_handPosition(0,0,0), _handPosition(0,0,0),
_bodyYaw(-90.0), _bodyYaw(-90.0),
_bodyPitch(0.0), _bodyPitch(0.0),

View file

@ -29,7 +29,7 @@ enum KeyState
class AvatarData : public AgentData { class AvatarData : public AgentData {
public: public:
AvatarData(); AvatarData(Agent* owningAgent);
~AvatarData(); ~AvatarData();
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }

View file

@ -8,4 +8,10 @@
#include "AgentData.h" #include "AgentData.h"
AgentData::AgentData(Agent* owningAgent) :
_owningAgent(owningAgent)
{
}
AgentData::~AgentData() {} AgentData::~AgentData() {}

View file

@ -3,16 +3,21 @@
// hifi // hifi
// //
// Created by Stephen Birarda on 2/19/13. // Created by Stephen Birarda on 2/19/13.
// // Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
// //
#ifndef hifi_AgentData_h #ifndef hifi_AgentData_h
#define hifi_AgentData_h #define hifi_AgentData_h
class Agent;
class AgentData { class AgentData {
public: public:
AgentData(Agent* owningAgent);
virtual ~AgentData() = 0; virtual ~AgentData() = 0;
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
private:
Agent* _owningAgent;
}; };
#endif #endif

View file

@ -12,6 +12,7 @@
#include <cstdio> #include <cstdio>
VoxelAgentData::VoxelAgentData() : VoxelAgentData::VoxelAgentData() :
AvatarData(NULL),
_viewSent(false), _viewSent(false),
_voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE), _voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE),
_maxSearchLevel(1), _maxSearchLevel(1),