Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.0KB

  1. /**
  2. * projectM -- Milkdrop-esque visualisation SDK
  3. * Copyright (C)2003-2021 projectM Team
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. * See 'LICENSE.txt' included within this release
  19. *
  20. * projectM-sdl
  21. * This is an implementation of projectM using libSDL2
  22. *
  23. * main.cpp
  24. * Authors: Created by Mischa Spiegelmock on 6/3/15.
  25. *
  26. *
  27. * RobertPancoast77@gmail.com :
  28. * experimental Stereoscopic SBS driver functionality
  29. * WASAPI looback implementation
  30. *
  31. *
  32. */
  33. #include "pmSDL.hpp"
  34. static int mainLoop(void *userData) {
  35. projectMSDL **appRef = (projectMSDL **)userData;
  36. auto app = *appRef;
  37. #if UNLOCK_FPS
  38. auto start = startUnlockedFPSCounter();
  39. #endif
  40. // frame rate limiter
  41. int fps = app->settings()->fps;
  42. if (fps <= 0)
  43. fps = 60;
  44. const Uint32 frame_delay = 1000/fps;
  45. Uint32 last_time = SDL_GetTicks();
  46. // loop
  47. while (! app->done) {
  48. // render
  49. app->renderFrame();
  50. if (app->fakeAudio)
  51. app->addFakePCM();
  52. processLoopbackFrame(app);
  53. #if UNLOCK_FPS
  54. advanceUnlockedFPSCounterFrame(start);
  55. #else
  56. app->pollEvent();
  57. Uint32 elapsed = SDL_GetTicks() - last_time;
  58. if (elapsed < frame_delay)
  59. SDL_Delay(frame_delay - elapsed);
  60. last_time = SDL_GetTicks();
  61. #endif
  62. }
  63. return 0;
  64. }
  65. int main(int argc, char *argv[]) {
  66. projectMSDL *app = setupSDLApp();
  67. int status = mainLoop(&app);
  68. // SDL_Thread *mainLoopThread;
  69. // int threadReturnValue;
  70. //
  71. // mainLoopThread = SDL_CreateThread(mainLoop, "MainLoop", &app);
  72. //
  73. // if (NULL == mainLoopThread) {
  74. // printf("SDL_CreateThread failed: %s\n", SDL_GetError());
  75. // return PROJECTM_ERROR;
  76. // } else {
  77. // SDL_WaitThread(mainLoopThread, &threadReturnValue);
  78. // printf("Thread returned value: %d\n", threadReturnValue);
  79. // }
  80. // Write back config with current app settings (if we loaded from a config file to begin with)
  81. std::string configFilePath = getConfigFilePath(DATADIR_PATH);
  82. if (!configFilePath.empty()) {
  83. projectm_write_config(configFilePath.c_str(), app->settings());
  84. }
  85. // cleanup
  86. SDL_GL_DeleteContext(app->glCtx);
  87. #if !FAKE_AUDIO
  88. if (!app->wasapi) // not currently using WASAPI, so we need to endAudioCapture.
  89. app->endAudioCapture();
  90. #endif
  91. delete app;
  92. return status;
  93. }