quinta-feira, 13 de outubro de 2011

void CSoundMaker::SendMsg(CGameObject*,int,int,int,int)

void CSoundMaker::SendMsg(CGameObject* sender, int message, int arg1, int arg2, int arg3)
{
switch( message )
{
default:
this->CRenderObject::SendMsg(sender,message,arg1,arg2,arg3);
return;
case 0xE:
{
C3dWorldRes::soundSrcInfo* sound = (C3dWorldRes::soundSrcInfo*)arg1;
m_waveName = sound->waveName;// std::string <- char[80]
m_vol = sound->vol;// float <- float
m_width = sound->width;// int <- int
m_height = sound->height;// int <- int
m_pos.x = sound->pos.x;// float <- float
m_pos.y = sound->pos.y;// float <- float
m_pos.z = sound->pos.z;// float <- float
m_diagonal = sqrt(m_width*m_width + m_height*m_height);// float
m_cycle = ftol(sound->cycle*1000.0f);
m_lastPlayTime = timeGetTime() - m_cycle;
return;
}
}
}

void CSoundMaker::OnProcess()

// FUNC: float CRenderObject::CalcDist(float x, float y);
// FUNC: PlayWave(const char *waveFileName, float x, float y, float z, int volumeMaxDist, int volumeMinDist, float vFactor);
// VAR: float CSoundMaker::m_diagonal = sqrt(m_width*m_width + m_height*m_height);
void CSoundMaker::OnProcess()
{
CPlayer* player = g_modeMgr.GetGameMode()->m_world->m_player;
if( CalcDist(player->m_pos.x,player->m_pos.z) - (m_diagonal+m_range) <= 130.0f )
{// passed circular range
float dist_x = player.m_pos.x - m_pos.x
float dist_z = player.m_pos.z - m_pos.z
float sign_x = (dist_x >= 0.0f)? 1.0f: -1.0f;
float sign_z = (dist_z >= 0.0f)? 1.0f: -1.0f;
float cZ = dist_z / dist_x;
float todo_x;
float todo_z;
if( (double)abs(cZ) <= (double)(m_height / m_width) )
{// TODO it's probably getting the point in the elipse for the direction between this soundmaker and the player
todo_x = m_width * sign_x * 0.5;
todo_z = todo_x * cZ;
}
else
{
todo_z = m_height * sign_z * 0.5;
todo_x = todo_z / cZ;
}
float point_x = todo_x + m_pos.x;
float point_z = todo_z + m_pos.y;
if( player->CalcDist(point_x,point_z) - m_range <= 75.0f && m_waveName.length() > 0 && timeGetTime() > m_lastPlayTime + m_cycle )
{// TODO passed elliptic range?
m_lastPlayTime = timeGetTime();
float x = point_x - player->m_pos.x;
float y = 0.0f;
float z = point_z - player->m_pos.z;
int volumeMaxDist = ftol(m_range);
int volumeMinDist = ftol(m_range*(1.0f/6.0f));
float vFactor = m_vol;
PlayWave(m_waveName.c_str(),x,y,z,volumeMaxDist,volumeMinDist,vFactor);
}
}
}