1
This commit is contained in:
parent
8452642179
commit
b4fb10686c
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "mapsearchnode.h"
|
#include "mapsearchnode.h"
|
||||||
#include "mapservice.h"
|
#include "mapservice.h"
|
||||||
|
#include "human.h"
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
float MapSearchNode::GoalDistanceEstimate(MapSearchNode &node_goal)
|
float MapSearchNode::GoalDistanceEstimate(MapSearchNode &node_goal)
|
||||||
{
|
{
|
||||||
@ -31,14 +33,14 @@ bool MapSearchNode::GetSuccessors(AStarSearch<MapSearchNode> *astarsearch, MapSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapSearchNode new_node;
|
MapSearchNode new_node;
|
||||||
new_node.map_service = map_service;
|
new_node.hum = hum;
|
||||||
for (int index = 0; index < GRID9_AGROUD_CELL_NUM; ++index) {
|
for (int index = 0; index < GRID9_AGROUD_CELL_NUM; ++index) {
|
||||||
int cell_x = x + GRID9_AGROUND_CELL_INDEX[index][0];
|
int cell_x = x + GRID9_AGROUND_CELL_INDEX[index][0];
|
||||||
int cell_y = y + GRID9_AGROUND_CELL_INDEX[index][1];
|
int cell_y = y + GRID9_AGROUND_CELL_INDEX[index][1];
|
||||||
if (parent_x == cell_x && parent_y == cell_y) {
|
if (parent_x == cell_x && parent_y == cell_y) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (map_service->GetMap(cell_x, cell_y ) < TILE_STATE_CLOSED) {
|
if (hum->room->map_service->GetMap(cell_x, cell_y ) < TILE_STATE_CLOSED) {
|
||||||
new_node = MapSearchNode(cell_x, cell_y);
|
new_node = MapSearchNode(cell_x, cell_y);
|
||||||
astarsearch->AddSuccessor(new_node);
|
astarsearch->AddSuccessor(new_node);
|
||||||
}
|
}
|
||||||
@ -50,9 +52,9 @@ bool MapSearchNode::GetSuccessors(AStarSearch<MapSearchNode> *astarsearch, MapSe
|
|||||||
float MapSearchNode::GetCost(MapSearchNode &successor)
|
float MapSearchNode::GetCost(MapSearchNode &successor)
|
||||||
{
|
{
|
||||||
if (x != successor.x && y != successor.y) {
|
if (x != successor.x && y != successor.y) {
|
||||||
return (float)(map_service->GetMap(x, y) + 0.41421356);
|
return (float)(hum->room->map_service->GetMap(x, y) + 0.41421356);
|
||||||
}
|
}
|
||||||
return (float)map_service->GetMap(x, y);
|
return (float)hum->room->map_service->GetMap(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapSearchNode::IsSameState(MapSearchNode &rhs)
|
bool MapSearchNode::IsSameState(MapSearchNode &rhs)
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include "framework/stlastar.h"
|
#include "framework/stlastar.h"
|
||||||
|
|
||||||
class MapService;
|
class Human;
|
||||||
class MapSearchNode
|
class MapSearchNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int x = 0; // the (x,y) positions of the node
|
int x = 0; // the (x,y) positions of the node
|
||||||
int y = 0;
|
int y = 0;
|
||||||
MapService* map_service = nullptr;
|
Human* hum = nullptr;
|
||||||
|
|
||||||
MapSearchNode() {}
|
MapSearchNode() {}
|
||||||
MapSearchNode(int px, int py) {x = px; y = py; }
|
MapSearchNode(int px, int py) {x = px; y = py; }
|
||||||
|
@ -267,9 +267,23 @@ FindPathStatus* MapService::AddFindPathRequest(Human* hum,
|
|||||||
status->hum = hum;
|
status->hum = hum;
|
||||||
status->start_pos = start_pos;
|
status->start_pos = start_pos;
|
||||||
status->end_pos = end_pos;
|
status->end_pos = end_pos;
|
||||||
status->curr_step = 0;
|
status->search_step = 0;
|
||||||
status->max_step_num = max_step_num;
|
status->max_step_num = max_step_num;
|
||||||
list_add_tail(&status->entry, &findpath_list_);
|
list_add_tail(&status->entry, &findpath_list_);
|
||||||
|
{
|
||||||
|
MapSearchNode node_start;
|
||||||
|
MapSearchNode node_goal;
|
||||||
|
node_start.hum = hum;
|
||||||
|
node_goal.hum = hum;
|
||||||
|
|
||||||
|
node_start.x = int(start_pos.x / map_width_);
|
||||||
|
node_start.y = int(start_pos.y / map_height_);
|
||||||
|
|
||||||
|
node_goal.x = int(end_pos.x / map_width_);
|
||||||
|
node_goal.y = int(end_pos.y / map_height_);
|
||||||
|
|
||||||
|
status->astar_search.SetStartAndGoalStates(node_start, node_goal);
|
||||||
|
}
|
||||||
findpath_requests_hash_[hum] = status;
|
findpath_requests_hash_[hum] = status;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -290,12 +304,15 @@ void MapService::DelFindPathRequest(Human* hum, FindPathStatus* status)
|
|||||||
|
|
||||||
void MapService::FindPathUpdate(FindPathStatus* find_status)
|
void MapService::FindPathUpdate(FindPathStatus* find_status)
|
||||||
{
|
{
|
||||||
|
do {
|
||||||
|
find_status->search_state = find_status->astar_search.SearchStep();
|
||||||
|
++find_status->search_step;
|
||||||
|
} while (find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapService::FindOk(FindPathStatus* find_status)
|
bool MapService::FindOk(FindPathStatus* find_status)
|
||||||
{
|
{
|
||||||
return false;
|
return find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapService::MoveDone(FindPathStatus* find_status)
|
bool MapService::MoveDone(FindPathStatus* find_status)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framework/stlastar.h"
|
#include "mapsearchnode.h"
|
||||||
|
|
||||||
class Human;
|
class Human;
|
||||||
class ColliderComponent;
|
class ColliderComponent;
|
||||||
@ -35,11 +35,13 @@ struct FindPathStatus
|
|||||||
Human* hum = nullptr;
|
Human* hum = nullptr;
|
||||||
a8::Vec2 start_pos;
|
a8::Vec2 start_pos;
|
||||||
a8::Vec2 end_pos;
|
a8::Vec2 end_pos;
|
||||||
int curr_step = 0;
|
int search_step = 0;
|
||||||
int max_step_num = 0;
|
int max_step_num = 0;
|
||||||
int path_index = 0;
|
int path_index = 0;
|
||||||
std::vector<MovePathPoint> out_points;
|
std::vector<MovePathPoint> out_points;
|
||||||
list_head entry;
|
list_head entry;
|
||||||
|
int search_state = AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING;
|
||||||
|
AStarSearch<MapSearchNode> astar_search;
|
||||||
|
|
||||||
FindPathStatus()
|
FindPathStatus()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user