// // This search function will sit with the turret deployed and look for a new target. // After a set amount of time, the barrel will spin down. After m_flMaxWait, the turret will // retact. // void CBaseTurret::SearchThink(void) { // ensure rethink SetTurretAnim(TURRET_ANIM_SPIN); StudioFrameAdvance( ); pev->nextthink = gpGlobals->time + 0.1; if (m_flSpinUpTime == 0 && m_flMaxSpin) m_flSpinUpTime = gpGlobals->time + m_flMaxSpin; Ping( ); // If we have a target and we're still healthy if (m_hEnemy != NULL) { if (!m_hEnemy->IsAlive() ) m_hEnemy = NULL;// Dead enemy forces a search for new one } // Acquire Target if (m_hEnemy == NULL) { Look(this->GetRange()); m_hEnemy = BestVisibleEnemy(); } // If we've found a target, spin up the barrel and start to attack if (m_hEnemy != NULL) { m_flLastSight = 0; m_flSpinUpTime = 0; SetThink(&CBaseTurret::ActiveThink); } else { // Are we out of time, do we need to retract? if (gpGlobals->time > m_flLastSight) { //Before we retrace, make sure that we are spun down. m_flLastSight = 0; m_flSpinUpTime = 0; SetThink(&CBaseTurret::Retire); } // should we stop the spin? else if ((m_flSpinUpTime) && (gpGlobals->time > m_flSpinUpTime)) { SpinDownCall(); } // generic hunt for new victims m_vecGoalAngles.y = (m_vecGoalAngles.y + 0.1 * m_fTurnRate); if (m_vecGoalAngles.y >= 360) m_vecGoalAngles.y -= 360; MoveTurret(); } }
void WinDecorator::_DoLayout() { STRACE(("WinDecorator()::_DoLayout()\n")); bool hasTab = false; fBorderRect=fFrame; fTabRect=fFrame; switch (Look()) { case B_MODAL_WINDOW_LOOK: fBorderRect.InsetBy(-4, -4); break; case B_TITLED_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK: hasTab = true; fBorderRect.InsetBy(-4, -4); break; case B_FLOATING_WINDOW_LOOK: hasTab = true; break; case B_BORDERED_WINDOW_LOOK: fBorderRect.InsetBy(-1, -1); break; default: break; } if (hasTab) { fBorderRect.top -= 19; fTabRect.top -= 19; fTabRect.bottom=fTabRect.top+19; fZoomRect=fTabRect; fZoomRect.top+=3; fZoomRect.right-=3; fZoomRect.bottom-=3; fZoomRect.left=fZoomRect.right-15; fCloseRect=fZoomRect; fZoomRect.OffsetBy(0-fZoomRect.Width()-3,0); fMinimizeRect=fZoomRect; fMinimizeRect.OffsetBy(0-fZoomRect.Width()-1,0); } else { fTabRect.Set(0.0, 0.0, -1.0, -1.0); fCloseRect.Set(0.0, 0.0, -1.0, -1.0); fZoomRect.Set(0.0, 0.0, -1.0, -1.0); fMinimizeRect.Set(0.0, 0.0, -1.0, -1.0); } }
//========================================================= // RunAI //========================================================= void CBaseMonster :: RunAI ( void ) { // to test model's eye height //UTIL_ParticleEffect ( pev->origin + pev->view_ofs, g_vecZero, 255, 10 ); // IDLE sound permitted in ALERT state is because monsters were silent in ALERT state. Only play IDLE sound in IDLE state // once we have sounds for that state. if ( ( m_MonsterState == MONSTERSTATE_IDLE || m_MonsterState == MONSTERSTATE_ALERT ) && RANDOM_LONG(0,99) == 0 && !(pev->flags & SF_MONSTER_GAG) ) { IdleSound(); } if ( m_MonsterState != MONSTERSTATE_NONE && m_MonsterState != MONSTERSTATE_PRONE && m_MonsterState != MONSTERSTATE_DEAD )// don't bother with this crap if monster is prone. { // collect some sensory Condition information. // don't let monsters outside of the player's PVS act up, or most of the interesting // things will happen before the player gets there! // UPDATE: We now let COMBAT state monsters think and act fully outside of player PVS. This allows the player to leave // an area where monsters are fighting, and the fight will continue. if ( !FNullEnt( FIND_CLIENT_IN_PVS( edict() ) ) || ( m_MonsterState == MONSTERSTATE_COMBAT ) ) { Look( m_flDistLook ); Listen();// check for audible sounds. // now filter conditions. ClearConditions( IgnoreConditions() ); GetEnemy(); } // do these calculations if monster has an enemy. if ( m_hEnemy != NULL ) { CheckEnemy( m_hEnemy ); } CheckAmmo(); } FCheckAITrigger(); PrescheduleThink(); MaintainSchedule(); // if the monster didn't use these conditions during the above call to MaintainSchedule() or CheckAITrigger() // we throw them out cause we don't want them sitting around through the lifespan of a schedule // that doesn't use them. m_afConditions &= ~( bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE ); }
int CAI_Senses::LookForHighPriorityEntities( int iDistance ) { int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookHighPriority > AI_HIGH_PRIORITY_SEARCH_TIME ) { AI_PROFILE_SENSES(CAI_Senses_LookForHighPriorityEntities); m_TimeLastLookHighPriority = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); // Players for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer ) { if ( origin.DistToSqr(pPlayer->GetAbsOrigin()) < distSq && Look( pPlayer ) ) { nSeen++; } #ifdef PORTAL else { CProp_Portal *pPortal = GetOuter()->FInViewConeThroughPortal( pPlayer ); if ( pPortal && UTIL_Portal_DistanceThroughPortalSqr( pPortal, origin, pPlayer->GetAbsOrigin() ) < distSq && LookThroughPortal( pPortal, pPlayer ) ) { nSeen++; } } #endif } } EndGather( nSeen, &m_SeenHighPriority ); } else { for ( int i = m_SeenHighPriority.Count() - 1; i >= 0; --i ) { if ( m_SeenHighPriority[i].Get() == NULL ) m_SeenHighPriority.FastRemove( i ); } nSeen = m_SeenHighPriority.Count(); } return nSeen; }
void CAI_Senses::PerformSensing( void ) { AI_PROFILE_SCOPE (CAI_BaseNPC_PerformSensing); // ----------------- // Look // ----------------- if( !HasSensingFlags(SENSING_FLAGS_DONT_LOOK) ) Look( m_LookDist ); // ------------------ // Listen // ------------------ if( !HasSensingFlags(SENSING_FLAGS_DONT_LISTEN) ) Listen(); }
static void LineInput(char *buf, size_t n) { event_t ev; glk_request_line_event(Bottom, buf, n - 1, 0); while(1) { glk_select(&ev); if(ev.type == evtype_LineInput) break; else if(ev.type == evtype_Arrange && split_screen) Look(); } buf[ev.val1] = 0; }
int CAI_Senses::LookForObjects( int iDistance ) { const int BOX_QUERY_MASK = FL_OBJECT; int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookMisc > AI_MISC_SEARCH_TIME ) { AI_PROFILE_SENSES(CAI_Senses_LookForObjects); m_TimeLastLookMisc = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); int iter; CBaseEntity *pEnt = g_AI_SensedObjectsManager.GetFirst( &iter ); while ( pEnt ) { if ( pEnt->GetFlags() & BOX_QUERY_MASK ) { if ( origin.DistToSqr(pEnt->GetAbsOrigin()) < distSq && Look( pEnt) ) { nSeen++; } } pEnt = g_AI_SensedObjectsManager.GetNext( &iter ); } EndGather( nSeen, &m_SeenMisc ); } else { for ( int i = m_SeenMisc.Count() - 1; i >= 0; --i ) { if ( m_SeenMisc[i].Get() == NULL ) m_SeenMisc.FastRemove( i ); } nSeen = m_SeenMisc.Count(); } return nSeen; }
int CAI_Senses::LookForHighPriorityEntities( int iDistance ) { int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookHighPriority > AI_HIGH_PRIORITY_SEARCH_TIME ) { m_TimeLastLookHighPriority = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); // Players for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CPlayer *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer ) { if ( origin.DistToSqr(pPlayer->GetAbsOrigin()) < distSq && Look( pPlayer->BaseEntity() ) ) { nSeen++; } } } EndGather( nSeen, &m_SeenHighPriority ); } else { for ( int i = m_SeenHighPriority.Count() - 1; i >= 0; --i ) { if ( m_SeenHighPriority[i].Get() == NULL ) m_SeenHighPriority.FastRemove( i ); } nSeen = m_SeenHighPriority.Count(); } return nSeen; }
void CLeech::SwitchLeechState( void ) { m_stateTime = gpGlobals->time + RANDOM_FLOAT( 3, 6 ); if ( m_MonsterState == MONSTERSTATE_COMBAT ) { m_hEnemy = NULL; SetState( MONSTERSTATE_IDLE ); // We may be up against the player, so redo the side checks m_sideTime = 0; } else { Look( m_flDistLook ); CBaseEntity *pEnemy = BestVisibleEnemy(); if ( pEnemy && pEnemy->pev->waterlevel != 0 ) { m_hEnemy = pEnemy; SetState( MONSTERSTATE_COMBAT ); m_stateTime = gpGlobals->time + RANDOM_FLOAT( 18, 25 ); AlertSound(); } } }
void CNihilanth :: NextActivity( ) { UTIL_MakeAimVectors( pev->angles ); if (m_irritation >= 2) { if (m_pBall == NULL) { m_pBall = CSprite::SpriteCreate( "sprites/tele1.spr", pev->origin, TRUE ); if (m_pBall) { m_pBall->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxNoDissipation ); m_pBall->SetAttachment( edict(), 1 ); m_pBall->SetScale( 4.0 ); m_pBall->pev->framerate = 10.0; m_pBall->TurnOn( ); } } if (m_pBall) { MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_ELIGHT ); WRITE_SHORT( entindex( ) + 0x1000 ); // entity, attachment WRITE_COORD( pev->origin.x ); // origin WRITE_COORD( pev->origin.y ); WRITE_COORD( pev->origin.z ); WRITE_COORD( 256 ); // radius WRITE_BYTE( 255 ); // R WRITE_BYTE( 192 ); // G WRITE_BYTE( 64 ); // B WRITE_BYTE( 200 ); // life * 10 WRITE_COORD( 0 ); // decay MESSAGE_END(); } } if ((pev->health < gSkillData.nihilanthHealth / 2 || m_iActiveSpheres < N_SPHERES / 2) && m_hRecharger == NULL && m_iLevel <= 9) { char szName[64]; CBaseEntity *pEnt = NULL; CBaseEntity *pRecharger = NULL; float flDist = 8192; sprintf(szName, "%s%d", m_szRechargerTarget, m_iLevel ); while ((pEnt = UTIL_FindEntityByTargetname( pEnt, szName )) != NULL) { float flLocal = (pEnt->pev->origin - pev->origin).Length(); if (flLocal < flDist) { flDist = flLocal; pRecharger = pEnt; } } if (pRecharger) { m_hRecharger = pRecharger; m_posDesired = Vector( pev->origin.x, pev->origin.y, pRecharger->pev->origin.z ); m_vecDesired = (pRecharger->pev->origin - m_posDesired).Normalize( ); m_vecDesired.z = 0; m_vecDesired = m_vecDesired.Normalize(); } else { m_hRecharger = NULL; ALERT( at_aiconsole, "nihilanth can't find %s\n", szName ); m_iLevel++; if (m_iLevel > 9) m_irritation = 2; } } float flDist = (m_posDesired - pev->origin).Length(); float flDot = DotProduct( m_vecDesired, gpGlobals->v_forward ); if (m_hRecharger != NULL) { // at we at power up yet? if (flDist < 128.0) { int iseq = LookupSequence( "recharge" ); if (iseq != pev->sequence) { char szText[64]; sprintf( szText, "%s%d", m_szDrawUse, m_iLevel ); FireTargets( szText, this, this, USE_ON, 1.0 ); ALERT( at_console, "fireing %s\n", szText ); } pev->sequence = LookupSequence( "recharge" ); } else { FloatSequence( ); } return; } if (m_hEnemy != NULL && !m_hEnemy->IsAlive()) { m_hEnemy = NULL; } if (m_flLastSeen + 15 < gpGlobals->time) { m_hEnemy = NULL; } if (m_hEnemy == NULL) { Look( 4096 ); m_hEnemy = BestVisibleEnemy( ); } if (m_hEnemy != NULL && m_irritation != 0) { if (m_flLastSeen + 5 > gpGlobals->time && flDist < 256 && flDot > 0) { if (m_irritation >= 2 && pev->health < gSkillData.nihilanthHealth / 2.0) { pev->sequence = LookupSequence( "attack1_open" ); } else { if (RANDOM_LONG(0, 1 ) == 0) { pev->sequence = LookupSequence( "attack1" ); // zap } else { char szText[64]; sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport ); CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText ); sprintf( szText, "%s%d", m_szTeleportUse, m_iTeleport ); CBaseEntity *pTrigger = UTIL_FindEntityByTargetname( NULL, szText ); if (pTrigger != NULL || pTouch != NULL) { pev->sequence = LookupSequence( "attack2" ); // teleport } else { m_iTeleport++; pev->sequence = LookupSequence( "attack1" ); // zap } } } return; } } FloatSequence( ); }
void CSqueakGrenade::HuntThink( void ) { // ALERT( at_console, "think\n" ); if (!IsInWorld()) { SetTouch( NULL ); UTIL_Remove( this ); return; } StudioFrameAdvance( ); pev->nextthink = gpGlobals->time + 0.1; // explode when ready if (gpGlobals->time >= m_flDie) { g_vecAttackDir = pev->velocity.Normalize( ); pev->health = -1; Killed( pev, 0 ); return; } // float if (pev->waterlevel != 0) { if (pev->movetype == MOVETYPE_BOUNCE) { pev->movetype = MOVETYPE_FLY; } pev->velocity = pev->velocity * 0.9; pev->velocity.z += 8.0; } else if (pev->movetype = MOVETYPE_FLY) { pev->movetype = MOVETYPE_BOUNCE; } // return if not time to hunt if (m_flNextHunt > gpGlobals->time) return; m_flNextHunt = gpGlobals->time + 2.0; CBaseEntity *pOther = NULL; Vector vecDir; TraceResult tr; Vector vecFlat = pev->velocity; vecFlat.z = 0; vecFlat = vecFlat.Normalize( ); UTIL_MakeVectors( pev->angles ); if (m_hEnemy == NULL || !m_hEnemy->IsAlive()) { // find target, bounce a bit towards it. Look( 512 ); m_hEnemy = BestVisibleEnemy( ); } // squeek if it's about time blow up if ((m_flDie - gpGlobals->time <= 0.5) && (m_flDie - gpGlobals->time >= 0.3)) { EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG(0,0x3F)); CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 256, 0.25 ); } // higher pitch as squeeker gets closer to detonation time float flpitch = 155.0 - 60.0 * ((m_flDie - gpGlobals->time) / SQUEEK_DETONATE_DELAY); if (flpitch < 80) flpitch = 80; if (m_hEnemy != NULL) { if (FVisible( m_hEnemy )) { vecDir = m_hEnemy->EyePosition() - pev->origin; m_vecTarget = vecDir.Normalize( ); } float flVel = pev->velocity.Length(); float flAdj = 50.0 / (flVel + 10.0); if (flAdj > 1.2) flAdj = 1.2; // ALERT( at_console, "think : enemy\n"); // ALERT( at_console, "%.0f %.2f %.2f %.2f\n", flVel, m_vecTarget.x, m_vecTarget.y, m_vecTarget.z ); pev->velocity = pev->velocity * flAdj + m_vecTarget * 300; } if (pev->flags & FL_ONGROUND) { pev->avelocity = Vector( 0, 0, 0 ); } else { if (pev->avelocity == Vector( 0, 0, 0)) { pev->avelocity.x = RANDOM_FLOAT( -100, 100 ); pev->avelocity.z = RANDOM_FLOAT( -100, 100 ); } } if ((pev->origin - m_posPrev).Length() < 1.0) { pev->velocity.x = RANDOM_FLOAT( -100, 100 ); pev->velocity.y = RANDOM_FLOAT( -100, 100 ); } m_posPrev = pev->origin; pev->angles = UTIL_VecToAngles( pev->velocity ); pev->angles.z = 0; pev->angles.x = 0; }
//========================================================= // MonsterThink, overridden for roaches. //========================================================= void CRoach :: MonsterThink( void ) { if ( FNullEnt( FIND_CLIENT_IN_PVS( edict() ) ) ) pev->nextthink = gpGlobals->time + RANDOM_FLOAT(1,1.5); else pev->nextthink = gpGlobals->time + 0.1;// keep monster thinking float flInterval = StudioFrameAdvance( ); // animate if ( !m_fLightHacked ) { // if light value hasn't been collection for the first time yet, // suspend the creature for a second so the world finishes spawning, then we'll collect the light level. pev->nextthink = gpGlobals->time + 1; m_fLightHacked = TRUE; return; } else if ( m_flLastLightLevel < 0 ) { // collect light level for the first time, now that all of the lightmaps in the roach's area have been calculated. m_flLastLightLevel = GETENTITYILLUM( ENT( pev ) ); } switch ( m_iMode ) { case ROACH_IDLE: case ROACH_EAT: { // if not moving, sample environment to see if anything scary is around. Do a radius search 'look' at random. if ( RANDOM_LONG(0,3) == 1 ) { Look( 150 ); if (HasConditions(bits_COND_SEE_FEAR)) { // if see something scary //ALERT ( at_aiconsole, "Scared\n" ); Eat( 30 + ( RANDOM_LONG(0,14) ) );// roach will ignore food for 30 to 45 seconds PickNewDest( ROACH_SCARED_BY_ENT ); SetActivity ( ACT_WALK ); } else if ( RANDOM_LONG(0,149) == 1 ) { // if roach doesn't see anything, there's still a chance that it will move. (boredom) //ALERT ( at_aiconsole, "Bored\n" ); PickNewDest( ROACH_BORED ); SetActivity ( ACT_WALK ); if ( m_iMode == ROACH_EAT ) { // roach will ignore food for 30 to 45 seconds if it got bored while eating. Eat( 30 + ( RANDOM_LONG(0,14) ) ); } } } // don't do this stuff if eating! if ( m_iMode == ROACH_IDLE ) { if ( FShouldEat() ) { Listen(); } if ( GETENTITYILLUM( ENT(pev) ) > m_flLastLightLevel ) { // someone turned on lights! //ALERT ( at_console, "Lights!\n" ); PickNewDest( ROACH_SCARED_BY_LIGHT ); SetActivity ( ACT_WALK ); } else if ( HasConditions(bits_COND_SMELL_FOOD) ) { CSound *pSound; pSound = CSoundEnt::SoundPointerForIndex( m_iAudibleList ); // roach smells food and is just standing around. Go to food unless food isn't on same z-plane. if ( pSound && abs( pSound->m_vecOrigin.z - pev->origin.z ) <= 3 ) { PickNewDest( ROACH_SMELL_FOOD ); SetActivity ( ACT_WALK ); } } } break; } case ROACH_SCARED_BY_LIGHT: { // if roach was scared by light, then stop if we're over a spot at least as dark as where we started! if ( GETENTITYILLUM( ENT( pev ) ) <= m_flLastLightLevel ) { SetActivity ( ACT_IDLE ); m_flLastLightLevel = GETENTITYILLUM( ENT ( pev ) );// make this our new light level. } break; } } if ( m_flGroundSpeed != 0 ) { Move( flInterval ); } }
void Civilian::Tick(World & world){ Hittable::Tick(*this, world); Bipedal::Tick(*this, world); switch(state){ case NEW:{ if(FindCurrentPlatform(*this, world)){ state = WALKING; state_i = -1; break; } /*res_bank = 121; res_index = 0; yv += world->gravity; if(yv > world->maxyvelocity){ yv = world->maxyvelocity; } Uint32 xe = x + xv; Uint32 ye = y + yv; Platform * platform = world->map.TestLine(x, y, xe, ye, &xe, &ye, Platform::RECTANGLE | Platform::STAIRSDOWN | Platform::STAIRSDOWN); if(platform){ currentplatformid = platform->id; state = WALKING; state_i = 0; } x = xe; y = ye;*/ }break; case STANDING:{ if(CheckTractVictim(world)){ break; } if(state_i >= 10){ state_i = 0; } res_bank = 121; res_index = state_i; }break; case WALKING:{ if(CheckTractVictim(world)){ break; } if(state_i >= 20){ state_i = 0; } res_bank = 122; res_index = state_i; if(res_index == 5){ EmitSound(world, world.resources.soundbank["stostep1.wav"], 16); } if(res_index == 15){ EmitSound(world, world.resources.soundbank["stostepr.wav"], 16); } if(DistanceToEnd(*this, world) <= world.minwalldistance){ mirrored = mirrored ? false : true; } xv = mirrored ? -speed : speed; FollowGround(*this, world, xv); if(state_i % 5 == 0){ Look(world); } }break; case RUNNING:{ if(CheckTractVictim(world)){ break; } if(state_i >= 150){ state = WALKING; state_i = -1; break; } xv = (mirrored ? -1 : 1) * (5 + speed); res_bank = 123; res_index = state_i % 15; if(res_index == 6){ EmitSound(world, world.resources.soundbank["futstonl.wav"], 16); } if(res_index == 14){ EmitSound(world, world.resources.soundbank["futstonr.wav"], 16); } if(DistanceToEnd(*this, world) <= world.minwalldistance){ mirrored = mirrored ? false : true; } FollowGround(*this, world, xv); if(state_i % 10 == 9){ Look(world); } }break; case DYINGFORWARD:{ tractteamid = 0; if(state_i == 0){ switch(rand() % 3){ case 0: EmitSound(world, world.resources.soundbank["groan2.wav"], 128); break; case 1: EmitSound(world, world.resources.soundbank["groan2a.wav"], 128); break; case 2: EmitSound(world, world.resources.soundbank["grunt2a.wav"], 128); break; } } collidable = false; if(state_i >= 14){ state = DEAD; state_i = -1; break; } FollowGround(*this, world, xv); res_bank = 126; res_index = state_i; }break; case DYINGBACKWARD:{ tractteamid = 0; if(state_i == 0){ switch(rand() % 3){ case 0: EmitSound(world, world.resources.soundbank["groan2.wav"], 128); break; case 1: EmitSound(world, world.resources.soundbank["groan2a.wav"], 128); break; case 2: EmitSound(world, world.resources.soundbank["grunt2a.wav"], 128); break; } } collidable = false; if(state_i >= 14){ state = DEAD; state_i = -1; break; } FollowGround(*this, world, xv); res_bank = 125; res_index = state_i; }break; case DYINGEXPLODE:{ tractteamid = 0; draw = false; state = DEAD; state_i = -1; break; }break; case DEAD:{ collidable = false; if(state_i >= 100){ draw = true; collidable = true; state = WALKING; state_warp = 12; state_i = -1; break; } }break; } state_i++; }
void EBePrivateWin::DispatchMessage(BMessage *bMsg, BHandler *handler) { bool handled = true; if(bMsg->what == 'etk_') { int32 what = 0; bMsg->FindInt32("etk:what", &what); switch(what) { case ETK_BEOS_QUIT: doQuit = true; PostMessage(B_QUIT_REQUESTED); break; case ETK_BEOS_CONTACT_TO: { fContactor = EMessenger(); const char *buffer = NULL; ssize_t size = -1; if(bMsg->FindData("etk:messenger", B_ANY_TYPE, (const void**)&buffer, &size) != B_OK) break; if(buffer == NULL || size <= 0) break; fContactor.Unflatten(buffer, (size_t)size); } break; case ETK_BEOS_SET_BACKGROUND: { rgb_color bkColor; if(bMsg->FindInt32("background", (int32*)&bkColor) != B_OK) break; fTopView->SetViewColor(bkColor); fTopView->Invalidate(); } break; case ETK_BEOS_SET_LOOK: { int8 look; if(bMsg->FindInt8("look", &look) != B_OK) break; switch((e_window_look)look) { case E_BORDERED_WINDOW_LOOK: SetLook(B_BORDERED_WINDOW_LOOK); break; case E_NO_BORDER_WINDOW_LOOK: SetLook(B_NO_BORDER_WINDOW_LOOK); break; case E_TITLED_WINDOW_LOOK: SetLook(B_TITLED_WINDOW_LOOK); break; case E_DOCUMENT_WINDOW_LOOK: SetLook(B_DOCUMENT_WINDOW_LOOK); break; case E_MODAL_WINDOW_LOOK: SetLook(B_MODAL_WINDOW_LOOK); break; case E_FLOATING_WINDOW_LOOK: SetLook(B_FLOATING_WINDOW_LOOK); break; default: break; } } break; case ETK_BEOS_SET_TITLE: { const char *title = NULL; if(bMsg->FindString("title", &title) != B_OK) break; SetTitle(title); } break; case ETK_BEOS_SET_WORKSPACES: { uint32 workspaces = 0; if(bMsg->FindInt32("workspaces", (int32*)&workspaces) != B_OK) break; if(workspaces == 0) workspaces = current_workspace() + 1; SetWorkspaces(workspaces); } break; case ETK_BEOS_GET_WORKSPACES: { uint32 workspaces = Workspaces(); bMsg->AddInt32("workspaces", *((int32*)&workspaces)); } break; case ETK_BEOS_ICONIFY: if(!IsMinimized()) Minimize(true); break; case ETK_BEOS_SHOW: if(IsHidden()) { uint32 oldFlags = Flags(); SetFlags(oldFlags | B_AVOID_FOCUS); Show(); if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags); } break; case ETK_BEOS_HIDE: if(!IsHidden()) Hide(); break; case ETK_BEOS_RAISE: if(!IsFront()) { uint32 oldFlags = Flags(); SetFlags(oldFlags | B_AVOID_FOCUS); Activate(true); if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags); } break; case ETK_BEOS_LOWER: { BHandler *_frontWin = NULL; if(bMsg->FindPointer("front", (void**)&_frontWin) != B_OK) break; BWindow *frontWin = e_cast_as(_frontWin, BWindow); if(frontWin == NULL) break; SendBehind(frontWin); bMsg->AddBool("done", true); } break; case ETK_BEOS_ACTIVATE: { bool state; if(bMsg->FindBool("state", &state) != B_OK || state == IsActive()) break; Activate(state); } break; case ETK_BEOS_GET_ACTIVATED_STATE: bMsg->AddBool("state", IsActive()); break; case ETK_BEOS_MOVE_RESIZE: { if(bMsg->HasPoint("where")) { BPoint pt; if(bMsg->FindPoint("where", &pt) == B_OK) MoveTo(pt); } if(bMsg->HasFloat("width") && bMsg->HasFloat("height")) { float w = -1, h = -1; bMsg->FindFloat("width", &w); bMsg->FindFloat("height", &h); if(w < 0 || h < 0) break; ResizeTo(w, h); } } break; case ETK_BEOS_DRAW_BITMAP: { BBitmap *bitmap = NULL; BRect srcRect, destRect; const ERegion *clipping = NULL; if(bMsg->FindPointer("bitmap", (void**)&bitmap) != B_OK || bitmap == NULL) break; bMsg->FindRect("src", &srcRect); bMsg->FindRect("dest", &destRect); if(srcRect.IsValid() == false || destRect.IsValid() == false) break; bMsg->FindPointer("clipping", (void**)&clipping); BRegion beRegion; __etk_convert_region(clipping, &beRegion, fTopView->Bounds()); fTopView->ConstrainClippingRegion(&beRegion); fTopView->DrawBitmap(bitmap, srcRect, destRect); } break; case ETK_BEOS_GRAB_MOUSE: case ETK_BEOS_UNGRAB_MOUSE: { uint32 options = (what == ETK_BEOS_GRAB_MOUSE ? B_LOCK_WINDOW_FOCUS : 0); if(fTopView->SetEventMask(B_POINTER_EVENTS, options) != B_OK) break; bMsg->AddBool("state", what == ETK_BEOS_GRAB_MOUSE); } break; case ETK_BEOS_GRAB_KEYBOARD: case ETK_BEOS_UNGRAB_KEYBOARD: { uint32 options = (what == ETK_BEOS_GRAB_KEYBOARD ? B_LOCK_WINDOW_FOCUS : 0); if(fTopView->SetEventMask(B_KEYBOARD_EVENTS, options) != B_OK) break; bMsg->AddBool("state", what == ETK_BEOS_GRAB_KEYBOARD); } break; case ETK_BEOS_QUERY_MOUSE: { BPoint pt; uint32 btns = 0; fTopView->GetMouse(&pt, &btns, false); bMsg->AddInt32("x", (int32)pt.x); bMsg->AddInt32("y", (int32)pt.y); bMsg->AddInt32("buttons", (int32)btns); } break; case ETK_BEOS_SET_SIZE_LIMITS: { BRect r; if(bMsg->FindRect("limits", &r) != B_OK) break; SetSizeLimits(r.left, r.right, r.top, r.bottom); bMsg->AddBool("done", true); } break; case ETK_BEOS_GET_SIZE_LIMITS: { BRect r(-1, -1, -1, -1); GetSizeLimits(&(r.left), &(r.right), &(r.top), &(r.bottom)); bMsg->AddRect("limits", r); } break; default: handled = false; break; } if(handled) { BMessage aMsg(*bMsg); bMsg->SendReply(&aMsg); return; } } switch(bMsg->what) { case B_WINDOW_ACTIVATED: { handled = false; if(fContactor.IsValid() == false) break; EMessage message(E_WINDOW_ACTIVATED); message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); fContactor.SendMessage(&message); } break; case B_MOUSE_DOWN: case B_MOUSE_UP: case B_MOUSE_MOVED: { if(fContactor.IsValid() == false) break; BPoint where; int32 buttons = 0; bMsg->FindPoint("where", &where); if(bMsg->what != B_MOUSE_UP) bMsg->FindInt32("buttons", &buttons); int32 clicks = 1; if(bMsg->what == B_MOUSE_DOWN) { #if 0 bMsg->FindInt32("clicks", &clicks); #else bigtime_t eventTime; if(bMsg->FindInt64("when", &eventTime) == B_OK) { if(eventTime - fPrevMouseDownTime <= CLICK_TIMEOUT) clicks = (fPrevMouseDownCount += 1); else clicks = fPrevMouseDownCount = 1; fPrevMouseDownTime = eventTime; } #endif } EMessage message; if(bMsg->what == B_MOUSE_DOWN) message.what = E_MOUSE_DOWN; else if(bMsg->what == B_MOUSE_UP) message.what = E_MOUSE_UP; else message.what = E_MOUSE_MOVED; message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); if(bMsg->what != B_MOUSE_UP) message.AddInt32("buttons", buttons); if(bMsg->what == B_MOUSE_DOWN) message.AddInt32("clicks", clicks); message.AddPoint("where", EPoint(where.x, where.y)); ConvertToScreen(&where); message.AddPoint("screen_where", EPoint(where.x, where.y)); // TODO: modifiers message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; case B_KEY_DOWN: case B_KEY_UP: case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_UP: { if(fContactor.IsValid() == false) break; int8 byte[4]; const char *bytes = NULL; int32 numBytes = 0; int32 key = 0; int32 key_repeat = 0; int32 beModifiers = 0; eint32 modifiers = 0; bMsg->FindInt32("key", &key); bMsg->FindInt32("modifiers", &beModifiers); bzero(byte, sizeof(int8) * 4); if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP) { for(int32 i = 0; i < 3; i++) bMsg->FindInt8("byte", i, &byte[i]); if(bMsg->FindString("bytes", &bytes) == B_OK) numBytes = strlen(bytes); // if(bMsg->what == B_KEY_DOWN) bMsg->FindInt32("be:key_repeat", &key_repeat); } else { etk_beos_get_byte(beModifiers, key, (char*)byte); } if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY; if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY; if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY; EMessage message; if(bMsg->what == B_KEY_DOWN) message.what = E_KEY_DOWN; else if(bMsg->what == B_KEY_UP) message.what = E_KEY_UP; else if(bMsg->what == B_UNMAPPED_KEY_DOWN) message.what = E_UNMAPPED_KEY_DOWN; else message.what = E_UNMAPPED_KEY_UP; message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); message.AddInt32("key", key); message.AddInt32("modifiers", modifiers); if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP) { if(bMsg->what == B_KEY_DOWN) message.AddInt32("etk:key_repeat", key_repeat); for(int32 i = 0; i < 3; i++) message.AddInt8("byte", byte[i]); if(!(numBytes != 1 || *bytes != byte[0])) { etk_beos_get_byte(beModifiers, key, (char*)byte); message.AddString("bytes", (char*)byte); } else if(numBytes > 0) { message.AddString("bytes", bytes); } } else if(byte[0] != 0) { message.AddInt8("byte", byte[0]); message.AddString("bytes", (char*)byte); } message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; case B_MODIFIERS_CHANGED: { if(fContactor.IsValid() == false) break; eint32 modifiers = 0; eint32 old_modifiers = 0; int32 beModifiers = 0; int32 old_beModifiers = 0; bMsg->FindInt32("modifiers", &beModifiers); bMsg->FindInt32("be:old_modifiers", &old_beModifiers); if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY; if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY; if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY; if(old_beModifiers & B_SHIFT_KEY) old_modifiers |= E_SHIFT_KEY; if(old_beModifiers & B_CONTROL_KEY) old_modifiers |= E_CONTROL_KEY; if(old_beModifiers & B_COMMAND_KEY) old_modifiers |= E_COMMAND_KEY; EMessage message(E_MODIFIERS_CHANGED); message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); message.AddInt32("modifiers", modifiers); message.AddInt32("etk:old_modifiers", old_modifiers); message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; default: handled = false; break; } if(!handled) BWindow::DispatchMessage(bMsg, handler); }
void MacDecorator::_DoLayout() { const int32 kDefaultBorderWidth = 6; STRACE(("MacDecorator: Do Layout\n")); // Here we determine the size of every rectangle that we use // internally when we are given the size of the client rectangle. bool hasTab = false; switch (Look()) { case B_MODAL_WINDOW_LOOK: fBorderWidth = kDefaultBorderWidth; break; case B_TITLED_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK: hasTab = true; fBorderWidth = kDefaultBorderWidth; break; case B_FLOATING_WINDOW_LOOK: hasTab = true; fBorderWidth = 3; break; case B_BORDERED_WINDOW_LOOK: fBorderWidth = 1; break; default: fBorderWidth = 0; } fBorderRect=fFrame; fBorderRect.InsetBy(-fBorderWidth, -fBorderWidth); // calculate our tab rect if (hasTab) { fBorderRect.top +=3; font_height fontHeight; fDrawState.Font().GetHeight(fontHeight); // TODO the tab is drawn in a fixed height for now fTabRect.Set(fFrame.left - fBorderWidth, fFrame.top - 23, ((fFrame.right - fFrame.left) < 32.0 ? fFrame.left + 32.0 : fFrame.right) + fBorderWidth, fFrame.top - 3); fZoomRect=fTabRect; fZoomRect.left=fZoomRect.right-12; fZoomRect.bottom=fZoomRect.top+12; fZoomRect.OffsetBy(-4,4); fCloseRect=fZoomRect; fMinimizeRect=fZoomRect; fCloseRect.OffsetTo(fTabRect.left+4,fTabRect.top+4); fZoomRect.OffsetBy(0-(fZoomRect.Width()+4),0); if (Title() && fDrawingEngine) { titlepixelwidth=fDrawingEngine->StringWidth(Title(),strlen(Title())); if (titlepixelwidth<(fZoomRect.left-fCloseRect.right-10)) { // start with offset from closerect.right textoffset=int(((fZoomRect.left-5)-(fCloseRect.right+5))/2); textoffset-=int(titlepixelwidth/2); // now make it the offset from fTabRect.left textoffset+=int(fCloseRect.right+5-fTabRect.left); } else textoffset=int(fCloseRect.right)+5; } else { textoffset=0; titlepixelwidth=0; } } else { // no tab fTabRect.Set(0.0, 0.0, -1.0, -1.0); fCloseRect.Set(0.0, 0.0, -1.0, -1.0); fZoomRect.Set(0.0, 0.0, -1.0, -1.0); fMinimizeRect.Set(0.0, 0.0, -1.0, -1.0); } }
void ff(TextureCompressDXT,format,coding,fiting)(RESOURCEINFO &texo, RESOURCEINFO &texd, ULONG *texs, ULONG *texr, int level, int l, int blocksize, int flags) { /* square dimension of this surface-level */ /* square area of this surface-level */ const int lv = (1 << l); const int av = lv * lv; /* ------------------------------------------------------------------------------------------------------- */ const int NORMALS_SCALEBYLEVEL = ::NORMALS_SCALEBYLEVEL; const int ALPHAS_SCALEBYLEVEL = ::ALPHAS_SCALEBYLEVEL; const float colorgamma = ::colorgamma; const float alphacontrast = ::alphacontrast; const float colorgammainv = ::colorgammainv; const float alphacontrastinv = ::alphacontrastinv; int iwidth = texo.Width; int iheight = texo.Height; int owidth = texd.Width; int oheight = texd.Height; int cwidth = owidth; int cheight = oheight; /* get the data back to the CPU */ cheight = (cheight + 3) / 4; /* 4x4 LONG ... */ cwidth = (cwidth + 3) / 4; /* 4x4 LONG ... */ cwidth *= 2 * blocksize; /* ... to 2x|4x LONG */ /* ensure tile ability (bit on overhead for non-4 resolutions) */ owidth = (owidth + (TX - 1)) & (~(TX - 1)); oheight = (oheight + (TY - 1)) & (~(TY - 1)); assert((owidth & (TX - 1)) == 0); assert((oheight & (TY - 1)) == 0); #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) /* constant buffer array */ Concurrency::array_view<const SingleColourLookup_CCR, 2> lArr(2, 256, (const SingleColourLookup_CCR *)::lookup_34_56_ccr); Concurrency::array_view<const IndexBlockLookup_CCR, 2> yArr(4, 8, (const IndexBlockLookup_CCR *)::lookup_c34a57_ccr); /* get a two-dimensional extend over the whole output (without re-cast to LONG), * then get a tile-extend over that one () */ Concurrency::extent<2> ee(oheight, owidth); Concurrency::tiled_extent<TY, TX> te(ee); Concurrency::array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); Concurrency::array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr); Concurrency::parallel_for_each(te /*dArr.extent.tile<TY, TX>(osize)*/, [=](tiled_index<TY, TX> elm) restrict(amp) { typedef type accu[DIM]; /* tile static memory */ // tile_static UTYPE bTex[2][TY*TX]; tile_static type fTex[2][TY*TX][DIM]; tile_static int iTex[2][TY*TX][DIM]; /* generate this level's 4x4-block from the original surface */ // const int y = elm.global[0] - ly; // const int x = elm.global[1] - lx; const int y = elm.tile[0] * TY; const int x = elm.tile[1] * TX; const int ly = elm.local[0]; const int lx = elm.local[1]; const int lxy = ly * TX + lx; #else Concurrency::array_view<const SingleColourLookup_CCR, 2> lArr(2, 256, (const SingleColourLookup_CCR *)::lookup_34_56_ccr); Concurrency::array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); Concurrency::array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr, true); for (int groupsy = 0; groupsy < (owidth / TY); groupsy++) for (int groupsx = 0; groupsx < (oheight / TX); groupsx++) { typedef type accu[DIM]; /* tile static memory */ // UTYPE bTex[2][TY*TX]; type fTex[2][TY*TX][DIM]; int iTex[2][TY*TX][DIM]; for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy * TY; const int x = groupsx * TX; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #endif { const int yl = ((y + ly) << l); const int xl = ((x + lx) << l); accu tt = {0}; /* access all pixels this level's 4x4-block represents in * the full dimension original surface (high quality mip-mapping) */ for (int oy = 0; oy < lv; oy += 1) { for (int ox = 0; ox < lv; ox += 1) { /* assume seamless tiling: wrap pixels around */ const int posx = (xl + ox) % iwidth; const int posy = (yl + oy) % iheight; const ULONG &t = sArr(posy, posx); Accu(tt, t); // += } } /* build average of each channel */ Norm(fTex[0][lxy], tt, av, level, l); } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static accu tr; tr[lxy & 7] = 0; tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else } accu tr = {0}; #endif /* runs on only 1 thread per tile (reduction) */ #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) if (elm.local == index<2>(0, 0)) #endif { /* analyze this level's 4x4-block */ for (int lxy = 0; lxy < TY*TX; lxy += 1) { Look(fTex[0][lxy], tr); } } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy; const int x = groupsx; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #endif /* generate this level's 4x4-block from the original surface */ { /* build average of each channel an join */ Code (fTex[0][lxy], tr, (TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS (format) ? 2 : 0)) == 2 ? 8 : (TCOMPRESS_SWIZZL (format) ? 6 : 5)); Range(iTex[0][lxy], fTex[0][lxy]); #if (TCOMPRESS_SWIZZL(format)) /* swizzle ABGR -> AGBR */ { int swap = iTex[0][lxy][1]; iTex[0][lxy][1] = iTex[0][lxy][2]; iTex[0][lxy][2] = swap ; } #endif /* write the result */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 4) /* ABGR -> RGBA */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 3) /* -BGR -> RGB- */ iTex[0][lxy][0] = 0xFF; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 2) /* --YX -> XY-- */ /* AL-- -> LA-- */ #if (format == TCOMPRESS_XYz) iTex[0][lxy][0] = iTex[0][lxy][2], // Y iTex[1][lxy][0] = iTex[0][lxy][3]; // X #else iTex[0][lxy][0] = iTex[0][lxy][0], // A iTex[1][lxy][0] = iTex[0][lxy][1]; // Z #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 1) /* -Z-- -> Z--- */ /* A--- -> A--- */ /* -LLL -> L--- */ #if (format == TCOMPRESS_a ) iTex[0][lxy][0] = iTex[0][lxy][0]; // A #elif (format == TCOMPRESS_A ) iTex[0][lxy][0] = iTex[0][lxy][0]; // A #elif (format == TCOMPRESS_xyZ) iTex[0][lxy][0] = iTex[0][lxy][1]; // Z #else iTex[0][lxy][0] = iTex[0][lxy][3]; // X #endif #else #error #endif } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #define local_is(a,b) elm.local == index<2>(a, b) #else } for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy; const int x = groupsx; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #define local_is(a,b) ((ly == a) && (lx == b)) #endif /* put this level's 4x4-block into the destination surface */ { /* round down */ int posx = (x + lx) >> 2; int posy = (y + ly) >> 2; /* first and second block */ unsigned int b[2][2]; /* compress to DXT1/DXT3/DXT5/ATI1/ATI2 */ #define sflgs TCOMPRESS_COLOR(format) ? SQUISH_METRIC_PERCEPTUAL : SQUISH_METRIC_UNIFORM, \ TCOMPRESS_TRANS(format), \ fiting /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 4) || \ ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 3) /* 1x LONG per block for DXT1, 2x for the others */ #if (coding == 1) { posx <<= 0; squish::CompressColorBtc1(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[1][0]; dArr(posy, posx + 1) = b[1][1]; } #elif (coding == 2) { posx <<= 1; squish::CompressAlphaBtc2(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressColorBtc2(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #elif (coding == 3) { posx <<= 1; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressColorBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #else #error #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 1) /* 1x LONG for ATI1 */ #if (coding == 4) { posx <<= 0; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; } #else #error #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 2) /* 2x LONG for ATI2 */ #if (coding == 5) { posx <<= 1; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[1], 0xFFFF, b[1] , yArr ); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #else #error #endif #else #error #endif #undef sflgs // elm.barrier.wait(); /* advance pointer of compressed blocks */ // wTex += blocksize; // dTex += blocksize; } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) // elm.barrier.wait(); // dTex += 0; }); dArr.synchronize(); #else }}
void WorkspacesWindow::MessageReceived(BMessage *message) { switch (message->what) { case B_SIMPLE_DATA: { // Drop from Tracker entry_ref ref; for (int i = 0; (message->FindRef("refs", i, &ref) == B_OK); i++) be_roster->Launch(&ref); break; } case B_ABOUT_REQUESTED: PostMessage(message, ChildAt(0)); break; case kMsgToggleBorder: { bool enable = false; if (Look() == B_NO_BORDER_WINDOW_LOOK) enable = true; if (enable) if (fSettings->HasTitle()) SetLook(B_TITLED_WINDOW_LOOK); else SetLook(B_MODAL_WINDOW_LOOK); else SetLook(B_NO_BORDER_WINDOW_LOOK); fSettings->SetHasBorder(enable); break; } case kMsgToggleTitle: { bool enable = false; if (Look() == B_MODAL_WINDOW_LOOK || Look() == B_NO_BORDER_WINDOW_LOOK) enable = true; if (enable) SetLook(B_TITLED_WINDOW_LOOK); else SetLook(B_MODAL_WINDOW_LOOK); // No matter what the setting for title, we must force the border on fSettings->SetHasBorder(true); fSettings->SetHasTitle(enable); break; } case kMsgToggleAutoRaise: SetAutoRaise(!IsAutoRaising()); SetFeel(B_NORMAL_WINDOW_FEEL); break; case kMsgToggleAlwaysOnTop: { bool enable = false; if (Feel() != B_FLOATING_ALL_WINDOW_FEEL) enable = true; if (enable) SetFeel(B_FLOATING_ALL_WINDOW_FEEL); else SetFeel(B_NORMAL_WINDOW_FEEL); fSettings->SetAlwaysOnTop(enable); break; } default: BWindow::MessageReceived(message); break; } }
int main() { char phonenumber[15]; int input; char name[15]; char custom1[3][2][30] = { 0, }; int dev = 0; int count = 0; char tmp[30] = { 0, }; int k; int i, j; while (1) { printf("[[ ADVANCED PHONEBOOK ]]\n"); printf("----------\n"); //MENU printf("| 0:추가\n"); printf("| 1:제거\n"); printf("| 2:보기\n"); printf("| 3:종료\n"); printf("| 4:검색\n"); printf("| 5:즐겨찾기 추가\n"); printf("| 6:즐겨찾기 보기\n"); printf("선택 :"); scanf("%d", &input); if (input == 0) { for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < 30; k++) { custom1[i][j][k] = 0; } } } system("cls"); printf("이름 : "); scanf("%s", name); printf("전화번호 :"); scanf("%s", phonenumber); printf("추가할 데이터가 있나요? Y:1/N:0.."); scanf("%d", &dev); if (dev) { printf("추가데이터 이름 : "); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][0][k] = tmp[k]; tmp[k] = 0; } printf("추가할 데이터 :"); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][1][k] = tmp[k]; tmp[k] = 0; } printf("\n추가할 데이터가 있나요? Y:1/N:0.."); scanf(" %d", &dev); if (dev) { count++; printf("추가데이터 이름 : "); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][0][k] = tmp[k]; tmp[k] = 0; } printf("추가할 데이터 :"); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][1][k] = tmp[k]; tmp[k] = 0; } printf("\n추가할 데이터가 있나요? Y:1/N:0.."); scanf(" %d", &dev); if (dev) { count++; printf("추가데이터 이름 : "); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][0][k] = tmp[k]; tmp[k] = 0; } printf("추가할 데이터 :"); scanf("%s", tmp); for (k = 0; k < 30; k++) { custom1[count][1][k] = tmp[k]; tmp[k] = 0; } Node * New; New = (Node*)malloc(sizeof(Node)); int i, j, k; strcpy(New->NameData, name); strcpy(New->PhonenumberData, phonenumber); New->favorite = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < 30; k++) { New->custom1Data[i][j][k] = custom1[i][j][k]; } } } New->next = NULL; if (head == NULL) { head = New; Last = New; } else { Last->next = New; Last = New; } printf("데이터가 모두 추가되었습니다.\n "); } else { Node * New; New = (Node*)malloc(sizeof(Node)); int i, j, k; strcpy(New->NameData, name); strcpy(New->PhonenumberData, phonenumber); New->favorite = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < 30; k++) { New->custom1Data[i][j][k] = custom1[i][j][k]; } } } New->next = NULL; if (head == NULL) { head = New; Last = New; } else { Last->next = New; Last = New; } printf("데이터가 모두 추가되었습니다.\n "); } } else { Node * New; New = (Node*)malloc(sizeof(Node)); int i, j, k; strcpy(New->NameData, name); strcpy(New->PhonenumberData, phonenumber); New->favorite = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < 30; k++) { New->custom1Data[i][j][k] = custom1[i][j][k]; } } } New->next = NULL; if (head == NULL) { head = New; Last = New; } else { Last->next = New; Last = New; } printf("데이터가 모두 추가되었습니다.\n "); } } else { Node * New; New = (Node*)malloc(sizeof(Node)); int i, j, k; strcpy(New->NameData, name); strcpy(New->PhonenumberData, phonenumber); New->favorite = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < 30; k++) { New->custom1Data[i][j][k] = custom1[i][j][k]; } } } New->next = NULL; if (head == NULL) { head = New; Last = New; } else { Last->next = New; Last = New; } printf("데이터가 모두 추가되었습니다.\n "); } } else if (input == 1) { system("cls"); printf("삭제할 전화번호 :"); scanf("%s", phonenumber); Delete(phonenumber); } else if (input == 2) { system("cls"); Look(); } else if (input == 3) { system("cls"); printf("프로그램 종료\n"); break; } else if (input == 4) { system("cls"); printf("이름을 입력해주세요:"); scanf("%s", name); Search(name); } else if (input == 5) { system("cls"); printf("즐겨 찾기에 추가할 이름을 입력해주세요:"); scanf("%s", name); SearchF(name); } else if (input == 6) { system("cls"); int i, j; Node*temp = head; if (head == NULL) { printf("보여줄 데이터가 없습니다.\n"); return 0; } if (temp->favorite == 1) { while (1) { printf("------------------------------------\n"); printf("l이름 :%s 전화번호:%s\n", temp->NameData, temp->PhonenumberData); for (i = 0; i < 3; i++) { printf("%d번째 사용자 데이터 \n", i + 1); if (temp->custom1Data == 0) { printf("데이터 없음"); } else { for (j = 0; j < 2; j++) { if (temp->custom1Data[i][j] != 0) printf("%s", temp->custom1Data[i][j]); else if (temp->custom1Data[i][j][k] == 0) { printf("데이터 없음"); } printf("\n"); } } printf("\n"); } printf("....................................\n"); temp = temp->next; if (temp == NULL) break; else printf("\n"); } } } else printf("0,1,2,3,4,5 중에서 입력해주세요.\n"); } }
void ff(TextureQuantizeRAW,format,A)(RESOURCEINFO &texo, RESOURCEINFO &texd, ULONG *texs, ULONG *texr, int level, int l) { /* square dimension of this surface-level */ /* square area of this surface-level */ const int lv = (1 << l); const int av = lv * lv; /* ------------------------------------------------------------------------------------------------------- */ const int NORMALS_SCALEBYLEVEL = ::NORMALS_SCALEBYLEVEL; const int ALPHAS_SCALEBYLEVEL = ::ALPHAS_SCALEBYLEVEL; const float colorgamma = ::colorgamma; const float alphacontrast = ::alphacontrast; const float colorgammainv = ::colorgammainv; const float alphacontrastinv = ::alphacontrastinv; int iwidth = texo.Width; int iheight = texo.Height; int owidth = texd.Width; int oheight = texd.Height; int cwidth = owidth; int cheight = oheight; /* get the data back to the CPU */ #if (TCOMPRESS_CHANNELS(format) == 4) /* ABGR -> ARGB */ cwidth = (cwidth + 0) >> 0; /* 1x LONG to 1x LONG */ #elif (TCOMPRESS_CHANNELS(format) == 3) /* -BGR -> -RGB */ cwidth = (cwidth + 1) >> 1; /* 1x LONG to 1x SHORT */ #elif (TCOMPRESS_CHANNELS(format) == 2) /* LA-- -> AL-- */ cwidth = (cwidth + 3) >> 2; /* 1x LONG to 1x CHAR */ #elif (TCOMPRESS_CHANNELS(format) == 1) /* A--- -> A--- */ cwidth = (cwidth + 31) >> 5; /* 8x LONG to 1x CHAR */ #else #error #endif /* ensure tile ability (bit on overhead for non-4 resolutions) */ owidth = (owidth + (TX - 1)) & (~(TX - 1)); oheight = (oheight + (TY - 1)) & (~(TY - 1)); assert((owidth & (TX - 1)) == 0); assert((oheight & (TY - 1)) == 0); #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) /* get a two-dimensional extend over the whole output (without re-cast to LONG), * then get a tile-extend over that one () */ Concurrency::extent<2> ee(oheight, owidth); Concurrency::tiled_extent<TY, TX> te(ee); Concurrency::array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); Concurrency::array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr); Concurrency::parallel_for_each(te /*dArr.extent.tile<TY, TX>(osize)*/, [=](tiled_index<TY, TX> elm) restrict(amp) { typedef type accu[DIM]; /* tile static memory */ // tile_static UTYPE bTex[2][TY][TX]; tile_static int bTex[2][TY][TX]; tile_static type fTex[2][TY][TX][DIM]; // const int y = elm.global[0] - ly; // const int x = elm.global[1] - lx; const int y = elm.tile[0] * TY; const int x = elm.tile[1] * TX; const int ly = elm.local[0]; const int lx = elm.local[1]; #else array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr, true); for (int groupsy = 0; groupsy < (owidth / TY); groupsy++) for (int groupsx = 0; groupsx < (oheight / TX); groupsx++) { typedef type accu[DIM]; /* tile static memory */ // UTYPE bTex[2][TY][TX]; int bTex[2][TY][TX]; type fTex[2][TY][TX][DIM]; for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy * TY; const int x = groupsx * TX; const int ly = tiley; const int lx = tilex; #endif /* generate this level's 4x4-block from the original surface */ { const int yl = ((y + ly) << l); const int xl = ((x + lx) << l); accu tt; tt[0] = tt[1] = tt[2] = tt[3] = tt[4] = tt[5] = tt[6] = tt[7] = 0; /* access all pixels this level's 4x4-block represents in * the full dimension original surface (high quality mip-mapping) */ for (int oy = 0; oy < lv; oy += 1) for (int ox = 0; ox < lv; ox += 1) { /* assume seamless tiling: wrap pixels around */ const int posx = (xl + ox) % iwidth; const int posy = (yl + oy) % iheight; const ULONG &t = sArr(posy, posx); Accu(tt, t); // += } /* build average of each channel */ Norm(fTex[0][ly][lx], tt, av, level, l); } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static accu tr; tr[(ly * TX + lx) & 7] = 0; tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else } accu tr = {0}; #endif /* runs on only 1 thread per tile (reduction) */ #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) if (elm.local == index<2>(0, 0)) #endif { /* analyze this level's 4x4-block */ for (int ly = 0; ly < TY; ly += 1) for (int lx = 0; lx < TX; lx += 1) { Look(fTex[0][ly][lx], tr); } } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy; const int x = groupsx; const int ly = tiley; const int lx = tilex; #endif /* generate this level's 4x4-block from the original surface */ { /* build average of each channel an join */ ULONG t; Code(fTex[0][ly][lx], tr, (A > 2 ? 4 : (A > 1 ? 10 : (A > 0 ? 5 : 6)))); t = Qunt(fTex[0][ly][lx], tr, (A > 2 ? 4 : (A > 1 ? 10 : (A > 0 ? 5 : 6)))); /* write the result */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if (TCOMPRESS_CHANNELS(format) == 4) /* ABGR -> RGBA */ bTex[0][ly][lx] = t; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif (TCOMPRESS_CHANNELS(format) == 3) /* -BGR -> RGB- */ bTex[0][ly][lx] = t; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif (TCOMPRESS_CHANNELS(format) == 2) /* AL-- -> LA-- */ bTex[0][ly][lx] = t; #else #error #endif } /* put this level's 4x4-block into the destination surface */ { /* assume seamless tiling: wrap pixels around */ const int posx = (x + lx) % owidth; const int posy = (y + ly) % oheight; /* convert unaligned output location to "int"-space output location */ const int linear = ((posy * owidth) + posx) * 1; const int lposx = (linear << 0) % (cwidth << 0); const int lposy = (linear << 0) / (cwidth << 0); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if (TCOMPRESS_CHANNELS(format) <= 4) /* ABGR -> ARGB */ if (sizeof(UTYPE) == 4) { /* every single thread */ { int t0 = bTex[0][ly][lx + 0]; /* write combining */ unsigned int val = (ULONG)t0; /* write out all of an "int" */ dArr(lposy, lposx) = val; } } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif (TCOMPRESS_CHANNELS(format) <= 3) /* -BGR -> -RGB */ if (sizeof(UTYPE) == 2) { /* every second thread */ if (!(elm.local[1] & 1)) { int t0 = bTex[0][ly][lx + 0]; int t1 = bTex[0][ly][lx + 1]; /* write combining */ unsigned int val = (ULONG)((t1 << 16) + (t0 << 0)); /* write out all of an "int" */ dArr(lposy, lposx) = val; } } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif (TCOMPRESS_CHANNELS(format) <= 2) /* --YX -> XY-- */ /* LA-- -> AL-- */ if (sizeof(UTYPE) == 1) { /* every fourth thread */ if (!(elm.local[1] & 3)) { int t0 = bTex[0][ly][lx + 0]; int t1 = bTex[0][ly][lx + 1]; int t2 = bTex[0][ly][lx + 2]; int t3 = bTex[0][ly][lx + 3]; /* write combining */ unsigned int val = (ULONG)((t3 << 24) + (t2 << 16) + (t1 << 8) + (t0 << 0)); /* write out all of an "int" */ dArr(lposy, lposx) = val; } } #else #error #endif } // dTex += 0; #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) }); dArr.synchronize(); #else }}
UserAction Controls::checkUserInput(Player *pPlayer) { enum UserAction action; int num_keys; Uint8 *key_states = SDL_GetKeyState(&num_keys); SDL_PumpEvents(); int ls = 0; if (key_states) { switch (ls) { case 0: { // Do not allow keyboard viewpoint control if currently scrolling via drag zones if ( !pPlayer->crosshairsInDragzone() ) { float dragAngle = pPlayer->perFrameDragAngle(); if ( key_states[SDLK_UP] ) pPlayer->RotateViewAboutHorizontal(dragAngle); if ( key_states[SDLK_DOWN] ) pPlayer->RotateViewAboutHorizontal(-dragAngle); if ( key_states[SDLK_LEFT] ) pPlayer->RotateViewAboutVertical(-dragAngle); if ( key_states[SDLK_RIGHT] ) pPlayer->RotateViewAboutVertical(dragAngle); } } break; default: printf("error: incorrect level status in Controls, %d\n",ls); exit(1); break; } } action = NOACTION; while ( SDL_PollEvent (&event) ) { switch (event.type) { case SDL_MOUSEMOTION: Look(pPlayer); break; case SDL_MOUSEBUTTONDOWN: //leftbutton = DOWN; break; case SDL_MOUSEBUTTONUP: //leftbutton = UP; break; case SDL_KEYDOWN: if ( pPlayer->theConsole.IsOpen() ) { printf("console is open\n"); //pass all key strokes to the console pPlayer->theConsole.KeyboardFunc( event.key.keysym.sym ); } /* if ( event.key.keysym.sym>=SDLK_a && event.key.keysym.sym<=SDLK_z ) { } */ else { switch( event.key.keysym.sym ) { case SDLK_ESCAPE: action = PAUSE; break; case SDLK_c: pPlayer->theConsole.ToggleConsole(); break; case SDLK_a: action = ABSORB; break; case SDLK_r: action = CREATE_SYNTHOID_SHELL; break; case SDLK_q: action = TRANSFER_TO_SYNTHOID; break; case SDLK_t: action = CREATE_TREE; break; case SDLK_b: action = CREATE_BOULDER; break; case SDLK_h: action = HYPERSPACE; break; default: break; } } default: break; } } return action; }
void glk_main(void) { FILE *f; int vb,no; Bottom = glk_window_open(0, 0, 0, wintype_TextBuffer, 1); if(Bottom == NULL) glk_exit(); glk_set_window(Bottom); if(game_file == NULL) Fatal("No game provided"); f = fopen(game_file, "r"); if(f==NULL) Fatal("Cannot open game"); if (Options & TRS80_STYLE) { Width = 64; TopHeight = 11; } else { Width = 80; TopHeight = 10; } if(split_screen) { Top = glk_window_open(Bottom, winmethod_Above | winmethod_Fixed, TopHeight, wintype_TextGrid, 0); if(Top == NULL) { split_screen = 0; Top = Bottom; } } else { Top = Bottom; } Output("\ Scott Free, A Scott Adams game driver in C.\n\ Release 1.14, (c) 1993,1994,1995 Swansea University Computer Society.\n\ Distributed under the GNU software license\n\n"); LoadDatabase(f,(Options&DEBUGGING)?1:0); fclose(f); srand(time(NULL)); while(1) { glk_tick(); PerformActions(0,0); Look(); if(GetInput(&vb,&no) == -1) continue; switch(PerformActions(vb,no)) { case -1:Output("I don't understand your command. "); break; case -2:Output("I can't do that yet. "); break; } /* Brian Howarth games seem to use -1 for forever */ if(Items[LIGHT_SOURCE].Location/*==-1*/!=DESTROYED && GameHeader.LightTime!= -1) { GameHeader.LightTime--; if(GameHeader.LightTime<1) { BitFlags|=(1<<LIGHTOUTBIT); if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) Output("Light has run out! "); else Output("Your light has run out. "); } if(Options&PREHISTORIC_LAMP) Items[LIGHT_SOURCE].Location=DESTROYED; } else if(GameHeader.LightTime<25) { if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) { Output("Light runs out in "); OutputNumber(GameHeader.LightTime); Output(" turns. "); } else { if(GameHeader.LightTime%5==0) Output("Your light is growing dim. "); } } } } } }
static bool TextureCompressQDM(LPDIRECT3DTEXTURE *base, LPDIRECT3DTEXTURE *norm, int minlevel) { LPDIRECT3DTEXTURE baset; LPDIRECT3DTEXTURE normt; RESOURCEINFO based, baseo; RESOURCEINFO normd, normo; TextureInfoLevel(*base, baseo, 0); TextureInfoLevel(*norm, normo, 0); #if 0 /* Converts a height map into a normal map. The (x,y,z) * components of each normal are mapped to the (r,g,b) * channels of the output texture. */ HRESULT D3DXComputeNormalMap( __out LPDIRECT3DTEXTURE pTexture, __in LPDIRECT3DTEXTURE pSrcTexture, __in const PALETTEENTRY *pSrcPalette, __in DWORD Flags, __in DWORD Channel, __in FLOAT Amplitude ); #endif /* they have to have the same dimension */ if ((baseo.Width != normo.Width ) || (baseo.Height != normo.Height)) return false; /* convert to ARGB8 (TODO: support at least the 16bit formats as well) */ if ((baseo.Format != TEXFMT_A8B8G8R8) && baseo.Format = TEXFMT_A8R8G8B8, !TextureConvert(baseo, base, false)) return false; if ((normo.Format != TEXFMT_A8B8G8R8) && normo.Format = TEXFMT_A8R8G8B8, !TextureConvert(normo, norm, true)) return false; /* create the textures */ int levels = TextureCalcMip(baseo.Width, baseo.Height, minlevel); int flags = squish::kColourIterativeClusterFit | squish::kBtc3; #ifdef DX11 ULONG *bases; ULONG *norms; DWORD basel = 1; DWORD norml = 1; DWORD level = max(basel, norml); #else /* create the textures */ pD3DDevice->CreateTexture(baseo.Width, baseo.Height, levels, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &baset, NULL); pD3DDevice->CreateTexture(normo.Width, normo.Height, levels, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &normt, NULL); /* damit */ if (!baset || !normt) { if (baset) baset->Release(); if (normt) normt->Release(); return false; } ULONG bPch, *bases = TextureLock(*base, &bPch, 0); ULONG nPch, *norms = TextureLock(*norm, &nPch, 0); DWORD basel = baset->GetLevelCount(); DWORD norml = normt->GetLevelCount(); DWORD level = max(basel, norml); #endif for (unsigned int l = 0; l < level; l++) { /* square dimension of this surface-level */ /* square area of this surface-level */ int lv = (1 << l); int av = lv * lv; TextureInfoLevel(baset, based, l); TextureInfoLevel(normt, normd, l); ULONG sPch, *baser = TextureLock(baset, l, &sPch, true); ULONG nPch, *normr = TextureLock(normt, l, &nPch, true); ULONG *sBase = (ULONG *)bases; ULONG *sNorm = (ULONG *)norms; ULONG *dBase = (ULONG *)baser; ULONG *dNorm = (ULONG *)normr; /* loop over 4x4-blocks of this level (DXT5) */ for (unsigned int y = 0; y < based.Height; y += TY) { if (!(y & 0x3F)) { // logrf("line processed %d/%d of level %d/%d\r", y, based.Height, l, level); // PollProgress(); } for (unsigned int x = 0; x < based.Width; x += TX) { UTYPE bBase[2][TY][TX]; ULONG bNorm[2][TY][TX]; type fBase[2][TY][TX][DIM]; float fNorm[2][TY][TX][DIM]; /* generate this level's 4x4-block from the original surface */ for (int ly = 0; ly < TY; ly += 1) for (int lx = 0; lx < TX; lx += 1) { type bs[DIM] = {0}; int yl = ((y + ly) << l); /*ng ns[DIM] = {0*/ int xl = ((x + lx) << l); float nn[DIM] = {0.0f}; /* access all pixels this level's 4x4-block represents in * the full dimension original surface (high quality mip-mapping) */ for (int oy = 0; oy < lv; oy += 1) for (int ox = 0; ox < lv; ox += 1) { /* assume seamless tiling: wrap pixels around */ int posx = (xl + ox) % baseo.Width; int posy = (yl + oy) % baseo.Height; ULONG &b = sBase[(posy * sPch) + posx]; ULONG &n = sNorm[(posy * nPch) + posx]; /* transfer heightmap into the normal-map (overwrite) */ if (LODed) n = (n & 0x00FFFFFF) + (b & 0xFF000000); { static const f<TCOMPRESS_RGBH> fmt; Accu(bs, b); } { static const f<TCOMPRESS_XYZD> fmt; Accu(nn, n); } // AccuRGBM<ACCUMODE_LINEAR>(bs, b, level, l, colorgamma); // += and max #if defined(NORMALS_INTEGER) // AccuXYZD<ACCUMODE_SCALE >(ns, n, level, l, NORMALS_SCALEBYLEVEL); // += #else // AccuXYZD<ACCUMODE_SCALE >(nn, n, level, l, NORMALS_SCALEBYLEVEL); // += #endif } /* build average of each channel */ { const int format = TCOMPRESS_RGBH; Norm(fBase[0][ly][lx], bs, av, levels, l); } { const int format = TCOMPRESS_XYZD; Norm(fNorm[0][ly][lx], nn, av, levels, l); } // NormRGBM<TRGTMODE_CODING_RGB >(fBase[0][ly][lx], bs, av, colorgammainv); #if defined(NORMALS_INTEGER) // NormXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], ns, av); #else // NormXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], nn, av); #endif } type br[DIM] = {0}; /*ng nr[DIM] = {0*/ float rn[DIM] = {0.0f}; /* analyze this level's 4x4-block */ for (int ly = 0; ly < TY; ly += 1) for (int lx = 0; lx < TX; lx += 1) { { const int format = TCOMPRESS_RGBH; Look(fBase[0][ly][lx], br); } { const int format = TCOMPRESS_XYZD; Look(fNorm[0][ly][lx], rn); } // LookRGBH<TRGTMODE_CODING_RGB >(fBase[0][ly][lx], br); #if defined(NORMALS_INTEGER) // LookXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], nr); #else // LookXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], rn); #endif } /* generate this level's 4x4-block from the original surface */ for (int ly = 0; ly < TY; ly += 1) for (int lx = 0; lx < TX; lx += 1) { /* build average of each channel an join */ UTYPE b; ULONG n; { const int format = TCOMPRESS_RGBH; Code(fBase[0][ly][lx], br, (TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS (format) ? 2 : 0)) == 2 ? 8 : (TCOMPRESS_SWIZZL (format) ? 6 : 5)); } { const int format = TCOMPRESS_XYZD; Code(fNorm[0][ly][lx], rn, (TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS (format) ? 2 : 0)) == 2 ? 8 : (TCOMPRESS_SWIZZL (format) ? 6 : 5)); } { const int format = TCOMPRESS_RGBH; b = Join(fBase[0][ly][lx], br); } { const int format = TCOMPRESS_XYZD; n = Join(fNorm[0][ly][lx], rn); } // CodeRGBH<TRGTMODE_CODING_RGB >(fBase[0][ly][lx], br); #if defined(NORMALS_INTEGER) // CodeXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE, TCOMPRESS_SWIZZL(format) ? 6 : 5>(fNorm[0][ly][lx], nr); #else // CodeXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE, TCOMPRESS_SWIZZL(format) ? 6 : 5>(fNorm[0][ly][lx], rn); #endif // b = JoinRGBH<TRGTMODE_CODING_RGB >(fBase[0][ly][lx], br); #if defined(NORMALS_INTEGER) // n = JoinXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], nr); #else // n = JoinXYZD<TRGTMODE_CODING_DXDYdZt | TRGTNORM_CUBESPACE>(fNorm[0][ly][lx], rn); #endif /* write the result ABGR */ bBase[0][ly][lx] = b; bNorm[0][ly][lx] = n; } /* compress to DXT5 */ #if 0 stb_compress_dxt_block((unsigned char *)dBase, (unsigned char *)bBase[0], true, STB_DXT_DITHER | STB_DXT_HIGHQUAL); stb_compress_dxt_block((unsigned char *)dNorm, (unsigned char *)bNorm[0], true, STB_DXT_NORMAL | STB_DXT_HIGHQUAL); #else squish::Compress((unsigned char *)bBase[0], dBase, flags + squish::kColourMetricPerceptual); squish::Compress((unsigned char *)bNorm[0], dNorm, flags + squish::kColourMetricUniform); #endif /* advance pointer of compressed blocks */ dBase += (128 / 32); dNorm += (128 / 32); #if 0 for (int ly = 0; ly < TY; ly += 1) for (int lx = 0; lx < TX; lx += 1) { dBase[((y + ly) * bPch) + (x + lx)] = bBase[0][ly][lx]; dNorm[((y + ly) * nPch) + (x + lx)] = bNorm[0][ly][lx]; } #endif } } TextureUnlock(baset, l); TextureUnlock(normt, l); } TextureUnlock((*base), 0); TextureUnlock((*norm), 0); (*base)->Release(); (*norm)->Release(); (*base) = baset; (*norm) = normt; return true; }
//========================================================= // Hornet is flying, gently tracking target //========================================================= void CMHornet :: TrackTarget ( void ) { Vector vecFlightDir; Vector vecDirToEnemy; float flDelta; StudioFrameAdvance( ); if (gpGlobals->time > m_flStopAttack) { SetTouch( NULL ); SetThink( SUB_Remove ); pev->nextthink = gpGlobals->time + 0.1; return; } // UNDONE: The player pointer should come back after returning from another level if ( m_hEnemy == NULL ) {// enemy is dead. Look( 512 ); m_hEnemy = BestVisibleEnemy( ); } if ( m_hEnemy != NULL && UTIL_FVisible( m_hEnemy, ENT(pev) )) { m_vecEnemyLKP = UTIL_BodyTarget( m_hEnemy, pev->origin ); } else { m_vecEnemyLKP = m_vecEnemyLKP + pev->velocity * m_flFlySpeed * 0.1; } vecDirToEnemy = ( m_vecEnemyLKP - pev->origin ).Normalize(); if (pev->velocity.Length() < 0.1) vecFlightDir = vecDirToEnemy; else vecFlightDir = pev->velocity.Normalize(); // measure how far the turn is, the wider the turn, the slow we'll go this time. flDelta = DotProduct ( vecFlightDir, vecDirToEnemy ); if ( flDelta < 0.5 ) {// hafta turn wide again. play sound switch (RANDOM_LONG(0,2)) { case 0: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 1: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 2: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; } } if ( flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED ) {// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far. flDelta = 0.25; } pev->velocity = ( vecFlightDir + vecDirToEnemy).Normalize(); if ( pev->owner && (pev->owner->v.flags & FL_MONSTER) ) { // random pattern only applies to hornets fired by monsters, not players. pev->velocity.x += RANDOM_FLOAT ( -0.10, 0.10 );// scramble the flight dir a bit. pev->velocity.y += RANDOM_FLOAT ( -0.10, 0.10 ); pev->velocity.z += RANDOM_FLOAT ( -0.10, 0.10 ); } switch ( m_iHornetType ) { case HORNET_TYPE_RED: pev->velocity = pev->velocity * ( m_flFlySpeed * flDelta );// scale the dir by the ( speed * width of turn ) pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1, 0.3 ); break; case HORNET_TYPE_ORANGE: pev->velocity = pev->velocity * m_flFlySpeed;// do not have to slow down to turn. pev->nextthink = gpGlobals->time + 0.1;// fixed think time break; } pev->angles = UTIL_VecToAngles (pev->velocity); pev->solid = SOLID_BBOX; }
void MainWindow::SaveSettings(BMessage* message) { // make sure the positioning info is correct _GetLocation(); // store window position if (message->ReplacePoint("window position", fScreenPosition) != B_OK) message->AddPoint("window position", fScreenPosition); if (message->ReplaceFloat("border distance", fBorderDist) != B_OK) message->AddFloat("border distance", fBorderDist); // store window frame and look if (message->ReplaceRect("window frame", Frame()) != B_OK) message->AddRect("window frame", Frame()); if (message->ReplaceInt32("window look", Look()) != B_OK) message->AddInt32("window look", Look()); // store orientation if (message->ReplaceInt32("orientation", (int32)fPadView->Orientation()) != B_OK) message->AddInt32("orientation", (int32)fPadView->Orientation()); // store icon size if (message->ReplaceInt32("icon size", fPadView->IconSize()) != B_OK) message->AddInt32("icon size", fPadView->IconSize()); // store ignore double click if (message->ReplaceBool("ignore double click", fPadView->IgnoreDoubleClick()) != B_OK) { message->AddBool("ignore double click", fPadView->IgnoreDoubleClick()); } // store buttons message->RemoveName("path"); message->RemoveName("description"); message->RemoveName("signature"); for (int32 i = 0; LaunchButton* button = fPadView->ButtonAt(i); i++) { BPath path(button->Ref()); if (path.InitCheck() >= B_OK) message->AddString("path", path.Path()); else message->AddString("path", ""); message->AddString("description", button->Description()); if (button->AppSignature()) message->AddString("signature", button->AppSignature()); else message->AddString("signature", ""); } // store auto raise setting if (message->ReplaceBool("auto raise", fAutoRaise) != B_OK) message->AddBool("auto raise", fAutoRaise); // store workspace setting if (message->ReplaceBool("all workspaces", fShowOnAllWorkspaces) != B_OK) message->AddBool("all workspaces", fShowOnAllWorkspaces); if (message->ReplaceInt32("workspaces", Workspaces()) != B_OK) message->AddInt32("workspaces", Workspaces()); }
void Interface::MainGame() { string input = ""; vector<string> parsedInput; bool quitGame = false; Look(); cout << "Type 'help' (no ' marks) for a short explanation of basic commands." << endl; cout << "Make sure to use the 'growth' command before gaining experience!" << endl; while(!quitGame) { Prompt(); getline(cin, input); for (int i = 0; i < input.size(); i++) input[i] = tolower(input[i]); parsedInput = ParseInput(input); command cmd = CommandControl::GetInstance()->GetCommand(parsedInput.front()); string target = parsedInput.back(); if (cmd == LOOK) Look(); if (cmd == GO_NORTH) North(); if (cmd == GO_SOUTH) South(); if (cmd == GO_EAST) East(); if (cmd == GO_WEST) West(); if (cmd == GO_DOWN) Down(); if (cmd == GO_UP) Up(); if (cmd == KILL) Kill(parsedInput.back()); if (cmd == SCORE) Score(); if (cmd == ABILITIES) Abilities(); if (cmd == HELP) Help(); if (cmd == GROWTH) Growth(); if (cmd == QUIT) Quit(); if (cmd == INVENTORY) Inventory(); if (cmd == EQUIPMENT) Equipment(); if (cmd == WEAR) Wear(parsedInput.back()); if (cmd == REMOVE) Remove(parsedInput.back()); if (cmd == EXAMINE) { command targetCmd = CommandControl::GetInstance()->GetCommand(parsedInput.back()); if (targetCmd == INVENTORY) ExaInv(); else if (targetCmd == EQUIPMENT) ExaEquip(); else if (targetCmd == LOOK) ExaLook(); else cout << "That is not a valid target to examine." << endl; } if (cmd == GET) Get(parsedInput.back()); if (cmd == DROP) Drop(parsedInput.back()); if (cmd == USE) Use(parsedInput.back()); if (cmd == SAVE) SavePlayer(); } }
void Verb_Parser(int *tokens) { switch(tokens[0]) { case Action_move: { Move(tokens); break; } case Action_pick: { Pick(tokens); break; } case Action_put: { Put(tokens); break; } case Action_look: { Look(tokens); break; } case Action_inventory: { Inventory(tokens); break; } case Action_examine: { Examine(tokens); break; } case Action_talk: { Talk(tokens); break; } case Action_save: { Save(tokens); break; } case Action_restore: { Restore(tokens); break; } case Action_exit: { Exit(tokens); break; } default: { printf("You must start a sentence with an action verb.\n"); break; } } }
void CApache :: HuntThink( void ) { StudioFrameAdvance( ); SetNextThink( 0.1 ); ShowDamage( ); if ( m_pGoalEnt == NULL && !FStringNull(pev->target) )// this monster has a target { m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( pev->target ) ); if (m_pGoalEnt) { m_posDesired = m_pGoalEnt->pev->origin; UTIL_MakeAimVectors( m_pGoalEnt->pev->angles ); m_vecGoal = gpGlobals->v_forward; } } // if (m_hEnemy == NULL) { Look( 4092 ); m_hEnemy = BestVisibleEnemy( ); } // generic speed up if (m_flGoalSpeed < 800) m_flGoalSpeed += 5; if (m_hEnemy != NULL) { // ALERT( at_console, "%s\n", STRING( m_hEnemy->pev->classname ) ); if (FVisible( m_hEnemy )) { if (m_flLastSeen < gpGlobals->time - 5) m_flPrevSeen = gpGlobals->time; m_flLastSeen = gpGlobals->time; m_posTarget = m_hEnemy->Center( ); } else { m_hEnemy = NULL; } } m_vecTarget = (m_posTarget - pev->origin).Normalize(); float flLength = (pev->origin - m_posDesired).Length(); if (m_pGoalEnt) { // ALERT( at_console, "%.0f\n", flLength ); if (flLength < 128) { m_pGoalEnt = UTIL_FindEntityByTargetname( NULL, STRING( m_pGoalEnt->pev->target ) ); if (m_pGoalEnt) { m_posDesired = m_pGoalEnt->pev->origin; UTIL_MakeAimVectors( m_pGoalEnt->pev->angles ); m_vecGoal = gpGlobals->v_forward; flLength = (pev->origin - m_posDesired).Length(); } } } else { m_posDesired = pev->origin; } if (flLength > 250) // 500 { // float flLength2 = (m_posTarget - pev->origin).Length() * (1.5 - DotProduct((m_posTarget - pev->origin).Normalize(), pev->velocity.Normalize() )); // if (flLength2 < flLength) if (m_flLastSeen + 90 > gpGlobals->time && DotProduct( (m_posTarget - pev->origin).Normalize(), (m_posDesired - pev->origin).Normalize( )) > 0.25) { m_vecDesired = (m_posTarget - pev->origin).Normalize( ); } else { m_vecDesired = (m_posDesired - pev->origin).Normalize( ); } } else { m_vecDesired = m_vecGoal; } Flight( ); // ALERT( at_console, "%.0f %.0f %.0f\n", gpGlobals->time, m_flLastSeen, m_flPrevSeen ); if ((m_flLastSeen + 1 > gpGlobals->time) && (m_flPrevSeen + 2 < gpGlobals->time)) { if (FireGun( )) { // slow down if we're fireing if (m_flGoalSpeed > 400) m_flGoalSpeed = 400; } // don't fire rockets and gun on easy mode if (g_iSkillLevel == SKILL_EASY) m_flNextRocket = gpGlobals->time + 10.0; } UTIL_MakeAimVectors( pev->angles ); Vector vecEst = (gpGlobals->v_forward * 800 + pev->velocity).Normalize( ); // ALERT( at_console, "%d %d %d %4.2f\n", pev->angles.x < 0, DotProduct( pev->velocity, gpGlobals->v_forward ) > -100, m_flNextRocket < gpGlobals->time, DotProduct( m_vecTarget, vecEst ) ); if ((m_iRockets % 2) == 1) { FireRocket( ); m_flNextRocket = gpGlobals->time + 0.5; if (m_iRockets <= 0) { m_flNextRocket = gpGlobals->time + 10; m_iRockets = 10; } } else if (pev->angles.x < 0 && DotProduct( pev->velocity, gpGlobals->v_forward ) > -100 && m_flNextRocket < gpGlobals->time) { if (m_flLastSeen + 60 > gpGlobals->time) { if (m_hEnemy != NULL) { // make sure it's a good shot if (DotProduct( m_vecTarget, vecEst) > .965) { TraceResult tr; UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096, ignore_monsters, edict(), &tr ); if ((tr.vecEndPos - m_posTarget).Length() < 512) FireRocket( ); } } else { TraceResult tr; UTIL_TraceLine( pev->origin, pev->origin + vecEst * 4096, dont_ignore_monsters, edict(), &tr ); // just fire when close if ((tr.vecEndPos - m_posTarget).Length() < 512) FireRocket( ); } } } }
//========================================================= // Hornet is flying, gently tracking target //========================================================= void CHornet :: TrackTarget ( void ) { Vector vecFlightDir; Vector vecDirToEnemy; float flDelta; StudioFrameAdvance( ); if (gpGlobals->time > m_flStopAttack) { SetTouch( NULL ); SetThink( SUB_Remove ); pev->nextthink = gpGlobals->time + 0.1; return; } // UNDONE: The player pointer should come back after returning from another level if ( m_hEnemy == NULL ) {// enemy is dead. Look( 512 ); m_hEnemy = BestVisibleEnemy( ); } if ( m_hEnemy != NULL && FVisible( m_hEnemy )) { m_vecEnemyLKP = m_hEnemy->BodyTarget( GetAbsOrigin() ); } else { m_vecEnemyLKP = m_vecEnemyLKP + GetAbsVelocity() * m_flFlySpeed * 0.1; } vecDirToEnemy = ( m_vecEnemyLKP - GetAbsOrigin() ).Normalize(); if (GetAbsVelocity().Length() < 0.1) vecFlightDir = vecDirToEnemy; else vecFlightDir = GetAbsVelocity().Normalize(); // measure how far the turn is, the wider the turn, the slow we'll go this time. flDelta = DotProduct ( vecFlightDir, vecDirToEnemy ); if ( flDelta < 0.5 ) {// hafta turn wide again. play sound switch (RANDOM_LONG(0,2)) { case 0: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 1: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 2: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; } } if ( flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED ) {// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far. flDelta = 0.25; } SetAbsVelocity(( vecFlightDir + vecDirToEnemy).Normalize() ); if( pev->owner && ( pev->owner->v.flags & FL_MONSTER )) { // random pattern only applies to hornets fired by monsters, not players. Vector vecVelocity = GetAbsVelocity(); vecVelocity.x += RANDOM_FLOAT ( -0.10, 0.10 );// scramble the flight dir a bit. vecVelocity.y += RANDOM_FLOAT ( -0.10, 0.10 ); vecVelocity.z += RANDOM_FLOAT ( -0.10, 0.10 ); SetAbsVelocity( vecVelocity ); } switch ( m_iHornetType ) { case HORNET_TYPE_RED: SetAbsVelocity( GetAbsVelocity() * ( m_flFlySpeed * flDelta ));// scale the dir by the ( speed * width of turn ) pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1, 0.3 ); break; case HORNET_TYPE_ORANGE: SetAbsVelocity( GetAbsVelocity() * m_flFlySpeed ); // do not have to slow down to turn. pev->nextthink = gpGlobals->time + 0.1;// fixed think time break; } SetAbsAngles( UTIL_VecToAngles( GetAbsVelocity())); pev->solid = SOLID_BBOX; // if hornet is close to the enemy, jet in a straight line for a half second. // (only in the single player game) if ( m_hEnemy != NULL && !g_pGameRules->IsMultiplayer() ) { if ( flDelta >= 0.4 && ( GetAbsOrigin() - m_vecEnemyLKP ).Length() <= 300 ) { Vector vecOrigin = GetAbsOrigin(); MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecOrigin ); WRITE_BYTE( TE_SPRITE ); WRITE_COORD( vecOrigin.x ); // pos WRITE_COORD( vecOrigin.y ); WRITE_COORD( vecOrigin.z ); WRITE_SHORT( iHornetPuff ); // model // WRITE_BYTE( 0 ); // life * 10 WRITE_BYTE( 2 ); // size * 10 WRITE_BYTE( 128 ); // brightness MESSAGE_END(); switch( RANDOM_LONG( 0, 2 )) { case 0: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM ); break; case 1: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM ); break; case 2: EMIT_SOUND( ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM ); break; } SetAbsVelocity( GetAbsVelocity() * 2 ); pev->nextthink = gpGlobals->time + 1.0; // don't attack again m_flStopAttack = gpGlobals->time; } } }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; static HPEN hpen,hpen1,hpen2; static HBRUSH hbrush,hbrush1,hbrush2; int x,y; switch (message) /* handle the messages */ { case WM_KEYDOWN: switch (wParam) { case VK_F5: Init(hwnd); Rectangle(hdc,0,0,xw,yw); for(x=0;x<MAX;x++) for(y=0;y<MAX;y++) { Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ; iGame[x][y]=Default; } SetTimer(hwnd,Time1,times,NULL); leng=1; plays=Play; break; case VK_F1: break; case VK_F2: SetTimer(hwnd,Time1,times,NULL); leng=1; plays=Play; break; case VK_F3: if(plays==Play) { KillTimer(hwnd,Time1); plays=Paush; } else if(plays==Paush) { SetTimer(hwnd,Time1,times,NULL); plays=Play; } break; } break; case WM_TIMER: switch (wParam) { case Time1: timechage(hwnd); break; } break; case WM_CREATE: plays=Stop; play=Player1; break; case WM_SIZE: xw=LOWORD(lParam); yw=HIWORD(lParam); xw-=TextWidth; InvalidateRect(hwnd,NULL,TRUE); break; case WM_LBUTTONDOWN: //获取但前鼠标坐标 point.x=LOWORD(lParam); point.y=HIWORD(lParam); //初始化设备DC Init(hwnd); //鼠标坐标换为数组坐标 x=(point.x)/(xw/MAX); y=(point.y)/(yw/MAX); if(plays==Stop)break; if(x<MAX&&y<MAX) { if(iGame[x][y]==Default&&plays==Play)//判断但前位置是否有棋子覆盖 { leng=1; paint(play,x,y); if(Look(x,y,play)) over(hwnd,play); chagePlayer(); } } break; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); Init(hwnd); Rectangle(hdc,0,0,xw,yw); for(x=0;x<MAX;x++) for(y=0;y<MAX;y++) { Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ; paint(iGame[x][y],x,y); } EndPaint(hwnd,&ps); break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }