void Chunk::pumpkinGenerate() { if(m_pumpkinCount < 1) { int rollIndex = rand()%32768; Vec3i coord = getBlockCoordsByBlockIndex(rollIndex); if(coord.x == 0 || coord.x == 15 || coord.y == 0 || coord.y == 15 || coord.z == 0) return; if(m_block[rollIndex - BLOCKS_IN_A_LAYER].m_type == GRASS && m_block[rollIndex].m_type == AIR) { m_pumpkinCount++; addBlock(getBlockCoordsByBlockIndex(rollIndex),PUMPKIN); } } }
void JsonInputFileFormatter::addTypes(const std::string & key, const moosecontrib::Json::Value & block) { if (!block.isMember(key)) return; auto & types = block[key]; if (types.isNull()) return; addLine(""); addLine("[./<types>]"); _level++; for (auto && name : types.getMemberNames()) addBlock("<" + name + ">", types[name]); _level--; addLine("[../]"); }
PinNode *BlockGraph::addOutput(PinModel *pin) { Q_ASSERT(pin->type() == PinModel::OUTPUT); QMap<PinModel*, PinNode*>::const_iterator nodeIt = nodeByPin_.find(pin); if (nodeIt != nodeByPin_.end()) { return *nodeIt; } PinNode *node = new PinNode(addBlock(pin->parent()), pin); nodeByPin_[pin] = node; PinModel *target = pin->connected(); if (target != 0 && target->type() == PinModel::INPUT) { node->addNeighbour(addInput(target)); } return node; }
int bufManagerByLFRU::writeFileSegment(unsigned int fileId,unsigned int segId){//要加锁,要防止中间被访问而该参数。 if(buf.size()==0){ myAlarmEvent.period = _period; myAlarmEvent.timeleft = _period; myAlarmEvent.callBackFunc = &LFRUBlockResetThread; myAlarmEvent.arg = this; addAlarmEvent(&myAlarmEvent); cout<<"add the alarm event ..."<<endl; } pthread_mutex_lock(&buf_mutex); if(buf.size() >=_blockNum){ pthread_mutex_unlock(&buf_mutex); eliminateBlock(); }else pthread_mutex_unlock(&buf_mutex); addBlock(fileId,segId); return 0; }
int getBlocks(char* plainText, int plainTextLen, BLOCK_LIST_T* pBlockList) { int i = 0; int sizeToCopy = 0; int padding = 0; int numBlocks = plainTextLen / BLOCK_SIZE; //int padding = BLOCK_SIZE - (plainTextLen % BLOCK_SIZE); char tempBuff[BLOCK_SIZE]; if (padding > 0) { numBlocks++; /* this block will contain padding */ } printf("Plaintext is len %d. There will be %d blocks (size %d) with %d padding.\n", plainTextLen, numBlocks, BLOCK_SIZE, padding); if (NULL == pBlockList || plainText == NULL) { return 1; } for (i = 0; i < plainTextLen;) { sizeToCopy = min(BLOCK_SIZE, (plainTextLen - i)); memcpy(tempBuff, plainText + i, sizeToCopy); /* Handle padding */ padding = BLOCK_SIZE - sizeToCopy; memset(tempBuff + sizeToCopy, PAD_CHAR, padding); printf("Copying %d bytes into new block\n", sizeToCopy); addBlock(tempBuff, sizeToCopy + padding, pBlockList); i += sizeToCopy; } return 0; }
Ground::Ground(int** heightMap) : Structure(glm::vec3(0, 0, 0)) { _isGround = true; int m_tailleChunk = 16; int m = 0; int **dHeight; dHeight = new int*[m_tailleChunk + 2]; for (int i = 0; i < m_tailleChunk + 2; i++) { dHeight[i] = new int[m_tailleChunk + 2]; for (int j = 0; j < m_tailleChunk + 2; j++) { dHeight[i][j] = 1; } } for (int i = 1; i < m_tailleChunk + 1; i++) { for (int j = 1; j < m_tailleChunk + 1; j++) { m = std::min(std::min(std::min(heightMap[i + 1][j], heightMap[i - 1][j]), heightMap[i][j - 1]), heightMap[i][j + 1]); if (m + 1 < heightMap[i][j]) { dHeight[i][j] = heightMap[i][j] - m; } } } for (int i = 1; i < m_tailleChunk + 1; i++) { for (int j = 1; j < m_tailleChunk + 1; j++) { for (int k = 0; k < dHeight[i][j]; k++) { addBlock(i - 1, j - 1, heightMap[i][j] + k - 1, Engine::BlockType::Grass); } } } for (int i = 0; i < m_tailleChunk + 2; i++) { delete dHeight[i]; } delete dHeight; }
PinNode *BlockGraph::addInput(PinModel *pin) { Q_ASSERT(pin->type() == PinModel::INPUT); QMap<PinModel*, PinNode*>::const_iterator nodeIt = nodeByPin_.find(pin); if (nodeIt != nodeByPin_.end()) { return *nodeIt; } PinNode *node = new PinNode(addBlock(pin->parent()), pin); nodeByPin_[pin] = node; // Check all output pins for this input pin QPtrList<PinModel> pins = pin->parent()->connectionsForInputPin(pin); for (QPtrListIterator<PinModel> it(pins); it != 0; ++it) { node->addNeighbour(addOutput(*it)); } return node; }
//----------------------------------------------------------------------- void DynamicBlockObject::addBlock( Vec3 oldPos, Vec3 pos ) { if(!mBlockManager->getDynamicBlockList()->getIsGridCreated()) { return; } BlockManager::BLOCK_FLAG blockFlag = BlockManager::BLF_ENTITY_ALLSIDE_BLOCK; addBlock( oldPos, pos, BlockManager::BLF_ENTITY_ALLSIDE_BLOCK); addBlock( oldPos, pos, BlockManager::BLF_STRUCTURE_ALLSIDE_BLOCK); addBlock( oldPos, pos, BlockManager::BLF_STRUCTURE_INSIDE_BLOCK ); addBlock( oldPos, pos, BlockManager::BLF_STRUCTURE_OUTSIDE_BLOCK ); addBlock( oldPos, pos, BlockManager::BLF_STRUCTURE_ROAD ); addBlock( oldPos, pos, BlockManager::BLF_STRUCTURE_PASSAGE ); }
BlockInfo* Buffer::getBlock(string& dbName, string& name, int blockNum, int type){ string fileName = dbName + '_' + name; FileInfo* tempFile = findFile(dbName, fileName, type); BlockInfo* tempBlock = tempFile->firstBlock; BlockInfo* oldBlock = NULL; while (tempBlock){ //search the block if (tempBlock->blockNum == blockNum){ //move the block to the tail if (tempBlock->next){ //not tail if (oldBlock) //not head oldBlock->next = tempBlock->next; else //head tempFile->firstBlock = tempBlock->next; BlockInfo* tempBlock2 = tempBlock; while (tempBlock2->next) tempBlock2 = tempBlock2->next; tempBlock2->next = tempBlock; tempBlock->next = NULL; } tempBlock->iTime++; //tail tempBlock->lock = 1; return tempBlock; } else{ //search the next block oldBlock = tempBlock; tempBlock = tempBlock->next; } } //do not find the block BlockInfo* tempBlock2 = findBlock(dbName); //find an available block from buffer //load a block from file into buffer readBlock(dbName, name, type, blockNum, tempBlock2); if (tempBlock2->blockNum != -2) addBlock(dbName, name, tempFile, tempBlock2); tempBlock2->iTime++; tempBlock2->lock = 1; return tempBlock2; }
/* * place - Places the Headers and footers in the block , also performs spilliting if neccessary * */ static void place(void *bp, size_t asize) { size_t csize = GET_SIZE(HDRP(bp)); /* Split the Block if the new created block size is greater than minimum block size(16 bytes) */ if ((csize - asize) >= (DSIZE + OVERHEAD)) { removeBlock(bp); PUT(HDRP(bp), PACK(asize, 1)); PUT(FTRP(bp), PACK(asize, 1)); bp = NEXT_BLKP(bp); PUT(HDRP(bp), PACK(csize-asize, 0)); PUT(FTRP(bp), PACK(csize-asize, 0)); addBlock(bp); } /* Do not split , just allocate the block's header ans footer */ else { /* Causes internal fragmentation */ PUT(HDRP(bp), PACK(csize, 1)); PUT(FTRP(bp), PACK(csize, 1)); removeBlock(bp); } }
UDisks2::UDisks2(QObject *parent) : QObject(parent) { auto system = QDBusConnection::systemBus(); system.connect("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", this, SLOT(dbus_interfaceAdded(QDBusObjectPath,QMap<QString,QVariant>))); system.connect("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", this, SLOT(dbus_interfaceRemoved(QDBusObjectPath,QStringList))); foreach (QString block, blockDevices()) { addBlock(block); }
void addBlocks(const geometry_msgs::PoseArrayConstPtr& msg) { interactive_m_server_.clear(); interactive_m_server_.applyChanges(); ROS_INFO("[block logic] Got block detection callback. Adding blocks."); geometry_msgs::Pose block; bool active = action_server_.isActive(); for (unsigned int i=0; i < msg->poses.size(); i++) { block = msg->poses[i]; addBlock(block, i, active, msg->header.frame_id); } ROS_INFO("[block logic] Added %d blocks to Rviz", int(msg->poses.size())); interactive_m_server_.applyChanges(); msg_ = msg; initialized_ = true; }
BlockInfo* Buffer::getEmptyBlock(string& dbName, string& name){ string fileName = dbName + "_" + name; FileInfo* tempFile = findFile(dbName, fileName, 1); BlockInfo* tempBlock = tempFile->firstBlock; BlockInfo* oldBlock = NULL; while (tempBlock){ //search the block if (tempBlock->charNum == 0){ //move the block to the tail if (tempBlock->next){ //not tail if (oldBlock) //not head oldBlock->next = tempBlock->next; else //head tempFile->firstBlock = tempBlock->next; BlockInfo* tempBlock2 = tempBlock; while (tempBlock2->next) tempBlock2 = tempBlock2->next; tempBlock2->next = tempBlock; tempBlock->next = NULL; } tempBlock->iTime++; //tail tempBlock->lock = 1; return tempBlock; } else{ //search the next block oldBlock = tempBlock; tempBlock = tempBlock->next; } } BlockInfo* tempBlock2 = findBlock(dbName); //find an available block from buffer //load a block from file into buffer readEmptyBlock(dbName, name, 1, tempBlock2); addBlock(dbName, name, tempFile, tempBlock2); tempBlock2->iTime++; tempBlock2->lock = 1; return tempBlock2; }
BlockInfo* Buffer::getAvaBlock(string& dbName, string& name){ string fileName = dbName + "_" + name; FileInfo* tempFile = findFile(dbName, fileName, 0); BlockInfo* tempBlock = tempFile->firstBlock; BlockInfo* oldBlock = NULL; while (tempBlock){ //search the block if (!tempBlock->isFull){ //move the block to the tail if (tempBlock->next){ //not tail if (oldBlock) //not head oldBlock->next = tempBlock->next; else //head tempFile->firstBlock = tempBlock->next; BlockInfo* tempBlock2 = tempBlock; while (tempBlock2->next) tempBlock2 = tempBlock2->next; tempBlock2->next = tempBlock; tempBlock->next = NULL; } tempBlock->iTime++; tempBlock->lock = 1; return tempBlock; } else{ //search the next block oldBlock = tempBlock; tempBlock = tempBlock->next; } } BlockInfo* tempBlock2 = findBlock(dbName); readEmptyBlock(dbName, name, 0, tempBlock2); addBlock(dbName, name, tempFile, tempBlock2); tempBlock2->iTime++; tempBlock2->lock = 1; return tempBlock2; }
void GameField::loadLevel(QString name){ QFile file(name); if (file.open(QIODevice::ReadOnly)){ QTextStream stream(&file); QString str; while(!stream.atEnd()){ stream>>str; if (str=="addblock"){ stream>>str; double x = str.toDouble(); stream>>str; double y = str.toDouble(); stream>>str; double width = str.toDouble(); stream>>str; double height = str.toDouble(); stream>>str; int color = str.toInt(); stream>>str; int type = str.toInt(); addBlock(QRectF(x,y,width,height), QColor(Qt::GlobalColor(color)), BlockType(type));; } }
void QNEMainWindow::createMenuBar(void) { QAction *saveXMLAct = new QAction(tr("&Export XML"), this); saveXMLAct->setShortcuts(QKeySequence::SaveXML); saveXMLAct->setStatusTip(tr("Save a file")); connect(saveXMLAct, SIGNAL(triggered()), this, SLOT(saveXML())); QAction *quitAct = new QAction(tr("&Quit"), this); quitAct->setShortcuts(QKeySequence::Quit); quitAct->setStatusTip(tr("Quit the application")); connect(quitAct, SIGNAL(triggered()), qApp, SLOT(quit())); QAction *loadAct = new QAction(tr("&Load"), this); loadAct->setShortcuts(QKeySequence::Open); loadAct->setStatusTip(tr("Open a file")); connect(loadAct, SIGNAL(triggered()), this, SLOT(loadFile())); QAction *saveAct = new QAction(tr("&Save"), this); saveAct->setShortcuts(QKeySequence::Save); saveAct->setStatusTip(tr("Save a file")); connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile())); QAction *addAct = new QAction(tr("&Add"), this); addAct->setStatusTip(tr("Add a block")); connect(addAct, SIGNAL(triggered()), this, SLOT(addBlock())); fileMenu = new QMenu(tr("&File"),this); menuBar = new QMenuBar; fileMenu->addAction(addAct); fileMenu->addAction(loadAct); fileMenu->addAction(saveAct); fileMenu->addAction(saveXMLAct); fileMenu->addSeparator(); fileMenu->addAction(quitAct); setWindowTitle(tr("Node Editor")); menuBar->addMenu(fileMenu); }
void SFCaveGame :: update( int state ) { Game::update( state ); if ( state == STATE_PLAYING ) { if ( nrFrames % 3 == 0 ) score ++; if ( nrFrames % 200 == 0 ) { if ( terrain->getMaxHeight() < sHeight - 100 ) { terrain->increaseMaxHeight( 10 ); // Reduce block height if ( terrain->getMaxHeight() > sHeight - 150 ) blockHeight -= 5; } } if ( checkCollisions() ) { parent->changeState( STATE_CRASHING ); return; } if ( nrFrames % blockDistance == 0 ) addBlock(); // Game logic goes here terrain->moveTerrain( 5 ); moveBlocks( 5 ); player->move( press ); } }
bool IPBlockList::load(const QString& path) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) { Out(SYS_IPF | LOG_NOTICE) << "Cannot open " << path << ": " << file.errorString() << endl; return false; } // Note: the conversion process has sorted the blocks ! int num_blocks = file.size() / sizeof(IPBlock); blocks.reserve(num_blocks); while (!file.atEnd() && blocks.size() < num_blocks) { IPBlock block; if (file.read((char*)&block, sizeof(IPBlock)) == sizeof(IPBlock)) addBlock(block); else break; } Out(SYS_IPF | LOG_NOTICE) << "Loaded " << blocks.size() << " blocked IP ranges" << endl; return true; }
bool BlockPlant::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { uint8_t oldblock; uint8_t oldmeta; /* move the x,y,z coords dependent upon placement direction */ if (!this->translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!ServerInstance->map(map)->getBlock(x, y - 1, z, &oldblock, &oldmeta)) { revertBlock(user, x, y, z, map); return true; } if (newblock != BLOCK_DIRT && newblock != BLOCK_SOIL && newblock != BLOCK_GRASS) { if (this->isBlockEmpty(x, y - 1, z, map) || !this->isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } if (!this->isBlockStackable(oldblock)) { revertBlock(user, x, y, z, map); return true; } } else { if (this->isUserOnBlock(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } } if ((newblock == BLOCK_REED || newblock == ITEM_REED) && (oldblock == BLOCK_GRASS || oldblock == BLOCK_DIRT)) { // TODO : Check for water ServerInstance->map(map)->sendBlockChange(x, y, z, BLOCK_REED, 0); ServerInstance->map(map)->setBlock(x, y, z, BLOCK_REED, 0); addBlock(x, y, z, map); return false; } if (newblock == BLOCK_CACTUS && oldblock != BLOCK_SAND) { revertBlock(user, x, y, z, map); return true; } if ((newblock == BLOCK_YELLOW_FLOWER || newblock == BLOCK_RED_ROSE) && (oldblock != BLOCK_DIRT && oldblock != BLOCK_GRASS)) { revertBlock(user, x, y, z, map); return true; } if ((newblock == ITEM_SEEDS || newblock == BLOCK_CROPS) && (oldblock == BLOCK_SOIL)) { ServerInstance->map(map)->sendBlockChange(x, y, z, BLOCK_CROPS, 0); ServerInstance->map(map)->setBlock(x, y, z, BLOCK_CROPS, 0); addBlock(x, y, z, map); return false; } if ((newblock == ITEM_SEEDS || newblock == BLOCK_CROPS)) { revertBlock(user, x, y, z, map); return true; } if (newblock > 255 && (oldblock == BLOCK_DIRT || oldblock == BLOCK_GRASS)) { // Hoe on dirt = Soil ServerInstance->map(map)->sendBlockChange(x, y - 1, z, BLOCK_SOIL, 0); ServerInstance->map(map)->setBlock(x, y - 1, z, BLOCK_SOIL, 0); if (SEEDS_CHANCE >= rand() % 10000) { ServerInstance->map(map)->createPickupSpawn(x, y + 1, z, ITEM_SEEDS, 1, 0, nullptr); } return true; } if (newblock > 255) { revertBlock(user, x, y, z, map); return true; } if ((newblock == BLOCK_BROWN_MUSHROOM || newblock == BLOCK_RED_MUSHROOM) && oldblock != BLOCK_DIRT) { revertBlock(user, x, y, z, map); return true; } if (newblock == BLOCK_SAPLING) { ServerInstance->map(map)->addSapling(user, x, y, z); } else { ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), 0); ServerInstance->map(map)->setBlock(x, y, z, char(newblock), 0); addBlocks(x, y, z, map); } return false; }
void Source::addSource(float x, float y, float z, int proba) { addBlock(x, y, z, Engine::BlockType::Source, proba); }
foreach (QString block, blockDevices()) { addBlock(block); }
void EditLayer::onMessage( unsigned int type, unsigned long param1, unsigned long param2 ) { switch (type) { case MSG_DELETESELECTED: deleteSelected(); break; case MSG_CHANGEITEMTYPE: changeEnemyType(param1, param2); break; case MSG_CHANGEITEMRINGTYPE: changeEnemyRingType(param1, param2); break; case MSG_CHANGEBOXTYPE: changeBlockBoxType(param1, param2); break; case MSG_CHANGESELECTED: { hidePropertyLayer(); hideBlockBoxPropertyLayer(); int old_sel = param1; int new_sel = param2; Node* pNode = this->getChildByTag(old_sel); if (pNode) pNode->removeChildByTag(TAG_SELECTED_RECT); Sprite* pSelected = dynamic_cast<Sprite*>(this->getChildByTag(new_sel)); if (pSelected) drawSelectedRect(pSelected); } break; case MSG_ADDBLOCK: { switch (param1) { case kBlockBox: addBlock(Vec2(200, 200)); break; case kBlockWheel: addWheel(Vec2(300, 300)); break; case kBlockVortex: addVortex(Vec2(400, 400)); break; case kBlockBomb: addBomb(Vec2(500, 500)); break; default: break; } } break; case MSG_ADDENEMYITEM: addEnemy(BallBase::kTypeNormal1, Vec2(100, 100), BallBase::kTypeBulletUnknown); break; case MSG_SAVESTAGE: { _sectionId = param1; _stageId = param2; save(); } break; case MSG_SETBULLETCOUNT: { _bulletCounter[param1] = param2; updateBulletCount(); } break; default: break; } }
void BlockPlant::addBlocks(int x, int y, int z, int map) { addBlock(x - 1, y, z, map); addBlock(x + 1, y, z, map); addBlock(x, y - 1, z, map); addBlock(x, y + 1, z, map); addBlock(x, y, z - 1, map); addBlock(x, y, z + 1, map); addBlock(x - 1, y, z - 1, map); addBlock(x - 1, y, z + 1, map); addBlock(x + 1, y, z - 1, map); addBlock(x + 1, y, z + 1, map); addBlock(x + 1, y + 1, z, map); addBlock(x - 1, y + 1, z, map); addBlock(x, y + 1, z + 1, map); addBlock(x, y + 1, z - 1, map); addBlock(x + 1, y - 1, z, map); addBlock(x - 1, y - 1, z, map); addBlock(x, y - 1, z + 1, map); addBlock(x, y - 1, z - 1, map); }
QNEMainWindow::QNEMainWindow(QWidget *parent) : QMainWindow(parent) { scene = new QGraphicsScene(); QAction *quitAct = new QAction(tr("&Quit"), this); quitAct->setShortcuts(QKeySequence::Quit); quitAct->setStatusTip(tr("Quit the application")); connect(quitAct, SIGNAL(triggered()), qApp, SLOT(quit())); QAction *loadAct = new QAction(tr("&Load"), this); loadAct->setShortcuts(QKeySequence::Open); loadAct->setStatusTip(tr("Open a file")); connect(loadAct, SIGNAL(triggered()), this, SLOT(loadFile())); QAction *saveAct = new QAction(tr("&Save"), this); saveAct->setShortcuts(QKeySequence::Save); saveAct->setStatusTip(tr("Save a file")); connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile())); QAction *addAct = new QAction(tr("&Add"), this); addAct->setStatusTip(tr("Add a block")); connect(addAct, SIGNAL(triggered()), this, SLOT(addBlock())); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(addAct); fileMenu->addAction(loadAct); fileMenu->addAction(saveAct); fileMenu->addSeparator(); fileMenu->addAction(quitAct); setWindowTitle(tr("Node Editor")); QDockWidget *dock = new QDockWidget(tr("Nodes"), this); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); view = new QGraphicsView(dock); view->setScene(scene); view->setRenderHint(QPainter::Antialiasing, true); dock->setWidget(view); addDockWidget(Qt::LeftDockWidgetArea, dock); nodesEditor = new QNodesEditor(this); nodesEditor->install(scene); QNEBlock *b = new QNEBlock(0); scene->addItem(b); b->addPort("test", 0, QNEPort::NamePort); b->addPort("TestBlock", 0, QNEPort::TypePort); b->addInputPort("in1"); b->addInputPort("in2"); b->addInputPort("in3"); b->addOutputPort("out1"); b->addOutputPort("out2"); b->addOutputPort("out3"); b = b->clone(); b->setPos(150, 0); b = b->clone(); b->setPos(150, 150); }
void Blocks::handle_logics( bool demo ){ Block *ibl,*delaux; for( ibl = FirstBlock->next; ibl != LastBlock; ibl = ibl->next ) { while( ibl->next != LastBlock && ibl->next->delme ) { delaux = ibl->next; ibl->next = ibl->next->next; delete delaux; } if( demo == false ) { if( ibl->rect.getPosition().y < shFloor.getPosition().y ) //+ ibl->rect.getSize().y { ibl->rect.move( 0,SpeedTimes ); } else { ibl->delme = true; if( !countScore && ibl->rect.getPosition().y > SCREEN_HEIGHT - shBlockMain.getSize().y - 50 ) countScore = true; } } else { if( ibl->rect.getPosition().y > shFloor.getPosition().y + shFloor.getSize().y ) ibl->delme = true; else ibl->rect.move( 0,SpeedTimes ); } } ///Increase Blocks Nr if( BlockIncTimesClock.getElapsedTime().asMilliseconds() > TRANS_BlockTimes && !demo ) if( BlocksTimes < MAX_BlockTimes ) { BlocksTimes ++; BlockIncTimesClock.restart(); } ///Increase Block Falling Speed if( SpeedIncTimesClock.getElapsedTime().asMilliseconds() > TRANS_SpeedTimes && !demo ) { SpeedTimes += cscr_rap_h; SpeedIncTimesClock.restart(); move_speed += cscr_rap_h; } ///Add Blocks Row if( BlockSpawnClock.getElapsedTime().asMilliseconds() > AddBlockDelay/SpeedTimes && !WIN ) { int i,nr; //nr = BlocksTimes + rand()%(10-BlocksTimes) ; nr = rand()%BlocksTimes + 1; for( i = 0; i < nr; i++ ) addBlock( rand()%10*100*cscr_rap_w ,- 100 ); BlockSpawnClock.restart(); } if( LookDir == RIGHT ) shTail.setPosition( shBlockMain.getPosition().x - shTail.getSize().x ,shBlockMain.getPosition().y + 30 ); else shTail.setPosition( shBlockMain.getPosition().x + shBlockMain.getSize().x ,shBlockMain.getPosition().y + 30 ); }
bool Memory::addBlockByName(const std::string &name) { if (name == "frame_info") return addBlock(name,new FrameInfoBlock(0,0,MEMORY_ROBOT)); if (name == "vision_frame_info") return addBlock(name,new FrameInfoBlock(0,0,MEMORY_ROBOT)); else if (name == "body_model") return addBlock(name,new BodyModelBlock()); else if (name == "graphable") return addBlock(name,new GraphableBlock()); // joints else if (name == "raw_joint_angles") return addBlock(name,new JointBlock()); else if (name == "processed_joint_angles") return addBlock(name,new JointBlock()); // commands else if (name == "raw_joint_commands") return addBlock(name,new JointCommandBlock()); else if (name == "processed_joint_commands") return addBlock(name,new JointCommandBlock()); // sensors else if (name == "raw_sensors") return addBlock(name,new SensorBlock()); else if (name == "processed_sensors") return addBlock(name,new SensorBlock()); // Sim else if (name == "sim_effectors") return addBlock(name, new SimEffectorBlock()); // motion else if (name == "walk_engine") return addBlock(name,new WalkEngineBlock()); else if (name == "walk_request") return addBlock(name,new WalkRequestBlock()); // odometry for localization (includes kick, walk, fall info) else if (name == "odometry") return addBlock(name,new OdometryBlock()); else { std::cerr << "Memory::addBlockByName: Error: Unknown memory block for name: " << name << std::endl << std::flush; return false; } }
bool Game1::init() { if (!Layer::init()) { return false; } padding = 70; counts = 25; flag = 0; //The Size seting. auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); //Keyboard seting. this->setKeyboardEnabled(true); this->setKeypadEnabled(true); //create the background auto BackgroundSprite = Sprite::create("Game/Level_1/background.png"); BackgroundSprite->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); addChild(BackgroundSprite); //create the bound. edgeSp = Sprite::create(); auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PhysicsMaterial(1.0f, 1.0f, 0.0f), 3); edgeSp->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2)); edgeSp->setTag(0); edgeSp->setPhysicsBody(boundBody); this->addChild(edgeSp); //create the ball ba = Ball::create(); ba->bindSprite(Sprite::create("Game/Level_1/ball.png")); this->addChild(ba); ball = ba->getSprite(); ball->setPosition(100, 100); auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width / 2, PhysicsMaterial(1.0f, 1.0f, 0.0f)); ballBody->setGravityEnable(false); Vect force = Vect(40000.0f, 40000.0f); ballBody->applyImpulse(force); ballBody->setCategoryBitmask(0x0001); ballBody->setCollisionBitmask(0x0001); ballBody->setContactTestBitmask(0x0001); ball->setPhysicsBody(ballBody); ball->setTag(1); //create the paddle. pa = Paddle::create(); pa->bindSprite(Sprite::create("Game/Level_1/paddle.png")); paddle = pa->getSprite(); this->addChild(pa); auto paddleBody = PhysicsBody::createBox(paddle->getContentSize(), PhysicsMaterial(10.0f, 1.0f, 0.0f)); paddleBody->setGravityEnable(false); paddleBody->setDynamic(false); paddle->setPhysicsBody(paddleBody); paddle->setTag(2); paddle->setPosition(visibleSize.width / 2, visibleSize.height * 0.05); //add the pink block. Sprite* block; bl = Block::create(); bl->bindSprite(Sprite::create("block/block4.png")); this->addChild(bl); block = bl->getSprite(); auto blockBody = PhysicsBody::createBox(block->getContentSize(), PhysicsMaterial(10.0f, 1.0f, 0.0f)); blockBody->setDynamic(false); blockBody->setCategoryBitmask(0x0001); blockBody->setCollisionBitmask(0x0001); blockBody->setContactTestBitmask(0x0001); block->setPhysicsBody(blockBody); block->setTag(10); for (int j = 0; j < 5; j++) { int Xoffset = 120; for (int i = 0; i < 5; i++) { Xoffset = padding + Xoffset; if (j == 4 && i == 4) { block->setPosition(Vec2(Xoffset, visibleSize.height*0.8 - j * 70)); } else { addBlock(Vec2(Xoffset, visibleSize.height*0.8 - j * 70)); } } } this->schedule(schedule_selector(Game1::callback4)); //add the pause btn. auto item1 = MenuItemImage::create("Game/btn_pause.png", "Game/btn_pause.png",CC_CALLBACK_1(Game1::call, this)); auto menu = Menu::create(item1, NULL); menu->setPosition(Vec2(visibleSize.width * 0.9, visibleSize.height * 0.95)); addChild(menu, 1); //eventlistener auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(Game1::onContactBegin, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this); return true; }
BlkModel::BlkModel(const BlkModel& rhs) { Blocks blocks = const_cast<BlkModel&>(rhs).blocks(); for (Blocks::iterator it = blocks.begin(); it != blocks.end(); ++it) addBlock(it->first, it->second); }
void GameScene::initGame() { blockVertexShader=new QGLShader(QGLShader::Vertex); blockVertexShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/block.vsh")); blockFragmentShader=new QGLShader(QGLShader::Fragment); blockFragmentShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/block.fsh")); blockProgram=new QGLShaderProgram; blockProgram->addShader(blockVertexShader); blockProgram->addShader(blockFragmentShader); if(!blockProgram->link()){ qWarning("Failed to compile and link shader program"); qWarning("Vertex shader log:"); qWarning() << blockVertexShader->log(); qWarning() << blockFragmentShader->log(); qWarning("Shader program log:"); qWarning() << blockProgram->log(); QMessageBox::warning(0,tr("错误"),tr("着色器程序加载失败造成游戏无法正常启动\n" "请联系开发者寻求解决方案"),QMessageBox::Ok); exit(1); } lineVertexShader=new QGLShader(QGLShader::Vertex); lineVertexShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/line.vsh")); lineFragmentShader=new QGLShader(QGLShader::Fragment); lineFragmentShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/line.fsh")); lineProgram=new QGLShaderProgram; lineProgram->addShader(lineVertexShader); lineProgram->addShader(lineFragmentShader); if(!lineProgram->link()){ qWarning("Failed to compile and link shader program"); qWarning("Vertex shader log:"); qWarning() << lineVertexShader->log(); qWarning() << lineFragmentShader->log(); qWarning("Shader program log:"); qWarning() << lineProgram->log(); QMessageBox::warning(0,tr("错误"),tr("着色器程序加载失败造成游戏无法正常启动\n" "请联系开发者寻求解决方案"),QMessageBox::Ok); exit(1); } //////////////////////////// camera=new Camera(QVector3D(0,4,0),QPointF(180.0,0.0)); world=new World; wThread=new QThread; world->moveToThread(wThread); connect(wThread,SIGNAL(finished()),world,SLOT(deleteLater())); //线程被销毁的同时销毁world connect(this,SIGNAL(reloadWorld()),world,SLOT(forcedUpdateWorld())); //强制进行世界刷新 connect(camera,SIGNAL(cameraMove(QVector3D)),world,SLOT(changeCameraPosition(QVector3D))); //连接camera移动与世界相机位移的槽 connect(this,SIGNAL(resetRenderLen()),world,SLOT(updateWorld())); connect(this,SIGNAL(addBlock()),camera,SLOT(addBlock())); connect(this,SIGNAL(removeBlock()),camera,SLOT(removeBlock())); connect(world,SIGNAL(loadOver()),this,SLOT(loadOverSlot())); wThread->start(); // world->setMaxRenderLen(maxRenderLen); world->setWorldName("new_world"); camera->setWorld(world); //传递世界指针 /////////////////////////// //这里是一个规定的加载顺序,后步骤会依赖于前步骤 world->loadBlockIndex(); //加载方块属性列表 loadTexture(); //加载纹理 //====================== line=new LineMesh(2); //十字准心 float lineLen=0.0004; line->addLine(QVector3D(-lineLen,0,-0.02),QVector3D(lineLen,0,-0.02)); line->addLine(QVector3D(0,-lineLen,-0.02),QVector3D(0,lineLen,-0.02)); lineQua=new LineMesh(12); //被选方块的包围线框 //======================= //数据面板 dataPanel=new DataPanel(0,0,200,100); addItem(dataPanel); glFps=0; drawCount=0; dataPanel->setRenderLen(maxRenderLen); connect(camera,SIGNAL(getPositions(QVector3D,QVector3D)),this,SLOT(dataShowPosition(QVector3D,QVector3D))); // dataPanel->hide(); //背包物品栏 backPackBar=new BackPackBar(this); hideBackPackBar(); backPackBar->setWorld(world); //传递world指针 //物品栏 itemBar=new ItemBar(this); connect(itemBar,SIGNAL(thingIndexChange(int)),camera,SLOT(setBlockId(int))); backPackBar->setPocket(itemBar); //======================= //消息面板 messagePanel=new MessagePanel; addItem(messagePanel); //=========================== //选项菜单 opWidget=new OptionsWidget(); opWidgetProxy=new QGraphicsProxyWidget(0); opWidgetProxy->setWidget(opWidget); this->addItem(opWidgetProxy); opWidgetProxy->hide(); inOpWidget=false; connect(opWidget,SIGNAL(continueGame()),this,SLOT(continueGame())); connect(opWidget,SIGNAL(mouseLevelValueChange(int)),camera,SLOT(setMouseLevel(int))); connect(opWidget,SIGNAL(renderValueChange(int)),this,SLOT(setRenderLen(int))); connect(opWidget,SIGNAL(quitClick()),gView,SLOT(close())); //============================= loadSettings(); camera->loadPosRot(); //加载位置视角信息 setRenderLen(maxRenderLen); //设置渲染距离并刷新整个世界 opWidget->setRenderLen(maxRenderLen); opWidget->setMouseLevel(camera->getMouseLevel()); }
void GameState::addMapBody(const Map::Node& n) { switch (n.type) { case Category::Block: addBlock(n.position, n.size); break; case Category::Solid: { auto node = std::make_unique<Node>(); node->setPosition(n.position); node->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Solid, n.size)); m_scene.addNode(node, Scene::Solid); } break; case Category::Water: { auto node = std::make_unique<Node>(); node->setPosition(n.position); auto drawable = static_cast<WaterDrawable*>(m_mapController.getDrawable(MapController::MapDrawable::Water)); drawable->setSize(n.size); node->setDrawable(drawable); node->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Water, n.size)); node->addObserver(m_particleController); m_scene.addNode(node, Scene::Water); } break; case Category::Item: { auto node = std::make_unique<Node>(); node->setPosition(n.position); node->setCategory(Category::Item); node->setDrawable(m_mapController.getDrawable(MapController::MapDrawable::Item)); node->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Item, n.size)); node->addObserver(m_particleController); node->addObserver(m_audioController); auto light = m_scene.addLight(sf::Vector3f(0.34f, 0.96f, 1.f), 400.f); if (light) { light->setDepth(50.f); node->setLight(light); } node->setBlendMode(sf::BlendAdd); m_scene.addNode(node, Scene::DynamicFront); } break; case Category::Light: { auto node = std::make_unique<Node>(); node->setCategory(Category::Light); //TODO magix0r numb0rz auto light = m_scene.addLight(colourToVec3(n.colour), 700.f); light->setDepth(50.f); node->setLight(light); node->setPosition(n.position + (n.size / 2.f)); node->addObserver(*light); node->setDrawable(&lightDrawable); node->setBlendMode(sf::BlendAlpha); //if (n.anchorOffset) //TODO make not broken (see contraint solve()) //{ // //we want a constraint on this light // node->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Type::FreeForm, { lightDrawable.getRadius(), lightDrawable.getRadius() })); // auto anchorNode = std::make_unique<Node>(); // anchorNode->setPosition(n.position); // anchorNode->move(0.f, -n.anchorOffset); // anchorNode->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Type::Anchor, { lightDrawable.getRadius(), lightDrawable.getRadius() })); // anchorNode->setDrawable(&c1); // m_collisionWorld.addConstraint(anchorNode->getCollisionBody(), node->getCollisionBody(), n.anchorOffset); // m_scene.addNode(anchorNode); //} m_scene.addNode(node, Scene::Background); break; } case Category::HatDropped: { auto node = std::make_unique<Node>(); node->setPosition(n.position); node->setDrawable(m_mapController.getDrawable(MapController::MapDrawable::Hat)); node->setCollisionBody(m_collisionWorld.addBody(CollisionWorld::Body::Type::FreeForm, n.size)); node->setCategory(n.type); auto light = m_scene.addLight(sf::Vector3f(1.f, 0.9f, 0.f), 200.f); light->setDepth(50.f); node->setLight(light); node->addObserver(m_particleController); node->addObserver(m_audioController); node->addObserver(m_mapController); node->addObserver(m_scoreBoard); node->addObserver(m_players[0]); node->addObserver(m_players[1]); m_scene.addNode(node, Scene::DynamicFront); break; } case Category::Bat: case Category::Bird: { auto node = std::make_unique<Node>(); node->setPosition(n.position); node->setCategory(n.type); node->setDrawable(m_mapController.getDrawable((n.type == Category::Bat) ? MapController::MapDrawable::Bat : MapController::MapDrawable::Bird)); m_scene.addNode(node, Scene::FrontDetail); break; } default: break; } }