Beispiel #1
0
    // fixture methods
    virtual void SetUp() {
        testFile1 = "logger_test_file1.txt";
        testFile2 = "logger_test_file2.txt";
        // avoid stomping over someone else's files.
        H_ASSERT( !fileExists( testFile1.c_str() ), "testfile1 exists" );
        H_ASSERT( !fileExists( testFile2.c_str() ), "testfile2 exists" );

        loggerNoEcho.open( testFile1, false, Logger::WARNING );
        std::streambuf* tmpBuff = std::cout.rdbuf( &consoleTestBuff );
        loggerEcho.open( testFile2, true, Logger::WARNING );
        
        // now that the logger has attached to our test buffer put the
        // original back into cout
        std::cout.rdbuf( tmpBuff );
    }
Beispiel #2
0
void CAES::setKey(const char *pszKey, const unsigned int uiKeyType)
{
    size_t iRKLens(RKLENGTH(uiKeyType));
    size_t iKeyLens(KEYLENGTH(uiKeyType));

    m_pEncodeRK = new(std::nothrow) unsigned long[iRKLens + 1];
    H_ASSERT(NULL != m_pEncodeRK, "malloc memory error.");
    H_Zero(m_pEncodeRK, iRKLens + 1);

    m_pDecodeRK = new(std::nothrow) unsigned long[iRKLens + 1];
    H_ASSERT(NULL != m_pDecodeRK, "malloc memory error.");
    H_Zero(m_pDecodeRK, iRKLens + 1);

    unsigned char * pKey = new(std::nothrow) unsigned char[iKeyLens + 1];
    H_ASSERT(NULL != pKey, "malloc memory error.");
    H_Zero(pKey, iKeyLens + 1);
    memcpy(pKey, pszKey, strlen(pszKey) > iKeyLens ? iKeyLens : strlen(pszKey));

    m_iEncodeRounds = rijndaelSetupEncrypt(m_pEncodeRK, pKey, uiKeyType);
    m_iDecodeRounds = rijndaelSetupDecrypt(m_pDecodeRK, pKey, uiKeyType);

    H_SafeDelArray(pKey);
}
Beispiel #3
0
double seval_deriv_forsythe( int n, double u, double *x, double *y, double *b, double *c, double *d ) {
    /* Evaluate the derivative of a cubic spline function.
     seval_deriv = b(i) + 2*c(i)*(u-x(i)) + 3*d(i)*(u-x(i))**2
     where  x(i) .lt. u .lt. x(i+1), using horner's rule.
     If  u .lt. x(1) then  i = 1  is used.
     If  u .ge. x(n) then  i = n  is used.
     Input:
     n = the number of data points
     u = the abscissa at which the spline is to be evaluated
     x,y = the arrays of data abscissas and ordinates
     b,c,d = arrays of spline coefficients computed by spline
     If  u  is not in the same interval as the previous call, then a binary search is
     performed to determine the proper interval.
     
     The function seval() is invoked with the (x, y) pairs underlying the interpolating
     function specified by the arguments x and y, and the spline coefficients that
     define the function as specified by b, c, and d. The argument n is the number
     of data points and the length of the coefficient arrays. */
    
    H_ASSERT( n && x && y && b && c && d, "seval_forsythe needs nonzero params" );
    
    static int i = 0;
    int j, k;
    double dx;
    
    /* Test for u within the interval of definition of the interpolating function. If not,
     return the value at an end point of the interval. */
    if (u < x[0]) { u = x[0]; }
    if (u > x[n-1]) { u = x[n-1]; }
    
    /* Search for the data points with independent values containing the
     argument u. */
    if (i >= n-1) i = 0;
    
    /* If u is not in the current interval, then execute a binary search. */
    if ((u < x[i]) || (u > x[i+1])) {
        i = 0;
        j = n;
        while (j > i + 1) {
            k = (int)(( i + j) / 2);
            if (u < x[k]) j = k;
            if (u >= x[k]) i = k;
        }
    }
    
    /* Evaluate the derivative of the spline function at the argument u. */
    dx = u - x[i];
    return b[i] + ( 2.0 * dx * c[i] ) + ( 3.0 * dx * dx * d[i] );
}
void r_WeatherEffectsParticleManager::Draw(
	const m_Mat4& view_matrix, const m_Vec3& cam_pos,
	const r_Texture& heightmap_texture, const m_Mat4& heightmap_matrix,
	float particel_size_px,
	const m_Vec3& light,
	float intensity )
{
	if( intensity > 1.0f )
	{
		H_ASSERT(false);
		intensity= 1.0f;
	}

	static const GLenum blend_func[2]= { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA };
	static const r_OGLState state(
		true, false, true, true,
		blend_func );
	r_OGLStateManager::UpdateState( state );

	vbo_.Bind();

	particle_texture_.Bind(0);
	heightmap_texture.Bind(1);

	shader_.Bind();
	shader_.Uniform( "particle_coord_delta", float(hGetTimeMS() - startup_time_) * 0.001f * m_Vec3( 0.0f, 0.0f, -R_RAIN_SPEED_MPS ) );
	shader_.Uniform( "particle_zone_coord", cam_pos - rain_zone_size_ * 0.5f );
	shader_.Uniform( "particle_zone_size", rain_zone_size_ );
	shader_.Uniform( "mat", view_matrix );
	shader_.Uniform( "particle_size", particel_size_px );
	shader_.Uniform( "tex", 0 );

	shader_.Uniform( "heightmap", 1 );
	shader_.Uniform( "heightmap_matrix", heightmap_matrix );

	shader_.Uniform( "light", light );

	glDrawArrays(
		GL_POINTS,
		0,
		(unsigned int)( float(particles_count_) * intensity ) );
}
Beispiel #5
0
void CNetListener::addListener(const char *pszParser, const unsigned short &usType,
    const char *pszHost, const unsigned short &usPort)
{
    CParser *pParser(m_pParserMgr->getParser(pszParser));
    H_ASSERT(NULL != pParser, "get parser error.");

    CNetInfo *pNetInfo = new(std::nothrow) CNetInfo(this, pParser, usType, pszHost, usPort);
    if (NULL == pNetInfo)
    {
        H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY);
        return;
    }

    CAddListenAdjure *pAdjure = new(std::nothrow) CAddListenAdjure(pNetInfo);
    if (NULL == pAdjure)
    {
        H_SafeDelete(pNetInfo);
        H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY);
        return;
    }

    Adjure(pAdjure);
}
Beispiel #6
0
CDESEncrypt::CDESEncrypt(void)
{
    m_pContext = getcontext();
    H_ASSERT(NULL != m_pContext, "malloc memory error.");
}
Beispiel #7
0
void h_Player::UpdateBuildPos( const p_WorldPhysMesh& phys_mesh )
{
	m_Vec3 eye_dir(
		-std::sin( view_angle_.z ) * std::cos( view_angle_.x ),
		+std::cos( view_angle_.z ) * std::cos( view_angle_.x ),
		+std::sin( view_angle_.x ) );

	m_Vec3 eye_pos= pos_;
	eye_pos.z+= eyes_level_;
	float square_dist= std::numeric_limits<float>::max();
	h_Direction block_dir= h_Direction::Unknown;

	m_Vec3 intersect_pos;
	m_Vec3 candidate_pos;
	m_Vec3 n;

	for( const p_UpperBlockFace& face : phys_mesh.upper_block_faces )
	{
		n= g_block_normals[ static_cast<size_t>(face.dir) ];

		// Triangulate polygon and check intersection with triangles.
		m_Vec3 triangle[3];
		triangle[0]= m_Vec3( face.vertices[0], face.z );
		for( unsigned int i= 0; i < face.vertex_count - 2; i++ )
		{
			triangle[1]= m_Vec3( face.vertices[ i + 1 ], face.z );
			triangle[2]= m_Vec3( face.vertices[ i + 2 ], face.z );
			if( pRayHasIniersectWithTriangle( triangle, n, eye_pos, eye_dir, &candidate_pos ) )
			{
				float candidate_square_dist= ( candidate_pos - eye_pos ).SquareLength();
				if( candidate_square_dist < square_dist )
				{
					square_dist= candidate_square_dist;
					intersect_pos= candidate_pos;
					block_dir= face.dir;
				}
			}
		}
	}

	for( const p_BlockSide& side : phys_mesh.block_sides )
	{
		n= g_block_normals[ static_cast<size_t>(side.dir) ];

		m_Vec3 triangles[6];
		triangles[0]= m_Vec3( side.edge[0], side.z0 );
		triangles[1]= m_Vec3( side.edge[1], side.z0 );
		triangles[2]= m_Vec3( side.edge[1], side.z1 );
		triangles[3]= m_Vec3( side.edge[0], side.z1 );
		triangles[4]= m_Vec3( side.edge[0], side.z0 );
		triangles[5]= m_Vec3( side.edge[1], side.z1 );
		for( unsigned int i= 0; i < 2; i++ )
		{
			if( pRayHasIniersectWithTriangle( triangles + i * 3, n, eye_pos, eye_dir, &candidate_pos ) )
			{
				float candidate_square_dist= ( candidate_pos - eye_pos ).SquareLength();
				if( candidate_square_dist < square_dist )
				{
					square_dist= candidate_square_dist;
					intersect_pos= candidate_pos;
					block_dir= side.dir;
				}
			}
		}
	}

	if( block_dir == h_Direction::Unknown ||
		square_dist > g_max_build_distance * g_max_build_distance )
	{
		build_direction_= h_Direction::Unknown;
		return;
	}

	// Fix accuracy. Move intersection point inside target block.
	intersect_pos-= g_block_normals[ static_cast<size_t>(block_dir) ] * 0.1f;

	pGetHexogonCoord( intersect_pos.xy(), &destroy_pos_[0], &destroy_pos_[1] );
	destroy_pos_[2]= short( intersect_pos.z );

	discret_build_pos_[0]= destroy_pos_[0];
	discret_build_pos_[1]= destroy_pos_[1];
	discret_build_pos_[2]= destroy_pos_[2];

	switch( block_dir )
	{
	case h_Direction::Up: discret_build_pos_[2]++; break;
	case h_Direction::Down: discret_build_pos_[2]--; break;

	case h_Direction::Forward: discret_build_pos_[1]++; break;
	case h_Direction::Back: discret_build_pos_[1]--; break;

	case h_Direction::ForwardRight:
		discret_build_pos_[1]+= ( (discret_build_pos_[0]^1) & 1 );
		discret_build_pos_[0]++;
		break;
	case h_Direction::BackRight:
		discret_build_pos_[1]-= discret_build_pos_[0] & 1;
		discret_build_pos_[0]++;
		break;

	case h_Direction::ForwardLeft:
		discret_build_pos_[1]+= ( (discret_build_pos_[0]^1) & 1 );
		discret_build_pos_[0]--;
		break;
	case h_Direction::BackLeft:
		discret_build_pos_[1]-= discret_build_pos_[0] & 1;
		discret_build_pos_[0]--;
		break;

	case h_Direction::Unknown: H_ASSERT(false); break;
	}

	build_pos_.x= float( discret_build_pos_[0] + 1.0f / 3.0f ) * H_SPACE_SCALE_VECTOR_X;
	build_pos_.y= float( discret_build_pos_[1] ) - 0.5f * float(discret_build_pos_[0]&1) + 0.5f;
	build_pos_.z= float( discret_build_pos_[2] );

	build_direction_= block_dir;
}
Beispiel #8
0
void spline_forsythe( int n, double *x, double *y, double *b, double *c, double *d ) {
    /* The coefficients b[i], c[i], and d[i], i = 1, 2, ..., n are computed for a cubic
     interpolating spline s(x) = y[i] + b[i]*(x-x[i]) + c[i]*(x-x[i])**2 + d[i]*(x-x[i])**3
     for  x[i] <= x <= x[i+1]. The accompanying function seval() can be used to
     evaluate the spline.
     
     Input:
     n = the number of data points or knots (n >= 2)
     x = the abscissas of the knots in strictly increasing order
     y = the ordinates of the knots
     
     Output:
     b, c, d  = arrays of spline coefficients as defined above.
     
     Using  p  to denote differentiation,
     y[i] = s(x[i])
     b[i] = sp(x[i])
     c[i] = spp(x[i])/2
     d[i] = sppp(x[i])/6  (derivative from the right). */
    
    int i, ib;
    double t;
    
    H_ASSERT( n && x && y && b && c && d, "spline arguments must be nonzero" );
    
    H_ASSERT( n >= 2, "Insufficient data for interpolation" );
    
    if (n < 3) {
        b[0] = (y[1] - y[0]) / (x[1] - x[0]);
        c[0] = 0.0;
        d[0] = 0.0;
        b[1] = b[0];
        c[1] = 0.0;
        d[1] = 0.0;
    }
    else {
        /* Set up tridiagonal system.
         b = diagonal, d = off-diagonal, c = right-hand side. */
        d[0] = x[1] - x[0];
        c[1] = (y[1] - y[0]) / d[0];
        for (i = 1; i < n-1; ++i) {
            d[i] = x[i+1] - x[i];
            b[i] = 2.0 * (d[i-1] + d[i]);
            c[i+1] = (y[i+1] - y[i]) / d[i];
            c[i] = c[i+1] - c[i];
        }
        
        /* End conditions. Third derivatives at  x[1]  and  x[n] obtained from
         divided differences. */
        b[0] = -d[0];
        b[n-1] = -d[n-2];
        c[0] = 0.0;
        c[n-1] = 0.0;
        if (n > 3) {
            c[0] = c[2] / (x[3] - x[1]) - c[1] / (x[2] - x[0]);
            c[n-1] = c[n-2] / (x[n-1] - x[n-3]) - c[n-3] / (x[n-2] - x[n-4]);
            c[0] = c[0] * d[0] * d[0] / (x[3] - x[0]);
            c[n-1] = -c[n-1] * d[n-2] * d[n-2] / (x[n-1] - x[n-4]);
        }
        
        /* Forward elimination. */
        for (i = 1; i < n; ++i) {
            t = d[i-1] / b[i-1];
            b[i] = b[i] - t * d[i-1];
            c[i] = c[i] - t * c[i-1];
        }
        
        /* Back substitution. */
        c[n-1] = c[n-1] / b[n-1];
        for (ib = 0; ib < n-1; ++ib) {
            i = n - ib - 1;
            c[i] = (c[i] - d[i] * c[i+1]) / b[i];
        }
        /* c[i] is now the sigma[i] of the text. */
        
        /* Compute polynomial coefficients. */
        b[n-1] = (y[n-1] - y[n-2]) / d[n-2] + d[n-2] * (c[n-2] + 2.0 * c[n-1]);
        for (i = 0; i < n-1; ++i) {
            b[i] = (y[i+1] - y[i]) / d[i] - d[i] * (c[i+1] + 2.0 * c[i]);
            d[i] = (c[i+1] - c[i]) / d[i];
            c[i] = 3.0 * c[i];
        }
        c[n-1] = 3.0 * c[n-1];
        d[n-1] = d[n-2];
    }
}