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; }
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; }
void Player::HandleEvent(const sf::Event& event, CommandQueue& commands) { if ( m_useJoystick ) { Command_t c; c.category = Category::PlayerAircraft; if ( event.type == sf::Event::JoystickButtonPressed ) { if ( event.joystickButton.button == 2) //if ( sf::Joystick::isButtonPressed( 0, 2 ) ) { // yes: shoot! c.action = DerivedAction<Creature>( []( Creature& a, sf::Time ){ a.LaunchMissile(); } ); commands.Push( c ); } } } else { if ( event.type == sf::Event::KeyPressed ) { // Check if pressed key appears in key binding, trigger command if so auto found = m_keyBinding.find( event.key.code ); if ( found != m_keyBinding.end() && !IsRealtimeAction( found->second ) ) commands.Push( m_actionBinding[found->second] ); } } }
//protected ICommand* AbstractManager::dequeueCommand() { ICommand* command=0; if(mLock.tryLockForWrite(mReadMaxWait)) { for(int severity=ICommand::HIGH; severity <= ICommand::LOW; severity++) { CommandQueue* queue = mHashCommandQueues.value(severity,0); if(queue) { if(!queue->isEmpty()) { command = queue->dequeue(); if(command) { break; } } } } mLock.unlock(); } return command; }
Heap * Heap::Alloc(ID3D12Device * Device, int Type) { Heap * heap = 0; D3D12Render * render = D3D12Render::GetRender(); CommandQueue * Queue = render->GetQueue(D3D12_COMMAND_LIST_TYPE_DIRECT); if (Free.Size()) { heap = Free.PopBack(); } else { bool Found = 0; for (auto Iter = Retired.Begin(); Iter != Retired.End(); Iter++) { heap = *Iter; UINT64 FenceValue = heap->FenceValue; if (Queue->FenceComplete(FenceValue)) { Retired.Remove(Iter); Found = 1; break; } } if (!Found) { heap = 0; } } if (heap) { return heap; } else { // new context heap = new Heap(); heap->Init(Device, MAX_CONSTANT_BUFFER_HEAP, Type); } return heap; }
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; } }
MessagePump* Pipe::getMessagePump() { LB_TS_THREAD( _pipeThread ); if( !_impl->thread ) return 0; CommandQueue* queue = _impl->thread->getWorkerQueue(); return queue->getMessagePump(); }
void Pipe::_exitCommandQueue() { // Non-threaded pipes have no pipe thread message pump if( !_impl->thread ) return; CommandQueue* queue = _impl->thread->getWorkerQueue(); LBASSERT( queue ); MessagePump* pump = queue->getMessagePump(); queue->setMessagePump( 0 ); delete pump; }
bool Event::removeWaitEvent(Event *event) { bool empty; pthread_mutex_lock(&p_state_mutex); p_wait_events.remove(event); empty = p_wait_events.empty(); pthread_mutex_unlock(&p_state_mutex); CommandQueue *q = (CommandQueue *) event->parent(); if (q != NULL) q->releaseEvent(event); return empty; }
int main(int argc, char ** argv) { // Load image SIPL::Image<float> * image = new SIPL::Image<float>("images/sunset.jpg"); // Create OpenCL context Context context = createCLContextFromArguments(argc, argv); // Compile OpenCL code Program program = buildProgramFromSource(context, "gaussian_blur.cl"); // Select device and create a command queue for it VECTOR_CLASS<Device> devices = context.getInfo<CL_CONTEXT_DEVICES>(); CommandQueue queue = CommandQueue(context, devices[0]); // Create an OpenCL Image / texture and transfer data to the device Image2D clImage = Image2D(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, ImageFormat(CL_R, CL_FLOAT), image->getWidth(), image->getHeight(), 0, (void*)image->getData()); // Create a buffer for the result Buffer clResult = Buffer(context, CL_MEM_WRITE_ONLY, sizeof(float)*image->getWidth()*image->getHeight()); // Create Gaussian mask int maskSize; float * mask = createBlurMask(10.0f, &maskSize); // Create buffer for mask and transfer it to the device Buffer clMask = Buffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(float)*(maskSize*2+1)*(maskSize*2+1), mask); // Run Gaussian kernel Kernel gaussianBlur = Kernel(program, "gaussian_blur"); gaussianBlur.setArg(0, clImage); gaussianBlur.setArg(1, clMask); gaussianBlur.setArg(2, clResult); gaussianBlur.setArg(3, maskSize); queue.enqueueNDRangeKernel( gaussianBlur, NullRange, NDRange(image->getWidth(), image->getHeight()), NullRange ); // Transfer image back to host float* data = new float[image->getWidth()*image->getHeight()]; queue.enqueueReadBuffer(clResult, CL_TRUE, 0, sizeof(float)*image->getWidth()*image->getHeight(), data); image->setData(data); // Save image to disk image->save("images/result.jpg", "jpeg"); image->display(); }
void Aircraft::checkPickupDrop(CommandQueue& commands) { if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup) commands.push(mDropPickupCommand); mSpawnedPickup = true; }
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]]); }
void queueCommandBuffer(pm4::Buffer *buf) { buf->submitTime = OSGetTime(); gx2::internal::setLastSubmittedTimestamp(buf->submitTime); gQueue.appendBuffer(buf); }
/** * Collate the OpenCL Kernel */ void collateExecuteCL(void) { if (m_sharedCL.size() > 0) { m_queue.enqueueReleaseGLObjects(&m_sharedCL); } // Buffer Reads // ... }
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]); } }
/** * Prepare a DoCommand to be send over the network * @param tile The tile to perform a command on (see #CommandProc) * @param p1 Additional data for the command (see #CommandProc) * @param p2 Additional data for the command (see #CommandProc) * @param cmd The command to execute (a CMD_* value) * @param callback A callback function to call after the command is finished * @param text The text to pass * @param company The company that wants to send the command */ void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company) { assert((cmd & CMD_FLAGS_MASK) == 0); CommandPacket c; c.company = company; c.tile = tile; c.p1 = p1; c.p2 = p2; c.cmd = cmd; c.callback = callback; strecpy(c.text, (text != NULL) ? text : "", lastof(c.text)); if (_network_server) { /* If we are the server, we queue the command in our 'special' queue. * In theory, we could execute the command right away, but then the * client on the server can do everything 1 tick faster than others. * So to keep the game fair, we delay the command with 1 tick * which gives about the same speed as most clients. */ c.frame = _frame_counter_max + 1; c.my_cmd = true; _local_wait_queue.Append(&c); return; } c.frame = 0; // The client can't tell which frame, so just make it 0 /* Clients send their command to the server and forget all about the packet */ MyClient::SendCommand(&c); }
/** * Stage the OpenCL Kernel */ void stageExecuteCL(void) { if (m_sharedCL.size() > 0) { m_queue.enqueueAcquireGLObjects(&m_sharedCL); } // Buffer Writes // ... p_time = m_time; m_time = glutGet(GLUT_ELAPSED_TIME); float time = (float)(m_time - p_time); // Update Camera m_rot += (0.05f * time); if (m_rot > 360.0f) { m_rot -= 360.0f; } if (m_rot < 0.0f) { m_rot += 360.0f; } setTranCam(m_camera[0], 0.0f, 0.0f, m_dist); setRotCam(m_camera[0], -20.0f, 0.0f, 0.0f); rotCam(m_camera[0], 0.0f, m_rot, 0.0f); makeLUCam(m_camera[0]); m_camera.writeBuffer(m_queue); }
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); }
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]); } }
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]); } }
/** * Sync our local command queue to the command queue of the given * socket. This is needed for the case where we receive a command * before saving the game for a joining client, but without the * execution of those commands. Not syncing those commands means * that the client will never get them and as such will be in a * desynced state from the time it started with joining. * @param cs The client to sync the queue to. */ void NetworkSyncCommandQueue(NetworkClientSocket *cs) { for (CommandPacket *p = _local_execution_queue.Peek(); p != NULL; p = p->next) { CommandPacket c = *p; c.callback = 0; cs->outgoing_queue.Append(&c); } }
void Player::handleRealtimeInput(CommandQueue& commands) { for (auto pair : mKeyBinding) { if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second)) commands.push(mActionBinding[pair.second]); } }
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); }
void fill_data( Image2D& _data ) { double* data; CALuint pitch; unsigned size; data = (double*)_queue.mapMemObject(_data,pitch); size = 2*_data.getWidth()*_data.getHeight(); for(unsigned i=0;i<size;i+=2) { *(data + 0) = i+1; *(data + 1) = i+1; data+=2; } _queue.unmapMemObject(_data); }
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]); } }
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; }
void run() { NDRange global; Event event; boost::array<boost::uint32_t,4> size; size.assign(2*256*64); global = NDRange(256,64); // run kernel A _kernel.setArg(0,size); _kernel.setArg(1,_input); _kernel.setArg(2,_output); _queue.enqueueNDRangeKernel( _kernel, global, &event ); _queue.flush(); _queue.waitForEvent(event); }
void Player::handleEvent(const sf::Event& event, CommandQueue& commands) { if (event.type == sf::Event::KeyPressed) { // Check if pressed key appears in key binding, trigger command if so auto found = mKeyBinding.find(event.key.code); if (found != mKeyBinding.end() && !isRealtimeAction(found->second)) commands.push(mActionBinding[found->second]); } }
void Player::handleRealtimeInput(CommandQueue& commands) { // Traverse all assigned keys and check if they are pressed 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]); } }
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]); } }