//-------------------------------------------------- // // void CPet::ApplyHurt( int damage, bool isHardAttack ) { CBaseDataPet* pPetBaseData = g_pClientLoader->GetBaseDataPetFromId(m_PetData.petid); int skilldata = CExpressions::GetInstance()->GetAttribute( pPetBaseData->skillaptitude, pPetBaseData->upskill, pPetBaseData->initskill, m_PetData.petlevel ); float pec = CExpressions::GetInstance()->GetSkillFrquency(skilldata, m_PetData.petlevel ); CBaseDataSkill* pDataSkill = g_pClientLoader->GetBaseDataSkillFromId(pPetBaseData->skillfield_defense[m_PetData.skilllevel.skillsLevel[1] - 1]); //skill attack if( CCRANDOM_0_1() < pec && m_PetData.skilllevel.skillsLevel[1] > 0 && m_PetData.mp >= pDataSkill->skillmp ) { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_defense, 1, callfunc_selector( CPet::HurtEndCallBack ), this, false, false ); m_PetData.mp = m_PetData.mp - pDataSkill->skillmp; if( m_PetData.mp <= 0 ) { m_PetData.mp = 0; } std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + pDataSkill->plist; if( !pDataSkill->plist.empty() ) { CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile(filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); g_pFightGroundLayer->addChild( pEmitter, 100 ); } if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) ) { string path = "data/audio/" + pDataSkill->skill_sound; CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(path.c_str(), false); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/scoreCount2.wav", false); } return; } m_PetData.hp = m_PetData.hp - damage; char strbuffer[32]; if( 0 == damage ) { sprintf( strbuffer, "%s", "miss"); } else { sprintf( strbuffer, "-%d", damage); } CCLabelTTF *plabel = CCLabelTTF::labelWithString(strbuffer, kFontSystem[FONT_GRAND].fontName,kFontSystem[FONT_GRAND].fontSize); const ccColor3B ccwhite = {255,255,255}; const ccColor3B ccYellow = {255,255,0}; const ccColor3B ccRed = {255,0,0 }; if( isHardAttack ) { plabel->setColor( ccYellow ); } else if( 0 == damage ) { plabel->setColor( ccRed ); } else { plabel->setColor( ccwhite ); } plabel->setPosition( ccp( getPosition().x, getPosition().y + getTextureRect().size.height ) ); g_pFightGroundLayer->addChild(plabel,100); plabel->runAction( CCFadeOut::actionWithDuration(1.5f) ); plabel->runAction(CCMoveBy::actionWithDuration(0.2f, ccp( 0, 50 ))); if( m_PetData.hp <= 0 ) { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_lost, 1, NULL, this, false, false ); m_pLockTarget->m_bIsWin = true; } else { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_injured, 1, callfunc_selector( CPet::HurtEndCallBack ), this, false, false ); } if( 0 != damage ) { std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + "hurteffect.plist"; CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); CCPoint pos = getPosition(); g_pFightGroundLayer->addChild( pEmitter, 100 ); } if( isHardAttack ) { std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + "bloodEffect.plist"; CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); CCPoint pos = getPosition(); g_pFightGroundLayer->addChild( pEmitter, 100 ); } }
//-------------------------------------- // // void CPet::HurtEndCallBack() { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_stand, -1, NULL, this, false, false ); }
void UiWidget::ScriptPlayAnimationStop(const char* name, const float start, const float end) { PlayAnimation(Ogre::String(name), UiAnimation::ONCE, start, end); }
//-------------------------------------------------- // // void CPet::AttackBeginCallBack( CCNode *pNode, void *d ) { //CBaseDataPet *pBaseDataPet = g_pClientLoader->GetBaseDataPetFromId(getID()); //¬∫¬∫∆í‚Ä? //CBaseDataSkill *pBaseDataSkill = g_pClientLoader->GetBaseDataSkillFromId(pBaseDataPet->m_arrSkillId[0]); //startAnimation( pBaseDataSkill->m_arrSkillId[0],pBaseDataSkill->m_arrSkillId[1],1,callfunc_selector(CPet::AttackEndCallBack),this,pBaseDataSkill->m_arrSkillId[2],false,false ); SAttackType *pAttackType = ( ( SAttackType* )d); if( CPET_STATE_NONE == pAttackType->Type ) { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_attack, 1, callfunc_selector(CPet::AttackEndCallBack), this, false, false ); CBaseDataPet* pPetBaseData = g_pClientLoader->GetBaseDataPetFromId(m_PetData.petid); //‚àÜ‚Äô√ï¬ÆœÄ‚Ä¢¬™Àú¬±¬©¬™À? int damage = CExpressions::GetInstance()->GetDamage( CExpressions::GetInstance()->GetAttribute( pPetBaseData->dexaptitude, pPetBaseData->updex, pPetBaseData->initdex, m_PetData.petlevel ) ); int skilldata = CExpressions::GetInstance()->GetAttribute( pPetBaseData->skillaptitude, pPetBaseData->upskill, pPetBaseData->initskill, m_PetData.petlevel ); float pec = CExpressions::GetInstance()->GetSkillFrquency(skilldata, m_PetData.petlevel ); if( CCRANDOM_0_1() <( pec / 2.0f ) ) { m_pLockTarget->ApplyHurt( damage + damage / 2 + rand() % (damage / 2 ), true ); } else if( CCRANDOM_0_1() < 0.9f ) { m_pLockTarget->ApplyHurt( damage ); } else { m_pLockTarget->ApplyHurt( 0 ); } if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) ) { string path = "data/audio/" + pPetBaseData->attack_sound; CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(path.c_str(), false); } } else { CCFiniteTimeAction *pTime = new CCFiniteTimeAction(); pTime->setDuration( 1.2f ); pTime->autorelease(); CCFiniteTimeAction* pTimeAction = CCCallFuncN::actionWithTarget( this, callfuncN_selector(CPet::AttackOverCallBack) ); runAction( CCSequence::actions( pTime, pTimeAction, NULL ) ); g_pFightGroundLayer->removeChildByTag( FIRE_BALL_TAG, true ); CBaseDataPet* pDataPet = g_pClientLoader->GetBaseDataPetFromId(m_PetData.petid); CBaseDataSkill* pDataSkill = g_pClientLoader->GetBaseDataSkillFromId(pDataPet->skillfield[m_PetData.skilllevel.skillsLevel[0]-1]); m_pLockTarget->ApplyHurt( pDataSkill->damage ); if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) ) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/Hit1.mp3", false); } } }
bool CClientWeaponDisc::PlayHoldDefenseAnimation( bool bResetAni ) { // get thde current animation and the current animation state uint32 dwAni = g_pLTClient->GetModelAnimation( m_hObject ); uint32 dwState = g_pLTClient->GetModelPlaybackState( m_hObject ); if ( GetPreHoldDefenseAni() == dwAni ) { if ( dwState & MS_PLAYDONE ) { PlayAnimation( GetHoldDefenseAni(), false, 1.0f, true ); return true; } } else if ( GetHoldDefenseAni() == dwAni ) { if ( !bResetAni ) { // play the hold "release" aniamtion PlayAnimation( GetPostHoldDefenseAni(), true ); // let the server know SendDefendMessage( MPROJ_END_HOLD_BLOCK, GetPostHoldDefenseAni() ); // turn off accurate rotations on the server g_pPlayerMgr->EndServerAccurateRotation(); // stop sending the camera offset to the server g_pPlayerMgr->EndSendingCameraOffsetToServer(); } else if ( m_bPlayImpactHoldAnimation ) { // play the impact hold animation PlayAnimation( GetImpactHoldDefenseAni() ); } return true; } else if ( GetImpactHoldDefenseAni() == dwAni ) { if ( dwState & MS_PLAYDONE ) { if ( bResetAni ) { // keep playing the hold animation PlayAnimation( GetHoldDefenseAni(), false, 1.0f, true ); } else { // play the hold "release" aniamtion PlayAnimation( GetPostHoldDefenseAni(), true ); // let the server know SendDefendMessage( MPROJ_END_HOLD_BLOCK, GetPostHoldDefenseAni() ); // turn off accurate rotations on the server g_pPlayerMgr->EndServerAccurateRotation(); // stop sending the camera offset to the server g_pPlayerMgr->EndSendingCameraOffsetToServer(); } } } else if ( GetPostHoldDefenseAni() == dwAni ) { if ( dwState & MS_PLAYDONE ) { // all done! if ( bResetAni ) { // button held down, play again PlayAnimation( GetPreHoldDefenseAni(), false ); // let the server know SendDefendMessage( MPROJ_START_HOLD_BLOCK, GetPreHoldDefenseAni() ); // keep on accurate rotations on the server g_pPlayerMgr->StartServerAccurateRotation(); // keep on the camera offset being sent to the server g_pPlayerMgr->StartSendingCameraOffsetToServer(); return true; } else { return false; } } } else { ASSERT( !IsHoldDefenseAni( dwAni ) ); // no hold animation playing, start the hold PlayAnimation( GetPreHoldDefenseAni(), false ); // let the server know SendDefendMessage( MPROJ_START_HOLD_BLOCK, GetPreHoldDefenseAni() ); // turn on accurate rotations on the server g_pPlayerMgr->StartServerAccurateRotation(); // start sending the camera offset to the server g_pPlayerMgr->StartSendingCameraOffsetToServer(); return true; } return true; }
/*virtual*/ void WBCompEldHands::HandleEvent( const WBEvent& Event ) { XTRACE_FUNCTION; Super::HandleEvent( Event ); STATIC_HASHED_STRING( OnWorldLoaded ); STATIC_HASHED_STRING( OnItemEquipped ); STATIC_HASHED_STRING( OnItemUnequipped ); STATIC_HASHED_STRING( OnItemsSwapped ); STATIC_HASHED_STRING( UseRightHand ); STATIC_HASHED_STRING( UseLeftHand ); STATIC_HASHED_STRING( ShowHands ); STATIC_HASHED_STRING( HideHands ); STATIC_HASHED_STRING( PlayHandAnim ); STATIC_HASHED_STRING( SetHandMeshes ); const HashedString EventName = Event.GetEventName(); if( EventName == sOnWorldLoaded ) { if( GetItemInRightHand() == GetWeapon() ) { WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() ); WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetWeapon() ); WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() ); } RestoreHandAnimations(); UpdateWeaponHUD(); } else if( EventName == sOnItemEquipped ) { STATIC_HASHED_STRING( Item ); WBEntity* const pItem = Event.GetEntity( sItem ); ASSERT( pItem ); // Hide fists and show ammo when we equip a weapon if( pItem == GetWeapon() ) { WB_MAKE_EVENT( Hide, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Hide, GetFists() ); WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() ); WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, pItem ); WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() ); ShowWeaponHUD(); } if( pItem == GetItemInRightHand() || pItem == GetItemInLeftHand() ) { AddAnimationsToHand( pItem ); } if( pItem == GetWeaponAlt() ) { // When traveling to a new world and spawning an item in the alt slot, immediately hide it WB_MAKE_EVENT( Hide, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() ); ShowWeaponAltHUD(); } } else if( EventName == sOnItemUnequipped ) { // Show fists when we unequip a weapon STATIC_HASHED_STRING( Item ); WBEntity* const pItem = Event.GetEntity( sItem ); if( pItem == GetWeapon() ) { WB_MAKE_EVENT( Show, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetFists() ); WB_MAKE_EVENT( OnWeaponUnequipped, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), OnWeaponUnequipped, GetEntity() ); // Revert to the fists animations AddAnimationsToHand( GetFists(), EH_Right ); // HACK: Play the idle animation. I could add an event for "restored equip focus" // or whatever and hook this up in data, but eh. That somehow feels worse. STATIC_HASHED_STRING( Idle ); PlayAnimation( GetFists(), sIdle, EH_Right ); HideWeaponHUD(); } } else if( EventName == sOnItemsSwapped ) { // HACK, since the only things we swap (currently) are Weapon/WeaponAlt // Hide the alt weapon, show the right hand item WB_MAKE_EVENT( Hide, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() ); WB_MAKE_EVENT( Show, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetItemInRightHand() ); AddAnimationsToHand( GetItemInRightHand() ); STATIC_HASHED_STRING( Idle ); PlayAnimation( GetItemInRightHand(), sIdle, EH_Right ); UpdateWeaponHUD(); WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() ); WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetItemInRightHand() ); WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() ); } else if( EventName == sUseRightHand ) { WBEntity* const pWeapon = GetItemInRightHand(); if( pWeapon ) { STATIC_HASHED_STRING( InputEdge ); const int InputEdge = Event.GetInt( sInputEdge ); { WB_MAKE_EVENT( Use, GetEntity() ); WB_SET_AUTO( Use, Int, InputEdge, InputEdge ); WB_DISPATCH_EVENT( GetEventManager(), Use, pWeapon ); } } } else if( EventName == sUseLeftHand ) { WBEntity* const pPower = GetItemInLeftHand(); if( pPower ) { STATIC_HASHED_STRING( InputEdge ); const int InputEdge = Event.GetInt( sInputEdge ); { WB_MAKE_EVENT( Use, GetEntity() ); WB_SET_AUTO( Use, Int, InputEdge, InputEdge ); WB_DISPATCH_EVENT( GetEventManager(), Use, pPower ); } } } else if( EventName == sShowHands ) { DecrementHideHandsRefs(); } else if( EventName == sHideHands ) { IncrementHideHandsRefs(); } else if( EventName == sPlayHandAnim ) { STATIC_HASHED_STRING( AnimatingEntity ); WBEntity* const pAnimatingEntity = Event.GetEntity( sAnimatingEntity ); STATIC_HASHED_STRING( AnimationName ); const HashedString AnimationName = Event.GetHash( sAnimationName ); // Don't play hand anim if we're restoring the alternate weapon if( pAnimatingEntity == GetItemInRightHand() || pAnimatingEntity == GetItemInLeftHand() ) { const EHand Hand = GetHandEnum( pAnimatingEntity ); PlayAnimation( pAnimatingEntity, AnimationName, Hand ); } } else if( EventName == sSetHandMeshes ) { STATIC_HASHED_STRING( LeftHandMesh ); const SimpleString LeftHandMesh = Event.GetString( sLeftHandMesh ); STATIC_HASHED_STRING( LeftHandTexture ); const SimpleString LeftHandTexture = Event.GetString( sLeftHandTexture ); STATIC_HASHED_STRING( RightHandMesh ); const SimpleString RightHandMesh = Event.GetString( sRightHandMesh ); STATIC_HASHED_STRING( RightHandTexture ); const SimpleString RightHandTexture = Event.GetString( sRightHandTexture ); SetHandMeshes( LeftHandMesh, LeftHandTexture, RightHandMesh, RightHandTexture ); RestoreHandAnimations(); } }
bool CBoidObject::PlayAnimationId( int nIndex,bool bLooped,float fBlendTime ) { if (nIndex >= 0 && nIndex < (int)m_flock->m_bc.animations.size()) return PlayAnimation( m_flock->m_bc.animations[nIndex],bLooped,fBlendTime ); return false; }
//----------------------------------------------------------------------------- // The player object class constructor. //----------------------------------------------------------------------------- PlayerObject::PlayerObject( PlayerInfo *player, Script *script, unsigned long type ) : AnimatedObject( script->GetStringData( "mesh_name" ), script->GetStringData( "mesh_path" ), type ) { // Set the player's DirectPlay ID. m_dpnid = player->dpnid; // Set the players's name. m_name = new char[strlen( player->name ) + 1]; strcpy( m_name, player->name ); // Players start with full health; m_health = 100.0f; m_dying = false; // Indicate that the view transform is not being taken from this player. m_isViewing = false; // Clear the player's score. m_frags = 0; m_deaths = 0; // Player objects start off invisible and disabled. SetVisible( false ); SetEnabled( false ); // Clear the player's input. m_drive = 0.0f; m_strafe = 0.0f; m_fire = false; // Set the correct ellipse radius. SetEllipsoidRadius( *script->GetVectorData( "ellipse_radius" ) ); // Level the player's view tilt. m_viewTilt = 0.0f; // Set the default view smoothing and sensitivity. m_viewSmoothing = 0.5f; m_viewSensitivity = 0.5f; // Get the view weapon offset. m_viewWeaponOffset = *script->GetVectorData( "view_weapon_offset" ); // Clear the weapons array. for( unsigned char w = 0; w < 10; w++ ) m_weapons[w] = NULL; // The player starts with the first basic weapon. Script *weaponScript = new Script( "Gun1.txt", "./Assets/Objects/Gun1/" ); m_weapons[0] = new Weapon( weaponScript, m_viewWeaponOffset ); m_currentWeapon = 0; if( player->dpnid == g_engine->GetNetwork()->GetLocalID() ) m_weapons[m_currentWeapon]->UseViewWeapon( true ); else m_weapons[m_currentWeapon]->UseViewWeapon( false ); SAFE_DELETE( weaponScript ); // Indicate that the player is not changing weapons. m_changingWeapon = 0.0f; m_weaponChanging = false; // Create the callback data used for tracking the player's foot steps. m_callbackData[0].foot = 0; m_callbackData[1].foot = 1; // Create the callback keys. The second key time is set per animation. D3DXKEY_CALLBACK keys[2]; keys[0].Time = 0; keys[0].pCallbackData = &m_callbackData[0]; keys[1].pCallbackData = &m_callbackData[1]; LPD3DXKEYFRAMEDANIMATIONSET oldAS; LPD3DXCOMPRESSEDANIMATIONSET newAS; LPD3DXBUFFER buffer; // Go through the four movement animations and set the foot step keys. for( char a = 1; a < 5; a++ ) { // Get the old animation. GetAnimationController()->GetAnimationSet( a, (LPD3DXANIMATIONSET*)&oldAS ); // Set the time for the second key. keys[1].Time = float( oldAS->GetPeriod() / 2.0f * oldAS->GetSourceTicksPerSecond() ); // Compress the old animation set. oldAS->Compress( D3DXCOMPRESS_DEFAULT, 0.4f, NULL, &buffer ); // Create the new animation using the old one and the foot step keys. D3DXCreateCompressedAnimationSet( oldAS->GetName(), oldAS->GetSourceTicksPerSecond(), oldAS->GetPlaybackType(), buffer, 2, keys, &newAS ); SAFE_RELEASE( buffer ); // Unregister the old animation set. GetAnimationController()->UnregisterAnimationSet( oldAS ); SAFE_RELEASE( oldAS ); // Register the new animation set. // Note: The new animation is appended to the end of the list. GetAnimationController()->RegisterAnimationSet( newAS ); SAFE_RELEASE( newAS ); } // Play the idle animation. PlayAnimation( 0, 0.0f ); // Create the step sound audio paths. m_leftStepAudioPath = new AudioPath3D; m_rightStepAudioPath = new AudioPath3D; // Set the friction on this object. SetFriction( 8.0f ); }
void Entity::ScriptPlayAnimationStop(const char* name) { PlayAnimation(Ogre::String(name), Entity::REQUESTED_ANIMATION, Entity::PLAY_ONCE, 0, -1); }
void Entity::ScriptPlayAnimationStop(const char* name, const float start, const float end) { PlayAnimation(Ogre::String(name), Entity::REQUESTED_ANIMATION, Entity::PLAY_ONCE, start, end); }
//------------------------------------------------------------------------------ void Background2D::ScriptPlayAnimationOnce( const char* name ) { PlayAnimation( Ogre::String( name ), Background2DAnimation::ONCE ); }
//------------------------------------------------------------------------------ void Background2D::ScriptPlayAnimationLooped( const char* name ) { PlayAnimation( Ogre::String( name ), Background2DAnimation::LOOPED ); }
void CDlgFTPTransfer::TransferThread() { //Create the Internet session handle (if needed) if (!m_bUsingAttached) { ASSERT(m_hInternetSession == NULL); m_hInternetSession = ::InternetOpen(AfxGetAppName(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (m_hInternetSession == NULL) { TRACE(_T("Failed in call to InternetOpen, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_GENERIC_ERROR); return; } //Should we exit the thread if (m_bAbort) { PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } } ASSERT(m_hInternetSession); //Setup the status callback function on the Internet session handle INTERNET_STATUS_CALLBACK pOldCallback = ::InternetSetStatusCallback(m_hInternetSession, _OnStatusCallBack); if (pOldCallback == INTERNET_INVALID_STATUS_CALLBACK) { TRACE(_T("Failed in call to InternetSetStatusCallback, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_GENERIC_ERROR); return; } //Should we exit the thread if (m_bAbort) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } //Make the connection to the FTP server (if needed) if (!m_bUsingAttached) { ASSERT(m_hFTPConnection == NULL); ASSERT(m_sServer.GetLength()); if (m_sUserName.GetLength()) m_hFTPConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, m_sUserName, m_sPassword, INTERNET_SERVICE_FTP, 0, (DWORD) this); else m_hFTPConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, NULL, NULL, INTERNET_SERVICE_FTP, 0, (DWORD) this); if (m_hFTPConnection == NULL) { TRACE(_T("Failed in call to InternetConnect, Error:%d\n"), ::GetLastError()); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_FAIL_CONNECT_SERVER); return; } //Should we exit the thread if (m_bAbort) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } } ASSERT(m_hFTPConnection); //Start the animation to signify that the download is taking place PlayAnimation(); //Update the status control to reflect that we are getting the file information SetStatus(IDS_FTPTRANSFER_GETTING_FILE_INFORMATION); // Get the length of the file to transfer DWORD dwFileSize = 0; BOOL bGotFileSize = FALSE; if (m_bDownload) { WIN32_FIND_DATA wfd; HINTERNET hFind = ::FtpFindFirstFile(m_hFTPConnection, m_sRemoteFile, &wfd, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); if (hFind) { //Set the progress control range bGotFileSize = TRUE; dwFileSize = (DWORD) wfd.nFileSizeLow; // SetProgressRange(dwFileSize); SetProgressRange(0,100); //Destroy the enumeration handle now that we are finished with it InternetCloseHandle(hFind); } } else { bGotFileSize = TRUE; dwFileSize = m_LocalFile.GetLength(); // SetProgressRange(dwFileSize); SetProgressRange(0, 100); } //Should we exit the thread if (m_bAbort) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } //check to see if the file already exists on the server if (!m_bDownload) { WIN32_FIND_DATA wfd; HINTERNET hFind = ::FtpFindFirstFile(m_hFTPConnection, m_sRemoteFile, &wfd, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); BOOL bFound = FALSE; if (hFind) { bFound = TRUE; //Destroy the enumeration handle now that we are finished with it InternetCloseHandle(hFind); } if (bFound && SendMessage(WM_FTPTRANSFER_ASK_OVERWRITE_FILE) == 0) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED, 1); return; } } //Should we exit the thread if (m_bAbort) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } //Open the remote file ASSERT(m_hFTPFile == NULL); if (m_bDownload) { if (m_bBinary) m_hFTPFile = FtpOpenFile(m_hFTPConnection, m_sRemoteFile, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); else m_hFTPFile = FtpOpenFile(m_hFTPConnection, m_sRemoteFile, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); } else { if (m_bBinary) m_hFTPFile = FtpOpenFile(m_hFTPConnection, m_sRemoteFile, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); else m_hFTPFile = FtpOpenFile(m_hFTPConnection, m_sRemoteFile, GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, (DWORD) this); } if (m_hFTPFile == NULL) { TRACE(_T("Failed in call to FtpOpenFile, Error:%d\n"), ::GetLastError()); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_FAIL_OPEN_FILE); return; } //Should we exit the thread if (m_bAbort) { if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); PostMessage(WM_FTPTRANSFER_THREAD_FINISHED); return; } //Update the status to say that we are now uploading / downloading the file if (m_bDownload) SetStatus(IDS_FTPTRANSFER_RETREIVEING_FILE); else SetStatus(IDS_FTPTRANSFER_UPLOADING_FILE); //Now do the actual reading / writing of the file DWORD dwStartTicks = ::GetTickCount(); DWORD dwCurrentTicks = dwStartTicks; DWORD dwBytesRead = 0; DWORD dwBytesWritten = 0; char szReadBuf[1024]; DWORD dwBytesToRead = 1024; DWORD dwTotalBytesRead = 0; DWORD dwTotalBytesWritten = 0; DWORD dwLastTotalBytes = 0; DWORD dwLastPercentage = 0; do { if (m_bDownload) { //Read from the remote file if (!::InternetReadFile(m_hFTPFile, szReadBuf, dwBytesToRead, &dwBytesRead)) { TRACE(_T("Failed in call to InternetReadFile, Error:%d\n"), ::GetLastError()); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_ERROR_READFILE); return; } else if (dwBytesRead && !m_bAbort) { //Write the data to file TRY { m_LocalFile.Write(szReadBuf, dwBytesRead); } CATCH(CFileException, e); { TRACE(_T("An exception occured while writing to the download file\n")); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_ERROR_READFILE, e->m_lOsError); e->Delete(); return; } END_CATCH //Increment the total number of bytes read dwTotalBytesRead += dwBytesRead; UpdateControlsDuringTransfer(dwStartTicks, dwCurrentTicks, dwTotalBytesRead, dwLastTotalBytes, dwLastPercentage, bGotFileSize, dwFileSize); } } else { //Read the data from the local file TRY { dwBytesRead = m_LocalFile.Read(szReadBuf, 1024); } CATCH(CFileException, e); { TRACE(_T("An exception occured while reading the local file\n")); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_ERROR_READFILE, e->m_lOsError); e->Delete(); return; } END_CATCH //Write to the remote file if (dwBytesRead) { if (!::InternetWriteFile(m_hFTPFile, szReadBuf, dwBytesRead, &dwBytesWritten)) { TRACE(_T("Failed in call to InternetWriteFile, Error:%d\n"), ::GetLastError()); if (pOldCallback) ::InternetSetStatusCallback(m_hInternetSession, pOldCallback); HandleThreadErrorWithLastError(IDS_FTPTRANSFER_ERROR_WRITEFILE); return; } else if (dwBytesWritten && !m_bAbort) { //Increment the total number of bytes read dwTotalBytesWritten += dwBytesWritten; UpdateControlsDuringTransfer(dwStartTicks, dwCurrentTicks, dwTotalBytesWritten, dwLastTotalBytes, dwLastPercentage, bGotFileSize, dwFileSize); } } } }
void Prey::SUBFSM() { if (FSTATE == FS_SLEEPING) { Sleep(); } else { if (MSTATE ==MS_ALERTED) { if (CheckNightTime()==false) MSTATE = MS_NORMAL; } if (AmLeader) { if ((mCurState!=ES_EVADING)&&(mCurState!=ES_MATING)&&(mCurState!=ES_ATTACK)) { LeaderHunterCheck(); } if (MSTATE == MS_NORMAL) { if(CheckNightTime()) { SetLeaderState(LS_PATROL); SetAnimationSpeed(200); PlayAnimation(ANIMATION_STANDING); SetState(ES_IDLE); } } switch(LSTATE) { case LS_NORMAL: Wander(); break; case LS_PATROL: Patrol(); break; default: break; } } else { if (MSTATE == MS_NORMAL) { if(CheckNightTime()) { SetFollowerState(FS_SLEEPING); SetAnimationSpeed(200); SetState(ES_IDLE); } } if (MyLeader) CheckLeaderAlive(); if (LeaderAlive) { switch(FSTATE) { case FS_NORMAL: FollowLeader(); break; case FS_CHASELEADER: ChaseLeader(); break; default: break; } } else { Wander(); } } } }
void UiWidget::Update() { if(m_Visible != true) { return; } if(m_AnimationCurrent != nullptr) { float delta_time = Timer::getSingleton().GetGameTimeDelta(); float time = m_AnimationCurrent->GetTime(); // if animation ended if(time + delta_time >= m_AnimationEndTime) { if(time != m_AnimationEndTime) { m_AnimationCurrent->AddTime(m_AnimationEndTime - time); } for(unsigned int i = 0; i < m_AnimationSync.size(); ++i) { ScriptManager::getSingleton().ContinueScriptExecution(m_AnimationSync[i]); } m_AnimationSync.clear(); if(m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "") { // in case of cycled default we need to sync with end time = time + delta_time - m_AnimationCurrent->GetLength(); PlayAnimation(m_AnimationDefault, UiAnimation::DEFAULT, time, -1); } else { m_AnimationCurrent = NULL; } } else { m_AnimationCurrent->AddTime(delta_time); } } else if( m_AnimationCurrent == NULL && m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "" ) { PlayAnimation( m_AnimationDefault, UiAnimation::DEFAULT, 0, -1 ); } if( m_UpdateTransformation == true ) { UpdateTransformation(); } for( unsigned int i = 0; i < m_Children.size(); ++i ) { m_Children[ i ]->Update(); } // debug output if(cv_debug_ui.GetI() >= 1) { float local_x1 = -m_FinalOrigin.x; float local_y1 = -m_FinalOrigin.y; float local_x2 = m_FinalSize.x + local_x1; float local_y2 = m_FinalSize.y + local_y1; float x = m_FinalTranslate.x; float y = m_FinalTranslate.y; DEBUG_DRAW.SetScreenSpace(true); DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1)); int x1, y1, x2, y2, x3, y3, x4, y4; if(m_FinalRotation != 0) { float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(m_FinalRotation))); float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(m_FinalRotation))); x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x); y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y); x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x); y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y); x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x); y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y); x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x); y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y); } else { x1 = static_cast<int>(local_x1 + x); y1 = static_cast<int>(local_y1 + y); x2 = static_cast<int>(local_x2 + x); y2 = static_cast<int>(local_y1 + y); x3 = static_cast<int>(local_x2 + x); y3 = static_cast<int>(local_y2 + y); x4 = static_cast<int>(local_x1 + x); y4 = static_cast<int>(local_y2 + y); } // slightly modify to let show things that are on board of screen DEBUG_DRAW.Line(static_cast<float>(x1), static_cast<float>(y1 + 1), static_cast<float>(x2), static_cast<float>(y2 + 1)); DEBUG_DRAW.Line(static_cast<float>(x2 - 1), static_cast<float>(y2), static_cast<float>(x3 - 1), static_cast<float>(y3)); DEBUG_DRAW.Line(static_cast<float>(x3), static_cast<float>(y3), static_cast<float>(x4), static_cast<float>(y4)); DEBUG_DRAW.Line(static_cast<float>(x4), static_cast<float>(y4), static_cast<float>(x1), static_cast<float>(y1)); // draw translation DEBUG_DRAW.SetColour(Ogre::ColourValue(0, 1, 0, 1)); Ogre::Vector2 area_origin = (m_Parent != nullptr) ? m_Parent->GetFinalOrigin() : Ogre::Vector2::ZERO; Ogre::Vector2 area_translate = (m_Parent != nullptr) ? m_Parent->GetFinalTranslate() : Ogre::Vector2::ZERO; Ogre::Vector2 pos = area_translate - area_origin; DEBUG_DRAW.Line(pos.x, pos.y, x, y); DEBUG_DRAW.Quad(x - 2, y - 2, x + 2, y - 2, x + 2, y + 2, x - 2, y + 2); if(cv_debug_ui.GetI() >= 2) { DEBUG_DRAW.SetColour(Ogre::ColourValue::White); DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.LEFT); DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1), m_PathName); DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1 + 12), GetCurrentAnimationName()); } // draw origin DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1)); DEBUG_DRAW.Line(x, y, static_cast<float>(x1), static_cast<float>(y1 + 1)); } }
void Graphics_Mesh(bool isOpenGLMode) { StartGraphicsTest(); SetGLEnable(isOpenGLMode); ace::Log* log = ace::Log_Imp::Create(L"graphics.html", L"メッシュ"); auto window = ace::Window_Imp::Create(640, 480, ace::ToAString(L"メッシュ").c_str()); ASSERT_TRUE(window != nullptr); auto graphics = ace::Graphics_Imp::Create(window, isOpenGLMode, log, false); ASSERT_TRUE(graphics != nullptr); auto renderer3d = new ace::Renderer3D(graphics); ASSERT_TRUE(renderer3d != nullptr); renderer3d->SetWindowSize(ace::Vector2DI(640, 480)); auto mesh1 = CreateMesh(graphics); auto mesh2 = CreateMesh(graphics); auto deformer = CreateDeformer(graphics); auto animation = CreateAnimation(); auto cameraObject = new ace::RenderedCameraObject3D(graphics); cameraObject->SetPosition(ace::Vector3DF(0, 0, 10)); cameraObject->SetFocus(ace::Vector3DF(0, 0, 0)); cameraObject->SetFieldOfView(20.0f); cameraObject->SetZNear(1.0f); cameraObject->SetZFar(20.0f); cameraObject->SetWindowSize(ace::Vector2DI(800, 600)); auto meshObject1 = new ace::RenderedModelObject3D(graphics); meshObject1->AddMeshGroup(); meshObject1->AddMesh(0, mesh1); meshObject1->SetPosition(ace::Vector3DF(1, 0, 0)); meshObject1->SetRotation(ace::Vector3DF(20.0f, 20.0f, 0.0f)); auto meshObject2 = new ace::RenderedModelObject3D(graphics); meshObject2->AddMeshGroup(); meshObject2->AddMesh(0, mesh2); meshObject2->SetDeformer(0, deformer.get()); meshObject2->SetPosition(ace::Vector3DF(-1, 0, 0)); meshObject2->SetRotation(ace::Vector3DF(20.0f, 20.0f, 0.0f)); meshObject2->AddAnimationClip(ace::ToAString("anime1").c_str(), animation.get()); meshObject2->PlayAnimation(ace::ToAString("anime1").c_str()); auto lightObject = new ace::RenderedDirectionalLightObject3D(graphics); lightObject->SetRotation(ace::Vector3DF(30, 160, 0)); renderer3d->AddObject(cameraObject); renderer3d->AddObject(meshObject1); renderer3d->AddObject(meshObject2); renderer3d->AddObject(lightObject); auto renderer2d = new ace::Renderer2D_Imp(graphics, log, window->GetSize()); int32_t time = 0; while (window->DoEvent()) { graphics->Begin(); graphics->Clear(true, false, ace::Color(0, 0, 0, 255)); renderer3d->Flip(); renderer3d->BeginRendering(); ace::Sleep(100); renderer3d->EndRendering(); graphics->SetRenderTarget(nullptr, nullptr); ace::Vector2DF positions[4]; ace::Color colors[4]; ace::Vector2DF uvs[4]; colors[0] = ace::Color(255, 255, 255, 255); colors[1] = ace::Color(255, 255, 255, 255); colors[2] = ace::Color(255, 255, 255, 255); colors[3] = ace::Color(255, 255, 255, 255); positions[0].X = 0; positions[0].Y = 0; positions[1].X = 640; positions[1].Y = 0; positions[2].X = 640; positions[2].Y = 480; positions[3].X = 0; positions[3].Y = 480; uvs[0].X = 0; uvs[0].Y = 0; uvs[1].X = 1; uvs[1].Y = 0; uvs[2].X = 1; uvs[2].Y = 1; uvs[3].X = 0; uvs[3].Y = 1; renderer2d->AddSprite(positions, colors, uvs, renderer3d->GetRenderTarget(), ace::eAlphaBlend::ALPHA_BLEND_BLEND, 0); renderer2d->DrawCache(); renderer2d->ClearCache(); graphics->Present(); graphics->End(); if (time == 10) { SAVE_SCREEN_SHOT(graphics, 0); } if (time == 11) { window->Close(); } time++; } meshObject1->Release(); meshObject2->Release(); cameraObject->Release(); lightObject->Release(); delete renderer2d; delete renderer3d; graphics->Release(); window->Release(); delete log; }
void UiWidget::ScriptPlayAnimation(const char* name) { PlayAnimation(Ogre::String(name), UiAnimation::DEFAULT, 0, -1); }
void CHttpDownloadDlg::DownloadThread() { ENCODING_INIT; //Create the Internet session handle ASSERT(m_hInternetSession == NULL); m_hInternetSession = ::InternetOpen(HTTP_USERAGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (m_hInternetSession == NULL) { TRACE(_T("Failed in call to InternetOpen, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_GENERIC_ERROR); return; } //Should we exit the thread if (m_bAbort) { PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED); return; } //Setup the status callback function if (::InternetSetStatusCallback(m_hInternetSession, _OnStatusCallBack) == INTERNET_INVALID_STATUS_CALLBACK) { TRACE(_T("Failed in call to InternetSetStatusCallback, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_GENERIC_ERROR); return; } //Should we exit the thread if (m_bAbort) { PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED); return; } //Make the connection to the HTTP server ASSERT(m_hHttpConnection == NULL); if (m_sUserName.GetLength()) m_hHttpConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_uPort, m_sUserName, m_sPassword, m_dwServiceType, 0, (DWORD) this); else m_hHttpConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_uPort, NULL, NULL, m_dwServiceType, 0, (DWORD) this); if (m_hHttpConnection == NULL) { TRACE(_T("Failed in call to InternetConnect, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER); return; } //Should we exit the thread if (m_bAbort) { PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED); return; } //Start the animation to signify that the download is taking place PlayAnimation(); //Issue the request to read the file LPCTSTR ppszAcceptTypes[2]; ppszAcceptTypes[0] = _T("*/*"); //We support accepting any mime file type since this is a simple download of a file ppszAcceptTypes[1] = NULL; ASSERT(m_hHttpFile == NULL); m_hHttpFile = HttpOpenRequest(m_hHttpConnection, NULL, m_sObject, NULL, NULL, ppszAcceptTypes, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION, (DWORD)this); if (m_hHttpFile == NULL) { TRACE(_T("Failed in call to HttpOpenRequest, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER); return; } //Should we exit the thread if (m_bAbort) { PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED); return; } //fill in what encoding we support HttpAddRequestHeaders(m_hHttpFile, ACCEPT_ENCODING_HEADER, CSTRLEN(ACCEPT_ENCODING_HEADER), HTTP_ADDREQ_FLAG_ADD); //label used to jump to if we need to resend the request resend: //Issue the request BOOL bSend = ::HttpSendRequest(m_hHttpFile, NULL, 0, NULL, 0); if (!bSend) { TRACE(_T("Failed in call to HttpSendRequest, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER); return; } // Check the HTTP status code DWORD dwStatusCode = 0, dwSz = sizeof(dwStatusCode); if (!HttpQueryInfo(m_hHttpFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwSz, NULL)) { TRACE(_T("Failed in call to HttpQueryInfo for HTTP query status code, Error:%d\n"), ::GetLastError()); HandleThreadError(IDS_HTTPDOWNLOAD_INVALID_SERVER_RESPONSE); return; } else { //Handle any authentication errors if (dwStatusCode == HTTP_STATUS_PROXY_AUTH_REQ || dwStatusCode == HTTP_STATUS_DENIED) { // We have to read all outstanding data on the Internet handle // before we can resubmit request. Just discard the data. char szData[51]; DWORD dwSize; do { ::InternetReadFile(m_hHttpFile, (LPVOID)szData, 50, &dwSize); } while (dwSize != 0); //Bring up the standard authentication dialog if (::InternetErrorDlg(GetSafeHwnd(), m_hHttpFile, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL) == ERROR_INTERNET_FORCE_RETRY) goto resend; } else if (dwStatusCode != HTTP_STATUS_OK) { TRACE(_T("Failed to retrieve a HTTP 200 status, Status Code:%d\n"), dwStatusCode); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_INVALID_HTTP_RESPONSE, dwStatusCode); return; } } //Check to see if any encodings are supported TCHAR szContentEncoding[32]; DWORD dwEncodeStringSize = sizeof(szContentEncoding); if(::HttpQueryInfo(m_hHttpFile, HTTP_QUERY_CONTENT_ENCODING, szContentEncoding, &dwEncodeStringSize, NULL)) { if(!_tcsicmp(szContentEncoding, _T("gzip")) || !_tcsicmp(szContentEncoding, _T("x-gzip"))) bEncodedWithGZIP = TRUE; } //Update the status control to reflect that we are getting the file information SetStatus(IDS_HTTPDOWNLOAD_GETTING_FILE_INFORMATION); // Get the length of the file DWORD dwFileSize = 0; BOOL bGotFileSize = FALSE; dwSz = sizeof(dwFileSize); if ( ::HttpQueryInfo( m_hHttpFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwFileSize, &dwSz, NULL ) && (dwFileSize != 0) ) { // Set the progress control range bGotFileSize = TRUE; SetProgressRange(dwFileSize); } //Update the status to say that we are now downloading the file SetStatus(IDS_HTTPDOWNLOAD_RETREIVEING_FILE); //Now do the actual read of the file DWORD dwStartTicks = ::GetTickCount(); DWORD dwCurrentTicks = dwStartTicks; DWORD dwBytesRead = 0; char szReadBuf[1024]; DWORD dwBytesToRead = 1024; DWORD dwTotalBytesRead = 0; DWORD dwLastTotalBytes = 0; DWORD dwLastPercentage = 0; PREPARE_DECODER; do { if (!::InternetReadFile(m_hHttpFile, szReadBuf, dwBytesToRead, &dwBytesRead)) { TRACE(_T("Failed in call to InternetReadFile, Error:%d\n"), ::GetLastError()); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_ERROR_READFILE); ENCODING_CLEAN_UP; return; } else if (dwBytesRead && !m_bAbort) { //Write the data to file try { DECODE_DATA(m_FileToWrite, szReadBuf, dwBytesRead); } catch(CFileException *error) { TRACE(_T("An exception occured while writing to the download file\n")); HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_ERROR_READFILE, error->m_lOsError); error->Delete(); //clean up any encoding data before we return ENCODING_CLEAN_UP; return; } //Increment the total number of bytes read dwTotalBytesRead += dwBytesRead; UpdateControlsDuringTransfer(dwStartTicks, dwCurrentTicks, dwTotalBytesRead, dwLastTotalBytes, dwLastPercentage, bGotFileSize, dwFileSize); } } while (dwBytesRead && !m_bAbort); //clean up any encoding data before we return ENCODING_CLEAN_UP; //Delete the file being downloaded to if it is present and the download was aborted m_FileToWrite.Close(); if (m_bAbort) ::DeleteFile(m_sFileToDownloadInto); //We're finished PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED); }
void UiWidget::ScriptPlayAnimationStop(const char* name) { PlayAnimation(Ogre::String(name), UiAnimation::ONCE, 0, -1); }
bool CClientWeaponDisc::PlayFireAnimation( bool bResetAni ) { // bResetAni is equivalant to saying "the fire key is down" // Can only set the last fire type if a fire animation isn't playing // (i.e., we'll assume this function will return false)... uint32 dwAni = g_pLTClient->GetModelAnimation( m_hObject ); uint32 dwState = g_pLTClient->GetModelPlaybackState( m_hObject ); bool bIsFireAni = IsFireAni( dwAni ); uint32 dwPreFireAni = GetPreFireAni(); uint32 dwPostFireAni = GetPostFireAni(); if ( !bIsFireAni ) { // If we have a pre-fire animation, play it before the fire animation... if( ( INVALID_ANI != dwPreFireAni ) && !bIsFireAni ) { PlayAnimation( dwPreFireAni ); return true; } } else { if ( ( dwPreFireAni == dwAni ) ) { // Since the disc firing sequence and the related variables // to esure we have a boomerang style weapon are pretty // sensitive to variation, force the entire prefire animation // to finish completely, the queue either a fire or a post // fire animation depending on what the user wants to do. if ( dwState & MS_PLAYDONE ) { // // There are 2 ways to fire a disc. Either click-to-fire // click-to-return, or hold-to-fire-release-to-return. // The logic here supports both versions. If the user // is pressing the fire button when the fire key is // received, we are considering that hold-to-fire. If // not, it is considered click-to-fire. // // if bResetAni is true, the user wants to fire if ( bResetAni || m_bIsDiscActive ) { // we are done playing the prefire animation, play the // fire animation as looping uint32 dwFireAni = GetFireAni( m_eLastFireType ); if ( INVALID_ANI == dwFireAni ) { // no valid fire animation ASSERT( !"no valid fire animation" ); return false; } PlayAnimation( dwFireAni, true, 1.0f, true ); } else { // // the user dosen't want to fire // if ( !m_bIsDiscActive ) { if ( INVALID_ANI == dwPostFireAni ) { // no valid fire animation return false; } PlayAnimation( dwPostFireAni ); } } } // else, don't let anything happen until the prefire is done } else if ( ( dwPostFireAni == dwAni ) && ( dwState & MS_PLAYDONE ) ) { // postfire animation is finished, // handle the ending DoSpecialEndFire(); if ( bResetAni ) { // the user wants to start throwing again...NOW! // Without this here, there is no way for the weapon // to start firing again until the user lets the // mouse button up. PlayAnimation( dwPreFireAni ); return true; } // no special animation playing return false; } else if ( ( dwPostFireAni != dwAni ) && ( !m_bIsDiscActive ) ) { // play the postfire animation immediately if ( INVALID_ANI == dwPostFireAni ) { // no valid postfire animation ASSERT( !"no valid postfire animation" ); return false; } PlayAnimation( dwPostFireAni ); } } return true; }
LRESULT CALLBACK winproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MENUITEMINFO mii; HMENU hMenu = GetMenu(hWnd); OPENFILENAME ofn; char path[MAX_PATH]; HCURSOR hcur; switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case ID_MENU_FILE_OPEN: // wczytywanie pliku memset(&ofn, 0, sizeof(ofn)); memset(path, 0, MAX_PATH); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd; ofn.lpstrFile = path; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = "3D Studio R4 (*.3ds)\0*.3ds\0\0"; ofn.lpstrTitle = NULL; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; ofn.lpstrInitialDir = ".\\"; if (::GetOpenFileName(&ofn)) { CLoader3DS load_3ds(g_Scene); hcur = ::SetCursor(LoadCursor(NULL, IDC_WAIT)); load_3ds.Load(path); if (!g_Scene.SetActiveCamera("Camera01")) g_Scene.SetFirstCamera(); ::SetCursor(hcur); /// ustaw odpowiednio menu systemowe: ::ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_ENABLED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); /// dopisz do titlebar'u nazwê otwartego pliku: char *foo = new char [strlen(g_lpszNoFileProgName) + strlen(path + ofn.nFileOffset) + 4]; strcpy(foo, g_lpszNoFileProgName); strcat(foo, " - "); strcat(foo, path + ofn.nFileOffset); DELETE_ARRAY(g_lpszProgName); g_lpszProgName = foo; ::SetWindowText(hWnd, g_lpszProgName); /// tutaj poœrednio ustawienie odpowiednie nazwu dla okienka z animacj¹: DELETE_ARRAY(g_WindowParams.szTitle); g_WindowParams.szTitle = strdup(path + ofn.nFileOffset); } break; case ID_MENU_FILE_CLOSE: { g_Scene.Release(); /// wygaœ odpowiednie opcje w menu: ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_GRAYED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); /// umieœæ w titlebarze sam¹ nazwê aplikacji: DELETE_ARRAY(g_lpszProgName); g_lpszProgName = strdup(g_lpszNoFileProgName); ::SetWindowText(hWnd, g_lpszProgName); } break; case ID_MENU_FILE_EXIT: g_Scene.Release(); ::SendMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_MENU_VIEW_ANIMATION: { if (!DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1), MainhWnd, (DLGPROC)SetupDlgProc)) return 0; if (g_WindowParams.szTitle == NULL) g_WindowParams.szTitle = strdup("test"); g_WindowParams.lpfnProc = MainWndProc; g_WindowParams.hInst = g_hInstance; try { if (!g_Scene.SetActiveCamera("Camera01")) g_Scene.SetFirstCamera(); ::EnableWindow(hWnd, FALSE); InitOpenGL(g_WindowParams, hWnd); g_Scene.SetScreenAspect((float)g_WindowParams.nWidth/g_WindowParams.nHeight); //g_Scene.PrintInfo(LOG); g_Scene.PrepareAnimation(); g_Scene.InitTextures(); g_Scene.InitDisplayLists(); PlayAnimation(); g_Scene.DeinitDisplayLists(); g_Scene.DeinitTextures(); DeInitOpenGL(g_WindowParams); ::EnableWindow(hWnd, TRUE); ::SetActiveWindow(hWnd); } catch (CException ex) { if (ex.type == CException::EXCEPTION_STRING) { static char *error_msg = strdup(ex.error_string); fatal_error(error_msg); } else { char buffer[10]; _itoa(ex.error, buffer, 10); fatal_error(buffer); } } catch (...) { fatal_error("Unknown error!"); } } break; case ID_MENU_HELP_ABOUT: ::DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), MainhWnd, (DLGPROC)AboutDlgProc); break; default: break; } break; case WM_DESTROY: ::PostQuitMessage(0); break; case WM_CREATE: ZeroMemory(&mii, sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; mii.fState = MFS_GRAYED; ::SetMenuItemInfo(hMenu, ID_MENU_VIEW_ANIMATION, FALSE, &mii); ::SetMenuItemInfo(hMenu, ID_MENU_FILE_CLOSE, FALSE, &mii); break; default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam); break; } return 0; }