示例#1
0
bool clsThreadBase::CheckIfExiting(uint64_t iStopWaitTimeMS)
{
    if (!m_bStopFlag)
    {
        return false;
    }

    if (m_bExiting)
    {
        return true;
    }

    uint64_t iCurrTimeMS = GetCurrTimeMS();

    if (m_iStopStartTimeMS == 0)
    {
        m_iStopStartTimeMS = iCurrTimeMS;
    }
    else if (m_iStopStartTimeMS + iStopWaitTimeMS <= iCurrTimeMS)
    {
        m_bExiting = true;
    }

    return m_bExiting;
}
示例#2
0
void MoveMonitor::Move(APoint start,APath& path,int speed,int timeOffset)
{
	Terminate();

	m_CurrPoint = start;

	m_Path = path;

	m_nSpeed = speed;

	m_lLastTime = GetCurrTimeMS();

	SetMoveTimeCost(0);
	AddMoveTimeCorrect(timeOffset);

	// 取出第一个目标点
	if ( m_Path.size() > 0 )
	{
		Step(m_Path.pop());
		// 计算方向
		m_nDir = DirectionBy(m_CurrPoint.x,m_CurrPoint.y,m_StepPoint.x,m_StepPoint.y);
	}
	else
	{
		Terminate();
	}

	m_nType = MoveType_Normal;
}
示例#3
0
void MoveMonitor::UpdateMove(float dt)
{
	static const int MOVE_UNIT = 35;	// 移动平滑处理

	// 测试移动卡帧
	//static int i = 0;
	//if ( i++ > 10 )
	//{
	//	i = 0;
	//	Sleep(50);
	//}
	long lNowTime = GetCurrTimeMS();
	long lTimeCost = lNowTime-m_lLastTime;
	if ( lTimeCost > MOVE_UNIT )
	{
		AddMoveTimeCorrect(lTimeCost-MOVE_UNIT);	// 修改矫正时间
		lTimeCost = MOVE_UNIT;
	}

	if ( GetMoveTimeCost() + lTimeCost >= GetMoveTimeOneCell() )	// 如果移动时间超过一个格子时间
	{
		lTimeCost = GetMoveTimeCost()+lTimeCost-GetMoveTimeOneCell();
		SetMoveTimeCost(0);
		// 单步移动结束,将目标位置置为当前位置;
		m_CurrPoint = m_StepPoint;

		// 获取移动路径中的下一个位置,继续移动;
		if ( m_Path.size() > 0 )
		{
			Step(m_Path.pop());
		}
		else
		{
			Terminate();
			return;
		}
	}

	m_lLastTime = lNowTime;
	AddMoveTimeCost(lTimeCost);
	
	//CCLOGERROR("lTimeCost:%d,getMoveTimeCost:%d,getMoveTimeOneCell:%d",lTimeCost,GetMoveTimeCost(),GetMoveTimeOneCell());

	// 计算方向
	m_nDir = DirectionBy(m_CurrPoint.x,m_CurrPoint.y,m_StepPoint.x,m_StepPoint.y);
	// 计算单位位移量
	float delta_s = GetMoveTimeOneCell()>0?(float)GetMoveTimeCost()/GetMoveTimeOneCell():1.0f;
	m_CurrPointOffset.x = _DELTA_X[m_nDir]*delta_s;
	m_CurrPointOffset.y = _DELTA_Y[m_nDir]*delta_s;
}
示例#4
0
void MoveMonitor::Flash(const APoint& start,const APoint& end,int speed,int timeOffset)
{
	Terminate();
	m_CurrPoint = start;

	m_nSpeed = speed;
	m_lLastTime = GetCurrTimeMS();

	SetMoveTimeCost(0);
	AddMoveTimeCorrect(timeOffset);

	Step(end);
	// 计算方向
	m_nDir = DirectionBy(m_CurrPoint.x,m_CurrPoint.y,m_StepPoint.x,m_StepPoint.y);

	m_nType = MoveType_Flash;
}
示例#5
0
void MoveMonitor::UpdateFlash(float dt)
{	
	long lNowTime = GetCurrTimeMS();
	long lTimeCost = lNowTime-m_lLastTime;

	m_lLastTime = lNowTime;
	AddMoveTimeCost(lTimeCost);

	if ( GetMoveTimeCost() + lTimeCost >= GetFlashTime() )	// 如果移动时间超过一个闪烁总时间
	{
		m_CurrPoint = m_StepPoint;
		Terminate();
		return ;
	}

	Point offset = DistanceByWorld(m_CurrPoint.x,m_CurrPoint.y,m_StepPoint.x,m_StepPoint.y);
	// 计算单位位移量
	float delta_s = (float)GetMoveTimeCost()/(float)GetFlashTime();
	m_CurrPointOffset.x = offset.x*delta_s;
	m_CurrPointOffset.y = offset.y*delta_s;
}