Rename cc in JSB (#1476)

* Rename __ccgl to __gl

* Rename __CCPrivateData to __PrivateData

* Change CanvasRenderingContext2D to global

* Change CanvasRenderingContext2D to global

* Change getDeviceMotionValue into Device

* Change FileUtils to global

* Change AudioEngine to global

* Change AudioEngine into Audio

* Remove cc in c++

* Remove __jsc__

* Change auto file template

* Name jsb_cocos2d_global to auto

* Reset jsb_cocos2dx_auto

* Register jsb_cocos2dx_global_auto
This commit is contained in:
wdzhangchukong
2018-08-24 17:03:50 +08:00
committed by minggo
parent 9e28e3420f
commit bf27fdd955
14 changed files with 157 additions and 62 deletions
+1
View File
@@ -80,6 +80,7 @@ scripting/js-bindings/auto/jsb_gfx_auto.cpp \
scripting/js-bindings/auto/jsb_cocos2dx_network_auto.cpp \
scripting/js-bindings/auto/jsb_renderer_auto.cpp \
scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp \
scripting/js-bindings/auto/jsb_cocos2dx_global_auto.cpp \
scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.cpp \
scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp \
scripting/js-bindings/manual/JavaScriptJavaBridge.cpp \
@@ -242,7 +242,7 @@ namespace se {
_globalObj->defineFunction("log", __log);
_globalObj->defineFunction("forceGC", __forceGC);
__jsb_CCPrivateData_class = Class::create("__CCPrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
__jsb_CCPrivateData_class->install();
@@ -292,7 +292,7 @@ namespace se {
JSObjectSetProperty(_cx, globalObj, propertyName, JSObjectMakeFunctionWithCallback(_cx, propertyName, __forceGC), kJSPropertyAttributeReadOnly, nullptr);
JSStringRelease(propertyName);
__jsb_CCPrivateData_class = Class::create("__CCPrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
__jsb_CCPrivateData_class->install();
@@ -524,7 +524,7 @@ namespace se {
JS::SetEnqueuePromiseJobCallback(_cx, onEnqueuePromiseJobCallback);
JS::SetGetIncumbentGlobalCallback(_cx, onGetIncumbentGlobalCallback);
__jsb_CCPrivateData_class = Class::create("__CCPrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, privateDataContructor);
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
__jsb_CCPrivateData_class->install();
@@ -143,7 +143,7 @@ namespace se {
obj->_obj.persistent().Reset();
obj->_rootCount = 0;
if (cls != nullptr && cls->_name == "__CCPrivateData")
if (cls != nullptr && cls->_name == "__PrivateData")
{
toReleaseObjects.push_back(obj);
}
@@ -428,7 +428,7 @@ namespace se {
_globalObj->defineFunction("log", __log);
_globalObj->defineFunction("forceGC", __forceGC);
__jsb_CCPrivateData_class = Class::create("__CCPrivateData", _globalObj, nullptr, nullptr);
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, nullptr);
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
__jsb_CCPrivateData_class->setCreateProto(false);
__jsb_CCPrivateData_class->install();
@@ -29,6 +29,7 @@
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp"
#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_global_auto.hpp"
#include "storage/local-storage/LocalStorage.h"
#include "cocos2d.h"
@@ -202,7 +203,15 @@ void __JSPlistDelegator::textHandler(void*, const char *ch, int len) {
static bool register_plist_parser(se::Object* obj)
{
se::Value v;
__ccObj->getProperty("PlistParser", &v);
se::Value jsbVal;
if (!obj->getProperty("jsb", &jsbVal))
{
se::HandleObject jsbObj(se::Object::createPlainObject());
jsbVal.setObject(jsbObj);
obj->setProperty("jsb", jsbVal);
}
se::Object* jsb = jsbVal.toObject();
jsb->getProperty("PlistParser", &v);
assert(v.isObject());
v.toObject()->defineFunction("getInstance", _SE(js_PlistParser_getInstance));
@@ -460,6 +469,57 @@ static bool js_cocos2dx_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback(
}
SE_BIND_FUNC(js_cocos2dx_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback)
static se::Object* __deviceMotionObject = nullptr;
static bool JSB_getDeviceMotionValue(se::State& s)
{
if (__deviceMotionObject == nullptr)
{
__deviceMotionObject = se::Object::createArrayObject(9);
__deviceMotionObject->root();
}
const auto& v = Device::getDeviceMotionValue();
__deviceMotionObject->setArrayElement(0, se::Value(v.accelerationX));
__deviceMotionObject->setArrayElement(1, se::Value(v.accelerationY));
__deviceMotionObject->setArrayElement(2, se::Value(v.accelerationZ));
__deviceMotionObject->setArrayElement(3, se::Value(v.accelerationIncludingGravityX));
__deviceMotionObject->setArrayElement(4, se::Value(v.accelerationIncludingGravityY));
__deviceMotionObject->setArrayElement(5, se::Value(v.accelerationIncludingGravityZ));
__deviceMotionObject->setArrayElement(6, se::Value(v.rotationRateAlpha));
__deviceMotionObject->setArrayElement(7, se::Value(v.rotationRateBeta));
__deviceMotionObject->setArrayElement(8, se::Value(v.rotationRateGamma));
s.rval().setObject(__deviceMotionObject);
return true;
}
SE_BIND_FUNC(JSB_getDeviceMotionValue)
static bool register_device(se::Object* obj)
{
se::Value device;
if (!obj->getProperty("Device", &device))
{
se::HandleObject deviceObj(se::Object::createPlainObject());
obj->setProperty("Device", se::Value(deviceObj));
device.setObject(deviceObj);
}
device.toObject()->defineFunction("getDeviceMotionValue", _SE(JSB_getDeviceMotionValue));
se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){
if (__deviceMotionObject != nullptr)
{
__deviceMotionObject->unroot();
__deviceMotionObject->decRef();
__deviceMotionObject = nullptr;
}
});
se::ScriptEngine::getInstance()->clearException();
return true;
}
static bool register_canvas_context2d(se::Object* obj)
{
_SE_DEFINE_PROP(CanvasRenderingContext2D, _width)
@@ -484,6 +544,7 @@ bool register_all_cocos2dx_manual(se::Object* obj)
{
register_plist_parser(obj);
register_sys_localStorage(obj);
register_device(obj);
register_canvas_context2d(obj);
return true;
}
@@ -42,8 +42,6 @@
using namespace cocos2d;
using namespace cocos2d::experimental;
se::Object* __jscObj = nullptr;
se::Object* __ccObj = nullptr;
se::Object* __jsbObj = nullptr;
se::Object* __glObj = nullptr;
@@ -1043,32 +1041,6 @@ static bool JSB_hideInputBox(se::State& s)
}
SE_BIND_FUNC(JSB_hideInputBox)
static se::Object* __deviceMotionObject = nullptr;
static bool JSB_getDeviceMotionValue(se::State& s)
{
if (__deviceMotionObject == nullptr)
{
__deviceMotionObject = se::Object::createArrayObject(9);
__deviceMotionObject->root();
}
const auto& v = Device::getDeviceMotionValue();
__deviceMotionObject->setArrayElement(0, se::Value(v.accelerationX));
__deviceMotionObject->setArrayElement(1, se::Value(v.accelerationY));
__deviceMotionObject->setArrayElement(2, se::Value(v.accelerationZ));
__deviceMotionObject->setArrayElement(3, se::Value(v.accelerationIncludingGravityX));
__deviceMotionObject->setArrayElement(4, se::Value(v.accelerationIncludingGravityY));
__deviceMotionObject->setArrayElement(5, se::Value(v.accelerationIncludingGravityZ));
__deviceMotionObject->setArrayElement(6, se::Value(v.rotationRateAlpha));
__deviceMotionObject->setArrayElement(7, se::Value(v.rotationRateBeta));
__deviceMotionObject->setArrayElement(8, se::Value(v.rotationRateGamma));
s.rval().setObject(__deviceMotionObject);
return true;
}
SE_BIND_FUNC(JSB_getDeviceMotionValue)
bool jsb_register_global_variables(se::Object* global)
{
__threadPool = ThreadPool::newFixedThreadPool(3);
@@ -1076,20 +1048,17 @@ bool jsb_register_global_variables(se::Object* global)
global->defineFunction("require", _SE(require));
global->defineFunction("requireModule", _SE(moduleRequire));
getOrCreatePlainObject_r("cc", global, &__ccObj);
getOrCreatePlainObject_r("jsb", global, &__jsbObj);
getOrCreatePlainObject_r("__jsc__", global, &__jscObj);
auto glContextCls = se::Class::create("WebGLRenderingContext", global, nullptr, nullptr);
glContextCls->install();
SAFE_DEC_REF(__glObj);
__glObj = se::Object::createObjectWithClass(glContextCls);
global->setProperty("__ccgl", se::Value(__glObj));
global->setProperty("__gl", se::Value(__glObj));
__jscObj->defineFunction("garbageCollect", _SE(jsc_garbageCollect));
__jscObj->defineFunction("dumpNativePtrToSeObjectMap", _SE(jsc_dumpNativePtrToSeObjectMap));
__jsbObj->defineFunction("garbageCollect", _SE(jsc_garbageCollect));
__jsbObj->defineFunction("dumpNativePtrToSeObjectMap", _SE(jsc_dumpNativePtrToSeObjectMap));
__jsbObj->defineFunction("loadImage", _SE(js_loadImage));
__jsbObj->defineFunction("setDebugViewText", _SE(js_setDebugViewText));
@@ -1099,7 +1068,6 @@ bool jsb_register_global_variables(se::Object* global)
__jsbObj->defineFunction("setPreferredFramesPerSecond", _SE(JSB_setPreferredFramesPerSecond));
__jsbObj->defineFunction("showInputBox", _SE(JSB_showInputBox));
__jsbObj->defineFunction("hideInputBox", _SE(JSB_hideInputBox));
__jsbObj->defineFunction("getDeviceMotionValue", _SE(JSB_getDeviceMotionValue));
global->defineFunction("__getPlatform", _SE(JSBCore_platform));
global->defineFunction("__getOS", _SE(JSBCore_os));
@@ -1121,13 +1089,6 @@ bool jsb_register_global_variables(se::Object* global)
delete __threadPool;
__threadPool = nullptr;
if (__deviceMotionObject != nullptr)
{
__deviceMotionObject->unroot();
__deviceMotionObject->decRef();
__deviceMotionObject = nullptr;
}
PoolManager::getInstance()->getCurrentPool()->clear();
});
@@ -1137,9 +1098,7 @@ bool jsb_register_global_variables(se::Object* global)
__moduleCache.clear();
SAFE_DEC_REF(__ccObj);
SAFE_DEC_REF(__jsbObj);
SAFE_DEC_REF(__jscObj);
SAFE_DEC_REF(__glObj);
});
@@ -33,7 +33,6 @@ namespace se {
class Value;
}
extern se::Object* __ccObj;
extern se::Object* __jsbObj;
extern se::Object* __glObj;
@@ -35,6 +35,7 @@
#include "cocos/scripting/js-bindings/auto/jsb_renderer_auto.hpp"
#include "cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp"
#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp"
#include "cocos/scripting/js-bindings/auto/jsb_cocos2dx_global_auto.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
#include "cocos/scripting/js-bindings/manual/jsb_node.hpp"
@@ -89,6 +90,7 @@ bool jsb_register_all_modules()
se->addRegisterCallback(jsb_register_gfx_manual);
se->addRegisterCallback(register_all_renderer);
se->addRegisterCallback(jsb_register_renderer_manual);
se->addRegisterCallback(register_all_cocos2dx_global);
se->addRegisterCallback(register_all_cocos2dx);
se->addRegisterCallback(register_all_cocos2dx_manual);
se->addRegisterCallback(register_platform_bindings);
@@ -1526,11 +1526,17 @@ static bool onReceiveNodeEvent(void* node, ScriptingCore::NodeEventType type)
bool jsb_register_Node_manual(se::Object* global)
{
#if STANDALONE_TEST
auto cls = se::Class::create("Node", __ccObj, nullptr, _SE(Node_constructor));
se::Object* ccObj = nullptr;
getOrCreatePlainObject_r("cc", global, &ccObj);
auto cls = se::Class::create("Node", ccObj, nullptr, _SE(Node_constructor));
cls->defineStaticFunction("create", _SE(Node_create));
cls->defineProperty("x", _SE(Node_get_x), _SE(Node_set_x));
cls->defineProperty("y", _SE(Node_get_y), _SE(Node_set_y));
cls->defineFunction("ctor", _SE(Node_ctor));
se::ScriptEngine::getInstance()->addAfterCleanupHook([](){
SAFE_DEC_REF(ccObj);
});
#else
auto cls = __jsb_cocos2d_Node_proto;
#endif
+6 -10
View File
@@ -5,7 +5,7 @@ prefix = cocos2dx
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = cc
target_namespace = jsb
android_headers =
@@ -30,7 +30,7 @@ replace_headers=
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = FileUtils$ SAXParser CanvasRenderingContext2D CanvasGradient Device
classes = SAXParser CanvasGradient
classes_need_extend =
@@ -43,13 +43,9 @@ field =
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = FileUtils::[getFileData setFilenameLookupDictionary destroyInstance getFullPathCache getContents],
SAXParser::[(?!(init))],
Device::[getDeviceMotionValue],
CanvasRenderingContext2D::[setCanvasBufferUpdatedCallback set_.+]
skip = SAXParser::[(?!(init))]
rename_functions = FileUtils::[loadFilenameLookupDictionaryFromFile=loadFilenameLookup],
CanvasRenderingContext2D::[getImageData=_getImageData]
rename_functions =
rename_classes = SAXParser::PlistParser
@@ -64,8 +60,8 @@ base_classes_to_skip = Ref Clonable
# classes that create no constructor
# Set is special and we will use a hand-written constructor
abstract_classes = SAXParser Device
abstract_classes = SAXParser
persistent_classes = FileUtils
persistent_classes =
classes_owned_by_cpp =
+70
View File
@@ -0,0 +1,70 @@
[cocos2d-x]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = cocos2dx_global
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace =
android_headers =
android_flags = -target armv7-none-linux-androideabi -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -DANDROID -D__ANDROID_API__=14 -gcc-toolchain %(gcc_toolchain_dir)s --sysroot=%(androidndkdir)s/platforms/android-14/arch-arm -idirafter %(androidndkdir)s/sources/android/support/include -idirafter %(androidndkdir)s/sysroot/usr/include -idirafter %(androidndkdir)s/sysroot/usr/include/arm-linux-androideabi -idirafter %(clangllvmdir)s/lib64/clang/5.0/include -I%(androidndkdir)s/sources/cxx-stl/llvm-libc++/include
clang_headers =
clang_flags = -nostdinc -x c++ -std=c++11 -fsigned-char -U__SSE__
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources
cocos_flags = -DANDROID
cxxgenerator_headers =
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/cocos2d.h
replace_headers=
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = FileUtils$ CanvasRenderingContext2D Device
classes_need_extend =
field =
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = FileUtils::[getFileData setFilenameLookupDictionary destroyInstance getFullPathCache getContents],
Device::[getDeviceMotionValue],
CanvasRenderingContext2D::[setCanvasBufferUpdatedCallback set_.+]
rename_functions = FileUtils::[loadFilenameLookupDictionaryFromFile=loadFilenameLookup],
CanvasRenderingContext2D::[getImageData=_getImageData]
rename_classes =
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip = Ref Clonable
# classes that create no constructor
# Set is special and we will use a hand-written constructor
abstract_classes = Device
persistent_classes = FileUtils
classes_owned_by_cpp =
+1
View File
@@ -148,6 +148,7 @@ def main():
'cocos2dx_audioengine.ini' : ('cocos2dx_audioengine', 'jsb_cocos2dx_audioengine_auto'),
'gfx.ini': ('gfx', 'jsb_gfx_auto'),
'renderer.ini': ('renderer', 'jsb_renderer_auto'),
'cocos2dx_global.ini' : ('cocos2d-x', 'jsb_cocos2dx_global_auto'),
}
target = 'spidermonkey'
generator_py = '%s/generator.py' % cxx_generator_root