game2004/server/gameserver/mapservice.h
2020-05-20 17:28:05 +08:00

42 lines
878 B
C++

#pragma once
class ColliderComponent;
struct CellNode
{
ColliderComponent* collider;
list_head entry;
CellNode* next = nullptr;
};
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);
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_;
};