⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsanimation.cpp

📁 网络泡泡被.net管理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		_m_play_flag	= GS_ANI_PLAY_NONE;
		return;
	}
	_m_play_flag	= style;

	if(delay>0)
		_m_frame_delay		= 1000.0f*delay;
	//if(bReset)
		_m_base_tick		= 0;
	//_m_pass_tick		= 0;
	if(loop<0)
		loop = 0;
	_m_play_tick		= (float)_m_frame_delay*loop*(m_frame_per_direction) + time - _m_base_tick - 1;

	switch(_m_play_flag)
	{
	case	GS_ANI_PLAY_LOOP:
		if(bReset)
			m_current_frame		= m_start_frame;
		_m_is_frame_up		= TRUE;
		break;
	case	GS_ANI_PLAY_LOOP_BACK:
		if(bReset)
			m_current_frame		= m_end_frame;
		_m_is_frame_up		= false;
		break;
	case	GS_ANI_PLAY_ROTATE:
		if(bReset)
			m_current_frame		= m_start_frame;
		_m_is_frame_up		= TRUE;
		break;
	case	GS_ANI_PLAY_ROTATE_BACK:
		if(bReset)
			m_current_frame		= m_end_frame;
		_m_is_frame_up		= false;
		break;
	}

	_m_pass_tick	= (m_current_frame-m_start_frame)*_m_frame_delay;
	m_percent_by	= 0;
}



VOID CGsAnimation::SetGsEngine(CGsEngine *pEngine)
{
	Cleanup();
	m_pEngine	= pEngine;
}

VOID CGsAnimation::PlayToEnd(BOOL bReset, float delay)
{
	if(bReset)
		m_current_frame	= m_start_frame;
	Play(GS_ANI_PLAY_LOOP, bReset, 0, _m_frame_delay*(m_frame_per_direction)-1, delay);
}

VOID CGsAnimation::PlayToStart(BOOL bReset, float delay)
{
	if(bReset)
		m_current_frame	= m_end_frame;
	Play(GS_ANI_PLAY_LOOP_BACK, bReset, 0, _m_frame_delay*(m_frame_per_direction)-1, delay);
}

VOID CGsAnimation::SetPos(int pos)
{
	if(pos<0 || pos>m_num_frame)
	{
		m_current_frame	= m_end_frame;
	}
	else
	{
		m_current_frame	= pos + m_start_frame;
	}
}

HRESULT CGsAnimation::Draw(LONG x, LONG y, 					  
						 FLOAT fZValue,
						 FLOAT fScaleW,			
						 FLOAT fScaleH,					
						 FLOAT fAlpha,					
						 FLOAT fAngle,					
						 D3DCOLOR cMix)
{
	if(!m_pEngine || !m_texture_group)
		return S_OK;
	CGsTexture* pTex;
	if(m_flag&TXG_FLAG_SHADOW)
	{
		if(m_apFrameData)
		{
			pTex = m_texture_group->GetTexture((m_apFrameData[m_start_frame + (m_current_frame)%m_frame_per_direction].index + m_base_frame+m_num_frame/m_num_direction/2)%m_num_frame);
		}
		else
		{
			pTex = m_texture_group->GetTexture((m_start_frame + (m_current_frame)%m_frame_per_direction + m_base_frame+m_frame_per_direction)%m_num_frame);
		}
		//if(pTex)
		//{
		//	pTex->UpdateFromCache();
		//}
		m_pEngine->Render_Paint(x, 
										y, 
										pTex,
										   fZValue,
										   fScaleW,
										   fScaleH,
										   fAlpha,
										   fAngle,
										   cMix);
	}
	if(m_apFrameData)
	{
		pTex = m_texture_group->GetTexture((m_apFrameData[m_start_frame + (m_current_frame)%m_frame_per_direction].index + m_base_frame)%m_num_frame);
	}
	else
	{
		pTex = m_texture_group->GetTexture((m_start_frame + (m_current_frame)%m_frame_per_direction + m_base_frame)%m_num_frame);
	}
	//if(pTex)
	//{
	//	pTex->UpdateFromCache();
	//}
	return m_pEngine->Render_Paint(x, 
									y, 
									pTex,
									   fZValue,
									   fScaleW,
									   fScaleH,
									   fAlpha,
									   fAngle,
									   cMix);
}

HRESULT CGsAnimation::DrawFast(LONG x, LONG y,					  
							 FLOAT fZValue,
							 FLOAT fScaleW,			
							 FLOAT fScaleH,					
							 FLOAT fAlpha,					
							 D3DCOLOR cMix)
{
	if(!m_pEngine || !m_texture_group)
		return S_OK;
	CGsTexture* pTex;
	if(m_flag&TXG_FLAG_SHADOW)
	{
		if(m_apFrameData)
		{
			pTex = m_texture_group->GetTexture((m_apFrameData[m_start_frame + (m_current_frame)%m_frame_per_direction].index + m_base_frame+m_num_frame/m_num_direction/2)%m_num_frame);
		}
		else
		{
			pTex = m_texture_group->GetTexture((m_start_frame + (m_current_frame)%m_frame_per_direction + m_base_frame+m_frame_per_direction)%m_num_frame);
		}
		//if(pTex)
		//{
		//	pTex->UpdateFromCache();
		//}
		m_pEngine->Render_PaintFast(x, 
									   y, 
									   pTex,
									   fZValue,
									   fScaleW,
									   fScaleH,
									   fAlpha,
									   cMix);
	}
	if(m_apFrameData)
	{
		pTex = m_texture_group->GetTexture((m_apFrameData[m_start_frame + (m_current_frame)%m_frame_per_direction].index + m_base_frame)%m_num_frame);
	}
	else
	{
		pTex = m_texture_group->GetTexture((m_start_frame + (m_current_frame)%m_frame_per_direction + m_base_frame)%m_num_frame);
	}
	//if(pTex)
	//{
	//	pTex->UpdateFromCache();
	//}
	return m_pEngine->Render_PaintFast(x, 
									   y, 
									   pTex,
									   fZValue,
									   fScaleW,
									   fScaleH,
									   fAlpha,
									   cMix);

}

HRESULT CGsAnimation::ReleaseObjects()
{
	if(m_texture_group)
		m_texture_group->ReleaseObjects();
	return S_OK;
}

VOID CGsAnimation::SetCache(int cache)
{
	if(m_texture_group)
		m_texture_group->SetCacheSize(cache);
}

VOID CGsAnimation::SetFaceTo(float fAngle)
{
//	while(fAngle<m_angle_base)
//	{
//		fAngle	+= const_2_PI;
//	}
	m_base_frame	= ((int)((fAngle - m_angle_base)*m_num_direction/const_2_PI) * m_num_frame/m_num_direction)%m_num_frame;

	m_angle_face_to	= fAngle;
}

VOID CGsAnimation::SetFaceToDegree(float degree)
{
	SetFaceTo(D3DXToRadian(degree));
}


VOID CGsAnimation::SetDirection(int nDirection)
{
	if(nDirection<0)
		nDirection	= m_base_frame*m_num_direction/m_num_frame + 1;
	if(nDirection>=m_num_direction)
	{
		nDirection	= nDirection%m_num_direction;
	}

	m_base_frame	= nDirection*m_num_frame/m_num_direction;

	m_angle_face_to	= m_angle_base + const_2_PI*nDirection/m_num_direction;
}

int CGsAnimation::SetDirectionFrame(int frame_in_direction, int direction)
{
	if(0==m_frame_per_direction)
	{
		return -1;
	}
	if(frame_in_direction==GSANI_FRAME_NOCHANGE)
	{
		frame_in_direction = m_current_frame%m_frame_per_direction;
	}
	if(direction==GSANI_DIRECTION_NOCHANGE)
	{
		direction	= m_current_frame/m_frame_per_direction;
	}
	else
	{
		direction	= direction%m_num_direction;
		m_angle_face_to	= m_angle_base + const_2_PI*direction/m_num_direction;
		m_base_frame	= direction*m_num_frame/m_num_direction;
	}
	m_current_frame	= direction*m_frame_per_direction + frame_in_direction;
//	if(direction!=GSANI_DIRECTION_NOCHANGE)
//	{
//		m_angle_face_to	= 360.0f*(m_current_frame/m_frame_per_direction)/m_num_direction;
//	}
	return m_current_frame;

}

GSANI_FRAME CGsAnimation::GetAniFrame(int index)
{
	if(index<0)
	{
		index	= 0;
	}
	if(index>=m_frame_per_direction)
	{
		index	= index%m_frame_per_direction;
	}

	if(m_apFrameData)
	{
		return m_apFrameData[index];
	}
	else
	{
		GSANI_FRAME	ani_frame;
		ani_frame.index	= index;
		ani_frame.flag	= 0;
		return ani_frame;
	}

}

BOOL CGsAnimation::SetAniFrame(int index, GSANI_FRAME *pframe)
{
	if(index==0 && pframe==NULL)
	{
		index	= m_frame_per_direction;
	}
	else if(index<0 && pframe==NULL)
	{
		index	= m_frame_per_direction-2;
	}

	if(index>=m_frame_per_direction || pframe==NULL)
	{
		GSANI_FRAME*	apNewFrame	= new GSANI_FRAME[index+1];
		if(apNewFrame==NULL)
			return FALSE;
		int index_temp = 0;
		for(int i=0; i<=index && i<m_frame_per_direction; i++)
		{
			apNewFrame[i]	= GetAniFrame(i);
			index_temp = i;
		}
		for(;i<=index;i++)
		{
			apNewFrame[i]	= apNewFrame[index_temp];
		}
		if(pframe)
			apNewFrame[index]	= *pframe;
		SAFE_DELETE_ARRAY(m_apFrameData);
		m_apFrameData	= apNewFrame;
		m_frame_per_direction	= index+1;
		m_end_frame	= index;

	}
	else
	{
		if(m_apFrameData==NULL)
		{
			GSANI_FRAME*	apNewFrame	= new GSANI_FRAME[m_frame_per_direction];
			for(int i=0; i<m_frame_per_direction; i++)
			{
				apNewFrame[i]	= GetAniFrame(i);
			}
			m_apFrameData	= apNewFrame;
		
		}
		m_apFrameData[index]	= *pframe;
	}
	return TRUE;
}

BOOL CGsAnimation::Save(CConfig &cfg)
{
	cfg.WriteString("animation", "GLOBALS", "config");
	cfg.WriteLong(m_frame_per_direction, "MAIN", "frame_count");

	cfg.WriteLong(_m_frame_delay, "MAIN", "frame_delay");
	cfg.WriteLong(0, "MAIN", "current_frame");
	cfg.WriteString(m_texture_group->GetSourceName(), "MAIN", "image");

	char strTemp[255];
	for(int i=0; i<m_frame_per_direction; i++)
	{
		GSANI_FRAME	frame = GetAniFrame(i);
		sprintf(strTemp, "frame_%d_index", i+1);
		cfg.WriteLong(frame.index, "MAIN", strTemp);
		sprintf(strTemp, "frame_%d_flag", i+1);
		cfg.WriteLong(frame.flag, "MAIN", strTemp);
	}


	return TRUE;
}

BOOL CGsAnimation::Export(LPCSTR strFile)
{
	if(strFile)
	{
		FILE* file= fopen(strFile, "w");
		if(NULL==file)
		{
			return FALSE;
		}
		fclose(file);
		CConfig cfg(strFile);
		return Save(cfg);
	}
	else
	{
		CConfig cfg;
		if(FALSE==m_pEngine->LoadConfig(cfg, m_key_config.c_str()))
			return FALSE;
		return Save(cfg);
	}

	return FALSE;
}

VOID CGsAnimation::SetCurrentFrame(int index)
{
	if(index<0)
	{
		m_current_frame	= m_frame_per_direction-1;
	}
	else
	{
		m_current_frame	= index%m_frame_per_direction;
	}
}

LPCSTR CGsAnimation::GetImage()
{
	if(m_texture_group)
		return m_texture_group->GetSourceName();

	return NULL;
}


void CGsAnimation::AttachAni(GSANI *pAni)
{
	if(pAni)
	{
		_m_is_frame_up	= pAni->_m_is_frame_up;
		_m_play_flag	= pAni->_m_play_flag;
		_m_base_tick		= pAni->_m_base_tick;
		_m_pass_tick		= pAni->_m_pass_tick;
		_m_play_tick		= pAni->_m_play_tick;
		SetFaceTo(pAni->m_angle_face_to);
	}
}

float CGsAnimation::GetFinishPercent()
{
	return m_current_frame*100.0f/m_frame_per_direction;
}

BOOL CGsAnimation::TestByPercent(float per)
{
	if(m_percent_by<per && GetFinishPercent()>per)
	{
		m_percent_by	= per;
		return TRUE;
	}
	else
		return FALSE;
}


float CGsAnimation::GetAngleFaceToDegree()
{
	return D3DXToDegree(m_angle_face_to);
}

int CGsAnimation::SetCurrentUse(BOOL use)
{
	if(m_texture_group)
		return m_texture_group->SetCurrentUse(use);
	else
		return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -