本文整理汇总了C++中CHandle类的典型用法代码示例。如果您正苦于以下问题:C++ CHandle类的具体用法?C++ CHandle怎么用?C++ CHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wmain
int wmain(int argc, wchar_t* argv[])
{
// Initialize COM and deinitialize when we go out of scope
HRESULT hrCoInit = ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
shared_ptr<HRESULT> spCoInit(&hrCoInit, [](const HRESULT* hrCom) -> void { if (SUCCEEDED(*hrCom)) { ::CoUninitialize(); } });
{
// Set a close handler to shutdown the chrome instance we launch
::SetConsoleCtrlHandler(OnClose, TRUE);
// Launch chrome
{
CString chromePath;
// Find the chrome install location via the registry
CString keyPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe";
CRegKey regKey;
// First see if we can find where Chrome is installed from the registry. This will only succeed if Chrome is installed for all users
if (regKey.Open(HKEY_LOCAL_MACHINE, keyPath, KEY_READ) == ERROR_SUCCESS)
{
ULONG bufferSize = MAX_PATH;
CString path;
LRESULT result = regKey.QueryStringValue(nullptr, path.GetBufferSetLength(bufferSize), &bufferSize);
path.ReleaseBufferSetLength(bufferSize);
if (result == ERROR_SUCCESS)
{
chromePath = path;
}
}
if (chromePath.GetLength() == 0)
{
// If Chrome is only installed for the current user, look in \AppData\Local\Google\Chrome\Application\ for Chrome.exe
CString appPath;
::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appPath.GetBuffer(MAX_PATH + 1));
appPath.ReleaseBuffer();
chromePath = appPath + L"\\Google\\Chrome\\Application\\chrome.exe";
}
// Get a temp location
CString temp;
Helpers::ExpandEnvironmentString(L"%Temp%", temp);
// Set arguments for the chrome that we launch
CString arguments;
arguments.Format(L"about:blank --remote-debugging-port=9223 --window-size=0,0 --silent-launch --no-first-run --no-default-browser-check --user-data-dir=\"%s\"", temp);
// Launch the process
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof(si);
si.wShowWindow = SW_MINIMIZE;
BOOL result = ::CreateProcess(
chromePath,
arguments.GetBuffer(),
nullptr,
nullptr,
FALSE,
0,
nullptr,
temp,
&si,
&pi);
arguments.ReleaseBuffer();
if (result)
{
// Store the handles
CHandle hThread(pi.hThread);
hChromeProcess.Attach(pi.hProcess);
DWORD waitResult = ::WaitForInputIdle(hChromeProcess, 30000);
}
else
{
std::cerr << "Could not open Chrome. Please ensure that Chrome is installed." << std::endl;
system("pause");
return -1;
}
}
// Get the current path that we are running from
CString fullPath;
DWORD count = ::GetModuleFileName(nullptr, fullPath.GetBuffer(MAX_PATH), MAX_PATH);
fullPath.ReleaseBufferSetLength(count);
LPWSTR buffer = fullPath.GetBuffer();
LPWSTR newPath = ::PathFindFileName(buffer);
if (newPath && newPath != buffer)
{
fullPath.ReleaseBufferSetLength((newPath - buffer));
}
else
{
fullPath.ReleaseBuffer();
}
// Load the proxy server
IEDiagnosticsAdapter proxy(fullPath);
//.........这里部分代码省略.........
示例2: usbdrv_thread
void usbdrv_thread(USB_DRV_INFO drv_info)
{
CHandle helper;
CHandle req_hnd;
USBGenericRequest request;
bool requested = false;
unsigned int sig=0;
ALLOCATE_SIGNAL(USB_DRIVER_SIG);
helper.tsk_safe_open(drv_info->info.drv_index, 0);
helper.tsk_start_command(NULL, 0);
req_hnd.tsk_safe_open(drv_info->info.drv_index, USB_DRV_MODE(EPT_0, EPT_0));
while(1)
{
sig |= tsk_get_signal(SIGNAL_ANY);
// 2) get waiting clients
if(sig & helper.signal)
{
HANDLE client;
sig ^= helper.signal;
helper.res &= ~FLG_SIGNALED;
client = (HANDLE)helper.dst.as_voidptr;
if(client)
{
RES_CODE res;
res = ((USB_API_FUNC)client->src.as_voidptr)(drv_info, client);
if(res & FLG_SIGNALED)
{
tsk_HND_SET_STATUS(client, res);
}
}
helper.tsk_start_command(NULL, 0);
}
if(sig & req_hnd.signal)
{
sig ^= req_hnd.signal;
req_hnd.res &= ~FLG_SIGNALED;
#if USB_ENABLE_DEVICE
TRACE1_USB(" | req:");
if(req_hnd.res == RES_OK)
{
drv_info->drv_data->device.RequestHandler(drv_info, &request, &req_hnd);
} else
#endif
{
TRACE_USB(" res %x", req_hnd.res);
tsk_sleep(5);
}
requested = false;
}
if(!requested)
{
#if USB_ENABLE_HOST
if(sig == USB_DRIVER_SIG)
{
if(drv_info->drv_data->otg_h_sig & OTG_H_SIG_CON)
{
do
{
sig = atomic_fetch((volatile int*)&drv_info->drv_data->otg_h_sig);
sig &= ~OTG_H_SIG_CON;
} while(atomic_store((volatile int*)&drv_info->drv_data->otg_h_sig, sig));
//wait 1s for connect
for(int retries =0; retries <10; ++retries)
{
if(drv_info->drv_data->otg_flags & USB_OTG_FLG_HOST_RST)
break;
sig = tsk_wait_signal(USB_DRIVER_SIG, 100);
if (sig)
break;
}
if( !(drv_info->drv_data->otg_h_sig & OTG_H_SIG_RST))
{
usb_api_otg_off(drv_info, NULL);
}
}
if(drv_info->drv_data->otg_h_sig & OTG_H_SIG_RST)
{
do
{
sig = atomic_fetch((volatile int*)&drv_info->drv_data->otg_h_sig);
sig &= ~OTG_H_SIG_RST;
} while(atomic_store((volatile int*)&drv_info->drv_data->otg_h_sig, sig));
if(drv_info->drv_data->otg_flags & USB_OTG_FLG_HOST_RST)
{
RES_CODE res;
// Reset requested
for(int retries =0; retries <3; ++retries)
{
tsk_sleep(100);
res = usb_host_reset_bus(drv_info, &req_hnd);
//.........这里部分代码省略.........
示例3: LoadLevel
void CGameServer::LoadLevel(const CHandle<CLevel>& pLevel)
{
// Create and name the entities first and add them to this array. This way we avoid a problem where
// one entity needs to connect to another entity which has not yet been created.
tmap<size_t, CBaseEntity*> apEntities;
// Do a quick precache now to load default models and such. Another precache will come later.
const auto& aEntities = pLevel->GetEntityData();
for (size_t i = 0; i < aEntities.size(); i++)
AddToPrecacheList("C" + aEntities[i].GetClass());
PrecacheList();
m_bAllowPrecaches = true;
for (size_t i = 0; i < aEntities.size(); i++)
{
const CLevelEntity* pLevelEntity = &aEntities[i];
tstring sClass = "C" + pLevelEntity->GetClass();
auto it = CBaseEntity::GetEntityRegistration().find(sClass);
TAssert(it != CBaseEntity::GetEntityRegistration().end());
if (it == CBaseEntity::GetEntityRegistration().end())
{
TError("Unregistered entity '" + sClass + "'\n");
continue;
}
AddToPrecacheList("C" + aEntities[i].GetClass());
CBaseEntity* pEntity = Create<CBaseEntity>(sClass.c_str());
apEntities[i] = pEntity;
pEntity->SetName(pLevelEntity->GetName());
// Process outputs here so that they exist when handle callbacks run.
for (size_t k = 0; k < pLevelEntity->GetOutputs().size(); k++)
{
auto pOutput = &pLevelEntity->GetOutputs()[k];
tstring sValue = pOutput->m_sOutput;
CSaveData* pSaveData = CBaseEntity::FindOutput(pEntity->GetClassName(), sValue);
TAssert(pSaveData);
if (!pSaveData)
{
TError("Unknown output '" + sValue + "'\n");
continue;
}
tstring sTarget = pOutput->m_sTargetName;
tstring sInput = pOutput->m_sInput;
tstring sArgs = pOutput->m_sArgs;
bool bKill = pOutput->m_bKill;
if (!sTarget.length())
{
TUnimplemented();
TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing a target.\n");
continue;
}
if (!sInput.length())
{
TUnimplemented();
TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing an input.\n");
continue;
}
pEntity->AddOutputTarget(sValue, sTarget, sInput, sArgs, bKill);
}
}
for (auto it = apEntities.begin(); it != apEntities.end(); it++)
{
auto pLevelEntity = &aEntities[it->first];
CBaseEntity* pEntity = it->second;
// Force physics related stuff first so it's available if there's a physics model.
auto itScale = pLevelEntity->GetParameters().find("Scale");
if (itScale != pLevelEntity->GetParameters().end())
UnserializeParameter("Scale", itScale->second, pEntity);
auto itOrigin = pLevelEntity->GetParameters().find("Origin");
if (itOrigin != pLevelEntity->GetParameters().end())
UnserializeParameter("Origin", itOrigin->second, pEntity);
for (auto it = pLevelEntity->GetParameters().begin(); it != pLevelEntity->GetParameters().end(); it++)
{
tstring sHandle = it->first;
tstring sValue = it->second;
if (sHandle == "MoveParent")
continue;
if (sHandle == "Scale")
continue;
if (sHandle == "Origin")
//.........这里部分代码省略.........
示例4: wmain
//.........这里部分代码省略.........
chromePath = appPath + L"\\Google\\Chrome\\Application\\chrome.exe";
}
// Get a temp location
CString temp;
Helpers::ExpandEnvironmentString(L"%Temp%", temp);
// Set arguments for the chrome that we launch
CString arguments;
arguments.Format(L"about:blank --remote-debugging-port=9223 --window-size=0,0 --silent-launch --no-first-run --no-default-browser-check --user-data-dir=\"%s\"", temp);
// Launch the process
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof(si);
si.wShowWindow = SW_MINIMIZE;
BOOL result = ::CreateProcess(
chromePath,
arguments.GetBuffer(),
nullptr,
nullptr,
FALSE,
0,
nullptr,
temp,
&si,
&pi);
arguments.ReleaseBuffer();
if (result)
{
// Store the handles
CHandle hThread(pi.hThread);
hChromeProcess.Attach(pi.hProcess);
DWORD waitResult = ::WaitForInputIdle(hChromeProcess, 30000);
}
else
{
std::cerr << "Could not open Chrome. Please ensure that Chrome is installed." << std::endl;
system("pause");
return -1;
}
}
// Kill all Edge instances if their is an aegument /killall
if (vm.count("killall"))
{
//killAllProcessByExe(L"MicrosoftEdgeCP.exe");
Helpers::KillAllProcessByExe(L"MicrosoftEdge.exe");
}
// Launch Edge if their is an argument set /launch:<url>
if (vm.count("launch"))
{
CString url(vm["launch"].as<string>().c_str());
if (url.GetLength() == 0)
{
url = L"https://www.bing.com";
}
HRESULT hr = Helpers::OpenUrlInMicrosoftEdge(url);
if (FAILED(hr))
{
std::cout << L"Failed to launch Microsoft Edge";
示例5: switch
//.........这里部分代码省略.........
( !pWeapon->UsesClipsForAmmo2() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iSecondaryAmmoType ) <= 0 ) ) )
{
bHasAnySecondary = true;
break;
}
}
}
if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasAnySecondary()", pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasAnySecondary ? "true" : "false" ) );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
}
return ( bNot ) ? ( !bHasAnySecondary ) : ( bHasAnySecondary );
}
case LESSON_ACTION_GET_MARINE:
{
int iTemp = static_cast<int>( fParam );
if ( iTemp <= 0 || iTemp > 2 )
{
if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[entityINVALID] = [%s]->GetMarine()\n", pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam selecting string is out of range!\n" );
}
return false;
}
CHandle<C_BaseEntity> *pHandle;
char const *pchParamNameTemp = NULL;
if ( iTemp == 2 )
{
pHandle = &m_hEntity2;
pchParamNameTemp = "entity2";
}
else
{
pHandle = &m_hEntity1;
pchParamNameTemp = "entity1";
}
C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
if ( !pPlayer )
{
if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] = [%s]->GetMarine()", pchParamNameTemp, pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "...\n" );
ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Player returned NULL!\n" );
}
return false;
}
C_ASW_Marine *pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
pHandle->Set( pMarine );
if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
示例6: SetChargerState
//-----------------------------------------------------------------------------
// Purpose:
// Input : state -
//-----------------------------------------------------------------------------
void CWeaponCrossbow::SetChargerState( ChargerState_t state )
{
// Make sure we're setup
CreateChargerEffects();
// Don't do this twice
if ( state == m_nChargeState )
return;
m_nChargeState = state;
switch( m_nChargeState )
{
case CHARGER_STATE_START_LOAD:
WeaponSound( SPECIAL1 );
// Shoot some sparks and draw a beam between the two outer points
DoLoadEffect();
break;
#ifndef CLIENT_DLL
case CHARGER_STATE_START_CHARGE:
{
if ( m_hChargerSprite == NULL )
break;
m_hChargerSprite->SetBrightness( 32, 0.5f );
m_hChargerSprite->SetScale( 0.025f, 0.5f );
m_hChargerSprite->TurnOn();
}
break;
case CHARGER_STATE_READY:
{
// Get fully charged
if ( m_hChargerSprite == NULL )
break;
m_hChargerSprite->SetBrightness( 80, 1.0f );
m_hChargerSprite->SetScale( 0.1f, 0.5f );
m_hChargerSprite->TurnOn();
}
break;
case CHARGER_STATE_DISCHARGE:
{
SetSkin( BOLT_SKIN_NORMAL );
if ( m_hChargerSprite == NULL )
break;
m_hChargerSprite->SetBrightness( 0 );
m_hChargerSprite->TurnOff();
}
break;
#endif
case CHARGER_STATE_OFF:
{
SetSkin( BOLT_SKIN_NORMAL );
#ifndef CLIENT_DLL
if ( m_hChargerSprite == NULL )
break;
m_hChargerSprite->SetBrightness( 0 );
m_hChargerSprite->TurnOff();
#endif
}
break;
default:
break;
}
}
示例7: BoltTouch
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
{
if ( pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS | FSOLID_TRIGGER) )
{
// Some NPCs are triggers that can take damage (like antlion grubs). We should hit them.
if ( ( pOther->m_takedamage == DAMAGE_NO ) || ( pOther->m_takedamage == DAMAGE_EVENTS_ONLY ) )
return;
}
if ( pOther->m_takedamage != DAMAGE_NO )
{
trace_t tr, tr2;
tr = BaseClass::GetTouchTrace();
Vector vecNormalizedVel = GetAbsVelocity();
ClearMultiDamage();
VectorNormalize( vecNormalizedVel );
#if defined(HL2_EPISODIC)
//!!!HACKHACK - specific hack for ep2_outland_10 to allow crossbow bolts to pass through her bounding box when she's crouched in front of the player
// (the player thinks they have clear line of sight because Alyx is crouching, but her BBOx is still full-height and blocks crossbow bolts.
if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->Classify() == CLASS_PLAYER_ALLY_VITAL && FStrEq(STRING(gpGlobals->mapname), "ep2_outland_10") )
{
// Change the owner to stop further collisions with Alyx. We do this by making her the owner.
// The player won't get credit for this kill but at least the bolt won't magically disappear!
SetOwnerEntity( pOther );
return;
}
#endif//HL2_EPISODIC
if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->IsNPC() )
{
CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), sk_plr_dmg_crossbow.GetFloat(), DMG_NEVERGIB );
dmgInfo.AdjustPlayerDamageInflictedForSkillLevel();
CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
dmgInfo.SetDamagePosition( tr.endpos );
pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
CBasePlayer *pPlayer = ToBasePlayer( GetOwnerEntity() );
if ( pPlayer )
{
gamestats->Event_WeaponHit( pPlayer, true, "weapon_crossbow", dmgInfo );
}
}
else
{
CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), sk_plr_dmg_crossbow.GetFloat(), DMG_BULLET | DMG_NEVERGIB );
CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
dmgInfo.SetDamagePosition( tr.endpos );
pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
}
ApplyMultiDamage();
//Adrian: keep going through the glass.
if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
return;
/*if ( !pOther->IsAlive() )
{
// We killed it!
const surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps );
if ( pdata->game.material == CHAR_TEX_GLASS )
{
return;
}
}*/
SetAbsVelocity( Vector( 0, 0, 0 ) );
// play body "thwack" sound
EmitSound( "Weapon_Crossbow.BoltHitBody" );
Vector vForward;
AngleVectors( GetAbsAngles(), &vForward );
VectorNormalize ( vForward );
UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vForward * 128, MASK_BLOCKLOS, pOther, COLLISION_GROUP_NONE, &tr2 );
if ( tr2.fraction != 1.0f )
{
// NDebugOverlay::Box( tr2.endpos, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 255, 0, 0, 10 );
// NDebugOverlay::Box( GetAbsOrigin(), Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 0, 255, 0, 10 );
if ( tr2.m_pEnt == NULL || ( tr2.m_pEnt && tr2.m_pEnt->GetMoveType() == MOVETYPE_NONE ) )
{
CEffectData data;
data.m_vOrigin = tr2.endpos;
data.m_vNormal = vForward;
data.m_nEntIndex = tr2.fraction != 1.0f;
DispatchEffect( "BoltImpact", data );
}
}
//.........这里部分代码省略.........
示例8: BoltTouch
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pOther -
//-----------------------------------------------------------------------------
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
{
if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) )
return;
if ( pOther->m_takedamage != DAMAGE_NO )
{
trace_t tr, tr2;
tr = BaseClass::GetTouchTrace();
Vector vecNormalizedVel = GetAbsVelocity();
ClearMultiDamage();
VectorNormalize( vecNormalizedVel );
if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->IsNPC() )
{
CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_NEVERGIB );
dmgInfo.AdjustPlayerDamageInflictedForSkillLevel();
CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
dmgInfo.SetDamagePosition( tr.endpos );
pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
}
else
{
CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_BULLET | DMG_NEVERGIB );
CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
dmgInfo.SetDamagePosition( tr.endpos );
pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
}
ApplyMultiDamage();
//Adrian: keep going through the glass.
if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
return;
SetAbsVelocity( Vector( 0, 0, 0 ) );
// play body "thwack" sound
EmitSound( "Weapon_Crossbow.BoltHitBody" );
Vector vForward;
AngleVectors( GetAbsAngles(), &vForward );
VectorNormalize ( vForward );
UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vForward * 128, MASK_OPAQUE, pOther, COLLISION_GROUP_NONE, &tr2 );
if ( tr2.fraction != 1.0f )
{
// NDebugOverlay::Box( tr2.endpos, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 255, 0, 0, 10 );
// NDebugOverlay::Box( GetAbsOrigin(), Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 0, 255, 0, 10 );
if ( tr2.m_pEnt == NULL || ( tr2.m_pEnt && tr2.m_pEnt->GetMoveType() == MOVETYPE_NONE ) )
{
CEffectData data;
data.m_vOrigin = tr2.endpos;
data.m_vNormal = vForward;
data.m_nEntIndex = tr2.fraction != 1.0f;
DispatchEffect( "BoltImpact", data );
}
}
SetTouch( NULL );
SetThink( NULL );
UTIL_Remove( this );
}
else
{
trace_t tr;
tr = BaseClass::GetTouchTrace();
// See if we struck the world
if ( pOther->GetMoveType() == MOVETYPE_NONE && !( tr.surface.flags & SURF_SKY ) )
{
EmitSound( "Weapon_Crossbow.BoltHitWorld" );
// if what we hit is static architecture, can stay around for a while.
Vector vecDir = GetAbsVelocity();
float speed = VectorNormalize( vecDir );
// See if we should reflect off this surface
float hitDot = DotProduct( tr.plane.normal, -vecDir );
if ( ( hitDot < 0.5f ) && ( speed > 100 ) )
{
Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir;
QAngle reflectAngles;
VectorAngles( vReflection, reflectAngles );
SetLocalAngles( reflectAngles );
//.........这里部分代码省略.........
示例9: SetupMovie
//-----------------------------------------------------------------------------
// Purpose: Either become the master of a group of screens, or become a slave to another
//-----------------------------------------------------------------------------
void CMovieDisplayScreen::SetupMovie( void )
{
// Only bother if we haven't been setup yet
if ( m_bInitialized )
return;
const char *szGroupName = m_hScreenEntity->GetGroupName();
CMovieDisplayScreen *pMasterScreen = NULL;
for ( int i = 0; i < g_MovieDisplays.Count(); i++ )
{
// Must be valid and not us
if ( g_MovieDisplays[i] == NULL || g_MovieDisplays[i] == this )
continue;
// Must have an associated movie entity
if ( g_MovieDisplays[i]->m_hScreenEntity == NULL )
continue;
// Must have a group name to care
if ( szGroupName[0] == NULL )
continue;
// Group names must match!
// FIXME: Use an ID instead?
const char *szTestGroupName = g_MovieDisplays[i]->m_hScreenEntity->GetGroupName();
if ( Q_strnicmp( szTestGroupName, szGroupName, 128 ) )
continue;
// See if we've found a master display
if ( g_MovieDisplays[i]->m_bInitialized && g_MovieDisplays[i]->m_bSlaved == false )
{
m_bSlaved = true;
// Share the info from the master
m_playbackInfo = g_MovieDisplays[i]->m_playbackInfo;
// We need to calculate our own playback dimensions as we may be a different size than our parent
CalculatePlaybackDimensions( m_playbackInfo.m_nSourceWidth, m_playbackInfo.m_nSourceHeight );
// Bind our texture
m_nTextureId = surface()->CreateNewTextureID( true );
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureId, m_playbackInfo.m_pMaterial );
// Hold this as the master screen
pMasterScreen = g_MovieDisplays[i];
break;
}
}
// We need to try again, we have no screen entity!
if ( m_hScreenEntity == NULL )
return;
// No master found, become one
if ( pMasterScreen == NULL )
{
const char *szFilename = m_hScreenEntity->GetMovieFilename();
BeginPlayback( szFilename );
m_bSlaved = false;
}
// Done
m_bInitialized = true;
}
示例10: SelectSchedule
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CNPC_CraneDriver::SelectSchedule( void )
{
if ( HasSpawnFlags(SF_VEHICLEDRIVER_INACTIVE) )
return BaseClass::SelectSchedule();
// If we've got an object to pickup, so go get it
if ( m_hPickupTarget )
{
// Only clear the pickup target if we managed to pick something up
if ( m_hCrane->GetTotalMassOnCrane() > 0 )
{
if ( m_bForcedPickup )
{
m_OnPickedUpObject.FireOutput( m_hPickupTarget, this );
}
// Remember what we dropped so we go try something else if we can.
m_PreviouslyPickedUpObjects.AddToTail( m_hPickupTarget );
m_hPickupTarget = NULL;
}
else
{
if ( m_NPCState == NPC_STATE_IDLE )
{
m_IdealNPCState = NPC_STATE_ALERT;
}
return SCHED_CRANE_PICKUP_OBJECT;
}
}
// If we're currently being forced to pickup something, do only that
if ( m_bForcedPickup )
{
if ( m_hPickupTarget )
return SCHED_CRANE_PICKUP_OBJECT;
// We've picked up our target, we're waiting to be told where to put it
return SCHED_IDLE_STAND;
}
// If we've been told to drop something off, do that
if ( m_bForcedDropoff )
return SCHED_CRANE_FORCED_DROP;
switch ( m_NPCState )
{
case NPC_STATE_IDLE:
break;
case NPC_STATE_ALERT:
break;
case NPC_STATE_COMBAT:
if ( HasCondition( COND_CAN_RANGE_ATTACK1 ) )
{
// Do we have anything on the crane? If not, look for something
if ( m_hCrane->GetTotalMassOnCrane() == 0 )
return SCHED_CRANE_FIND_LARGE_OBJECT;
// We've got something on the crane, so try and drop it on the enemy
return SCHED_CRANE_RANGE_ATTACK1;
}
// We can't attack him, so if we don't have anything on the crane, grab something
if ( m_hCrane->GetTotalMassOnCrane() == 0 )
return SCHED_CRANE_FIND_LARGE_OBJECT;
}
return BaseClass::SelectSchedule();
}
示例11: SpotlightCreate
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
void CPointSpotlight::SpotlightCreate(void)
{
if ( m_hSpotlightTarget.Get() != NULL )
return;
AngleVectors( GetAbsAngles(), &m_vSpotlightDir );
trace_t tr;
UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + m_vSpotlightDir * m_flSpotlightMaxLength, MASK_NPCSOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
m_hSpotlightTarget = (CSpotlightEnd*)CreateEntityByName( "spotlight_end" );
m_hSpotlightTarget->Spawn();
m_hSpotlightTarget->SetAbsOrigin( tr.endpos );
m_hSpotlightTarget->SetOwnerEntity( this );
m_hSpotlightTarget->m_clrRender = m_clrRender;
m_hSpotlightTarget->m_Radius = m_flSpotlightMaxLength;
if ( FBitSet (m_spawnflags, SF_SPOTLIGHT_NO_DYNAMIC_LIGHT) )
{
m_hSpotlightTarget->m_flLightScale = 0.0;
}
//m_hSpotlight = CBeam::BeamCreate( "sprites/spotlight.vmt", m_flSpotlightGoalWidth );
m_hSpotlight = CBeam::BeamCreate( "sprites/glow_test02.vmt", m_flSpotlightGoalWidth );
// Set the temporary spawnflag on the beam so it doesn't save (we'll recreate it on restore)
m_hSpotlight->SetHDRColorScale( m_flHDRColorScale );
m_hSpotlight->AddSpawnFlags( SF_BEAM_TEMPORARY );
m_hSpotlight->SetColor( m_clrRender->r, m_clrRender->g, m_clrRender->b );
m_hSpotlight->SetHaloTexture(m_nHaloSprite);
m_hSpotlight->SetHaloScale(60);
m_hSpotlight->SetEndWidth(m_flSpotlightGoalWidth);
m_hSpotlight->SetBeamFlags( (FBEAM_SHADEOUT|FBEAM_NOTILE) );
m_hSpotlight->SetBrightness( 64 );
m_hSpotlight->SetNoise( 0 );
m_hSpotlight->EntsInit( this, m_hSpotlightTarget );
}
示例12: Fire
void CWeaponEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
//CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 450, 0.1 );
WeaponSound( SINGLE );
Vector vecDest = vecOrigSrc + (vecDir * MAX_TRACE_LENGTH);
trace_t tr;
UTIL_TraceLine( vecOrigSrc, vecDest, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid )
return;
CBaseEntity *pEntity = tr.m_pEnt;
if ( pEntity == NULL )
return;
if ( g_pGameRules->IsMultiplayer() )
{
if ( m_hSprite )
{
if ( pEntity->m_takedamage != DAMAGE_NO )
{
m_hSprite->TurnOn();
}
else
{
m_hSprite->TurnOff();
}
}
}
if ( m_flDmgTime < gpGlobals->curtime )
{
// wide mode does damage to the ent, and radius damage
if ( pEntity->m_takedamage != DAMAGE_NO )
{
ClearMultiDamage();
CTakeDamageInfo info(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier(), DMG_ENERGYBEAM | DMG_ALWAYSGIB | DMG_CRUSH);
CalculateMeleeDamageForce( &info, vecDir, tr.endpos );
pEntity->DispatchTraceAttack( info, vecDir, &tr );
ApplyMultiDamage();
}
if ( g_pGameRules->IsMultiplayer() )
{
// radius damage a little more potent in multiplayer.
#ifndef CLIENT_DLL
RadiusDamage(CTakeDamageInfo(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB | DMG_CRUSH), tr.endpos, 128, CLASS_NONE, NULL);
#endif
}
if ( !pPlayer->IsAlive() )
return;
if ( g_pGameRules->IsMultiplayer() )
{
//multiplayer uses 5 ammo/second
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.2;
}
}
else
{
// Wide mode uses 10 charges per second in single player
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.1;
}
}
m_flDmgTime = gpGlobals->curtime + EGON_DISCHARGE_INTERVAL;
if ( m_flShakeTime < gpGlobals->curtime )
{
#ifndef CLIENT_DLL
UTIL_ScreenShake( tr.endpos, 5.0, 150.0, 0.75, 250.0, SHAKE_START );
#endif
m_flShakeTime = gpGlobals->curtime + 1.5;
}
}
Vector vecUp, vecRight;
QAngle angDir;
VectorAngles( vecDir, angDir );
AngleVectors( angDir, NULL, &vecRight, &vecUp );
Vector tmpSrc = vecOrigSrc + (vecUp * -8) + (vecRight * 3);
UpdateEffect( tmpSrc, tr.endpos );
}
示例13: KeepTunneling
bool CObjectTunnelTrigger::KeepTunneling( TunnelPlayer *tunnel )
{
if ( !tunnel || ( tunnel->player == NULL ) )
{
return false;
}
float remaining = tunnel->teleporttime - gpGlobals->curtime + 0.5f;
remaining = max( 0.0f, remaining );
tunnel->iremaining = (int)( remaining );
if ( !tunnel->exitstarted )
{
if ( gpGlobals->curtime > tunnel->fadeintime )
{
tunnel->exitstarted = true;
// Fade user screen to black
color32 black = {0,0,0,255};
UTIL_ScreenFade( tunnel->player, black, tunnel->fadetime, 0.0, FFADE_IN | FFADE_PURGE );
// Move to tunnel exit spot now that we're half-way through teleport
if ( m_hTunnelExit != NULL )
{
tunnel->player->EnableControl( true );
tunnel->player->RemoveEffects( EF_NODRAW );
// Change the player to non-solid before the teleport, so the physics system doesn't think he
// actually moved this distance:
int OriginalSolidFlags = tunnel->player->GetSolidFlags();
tunnel->player->AddSolidFlags( FSOLID_NOT_SOLID);
// Do a placement test to prevent the player from teleporting inside another player, the ground, or just to help
// prevent badly placed tunnels from causing stuck situations.
Vector vTarget = m_hTunnelExit->GetAbsOrigin();
Vector vOriginal = vTarget;
if ( !EntityPlacementTest( tunnel->player, vOriginal, vTarget, true ) )
{
Warning("Couldn't place entity after tunnel teleport.\n");
}
tunnel->player->Teleport( &vTarget /*m_hTunnelExit->GetAbsOrigin()*/, &m_hTunnelExit->GetAbsAngles(), NULL );
tunnel->player->SnapEyeAngles( m_hTunnelExit->GetAbsAngles() );
tunnel->player->SetAbsVelocity( vec3_origin );
// Restore the player's solid flags.
tunnel->player->SetSolidFlags(OriginalSolidFlags);
}
}
// Can't quite do this because the player's weapons are still visible flying across the map even if
// he is hidden
#if 0
else if ( gpGlobals->curtime > tunnel->tunnelstarted + tunnel->fadetime )
{
float travel_time = tunnel->duration - 2 * tunnel->fadetime;
if ( travel_time > 0.0f )
{
float f = ( gpGlobals->curtime - tunnel->tunnelstarted - tunnel->fadetime ) / travel_time;
f = clamp( f, 0.0f, 1.0f );
if ( m_hTunnelExit != NULL )
{
Vector delta = m_hTunnelExit->GetAbsOrigin() - tunnel->startpos;
Vector currentPos;
VectorMA( tunnel->startpos, f, delta, currentPos );
tunnel->player->Teleport( ¤tPos, NULL, NULL );
}
}
}
#endif
}
if ( tunnel->ilastremaining != tunnel->iremaining &&
tunnel->needremainigcounter &&
tunnel->iremaining >= 1 &&
tunnel->player != NULL )
{
// Counter
ClientPrint( tunnel->player, HUD_PRINTCENTER, UTIL_VarArgs("\nExiting tunnel in %d %s\n", tunnel->iremaining, tunnel->iremaining > 1 ? "seconds" : "second" ) );
}
tunnel->ilastremaining = tunnel->iremaining;
// TODO: Play footstep or some other teleport sounds occasionaly to this player?
bool done = ( gpGlobals->curtime > tunnel->teleporttime ) ? true : false;
if ( done )
{
color32 black = {0,0,0,255};
UTIL_ScreenFade( tunnel->player, black, 0.0f, 0.0f, FFADE_IN | FFADE_PURGE );
tunnel->player->SetMoveType( MOVETYPE_WALK );
tunnel->player->EnableControl( true );
tunnel->player->RemoveEffects( EF_NODRAW );
tunnel->player->RemoveSolidFlags( FSOLID_NOT_SOLID );
// TODO: Play an exit sound??
//.........这里部分代码省略.........
示例14: DriveVehicle
//-----------------------------------------------------------------------------
// Purpose: This takes the current place the NPC's trying to get to, figures out
// what keys to press to get the vehicle to go there, and then sends
// them to the vehicle.
//-----------------------------------------------------------------------------
void CNPC_CraneDriver::DriveVehicle( void )
{
// No targets?
if ( !GetEnemy() && m_vecDesiredPosition == vec3_origin )
return;
Vector vecTarget = m_vecDesiredPosition;
// Track our targets
if ( m_hPickupTarget )
{
vecTarget = m_hPickupTarget->GetAbsOrigin();
}
else if ( !m_bForcedPickup && !m_bForcedDropoff && GetEnemy() )
{
vecTarget = GetEnemy()->GetAbsOrigin();
}
// Move the crane over the target
// Use the crane type as a targeting point
Vector vecCraneTip = m_hCrane->GetCraneTipPosition();
Vector2D vecCraneTip2D( vecCraneTip.x, vecCraneTip.y );
Vector2D vecTarget2D( vecTarget.x, vecTarget.y );
Vector2D vecOrigin2D( m_hCrane->GetAbsOrigin().x, m_hCrane->GetAbsOrigin().y );
if ( g_debug_vehicledriver.GetInt() )
{
NDebugOverlay::Box( vecTarget, -Vector(50,50,50), Vector(50,50,50), 0,255,0, true, 0.1 );
NDebugOverlay::Box( vecCraneTip, -Vector(2,2,5000), Vector(2,2,5), 0,255,0, true, 0.1 );
NDebugOverlay::Box( vecTarget, -Vector(2,2,5), Vector(2,2,5000), 0,255,0, true, 0.1 );
}
// Store off the distance to our target
m_flDistanceToTarget = (vecTarget2D - vecCraneTip2D).Length();
// First determine whether we need to extend / retract the arm
float flDistToTarget = (vecOrigin2D - vecTarget2D).LengthSqr();
float flDistToCurrent = (vecOrigin2D - vecCraneTip2D).LengthSqr();
float flDelta = fabs(flDistToTarget - flDistToCurrent);
// Slow down as we get closer, but do it based upon our current extension rate
float flMinDelta = 50 + (50 * fabs(m_hCrane->GetExtensionRate() / CRANE_EXTENSION_RATE_MAX));
flMinDelta *= flMinDelta;
if ( flDelta > flMinDelta )
{
if ( flDistToCurrent > flDistToTarget )
{
// Retract
m_pVehicleInterface->NPC_ThrottleReverse();
}
else if ( flDistToCurrent < flDistToTarget )
{
// Extend
m_pVehicleInterface->NPC_ThrottleForward();
}
}
else
{
m_pVehicleInterface->NPC_ThrottleCenter();
}
// Then figure out if we need to rotate. Do it all in 2D space.
Vector vecRight, vecForward;
m_hCrane->GetVectors( &vecForward, &vecRight, NULL );
vecRight.z = 0;
vecForward.z = 0;
VectorNormalize( vecRight );
VectorNormalize( vecForward );
Vector vecToTarget = ( vecTarget - m_hCrane->GetAbsOrigin() );
vecToTarget.z = 0;
VectorNormalize( vecToTarget );
float flDotRight = DotProduct( vecRight, vecToTarget );
float flDotForward = DotProduct( vecForward, vecToTarget );
// Start slowing if we're going to hit the point soon
float flTurnInDeg = RAD2DEG( acos(flDotForward) );
float flSpeed = m_hCrane->GetMaxTurnRate() * (flTurnInDeg / 15.0);
flSpeed = min( m_hCrane->GetMaxTurnRate(), flSpeed );
if ( fabs(flSpeed) < 0.05 )
{
// We're approaching the target, so stop turning
m_pVehicleInterface->NPC_TurnCenter();
}
else
{
if ( flDotRight < 0 )
{
// Turn right
m_pVehicleInterface->NPC_TurnRight( flSpeed );
}
else if ( flDotRight > 0 )
{
// Turn left
m_pVehicleInterface->NPC_TurnLeft( flSpeed );
}
}
}
示例15: StartTask
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pTask -
//-----------------------------------------------------------------------------
void CNPC_CraneDriver::StartTask( const Task_t *pTask )
{
switch( pTask->iTask )
{
case TASK_WAIT_FOR_MOVEMENT:
break;
case TASK_CRANE_GET_POSITION_OVER_ENEMY:
{
if ( !GetEnemy() )
{
TaskFail(FAIL_NO_ROUTE);
return;
}
SetDesiredPosition( GetEnemy()->GetAbsOrigin() );
TaskComplete();
}
break;
case TASK_CRANE_GET_POSITION_OVER_OBJECT:
{
if ( !m_hPickupTarget )
{
TaskFail("No object to pickup!");
return;
}
SetDesiredPosition( m_hPickupTarget->GetAbsOrigin() );
TaskComplete();
}
break;
case TASK_CRANE_GET_POSITION_OVER_LASTPOSITION:
{
SetDesiredPosition( m_vecLastPosition );
TaskComplete();
}
break;
case TASK_CRANE_TURN_MAGNET_OFF:
{
// If we picked up something, and we were being forced to pick something up, fire our output
if ( m_hCrane->GetTotalMassOnCrane() > 0 && m_bForcedDropoff )
{
// Are we supposed to pause first?
if ( m_flReleasePause )
{
m_flReleaseAt = gpGlobals->curtime + m_flReleasePause;
m_OnPausingBeforeDrop.FireOutput( this, this );
return;
}
m_OnDroppedObject.FireOutput( this, this );
}
m_hCrane->TurnMagnetOff();
TaskComplete();
}
break;
case TASK_END_FORCED_DROP:
{
m_bForcedDropoff = false;
TaskComplete();
}
break;
case TASK_CRANE_FIND_OBJECT_TO_PICKUP:
{
Vector2D vecOrigin2D( m_hCrane->GetAbsOrigin().x, m_hCrane->GetAbsOrigin().y );
// Find a large physics object within our reach to pickup
float flLargestMass = 0;
CBaseEntity *pLargestEntity = NULL;
CBaseEntity *pList[1024];
Vector delta( m_flDistTooFar, m_flDistTooFar, m_flDistTooFar*2 );
int count = UTIL_EntitiesInBox( pList, 1024, m_hCrane->GetAbsOrigin() - delta, m_hCrane->GetAbsOrigin() + delta, 0 );
for ( int i = 0; i < count; i++ )
{
if ( !pList[i] )
continue;
// Ignore the crane & the magnet
if ( pList[i] == m_hCrane || pList[i] == m_hCrane->GetMagnet() )
continue;
if ( m_PreviouslyPickedUpObjects.Find( pList[i] ) != m_PreviouslyPickedUpObjects.InvalidIndex() )
continue;
// Get the VPhysics object
IPhysicsObject *pPhysics = pList[i]->VPhysicsGetObject();
if ( pPhysics && pList[i]->GetMoveType() == MOVETYPE_VPHYSICS )
{
float flMass = pPhysics->GetMass();
if ( flMass > flLargestMass && (flMass < MAXIMUM_CRANE_PICKUP_MASS) && (flMass > MINIMUM_CRANE_PICKUP_MASS) )
{
//.........这里部分代码省略.........