Skip to content

Commit bfeb33a

Browse files
committed
跨cellapp的teleport实现
kbengine#49
1 parent f03ba95 commit bfeb33a

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

kbe/src/server/cellapp/cellapp.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,13 +1622,16 @@ void Cellapp::reqTeleportToCellApp(Network::Channel* pChannel, MemoryStream& s)
16221622
e->setPositionAndDirection(pos, dir);
16231623

16241624
// 进入新space之前必须通知客户端leaveSpace
1625-
Network::Bundle* pSendBundle = Network::Bundle::ObjPool().createObject();
1626-
Network::Bundle* pForwardBundle = Network::Bundle::ObjPool().createObject();
1627-
(*pForwardBundle).newMessage(ClientInterface::onEntityLeaveSpace);
1628-
(*pForwardBundle) << e->id();
1629-
NETWORK_ENTITY_MESSAGE_FORWARD_CLIENT(e->id(), (*pSendBundle), (*pForwardBundle));
1630-
e->clientMailbox()->postMail(pSendBundle);
1631-
Network::Bundle::ObjPool().reclaimObject(pForwardBundle);
1625+
if(e->clientMailbox())
1626+
{
1627+
Network::Bundle* pSendBundle = Network::Bundle::ObjPool().createObject();
1628+
Network::Bundle* pForwardBundle = Network::Bundle::ObjPool().createObject();
1629+
(*pForwardBundle).newMessage(ClientInterface::onEntityLeaveSpace);
1630+
(*pForwardBundle) << e->id();
1631+
NETWORK_ENTITY_MESSAGE_FORWARD_CLIENT(e->id(), (*pSendBundle), (*pForwardBundle));
1632+
e->clientMailbox()->postMail(pSendBundle);
1633+
Network::Bundle::ObjPool().reclaimObject(pForwardBundle);
1634+
}
16321635

16331636
// 进入新的space中
16341637
space->addEntityAndEnterWorld(e);

kbe/src/server/cellapp/controllers.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ bool Controllers::add(Controller* pController)
5656
{
5757
uint32 id = pController->id();
5858
if(id == 0)
59+
{
5960
id = freeID();
61+
}
62+
else
63+
{
64+
// Ë¢ÐÂid¼ÆÊýÆ÷
65+
if(lastid_ <= id)
66+
lastid_ = id + 1;
67+
}
6068

6169
objects_[id].reset(pController);
6270
pController->id(id);
@@ -86,8 +94,7 @@ bool Controllers::remove(uint32 id)
8694
//-------------------------------------------------------------------------------------
8795
void Controllers::addToStream(KBEngine::MemoryStream& s)
8896
{
89-
uint32 size = 0;
90-
size = objects_.size();
97+
uint32 size = objects_.size();
9198
s << lastid_ << size;
9299

93100
CONTROLLERS_MAP::iterator iter = objects_.begin();
@@ -129,7 +136,9 @@ void Controllers::createFromStream(KBEngine::MemoryStream& s)
129136
};
130137

131138
pController->type(type);
132-
objects_[pController->id()].reset(pController);
139+
pController->createFromStream(s);
140+
141+
add(pController);
133142
}
134143
}
135144

kbe/src/server/cellapp/entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2987,8 +2987,8 @@ void Entity::createMoveHandlerFromStream(KBEngine::MemoryStream& s)
29872987
stopMove();
29882988

29892989
pMoveController_ = new MoveController(this);
2990-
pControllers_->objects()[pMoveController_->id()].reset(pMoveController_);
29912990
pMoveController_->createFromStream(s);
2991+
pControllers_->add(pMoveController_);
29922992
}
29932993
}
29942994

kbe/src/server/cellapp/proximity_controller.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ y_(y)
4242
//-------------------------------------------------------------------------------------
4343
ProximityController::ProximityController(Entity* pEntity):
4444
Controller(pEntity),
45+
pTrapTrigger_(NULL),
4546
xz_(0.f),
4647
y_(0.f)
4748
{
@@ -71,6 +72,14 @@ void ProximityController::createFromStream(KBEngine::MemoryStream& s)
7172
//-------------------------------------------------------------------------------------
7273
bool ProximityController::reinstall(CoordinateNode* pCoordinateNode)
7374
{
75+
// 跨cellapp场景跳转时可能出现这种情况
76+
// 因为使用ProximityController::ProximityController(Entity* pEntity)构造
77+
if(pTrapTrigger_ == NULL)
78+
{
79+
pTrapTrigger_ = new TrapTrigger(static_cast<EntityCoordinateNode*>(pCoordinateNode),
80+
this, xz_, y_);
81+
}
82+
7483
return pTrapTrigger_->reinstall(pCoordinateNode);
7584
}
7685

0 commit comments

Comments
 (0)