Revision 90fa4b4e server/src/Arbiter.cpp

View differences:

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;
......
69 71

  
70 72
void Arbiter::set_default_emotion(EmotionState e) {
71 73
	// lock access
72
	mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
74
	boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
73 75

  
74 76
	// update our config, ignore duration as this is the default emotion
75 77
	emotion_config_default.select_config(e.value);
......
82 84

  
83 85
void Arbiter::set_current_emotion(EmotionState e) {
84 86
	// lock access
85
	mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
87
	boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
86 88

  
87 89
	// this will set a emotion override for a given time, after the timeout
88 90
	// we will return to the default emotion state:
......
97 99

  
98 100
void Arbiter::set_mouth_config(MouthConfig m) {
99 101
	// lock access
100
	mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
102
	boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
101 103

  
102 104
	mouth_config = m;
103 105
}
104 106

  
105 107
void Arbiter::set_gaze_target(humotion::GazeState target) {
106 108
	// lock access
107
	mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
109
	boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
108 110

  
109 111
	requested_gaze_state = target;
110 112
}
111 113

  
112 114
void Arbiter::set_mouth_target(humotion::MouthState target) {
113 115
	// lock access
114
	mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
116
	boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
115 117

  
116 118
	requested_mouth_state = target;
117 119
}
......
120 122
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation) {
121 123
	// incoming animation, check if this would conflict with any pending animations:
122 124
	// lock access & iterate over vector:
123
	mutex::scoped_lock lock_av(active_animation_vector_mutex);
125
	boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
124 126
	active_animation_vector_t::iterator it;
125 127
	for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
126 128
		boost::shared_ptr<Animation> current_ani = *it;
......
165 167
void Arbiter::speak(
166 168
   boost::shared_ptr<Utterance> u) { //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
167 169
	// lock audio playback as such:
168
	mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
170
	boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
169 171

  
170 172
	// lock utterance & store data:
171
	mutex::scoped_lock scoped_lock(utterance_mutex);
173
	boost::mutex::scoped_lock scoped_lock(utterance_mutex);
172 174
	utterance = u;
173 175
	scoped_lock.unlock();
174 176

  
......
277 279
	}
278 280

  
279 281
	// lock access
280
	mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
282
	boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
281 283

  
282 284
	// did the current emotion time out?
283 285
	if (!emotion_target->is_active()) {
......
317 319
		// new incoming target, set up soft fade:
318 320
		cout << "NEW EMOTION\n";
319 321
		gaze_state_old = gaze_state;
320
		gaze_state_end_time = get_system_time() + boost::posix_time::milliseconds(overblend_time);
322
		gaze_state_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(overblend_time);
321 323
		gaze_state_animation_restart = false;
322 324
	}
323 325
	// do smooth overblend, all targets should be reached at gaze_state_end_time
324
	boost::posix_time::time_duration tdiff = gaze_state_end_time - get_system_time();
325
	if (tdiff.is_negative()) {
326
	double diff_ms =
327
	   std::chrono::duration<double, std::milli>(gaze_state_end_time - std::chrono::steady_clock::now()).count();
328
	if (diff_ms < 0) {
326 329
		// animation is done, exit now
327 330
		return gaze_target;
328 331
	}
329 332
	else {
330 333
		// do smooth animation
331
		double diff_ms = tdiff.total_milliseconds();
332 334
		double tp = 1.0 - diff_ms / static_cast<double>(overblend_time);
333 335

  
334 336
		result.pan_offset = gaze_state_old.pan_offset + tp * (gaze_target.pan_offset - gaze_state_old.pan_offset);
......
349 351

  
350 352
void Arbiter::override_by_animation() {
351 353
	// lock access & iterate over vector:
352
	mutex::scoped_lock lock_av(active_animation_vector_mutex);
354
	boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
353 355
	active_animation_vector_t::iterator it;
354 356
	for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
355 357
		boost::shared_ptr<Animation> current_ani = *it;

Also available in: Unified diff