This commit is contained in:
blank
2021-06-07 15:13:32 +08:00
parent 74d5947e9d
commit 346fc42e67
500 changed files with 77303 additions and 1 deletions

View File

@@ -0,0 +1,101 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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 "Game.h"
#include "cocos/bindings/event/CustomEventTypes.h"
#include "cocos/bindings/event/EventDispatcher.h"
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_classtype.h"
#include "cocos/bindings/manual/jsb_global.h"
#include "cocos/bindings/manual/jsb_module_register.h"
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
#include "platform/Device.h"
#endif
////blank
#include "cxJsb.hpp"
Game::Game(int width, int height) : cc::Application(width, height) {}
bool Game::init()
{
cc::Application::init();
se::ScriptEngine *se = se::ScriptEngine::getInstance();
jsb_set_xxtea_key("");
jsb_init_file_operation_delegate();
#if defined(CC_DEBUG) && (CC_DEBUG > 0)
// Enable debugger here
jsb_enable_debugger("0.0.0.0", 6086, false);
#endif
se->setExceptionCallback([](const char *location, const char *message, const char *stack) {
// Send exception information to server like Tencent Bugly.
CC_LOG_ERROR("\nUncaught Exception:\n - location : %s\n - msg : %s\n - detail : \n %s\n", location, message, stack);
});
se->addRegisterCallback(register_all_cx);
jsb_register_all_modules();
se->start();
se::AutoHandleScope hs;
jsb_run_script("jsb-adapter/jsb-builtin.js");
jsb_run_script("boot.js");
se->addAfterCleanupHook([]() {
JSBClassType::destroy();
});
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
cc::Vec2 logicSize = getViewLogicalSize();
float pixelRatio = cc::Device::getDevicePixelRatio();
cc::EventDispatcher::dispatchResizeEvent(logicSize.x * pixelRatio, logicSize.y * pixelRatio);
#endif
return true;
}
void Game::onPause()
{
cc::Application::onPause();
cc::CustomEvent event;
event.name = EVENT_COME_TO_BACKGROUND;
cc::EventDispatcher::dispatchCustomEvent(event);
cc::EventDispatcher::dispatchEnterBackgroundEvent();
}
void Game::onResume()
{
cc::Application::onResume();
cc::CustomEvent event;
event.name = EVENT_COME_TO_FOREGROUND;
cc::EventDispatcher::dispatchCustomEvent(event);
cc::EventDispatcher::dispatchEnterForegroundEvent();
}

View File

@@ -0,0 +1,43 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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.
****************************************************************************/
#pragma once
#include "platform/Application.h"
/**
@brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by Director.
*/
class Game : public cc::Application
{
public:
/**
* width and height in logical pixel unit
*/
Game(int width, int height);
virtual bool init() override;
virtual void onPause() override;
virtual void onResume() override;
};

View File

@@ -0,0 +1,36 @@
#include "cxCreator.h"
#include "cxIntf.h"
#if CC_PLATFORM == CC_PLATFORM_MAC_IOS
#include "cxMask/cxMaskIntf.h"
#endif
#if CC_PLATFORM != CC_PLATFORM_ANDROID
#include "cxSys/cxSysIntf.h"
#endif
NativeIntfClass* NativeCreator::createNativeClass(std::string classname)
{
if (classname == "cx")
return CxIntf::ins();
#if CC_PLATFORM == CC_PLATFORM_MAC_IOS
if (classname == "cx.mask")
return CxMaskIntf::ins();
#endif
#if CC_PLATFORM != CC_PLATFORM_ANDROID
if (classname == "cx.sys")
return CxSysIntf::ins();
return createAppNativeClass(classname);
#endif
return nullptr;
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "cxDefine.h"
#if CC_PLATFORM != CC_PLATFORM_ANDROID
extern NativeIntfClass* createAppNativeClass(std::string classname);
#endif
class NativeCreator
{
public:
static NativeIntfClass* createNativeClass(std::string classname);
};

View File

@@ -0,0 +1,13 @@
#pragma once
#include "cocos/base/Value.h"
typedef std::function<void(int v1, std::string v2)> DataCallback;
class NativeIntfClass
{
public:
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback){ return nullptr; };
};

View File

@@ -0,0 +1,23 @@
#include "cxIntf.h"
DataCallback CxIntf::m_cxCallback = NULL;
static CxIntf* s_sharedCxIntf = nullptr;
CxIntf* CxIntf::ins()
{
if (!s_sharedCxIntf)
s_sharedCxIntf = new CxIntf();
return s_sharedCxIntf;
}
std::string CxIntf::call(std::string fname, cc::ValueVector params, const DataCallback& callback)
{
if (fname == "encode" || fname == "decode" || fname == "md5")
return params.at(0).asString();
return "";
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "cocos/base/Value.h"
#include "cxDefine.h"
class CxIntf : public NativeIntfClass
{
public:
static CxIntf* ins();
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback) override;
static DataCallback m_cxCallback;
private:
};

View File

@@ -0,0 +1,228 @@
#include "cxJsb.hpp"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/bindings/manual/jsb_global.h"
#include "platform/FileUtils.h"
#include "cxCreator.h"
se::Object* __jsb_NativeCreator_proto = nullptr;
se::Class* __jsb_NativeCreator_class = nullptr;
//***********************************
//NativeCreator
//***********************************
static bool js_cx_NativeCreator_createNativeClass(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
std::string arg0;
ok &= seval_to_std_string(args[0], &arg0);
SE_PRECONDITION2(ok, false, "js_cx_NativeCreator_createNativeClass : Error processing arguments");
NativeIntfClass* result = NativeCreator::createNativeClass(arg0);
ok &= native_ptr_to_seval<NativeIntfClass>((NativeIntfClass*)result, &s.rval());
SE_PRECONDITION2(ok, false, "js_cx_NativeCreator_createNativeClass : Error processing arguments");
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(js_cx_NativeCreator_createNativeClass)
static bool js_NativeCreator_finalize(se::State& s)
{
// SE_LOGD("jsbindings: finalizing JS object %p (NativeCreator)", s.nativeThisObject());
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
{
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
NativeCreator* cobj = (NativeCreator*)s.nativeThisObject();
delete cobj;
}
return true;
}
SE_BIND_FINALIZE_FUNC(js_NativeCreator_finalize)
bool js_register_cx_NativeCreator(se::Object* obj)
{
auto cls = se::Class::create("NativeCreator", obj, nullptr, nullptr);
cls->defineStaticFunction("createNativeClass", _SE(js_cx_NativeCreator_createNativeClass));
cls->defineFinalizeFunction(_SE(js_NativeCreator_finalize));
cls->install();
JSBClassType::registerClass<NativeCreator>(cls);
__jsb_NativeCreator_proto = cls->getProto();
__jsb_NativeCreator_class = cls;
se::ScriptEngine::getInstance()->clearException();
return true;
}
//***********************************
//NativeIntfClass
//***********************************
se::Object* __jsb_NativeIntfClass_proto = nullptr;
se::Class* __jsb_NativeIntfClass_class = nullptr;
static bool js_cx_NativeIntfClass_call(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
std::string arg0;
cc::ValueVector arg1;
std::function<void (int, std::string)> arg2 = nullptr;
if (argc >= 1)
{
ok &= seval_to_std_string(args[0], &arg0);
}
if (argc >= 2)
{
ok &= seval_to_std_string(args[0], &arg0);
ok &= seval_to_ccvaluevector(args[1], &arg1);
}
if (ok && argc == 3)
{
if (args[2].isObject() && args[2].toObject()->isFunction())
{
se::Value jsThis(s.thisObject());
se::Value jsFunc(args[2]);
//https://docs.cocos.com/creator/manual/zh/advanced-topics/JSB2.0-learning.html
//如果当前类是一个单例类,或者永远只有一个实例的类,我们不能用 se::Object::attachObject 去关联, 必须使用 se::Object::root
//jsThis.toObject()->attachObject(jsFunc.toObject());
jsFunc.toObject()->root();
jsThis.toObject()->root();
auto lambda = [=](int larg0, std::string larg1) -> void
{
se::ScriptEngine::getInstance()->clearException();
se::AutoHandleScope hs;
CC_UNUSED bool ok = true;
se::ValueArray args;
args.resize(2);
ok &= int32_to_seval(larg0, &args[0]);
ok &= std_string_to_seval(larg1, &args[1]);
se::Value rval;
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
se::Object* funcObj = jsFunc.toObject();
bool succeed = funcObj->call(args, thisObj, &rval);
if (!succeed)
{
se::ScriptEngine::getInstance()->clearException();
}
};
arg2 = lambda;
}
}
SE_PRECONDITION2(ok, false, "js_cx_NativeIntfClass_func : Error processing arguments");
if (ok)
{
NativeIntfClass* cobj = (NativeIntfClass*)s.nativeThisObject();
std::string result = cobj->call(arg0, arg1, arg2);
std_string_to_seval(result, &s.rval());
return true;
}
return false;
}
SE_BIND_FUNC(js_cx_NativeIntfClass_call)
static bool js_NativeIntfClass_finalize(se::State& s)
{
// SE_LOGD("jsbindings: finalizing JS object %p (NativeCreator)", s.nativeThisObject());
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
{
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
NativeIntfClass* cobj = (NativeIntfClass*)s.nativeThisObject();
delete cobj;
}
return true;
}
SE_BIND_FINALIZE_FUNC(js_NativeIntfClass_finalize)
bool js_register_cx_NativeIntfClass(se::Object* obj)
{
auto cls = se::Class::create("NativeIntfClass", obj, nullptr, nullptr);
cls->defineFunction("call", _SE(js_cx_NativeIntfClass_call));
cls->defineFinalizeFunction(_SE(js_NativeIntfClass_finalize));
cls->install();
JSBClassType::registerClass<NativeIntfClass>(cls);
__jsb_NativeIntfClass_proto = cls->getProto();
__jsb_NativeIntfClass_class = cls;
se::ScriptEngine::getInstance()->clearException();
return true;
}
//***********************************
//NativeUtils
//***********************************
se::Object* __jsb_NativeUtils_proto = nullptr;
se::Class* __jsb_NativeUtils_class = nullptr;
static bool js_cx_NativeUtils_writeDataToFile(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 2) {
cc::Data arg0;
std::string arg1;
ok &= seval_to_Data(args[0], &arg0);
ok &= seval_to_std_string(args[1], &arg1);
SE_PRECONDITION2(ok, false, "js_engine_FileUtils_writeDataToFile : Error processing arguments");
bool result = cc::FileUtils::getInstance()->writeDataToFile(arg0, arg1);
ok &= boolean_to_seval(result, &s.rval());
SE_PRECONDITION2(ok, false, "js_engine_FileUtils_writeDataToFile : Error processing result");
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
return false;
}
SE_BIND_FUNC(js_cx_NativeUtils_writeDataToFile)
bool js_register_cx_NativeUtils(se::Object* obj)
{
auto cls = se::Class::create("NativeUtils", obj, nullptr, nullptr);
cls->defineStaticFunction("writeDataToFile", _SE(js_cx_NativeUtils_writeDataToFile));
cls->install();
__jsb_NativeUtils_proto = cls->getProto();
__jsb_NativeUtils_class = cls;
se::ScriptEngine::getInstance()->clearException();
return true;
}
//***********************************
//register
//***********************************
bool register_all_cx(se::Object* obj)
{
// Get the ns
se::Value nsVal;
if (!obj->getProperty("cxnative", &nsVal))
{
se::HandleObject jsobj(se::Object::createPlainObject());
nsVal.setObject(jsobj);
obj->setProperty("cxnative", nsVal);
}
se::Object* ns = nsVal.toObject();
js_register_cx_NativeCreator(ns);
js_register_cx_NativeIntfClass(ns);
js_register_cx_NativeUtils(ns);
return true;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "cocos/bindings/jswrapper/SeApi.h"
extern se::Object* __jsb_NativeCreator_proto;
extern se::Class* __jsb_NativeCreator_class;
bool js_register_NativeCreator(se::Object* obj);
bool register_all_cx(se::Object* obj);
SE_DECLARE_FUNC(js_cx_NativeCreator_createNativeClass);

View File

@@ -0,0 +1,20 @@
#pragma once
#include "cxDefine.h"
class CxMaskIntf : public NativeIntfClass
{
public:
static CxMaskIntf* ins();
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback) override;
void addNativeView(std::string maskName, void* view);
bool hasNativeView(std::string maskName, void* view);
private:
};

View File

@@ -0,0 +1,127 @@
#include "cxMaskIntf.h"
#include "AppController.h"
#include "cxMaskView.h"
std::unordered_map<std::string, CxMaskView*> m_maskViewList;
CxMaskView* getMaskView(std::string name)
{
auto itr = m_maskViewList.find(name);
if (itr != m_maskViewList.end())
return itr->second;
return nullptr;
}
static CxMaskIntf* s_sharedCxMaskIntf = nullptr;
CxMaskIntf* CxMaskIntf::ins()
{
if (!s_sharedCxMaskIntf)
s_sharedCxMaskIntf = new CxMaskIntf();
return s_sharedCxMaskIntf;
}
std::string CxMaskIntf::call(std::string fname, cc::ValueVector params, const DataCallback& callback)
{
if (fname == "createMask")
{
std::string name = params.at(0).asString();
float rectX = params.at(1).asFloat();
float rectY = params.at(2).asFloat();
float rectW = params.at(3).asFloat();
float rectH = params.at(4).asFloat();
if (getMaskView(name))
return "";
CxMaskView* maskView = [[CxMaskView alloc] initWithFrame:CGRectMake(rectX, rectY, rectW, rectH)];
//maskView.contentView.backgroundColor = [UIColor colorWithRed:100 green:0 blue:0 alpha:0.4];
[[AppController ins] addView:maskView];
m_maskViewList.emplace(name, maskView);
}
else if (fname == "setMaskVisible")
{
std::string name = params.at(0).asString();
bool visible = params.at(1).asBool();
auto maskView = getMaskView(name);
if (maskView)
[maskView setHidden:!visible];
}
else if (fname == "setMaskSize")
{
std::string name = params.at(0).asString();
float rectW = params.at(1).asFloat();
float rectH = params.at(2).asFloat();
auto maskView = getMaskView(name);
if (maskView)
maskView.frame = CGRectMake(maskView.frame.origin.x, maskView.frame.origin.y, rectW, rectH);
}
else if (fname == "setMaskMask")
{
std::string name = params.at(0).asString();
auto maskView = getMaskView(name);
if (maskView)
{
float maskX = params.at(1).asFloat();
float maskY = params.at(2).asFloat();
float maskW = params.at(3).asFloat();
float maskH = params.at(4).asFloat();
float radius = params.at(5).asFloat();
UIBezierPath* path = [UIBezierPath bezierPathWithRect:maskView.contentView.bounds];
UIBezierPath* round = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(maskX, maskY, maskW, maskH) cornerRadius:radius];
CAShapeLayer* maskLayer = [CAShapeLayer layer];
[path appendPath:round];
maskLayer.path = [path CGPath];
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskView.contentView.layer.mask = maskLayer;
}
}
else if (fname == "clearMaskMask")
{
std::string name = params.at(0).asString();
auto maskView = getMaskView(name);
if (maskView)
maskView.contentView.layer.mask = nil;
}
else if (fname == "removeMask")
{
std::string name = params.at(0).asString();
auto maskView = getMaskView(name);
if (maskView)
{
[maskView removeFromSuperview];
m_maskViewList.erase(name);
}
}
return "";
}
void CxMaskIntf::addNativeView(std::string maskName, void* view)
{
auto maskView = getMaskView(maskName);
if (maskView)
[maskView.contentView addSubview:(UIView*)view];
}
bool CxMaskIntf::hasNativeView(std::string maskName, void* view)
{
auto maskView = getMaskView(maskName);
if (maskView)
{
for (UIView* subview in maskView.contentView.subviews)
{
if (subview == view)
return true;
}
}
return false;
}

View File

@@ -0,0 +1,9 @@
#import <UIKit/UIKit.h>
@interface CxMaskView : UIView
@property (strong, nonatomic) UIView* contentView;
@end

View File

@@ -0,0 +1,25 @@
#import "cxMaskView.h"
#define pop_height 200
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
@implementation CxMaskView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
self.userInteractionEnabled = false;
self.clipsToBounds = true;
CGSize screen = [[UIScreen mainScreen] bounds].size;
self.contentView = [[UIView alloc] initWithFrame:CGRectMake(-frame.origin.x, -frame.origin.y, screen.width, screen.height)];
self.contentView.userInteractionEnabled = false;
[self addSubview:self.contentView];
return self;
}
@end

View File

@@ -0,0 +1,23 @@
#pragma once
#include "cxDefine.h"
#include "cocos/bindings/event/EventDispatcher.h"
class CxSysIntf : public NativeIntfClass
{
public:
static CxSysIntf* ins();
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback) override;
static DataCallback m_cxSysCallback;
private:
void restartForUpdate(cc::CustomEvent evt);
};

View File

@@ -0,0 +1,70 @@
#include "cxSysIntf.h"
#include "AppController.h"
#include "platform/Application.h"
#include "cocos/bindings/event/CustomEventTypes.h"
DataCallback CxSysIntf::m_cxSysCallback = NULL;
static CxSysIntf* s_sharedCxSysIntf = nullptr;
CxSysIntf* CxSysIntf::ins()
{
if (!s_sharedCxSysIntf)
s_sharedCxSysIntf = new CxSysIntf();
return s_sharedCxSysIntf;
}
std::string CxSysIntf::call(std::string fname, cc::ValueVector params, const DataCallback& callback)
{
if (fname == "getStoragePath")
{
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
return "";
#endif
return call("getPackageName", params, callback);
}
if (fname == "getPackageName")
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* packageName = [infoDictionary objectForKey:@"CFBundleIdentifier"];
return [packageName UTF8String];
}
if (fname == "getVersionCode")
{
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] UTF8String];
}
if (fname == "getVersionName")
{
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
}
if (fname == "removeLaunchImage")
{
[[AppController ins] removeLaunchImage];
return "";
}
//只供在main.js中且是ios时调用这个方法
if (fname == "restartForUpdate")
{
//ios弹出网络授权时应用会进入后台点击后回到前台侦听回到前台时重启
cc::EventDispatcher::addCustomEventListener(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(CxSysIntf::restartForUpdate, this));
return "";
}
return "";
}
void CxSysIntf::restartForUpdate(cc::CustomEvent evt)
{
if (evt.name == EVENT_COME_TO_FOREGROUND)
{
cc::EventDispatcher::removeAllCustomEventListeners(EVENT_COME_TO_FOREGROUND);
cc::Application::getInstance()->restart();
}
}

View File

@@ -0,0 +1,187 @@
/****************************************************************************
Copyright (c) 2017-2021 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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 "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_module_register.h"
#include "cocos/bindings/auto/jsb_cocos_auto.h"
#include "cocos/base/AutoreleasePool.h"
#include "cocos/bindings/dop/jsb_dop.h"
#include "cocos/bindings/auto/jsb_extension_auto.h"
#include "cocos/bindings/auto/jsb_network_auto.h"
#include "cocos/bindings/auto/jsb_gfx_auto.h"
#include "cocos/bindings/auto/jsb_pipeline_auto.h"
#include "cocos/bindings/manual/jsb_pipeline_manual.h"
#include "cocos/bindings/manual/jsb_cocos_manual.h"
#include "cocos/bindings/manual/jsb_network_manual.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/bindings/manual/jsb_gfx_manual.h"
#include "cocos/bindings/manual/jsb_global.h"
#include "cocos/bindings/manual/jsb_platform.h"
#include "cocos/bindings/manual/jsb_xmlhttprequest.h"
#if USE_GFX_RENDERER
#endif
#if USE_SOCKET
#include "cocos/bindings/manual/jsb_socketio.h"
#include "cocos/bindings/manual/jsb_websocket.h"
#endif // USE_SOCKET
#if USE_AUDIO
#include "cocos/bindings/auto/jsb_audio_auto.h"
#endif
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_MAC_OSX)
#include "cocos/bindings/manual/JavaScriptObjCBridge.h"
#endif
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
#include "cocos/bindings/manual/JavaScriptJavaBridge.h"
#endif
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_ANDROID)
#if USE_VIDEO
#include "cocos/bindings/auto/jsb_video_auto.h"
#endif
#if USE_WEBVIEW
#include "cocos/bindings/auto/jsb_webview_auto.h"
#endif
#endif // (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_ANDROID)
#if USE_SOCKET && USE_WEBSOCKET_SERVER
#include "cocos/bindings/manual/jsb_websocket_server.h"
#endif
#if USE_MIDDLEWARE
#include "cocos/bindings/auto/jsb_editor_support_auto.h"
#if USE_SPINE
#include "cocos/bindings/auto/jsb_spine_auto.h"
#include "cocos/bindings/manual/jsb_spine_manual.h"
#endif
#if USE_DRAGONBONES
#include "cocos/bindings/auto/jsb_dragonbones_auto.h"
#include "cocos/bindings/manual/jsb_dragonbones_manual.h"
#endif
#endif // USE_MIDDLEWARE
#if USE_PHYSICS_PHYSX
#include "cocos/bindings/auto/jsb_physics_auto.h"
#endif
using namespace cc;
bool jsb_register_all_modules() {
se::ScriptEngine *se = se::ScriptEngine::getInstance();
se->addBeforeInitHook([]() {
JSBClassType::init();
});
se->addBeforeCleanupHook([se]() {
se->garbageCollect();
PoolManager::getInstance()->getCurrentPool()->clear();
se->garbageCollect();
PoolManager::getInstance()->getCurrentPool()->clear();
});
se->addRegisterCallback(jsb_register_global_variables);
se->addRegisterCallback(register_all_engine);
se->addRegisterCallback(register_all_cocos_manual);
se->addRegisterCallback(register_platform_bindings);
se->addRegisterCallback(register_all_gfx);
se->addRegisterCallback(register_all_gfx_manual);
se->addRegisterCallback(register_all_network);
se->addRegisterCallback(register_all_network_manual);
se->addRegisterCallback(register_all_xmlhttprequest);
// extension depend on network
se->addRegisterCallback(register_all_extension);
se->addRegisterCallback(register_all_dop_bindings);
se->addRegisterCallback(register_all_pipeline);
se->addRegisterCallback(register_all_pipeline_manual);
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_MAC_OSX)
se->addRegisterCallback(register_javascript_objc_bridge);
#endif
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
se->addRegisterCallback(register_javascript_java_bridge);
#endif
#if USE_AUDIO
se->addRegisterCallback(register_all_audio);
#endif
#if USE_SOCKET
se->addRegisterCallback(register_all_websocket);
se->addRegisterCallback(register_all_socketio);
#endif
#if USE_MIDDLEWARE
se->addRegisterCallback(register_all_editor_support);
#if USE_SPINE
se->addRegisterCallback(register_all_spine);
se->addRegisterCallback(register_all_spine_manual);
#endif
#if USE_DRAGONBONES
se->addRegisterCallback(register_all_dragonbones);
se->addRegisterCallback(register_all_dragonbones_manual);
#endif
#endif // USE_MIDDLEWARE
#if USE_PHYSICS_PHYSX
se->addRegisterCallback(register_all_physics);
#endif
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_ANDROID)
#if USE_VIDEO
se->addRegisterCallback(register_all_video);
#endif
#if USE_WEBVIEW
se->addRegisterCallback(register_all_webview);
#endif
#endif // (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_ANDROID)
#if USE_SOCKET && USE_WEBSOCKET_SERVER
se->addRegisterCallback(register_all_websocket_server);
#endif
se->addAfterCleanupHook([]() {
PoolManager::getInstance()->getCurrentPool()->clear();
JSBClassType::destroy();
});
return true;
}