addobjectlater ok

This commit is contained in:
aozhiwei 2019-04-24 15:48:21 +08:00
parent 4ac5881160
commit 5120480f41
2 changed files with 19 additions and 3 deletions

View File

@ -180,6 +180,7 @@ void Room::AddPlayer(Player* hum)
unsigned short Room::AllocUniid()
{
while (GetEntityByUniId(++current_uniid) ||
later_add_hash_.find(current_uniid) != later_add_hash_.end() ||
current_uniid == 0) {}
return current_uniid;
}
@ -503,7 +504,6 @@ void Room::RemoveObjectLater(Entity* entity)
auto remove_func = [] (const a8::XParams& param)
{
Entity* entity = (Entity*)param.sender.GetUserData();
entity->room->uniid_hash_.erase(entity->entity_uniid);
switch (entity->entity_type) {
case ET_Bullet:
{
@ -521,6 +521,7 @@ void Room::RemoveObjectLater(Entity* entity)
}
break;
}
entity->room->uniid_hash_.erase(entity->entity_uniid);
delete entity;
};
xtimer.AddDeadLineTimerAndAttach(0,
@ -969,5 +970,19 @@ Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
void Room::AddObjectLater(Entity* entity)
{
auto add_func = [] (const a8::XParams& param)
{
Entity* entity = (Entity*)param.sender.GetUserData();
if (entity->entity_type == ET_Bullet) {
entity->room->moveable_hash_[entity->entity_uniid] = entity;
}
entity->room->uniid_hash_[entity->entity_uniid] = entity;
entity->room->later_add_hash_.erase(entity->entity_uniid);
};
later_add_hash_[entity->entity_uniid] = entity;
xtimer.AddDeadLineTimerAndAttach(0,
a8::XParams()
.SetSender(entity),
add_func,
&entity->xtimer_attacher.timer_list_);
}

View File

@ -75,7 +75,6 @@ public:
void ScatterDrop(Vector2D center, int drop_id);
void DropItem(Vector2D pos, int item_id, int item_count);
Obstacle* CreateObstacle(int id, float x, float y);
void CreateLoot(int equip_id, Vector2D pos, int count);
void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance);
@ -95,6 +94,7 @@ private:
void AirDrop(int appear_time, int box_id);
void ShuaPlane();
int NewTeam();
Obstacle* CreateObstacle(int id, float x, float y);
void CreateThings();
void CreateBuilding(int thing_id, float building_x, float building_y);
Obstacle* InternalCreateObstacle(int id, float x, float y,
@ -115,5 +115,6 @@ private:
std::map<std::string, Player*> accountid_hash_;
std::map<unsigned short, Entity*> moveable_hash_;
std::map<unsigned short, Entity*> uniid_hash_;
std::map<unsigned short, Entity*> later_add_hash_;
std::map<unsigned short, Human*> human_hash_;
};