remove roomobstacle weakptr
This commit is contained in:
parent
4816e94a3d
commit
17658a756e
@ -1710,7 +1710,7 @@ void Creature::SummonObstacle(Buff* buff, int id, const Position& target_pos)
|
||||
obstacle->SetRotate(*p_rotate);
|
||||
}
|
||||
obstacle->context_ability = context_ability;
|
||||
slave_things_.push_back(std::make_tuple(buff->meta->buff_id(), obstacle->GetWeakPtrRef()));
|
||||
slave_things_.push_back(std::make_tuple(buff->meta->buff_id(), obstacle->GetEntityWeakPtrRef()));
|
||||
if (buff->skill_meta) {
|
||||
SkillHelper::ProcSummonObstacle(buff->skill_meta, obstacle);
|
||||
}
|
||||
@ -1939,16 +1939,17 @@ void Creature::RemoveSurplusHero(int hero_id, int num)
|
||||
void Creature::RemoveSurplusObstacle(int buff_id, int id, int num)
|
||||
{
|
||||
if (slave_things_.size() >= num && num > 0) {
|
||||
std::vector<RoomObstacleWeakPtr> matched_things;
|
||||
std::vector<EntityWeakPtr> matched_things;
|
||||
for (auto& itr : slave_things_) {
|
||||
if (std::get<0>(itr) == buff_id &&
|
||||
std::get<1>(itr).Get() &&
|
||||
std::get<1>(itr).Get()->meta->thing_id() == id) {
|
||||
std::get<1>(itr).Get()->IsRoomObstacle() &&
|
||||
std::get<1>(itr).Get()->AsRoomObstacle()->meta->thing_id() == id) {
|
||||
matched_things.push_back(std::get<1>(itr));
|
||||
}
|
||||
}
|
||||
while (matched_things.size() > num) {
|
||||
matched_things[0].Get()->Destory();
|
||||
matched_things[0].Get()->AsRoomObstacle()->Destory();
|
||||
matched_things.erase(matched_things.begin());
|
||||
}
|
||||
}
|
||||
@ -2967,10 +2968,10 @@ void Creature::TraverseEffect(std::function<void (Effect*, bool&)> cb)
|
||||
|
||||
void Creature::RemoveSkillObstacle(const mt::Skill* skill_meta)
|
||||
{
|
||||
std::vector<RoomObstacleWeakPtr> del_obs;
|
||||
std::vector<EntityWeakPtr> del_obs;
|
||||
for (auto itr = slave_things_.begin(); itr != slave_things_.end(); ++itr) {
|
||||
RoomObstacleWeakPtr ob = std::get<1>(*itr);
|
||||
if (ob.Get() && ob.Get()->skill_meta == skill_meta) {
|
||||
EntityWeakPtr ob = std::get<1>(*itr);
|
||||
if (ob.Get() && ob.Get()->IsRoomObstacle() && ob.Get()->AsRoomObstacle()->skill_meta == skill_meta) {
|
||||
del_obs.push_back(ob);
|
||||
}
|
||||
}
|
||||
@ -2978,12 +2979,12 @@ void Creature::RemoveSkillObstacle(const mt::Skill* skill_meta)
|
||||
int save_num = skill_meta->_number_meta->number() * 2 - 2;
|
||||
if (del_obs.size() > save_num & save_num > 0) {
|
||||
for (int i = 0; i < del_obs.size() - save_num; ++i) {
|
||||
del_obs[i].Get()->Destory();
|
||||
del_obs[i].Get()->AsRoomObstacle()->Destory();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto ob : del_obs) {
|
||||
ob.Get()->Destory();
|
||||
ob.Get()->AsRoomObstacle()->Destory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ private:
|
||||
std::map<int, std::shared_ptr<Effect>> effect_hash_;
|
||||
std::map<int, list_head> slave_heros_;
|
||||
std::map<int, list_head> slave_things2_;
|
||||
std::list<std::tuple<int, RoomObstacleWeakPtr>> slave_things_;
|
||||
std::list<std::tuple<int, EntityWeakPtr>> slave_things_;
|
||||
a8::XTimerWp auto_switch_weapon_timer_;
|
||||
a8::XTimerWp reload_delay_timer_;
|
||||
int follow_times_ = 0;
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
bool debug_trace = false;
|
||||
bool added_to_over_room = false;
|
||||
glm::vec3 last_player_jump_pos;
|
||||
std::map<int, RoomObstacleWeakPtr> mine_objects;
|
||||
std::map<int, EntityWeakPtr> mine_objects;
|
||||
const mt::PveGeminiMode* pve_mode_meta = nullptr;
|
||||
const mt::PveGemini* pve_instance = nullptr;
|
||||
int pve_human_num = 0;
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
RoomObstacle::RoomObstacle():Obstacle()
|
||||
{
|
||||
weak_ptr_chunk_.Set(this);
|
||||
INIT_LIST_HEAD(&entry);
|
||||
}
|
||||
|
||||
@ -51,7 +50,7 @@ void RoomObstacle::Initialize()
|
||||
Obstacle::Initialize();
|
||||
xtimer_attacher.SetOwner(&room->xtimer);
|
||||
if (meta->_sweep_tags != 0) {
|
||||
room->mine_objects[GetUniId()] = GetWeakPtrRef();
|
||||
room->mine_objects[GetUniId()] = GetEntityWeakPtrRef();
|
||||
}
|
||||
born_frameno = room->GetFrameNo();
|
||||
}
|
||||
@ -591,21 +590,6 @@ void RoomObstacle::ProcKeepRangeBuff()
|
||||
}
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr RoomObstacle::AllocWeakPtr()
|
||||
{
|
||||
RoomObstacleWeakPtr ptr;
|
||||
ptr.Attach(this);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr& RoomObstacle::GetWeakPtrRef()
|
||||
{
|
||||
if (!weak_ptr_.Get()) {
|
||||
weak_ptr_.Attach(this);
|
||||
}
|
||||
return weak_ptr_;
|
||||
}
|
||||
|
||||
void RoomObstacle::OnBattleStart(Room* room)
|
||||
{
|
||||
if (master.Get()) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "weakptr.h"
|
||||
#include "gridservice.h"
|
||||
#include "obstacle.h"
|
||||
#include "weakptr.h"
|
||||
|
||||
class Ability;
|
||||
class RoomObstacle : public Obstacle
|
||||
@ -34,9 +33,6 @@ class RoomObstacle : public Obstacle
|
||||
virtual void Die(Room* room) override;
|
||||
Entity* GetRealObject(Room* room);
|
||||
|
||||
RoomObstacleWeakPtrChunk* GetWeakPtrChunk() { return &weak_ptr_chunk_; };
|
||||
RoomObstacleWeakPtr AllocWeakPtr();
|
||||
RoomObstacleWeakPtr& GetWeakPtrRef();
|
||||
void Destory();
|
||||
void PushCollisionObjects();
|
||||
void DestoryAt(int time);
|
||||
@ -66,9 +62,6 @@ private:
|
||||
void RemoveSameSkillObstacle();
|
||||
|
||||
protected:
|
||||
RoomObstacleWeakPtr weak_ptr_;
|
||||
RoomObstacleWeakPtrChunk weak_ptr_chunk_;
|
||||
|
||||
std::shared_ptr<std::set<GridCell*>> grid_list_;
|
||||
int explosion_times_ = 0;
|
||||
bool detached_ = false;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "precompile.h"
|
||||
#include "weakptr.h"
|
||||
#include "creature.h"
|
||||
#include "roomobstacle.h"
|
||||
#include "perf.h"
|
||||
|
||||
CreatureWeakPtrChunk::CreatureWeakPtrChunk()
|
||||
@ -121,120 +120,6 @@ void CreatureWeakPtr::Detach()
|
||||
}
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtrChunk::RoomObstacleWeakPtrChunk()
|
||||
{
|
||||
INIT_LIST_HEAD(&ptrs_);
|
||||
++Perf::Instance()->o_wptr_chunk_num;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtrChunk::~RoomObstacleWeakPtrChunk()
|
||||
{
|
||||
Clear();
|
||||
--Perf::Instance()->o_wptr_chunk_num;
|
||||
}
|
||||
|
||||
void RoomObstacleWeakPtrChunk::Clear()
|
||||
{
|
||||
struct RoomObstacleWeakPtr *weakptr, *tmp;
|
||||
struct list_head ptr_list;
|
||||
|
||||
list_replace_init(&ptrs_, &ptr_list);
|
||||
list_for_each_entry_safe(weakptr, tmp, &ptr_list, entry_) {
|
||||
weakptr->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void RoomObstacleWeakPtrChunk::Set(RoomObstacle* c)
|
||||
{
|
||||
ptr_ = c;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr::RoomObstacleWeakPtr()
|
||||
{
|
||||
INIT_LIST_HEAD(&entry_);
|
||||
++Perf::Instance()->o_wptr_num;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr::RoomObstacleWeakPtr(const RoomObstacleWeakPtr& x)
|
||||
{
|
||||
INIT_LIST_HEAD(&entry_);
|
||||
if (x.ptr_) {
|
||||
Attach(x.ptr_);
|
||||
}
|
||||
++Perf::Instance()->o_wptr_num;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr::RoomObstacleWeakPtr(RoomObstacleWeakPtr&& x)
|
||||
{
|
||||
INIT_LIST_HEAD(&entry_);
|
||||
if (x.ptr_) {
|
||||
Attach(x.ptr_);
|
||||
x.Detach();
|
||||
}
|
||||
++Perf::Instance()->o_wptr_num;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr& RoomObstacleWeakPtr::operator=(const RoomObstacleWeakPtr& x)
|
||||
{
|
||||
if (ptr_) {
|
||||
Detach();
|
||||
}
|
||||
if (x.ptr_) {
|
||||
Attach(x.ptr_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr&& RoomObstacleWeakPtr::operator=(RoomObstacleWeakPtr&& x)
|
||||
{
|
||||
if (ptr_) {
|
||||
Detach();
|
||||
}
|
||||
if (x.ptr_) {
|
||||
Attach(x.ptr_);
|
||||
x.Detach();
|
||||
}
|
||||
A8_ABORT();
|
||||
//return *this;
|
||||
}
|
||||
|
||||
RoomObstacleWeakPtr::~RoomObstacleWeakPtr()
|
||||
{
|
||||
Reset();
|
||||
--Perf::Instance()->o_wptr_num;
|
||||
}
|
||||
|
||||
void RoomObstacleWeakPtr::Reset()
|
||||
{
|
||||
if (ptr_) {
|
||||
Detach();
|
||||
}
|
||||
}
|
||||
|
||||
RoomObstacle* RoomObstacleWeakPtr::Get()
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
void RoomObstacleWeakPtr::Attach(RoomObstacle* c)
|
||||
{
|
||||
Reset();
|
||||
RoomObstacleWeakPtrChunk* chunk = c->GetWeakPtrChunk();
|
||||
if (c != chunk->ptr_) {
|
||||
A8_ABORT();
|
||||
}
|
||||
ptr_ = c;
|
||||
list_add_tail(&entry_, &chunk->ptrs_);
|
||||
}
|
||||
|
||||
void RoomObstacleWeakPtr::Detach()
|
||||
{
|
||||
if (ptr_) {
|
||||
ptr_ = nullptr;
|
||||
list_del_init(&entry_);
|
||||
}
|
||||
}
|
||||
|
||||
EntityWeakPtrChunk::EntityWeakPtrChunk()
|
||||
{
|
||||
INIT_LIST_HEAD(&ptrs_);
|
||||
|
@ -42,45 +42,6 @@ class CreatureWeakPtr
|
||||
friend class CreatureWeakPtrChunk;
|
||||
};
|
||||
|
||||
class RoomObstacle;
|
||||
|
||||
class RoomObstacleWeakPtrChunk
|
||||
{
|
||||
public:
|
||||
|
||||
RoomObstacleWeakPtrChunk();
|
||||
~RoomObstacleWeakPtrChunk();
|
||||
void Clear();
|
||||
void Set(RoomObstacle* c);
|
||||
|
||||
private:
|
||||
RoomObstacle* ptr_ = nullptr;
|
||||
list_head ptrs_;
|
||||
friend class RoomObstacleWeakPtr;
|
||||
};
|
||||
|
||||
class RoomObstacleWeakPtr
|
||||
{
|
||||
public:
|
||||
|
||||
RoomObstacleWeakPtr();
|
||||
RoomObstacleWeakPtr(const RoomObstacleWeakPtr& x);
|
||||
RoomObstacleWeakPtr(RoomObstacleWeakPtr&& x);
|
||||
RoomObstacleWeakPtr& operator=(const RoomObstacleWeakPtr& x);
|
||||
RoomObstacleWeakPtr&& operator=(RoomObstacleWeakPtr&& x);
|
||||
~RoomObstacleWeakPtr();
|
||||
void Reset();
|
||||
RoomObstacle* Get();
|
||||
void Attach(RoomObstacle* c);
|
||||
void Detach();
|
||||
|
||||
private:
|
||||
RoomObstacle* ptr_ = nullptr;
|
||||
list_head entry_;
|
||||
|
||||
friend class RoomObstacleWeakPtrChunk;
|
||||
};
|
||||
|
||||
class Entity;
|
||||
|
||||
class EntityWeakPtrChunk
|
||||
|
Loading…
x
Reference in New Issue
Block a user