bool IOMapSerialize::saveMap()
{
	int64_t start = OTSYS_TIME();
	Database* db = Database::getInstance();
	std::ostringstream query;

	//Start the transaction
	DBTransaction transaction;
	if (!transaction.begin()) {
		return false;
	}

	//clear old tile data
	if (!db->executeQuery("DELETE FROM `tile_store`")) {
		return false;
	}

	DBInsert stmt;
	stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `data`) VALUES ");

	PropWriteStream stream;
	for (const auto& it : Houses::getInstance().getHouses()) {
		//save house items
		House* house = it.second;
		for (HouseTile* tile : house->getTiles()) {
			saveTile(stream, tile);

			size_t attributesSize;
			const char* attributes = stream.getStream(attributesSize);
			if (attributesSize > 0) {
				query << house->getId() << ',' << db->escapeBlob(attributes, attributesSize);
				if (!stmt.addRow(query)) {
					return false;
				}
			}

			stream.clear();
		}
	}

	if (!stmt.execute()) {
		return false;
	}

	//End the transaction
	bool success = transaction.commit();
	std::cout << "> Saved house items in: " <<
	          (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
	return success;
}
示例#2
0
int FileWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: newScene(); break;
        case 1: addChunk(); break;
        case 2: addTile(); break;
        case 3: saveChunk(); break;
        case 4: saveTile(); break;
        default: ;
        }
        _id -= 5;
    }
    return _id;
}
bool IOMapSerialize::saveHouseBinary(Database* db, DBInsert& stmt, House* house)
{
	PropWriteStream stream;
	for(HouseTileList::iterator tit = house->getHouseTileBegin(); tit != house->getHouseTileEnd(); ++tit)
	{
		if(!saveTile(stream, *tit))
 			continue;
 	}

	uint32_t attributesSize = 0;
	const char* attributes = stream.getStream(attributesSize);
	if(!attributesSize)
		return true;

	DBQuery query;
	query << house->getId() << ", " << g_config.getNumber(ConfigManager::WORLD_ID)
		<< ", " << db->escapeBlob(attributes, attributesSize);
	return stmt.addRow(query);
}
示例#4
0
bool IOMapSerialize::saveMapBinary(Map* map)
{
 	Database* db = Database::getInstance();
	//Start the transaction
 	DBTransaction transaction(db);
 	if(!transaction.begin())
 		return false;

	DBQuery query;
	query << "DELETE FROM `house_data` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
	if(!db->executeQuery(query.str()))
 		return false;

	DBInsert stmt(db);
	stmt.setQuery("INSERT INTO `house_data` (`house_id`, `world_id`, `data`) VALUES ");
 	for(HouseMap::iterator it = Houses::getInstance()->getHouseBegin(); it != Houses::getInstance()->getHouseEnd(); ++it)
	{
 		//save house items
		PropWriteStream stream;
		for(HouseTileList::iterator tit = it->second->getHouseTileBegin(); tit != it->second->getHouseTileEnd(); ++tit)
		{
			if(!saveTile(stream, *tit))
 				return false;
 		}

		uint32_t attributesSize = 0;
		const char* attributes = stream.getStream(attributesSize);
		query.str("");

		query << it->second->getId() << ", " << g_config.getNumber(ConfigManager::WORLD_ID)
			<< ", " << db->escapeBlob(attributes, attributesSize);
		if(!stmt.addRow(query))
			return false;
 	}

	query.str("");
	if(!stmt.execute())
		return false;

 	//End the transaction
 	return transaction.commit();
}
示例#5
0
FileWidget::FileWidget() 
	: QWidget(0)
{
	newSceneBtn = new QPushButton("New Scene");

	chunkCmb = new QComboBox();
	addChunkToSceneBtn = new QPushButton("Add Scene");

	tileCmb = new QComboBox();
	addTileToSceneBtn = new QPushButton("Add Tile");

	saveAsChunkBtn = new QPushButton("Save as Scene");
	saveAsTileBtn = new QPushButton("Save as Tile");

	QVBoxLayout *mainLayout = new QVBoxLayout;
		QHBoxLayout *chunkLayout = new QHBoxLayout;
		QHBoxLayout *tileLayout = new QHBoxLayout;
		QHBoxLayout *saveLayout = new QHBoxLayout;

	chunkLayout->addWidget(chunkCmb);
	chunkLayout->addWidget(addChunkToSceneBtn);

	saveLayout->addWidget(saveAsChunkBtn);

	mainLayout->addWidget(newSceneBtn);
	mainLayout->addLayout(chunkLayout);
	mainLayout->addLayout(saveLayout);
	mainLayout->setContentsMargins(0,0,0,0);

	setLayout(mainLayout);

	connect(newSceneBtn, SIGNAL(clicked()),this, SLOT(newScene()));
	connect(addChunkToSceneBtn, SIGNAL(clicked()),this, SLOT(addChunk()));
	connect(addTileToSceneBtn, SIGNAL(clicked()),this, SLOT(addTile()));
	connect(saveAsChunkBtn, SIGNAL(clicked()),this, SLOT(saveChunk()));
	connect(saveAsTileBtn, SIGNAL(clicked()),this, SLOT(saveTile()));

	setFixedHeight(sizeHint().height());
	setFixedWidth(400);
}
示例#6
0
    void ImageManager::receivedImage(const QPixmap pixmap, const QString& url)
    {
        //qDebug() << "ImageManager::receivedImage";
        QPixmapCache::insert(md5hex(url), pixmap);

        if (doPersistentCaching && !tileExist(url))
        {
            saveTile(url,pixmap);
        }

        if (!prefetch.contains(url))
        {
            emit(imageReceived());
        }
        else
        {

#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
            prefetch.remove(prefetch.indexOf(url));
#endif
        }
    }
示例#7
0
    void ImageManager::receivedImage(const QPixmap pixmap, const QString& url)
    {
        //qDebug() << "ImageManager::receivedImage";
        QPixmapCache::insert(url, pixmap);
        //images[url] = pixmap;

        // needed?
        if (doPersistentCaching && !tileExist(url) )
            saveTile(url,pixmap);

        //((Layer*)this->parent())->imageReceived();

        if (!prefetch.contains(url))
        {
            emit(imageReceived());
        }
        else
        {

#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
            prefetch.remove(prefetch.indexOf(url));
#endif
        }
    }