2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
#include "base/ccConfig.h"
|
|
|
|
#if CC_USE_NAVMESH
|
2022-07-12 21:31:54 +08:00
|
|
|
# include "scripting/lua-bindings/manual/navmesh/lua_axis_navmesh_manual.h"
|
|
|
|
# include "scripting/lua-bindings/auto/lua_axis_navmesh_auto.hpp"
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "scripting/lua-bindings/manual/tolua_fix.h"
|
|
|
|
# include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
|
|
|
# include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
|
|
|
# include "navmesh/CCNavMesh.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int lua_axis_navmesh_NavMeshAgent_move(lua_State* tolua_S)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::NavMeshAgent* cobj = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
# if COCOS2D_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_Error tolua_err;
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# if COCOS2D_DEBUG >= 1
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(tolua_S, 1, "ax.NavMeshAgent", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
# endif
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
cobj = (axis::NavMeshAgent*)tolua_tousertype(tolua_S, 1, 0);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
# if COCOS2D_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!cobj)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(tolua_S, "invalid 'cobj' in function 'lua_axis_navmesh_NavMeshAgent_move'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
argc = lua_gettop(tolua_S) - 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 arg0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(tolua_S, 2, &arg0, "ax.NavMeshAgent:move");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(tolua_S, "invalid arguments in function 'lua_axis_navmesh_NavMeshAgent_move'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cobj->move(arg0);
|
|
|
|
lua_settop(tolua_S, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 arg0;
|
2019-11-23 20:27:39 +08:00
|
|
|
LUA_FUNCTION handler;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
ok &= luaval_to_vec3(tolua_S, 2, &arg0, "ax.NavMeshAgent:move");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
# if COCOS2D_DEBUG >= 1
|
|
|
|
if (!toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err))
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
goto tolua_lerror;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
handler = toluafix_ref_function(tolua_S, 3, 0);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (!ok)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(tolua_S, "invalid arguments in function 'lua_axis_navmesh_NavMeshAgent_move'", nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
cobj->move(arg0, [=](axis::NavMeshAgent* agent, float totalTimeAfterMove) {
|
2021-11-15 19:05:08 +08:00
|
|
|
auto stack = LuaEngine::getInstance()->getLuaStack();
|
2021-12-25 10:04:45 +08:00
|
|
|
auto Ls = stack->getLuaState();
|
2022-07-12 21:31:54 +08:00
|
|
|
object_to_luaval<axis::NavMeshAgent>(Ls, "ax.NavMeshAgent", (axis::NavMeshAgent*)agent);
|
2021-11-15 19:05:08 +08:00
|
|
|
tolua_pushnumber(Ls, (lua_Number)totalTimeAfterMove);
|
|
|
|
stack->executeFunctionByHandler(handler, 2);
|
2019-11-23 20:27:39 +08:00
|
|
|
});
|
|
|
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)cobj, handler);
|
|
|
|
lua_settop(tolua_S, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.NavMeshAgent:move", argc, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
# if COCOS2D_DEBUG >= 1
|
2019-11-23 20:27:39 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(tolua_S, "#ferror in function 'lua_axis_navmesh_NavMeshAgent_move'.", &tolua_err);
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extendNavMeshAgent(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "ax.NavMeshAgent");
|
2019-11-23 20:27:39 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "move", lua_axis_navmesh_NavMeshAgent_move);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int register_all_navmesh_manual(lua_State* L)
|
|
|
|
{
|
|
|
|
if (nullptr == L)
|
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
extendNavMeshAgent(L);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int register_navmesh_module(lua_State* L)
|
|
|
|
{
|
|
|
|
lua_getglobal(L, "_G");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1)) // stack:...,_G,
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
register_all_axis_navmesh(L);
|
2019-11-23 20:27:39 +08:00
|
|
|
register_all_navmesh_manual(L);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|