Skip to content

Commit

Permalink
fix: drag delay timer too big bug
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ran committed Jun 28, 2021
1 parent 6f33ea7 commit e23c566
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ int InputConvertGame::getTouchID(int key)
// -------- steer wheel event --------

void InputConvertGame::getDelayQueue(const QPointF& start, const QPointF& end,
const double& distanceStep, const double& posStepconst, const double& timerStep,
QQueue<QPointF>& queuePos, QQueue<double>& queueTimer) {
double timerBase = 5.0f; // ms
const double& distanceStep, const double& posStepconst,
quint32 lowestTimer, quint32 highestTimer,
QQueue<QPointF>& queuePos, QQueue<quint32>& queueTimer) {
double x1 = start.x();
double y1 = start.y();
double x2 = end.x();
Expand All @@ -262,11 +262,11 @@ void InputConvertGame::getDelayQueue(const QPointF& start, const QPointF& end,
dy/=e;

QQueue<QPointF> queue;
QQueue<double> queue2;
QQueue<quint32> queue2;
for(int i=1;i<=e;i++) {
QPointF pos(x1+(QRandomGenerator::global()->bounded(posStepconst*2)-posStepconst), y1+(QRandomGenerator::global()->bounded(posStepconst*2)-posStepconst));
queue.enqueue(pos);
queue2.enqueue(QRandomGenerator::global()->bounded(timerStep*2)-timerStep + timerBase);
queue2.enqueue(QRandomGenerator::global()->bounded(lowestTimer, highestTimer));
x1+=dx;
y1+=dy;
}
Expand Down Expand Up @@ -355,12 +355,12 @@ void InputConvertGame::processSteerWheel(const KeyMap::KeyMapNode &node, const Q
sendTouchDownEvent(id, node.data.steerWheel.centerPos);

getDelayQueue(node.data.steerWheel.centerPos, node.data.steerWheel.centerPos+offset,
0.01f, 0.002f, 3.0f,
0.01f, 0.002f, 2, 8,
m_ctrlSteerWheel.delayData.queuePos,
m_ctrlSteerWheel.delayData.queueTimer);
} else {
getDelayQueue(m_ctrlSteerWheel.delayData.currentPos, node.data.steerWheel.centerPos+offset,
0.01f, 0.002f, 3.0f,
0.01f, 0.002f, 2, 8,
m_ctrlSteerWheel.delayData.queuePos,
m_ctrlSteerWheel.delayData.queueTimer);
}
Expand Down Expand Up @@ -477,7 +477,7 @@ void InputConvertGame::processKeyDrag(const QPointF &startPos, QPointF endPos, c
m_dragDelayData.queuePos.clear();
m_dragDelayData.queueTimer.clear();
getDelayQueue(startPos, endPos,
0.01f, 0.002f, 2.0f,
0.01f, 0.002f, 0, 2,
m_dragDelayData.queuePos,
m_dragDelayData.queueTimer);
m_dragDelayData.timer->start();
Expand Down
9 changes: 5 additions & 4 deletions QtScrcpy/device/controller/inputconvert/inputconvertgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class InputConvertGame : public InputConvertNormal
void hideMouseCursor(bool hide);

void getDelayQueue(const QPointF& start, const QPointF& end,
const double& distanceStep, const double& posStepconst, const double& timerStep,
QQueue<QPointF>& queuePos, QQueue<double>& queueTimer);
const double& distanceStep, const double& posStepconst,
quint32 lowestTimer, quint32 highestTimer,
QQueue<QPointF>& queuePos, QQueue<quint32>& queueTimer);

protected:
void timerEvent(QTimerEvent *event);
Expand Down Expand Up @@ -97,7 +98,7 @@ private slots:
QPointF currentPos;
QTimer* timer = nullptr;
QQueue<QPointF> queuePos;
QQueue<double> queueTimer;
QQueue<quint32> queueTimer;
int pressedNum = 0;
} delayData;
} m_ctrlSteerWheel;
Expand All @@ -117,7 +118,7 @@ private slots:
QPointF currentPos;
QTimer* timer = nullptr;
QQueue<QPointF> queuePos;
QQueue<double> queueTimer;
QQueue<quint32> queueTimer;
int pressKey = 0;
} m_dragDelayData;
};
Expand Down

0 comments on commit e23c566

Please sign in to comment.