void CWeaponStatMgun::net_Import(NET_Packet& P) // import from server { inheritedPH::net_Import (P); u8 state = P.r_u8(); load_data (m_destEnemyDir, P); if(TRUE==IsWorking()&&!state) FireEnd (); if(FALSE==IsWorking()&&state) FireStart (); }
void AudioCaptureThread::ON_WIMDATA(WPARAM wParam, LPARAM lParam) { if(IsWorking()) { #ifdef ENABLE_AUDIO_DENOISE Denoise((BYTE*)((PWAVEHDR)lParam)->lpData, ((PWAVEHDR)lParam)->dwBytesRecorded); #endif//ENABLE_AUDIO_DENOISE static ULONG ulPkgNo = 0; MMRESULT mmResult = MMSYSERR_NOERROR; PWAVEHDR waveHdr = (PWAVEHDR) lParam; #ifdef ENABLE_AUDIO_AEC VERIFY(::GetMicQueue()); { double dCurTime = jrtplib::RTPTime::CurrentTime().GetDouble(); RecPkgQueue::element_type bufAEC(new AudioBuffer((BYTE*)waveHdr->lpData, waveHdr->dwBytesRecorded, dCurTime)); if (IsWorking()) { ::GetMicQueue()->push_back(bufAEC); #ifdef PRINT_AEC_INFO SPRINTF_S(dbg_str, "Audio data: mic recv= %d" "\ttime: %f" , ulPkgNo , dCurTime); DEBUG_INFO(dbg_str); #endif//PRINT_AEC_INFO } } #else //ENABLE_AUDIO_AEC RecPkgQueue::element_type buf2Send(new AudioBuffer((BYTE*)((PWAVEHDR)lParam)->lpData, ((PWAVEHDR)lParam)->dwBytesRecorded, 0)); ((AudioSendSession*)m_pSession)->getPackageQueue()->push_back(buf2Send); #endif//ENABLE_AUDIO_AEC //mmResult = ::waveInPrepareHeader (hWaveIn, waveHdr, sizeof(WAVEHDR)); //checkMMError(mmResult, true); waveHdr->dwFlags = WHDR_PREPARED; mmResult = ::waveInAddBuffer (m_hWaveIn, waveHdr, sizeof(WAVEHDR)); checkMMError(mmResult, true); ++ulPkgNo; } }
BOOL CEasyThread::Start(BOOL IsSuspended) { unsigned int ThreadID; int Flag = 0; if(IsWorking()) return FALSE; if (IsSuspended) { Flag = CREATE_SUSPENDED; m_IsSuspended = TRUE; } else m_IsSuspended = FALSE; m_IsWorking=TRUE; m_IsTerminate=FALSE; HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, CEasyThread::ThreadProc, (void*)this, Flag, (UINT *)&ThreadID); if (hThread == INVALID_HANDLE_VALUE) return FALSE; m_ThreadID = ThreadID; m_hThread = hThread; return TRUE; }
int FAACEncoder::Init(int nSampleRate, int nChannels) { if (IsWorking()) { return 0; } m_nSampleRate = nSampleRate; m_nChannels = nChannels; m_hfaac = faacEncOpen(m_nSampleRate, m_nChannels, &m_nInputSamples, &m_nMaxOutputBytes); if (m_hfaac!=NULL) { m_pfaacconf = faacEncGetCurrentConfiguration(m_hfaac); m_pfaacconf->inputFormat = FAAC_INPUT_16BIT; m_pfaacconf->outputFormat=1;//0raw 1adst m_pfaacconf->useTns=true; m_pfaacconf->useLfe=false; m_pfaacconf->aacObjectType=LOW; m_pfaacconf->shortctl=SHORTCTL_NORMAL; m_pfaacconf->quantqual=100; m_pfaacconf->bandWidth=0; m_pfaacconf->bitRate=0; faacEncSetConfiguration(m_hfaac,m_pfaacconf); faacEncGetDecoderSpecificInfo(m_hfaac,&m_pfaacinfobuffer,&m_nfaacinfosize); } return 0; }
void CHelicopter::MGunFireStart() { if(!m_use_mgun_on_attack) return; if(FALSE==IsWorking() && m_enemy.bUseFireTrail){ //start calc fire trail m_enemy.fStartFireTime = Device.fTimeGlobal; Fvector fp = get_CurrentFirePoint(); Fvector ep = m_enemy.destEnemyPos; //calc min firetrail length float h = fp.y-ep.y; if(h>0.0f){ float dl =h*tan(m_lim_x_rot.y); float ds = fp.distance_to_xz(ep); if(ds>dl){ float half_trail = ds-dl; m_enemy.fire_trail_length_curr = half_trail*2.0f; clamp(m_enemy.fire_trail_length_curr,0.0f,m_enemy.fire_trail_length_des); // Msg("Start fire. Desired length=%f, cur_length=%f",m_enemy.fire_trail_length_des,m_enemy.fire_trail_length_curr); }else m_enemy.fire_trail_length_curr = m_enemy.fire_trail_length_des; }else m_enemy.fire_trail_length_curr = m_enemy.fire_trail_length_des; } CShootingObject::FireStart (); }
void UpdateAI(uint32 diff) override { if (IsWorking()) me->HandleEmoteCommand(EMOTE_ONESHOT_WORK_MINING); if (rebuffTimer <= diff) { Reset(); switch (urand(0, 2)) { case 0: me->HandleEmoteCommand(EMOTE_STATE_EXCLAIM); break; case 1: me->HandleEmoteCommand(EMOTE_STATE_DANCE); break; case 2: me->HandleEmoteCommand(EMOTE_ONESHOT_NONE); break; } rebuffTimer = 120000; // Rebuff again in 2 minutes } else rebuffTimer -= diff; if (!UpdateVictim()) return; //DoMeleeAttackIfReady(); }
int CAACEncoderManager::Init() { if (IsWorking()) { return 0; } // Clean(); EnterCriticalSection(&m_hcritical_section); m_hAACEncoder = faacEncOpen(m_nSampleRate, m_nChannels, &m_nInputSamples, &m_nMaxOutputBytes); if (m_hAACEncoder!=NULL) { m_pAACConfiguration = faacEncGetCurrentConfiguration(m_hAACEncoder); m_pAACConfiguration->inputFormat = FAAC_INPUT_16BIT; m_pAACConfiguration->outputFormat=0;//0raw 1adst m_pAACConfiguration->useTns=true; m_pAACConfiguration->useLfe=false; m_pAACConfiguration->aacObjectType=LOW; m_pAACConfiguration->shortctl=SHORTCTL_NORMAL; m_pAACConfiguration->quantqual=100; m_pAACConfiguration->bandWidth=0; m_pAACConfiguration->bitRate=0; faacEncSetConfiguration(m_hAACEncoder,m_pAACConfiguration); } LeaveCriticalSection(&m_hcritical_section); return 0; }
void CWeaponMagazined::state_Fire(float dt) { VERIFY(fTimeToFire > 0.f); Fvector p1, d; p1.set(get_LastFP()); d.set(get_LastFD()); if (!H_Parent()) return; CInventoryOwner* io = smart_cast<CInventoryOwner*>(H_Parent()); if (NULL == io->inventory().ActiveItem()) { Log("current_state", GetState()); Log("next_state", GetNextState()); Log("state_time", m_dwStateTime); Log("item_sect", cNameSect().c_str()); Log("H_Parent", H_Parent()->cNameSect().c_str()); } smart_cast<CEntity*> (H_Parent())->g_fireParams(this, p1, d); if (m_iShotNum == 0) { m_vStartPos = p1; m_vStartDir = d; }; VERIFY(!m_magazine.empty()); // Msg("%d && %d && (%d || %d) && (%d || %d)", !m_magazine.empty(), fTime<=0, IsWorking(), m_bFireSingleShot, m_iQueueSize < 0, m_iShotNum < m_iQueueSize); while (!m_magazine.empty() && fTime <= 0 && (IsWorking() || m_bFireSingleShot) && (m_iQueueSize < 0 || m_iShotNum < m_iQueueSize)) { m_bFireSingleShot = false; VERIFY(fTimeToFire > 0.f); fTime += fTimeToFire; ++m_iShotNum; OnShot(); static int i = 0; if (i || m_iShotNum > m_iShootEffectorStart) { // Do Weapon Callback. (Cribbledirge) StateSwitchCallback(GameObject::eOnActorWeaponFire, GameObject::eOnNPCWeaponFire); FireTrace(p1, d); } else { FireTrace(m_vStartPos, m_vStartDir); } } if (m_iShotNum == m_iQueueSize) m_bStopedAfterQueueFired = true; UpdateSounds(); }
void CCustomDetector::UpdateCL() { inherited::UpdateCL(); UpdateVisibility (); if( !IsWorking() ) return; UpfateWork (); }
void CCustomDetector::shedule_Update(u32 dt) { inherited::shedule_Update(dt); if( !IsWorking() ) return; Position().set(H_Parent()->Position()); Fvector P; P.set (H_Parent()->Position()); m_artefacts.feel_touch_update(P,m_fAfDetectRadius); }
bool Worker::AddWork(Work* someWork) { if (IsWorking() == false) { myWork = someWork; myConditionVariable.notify_one(); return true; } else { return false; } }
void MScheduler::WaitForAllJobs() { // determine which worker thread we are (if we are one) const uint32 workerId = GetCurrentWorkerId(); LWorker *const pWorker = workerId < m_cWorkers ? m_pWorkers[ workerId ] : nullptr; CAutoNotifyWaitWork Notification_WaitWork_; // work completion checking static const uint32 kMinCheckWorkingSpins = 16; static const uint32 kMaxCheckWorkingSpins = kBackoffMaxSpinCount; uint32 cCheckWorkingSpins = kMinCheckWorkingSpins; // if we are a worker then work until we have nothing else if( pWorker != nullptr ) { AX_ASSERT_MSG( workerId == 0, "Only the main thread or a non-worker thread can wait for jobs to complete" ); // do work until all workers have no work to do do { // // NOTE: We want to "work until no work" as other workers may // - be finishing the last of theirs to release // - dependencies into the queue. // if( !pWorker->ExecuteUntilNoWork() ) { NotifyIdleSpin(); Backoff( cCheckWorkingSpins, kMaxCheckWorkingSpins ); } else if( cCheckWorkingSpins > kMinCheckWorkingSpins*2 ) { cCheckWorkingSpins = cCheckWorkingSpins/2; } } while( IsWorking() ); } else { // wait until all workers become idle as well -- do not sleep here while( IsWorking() ) { Backoff( cCheckWorkingSpins, kMaxCheckWorkingSpins ); } } }
BOOL CEasyThread::WaitForTerminate(DWORD Milliseconds) { if(Milliseconds==INFINITE) { while(IsWorking()) { Sleep(10); } return TRUE; } else { CEasyTimer Timer; Timer.SetTimeOut(Milliseconds); while(!Timer.IsTimeOut()) { if(!IsWorking()) return TRUE; Sleep(10); } return FALSE; } }
void CHelicopter::MGunUpdateFire() { fShotTimeCounter -= Device.fTimeDelta; if (delta_t < 0){ delta_t = Device.fTimeGlobal; flag_by_fire = 0; } float time_f = Device.fTimeGlobal - delta_t; float fire_time; if(pSettings->line_exist(*cNameSect(),"fire_time")) fire_time = pSettings->r_float(*cNameSect(),"fire_time"); else fire_time = -1; float no_fire_time; if(pSettings->line_exist(*cNameSect(),"no_fire_time")) no_fire_time = pSettings->r_float(*cNameSect(),"no_fire_time"); else no_fire_time = -1; CShootingObject::UpdateFlameParticles(); CShootingObject::UpdateLight(); if(!IsWorking()) { clamp(fShotTimeCounter,0.0f, flt_max); return; } if(no_fire_time > 0 && fire_time > 0) { if (flag_by_fire==1 && time_f > fire_time){ delta_t = Device.fTimeGlobal; time_f = Device.fTimeGlobal - delta_t; flag_by_fire = 0; } if (time_f > no_fire_time && flag_by_fire ==0){ delta_t = Device.fTimeGlobal; time_f = Device.fTimeGlobal - delta_t; flag_by_fire = 1; } if(flag_by_fire ==0 && time_f < no_fire_time) return; } if(fShotTimeCounter<=0) { OnShot(); fShotTimeCounter += fOneShotTime; } }
void CCustomDetector::UpdateNightVisionMode() { // CObject* tmp = Level().CurrentViewEntity(); bool bNightVision = false; if (GameID() == GAME_SINGLE) { bNightVision = Actor()->Cameras().GetPPEffector(EEffectorPPType(effNightvision))!=NULL; } else { if (Level().CurrentViewEntity() && Level().CurrentViewEntity()->CLS_ID == CLSID_OBJECT_ACTOR) { CActor* pActor = smart_cast<CActor*>(Level().CurrentViewEntity()); if (pActor) bNightVision = pActor->Cameras().GetPPEffector(EEffectorPPType(effNightvision))!=NULL; } } bool bOn = bNightVision && m_pCurrentActor && m_pCurrentActor==Level().CurrentViewEntity()&& IsWorking() && m_nightvision_particle.size(); ZONE_INFO_MAP_IT it; for(it = m_ZoneInfoMap.begin(); m_ZoneInfoMap.end() != it; ++it) { CCustomZone *pZone = it->first; ZONE_INFO& zone_info = it->second; if(bOn){ Fvector zero_vector; zero_vector.set(0.f,0.f,0.f); if(!zone_info.pParticle) zone_info.pParticle = CParticlesObject::Create(*m_nightvision_particle,FALSE); zone_info.pParticle->UpdateParent(pZone->XFORM(),zero_vector); if(!zone_info.pParticle->IsPlaying()) zone_info.pParticle->Play(); }else{ if(zone_info.pParticle){ zone_info.pParticle->Stop (); CParticlesObject::Destroy(zone_info.pParticle); } } } }
void CCustomDetector::shedule_Update(u32 dt) { inherited::shedule_Update (dt); if( !IsWorking() ) return; if( !H_Parent() ) return; Position().set(H_Parent()->Position()); Fvector P; P.set (H_Parent()->Position()); feel_touch_update (P,m_fRadius); UpdateNightVisionMode(); }
void CWeaponMagazined::switch2_Fire() { CInventoryOwner* io = smart_cast<CInventoryOwner*>(H_Parent()); CInventoryItem* ii = smart_cast<CInventoryItem*>(this); #ifdef DEBUG VERIFY2(io, make_string("no inventory owner, item %s", *cName())); if (ii != io->inventory().ActiveItem()) Msg("! not an active item, item %s, owner %s, active item %s", *cName(), *H_Parent()->cName(), io->inventory().ActiveItem() ? *io->inventory().ActiveItem()->object().cName() : "no_active_item"); if (!(io && (ii == io->inventory().ActiveItem()))) { CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(H_Parent()); if (stalker) { stalker->planner().show(); stalker->planner().show_current_world_state(); stalker->planner().show_target_world_state(); } } #else if (!io) return; #endif // DEBUG // // VERIFY2( // io && (ii == io->inventory().ActiveItem()), // make_string( // "item[%s], parent[%s]", // *cName(), // H_Parent() ? *H_Parent()->cName() : "no_parent" // ) // ); m_bStopedAfterQueueFired = false; m_bFireSingleShot = true; m_iShotNum = 0; if ((OnClient() || Level().IsDemoPlay()) && !IsWorking()) FireStart(); /* if(SingleShotMode()) { m_bFireSingleShot = true; bWorking = false; }*/ }
void CCustomDetector::UpdateCL() { inherited::UpdateCL(); if( !IsWorking() ) return; if( !H_Parent() ) return; if(!m_pCurrentActor) return; ZONE_INFO_MAP_IT it; for(it = m_ZoneInfoMap.begin(); m_ZoneInfoMap.end() != it; ++it) { CCustomZone *pZone = it->first; ZONE_INFO& zone_info = it->second; //такой тип зон не обнаруживается if(m_ZoneTypeMap.find(pZone->CLS_ID) == m_ZoneTypeMap.end() || !pZone->VisibleByDetector()) continue; ZONE_TYPE& zone_type = m_ZoneTypeMap[pZone->CLS_ID]; float dist_to_zone = H_Parent()->Position().distance_to(pZone->Position()) - 0.8f*pZone->Radius(); if(dist_to_zone<0) dist_to_zone = 0; float fRelPow = 1.f - dist_to_zone / m_fRadius; clamp(fRelPow, 0.f, 1.f); //определить текущую частоту срабатывания сигнала zone_info.cur_freq = zone_type.min_freq + (zone_type.max_freq - zone_type.min_freq) * fRelPow* fRelPow* fRelPow* fRelPow; float current_snd_time = 1000.f*1.f/zone_info.cur_freq; if((float)zone_info.snd_time > current_snd_time) { zone_info.snd_time = 0; HUD_SOUND::PlaySound (zone_type.detect_snds, Fvector().set(0,0,0), this, true, false); } else zone_info.snd_time += Device.dwTimeDelta; } }
void CHelicopter::MGunUpdateFire() { fTime -= Device.fTimeDelta; CShootingObject::UpdateFlameParticles(); CShootingObject::UpdateLight(); if(!IsWorking()) { if(fTime<0) fTime = 0.f; return; } if(fTime<=0) { OnShot(); fTime += fTimeToFire; } }
void CWeaponStatMgun::UpdateFire() { fShotTimeCounter -= Device.fTimeDelta; inheritedShooting::UpdateFlameParticles(); inheritedShooting::UpdateLight(); if(!IsWorking()){ clamp(fShotTimeCounter,0.0f, flt_max); return; } if(fShotTimeCounter<=0) { OnShot (); fShotTimeCounter += fOneShotTime; }else { angle_lerp (m_dAngle.x,0.f,5.f,Device.fTimeDelta); angle_lerp (m_dAngle.y,0.f,5.f,Device.fTimeDelta); } }
void CWeaponMagazined::FireStart() { if (IsValid() && !IsMisfire()) { if (!IsWorking() || AllowFireWhileWorking()) { if (GetState() == eReload) return; if (GetState() == eShowing) return; if (GetState() == eHiding) return; if (GetState() == eMisfire) return; inherited::FireStart(); if (iAmmoElapsed == 0) OnMagazineEmpty(); else SwitchState(eFire); } } else { if (eReload != GetState() && eMisfire != GetState()) OnMagazineEmpty(); } }
void CCarWeapon::UpdateFire() { fTime -= Device.fTimeDelta; inheritedShooting::UpdateFlameParticles(); inheritedShooting::UpdateLight(); if(m_bAutoFire){ if(m_allow_fire){ FireStart(); }else FireEnd(); }; if(!IsWorking()){ if(fTime<0) fTime = 0.f; return; } if(fTime<=0){ OnShot(); fTime += fTimeToFire; } }
// Called every frame void AJustDoITWorkplace::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); bIsWorking = IsWorking(); }
void CWeaponStatMgun::net_Export(NET_Packet& P) // export to server { inheritedPH::net_Export (P); P.w_u8 (IsWorking() ? 1 : 0); save_data (m_destEnemyDir, P); }
void AudioAECThread::DoJob() { DEBUG_INFO("AudioAECThread::DoJob()......"); #ifdef ENABLE_AUDIO_AEC RecPkgQueue* pQueueMic = ::GetMicQueue(); RecPkgQueue* pQueueRef = ::GetRefQueue(); RecPkgQueue* pQueueOut = ::GetOutQueue(); AECQueue aecQueue(pQueueMic, pQueueRef); EchoCanceller aec; bool bUseAEC = ::GetUseAEC();// enable AEC on recorded data ? BYTE* pAecOut = NULL; if (bUseAEC) { aec.Init(); pAecOut = new BYTE[RECORD_SEND_BUFFER_SIZE]; //TODO: customization needed DEBUG_INFO(L"AEC EN-ABLED for audio data"); } else DEBUG_INFO(L"AEC DIS-ABLED for audio data"); int nSentMiced = 0; double dLastMatchedMic = 0, dLastMatchedRef = 0; bool bMatchedBefore = false; for(; IsWorking(); ) { while (IsWorking() && pQueueMic->size()) { if (bUseAEC) { if ( pQueueRef->size() == 0 ) { //TODO: no play data, if never did AEC, record data is ok to send out // otherwise, reserve for sync & AEC if (!bMatchedBefore) { #ifdef PRINT_AEC_INFO SPRINTF_S(dbg_str, "Audio data: mic sent= %d" , nSentMiced); DEBUG_INFO(dbg_str); #endif//PRINT_AEC_INFO ++nSentMiced; RecPkgQueue::const_reference& pBufMic = pQueueMic->front(); pQueueOut->push_back(pBufMic); pQueueMic->pop_front(); } } else { int idxMic = 0, idxRef = 0; bool bMatch = aecQueue.FindMatch(AEC_TIME_OFFSET, MAX_AEC_TIME_INTERVAL, idxMic, idxRef); if (bMatch) { bMatchedBefore = true; while (idxMic > 0) { pQueueMic->pop_front(); --idxMic; } while (idxRef > 1) // TODO: reserve 1 play for later match { pQueueRef->pop_front(); --idxRef; } RecPkgQueue::const_reference& pBufMic = pQueueMic->front(); RecPkgQueue::reference& pBufRef = pQueueRef->front(); if (idxRef == 1) pBufRef = pQueueRef->at(1); const int nSizeMic = pBufMic->getSize(); const int nSizeRef = pBufRef->getSize(); ASSERT(nSizeMic == nSizeRef); aec.DoAEC(pBufMic->getBuffer(), pBufRef->getBuffer(), pAecOut); RecPkgQueue::element_type buf2Send(new AudioBuffer(pAecOut, RECORD_SEND_BUFFER_SIZE, 0));//TODO: customization needed pQueueOut->push_back(buf2Send); pQueueMic->pop_front(); } else { // if can't found matched audio data, reserve it for later use #ifdef PRINT_AEC_INFO SPRINTF_S(dbg_str, "Audio data match failed, ref queue = %d" , pQueueRef->size()); DEBUG_INFO(dbg_str); #endif//PRINT_AEC_INFO } jrtplib::RTPTime::Wait(jrtplib::RTPTime(0, 1)); } } else // bUseAEC == false { RecPkgQueue::const_reference& pBufMic = pQueueMic->front(); pQueueOut->push_back(pBufMic); pQueueMic->pop_front(); } jrtplib::RTPTime::Wait(jrtplib::RTPTime(0, 1)); } jrtplib::RTPTime::Wait(jrtplib::RTPTime(0, 1)); } if (bUseAEC) { aec.Uninit(); delete[] pAecOut; } #else//ENABLE_AUDIO_AEC ASSERT(0); // use this thread while ENABLE_AUDIO_AEC disabled? #endif//ENABLE_AUDIO_AEC DEBUG_INFO("AudioAECThread::DoJob() DONE"); }
bool CEliteDetector::render_item_3d_ui_query() { return IsWorking(); }
void CCustomDetector::UpdateMapLocations() // called on turn on/off only { ZONE_INFO_MAP_IT it; for(it = m_ZoneInfoMap.begin(); it != m_ZoneInfoMap.end(); ++it) AddRemoveMapSpot(it->first,IsWorking()); }