80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
#pragma once
|
|
|
|
class Entity;
|
|
class Human;
|
|
class Bullet;
|
|
|
|
struct GridCell
|
|
{
|
|
std::set<Human*> human_list;
|
|
std::set<Entity*> entity_list;
|
|
std::set<Bullet*> bullet_list;
|
|
};
|
|
|
|
/*
|
|
1 2 3
|
|
4 5 6
|
|
7 8 9
|
|
*/
|
|
class Human;
|
|
class Entity;
|
|
class Room;
|
|
class GridService
|
|
{
|
|
public:
|
|
GridService();
|
|
~GridService();
|
|
|
|
void Init(int width, int height, int cell_width);
|
|
void UnInit();
|
|
bool BroderOverFlow(int x, int y);
|
|
void GetAllCells(int grid_id, std::set<GridCell*>& grid_list);
|
|
void GetAllCellsByXy(int x, int y, std::set<GridCell*>& grid_list);
|
|
|
|
void AddHuman(Human* hum);
|
|
void MoveHuman(Human* hum);
|
|
|
|
void AddBullet(Bullet* bullet);
|
|
void MoveBullet(Bullet* bullet);
|
|
void DelBullet(Bullet* bullet);
|
|
|
|
void AddEntity(Entity* entity);
|
|
void DelEntity(Entity* entity);
|
|
|
|
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
|
|
bool EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list);
|
|
bool InView(int a_grid, int b_grid);
|
|
void RemoveFromGridList(std::set<GridCell*>& grid_list, Entity* entity);
|
|
|
|
private:
|
|
void Get123(int grid_id, std::set<GridCell*>& grid_list);
|
|
void Get456(int grid_id, std::set<GridCell*>& grid_list);
|
|
void Get789(int grid_id, std::set<GridCell*>& grid_list);
|
|
void Get147(int grid_id, std::set<GridCell*>& grid_list);
|
|
void Get258(int grid_id, std::set<GridCell*>& grid_list);
|
|
void Get369(int grid_id, std::set<GridCell*>& grid_list);
|
|
|
|
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;
|
|
GridCell* cells_ = nullptr;
|
|
int max_grid_id_ = 0;
|
|
int map_width_ = 0;
|
|
int map_height_ = 0;
|
|
int cell_width_ = 0;
|
|
int cell_count_per_row_ = 0;
|
|
int cell_count_per_col_ = 0;
|
|
int min_x_ = 0;
|
|
int min_y_ = 0;
|
|
int max_x_ = 0;
|
|
int max_y_ = 0;
|
|
int grid_offset_arr_[9] = {0};
|
|
|
|
};
|