add pathfinding.remove_agent
This commit is contained in:
parent
3aac6ecbcb
commit
5a6537c89d
@ -13,6 +13,11 @@ static int l_create_agent(lua::State* L) {
|
|||||||
return lua::pushinteger(L, level->pathfinding->createAgent());
|
return lua::pushinteger(L, level->pathfinding->createAgent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_remove_agent(lua::State* L) {
|
||||||
|
int id = lua::tointeger(L, 1);
|
||||||
|
return lua::pushboolean(L, level->pathfinding->removeAgent(id));
|
||||||
|
}
|
||||||
|
|
||||||
static int l_set_enabled(lua::State* L) {
|
static int l_set_enabled(lua::State* L) {
|
||||||
if (auto agent = get_agent(L)) {
|
if (auto agent = get_agent(L)) {
|
||||||
agent->enabled = lua::toboolean(L, 2);
|
agent->enabled = lua::toboolean(L, 2);
|
||||||
@ -88,6 +93,7 @@ static int l_set_max_visited_blocks(lua::State* L) {
|
|||||||
|
|
||||||
const luaL_Reg pathfindinglib[] = {
|
const luaL_Reg pathfindinglib[] = {
|
||||||
{"create_agent", lua::wrap<l_create_agent>},
|
{"create_agent", lua::wrap<l_create_agent>},
|
||||||
|
{"remove_agent", lua::wrap<l_remove_agent>},
|
||||||
{"set_enabled", lua::wrap<l_set_enabled>},
|
{"set_enabled", lua::wrap<l_set_enabled>},
|
||||||
{"is_enabled", lua::wrap<l_is_enabled>},
|
{"is_enabled", lua::wrap<l_is_enabled>},
|
||||||
{"make_route", lua::wrap<l_make_route>},
|
{"make_route", lua::wrap<l_make_route>},
|
||||||
|
|||||||
@ -63,6 +63,15 @@ int Pathfinding::createAgent() {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Pathfinding::removeAgent(int id) {
|
||||||
|
auto found = agents.find(id);
|
||||||
|
if (found != agents.end()) {
|
||||||
|
agents.erase(found);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Pathfinding::performAllAsync(int stepsPerAgent) {
|
void Pathfinding::performAllAsync(int stepsPerAgent) {
|
||||||
for (auto& [id, agent] : agents) {
|
for (auto& [id, agent] : agents) {
|
||||||
if (agent.state.finished) {
|
if (agent.state.finished) {
|
||||||
|
|||||||
@ -63,6 +63,8 @@ namespace voxels {
|
|||||||
|
|
||||||
int createAgent();
|
int createAgent();
|
||||||
|
|
||||||
|
bool removeAgent(int id);
|
||||||
|
|
||||||
void performAllAsync(int stepsPerAgent);
|
void performAllAsync(int stepsPerAgent);
|
||||||
|
|
||||||
Route perform(Agent& agent, int maxVisited = -1);
|
Route perform(Agent& agent, int maxVisited = -1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user