示例#1
0
/* convert ccsds embedded time to a human readable string - NOT THREAD SAFE */
static const char* embedded_time_to_string ( int coarse_time, int fine_time )
{
        static int utcdiff = 0;
        nstime_t t;
        int yr;
        int fraction;
        int multiplier = 1000;

        /* compute the static constant difference in seconds
         * between midnight 5-6 January 1980 (GPS time) and
         * seconds since 1/1/1970 (UTC time) just this once
         */
        if ( 0 == utcdiff )
        {
                for ( yr=1970; yr < 1980; ++yr )
                {
                        utcdiff += ( Leap(yr)  ?  366 : 365 ) * 24 * 60 * 60;
                }

                utcdiff += 5 * 24 * 60 * 60;  /* five days of January 1980 */
        }

        t.secs = coarse_time + utcdiff;
        fraction = ( multiplier * ( (int)fine_time & 0xff ) ) / 256;
        t.nsecs = fraction*1000000;	/* msecs to nsecs */

	return abs_time_to_str(&t, ABSOLUTE_TIME_DOY_UTC, TRUE);
}
示例#2
0
文件: CDate.cpp 项目: LoadLow/cours
void CDate::Reset() throw()
{
	m_Day = 1;
	m_Month = 1;
	m_Year = 1900;
	Leap();
}
示例#3
0
文件: CDate.cpp 项目: LoadLow/cours
CDate::CDate(unsigned Day /* = 1 */, unsigned Month /* = 1 */, unsigned Year /* = 1900 */)
{
	if(Day < 1 || Day > 31)
	{
		Reset();
		return;
	}

	if(Month > 12 || Year < 1900 || Year > 2013)
	{
		Reset();
		return;
	}

	m_Year = Year;
	Leap();

	switch(Month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if(Day > 31)
			{
				Reset();
				return;
			}
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if(Day > 31)
			{
				Reset();
				return;
			}
			break;
		case 2:
			if((m_Leap && Day > 29) || (!m_Leap && Day > 28))
			{
				Reset();
				return;
			}
			break;
		default:
			Reset();
			return;
	}

	m_Month = Month;
	m_Day = Day;
}
示例#4
0
/* convert smex PB5 header time to a human readable string - NOT THREAD SAFE
 *
 * note:  this is not true PB5 time either, but a tsi specific version, although it is similar
 */
static const char *
smex_time_to_string (int pb5_days_since_midnight_9_10_oct_1995, int pb5_seconds, int pb5_milliseconds)
{
    static int utcdiff = 0;
    nstime_t t;

    static int Days[2][13] =
    {
        { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
        { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
    };

    int yr;
    int ix, days, month;

    /* compute the static constant difference in seconds
     * between midnight 9-10 October 1995 (PB5 time) and
     * seconds since 1/1/1970 (UTC time) just this once
     */
    if (0 == utcdiff)
    {
        for (yr=1970; yr < 1995; ++yr)
        {
            utcdiff += (Leap(yr)  ?  366 : 365) * 24 * 60 * 60;
        }

        days = 0;
        ix = (Leap(1995)  ?  1 : 0);

        for (month=1; month < 10; ++month)
        {
            days += Days[ix][month];
        }

        days += 9;  /* this gets us up to midnight october 9-10 */

        utcdiff += days * 24 * 60 * 60;  /* add days in 1995 prior to October 10 */
    }

    t.secs = (pb5_days_since_midnight_9_10_oct_1995 * 86400) + pb5_seconds + utcdiff;
    t.nsecs = pb5_milliseconds*1000000; /* msecs to nsecs */

    return abs_time_to_str(wmem_packet_scope(), &t, ABSOLUTE_TIME_DOY_UTC, TRUE);
}
示例#5
0
//-----------------------------------------------------------------------------
// Purpose: Does a jump attack at the given position.
// Input  : bRandomJump - Just hop in a random direction.
//			vecPos - Position to jump at, ignored if bRandom is set to true.
//			bThrown - 
//-----------------------------------------------------------------------------
void CASW_Parasite::JumpAttack( bool bRandomJump, const Vector &vecPos, bool bThrown )
{
	Vector vecJumpVel;
	if ( !bRandomJump )
	{
		float gravity = sv_gravity.GetFloat();
		if ( gravity <= 1 )
		{
			gravity = 1;
		}

		// How fast does the headcrab need to travel to reach the position given gravity?
		float flActualHeight = vecPos.z - GetAbsOrigin().z;
		float height = flActualHeight;
		if ( height < 16 )
		{
			height = 60; //16;
		}
		else
		{
			float flMaxHeight = bThrown ? 400 : 120;
			if ( height > flMaxHeight )
			{
				height = flMaxHeight;
			}
		}

		// overshoot the jump by an additional 8 inches
		// NOTE: This calculation jumps at a position INSIDE the box of the enemy (player)
		// so if you make the additional height too high, the crab can land on top of the
		// enemy's head.  If we want to jump high, we'll need to move vecPos to the surface/outside
		// of the enemy's box.
		
		float additionalHeight = 0;
		if ( height < 32 )
		{
			additionalHeight = 8;
		}

		height += additionalHeight;

		// NOTE: This equation here is from vf^2 = vi^2 + 2*a*d
		float speed = sqrt( 2 * gravity * height );
		float time = speed / gravity;

		// add in the time it takes to fall the additional height
		// So the impact takes place on the downward slope at the original height
		time += sqrt( (2 * additionalHeight) / gravity );

		// Scale the sideways velocity to get there at the right time
		VectorSubtract( vecPos, GetAbsOrigin(), vecJumpVel );
		vecJumpVel /= time;

		// Speed to offset gravity at the desired height.
		vecJumpVel.z = speed;

		// Don't jump too far/fast.
		float flJumpSpeed = vecJumpVel.Length();
		float flMaxSpeed = bThrown ? 1000.0f : 650.0f;
		if ( flJumpSpeed > flMaxSpeed )
		{
			vecJumpVel *= flMaxSpeed / flJumpSpeed;
		}
	}
	else
	{
		//
		// Jump hop, don't care where.
		//
		Vector forward, up;
		AngleVectors( GetLocalAngles(), &forward, NULL, &up );
		vecJumpVel = Vector( forward.x, forward.y, up.z ) * 350;
	}

	AttackSound();
	Leap( vecJumpVel );
}