示例#1
0
文件: atlas.cpp 项目: untgames/funner
 TileEntry (const char* in_name, const char* in_image, const math::vec2ui& origin, const math::vec2ui& size, unsigned int tag)
   : name (in_name)
   , image (in_image)
   {
     tile.origin = origin;
     tile.size   = size;
     tile.name   = name.c_str ();
     tile.image  = image.c_str ();
     tile.tag    = tag;
   }
示例#2
0
istAPI bool ist::FileToString( const char *path, stl::string &out )
{
    FILE *fin = fopen(path, "rb");
    if(!fin) { return false; }
    fseek(fin, 0, SEEK_END);
    out.resize((size_t)ftell(fin));
    fseek(fin, 0, SEEK_SET);
    fread(&out[0], 1, out.size(), fin);
    fclose(fin);
    return true;
}
 Impl (const char* in_name, EntityImpl& entity, const RenderManager::DynamicTextureCreator& creator)
   : name (in_name ? in_name : "")
   , dynamic_texture (0)
 {
   try
   {
     if (!in_name)
       throw xtl::make_null_argument_exception ("", "name");
       
     Entity entity_wrapper = Wrappers::Wrap<Entity> (&entity);
       
     dynamic_texture = creator (name.c_str (), entity_wrapper);
     
     if (!dynamic_texture)
       throw xtl::format_operation_exception ("", "Dynamic texture creator failed for texture '%s'", name.c_str ());
     
     try
     {
       texture = Wrappers::Unwrap<TextureImpl> (dynamic_texture->Texture ());
       
       if (!texture)
         throw xtl::format_operation_exception ("", "IDynamicTexture::Texture failed for texture '%s'", name.c_str ());
     }
     catch (...)
     {
       dynamic_texture->Release ();
       throw;
     }
   }
   catch (xtl::exception& e)
   {
     e.touch ("render::manager::DynamicTextureImpl::Impl::Impl");
     throw;
   }
 }
示例#4
0
bool DiskFile::Open(const stl::string &filename, int mode)
{
	ASSERT(IsOpen() == false);
	m_filename = filename;

	char fopenMode[3] = { '\0', '\0', '\0' };
	if (mode & FILEMODE_READ)
	{
		fopenMode[0] = 'r';
		m_canRead = true;
	}
	else if (mode & FILEMODE_WRITE)
	{
		fopenMode[0] = 'w';
		m_canWrite = true;
	}
	else if (mode & FILEMODE_APPEND)
	{
		fopenMode[0] = 'a';
		m_canWrite = true;
	}
	if (mode & FILEMODE_BINARY && fopenMode[0] != '\0')
		fopenMode[1] = 'b';

	if (fopenMode[0] == '\0')
	{
		ASSERT(!"Unrecognized mode.");
		return false;
	}
	else
	{
		ASSERT(m_canRead == true || m_canWrite == true);

		m_fp = fopen(filename.c_str(), fopenMode);
		if (m_fp)
		{
			LOG_INFO(LOGCAT_FILEIO, "Opened DiskFile \"%s\", mode = %s\n", filename.c_str(), fopenMode);
			m_mode = mode;
			return true;
		}
		else
		{
			LOG_WARN(LOGCAT_FILEIO, "Failed to open DiskFile \"%s\", mode = %s\n", filename.c_str(), fopenMode);
			return false;
		}
	}
}
示例#5
0
void RigidBodyImpl::ProcessCollisionWithMask (CollisionEventType event_type, RigidBody& this_body, RigidBody& second_body,
                                              const math::vec3f& collision_point, const stl::string& wanted_group_mask,
                                              const CollisionCallback& callback_handler)
{
  if (!common::wcmatch (second_body.CollisionGroup (), wanted_group_mask.c_str ()))
    return;

  callback_handler (event_type, this_body, second_body, collision_point);
}
示例#6
0
///Конструктор
  Impl (const DeviceManagerPtr& in_device_manager, TextureDimension in_dimension, PixelFormat in_format, render::low_level::PixelFormat in_target_format, const char* in_name)
    : device_manager (in_device_manager)
    , dimension (in_dimension)
    , format (in_format)
    , target_format (in_target_format)
    , width (0)
    , height (0)
    , depth (0)
  {
    if (!in_name)
      throw xtl::make_null_argument_exception ("render::manager::TextureImpl::Impl::Impl", "name");
      
    name = in_name;
    
    if (device_manager->Settings ().HasDebugLog ())
      Log ().Printf  ("Texture '%s' created (id=%u)", name.c_str (), Id ());
  }
示例#7
0
///Деструктор
  ~Impl ()
  {
    if (device_manager->Settings ().HasDebugLog ())
      Log ().Printf  ("Texture '%s' destroyed (id=%u)", name.c_str (), Id ());
  }
示例#8
0
istAPI bool FileToString( const stl::string &path, stl::string &out )
{
    return FileToString(path.c_str(), out);
}
/// Конструктор
  Impl (const ProgramParametersLayoutDesc& in_desc)
  {
    static const char* METHOD_NAME = "render::low_level::helpers::ProgramParametersLayout::Impl::Impl";

      //проверка корректности аргументов

    if (!in_desc.parameters)
      throw xtl::make_null_argument_exception (METHOD_NAME, "desc.parameters");
      
      /*
          Подготовка данных:
            1) проверка корректности аргументов;
            2) построение массива указателей на параметры для упорядочивания по номеру константного буфера, к которому они отностятся;
            3) подсчёт длины строки имён параметров.
      */
      
    typedef stl::vector<const ProgramParameter*> ParameterPtrArray;

    ParameterPtrArray src_parameters (in_desc.parameters_count);      
      
    size_t names_length = 0;    

    for (size_t i=0; i<in_desc.parameters_count; i++)
    {
      const ProgramParameter& param = in_desc.parameters [i];

      if (!param.count)
        throw xtl::format_exception<xtl::null_argument_exception> (METHOD_NAME, "Null argument desc.parameters[%u].count", i);

      if (!param.name)
        throw xtl::format_exception<xtl::null_argument_exception> (METHOD_NAME, "Null argument desc.parameters[%u].name", i);

      if (param.slot >= DEVICE_CONSTANT_BUFFER_SLOTS_COUNT)
        throw xtl::make_range_exception (METHOD_NAME, "desc.parameters.slot", (size_t)param.slot, (size_t)0, (size_t)DEVICE_CONSTANT_BUFFER_SLOTS_COUNT);

      if (param.type >= ProgramParameterType_Num)
        throw xtl::format_exception<xtl::bad_argument> (METHOD_NAME, "Invalid argument value desc.parameters[%u].type=%d", i,
          param.type);

      src_parameters [i]  = &param;
      names_length       += strlen (param.name) + 1;
    }

      //упорядочивание указателей на параметры по номеру константного буфера

    stl::sort (src_parameters.begin (), src_parameters.end (), ProgramParameterComparator ());
    
      //построение массива параметров и массива групп параметров
      
    ParameterArray new_parameters;
    GroupArray     new_groups;
    stl::string    new_names;

    new_parameters.reserve (in_desc.parameters_count);
    new_groups.reserve     (DEVICE_CONSTANT_BUFFER_SLOTS_COUNT);
    new_names.reserve      (names_length + 1);

    size_t current_slot = DEVICE_CONSTANT_BUFFER_SLOTS_COUNT + 1; //номер текущего слота (для отслеживания изменения группы параметров)
      
    for (ParameterPtrArray::iterator iter=src_parameters.begin (), end=src_parameters.end (); iter!=end; ++iter)
    {
        //добавление параметра
      
      const ProgramParameter& src_param = **iter;
      
      new_parameters.push_back (src_param);
      
        //добавление имени параметра и установка смещения имени параметра в буфере имён

      new_parameters.back ().name = reinterpret_cast<const char*> (new_names.size ());

      new_names += src_param.name;
      new_names += '\0';

        //отслеживание появления новой группы

      if (current_slot != src_param.slot)
      {
        new_groups.push_back ();

        ProgramParameterGroup& new_group = new_groups.back ();
        
        new_group.slot       = src_param.slot;
        new_group.parameters = &new_parameters.back ();
        new_group.count      = 0;
        current_slot         = src_param.slot;
      }
    }  

    if (!new_groups.empty ())  
    {
        //подсчёт количества параметров в группах

      for (GroupArray::iterator iter=new_groups.begin (), end=new_groups.end ()-1; iter!=end; ++iter)
        iter->count = (unsigned int)(iter [1].parameters - iter [0].parameters);

      new_groups.back ().count = (unsigned int)(new_parameters.end () - new_groups.back ().parameters);
    }

      //обмен
      
    parameters.swap (new_parameters);
    groups.swap     (new_groups);
    names.swap      (new_names);
    
      //установка имён

    for (ParameterArray::iterator iter=parameters.begin (), end=parameters.end (); iter!=end; ++iter)
      iter->name = names.c_str () + reinterpret_cast<size_t> (iter->name);
  }