add RoomObstackeWeakPtr
This commit is contained in:
parent
d7064a0c9e
commit
d66076ce04
@ -3,7 +3,6 @@
|
|||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
#include "moveableentity.h"
|
#include "moveableentity.h"
|
||||||
#include "buff.h"
|
#include "buff.h"
|
||||||
#include "weakptr.h"
|
|
||||||
#include "trigger.h"
|
#include "trigger.h"
|
||||||
#include "ability.h"
|
#include "ability.h"
|
||||||
|
|
||||||
|
@ -8,36 +8,6 @@
|
|||||||
#include "metamgr.h"
|
#include "metamgr.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
enum HeroState_e : int
|
|
||||||
{
|
|
||||||
HSE_Idle = 0,
|
|
||||||
HSE_Thinking = 1,
|
|
||||||
HSE_Attack = 2,
|
|
||||||
HSE_RandomWalk = 3,
|
|
||||||
HSE_Pursuit = 4,
|
|
||||||
HSE_FollowMaster = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
class HeroAINode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HeroState_e main_state = HSE_Idle;
|
|
||||||
long long frameno = 0;
|
|
||||||
long long exec_frame_num = 0;
|
|
||||||
long long start_shot_frameno = 0;
|
|
||||||
long long next_random_move_frameno = 0;
|
|
||||||
int shot_times = 0;
|
|
||||||
int total_shot_times = 0;
|
|
||||||
int next_total_shot_times = 0;
|
|
||||||
|
|
||||||
long long param1 = 0;
|
|
||||||
CreatureWeakPtr target;
|
|
||||||
CreatureWeakPtr nearest_human;
|
|
||||||
long long last_check_nearest_human_frameno = 0;
|
|
||||||
a8::Vec2 shot_dir;
|
|
||||||
a8::Vec2 target_pos;
|
|
||||||
};
|
|
||||||
|
|
||||||
HeroAI::HeroAI()
|
HeroAI::HeroAI()
|
||||||
{
|
{
|
||||||
node_ = new HeroAINode();
|
node_ = new HeroAINode();
|
||||||
|
@ -1,10 +1,40 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <a8/vec2.h>
|
||||||
|
|
||||||
#include "aicomponent.h"
|
#include "aicomponent.h"
|
||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
|
|
||||||
enum HeroState_e : int;
|
enum HeroState_e : int
|
||||||
class HeroAINode;
|
{
|
||||||
|
HSE_Idle = 0,
|
||||||
|
HSE_Thinking = 1,
|
||||||
|
HSE_Attack = 2,
|
||||||
|
HSE_RandomWalk = 3,
|
||||||
|
HSE_Pursuit = 4,
|
||||||
|
HSE_FollowMaster = 5
|
||||||
|
};
|
||||||
|
|
||||||
|
class HeroAINode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HeroState_e main_state = HSE_Idle;
|
||||||
|
long long frameno = 0;
|
||||||
|
long long exec_frame_num = 0;
|
||||||
|
long long start_shot_frameno = 0;
|
||||||
|
long long next_random_move_frameno = 0;
|
||||||
|
int shot_times = 0;
|
||||||
|
int total_shot_times = 0;
|
||||||
|
int next_total_shot_times = 0;
|
||||||
|
|
||||||
|
long long param1 = 0;
|
||||||
|
CreatureWeakPtr target;
|
||||||
|
CreatureWeakPtr nearest_human;
|
||||||
|
long long last_check_nearest_human_frameno = 0;
|
||||||
|
a8::Vec2 shot_dir;
|
||||||
|
a8::Vec2 target_pos;
|
||||||
|
};
|
||||||
|
|
||||||
class HeroAI : public AIComponent
|
class HeroAI : public AIComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
RoomObstacle::RoomObstacle():Obstacle()
|
RoomObstacle::RoomObstacle():Obstacle()
|
||||||
{
|
{
|
||||||
|
weak_ptr_chunk_.Set(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomObstacle::~RoomObstacle()
|
RoomObstacle::~RoomObstacle()
|
||||||
@ -549,3 +550,18 @@ void RoomObstacle::ProcKeepRangeBuff()
|
|||||||
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
|
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtr RoomObstacle::AllocWeakPtr()
|
||||||
|
{
|
||||||
|
RoomObstacleWeakPtr ptr;
|
||||||
|
ptr.Attach(this);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtr& RoomObstacle::GetWeakPtrRef()
|
||||||
|
{
|
||||||
|
if (!weak_ptr_.Get()) {
|
||||||
|
weak_ptr_.Attach(this);
|
||||||
|
}
|
||||||
|
return weak_ptr_;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "weakptr.h"
|
||||||
#include "gridservice.h"
|
#include "gridservice.h"
|
||||||
#include "obstacle.h"
|
#include "obstacle.h"
|
||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
@ -28,6 +29,10 @@ class RoomObstacle : public Obstacle
|
|||||||
virtual void Die(Room* room) override;
|
virtual void Die(Room* room) override;
|
||||||
Entity* GetRealObject(Room* room);
|
Entity* GetRealObject(Room* room);
|
||||||
|
|
||||||
|
RoomObstacleWeakPtrChunk* GetWeakPtrChunk() { return &weak_ptr_chunk_; };
|
||||||
|
RoomObstacleWeakPtr AllocWeakPtr();
|
||||||
|
RoomObstacleWeakPtr& GetWeakPtrRef();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SpecExplosion();
|
void SpecExplosion();
|
||||||
void ActiveSelfExplosion();
|
void ActiveSelfExplosion();
|
||||||
@ -44,6 +49,9 @@ private:
|
|||||||
void ProcKeepRangeBuff();
|
void ProcKeepRangeBuff();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
RoomObstacleWeakPtr weak_ptr_;
|
||||||
|
RoomObstacleWeakPtrChunk weak_ptr_chunk_;
|
||||||
|
|
||||||
std::set<GridCell*>* grid_list_ = nullptr;
|
std::set<GridCell*>* grid_list_ = nullptr;
|
||||||
int explosion_times_ = 0;
|
int explosion_times_ = 0;
|
||||||
bool detached_ = false;
|
bool detached_ = false;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
#include "weakptr.h"
|
#include "weakptr.h"
|
||||||
#include "creature.h"
|
#include "creature.h"
|
||||||
|
#include "roomobstacle.h"
|
||||||
|
|
||||||
CreatureWeakPtrChunk::CreatureWeakPtrChunk()
|
CreatureWeakPtrChunk::CreatureWeakPtrChunk()
|
||||||
{
|
{
|
||||||
@ -109,3 +110,111 @@ void CreatureWeakPtr::Detach()
|
|||||||
list_del_init(&entry_);
|
list_del_init(&entry_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtrChunk::RoomObstacleWeakPtrChunk()
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&ptrs_);
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtrChunk::~RoomObstacleWeakPtrChunk()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
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_);
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtr::RoomObstacleWeakPtr(const RoomObstacleWeakPtr& x)
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&entry_);
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtr::RoomObstacleWeakPtr(RoomObstacleWeakPtr&& x)
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&entry_);
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
x.Detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
// return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomObstacleWeakPtr::~RoomObstacleWeakPtr()
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
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_) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
ptr_ = c;
|
||||||
|
list_add_tail(&entry_, &chunk->ptrs_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomObstacleWeakPtr::Detach()
|
||||||
|
{
|
||||||
|
if (ptr_) {
|
||||||
|
ptr_ = nullptr;
|
||||||
|
list_del_init(&entry_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,3 +41,42 @@ class CreatureWeakPtr
|
|||||||
|
|
||||||
friend class CreatureWeakPtrChunk;
|
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;
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user