summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Young <rcxdude@gmail.com>2008-06-22 17:14:02 +0100
committerDouglas Young <rcxdude@gmail.com>2008-06-22 17:14:02 +0100
commit0a43af785048a90b7b1a41d4ea062653a53a4061 (patch)
tree5d575024b8ae7a7dae13b2bff87ae9087f8e06e7
parent5980f53848e469cf577da24425137f532334f8b6 (diff)
downloaddodge-0a43af785048a90b7b1a41d4ea062653a53a4061.tar.gz
dodge-0a43af785048a90b7b1a41d4ea062653a53a4061.tar.bz2
further fix algorithm to stop high CPU usage when enabled
-rw-r--r--dodge.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/dodge.c b/dodge.c
index d7c55b1..5bc3e9a 100644
--- a/dodge.c
+++ b/dodge.c
@@ -48,6 +48,8 @@ typedef struct _DodgeWindow
{
float vx; /* velocity */
float vy;
+ float x; /* position as float */
+ float y;
int ox; /* original position */
int oy;
@@ -235,6 +237,7 @@ dodgestep (CompWindow *w, int ms, int away)
break;
}
+
/* apply friction */
dw->vx -= FRICTION * dw->vx * ms;
dw->vy -= FRICTION * dw->vy * ms;
@@ -252,15 +255,18 @@ dodgestep (CompWindow *w, int ms, int away)
if (dw->vx > w->screen->width || dw->vx < 0 - w->screen->width ||
dw->vy > w->screen->height || dw->vx < 0 - w->screen->height)
dw->vx = dw->vy = 0;
-
- /* if there's enough velocity, move the window */
- if (fabs(dw->vx)*ms >= 1 || fabs(dw->vy)*ms >= 1)
+
+ dw->x += dw->vx * ms;
+ dw->y += dw->vy * ms;
+ /* if there's enough differenc, move the window */
+ if (fabs(dw->x - WIN_X(w)) >= 1 || fabs(dw->y - WIN_Y(w)) >= 1)
{
- moveWindow (w,dw->vx*ms,dw->vy*ms,TRUE,TRUE);
+ moveWindow (w,(int) dw->x - WIN_X(w),
+ (int) dw->y - WIN_Y(w),TRUE,TRUE);
syncWindowPosition (w);
ds->moreAdjust = TRUE;
}
- if (dy || dx || dw->vx > 0.03 || dw->vy > 0.03)
+ if ((dy || dx) && !ds->model == ModelSimpleAvoid)
{
ds->moreAdjust = TRUE;
}
@@ -338,6 +344,8 @@ dodgeUpdateDodgeWindow (CompWindow *w)
dw->isdodge = TRUE;
dw->vx = 0;
dw->vy = 0;
+ dw->x = (float) WIN_X(w);
+ dw->y = (float) WIN_Y(w);
/* don't change original position if dodge is active */
if (!ds->active || !(dw->ox || dw->oy))
{