void ResourceManager::LoadImageResource(ImageResource* imgres)
{
    // loading should not already be in progress (also prohibit state: loaded + metadata loading)
    if (imgres->loadState != RLS_RETRIEVING && imgres->loadState != RLS_LOADING_FROM_FILE && !(imgres->loadState == RLS_LOADED && imgres->metaLoadState == RLS_RETRIEVING))
    {
        ImageDatabaseRecord* rec = !imgres->isInternal ? sImageStorage->GetImageRecord(imgres->id) : sInternalImageStorage->GetImageRecord(imgres->id);
        // we know about this resource
        if (rec)
        {
            imgres->loadState = RLS_LOADING_FROM_FILE;
            SDL_Surface* imgsurface = IMG_Load((std::string(DATA_DIR) + rec->filename).c_str());
            if (imgsurface)
            {
                if (imgres->renderedTexture)
                {
                    // TODO: this should be atomic; please, after reworking loading procedure
                    // to threaed stuff, remember to put lock here, thanks
                    SDL_DestroyTexture(imgres->renderedTexture);
                    imgres->renderedTexture = nullptr;
                }
                imgres->renderedTexture = SDL_CreateTextureFromSurface(sDrawing->GetRenderer(), imgsurface);
                imgres->loadState = RLS_LOADED;

                SDL_FreeSurface(imgsurface);

                CacheAnimSpriteRectagles(imgres);

                // signal drawing class to redraw all visible stuff
                sDrawing->SetCanvasRedrawFlag();
            }
            else
            {
                sLog->Error("Could not load image (ID: %u) from file %s", imgres->id, rec->filename.c_str());
            }

            // i know i would read this later, so.. my idea is to draw the old resource,
            // send checksum verify packet and if the checksum does not match, request the
            // resource once again, drop old texture, load new texture and redraw

            // internal resources are pure client-side - i.e. UI textures, etc.

            if (!imgres->isInternal)
                sResourceStreamManager->SendVerifyChecksumPacket(RSTYPE_IMAGE, imgres->id, rec->checksumStr.c_str());
        }
        else
        {
            // this will send request packet and set state to "retrieving"
            // the rest is handled by NetworkHandlers and ResourceStreamManager
            if (!imgres->isInternal)
                RequestResource(RSTYPE_IMAGE, imgres->id);
        }
    }
}
Exemplo n.º 2
0
static Error rsGetSysResource( Object *obj, const char *resname )
{
   Error err;
   int tries;
   os_duration delay = 250*OS_DURATION_MILLISECOND;

   for ( tries = 0; tries < DDS_MAX_TRIES_TO_LOCATE_RESOURCESTORE; tries++ )
   {
      err = RequestResource(obj,
                            resname,
                            DDS_RES_PASSWD);
      if ( err != ResourceNotAvailable )
      {
         break;
      }
      else
      {
         ospl_os_sleep(delay);
      }
   }
   return( err );
}
Exemplo n.º 3
0
/******************** RequestResources *************************/
TArray<UResource*> UStorageMap::RequestResources(APOTLStructure* Requester, TArray<FString> ResourceIds)
{
	TArray<UResource*> RequestedResources;
	if (Requester)
	{
		// Check if total request can be met
		if (HasResourceAvailable(ResourceIds))
		{
			// Get resoruces
			for (auto& ResourceId : ResourceIds)
			{
				UResource* Resource = RequestResource(Requester, ResourceId);
				if (Resource)
				{
					RequestedResources.Add(Resource);
				}
			}
		}
	}

	return RequestedResources;
}