コード例 #1
0
bool res_file_t::get_resource(uint32 type, int id, LoadedResource &rsrc) const
{
  rsrc.Unload();

  // Find resource in map
  type_map_t::const_iterator i = types.find(type);
  if (i != types.end()) {
    id_map_t::const_iterator j = i->second.find(id);
    if (j != i->second.end()) {
      // Found, read data size
      SDL_RWseek(f, j->second, SEEK_SET);
      uint32 size = SDL_ReadBE32(f);

      // Allocate memory and read data
      void *p = malloc(size);
      if (p == NULL) {
        return false;
      }
      SDL_RWread(f, p, 1, size);
#ifdef mac
      rsrc.SetData(p, size);
#else
      rsrc.p = p;
      rsrc.size = size;
#endif

//			fprintf(stderr, "get_resource type %c%c%c%c, id %d -> data %p, size %d\n", type >> 24, type >> 16, type >> 8, type, id, p, size);
      return true;
    }
  }
  return false;
}
コード例 #2
0
bool res_file_t::get_ind_resource(uint32 type, int index,
                                  LoadedResource &rsrc) const
{
  rsrc.Unload();

  // Find resource in map
  type_map_t::const_iterator i = types.find(type);
  if (i != types.end()) {
    if (index < 1 || index > int(i->second.size())) {
      return false;
    }
    id_map_t::const_iterator j = i->second.begin();
    for (int k=1; k<index; k++)
      ++j;

    // Read data size
    SDL_RWseek(f, j->second, SEEK_SET);
    uint32 size = SDL_ReadBE32(f);

    // Allocate memory and read data
    void *p = malloc(size);
    if (p == NULL) {
      return false;
    }
    SDL_RWread(f, p, 1, size);
#ifdef mac
    rsrc.SetData(p, size);
#else
    rsrc.p = p;
    rsrc.size = size;
#endif

//		fprintf(stderr, "get_ind_resource type %c%c%c%c, index %d -> data %p, size %d\n", type >> 24, type >> 16, type >> 8, type, index, p, size);
    return true;
  }
  return false;
}