2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
#include "scripting/lua-bindings/manual/navmesh/lua_axis_navmesh_conversions.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "base/ccConfig.h"
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_USE_NAVMESH
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
|
|
|
# include "navmesh/CCNavMeshAgent.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# if COCOS2D_DEBUG >= 1
|
|
|
|
extern void luaval_to_native_err(lua_State* L, const char* msg, tolua_Error* err, const char* funcName);
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool luaval_to_navmeshagentparam(lua_State* L, int lo, axis::NavMeshAgentParam* outValue, const char* funcName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L || nullptr == outValue)
|
|
|
|
return false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!tolua_istable(L, lo, 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
# if COCOS2D_DEBUG >= 1
|
|
|
|
luaval_to_native_err(L, "#ferror:", &tolua_err, funcName);
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
ok = false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "radius");
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_gettable(L, lo);
|
|
|
|
outValue->radius = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : 0.6f;
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "height");
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_gettable(L, lo);
|
|
|
|
outValue->height = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : 2.0f;
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "maxAcceleration");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->maxAcceleration = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : 8.0f;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "maxSpeed");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->maxSpeed = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : 3.5f;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "collisionQueryRange");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->collisionQueryRange = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : outValue->radius * 12.0f;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "pathOptimizationRange");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->pathOptimizationRange = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : outValue->radius * 30.0f;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "separationWeight");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->separationWeight = lua_isnumber(L, -1) ? (float)lua_tonumber(L, -1) : 2.0f;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "updateFlags");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->updateFlags = lua_isnumber(L, -1) ? (unsigned char)lua_tonumber(L, -1)
|
|
|
|
: DT_CROWD_ANTICIPATE_TURNS | DT_CROWD_OPTIMIZE_VIS |
|
|
|
|
DT_CROWD_OPTIMIZE_TOPO | DT_CROWD_OBSTACLE_AVOIDANCE;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "obstacleAvoidanceType");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->obstacleAvoidanceType = lua_isnumber(L, -1) ? (unsigned char)lua_tonumber(L, -1) : 3;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, "queryFilterType");
|
|
|
|
lua_gettable(L, lo);
|
2021-12-25 10:04:45 +08:00
|
|
|
outValue->queryFilterType = lua_isnumber(L, -1) ? (unsigned char)lua_tonumber(L, -1) : 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool luaval_to_offmeshlinkdata(lua_State* L, int lo, axis::OffMeshLinkData* outValue, const char* funcName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L || nullptr == outValue)
|
|
|
|
return false;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ok = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!tolua_istable(L, lo, 0, &tolua_err))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
# if COCOS2D_DEBUG >= 1
|
|
|
|
luaval_to_native_err(L, "#ferror:", &tolua_err, funcName);
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
ok = false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "startPosition");
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_gettable(L, lo);
|
2019-11-23 20:27:39 +08:00
|
|
|
ok &= luaval_to_vec3(L, lua_gettop(L), &outValue->startPosition);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_pop(L, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
lua_pushstring(L, "endPosition");
|
|
|
|
ok &= luaval_to_vec3(L, lua_gettop(L), &outValue->endPosition);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
lua_pop(L, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void navmeshagentparam_to_luaval(lua_State* L, const axis::NavMeshAgentParam& inValue)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L)
|
|
|
|
return;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_newtable(L);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "radius");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.radius);
|
|
|
|
lua_rawset(L, -3);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "height");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.height);
|
|
|
|
lua_rawset(L, -3);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "maxAcceleration");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.maxAcceleration);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "maxSpeed");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.maxSpeed);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "collisionQueryRange");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.collisionQueryRange);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "pathOptimizationRange");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.pathOptimizationRange);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "separationWeight");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.separationWeight);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "updateFlags");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.updateFlags);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "obstacleAvoidanceType");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.obstacleAvoidanceType);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
lua_pushstring(L, "queryFilterType");
|
|
|
|
lua_pushnumber(L, (lua_Number)inValue.queryFilterType);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void offmeshlinkdata_to_luaval(lua_State* L, const axis::OffMeshLinkData& inValue)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L)
|
|
|
|
return;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushstring(L, "startPosition");
|
|
|
|
vec3_to_luaval(L, inValue.startPosition);
|
|
|
|
lua_rawset(L, -3);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_pushstring(L, "endPosition");
|
|
|
|
vec3_to_luaval(L, inValue.endPosition);
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|