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

Commit 381d7028 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 21750 into eclair

* changes:
  Tweak the galaxy
parents 3f648af2 cac80a6e
Loading
Loading
Loading
Loading
−244 B (413 B)
Loading image diff...
+15 −12
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@

#define PARTICLES_TEXTURES_COUNT 2

#define ELLIPSE_RATIO 0.86f
#define ELLIPSE_RATIO 0.892f
#define ELLIPSE_TWIST 0.02333333333f

void drawSpace(int width, int height) {
@@ -47,15 +47,18 @@ void drawSpace(int width, int height) {
}

void drawLights(int width, int height) {
    float x = (width - 512.0f) / 2.0f;
    float y = (height - 512.0f) / 2.0f;
    float x = (width - 512.0f) * 0.5f;
    float y = (height - 512.0f) * 0.5f;
    
    // increase the size of the texture by 5% on each side
    x -= 512.0f * 0.05f;

    bindProgramFragment(NAMED_PFBackground);
    bindTexture(NAMED_PFBackground, 0, NAMED_TLight1);
    drawQuad(x + 512.0f, y         , 0.0f,
    drawQuad(x + 512.0f * 1.1f, y         , 0.0f,
             x                , y         , 0.0f,
             x                , y + 512.0f, 0.0f,
             x + 512.0f, y + 512.0f, 0.0f);
             x + 512.0f * 1.1f, y + 512.0f, 0.0f);
}

void drawParticle(float *particle, int index, float *particleBuffer, int bufferIndex,
@@ -67,11 +70,11 @@ void drawParticle(float *particle, int index, float *particleBuffer, int bufferI
    float r = particle[index + PARTICLE_STRUCT_RADIUS];

    float a = angle + speed;
    float x = distance * sinf(a);
    float y = distance * cosf(a) * ELLIPSE_RATIO;
    float x = distance * sinf_fast(a);
    float y = distance * cosf_fast(a) * ELLIPSE_RATIO;
    float z = distance * ELLIPSE_TWIST;
    float s = cosf(z);
    float t = sinf(z);
    float s = cosf_fast(z);
    float t = sinf_fast(z);

    float sX = t * x + s * y + w;
    float sY = s * x - t * y + h;
+10 −12
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ class GalaxyRS {
    private static final int RSID_STATE = 0;

    private static final int TEXTURES_COUNT = 3;
    private static final int PARTICLES_TEXTURES_COUNT = 2;
    private static final int RSID_TEXTURE_SPACE = 0;
    private static final int RSID_TEXTURE_LIGHT1 = 1;
    private static final int RSID_TEXTURE_FLARES = 2;
@@ -216,13 +215,15 @@ class GalaxyRS {

    @SuppressWarnings({"PointlessArithmeticExpression"})
    private void createParticle(float[] particles, int index, int bufferIndex) {
        float d = abs(randomGauss()) * GALAXY_RADIUS / 2.0f;
        float d = abs(randomGauss()) * GALAXY_RADIUS / 2.0f + random(-4.0f, 4.0f);
        float z = randomGauss() * 0.5f * 0.8f * ((GALAXY_RADIUS - d) / (float) GALAXY_RADIUS);
        z += 1.0f;

        particles[index + PARTICLE_STRUCT_ANGLE] = random(0.0f, (float) (Math.PI * 2.0));
        particles[index + PARTICLE_STRUCT_DISTANCE] = d;
        particles[index + PARTICLE_STRUCT_SPEED] = random(0.0015f, 0.0025f) *
                (0.5f + (0.5f * (float) GALAXY_RADIUS / d));
        particles[index + PARTICLE_STRUCT_RADIUS] = random(1.0f, 2.1f);
                (0.5f + (0.5f * (float) GALAXY_RADIUS / d)) * 0.7f;
        particles[index + PARTICLE_STRUCT_RADIUS] = z * random(1.2f, 2.1f);

        int red, green, blue;
        if (d < GALAXY_RADIUS / 3.0f) {
@@ -235,26 +236,23 @@ class GalaxyRS {
            blue = (int) constrain(140 + (d / (float) GALAXY_RADIUS) * 115, 140, 255);
        }
        
        final int color = 0xFF000000 | red | green << 8 | blue << 16;
        final int sprite = random(PARTICLES_TEXTURES_COUNT);        
        final float u1 = sprite / (float) PARTICLES_TEXTURES_COUNT;
        final float u2 = (sprite + 1) / (float) PARTICLES_TEXTURES_COUNT;
        final int color = red | green << 8 | blue << 16 | 0xff000000;

        final float[] floatData = mFloatData5;
        final Allocation buffer = mParticlesBuffer;
        
        floatData[0] = Float.intBitsToFloat(color);
        floatData[3] = u1;
        floatData[3] = 0.0f;
        floatData[4] = 1.0f;
        buffer.subData1D(bufferIndex, 1, floatData);

        bufferIndex++;
        floatData[3] = u2;
        floatData[3] = 1.0f;
        floatData[4] = 1.0f;
        buffer.subData1D(bufferIndex, 1, floatData);

        bufferIndex++;
        floatData[3] = u1 + (u2 - u1) / 2.0f;
        floatData[3] = 0.5f;
        floatData[4] = 0.0f;
        buffer.subData1D(bufferIndex, 1, floatData);
    }
+42 −0
Original line number Diff line number Diff line
@@ -170,6 +170,44 @@ static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
#define DEG_TO_RAD PI / 180.0f
#define RAD_TO_DEG 180.0f / PI

static float SC_sinf_fast(float x)
{
    const float A =   1.0f / (2.0f * M_PI);
    const float B = -16.0f;
    const float C =   8.0f;
    
    // scale angle for easy argument reduction
    x *= A;
    
    if (fabsf(x) >= 0.5f) {
        // argument reduction
        x = x - ceilf(x + 0.5f) + 1.0f;
    }
    
    const float y = B * x * fabsf(x) + C * x;
    return 0.2215f * (y * fabsf(y) - y) + y;
}

static float SC_cosf_fast(float x)
{
    x += float(M_PI / 2);

    const float A =   1.0f / (2.0f * M_PI);
    const float B = -16.0f;
    const float C =   8.0f;
    
    // scale angle for easy argument reduction
    x *= A;
    
    if (fabsf(x) >= 0.5f) {
        // argument reduction
        x = x - ceilf(x + 0.5f) + 1.0f;
    }
    
    const float y = B * x * fabsf(x) + C * x;
    return 0.2215f * (y * fabsf(y) - y) + y;
}

static float SC_randf(float max)
{
    float r = (float)rand();
@@ -846,6 +884,10 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
        "int", "(int)" },
    { "absf", (void *)&fabs,
        "float", "(float)" },
    { "sinf_fast", (void *)&SC_sinf_fast,
        "float", "(float)" },
    { "cosf_fast", (void *)&SC_cosf_fast,
        "float", "(float)" },
    { "sinf", (void *)&sinf,
        "float", "(float)" },
    { "cosf", (void *)&cosf,