diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 62df071de0..5f20c86ca9 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -14,4 +14,5 @@ setup_hifi_project(${TARGET_NAME} TRUE) # link in the shared library include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) -link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file +link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR}) +link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 2b2686e083..870f165a94 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,8 @@ const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000; int main(int argc, char* const argv[]) { + setvbuf(stdout, NULL, _IOLBF, 0); + // create a NodeList as an unassigned client NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED); nodeList->getNodeSocket()->setBlocking(false); @@ -72,8 +75,11 @@ int main(int argc, char* const argv[]) { qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr); } - // run the AudioMixer, it's the only possible assignment for now - AudioMixer::run(); + if (deployedAssignment.getType() == Assignment::AudioMixer) { + AudioMixer::run(); + } else { + AvatarMixer::run(); + } // reset our NodeList by switching back to unassigned and clearing the list nodeList->setOwnerType(NODE_TYPE_UNASSIGNED); diff --git a/avatar-mixer/CMakeLists.txt b/avatar-mixer/CMakeLists.txt deleted file mode 100644 index 33f603e228..0000000000 --- a/avatar-mixer/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -set(TARGET_NAME "avatar-mixer") - -set(ROOT_DIR ..) -set(MACRO_DIR ${ROOT_DIR}/cmake/macros) - -# setup for find modules -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/") - -# setup the project -include(${MACRO_DIR}/SetupHifiProject.cmake) -setup_hifi_project(${TARGET_NAME} TRUE) - -# include glm -include(${MACRO_DIR}/IncludeGLM.cmake) -include_glm(${TARGET_NAME} ${ROOT_DIR}) - -# link required hifi libraries -include(${MACRO_DIR}/LinkHifiLibrary.cmake) -link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) -link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index ac6249a823..bc2b035b83 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -107,6 +107,10 @@ int main(int argc, char* const argv[]) // create an assignment to send, ask for an audio mixer, pass the assignment pool if it exists Assignment mixerAssignment(Assignment::Create, Assignment::AudioMixer, assignmentPool); nodeList->sendAssignment(mixerAssignment); + } else if (!nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER)) { + // create an assignment to send, ask for an avatar mixer, pass the assignment pool if it exists + Assignment avatarAssignment(Assignment::Create, Assignment::AvatarMixer, assignmentPool); + nodeList->sendAssignment(avatarAssignment); } diff --git a/avatar-mixer/src/main.cpp b/libraries/avatars/src/AvatarMixer.cpp similarity index 85% rename from avatar-mixer/src/main.cpp rename to libraries/avatars/src/AvatarMixer.cpp index 0677ffbc7e..72fa131866 100644 --- a/avatar-mixer/src/main.cpp +++ b/libraries/avatars/src/AvatarMixer.cpp @@ -1,44 +1,26 @@ // -// main.cpp -// Avatar Mixer +// AvatarMixer.cpp +// hifi // -// Created by Leonardo Murillo on 03/25/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved +// Created by Stephen Birarda on 9/5/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// +// Original avatar-mixer main created by Leonardo Murillo on 03/25/13. // // The avatar mixer receives head, hand and positional data from all connected // nodes, and broadcasts that data back to them, every BROADCAST_INTERVAL ms. -// -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include -#include -#include +#include #include "AvatarData.h" -const int AVATAR_LISTEN_PORT = 55444; +#include "AvatarMixer.h" unsigned char* addNodeToBroadcastPacket(unsigned char *currentPosition, Node *nodeToAdd) { currentPosition += packNodeId(currentPosition, nodeToAdd->getNodeID()); - + AvatarData *nodeData = (AvatarData *)nodeToAdd->getLinkedData(); currentPosition += nodeData->getBroadcastData(currentPosition); @@ -55,7 +37,7 @@ void attachAvatarDataToNode(Node* newNode) { // 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present // if the avatar is not in view or in the keyhole. // 2) after culling for view frustum, sort order the avatars by distance, send the closest ones first. -// 3) if we need to rate limit the amount of data we send, we can use a distance weighted "semi-random" function to +// 3) if we need to rate limit the amount of data we send, we can use a distance weighted "semi-random" function to // determine which avatars are included in the packet stream // 4) we should optimize the avatar data format to be more compact (100 bytes is pretty wasteful). void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) { @@ -66,13 +48,13 @@ void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) { unsigned char* currentBufferPosition = broadcastPacket + numHeaderBytes; int packetLength = currentBufferPosition - broadcastPacket; int packetsSent = 0; - + // send back a packet with other active node data to this node for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { if (node->getLinkedData() && !socketMatch(nodeAddress, node->getActiveSocket())) { unsigned char* avatarDataEndpoint = addNodeToBroadcastPacket((unsigned char*)&avatarDataBuffer[0], &*node); int avatarDataLength = avatarDataEndpoint - (unsigned char*)&avatarDataBuffer; - + if (avatarDataLength + packetLength <= MAX_PACKET_SIZE) { memcpy(currentBufferPosition, &avatarDataBuffer[0], avatarDataLength); packetLength += avatarDataLength; @@ -98,17 +80,9 @@ void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) { nodeList->getNodeSocket()->send(nodeAddress, broadcastPacket, currentBufferPosition - broadcastPacket); } -int main(int argc, const char* argv[]) { - - NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT); - setvbuf(stdout, NULL, _IOLBF, 0); - - // Handle Local Domain testing with the --local command line - const char* local = "--local"; - if (cmdOptionExists(argc, argv, local)) { - printf("Local Domain MODE!\n"); - nodeList->setDomainIPToLocalhost(); - } +void AvatarMixer::run() { + NodeList* nodeList = NodeList::getInstance(); + nodeList->setOwnerType(NODE_TYPE_AVATAR_MIXER); nodeList->linkedDataCreateCallback = attachAvatarDataToNode; @@ -119,13 +93,12 @@ int main(int argc, const char* argv[]) { unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE]; - uint16_t nodeID = 0; Node* avatarNode = NULL; timeval lastDomainServerCheckIn = {}; // we only need to hear back about avatar nodes from the DS - NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_AGENT, 1); + nodeList->setNodeTypesOfInterest(&NODE_TYPE_AGENT, 1); while (true) { @@ -174,6 +147,4 @@ int main(int argc, const char* argv[]) { } nodeList->stopSilentNodeRemovalThread(); - - return 0; -} +} \ No newline at end of file diff --git a/libraries/avatars/src/AvatarMixer.h b/libraries/avatars/src/AvatarMixer.h new file mode 100644 index 0000000000..cf3f2245fe --- /dev/null +++ b/libraries/avatars/src/AvatarMixer.h @@ -0,0 +1,19 @@ +// +// AvatarMixer.h +// hifi +// +// Created by Stephen Birarda on 9/5/13. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#ifndef __hifi__AvatarMixer__ +#define __hifi__AvatarMixer__ + +#include + +class AvatarMixer { +public: + static void run(); +}; + +#endif /* defined(__hifi__AvatarMixer__) */ diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 54e1d912d4..020ce341ea 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -16,6 +16,7 @@ public: enum Type { AudioMixer, + AvatarMixer, All };