public void HandleResponse( WorkQueue.Response res, WorkQueue srcq )
{
// Main thread
var ddres = (DerivedDataResponse)res.Data;
var ddreq = (DerivedDataRequest)res.Request.Data;
// only deal with own requests
if ( ddreq.Terrain != this )
{
return;
}
if ( ( ( ddreq.TypeMask & DERIVED_DATA_DELTAS ) == ddreq.TypeMask ) &&
( ( ddres.RemainingTypeMask & DERIVED_DATA_DELTAS ) != DERIVED_DATA_DELTAS ) )
{
FinalizeHeightDeltas( ddres.DeltaUpdateRect, false );
}
if ( ( ( ddreq.TypeMask & DERIVED_DATA_NORMALS ) == ddreq.TypeMask ) &&
( ( ddres.RemainingTypeMask & DERIVED_DATA_NORMALS ) != DERIVED_DATA_NORMALS ) )
{
FinalizeNormals( ddres.NormalUpdateRect, ddres.NormalMapBox );
this.mCompositeMapDirtyRect.Merge( ddreq.DirtyRect );
}
if ( ( ( ddreq.TypeMask & DERIVED_DATA_LIGHTMAP ) == ddreq.TypeMask ) &&
( ( ddres.RemainingTypeMask & DERIVED_DATA_LIGHTMAP ) != DERIVED_DATA_LIGHTMAP ) )
{
FinalizeLightMap( ddres.LightMapUpdateRect, ddres.LightMapPixelBox );
this.mCompositeMapDirtyRect.Merge( ddreq.DirtyRect );
this.mCompositeMapDirtyRectLightmapUpdate = true;
}
IsDerivedDataUpdateInProgress = false;
// Re-trigger another request if there are still things to do, or if
// we had a new request since this one
var newRect = new Rectangle( 0, 0, 0, 0 );
if ( ddres.RemainingTypeMask != 0 )
{
newRect.Merge( ddreq.DirtyRect );
}
if ( this.mDerivedUpdatePendingMask != 0 )
{
newRect.Merge( this.mDirtyDerivedDataRect );
this.mDirtyDerivedDataRect.IsNull = true;
}
var newLightmapExtraRext = new Rectangle( 0, 0, 0, 0 );
if ( ddres.RemainingTypeMask != 0 )
{
newLightmapExtraRext.Merge( ddreq.LightmapExtraDirtyRect );
}
if ( this.mDerivedUpdatePendingMask != 0 )
{
newLightmapExtraRext.Merge( this.mDirtyLightmapFromNeighboursRect );
this.mDirtyLightmapFromNeighboursRect.IsNull = true;
}
var newMask = (byte)( ddres.RemainingTypeMask | this.mDerivedUpdatePendingMask );
if ( newMask != 0 )
{
// trigger again
UpdateDerivedDataImpl( newRect, newLightmapExtraRext, false, newMask );
}
else
{
// we've finished all the background processes
// update the composite map if enabled
if ( this.mCompositeMapRequired )
{
UpdateCompositeMap();
}
}
}