JSB export math class : Vec2/Vec3/Vec4/Quat/Mat3/Mat4/Color (#12968)

This commit is contained in:
江战
2022-10-31 17:24:54 +08:00
committed by GitHub
parent 118ab30e39
commit 7ccd14e6e6
21 changed files with 1615 additions and 3514 deletions
+21
View File
@@ -194,6 +194,27 @@ declare namespace jsb {
export function getOriginalPCMBuffer (url: string, channelID: number): ArrayBuffer | undefined;
}
class NativePOD {
underlyingData(): ArrayBuffer;
_data(): TypedArray;
__data: TypedArray;
}
export class Color extends NativePOD {
}
export class Quat extends NativePOD {
}
export class Vec2 extends NativePOD {
}
export class Vec3 extends NativePOD {
}
export class Vec4 extends NativePOD {
}
export class Mat3 extends NativePOD {
}
export class Mat4 extends NativePOD {
}
export interface ManifestAsset {
md5: string;
path: string;
+1
View File
@@ -27,6 +27,7 @@
import * as bits from './bits';
import './deprecated';
import './math-native-ext';
/**
* Export module bits.
*/
+108
View File
@@ -0,0 +1,108 @@
/*
Copyright (c) 2022 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.
*/
import { NATIVE } from 'internal:constants';
import { Mat4 } from './mat4';
import { Mat3 } from './mat3';
import { Vec3 } from './vec3';
import { Vec2 } from './vec2';
import { Vec4 } from './vec4';
import { Quat } from './quat';
import { Color } from './color';
const defineAttr = (proto, name, offset) => {
Object.defineProperty(proto, name, {
configurable: true,
enumerable: true,
get () {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this._data()[offset];
},
set (v: number) {
this._data()[offset] = v;
},
});
};
enum MathType {
VEC2 = 0,
VEC3,
VEC4,
QUATERNION,
MAT3,
MAT4,
SIZE,
RECT,
COLOR,
}
function extendType (proto:any, parentProto:any, typ: MathType) {
proto._data = function () {
if (!this.__data) {
this.__data = new Float32Array(this.underlyingData());
}
return this.__data as Float32Array;
};
Object.setPrototypeOf(proto, parentProto);
Object.defineProperty(proto, 'type', { configurable: true, enumerable: true, writable: false, value: typ });
}
if (NATIVE) {
extendType(jsb.Mat4.prototype, Mat4.prototype, MathType.MAT4);
for (let i = 0; i < 16; i++) {
const numb = `0${i}`;
defineAttr(jsb.Mat4.prototype, `m${numb.substring(numb.length - 2)}`, i);
}
for (let i = 0; i < 9; i++) {
const numb = `0${i}`;
defineAttr(jsb.Mat3.prototype, `m${numb.substring(numb.length - 2)}`, i);
}
extendType(jsb.Mat3.prototype, Mat3.prototype, MathType.MAT3);
defineAttr(jsb.Vec2.prototype, 'x', 0);
defineAttr(jsb.Vec2.prototype, 'y', 1);
extendType(jsb.Vec2.prototype, Vec2.prototype, MathType.VEC2);
defineAttr(jsb.Vec3.prototype, 'x', 0);
defineAttr(jsb.Vec3.prototype, 'y', 1);
defineAttr(jsb.Vec3.prototype, 'z', 2);
extendType(jsb.Vec3.prototype, Vec3.prototype, MathType.VEC3);
defineAttr(jsb.Vec4.prototype, 'x', 0);
defineAttr(jsb.Vec4.prototype, 'y', 1);
defineAttr(jsb.Vec4.prototype, 'z', 2);
defineAttr(jsb.Vec4.prototype, 'w', 3);
extendType(jsb.Vec4.prototype, Vec4.prototype, MathType.VEC4);
defineAttr(jsb.Quat.prototype, 'x', 0);
defineAttr(jsb.Quat.prototype, 'y', 1);
defineAttr(jsb.Quat.prototype, 'z', 2);
defineAttr(jsb.Quat.prototype, 'w', 3);
extendType(jsb.Quat.prototype, Quat.prototype, MathType.QUATERNION);
Object.setPrototypeOf(jsb.Color.prototype, Color.prototype);
Object.defineProperty(jsb.Color.prototype, 'type', { configurable: true, enumerable: true, writable: false, value: MathType.COLOR });
}
@@ -97,7 +97,7 @@ int CocosApplication::init() {
IScreen *screen = _engine->getInterface<IScreen>();
float pixelRatio = screen->getDevicePixelRatio();
uint32_t windowId = _systemWindow->getWindowId();
events::Resize::broadcast(logicSize.x * pixelRatio, logicSize.y * pixelRatio, windowId);
events::Resize::broadcast(logicSize.width * pixelRatio, logicSize.height * pixelRatio, windowId);
#endif
return 0;
}
File diff suppressed because it is too large Load Diff
+40 -10
View File
@@ -47,6 +47,11 @@
#include "platform/FileUtils.h"
#include "platform/SAXParser.h"
#include "math/Vec2.h"
#include "math/Vec3.h"
#include "math/Vec4.h"
#include "math/Mat3.h"
#include "math/Mat4.h"
#include "math/Quaternion.h"
#include "math/Color.h"
#include "profiler/DebugRenderer.h"
@@ -55,6 +60,41 @@
bool register_all_engine(se::Object* obj);
JSB_REGISTER_OBJECT_TYPE(cc::Vec2);
extern se::Object *__jsb_cc_Vec2_proto; // NOLINT
extern se::Class * __jsb_cc_Vec2_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Color);
extern se::Object *__jsb_cc_Color_proto; // NOLINT
extern se::Class * __jsb_cc_Color_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Vec3);
extern se::Object *__jsb_cc_Vec3_proto; // NOLINT
extern se::Class * __jsb_cc_Vec3_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Vec4);
extern se::Object *__jsb_cc_Vec4_proto; // NOLINT
extern se::Class * __jsb_cc_Vec4_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Mat3);
extern se::Object *__jsb_cc_Mat3_proto; // NOLINT
extern se::Class * __jsb_cc_Mat3_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Mat4);
extern se::Object *__jsb_cc_Mat4_proto; // NOLINT
extern se::Class * __jsb_cc_Mat4_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Quaternion);
extern se::Object *__jsb_cc_Quaternion_proto; // NOLINT
extern se::Class * __jsb_cc_Quaternion_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::CCObject);
extern se::Object *__jsb_cc_CCObject_proto; // NOLINT
extern se::Class * __jsb_cc_CCObject_class; // NOLINT
@@ -118,16 +158,6 @@ JSB_REGISTER_OBJECT_TYPE(cc::SAXParser);
extern se::Object *__jsb_cc_SAXParser_proto; // NOLINT
extern se::Class * __jsb_cc_SAXParser_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Vec2);
extern se::Object *__jsb_cc_Vec2_proto; // NOLINT
extern se::Class * __jsb_cc_Vec2_class; // NOLINT
JSB_REGISTER_OBJECT_TYPE(cc::Color);
extern se::Object *__jsb_cc_Color_proto; // NOLINT
extern se::Class * __jsb_cc_Color_class; // NOLINT
#if CC_USE_DEBUG_RENDERER
JSB_REGISTER_OBJECT_TYPE(cc::DebugTextInfo);
@@ -62,6 +62,7 @@
#include "bindings/auto/jsb_geometry_auto.h"
#include "bindings/auto/jsb_cocos_auto.h"
@@ -25,6 +25,7 @@
#include "jsb_cocos_manual.h"
#include "bindings/manual/jsb_global.h"
#include "cocos/bindings/auto/jsb_cocos_auto.h"
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
@@ -734,10 +735,8 @@ static bool register_engine_Color_manual(se::Object * /*obj*/) { // NOLINT(reada
return true;
}
static bool js_cc_ISystemWindowManager_getInstance_static(se::State &s) { // NOLINT(readability-identifier-naming)
const auto &args = s.args();
CC_UNUSED bool ok = true;
auto *instance = CC_GET_PLATFORM_INTERFACE(cc::ISystemWindowManager);
ok &= nativevalue_to_se(instance, s.rval(), s.thisObject());
@@ -754,7 +753,58 @@ static bool register_platform(se::Object * /*obj*/) { // NOLINT(readability-iden
return result;
}
template <typename T>
static bool bindAsExternalBuffer(se::State &s) { // NOLINT
auto *self = SE_THIS_OBJECT<T>(s);
if (!self) {
return false;
}
// NOLINTNEXTLINE
se::HandleObject buffer(se::Object::createExternalArrayBufferObject(self, sizeof(*self), [](void *, size_t, void *) {}));
s.rval().setObject(buffer);
return true;
}
static bool js_cc_Vec2_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Vec2>(s);
}
SE_BIND_FUNC(js_cc_Vec2_underlyingData)
static bool js_cc_Vec3_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Vec3>(s);
}
SE_BIND_FUNC(js_cc_Vec3_underlyingData)
static bool js_cc_Vec4_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Vec4>(s);
}
SE_BIND_FUNC(js_cc_Vec4_underlyingData)
static bool js_cc_Mat3_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Mat3>(s);
}
SE_BIND_FUNC(js_cc_Mat3_underlyingData)
static bool js_cc_Mat4_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Mat4>(s);
}
SE_BIND_FUNC(js_cc_Mat4_underlyingData)
static bool js_cc_Quaternion_underlyingData(se::State &s) { // NOLINT
return bindAsExternalBuffer<cc::Quaternion>(s);
}
SE_BIND_FUNC(js_cc_Quaternion_underlyingData)
bool register_all_cocos_manual(se::Object *obj) { // NOLINT(readability-identifier-naming)
__jsb_cc_Vec2_proto->defineFunction("underlyingData", _SE(js_cc_Vec2_underlyingData));
__jsb_cc_Vec3_proto->defineFunction("underlyingData", _SE(js_cc_Vec3_underlyingData));
__jsb_cc_Vec4_proto->defineFunction("underlyingData", _SE(js_cc_Vec4_underlyingData));
__jsb_cc_Mat3_proto->defineFunction("underlyingData", _SE(js_cc_Mat3_underlyingData));
__jsb_cc_Mat4_proto->defineFunction("underlyingData", _SE(js_cc_Mat4_underlyingData));
__jsb_cc_Quaternion_proto->defineFunction("underlyingData", _SE(js_cc_Quaternion_underlyingData));
register_plist_parser(obj);
register_sys_localStorage(obj);
register_device(obj);
@@ -360,6 +360,10 @@ bool seval_to_DownloaderHints(const se::Value &v, cc::network::DownloaderHints *
bool sevalue_to_native(const se::Value &from, cc::Vec4 *to, se::Object * /*ctx*/) {
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Vec4 failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateData()) {
*to = *obj->getTypedPrivateData<cc::Vec4>();
return true;
}
se::Value tmp;
set_member_field(obj, to, "x", &cc::Vec4::x, tmp);
set_member_field(obj, to, "y", &cc::Vec4::y, tmp);
@@ -399,6 +403,11 @@ bool sevalue_to_native(const se::Value &from, cc::Mat3 *to, se::Object * /*ctx*/
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Matrix3 failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateData()) {
*to = *obj->getTypedPrivateData<cc::Mat3>();
return true;
}
if (obj->isTypedArray()) {
// typed array
SE_PRECONDITION2(obj->isTypedArray(), false, "Convert parameter to Matrix3 failed!");
@@ -440,6 +449,10 @@ bool sevalue_to_native(const se::Value &from, cc::Mat3 *to, se::Object * /*ctx*/
bool sevalue_to_native(const se::Value &from, cc::Mat4 *to, se::Object * /*unused*/) {
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Matrix4 failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateData()) {
*to = *obj->getTypedPrivateData<cc::Mat4>();
return true;
}
if (obj->isTypedArray()) {
// typed array
@@ -484,6 +497,10 @@ bool sevalue_to_native(const se::Value &from, cc::Vec3 *to, se::Object * /*unuse
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Vec3 failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateData() != nullptr) {
*to = *obj->getTypedPrivateData<cc::Vec3>();
return true;
}
se::Value tmp;
set_member_field(obj, to, "x", &cc::Vec3::x, tmp);
set_member_field(obj, to, "y", &cc::Vec3::y, tmp);
@@ -496,6 +513,10 @@ bool sevalue_to_native(const se::Value &from, cc::Color *to, se::Object * /*unus
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Color failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateObject()) {
*to = *obj->getTypedPrivateData<cc::Color>();
return true;
}
se::Value t;
set_member_field(obj, to, "r", &cc::Color::r, t);
set_member_field(obj, to, "g", &cc::Color::g, t);
@@ -509,6 +530,10 @@ bool sevalue_to_native(const se::Value &from, cc::Vec2 *to, se::Object * /*unuse
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Vec2 failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateObject()) {
*to = *obj->getTypedPrivateData<cc::Vec2>();
return true;
}
se::Value tmp;
set_member_field(obj, to, "x", &cc::Vec2::x, tmp);
set_member_field(obj, to, "y", &cc::Vec2::y, tmp);
@@ -530,6 +555,10 @@ bool sevalue_to_native(const se::Value &from, cc::Size *to, se::Object * /*unuse
bool sevalue_to_native(const se::Value &from, cc::Quaternion *to, se::Object * /*unused*/) {
SE_PRECONDITION2(from.isObject(), false, "Convert parameter to Quaternion failed!");
se::Object *obj = from.toObject();
if(obj->getPrivateObject()) {
*to = *obj->getTypedPrivateData<cc::Quaternion>();
return true;
}
se::Value tmp;
set_member_field(obj, to, "x", &cc::Quaternion::x, tmp);
set_member_field(obj, to, "y", &cc::Quaternion::y, tmp);
@@ -1379,39 +1408,6 @@ bool nativevalue_to_se(const ccstd::unordered_map<ccstd::string, cc::Value> &fro
return ok;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Vec4 &from, se::Value &to, se::Object * /*unused*/) {
se::HandleObject obj(se::Object::createPlainObject());
obj->setProperty("x", se::Value(from.x));
obj->setProperty("y", se::Value(from.y));
obj->setProperty("z", se::Value(from.z));
obj->setProperty("w", se::Value(from.w));
obj->setProperty("type", se::Value(static_cast<uint32_t>(MathType::VEC4)));
to.setObject(obj);
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Vec2 &from, se::Value &to, se::Object * /*unused*/) {
se::HandleObject obj(se::Object::createPlainObject());
obj->setProperty("x", se::Value(from.x));
obj->setProperty("y", se::Value(from.y));
obj->setProperty("type", se::Value(static_cast<uint32_t>(MathType::VEC2)));
to.setObject(obj);
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Vec3 &from, se::Value &to, se::Object * /*unused*/) {
se::HandleObject obj(se::Object::createPlainObject());
obj->setProperty("x", se::Value(from.x));
obj->setProperty("y", se::Value(from.y));
obj->setProperty("z", se::Value(from.z));
obj->setProperty("type", se::Value(static_cast<uint32_t>(MathType::VEC3)));
to.setObject(obj);
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Size &from, se::Value &to, se::Object * /*unused*/) {
se::HandleObject obj(se::Object::createPlainObject());
@@ -1514,31 +1510,6 @@ bool nativevalue_to_se(const cc::NativeDep &from, se::Value &to, se::Object * /*
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Mat3 &from, se::Value &to, se::Object * /*ctx*/) {
se::HandleObject obj(se::Object::createPlainObject());
char keybuf[8] = {0};
for (auto i = 0; i < 9; i++) {
snprintf(keybuf, sizeof(keybuf), "m%02d", i);
obj->setProperty(keybuf, se::Value(from.m[i]));
}
obj->setProperty("type", se::Value(static_cast<uint32_t>(MathType::MAT3)));
to.setObject(obj);
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
bool nativevalue_to_se(const cc::Mat4 &from, se::Value &to, se::Object * /*ctx*/) {
se::HandleObject obj(se::Object::createPlainObject());
char keybuf[8] = {0};
for (auto i = 0; i < 16; i++) {
snprintf(keybuf, sizeof(keybuf), "m%02d", i);
obj->setProperty(keybuf, se::Value(from.m[i]));
}
obj->setProperty("type", se::Value(static_cast<uint32_t>(MathType::MAT4)));
to.setObject(obj);
return true;
}
#if CC_USE_PHYSICS_PHYSX
@@ -535,15 +535,8 @@ inline bool nativevalue_to_se(char *from, se::Value &to, se::Object * /*ctx*/) {
return true;
}
// template <>
// bool nativevalue_to_se(const cc::Color &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::NativeDep &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Mat3 &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Mat4 &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
// JSB_REGISTER_OBJECT_TYPE(cc::network::DownloaderHints);
bool nativevalue_to_se(const cc::Data &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
@@ -552,23 +545,8 @@ bool nativevalue_to_se(const cc::Value &from, se::Value &to, se::Object *ctx); /
bool nativevalue_to_se(const ccstd::unordered_map<ccstd::string, cc::Value> &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Vec2 &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Vec3 &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
inline bool nativevalue_to_se(const cc::Vec3 *from, se::Value &to, se::Object *ctx) { // NOLINT(readability-identifier-naming)
if (from != nullptr) {
return nativevalue_to_se(*from, to, ctx);
}
to.setUndefined();
return true;
}
bool nativevalue_to_se(const cc::Vec4 &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Size &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Quaternion &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::extension::ManifestAsset &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
bool nativevalue_to_se(const cc::Rect &from, se::Value &to, se::Object *ctx); // NOLINT(readability-identifier-naming)
+2 -2
View File
@@ -106,8 +106,8 @@ scene::RenderWindow *Root::createRenderWindowFromSystemWindow(ISystemWindow *win
const auto &size = window->getViewSize();
gfx::SwapchainInfo info;
info.width = static_cast<uint32_t>(size.x);
info.height = static_cast<uint32_t>(size.y);
info.width = static_cast<uint32_t>(size.width);
info.height = static_cast<uint32_t>(size.height);
info.windowHandle = reinterpret_cast<void *>(handle);
info.windowId = window->getWindowId();
+2 -2
View File
@@ -82,8 +82,8 @@ bool setCanvasCallback(se::Object * /*global*/) {
std::stringstream ss;
{
ss << "window.innerWidth = " << static_cast<int>(viewSize.x / dpr) << ";";
ss << "window.innerHeight = " << static_cast<int>(viewSize.y / dpr) << ";";
ss << "window.innerWidth = " << static_cast<int>(viewSize.width / dpr) << ";";
ss << "window.innerHeight = " << static_cast<int>(viewSize.height / dpr) << ";";
ss << "window.windowHandler = ";
if (sizeof(handler) == 8) { // use bigint
ss << static_cast<uint64_t>(handler) << "n;";
@@ -27,7 +27,7 @@
#include <iostream>
#include "base/std/container/array.h"
#include "math/Vec2.h"
#include "math/Geometry.h"
#include "platform/interfaces/OSInterface.h"
namespace cc {
@@ -36,7 +36,7 @@ class CC_DLL ISystemWindow : public OSInterface {
public:
static constexpr uint32_t mainWindowId = 1;
using Size = cc::Vec2;
using Size = cc::Size;
enum WindowFlags {
/* !!! FIXME: change this to name = (1<<x). */
CC_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window */
+1 -1
View File
@@ -231,7 +231,7 @@ void DebugRenderer::activate(gfx::Device *device, const DebugRendererInfo &info)
_buffer->init(_device, info.maxCharacters * DEBUG_VERTICES_PER_CHAR, ATTRIBUTES);
const auto *window = CC_GET_MAIN_SYSTEM_WINDOW();
const auto width = window->getViewSize().x * Device::getDevicePixelRatio();
const auto width = window->getViewSize().width * Device::getDevicePixelRatio();
auto fontSize = static_cast<uint32_t>(width / 800.0F * info.fontSize);
fontSize = fontSize < 10U ? 10U : (fontSize > 20U ? 20U : fontSize);
+3 -3
View File
@@ -204,8 +204,8 @@ void Profiler::doIntervalUpdate() {
_coreStats.multiThread = gfx::DeviceManager::isDetachDeviceThread();
_coreStats.occlusionQuery = pipeline->isOcclusionQueryEnabled();
_coreStats.shadowMap = shadows != nullptr && shadows->isEnabled() && shadows->getType() == scene::ShadowType::SHADOW_MAP;
_coreStats.screenWidth = static_cast<uint32_t>(viewSize.x);
_coreStats.screenHeight = static_cast<uint32_t>(viewSize.y);
_coreStats.screenWidth = static_cast<uint32_t>(viewSize.width);
_coreStats.screenHeight = static_cast<uint32_t>(viewSize.height);
}
void Profiler::doFrameUpdate() {
@@ -225,7 +225,7 @@ void Profiler::printStats() {
auto *renderer = CC_DEBUG_RENDERER;
const auto *window = CC_GET_MAIN_SYSTEM_WINDOW();
const auto viewSize = window->getViewSize() * Device::getDevicePixelRatio();
const auto width = viewSize.x;
const auto width = viewSize.width;
const auto lineHeight = renderer->getLineHeight();
const auto columnWidth = width / 12.0F; // divide column numbers
const auto leftOffset = width * 0.01F;
@@ -234,7 +234,7 @@ void CCVKSwapchain::doInit(const SwapchainInfo &info) {
#if CC_PLATFORM == CC_PLATFORM_ANDROID
auto *window = CC_GET_SYSTEM_WINDOW(_windowId);
auto viewSize = window->getViewSize();
checkSwapchainStatus(viewSize.x, viewSize.y);
checkSwapchainStatus(viewSize.width, viewSize.height);
// Android Game Frame Pacing:swappy
#if CC_SWAPPY_ENABLED
@@ -451,7 +451,7 @@ void CCVKSwapchain::doCreateSurface(void *windowHandle) { // NOLINT
#if CC_PLATFORM == CC_PLATFORM_ANDROID
auto *window = CC_GET_SYSTEM_WINDOW(_windowId);
auto viewSize = window->getViewSize();
checkSwapchainStatus(viewSize.x, viewSize.y);
checkSwapchainStatus(viewSize.width, viewSize.height);
#else
checkSwapchainStatus();
#endif
+2 -2
View File
@@ -243,12 +243,12 @@ void EditBox::show(const EditBox::ShowInfo &showInfo) {
RECT rect;
GetWindowRect(getCurrentWindowHwnd(), &rect);
float WindowRatio = (float)(rect.bottom - rect.top) / (float)CC_GET_PLATFORM_INTERFACE(ISystemWindow)->getViewSize().y;
float WindowRatio = (float)(rect.bottom - rect.top) / (float)CC_GET_PLATFORM_INTERFACE(ISystemWindow)->getViewSize().height;
float JsFontRatio = float(showInfo.fontSize) / 5;
/** A probale way to calculate the increase of font size
* OriginalSize + Increase = OriginalSize * Ratio_of_js_fontSize * Ratio_of_window
* Default value : OriginalSize = 8, Ratio_of_js_fontSize = showInfo.fontSize /5,
* Ratio_of_window = (float)height / (float)CC_GET_PLATFORM_INTERFACE(ISystemWindow)->getViewSize().y
* Ratio_of_window = (float)height / (float)CC_GET_PLATFORM_INTERFACE(ISystemWindow)->getViewSize().height
* thus Increase was calculated.
*/
int fsize = (float)(JsFontRatio + 8) * WindowRatio - 8;
+24 -3
View File
@@ -18,6 +18,11 @@
#include "platform/FileUtils.h"
#include "platform/SAXParser.h"
#include "math/Vec2.h"
#include "math/Vec3.h"
#include "math/Vec4.h"
#include "math/Mat3.h"
#include "math/Mat4.h"
#include "math/Quaternion.h"
#include "math/Color.h"
#include "profiler/DebugRenderer.h"
%}
@@ -42,6 +47,15 @@
// 2. namespace is needed
//
%rename("$ignore", regextarget=1, fullname=1) "cc::Vec2::.*[^2]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Vec3::.*[^3]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Vec3::t.*$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Vec4::.*[^4]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Mat3::.*[^3]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Mat4::.*[^4]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Quaternion::.*[^n]$";
%rename("$ignore", regextarget=1, fullname=1) "cc::Color::.*[^n]$";
namespace cc {
//%ignore ISystemWindowManager;
@@ -106,6 +120,7 @@ namespace cc {
// %rename(CanvasGradient) cc::ICanvasGradient;
%rename(PlistParser) cc::SAXParser;
%rename(Quat) cc::Quaternion;
// ----- Module Macro Section ------
@@ -166,7 +181,15 @@ namespace cc {
%import "math/MathBase.h"
%import "math/Geometry.h"
%import "math/Vec4.h"
%include "math/Vec2.h"
%include "math/Color.h"
%include "math/Vec3.h"
%include "math/Vec4.h"
%include "math/Mat3.h"
%include "math/Mat4.h"
%include "math/Quaternion.h"
%import "platform/interfaces/modules/IScreen.h"
%import "platform/interfaces/modules/ISystem.h"
%import "platform/interfaces/modules/INetwork.h"
@@ -185,8 +208,6 @@ namespace cc {
%include "platform/interfaces/modules/ISystemWindowManager.h"
%include "platform/FileUtils.h"
%include "platform/SAXParser.h"
%include "math/Vec2.h"
%include "math/Color.h"
%include "profiler/DebugRenderer.h"
+1
View File
@@ -15,6 +15,7 @@
// Insert code at the beginning of generated source file (.cpp)
%{
#include "bindings/auto/jsb_geometry_auto.h"
#include "bindings/auto/jsb_cocos_auto.h"
%}
// ----- Ignore Section ------
+1 -1
View File
@@ -23,7 +23,7 @@ export class MouseInputSource {
const windowSize = window.getViewSize();
const dpr = screenAdapter.devicePixelRatio;
const x = event.x * dpr;
const y = windowSize.y - event.y * dpr;
const y = windowSize.height - event.y * dpr;
return new Vec2(x, y);
}
+1 -1
View File
@@ -58,7 +58,7 @@ export class TouchInputSource {
private _getLocation (touch: globalThis.Touch, windowSize: Size): Vec2 {
const dpr = screenAdapter.devicePixelRatio;
const x = touch.clientX * dpr;
const y = windowSize.y - touch.clientY * dpr;
const y = windowSize.height - touch.clientY * dpr;
return new Vec2(x, y);
}