void Serializable::initWithParseNode(const parse::Node* n) { for(vector<parse::Node*>::const_iterator itr = n->children.begin(); itr!=n->children.end(); itr++) { const parse::Node* node = *itr; if(node->type == parse::kString && node->data.value!=NULL) handleChild(node); } }
int main(int argc, char *argv[]) { pid_t pid = fork(); if (pidIsFailed(pid)) { handleFailed(argc, argv); } if (pidIsChild(pid)) { handleChild(argc, argv); } if (pidIsParent(pid)) { handleParent(argc, argv); } fprintf(stderr, "Something wrong."); exit(EXIT_FAILURE); }
// fork manager void executeInputLine(char* line) { pid_t pid = fork(); if (pidIsFailed(pid)) { return handleFailed(line); } if (pidIsChild(pid)) { return handleChild(line); } if (pidIsParent(pid)) { return handleParent(line); } fprintf(stderr, "Something wrong."); exit(EXIT_FAILURE); }
void WorldGenerator::createChunk(ow::Chunk& chunk, sf::Vector2i pos) { if (mMap == nullptr) { #ifdef OW_DEBUG std::cout << "ChunkGenerator: hasn't any Map" << std::endl; #endif // OW_DEBUG return; } chunk.setTileset(mMap->getTileset(mDefaultTileset)); chunk.setPos(pos); chunk.clearLayers(); chunk.addLayer(); fill(chunk,mWaterId,0); std::vector<sf::Vector2i> transformed; std::vector<sf::Vector2i> checkList; unsigned int tileLimit = chunk.getSize().x * chunk.getSize().y * mPercentGrassOverWater / 100; bool neighboorsHandled = neighboorsChunks(pos,checkList,transformed,chunk); bool transformingDone = false; while (!transformingDone) { // if neighboors handled or no neighboors if (neighboorsHandled) { sf::Vector2i firstTile; firstTile.x = rand() % chunk.getSize().x; firstTile.y = rand() % chunk.getSize().y; transformed.push_back(firstTile); checkList.push_back(firstTile); chunk.getLayer(0)->setTileId(firstTile.x,firstTile.y,mSandId); } while (!checkList.empty()) { sf::Vector2i parentTile = checkList[0]; if (parentTile.x > 0) // left child handleChild(sf::Vector2i(parentTile.x-1,parentTile.y),checkList,transformed,chunk); if (parentTile.y > 0) // upper child handleChild(sf::Vector2i(parentTile.x,parentTile.y-1),checkList,transformed,chunk); if (parentTile.x < chunk.getSize().x -1) // right child handleChild(sf::Vector2i(parentTile.x+1,parentTile.y),checkList,transformed,chunk); if (parentTile.y < chunk.getSize().y -1) // lower child handleChild(sf::Vector2i(parentTile.x,parentTile.y+1),checkList,transformed,chunk); // End of the loop tasks & checks checkList.erase(checkList.begin()); if (neighboorsHandled && transformed.size() >= tileLimit) { checkList.clear(); transformingDone = true; } } if (!neighboorsHandled) { neighboorsHandled = true; } } for (unsigned int i = 0; i < transformed.size(); i++) { sf::Vector2i tile = transformed[i]; if (((tile.x > 0 && chunk.getLayer(0)->getTileId(tile.x-1,tile.y) != mWaterId) && (tile.y > 0 && chunk.getLayer(0)->getTileId(tile.x,tile.y-1) != mWaterId) && (tile.x < chunk.getSize().x-1 && chunk.getLayer(0)->getTileId(tile.x+1,tile.y) != mWaterId) && (tile.y < chunk.getSize().y-1 && chunk.getLayer(0)->getTileId(tile.x,tile.y+1) != mWaterId)) || tile.x == 0 || tile.y == 0 || tile.x == chunk.getSize().x -1 || tile.y == chunk.getSize().y -1) { chunk.getLayer(0)->setTileId(tile.x,tile.y,mGrassId); } } chunk.saveToFile(mMap->getDirectory() + std::to_string(pos.x) + "_" + std::to_string(pos.y) + ".chunk"); }