add pathfinding.remove_agent

This commit is contained in:
MihailRis 2025-08-03 02:48:52 +03:00
parent 3aac6ecbcb
commit 5a6537c89d
3 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,11 @@ static int l_create_agent(lua::State* L) {
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) {
if (auto agent = get_agent(L)) {
agent->enabled = lua::toboolean(L, 2);
@ -88,6 +93,7 @@ static int l_set_max_visited_blocks(lua::State* L) {
const luaL_Reg pathfindinglib[] = {
{"create_agent", lua::wrap<l_create_agent>},
{"remove_agent", lua::wrap<l_remove_agent>},
{"set_enabled", lua::wrap<l_set_enabled>},
{"is_enabled", lua::wrap<l_is_enabled>},
{"make_route", lua::wrap<l_make_route>},

View File

@ -63,6 +63,15 @@ int Pathfinding::createAgent() {
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) {
for (auto& [id, agent] : agents) {
if (agent.state.finished) {

View File

@ -63,6 +63,8 @@ namespace voxels {
int createAgent();
bool removeAgent(int id);
void performAllAsync(int stepsPerAgent);
Route perform(Agent& agent, int maxVisited = -1);