[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.12 版本

This commit is contained in:
SmallMain
2023-10-30 22:32:32 +08:00
parent 2508616ad9
commit 0092eb9f05
787 changed files with 206249 additions and 422 deletions

View File

@@ -707,7 +707,12 @@ static void js_engine_LabelRenderer_export_structs_info(se::Object *obj)
ss << ",";
DESCRIPT_FIELD(cocos2d::LabelRenderer::LabelRendererConfig, fontSizeRetina, "float");
ss << "}";
se::Object *cfgFields = se::Object::createJSONObject(ss.str());
se::Object *cfgFields;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
cfgFields = se::Object::createUTF8String(ss.str());
#else
cfgFields = se::Object::createJSONObject(ss.str());
#endif
assert(cfgFields);
self->setProperty("_cfgFields", se::Value(cfgFields));
cfgFields->decRef();
@@ -755,7 +760,12 @@ static void js_engine_LabelRenderer_export_structs_info(se::Object *obj)
ss << "," ;
DESCRIPT_FIELD(cocos2d::LabelLayoutInfo, overflow, "int8");
ss << "}";
se::Object *cfgFields = se::Object::createJSONObject(ss.str());
se::Object *cfgFields;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
cfgFields = se::Object::createUTF8String(ss.str());
#else
cfgFields = se::Object::createJSONObject(ss.str());
#endif
assert(cfgFields);
self->setProperty("_layoutFields", se::Value(cfgFields));
cfgFields->decRef();

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "base/ccConfig.h"
#include "jsb_cocos2dx_network_manual.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
#include "scripting/js-bindings/manual/jsb_global.h"
#include "network/CCDownloader.h"

View File

@@ -3201,4 +3201,69 @@ bool spine_Vector_String_to_seval(const spine::Vector<spine::String>& v, se::Val
return ok;
}
bool native_int_to_se(int32_t from, se::Value &to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming)
to.setInt32(from);
return true;
}
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
bool native_unorderedmap_to_se(const std::unordered_map<std::string, cocos2d::Value> &from, se::Value &to, se::Object *ctx) {
se::HandleObject obj(se::Object::createPlainObject());
bool ok = true;
for (const auto &e : from) {
const std::string &key = e.first;
const cocos2d::Value &value = e.second;
if (key.empty()) {
continue;
}
se::Value tmp;
if (!native_cocos_value_to_se(value, tmp, nullptr)) {
ok = false;
to.setUndefined();
break;
}
obj->setProperty(key.c_str(), tmp);
}
if (ok) {
to.setObject(obj);
}
return ok;
}
#endif
bool native_cocos_value_to_se(const cocos2d::Value &from, se::Value &to, se::Object * /*unused*/) {
bool ok = true;
switch (from.getType()) {
case cocos2d::Value::Type::NONE:
to.setNull();
break;
case cocos2d::Value::Type::UNSIGNED:
to.setUint32(from.asUnsignedInt());
break;
case cocos2d::Value::Type::INTEGER:
to.setInt32(from.asInt());
break;
case cocos2d::Value::Type::STRING:
to.setString(from.asString());
break;
case cocos2d::Value::Type::BOOLEAN:
to.setBoolean(from.asBool());
break;
case cocos2d::Value::Type::FLOAT:
case cocos2d::Value::Type::DOUBLE:
to.setDouble(from.asDouble());
break;
default:
SE_LOGE("Could not the way to convert cocos2d::Value::Type (%d) type!", (int)from.getType());
ok = false;
break;
}
return ok;
}
#endif

View File

@@ -27,7 +27,7 @@
#include "scripting/js-bindings/jswrapper/SeApi.h"
#include "scripting/js-bindings/manual/jsb_classtype.hpp"
#include <unordered_map>
#include "cocos2d.h"
#include "renderer/gfx/GFX.h"
#include "renderer/renderer/Renderer.h"
@@ -188,6 +188,44 @@ bool seval_to_native_ptr(const se::Value& v, T* ret)
return false;
}
inline bool seval_to_native_base_type(const se::Value& from, bool* to) { // NOLINT(readability-identifier-naming)
*to = from.isNullOrUndefined() ? false : (from.isNumber() ? from.toDouble() != 0 : from.toBoolean());
return true;
}
inline bool seval_to_native_base_type(const se::Value& from, int32_t* to) { // NOLINT(readability-identifier-naming)
*to = from.toInt32();
return true;
}
inline bool seval_to_native_base_type(const se::Value& from, float* to) { // NOLINT(readability-identifier-naming)
*to = from.toFloat();
return true;
}
inline bool seval_to_native_base_type(const se::Value& from, std::string* to) { // NOLINT(readability-identifier-naming)
assert(to != nullptr);
*to = from.toStringForce();
return true;
}
inline bool seval_to_native_base_type(const se::Value &from, std::vector<float>* to) { // NOLINT(readability-identifier-naming)
if (from.isNullOrUndefined()) {
to->clear();
return true;
}
auto *array = from.toObject();
uint32_t size;
se::Value tmp;
array->getArrayLength(&size);
to->resize(size);
for (uint32_t i = 0; i < size; i++) {
array->getArrayElement(i, &tmp);
(*to)[i] = tmp.toFloat();
}
return true;
}
template<typename T>
bool seval_to_Vector(const se::Value& v, cocos2d::Vector<T>* ret)
{
@@ -256,6 +294,8 @@ bool seval_to_Map_string_key(const se::Value& v, cocos2d::Map<std::string, T>* r
return true;
}
// native value -> se value
bool int8_to_seval(int8_t v, se::Value* ret);
bool uint8_to_seval(uint8_t v, se::Value* ret);
@@ -313,6 +353,13 @@ bool TechniqueParameter_to_seval(const cocos2d::renderer::Technique::Parameter&
bool std_vector_TechniqueParameter_to_seval(const std::vector<cocos2d::renderer::Technique::Parameter>& v, se::Value* ret);
#endif
bool native_cocos_value_to_se(const cocos2d::Value &from, se::Value &to, se::Object * /*unused*/);
bool native_int_to_se(int32_t from, se::Value &to, se::Object * /*ctx*/);
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
bool native_unorderedmap_to_se(const std::unordered_map<std::string, cocos2d::Value> &from, se::Value &to, se::Object *ctx);
#endif
template<typename T>
bool native_ptr_to_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Value* ret, bool* isReturnCachedValue = nullptr)
{

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "base/ccConfig.h"
#include "jsb_gfx_manual.hpp"
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "gfx/GFX.h"

View File

@@ -287,17 +287,27 @@ bool jsb_set_extend_property(const char* ns, const char* clsName)
namespace {
std::unordered_map<std::string, se::Value> __moduleCache;
static bool require(se::State& s)
{
const auto& args = s.args();
int argc = (int)args.size();
assert(argc >= 1);
assert(args[0].isString());
return jsb_run_script(args[0].toString(), &s.rval());
}
SE_BIND_FUNC(require)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_OPENHARMONY)
static bool require(se::State& s)
{
const auto& args = s.args();
int argc = (int)args.size();
assert(argc >= 1);
assert(args[0].isString());
return jsb_run_script(args[0].toString(), &s.rval());
}
SE_BIND_FUNC(require)
#else
static bool run_script(se::State& s)
{
const auto& args = s.args();
int argc = (int)args.size();
assert(argc >= 1);
assert(args[0].isString());
return jsb_run_script(args[0].toString(), &s.rval());
}
SE_BIND_FUNC(run_script)
#endif
static bool doModuleRequire(const std::string& path, se::Value* ret, const std::string& prevScriptFileDir)
{
@@ -416,18 +426,18 @@ namespace {
assert(false);
return false;
}
static bool moduleRequire(se::State& s)
{
const auto& args = s.args();
int argc = (int)args.size();
assert(argc >= 2);
assert(args[0].isString());
assert(args[1].isString());
return doModuleRequire(args[0].toString(), &s.rval(), args[1].toString());
}
SE_BIND_FUNC(moduleRequire)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_OPENHARMONY)
static bool moduleRequire(se::State& s)
{
const auto& args = s.args();
int argc = (int)args.size();
assert(argc >= 2);
assert(args[0].isString());
assert(args[1].isString());
return doModuleRequire(args[0].toString(), &s.rval(), args[1].toString());
}
SE_BIND_FUNC(moduleRequire)
#endif
} // namespace {
bool jsb_run_script(const std::string& filePath, se::Value* rval/* = nullptr */)
@@ -540,6 +550,8 @@ static bool JSBCore_os(se::State& s)
os.setString("OS X");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
os.setString("WINRT");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
os.setString("OpenHarmony");
#else
os.setString("Unknown");
#endif
@@ -1257,9 +1269,12 @@ SE_BIND_FUNC(JSB_hideInputBox)
bool jsb_register_global_variables(se::Object* global)
{
g_threadPool.reset(ThreadPool::newFixedThreadPool(3));
global->defineFunction("require", _SE(require));
global->defineFunction("requireModule", _SE(moduleRequire));
#if (CC_TARGET_PLATFORM != CC_PLATFORM_OPENHARMONY)
global->defineFunction("require", _SE(require));
global->defineFunction("requireModule", _SE(moduleRequire));
#else
global->defineFunction("run_script", _SE(run_script));
#endif
getOrCreatePlainObject_r("jsb", global, &__jsbObj);

View File

@@ -87,7 +87,7 @@
#endif // USE_MIDDLEWARE
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#if USE_VIDEO
#include "cocos/scripting/js-bindings/auto/jsb_video_auto.hpp"
@@ -97,7 +97,7 @@
#include "cocos/scripting/js-bindings/auto/jsb_webview_auto.hpp"
#endif
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
using namespace cocos2d;
@@ -180,7 +180,13 @@ bool jsb_register_all_modules()
se->addRegisterCallback(register_all_video);
#endif
#if USE_WEB_VIEW
#if USE_WEBVIEW
se->addRegisterCallback(register_all_webview);
#endif
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#if USE_WEBVIEW
se->addRegisterCallback(register_all_webview);
#endif

View File

@@ -3559,6 +3559,8 @@ static bool JSB_glGetSupportedExtensions(se::State& s) {
extensionName = "WEBGL_compressed_texture_etc1";
else if (0 == strcmp(extensionName, "GL_IMG_texture_compression_pvrtc"))
extensionName = "WEBGL_compressed_texture_pvrtc";
else if (0 == strcmp(extensionName, "GL_KHR_texture_compression_astc_ldr"))
extensionName = "WEBGL_compressed_texture_astc";
jsobj->setArrayElement(element, se::Value(extensionName));
@@ -3580,6 +3582,10 @@ static bool JSB_glGetSupportedExtensions(se::State& s) {
jsobj->setArrayElement(element++, se::Value("OES_standard_derivatives"));
}
if (Configuration::getInstance()->supportsASTC()) {
jsobj->setArrayElement(element++, se::Value("WEBGL_compressed_texture_astc"));
}
s.rval().setObject(jsobj.get());
CC_SAFE_DELETE_ARRAY(copy);
return true;

View File

@@ -0,0 +1,60 @@
/****************************************************************************
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 "jsb_platform.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
#include "cocos/platform/CCFileUtils.h"
#include <regex>
#ifndef JCLS_CANVASIMPL
#define JCLS_CANVASIMPL "org/cocos2dx/lib/CanvasRenderingContext2DImpl"
#endif
using namespace cocos2d;
static std::unordered_map<std::string, std::string> _fontFamilyNameMap;
const std::unordered_map<std::string, std::string>& getFontFamilyNameMap()
{
return _fontFamilyNameMap;
}
static bool JSB_loadFont(se::State& s)
{
// TODO(qgh):Currently it does not support loading OpenHarmony fonts, it may be supported in the future
return true;
}
SE_BIND_FUNC(JSB_loadFont)
bool register_platform_bindings(se::Object* obj)
{
__jsbObj->defineFunction("loadFont", _SE(JSB_loadFont));
return true;
}

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "base/ccConfig.h"
#include "jsb_renderer_manual.hpp"
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "cocos/scripting/js-bindings/auto/jsb_renderer_auto.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "scene/NodeProxy.hpp"

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "base/ccConfig.h"
#include "jsb_websocket.hpp"
#if (USE_SOCKET > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (USE_SOCKET > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"

View File

@@ -24,10 +24,14 @@
****************************************************************************/
#include "base/ccConfig.h"
#if (USE_SOCKET > 0) && (USE_WEBSOCKET_SERVER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (USE_SOCKET > 0) && (USE_WEBSOCKET_SERVER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "jsb_websocket_server.hpp"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include "uv.h"
#else
#include "uv/uv.h"
#endif
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/manual/jsb_global.h"

View File

@@ -32,7 +32,7 @@
//
#include "base/ccConfig.h"
#include "jsb_xmlhttprequest.hpp"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY)
#include <unordered_map>
#include <string>
#include <functional>