DTboolean ScriptingVector3Switcher::compute (const PlugBase *plug) { PROFILER(SCRIPTING); if (super_type::compute(plug)) return true; if (plug == &_out) { if (_in8) _out = _in_vector8; else if (_in7) _out = _in_vector7; else if (_in6) _out = _in_vector6; else if (_in5) _out = _in_vector5; else if (_in4) _out = _in_vector4; else if (_in3) _out = _in_vector3; else if (_in2) _out = _in_vector2; else if (_in1) _out = _in_vector1; else if (!_buffer_output) _out = Vector3(0.0F,0.0F,0.0F); _out.set_clean(); return true; } return false; }
DTboolean ScriptingIntSwitcher::compute (const PlugBase *plug) { PROFILER(SCRIPTING); if (super_type::compute(plug)) return true; if (plug == &_out) { if (_in4) _out = _in_int4; else if (_in3) _out = _in_int3; else if (_in2) _out = _in_int2; else if (_in1) _out = _in_int1; else if (!_buffer_output) _out = 0; _out.set_clean(); return true; } return false; }
DTboolean ScriptingStringSwitcher::compute (const PlugBase *plug) { PROFILER(SCRIPTING); if (super_type::compute(plug)) return true; if (plug == &_out) { if (_in16) _out = _in_string16; else if (_in15) _out = _in_string15; else if (_in14) _out = _in_string14; else if (_in13) _out = _in_string13; else if (_in12) _out = _in_string12; else if (_in11) _out = _in_string11; else if (_in10) _out = _in_string10; else if (_in9) _out = _in_string9; else if (_in8) _out = _in_string8; else if (_in7) _out = _in_string7; else if (_in6) _out = _in_string6; else if (_in5) _out = _in_string5; else if (_in4) _out = _in_string4; else if (_in3) _out = _in_string3; else if (_in2) _out = _in_string2; else if (_in1) _out = _in_string1; else if (!_buffer_output) _out = ""; _out.set_clean(); return true; } return false; }
void ScriptingParticleVelocityAdder::dump_code(const std::string &object_name, Stream &s) { PROFILER(PARTICLES); s << object_name << "->set_continuous(" << _continuous << ");\n"; s << object_name << "->set_velocity(Vector3(" << _velocity->x << "," << _velocity->y << "," << _velocity->z << "));\n"; }
DTboolean ScriptingSoundRandomizer::compute (const PlugBase *plug) { PROFILER(SOUND); if (super_type::compute(plug)) return true; if (plug == &_sound_packet_out) { switch (_current_input) { case 0: _sound_packet_out = _sound_packet_in_1.as_ref_no_compute(); break; case 1: _sound_packet_out = _sound_packet_in_2.as_ref_no_compute(); break; case 2: _sound_packet_out = _sound_packet_in_3.as_ref_no_compute(); break; default: _sound_packet_out = _sound_packet_in_4.as_ref_no_compute(); break; } _sound_packet_out.set_clean(); return true; } return false; }
void DeviceAudioDX11::setNumberOfChannels (const DTint num_channels) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif PROFILER(PROFILER_SOUND); clearChannels(); _channels.resize(num_channels); for (DTuint c = 0; c < _channels.size(); ++c) { DeviceAudioDX11Channel &channel = _channels[c]; channel._x_voice = NULL; // Initialize channel ::memset(&channel._x_format, 0, sizeof(WAVEFORMATEX)); initializeChannel(channel, 44100, 16, 1); // Initialize 3D emitter ::memset(&channel._x3_emitter,0,sizeof(X3DAUDIO_EMITTER)); channel._x3_emitter.ChannelCount = 1; channel._x3_emitter.CurveDistanceScaler = FLT_MIN; channel._current_packet = 0; channel._source = NULL; channel._ready_to_start = false; channel._needs_priming = false; channel._is_playing = false; } }
void ScriptingKeyframesBool::set_key (void) { PROFILER(SCRIPTING); const std::vector<PlugBase*> &outgoing = _out.outgoing_connections(); if (outgoing.size() > 0) { // get first connected plug Plug<DTboolean> *outplug = static_cast<Plug<DTboolean>*>(*(outgoing.begin())); // get the value of the first connected plug DTboolean val = outplug->value_without_compute(); // clear any existing key clear_key(); // add the keyframe keyframe k; k._time = _t; k._value = val; k._id = _id++; _keyframes.push_back(k); std::sort(_keyframes.begin(), _keyframes.end()); } }
void ScriptingKeyframesMaterialResource::clear_key (DTint k) { PROFILER(SCRIPTING); auto i = _keyframes.begin() + k; _keyframes.erase(i); }
void ScriptingVector3Filter2Pole::tick (const DTfloat dt) { PROFILER(SCRIPTING); if (!_initialized) { _passes.resize(_num_passes); for (DTuint i = 0; i < _passes.size(); ++i) { _passes[i]._fx.initialize(_type, _num_passes, _freq_3db, _freq_sampling, _in->x); _passes[i]._fy.initialize(_type, _num_passes, _freq_3db, _freq_sampling, _in->y); _passes[i]._fz.initialize(_type, _num_passes, _freq_3db, _freq_sampling, _in->z); } _initialized = true; } Vector3 out = _in; for (DTuint i = 0; i < _passes.size(); ++i) { out.x = _passes[i]._fx.filter(out.x); out.y = _passes[i]._fy.filter(out.y); out.z = _passes[i]._fz.filter(out.z); } _out = out; _out.set_dirty(); }
DTboolean ScriptingParticleSizeSequencer::compute (const PlugBase *plug) { PROFILER(PARTICLES); if (super_type::compute(plug)) return true; if (plug == &_out) { // Make sure there are input particles std::shared_ptr<Particles> particles = _in; if (!particles || particles->translations_stream().size() <= 0) { _out.set_clean(); return true; } // Build the sizes stream if (particles->sizes_stream().size() <= 0) { particles->build_sizes_stream(); } // allocate the cache if (_cache.size() != particles->translations_stream().size()) _cache.resize(particles->translations_stream().size(), 0); // Do processing std::vector<DTfloat> &lifetimes = particles->lifetimes_stream(); std::vector<DTfloat> &sizes = particles->sizes_stream(); for (DTint i = particles->active_start(); i != particles->active_end(); i = (i + 1) % particles->translations_stream().size()) { DTfloat &lifetime = lifetimes[i]; DTint &cache = _cache[i]; DTfloat &size = sizes[i]; // If lifetime is less than the cache entry, just start over if (lifetime < _t[cache]) { cache = 0; } // Search the cache while (cache < NUM_ENTRIES-1 && lifetime >= _t[cache+1]) { ++cache; } // lerp the color value DTfloat lerp = (lifetime - _t[cache]) / (_t[cache+1] - _t[cache]); DTfloat one_minus_lerp = 1.0F - lerp; size = _s[cache] * one_minus_lerp + _s[cache+1] * lerp; } _out = particles; _out.set_clean(); return true; } return false; }
void ScriptingGlobalWriter::write (PlugNode *sender) { PROFILER(SCRIPTING); LOG_MESSAGE << "Writing global " << _global << " = " << _value; Globals::set_global(_global, _value, (_persistent ? Globals::PERSISTENT : Globals::VOLATILE) ); }
void ScriptingTouch::draw (const std::shared_ptr<CameraObject> &camera, const DTfloat lag) { PROFILER(SCRIPTING); _touch_vel_1 = Vector2(0.0F,0.0F); _touch_vel_2 = Vector2(0.0F,0.0F); _touch_vel_3 = Vector2(0.0F,0.0F); }
DTboolean ScriptingKeyframesMatrix3::compute (const PlugBase *plug) { PROFILER(SCRIPTING); if (super_type::compute(plug)) return true; if (plug == &_out) { DTfloat t = _t; // Special cases if (_keyframes.size() == 0) { _out.set_clean(); return true; } if (_keyframes.size() == 1) { _out = Matrix3(_keyframes[0]._value); return true; } // Scan for the best key if (_keyframe_cache < 0) _keyframe_cache = 0; else if (_keyframe_cache > (DTint) _keyframes.size() - 2) _keyframe_cache = (DTint) _keyframes.size() - 2; while (1) { if (t < _keyframes[_keyframe_cache]._time) { --_keyframe_cache; if (_keyframe_cache < 0) { _keyframe_cache = 0; _out = Matrix3(_keyframes[_keyframe_cache]._value); break; } } else if (t > _keyframes[_keyframe_cache+1]._time) { ++_keyframe_cache; if (_keyframe_cache > (DTint) _keyframes.size() - 2) { _keyframe_cache = (DTint) _keyframes.size() - 2; _out = Matrix3(_keyframes[_keyframe_cache+1]._value); break; } } else { DTfloat interp = (t - _keyframes[_keyframe_cache]._time) / (_keyframes[_keyframe_cache+1]._time - _keyframes[_keyframe_cache]._time); Quaternion out = Quaternion::slerp(_keyframes[_keyframe_cache]._value, _keyframes[_keyframe_cache+1]._value, interp); _out = Matrix3(out); break; } } _out.set_clean(); return true; } return false; }
DTboolean DeviceAudioDX11::isPlaying (SoundSource *source) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif PROFILER(PROFILER_SOUND); return getChannel(source) >= 0; }
void ScriptingGyro::accelerate (const Vector3 &a) { PROFILER(SCRIPTING); const DTfloat FILTER_FACTOR = 0.1F; _out = a; _out_low_freq = (a * FILTER_FACTOR) + (_out_low_freq * (1.0F - FILTER_FACTOR)); _out_high_freq = a - _out_low_freq; }
void DeviceAudioDX11::clearChannels (void) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif PROFILER(PROFILER_SOUND); stopAll(); destroyChannels(); }
void ScriptingKeyframesBool::clear_key (void) { PROFILER(SCRIPTING); FOR_EACH (i,_keyframes) { if (_t <= i->_time + (1.0F/30.0F) && _t > i->_time - (1.0F/30.0F)) { _keyframes.erase(i); return; } } }
DTboolean DeviceAudioDX11::play (SoundSource *source, ScriptingSound *sound_loader) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif PROFILER(PROFILER_SOUND); // Don't bother if gain is too low if (_gain < 0.01F) return false; // Search for this source already playing for (DTuint c = 0; c < _channels.size(); ++c) { DeviceAudioDX11Channel &channel = _channels[c]; if (channel._source == source) { playOnChannel(channel, source, sound_loader); return true; } } // Search for an empty channel for (DTuint c = 0; c < _channels.size(); ++c) { DeviceAudioDX11Channel &channel = _channels[c]; if (channel._source == NULL) { playOnChannel(channel, source, sound_loader); return true; } } // No empty spots on list so we can check if we should // bump an existing sound. Find the lowest priority object. DTfloat smallest_pri = std::numeric_limits<DTfloat>::infinity(); DTuint smallest_pri_index = 0; for (DTuint c = 0; c < _channels.size(); ++c) { DTfloat pri = estimatePriority(_channels[c]._source); if (pri < smallest_pri) { smallest_pri_index = c; smallest_pri = pri; } } // Check if the new sound is more important if (smallest_pri < estimatePriority(source)) { playOnChannel(_channels[smallest_pri_index], source, sound_loader); return true; } return false; }
void PackageList::showData(const String& pattern) { // clear packages.clear(); // find matching packages vector<PackagedP> matching; { PROFILER(_("find matching packages")); package_manager.findMatching(pattern, matching); } FOR_EACH(p, matching) { // open image PROFILER(_("load package image")); InputStreamP stream = p->openIconFile(); Image img; Bitmap bmp; if (stream && img.LoadFile(*stream)) { bmp = Bitmap(img); } // add to list packages.push_back(PackageData(p, bmp)); }
void DeviceAudioDX11::stopAll (void) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif PROFILER(PROFILER_SOUND); for (DTuint c = 0; c < _channels.size(); ++c) { stopOnChannel(_channels[c]); } }
DTboolean PlugBase::set_incoming_connection (PlugBase* incoming) { PROFILER(SCRIPTING); // // Lock this owner and the incoming owner // std::unique_lock<std::recursive_mutex> lock_this(owner()->lock(),std::try_to_lock); std::unique_lock<std::recursive_mutex> lock_incoming(incoming->owner()->lock(),std::try_to_lock); DTboolean lock_this_status = lock_this.owns_lock(); DTboolean lock_incoming_status = lock_incoming.owns_lock(); while (!lock_this_status || !lock_incoming_status) { if (lock_this_status) lock_this.unlock(); if (lock_incoming_status) lock_incoming.unlock(); lock_this_status = lock_this.owns_lock(); lock_incoming_status = lock_incoming.owns_lock(); } // // Do modifications // PlugBase *&incoming_ref = connections()._incoming; if (is_compatible(incoming) && incoming_ref != incoming) { // Disconnect old node if (incoming_ref) { owner()->incoming_plug_was_disconnected(incoming_ref, this); incoming_ref->remove_outgoing_connection(this); } // Connect new node incoming_ref = incoming; // Add this plug to the outgoing connections incoming_ref->add_outgoing_connection(this); set_dirty(); owner()->incoming_plug_was_attached(incoming_ref, this); return true; } else { if (!is_compatible(incoming)) LOG_MESSAGE << plug_type() << " doesn't match " << incoming->plug_type(); } return false; }
void Images::load_texture( ClutterTexture * texture, TPImage * image , guint x , guint y , guint w , guint h ) { PROFILER( "Images::load_texture/clutter" , PROFILER_INTERNAL_CALLS ); g_assert( texture ); g_assert( image ); const guchar * pixels = ( const guchar * ) image->pixels; guint width = image->width; guint height = image->height; if ( w != 0 && h != 0 ) { pixels += x * image->depth + y * image->pitch; width = w; height = h; } ClutterTextureFlags flags = image->bgr ? CLUTTER_TEXTURE_RGB_FLAG_BGR : CLUTTER_TEXTURE_NONE; if ( image->depth == 4 && image->pm_alpha ) { flags = ( ClutterTextureFlags ) ( flags | CLUTTER_TEXTURE_RGB_FLAG_PREMULT ); } clutter_texture_set_from_rgb_data( texture, pixels, image->depth == 4, width, height, image->pitch, image->depth, flags, NULL ); #ifndef TP_PRODUCTION ImageInfo info( image ); if ( w !=0 && h != 0 ) { info.width = w; info.height = h; info.bytes = w * h * image->depth; } add_to_image_list( texture , info ); #endif }
void ScriptingGlobalPoll::tick (const DTfloat dt) { PROFILER(SCRIPTING); if (_read) { if (_substitute) { _value = Globals::substitute_global(_global); } else { _value = Globals::global(_global); } } }
void Event::add_incoming_connection (Event* incoming) { PROFILER(SCRIPTING); std::vector<Event*> &incoming_ref = connections()._incoming; if (std::find(incoming_ref.begin(), incoming_ref.end(), incoming) == incoming_ref.end()) { incoming_ref.push_back(incoming); incoming->add_outgoing_connection(this); owner()->incoming_event_was_attached(incoming, this); } }
void ScriptingIsTransitioning::tick (const DTfloat dt) { PROFILER(SCRIPTING); _is_transitioning = System::application()->is_transitioning(); if (_is_transitioning && !_last_is_transitioning) _begin_transition_e.send(this); else if (!_is_transitioning && _last_is_transitioning) _end_transition_e.send(this); _last_is_transitioning = _is_transitioning; }
DTboolean PlugBase::add_outgoing_connection (PlugBase* outgoing) { PROFILER(SCRIPTING); // // Lock this owner and the outgoing owner // std::unique_lock<std::recursive_mutex> lock_this(owner()->lock(),std::try_to_lock); std::unique_lock<std::recursive_mutex> lock_outgoing(outgoing->owner()->lock(),std::try_to_lock); DTboolean lock_this_status = lock_this.owns_lock(); DTboolean lock_outgoing_status = lock_outgoing.owns_lock(); while (!lock_this_status || !lock_outgoing_status) { if (lock_this_status) lock_this.unlock(); if (lock_outgoing_status) lock_outgoing.unlock(); lock_this_status = lock_this.owns_lock(); lock_outgoing_status = lock_outgoing.owns_lock(); } // // Do modifications // std::vector<PlugBase*> &outgoing_ref = connections()._outgoing; // Check if only a single output is allowed if (!info().is_single_output() || (info().is_single_output() && outgoing_ref.size() == 0)) { // Check compatibility if (is_compatible(outgoing)) { auto i = std::find(outgoing_ref.begin(), outgoing_ref.end(), outgoing); if (i == outgoing_ref.end()) { outgoing_ref.push_back(outgoing); outgoing->set_dirty(); outgoing->set_incoming_connection(this); // Increasse Ref count for owner owner()->outgoing_plug_was_attached(this, outgoing); } return true; } } return false; }
void ScriptingDelayOff::tick (const DTfloat dt) { PROFILER(SCRIPTING); _time += dt; if (_in) { _time = 0.0F; _out = true; } else { if (_time >= _delay) _out = false; else _out = true; } }
DTboolean ScriptingNotEqual::compute (const PlugBase *plug) { PROFILER(SCRIPTING); if (super_type::compute(plug)) return true; if (plug == &_out) { _out = (_in1) != (_in2); _out.set_clean(); return true; } return false; }
TPImage * Images::decode_image( const char * filename ) { PROFILER( "Images::decode_image/file" , PROFILER_INTERNAL_CALLS ); if ( ! g_file_test( filename, G_FILE_TEST_IS_REGULAR ) ) { tpwarn( "IMAGE DOES NOT EXIST %s", filename ); return NULL; } TPImage image; memset( &image, 0, sizeof( TPImage ) ); DecoderList decoders = get_decoders( filename ); for ( DecoderList::const_iterator it = decoders.begin(); it != decoders.end(); ++it ) { tplog( "TRYING TO DECODE '%s' USING %s", filename, ( * it )->name() ); int r = ( * it )->decode( filename, &image ); if ( r == TP_IMAGE_UNSUPPORTED_FORMAT ) { tplog( " UNSUPPORTED" ); continue; } if ( r == TP_IMAGE_DECODE_FAILED ) { tplog( " FAILED" ); break; } tplog( " DECODED" ); // It was decoded g_assert( image.pixels ); g_assert( image.depth == 3 || image.depth == 4 ); g_assert( image.width * image.depth <= image.pitch ); g_assert( image.bgr == 0 || image.bgr == 1 ); return g_slice_dup( TPImage, &image ); } tpwarn( "FAILED TO DECODE %s", filename ); return NULL; }
DTint ScriptingKeyframesBool::set_key_time (DTint k, DTfloat time) { PROFILER(SCRIPTING); DTint oldid = _keyframes[k]._id; _keyframes[k]._time = time; std::sort(_keyframes.begin(), _keyframes.end()); for (std::size_t i = 0; i < _keyframes.size(); ++i) if (oldid == _keyframes[i]._id) return static_cast<DTint>(i); return -1; }