game2005/server/gameserver/mapservice.h
2020-10-28 11:50:16 +08:00

66 lines
1.4 KiB
C++

#pragma once
class Human;
class ColliderComponent;
struct CellNode
{
ColliderComponent* collider;
list_head entry;
CellNode* next = nullptr;
};
struct MovePathPoint
{
a8::Vec2 pos;
float distance = 0;
};
struct FindPathStatus
{
long long frameno = 0;
Human* hum = nullptr;
a8::Vec2 start_pos;
a8::Vec2 end_pos;
int curr_step = 0;
int max_step_num = 0;
std::vector<MovePathPoint> out_ponits;
};
class Room;
class MapService
{
public:
MapService();
~MapService();
void Init(int width, int height, int cell_width);
void UnInit();
void AddCollider(ColliderComponent* collider);
void RemoveCollider(ColliderComponent* collider);
void GetColliders(Room* room,
float world_x,
float world_y,
std::set<ColliderComponent*>& colliders);
int FindPathRequest(Human* hum,
const a8::Vec2& start_pos,
const a8::Vec2& end_pos,
int max_step_num);
FindPathStatus* QueryFindPathStatus(int query_id);
void RemoveFindPathRequest(Human* hum, int query_id);
private:
int GetGridId(float world_x, float world_y);
private:
list_head* map_cells_ = nullptr;
int map_width_ = 0;
int map_height_ = 0;
int cell_width_ = 0;
int max_grid_id_ = 0;
int grid_offset_arr_[9] = {0};
std::map<ColliderComponent*, CellNode*> node_hash_;
};