mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:29:03 +02:00
Merge pull request #100 from birarda/eve
intial revision of eve the NPC
This commit is contained in:
commit
487b74f073
11 changed files with 159 additions and 16 deletions
|
@ -5,6 +5,7 @@ project(hifi)
|
||||||
add_subdirectory(avatar-mixer)
|
add_subdirectory(avatar-mixer)
|
||||||
add_subdirectory(audio-mixer)
|
add_subdirectory(audio-mixer)
|
||||||
add_subdirectory(domain-server)
|
add_subdirectory(domain-server)
|
||||||
|
add_subdirectory(eve)
|
||||||
add_subdirectory(interface)
|
add_subdirectory(interface)
|
||||||
add_subdirectory(injector)
|
add_subdirectory(injector)
|
||||||
add_subdirectory(space-server)
|
add_subdirectory(space-server)
|
||||||
|
|
20
eve/CMakeLists.txt
Normal file
20
eve/CMakeLists.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
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/")
|
||||||
|
|
||||||
|
set(TARGET_NAME eve)
|
||||||
|
|
||||||
|
include(${MACRO_DIR}/SetupHifiProject.cmake)
|
||||||
|
setup_hifi_project(${TARGET_NAME})
|
||||||
|
|
||||||
|
include(${MACRO_DIR}/IncludeGLM.cmake)
|
||||||
|
include_glm(${TARGET_NAME} ${ROOT_DIR})
|
||||||
|
|
||||||
|
# link the required hifi libraries
|
||||||
|
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
||||||
|
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||||
|
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
|
128
eve/src/main.cpp
Normal file
128
eve/src/main.cpp
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
//
|
||||||
|
// main.cpp
|
||||||
|
// eve
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 4/22/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
#include <AgentTypes.h>
|
||||||
|
#include <PacketHeaders.h>
|
||||||
|
#include <AgentList.h>
|
||||||
|
#include <AvatarData.h>
|
||||||
|
|
||||||
|
const int EVE_AGENT_LIST_PORT = 55441;
|
||||||
|
const float DATA_SEND_INTERVAL_MSECS = 10;
|
||||||
|
|
||||||
|
bool stopReceiveAgentDataThread;
|
||||||
|
|
||||||
|
void *receiveAgentData(void *args)
|
||||||
|
{
|
||||||
|
sockaddr senderAddress;
|
||||||
|
ssize_t bytesReceived;
|
||||||
|
unsigned char incomingPacket[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
|
AgentList *agentList = AgentList::getInstance();
|
||||||
|
Agent *avatarMixer = NULL;
|
||||||
|
|
||||||
|
while (!::stopReceiveAgentDataThread) {
|
||||||
|
if (agentList->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
|
||||||
|
switch (incomingPacket[0]) {
|
||||||
|
case PACKET_HEADER_BULK_AVATAR_DATA:
|
||||||
|
// this is the positional data for other agents
|
||||||
|
// eve doesn't care about this for now, so let's just update the receive time for the
|
||||||
|
// avatar mixer - this makes sure it won't be killed during silent agent removal
|
||||||
|
avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
|
||||||
|
|
||||||
|
if (avatarMixer != NULL) {
|
||||||
|
avatarMixer->setLastRecvTimeUsecs(usecTimestampNow());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// have the agentList handle list of agents from DS, replies from other agents, etc.
|
||||||
|
agentList->processAgentData(&senderAddress, incomingPacket, bytesReceived);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
// create an AgentList instance to handle communication with other agents
|
||||||
|
AgentList *agentList = AgentList::createInstance(AGENT_TYPE_AVATAR, EVE_AGENT_LIST_PORT);
|
||||||
|
|
||||||
|
// start telling the domain server that we are alive
|
||||||
|
agentList->startDomainServerCheckInThread();
|
||||||
|
|
||||||
|
// start the agent list thread that will kill off agents when they stop talking
|
||||||
|
agentList->startSilentAgentRemovalThread();
|
||||||
|
|
||||||
|
// start the ping thread that hole punches to create an active connection to other agents
|
||||||
|
agentList->startPingUnknownAgentsThread();
|
||||||
|
|
||||||
|
pthread_t receiveAgentDataThread;
|
||||||
|
pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL);
|
||||||
|
|
||||||
|
// create an AvatarData object, "eve"
|
||||||
|
AvatarData eve = AvatarData();
|
||||||
|
|
||||||
|
// move eve away from the origin
|
||||||
|
eve.setBodyPosition(glm::vec3(3, 0, -3));
|
||||||
|
|
||||||
|
// turn her back towards the origin
|
||||||
|
eve.setBodyYaw(-45);
|
||||||
|
|
||||||
|
// put her hand out so somebody can shake it
|
||||||
|
eve.setHandPosition(glm::vec3(eve.getBodyPosition()[0] - 0.2,
|
||||||
|
0.25,
|
||||||
|
eve.getBodyPosition()[2] + 0.1));
|
||||||
|
|
||||||
|
unsigned char broadcastPacket[MAX_PACKET_SIZE];
|
||||||
|
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
|
||||||
|
|
||||||
|
int numBytesToSend = 0;
|
||||||
|
|
||||||
|
timeval thisSend;
|
||||||
|
double numMicrosecondsSleep = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
// update the thisSend timeval to the current time
|
||||||
|
gettimeofday(&thisSend, NULL);
|
||||||
|
|
||||||
|
// find the current avatar mixer
|
||||||
|
Agent *avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
|
||||||
|
|
||||||
|
// make sure we actually have an avatar mixer with an active socket
|
||||||
|
if (avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) {
|
||||||
|
// use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer
|
||||||
|
numBytesToSend = eve.getBroadcastData((broadcastPacket + 1));
|
||||||
|
|
||||||
|
|
||||||
|
// use the UDPSocket instance attached to our agent list to send avatar data to mixer
|
||||||
|
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, numBytesToSend);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sleep for the correct amount of time to have data send be consistently timed
|
||||||
|
if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
|
||||||
|
usleep(numMicrosecondsSleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop the receive agent data thread
|
||||||
|
stopReceiveAgentDataThread = true;
|
||||||
|
pthread_join(receiveAgentDataThread, NULL);
|
||||||
|
|
||||||
|
// stop the agent list's threads
|
||||||
|
agentList->stopDomainServerCheckInThread();
|
||||||
|
agentList->stopPingUnknownAgentsThread();
|
||||||
|
agentList->stopSilentAgentRemovalThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ project(${TARGET_NAME})
|
||||||
|
|
||||||
# setup for find modules
|
# setup for find modules
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
|
||||||
set(GLM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
|
||||||
set(LODEPNG_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/LodePNG)
|
set(LODEPNG_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/LodePNG)
|
||||||
set(PORTAUDIO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
|
set(PORTAUDIO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
|
||||||
|
|
||||||
|
|
|
@ -334,7 +334,7 @@ void Head::simulate(float deltaTime) {
|
||||||
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
|
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
|
||||||
agent != agentList->getAgents().end();
|
agent != agentList->getAgents().end();
|
||||||
agent++) {
|
agent++) {
|
||||||
if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_INTERFACE ) )) {
|
if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) {
|
||||||
Head *otherAvatar = (Head *)agent->getLinkedData();
|
Head *otherAvatar = (Head *)agent->getLinkedData();
|
||||||
|
|
||||||
if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) {
|
if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) {
|
||||||
|
|
|
@ -1639,7 +1639,7 @@ int main(int argc, const char * argv[])
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentList::createInstance(AGENT_TYPE_INTERFACE);
|
AgentList::createInstance(AGENT_TYPE_AVATAR);
|
||||||
|
|
||||||
gettimeofday(&applicationStartupTime, NULL);
|
gettimeofday(&applicationStartupTime, NULL);
|
||||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
||||||
|
|
|
@ -132,7 +132,7 @@ const char* Agent::getTypeName() const {
|
||||||
case AGENT_TYPE_VOXEL:
|
case AGENT_TYPE_VOXEL:
|
||||||
name = AGENT_TYPE_NAME_VOXEL;
|
name = AGENT_TYPE_NAME_VOXEL;
|
||||||
break;
|
break;
|
||||||
case AGENT_TYPE_INTERFACE:
|
case AGENT_TYPE_AVATAR:
|
||||||
name = AGENT_TYPE_NAME_INTERFACE;
|
name = AGENT_TYPE_NAME_INTERFACE;
|
||||||
break;
|
break;
|
||||||
case AGENT_TYPE_AUDIO_MIXER:
|
case AGENT_TYPE_AUDIO_MIXER:
|
||||||
|
|
|
@ -228,7 +228,6 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
|
|
||||||
if (agent == agents.end()) {
|
if (agent == agents.end()) {
|
||||||
// we didn't have this agent, so add them
|
// we didn't have this agent, so add them
|
||||||
|
|
||||||
Agent newAgent = Agent(publicSocket, localSocket, agentType, agentId);
|
Agent newAgent = Agent(publicSocket, localSocket, agentType, agentId);
|
||||||
|
|
||||||
if (socketMatch(publicSocket, localSocket)) {
|
if (socketMatch(publicSocket, localSocket)) {
|
||||||
|
@ -281,7 +280,7 @@ void AgentList::broadcastToAgents(unsigned char *broadcastData, size_t dataBytes
|
||||||
void AgentList::handlePingReply(sockaddr *agentAddress) {
|
void AgentList::handlePingReply(sockaddr *agentAddress) {
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
// check both the public and local addresses for each agent to see if we find a match
|
// check both the public and local addresses for each agent to see if we find a match
|
||||||
// prioritize the private address so that we prune erroneous local matches
|
// prioritize the private address so that we prune erroneous local matches
|
||||||
if (socketMatch(agent->getPublicSocket(), agentAddress)) {
|
if (socketMatch(agent->getPublicSocket(), agentAddress)) {
|
||||||
agent->activatePublicSocket();
|
agent->activatePublicSocket();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
// Agent Type Codes
|
// Agent Type Codes
|
||||||
const char AGENT_TYPE_DOMAIN = 'D';
|
const char AGENT_TYPE_DOMAIN = 'D';
|
||||||
const char AGENT_TYPE_VOXEL = 'V';
|
const char AGENT_TYPE_VOXEL = 'V';
|
||||||
const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector???
|
const char AGENT_TYPE_AVATAR = 'I'; // could also be injector???
|
||||||
const char AGENT_TYPE_AUDIO_MIXER = 'M';
|
const char AGENT_TYPE_AUDIO_MIXER = 'M';
|
||||||
const char AGENT_TYPE_AVATAR_MIXER = 'W';
|
const char AGENT_TYPE_AVATAR_MIXER = 'W';
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
|
||||||
|
|
||||||
# setup for find modules
|
# setup for find modules
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
|
||||||
set(GLM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
|
||||||
|
|
||||||
# set up the external glm library
|
# set up the external glm library
|
||||||
include(${MACRO_DIR}/IncludeGLM.cmake)
|
include(${MACRO_DIR}/IncludeGLM.cmake)
|
||||||
|
@ -22,7 +21,4 @@ include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
||||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||||
|
|
||||||
# link in the hifi voxels library
|
# link in the hifi voxels library
|
||||||
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
|
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
|
||||||
|
|
||||||
# find required libraries
|
|
||||||
find_package(GLM REQUIRED)
|
|
|
@ -345,7 +345,7 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
// Now send this to the connected agents so they know to delete
|
// Now send this to the connected agents so they know to delete
|
||||||
printf("rebroadcasting delete voxel message to connected agents... agentList.broadcastToAgents()\n");
|
printf("rebroadcasting delete voxel message to connected agents... agentList.broadcastToAgents()\n");
|
||||||
agentList->broadcastToAgents(packetData,receivedBytes, &AGENT_TYPE_INTERFACE, 1);
|
agentList->broadcastToAgents(packetData,receivedBytes, &AGENT_TYPE_AVATAR, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (packetData[0] == PACKET_HEADER_Z_COMMAND) {
|
if (packetData[0] == PACKET_HEADER_Z_COMMAND) {
|
||||||
|
@ -373,14 +373,14 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
// Now send this to the connected agents so they can also process these messages
|
// Now send this to the connected agents so they can also process these messages
|
||||||
printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n");
|
printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n");
|
||||||
agentList->broadcastToAgents(packetData,receivedBytes, &AGENT_TYPE_INTERFACE, 1);
|
agentList->broadcastToAgents(packetData,receivedBytes, &AGENT_TYPE_AVATAR, 1);
|
||||||
}
|
}
|
||||||
// If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_INTERFACE, and we
|
// If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we
|
||||||
// need to make sure we have it in our agentList.
|
// need to make sure we have it in our agentList.
|
||||||
if (packetData[0] == PACKET_HEADER_HEAD_DATA) {
|
if (packetData[0] == PACKET_HEADER_HEAD_DATA) {
|
||||||
if (agentList->addOrUpdateAgent(&agentPublicAddress,
|
if (agentList->addOrUpdateAgent(&agentPublicAddress,
|
||||||
&agentPublicAddress,
|
&agentPublicAddress,
|
||||||
AGENT_TYPE_INTERFACE,
|
AGENT_TYPE_AVATAR,
|
||||||
agentList->getLastAgentId())) {
|
agentList->getLastAgentId())) {
|
||||||
agentList->increaseAgentId();
|
agentList->increaseAgentId();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue