Skip to content

Commit fb53420

Browse files
author
minggo
authored
reduce cleanning clear buffer times (#19131)
1 parent 5f6c904 commit fb53420

File tree

6 files changed

+55
-104
lines changed

6 files changed

+55
-104
lines changed

cocos/2d/CCCamera.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,8 @@ const Camera* Camera::getVisitingCamera()
107107
// end static methods
108108

109109
Camera::Camera()
110-
: _scene(nullptr)
111-
, _viewProjectionDirty(true)
112-
, _viewProjectionUpdated(false)
113-
, _cameraFlag(1)
114-
, _frustumDirty(true)
115-
, _depth(-1)
116-
, _fbo(nullptr)
117110
{
118111
_frustum.setClipZ(true);
119-
_clearBrush = CameraBackgroundBrush::createDepthBrush(1.f);
120-
_clearBrush->retain();
121112
}
122113

123114
Camera::~Camera()

cocos/2d/CCCamera.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class CC_DLL Camera :public Node
121121
Camera::Type getType() const { return _type; }
122122

123123
/**get & set Camera flag*/
124-
CameraFlag getCameraFlag() const { return (CameraFlag)_cameraFlag; }
125-
void setCameraFlag(CameraFlag flag) { _cameraFlag = (unsigned short)flag; }
124+
CameraFlag getCameraFlag() const { return _cameraFlag; }
125+
void setCameraFlag(CameraFlag flag) { _cameraFlag = flag; }
126126

127127
/**
128128
* Make Camera looks at target
@@ -309,7 +309,7 @@ class CC_DLL Camera :public Node
309309
static Camera* _visitingCamera;
310310
static experimental::Viewport _defaultViewport;
311311

312-
Scene* _scene; //Scene camera belongs to
312+
Scene* _scene = nullptr; //Scene camera belongs to
313313
Mat4 _projection;
314314
mutable Mat4 _view;
315315
mutable Mat4 _viewInv;
@@ -322,20 +322,20 @@ class CC_DLL Camera :public Node
322322
float _aspectRatio;
323323
float _nearPlane;
324324
float _farPlane;
325-
mutable bool _viewProjectionDirty;
326-
bool _viewProjectionUpdated; //Whether or not the viewprojection matrix was updated since the last frame.
327-
unsigned short _cameraFlag; // camera flag
325+
mutable bool _viewProjectionDirty = true;
326+
bool _viewProjectionUpdated = false; //Whether or not the viewprojection matrix was updated since the last frame.
327+
CameraFlag _cameraFlag = CameraFlag::DEFAULT; // camera flag
328328
mutable Frustum _frustum; // camera frustum
329-
mutable bool _frustumDirty;
330-
int8_t _depth; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller depth
329+
mutable bool _frustumDirty = true;
330+
int8_t _depth = -1; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller depth
331331

332-
CameraBackgroundBrush* _clearBrush; //brush used to clear the back ground
332+
CameraBackgroundBrush* _clearBrush = nullptr; //brush used to clear the back ground
333333

334334
experimental::Viewport _viewport;
335-
experimental::FrameBuffer* _fbo;
335+
experimental::FrameBuffer* _fbo = nullptr;
336336
GLint _oldViewport[4];
337337
};
338338

339339
NS_CC_END
340340

341-
#endif// __CCCAMERA_H_
341+
#endif// __CCCAMERA_H_

cocos/base/CCDirector.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,53 +115,18 @@ Director* Director::getInstance()
115115
}
116116

117117
Director::Director()
118-
: _deltaTimePassedByCaller(false)
119-
, _isStatusLabelUpdated(true)
120-
, _invalid(true)
121118
{
122119
}
123120

124121
bool Director::init(void)
125122
{
126123
setDefaultValues();
127124

128-
// scenes
129-
_runningScene = nullptr;
130-
_nextScene = nullptr;
131-
132-
_notificationNode = nullptr;
133-
134125
_scenesStack.reserve(15);
135126

136127
// FPS
137-
_accumDt = 0.0f;
138-
_frameRate = 0.0f;
139-
_FPSLabel = _drawnBatchesLabel = _drawnVerticesLabel = nullptr;
140-
_totalFrames = 0;
141128
_lastUpdate = std::chrono::steady_clock::now();
142129

143-
_secondsPerFrame = 1.0f;
144-
_frames = 0;
145-
146-
// paused ?
147-
_paused = false;
148-
149-
// purge ?
150-
_purgeDirectorInNextLoop = false;
151-
152-
// restart ?
153-
_restartDirectorInNextLoop = false;
154-
155-
// invalid ?
156-
_invalid = false;
157-
158-
_winSizeInPoints = Size::ZERO;
159-
160-
_openGLView = nullptr;
161-
_defaultFBO = nullptr;
162-
163-
_contentScaleFactor = 1.0f;
164-
165130
_console = new (std::nothrow) Console;
166131

167132
// scheduler
@@ -214,7 +179,6 @@ Director::~Director(void)
214179
CC_SAFE_RELEASE(_notificationNode);
215180
CC_SAFE_RELEASE(_scheduler);
216181
CC_SAFE_RELEASE(_actionManager);
217-
CC_SAFE_DELETE(_defaultFBO);
218182

219183
CC_SAFE_RELEASE(_beforeSetNextScene);
220184
CC_SAFE_RELEASE(_afterSetNextScene);
@@ -437,9 +401,6 @@ void Director::setOpenGLView(GLView *openGLView)
437401
{
438402
_eventDispatcher->setEnabled(true);
439403
}
440-
441-
_defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
442-
_defaultFBO->retain();
443404
}
444405
}
445406

@@ -770,9 +731,6 @@ void Director::setDepthTest(bool on)
770731
void Director::setClearColor(const Color4F& clearColor)
771732
{
772733
_renderer->setClearColor(clearColor);
773-
auto defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
774-
775-
if(defaultFBO) defaultFBO->setClearColor(clearColor);
776734
}
777735

778736
static void GLToClipTransform(Mat4 *transformOut)

cocos/base/CCDirector.h

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,10 @@ class CC_DLL Director : public Ref
591591
virtual void setAnimationInterval(float interval, SetIntervalReason reason);
592592

593593
void purgeDirector();
594-
bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
594+
bool _purgeDirectorInNextLoop = false; // this flag will be set to true in end()
595595

596596
void restartDirector();
597-
bool _restartDirectorInNextLoop; // this flag will be set to true in restart()
597+
bool _restartDirectorInNextLoop = false; // this flag will be set to true in restart()
598598

599599
void setNextScene();
600600

@@ -625,61 +625,66 @@ class CC_DLL Director : public Ref
625625
/** Scheduler associated with this director
626626
@since v2.0
627627
*/
628-
Scheduler *_scheduler;
628+
Scheduler *_scheduler = nullptr;
629629

630630
/** ActionManager associated with this director
631631
@since v2.0
632632
*/
633-
ActionManager *_actionManager;
633+
ActionManager *_actionManager = nullptr;
634634

635635
/** EventDispatcher associated with this director
636636
@since v3.0
637637
*/
638-
EventDispatcher* _eventDispatcher;
639-
EventCustom *_eventProjectionChanged, *_eventBeforeDraw, *_eventAfterDraw, *_eventAfterVisit, *_eventBeforeUpdate, *_eventAfterUpdate, *_eventResetDirector, *_beforeSetNextScene, *_afterSetNextScene;
638+
EventDispatcher* _eventDispatcher = nullptr;
639+
EventCustom* _eventProjectionChanged = nullptr;
640+
EventCustom* _eventBeforeDraw =nullptr;
641+
EventCustom* _eventAfterDraw = nullptr;
642+
EventCustom* _eventAfterVisit = nullptr;
643+
EventCustom* _eventBeforeUpdate = nullptr;
644+
EventCustom* _eventAfterUpdate = nullptr;
645+
EventCustom* _eventResetDirector = nullptr;
646+
EventCustom* _beforeSetNextScene = nullptr;
647+
EventCustom* _afterSetNextScene = nullptr;
640648

641649
/* delta time since last tick to main loop */
642-
float _deltaTime;
643-
bool _deltaTimePassedByCaller;
650+
float _deltaTime = 0.0f;
651+
bool _deltaTimePassedByCaller = false;
644652

645653
/* The _openGLView, where everything is rendered, GLView is a abstract class,cocos2d-x provide GLViewImpl
646654
which inherit from it as default renderer context,you can have your own by inherit from it*/
647-
GLView *_openGLView;
655+
GLView *_openGLView = nullptr;
648656

649657
//texture cache belongs to this director
650-
TextureCache *_textureCache;
658+
TextureCache *_textureCache = nullptr;
651659

652-
float _animationInterval;
653-
float _oldAnimationInterval;
654-
655-
/* landscape mode ? */
656-
bool _landscape;
660+
float _animationInterval = 0.0f;
661+
float _oldAnimationInterval = 0.0f;
657662

658-
bool _displayStats;
659-
float _accumDt;
660-
float _frameRate;
663+
bool _displayStats = false;
664+
float _accumDt = 0.0f;
665+
float _frameRate = 0.0f;
661666

662-
LabelAtlas *_FPSLabel;
663-
LabelAtlas *_drawnBatchesLabel;
664-
LabelAtlas *_drawnVerticesLabel;
667+
LabelAtlas *_FPSLabel = nullptr;
668+
LabelAtlas *_drawnBatchesLabel = nullptr;
669+
LabelAtlas *_drawnVerticesLabel = nullptr;
665670

666671
/** Whether or not the Director is paused */
667-
bool _paused;
672+
bool _paused = false;
668673

669674
/* How many frames were called since the director started */
670-
unsigned int _totalFrames;
671-
unsigned int _frames;
672-
float _secondsPerFrame;
675+
unsigned int _totalFrames = 0;
676+
unsigned int _frames = 0;
677+
float _secondsPerFrame = 1.f;
673678

674679
/* The running scene */
675-
Scene *_runningScene;
680+
Scene *_runningScene = nullptr;
676681

677682
/* will be the next 'runningScene' in the next frame
678683
nextScene is a weak reference. */
679-
Scene *_nextScene;
684+
Scene *_nextScene = nullptr;
680685

681686
/* If true, then "old" scene will receive the cleanup message */
682-
bool _sendCleanupToScene;
687+
bool _sendCleanupToScene = false;
683688

684689
/* scheduled scenes */
685690
Vector<Scene*> _scenesStack;
@@ -688,36 +693,33 @@ class CC_DLL Director : public Ref
688693
std::chrono::steady_clock::time_point _lastUpdate;
689694

690695
/* whether or not the next delta time will be zero */
691-
bool _nextDeltaTimeZero;
696+
bool _nextDeltaTimeZero = false;
692697

693698
/* projection used */
694-
Projection _projection;
699+
Projection _projection = Projection::DEFAULT;
695700

696701
/* window size in points */
697-
Size _winSizeInPoints;
702+
Size _winSizeInPoints = Size::ZERO;
698703

699704
/* content scale factor */
700-
float _contentScaleFactor;
705+
float _contentScaleFactor = 1.0f;
701706

702707
/* This object will be visited after the scene. Useful to hook a notification node */
703-
Node *_notificationNode;
708+
Node *_notificationNode = nullptr;
704709

705710
/* Renderer for the Director */
706-
Renderer *_renderer;
707-
708-
/* Default FrameBufferObject*/
709-
experimental::FrameBuffer* _defaultFBO;
711+
Renderer *_renderer = nullptr;
710712

711713
/* Console for the director */
712-
Console *_console;
714+
Console *_console = nullptr;
713715

714-
bool _isStatusLabelUpdated;
716+
bool _isStatusLabelUpdated = true;
715717

716718
/* cocos2d thread id */
717719
std::thread::id _cocos2d_thread_id;
718720

719721
/* whether or not the director is in a valid state */
720-
bool _invalid;
722+
bool _invalid = false;
721723

722724
// GLView will recreate stats labels to fit visible rect
723725
friend class GLView;

tests/cpp-empty-test/proj.ios/AppController.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626
#import "AppController.h"
2727
#import "cocos2d.h"
2828
#import "platform/ios/CCEAGLView-ios.h"
29-
#import "AppDelegate.h"
29+
#import "../Classes/AppDelegate.h"
3030
#import "RootViewController.h"
3131

3232
@implementation AppController

tests/cpp-tests/proj.ios/Classes/testsAppDelegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828

2929
#import "platform/ios/CCEAGLView-ios.h"
3030
#import "cocos2d.h"
31-
#import "AppDelegate.h"
31+
#import "../../Classes/AppDelegate.h"
3232
#import "RootViewController.h"
3333

3434
@implementation AppController

0 commit comments

Comments
 (0)