cocos2d-x-3.5 中new 出来的对象大部分是如何处理的

前端之家收集整理的这篇文章主要介绍了cocos2d-x-3.5 中new 出来的对象大部分是如何处理的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

以下来自对 cocos2d-x-3.5 的源码分析,今天重点研究它的动态开辟的对象释放问题.


涉及以下3个基本的class 和一个模板类


  • 手动引用计数类 class Ref

    • Ref 是 cocos2d 中很大一部分类的祖先类 . @H_404_19@
    • Ref 支持以下三个接口:
      • retain() 累加引用计数,当我们将指针复制给新的指针的时候,请自觉手动调用! @H_404_19@
      • release() 指针释放无用或者即将挪作它用之前,自己自觉手动调用!@H_404_19@
      • autorelease() 将释放的任务交给当前的 AutoreleasePool,这样程序员就不需要在意这个指针什么时候被释放或者挪作它用了. @H_404_19@
      @H_404_19@
    @H_404_19@
  • Ref 对象池 AutoreleasePool

    • 任何一个AutoreleasePool 对象构造的时候就会被压栈到下面的PoolManager 中,析构的时候自动退栈 .@H_404_19@
    • AutoreleasePool 会在 clear 或者析构的时候将自己管理的Ref 自动release() 一下. @H_404_19@
    • AutoreleasePool 支持:
      • 添加void addObject(Ref *object) @H_404_19@
      • 查询bool contains(Ref* object) const@H_404_19@
      • 清除 void clear()@H_404_19@
      @H_404_19@
    @H_404_19@
  • 对象池管理员PoolManager

    • PoolManager 是单例的 !
      • static PoolManager* getInstance()@H_404_19@
      @H_404_19@
    • 池子只能有压栈和退栈两个操作.
      • void push(AutoreleasePool *pool);@H_404_19@
      • void pop();@H_404_19@
      @H_404_19@
    • 构造单例时候会自动构造一个 AutoreleasePool 作为当前使用的池子.@H_404_19@
    • 总是使用栈顶的池子.@H_404_19@
    @H_404_19@
  • 模板类RefPtr 模拟shared_ptr

    @H_404_19@

另外还有一个相关的class : class Clonable .
* 支持接口 Clonable* clone(),会复制Ref,重新开始计数.



可以看到 cocos2d-x 提供了基本的管理机制,但是需要依赖程序员的自觉性!!!



基于Ref的继承体系速查

  • Ref

    • Director
      • DisplayLinkDirector@H_404_19@
      @H_404_19@
    • EventListener

      • EventListenerAcceleration@H_404_19@
      • EventListenerController@H_404_19@
      • EventListenerCustom@H_404_19@
      • EventListenerFocus@H_404_19@
      • EventListenerKeyboard@H_404_19@
      • EventListenerMouse@H_404_19@
      • EventListenerTouchOneByOne@H_404_19@
      @H_404_19@
    • Event
      • EventDispatcher@H_404_19@
      • EventController@H_404_19@
      • EventFocus@H_404_19@
      • EventCustom@H_404_19@
      • EventKeyboard@H_404_19@
      • EventMouse@H_404_19@
      • EventTouch@H_404_19@
      @H_404_19@
    • Scheduler@H_404_19@
    • ScriptHandlerEntry@H_404_19@
    • Touch@H_404_19@
    • ActionManager@H_404_19@
    • Action : Cloneable
      • FiniteTimeAction
        • ActionInstant
          • StopGrid@H_404_19@
          @H_404_19@
        • ActionInterval
          • GridAction
            • Grid3DAction@H_404_19@
            • TiledGrid3DAction@H_404_19@
            • AccelDeccelAmplitude@H_404_19@
            @H_404_19@
          • AccelAmplitude@H_404_19@
          • DeccelAmplitude@H_404_19@
          • ActionEase
            • EaseBackIn@H_404_19@
            • EaseBackInOut@H_404_19@
            • EaseBackOut@H_404_19@
            • EaseBezierAction@H_404_19@
            • EaseBounce
              • EaseBounceIn@H_404_19@
              • EaseBounceInOut@H_404_19@
              @H_404_19@
            • EaseCircleActionIn@H_404_19@
            • EaseCircleActionInOut@H_404_19@
            • EaseCircleActionOut@H_404_19@
            • EaseCubicActionIn@H_404_19@
            • EaseCubicActionInOut@H_404_19@
            @H_404_19@
          • Animate@H_404_19@
          • BezierBy@H_404_19@
          • BezierTo@H_404_19@
          • Blink@H_404_19@
          • FadeTo
            • FadeIn@H_404_19@
            • FadeOut@H_404_19@
            @H_404_19@
          • JumpBy
            • JumpTo@H_404_19@
            @H_404_19@
          • MoveBy
            • MoveTo@H_404_19@
            @H_404_19@
          • Repeat@H_404_19@
          • RepeatForever@H_404_19@
          • ReverseTime@H_404_19@
          • RotateBy@H_404_19@
          • RotateTo@H_404_19@
          • ScaleTo
            • ScaleBy@H_404_19@
            @H_404_19@
          • TintBy@H_404_19@
          • TintTo@H_404_19@
          • TargetedAction@H_404_19@
          • ProgressFromTo@H_404_19@
          • ProgressTo@H_404_19@
          • ActionTween@H_404_19@
          @H_404_19@
        • Sequence @H_404_19@
        • SkewTo
          • SkewBy@H_404_19@
          @H_404_19@
        • Spawn@H_404_19@
        @H_404_19@
      • Follow@H_404_19@
      • Speed@H_404_19@
      • ActionCamera
        • OrbitCamera@H_404_19@
        @H_404_19@
      @H_404_19@
    • PointArray@H_404_19@
    • AnimationFrame : Cloneable@H_404_19@
    • Animation : Cloneable@H_404_19@
    • AnimationCache@H_404_19@
    • Node
      • Camera@H_404_19@
      • BaseLight
        • AmbientLight@H_404_19@
        • DirectionLight@H_404_19@
        • PointLight@H_404_19@
        • SpotLight@H_404_19@
        @H_404_19@
      • AtlasNode
        • LabelAtlas : LabelProtocol @H_404_19@
        • TileMapAtlas@H_404_19@
        @H_404_19@
      • ClippingNode@H_404_19@
      • ClippingRectangleNode@H_404_19@
      • DrawNode@H_404_19@
      • TMXLayer@H_404_19@
      • TMXTiledMap@H_404_19@
      • LabelTTF : LabelProtocol,BlendProtocol@H_404_19@
      • LabelBMFont : LabelProtocol,BlendProtocol@H_404_19@
      • Layer
        • LayerMultiplex@H_404_19@
        • LayerColor : BlendProtocol
          • LayerGradient@H_404_19@
          @H_404_19@
        • Menu@H_404_19@
        • MenuItem@H_404_19@
        • ImageView
          • MenuItemSprite@H_404_19@
          • MenuItemToggle@H_404_19@
          • MenuItemLabel
            • MenuItemAtlasFont@H_404_19@
            • MenuItemFont@H_404_19@
            • MenuItemFont@H_404_19@
            @H_404_19@
          @H_404_19@
        @H_404_19@
      • MotionStreak : TextureProtocol @H_404_19@
      • NodeGrid@H_404_19@
      • RenderTexture@H_404_19@
      • ParallaxNode@H_404_19@
      • ProtectedNode
        • Widget : LayoutParameterProtocol
          • Button@H_404_19@
          • CheckBox@H_404_19@
          • LoadingBar@H_404_19@
          • Slider@H_404_19@
          • Text@H_404_19@
          • TextAtlas@H_404_19@
          • TextBMFont@H_404_19@
          • VideoPlayer@H_404_19@
          • WebView@H_404_19@
          • Layout : LayoutProtocol
            @H_404_19@
          @H_404_19@
        @H_404_19@
      • ParticleBatchNode : TextureProtocol@H_404_19@
      • ParticleSystem : TextureProtocol
        • ParticleSystemQuad
          • ParticleExplosion@H_404_19@
          • ParticleMeteor@H_404_19@
          • ParticleFire@H_404_19@
          • ParticleFireworks@H_404_19@
          • ParticleFlower@H_404_19@
          • ParticleGalaxy@H_404_19@
          • ParticleRain@H_404_19@
          • ParticleSmoke@H_404_19@
          • ParticleSnow@H_404_19@
          • ParticleSpiral@H_404_19@
          • ParticleSun@H_404_19@
          @H_404_19@
        @H_404_19@
      • Scene
        • TransitionScene
          • TransitionCrossFade@H_404_19@
          • TransitionFade@H_404_19@
          • TransitionJumpZoom@H_404_19@
          • TransitionShrinkGrow: TransitionEaseScene@H_404_19@
          • TransitionMoveInL: TransitionEaseScene
            • TransitionMoveInB@H_404_19@
            • TransitionMoveInR@H_404_19@
            • TransitionMoveInT@H_404_19@
            @H_404_19@
          • TransitionSceneOriented
            • TransitionFlipAngular@H_404_19@
            • TransitionFlipX@H_404_19@
            • TransitionFlipY@H_404_19@
            • TransitionZoomFlipX@H_404_19@
            • TransitionZoomFlipY@H_404_19@
            @H_404_19@
          • TransitionFadeTR : TransitionEaseScene
            • TransitionFadeDown@H_404_19@
            • TransitionFadeUp@H_404_19@
            @H_404_19@
          • TransitionSlideInL: TransitionEaseScene
            • TransitionSlideInR@H_404_19@
            • TransitionSlideInT@H_404_19@
            @H_404_19@
          • TransitionSplitCols: TransitionEaseScene
            • TransitionSplitRows@H_404_19@
            @H_404_19@
          • TransitionTurnOffTiles@H_404_19@
          • TransitionPageTurn@H_404_19@
          • TransitionProgress@H_404_19@
          @H_404_19@
        @H_404_19@
      • Sprite : TextureProtocol@H_404_19@
      • SpriteBatchNode : TextureProtocol
        • TMXLayer@H_404_19@
        @H_404_19@
      • TMXTiledMap@H_404_19@
      @H_404_19@
    • Component
      • FontCharMap@H_404_19@
      • FontFNT@H_404_19@
      • FontFreeType@H_404_19@
      • LayoutComponent@H_404_19@
      @H_404_19@
    • FontAtlas@H_404_19@
    • Grabber@H_404_19@
    • GridBase
      • Grid3D@H_404_19@
      • TiledGrid3D@H_404_19@
      @H_404_19@
    • SpriteFrame : Clonable@H_404_19@
    • SpriteFrameCache@H_404_19@
    • TMXObjectGroup@H_404_19@
    • TMXLayerInfo@H_404_19@
    • LayoutManager@H_404_19@
    • RichElement@H_404_19@
    • GLView@H_404_19@
    @H_404_19@
原文链接:https://www.f2er.com/cocos2dx/343410.html

猜你在找的Cocos2d-x相关文章