示例#1
0
void MCInternalObjectListenerListListeners(MCExecPoint &ep)
{
	ep . clear();
	MCObjectHandle *t_current_object;
	t_current_object = ep . getobj() -> gethandle();
	
	bool t_first;
	t_first = true;
	
	MCObjectListener *t_prev_listener;
	t_prev_listener = nil;
	
	MCObjectListener *t_listener;
	t_listener = s_object_listeners;
	while(t_listener != nil)
	{
		if (!t_listener -> object -> Exists())
			remove_object_listener_from_list(t_listener, t_prev_listener);
		else
		{				
			MCObjectListenerTarget *t_target;
			t_target = nil;
			MCObjectListenerTarget *t_prev_target;
			t_prev_target = nil;	
			
			MCExecPoint ep1(ep);
			t_listener -> object -> Get() -> getprop(0, P_LONG_ID, ep1, false);
						
			for (t_target = t_listener -> targets; t_target != nil; t_target = t_target -> next)
			{
				if (!t_target -> target -> Exists())
					remove_object_listener_target_from_list(t_target, t_prev_target, t_listener, t_prev_listener);
				else if (t_target -> target ==  t_current_object)
				{
					ep . concatmcstring(ep1 . getsvalue(), EC_RETURN, t_first);
					t_first = false;		
				}
			}
			
			t_prev_listener = t_listener;
		}
		
		if (t_listener != nil)
			t_listener = t_listener -> next;
		else
			t_listener = s_object_listeners;
	}
}
示例#2
0
        void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
            const PLSQuadEdgeEffect& qe = args.fGP.cast<PLSQuadEdgeEffect>();
            GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder;
            GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
            GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;

            // emit attributes
            varyingHandler->emitAttributes(qe);

            GrGLSLVertToFrag uv(kVec2f_GrSLType);
            varyingHandler->addVarying("uv", &uv, kHigh_GrSLPrecision);
            vsBuilder->codeAppendf("%s = %s;", uv.vsOut(), qe.inUV()->fName);

            GrGLSLVertToFrag ep1(kVec2f_GrSLType);
            varyingHandler->addVarying("endpoint1", &ep1, kHigh_GrSLPrecision);
            vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep1.vsOut(), 
                                  qe.inEndpoint1()->fName, qe.inEndpoint1()->fName);

            GrGLSLVertToFrag ep2(kVec2f_GrSLType);
            varyingHandler->addVarying("endpoint2", &ep2, kHigh_GrSLPrecision);
            vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep2.vsOut(), 
                                  qe.inEndpoint2()->fName, qe.inEndpoint2()->fName);

            GrGLSLVertToFrag delta(kVec2f_GrSLType);
            varyingHandler->addVarying("delta", &delta, kHigh_GrSLPrecision);
            vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", 
                                   delta.vsOut(), ep1.vsOut(), ep2.vsOut(), ep2.vsOut(), 
                                   ep1.vsOut());

            GrGLSLVertToFrag windings(kInt_GrSLType);
            varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPrecision);
            vsBuilder->codeAppendf("%s = %s;", 
                                   windings.vsOut(), qe.inWindings()->fName);

            // Setup position
            this->setupPosition(vsBuilder, gpArgs, qe.inPosition()->fName);

            // emit transforms
            this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpArgs->fPositionVar, 
                                 qe.inPosition()->fName, qe.localMatrix(), args.fTransformsIn, 
                                 args.fTransformsOut);

            GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
            SkAssertResult(fsBuilder->enableFeature(
                           GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLFeature));
            SkAssertResult(fsBuilder->enableFeature(
                    GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
            static const int QUAD_ARGS = 2;
            GrGLSLShaderVar inQuadArgs[QUAD_ARGS] = {
                GrGLSLShaderVar("dot", kFloat_GrSLType, 0, kHigh_GrSLPrecision),
                GrGLSLShaderVar("uv", kVec2f_GrSLType, 0, kHigh_GrSLPrecision)
            };
            SkString inQuadName;

            const char* inQuadCode = "if (uv.x * uv.x <= uv.y) {"
                                     "return dot >= 0.0;"
                                     "} else {"
                                     "return false;"
                                     "}";
            fsBuilder->emitFunction(kBool_GrSLType, "in_quad", QUAD_ARGS, inQuadArgs, inQuadCode, 
                                    &inQuadName);
            fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL);
            // keep the derivative instructions outside the conditional
            fsBuilder->codeAppendf("highp vec2 uvdX = dFdx(%s);", uv.fsIn());
            fsBuilder->codeAppendf("highp vec2 uvdY = dFdy(%s);", uv.fsIn());
            fsBuilder->codeAppend("highp vec2 uvIncX = uvdX * 0.45 + uvdY * -0.1;");
            fsBuilder->codeAppend("highp vec2 uvIncY = uvdX * 0.1 + uvdY * 0.55;");
            fsBuilder->codeAppendf("highp vec2 uv = %s.xy - uvdX * 0.35 - uvdY * 0.25;", 
                                   uv.fsIn());
            fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);",
                                   fsBuilder->fragmentPosition());
            fsBuilder->codeAppendf("highp float d = dot(%s, (firstSample - %s).yx) * 2.0;", 
                                   delta.fsIn(), ep1.fsIn());
            fsBuilder->codeAppendf("pls.windings[0] += %s(d, uv) ? %s : 0;", inQuadName.c_str(), 
                                   windings.fsIn());
            fsBuilder->codeAppend("uv += uvIncX;");
            fsBuilder->codeAppendf("d += %s.x;", delta.fsIn());
            fsBuilder->codeAppendf("pls.windings[1] += %s(d, uv) ? %s : 0;", inQuadName.c_str(), 
                                   windings.fsIn());
            fsBuilder->codeAppend("uv += uvIncY;");
            fsBuilder->codeAppendf("d += %s.y;", delta.fsIn());
            fsBuilder->codeAppendf("pls.windings[2] += %s(d, uv) ? %s : 0;", inQuadName.c_str(), 
                                   windings.fsIn());
            fsBuilder->codeAppend("uv -= uvIncX;");
            fsBuilder->codeAppendf("d -= %s.x;", delta.fsIn());
            fsBuilder->codeAppendf("pls.windings[3] += %s(d, uv) ? %s : 0;", inQuadName.c_str(), 
                                   windings.fsIn());
        }
示例#3
0
文件: sha256.c 项目: noryb009/sha256
int main(int argc, char* argv[]) {
    if(argc < 2) {
        printf("Usage: sha256 <string>\n");
        return 0;
    }

    // 4.2.2
    uint32_t K[] = {
        0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
        0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
        0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
        0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
        0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
        0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
        0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
        0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
    };

    // 5.3.2
    uint32_t H[] = {
        0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
    };

    char* msg = argv[1];
    size_t len = strlen(msg);

    // 5.1.1
    uint64_t l = len * sizeof(char) * 8;
    size_t k = (448 - l - 1) % 512;
    if(k < 0) k += 512;
    assert((l+1+k) % 512 == 448);

    size_t msgSize = l + 1 + k + 64;

    char* msgPad = (char*)calloc((msgSize / 8), sizeof(char));
    memcpy(msgPad, msg, len);
    msgPad[len] = 0x80;
    l = swapE64(l);
    memcpy(msgPad+(msgSize/8)-8, &l, 8);

    // 5.2.1
    size_t N = msgSize / 512;

    // 6.2
    uint32_t v[8];
    uint32_t W[64];
    uint32_t* M = (uint32_t*)msgPad;
    uint32_t T1, T2;

    for(size_t i = 0; i < N * 16; i++) {
        M[i] = swapE32(M[i]);
    }

    // 6.2.2
    for(size_t i = 0; i < N; i++) {
        // 1
        for(size_t t = 0; t < 16; t++) {
            W[t] = M[i*16 + t];
        }
        for(size_t t = 16; t < 64; t++) {
            W[t] = sig1(W[t-2]) + W[t-7] + sig0(W[t-15]) + W[t-16];
        }

        // 2
        for(size_t t = 0; t < 8; t++) {
            v[t] = H[t];
        }

        // 3
        for(size_t t = 0; t < 64; t++) {
            // a=0 b=1 c=2 d=3 e=4 f=5 g=6 h=7
            T1 = v[7] + ep1(v[4]) + Ch(v[4], v[5], v[6]) + K[t] + W[t];
            T2 = ep0(v[0]) + Maj(v[0], v[1], v[2]);

            v[7] = v[6];
            v[6] = v[5];
            v[5] = v[4];
            v[4] = v[3] + T1;
            v[3] = v[2];
            v[2] = v[1];
            v[1] = v[0];
            v[0] = T1 + T2;
        }

        for(size_t t = 0; t < 8; t++) {
            H[t] += v[t];
        }
    }

    for(size_t i = 0; i < 8; i++) {
        H[i] = swapE32(H[i]);
        hex(&H[i], 4);
    }
    printf("\n");

    free(msgPad);
    return 0;
}
示例#4
0
void Bond::Render(Render2D * r)
{
    double myangle, x1, y1, x2, y2, rise, run, lx, ly, cf = 0.02;
    QColor c1;

    if ( highlighted )
        c1 = Render2D::highlightColor;
    else
        c1 = color;
    // for single bonds
    if ( order == 1 ) {
        if ( dashed > 0 )
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 );
        else
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 );
        return;
    }
    // for stereo_up bonds
    if ( order == 5 ) {
        r->drawUpLine( start->toQPoint(), end->toQPoint(), c1 );
        return;
    }
    // for wavy bonds (order = 6)
    if ( order == 6 ) {
        r->drawWavyLine( start->toQPoint(), end->toQPoint(), c1 );
        return;
    }
    // for stereo_down bonds
    if ( order == 7 ) {
        r->drawDownLine( start->toQPoint(), end->toQPoint(), c1 );
        return;
    }
    // for double and triple bonds
    myangle = getAngle( start, end );
    myangle += 90.0;
    myangle = myangle * ( M_PI / 180.0 );
    //double offs = start->distanceTo(end) / 25.0;
    /*
       offs = preferences.getDoubleBondOffset();
       if (order == 3) {
       if (thick > 2) offs += 0.5;
       if (thick > 3) offs += 0.4;
       if (thick > 4) offs += 0.3;
       } else {
       if (thick > 2) offs += 0.3;
       if (thick > 4) offs += 0.3;
       }
       x2 = cos(myangle) * 3.0 * offs;
       y2 = sin(myangle) * 3.0 * offs;
       // x1, y1, 3 and 4 are for use with special case 1 below
       x1 = cos(myangle) * 2.5 * offs;
       y1 = sin(myangle) * 2.5 * offs;
     */

    /* original (does not use preferences!)
       double abl = 1.0;
       abl = (double)thick / 2.0 + 1.0;
     */

    double abl = 1.0;

    abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset();

    // check for order 2 special case (center double bond)
    bool special_case_1 = false;

    if ( order == 2 ) {
        //qDebug() << "start->element: " << start->element ;
        //qDebug() << "start->subst: " << start->substituents ;
        //qDebug() << "end->element: " << end->element ;
        //qDebug() << "end->subst: " << end->substituents ;
        if ( ( start->element == "O" ) && ( start->substituents == 2 ) )
            special_case_1 = true;
        if ( ( end->element == "O" ) && ( end->substituents == 2 ) )
            special_case_1 = true;
        if ( ( start->element == "C" ) && ( start->substituents == 2 ) )
            special_case_1 = true;
        if ( ( end->element == "C" ) && ( end->substituents == 2 ) )
            special_case_1 = true;
        if ( ( start->element == "CH2" ) && ( start->substituents == 2 ) )
            special_case_1 = true;
        if ( ( end->element == "CH2" ) && ( end->substituents == 2 ) )
            special_case_1 = true;
        if ( ( start->element == "N" ) && ( end->element == "N" ) )
            special_case_1 = true;
        if ( wside == 2 )       // force centered double bond
            special_case_1 = true;
    }
    if ( special_case_1 )
        abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset() / 4.0;
    else
        abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset() / 2.0;

    //qDebug() << "abl = " << abl;

    x2 = cos( myangle ) * abl;
    y2 = sin( myangle ) * abl;
    // x1, y1, 3 and 4 are for use with special case 1 below
    x1 = cos( myangle ) * abl;
    y1 = sin( myangle ) * abl;

    QPoint sp3( qRound( start->x + x1 ), qRound( start->y + y1 ) );
    QPoint ep3( qRound( end->x + x1 ), qRound( end->y + y1 ) );
    QPoint sp4( qRound( start->x - x1 ), qRound( start->y - y1 ) );
    QPoint ep4( qRound( end->x - x1 ), qRound( end->y - y1 ) );

    // shorten lines by removing from each end
    double bl = start->distanceTo( end );

    if ( bl < 100.0 )
        cf = 0.03;
    if ( bl < 51.0 )
        cf = 0.05;
    if ( bl < 27.0 )
        cf = 0.07;
    // find sp1 and ep1
    rise = ( end->y + y2 ) - ( start->y + y2 );
    run = ( end->x + x2 ) - ( start->x + x2 );
    lx = start->x + x2 + run * cf;
    ly = start->y + y2 + rise * cf;
    QPoint sp1( ( int ) lx, ( int ) ly );

    lx = start->x + x2 + run * ( 1.0 - cf );
    ly = start->y + y2 + rise * ( 1.0 - cf );
    QPoint ep1( ( int ) lx, ( int ) ly );

    // find sp2 and ep2
    rise = ( end->y - y2 ) - ( start->y - y2 );
    run = ( end->x - x2 ) - ( start->x - x2 );
    lx = start->x - x2 + run * cf;
    ly = start->y - y2 + rise * cf;
    QPoint sp2( ( int ) lx, ( int ) ly );

    lx = start->x - x2 + run * ( 1.0 - cf );
    ly = start->y - y2 + rise * ( 1.0 - cf );
    QPoint ep2( ( int ) lx, ( int ) ly );

    if ( special_case_1 == true ) {
        if ( dashed > 1 )
            r->drawLine( sp3, ep3, thick, c1, 1 );
        else
            r->drawLine( sp3, ep3, thick, c1 );
        if ( dashed > 0 )
            r->drawLine( sp4, ep4, thick, c1, 1 );
        else
            r->drawLine( sp4, ep4, thick, c1 );
        return;
    }

    QPoint sp, ep;

    if ( order == 2 ) {
        if ( wside == 1 ) {
            sp = sp1;
            ep = ep1;
        } else {
            sp = sp2;
            ep = ep2;
        }
        //qDebug() << "wside:" << wside;
        if ( dashed > 1 )
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 );
        else
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 );
        if ( dashed > 0 )
            r->drawLine( sp, ep, thick, c1, 1 );
        else
            r->drawLine( sp, ep, thick, c1 );
        return;
    }
    if ( order == 3 ) {
        if ( dashed > 2 )
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 );
        else
            r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 );
        if ( dashed > 1 )
            r->drawLine( sp1, ep1, thick, c1, 1 );
        else
            r->drawLine( sp1, ep1, thick, c1 );
        if ( dashed > 0 )
            r->drawLine( sp2, ep2, thick, c1, 1 );
        else
            r->drawLine( sp2, ep2, thick, c1 );
        return;
    }
}