Пример #1
0
void HM_LC_SWX_FM::loadVariables()
{
	try
	{
		HomeMaticDevice::loadVariables();
		_databaseMutex.lock();
		DataTable rows = GD::db.executeCommand("SELECT * FROM deviceVariables WHERE deviceID=" + std::to_string(_deviceID));
		for(DataTable::iterator row = rows.begin(); row != rows.end(); ++row)
		{
			_variableDatabaseIDs[row->second.at(2)->intValue] = row->second.at(0)->intValue;
			switch(row->second.at(2)->intValue)
			{
			case 1000:
				_channelCount = row->second.at(3)->intValue;
				break;
			case 1001:
				unserializeStates(row->second.at(5)->binaryValue);
				break;
			}
		}
	}
	catch(const std::exception& ex)
    {
    	Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(Exception& ex)
    {
    	Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	Output::printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
	_databaseMutex.unlock();
}
Пример #2
0
void IDbResult::init(DataTable &table)
{
	uint32 count = columns();
	table.setColumns(count);
	for(uint32 i = 0;  i < count; i++)
		table.setColumnName(i, columnName(i));
}
Пример #3
0
void CompatibilityManager::migrateAccounts(const shared_ptr<IPortalDatabase> &database)
{
	shared_ptr<IDbConnection> globalConnection = Engine::instance()->createSystemConnection();

	DataTable result;
	String sql = _S("select * from os_accounts");
	
	database->execute(sql,result);

	for(uint32 r=0;r<result.rows();r++)
	{
		String id = result.get(r,_S("id"));

		shared_ptr<DataAccount> dataAccount(OS_NEW DataAccount());

		dataAccount->read(result[r]);

		dataAccount->description = _S("Imported from portal '") + database->getPortal()->getName();
		
		String sql = String::format(_S("select count(*) from os_accounts where id='%S'").c_str(), id.c_str());
		int nRecordExists = globalConnection->value_of(sql);
		bool alreadyExists = (nRecordExists>0); 

		DbSqlValues values;
		dataAccount->write(values);
		if(alreadyExists)
			globalConnection->executeStatement(globalConnection->prepare_update(DBTABLES::ACCOUNTS_TABLE, values, DBTABLES::ACCOUNTS::ID, Convert::toSQL(dataAccount->id)), values);
		else
		
			globalConnection->executeStatement(globalConnection->prepare_insert(DBTABLES::ACCOUNTS_TABLE, values), values);
	}
}
Пример #4
0
void Michalewicz::runProblem()
{
    double pi = atan(1)*4;

    std::vector<VariablePtr> vars = {
        std::make_shared<Variable>(0, 0, pi),
        std::make_shared<Variable>(0, 0, pi),
        std::make_shared<Variable>(1)
    };

    // Set starting points
    vars.at(0)->setValue(1.0);
    vars.at(1)->setValue(1.0);

    DataTable data;

    double dx = 0.05;
    for (double x1 = 0; x1 <= pi; x1+=dx)
    {
        for (double x2 = 0; x2 <= pi; x2+=dx)
        {
            std::vector<double> x = {x1, x2};

            DenseVector xd(2); xd << x1, x2;
            DenseVector yd = michalewiczFunction(xd);

            data.addSample(x,yd(0));
        }
    }

    // Test accuracy of B-spline
//    DenseVector (*foo)(DenseVector);
//    foo = &michalewiczFunction;
//    BSpline* bs = new BSpline(*data, 3);
//    bool testpassed = bs->testBspline(foo);
//    if (testpassed)
//    {
//        cout << "B-spline is very accurate:)" << endl;
//    }
//    else
//    {
//        cout << "B-spline is NOT very accurate:(" << endl;
//    }

    BSpline bs(data, BSplineType::CUBIC);
    auto constraint = std::make_shared<ConstraintBSpline>(vars, bs, false);

    //SolverIpopt solver(constraint);
    BB::BranchAndBound solver(constraint);

    // Optimize
    SolverResult result = solver.optimize();

    cout << result << endl;

    fopt_found = result.objectiveValue;
    zopt_found = result.primalVariables;

    cout << zopt_found << endl;
}
Пример #5
0
void Michalewicz::runProblem()
{
    double pi = atan(1)*4;

    std::vector<VariablePtr> vars = {
        std::make_shared<Variable>(0, 0, pi),
        std::make_shared<Variable>(0, 0, pi),
        std::make_shared<Variable>(1)
    };

    // Set starting points
    vars.at(0)->setValue(1.0);
    vars.at(1)->setValue(1.0);

    DataTable data;

    unsigned int nums = 10; // 60x60 yields is sufficient to model function around optimum
    auto x1 = linspace(0, 4, nums);
    auto x2 = linspace(0, 4, nums);

    for (auto x1i : x1)
    {
        for (auto x2i : x2)
        {
            DenseVector xd(2); xd << x1i, x2i;
            double yd = michalewiczFunction(xd);
            data.addSample(xd, yd);
        }
    }

    // Test accuracy of B-spline
//    DenseVector (*foo)(DenseVector);
//    foo = &michalewiczFunction;
//    BSpline* bs = new BSpline(*data, 3);
//    bool testpassed = bs->testBspline(foo);
//    if (testpassed)
//    {
//        cout << "B-spline is very accurate:)" << endl;
//    }
//    else
//    {
//        cout << "B-spline is NOT very accurate:(" << endl;
//    }

    BSpline bs = BSpline::Builder(data).degree(3).build();
    auto constraint = std::make_shared<ConstraintBSpline>(vars, bs, false);

    //SolverIpopt solver(constraint);
    BB::BranchAndBound solver(constraint);

    // Optimize
    SolverResult result = solver.optimize();

    cout << result << endl;

    fopt_found = result.objectiveValue;
    zopt_found = result.primalVariables;

    cout << zopt_found << endl;
}
Пример #6
0
void SocialsManager::load (const std::string & filename)
{	
	Iff iff;
	
	if (!iff.open (filename.c_str (), true))
		WARNING (true, ("Data file %s not available.", filename.c_str ()));
	else
	{
		DataTable dt;
		dt.load (iff);
		iff.close ();

		const int numRows = dt.getNumRows ();

		uint32 count = 0;
		for (int i = 0; i < numRows; ++i)
		{
			const std::string & name = Unicode::toLower (dt.getStringValue (DC_name, i));
			++count;

			s_idToNameMap.insert (std::make_pair (count, name));
			s_crcToNameMap.insert (std::make_pair (Crc::calculate(name.c_str()), name));

			const std::pair<StringIntMap::const_iterator, bool> retval = s_nameToIdMap.insert (std::make_pair (name, count));

			if (!retval.second)
				WARNING_STRICT_FATAL (true, ("SocialsManager file '%s' duplicate social type '%s'", filename.c_str (), name.c_str ()));
		}
	}
}
void SetupSharedUtility::installFileManifestEntries ()
{
	// read in the datatable entries for sharedFile/FileManifest.cpp
	std::string datatableName = FileManifest::getDatatableName();

	FATAL(!TreeFile::exists(datatableName.c_str()), ("%s could not be found. Are your paths set up correctly?", datatableName.c_str()));

	DataTable * manifestDatatable = DataTableManager::getTable(datatableName, true);

	if (manifestDatatable)
	{
		int numRows = manifestDatatable->getNumRows();

		for (int i = 0; i < numRows; ++i)
		{
			std::string fileName = manifestDatatable->getStringValue("fileName", i);
			std::string sceneId = manifestDatatable->getStringValue("sceneId", i);
			int fileSize = manifestDatatable->getIntValue("fileSize", i);

			if (!fileName.empty())
				FileManifest::addStoredManifestEntry(fileName.c_str(), sceneId.c_str(), fileSize);
			else
				DEBUG_WARNING(true, ("SetupSharedUtility::installFileManifestEntries(): found an entry with a null filename: (row %i)\n", i));
		}
	}
	else
		DEBUG_WARNING(true, ("SetupSharedUtility::installFileManifestEntries(): can't find %s\n", datatableName.c_str()));
	DataTableManager::close(datatableName);
}
Пример #8
0
// ----------------------------------------------------------------------
void Squad::install()
{
	DEBUG_FATAL(s_installed, ("Already installed"));

	// Create the data table

	Iff iff;

	if (iff.open("datatables/space_mobile/space_mobile.iff", true))
	{
		DataTable dataTable;
		dataTable.load(iff);

		int const rowCount = dataTable.getNumRows();

		for (int row = 0; row < rowCount; ++row)
		{
			PersistentCrcString const shipName(dataTable.getStringValue("strIndex", row), false);
			int const formationPriority = dataTable.getIntValue("formationPriority", row);
			
			IGNORE_RETURN(s_formationPriorityList.insert(std::make_pair(shipName, formationPriority)));

			LOGC((ConfigServerGame::isSpaceAiLoggingEnabled() && formationPriority  <= 0), "space_debug_ai", ("Squad::install() ERROR: Invalid formationPriority(%d) specified for shipName(%s)", formationPriority, shipName.getString()));
		}
	}
	else
	{
		DEBUG_WARNING(true, ("Unable to load space_mobile.iff to retrieve formation priorities!"));
	}

	ExitChain::add(&remove, "Squad::remove");

	s_installed = true;
}
Пример #9
0
DataItem IDbConnection::queryValue(const String &sql)
{
	DataItem value;

	DataTable result;
	if(query(sql, result))
		if(result.rows() > 0 && result.columns() > 0)
			value = *result[0][0];			
	return value;
}
Пример #10
0
bool compareDataTables(DataTable &a, DataTable &b)
{
    if (a.getNumVariables() != b.getNumVariables())
        return false;

    auto ait = a.cbegin(), bit = b.cbegin();
    for (; ait != a.cend() && bit != b.cend(); ait++, bit++)
    {
        for (unsigned int i = 0; i < a.getNumVariables(); i++)
        {
//            std::cout << std::setprecision(SAVE_DOUBLE_PRECISION) << ait->getX().at(i) << " == " << std::setprecision(SAVE_DOUBLE_PRECISION) << bit->getX().at(i) << " ";
            if (!equalsWithinRange(ait->getX().at(i), bit->getX().at(i)))
                return false;
        }

//            std::cout << std::setprecision(SAVE_DOUBLE_PRECISION) << ait->getY().at(j) << " == " << std::setprecision(SAVE_DOUBLE_PRECISION) << bit->getY().at(j) << " ";
        if (!equalsWithinRange(ait->getY(), bit->getY()))
            return false;
//        std::cout << std::endl;
    }

//    std::cout << "Finished comparing samples..." << std::endl;

    return ait == a.cend() && bit == b.cend();
}
Пример #11
0
uint32 IDbConnection::value_of(const String &sql) // TOCLEAN, rimpiazzare con la queryValue
{
	DataTable result;
	if(query(sql, result) == false)
		return false;

	uint32 value = 0;
	if(result.rows() > 0 && result.columns() > 0)
		value = *result[0][0];

	return value;
}
float CombatTimingTable::getWeaponReloadTimeSeconds(std::string const & weaponType)
{
	float result = 0;

	DataTable * combatTimingTable = DataTableManager::getTable(cs_combatTimingTableName, true);
	if (combatTimingTable)
	{
		int rowNum = combatTimingTable->searchColumnString(0, weaponType);
		result = combatTimingTable->getFloatValue("WeaponReloadTimeSeconds", rowNum);
	}

	return result;
}
bool CombatTimingTable::isContinuous(std::string const & weaponType)
{
	bool result = false;

	DataTable * combatTimingTable = DataTableManager::getTable(cs_combatTimingTableName, true);
	if (combatTimingTable)
	{
		int rowNum = combatTimingTable->searchColumnString(0, weaponType);
		result = combatTimingTable->getIntValue("Continuous", rowNum) ? true : false;
	}

	return result;
}
const char *CombatTimingTable::getWeaponReloadClientAnimation(std::string const & weaponType)
{
	const char * result = 0;

	DataTable * combatTimingTable = DataTableManager::getTable(cs_combatTimingTableName, true);
	if (combatTimingTable)
	{
		int rowNum = combatTimingTable->searchColumnString(0, weaponType);
		result = combatTimingTable->getStringValue("WeaponReloadClientAnimation", rowNum);
	}

	return result;
}
int CombatTimingTable::getMaximumShotsTillWeaponReload(std::string const & weaponType)
{
	int result = 0;

	DataTable * combatTimingTable = DataTableManager::getTable(cs_combatTimingTableName, true);
	if (combatTimingTable)
	{
		int rowNum = combatTimingTable->searchColumnString(0, weaponType);
		result = combatTimingTable->getIntValue("MaximumShotsTillWeaponReload", rowNum);
	}

	return result;
}
Пример #16
0
void CompatibilityManager::resigner(const shared_ptr<IPortalDatabase> &database, shared_ptr<IdeSession> session)
{
	shared_ptr<ObjectsUser> user = session->getUser(database);
	if(user != nullptr)
	{
		Buffer signature = user->signature;
		if( (signature.getSize() == 1) && (signature.getAt(0) == 0) )
		{
			// Need re-sign.
			DataTable result;
			String sql = String::format(_S("select id,entity_author,author from os_entries where author='%S' union select id,entity_author,author from os_entries where entity_author='%S'").c_str(),user->id->toUTF16().c_str(),user->id->toUTF16().c_str());
			database->execute(sql,result);

			for(uint32 r=0;r<result.rows();r++)
			{
				String id = result.get(r,_S("id"));
				String entityAuthor = result.get(r,_S("entity_author"));
				String author = result.get(r,_S("author"));

				shared_ptr<ObjectsIObject> object = database->getPortal()->getObject(database, id.to_ascii());
				if(object != nullptr)
				{
					LanguageResult acceptable = object->acceptable(database);
					if(acceptable.empty())
					{
						if( (entityAuthor == user->id->toUTF16()) && (author == user->id->toUTF16()) )
						{
							shared_ptr<ObjectsIRevisionable> revisionable = objects_revisionable_cast(object);			
							if(revisionable != nullptr)
							{
								bool done = revisionable->signEntity(session->getPrivateKey(), database->getPortal()->getPortalID());
								OS_ASSERT(done);
							}
						}

						if(author == user->id->toUTF16())
						{
							bool done = object->sign(session->getPrivateKey(), database->getPortal()->getPortalID());							
							OS_ASSERT(done);
						}

						LanguageResult result = object->store(database);
						OS_ASSERT(result.empty());						
					}
				}
			}
		}
	}
}
Пример #17
0
void Connection::doQuery(sqlite3 *connection, const String &sql, DataTable &table)
{
	table.clear();

	shared_ptr<Result> result = doQuery(connection, sql);
	if(result != nullptr)
		result->bind(table);
}
Пример #18
0
Profile::Profile(shared_ptr<Portal> portal, shared_ptr<IPortalDatabase> database, shared_ptr<ObjectsUser> user) : m_portal(portal),
																				 						   m_user(user)
{
	// Calcolo Score
	DataTable result;
	String sql = String::format(_S("select score, description, follow from os_snapshot_users where id='%S'").c_str(), m_user->id->toUTF16().c_str());
	database->execute(sql, result);
	if(result.hasRow(0))
	{
		// Estrae il punteggio
		m_score.setValue(result.get(0, _S("score")));
		// Estrae la descrizione
		m_score.setDescription(result.get(0, _S("description")));
		// Estrae il follow
		m_score.setFollow(result.get(0, _S("follow")));
	}
}
Пример #19
0
PSpline::PSpline(const DataTable &samples, double lambda)
    : lambda(lambda)
{
    // Check data
    assert(samples.isGridComplete());

    std::vector< std::vector<double> > xdata = samples.getTableX();

    numVariables = samples.getNumVariables();

    // Assuming a cubic spline
    std::vector<unsigned int> basisDegrees(samples.getNumVariables(), 3);
    basis = BSplineBasis(xdata, basisDegrees, KnotVectorType::FREE);
    computeControlPoints(samples);

    init();

    checkControlPoints();
}
Пример #20
0
void IDbResult::bind(DataTable &table)
{
	init(table);
	while(end() == false)
	{
	    DataTableRow row = table.addRow();
		bind(row);
		moveNext();
	}
}
Пример #21
0
DataTable operator+(const DataTable &lhs, const DataTable &rhs)
{
    if(lhs.getNumVariables() != rhs.getNumVariables()) {
        throw Exception("operator+(DataTable, DataTable): trying to add two DataTable's of different dimensions!");
    }

    DataTable result;
    for(auto it = lhs.cbegin(); it != lhs.cend(); it++) {
        result.addSample(*it);
    }
    for(auto it = rhs.cbegin(); it != rhs.cend(); it++) {
        result.addSample(*it);
    }

    return result;
}
Пример #22
0
shared_ptr<EntitiesEntities> EntitiesEntity::getChilds(const shared_ptr<IPortalDatabase> &database, const ObjectsTypes &types, const RangeUint32 &range, shared_ptr<DbSqlSelect> select) const
{
	OS_ASSERT(select != nullptr);
	OS_ASSERT(select->count == false);

	OS_LOCK(m_cs);

	String sql;
	// Genera l'sql di caricamento dei figli
	_getSql(database, types, range, false, select, sql);

	String childsKey = getChildsKey(types);

	shared_ptr<EntitiesEntities> childs = m_childs.get(childsKey);
	// Controlla se i figli della tipologia specificata sono gi stati caricati in precedenza
	if(childs != nullptr)
	{
		if(childs->getRange() == range && childs->getSql() == sql)
			return childs;	// Se il range in cui sono stati caricati i figli e l'sql di estrazione corrispondono non serve effettuare nuovamente il caricamento...

		// Nota: se il range richiesto non coincide con quello attuale o l'sql  differente bisogna ricaricare i figli
		// Anche se il range attuale comprendesse quello richiesto bisogna comunque ricaricare i figli altrimenti dall'esterno,
		// una volta richiesto un range, scorrendo i figli non si avrebbe la certezza che siano nel range richiesto (a meno di complicare i vari giri)

		m_childs.remove(childsKey);
	}

	// Inizializza la lista dei figli prima di aprire il database (la connessione potrebbe fallire, ma la lista deve essere comunque creata)
	childs.reset(OS_NEW EntitiesEntities(const_cast <EntitiesEntity *>(this)->get_this_ptr(), sql));
	m_childs.push_back(childsKey, childs);

	DataTable result;
	database->execute(sql, result);
	for(uint32 i = 0; i < result.rows(); i++)
	{
		String child_id = result.get(i, DBTABLES::ENTITY);
		childs->push_back(child_id.to_ascii());
	}

	return childs;
}
Пример #23
0
bool IExtensionsExtension::isExtensionRegistered(shared_ptr<Portal> portal, shared_ptr<IPortalDatabase> db, Version &version) const
{
	OS_ASSERT(portal != nullptr);

	OS_EXCEPT_IF(db == nullptr, "Invalid database");

	shared_ptr<DbSqlSelect> select(OS_NEW DbSqlSelect(DBTABLES::EXTENSIONS_TABLE));
	select->fields.add(DbSqlField(DBTABLES::EXTENSIONS::VERSION));
	select->where.add(DBTABLES::EXTENSIONS::ID, Convert::toSQL(getID().toUTF16()));
	select->limit.setCount(1);

	DataTable result;
	if(db->execute(select, result) == false)
		return false;

	if(result.rows() == 0)
		return false;

	version.fromString(static_cast<String>(*result[0][0]).to_ascii());
	return true;
}
Пример #24
0
bool P2pMachine::load(const String &id)
{
	try
	{
		shared_ptr<IDbConnection> connection = Engine::instance()->createSystemConnection();
		
		shared_ptr<DbSqlSelect> select(OS_NEW DbSqlSelect(_S("os_machines")));
		select->where.add(_S("id"), Convert::toSQL(id));
		select->limit.setCount(1);

		DataTable result;
		connection->query(select, result);

		if(result.rows() == 1)
		{
			DataTableRow row = result[0];

			DbValue<String> id;
			id.read(row, _S("id"));
			if(m_id.fromHex(id->to_ascii()) == false)
			{
				OS_ASSERTFALSE();
				return false;
			}

			DbValue<Buffer> public_key;
			public_key.read(row, _S("public_key"));
			m_publicKey = public_key;

			return true;
		}
	}
	catch(std::exception &e)
	{
		OS_LOG_ERROR(e.what());
	}

	return false;
}
DataTable* DataTableManager::open(const std::string& table)
{
	FATAL(!m_installed, ("DataTableManager::open: not installed."));
	DataTable *retVal = getTable(table, false);
	if (retVal)
		return retVal;

	if (!TreeFile::exists(table.c_str()))
	{
		DEBUG_WARNING(true, ("Could not find treefile table for open [%s]", table.c_str()));
		return 0;
	}

	Iff iff(table.c_str(), false);
	retVal = new DataTable;
	retVal->load(iff);

	m_cachedTable = retVal;
	m_cachedTableName = table;
	m_tables[table] = retVal;

	return retVal;
}
Пример #26
0
DataTable operator-(const DataTable &lhs, const DataTable &rhs)
{
    if(lhs.getNumVariables() != rhs.getNumVariables()) {
        throw Exception("operator-(DataTable, DataTable): trying to subtract two DataTable's of different dimensions!");
    }

    DataTable result;
    auto rhsSamples = rhs.getSamples();
    // Add all samples from lhs that are not in rhs
    for(auto it = lhs.cbegin(); it != lhs.cend(); it++) {
        if(rhsSamples.count(*it) == 0) {
            result.addSample(*it);
        }
    }

    return result;
}
Пример #27
0
void ShipTurretManager::install() // static
{
    InstallTimer const installTimer("ShipTurretManager::install");

    Iff iff;
    if (iff.open("datatables/space/ship_turret.iff", true))
    {
        DataTable dataTable;
        dataTable.load(iff);
        int numberOfRows = dataTable.getNumRows();
        for (int row = 0; row < numberOfRows; ++row)
        {
            std::string const chassisName(dataTable.getStringValue("chassis", row));
            ShipChassis const * const chassis = ShipChassis::findShipChassisByName(TemporaryCrcString(chassisName.c_str(), false));
            FATAL(!chassis, ("ShipTurretManager::install: no such chassis '%s'", chassisName.c_str()));
            int const weaponIndex = dataTable.getIntValue("weaponIndex", row);
            ShipTurretData &shipTurretData = s_shipTurretData[chassis->getCrc()][weaponIndex];
            shipTurretData.minYaw = dataTable.getFloatValue("minYaw", row) * PI_OVER_180;
            shipTurretData.maxYaw = dataTable.getFloatValue("maxYaw", row) * PI_OVER_180;
            shipTurretData.minPitch = dataTable.getFloatValue("minPitch", row) * PI_OVER_180;
            shipTurretData.maxPitch = dataTable.getFloatValue("maxPitch", row) * PI_OVER_180;
        }
    }
}
Пример #28
0
void RewardMappingTools::readFromStream(istream& in, ProbabilisticRewardMapping& rewards)
throw (IOException)
{
  try
  {
    DataTable* data = DataTable::read(in, "\t", true, -1);
    vector<string> ids = data->getColumn(0);
    data->deleteColumn(0); // Remove ids
    data->deleteColumn(0); // Remove means
    // Now parse the table:
    size_t nbSites = data->getNumberOfColumns();
    rewards.setNumberOfSites(nbSites);
    size_t nbBranches = data->getNumberOfRows();
    for (size_t i = 0; i < nbBranches; i++)
    {
      int id = TextTools::toInt(ids[i]);
      size_t br = rewards.getNodeIndex(id);
      for (size_t j = 0; j < nbSites; j++)
      {
        rewards(br, j) = TextTools::toDouble((*data)(i, j));
      }
    }
    // Parse the header:
    for (size_t i = 0; i < nbSites; i++)
    {
      string siteTxt = data->getColumnName(i);
      int site = 0;
      if (siteTxt.substr(0, 4) == "Site")
        site = TextTools::to<int>(siteTxt.substr(4));
      else
        site = TextTools::to<int>(siteTxt);
      rewards.setSitePosition(i, site);
    }

    delete data;
  }
  catch (Exception& e)
  {
    throw IOException(string("Bad input file. ") + e.what());
  }
}
Пример #29
0
void BuildingObject::changeTeleportDestination(Vector & position, float & yaw) const
{
	if (!isAuthoritative())
	{
		WARNING(true, ("BuildingObject::changeTeleportDestination called on "
			"non-authoritative building %s", getNetworkId().getValueString().c_str()));
		return;
	}

	// call a script trigger that will give us the index of the cloning facility
	// tube to respawn in, if any
	int index = -1;
	ScriptParams params;
	params.addParam(index);
	IGNORE_RETURN(const_cast<GameScriptObject *>(getScriptObject())->trigAllScripts(
		Scripting::TRIG_GET_RESPAWN_LOC, params));
	index = params.getIntParam(0);
	if (index >= 0)
	{
		DataTable * respawnTable = DataTableManager::getTable(CLONE_RESPAWN_TABLE, 
			true);
		if (respawnTable != NULL)
		{
			int row = respawnTable->searchColumnString(0, getTemplateName());
			if (row >= 0)
			{
				char buffer[32];
				sprintf(buffer, "TUBE%d_X", index+1);
				int column = respawnTable->findColumnNumber(buffer);
				if (column >= 0)
				{
					position.x = respawnTable->getFloatValue(column, row);
					position.z = respawnTable->getFloatValue(column+1, row);
					yaw = convertDegreesToRadians(respawnTable->getFloatValue(column+2, row));
				}
			}
		}
	}
}
Пример #30
0
//bool EntitiesEntity::_loadObject(const shared_ptr<IPortalDatabase> &database, shared_ptr<ObjectsIRevisionable> object)
bool EntitiesEntity::load(const shared_ptr<IPortalDatabase> &database, const EntityID & id)
{
	OS_TIMER_PERFORMANCE(TP, _S("Entity::_loadObject"));
	OS_LOCK(m_cs);

#ifndef OS_TODOCIP
	shared_ptr<ObjectsIRevisionable> object = objects_revisionable_cast(database->getPortal()->getObject(database, id.toUTF16()));
	m_primary = object;
	//OS_ASSERT(getEntityID() == id);
#endif

	if(database->getPortal()->getSnapshotManager()->m_enableEnsureLoadingEntity)
		database->getPortal()->getSnapshotManager()->ensure(database, id);

	DataTable result;
	// TOCLEAN_SNAPSHOT_SCORE
	//String sql = String::format(_S("select current,visible,score,depth,parent,section,stability_date from os_snapshot_objects where reference='%S'").c_str(), m_primary->id->toUTF16().c_str());
	String sql = String::format(_S("select type,current,visible,depth,parent,section,stability_date from os_snapshot_objects where entity='%S'").c_str(), id.toUTF16().c_str());
	database->execute(sql, result);
	if(!result.hasRow(0))
	{
		clear();
		return false;
	}
	else
	{
		ObjectID currentID = static_cast<String>(result.get(0,_S("current"))).to_ascii();
		m_type = Convert::toObjectType(static_cast<uint32>(result.get(0,_S("type"))));
		m_visible = result.get(0,_S("visible"));
		//m_score = *result.get(0,_S("score")); // TOCLEAN_SNAPSHOT_SCORE
		m_depth = result.get(0,_S("depth"));
		m_parent = static_cast<String>(result.get(0,_S("parent"))).to_ascii();
		m_section = static_cast<String>(result.get(0,_S("section"))).to_ascii();
		m_stabilityDate = String(result.get(0,_S("stability_date")));

		if(id == ObjectsSystem::instance()->getRootID())
			//m_current = objects_revisionable_cast(database->getPortal()->getObject(database, ObjectsSystem::instance()->getRootID().toObjectID()));
			m_current = ObjectsSection::getRootSection();
		else
		{		
#ifdef OS_TODOCIP
			/*
			if(currentID.empty())
				return false;
			m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
			if(m_current == nullptr)
				return false;				
			*/

			if(currentID.empty() == false)
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#else
			if(currentID.empty())
			{
				m_current.reset();
				// OS_ASSERT(m_parent == ObjectsSystem::instance()->getSkippedID());
				// No, dato che la getEntity non fa + l'ensure, può succedere che carica un oggetto non stabilizzato.
				m_visible = false;
			}
			else
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#endif
		}

		return true;
	}
}