Since the PIG uses C code, we start analysis from Main, from the SDL calling process as follows: 1. Initialize SDL2 through SDL_NITVIDeomode. By SDL_setKeyState Get the keyboard status array 4. Start the message loop 5. Get the message via SDL_POLLEVENT and processes until the following is a main function / * --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- * / int main (int argc, char * argv []) {sdl_surface * Screen; GameState * GS; INT i; int bpp = 0; int last_tick, start_time, end_time; int Dashframe; float logic_fps = 20.0; int flags = SDL_DOUBUF | SDL_HWSURFACE;
// SDL video initializes SDL_INIT (SDL_INIT_VIDEO);
// Press the function SDL_QUIT to the exit handler ATEXIT (SDL_QUIT);
// Set the interrupt handle, set when Ctrl Break and program abort, call BreakHandler // to reset the interrupt handle in BreakHandler, and set the interrupt flag to 1 Signal (SIGTERM, BREAKHANDAL); SIGNAL (Sigint, Breakhandler );
// Treat parameter for (i = 1; i // Set the width and height of the video mode, because BPP = 0, so use the current color number screen = SDL_SETVIDEODEMODE (Screen_W, Screen_H, BPP, Flags) {FPrintf (stderr, "Failed to Open Screen! / N "); return 1;} / / Set the title of the window and the name SDL_WM_SETCAPTION ("Fixed Rate Pig") ("Fixed Rate Pig"); // Hide mouse SDL_SHOWCURSOR (0); // Initialize the game status structure GS = init_all (screen); if (! GS) Return 1; // Note the keyboard state, the keyboard status is an UINT8 array, contains all the current status // Use Example IF (GS-> Keys [SDLK_RETURN]) ... // Initialization of logic GS-> logic_frames = 0; gs-> rendered_frames = 0; GS-> PE-> before_objects = before_objects; // Initialize the elf and the original picture Pig_Start (GS-> PE, 0) in Pig Engine; gs-> refresh_screen = GS-> pe-> pages; // Record the current time start_time = last_tick = SDL_GETTICKS (); // Start the message processing loop while (gs-> running) {Int Tick; float frames, dt; sdl_event ev; / * Handle INPUT * / / / / SDL_POLLEVENTIns a bit similar to PeekMessage While (SDL_POLLEVENT (& EV)> 0) // Processing keyboard and mouse event Handle_Input (GS, & EV); // Empty function handle_keys (GS); / / The determination program is interrupted // The front is set by Signal When the interrupt occurs when Ctrl Break or the program ends, Break_Received is set to 1 // Note that the message loop is not directly interrupt, so the operation of this loop is processed. In the future, you can really exit if (Break_Received) GS-> Running = 0; / * Calculate Time Since Last Update * / / This is used to calculate and last message loop interval, and determine the ID Tick = SDL_GETTICKS () of the logical required to display by displaying the number parameters; DT = (Tick - Last_Tick) * 0.001; Frames = DT * logic_fps; / * Run the game logic * / // Display logic Pig_animate (GS-> PE, FRAMES); / * * Limit the dashboard frame rate to 15 fps * when there's no wobbling going on. * * The 'dashframe' deal is about keeping the * pages in sync on a double buffered display. * / If (gs-> lives_wobble || GS-> score_wobble || (GS-> Dashboard_time> 1.0 / 15.0)) {dashframe = GS-> PE-> Pages; GS-> Dashboard_time = 0;} IF (dashframe) {- Dashframe; Dashboard (GS); } / * Update sprites * / if (gs-> refresh_screen) {--GS-> refresh_screen; pig_refresh_all (gs-> pe);} else pig_refresh (GS-> PE); / * Make the new frame visible * / pog_flip (GS-> PE); / * Update statistics, Timers and stuff * / GS-> rendered_frames; gs-> lives_wobble_time = dt; gs-> score_wobble_time = dt; gs-> dashboard_time = dt; // Record the time convenient and final calculation last_thing = tick; // Nice seems to be a sign of an effect, and it is still not sure if (GS-> nice) SDL_DELAY (10);} / * print Some Statistics * / End_time = SDL_GETTICKS (); i = end_time - start_time; printf (" Total Time Running:% D MS / N ", I); if (! I) i = 1; Printf (" Average Rendering Frame Rate:% .2F FPS / N ", GS-> Rendered_Frames * 1000.0 / i); Printf ("Average Logic Frame Rate:% .2F FPS / N", GS-> Logic_Frames * 1000.0 / i); / / Release PIG Engine Pig_Close (GS-> PE); Return 0;} Note: Although the title of the form is set, there is no form generated by the form, is SDL automatically created a form? Or is it hidden in the undefiltrated code? I believe that the continuous development of the code should be more clear.