int gams::platforms::OscJoystickPlatform::orient(const pose::Orientation & target, const pose::OrientationBounds &bounds) { // update variables BasePlatform::orient(target, bounds); madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_TRACE, "gams::platforms::OscJoystickPlatform::orient:" \ " %s: requested target \"%f,%f,%f\"\n", self_->agent.prefix.c_str(), target.rx(), target.ry(), target.rz()); // convert from input reference frame to vrep reference frame, if necessary pose::Orientation new_target(get_frame(), target); last_orient_ = new_target; utility::OscUdp::OscMap values; std::vector<double> yaw_velocity; yaw_velocity.push_back(0); values[yaw_velocity_prefix_] = yaw_velocity; osc_.send(values); // we're not changing orientation. this has to be done for move alg to work return PLATFORM_ARRIVED; }
void source_accept_cb(uv_stream_t *server, int status) { struct source_context *source = new_source(); struct target_context *target = new_target(); source->target = target; target->source = source; uv_tcp_init(server->loop, &source->handle.tcp); uv_tcp_init(server->loop, &target->handle.tcp); uv_tcp_nodelay(&source->handle.tcp, 0); uv_tcp_nodelay(&target->handle.tcp, 0); uv_tcp_keepalive(&source->handle.tcp, 1, 60); uv_tcp_keepalive(&target->handle.tcp, 1, 60); int rc = uv_accept(server, &source->handle.stream); if (rc == 0) { connect_to_target(target); } else { logger_log(LOG_ERR, "accept error: %s", uv_strerror(rc)); close_source(source); close_target(target); } }
static void create_drop_targets(const SDL_Rect& loc, gui::drop_group_manager_ptr group, target_store& targets, int& id_counter) { gui::drop_target_ptr new_target(new test_drop_target(group, loc)); BOOST_CHECK_EQUAL(id_counter++, new_target->get_id()); // Test that drop gives -1 correctly for non overlapping // targets BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(new_target.get())->handle_drop(), -1); targets.push_back(new_target); }
struct stumpless_target * stumpless_open_buffer_target( const char *name, char *buffer, size_t size, int options, int default_facility ) { struct stumpless_target *target; clear_error( ); if( !name ) { raise_argument_empty( "name is NULL" ); return NULL; } if( !buffer ) { raise_argument_empty( "buffer is NULL" ); return NULL; } target = new_target( STUMPLESS_BUFFER_TARGET, name, options, default_facility ); if( !target ) { goto fail; } target->id = new_buffer_target( buffer, size ); if( !target->id ) { goto fail_id; } stumpless_set_current_target( target ); return target; fail_id: destroy_target( target ); fail: return NULL; }
/** * Given a target, trys to return one of the 8+ adjacent tiles * Returns the retargeted position on success, returns the original position on failure */ FPoint MapCollision::getRandomNeighbor(const Point& target, int range, bool ignore_blocked) { FPoint new_target(target); std::vector<FPoint> valid_tiles; for (int i=-range; i<=range; i++) { for (int j=-range; j<=range; j++) { if (i == 0 && j == 0) continue; // skip the middle tile new_target.x = static_cast<float>(target.x + i) + 0.5f; new_target.y = static_cast<float>(target.y + j) + 0.5f; if (isValidPosition(new_target.x, new_target.y, MOVE_NORMAL, COLLIDE_NORMAL) || ignore_blocked) valid_tiles.push_back(new_target); } } if (!valid_tiles.empty()) return valid_tiles[rand() % valid_tiles.size()]; else return FPoint(target); }
int gams::platforms::OscJoystickPlatform::move(const pose::Position & target, const pose::PositionBounds & bounds) { // update variables BasePlatform::move(target, bounds); int result = PLATFORM_MOVING; madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_TRACE, "gams::platforms::OscJoystickPlatform::move:" \ " %s: requested target \"%f,%f,%f\"\n", self_->agent.prefix.c_str(), target.x(), target.y(), target.z()); // convert from input reference frame to vrep reference frame, if necessary pose::Position new_target(get_frame(), target); madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_TRACE, "gams::platforms::OscJoystickPlatform::move:" \ " %s: target \"%f,%f,%f\"\n", self_->agent.prefix.c_str(), new_target.x(), new_target.y(), new_target.z()); // are we moving to a new location? If so, start an acceleration timer if (!last_move_.approximately_equal(new_target, 0.1)) { move_timer_.start(); last_move_ = new_target; } pose::Position cur_loc = get_location(); utility::OscUdp::OscMap values; std::vector<double> xy_velocity; std::vector<double> z_velocity; // if (bounds.check_position(cur_loc, new_target)) // quick hack to check position is within 0.5 meters bool finished = false; xy_velocity = calculate_thrust(cur_loc, new_target, finished); // if we have just started our movement, modify velocity to account // for acceleration. This will help animation be smooth in Unreal. move_timer_.stop(); double move_time = move_timer_.duration_ds(); if (move_time < 1.0) { // have acceleration ramp up over a second at .1 per 1/20 second for (size_t i = 0; i < xy_velocity.size(); ++i) { double abs_velocity = fabs(xy_velocity[i]); double signed_move_time = xy_velocity[i] < 0 ? -move_time : move_time; xy_velocity[i] = move_time < abs_velocity ? signed_move_time : xy_velocity[i]; } madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_MAJOR, "gams::platforms::OscJoystickPlatform::move:" \ " %s: moving to new target at time %f with modified velocity " "[%f,%f,%f]\n", self_->agent.prefix.c_str(), move_time, xy_velocity[0], xy_velocity[1], xy_velocity[2]); } z_velocity.push_back(xy_velocity[2]); xy_velocity.resize(2); if (finished) { madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_MINOR, "gams::platforms::OscJoystickPlatform::move:" \ " %s: ARRIVED at target \"%f,%f,%f\"\n", self_->agent.prefix.c_str(), new_target.x(), new_target.y(), new_target.z()); result = PLATFORM_ARRIVED; } values[xy_velocity_prefix_] = xy_velocity; values[z_velocity_prefix_] = z_velocity; osc_.send(values); // unlike other platforms, we do not send the velocities // Moving to the location is up to the user with the controller return result; }
fruitlib::pp::texture::counted_instance const fruitlib::pp::texture::manager::query_internal( descriptor const &d) { boost::iterator_range<texture_map::iterator> eq_range = textures_.equal_range( d); for( texture_map::iterator i = eq_range.begin(); i != eq_range.end(); ++i) { // Texture is correct, but it's locked if (i->second->locked()) continue; // Texture is correct and not locked! i->second->locked( true); return counted_instance( *(i->second), std::bind( static_cast<void (instance::*)(bool)>( &instance::locked), std::placeholders::_1, false)); } sge::renderer::texture::planar_unique_ptr new_texture = renderer_.create_planar_texture( sge::renderer::texture::planar_parameters( d.size(), sge::renderer::texture::color_format( d.image_format(), sge::renderer::texture::emulate_srgb::no), sge::renderer::texture::mipmap::off(), sge::renderer::resource_flags_field::null(), sge::renderer::texture::capabilities_field{ sge::renderer::texture::capabilities::render_target})); sge::renderer::target::offscreen_unique_ptr new_target( sge::renderer::target::from_texture( renderer_, *new_texture)); fruitlib::pp::texture::optional_depth_stencil_surface new_target_depth_stencil; switch (d.depth_stencil()) { case depth_stencil_format::off: break; case depth_stencil_format::d16: new_target_depth_stencil = fruitlib::pp::texture::optional_depth_stencil_surface( renderer_.create_depth_stencil_surface( sge::renderer::depth_stencil_buffer::surface_parameters( d.size(), sge::image::ds::format::d16))); break; case depth_stencil_format::d32: new_target_depth_stencil = fruitlib::pp::texture::optional_depth_stencil_surface( renderer_.create_depth_stencil_surface( sge::renderer::depth_stencil_buffer::surface_parameters( d.size(), sge::image::ds::format::d32))); break; case depth_stencil_format::d24s8: new_target_depth_stencil = fruitlib::pp::texture::optional_depth_stencil_surface( renderer_.create_depth_stencil_surface( sge::renderer::depth_stencil_buffer::surface_parameters( d.size(), sge::image::ds::format::d24s8))); break; } fcppt::optional::maybe_void( new_target_depth_stencil, [ &new_target ]( sge::renderer::depth_stencil_buffer::surface_unique_ptr const &_surface ) { new_target->depth_stencil_surface( sge::renderer::depth_stencil_buffer::optional_surface_ref( fcppt::make_ref( *_surface))); } ); // There are no matching textures? Gotta create a new one! texture_map::iterator const result( textures_.insert( std::make_pair( d, fcppt::make_unique_ptr<fruitlib::pp::texture::instance>( d, std::move( new_texture), std::move( new_target), std::move( new_target_depth_stencil), fruitlib::pp::texture::is_locked( true))))); return fruitlib::pp::texture::counted_instance( *result->second, std::bind( static_cast<void (instance::*)(bool)>( &instance::locked), std::placeholders::_1, false)); }
void sge::d3d9::render_context::object::offscreen_target( sge::renderer::target::optional_offscreen_ref const &_new_target ) { fcppt::optional::maybe( _new_target, [ this ]{ { sge::d3d9::target::base &cur_target( FCPPT_ASSERT_OPTIONAL_ERROR( offscreen_target_ ).get() ); cur_target.active( false ); } offscreen_target_ = sge::d3d9::render_context::object::optional_target_base_ref(); scoped_target_.target().active( true ); }, [ this ]( fcppt::reference< sge::renderer::target::offscreen > const _target ) { FCPPT_ASSERT_PRE( !offscreen_target_.has_value() ); scoped_target_.target().active( false ); sge::d3d9::target::base &new_target( dynamic_cast< sge::d3d9::target::base & >( _target.get() ) ); new_target.active( true ); offscreen_target_ = sge::d3d9::render_context::object::optional_target_base_ref( fcppt::make_ref( new_target ) ); } ); }