Ccapplication inherits from Applicationprotocol (class Cc_dll application:public Applicationprotocol)
The Applicationprotocol class defines the relevant platform enumerator, applies the startup completion callback, applies the callback to the background, enters the application callback from the background, the program executes the interval cycle, the program runs the platform, and the program's configuration language. The program has only applicationprotocol. h files, and this class is a virtual base class.
Ccapplication uses a singleton pattern, wherein the singleton is application * application::sm_psharedapplication = 0; This variable.
The important Application::Run function, which initializes the Director,glview two variable handles in the Run function,
Two functions:
QueryPerformanceFrequency () function to obtain the CPU frequency.
QueryPerformanceCounter () function to get the number of ticks
Can know:
Total times/time = frequency can be deduced: Time = total number/frequency. You can therefore calculate the number of frames rendered.
Setanimationinterval (1.0/60); This sentence is familiar, set the frame rate. The code is as follows:
void Application::setanimationinterval (double interval)
{
Large_integer Nfreq;
QueryPerformanceFrequency (&nfreq);
_animationinterval.quadpart = (longlong) (interval * nfreq.quadpart); time *CPU frequency = total number of times (this total count is the count of 1/60 second CPU)
}
After the total number of _animationinterval.quadpart, continue to see the code inside the run:
There is a while main loop that executes in the loop:
Subtract the number of times before and after two times, and render once only when the total number of times calculated above is reached. 1/60 seconds render once
if (Nnow.quadpart-nlast.quadpart > _animationinterval.quadpart)
{
Nlast.quadpart = Nnow.quadpart;
Director->mainloop ();
Glview->pollevents ();
}else
{
Sleep (0);
}
There are 2 important functions:
Director->mainloop (); Glview->pollevents (); The Mainloop handler function for the Director class, and the Glview event handler function.
This main loop is followed by the program toward the end, executing the function, judging Glview->isopenglready (), and if OpenGL is present, execute the Director->end () function.
and release Glview.
At this point, the main process of the program completes the start-run-end procedure in the application class.
(This is the ccapplication file for the Win32 platform, the ccapplication files on other platforms are not consistent, there are differences depending on the relevant platform)
Inheritance Relationship:
Applicationprotocol
| ———— Application
cocos2dx-3.2 Engine Learning (i) ccapplication