Esempio n. 1
0
static int CreatorClient_setattr(PyCreatorClient *self, char *name, PyObject *v)
{
    if (self->m_mind == NULL) {
        return -1;
    }
    if (self->CreatorClient_attr == NULL) {
        self->CreatorClient_attr = PyDict_New();
        if (self->CreatorClient_attr == NULL) {
            return -1;
        }
    }
    if (strcmp(name, "map") == 0) {
        return -1;
    }
    LocatedEntity * thing = self->m_mind;
    //std::string attr(name);
    //if (v == NULL) {
        //thing->attributes.erase(attr);
        //return 0;
    //}
    Element obj;
    if (PyObject_asMessageElement(v, obj) == 0 && !obj.isMap() && !obj.isList()) {
        thing->setAttr(name, obj);
        return 0;
    }
    // If we get here, then the attribute is not Atlas compatable, so we
    // need to store it in a python dictionary
    return PyDict_SetItemString(self->CreatorClient_attr, name, v);
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
void EntityTypeProvider::value(Atlas::Message::Element& value, const LocatedEntity& entity) const
{
    if (!entity.getType()) {
        return;
    }

    if (m_consumer) {
        m_consumer->value(value, *entity.getType());
    } else {
        value = (void*)(entity.getType());
    }
}
Esempio n. 5
0
void LocatedEntitytest::test_removeAttr()
{
    std::string test_property("test_property");
    LocatedEntity* entity = new LocatedEntityTest("1", 1);

    ASSERT_TRUE(!m_TestProperty_remove_called);

    PropertyBase * tp = new TestProperty();

    entity->setProperty(test_property, tp);

    ASSERT_TRUE(!m_TestProperty_remove_called);
    delete entity;
    ASSERT_TRUE(m_TestProperty_remove_called);
}
Esempio n. 6
0
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
}
Esempio n. 7
0
std::shared_ptr<Awareness> AwarenessStore::requestAwareness(const LocatedEntity& domainEntity)
{
    //Check if there's already an awareness for the domain entity.
    auto I = m_awarenesses.find(domainEntity.getIntId());
    if (I != m_awarenesses.end()) {
        //check if it's still valid
        if (!I->second.expired()) {
            return I->second.lock();
        }
        //else remove it
        m_awarenesses.erase(I);
    }

    auto bbox = domainEntity.m_location.bBox();

    auto awareness = std::make_shared < Awareness > (domainEntity, mAgentRadius, mAgentHeight, mHeightProvider, bbox, mTileSize);
    m_awarenesses.insert(std::make_pair(domainEntity.getIntId(), std::weak_ptr < Awareness > (awareness)));
    return awareness;
}
Esempio n. 8
0
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);
    }
}
Esempio n. 9
0
void LocatedEntitytest::test_setProperty()
{
    std::string test_property("test_property");
    ASSERT_TRUE(m_entity->m_properties.find(test_property) ==
                m_entity->m_properties.end());

    PropertyBase * tp = new SoftProperty;

    m_entity->setProperty(test_property, tp);

    ASSERT_TRUE(m_entity->m_properties.find(test_property) !=
                m_entity->m_properties.end());
}
Esempio n. 10
0
void SoftPropertyProvider::value(Atlas::Message::Element& value, const LocatedEntity& entity) const
{
    auto prop = entity.getProperty(m_attribute_name);
    if (!prop) {
        return;
    }
    if (m_consumer) {
        Atlas::Message::Element propElem;
        prop->get(propElem);
        m_consumer->value(value, propElem);
    } else {
        prop->get(value);
    }
}
void LocatedEntity::changeContainer(LocatedEntity * new_loc)
{
    assert(m_location.m_loc != 0);
    assert(m_location.m_loc->m_contains != 0);
    m_location.m_loc->m_contains->erase(this);
    if (m_location.m_loc->m_contains->empty()) {
        m_location.m_loc->onUpdated();
    }
    new_loc->makeContainer();
    bool was_empty = new_loc->m_contains->empty();
    new_loc->m_contains->insert(this);
    if (was_empty) {
        new_loc->onUpdated();
    }
    assert(m_location.m_loc->checkRef() > 0);
    LocatedEntity* oldLoc = m_location.m_loc;
    m_location.m_loc = new_loc;
    m_location.m_loc->incRef();
    assert(m_location.m_loc->checkRef() > 0);

    onContainered(oldLoc);
    oldLoc->decRef();
}
Esempio n. 12
0
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
}
Esempio n. 13
0
/// \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;
    }
}
Esempio n. 14
0
inline OpQueEntry::OpQueEntry(const OpQueEntry & o) : op(o.op), from(o.from)
{
    from->incRef();
}
Esempio n. 15
0
void EntityIdProvider::value(Atlas::Message::Element& value,
                                     const LocatedEntity& entity) const
{
    value = Atlas::Message::Element(entity.getIntId());
}
Esempio n. 16
0
static PyObject * CreatorClient_getattr(PyCreatorClient *self, char *name)
{
    // Fairly major re-write of this to use operator[] of CreatorClient base class
#ifndef NDEBUG
    if (self->m_mind == NULL) {
        PyErr_SetString(PyExc_AssertionError, "NULL CreatorClient in CreatorClient.getattr");
        return NULL;
    }
#endif // NDEBUG
    // If operation search gets to here, it goes no further
    if (strstr(name, "_operation") != NULL) {
        PyErr_SetString(PyExc_AttributeError, name);
        return NULL;
    }
    if (strcmp(name, "type") == 0) {
        PyObject * list = PyList_New(0);
        if (list == NULL) {
            return NULL;
        }
        PyList_Append(list, PyString_FromString(self->m_mind->getType()->name().c_str()));
        return list;
    }
    if (strcmp(name, "map") == 0) {
        PyMap * map = newPyMap();
        if (map != NULL) {
            map->m_map = self->m_mind->getMap();
        }
        return (PyObject *)map;
    }
    if (strcmp(name, "location") == 0) {
        PyLocation * loc = newPyLocation();
        if (loc != NULL) {
            loc->location = &self->m_mind->m_location;
            loc->owner = self->m_mind;
        }
        return (PyObject *)loc;
    }
    if (strcmp(name, "time") == 0) {
        PyWorldTime * worldtime = newPyWorldTime();
        if (worldtime != NULL) {
            worldtime->time = self->m_mind->getTime();
        }
        return (PyObject *)worldtime;
    }
    if (self->CreatorClient_attr != NULL) {
        PyObject *v = PyDict_GetItemString(self->CreatorClient_attr, name);
        if (v != NULL) {
            Py_INCREF(v);
            return v;
        }
    }
    LocatedEntity * thing = self->m_mind;
    Element attr;
    if (!thing->getAttr(name, attr)) {
        return Py_FindMethod(CreatorClient_methods, (PyObject *)self, name);
    }
    PyObject * ret = MessageElement_asPyObject(attr);
    if (ret == NULL) {
        return Py_FindMethod(CreatorClient_methods, (PyObject *)self, name);
    }
    return ret;
}
Esempio n. 17
0
void LocatedEntitytest::test_coverage()
{
    m_entity->setScript(new Script());
    // Installing a second one should delete the first.
    m_entity->setScript(new Script());

    m_entity->onContainered(nullptr);
    m_entity->onUpdated();

    EntityExerciser ee(*m_entity);
    // Throw an op of every type at the entity
    ee.runOperations();

    // Subscribe the entity to every class of op
    std::set<std::string> opNames;
    ee.addAllOperations(opNames);

    std::set<std::string> attrNames;
    attrNames.insert("id");

    // Make sure we have all the default attributes
    assert(ee.checkAttributes(attrNames));

    attrNames.insert("test_int");
    attrNames.insert("test_float");
    attrNames.insert("test_list_string");
    attrNames.insert("test_list_int");
    attrNames.insert("test_list_float");
    attrNames.insert("test_map_string");
    attrNames.insert("test_map_int");
    attrNames.insert("test_map_float");

    // Make sure we don't have the test attributes yet
    assert(!ee.checkAttributes(attrNames));

    // Add the test attributes
    m_entity->setAttr("test_int", 1);
    m_entity->setAttr("test_float", 1.f);
    m_entity->setAttr("test_list_string", "test_value");
    m_entity->setAttr("test_list_int", ListType(1, 1));
    m_entity->setAttr("test_list_float", ListType(1, 1.f));
    m_entity->setAttr("test_map_string", ListType(1, "test_value"));
    MapType test_map;
    test_map["test_key"] = 1;
    m_entity->setAttr("test_map_int", test_map);
    test_map["test_key"] = 1.f;
    m_entity->setAttr("test_map_float", test_map);
    test_map["test_key"] = "test_value";
    m_entity->setAttr("test_map_string", test_map);
    
    // Make sure we have the test attributes now
    assert(ee.checkAttributes(attrNames));

    MapType entityAsAtlas;

    m_entity->merge(entityAsAtlas);

    // Throw an op of every type at the entity again now it is subscribed,
    // and full of data.
    ee.runOperations();

}
Esempio n. 18
0
InventoryDomain::InventoryDomain(LocatedEntity& entity) :
        Domain(entity)
{
    entity.makeContainer();
}
Esempio n. 19
0
inline OpQueEntry::OpQueEntry(const Operation & o, LocatedEntity & f) : op(o),
                                                                        from(&f)
{
    from->incRef();
}
ExternalMind::ExternalMind(LocatedEntity & e) : Router(e.getId(), e.getIntId()),
                                         m_external(0), m_entity(e)
{
}
Esempio n. 21
0
inline OpQueEntry::~OpQueEntry()
{
    from->decRef();
}