Revision 9cb381ec server/src/Arbiter.cpp
| server/src/Arbiter.cpp | ||
|---|---|---|
| 30 | 30 |
#include "AudioPlayerLibAO.h" |
| 31 | 31 |
#include "AudioPlayerRSB.h" |
| 32 | 32 |
#include <boost/algorithm/string/predicate.hpp> |
| 33 |
#include <boost/thread/mutex.hpp> |
|
| 34 |
#include <iostream> |
|
| 33 | 35 |
|
| 34 | 36 |
using namespace boost; |
| 35 | 37 |
using namespace std; |
| ... | ... | |
| 66 | 68 |
|
| 67 | 69 |
void Arbiter::set_default_emotion(EmotionState e){
|
| 68 | 70 |
//lock access |
| 69 |
mutex::scoped_lock scoped_lock(emotion_config_default_mutex); |
|
| 71 |
boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
|
|
| 70 | 72 |
|
| 71 | 73 |
//update our config, ignore duration as this is the default emotion |
| 72 | 74 |
emotion_config_default.select_config(e.value); |
| ... | ... | |
| 79 | 81 |
|
| 80 | 82 |
void Arbiter::set_current_emotion(EmotionState e){
|
| 81 | 83 |
//lock access |
| 82 |
mutex::scoped_lock scoped_lock(emotion_config_current_mutex); |
|
| 84 |
boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
|
|
| 83 | 85 |
|
| 84 | 86 |
//this will set a emotion override for a given time, after the timeout |
| 85 | 87 |
//we will return to the default emotion state: |
| ... | ... | |
| 94 | 96 |
|
| 95 | 97 |
void Arbiter::set_mouth_config(MouthConfig m){
|
| 96 | 98 |
//lock access |
| 97 |
mutex::scoped_lock scoped_lock(mouth_config_override_mutex); |
|
| 99 |
boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
|
|
| 98 | 100 |
|
| 99 | 101 |
mouth_config = m; |
| 100 | 102 |
} |
| 101 | 103 |
|
| 102 | 104 |
void Arbiter::set_gaze_target(humotion::GazeState target){
|
| 103 | 105 |
//lock access |
| 104 |
mutex::scoped_lock scoped_lock(requested_gaze_state_mutex); |
|
| 106 |
boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
|
|
| 105 | 107 |
|
| 106 | 108 |
requested_gaze_state = target; |
| 107 | 109 |
} |
| 108 | 110 |
|
| 109 | 111 |
void Arbiter::set_mouth_target(humotion::MouthState target){
|
| 110 | 112 |
//lock access |
| 111 |
mutex::scoped_lock scoped_lock(requested_mouth_state_mutex); |
|
| 113 |
boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
|
|
| 112 | 114 |
|
| 113 | 115 |
requested_mouth_state = target; |
| 114 | 116 |
} |
| ... | ... | |
| 117 | 119 |
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation){
|
| 118 | 120 |
//incoming animation, check if this would conflict with any pending animations: |
| 119 | 121 |
//lock access & iterate over vector: |
| 120 |
mutex::scoped_lock lock_av(active_animation_vector_mutex); |
|
| 122 |
boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
|
|
| 121 | 123 |
active_animation_vector_t::iterator it; |
| 122 | 124 |
for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
|
| 123 | 125 |
boost::shared_ptr<Animation> current_ani = *it; |
| ... | ... | |
| 160 | 162 |
|
| 161 | 163 |
void Arbiter::speak(boost::shared_ptr<Utterance> u){ //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
|
| 162 | 164 |
//lock audio playback as such: |
| 163 |
mutex::scoped_lock scoped_lock_audio(audio_player_mutex); |
|
| 165 |
boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
|
|
| 164 | 166 |
|
| 165 | 167 |
//lock utterance & store data: |
| 166 |
mutex::scoped_lock scoped_lock(utterance_mutex); |
|
| 168 |
boost::mutex::scoped_lock scoped_lock(utterance_mutex);
|
|
| 167 | 169 |
utterance = u; |
| 168 | 170 |
scoped_lock.unlock(); |
| 169 | 171 |
|
| ... | ... | |
| 270 | 272 |
} |
| 271 | 273 |
|
| 272 | 274 |
//lock access |
| 273 |
mutex::scoped_lock scoped_lock1(emotion_config_default_mutex); |
|
| 275 |
boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
|
|
| 274 | 276 |
|
| 275 | 277 |
|
| 276 | 278 |
// did the current emotion time out? |
| ... | ... | |
| 312 | 314 |
// new incoming target, set up soft fade: |
| 313 | 315 |
cout << "NEW EMOTION\n"; |
| 314 | 316 |
gaze_state_old = gaze_state; |
| 315 |
gaze_state_end_time = get_system_time() + boost::posix_time::milliseconds(overblend_time);
|
|
| 317 |
gaze_state_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(overblend_time);
|
|
| 316 | 318 |
gaze_state_animation_restart = false; |
| 317 | 319 |
} |
| 318 | 320 |
// do smooth overblend, all targets should be reached at gaze_state_end_time |
| 319 |
boost::posix_time::time_duration tdiff = gaze_state_end_time - get_system_time();
|
|
| 320 |
if (tdiff.is_negative()) {
|
|
| 321 |
double diff_ms = std::chrono::duration<double, std::milli>(gaze_state_end_time - std::chrono::steady_clock::now()).count();
|
|
| 322 |
if (diff_ms < 0) {
|
|
| 321 | 323 |
// animation is done, exit now |
| 322 | 324 |
return gaze_target; |
| 323 | 325 |
} else {
|
| 324 | 326 |
// do smooth animation |
| 325 |
double diff_ms = tdiff.total_milliseconds(); |
|
| 326 | 327 |
double tp = 1.0 - diff_ms / static_cast<double>(overblend_time); |
| 327 | 328 |
|
| 328 | 329 |
result.pan_offset = gaze_state_old.pan_offset + tp * (gaze_target.pan_offset - gaze_state_old.pan_offset); |
| ... | ... | |
| 343 | 344 |
|
| 344 | 345 |
void Arbiter::override_by_animation(){
|
| 345 | 346 |
//lock access & iterate over vector: |
| 346 |
mutex::scoped_lock lock_av(active_animation_vector_mutex); |
|
| 347 |
boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
|
|
| 347 | 348 |
active_animation_vector_t::iterator it; |
| 348 | 349 |
for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
|
| 349 | 350 |
boost::shared_ptr<Animation> current_ani = *it; |
Also available in: Unified diff