SyncAroundPlayers移动到MoveableEntity实现

This commit is contained in:
aozhiwei 2021-03-04 19:52:36 +08:00
parent ef24695c17
commit 1ce91113b9
4 changed files with 78 additions and 74 deletions

View File

@ -802,77 +802,6 @@ void Human::UpdatePoisoning()
} }
} }
void Human::SyncAroundPlayers(const char* file, int line, const char* func)
{
if (a8::HasBitFlag(status, HS_Disable)) {
return;
}
#ifdef DEBUG
#if 0
room->CheckPartObjects();
a8::UdpLog::Instance()->Debug("room_idx:%d syncaround begin %s %d %s",
{
room->GetRoomIdx(),
file,
line,
func
});
#endif
#endif
TouchAllLayerHumanList
(
[this, file, line, func] (Human* hum, bool& stop)
{
hum->AddToNewObjects(this);
#ifdef DEBUG
#if 0
{
std::string objs_str;
for (auto& obj : hum->part_objects) {
objs_str += a8::Format("%d ", {(long long)obj});
}
a8::UdpLog::Instance()->Debug("hum1 %d %s", {(long long)hum, objs_str});
}
{
std::string objs_str;
for (auto& obj : part_objects) {
objs_str += a8::Format("%d ", {(long long)obj});
}
a8::UdpLog::Instance()->Debug("hum2 %d %s", {(long long)this, objs_str});
}
room->CheckPartObjects(hum, this);
hum->InPartObjects(this);
#endif
#endif
assert(hum->part_objects.find(this) != hum->part_objects.end());
if (hum->part_objects.find(this) == hum->part_objects.end()) {
static long long last_debugout_tick = 0;
if (a8::XGetTickCount() - last_debugout_tick > 1000 * 10) {
last_debugout_tick = a8::XGetTickCount();
a8::UdpLog::Instance()->Warning
("SyncAroundPlayers error room_idx:%d, file:%s line:%d func:%s",
{
room->GetRoomIdx(),
file,
line,
func
});
}
}
});
#ifdef DEBUG
#if 0
room->CheckPartObjects();
a8::UdpLog::Instance()->Debug("syncaround end %s %d %s",
{
file,
line,
func
});
#endif
#endif
}
void Human::AutoLoadingBullet(bool manual) void Human::AutoLoadingBullet(bool manual)
{ {
Weapon* p_weapon = curr_weapon; Weapon* p_weapon = curr_weapon;
@ -1271,7 +1200,7 @@ int Human::GetPartObjectsCount()
return part_objects.size(); return part_objects.size();
} }
bool Human::InPartObjects(Human* target) bool Human::InPartObjects(Entity* target)
{ {
return part_objects.find(target) != part_objects.end(); return part_objects.find(target) != part_objects.end();
} }

View File

@ -185,7 +185,6 @@ class Human : public MoveableEntity
float GetMaxHP(); float GetMaxHP();
void UpdateSkill(); void UpdateSkill();
void UpdatePoisoning(); void UpdatePoisoning();
void SyncAroundPlayers(const char* file, int line, const char* func);
void AutoLoadingBullet(bool manual = false); void AutoLoadingBullet(bool manual = false);
void StartAction(ActionType_e action_type, void StartAction(ActionType_e action_type,
int action_duration, int action_duration,
@ -198,7 +197,7 @@ class Human : public MoveableEntity
void AddToNewObjects(Entity* entity); void AddToNewObjects(Entity* entity);
void AddToPartObjects(Entity* entity); void AddToPartObjects(Entity* entity);
void RemovePartObjects(Entity* entity); void RemovePartObjects(Entity* entity);
bool InPartObjects(Human* target); bool InPartObjects(Entity* target);
int GetPartObjectsCount(); int GetPartObjectsCount();
void RemoveObjects(Entity* entity); void RemoveObjects(Entity* entity);
void AddOutObjects(Entity* entity); void AddOutObjects(Entity* entity);

View File

@ -1,6 +1,7 @@
#include "precompile.h" #include "precompile.h"
#include "moveableentity.h" #include "moveableentity.h"
#include "room.h" #include "room.h"
#include "human.h"
void MoveableEntity::TouchLayer0EntityList(std::function<void (Entity*, bool&)> func) void MoveableEntity::TouchLayer0EntityList(std::function<void (Entity*, bool&)> func)
{ {
@ -21,3 +22,76 @@ void MoveableEntity::TouchAllLayerHumanList(std::function<void (Human*, bool&)>
{ {
room->grid_service->TouchAllLayerHumanList(room->GetRoomIdx(), grid_list_, func); room->grid_service->TouchAllLayerHumanList(room->GetRoomIdx(), grid_list_, func);
} }
void MoveableEntity::SyncAroundPlayers(const char* file, int line, const char* func)
{
#if 0
if (a8::HasBitFlag(status, HS_Disable)) {
return;
}
#endif
#ifdef DEBUG
#if 0
room->CheckPartObjects();
a8::UdpLog::Instance()->Debug("room_idx:%d syncaround begin %s %d %s",
{
room->GetRoomIdx(),
file,
line,
func
});
#endif
#endif
TouchAllLayerHumanList
(
[this, file, line, func] (Human* hum, bool& stop)
{
hum->AddToNewObjects(this);
#ifdef DEBUG
#if 0
{
std::string objs_str;
for (auto& obj : hum->part_objects) {
objs_str += a8::Format("%d ", {(long long)obj});
}
a8::UdpLog::Instance()->Debug("hum1 %d %s", {(long long)hum, objs_str});
}
{
std::string objs_str;
for (auto& obj : part_objects) {
objs_str += a8::Format("%d ", {(long long)obj});
}
a8::UdpLog::Instance()->Debug("hum2 %d %s", {(long long)this, objs_str});
}
room->CheckPartObjects(hum, this);
hum->InPartObjects(this);
#endif
#endif
assert(hum->InPartObjects(this));
if (!hum->InPartObjects(this)) {
static long long last_debugout_tick = 0;
if (a8::XGetTickCount() - last_debugout_tick > 1000 * 10) {
last_debugout_tick = a8::XGetTickCount();
a8::UdpLog::Instance()->Warning
("SyncAroundPlayers error room_idx:%d, file:%s line:%d func:%s",
{
room->GetRoomIdx(),
file,
line,
func
});
}
}
});
#ifdef DEBUG
#if 0
room->CheckPartObjects();
a8::UdpLog::Instance()->Debug("syncaround end %s %d %s",
{
file,
line,
func
});
#endif
#endif
}

View File

@ -15,6 +15,8 @@ class MoveableEntity : public RoomEntity
void TouchAllLayerEntityList(std::function<void (Entity*, bool&)> func); void TouchAllLayerEntityList(std::function<void (Entity*, bool&)> func);
void TouchAllLayerHumanList(std::function<void (Human*, bool&)> func); void TouchAllLayerHumanList(std::function<void (Human*, bool&)> func);
void SyncAroundPlayers(const char* file, int line, const char* func);
protected: protected:
int updated_times_ = 0; int updated_times_ = 0;