5 #include "EntityRouter.h"
7 #include "ViewEntity.h"
8 #include "TypeService.h"
12 #include "Connection.h"
13 #include "TypeBoundRedispatch.h"
15 #include <Atlas/Objects/Operation.h>
16 #include <Atlas/Objects/Entity.h>
18 using namespace Atlas::Objects::Operation;
19 using Atlas::Objects::Root;
20 using Atlas::Objects::smart_dynamic_cast;
24 EntityRouter::EntityRouter(Entity& ent, View& view) :
28 m_view.getConnection().registerRouterForFrom(
this, m_entity.getId());
31 EntityRouter::~EntityRouter() {
32 m_view.getConnection().unregisterRouterForFrom(m_entity.getId());
35 Router::RouterResult EntityRouter::handleOperation(
const RootOperation& op)
37 assert(op->getFrom() == m_entity.getId());
38 const std::vector<Root>& args = op->getArgs();
42 if (op->getClassNo() == SIGHT_NO) {
43 for (
const auto& arg : args) {
44 RootOperation sop = smart_dynamic_cast<RootOperation>(arg);
46 return handleSightOp(sop);
51 if (op->getClassNo() == SOUND_NO) {
52 for (
const auto& arg : args) {
53 if (arg->getClassNo() == TALK_NO)
55 RootOperation talk = smart_dynamic_cast<RootOperation>(arg);
56 m_entity.onTalk(talk);
58 if (!arg->isDefaultParent()) {
59 auto ty = m_view.getTypeService().getTypeForAtlas(arg);
61 new TypeBoundRedispatch(m_view.getConnection(), op, ty);
62 }
else if (ty->isA(m_view.getTypeService().getTypeByName(
"action"))) {
64 RootOperation act = smart_dynamic_cast<RootOperation>(arg);
65 m_entity.onSoundAction(act, *ty);
67 warning() <<
"entity " << m_entity.getId() <<
" emitted sound with strange argument: " << op;
70 warning() <<
"entity " << m_entity.getId() <<
" emitted sound with strange argument: " << op;
82 Router::RouterResult EntityRouter::handleSightOp(
const RootOperation& op)
84 const std::vector<Root>& args = op->getArgs();
106 if (op->instanceOf(IMAGINARY_NO)) {
108 error() <<
"entity " << m_entity.getId() <<
" sent imaginary with no args: " << op;
110 for (
const auto& arg : args) {
111 m_entity.onImaginary(arg);