@@ -84,7 +84,9 @@ bool Cellapp::canShutdown()
84
84
Entities<Entity>::ENTITYS_MAP::iterator iter = entities.begin ();
85
85
for (; iter != entities.end (); iter++)
86
86
{
87
- if (static_cast <Entity*>(iter->second .get ())->baseMailbox () != NULL )
87
+ Entity* pEntity = static_cast <Entity*>(iter->second .get ());
88
+ if (pEntity->baseMailbox () != NULL &&
89
+ pEntity->scriptModule ()->isPersistent ())
88
90
{
89
91
lastShutdownFailReason_ = " destroyHasBaseEntitys" ;
90
92
return false ;
@@ -102,15 +104,25 @@ void Cellapp::onShutdown(bool first)
102
104
int count = g_serverConfig.getCellApp ().perSecsDestroyEntitySize ;
103
105
Entities<Entity>::ENTITYS_MAP& entities = this ->pEntities ()->getEntities ();
104
106
107
+ std::vector<Entity*> vecs;
108
+
105
109
while (count > 0 )
106
110
{
107
111
bool done = false ;
108
112
Entities<Entity>::ENTITYS_MAP::iterator iter = entities.begin ();
109
113
for (; iter != entities.end (); iter++)
110
114
{
111
- if (static_cast <Entity*>(iter->second .get ())->baseMailbox () != NULL &&
112
- static_cast <Entity*>(iter->second .get ())->scriptModule ()->isPersistent ())
115
+ Entity* pEntity = static_cast <Entity*>(iter->second .get ());
116
+ if (pEntity->baseMailbox () != NULL &&
117
+ pEntity->scriptModule ()->isPersistent ())
113
118
{
119
+ Space* space = Spaces::findSpace (pEntity->spaceID ());
120
+ if (space && space->creatorID () == pEntity->id ())
121
+ {
122
+ vecs.push_back (pEntity);
123
+ continue ;
124
+ }
125
+
114
126
this ->destroyEntity (static_cast <Entity*>(iter->second .get ())->id (), true );
115
127
116
128
count--;
@@ -119,6 +131,20 @@ void Cellapp::onShutdown(bool first)
119
131
}
120
132
}
121
133
134
+ // 如果count等于perSecsDestroyEntitySize说明上面已经没有可处理的东西了
135
+ // 剩下的应该都是space,可以开始销毁了
136
+ if (g_serverConfig.getCellApp ().perSecsDestroyEntitySize == count && vecs.size () > 0 )
137
+ {
138
+ std::vector<Entity*>::iterator iter1 = vecs.begin ();
139
+ for (; iter1 != vecs.end (); iter1++)
140
+ {
141
+ this ->destroyEntity (static_cast <Entity*>(*iter1)->id (), true );
142
+
143
+ count--;
144
+ done = true ;
145
+ }
146
+ }
147
+
122
148
if (!done)
123
149
break ;
124
150
}
0 commit comments