diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 9cc0a84..8a3defa 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -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_); } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 12a393e..fc53683 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -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 accountid_hash_; std::map moveable_hash_; std::map uniid_hash_; + std::map later_add_hash_; std::map human_hash_; };