game2006/server/gameserver/gridservice.h
aozhiwei e70e3b335e 1
2021-03-16 16:52:06 +08:00

87 lines
2.7 KiB
C++

#pragma once
class Human;
class Entity;
class Room;
class Bullet;
class Car;
class Hero;
class GridCell;
class GridService
{
public:
GridService();
~GridService();
void Init(int width, int height, int cell_width);
void UnInit();
bool BroderOverFlow(int x, int y);
void GetAllCells(Room* room, int grid_id, std::set<GridCell*>& grid_list);
void GetAllCellsByXy(Room* room, int x, int y, std::set<GridCell*>& grid_list);
bool CanAdd(float x, float y);
void ClearRoomData(Room* room);
void AddHuman(Human* hum);
void MoveHuman(Human* hum);
void AddBullet(Bullet* bullet);
void MoveBullet(Bullet* bullet);
void DelBullet(Bullet* bullet);
void AddCar(Car* car);
void MoveCar(Car* car);
void DelCar(Car* car);
void AddHero(Hero* hero);
void MoveHero(Hero* hero);
void DelHero(Hero* hero);
void AddRoomEntity(Room* room, Entity* entity);
void DelRoomEntity(Room* room, Entity* entity);
void AddPermanentEntity(Entity* entity);
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
bool EntityInGridList(Room* room, Entity* entity, std::set<GridCell*>& grid_list);
bool InView(int a_grid, int b_grid);
bool InView(int grid_id, float x, float y);
void TouchLayer0EntityList(std::set<GridCell*>& grid_list,
std::function<void (Entity*, bool&)> func);
void TouchLayer1EntityList(int room_idx,
std::set<GridCell*>& grid_list,
std::function<void (Entity*, bool&)> func);
void TouchAllLayerEntityList(int room_idx,
std::set<GridCell*>& grid_list,
std::function<void (Entity*, bool&)> func);
void TouchAllLayerHumanList(int room_idx,
std::set<GridCell*>& grid_list,
std::function<void (Human*, bool&)> func);
void DeatchHuman(Human* hum);
private:
inline void GetGridList(int grid_id, int offset,
std::set<GridCell*>& grid_list);
void ComputeDiff(Room* room,
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:
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};
};