Cocos3 -- 1. Engine running process
1. program entry
// create the application instance AppDelegate app; return Application::getInstance()->run();
2. Main Loop
Int Application: run ():
While (! Glview-> windowShouldClose () {QueryPerformanceCounter (& nNow); if (nNow. quadPart-nLast. quadPart> _ animationInterval. quadPart) {nLast. quadPart = nNow. quadPart; // The director's main cycle director-> mainLoop (); glview-> pollEvents ();} else {Sleep (0 );}}
MainLoop-> drawScene:
PushMatrix (MATRIX_STACK_TYPE: MATRIX_STACK_MODELVIEW); if (_ runningScene) {// clear draw stats _ renderer-> clearDrawStats (); // visit and draw scenarios (but draw only adds the rendering command) // The rendering command is in: renderer-> render (); // render the scene _ runningScene-> render (_ renderer); _ eventDispatcher-> dispatchEvent (_ eventAfterVisit);} // notification node, rendering independently of the scenario // draw the events node if (_ icationicationnode) {_ notificationNode-> visit (_ renderer, Mat4: IDENTITY, 0);} if (_ displayStats) {showStats () ;}// the following render _ icationicationnode and stats _ renderer-> render (); _ eventDispatcher-> dispatchEvent (_ eventAfterDraw); popMatrix (MATRIX_STACK_TYPE :: MATRIX_STACK_MODELVIEW); _ totalFrames ++; // swap buffers if (_ openGLView) {_ openGLView-> swapBuffers ();}
Void Scene: render (Renderer * renderer ):
Camera::_visitingCamera = defaultCamera; director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix()); //visit the scene visit(renderer, Mat4::IDENTITY, 0); renderer->render(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
3. node Traversal
Void Node: visit (Renderer * renderer, const Mat4 & parentTransform, uint32_t parentFlags ):
// quick return if not visible. children won't be drawn. if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); bool visibleByCamera = isVisitableByVisitingCamera(); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->_localZOrder < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } // self draw if (visibleByCamera) this->draw(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);