82 lines
2.7 KiB
C++
82 lines
2.7 KiB
C++
#pragma once
|
|
|
|
class Human;
|
|
class Entity;
|
|
class Room;
|
|
class Bullet;
|
|
class Creature;
|
|
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 AddCreature(Creature* c);
|
|
void RemoveCreature(Creature* c);
|
|
void MoveCreature(Creature* c);
|
|
|
|
void AddBullet(Bullet* bullet);
|
|
void MoveBullet(Bullet* bullet);
|
|
void DelBullet(Bullet* bullet);
|
|
|
|
void AddRoomEntity(Room* room, Entity* entity);
|
|
void DelRoomEntity(Room* room, Entity* entity);
|
|
|
|
void AddPermanentEntity(Entity* entity);
|
|
|
|
bool CreatureInGridList(Creature* c, 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 TouchCreatures(int room_idx,
|
|
std::set<GridCell*>& grid_list,
|
|
std::function<void (Creature*, 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};
|
|
|
|
};
|