2015-06-17 18:38:18 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2015-06-17 18:38:18 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "scripting/js-bindings/auto/jsb_cocos2dx_navmesh_auto.hpp"
|
2015-06-17 18:38:18 +08:00
|
|
|
#if CC_USE_NAVMESH
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "scripting/js-bindings/manual/ScriptingCore.h"
|
|
|
|
#include "scripting/js-bindings/manual/cocos2d_specifics.hpp"
|
2016-04-18 15:09:21 +08:00
|
|
|
|
2015-06-17 18:38:18 +08:00
|
|
|
#include "navmesh/CCNavMesh.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "scripting/js-bindings/manual/js_manual_conversions.h"
|
2015-06-17 18:38:18 +08:00
|
|
|
|
|
|
|
static bool jsb_cocos2dx_navmesh_NavMeshAgent_move(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
2015-11-25 14:33:43 +08:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
2015-06-17 18:38:18 +08:00
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
|
|
|
cocos2d::NavMeshAgent* cobj = (cocos2d::NavMeshAgent *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2(cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if (argc == 1){
|
|
|
|
cocos2d::Vec3 arg0;
|
|
|
|
ok &= jsval_to_vector3(cx, args.get(0), &arg0);
|
|
|
|
JSB_PRECONDITION2(ok, cx, false, "jsb_cocos2dx_navmesh_NavMeshAgent_move : Error processing arguments");
|
|
|
|
cobj->move(arg0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2){
|
|
|
|
cocos2d::Vec3 arg0;
|
|
|
|
ok &= jsval_to_vector3(cx, args.get(0), &arg0);
|
|
|
|
JSB_PRECONDITION2(ok, cx, false, "jsb_cocos2dx_navmesh_NavMeshAgent_move : Error processing arguments");
|
|
|
|
|
|
|
|
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(1)));
|
|
|
|
|
|
|
|
cobj->move(arg0, [=](cocos2d::NavMeshAgent *agent, float totalTimeAfterMove)->void{
|
2015-12-17 21:55:10 +08:00
|
|
|
jsval arg[2];
|
|
|
|
JS::RootedObject jsobj(cx, js_get_or_create_jsobject<cocos2d::NavMeshAgent>(cx, agent));
|
|
|
|
arg[0] = OBJECT_TO_JSVAL(jsobj);
|
2015-06-17 18:38:18 +08:00
|
|
|
arg[1] = DOUBLE_TO_JSVAL((double)totalTimeAfterMove);
|
|
|
|
JS::RootedValue rval(cx);
|
|
|
|
|
2015-06-18 22:57:41 +08:00
|
|
|
bool invokeOk = func->invoke(2, arg, &rval);
|
|
|
|
if (!invokeOk && JS_IsExceptionPending(cx)) {
|
2015-06-17 18:38:18 +08:00
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-18 22:57:41 +08:00
|
|
|
|
|
|
|
JS_ReportError(cx, "jsb_cocos2dx_navmesh_NavMeshAgent_move : wrong number of arguments: %d, was expecting %d or %d", argc, 1, 2);
|
|
|
|
return false;
|
2015-06-17 18:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern JSObject *jsb_cocos2d_NavMeshAgent_prototype;
|
|
|
|
|
|
|
|
void register_all_cocos2dx_navmesh_manual(JSContext *cx, JS::HandleObject global)
|
|
|
|
{
|
2015-11-27 01:26:54 +08:00
|
|
|
JS::RootedObject proto(cx, jsb_cocos2d_NavMeshAgent_prototype);
|
|
|
|
JS_DefineFunction(cx, proto, "move", jsb_cocos2dx_navmesh_NavMeshAgent_move, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
2015-06-17 18:38:18 +08:00
|
|
|
}
|
|
|
|
#endif //#if CC_USE_NAVMESH
|