AddToNewObjects

This commit is contained in:
aozhiwei 2019-04-23 20:28:27 +08:00
parent 4822180ce9
commit 854e168ae7
10 changed files with 94 additions and 63 deletions

View File

@ -95,13 +95,7 @@ void Bullet::OnHit(std::vector<Entity*>& objects)
obstacle->ClearColliders(); obstacle->ClearColliders();
room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop()); room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
} }
room->TouchPlayerList(a8::XParams() obstacle->BroadcastFullState();
.SetSender(obstacle),
[] (Player* hum, a8::XParams& param)
{
Obstacle* obstacle = (Obstacle*)param.sender.GetUserData();
hum->AddToNewObjects(obstacle);
});
} }
} }
break; break;

View File

@ -80,3 +80,16 @@ void Entity::FindLocationWithTarget(Entity* target)
DestoryCollider(target_collider); DestoryCollider(target_collider);
DestoryCollider(a_collider); DestoryCollider(a_collider);
} }
void Entity::BroadcastFullState()
{
#if 0
room->TouchPlayerList(a8::XParams()
.SetSender(obstacle),
[] (Player* hum, a8::XParams& param)
{
Obstacle* obstacle = (Obstacle*)param.sender.GetUserData();
hum->AddToNewObjects(obstacle);
});
#endif
}

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "gridservice.h"
namespace cs namespace cs
{ {
class MFObjectPart; class MFObjectPart;
@ -48,6 +50,8 @@ class Entity
bool deleted = false; bool deleted = false;
a8::XTimerAttacher xtimer_attacher; a8::XTimerAttacher xtimer_attacher;
int grid_id = 0;
std::set<GridCell*> grid_list;
Obstacle* last_collision_door = nullptr; Obstacle* last_collision_door = nullptr;
Entity(); Entity();
@ -61,5 +65,6 @@ class Entity
bool TestCollision(Entity* b); bool TestCollision(Entity* b);
void ClearColliders(); void ClearColliders();
void FindLocationWithTarget(Entity* target); void FindLocationWithTarget(Entity* target);
void BroadcastFullState();
}; };

View File

@ -111,7 +111,7 @@ void GridService::MoveHuman(Human* hum, float x, float y,
} }
void GridService::AddEntity(Entity* entity) void GridService::AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list)
{ {
} }

View File

@ -1,10 +1,12 @@
#pragma once #pragma once
class Entity;
class Human; class Human;
struct GridCell struct GridCell
{ {
std::set<Human*> human_list; std::set<Human*> human_list;
std::set<Entity*> entity_list;
}; };
/* /*
@ -37,7 +39,7 @@ class GridService
std::set<GridCell*>& dec_grid_list std::set<GridCell*>& dec_grid_list
); );
void AddEntity(Entity* entity); void AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list);
private: private:
inline void GetGridList(int grid_id, int offset, inline void GetGridList(int grid_id, int offset,

View File

@ -663,3 +663,29 @@ void Human::FindLocation()
FindLocationWithTarget(target); FindLocationWithTarget(target);
} }
} }
void Human::RefreshView()
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list) {
hum->AddToNewObjects(this);
hum->AddToPartObjects(this);
AddToNewObjects(hum);
AddToPartObjects(hum);
}
for (Entity* entity : cell->entity_list) {
switch (entity->entity_type) {
case ET_Building:
case ET_Obstacle:
{
AddToNewObjects(entity);
}
break;
default:
{
}
break;
}
}
}
}

View File

@ -29,7 +29,6 @@ class Human : public Entity
MetaData::Player* meta = nullptr; MetaData::Player* meta = nullptr;
MetaData::Equip* helmet_meta = nullptr; MetaData::Equip* helmet_meta = nullptr;
MetaData::Equip* chest_meta = nullptr; MetaData::Equip* chest_meta = nullptr;
int grid_id = 0;
Vector2D move_dir; Vector2D move_dir;
Vector2D attack_dir; Vector2D attack_dir;
@ -122,6 +121,7 @@ class Human : public Entity
void Land(); void Land();
void DoJump(); void DoJump();
void FindLocation(); void FindLocation();
void RefreshView();
protected: protected:

View File

@ -550,7 +550,6 @@ void Player::ObstacleInteraction(Obstacle* entity)
} }
return true; return true;
}); });
} else {
} }
} }
@ -989,4 +988,3 @@ void Player::FillMFGasData(cs::MFGasData* gas_data)
gas_data->set_rad_old(room->gas_data.rad_old); gas_data->set_rad_old(room->gas_data.rad_old);
gas_data->set_rad_new(room->gas_data.rad_new); gas_data->set_rad_new(room->gas_data.rad_new);
} }

View File

@ -263,39 +263,12 @@ void Room::AddPlayer(Player* hum)
accountid_hash_[hum->account_id] = hum; accountid_hash_[hum->account_id] = hum;
human_hash_[hum->entity_uniid] = hum; human_hash_[hum->entity_uniid] = hum;
++alive_count_; ++alive_count_;
hum->AddToNewObjects(hum);
hum->AddToPartObjects(hum);
for (auto& pair : human_hash_) {
if (pair.second != hum) {
pair.second->AddToNewObjects(hum);
pair.second->AddToPartObjects(hum);
hum->AddToNewObjects(pair.second);
hum->AddToPartObjects(pair.second);
if (!hum->team_uuid.empty() && pair.second->team_uuid == hum->team_uuid) {
if (!pair.second->team_members) {
pair.second->team_id = NewTeam();
pair.second->team_members = &team_hash_[pair.second->team_id];
pair.second->team_members->insert(pair.second);
}
pair.second->team_members->insert(hum);
hum->team_id = pair.second->team_id;
}
}
}
for (auto& pair : uniid_hash_) {
switch (pair.second->entity_type) {
case ET_Building:
case ET_Obstacle:
{ {
hum->AddToNewObjects(pair.second); std::set<GridCell*> inc_grid_list;
} grid_service.AddHuman(hum, inc_grid_list);
break; hum->RefreshView();
default:
{
}
break;
}
} }
MatchTeam(hum);
} }
unsigned short Room::AllocUniid() unsigned short Room::AllocUniid()
@ -332,14 +305,10 @@ void Room::ShuaAndroid()
moveable_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum;
human_hash_[hum->entity_uniid] = hum; human_hash_[hum->entity_uniid] = hum;
++alive_count_; ++alive_count_;
{
for (auto& pair : human_hash_) { std::set<GridCell*> inc_grid_list;
if (pair.second != hum) { grid_service.AddHuman(hum, inc_grid_list);
pair.second->AddToNewObjects(hum); hum->RefreshView();
pair.second->AddToPartObjects(hum);
hum->AddToNewObjects(pair.second);
hum->AddToPartObjects(pair.second);
}
} }
} }
} }
@ -568,8 +537,9 @@ void Room::DropItem(Vector2D pos, int item_id, int item_count)
entity->count = item_count; entity->count = item_count;
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { {
pair.second->AddToNewObjects(entity); std::set<GridCell*> inc_grid_list;
grid_service.AddEntity(entity, inc_grid_list);
} }
} }
} }
@ -595,8 +565,9 @@ void Room::CreateDoor(Building* building, int door_idx)
building->pos.y + entity->door_state0->y() - building->meta->i->tileheight() / 2.0); building->pos.y + entity->door_state0->y() - building->meta->i->tileheight() / 2.0);
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { {
pair.second->AddToNewObjects(entity); std::set<GridCell*> inc_grid_list;
grid_service.AddEntity(entity, inc_grid_list);
} }
} }
} }
@ -615,8 +586,9 @@ void Room::CreateHouseObstacle(Building* building, int id, float x, float y)
building->pos.y + y - building->meta->i->tileheight() / 2.0); building->pos.y + y - building->meta->i->tileheight() / 2.0);
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { {
pair.second->AddToNewObjects(entity); std::set<GridCell*> inc_grid_list;
grid_service.AddEntity(entity, inc_grid_list);
} }
} }
} }
@ -636,8 +608,9 @@ void Room::CreateObstacle(int id, float x, float y)
entity->pos = Vector2D(x, y); entity->pos = Vector2D(x, y);
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { {
pair.second->AddToNewObjects(entity); std::set<GridCell*> inc_grid_list;
grid_service.AddEntity(entity, inc_grid_list);
} }
} }
} }
@ -655,8 +628,9 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
entity->count = count; entity->count = count;
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { {
pair.second->AddToNewObjects(entity); std::set<GridCell*> inc_grid_list;
grid_service.AddEntity(entity, inc_grid_list);
} }
} }
} }
@ -1063,6 +1037,23 @@ void Room::AutoMatchTeam()
#endif #endif
} }
void Room::MatchTeam(Human* hum)
{
for (auto& pair : human_hash_) {
if (pair.second != hum) {
if (!hum->team_uuid.empty() && pair.second->team_uuid == hum->team_uuid) {
if (!pair.second->team_members) {
pair.second->team_id = NewTeam();
pair.second->team_members = &team_hash_[pair.second->team_id];
pair.second->team_members->insert(pair.second);
}
pair.second->team_members->insert(hum);
hum->team_id = pair.second->team_id;
}
}
}
}
void Room::InitAirDrop() void Room::InitAirDrop()
{ {
std::list<MetaData::AirDrop>& air_drops = MetaMgr::Instance()->GetAirDrops(); std::list<MetaData::AirDrop>& air_drops = MetaMgr::Instance()->GetAirDrops();
@ -1152,5 +1143,4 @@ void Room::ShuaPlane()
hum->AddToPartObjects(pair.second); hum->AddToPartObjects(pair.second);
} }
} }
} }

View File

@ -5,6 +5,7 @@
#include "frameevent.h" #include "frameevent.h"
#include "framemaker.h" #include "framemaker.h"
#include "gridservice.h"
namespace MetaData namespace MetaData
{ {
@ -39,6 +40,7 @@ public:
RoomProfile profile; RoomProfile profile;
a8::XTimer xtimer; a8::XTimer xtimer;
Plane plane; Plane plane;
GridService grid_service;
~Room(); ~Room();
void Init(); void Init();
@ -95,6 +97,7 @@ private:
Vector2D& out_pos); Vector2D& out_pos);
void OutputDebugLog(); void OutputDebugLog();
void AutoMatchTeam(); void AutoMatchTeam();
void MatchTeam(Human* hum);
void InitAirDrop(); void InitAirDrop();
void AirDrop(int appear_time, int box_id); void AirDrop(int appear_time, int box_id);
void ShuaPlane(); void ShuaPlane();