Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static string RawUrl(DecentralandUrl decentralandUrl) =>
DecentralandUrl.MarketplaceClaimName => $"https://decentraland.{ENV}/marketplace/names/claim",
DecentralandUrl.WorldContentServer => $"https://worlds-content-server.decentraland.{ENV}/world",
DecentralandUrl.Servers => $"https://peer.decentraland.{ENV}/lambdas/contracts/servers",
DecentralandUrl.MediaConverter => $"https://media-opticonverter.decentraland.{ENV}/convert?ktx2=true&fileUrl={{0}}",
DecentralandUrl.MediaConverter => $"https://metamorph-api.decentraland.{ENV}/convert?url={{0}}",
DecentralandUrl.MarketplaceCredits => $"https://credits.decentraland.{ENV}",
DecentralandUrl.GoShoppingWithMarketplaceCredits => $"https://decentraland.{ENV}/marketplace/browse?sortBy=newest&status=on_sale&withCredits=true",
DecentralandUrl.EmailSubscriptions => $"https://notifications.decentraland.{ENV}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public struct GetNFTShapeIntention : ILoadingIntention, IEquatable<GetNFTShapeIn

public readonly string URN;

public bool DisableDiskCache => true;
public CommonLoadingArguments CommonArguments { get; set; }

public readonly CancellationTokenSource CancellationTokenSource => CommonArguments.CancellationTokenSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using CommunicationData.URLHelpers;
using Cysharp.Threading.Tasks;
using DCL.Diagnostics;
using DCL.FeatureFlags;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Optimization.Pools;
using DCL.WebRequests;
using DCL.WebRequests.WebContentSizes;
using ECS.Prioritization.Components;
using ECS.StreamableLoading.Cache;
using ECS.StreamableLoading.Cache.Disk;
Expand All @@ -15,45 +15,53 @@
using ECS.StreamableLoading.Textures;
using System;
using System.Threading;
using UnityEngine;

namespace ECS.StreamableLoading.NFTShapes
{
[UpdateInGroup(typeof(StreamableLoadingGroup))]
[LogCategory(ReportCategory.NFT_SHAPE_WEB_REQUEST)]
public partial class LoadNFTShapeSystem : LoadSystemBase<Texture2DData, GetNFTShapeIntention>
{
private const long MAX_PREVIEW_SIZE = 8388608;
Comment thread
pravusjif marked this conversation as resolved.

private readonly IWebRequestController webRequestController;
private readonly IWebContentSizes webContentSizes;
private readonly ExtendedObjectPool<Texture2D> videoTexturePool;
private readonly IDecentralandUrlsSource urlsSource;
private readonly bool ktxEnabled;

public LoadNFTShapeSystem(World world, IStreamableCache<Texture2DData, GetNFTShapeIntention> cache, IWebRequestController webRequestController, IDiskCache<Texture2DData> diskCache, IWebContentSizes webContentSizes,
bool ktxEnabled)
: base(
world, cache, new DiskCacheOptions<Texture2DData, GetNFTShapeIntention>(diskCache, GetNFTShapeIntention.DiskHashCompute.INSTANCE, "nft")
)
public LoadNFTShapeSystem(World world, IStreamableCache<Texture2DData, GetNFTShapeIntention> cache, IWebRequestController webRequestController, IDiskCache<Texture2DData> diskCache, bool ktxEnabled,
ExtendedObjectPool<Texture2D> videoTexturePool, IDecentralandUrlsSource urlsSource)
: base(world, cache, new DiskCacheOptions<Texture2DData, GetNFTShapeIntention>(diskCache, GetNFTShapeIntention.DiskHashCompute.INSTANCE, "nft"))
{
this.webRequestController = webRequestController;
this.webContentSizes = webContentSizes;
this.videoTexturePool = videoTexturePool;
this.urlsSource = urlsSource;
this.ktxEnabled = ktxEnabled;
}

protected override async UniTask<StreamableLoadingResult<Texture2DData>> FlowInternalAsync(GetNFTShapeIntention intention, StreamableLoadingState state, IPartitionComponent partition, CancellationToken ct)
{
string imageUrl = await ImageUrlAsync(intention.CommonArguments, ct);
string convertUrl = ktxEnabled ? string.Format(urlsSource.Url(DecentralandUrl.MediaConverter), Uri.EscapeDataString(imageUrl)) : imageUrl;
var contentInfo = await WebContentInfo.FetchAsync(convertUrl, ct);

if (!ktxEnabled)
{
bool isOkSize = await webContentSizes.IsOkSizeAsync(imageUrl, ct);
if (!ktxEnabled && contentInfo is { Type: WebContentInfo.ContentType.Image, SizeInBytes: > MAX_PREVIEW_SIZE })
return new StreamableLoadingResult<Texture2DData>(GetReportCategory(), new Exception("Image size is too big"));

if (isOkSize == false)
return new StreamableLoadingResult<Texture2DData>(GetReportCategory(), new Exception("Image size is too big"));
}
return contentInfo.Type switch
{
WebContentInfo.ContentType.Image or WebContentInfo.ContentType.KTX2 => await HandleImageAsync(imageUrl, ct),
WebContentInfo.ContentType.Video => HandleVideo(convertUrl),
_ => throw new NotSupportedException("Could not handle content type " + contentInfo.Type + " for url " + convertUrl)
};
}

// No need to check the size since we're using our converter so size will always be ok
// texture request
private async UniTask<StreamableLoadingResult<Texture2DData>> HandleImageAsync(string url, CancellationToken ct)
{
// Attempts should be always 1 as there is a repeat loop in `LoadSystemBase`
var result = await webRequestController.GetTextureAsync(
new CommonLoadingArguments(URLAddress.FromString(imageUrl), attempts: 1),
new CommonLoadingArguments(URLAddress.FromString(url), attempts: 1),
new GetTextureArguments(TextureType.Albedo, true),
new GetTextureWebRequest.CreateTextureOp(GetNFTShapeIntention.WRAP_MODE, GetNFTShapeIntention.FILTER_MODE),
ct,
Expand All @@ -63,12 +71,18 @@ protected override async UniTask<StreamableLoadingResult<Texture2DData>> FlowInt
if (result == null)
return new StreamableLoadingResult<Texture2DData>(
GetReportData(),
new Exception($"Error loading texture from url {intention.CommonArguments.URL}")
new Exception($"Error loading texture from url {url}")
);

return new StreamableLoadingResult<Texture2DData>(new Texture2DData(result));
}

private StreamableLoadingResult<Texture2DData> HandleVideo(string url)
{
var texture2D = videoTexturePool.Get();
return new StreamableLoadingResult<Texture2DData>(new Texture2DData(texture2D, url));
}

private async UniTask<string> ImageUrlAsync(CommonArguments commonArguments, CancellationToken ct)
{
GenericDownloadHandlerUtils.Adapter<GenericGetRequest, GenericGetArguments> infoRequest = webRequestController.GetAsync(commonArguments, ct, GetReportData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace ECS.StreamableLoading.Textures
{
public struct GetTextureIntention : ILoadingIntention, IEquatable<GetTextureIntention>
{
public bool DisableDiskCache => true;
public CommonLoadingArguments CommonArguments { get; set; }

public readonly TextureWrapMode WrapMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ECS.StreamableLoading.Textures
public class Texture2DData : StreamableRefCountData<Texture2D>, ISizedContent
{
private readonly IOwnedTexture2D? ownedTexture2D;
public string? VideoURL { get; set; }

public long ByteSize => Asset.GetRawTextureData<byte>().Length;

Expand All @@ -21,11 +22,18 @@ public class Texture2DData : StreamableRefCountData<Texture2D>, ISizedContent
protected override void DestroyObject()
{
ownedTexture2D?.Dispose();
UnityObjectUtils.SafeDestroy(Asset);

if (VideoURL == null)
UnityObjectUtils.SafeDestroy(Asset);
}

public Texture2DData(Texture2D texture) : base(texture, ReportCategory.TEXTURES) { }

public Texture2DData(Texture2D texture, string videoUrl) : base(texture, ReportCategory.TEXTURES)
{
VideoURL = videoUrl;
}

public Texture2DData(IOwnedTexture2D asset) : base(asset.Texture, ReportCategory.TEXTURES)
{
ownedTexture2D = asset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace ECS.StreamableLoading.Textures
{
public class TextureDiskSerializer : IDiskSerializer<Texture2DData, SerializeMemoryIterator<TextureDiskSerializer.State>>
{
public SerializeMemoryIterator<State> Serialize(Texture2DData data) =>
ToArray(data);

public async UniTask<Texture2DData> DeserializeAsync(SlicedOwnedMemory<byte> data, CancellationToken token)
{
var meta = Meta.FromSpan(data.Memory.Span);
Expand All @@ -32,7 +29,7 @@ public async UniTask<Texture2DData> DeserializeAsync(SlicedOwnedMemory<byte> dat
return new Texture2DData(texture);
}

private static SerializeMemoryIterator<State> ToArray(Texture2DData data)
public SerializeMemoryIterator<State> Serialize(Texture2DData data)
{
var textureData = data.Asset.GetRawTextureData<byte>()!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public VideoTextureConsumer(Texture2D texture)
renderers = new List<MeshRenderer>();
}

public VideoTextureConsumer(Texture2DData t2dd)
{
Texture = t2dd;
renderers = new List<MeshRenderer>();
}

public void Dispose()
{
// On Dispose video textures are dereferenced by material that acquired it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ await UniTask.WhenAll(
{
new TransformsPlugin(sharedDependencies, exposedPlayerTransform, exposedGlobalDataContainer.ExposedCameraData),
new BillboardPlugin(exposedGlobalDataContainer.ExposedCameraData),
new NFTShapePlugin(decentralandUrlsSource, container.assetsProvisioner, sharedDependencies.FrameTimeBudget, componentsContainer.ComponentPoolsRegistry, container.WebRequestsContainer.WebRequestController, container.CacheCleaner, textureDiskCache, container.FeatureFlagsCache),
new NFTShapePlugin(decentralandUrlsSource, container.assetsProvisioner, sharedDependencies.FrameTimeBudget, componentsContainer.ComponentPoolsRegistry, container.WebRequestsContainer.WebRequestController, container.CacheCleaner, textureDiskCache, container.FeatureFlagsCache, videoTexturePool),
new TextShapePlugin(sharedDependencies.FrameTimeBudget, container.CacheCleaner, componentsContainer.ComponentPoolsRegistry),
new MaterialsPlugin(sharedDependencies, videoTexturePool),
textureResolvePlugin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DCL.SDKComponents.NFTShape.Frames.Pool;
using DCL.WebRequests.WebContentSizes.Sizes;
using System;
using UnityEngine;

Expand All @@ -11,8 +10,5 @@ public class NFTShapePluginSettings : IDCLPluginSettings
[field: Header("Nft Shape")] [field: Space]
[field: SerializeField]
public NFTShapeSettings Settings { get; private set; }

[field: SerializeField]
public MaxSize MaxSizeOfNftForDownload { get; private set; }
}
}
41 changes: 14 additions & 27 deletions Explorer/Assets/DCL/PluginSystem/World/NFTShapePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
using DCL.SDKComponents.NFTShape.Renderer.Factory;
using DCL.SDKComponents.NFTShape.System;
using DCL.WebRequests;
using DCL.WebRequests.WebContentSizes;
using DCL.WebRequests.WebContentSizes.Sizes.Lazy;
using ECS.Abstract;
using ECS.LifeCycle;
using ECS.LifeCycle.Systems;
Expand All @@ -28,6 +26,7 @@
using ECS.StreamableLoading.Textures;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

namespace DCL.PluginSystem.World
{
Expand All @@ -39,10 +38,9 @@ public class NFTShapePlugin : IDCLWorldPlugin<NFTShapePluginSettings>
private readonly IComponentPoolsRegistry componentPoolsRegistry;
private readonly IWebRequestController webRequestController;
private readonly IFramePrefabs framePrefabs;
private readonly IWebContentSizes webContentSizes;
private readonly ILazyMaxSize lazyMaxSize;
private readonly IDiskCache<Texture2DData> diskCache;
private readonly FeatureFlagsCache featureFlags;
private readonly ExtendedObjectPool<Texture2D> videoTexturePool;
private readonly ISizedStreamableCache<Texture2DData, GetNFTShapeIntention> cache = new NftShapeCache();

static NFTShapePlugin()
Expand All @@ -58,7 +56,8 @@ public NFTShapePlugin(
IWebRequestController webRequestController,
CacheCleaner cacheCleaner,
IDiskCache<Texture2DData> diskCache,
FeatureFlagsCache featureFlags
FeatureFlagsCache featureFlags,
ExtendedObjectPool<Texture2D> videoTexturePool
) : this(
decentralandUrlsSource,
instantiationFrameTimeBudgetProvider,
Expand All @@ -67,10 +66,9 @@ FeatureFlagsCache featureFlags
framePrefabs,
webRequestController,
cacheCleaner,
new IWebContentSizes.Default(LazyMaxSize(out var lazyMaxSize)),
lazyMaxSize,
diskCache,
featureFlags
featureFlags,
videoTexturePool
) { }

public NFTShapePlugin(
Expand All @@ -81,10 +79,9 @@ public NFTShapePlugin(
IFramePrefabs framePrefabs,
IWebRequestController webRequestController,
CacheCleaner cacheCleaner,
IWebContentSizes webContentSizes,
ILazyMaxSize lazyMaxSize,
IDiskCache<Texture2DData> diskCache,
FeatureFlagsCache featureFlags
FeatureFlagsCache featureFlags,
ExtendedObjectPool<Texture2D> videoTexturePool
) : this(
decentralandUrlsSource,
new PoolNFTShapeRendererFactory(componentPoolsRegistry, framesPool),
Expand All @@ -93,10 +90,9 @@ FeatureFlagsCache featureFlags
webRequestController,
cacheCleaner,
framePrefabs,
webContentSizes,
lazyMaxSize,
diskCache,
featureFlags
featureFlags,
videoTexturePool
) { }

public NFTShapePlugin(
Expand All @@ -107,10 +103,9 @@ public NFTShapePlugin(
IWebRequestController webRequestController,
CacheCleaner cacheCleaner,
IFramePrefabs framePrefabs,
IWebContentSizes webContentSizes,
ILazyMaxSize lazyMaxSize,
IDiskCache<Texture2DData> diskCache,
FeatureFlagsCache featureFlags
FeatureFlagsCache featureFlags,
ExtendedObjectPool<Texture2D> videoTexturePool
)
{
this.decentralandUrlsSource = decentralandUrlsSource;
Expand All @@ -119,10 +114,9 @@ FeatureFlagsCache featureFlags
this.componentPoolsRegistry = componentPoolsRegistry;
this.webRequestController = webRequestController;
this.framePrefabs = framePrefabs;
this.webContentSizes = webContentSizes;
this.lazyMaxSize = lazyMaxSize;
this.diskCache = diskCache;
this.featureFlags = featureFlags;
this.videoTexturePool = videoTexturePool;
cacheCleaner.Register(cache);
}

Expand All @@ -133,8 +127,6 @@ public void Dispose()

public UniTask InitializeAsync(NFTShapePluginSettings settings, CancellationToken ct)
{
lazyMaxSize.Initialize(settings.MaxSizeOfNftForDownload);

return framePrefabs.InitializeAsync(
settings.Settings.FramePrefabs(),
settings.Settings.DefaultFrame(),
Expand All @@ -148,7 +140,7 @@ public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder,

bool isKtxEnabled = featureFlags.Configuration.IsEnabled(FeatureFlagsStrings.KTX2_CONVERSION);

LoadNFTShapeSystem.InjectToWorld(ref builder, cache, webRequestController, diskCache, webContentSizes, isKtxEnabled);
LoadNFTShapeSystem.InjectToWorld(ref builder, cache, webRequestController, diskCache, isKtxEnabled, videoTexturePool, decentralandUrlsSource);
LoadCycleNftShapeSystem.InjectToWorld(ref builder, new BasedURNSource(decentralandUrlsSource));
InstantiateNftShapeSystem.InjectToWorld(ref builder, nftShapeRendererFactory, instantiationFrameTimeBudgetProvider, framePrefabs, buffer);
VisibilityNftShapeSystem.InjectToWorld(ref builder, buffer);
Expand All @@ -163,10 +155,5 @@ private static IFramePrefabs NewFramePrefabs(IAssetsProvisioner assetsProvisione
{
return framePrefabs = new AssetProvisionerFramePrefabs(assetsProvisioner);
}

private static ILazyMaxSize LazyMaxSize(out ILazyMaxSize lazyMaxSize)
{
return lazyMaxSize = new LazyMaxSize();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using DCL.Browser.DecentralandUrls;
using DCL.DemoWorlds;
using DCL.ECSComponents;
using DCL.FeatureFlags;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Optimization.PerformanceBudgeting;
using DCL.Optimization.Pools;
Expand All @@ -11,10 +10,9 @@
using DCL.SDKComponents.NFTShape.Frames.Pool;
using DCL.SDKComponents.NFTShape.Renderer.Factory;
using DCL.SDKComponents.NFTShape.System;
using DCL.SDKComponents.VideoPlayer;
using DCL.Utilities.Extensions;
using DCL.WebRequests;
using DCL.WebRequests.WebContentSizes;
using DCL.WebRequests.WebContentSizes.Sizes;
using ECS.Abstract;
using ECS.Prioritization.Components;
using ECS.StreamableLoading.Cache.Disk;
Expand Down Expand Up @@ -63,13 +61,9 @@ public NFTShapeDemoWorld(World world, IFramesPool framesPool,
new NftShapeCache(),
IWebRequestController.DEFAULT,
IDiskCache<Texture2DData>.Null.INSTANCE,
new IWebContentSizes.Default(
new MaxSize
{
maxSizeInBytes = 300 * 1024 * 1024,
}
),
true
true,
VideoTextureFactory.CreateVideoTexturesPool(),
new DecentralandUrlsSource(DecentralandEnvironment.Zone, ILaunchMode.PLAY)
).InitializeAndReturnSelf(),
w => new LoadCycleNftShapeSystem(w, new BasedURNSource(new DecentralandUrlsSource(DecentralandEnvironment.Org, ILaunchMode.PLAY))),
w => new InstantiateNftShapeSystem(w, new PoolNFTShapeRendererFactory(new ComponentPoolsRegistry(), framesPool), new FrameTimeCapBudget.Default(), framePrefabs, buffer),
Expand Down
Loading