本文整理汇总了C++中RootEntity::setId方法的典型用法代码示例。如果您正苦于以下问题:C++ RootEntity::setId方法的具体用法?C++ RootEntity::setId怎么用?C++ RootEntity::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RootEntity
的用法示例。
在下文中一共展示了RootEntity::setId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createCharacter
void ClientConnection::createCharacter(const RootOperation& op)
{
static unsigned int charCounter = 0;
char charId[64];
::snprintf(charId, 64, "_customChar_%d", ++charCounter);
RootEntity ent = smart_dynamic_cast<RootEntity>(op->getArgs().front());
ent->setId(charId);
ent->setLoc("_world");
m_server->m_world[charId] = ent;
StringList children(m_server->m_world["_world"]->getContains());
children.push_back(charId);
m_server->m_world["_world"]->setContains(children);
Agent* ag = new Agent(this, charId);
ag->setEntityVisible(charId, true);
m_agents[charId] = ag;
Info info;
info->setArgs1(m_server->m_world[charId]);
info->setFrom(charId);
info->setTo(m_account); // I *think* this is right
info->setRefno(op->getSerialno());
send(info);
}
示例2: addToEntity
void Juncture::addToEntity(const RootEntity & ent) const
{
ent->setObjtype("obj");
ent->setId(getId());
ent->setParents(std::list<std::string>(1,"juncture"));
}
示例3: dispatch
void Commander::dispatch(const RootOperation& op)
{
Appearance appear = smart_dynamic_cast<Appearance>(op);
if (appear.isValid()) {
assert(op->hasAttr("for"));
Agent* ag = m_server->findAgentForEntity(op->getAttr("for").asString());
if (ag) {
ag->setEntityVisible(op->getTo(), true);
} else {
// doesn't exist yet, mark as visible if / when the agent is created
Agent::setEntityVisibleForFutureAgent(op->getTo(), op->getAttr("for").asString());
}
}
Disappearance disap = smart_dynamic_cast<Disappearance>(op);
if (disap.isValid()) {
assert(op->hasAttr("for"));
Agent* ag = m_server->findAgentForEntity(op->getAttr("for").asString());
if (ag) ag->setEntityVisible(op->getTo(), false);
}
Create cr = smart_dynamic_cast<Create>(op);
if (cr.isValid()) {
std::vector<Root> args(op->getArgs());
assert(!args.empty());
RootEntity ent = smart_dynamic_cast<RootEntity>(args.front());
assert(ent.isValid());
static int idCounter = 900;
char buf[32];
snprintf(buf, 32, "_created_%d", ++idCounter);
std::string id(buf);
ent->setId(id);
std::string loc = ent->getLoc();
assert(m_server->m_world.count(loc));
StringList children(m_server->m_world[loc]->getContains());
children.push_back(id);
m_server->m_world[loc]->setContains(children);
m_server->m_world[id] = ent;
Create bcr(cr);
bcr->setArgs1(ent);
Agent::broadcastSight(bcr);
}
Delete del = smart_dynamic_cast<Delete>(op);
if (del.isValid()) {
std::vector<Root> args(op->getArgs());
assert(!args.empty());
std::string id = args.front()->getId();
assert(m_server->m_world.count(id));
m_server->m_world.erase(id);
Agent::broadcastSight(op);
}
Move mv = smart_dynamic_cast<Move>(op);
if (mv.isValid()) {
RootEntity ent = m_server->getEntity(op->getTo());
std::vector<Root> args(op->getArgs());
if (args.front()->hasAttr("loc")) {
std::string newLocId = args.front()->getAttr("loc").asString();
RootEntity oldLoc = m_server->getEntity(ent->getLoc()),
newLoc = m_server->getEntity(newLocId);
ent->setLoc(newLocId);
// modify stamps?
oldLoc->modifyContains().remove(ent->getId());
newLoc->modifyContains().push_back(ent->getId());
}
if (args.front()->hasAttr("pos"))
ent->setPosAsList(args.front()->getAttr("pos").asList());
// handle velocity changes
Agent::broadcastSight(op);
return;
}
Sound snd = smart_dynamic_cast<Sound>(op);
if (snd.isValid()) {
std::vector<Root> args(op->getArgs());
assert(!args.empty());
if (snd->hasAttr("broadcast")) {
Agent::broadcastSound(smart_dynamic_cast<RootOperation>(args.front()));
}
}
Sight st = smart_dynamic_cast<Sight>(op);
if (st.isValid()) {
if (st->hasAttr("broadcast")) {
//.........这里部分代码省略.........
示例4: testXML
void testXML()
{
RootEntity human;
human->setId("foo");
Move move_op;
move_op->setFrom(std::string("bar"));
std::vector<Root> move_args(1);
move_args[0] = human;
move_op->setArgs(move_args);
Atlas::Message::ListType velocity;
velocity.push_back(2.0);
velocity.push_back(1.0);
velocity.push_back(0.0);
human->setVelocityAsList(velocity);
// typedef BaseObjectData *(*alloc_func)();
// alloc_func alloc_entity = &Entity::RootEntityDataInstance::alloc;
// BaseObjectData *bod = alloc_entity();
//Root human2(bod);
Root human2 = Atlas::Objects::factory<Atlas::Objects::Entity::RootEntityData>("root_enitty", Atlas::Objects::Entity::RootEntity()->getClassNo());
std::cout<<"human.id="<<human->getId()<<std::endl;
std::cout<<"human2.id="<<human2->getId()<<std::endl;
#if 0
typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs;
FactoryCodecs *myCodecs = &Factory<Codec >::factories();
FactoryCodecs::iterator i;
std::cout<<"myCodecs: "<<myCodecs->size();
for (i = myCodecs->begin(); i != myCodecs->end(); ++i)
std::cout<<":"<<(*i)->getName();
std::cout<<std::endl;
#endif
//DebugBridge bridge;
TestDecoder bridge;
#if USE_FILE
fstream stream;
std::string atlas_xml_path;
char * srcdir_env = getenv("srcdir");
if (srcdir_env != 0) {
atlas_xml_path = srcdir_env;
atlas_xml_path += "/";
}
atlas_xml_path += "../../protocol/spec/atlas.xml";
stream.open(atlas_xml_path, std::ios::in);
assert(!!stream);
#else
std::stringstream stream;
#endif
// typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs;
// FactoryCodecs *myCodecs = &Factory<Codec >::factories();
// FactoryCodecs::iterator codec_i;
// Atlas::Codec *codec = NULL;
// for(codec_i = myCodecs->begin(); codec_i != myCodecs->end(); ++codec_i)
// {
// std::cout<<(*codec_i)->getName()<<std::endl;
// if ((*codec_i)->getName() == "XML") {
// codec = (*codec_i)->New(Codec::Parameters(stream, &bridge));
// }
// }
// assert(codec);
Account account;
Login l;
account->setAttr("id", std::string("al"));
account->setAttr("password", std::string("ping"));
//list<Message::Object> args(1,account->asObject());
//l->setArgsAsList(args);
std::vector<Root> args(1);
args[0] = account;
l->setArgs(args);
//coder->streamObjectsMessage((Root&)l);
//<map><list name="args"><map><std::string name="id">al</strin
//g></map></list><list name="parents"><std::string>root</std::string></list><std::string name="ob
//jtype">op_definition</std::string></map>
Atlas::Codec *codec;
#if USE_XML
codec = new Atlas::Codecs::XML((std::iostream&)stream, bridge);
#else
codec = new Atlas::Codecs::Packed(stream, bridge);
#endif
assert(codec);
#if USE_FILE
while(stream) {
codec->poll();
//std::cout<<"--------"<<std::endl;
}
#else
codec->streamBegin();
Atlas::Objects::ObjectsEncoder eno(*codec);
// eno.streamObjectsMessage(move_op);
eno.streamObjectsMessage(l);
Anonymous e;
//.........这里部分代码省略.........