(
url: string,
imageName: string,
bitmapCache: FrustumBitmapCache,
deps: LoadFrustumBitmapDeps = {}
)
| 52 | } |
| 53 | |
| 54 | export async function getOrLoadFrustumBitmap( |
| 55 | url: string, |
| 56 | imageName: string, |
| 57 | bitmapCache: FrustumBitmapCache, |
| 58 | deps: LoadFrustumBitmapDeps = {} |
| 59 | ): Promise<ImageBitmap | null> { |
| 60 | const cached = getCachedFrustumBitmap(bitmapCache, imageName, deps.now); |
| 61 | if (cached) return cached; |
| 62 | |
| 63 | try { |
| 64 | const fetchBlob = deps.fetchBlob ?? ((input: string) => fetch(input)); |
| 65 | const createBitmap = deps.createBitmap ?? createImageBitmap; |
| 66 | const response = await fetchBlob(url); |
| 67 | const blob = await response.blob(); |
| 68 | const bitmap = await createBitmap(blob); |
| 69 | |
| 70 | bitmapCache.set(imageName, { bitmap, lastUsed: (deps.now ?? Date.now)() }); |
| 71 | return bitmap; |
| 72 | } catch { |
| 73 | return null; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | export function getActiveFrustumTexture( |
| 78 | activeTextures: FrustumTextureCache, |
no test coverage detected