import { platform } from '../../Environment' ; import { RenderBatch , ArrayRange , ArrayRangeReader , ArrayBuilderSegment , RenderTreeDiff , RenderTreeEdit , RenderTreeFrame , ArrayValues , EditType , FrameType , RenderTreeFrameReader } from './RenderBatch' ; import { Pointer , System_Array , System_Object } from '../../Platform/Platform' ; export class SharedMemoryRenderBatch implements RenderBatch { constructor ( private batchAddress ) { } updatedComponents ( ) { return platform . readStructField < Pointer > ( this . batchAddress , 0 ) as any as ArrayRange < RenderTreeDiff > ; } referenceFrames ( ) { return platform . readStructField < Pointer > ( this . batchAddress , arrayRangeReader . structLength ) as any as ArrayRange < RenderTreeDiff > ; } disposedComponentIds ( ) { return platform . readStructField < Pointer > ( this . batchAddress , arrayRangeReader . structLength * 2 ) as any as ArrayRange < number > ; } disposedEventHandlerIds ( ) { return platform . readStructField < Pointer > ( this . batchAddress , arrayRangeReader . structLength * 3 ) as any as ArrayRange < number > ; } updatedComponentsEntry ( values , index ) { return arrayValuesEntry ( values , index , diffReader . structLength ) ; } referenceFramesEntry ( values , index ) { return arrayValuesEntry ( values , index , frameReader . structLength ) ; } disposedComponentIdsEntry ( values , index ) { const pointer = arrayValuesEntry ( values , index , 4 ) ; return platform . readInt32Field ( pointer as any as Pointer ) ; } disposedEventHandlerIdsEntry ( values , index ) { const pointer = arrayValuesEntry ( values , index , 8 ) ; return platform . readUint64Field ( pointer as any as Pointer ) ; } arrayRangeReader = arrayRangeReader ; arrayBuilderSegmentReader = arrayBuilderSegmentReader ; diffReader = diffReader ; editReader = editReader ; frameReader = frameReader ; } const arrayRangeReader = { structLength : 8 , values : < T > ( arrayRange ) => platform . readObjectField < System_Array < T > > ( arrayRange as any , 0 ) as any as ArrayValues < T > , count : < T > ( arrayRange ) => platform . readInt32Field ( arrayRange as any , 4 ) , } ; const arrayBuilderSegmentReader = { structLength : 12 , values : < T > ( arrayBuilderSegment ) => { const builder = platform . readObjectField < System_Object > ( arrayBuilderSegment as any , 0 ) ; const builderFieldsAddress = platform . getObjectFieldsBaseAddress ( builder ) ; return platform . readObjectField < System_Array < T > > ( builderFieldsAddress , 0 ) as any as ArrayValues < T > ; } , offset : < T > ( arrayBuilderSegment ) => platform . readInt32Field ( arrayBuilderSegment as any , 4 ) , count : < T > ( arrayBuilderSegment ) => platform . readInt32Field ( arrayBuilderSegment as any , 8 ) , } ; const diffReader = { structLength : 4 + arrayBuilderSegmentReader . structLength , componentId : ( diff ) => platform . readInt32Field ( diff as any , 0 ) , edits : ( diff ) => platform . readStructField < Pointer > ( diff as any , 4 ) as any as ArrayBuilderSegment < RenderTreeEdit > , editsEntry : ( values , index ) => arrayValuesEntry ( values , index , editReader . structLength ) , } ; const editReader = { structLength : 20 , editType : ( edit ) => platform . readInt32Field ( edit as any , 0 ) as EditType , siblingIndex : ( edit ) => platform . readInt32Field ( edit as any , 4 ) , newTreeIndex : ( edit ) => platform . readInt32Field ( edit as any , 8 ) , moveToSiblingIndex : ( edit ) => platform . readInt32Field ( edit as any , 8 ) , removedAttributeName : ( edit ) => platform . readStringField ( edit as any , 16 ) , } ; const frameReader = { structLength : 36 , frameType : ( frame ) => platform . readInt16Field ( frame as any , 4 ) as FrameType , subtreeLength : ( frame ) => platform . readInt32Field ( frame as any , 8 ) , elementReferenceCaptureId : ( frame ) => platform . readStringField ( frame as any , 16 ) , componentId : ( frame ) => platform . readInt32Field ( frame as any , 12 ) , elementName : ( frame ) => platform . readStringField ( frame as any , 16 ) , textContent : ( frame ) => platform . readStringField ( frame as any , 16 ) , markupContent : ( frame ) => platform . readStringField ( frame as any , 16 ) ! , attributeName : ( frame ) => platform . readStringField ( frame as any , 16 ) , attributeValue : ( frame ) => platform . readStringField ( frame as any , 24 ) , attributeEventHandlerId : ( frame ) => platform . readUint64Field ( frame as any , 8 ) , } ; function arrayValuesEntry < T > ( arrayValues , index , itemSize ) { return platform . getArrayEntryPtr ( arrayValues as any as System_Array < T > , index , itemSize ) as any as T ; }