[PATCH 05/14] QtMaze: use accelerometer callback instead of running own timer
Neil Jerram
neil at ossau.homelinux.net
Sun Jul 29 20:34:43 CEST 2012
---
src/3rdparty/games/qtmaze/form.cpp | 23 ++++++++++-------------
src/3rdparty/games/qtmaze/form.h | 5 +++--
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/3rdparty/games/qtmaze/form.cpp b/src/3rdparty/games/qtmaze/form.cpp
index f021414..c02c97a 100644
--- a/src/3rdparty/games/qtmaze/form.cpp
+++ b/src/3rdparty/games/qtmaze/form.cpp
@@ -195,15 +195,10 @@ void Form::apply_temp_phys_res()
post_phys_res(tmp_px,tmp_py, tmp_vx,tmp_vy);
}
-void Form::tout()
+void Form::tout(double ax, double ay)
{
- //printf("[acc] %.4f %.4f %.4f\n", getacx(), getacy(), getacz());
-
new_game_state = GAME_STATE_NORMAL;
- double ax = getacx();
- double ay = getacy();
-
double mid_px=px, mid_py=py;
double mid_vx=vx, mid_vy=vy;
@@ -537,13 +532,13 @@ void Form::MoveBall(double x, double y)
ballshadow_lbl->move(lpx+shadow_shift, lpy+shadow_shift);
}
-void Form::acc_timerAction()
+void Form::acc_timerAction(double acx, double acy)
{
if (!fullscreen) return;
if (game_state == GAME_STATE_NORMAL)
{
- tout();
+ tout(acx, acy);
if (game_state != GAME_STATE_NORMAL)
{
int bshift = (qt_game_config.hole_r - qt_game_config.ball_r) / 3;
@@ -854,15 +849,11 @@ Form::Form(QWidget *parent, Qt::WFlags f)
info1_lbl->setText( "<font color=\"#e0bc70\" size=\"" FONT_SIZE "\">Touch the screen to continue</font>" );
InitState();
- accelerometer_start(0, NULL, NULL);
+ accelerometer_start(PROC_ACC_DATA_INTERVAL, Form::accel_callback, this);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timerAction()));
- QTimer *acc_timer = new QTimer(this);
- connect(acc_timer, SIGNAL(timeout()), this, SLOT(acc_timerAction()));
- acc_timer->start(PROC_ACC_DATA_INTERVAL);
-
installEventFilter(this);
this->levelno_lbl->installEventFilter(this);
this->info1_lbl->installEventFilter(this);
@@ -884,3 +875,9 @@ Form::~Form()
{
// no need to delete child widgets, Qt does it all for us
}
+
+void Form::accel_callback(void *closure, double acx, double acy, double acz)
+{
+ Form *form = (Form *)closure;
+ form->acc_timerAction(acx, acy);
+}
diff --git a/src/3rdparty/games/qtmaze/form.h b/src/3rdparty/games/qtmaze/form.h
index 9af8422..68f2e17 100644
--- a/src/3rdparty/games/qtmaze/form.h
+++ b/src/3rdparty/games/qtmaze/form.h
@@ -49,12 +49,14 @@ private:
void ProcessGameState();
int testbump(double x,double y, double mm_vx,double mm_vy);
int edgebump(int tx,int ty, double x,double y, double mm_vx,double mm_vy);
- void tout();
+ void tout(double ax, double ay);
void apply_temp_phys_res();
void post_temp_phys_res(double x, double y, double mm_vx, double mm_vy);
void post_phys_res(double x, double y, double mm_vx, double mm_vy);
void BumpVibrate(double speed);
void setButtonsPics();
+ void acc_timerAction(double acx, double acy);
+ static void accel_callback(void *closure, double acx, double acy, double acz);
public:
Form( QWidget *parent = 0, Qt::WFlags f = 0 );
@@ -62,7 +64,6 @@ public:
private slots:
void timerAction();
- void acc_timerAction();
bool eventFilter(QObject *target, QEvent *event);
void ScreenTouchedPause();
void ScreenTouchedContinue();
--
1.7.10.4
--=-=-=--
More information about the community
mailing list