本文整理汇总了C++中CommandQueue::push方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandQueue::push方法的具体用法?C++ CommandQueue::push怎么用?C++ CommandQueue::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandQueue
的用法示例。
在下文中一共展示了CommandQueue::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkProjectileLaunch
void Aircraft::checkProjectileLaunch(sf::Time dt, CommandQueue& commands)
{
// Enemies try to fire all the time
if (!isAllied())
fire();
// Check for automatic gunfire, allow only in intervals
if (mIsFiring && mFireCountdown <= sf::Time::Zero)
{
// Interval expired: We can fire a new bullet
commands.push(mFireCommand);
mFireCountdown += Table[mType].fireInterval / (mFireRateLevel + 1.f);
mIsFiring = false;
}
else if (mFireCountdown > sf::Time::Zero)
{
// Interval not expired: Decrease it further
mFireCountdown -= dt;
mIsFiring = false;
}
// Check for missile launch
if (mIsLaunchingMissile)
{
commands.push(mMissileCommand);
mIsLaunchingMissile = false;
}
}
示例2: updateCurrent
void Tile::updateCurrent(sf::Time dt, CommandQueue& commands)
{
// Entity has been destroyed: Possibly drop pickup, mark for removal
if (isDestroyed())
{
checkPickupDrop(commands);
mExplosion.update(dt);
// Play explosion sound only once
if (!mExplosionBegan)
{
// Play sound effect
SoundEffect::ID soundEffect = (randomInt(2) == 0) ? SoundEffect::Explosion1 : SoundEffect::Explosion2;
playLocalSound(commands, soundEffect);
// Emit network game action for explosions
if (isBlock())
{
sf::Vector2f position = getWorldPosition();
Command command;
command.category = Category::Network;
command.action = derivedAction<NetworkNode>([position] (NetworkNode& node, sf::Time)
{
node.notifyGameAction(GameActions::EnemyExplode, position);
});
commands.push(command);
mExplosionBegan = true;
}
}
return;
}
Entity::updateCurrent(dt, commands);
}
示例3: updateInput
void Player::updateInput(CommandQueue &command_queue)
{
if (keyboard_works == true)
for (auto &itr : key_to_action)
{
//If the key is pressed add to the set. If not then delete from the set.
//If it's a new key then refresh the last_key_pressed and current_action
if (sf::Keyboard::isKeyPressed(itr.first))
{
auto key = keys_pressed.find(itr.first);
if (key == keys_pressed.end())
{
current_action = key_to_action[itr.first];
last_key_pressed = itr.first;
}
keys_pressed.insert(itr.first);
}
else
{
auto key = keys_pressed.find(itr.first);
if (key != keys_pressed.end()) keys_pressed.erase(itr.first);
}
}
if(last_key_pressed != 0 && keyboard_works == true)
command_queue.push(action_to_command[current_action]);
//command_queue.push(action_to_command[key_to_action[last_key_pressed]]);
}
示例4: handleEvent
void Player::handleEvent(const sf::Event& event, CommandQueue& commands)
{
// event souris
if (event.type == sf::Event::KeyPressed)
{
auto found = m_keyBinding.find(event.key.code);
if (found != m_keyBinding.end() && !isRealtimeAction(found->second))
commands.push(m_actionBinding[found->second]);
}
else if(event.type == sf::Event::MouseButtonPressed)
{
auto found = m_mouseBinding.find(event.mouseButton.button);
if (found != m_mouseBinding.end() && !isRealtimeAction(found->second))
commands.push(m_actionBinding[found->second]);
}
}
示例5: dispatchCommand
bool Dispatcher::dispatchCommand( Command& command )
{
EQVERB << "dispatch " << command << " on " << base::className( this )
<< std::endl;
const uint32_t which = command->command;
#ifndef NDEBUG
if( which >= _qTable.size( ))
{
EQABORT( "Command " << command
<< " higher than number of registered command handlers ("
<< _qTable.size() << ") for object of type "
<< base::className( this ) << std::endl );
return false;
}
#endif
CommandQueue* queue = _qTable[which];
if( queue )
{
command.setDispatchFunction( _fTable[which] );
queue->push( command );
return true;
}
// else
EQCHECK( _fTable[which]( command ));
return true;
}
示例6: dispatchCommand
bool Dispatcher::dispatchCommand( ICommand& command )
{
LBASSERT( command.isValid( ));
LBVERB << "dispatch " << command << " on " << lunchbox::className( this )
<< std::endl;
const uint32_t which = command.getCommand();
#ifndef NDEBUG
if( which >= _impl->qTable.size( ))
{
LBABORT( "ICommand " << command
<< " higher than number of registered command handlers ("
<< _impl->qTable.size() << ") for object of type "
<< lunchbox::className( this ) << std::endl );
return false;
}
#endif
CommandQueue* queue = _impl->qTable[ which ];
if( queue )
{
command.setDispatchFunction( _impl->fTable[ which ] );
queue->push( command );
return true;
}
// else
LBCHECK( _impl->fTable[ which ]( command ));
return true;
}
示例7: checkPickupDrop
void Aircraft::checkPickupDrop(CommandQueue& commands)
{
if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup)
commands.push(mDropPickupCommand);
mSpawnedPickup = true;
}
示例8: playLocalSound
void Entity::playLocalSound(CommandQueue &commands, Sounds::ID sound)
{
Command command;
command.category = Category::SoundEffect;
command.action = derivedAction<SoundNode>(std::bind(&SoundNode::playSound, std::placeholders::_1, sound, getWorldPosition()));
commands.push(command);
}
示例9: handleRealtimeInput
void Player::handleRealtimeInput(CommandQueue& commands)
{
for (auto pair : mKeyBinding)
{
if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second))
commands.push(mActionBinding[pair.second]);
}
}
示例10: handleEvent
void Player::handleEvent(const sf::Event& event, CommandQueue& commands) {
if (event.type == sf::Event::KeyPressed) {
// Commands happen when the player presses a key that corresponds with a command
auto found = mKeyBinding.find(event.key.code);
if (found != mKeyBinding.end() && !isRealtimeAction(found->second))
commands.push(mActionBinding[found->second]);
}
}
示例11: handleRealtimeInput
void Player::handleRealtimeInput(CommandQueue& commands) {
// Checks every key for a press
for (auto pair : mKeyBinding) {
// if something is pressed make sure to trigger command
if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second))
commands.push(mActionBinding[pair.second]);
}
}
示例12: handleRealTimeInput
void Player::handleRealTimeInput(CommandQueue& commands)
{
// Traverse all assigned keys and check if they are pressed
for (auto it = m_keyBinding.begin(); it!= m_keyBinding.end(); ++it)
{
// If key is pressed, lookup action and trigger corresponding command
if (sf::Keyboard::isKeyPressed((*it).first) && isRealtimeAction((*it).second))
commands.push(m_actionBinding[(*it).second]);
}
// Check if mouse button are pressed
for (auto it = m_mouseBinding.begin(); it!= m_mouseBinding.end(); ++it)
{
// If key is pressed, lookup action and trigger corresponding command
if (sf::Mouse::isButtonPressed((*it).first) && isRealtimeAction((*it).second))
commands.push(m_actionBinding[(*it).second]);
}
}
示例13: checkPickupDrop
void Tile::checkPickupDrop(CommandQueue& commands)
{
// Drop pickup, if enemy airplane, with probability 1/4, if pickup not yet dropped
// and if not in network mode (where pickups are dropped via packets)
if (isBlock() && randomInt(5) == 0 && !mSpawnedPickup && mPickupsEnabled){
commands.push(mDropPickupCommand);
}
mSpawnedPickup = true;
}
示例14: handleRealTimeInput
void Player::handleRealTimeInput(CommandQueue& commands)
{
for (auto pair : mKeyBinding)
{
// If key is pressed, lookup action and trigger corresponding command
if (sf::Keyboard::isKeyPressed(pair.first) && isRealTimeAction(pair.second))
commands.push(mActionBinding[pair.second]);
}
}
示例15: checkProjectileLaunch
void Aircraft::checkProjectileLaunch(sf::Time delta, CommandQueue& commands)
{
if (!isAllied()) fire();
if (bFiring && mFireCountdown <= sf::Time::Zero) {
commands.push(mFireCommand);
mFireCountdown += sf::seconds(1.f / (mFireRateLevel + 1));
bFiring = false;
playLocalSound(commands, isAllied() ? SoundEffects::AlliedGunfire : SoundEffects::EnemyGunfire);
} else if (mFireCountdown > sf::Time::Zero)
mFireCountdown -= delta;
if (bLaunchingMissile) {
commands.push(mMissileCommand);
bLaunchingMissile = false;
playLocalSound(commands, SoundEffects::LaunchMissile);
}
}