BarrageDispatcher.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Part of BarrageRenderer. Created by UnAsh.
  2. // Blog: http://blog.exbye.com
  3. // Github: https://github.com/unash/BarrageRenderer
  4. // This code is distributed under the terms and conditions of the MIT license.
  5. // Copyright (c) 2015年 UnAsh.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #import <Foundation/Foundation.h>
  25. @class BarrageSprite;
  26. @class BarrageDispatcher;
  27. @protocol BarrageDispatcherDelegate <NSObject>
  28. @optional
  29. /// 是否激活此弹幕精灵.
  30. - (BOOL)shouldActiveSprite:(BarrageSprite *)sprite;
  31. - (NSTimeInterval)timeForBarrageDispatcher:(BarrageDispatcher *)dispatcher;
  32. @required
  33. - (void)willActiveSprite:(BarrageSprite *)sprite;
  34. - (void)willDeactiveSprite:(BarrageSprite *)sprite;
  35. @end
  36. /// 弹幕调度器, 主要完成负载均衡的工作.
  37. @interface BarrageDispatcher : NSObject
  38. /// 添加精灵.
  39. - (void)addSprite:(BarrageSprite *)sprite;
  40. /// 派发精灵.
  41. - (void)dispatchSprites;
  42. /// 是否开启过期精灵缓存功能, 默认关闭, 如需支持后退时重新播放弹幕, 则需置为YES.
  43. @property (nonatomic,assign)BOOL cacheDeadSprites;
  44. /// 当前活跃的精灵.
  45. @property (nonatomic,strong,readonly)NSArray * activeSprites;
  46. /// 停止当前被激活的精灵
  47. - (void)deactiveAllSprites;
  48. /// 平滑系数, 范围为[0,1],当为0时,无平滑; 否则越大,越平滑;
  49. /// 高平滑值在大量弹幕的时候(一般100+),可能造成弹幕丢失
  50. @property(nonatomic,assign)CGFloat smoothness;
  51. @property (nonatomic,weak)id<BarrageDispatcherDelegate> delegate;
  52. @end