重构 GiftComboManager,移除 giftComboQueue,新增 networkQueue 和 uiQueue,优化队列处理逻辑,提升代码可维护性和可读性。同时,更新相关方法以支持新的队列结构,确保连击效果的准确处理。

This commit is contained in:
edwinQQQ
2025-08-19 15:30:39 +08:00
parent c551146afd
commit 83e26bdbae

View File

@@ -32,8 +32,9 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
@property (nonatomic, strong) NSMutableArray *requestQueue;
// GiftReceiveInfoModel NSDictionary
@property (nonatomic, strong) NSMutableArray *giftComboQueue;
@property (nonatomic, strong) NSMutableArray *comboFlagQueue;
// @property (nonatomic, strong) NSMutableArray *giftComboQueue;
@property (nonatomic, strong) NSMutableArray *networkQueue; // AttachmentModel
@property (nonatomic, strong) NSMutableArray *uiQueue; // UIGiftReceiveInfoModel
@property (nonatomic, strong) dispatch_source_t comboFlagTimer;
@property (nonatomic, strong) UIView *containerView;
@@ -66,9 +67,9 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
#pragma mark -
- (void)dealloc {
[self stopProcessingGiftComboFlagQueue];
if (self.comboFlagQueue) {
self.comboFlagQueue = NULL;
[self stopProcessingUIQueue];
if (self.uiQueue) {
self.uiQueue = NULL;
}
}
@@ -77,11 +78,12 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
sharedInstance.giftComboQueue = [NSMutableArray array];
// sharedInstance.giftComboQueue = [NSMutableArray array];
sharedInstance.networkQueue = [NSMutableArray array];
sharedInstance.uiQueue = [NSMutableArray array];
sharedInstance.activeViews = [NSMutableArray array];
sharedInstance.comboFlagQueue = [NSMutableArray array];
sharedInstance.requestQueue = [NSMutableArray array];
[sharedInstance startProcessingGiftComboFlagQueue];
[sharedInstance startProcessingUIQueue];
});
return sharedInstance;
}
@@ -92,7 +94,7 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
//
@synchronized (self) {
NSDictionary *comboData = @{@"info": info, @"metadata": metadata};
[self.giftComboQueue addObject:comboData];
[self.networkQueue addObject:comboData];
}
//
[self startProcessingQueue];
@@ -103,7 +105,7 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
if (attachment) {
//
@synchronized (self) {
[self.giftComboQueue addObject:attachment];
[self.networkQueue addObject:attachment];
}
//
[self startProcessingQueue];
@@ -285,21 +287,15 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
- (void)clearAllQueues {
@synchronized (self) {
[self.requestQueue removeAllObjects];
[self.giftComboQueue removeAllObjects];
[self.comboFlagQueue removeAllObjects];
[self.networkQueue removeAllObjects];
[self.uiQueue removeAllObjects];
}
}
- (NSInteger)loadTotalGiftNum {
return self.combo * self.countModel.giftNumber.integerValue * self.sendGiftToUIDs.count;
}
//
- (BOOL)isComboStateValid {
@synchronized (self) {
@@ -360,18 +356,18 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
container:(UIView *)container {
NSLog(@"[Combo effect] 🎪 收到连击飘屏请求 - combo: %ld, giftId: %ld", (long)receiveInfo.comboCount, (long)receiveInfo.gift.giftId);
self.containerView = container;
[self.giftComboQueue addObject:receiveInfo];
NSLog(@"[Combo effect] 📊 连击飘屏队列数量: %ld", (long)self.giftComboQueue.count);
[self startProcessingGiftComboFlagQueue];
[self.uiQueue addObject:receiveInfo];
NSLog(@"[Combo effect] 📊 连击飘屏队列数量: %ld", (long)self.uiQueue.count);
[self startProcessingUIQueue];
}
- (void)removeComboFlag {
self.containerView = nil;
[self stopProcessingQueue];
[self stopProcessingGiftComboFlagQueue];
[self stopProcessingUIQueue];
}
- (void)startProcessingGiftComboFlagQueue {
- (void)startProcessingUIQueue {
if (self.comboFlagTimer) {
return;
}
@@ -394,7 +390,7 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
self.comboFlagTimer = timer;
}
- (void)stopProcessingGiftComboFlagQueue {
- (void)stopProcessingUIQueue {
if (self.comboFlagTimer) {
dispatch_source_cancel(self.comboFlagTimer);
@@ -407,17 +403,19 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
}
- (void)processGiftFlagQueue {
if (self.giftComboQueue.count == 0) {
return;
}
@synchronized (self) {
if (self.uiQueue.count == 0) {
return;
}
GiftReceiveInfoModel *receiveInfo = [self.giftComboQueue firstObject];
NSLog(@"[Combo effect] 🎪 处理连击飘屏 - combo: %ld, giftId: %ld", (long)receiveInfo.comboCount, (long)receiveInfo.gift.giftId);
[self.giftComboQueue xpSafeRemoveObjectAtIndex:0];
NSLog(@"[Combo effect] 📊 移除后连击飘屏队列数量: %ld", (long)self.giftComboQueue.count);
dispatch_async(dispatch_get_main_queue(), ^{
[self handleGiftInfo:receiveInfo];
});
GiftReceiveInfoModel *receiveInfo = [self.uiQueue firstObject];
NSLog(@"[Combo effect] 🎪 处理连击飘屏 - combo: %ld, giftId: %ld", (long)receiveInfo.comboCount, (long)receiveInfo.gift.giftId);
[self.uiQueue xpSafeRemoveObjectAtIndex:0];
NSLog(@"[Combo effect] <EFBFBD><EFBFBD> 移除后UI动画队列数量: %ld", (long)self.uiQueue.count);
dispatch_async(dispatch_get_main_queue(), ^{
[self handleGiftInfo:receiveInfo];
});
}
}
- (void)handleGiftInfo:(GiftReceiveInfoModel *)receiveInfo {
@@ -558,7 +556,7 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
//
- (void)stopProcessingQueue {
if (self.timer) {
if (self.requestQueue.count == 0 && self.giftComboQueue.count == 0) {
if (self.requestQueue.count == 0 && self.networkQueue.count == 0) {
//
dispatch_source_cancel(self.timer);
@@ -574,14 +572,23 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
//
- (void)processGiftComboQueue {
@synchronized (self) {
if (self.giftComboQueue.count > 0) {
//
AttachmentModel *attachment = [self.giftComboQueue firstObject];
[self.giftComboQueue xpSafeRemoveObjectAtIndex:0];
@synchronized (self) {
if (self.networkQueue.count > 0) {
//
id networkData = [self.networkQueue firstObject];
[self.networkQueue xpSafeRemoveObjectAtIndex:0];
//
[self processGiftComboWith:attachment];
if ([networkData isKindOfClass:[AttachmentModel class]]) {
[self processGiftComboWith:(AttachmentModel *)networkData];
} else if ([networkData isKindOfClass:[NSDictionary class]]) {
// infometadata
NSDictionary *comboData = (NSDictionary *)networkData;
GiftReceiveInfoModel *info = comboData[@"info"];
NSDictionary *metadata = comboData[@"metadata"];
//
NSLog(@"[Combo effect] <20><> 处理网络数据 - info: %@, metadata: %@", info, metadata);
}
} else {
[self stopProcessingQueue];
}