Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ccc75fa authored by Jason Sams's avatar Jason Sams Committed by Android (Google) Code Review
Browse files

Merge "Add multitouch support to physics test. Fix context state overwrite calling invoke."

parents 45f1e08c 4859f523
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -129,9 +129,7 @@ public class BallsRS {
    }

    public void newTouchPosition(float x, float y, float pressure, int id) {
        mPhysicsScript.set_touchX(x);
        mPhysicsScript.set_touchY(y);
        mPhysicsScript.set_touchPressure(pressure);
        mPhysicsScript.invoke_touch(x, y, pressure, id);
    }

    public void setAccel(float x, float y) {
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class BallsView extends RSSurfaceView {
            int pointerIndex = ev.getActionIndex();
            int pointerId = ev.getPointerId(pointerIndex);
            mRender.newTouchPosition(0, 0, 0, pointerId);
            return false;
        }
        int count = ev.getHistorySize();
        int pcount = ev.getPointerCount();
+17 −21
Original line number Diff line number Diff line
@@ -8,18 +8,22 @@ float2 gGravityVector = {0.f, 9.8f};
float2 gMinPos = {0.f, 0.f};
float2 gMaxPos = {1280.f, 700.f};

float touchX;
float touchY;
float touchPressure = 0.f;
static float2 touchPos[10];
static float touchPressure[10];

void setGamma(float g) {
void touch(float x, float y, float pressure, int id) {
    if (id >= 10) {
        return;
    }

    touchPos[id].x = x;
    touchPos[id].y = y;
    touchPressure[id] = pressure;
}

void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint32_t x) {
    float2 fv = {0, 0};
    float2 pos = ballIn->position;
    //rsDebug("physics pos in", pos);

    int arcID = -1;
    float arcInvStr = 100000;
@@ -38,10 +42,6 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
            if (len2 > 16 /* (minDist*minDist)*/)  {
                // Repulsion
                float len = sqrt(len2);
                //if (len < arcInvStr) {
                    //arcInvStr = len;
                    //arcID = xin;
                //}
                fv -= (vec / (len * len * len)) * 20000.f * forceScale;
            } else {
                if (len2 < 1) {
@@ -78,12 +78,13 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
    fv -= gGravityVector * 4.f;
    fv *= ctl->dt;

    if (touchPressure > 0.1f) {
        float2 tp = {touchX, touchY};
        float2 vec = tp - ballIn->position;
    for (int i=0; i < 10; i++) {
        if (touchPressure[i] > 0.1f) {
            float2 vec = touchPos[i] - ballIn->position;
            float2 vec2 = vec * vec;
            float len2 = max(2.f, vec2.x + vec2.y);
        fv -= (vec / len2) * touchPressure * 400.f;
            fv -= (vec / len2) * touchPressure[i] * 300.f;
        }
    }

    ballOut->delta = (ballIn->delta * (1.f - 0.004f)) + fv;
@@ -138,11 +139,6 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
        }
    }

    //ballOut->color.b = 1.f;
    //ballOut->color.r = min(sqrt(length(ballOut->delta)) * 0.1f, 1.f);
    //ballOut->color.g = min(sqrt(length(fv) * 0.1f), 1.f);
    //ballOut->arcID = arcID;
    //ballOut->arcStr = 8 / arcInvStr;
    ballOut->size = ballIn->size;

    //rsDebug("physics pos out", ballOut->position);
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ ScriptC::~ScriptC() {
}

void ScriptC::setupScript(Context *rsc) {
    setupGLState(rsc);
    mEnviroment.mStartTimeMillis
                = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));

@@ -123,6 +122,7 @@ uint32_t ScriptC::run(Context *rsc) {
        return 0;
    }

    setupGLState(rsc);
    setupScript(rsc);

    uint32_t ret = 0;
@@ -278,6 +278,7 @@ void ScriptC::runForEach(Context *rsc,

    rsAssert(ain->getType()->getDimZ() == 0);

    setupGLState(rsc);
    setupScript(rsc);
    Script * oldTLS = setTLS(this);

@@ -336,7 +337,6 @@ void ScriptC::runForEach(Context *rsc,
}

void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) {
    //LOGE("rsi_ScriptInvoke %i", slot);
    if ((slot >= mEnviroment.mInvokeFunctionCount) ||
        (mEnviroment.mInvokeFunctions[slot] == NULL)) {
        rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");