@web-engine-dev/streaming
World and level streaming with chunk loading for large game worlds.
Features
- Chunk Streaming: Load/unload world chunks
- LOD Streaming: Level-of-detail asset streaming
- Background Loading: Async chunk loading
- Memory Budget: Automatic unloading
- Priority Queue: Distance-based loading priority
Installation
bash
npm install @web-engine-dev/streaming
# or
pnpm add @web-engine-dev/streamingQuick Start
typescript
import { WorldStreamer, ChunkManager } from '@web-engine-dev/streaming';
// Create streamer
const streamer = new WorldStreamer({
chunkSize: 256,
loadRadius: 3, // Chunks around player
unloadRadius: 5, // Chunks to keep loaded
});
// Update based on player position
streamer.update(playerPosition);
// Process loading queue
await streamer.processQueue();API Overview
World Streamer
typescript
const streamer = new WorldStreamer({
chunkSize: 256, // World units per chunk
loadRadius: 3, // Chunks to load ahead
unloadRadius: 5, // When to unload
maxConcurrentLoads: 2, // Parallel chunk loads
memoryBudget: 512, // MB
});
// Set focus point (player position)
streamer.setFocus(position);
// Update loading/unloading
streamer.update();
// Get loaded chunks
const chunks = streamer.getLoadedChunks();Chunk Manager
typescript
const chunks = new ChunkManager({
chunkSize: 256,
loader: async (x, z) => {
return loadChunkData(x, z);
},
unloader: (chunk) => {
chunk.dispose();
},
});
// Query chunk at position
const chunk = chunks.getChunkAt(worldX, worldZ);
// Manual load/unload
await chunks.loadChunk(chunkX, chunkZ);
chunks.unloadChunk(chunkX, chunkZ);LOD Streaming
typescript
const lod = new LODStreamer({
levels: [
{ distance: 0, quality: 'high' },
{ distance: 100, quality: 'medium' },
{ distance: 500, quality: 'low' },
],
});
// Update LOD based on camera
lod.update(cameraPosition);Memory Management
typescript
const streamer = new WorldStreamer({
memoryBudget: 512, // MB
onMemoryPressure: () => {
// Unload non-essential assets
},
});
// Check memory usage
const usage = streamer.getMemoryUsage();
console.log(`${usage.used}/${usage.budget} MB`);