|
From: Tapio V. <aa...@us...> - 2010-05-16 16:31:06
|
Module: performous
Branch: instrumentgraph
Commit: 9866cca05a8ec52bc1e85c0850122700e923cf1b
Author: Tapio Vierros <tap...@gm...>
Date: Sun May 9 21:24:56 2010 +0300
Webcam can be disabled from config or toggled during gameplay.
---
data/schema.xml | 6 ++++++
game/screen_sing.cc | 14 ++++++++++----
game/screen_sing.hh | 4 ++--
game/webcam.cc | 2 +-
game/webcam.hh | 1 +
5 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index 42a49f3..1eea68e 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -118,6 +118,12 @@ to save the current settings to XML.
<long>Allows completely disabling background videos. It is recommended to leave this enabled as Performous will still smoothly fade out the video if your computer is not fast enough.</long>
</locale>
</entry>
+ <entry name="graphic/webcam" type="bool" value="true">
+ <locale name="C">
+ <short>Webcam background</short>
+ <long>Performous can try to use webcam as a background video. You can disable it if it annoys you.</long>
+ </locale>
+ </entry>
<entry name="graphic/3d_notes" type="bool" value="true">
<locale name="C">
<short>3D notes</short>
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 8b0f914..d7e18e2 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -56,6 +56,9 @@ void ScreenSing::enter() {
std::cerr << e.what() << std::endl;
}
}
+ if (config["graphic/webcam"].b()) { // Initialize webcam
+ m_cam.reset(new Webcam());
+ }
if (!m_song->video.empty() && config["graphic/video"].b()) { // Load video
m_video.reset(new Video(m_song->path + m_song->video, m_song->videoGap));
}
@@ -175,6 +178,7 @@ void ScreenSing::exit() {
m_engine.reset();
m_help.reset();
m_pause_icon.reset();
+ m_cam.reset();
m_video.reset();
m_background.reset();
m_song->dropNotes();
@@ -243,6 +247,7 @@ 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
+ if (key == SDLK_a) dispInFlash(++config["graphic/webcam"]); // Toggle webcam
// Latency settings
if (key == SDLK_F1) dispInFlash(--config["audio/video_delay"]);
if (key == SDLK_F2) dispInFlash(++config["audio/video_delay"]);
@@ -298,7 +303,11 @@ void ScreenSing::draw() {
if (ar > arMax || (m_video && ar > arMin)) fillBG(); // Fill white background to avoid black borders
m_background->draw();
} else fillBG();
- if (m_video) { m_video->render(time); double tmp = m_video->dimensions().ar(); if (tmp > 0.0) ar = tmp; }
+ // Video
+ if (m_video && !m_cam && !(*m_cam)()) { 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(time);
+ // Top/bottom borders
ar = clamp(ar, arMin, arMax);
double offset = 0.5 / ar + 0.2;
theme->bg_bottom.dimensions.fixedWidth(1.0).bottom(offset);
@@ -307,9 +316,6 @@ void ScreenSing::draw() {
theme->bg_top.draw();
}
- // Webcam image
- m_cam.render(time);
-
if( !m_dancers.empty() ) {
danceLayout(time);
//m_layout_singer->draw(time, LayoutSinger::LEFT);
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index b7e4f68..e73eb17 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -50,7 +50,7 @@ class ScreenSing: public Screen {
public:
/// constructor
ScreenSing(std::string const& name, Audio& audio, Capture& capture, Database& database, Backgrounds& bgs):
- Screen(name), m_audio(audio), m_capture(capture), m_database(database), m_backgrounds(bgs), m_latencyAV(), m_only_singers_alive(true), m_cam()
+ Screen(name), m_audio(audio), m_capture(capture), m_database(database), m_backgrounds(bgs), m_latencyAV(), m_only_singers_alive(true)
{}
void enter();
void exit();
@@ -81,6 +81,7 @@ class ScreenSing: public Screen {
boost::scoped_ptr<ProgressBar> m_progress;
boost::scoped_ptr<Surface> m_background;
boost::scoped_ptr<Video> m_video;
+ boost::scoped_ptr<Webcam> m_cam;
boost::scoped_ptr<Surface> m_pause_icon;
boost::scoped_ptr<Surface> m_help;
boost::scoped_ptr<Engine> m_engine;
@@ -91,6 +92,5 @@ class ScreenSing: public Screen {
boost::shared_ptr<ThemeSing> theme;
AnimValue m_quitTimer;
bool m_only_singers_alive;
- Webcam m_cam;
};
diff --git a/game/webcam.cc b/game/webcam.cc
index 51cbb00..5595309 100644
--- a/game/webcam.cc
+++ b/game/webcam.cc
@@ -14,7 +14,7 @@ Webcam::Webcam(int cam_id): m_capture(NULL), m_timestamp(0) {
void Webcam::render(double time) {
if (!m_capture) return;
IplImage* frame = 0;
- if (time > m_timestamp + 0.333) {
+ if (time > m_timestamp + 0.5) {
frame = cvQueryFrame(m_capture);
if (!frame) return;
m_surface.load(frame->width, frame->height, pix::RGB, (const unsigned char*)frame->imageData);
diff --git a/game/webcam.hh b/game/webcam.hh
index 33caad1..e1b7ce4 100644
--- a/game/webcam.hh
+++ b/game/webcam.hh
@@ -6,6 +6,7 @@
class Webcam {
public:
+ /// cam_id -1 means pick any device
Webcam(int cam_id = -1);
~Webcam() { cvReleaseCapture(&m_capture); }
|