80 lines
2.2 KiB
C++
80 lines
2.2 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);
|
|
void GetSpecColliders(long long flags,
|
|
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);
|
|
bool CollisionDetection(Room* room,
|
|
bool through_wall,
|
|
const a8::Vec2& pos,
|
|
ColliderComponent* collider);
|
|
bool CollisionDetectionAndGetCollider(Room* room,
|
|
bool through_wall,
|
|
const a8::Vec2& pos,
|
|
ColliderComponent* collider,
|
|
ColliderComponent** pickup_collider);
|
|
|
|
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_;
|
|
|
|
};
|