mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:49:05 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
308b9dcf82
10 changed files with 82 additions and 49 deletions
|
@ -52,11 +52,10 @@ const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SA
|
||||||
const long MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max();
|
const long MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max();
|
||||||
const long MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
|
const long MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
|
||||||
|
|
||||||
const float DISTANCE_RATIO = 3.0/4.2;
|
const float DISTANCE_RATIO = 3.0f / 0.3f;
|
||||||
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
|
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
|
||||||
const int PHASE_DELAY_AT_90 = 20;
|
const int PHASE_DELAY_AT_90 = 20;
|
||||||
|
|
||||||
|
|
||||||
const int AGENT_LOOPBACK_MODIFIER = 307;
|
const int AGENT_LOOPBACK_MODIFIER = 307;
|
||||||
|
|
||||||
const int LOOPBACK_SANITY_CHECK = 0;
|
const int LOOPBACK_SANITY_CHECK = 0;
|
||||||
|
@ -127,7 +126,7 @@ void *sendBuffer(void *args)
|
||||||
|
|
||||||
|
|
||||||
for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) {
|
for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) {
|
||||||
if (otherAgent != agent || ( otherAgent == agent && agentWantsLoopback)) {
|
if (otherAgent != agent || (otherAgent == agent && agentWantsLoopback)) {
|
||||||
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
|
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
|
||||||
|
|
||||||
float *agentPosition = agentRingBuffer->getPosition();
|
float *agentPosition = agentRingBuffer->getPosition();
|
||||||
|
|
|
@ -151,10 +151,8 @@ int audioCallback (const void *inputBuffer,
|
||||||
unsigned char *currentPacketPtr = dataPacket + 1;
|
unsigned char *currentPacketPtr = dataPacket + 1;
|
||||||
|
|
||||||
// memcpy the three float positions
|
// memcpy the three float positions
|
||||||
for (int p = 0; p < 3; p++) {
|
memcpy(currentPacketPtr, &data->linkedAvatar->getHeadPosition(), sizeof(float) * 3);
|
||||||
memcpy(currentPacketPtr, &data->linkedAvatar->getPosition()[p], sizeof(float));
|
currentPacketPtr += (sizeof(float) * 3);
|
||||||
currentPacketPtr += sizeof(float);
|
|
||||||
}
|
|
||||||
|
|
||||||
// tell the mixer not to add additional attenuation to our source
|
// tell the mixer not to add additional attenuation to our source
|
||||||
*(currentPacketPtr++) = 255;
|
*(currentPacketPtr++) = 255;
|
||||||
|
|
|
@ -662,7 +662,7 @@ void Avatar::render(bool lookingInMirror) {
|
||||||
glTranslatef(width * 0.5, 0, 0);
|
glTranslatef(width * 0.5, 0, 0);
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
if (_keyState == NoKeyDown) {
|
if (_keyState == NO_KEY_DOWN) {
|
||||||
drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0);
|
drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,8 +15,8 @@ using namespace std;
|
||||||
const int MAX_CONTENT_LENGTH = 140;
|
const int MAX_CONTENT_LENGTH = 140;
|
||||||
|
|
||||||
void ChatEntry::clear () {
|
void ChatEntry::clear () {
|
||||||
contents.clear();
|
_contents.clear();
|
||||||
cursorPos = 0;
|
_cursorPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatEntry::key(unsigned char k) {
|
bool ChatEntry::key(unsigned char k) {
|
||||||
|
@ -25,22 +25,22 @@ bool ChatEntry::key(unsigned char k) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case '\b':
|
case '\b':
|
||||||
if (cursorPos != 0) {
|
if (_cursorPos != 0) {
|
||||||
contents.erase(cursorPos - 1, 1);
|
_contents.erase(_cursorPos - 1, 1);
|
||||||
cursorPos--;
|
_cursorPos--;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 127: // delete
|
case 127: // delete
|
||||||
if (cursorPos < contents.size()) {
|
if (_cursorPos < _contents.size()) {
|
||||||
contents.erase(cursorPos, 1);
|
_contents.erase(_cursorPos, 1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (contents.size() != MAX_CONTENT_LENGTH) {
|
if (_contents.size() != MAX_CONTENT_LENGTH) {
|
||||||
contents.insert(cursorPos, 1, k);
|
_contents.insert(_cursorPos, 1, k);
|
||||||
cursorPos++;
|
_cursorPos++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -49,24 +49,24 @@ bool ChatEntry::key(unsigned char k) {
|
||||||
void ChatEntry::specialKey(unsigned char k) {
|
void ChatEntry::specialKey(unsigned char k) {
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case GLUT_KEY_LEFT:
|
case GLUT_KEY_LEFT:
|
||||||
if (cursorPos != 0) {
|
if (_cursorPos != 0) {
|
||||||
cursorPos--;
|
_cursorPos--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLUT_KEY_RIGHT:
|
case GLUT_KEY_RIGHT:
|
||||||
if (cursorPos != contents.size()) {
|
if (_cursorPos != _contents.size()) {
|
||||||
cursorPos++;
|
_cursorPos++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatEntry::render(int screenWidth, int screenHeight) {
|
void ChatEntry::render(int screenWidth, int screenHeight) {
|
||||||
drawtext(20, screenHeight - 150, 0.10, 0, 1.0, 0, contents.c_str(), 1, 1, 1);
|
drawtext(20, screenHeight - 150, 0.10, 0, 1.0, 0, _contents.c_str(), 1, 1, 1);
|
||||||
|
|
||||||
float width = 0;
|
float width = 0;
|
||||||
for (string::iterator it = contents.begin(), end = it + cursorPos; it != end; it++) {
|
for (string::iterator it = _contents.begin(), end = it + _cursorPos; it != end; it++) {
|
||||||
width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.10;
|
width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.10;
|
||||||
}
|
}
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
class ChatEntry {
|
class ChatEntry {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const std::string& getContents () const { return contents; }
|
const std::string& getContents () const { return _contents; }
|
||||||
|
|
||||||
void clear ();
|
void clear ();
|
||||||
|
|
||||||
|
@ -25,9 +25,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string contents;
|
std::string _contents;
|
||||||
|
int _cursorPos;
|
||||||
int cursorPos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__ChatEntry__) */
|
#endif /* defined(__interface__ChatEntry__) */
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
@ -88,10 +88,11 @@ using namespace std;
|
||||||
void reshape(int width, int height); // will be defined below
|
void reshape(int width, int height); // will be defined below
|
||||||
void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below
|
void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below
|
||||||
|
|
||||||
|
bool enableNetworkThread = true;
|
||||||
pthread_t networkReceiveThread;
|
pthread_t networkReceiveThread;
|
||||||
bool stopNetworkReceiveThread = false;
|
bool stopNetworkReceiveThread = false;
|
||||||
|
|
||||||
|
unsigned char incomingPacket[MAX_PACKET_SIZE];
|
||||||
int packetCount = 0;
|
int packetCount = 0;
|
||||||
int packetsPerSecond = 0;
|
int packetsPerSecond = 0;
|
||||||
int bytesPerSecond = 0;
|
int bytesPerSecond = 0;
|
||||||
|
@ -353,8 +354,11 @@ void terminate () {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
audio.terminate();
|
audio.terminate();
|
||||||
#endif
|
#endif
|
||||||
stopNetworkReceiveThread = true;
|
|
||||||
pthread_join(networkReceiveThread, NULL);
|
if (enableNetworkThread) {
|
||||||
|
stopNetworkReceiveThread = true;
|
||||||
|
pthread_join(networkReceiveThread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -1348,7 +1352,7 @@ void specialkey(int k, int x, int y)
|
||||||
|
|
||||||
void keyUp(unsigned char k, int x, int y) {
|
void keyUp(unsigned char k, int x, int y) {
|
||||||
if (::chatEntryOn) {
|
if (::chatEntryOn) {
|
||||||
myAvatar.setKeyState(AvatarData::NoKeyDown);
|
myAvatar.setKeyState(NO_KEY_DOWN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1366,7 +1370,7 @@ void key(unsigned char k, int x, int y)
|
||||||
if (::chatEntryOn) {
|
if (::chatEntryOn) {
|
||||||
if (chatEntry.key(k)) {
|
if (chatEntry.key(k)) {
|
||||||
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
|
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
|
||||||
AvatarData::DeleteKeyDown : AvatarData::InsertKeyDown);
|
DELETE_KEY_DOWN : INSERT_KEY_DOWN);
|
||||||
myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X'));
|
myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X'));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1445,18 +1449,17 @@ void key(unsigned char k, int x, int y)
|
||||||
|
|
||||||
if (k == '\r') {
|
if (k == '\r') {
|
||||||
::chatEntryOn = true;
|
::chatEntryOn = true;
|
||||||
myAvatar.setKeyState(AvatarData::NoKeyDown);
|
myAvatar.setKeyState(NO_KEY_DOWN);
|
||||||
myAvatar.setChatMessage(string());
|
myAvatar.setChatMessage(string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive packets from other agents/servers and decide what to do with them!
|
// Receive packets from other agents/servers and decide what to do with them!
|
||||||
void *networkReceive(void *args)
|
void* networkReceive(void* args)
|
||||||
{
|
{
|
||||||
sockaddr senderAddress;
|
sockaddr senderAddress;
|
||||||
ssize_t bytesReceived;
|
ssize_t bytesReceived;
|
||||||
unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE];
|
|
||||||
|
|
||||||
while (!stopNetworkReceiveThread) {
|
while (!stopNetworkReceiveThread) {
|
||||||
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
packetCount++;
|
packetCount++;
|
||||||
|
@ -1480,12 +1483,15 @@ void *networkReceive(void *args)
|
||||||
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (!enableNetworkThread) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] incomingPacket;
|
if (enableNetworkThread) {
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
return NULL;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle(void) {
|
void idle(void) {
|
||||||
|
@ -1520,6 +1526,11 @@ void idle(void) {
|
||||||
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
|
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
|
||||||
//
|
//
|
||||||
updateAvatar(deltaTime);
|
updateAvatar(deltaTime);
|
||||||
|
|
||||||
|
// read incoming packets from network
|
||||||
|
if (!enableNetworkThread) {
|
||||||
|
networkReceive(0);
|
||||||
|
}
|
||||||
|
|
||||||
//loop through all the other avatars and simulate them...
|
//loop through all the other avatars and simulate them...
|
||||||
AgentList* agentList = AgentList::getInstance();
|
AgentList* agentList = AgentList::getInstance();
|
||||||
|
@ -1663,6 +1674,10 @@ int main(int argc, const char * argv[])
|
||||||
listenPort = atoi(portStr);
|
listenPort = atoi(portStr);
|
||||||
}
|
}
|
||||||
AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort);
|
AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort);
|
||||||
|
enableNetworkThread = !cmdOptionExists(argc, argv, "--nonblocking");
|
||||||
|
if (!enableNetworkThread) {
|
||||||
|
AgentList::getInstance()->getAgentSocket().setBlocking(false);
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(&applicationStartupTime, NULL);
|
gettimeofday(&applicationStartupTime, NULL);
|
||||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
||||||
|
@ -1746,8 +1761,10 @@ int main(int argc, const char * argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// create thread for receipt of data via UDP
|
// create thread for receipt of data via UDP
|
||||||
pthread_create(&networkReceiveThread, NULL, networkReceive, NULL);
|
if (enableNetworkThread) {
|
||||||
printLog("Network receive thread created.\n");
|
pthread_create(&networkReceiveThread, NULL, networkReceive, NULL);
|
||||||
|
printLog("Network receive thread created.\n");
|
||||||
|
}
|
||||||
|
|
||||||
glutTimerFunc(1000, Timer, 0);
|
glutTimerFunc(1000, Timer, 0);
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
|
@ -51,7 +51,7 @@ AvatarData::AvatarData() :
|
||||||
_cameraAspectRatio(0.0f),
|
_cameraAspectRatio(0.0f),
|
||||||
_cameraNearClip(0.0f),
|
_cameraNearClip(0.0f),
|
||||||
_cameraFarClip(0.0f),
|
_cameraFarClip(0.0f),
|
||||||
_keyState(NoKeyDown) {
|
_keyState(NO_KEY_DOWN) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,13 @@
|
||||||
|
|
||||||
#include <AgentData.h>
|
#include <AgentData.h>
|
||||||
|
|
||||||
|
enum KeyState
|
||||||
|
{
|
||||||
|
NO_KEY_DOWN,
|
||||||
|
INSERT_KEY_DOWN,
|
||||||
|
DELETE_KEY_DOWN
|
||||||
|
};
|
||||||
|
|
||||||
class AvatarData : public AgentData {
|
class AvatarData : public AgentData {
|
||||||
public:
|
public:
|
||||||
AvatarData();
|
AvatarData();
|
||||||
|
@ -76,8 +83,6 @@ public:
|
||||||
void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; }
|
void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; }
|
||||||
void setCameraFarClip(float farClip) { _cameraFarClip = farClip; }
|
void setCameraFarClip(float farClip) { _cameraFarClip = farClip; }
|
||||||
|
|
||||||
enum KeyState { NoKeyDown, InsertKeyDown, DeleteKeyDown };
|
|
||||||
|
|
||||||
// key state
|
// key state
|
||||||
void setKeyState(KeyState s) { _keyState = s; }
|
void setKeyState(KeyState s) { _keyState = s; }
|
||||||
KeyState keyState() const { return _keyState; }
|
KeyState keyState() const { return _keyState; }
|
||||||
|
@ -118,7 +123,7 @@ protected:
|
||||||
float _cameraNearClip;
|
float _cameraNearClip;
|
||||||
float _cameraFarClip;
|
float _cameraFarClip;
|
||||||
|
|
||||||
// key state (nothing, down, up, backspace)
|
// key state
|
||||||
KeyState _keyState;
|
KeyState _keyState;
|
||||||
|
|
||||||
// chat message
|
// chat message
|
||||||
|
|
|
@ -119,7 +119,7 @@ unsigned short loadBufferWithSocketInfo(char *addressBuffer, sockaddr *socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPSocket::UDPSocket(int listeningPort) {
|
UDPSocket::UDPSocket(int listeningPort) : blocking(true) {
|
||||||
init();
|
init();
|
||||||
// create the socket
|
// create the socket
|
||||||
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
@ -191,6 +191,18 @@ bool UDPSocket::init() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UDPSocket::setBlocking(bool blocking) {
|
||||||
|
this->blocking = blocking;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
u_long mode = blocking ? 0 : 1;
|
||||||
|
ioctlsocket(handle, FIONBIO, &mode);
|
||||||
|
#else
|
||||||
|
int flags = fcntl(handle, F_GETFL, 0);
|
||||||
|
fcntl(handle, F_SETFL, blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Receive data on this socket with retrieving address of sender
|
// Receive data on this socket with retrieving address of sender
|
||||||
bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) {
|
bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) {
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,15 @@ class UDPSocket {
|
||||||
UDPSocket(int listening_port);
|
UDPSocket(int listening_port);
|
||||||
~UDPSocket();
|
~UDPSocket();
|
||||||
bool init();
|
bool init();
|
||||||
|
void setBlocking(bool blocking);
|
||||||
|
bool isBlocking() { return blocking; }
|
||||||
int send(sockaddr *destAddress, const void *data, size_t byteLength);
|
int send(sockaddr *destAddress, const void *data, size_t byteLength);
|
||||||
int send(char *destAddress, int destPort, const void *data, size_t byteLength);
|
int send(char *destAddress, int destPort, const void *data, size_t byteLength);
|
||||||
bool receive(void *receivedData, ssize_t *receivedBytes);
|
bool receive(void *receivedData, ssize_t *receivedBytes);
|
||||||
bool receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes);
|
bool receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes);
|
||||||
private:
|
private:
|
||||||
int handle;
|
int handle;
|
||||||
|
bool blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool socketMatch(sockaddr *first, sockaddr *second);
|
bool socketMatch(sockaddr *first, sockaddr *second);
|
||||||
|
|
Loading…
Reference in a new issue