Advertisement
Guest User

Loop

a guest
Jan 3rd, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. void Window_Run(TGUIWindow *AWindow)
  2. {
  3.   TIterator *BIteratorWidget = NULL;
  4.   TGUIWidget *BClientWidget = NULL;
  5.   double BTime = glfwGetTime();
  6.   unsigned int BFrames = 0;
  7.   long BDiff = 0;
  8.  
  9.   struct timespec BRenderingClockLast;
  10.   struct timespec BRenderingClockCurrent;
  11.   clock_gettime(CLOCK_REALTIME, &BRenderingClockLast);
  12.  
  13.   TGUIWidgetProperties *BWidgetProperties = NULL;
  14.   AWindow->FRunning = TRUE;
  15.   glfwGetWindowSize(AWindow->FGLFW_Window, &AWindow->FWidth, &AWindow->FHeight);
  16.   #ifdef GUI_DEBUG_MODE
  17.   printf("[MESSAGE] Running window.\n");
  18.   #endif
  19.  
  20.   Window_ResolveAlignment(AWindow);
  21.   glfwShowWindow(AWindow->FGLFW_Window);
  22.   while (!glfwWindowShouldClose(AWindow->FGLFW_Window))
  23.   {
  24.     glfwPollEvents();
  25.  
  26.     clock_gettime(CLOCK_REALTIME, &BRenderingClockCurrent);
  27.     BDiff = time_diff(&BRenderingClockCurrent, &BRenderingClockLast);
  28.     if (BDiff > 16.666666667)
  29.     {
  30.       clock_gettime(CLOCK_REALTIME, &BRenderingClockLast);
  31.       Window_Render(AWindow);
  32.       glfwSwapBuffers(AWindow->FGLFW_Window);
  33.     };
  34.     BFrames++;
  35.    
  36.     if (glfwGetTime() - BTime >= 1)
  37.     {
  38.       #ifdef GUI_DEBUG_MODE
  39.       if ((BFrames < 59) || (AWindow->FRenderingFrameRate < 59))
  40.       {
  41.         // This message is printed only if the frame-rate is bellow the normal.
  42.         printf("[MESSAGE] Process frame-rate: %i frames per second.\n", BFrames);
  43.         printf("[MESSAGE] Rendering frame-rate: %i frames per second.\n", AWindow->FRenderingFrameRate);
  44.       };
  45.       #endif
  46.       AWindow->FRenderingFrameRate = 0;
  47.       BFrames = 0;
  48.       BTime = glfwGetTime();
  49.     };
  50.   };
  51.   #ifdef GUI_DEBUG_MODE
  52.   printf("[MESSAGE] Finishing window.\n");
  53.   #endif
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement