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

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

Merge "Fountain update. Update field names to match legacy expectations. Cleanup java code."

parents 40ac2e6d 96d3749e
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@ rs_mesh partMesh;

typedef struct __attribute__((packed, aligned(4))) Point_s {
    float2 delta;
    rs_position2 pos;
    rs_color4u color;
    float2 position;
    uchar4 color;
} Point_t;
Point_t *point;

@@ -28,8 +28,8 @@ int root() {
    Point_t * p = point;
    for (int ct=0; ct < size; ct++) {
        p->delta.y += 0.15f;
        p->pos += p->delta;
        if ((p->pos.y > height) && (p->delta.y > 0)) {
        p->position += p->delta;
        if ((p->position.y > height) && (p->delta.y > 0)) {
            p->delta.y *= -0.3f;
        }
        p++;
@@ -42,16 +42,18 @@ int root() {

void addParticles(int rate, int x, int y)
{
    rsDebug("partColor", partColor);
    rsDebug("partColor x", partColor.x);
    rsDebug("partColor y", partColor.y);
    rsDebug("partColor z", partColor.z);
    rsDebug("partColor w", partColor.w);
    //rsDebug("partColor", partColor);
    //rsDebug("partColor x", partColor.x);
    //rsDebug("partColor y", partColor.y);
    //rsDebug("partColor z", partColor.z);
    //rsDebug("partColor w", partColor.w);

    float rMax = ((float)rate) * 0.005f;
    int size = rsAllocationGetDimX(rsGetAllocation(point));

    rs_color4u c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);
    uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);

    //rsDebug("color ", ((int *)&c)[0]);
    Point_t * np = &point[newPart];

    float2 p = {x, y};
@@ -60,7 +62,7 @@ void addParticles(int rate, int x, int y)
        float len = rsRand(rMax);
        np->delta.x = len * sin(angle);
        np->delta.y = len * cos(angle);
        np->pos = p;
        np->position = p;
        np->color = c;
        newPart++;
        np++;
+21 −37
Original line number Diff line number Diff line
@@ -27,26 +27,36 @@ public class FountainRS {
    public FountainRS() {
    }

    private Resources mRes;
    private RenderScriptGL mRS;
    private ScriptC_Fountain mScript;
    public void init(RenderScriptGL rs, Resources res, int width, int height) {
        mRS = rs;
        mRes = res;
        initRS();

        ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);

        SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
        int vtxSlot = smb.addVertexType(points.getType());
        smb.setPrimitive(Primitive.POINT);
        SimpleMesh sm = smb.create();
        sm.bindVertexAllocation(points.getAllocation(), vtxSlot);

        mScript = new ScriptC_Fountain(mRS, mRes, true);
        mScript.set_partMesh(sm);
        mScript.bind_point(points);
        mRS.contextBindRootScript(mScript);
    }

    Float4 tmpColor = new Float4();
    boolean holdingColor = false;
    java.util.Random mRand = new java.util.Random();
    public void newTouchPosition(int x, int y, int rate) {
        if (rate > 0) {
            if (true/*!holdingColor*/) {
                tmpColor.x = ((x & 0x1) != 0) ? 0.f : 1.f;
                tmpColor.y = ((x & 0x2) != 0) ? 0.f : 1.f;
                tmpColor.z = ((x & 0x4) != 0) ? 0.f : 1.f;
                if ((tmpColor.x + tmpColor.y + tmpColor.z) < 0.9f) {
                    tmpColor.x = 0.8f;
                    tmpColor.y = 0.5f;
                    tmpColor.z = 1.0f;
                }
                android.util.Log.e("rs", "set color " + tmpColor.x + ", " + tmpColor.y + ", " + tmpColor.z);
            if (!holdingColor) {
                tmpColor.x = mRand.nextFloat() * 0.5f + 0.5f;
                tmpColor.y = mRand.nextFloat();
                tmpColor.z = mRand.nextFloat();
                mScript.set_partColor(tmpColor);
            }
            mScript.invokable_addParticles(rate, x, y);
@@ -56,32 +66,6 @@ public class FountainRS {
        }

    }


    /////////////////////////////////////////

    private Resources mRes;

    private ScriptField_Point mPoints;
    private ScriptC_Fountain mScript;
    private RenderScriptGL mRS;
    private SimpleMesh mSM;

    private void initRS() {
        mPoints = new ScriptField_Point(mRS, PART_COUNT);

        SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
        int vtxSlot = smb.addVertexType(mPoints.getType());
        smb.setPrimitive(Primitive.POINT);
        mSM = smb.create();
        mSM.bindVertexAllocation(mPoints.getAllocation(), vtxSlot);

        mScript = new ScriptC_Fountain(mRS, mRes, true);
        mScript.set_partMesh(mSM);
        mScript.bind_point(mPoints);
        mRS.contextBindRootScript(mScript);
    }

}

+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ public class ScriptField_Point

        Element.Builder eb = new Element.Builder(rs);
        eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta");
        eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "pos");
        eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position");
        eb.add(Element.createAttrib(rs, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
        mElement = eb.create();