|
From: Tapio V. <aa...@us...> - 2010-05-17 19:45:48
|
Module: performous
Branch: master
Commit: 4024ea60adccf2ef75f9080cf617c0dc0f405f36
Author: Tapio Vierros <tap...@gm...>
Date: Mon May 17 22:41:50 2010 +0300
Moved all #ifdef USE_OPENCV stuff inside webcam files (prettier screen_sing).
If you have trouble compiling with OpenCV disabled
(should be no trouble), fix things in webcam.hh/.cc
---
game/main.cc | 6 +-----
game/screen_sing.cc | 34 +++++++++++++---------------------
game/screen_sing.hh | 6 ------
game/webcam.cc | 2 ++
game/webcam.hh | 9 +++++++++
5 files changed, 25 insertions(+), 32 deletions(-)
diff --git a/game/main.cc b/game/main.cc
index 4af988a..d3a432a 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -422,10 +422,6 @@ void outputOptionalFeatureStatus() {
"Disabled"
#endif
<< std::endl << " Webcam support: " <<
- #ifdef USE_OPENCV
- "Enabled"
- #else
- "Disabled"
- #endif
+ (Webcam::enabled() ? "Enabled" : "Disabled")
<< std::endl;
}
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 2236b32..c206d55 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -56,17 +56,16 @@ void ScreenSing::enter() {
std::cerr << e.what() << std::endl;
}
}
-
-#ifdef USE_OPENCV
- if (config["graphic/webcam"].b()) { // Initialize webcam
+ // Initialize webcam
+ if (config["graphic/webcam"].b() && Webcam::enabled()) {
m_cam.reset(new Webcam());
}
-#endif
-
- if (!m_song->video.empty() && config["graphic/video"].b()) { // Load video
+ // Load video
+ if (!m_song->video.empty() && config["graphic/video"].b()) {
m_video.reset(new Video(m_song->path + m_song->video, m_song->videoGap));
}
- if (!foundbg) { // Use random bg if specified fails (also for tracks with video)
+ // Use random bg if specified fails (also for tracks with video)
+ if (!foundbg) {
for (int i = 1; i <= 2; ++i) { // Try two times in case first is b0rked
try {
std::string bgpath = m_backgrounds.getRandom();
@@ -182,9 +181,7 @@ void ScreenSing::exit() {
m_engine.reset();
m_help.reset();
m_pause_icon.reset();
-#ifdef USE_OPENCV
m_cam.reset();
-#endif
m_video.reset();
m_background.reset();
m_song->dropNotes();
@@ -253,13 +250,11 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_v) m_audio.streamFade("vocals", event.key.keysym.mod & KMOD_SHIFT ? 1.0 : 0.0);
if (key == SDLK_k) dispInFlash(++config["game/karaoke_mode"]); // Toggle karaoke mode
if (key == SDLK_w) dispInFlash(++config["game/pitch"]); // Toggle pitch wave
- #ifdef USE_OPENCV
// Toggle webcam
- if (key == SDLK_a) {
- if (!m_cam) m_cam.reset(new Webcam());
+ if (key == SDLK_a && Webcam::enabled()) {
+ if (!m_cam) m_cam.reset(new Webcam()); // Initialize if we haven't done that already
if (m_cam) { dispInFlash(++config["graphic/webcam"]); m_cam->pause(!config["graphic/webcam"].b()); }
}
- #endif
// Latency settings
if (key == SDLK_F1) dispInFlash(--config["audio/video_delay"]);
if (key == SDLK_F2) dispInFlash(++config["audio/video_delay"]);
@@ -310,21 +305,18 @@ void ScreenSing::draw() {
// Rendering starts
{
double ar = arMax;
+ // Background image
if (m_background) {
ar = m_background->dimensions.ar();
if (ar > arMax || (m_video && ar > arMin)) fillBG(); // Fill white background to avoid black borders
m_background->draw();
- } else fillBG();
+ } else fillBG(); // Blank
// Video
- if (m_video
- #ifdef USE_OPENCV
- && (!m_cam || !m_cam->is_good())
- #endif
- ) { m_video->render(time); double tmp = m_video->dimensions().ar(); if (tmp > 0.0) ar = tmp; }
-#ifdef USE_OPENCV
+ if (m_video && (!m_cam || !m_cam->is_good())) {
+ m_video->render(time); double tmp = m_video->dimensions().ar(); if (tmp > 0.0) ar = tmp;
+ }
// Webcam
if (m_cam && config["graphic/webcam"].b()) m_cam->render();
-#endif
// Top/bottom borders
ar = clamp(ar, arMin, arMax);
double offset = 0.5 / ar + 0.2;
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index 53439bd..5ba012d 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -15,11 +15,7 @@
#include "surface.hh"
#include "opengl_text.hh"
#include "progressbar.hh"
-
-#ifdef USE_OPENCV
#include "webcam.hh"
-#endif
-
#include "screen_players.hh"
class Players;
@@ -85,9 +81,7 @@ class ScreenSing: public Screen {
boost::scoped_ptr<ProgressBar> m_progress;
boost::scoped_ptr<Surface> m_background;
boost::scoped_ptr<Video> m_video;
-#ifdef USE_OPENCV
boost::scoped_ptr<Webcam> m_cam;
-#endif
boost::scoped_ptr<Surface> m_pause_icon;
boost::scoped_ptr<Surface> m_help;
boost::scoped_ptr<Engine> m_engine;
diff --git a/game/webcam.cc b/game/webcam.cc
index 31bc263..c4487c5 100644
--- a/game/webcam.cc
+++ b/game/webcam.cc
@@ -50,7 +50,9 @@ void Webcam::operator()() {
}
void Webcam::pause(bool do_pause) {
+ #ifdef USE_OPENCV
boost::mutex::scoped_lock l(m_mutex);
+ #endif
m_running = !do_pause;
m_frameAvailable = false;
}
diff --git a/game/webcam.hh b/game/webcam.hh
index 8c39c62..6ed0585 100644
--- a/game/webcam.hh
+++ b/game/webcam.hh
@@ -49,4 +49,13 @@ class Webcam {
bool m_frameAvailable;
volatile bool m_running;
volatile bool m_quit;
+
+ public:
+ static bool enabled() {
+ #ifdef USE_OPENCV
+ return true;
+ #else
+ return false;
+ #endif
+ }
};
|