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