Skip to content

Commit fb80b07

Browse files
committed
refactor-CCScene
prefer in-class initialization
1 parent 2727af8 commit fb80b07

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Diff for: cocos/2d/CCScene.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,16 @@ THE SOFTWARE.
5252
NS_CC_BEGIN
5353

5454
Scene::Scene()
55+
: _defaultCamera(Camera::create())
56+
, _event(Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1)))
5557
{
56-
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
57-
_physics3DWorld = nullptr;
58-
_physics3dDebugCamera = nullptr;
59-
#endif
60-
#if CC_USE_NAVMESH
61-
_navMesh = nullptr;
62-
_navMeshDebugCamera = nullptr;
63-
#endif
64-
#if CC_USE_PHYSICS
65-
_physicsWorld = nullptr;
66-
#endif
6758
_ignoreAnchorPointForPosition = true;
6859
setAnchorPoint(Vec2(0.5f, 0.5f));
6960

70-
_cameraOrderDirty = true;
71-
7261
//create default camera
73-
_defaultCamera = Camera::create();
62+
7463
addChild(_defaultCamera);
7564

76-
_event = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1));
7765
_event->retain();
7866

7967
Camera::_visitingCamera = nullptr;

Diff for: cocos/2d/CCScene.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CC_DLL Scene : public Node
156156

157157
std::vector<Camera*> _cameras; //weak ref to Camera
158158
Camera* _defaultCamera; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called
159-
bool _cameraOrderDirty; // order is dirty, need sort
159+
bool _cameraOrderDirty = true; // order is dirty, need sort
160160
EventListenerCustom* _event;
161161

162162
std::vector<BaseLight *> _lights;
@@ -201,12 +201,12 @@ class CC_DLL Scene : public Node
201201
void addChildToPhysicsWorld(Node* child);
202202

203203
#if CC_USE_PHYSICS
204-
PhysicsWorld* _physicsWorld;
204+
PhysicsWorld* _physicsWorld = nullptr;
205205
#endif
206206

207207
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
208-
Physics3DWorld* _physics3DWorld;
209-
Camera* _physics3dDebugCamera; //
208+
Physics3DWorld* _physics3DWorld = nullptr;
209+
Camera* _physics3dDebugCamera = nullptr;
210210
#endif
211211
#endif // (CC_USE_PHYSICS || CC_USE_3D_PHYSICS)
212212

@@ -222,8 +222,8 @@ class CC_DLL Scene : public Node
222222
void setNavMeshDebugCamera(Camera *camera);
223223

224224
protected:
225-
NavMesh* _navMesh;
226-
Camera * _navMeshDebugCamera;
225+
NavMesh* _navMesh = nullptr;
226+
Camera * _navMeshDebugCamera = nullptr;
227227
#endif
228228

229229
#if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH)

0 commit comments

Comments
 (0)