/** @brief Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'
  * 
  * @param dst_buffer    A smart pointer to the beginning of an allocated buffer
  * @param dst_offset    Offset of the first written byte from the beginning of 'dst_buffer' (in bytes)
  * @param bytes_to_copy Number of bytes to be copied
  * @param ptr           Pointer to the first byte to be written
  */
 inline void memory_write(handle_type & dst_buffer,
                          std::size_t dst_offset,
                          std::size_t bytes_to_copy,
                          const void * ptr)
 {
   assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));
   
   for (std::size_t i=0; i<bytes_to_copy; ++i)
     dst_buffer.get()[i+dst_offset] = static_cast<const char *>(ptr)[i];
 }
 /** @brief Reads data from a buffer back to main RAM.
  * 
  * @param src_buffer         A smart pointer to the beginning of an allocated source buffer
  * @param src_offset         Offset of the first byte to be read from the beginning of src_buffer (in bytes_
  * @param bytes_to_copy      Number of bytes to be read
  * @param ptr                Location in main RAM where to read data should be written to
  */
 inline void memory_read(handle_type const & src_buffer,
                         std::size_t src_offset,
                         std::size_t bytes_to_copy,
                         void * ptr)
 {
   assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));
   
   for (std::size_t i=0; i<bytes_to_copy; ++i)
     static_cast<char *>(ptr)[i] = src_buffer.get()[i+src_offset];
 }
 /** @brief Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'dst_buffer + dst_offset'.
  *  
  *  @param src_buffer     A smart pointer to the begin of an allocated buffer
  *  @param dst_buffer     A smart pointer to the end of an allocated buffer
  *  @param src_offset     Offset of the first byte to be written from the address given by 'src_buffer' (in bytes)
  *  @param dst_offset     Offset of the first byte to be written to the address given by 'dst_buffer' (in bytes)
  *  @param bytes_to_copy  Number of bytes to be copied
  */
 inline void memory_copy(handle_type const & src_buffer,
                         handle_type & dst_buffer,
                         std::size_t src_offset,
                         std::size_t dst_offset,
                         std::size_t bytes_to_copy)
 {
   assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));
   assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));
   
   for (std::size_t i=0; i<bytes_to_copy; ++i)
     dst_buffer.get()[i+dst_offset] = src_buffer.get()[i + src_offset];
 }
Exemple #4
0
      /** @brief Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' on the CUDA device to memory starting at address 'dst_buffer + dst_offset' on the same CUDA device.
       *
       *  @param src_buffer     A smart pointer to the begin of an allocated CUDA buffer
       *  @param dst_buffer     A smart pointer to the end of an allocated CUDA buffer
       *  @param src_offset     Offset of the first byte to be written from the address given by 'src_buffer' (in bytes)
       *  @param dst_offset     Offset of the first byte to be written to the address given by 'dst_buffer' (in bytes)
       *  @param bytes_to_copy  Number of bytes to be copied
       */
      inline void memory_copy(handle_type const & src_buffer,
                              handle_type & dst_buffer,
                              std::size_t src_offset,
                              std::size_t dst_offset,
                              std::size_t bytes_to_copy)
      {
        assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));
        assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));

        cudaMemcpy(reinterpret_cast<void *>(dst_buffer.get() + dst_offset),
                   reinterpret_cast<void *>(src_buffer.get() + src_offset),
                   bytes_to_copy,
                   cudaMemcpyDeviceToDevice);
      }
Exemple #5
0
/** @brief Reads data from a buffer back to main RAM.
 *
 * @param src_buffer         A smart pointer to the beginning of an allocated source buffer
 * @param src_offset         Offset of the first byte to be read from the beginning of src_buffer (in bytes_
 * @param bytes_to_copy      Number of bytes to be read
 * @param ptr                Location in main RAM where to read data should be written to
 */
inline void memory_read(handle_type const & src_buffer,
                        vcl_size_t src_offset,
                        vcl_size_t bytes_to_copy,
                        void * ptr,
                        bool /*async*/)
{
  assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));

#ifdef VIENNACL_WITH_OPENMP
  #pragma omp parallel for
#endif
  for (long i=0; i<long(bytes_to_copy); ++i)
    static_cast<char *>(ptr)[i] = src_buffer.get()[vcl_size_t(i)+src_offset];
}
Exemple #6
0
/** @brief Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'
 *
 * @param dst_buffer    A smart pointer to the beginning of an allocated buffer
 * @param dst_offset    Offset of the first written byte from the beginning of 'dst_buffer' (in bytes)
 * @param bytes_to_copy Number of bytes to be copied
 * @param ptr           Pointer to the first byte to be written
 */
inline void memory_write(handle_type & dst_buffer,
                         vcl_size_t dst_offset,
                         vcl_size_t bytes_to_copy,
                         const void * ptr,
                         bool /*async*/)
{
  assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));

#ifdef VIENNACL_WITH_OPENMP
  #pragma omp parallel for
#endif
  for (long i=0; i<long(bytes_to_copy); ++i)
    dst_buffer.get()[vcl_size_t(i)+dst_offset] = static_cast<const char *>(ptr)[i];
}
Exemple #7
0
/** @brief Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'dst_buffer + dst_offset'.
 *
 *  @param src_buffer     A smart pointer to the begin of an allocated buffer
 *  @param dst_buffer     A smart pointer to the end of an allocated buffer
 *  @param src_offset     Offset of the first byte to be written from the address given by 'src_buffer' (in bytes)
 *  @param dst_offset     Offset of the first byte to be written to the address given by 'dst_buffer' (in bytes)
 *  @param bytes_to_copy  Number of bytes to be copied
 */
inline void memory_copy(handle_type const & src_buffer,
                        handle_type & dst_buffer,
                        vcl_size_t src_offset,
                        vcl_size_t dst_offset,
                        vcl_size_t bytes_to_copy)
{
  assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));
  assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));

#ifdef VIENNACL_WITH_OPENMP
  #pragma omp parallel for
#endif
  for (long i=0; i<long(bytes_to_copy); ++i)
    dst_buffer.get()[vcl_size_t(i)+dst_offset] = src_buffer.get()[vcl_size_t(i) + src_offset];
}
Exemple #8
0
      /** @brief Reads data from a CUDA buffer back to main RAM.
       *
       * @param src_buffer         A smart pointer to the beginning of an allocated CUDA source buffer
       * @param src_offset         Offset of the first byte to be read from the beginning of src_buffer (in bytes_
       * @param bytes_to_copy      Number of bytes to be read
       * @param ptr                Location in main RAM where to read data should be written to
       */
      inline void memory_read(handle_type const & src_buffer,
                              std::size_t src_offset,
                              std::size_t bytes_to_copy,
                              void * ptr,
                              bool async = false)
      {
        assert( (src_buffer.get() != NULL) && bool("Memory not initialized!"));

        if (async)
          cudaMemcpyAsync(reinterpret_cast<char *>(ptr),
                          reinterpret_cast<char *>(src_buffer.get()) + src_offset,
                          bytes_to_copy,
                          cudaMemcpyDeviceToHost);
        else
          cudaMemcpy(reinterpret_cast<char *>(ptr),
                     reinterpret_cast<char *>(src_buffer.get()) + src_offset,
                     bytes_to_copy,
                     cudaMemcpyDeviceToHost);
      }
Exemple #9
0
      /** @brief Writes data from main RAM identified by 'ptr' to the CUDA buffer identified by 'dst_buffer'
       *
       * @param dst_buffer    A smart pointer to the beginning of an allocated CUDA buffer
       * @param dst_offset    Offset of the first written byte from the beginning of 'dst_buffer' (in bytes)
       * @param bytes_to_copy Number of bytes to be copied
       * @param ptr           Pointer to the first byte to be written
       */
      inline void memory_write(handle_type & dst_buffer,
                               std::size_t dst_offset,
                               std::size_t bytes_to_copy,
                               const void * ptr,
                               bool async = false)
      {
        assert( (dst_buffer.get() != NULL) && bool("Memory not initialized!"));

        if (async)
          cudaMemcpyAsync(reinterpret_cast<char *>(dst_buffer.get()) + dst_offset,
                          reinterpret_cast<const char *>(ptr),
                          bytes_to_copy,
                          cudaMemcpyHostToDevice);
        else
          cudaMemcpy(reinterpret_cast<char *>(dst_buffer.get()) + dst_offset,
                     reinterpret_cast<const char *>(ptr),
                     bytes_to_copy,
                     cudaMemcpyHostToDevice);
      }
Exemple #10
0
/**
 * \brief Get the bounding box of a speaker of the screen.
 * \param speaker The speaker.
 */
bear::universe::rectangle_type
bear::engine::balloon_layer::get_bounding_box_on_screen
( handle_type& speaker ) const
{
  const universe::rectangle_type cam( get_level().get_camera_focus() );
  const double x_ratio = get_size().x / cam.size().x;
  const double y_ratio = get_size().y / cam.size().y;

  const universe::coordinate_type left =
    x_ratio * (speaker.get_item()->get_left() - cam.left());
  const universe::coordinate_type right =
    x_ratio * (speaker.get_item()->get_right() - cam.left());
  const universe::coordinate_type top =
    y_ratio * (speaker.get_item()->get_top() - cam.bottom());
  const universe::coordinate_type bottom =
    y_ratio * (speaker.get_item()->get_bottom() - cam.bottom());

  return universe::rectangle_type( left, bottom, right, top );
} // balloon_layer::get_bounding_box_on_screen()
Exemple #11
0
 void operator() (handle_type & handle) const {
     impl::server_set servers;
     impl::add_servers<handle_type> server_adder(handle, servers);
     fusion::for_each(
             _tuple,
             server_adder
             );
     
     typename handle_type::pool_info p_info 
         = { _status, servers };
     
     handle.add_pool(_name, p_info);
 }
Exemple #12
0
 void operator() (handle_type & handle) const {
     impl::server_set servers;
     impl::add_servers<handle_type> server_adder(handle, servers);
     std::for_each(
             _pool.servers.begin(), 
             _pool.servers.end(), 
             server_adder
             )
         ;
     
     typename handle_type::pool_info p_info 
         = { _pool.status, servers };
     
     handle.add_pool(_pool.name, p_info);
 }
/**
 * \brief Play the sound when the mouse is on the item.
 */
void bear::mouse_over_manager::play_sound( handle_type item )
{
  if ( m_sample != NULL )
    {
      bool play(true);
      
      engine::with_rendering_attributes* a = 
        dynamic_cast<engine::with_rendering_attributes*>( item.get() );  
 
      if ( a != NULL )
        play = a->get_rendering_attributes().get_opacity() != 0; 
  
      if ( play )
        {
          audio::sound_effect effect(m_sample->get_effect());
          effect.set_position( this->get_center_of_mass() );
          m_sample->play(effect);
        }
    }
} // mouse_over_manager::play_sound()