virtual bool IsDone() const{ if(!snd->IsPlaying() && GetPlayPos()==GetPlayTime()){ //finish with some delay, so that hw has time to play the sound if(!end_play_time) end_play_time = GetTickTime(); if(GetTickTime()-end_play_time > 1000) return true; } return false; }
void C_thread::CreateThread(E_PRIORITY priority){ quit_request = false; KillThread(); status = STATUS_STARTING; RThread1 *tp = new(true) RThread1; tp->owner = (C_thread_access*)this; #ifndef __SYMBIAN_3RD__ tp->gd = GetGlobalData(); #endif imp = tp; //make unique thread name Cstr_w tname; tname<<L"Thread-" <<GetTickTime(); tp->Create(TPtrC((const word*)(const wchar*)tname, tname.Length()), ThreadProcThunk, 8192, NULL, tp); TThreadPriority pr; switch(priority){ case PRIORITY_VERY_LOW: pr = EPriorityMuchLess; break; case PRIORITY_LOW: pr = EPriorityLess; break; default: assert(0); case PRIORITY_NORMAL: pr = EPriorityNormal; break; case PRIORITY_HIGH: pr = EPriorityMore; break; case PRIORITY_VERY_HIGH: //pr = EPriorityRealTime; pr = EPriorityAbsoluteHigh; break; } tp->SetPriority(pr); tp->Resume(); }
void C_sound_writer_mixer::ResetBufferPos(){ pos_read = pos_write = 0; curr_time_system_base = pause_time_system_base = GetTickTime(); last_time = 0xffffffff; last_mix_time = 0xffffffff; }
void C_sound_writer_mixer::Pause(){ if(is_playing){ //drv->Activate(false); drv->UnregisterSoundWriter(this); pause_time_system_base = GetTickTime(); is_playing = false; } }
void C_sound_writer_mixer::Play(){ if(!is_playing){ is_playing = true; drv->RegisterSoundWriter(this); //drv->Activate(true); curr_time_system_base += GetTickTime()-pause_time_system_base; last_time = 0xffffffff; last_mix_time = 0xffffffff; } }
dword C_sound_writer_mixer::GetCurrTime() const{ int pos = pos_read; pos = Max(0, int(pos)-int(drv->GetHardwareBufferSize())); dword t = pos_read_base_time + GetTimeFromSamples(pos); int delta = (!is_playing ? pause_time_system_base : GetTickTime()) - curr_time_system_base; delta = Max(0, Min(1000, delta)); t += delta; if(last_time!=0xffffffff){ if(t<last_time) t = last_time; } last_time = t; return t; }
void C_sound_writer_mixer::MixIntoBuffer(short *buf, dword num_samples, C_fixed _mix_volume){ //check that we're not ahead of write pointer dword copy_len = Min(num_samples, pos_write-pos_read); if(copy_len < num_samples){ //decoder doesn't have enough data, fill rest by zero MemSet(buf+copy_len, 0, (num_samples - copy_len)*sizeof(short)); if(pos_write){ LOG_DEBUG("Audio buffer underflow, mix silence"); } } const dword DECODE_BUF_MASK = DECODE_BUF_SIZE-1; //copy the temp buffer, and adjust read pointer dword end_pos = pos_read + copy_len; if((pos_read & ~DECODE_BUF_MASK) != ((end_pos-1) & ~DECODE_BUF_MASK)){ dword num = (end_pos & ~DECODE_BUF_MASK) - pos_read; MemCpy(buf, &decode_buf[pos_read&DECODE_BUF_MASK], num*sizeof(short)); pos_read += num; copy_len -= num; buf += num; } MemCpy(buf, &decode_buf[pos_read&DECODE_BUF_MASK], copy_len*sizeof(short)); dword tick_time = GetTickTime(); if(last_time!=0xffffffff){ //compensate for uneven time periods when hw device may call this function dword buf_time = GetTimeFromSamples(num_samples); //proposed (ideal) time when this func is called dword proposed_time = curr_time_system_base + buf_time; //get time delta (error) int time_delta = int(proposed_time)-int(tick_time); //add part of delta to tick time for compensation tick_time += time_delta*3/4; } curr_time_system_base = tick_time; pos_read += copy_len; }
bool CAutoTracker::Init(uint32 uAttackerID, uint32 uTargetID, float fReachGridDist, IAutoTrackerHandler* pHandler, bool bIsNormalAttackTracker) { //if(fReachGridDist < GetDistAdjustment()) //{ // fReachGridDist = GetDistAdjustment() + 0.5f; //} CEntityClient* pAttacker = CEntityClientManager::GetEntityByID(uAttackerID); CCharacterDirector* pCharAttacker = class_cast<CCharacterDirector*>(pAttacker); if(!pCharAttacker || pCharAttacker->CppGetCtrlState(eFCS_ForbitAutoTrack)) return false; CEntityClient* pTarget = CEntityClientManager::GetEntityByID(uTargetID); if (pTarget->GetGameEntityType() == eGET_CharacterFollower) { CCharacterFollower* pCharTarget = class_cast<CCharacterFollower*>(pTarget); CRelationMgrClient& relationMgr = CRelationMgrClient::Inst(); if (relationMgr.GetRelationType(pAttacker->GetFighter(), pCharTarget->GetFighter()) == eRT_DuelTargetWrong) { pCharAttacker->OnMagicCondFail(eDSR_DuelTargetWrong); return false; } } m_uAttackerID = uAttackerID; m_uTargetID = uTargetID; m_fReachGridDist = fReachGridDist; SetHandler(pHandler); m_bIsAutoTracking = true; m_bIsNormalAttackTracker = bIsNormalAttackTracker; m_posDest = CFPos(0.0f, 0.0f); //cout << "CAutoTracker::Init" << endl; pAttacker->RegistDistortedTick(this, GetTickTime()); this->OnTick(); return true; }