Browse Source

give named target a fallback

we need to give named target a fallback image so references are kept when a named target is not ready.
marauder2k7 10 months ago
parent
commit
bab7878ca6

+ 20 - 3
Engine/source/T3D/assets/ImageAsset.cpp

@@ -53,6 +53,7 @@
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
 StringTableEntry ImageAsset::smNoImageAssetFallback = NULL;
 StringTableEntry ImageAsset::smNoImageAssetFallback = NULL;
+StringTableEntry ImageAsset::smNamedTargetAssetFallback = NULL;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
@@ -139,7 +140,6 @@ ConsoleSetType(TypeImageAssetPtrRefactor)
       // Is the asset pointer the correct type?
       // Is the asset pointer the correct type?
       if (pAssetPtr == NULL)
       if (pAssetPtr == NULL)
       {
       {
-         // No, so fail.
          Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
          Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
          return;
          return;
       }
       }
@@ -207,7 +207,12 @@ void ImageAsset::consoleInit()
       "The assetId of the texture to display when the requested image asset is missing.\n"
       "The assetId of the texture to display when the requested image asset is missing.\n"
       "@ingroup GFX\n");
       "@ingroup GFX\n");
 
 
+   Con::addVariable("$Core::NamedTargetFallback", TypeString, &smNamedTargetAssetFallback,
+      "The assetId of the texture to display when the requested image asset is named target.\n"
+      "@ingroup GFX\n");
+
    smNoImageAssetFallback = StringTable->insert(Con::getVariable("$Core::NoImageAssetFallback"));
    smNoImageAssetFallback = StringTable->insert(Con::getVariable("$Core::NoImageAssetFallback"));
+   smNamedTargetAssetFallback = StringTable->insert(Con::getVariable("$Core::NamedTargetFallback"));
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -447,7 +452,19 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
    load();
    load();
 
 
    if (isNamedTarget())
    if (isNamedTarget())
-      return getNamedTarget()->getTexture();
+   {
+      GFXTexHandle tex = getNamedTarget()->getTexture();
+      if(tex.isNull())
+      {
+         AssetPtr<ImageAsset> fallbackAsset;
+         ImageAsset::getAssetById(smNamedTargetAssetFallback, &fallbackAsset);
+         return fallbackAsset->getTexture();
+      }
+      else
+      {
+         return tex;
+      }
+   }
 
 
    if (mLoadedState == Ok)
    if (mLoadedState == Ok)
    {
    {
@@ -460,7 +477,7 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
 
 
          //If we don't have an existing map case to the requested format, we'll just create it and insert it in
          //If we don't have an existing map case to the requested format, we'll just create it and insert it in
          GFXTexHandle newTex;
          GFXTexHandle newTex;
-         newTex.set(mImageFile, requestedProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
+         newTex.set(mImageFile, requestedProfile, avar("%s %s() - mTextureObject (line %d)", mImageFile, __FUNCTION__, __LINE__));
          if (newTex)
          if (newTex)
          {
          {
             mLoadedState = AssetErrCode::Ok;
             mLoadedState = AssetErrCode::Ok;

+ 1 - 0
Engine/source/T3D/assets/ImageAsset.h

@@ -113,6 +113,7 @@ public:
    };
    };
 
 
    static StringTableEntry smNoImageAssetFallback;
    static StringTableEntry smNoImageAssetFallback;
+   static StringTableEntry smNamedTargetAssetFallback;
 
 
    enum ImageAssetErrCode
    enum ImageAssetErrCode
    {
    {

+ 1 - 0
Templates/BaseGame/game/core/rendering/Core_Rendering.tscript

@@ -9,6 +9,7 @@ function Core_Rendering::onCreate(%this)
    $Core::WetnessTexture = "core/rendering/images/wetMap.png";
    $Core::WetnessTexture = "core/rendering/images/wetMap.png";
    
    
    $Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image";
    $Core::NoImageAssetFallback = "Core_Rendering:missingTexture_image";
+   $Core::NamedTargetFallback = "Core_Rendering:namedTarget_image";
    $Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial";
    $Core::NoMaterialAssetFallback = "Core_Rendering:noMaterial";
    $Core::NoShapeAssetFallback = "Core_Rendering:noShape";
    $Core::NoShapeAssetFallback = "Core_Rendering:noShape";
    
    

BIN
Templates/BaseGame/game/core/rendering/images/namedTarget.png


+ 3 - 0
Templates/BaseGame/game/core/rendering/images/namedTarget_image.asset.taml

@@ -0,0 +1,3 @@
+<ImageAsset
+    AssetName="namedTarget_image"
+    imageFile="@assetFile=namedTarget.png"/>