蜘蛛盘本地跟手并合并宿主拖动写入

这个提交包含在:
mac 于 2026-11-09 11:26:55 +08:00 提交
1 父节点 9f12f7b42a
当前提交 178e1e7d16
12 个文件已更改
+251 -79

没有与搜索条件相匹配的文件

@@ -68,7 +68,8 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
NSDictionary *_snapshot,*_sourceDocument;NSString *_selectedNode;
CMTime _snapshotTime;
BOOL _invalidated,_validationScheduled;
uint64_t _requestSequence,_requestedGesture,_completedGesture;
uint64_t _requestSequence,_requestedGesture,_completedGesture,_pendingSpiderGesture;
NSData *_pendingSpiderMesh;
// The fields below are confined to the main queue.
id<PROAPIAccessing> _writerHost,_writerTarget;
@@ -88,7 +89,7 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
// the queued block keeps the bridge alive until its host group is closed.
NSCAssert(!_writerUndoOpen,@"Viewer parameter group must be closed before teardown");
[NSNotificationCenter.defaultCenter removeObserver:self];[_renderer release];[_selectedNode release];[_snapshot release];[_sourceDocument release];[_writerHost release];[_writerTarget release];
[_writerDescriptors release];[_writerLastValues release];[_writerCompanions release];[_writerNode release];[_writerType release];[super dealloc];
[_writerDescriptors release];[_writerLastValues release];[_writerCompanions release];[_writerNode release];[_writerType release];[_pendingSpiderMesh release];[super dealloc];
}
- (void)publishAssets:(DYAssetState*)assets atTime:(CMTime)time {
@synchronized(self){if(_invalidated||!_snapshot||CMTimeCompare(time,_snapshotTime)!=0)return;NSMutableDictionary *next=[[_snapshot mutableCopy]autorelease];next[@"spider"]=assets.spiderMesh?:[NSData data];[_snapshot release];_snapshot=[next copy];}
@@ -307,27 +308,47 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
if(!descriptor)return;[self beginParameter:descriptor node:node value:enabled atTime:time];uint64_t gesture;@synchronized(self){gesture=_requestedGesture;}NSData *original=[mesh copy]?:[NSData new];
dispatch_async(dispatch_get_main_queue(),^{if(self->_writerGesture==gesture&&[self->_writerType isEqual:@"spider"]){self->_writerSpider=YES;self->_writerLastMesh=[original copy];if(![self writerStillValid])[self closeWriter];}});[original release];
}
- (void)changeSpider:(NSData*)mesh {
if(!DYSpiderMeshIsValid(mesh))return;NSData *frozen=[mesh copy];uint64_t gesture;@synchronized(self){gesture=_invalidated?0:_requestedGesture;}
if(gesture)dispatch_async(dispatch_get_main_queue(),^{
if(self->_writerGesture!=gesture||!self->_writerSpider)return;
if(![self writerStillValid]){[self closeWriter];return;}
if([frozen isEqual:self->_writerLastMesh])return;
id<FxCustomParameterActionAPI_v4>a=[self->_writerTarget apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];BOOL changed=NO,failed=NO;
[a startAction:self];@try{
if(!CMTIME_IS_NUMERIC(a.currentTime)||CMTimeCompare(DYHostDisplayedFrameTime(self->_writerHost,a.currentTime),self->_writerTime)!=0||![self writerValueMatches]){failed=YES;}
else{
if(!self->_writerUndoOpen)self->_writerUndoOpen=[[self->_writerHost apiForProtocol:@protocol(FxUndoAPI)]startUndoGroup:@"画面调整 · 蜘蛛盘"];
if(self->_writerUndoOpen){DYAssetState *old=DYReadAssets(self->_writerTarget,self->_writerTime);DYAssetState *next=[[old copy]autorelease];next.spiderMesh=frozen;
failed=!DYWriteAssets(self->_writerTarget,next,self->_writerTime);
if(failed)DYWriteAssets(self->_writerTarget,old,self->_writerTime);else changed=YES;
}
- (void)flushSpiderGesture:(uint64_t)gesture {
NSData *mesh=nil;
@synchronized(self){
if(_invalidated||_pendingSpiderGesture!=gesture)return;
mesh=[_pendingSpiderMesh autorelease];_pendingSpiderMesh=nil;_pendingSpiderGesture=0;
}
if(_writerGesture!=gesture||!_writerSpider||[mesh isEqual:_writerLastMesh])return;
id<FxCustomParameterActionAPI_v4>a=[_writerTarget apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];
if(!a){[self closeWriter];return;}
BOOL changed=NO,failed=NO;
[a startAction:self];@try{
if(!CMTIME_IS_NUMERIC(a.currentTime)||CMTimeCompare(DYHostDisplayedFrameTime(_writerHost,a.currentTime),_writerTime)!=0||![self writerValueMatches]){failed=YES;}
else{
if(!_writerUndoOpen)_writerUndoOpen=[[_writerHost apiForProtocol:@protocol(FxUndoAPI)]startUndoGroup:@"画面调整 · 蜘蛛盘"];
if(_writerUndoOpen){
DYAssetState *old=DYReadAssets(_writerTarget,_writerTime);DYAssetState *next=[[old copy]autorelease];next.spiderMesh=mesh;
failed=!DYWriteAssets(_writerTarget,next,_writerTime);
if(failed)DYWriteAssets(_writerTarget,old,_writerTime);else changed=YES;
}
}@finally{[a endAction:self];}
// Re-read after DYToolManager commits its document at the outer boundary.
if(changed){[a startAction:self];NSData *actual=nil;@try{actual=[DYReadAssets(self->_writerTarget,self->_writerTime).spiderMesh retain];}@finally{[a endAction:self];}BOOL saved=[actual isEqual:frozen];[actual release];if(!saved)failed=YES;else{[self->_writerLastMesh release];self->_writerLastMesh=[frozen copy];[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self->_apiManager];}}
if(failed)[self closeWriter];
});[frozen release];
}
}@finally{[a endAction:self];}
// Re-read after DYToolManager commits its document at the outer boundary.
if(changed){
[a startAction:self];NSData *actual=nil;
@try{actual=[DYReadAssets(_writerTarget,_writerTime).spiderMesh retain];}@finally{[a endAction:self];}
BOOL saved=[actual isEqual:mesh];[actual release];
if(!saved)failed=YES;
else{[_writerLastMesh release];_writerLastMesh=[mesh copy];[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:_apiManager];}
}
if(failed)[self closeWriter];
}
- (void)changeSpider:(NSData*)mesh {
if(!DYSpiderMeshIsValid(mesh))return;
@synchronized(self){
if(_invalidated||!_requestedGesture)return;
uint64_t gesture=_requestedGesture;
[_pendingSpiderMesh release];_pendingSpiderMesh=[mesh copy];
if(_pendingSpiderGesture==gesture)return;
_pendingSpiderGesture=gesture;
dispatch_async(dispatch_get_main_queue(),^{[self flushSpiderGesture:gesture];});
}
}
- (void)writeValues:(NSDictionary<NSString*,NSNumber*>*)values gesture:(uint64_t)gesture {
NSCAssert(NSThread.isMainThread,@"Host writes require the main queue");
@@ -464,7 +485,7 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) {
@synchronized(self){return !_invalidated&&gesture>_completedGesture;}
}
- (void)invalidate {
@synchronized(self){if(_invalidated)return;_invalidated=YES;_requestedGesture=0;_apiManager=nil;}
@synchronized(self){if(_invalidated)return;_invalidated=YES;_requestedGesture=0;_pendingSpiderGesture=0;[_pendingSpiderMesh release];_pendingSpiderMesh=nil;_apiManager=nil;}
dispatch_async(dispatch_get_main_queue(),^{[self closeWriter];});
}
@end