From 83e26bdbae46ce2162f892db112eefe8a06f3925 Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Tue, 19 Aug 2025 15:30:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=20GiftComboManager=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20giftComboQueue=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20networkQueue=20=E5=92=8C=20uiQueue=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=98=9F=E5=88=97=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E6=80=A7=E5=92=8C=E5=8F=AF=E8=AF=BB=E6=80=A7=E3=80=82?= =?UTF-8?q?=E5=90=8C=E6=97=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BB=A5=E6=94=AF=E6=8C=81=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=98=9F=E5=88=97=E7=BB=93=E6=9E=84=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E8=BF=9E=E5=87=BB=E6=95=88=E6=9E=9C=E7=9A=84=E5=87=86=E7=A1=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/SendGiftView/GiftComboManager.m | 89 ++++++++++--------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m index 2b13a3bd..90545c79 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m +++ b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m @@ -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; // UI动画队列(GiftReceiveInfoModel) @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] �� 移除后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]]) { + // 处理包含info和metadata的字典 + NSDictionary *comboData = (NSDictionary *)networkData; + GiftReceiveInfoModel *info = comboData[@"info"]; + NSDictionary *metadata = comboData[@"metadata"]; + // 这里可以添加相应的处理逻辑 + NSLog(@"[Combo effect] �� 处理网络数据 - info: %@, metadata: %@", info, metadata); + } } else { [self stopProcessingQueue]; }