OnGridListChange
This commit is contained in:
parent
9dfdb4952d
commit
1e88baf74e
@ -119,15 +119,37 @@ void GridService::AddHuman(Human* hum)
|
||||
Get123456789(hum->grid_id, hum->grid_list);
|
||||
}
|
||||
|
||||
void GridService::MoveHuman(Human* hum, float x, float y,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list
|
||||
)
|
||||
void GridService::MoveHuman(Human* hum)
|
||||
{
|
||||
int new_x = (int)hum->pos.x + cell_width_;
|
||||
int new_y = (int)hum->pos.y + cell_width_;
|
||||
int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_;
|
||||
if (new_grid_id != hum->grid_id) {
|
||||
std::set<GridCell*> inc_grid_list;
|
||||
std::set<GridCell*> dec_grid_list;
|
||||
std::set<GridCell*> old_grid_list = hum->grid_list;
|
||||
ComputeDiff(hum->grid_id, new_grid_id,
|
||||
hum->grid_list,
|
||||
inc_grid_list,
|
||||
dec_grid_list);
|
||||
cells_[hum->grid_id].human_list.erase(hum);
|
||||
cells_[new_grid_id].human_list.insert(hum);
|
||||
hum->grid_id = new_grid_id;
|
||||
hum->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list);
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GridService::AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list)
|
||||
bool GridService::HumanInGridList(Human* hum, std::set<GridCell*>& grid_list)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool GridService::EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list)
|
||||
{
|
||||
|
||||
}
|
||||
@ -146,3 +168,11 @@ void GridService::GetGridList(int grid_id, int offset,
|
||||
grid_list.insert(&cells_[tmp_grid_id]);
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::ComputeDiff(int old_grid_id, int new_grid_id,
|
||||
std::set<GridCell*>& grid_list,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list)
|
||||
{
|
||||
int diff_grid = new_grid_id - old_grid_id;
|
||||
}
|
||||
|
@ -35,16 +35,20 @@ class GridService
|
||||
void Get369(int grid_id, std::set<GridCell*>& grid_list);
|
||||
|
||||
void AddHuman(Human* hum);
|
||||
void MoveHuman(Human* hum, float x, float y,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list
|
||||
);
|
||||
void MoveHuman(Human* hum);
|
||||
|
||||
void AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list);
|
||||
|
||||
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
|
||||
bool EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list);
|
||||
|
||||
private:
|
||||
inline void GetGridList(int grid_id, int offset,
|
||||
std::set<GridCell*>& grid_list);
|
||||
void ComputeDiff(int old_grid_id, int new_grid_id,
|
||||
std::set<GridCell*>& grid_list,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list);
|
||||
|
||||
private:
|
||||
Room* room_ = nullptr;
|
||||
|
@ -584,14 +584,9 @@ void Human::AddToPartObjects(Entity* entity)
|
||||
part_objects.insert(entity);
|
||||
}
|
||||
|
||||
void Human::RemoveNewObjects(Entity* entity)
|
||||
void Human::RemoveObjects(Entity* entity)
|
||||
{
|
||||
new_objects.erase(entity);
|
||||
}
|
||||
|
||||
void Human::RemovePartObjects(Entity* entity)
|
||||
{
|
||||
part_objects.erase(entity);
|
||||
del_objects.insert(entity->entity_uniid);
|
||||
}
|
||||
|
||||
bool Human::HasLiveTeammate()
|
||||
@ -713,3 +708,59 @@ void Human::RefreshView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list
|
||||
)
|
||||
{
|
||||
for (GridCell* cell : inc_grid_list) {
|
||||
for (Human* hum : cell->human_list) {
|
||||
if (!room->grid_service.HumanInGridList(hum, old_grid_list)) {
|
||||
hum->AddToNewObjects(this);
|
||||
hum->AddToPartObjects(this);
|
||||
AddToNewObjects(hum);
|
||||
AddToPartObjects(hum);
|
||||
}
|
||||
}
|
||||
for (Entity* entity : cell->entity_list) {
|
||||
if (!room->grid_service.EntityInGridList(entity, old_grid_list)) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Building:
|
||||
case ET_Obstacle:
|
||||
{
|
||||
AddToNewObjects(entity);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (GridCell* cell : dec_grid_list) {
|
||||
for (Human* entity : cell->human_list) {
|
||||
if (!room->grid_service.HumanInGridList(entity, grid_list)) {
|
||||
RemoveObjects(entity);
|
||||
}
|
||||
}
|
||||
for (Entity* entity : cell->entity_list) {
|
||||
if (!room->grid_service.EntityInGridList(entity, grid_list)) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Building:
|
||||
case ET_Obstacle:
|
||||
{
|
||||
RemoveObjects(entity);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,18 +115,22 @@ class Human : public Entity
|
||||
void DecHP(float dec_hp, int killer_id, const std::string& killer_name);
|
||||
void AddToNewObjects(Entity* entity);
|
||||
void AddToPartObjects(Entity* entity);
|
||||
void RemoveNewObjects(Entity* entity);
|
||||
void RemovePartObjects(Entity* entity);
|
||||
void RemoveObjects(Entity* entity);
|
||||
bool HasLiveTeammate();
|
||||
void Land();
|
||||
void DoJump();
|
||||
void FindLocation();
|
||||
void RefreshView();
|
||||
void OnGridListChange(std::set<GridCell*>& old_grid_list,
|
||||
std::set<GridCell*>& inc_grid_list,
|
||||
std::set<GridCell*>& dec_grid_list
|
||||
);
|
||||
|
||||
protected:
|
||||
long long last_shot_frameno_ = 0;
|
||||
std::set<Entity*> new_objects;
|
||||
std::set<Entity*> part_objects;
|
||||
std::set<int> del_objects;
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
@ -101,6 +101,7 @@ void Player::UpdateMove()
|
||||
moved_frames = 0;
|
||||
return;
|
||||
}
|
||||
bool move_ok = false;
|
||||
int speed = std::max(1, (int)GetSpeed());
|
||||
for (int i = 0; i < speed; ++i) {
|
||||
Vector2D old_pos = pos;
|
||||
@ -112,6 +113,10 @@ void Player::UpdateMove()
|
||||
}
|
||||
break;
|
||||
}
|
||||
move_ok = true;
|
||||
}
|
||||
if (move_ok) {
|
||||
room->grid_service.MoveHuman(this);
|
||||
}
|
||||
if (last_collision_door && !TestCollision(last_collision_door)) {
|
||||
last_collision_door = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user