void Layer::ParseXML(const TiXmlNode *dataNode) { const TiXmlNode *tileNode = dataNode->FirstChild("tile"); int tileCount = 0; while (tileNode) { const TiXmlElement *tileElem = tileNode->ToElement(); unsigned gid = 0; // Read the Global-ID of the tile. const char* gidText = tileElem->Attribute("gid"); // Convert to an unsigned. sscanf(gidText, "%u", &gid); // Find the tileset index. const int tilesetIndex = map->FindTilesetIndex(gid); if (tilesetIndex != -1) { // If valid, set up the map tile with the tileset. const Tmx::Tileset* tileset = map->GetTileset(tilesetIndex); tile_map[tileCount] = MapTile(gid, tileset->GetFirstGid(), tilesetIndex); } else { // Otherwise, make it null. tile_map[tileCount] = MapTile(gid, 0, -1); } tileNode = dataNode->IterateChildren("tile", tileNode); tileCount++; } }
void Layer::ParseCSV(const std::string &innerText) { // Duplicate the string for use with C stdio. char *csv = strdup(innerText.c_str()); // Iterate through every token of ';' in the CSV string. char *pch = strtok(csv, ","); int tileCount = 0; while (pch) { unsigned gid; sscanf(pch, "%u", &gid); // Find the tileset index. const int tilesetIndex = map->FindTilesetIndex(gid); if (tilesetIndex != -1) { // If valid, set up the map tile with the tileset. const Tmx::Tileset* tileset = map->GetTileset(tilesetIndex); tile_map[tileCount] = MapTile(gid, tileset->GetFirstGid(), tilesetIndex); } else { // Otherwise, make it null. tile_map[tileCount] = MapTile(gid, 0, -1); } pch = strtok(NULL, ","); tileCount++; } free(csv); }
void Layer::ParseBase64(const std::string &innerText) { const std::string &text = Util::DecodeBase64(innerText); // Temporary array of gids to be converted to map tiles. unsigned *out = 0; if (compression == TMX_COMPRESSION_ZLIB) { // Use zlib to uncompress the layer into the temporary array of tiles. uLongf outlen = width * height * 4; out = (unsigned *)malloc(outlen); uncompress( (Bytef*)out, &outlen, (const Bytef*)text.c_str(), text.size()); } else if (compression == TMX_COMPRESSION_GZIP) { // Use the utility class for decompressing (which uses zlib) out = (unsigned *)Util::DecompressGZIP( text.c_str(), text.size(), width * height * 4); } else { out = (unsigned *)malloc(text.size()); // Copy every gid into the temporary array since // the decoded string is an array of 32-bit integers. memcpy(out, text.c_str(), text.size()); } // Convert the gids to map tiles. for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { unsigned gid = out[y * width + x]; // Find the tileset index. const int tilesetIndex = map->FindTilesetIndex(gid); if (tilesetIndex != -1) { // If valid, set up the map tile with the tileset. const Tmx::Tileset* tileset = map->GetTileset(tilesetIndex); tile_map[y * width + x] = MapTile(gid, tileset->GetFirstGid(), tilesetIndex); } else { // Otherwise, make it null. tile_map[y * width + x] = MapTile(gid, 0, -1); } } } // Free the temporary array from memory. free(out); }
MapGenerator::MapGenerator(char size_n, int seed, double rough) : _size(pow(2, size_n)), _seed(seed), _rough(rough), _height_map(_size, _size, seed, rough) { _hm.reserve(sizeof(std::vector<int>) * _size); for(int i = 0; i < _size; i++) { std::vector<MapTile> row; row.reserve(sizeof(int)*_size); for(int j = 0; j < _size; j++) row.push_back(MapTile()); _hm.push_back(row); } std::cout << "Generating map of dimensions " << _hm.size() << "x" << _hm.at(0).size() << std::endl; _rng.seed(seed); noise::module::Perlin* rain_map = new noise::module::Perlin; rain_map->SetSeed(seed); rain_map->SetFrequency(0.05); _humidity_map = noise::model::Plane(*curve_modifier(clamp_modifier(rain_map), [](double x){return (pow(x, 3) + x + 2)/4;})); noise::module::Perlin* temp_map = new noise::module::Perlin; temp_map->SetSeed(seed *123653); temp_map->SetFrequency(0.01); _temprature_map = noise::model::Plane(*curve_modifier(clamp_modifier(temp_map), [](double x) {return (pow(x, 3) + x + 2)/4;})); }
void Map::fromStream(std::istream& stream) { if (m_data != NULL) { delete[] m_data; } m_data = NULL; m_size = Point(0, 0); stream>>m_size.x>>m_size.y; m_size.x += 2; m_size.y += 2; m_data = new MapTile[m_size.x * m_size.y]; for(unsigned x = 0; x < unsigned(m_size.x); ++x) { data(x, 0) = WALL; data(x, m_size.y-1) = WALL; } for(unsigned y = 0; y < unsigned(m_size.y); ++y) { data(0, y) = WALL; data(m_size.x - 1, y) = WALL; } unsigned tile; for(unsigned y = 1; y < unsigned(m_size.y) - 1; ++y) { for(unsigned x = 1; x < unsigned(m_size.x) - 1; ++x) { stream>>tile; data(x, y) = MapTile(tile); } } }
void TileLoader::start() { // discard previous set of tiles and all pending requests abort(); qnam_ = new QNetworkAccessManager(this); QObject::connect(qnam_, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedRequest(QNetworkReply *))); // determine what range of tiles we can load const int min_x = std::max(0, tile_x_ - blocks_); const int min_y = std::max(0, tile_y_ - blocks_); const int max_x = std::min(maxTiles(), tile_x_ + blocks_); const int max_y = std::min(maxTiles(), tile_y_ + blocks_); // initiate requests for (int y = min_y; y <= max_y; y++) { for (int x = min_x; x <= max_x; x++) { const QUrl uri = uriForTile(x, y); // send request const QNetworkRequest request = QNetworkRequest(uri); QNetworkReply *rep = qnam_->get(request); emit initiatedRequest(request); tiles_.push_back(MapTile(x, y, rep)); } } }
void TileLoader::start() { // discard previous set of tiles and all pending requests abort(); ROS_INFO("loading %d blocks around tile=(%d,%d)", blocks_, center_tile_x_, center_tile_y_ ); qnam_.reset( new QNetworkAccessManager(this) ); QObject::connect(qnam_.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedRequest(QNetworkReply *))); // determine what range of tiles we can load const int min_x = std::max(0, center_tile_x_ - blocks_); const int min_y = std::max(0, center_tile_y_ - blocks_); const int max_x = std::min(maxTiles(), center_tile_x_ + blocks_); const int max_y = std::min(maxTiles(), center_tile_y_ + blocks_); // initiate requests for (int y = min_y; y <= max_y; y++) { for (int x = min_x; x <= max_x; x++) { // Generate filename const QString full_path = cachedPathForTile(x, y, zoom_); // Check if tile is already in the cache QFile tile(full_path); if (tile.exists()) { QImage image(full_path); tiles_.push_back(MapTile(x, y, zoom_, image)); } else { const QUrl uri = uriForTile(x, y, zoom_); // send request const QNetworkRequest request = QNetworkRequest(uri); QNetworkReply *rep = qnam_->get(request); emit initiatedRequest(request); tiles_.push_back(MapTile(x, y, zoom_, rep)); } } } checkIfLoadingComplete(); }
void LocalMap::generate(weak_ptr<AStarSearch> pf, weak_ptr<EventService> ev) { _events = ev; _pFinder = pf; _actor = make_shared<Actor>(_res->getObjectID("actor"), Point(54, 54), 24); srand((unsigned)time(NULL)); _rowmax = TD_MAP_ROWS; _colmax = TD_MAP_COLS; _xmax = _colmax * TILE_MASK; for (unsigned row = 0; row < _rowmax; row++){ for (unsigned col = 0; col < _colmax; col++){ _tiles.push_back(MapTile(8 + (rand() % 6))); } } unsigned pRow = 0, pCol = 0; pRow += rand() % 7; while (pRow < _rowmax){ pCol += rand() % 15; while (pCol < _colmax){ _tiles[pRow * _colmax + pCol].setType(47); pCol += rand() % 15; } pRow += rand() % 7; pCol = 0; } // tree generation (sprite 79) int objMaxDensity = 10; // 10% max int randOffset = 0; //_objects.reserve(_rowmax * _colmax / 100); _objects.setObject(make_shared<MapObject>(_res->getObjectID("hut"), Point(150, 150))); _objects.setObject(make_shared<MapObject>(_res->getObjectID("hide"), Point(80, 90))); _objects.setObject(make_shared<SmartActor>(_res->getObjectID("actor"), Point(110, 110), 24, _events)); int reetID = _res->getObjectID("reet"); for (unsigned row = 0; row < _rowmax; row += 10){ for (unsigned col = 0; col < _colmax; col += 10){ for (int k = 0; k < objMaxDensity; k++){ randOffset = rand() % 100; Point objPos((col + (randOffset % 10)) * TILE_MASK, (row + (randOffset / 10)) * TILE_MASK); cout << "OBJ: " << col + (randOffset % 10) << "," << row + (randOffset / 10); cout << " >> " << objPos._x << "," << objPos._y << " Prio: " << objPos.toRenderPriority() << endl; _objects.setObject(make_shared<MapObject>(reetID, objPos)); } } } _ready = true; }
void Layer::ParseBase64(const std::string &innerText) { const std::string &text = Util::DecodeBase64(innerText); // Temporary array of gids to be converted to map tiles. int *out = 0; if (compression == TMX_COMPRESSION_ZLIB) { // Use zlib to uncompress the layer into the temporary array of tiles. uLongf outlen = width * height * 4; out = (int *)malloc(outlen); uncompress( (Bytef*)out, &outlen, (const Bytef*)text.c_str(), text.size()); } else if (compression == TMX_COMPRESSION_GZIP) { // Use the utility class for decompressing (which uses zlib) out = (int*)Util::DecompressGZIP( text.c_str(), text.size(), width * height * 4); } else { out = (int*)malloc(text.size()); // Copy every gid into the temporary array since // the decoded string is an array of 32-bit integers. memcpy(out, text.c_str(), text.size()); } // Convert the gids to map tiles. for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tile_map[y * width + x] = MapTile(out[y * width + x]); } } // Free the temporary array from memory. free(out); }
void Map::InitToField(int width, int height, int tileMaterial) { std::vector<MapTile> mapColumn(height, MapTile(0)); std::vector<std::vector<MapTile> > mapRow(width, mapColumn); tile = mapRow; int r = rng::Rand(4); //int r = rng::rand(4); for(int x = 0; x < width; x++) for(int y=0; y < height; y++) { int r = rng::Rand(4); tile[x][y].variant = r; } }
void MapRoom::clearMap() { for (int i=0; i < m_xSize; i++) { for (int j=0; j < m_ySize; j++) { for( int k=0; k < m_zSize; k++) { m_map[index(i,j,k)] = MapTile(); } } } m_enemies.clear(); m_items.clear(); m_message1 = ""; m_message2 = ""; }
void Layer::ParseCSV(const std::string &innerText) { // Duplicate the string for use with C stdio. char *csv = strdup(innerText.c_str()); // Iterate through every token of ';' in the CSV string. char *pch = strtok(csv, ";"); int tileCount = 0; while (pch) { tile_map[tileCount] = MapTile(atoi(pch)); ++tileCount; pch = strtok(NULL, ";"); } free(csv); }
void Layer::ParseXML(const TiXmlNode *dataNode) { const TiXmlNode *tileNode = dataNode->FirstChild("tile"); int tileCount = 0; while (tileNode) { const TiXmlElement *tileElem = tileNode->ToElement(); int gid = 0; // Read the Global-ID of the tile directly into the array entry. tileElem->Attribute("gid", &gid); // Convert the gid to a map tile. tile_map[tileCount++] = MapTile(gid); tileNode = dataNode->IterateChildren("tile", tileNode); } }
void Map::ParseDefine(std::vector<std::string> parts) { if (parts[0] != "define") return; if (parts.size() > 6 && parts[1] == "tile") { std::string texLocation = rootFolder + parts[2]; std::string tilename = parts[3]; sf::Image tileImage; if (!tileImage.LoadFromFile(texLocation)) { std::cout << "ERROR: Could not find texture at: " << texLocation << "." << '\n'; return; } MapTile tempTile = MapTile(&tileImage, tilename); MapTileController::GetSingleton()->AddTile(tempTile); } }
bool MapWidget::addTiles(QStringList const & files) { QSize tileSize = mTileSize; QVector<MapTile> tiles; QStringList list = files; for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QImage im(*it); if (!im.isNull()) { qDebug() << "Loading tile: " << *it << " / " << im.size(); if (tileSize.isEmpty()) { tileSize = im.size(); } else if (tileSize != im.size()) { QMessageBox msg; msg.setInformativeText("Operation canceled due to errors"); QString s = QString("Tile in file %1 have dimensions %2x%3 while expected tile size is %4x%5").arg(*it).arg(im.size().width()).arg(im.size().height()).arg(tileSize.width()).arg(tileSize.height()); msg.setText(s); msg.setIcon(QMessageBox::Critical); msg.exec(); return false; // to do: maybe just throw an exception? } tiles << MapTile(*it, im); } else { QMessageBox msg(QMessageBox::Warning, "Cannot read file", "Failed to read file " + *it); msg.exec(); } } // If succeed if (mTileSize.isEmpty()) mTileSize = tileSize; mTiles += tiles; return true; }
void mapClient::PutEntityAt( entType entity, uint8 x, uint8 y ) { mapClientTile & tile = MapTile(x,y); tile.entity = entity; }
void MapWidget::loadMap(QString const & filename) { // read file QFile qf(filename); if (!qf.open(QIODevice::ReadOnly)) throw qf.errorString(); QByteArray jsn_in = qf.readAll(); qf.close(); if (jsn_in.isEmpty()) throw QString("Empty file"); // parse file QJsonDocument jsn_doc; if (filename.endsWith("json")) { jsn_doc = QJsonDocument::fromJson(jsn_in); } else { jsn_doc = QJsonDocument::fromBinaryData(jsn_in); } if (jsn_doc.isNull()) throw QString("Failed to validate JSON data"); if (!jsn_doc.isObject()) throw QString("Top level JSON value is not an object"); QJsonObject jsn_map = jsn_doc.object(); // load generic map info QJsonObject::const_iterator it; it = jsn_map.find("rows"); if (it == jsn_map.end()) throw QString("File not contains 'rows'"); if (!it.value().isDouble()) throw QString("'rows' is not a number"); int rows = int(it.value().toDouble()); it = jsn_map.find("cols"); if (it == jsn_map.end()) throw QString("File not contains 'cols'"); if (!it.value().isDouble()) throw QString("'cols' is not a number"); int cols = int(it.value().toDouble()); // load tiles FIXME: each key must be in [0; jsn_tiles.size()-1] or assertion happens it = jsn_map.find("tiles"); if (it == jsn_map.end()) throw QString("File not contains 'tiles'"); if (!it.value().isObject()) throw QString("'cells' is not an object"); QJsonObject jsn_tiles = it.value().toObject(); QVector<MapTile> tiles(jsn_tiles.size()); QSize tileSize(-1, -1); int prev_tile_id = -1; for(QJsonObject::const_iterator i = jsn_tiles.begin(); i != jsn_tiles.end(); ++i) { int tile_id = i.key().toInt(); if (tile_id - prev_tile_id != 1) throw QString("Non-monotonic tile keys"); if (!i.value().isString()) throw QString("Incorrect tile's path"); QImage im(i.value().toString()); if (im.isNull()) throw QString("Can't open image"); if (tileSize.isEmpty()) { tileSize = im.size(); } else if (tileSize != im.size()) { throw QString("Tile's dimensions not same"); } tiles[tile_id] = MapTile(i.value().toString(), im); prev_tile_id = tile_id; } // load cells QVector<int> cells(cols * rows); it = jsn_map.find("cells"); if (it == jsn_map.end()) throw QString("File not contains 'cells'"); if (!it.value().isArray()) throw QString("'cells' is not an array"); QJsonArray jsn_cells = it.value().toArray(); if (jsn_cells.size() != cols * rows) throw QString("Incorrect 'cells' length"); int index = -1; for(QJsonArray::const_iterator i = jsn_cells.begin(); i != jsn_cells.end(); ++i) { if (!(*i).isDouble()) throw QString("Not number in 'cells'"); int val = int((*i).toDouble()); if (val < -1 || val >= tiles.size()) throw QString("Incorrect range in 'cells'"); if (val > 0 && false == tiles[val].isValid()) throw QString("Incorrect link in 'cells'"); cells[++index] = val; } // if everything is fine mCells = cells; mTiles = tiles; mRows = rows; mCols = cols; mTileSize = tileSize; mViewportPos = QPointF(.0f, .0f); mCellUnderMouse = QPoint(-1, -1); mSelectionBegin = NULL; mSelectionEnd = NULL; mScale = 1.0f; update(); }
/** * \brief RunModeIdsTileMpipeAuto set up the following thread packet handlers: * - Receive thread (from iface pcap) * - Decode thread * - Stream thread * - Detect: If we have only 1 cpu, it will setup one Detect thread * If we have more than one, it will setup num_cpus - 1 * starting from the second cpu available. * - Respond/Reject thread * - Outputs thread * By default the threads will use the first cpu available * except the Detection threads if we have more than one cpu * * \param de_ctx pointer to the Detection Engine * \param iface pointer to the name of the interface from which we will * fetch the packets * \retval 0 if all goes well. (If any problem is detected the engine will * exit()) */ int RunModeIdsTileMpipeAuto(DetectEngineCtx *de_ctx) { SCEnter(); char tname[32]; char *thread_name; uint16_t cpu = 0; TmModule *tm_module; uint16_t thread; /*uint32_t tile = 1;*/ int pipe; unsigned int poll_n = TileNumPipelinesPerRx; char *detectmode = NULL; int pool_detect_threads = 0; extern TmEcode ReceiveMpipeInit(void); // move this /*SCLogInfo("RunModeIdsTileMpipeAuto\n");*/ if (ConfGet("tile.detect", &detectmode) == 1) { if (detectmode) { SCLogInfo("DEBUG: detectmode %s", detectmode); if (strcmp(detectmode, "pooled") == 0) { pool_detect_threads = 1; } } } RunModeTileMpipeMapCores(); RunModeInitialize(); /* Available cpus */ uint16_t ncpus = UtilCpuGetNumProcessorsOnline(); TimeModeSetLive(); int pipe_max = TileNumPipelines; ReceiveMpipeInit(); char *mpipe_dev = NULL; int nlive = LiveGetDeviceCount(); if (nlive > 0) { char *link_name; int i; SCLogInfo("Using %d live device(s).", nlive); /*mpipe_dev = LiveGetDevice(0);*/ for (i = 0; i < nlive; i++) { MpipeIfaceConfig *aconf; link_name = LiveGetDeviceName(i); aconf = ParseMpipeConfig(link_name); if (aconf != NULL) SCFree(aconf); } } else { /* * Attempt to get interface from config file * overrides -i from command line. */ if (ConfGet("mpipe.interface", &mpipe_dev) == 0) { if (ConfGet("mpipe.single_mpipe_dev", &mpipe_dev) == 0) { SCLogError(SC_ERR_RUNMODE, "Failed retrieving " "mpipe.single_mpipe_dev from Conf"); exit(EXIT_FAILURE); } } } /* * Careful. All of the pickup_queues must be created * prior to building to pipeline so that the queues * are adjacent in the lookup table. This lets the * demux2 queue handler work. */ for (pipe = 0; pipe < pipe_max; pipe++) { sprintf(pickup_queue[pipe], "pickup-queue%d", pipe); if (TmqCreateQueue(pickup_queue[pipe]) == NULL) { SCLogError(SC_ERR_RUNMODE, "Could not create pickup queue"); exit(EXIT_FAILURE); } } for (pipe = 0; pipe < pipe_max; pipe++) { char *mpipe_devc; /* HACK: Receive Threads are shared between pairs of * pipelines. So for every other pipeline create two * queues and spawn only one thread. */ if (nlive > 0) { mpipe_devc = SCStrdup("multi"); } else { mpipe_devc = SCStrdup(mpipe_dev); } //sprintf(pickup_queue[pipe], "pickup-queue%d", pipe); snprintf(tname, sizeof(tname), "ReceiveMpipe%d", pipe+1); thread_name = SCStrdup(tname); /* create the threads */ ThreadVars *tv_receivempipe = TmThreadCreatePacketHandler(thread_name, "packetpool", "packetpool", //pickup_queue[pipe],"simple", pickup_queue[pipe],(poll_n == 2)?"demux2":"simple", "pktacqloop"); if (tv_receivempipe == NULL) { printf("ERROR: TmThreadsCreate failed\n"); exit(EXIT_FAILURE); } tm_module = TmModuleGetByName("ReceiveMpipe"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName failed for ReceiveMpipe\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_receivempipe, tm_module, (void *)mpipe_devc); if ((pipe % poll_n) == 0) { /* set affinity for mpipe */ TmThreadSetCPUAffinity(tv_receivempipe, 1+(pipe/poll_n)); SCLogInfo("Thread %s pipe_max %d pipe %d cpu %d", thread_name, pipe_max, pipe, 1+(pipe/poll_n)); if (TmThreadSpawn(tv_receivempipe) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } } sprintf(stream_queue[pipe], "stream-queue%d", pipe); snprintf(tname, sizeof(tname), "Decode&Stream%d", pipe+1); thread_name = SCStrdup(tname); ThreadVars *tv_decode1 = TmThreadCreatePacketHandler(thread_name, //pickup_queue[pipe],"simple", pickup_queue[pipe],(poll_n==2)?"demux2":"simple", stream_queue[(pool_detect_threads) ? 0 : pipe], (queue_type == simple) ? "simple" : "tmc_mrsw", "varslot"); if (tv_decode1 == NULL) { printf("ERROR: TmThreadCreate failed for Decode1\n"); exit(EXIT_FAILURE); } tm_module = TmModuleGetByName("DecodeMpipe"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName DecodeMpipe failed\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_decode1,tm_module,NULL); tm_module = TmModuleGetByName("StreamTcp"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName StreamTcp failed\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_decode1,tm_module,NULL); //TmThreadSetCPUAffinity(tv_decode1, MapTile(tile++)); TmThreadSetCPUAffinity(tv_decode1, 1+((pipe_max+1)/poll_n)+(pipe*TILES_PER_PIPELINE)); SCLogInfo("Thread %s pipe_max %d pipe %d cpu %d", thread_name, pipe_max, pipe, 1+((pipe_max+1)/poll_n)+(pipe*TILES_PER_PIPELINE)); if (TmThreadSpawn(tv_decode1) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } int thread_max = TileDetectThreadPerPipeline; for (thread = 0; thread < thread_max; thread++) { snprintf(tname, sizeof(tname),"Detect%d-%"PRIu16, pipe+1, thread+1); if (tname == NULL) break; thread_name = SCStrdup(tname); SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu); sprintf(verdict_queue[pipe], "verdict-queue%d", pipe); //#define PIPELINES_PER_OUTPUT 2 #define PIPELINES_PER_OUTPUT 1 ThreadVars *tv_detect_ncpu = TmThreadCreatePacketHandler(thread_name, stream_queue[(pool_detect_threads) ? 0 : pipe], (queue_type == simple) ? "simple" : "tmc_mrsw", #if 1 verdict_queue[pipe/PIPELINES_PER_OUTPUT], (queue_type == simple) ? "simple" : "tmc_srmw", #else "packetpool", "packetpool", #endif "1slot"); if (tv_detect_ncpu == NULL) { printf("ERROR: TmThreadsCreate failed\n"); exit(EXIT_FAILURE); } tm_module = TmModuleGetByName("Detect"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName Detect failed\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_detect_ncpu,tm_module,(void *)de_ctx); //TmThreadSetCPUAffinity(tv_detect_ncpu, MapTile(tile++)); TmThreadSetCPUAffinity(tv_detect_ncpu, 1+((pipe_max+1)/poll_n)+(pipe*TILES_PER_PIPELINE)+thread+1); SCLogInfo("Thread %s pipe_max %d pipe %d cpu %d", thread_name, pipe_max, pipe, 1+((pipe_max+1)/poll_n)+(pipe*TILES_PER_PIPELINE)+thread+1); char *thread_group_name = SCStrdup("Detect"); if (thread_group_name == NULL) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } tv_detect_ncpu->thread_group_name = thread_group_name; if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } if ((cpu + 1) == ncpus) cpu = 0; else cpu++; } #ifdef COMBINE_RESPOND_REJECT_AND_OUTPUT //if ((pipe % PIPELINES_PER_OUTPUT) == 0) { if (1) { snprintf(tname, sizeof(tname), "RR&Output%d", pipe+1); thread_name = SCStrdup(tname); ThreadVars *tv_outputs = TmThreadCreatePacketHandler(thread_name, verdict_queue[pipe/PIPELINES_PER_OUTPUT], (queue_type == simple) ? "simple" : "tmc_srmw", "packetpool", "packetpool", "varslot"); if (tv_outputs == NULL) { printf("ERROR: TmThreadsCreate failed\n"); exit(EXIT_FAILURE); } //TmThreadSetCPUAffinity(tv_outputs, MapTile(tile++)); //TmThreadSetCPUAffinity(tv_outputs, MapTile((pipe_max * TILES_PER_PIPELINE) + (pipe / 2) + 1)); TmThreadSetCPUAffinity(tv_outputs, 1+((pipe_max+1)/poll_n)+(pipe_max*TILES_PER_PIPELINE)+(pipe/PIPELINES_PER_OUTPUT)); tm_module = TmModuleGetByName("RespondReject"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName for RespondReject failed\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_outputs,tm_module,NULL); SetupOutputs(tv_outputs); if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } } #else sprintf(alert_queue[pipe], "alert-queue%d", pipe); snprintf(tname, sizeof(tname), "RespondReject%"PRIu16, pipe+1); thread_name = SCStrdup(tname); ThreadVars *tv_rreject = TmThreadCreatePacketHandler(thread_name, verdict_queue[pipe],"simple", alert_queue[pipe],"simple", "1slot"); if (tv_rreject == NULL) { printf("ERROR: TmThreadsCreate failed\n"); exit(EXIT_FAILURE); } tm_module = TmModuleGetByName("RespondReject"); if (tm_module == NULL) { printf("ERROR: TmModuleGetByName for RespondReject failed\n"); exit(EXIT_FAILURE); } TmSlotSetFuncAppend(tv_rreject,tm_module,NULL); TmThreadSetCPUAffinity(tv_rreject, MapTile(tile++)); if (TmThreadSpawn(tv_rreject) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } snprintf(tname, sizeof(tname), "Outputs%"PRIu16, pipe+1); thread_name = SCStrdup(tname); ThreadVars *tv_outputs = TmThreadCreatePacketHandler(thread_name, alert_queue[pipe], "simple", "packetpool", "packetpool", "varslot"); SetupOutputs(tv_outputs); TmThreadSetCPUAffinity(tv_outputs, MapTile(tile++)); if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); } #endif } return 0; }
void Map::loadmap( string filename ) { string tmp; FILE *fp = NULL; ssize_t rr = 0; char *line = NULL; size_t len = 0, linenum = 0; vector<string> cells; NPCNode node; clear(); enforce(( fp = fopen( filename.c_str(), "r" )) != NULL, "Failed to open " << filename << " (" << strerror( errno ) << ")" ); while(( rr = readline( &line, &len, fp )) != -1 ) { ++linenum; tmp = line; trim( tmp ); if( tmp.empty()) continue; cells.clear(); stringSep( tmp, cells, ',' ); if( !hloaded ) { enforce( cells.size() == 4, "Bad Map File: " << filename << "\n" << linenum << ": " << line ); id = convert( cells[0] ); name = cells[1]; width = convert( cells[2] ); height = convert( cells[3] ); hloaded = true; enforce( 10000 <= id && id <= 11000, "Bad Map ID\n" << linenum << ": " << line ); } else if( tilemap.size() < ( width * height )) { enforce( cells.size() == width, "Bad Map Line\n" << linenum << ": " << line ); for( size_t i = 0; i < cells.size(); ++i ) { tilemap.push_back( MapTile( cells[i] )); //tilemap.back().print(); } } else { // read in NPCs enforce( cells.size() == 7, "Bad Map Line\n" << linenum << ": " << line ); node.npc_id = convert( cells[0] ); node.x = convert( cells[1] ); node.y = convert( cells[2] ); node.direction = convert( cells[3] ); node.alive = convert( cells[4] ); node.type = convert( cells[5] ); node.mut_id = convert( cells[6] ); npclist.push_back( node ); } } enforce( tilemap.size() == ( width * height ), "Bad Map! Got " << tilemap.size() << " tiles. Expecting " << width * height << " tiles." << endl ); cout << "Map " << name << " has " << npclist.size() << " NPCS" << endl; enforce( fclose( fp ) == 0, "Failed to close " << filename << " (" << strerror( errno ) << ")" ); free( line ); }
// tell the ghosts to turn blue and wander void EntGhost::Scatter(int time) { scattering = true; scatterTime = time; lastTile = MapTile(-1, -1); }