1
This commit is contained in:
parent
b1305976bb
commit
933a39dfed
@ -175,5 +175,6 @@ void Car::SyncPos()
|
||||
room->grid_service->MoveHuman(hum);
|
||||
}
|
||||
}
|
||||
room->grid_service->MoveCar(this);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ GridCell::GridCell()
|
||||
human_list_.push_back(std::set<Human*>());
|
||||
entity_list_.push_back(std::set<Entity*>());
|
||||
bullet_list_.push_back(std::set<Bullet*>());
|
||||
car_list_.push_back(std::set<Car*>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,6 +231,7 @@ void GridService::MoveCar(Car* car)
|
||||
cells_[car->GetGridId()].RemoveCar(car);
|
||||
cells_[new_grid_id].AddCar(car);
|
||||
car->SetGridId(new_grid_id);
|
||||
car->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1497,6 +1497,79 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grids,
|
||||
}
|
||||
}
|
||||
|
||||
void Human::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
|
||||
}
|
||||
|
||||
void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
|
||||
{
|
||||
{
|
||||
|
@ -209,11 +209,12 @@ class Human : public MoveableEntity
|
||||
void DoGetOn(int obj_uniid);
|
||||
void DoGetDown();
|
||||
void FindLocation();
|
||||
void RefreshView();
|
||||
void OnGridListChange(std::set<GridCell*>& old_grids,
|
||||
virtual void RefreshView() override;
|
||||
virtual void OnGridListChange(std::set<GridCell*>& old_grids,
|
||||
std::set<GridCell*>& inc_grids,
|
||||
std::set<GridCell*>& dec_grids
|
||||
);
|
||||
) override;
|
||||
virtual void SyncAroundPlayers(const char* file, int line, const char* func) override;
|
||||
void FillMFActivePlayerData(cs::MFActivePlayerData* player_data);
|
||||
void FillMFGasData(cs::MFGasData* gas_data);
|
||||
bool CanSee(const Human* hum) const;
|
||||
|
@ -23,75 +23,56 @@ void MoveableEntity::TouchAllLayerHumanList(std::function<void (Human*, bool&)>
|
||||
room->grid_service->TouchAllLayerHumanList(room->GetRoomIdx(), grid_list_, func);
|
||||
}
|
||||
|
||||
void MoveableEntity::RefreshView()
|
||||
{
|
||||
TouchAllLayerHumanList
|
||||
(
|
||||
[this] (Human* hum, bool& stop)
|
||||
{
|
||||
hum->AddToNewObjects(this);
|
||||
hum->AddToPartObjects(this);
|
||||
});
|
||||
}
|
||||
|
||||
void MoveableEntity::OnGridListChange(std::set<GridCell*>& old_grids,
|
||||
std::set<GridCell*>& inc_grids,
|
||||
std::set<GridCell*>& dec_grids
|
||||
)
|
||||
{
|
||||
{
|
||||
room->grid_service->TouchAllLayerHumanList
|
||||
(
|
||||
room->GetRoomIdx(),
|
||||
inc_grids,
|
||||
[this, &old_grids] (Human* hum, bool& stop)
|
||||
{
|
||||
if (!room->grid_service->HumanInGridList(hum, old_grids)) {
|
||||
hum->AddToNewObjects(this);
|
||||
hum->AddToPartObjects(this);
|
||||
hum->RemoveOutObjects(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
room->grid_service->TouchAllLayerHumanList
|
||||
(
|
||||
room->GetRoomIdx(),
|
||||
dec_grids,
|
||||
[this] (Human* hum, bool& stop)
|
||||
{
|
||||
if (!room->grid_service->HumanInGridList(hum, GetGridList())) {
|
||||
hum->AddOutObjects(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -15,7 +15,12 @@ class MoveableEntity : public RoomEntity
|
||||
void TouchAllLayerEntityList(std::function<void (Entity*, bool&)> func);
|
||||
void TouchAllLayerHumanList(std::function<void (Human*, bool&)> func);
|
||||
|
||||
void SyncAroundPlayers(const char* file, int line, const char* func);
|
||||
virtual void RefreshView();
|
||||
virtual void OnGridListChange(std::set<GridCell*>& old_grids,
|
||||
std::set<GridCell*>& inc_grids,
|
||||
std::set<GridCell*>& dec_grids
|
||||
);
|
||||
virtual void SyncAroundPlayers(const char* file, int line, const char* func);
|
||||
|
||||
protected:
|
||||
int updated_times_ = 0;
|
||||
|
@ -564,6 +564,7 @@ Car* Room::CreateCar(Human* driver,
|
||||
AddToEntityHash(car);
|
||||
grid_service->AddCar(car);
|
||||
car->BroadcastFullState(this);
|
||||
car->RefreshView();
|
||||
return car;
|
||||
}
|
||||
|
||||
|
@ -168,9 +168,9 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
);
|
||||
hum->meta = MetaMgr::Instance()->human_meta;
|
||||
hum->room = room;
|
||||
room->AddPlayer(hum);
|
||||
hum->ProcPrepareItems(msg.prepare_items());
|
||||
hum->ProcPrepareItems2(msg.prepare_items2());
|
||||
room->AddPlayer(hum);
|
||||
PlayerMgr::Instance()->IncAccountNum(msg.account_id());
|
||||
if (JsonDataMgr::Instance()->channel != 0 &&
|
||||
JsonDataMgr::Instance()->channel != channel) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user