void World::sendRelayToEntity(const LocatedEntity& to, const Operation& op, sigc::slot<void, const Operation&, const std::string&> callback) { //Make the op appear to come from the destination entity. op->setFrom(to.getId()); long int serialNo = ++m_serialNumber; Atlas::Objects::Operation::Relay relayOp; relayOp->setTo(to.getId()); relayOp->setSerialno(serialNo); relayOp->setArgs1(op); Relay relay; relay.entityId = to.getId(); relay.callback = std::move(callback); m_relays.insert(std::make_pair(serialNo, relay)); sendWorld(relayOp); //Also send a future Relay op to ourselves to make sure that the registered relay in m_relays //is removed in the case that we don't get any response. Atlas::Objects::Operation::Relay pruneOp; pruneOp->setTo(getId()); pruneOp->setFrom(getId()); pruneOp->setRefno(serialNo); pruneOp->setFutureSeconds(5); sendWorld(pruneOp); }
void DomainProperty::scheduleTick(LocatedEntity& entity, float timeForNextTick) { Atlas::Objects::Entity::Anonymous tick_arg; tick_arg->setName("domain"); Atlas::Objects::Operation::Tick tickOp; tickOp->setTo(entity.getId()); tickOp->setSeconds(timeForNextTick); tickOp->setArgs1(tick_arg); entity.sendWorld(tickOp); }
void Accountintegration::test_LookOperation() { Anonymous new_char; LocatedEntity * chr = m_ac->addNewCharacter("thing", new_char, RootEntity()); Anonymous op_arg; op_arg->setId("1"); op_arg->setId(chr->getId()); Look op; op->setArgs1(op_arg); OpVector res; m_ac->operation(op, res); // FIXME This doesn't test a lot }
void StorageManager::restoreChildren(LocatedEntity * parent) { Database * db = Database::instance(); DatabaseResult res = db->selectEntities(parent->getId()); EntityBuilder * eb = EntityBuilder::instance(); // Iterate over res creating entities, and sorting out position, location // and orientation. Restore children, but don't restore any properties yet. DatabaseResult::const_iterator I = res.begin(); DatabaseResult::const_iterator Iend = res.end(); for (; I != Iend; ++I) { const std::string id = I.column("id"); const int int_id = forceIntegerId(id); const std::string type = I.column("type"); //By sending an empty attributes pointer we're telling the builder not to apply any default //attributes. We will instead apply all attributes ourselves when we later on restore attributes. Atlas::Objects::SmartPtr<Atlas::Objects::Entity::RootEntityData> attrs(nullptr); LocatedEntity * child = eb->newEntity(id, int_id, type, attrs, BaseWorld::instance()); if (!child) { log(ERROR, compose("Could not restore entity with id %1 of type %2" ", most likely caused by this type missing.", id, type)); continue; } const std::string location_string = I.column("location"); MapType loc_data; db->decodeMessage(location_string, loc_data); child->m_location.readFromMessage(loc_data); if (!child->m_location.pos().isValid()) { std::cout << "No pos data" << std::endl << std::flush; log(ERROR, compose("Entity %1 restored from database has no " "POS data. Ignored.", child->getId())); delete child; continue; } child->m_location.m_loc = parent; child->setFlags(entity_clean | entity_pos_clean | entity_orient_clean); BaseWorld::instance().addEntity(child); restoreChildren(child); } }
/// \brief Add an operation to the ordered op queue. /// /// Any time adjustment required is made to the operation, and it /// is added to the apropriate place in the chronologically ordered /// queue. The From attribute of the operation is set to the id of /// the entity that is responsible for adding the operation to the /// queue. void OperationsDispatcher::addOperationToQueue(const Operation & op, LocatedEntity & ent) { assert(op.isValid()); assert(op->getFrom() != "cheat"); m_operation_queues_dirty = true; op->setFrom(ent.getId()); if (!op->hasAttrFlag(Atlas::Objects::Operation::FUTURE_SECONDS_FLAG)) { op->setSeconds(getTime()); m_immediateQueue.push(OpQueEntry(op, ent)); return; } double t = getTime() + (op->getFutureSeconds() * consts::time_multiplier); op->setSeconds(t); op->setFutureSeconds(0.); m_operationQueue.push(OpQueEntry(op, ent)); if (debug_flag) { std::cout << "WorldRouter::addOperationToQueue {" << std::endl; debug_dump(op, std::cout); std::cout << "}" << std::endl << std::flush; } }
void Accountintegration::test_SetOperation() { Anonymous new_char; LocatedEntity * chr = m_ac->addNewCharacter("thing", new_char, RootEntity()); BBox newBox(WFMath::Point<3>(-0.5, -0.5, 0.0), WFMath::Point<3>(-0.5, -0.5, 2.0)); chr->m_location.setBBox(newBox); Anonymous op_arg; op_arg->setId(chr->getId()); op_arg->setAttr("guise", "foo"); op_arg->setAttr("height", 3.0); op_arg->setAttr("tasks", ListType()); Set op; op->setArgs1(op_arg); OpVector res; m_ac->operation(op, res); // FIXME Ensure character has been modified }
ExternalMind::ExternalMind(LocatedEntity & e) : Router(e.getId(), e.getIntId()), m_external(0), m_entity(e) { }