EntropyEngine::Networking::BatchManager
EntropyEngine::Networking::BatchManager
Section titled “EntropyEngine::Networking::BatchManager”Batches high-frequency property updates for efficient network transmission. More…
#include <BatchManager.h>
Public Classes
Section titled “Public Classes”| Name | |
|---|---|
| struct | Stats Get statistics. |
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~BatchManager() | |
| void | updateProperty(PropertyHash hash, PropertyType type, const PropertyValue & value) Update a property value (will be batched). |
| void | setOnBatchDropped(std::function< void(size_t)> callback) Set callback for dropped batches (backpressure monitoring). |
| void | setBatchInterval(uint32_t intervalMs) Set the batch interval. |
| void | processBatch() Process pending updates and send a batch. |
| Stats | getStats() const |
| size_t | getPendingCount() const Get number of pending updates waiting to be batched. |
| uint32_t | getBatchInterval() const Get current batch interval. |
| void | flush() Force an immediate flush of pending updates. |
| BatchManager(SessionHandle session, uint32_t batchIntervalMs =16) Construct a batch manager for a network session. |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Networking::BatchManager;Batches high-frequency property updates for efficient network transmission.
Design:
- Global batch rate (configurable, default 16ms for 60Hz)
- Accumulates property updates in a map (automatic deduplication)
- Uses WorkContract for scheduling batch processing
- Sends batches on unreliable channel
- Dynamic rate adjustment on backpressure (drop old batches, reduce rate)
- Property hashes are provided by caller (never computed internally)
Usage:
ConnectionManager connMgr(1024);SessionManager sessMgr(&connMgr, 512);auto session = sessMgr.createSession(connection);
auto batcher = std::make_shared<BatchManager>(session);
// Caller computes hash from entity metadataauto hash = computePropertyHash(entityId, componentType, "transform.position");batcher->updateProperty(hash, PropertyType::Vec3, position);
// Application schedules periodic batch processing// Example using std::thread and timer:std::atomic<bool> running{true};std::thread batchThread([&]() { while (running) { batcher->processBatch(); std::this_thread::sleep_for(std::chrono::milliseconds(batcher->getBatchInterval())); }});
// Optional: Set callback for dropped batches (backpressure monitoring)batcher->setOnBatchDropped([](size_t droppedCount) { LOG_WARNING("Dropped batch with " + std::to_string(droppedCount) + " updates due to backpressure");});Public Functions Documentation
Section titled “Public Functions Documentation”function ~BatchManager
Section titled “function ~BatchManager”~BatchManager()function updateProperty
Section titled “function updateProperty”void updateProperty( PropertyHash hash, PropertyType type, const PropertyValue & value)Update a property value (will be batched).
Parameters:
- hash Property hash (computed by caller)
- type Property type
- value Property value
Accumulates the update. If the same property is updated multiple times before the next batch, only the latest value is kept.
function setOnBatchDropped
Section titled “function setOnBatchDropped”void setOnBatchDropped( std::function< void(size_t)> callback)Set callback for dropped batches (backpressure monitoring).
Parameters:
- callback Function called when a batch is dropped, receives the number of updates that were dropped
function setBatchInterval
Section titled “function setBatchInterval”void setBatchInterval( uint32_t intervalMs)Set the batch interval.
Parameters:
- intervalMs New interval in milliseconds
function processBatch
Section titled “function processBatch”void processBatch()Process pending updates and send a batch.
This should be called periodically by the application (e.g., via work contracts). The application is responsible for scheduling this at the desired batch interval.
function getStats
Section titled “function getStats”Stats getStats() constfunction getPendingCount
Section titled “function getPendingCount”size_t getPendingCount() constGet number of pending updates waiting to be batched.
function getBatchInterval
Section titled “function getBatchInterval”inline uint32_t getBatchInterval() constGet current batch interval.
function flush
Section titled “function flush”void flush()Force an immediate flush of pending updates.
Alias for processBatch(). Useful for critical updates that can’t wait.
function BatchManager
Section titled “function BatchManager”explicit BatchManager( SessionHandle session, uint32_t batchIntervalMs =16)Construct a batch manager for a network session.
Parameters:
- session The session handle to send batches through
- batchIntervalMs Batch interval in milliseconds (default 16ms = 60Hz)
Note: The application is responsible for calling processBatch() periodically, typically by scheduling work contracts in a loop.
Updated on 2026-01-26 at 16:50:32 -0500