ManaPlus
Public Member Functions | Static Public Member Functions | Static Private Member Functions
NavigationManager Class Reference

#include <navigationmanager.h>

Public Member Functions

 NavigationManager ()
 
 ~NavigationManager ()
 

Static Public Member Functions

static ResourceloadWalkLayer (const Map *const map)
 

Static Private Member Functions

static bool findWalkableTile (int &x1, int &y1, const int width, const int height, const MetaTile *const tiles, const int *const data)
 
static void fillNum (int x, int y, const int width, const int height, const int num, const MetaTile *const tiles, int *const data)
 

Detailed Description

Definition at line 32 of file navigationmanager.h.

Constructor & Destructor Documentation

◆ NavigationManager()

NavigationManager::NavigationManager ( )

Definition at line 55 of file navigationmanager.cpp.

56 {
57 }

◆ ~NavigationManager()

NavigationManager::~NavigationManager ( )

Definition at line 59 of file navigationmanager.cpp.

60 {
61 }

Member Function Documentation

◆ fillNum()

void NavigationManager::fillNum ( int  x,
int  y,
const int  width,
const int  height,
const int  num,
const MetaTile *const  tiles,
int *const  data 
)
staticprivate

Definition at line 92 of file navigationmanager.cpp.

98 {
99  STD_VECTOR<Cell> cells;
100  cells.push_back(Cell(x, y));
101  while (!cells.empty())
102  {
103  const Cell cell = cells.back();
104  cells.pop_back();
105  int ptr;
106  x = cell.x;
107  y = cell.y;
108  data[x + width * y] = num;
109  if (x > 0)
110  {
111  ptr = (x - 1) + width * y;
112  if (data[ptr] == 0)
113  {
114  if ((tiles[ptr].blockmask & blockWalkMask) == 0)
115  cells.push_back(Cell(x - 1, y));
116  else
117  data[ptr] = -num;
118  }
119  }
120  if (x < width - 1)
121  {
122  ptr = (x + 1) + width * y;
123  if (data[ptr] == 0)
124  {
125  if ((tiles[ptr].blockmask & blockWalkMask) == 0)
126  cells.push_back(Cell(x + 1, y));
127  else
128  data[ptr] = -num;
129  }
130  }
131  if (y > 0)
132  {
133  ptr = x + width * (y - 1);
134  if (data[ptr] == 0)
135  {
136  if ((tiles[ptr].blockmask & blockWalkMask) == 0)
137  cells.push_back(Cell(x, y - 1));
138  else
139  data[ptr] = -num;
140  }
141  }
142  if (y < height - 1)
143  {
144  ptr = x + width * (y + 1);
145  if (data[ptr] == 0)
146  {
147  if ((tiles[ptr].blockmask & blockWalkMask) == 0)
148  cells.push_back(Cell(x, y + 1));
149  else
150  data[ptr] = -num;
151  }
152  }
153  }
154 }
uint32_t data
static const int blockWalkMask

References blockWalkMask, data, x, and y.

◆ findWalkableTile()

bool NavigationManager::findWalkableTile ( int &  x1,
int &  y1,
const int  width,
const int  height,
const MetaTile *const  tiles,
const int *const  data 
)
staticprivate

Definition at line 156 of file navigationmanager.cpp.

161 {
162  for (int y = 0; y < height; y ++)
163  {
164  const int y2 = y * width;
165  for (int x = 0; x < width; x ++)
166  {
167  const int ptr = x + y2;
168  if (((tiles[ptr].blockmask & blockWalkMask) == 0) &&
169  data[ptr] == 0)
170  {
171  x1 = x;
172  y1 = y;
173  return true;
174  }
175  }
176  }
177  return false;
178 }

References blockWalkMask, data, x, and y.

◆ loadWalkLayer()

Resource * NavigationManager::loadWalkLayer ( const Map *const  map)
static

Definition at line 64 of file navigationmanager.cpp.

65 {
66  if (map == nullptr)
67  return nullptr;
68 
69  const int width = map->getWidth();
70  const int height = map->getHeight();
71  if (width < 2 || height < 2)
72  return nullptr;
73  WalkLayer *const walkLayer = new WalkLayer(width, height);
74 
75  const MetaTile *const tiles = map->getMetaTiles();
76  int *const data = walkLayer->getData();
77  if ((tiles == nullptr) || (data == nullptr))
78  return walkLayer;
79 
80  int x = 0;
81  int y = 0;
82  int num = 1;
83  while (findWalkableTile(x, y, width, height, tiles, data))
84  {
85  fillNum(x, y, width, height, num, tiles, data);
86  num ++;
87  }
88 
89  return walkLayer;
90 }
const MetaTile * getMetaTiles() const
Definition: map.h:344
int getHeight() const
Definition: map.h:172
int getWidth() const
Definition: map.h:166
static bool findWalkableTile(int &x1, int &y1, const int width, const int height, const MetaTile *const tiles, const int *const data)
static void fillNum(int x, int y, const int width, const int height, const int num, const MetaTile *const tiles, int *const data)
int * getData()
Definition: walklayer.h:38

References data, WalkLayer::getData(), Map::getHeight(), Map::getMetaTiles(), Map::getWidth(), x, and y.

Referenced by WalkLayerLoader::load().


The documentation for this class was generated from the following files: