diff --git a/native/.github/workflows/filter_by_cdb.js b/native/.github/workflows/filter_by_cdb.js index 2e8e358847..29225f9267 100644 --- a/native/.github/workflows/filter_by_cdb.js +++ b/native/.github/workflows/filter_by_cdb.js @@ -5,6 +5,11 @@ const fs = require('fs'); const ARGS = process.argv.slice(2); +const excludes = [ + 'cocos/renderer/gfx-vulkan/volk', + 'cocos/bindings/auto', +]; + let result = []; const cdbFile = path.join(__dirname, '../../build/compile_commands.json'); @@ -12,6 +17,7 @@ if (fs.existsSync(cdbFile)) { const db = JSON.parse(fs.readFileSync(cdbFile, { encoding: 'utf8' })); for (let f of ARGS) { const name = f.endsWith('.h') ? f.slice(0, -2) : f; // ignore .h extension name + if (excludes.some((e) => name.includes(e))) continue; if (db.some((info) => info.file.includes(name))) { result.push(f); } diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 98637b022e..88c4d00a30 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -404,6 +404,7 @@ cocos_source_files( cocos/base/etc2.cpp cocos/base/etc2.h cocos/base/IndexHandle.h + cocos/base/LinearAllocatorPool.h cocos/base/Log.cpp cocos/base/Log.h cocos/base/Macros.h @@ -760,7 +761,6 @@ cocos_source_files( cocos/renderer/gfx-agent/FramebufferAgent.cpp cocos/renderer/gfx-agent/InputAssemblerAgent.h cocos/renderer/gfx-agent/InputAssemblerAgent.cpp - cocos/renderer/gfx-agent/LinearAllocatorPool.h cocos/renderer/gfx-agent/PipelineLayoutAgent.h cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp cocos/renderer/gfx-agent/PipelineStateAgent.h @@ -1933,6 +1933,7 @@ if(WIN32) NOMINMAX UNICODE _UNICODE + _USE_MATH_DEFINES _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS _USRLIBSIMSTATIC diff --git a/native/cocos/base/Agent.h b/native/cocos/base/Agent.h index f7d7f2eb40..062a8ba194 100644 --- a/native/cocos/base/Agent.h +++ b/native/cocos/base/Agent.h @@ -38,7 +38,7 @@ public: explicit Agent(Actor *const actor) noexcept : Actor(), _actor(actor) {} - ~Agent() override {} + ~Agent() override = default; Agent(Agent const &) = delete; diff --git a/native/cocos/base/CachedArray.h b/native/cocos/base/CachedArray.h index 6d2448b377..f29a25c19c 100755 --- a/native/cocos/base/CachedArray.h +++ b/native/cocos/base/CachedArray.h @@ -34,9 +34,9 @@ template class CachedArray : public Object { public: explicit CachedArray(uint size = 1U) { - _size = 0; - _capacity = std::max(size, 1u); - _array = CC_NEW_ARRAY(T, _capacity); + _size = 0; + _capacity = std::max(size, 1U); + _array = CC_NEW_ARRAY(T, _capacity); } // The rule of five applies here @@ -49,55 +49,53 @@ public: memcpy(_array, other._array, _size * sizeof(T)); } - // NOLINTNEXTLINE(bugprone-unhandled-self-assignment) false positive - CachedArray &operator=(const CachedArray &other) noexcept { + CachedArray &operator=(const CachedArray &other) { if (this != &other) { CC_DELETE_ARRAY(_array); - _size = other._size; + _size = other._size; _capacity = other._capacity; - _array = CC_NEW_ARRAY(T, _capacity); + _array = CC_NEW_ARRAY(T, _capacity); memcpy(_array, other._array, _size * sizeof(T)); } return *this; } - CachedArray(CachedArray &&other) - noexcept : _size(other._size), _capacity(other._capacity), _array(other._array) { - other._size = 0; + CachedArray(CachedArray &&other) noexcept : _size(other._size), _capacity(other._capacity), _array(other._array) { + other._size = 0; other._capacity = 0; - other._array = nullptr; + other._array = nullptr; } CachedArray &operator=(CachedArray &&other) noexcept { if (this != &other) { CC_DELETE_ARRAY(_array); - _size = other._size; - _capacity = other._capacity; - _array = other._array; - other._size = 0; + _size = other._size; + _capacity = other._capacity; + _array = other._array; + other._size = 0; other._capacity = 0; - other._array = nullptr; + other._array = nullptr; } return *this; } // Subscription operators - T &operator[](int index) { + T &operator[](uint index) { return _array[index]; } - const T &operator[](int index) const { + const T &operator[](uint index) const { return _array[index]; } CC_INLINE void clear() { _size = 0; } CC_INLINE uint size() const { return _size; } - CC_INLINE T pop() { return _array[--_size]; } + CC_INLINE T pop() { return _array[--_size]; } void reserve(uint size) { if (size > _capacity) { T *temp = _array; - _array = CC_NEW_ARRAY(T, size); + _array = CC_NEW_ARRAY(T, size); memcpy(_array, temp, _capacity * sizeof(T)); _capacity = size; CC_DELETE_ARRAY(temp); @@ -107,7 +105,7 @@ public: void push(T item) { if (_size >= _capacity) { T *temp = _array; - _array = CC_NEW_ARRAY(T, _capacity * 2); + _array = CC_NEW_ARRAY(T, _capacity * 2); memcpy(_array, temp, _capacity * sizeof(T)); _capacity *= 2; CC_DELETE_ARRAY(temp); @@ -117,9 +115,9 @@ public: void concat(const CachedArray &array) { if (_size + array._size > _capacity) { - T *temp = _array; + T * temp = _array; uint size = std::max(_capacity * 2, _size + array._size); - _array = CC_NEW_ARRAY(T, size); + _array = CC_NEW_ARRAY(T, size); memcpy(_array, temp, _size * sizeof(T)); _capacity = size; CC_DELETE_ARRAY(temp); @@ -130,9 +128,9 @@ public: void concat(T *array, uint count) { if (_size + count > _capacity) { - T *temp = _array; + T * temp = _array; uint size = std::max(_capacity * 2, _size + count); - _array = CC_NEW_ARRAY(T, size); + _array = CC_NEW_ARRAY(T, size); memcpy(_array, temp, _size * sizeof(T)); _capacity = size; CC_DELETE_ARRAY(temp); @@ -158,9 +156,9 @@ public: } private: - uint _size = 0; + uint _size = 0; uint _capacity = 0; - T *_array = nullptr; + T * _array = nullptr; }; } // namespace cc diff --git a/native/cocos/base/CoreStd.h b/native/cocos/base/CoreStd.h index c239f19019..d6ac48dcef 100644 --- a/native/cocos/base/CoreStd.h +++ b/native/cocos/base/CoreStd.h @@ -27,7 +27,7 @@ #include "base/Macros.h" -// STD including +// STD includes #include #include #include @@ -37,11 +37,10 @@ #include #include -// STL including +// STL includes #include #include #include -#include #include #include #include diff --git a/native/cocos/renderer/gfx-agent/LinearAllocatorPool.h b/native/cocos/base/LinearAllocatorPool.h similarity index 72% rename from native/cocos/renderer/gfx-agent/LinearAllocatorPool.h rename to native/cocos/base/LinearAllocatorPool.h index b65fb9aa5c..815bafce61 100644 --- a/native/cocos/renderer/gfx-agent/LinearAllocatorPool.h +++ b/native/cocos/base/LinearAllocatorPool.h @@ -25,30 +25,20 @@ #pragma once -#include #include -#include "base/threading/ThreadSafeLinearAllocator.h" +#include + +#include "Utils.h" +#include "memory/Memory.h" +#include "threading/ThreadSafeLinearAllocator.h" namespace cc { -namespace gfx { -namespace { constexpr size_t DEFAULT_BLOCK_SIZE = 4096 * 16; -uint nextPowerOf2(uint v) { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return ++v; -} -} - -class CC_DLL LinearAllocatorPool final { +class LinearAllocatorPool final { public: - LinearAllocatorPool(size_t defaultBlockSize = DEFAULT_BLOCK_SIZE): _defaultBlockSize(defaultBlockSize) { + explicit LinearAllocatorPool(size_t defaultBlockSize = DEFAULT_BLOCK_SIZE) : _defaultBlockSize(defaultBlockSize) { _allocators.emplace_back(CC_NEW(ThreadSafeLinearAllocator(static_cast(_defaultBlockSize)))); } @@ -59,19 +49,19 @@ public: _allocators.clear(); } - template - T* allocate(const uint count, uint alignment = 64u) noexcept { + template + T *allocate(const uint count, uint alignment = 64U) noexcept { if (!count) return nullptr; - T* res = nullptr; + T * res = nullptr; size_t size = count * sizeof(T); for (ThreadSafeLinearAllocator *allocator : _allocators) { - res = reinterpret_cast(allocator->allocate(size, alignment)); + res = reinterpret_cast(allocator->allocate(size, alignment)); if (res) return res; } - uint capacity = nextPowerOf2(static_cast(std::max(DEFAULT_BLOCK_SIZE, size + static_cast(alignment)))); // reserve enough padding space for alignment + uint capacity = utils::nextPOT(static_cast(std::max(DEFAULT_BLOCK_SIZE, size + static_cast(alignment)))); // reserve enough padding space for alignment _allocators.emplace_back(CC_NEW(ThreadSafeLinearAllocator(static_cast(capacity)))); - return reinterpret_cast(_allocators.back()->allocate(size, alignment)); + return reinterpret_cast(_allocators.back()->allocate(size, alignment)); } inline void reset() { @@ -82,8 +72,7 @@ public: protected: vector _allocators; - size_t _defaultBlockSize = DEFAULT_BLOCK_SIZE; + size_t _defaultBlockSize = DEFAULT_BLOCK_SIZE; }; -} // namespace gfx } // namespace cc diff --git a/native/cocos/base/TypeDef.h b/native/cocos/base/TypeDef.h index 994139c326..07bce4f465 100755 --- a/native/cocos/base/TypeDef.h +++ b/native/cocos/base/TypeDef.h @@ -39,6 +39,8 @@ using FlagBits = uint32_t; inline T operator|(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) | static_cast::type>(rhs)); } \ inline T operator&(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) & static_cast::type>(rhs)); } \ inline T operator^(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) ^ static_cast::type>(rhs)); } \ + inline T operator+(const T lhs, const T rhs) { return static_cast(static_cast::type>(lhs) + static_cast::type>(rhs)); } \ + inline T operator+(const T lhs, bool rhs) { return static_cast(static_cast::type>(lhs) + rhs); } \ inline void operator|=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) | static_cast::type>(rhs)); } \ inline void operator&=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) & static_cast::type>(rhs)); } \ inline void operator^=(T &lhs, const T rhs) { lhs = static_cast(static_cast::type>(lhs) ^ static_cast::type>(rhs)); } \ diff --git a/native/cocos/base/Utils.cpp b/native/cocos/base/Utils.cpp index 1559291af2..b4d9fdcb08 100644 --- a/native/cocos/base/Utils.cpp +++ b/native/cocos/base/Utils.cpp @@ -60,7 +60,7 @@ double atof(const char *str) { return ::atof(buf); } -int nextPOT(int x) { +uint nextPOT(uint x) { x = x - 1; x = x | (x >> 1); x = x | (x >> 2); diff --git a/native/cocos/base/threading/MessageQueue.h b/native/cocos/base/threading/MessageQueue.h index 924bcf0457..eef9aa2ecc 100644 --- a/native/cocos/base/threading/MessageQueue.h +++ b/native/cocos/base/threading/MessageQueue.h @@ -55,7 +55,7 @@ public: Message &operator=(Message const &) = delete; Message &operator=(Message &&) = delete; - virtual void execute() noexcept = 0; + virtual void execute() = 0; virtual char const *getName() const noexcept = 0; inline Message * getNext() const noexcept { return _next; } @@ -125,10 +125,10 @@ public: void recycleMemoryChunk(uint8_t *chunk) const noexcept; static void freeChunksInFreeQueue(MessageQueue *mainMessageQueue) noexcept; - inline void setImmediateMode(bool immediateMode) noexcept { _immediateMode = immediateMode; } - inline int getPendingMessageCount() const noexcept { return _writer.pendingMessageCount; } - inline int getWrittenMessageCount() const noexcept { return _writer.writtenMessageCount; } - inline int getNewMessageCount() const noexcept { return _reader.newMessageCount; } + inline void setImmediateMode(bool immediateMode) noexcept { _immediateMode = immediateMode; } + inline uint32_t getPendingMessageCount() const noexcept { return _writer.pendingMessageCount; } + inline uint32_t getWrittenMessageCount() const noexcept { return _writer.writtenMessageCount; } + inline uint32_t getNewMessageCount() const noexcept { return _reader.newMessageCount; } private: class alignas(64) MemoryAllocator final { @@ -254,461 +254,461 @@ T *MessageQueue::allocateAndZero(uint32_t const count) noexcept { } \ } -#define ENQUEUE_MESSAGE_0(queue, MessageName, Code) \ - { \ - class MessageName final : public Message { \ - public: \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - }; \ - WRITE_MESSAGE(queue, MessageName, ); \ +#define ENQUEUE_MESSAGE_0(queue, MessageName, Code) \ + { \ + class MessageName final : public Message { \ + public: \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + }; \ + WRITE_MESSAGE(queue, MessageName, ); \ } -#define ENQUEUE_MESSAGE_1(queue, MessageName, \ - Param1, Value1, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - \ - class MessageName final : public Message { \ - public: \ - explicit MessageName(Type1 In##Param1) \ - : Param1(std::move(In##Param1)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - }; \ - WRITE_MESSAGE(queue, MessageName, (Value1)) \ +#define ENQUEUE_MESSAGE_1(queue, MessageName, \ + Param1, Value1, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + \ + class MessageName final : public Message { \ + public: \ + explicit MessageName(Type1 In##Param1) \ + : Param1(std::move(In##Param1)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + }; \ + WRITE_MESSAGE(queue, MessageName, (Value1)) \ } -#define ENQUEUE_MESSAGE_2(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - \ - class MessageName final : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, Type2 In##Param2) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - }; \ - WRITE_MESSAGE(queue, MessageName, (Value1, Value2)) \ +#define ENQUEUE_MESSAGE_2(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + \ + class MessageName final : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, Type2 In##Param2) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + }; \ + WRITE_MESSAGE(queue, MessageName, (Value1, Value2)) \ } -#define ENQUEUE_MESSAGE_3(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - \ - class MessageName final : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3)) \ +#define ENQUEUE_MESSAGE_3(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + \ + class MessageName final : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3)) \ } -#define ENQUEUE_MESSAGE_4(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4)) \ +#define ENQUEUE_MESSAGE_4(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4)) \ } -#define ENQUEUE_MESSAGE_5(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Param5, Value5, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - using Type5 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4, \ - Type5 In##Param5) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)), \ - Param5(std::move(In##Param5)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - Type5 Param5; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4, \ - Value5)) \ +#define ENQUEUE_MESSAGE_5(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Param5, Value5, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + using Type5 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4, \ + Type5 In##Param5) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)), \ + Param5(std::move(In##Param5)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + Type5 Param5; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4, \ + Value5)) \ } -#define ENQUEUE_MESSAGE_6(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Param5, Value5, \ - Param6, Value6, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - using Type5 = std::decay::type; \ - using Type6 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4, \ - Type5 In##Param5, \ - Type6 In##Param6) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)), \ - Param5(std::move(In##Param5)), \ - Param6(std::move(In##Param6)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - Type5 Param5; \ - Type6 Param6; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4, \ - Value5, \ - Value6)) \ +#define ENQUEUE_MESSAGE_6(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Param5, Value5, \ + Param6, Value6, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + using Type5 = std::decay::type; \ + using Type6 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4, \ + Type5 In##Param5, \ + Type6 In##Param6) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)), \ + Param5(std::move(In##Param5)), \ + Param6(std::move(In##Param6)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + Type5 Param5; \ + Type6 Param6; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4, \ + Value5, \ + Value6)) \ } -#define ENQUEUE_MESSAGE_7(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Param5, Value5, \ - Param6, Value6, \ - Param7, Value7, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - using Type5 = std::decay::type; \ - using Type6 = std::decay::type; \ - using Type7 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName( \ - Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4, \ - Type5 In##Param5, \ - Type6 In##Param6, \ - Type7 In##Param7) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)), \ - Param5(std::move(In##Param5)), \ - Param6(std::move(In##Param6)), \ - Param7(std::move(In##Param7)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual const char *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - Type5 Param5; \ - Type6 Param6; \ - Type7 Param7; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4, \ - Value5, \ - Value6, \ - Value7)) \ +#define ENQUEUE_MESSAGE_7(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Param5, Value5, \ + Param6, Value6, \ + Param7, Value7, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + using Type5 = std::decay::type; \ + using Type6 = std::decay::type; \ + using Type7 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName( \ + Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4, \ + Type5 In##Param5, \ + Type6 In##Param6, \ + Type7 In##Param7) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)), \ + Param5(std::move(In##Param5)), \ + Param6(std::move(In##Param6)), \ + Param7(std::move(In##Param7)) { \ + } \ + void execute() override { \ + Code \ + } \ + const char *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + Type5 Param5; \ + Type6 Param6; \ + Type7 Param7; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4, \ + Value5, \ + Value6, \ + Value7)) \ } -#define ENQUEUE_MESSAGE_8(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Param5, Value5, \ - Param6, Value6, \ - Param7, Value7, \ - Param8, Value8, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - using Type5 = std::decay::type; \ - using Type6 = std::decay::type; \ - using Type7 = std::decay::type; \ - using Type8 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName(Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4, \ - Type5 In##Param5, \ - Type6 In##Param6, \ - Type7 In##Param7, \ - Type8 In##Param8) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)), \ - Param5(std::move(In##Param5)), \ - Param6(std::move(In##Param6)), \ - Param7(std::move(In##Param7)), \ - Param8(std::move(In##Param8)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - Type5 Param5; \ - Type6 Param6; \ - Type7 Param7; \ - Type8 Param8; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4, \ - Value5, \ - Value6, \ - Value7, \ - Value8)) \ +#define ENQUEUE_MESSAGE_8(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Param5, Value5, \ + Param6, Value6, \ + Param7, Value7, \ + Param8, Value8, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + using Type5 = std::decay::type; \ + using Type6 = std::decay::type; \ + using Type7 = std::decay::type; \ + using Type8 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName(Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4, \ + Type5 In##Param5, \ + Type6 In##Param6, \ + Type7 In##Param7, \ + Type8 In##Param8) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)), \ + Param5(std::move(In##Param5)), \ + Param6(std::move(In##Param6)), \ + Param7(std::move(In##Param7)), \ + Param8(std::move(In##Param8)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + Type5 Param5; \ + Type6 Param6; \ + Type7 Param7; \ + Type8 Param8; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4, \ + Value5, \ + Value6, \ + Value7, \ + Value8)) \ } -#define ENQUEUE_MESSAGE_9(queue, MessageName, \ - Param1, Value1, \ - Param2, Value2, \ - Param3, Value3, \ - Param4, Value4, \ - Param5, Value5, \ - Param6, Value6, \ - Param7, Value7, \ - Param8, Value8, \ - Param9, Value9, \ - Code) \ - { \ - using Type1 = std::decay::type; \ - using Type2 = std::decay::type; \ - using Type3 = std::decay::type; \ - using Type4 = std::decay::type; \ - using Type5 = std::decay::type; \ - using Type6 = std::decay::type; \ - using Type7 = std::decay::type; \ - using Type8 = std::decay::type; \ - using Type9 = std::decay::type; \ - \ - class MessageName : public Message { \ - public: \ - MessageName(Type1 In##Param1, \ - Type2 In##Param2, \ - Type3 In##Param3, \ - Type4 In##Param4, \ - Type5 In##Param5, \ - Type6 In##Param6, \ - Type7 In##Param7, \ - Type8 In##Param8, \ - Type9 In##Param9) \ - : Param1(std::move(In##Param1)), \ - Param2(std::move(In##Param2)), \ - Param3(std::move(In##Param3)), \ - Param4(std::move(In##Param4)), \ - Param5(std::move(In##Param5)), \ - Param6(std::move(In##Param6)), \ - Param7(std::move(In##Param7)), \ - Param8(std::move(In##Param8)), \ - Param9(std::move(In##Param9)) { \ - } \ - virtual void execute() noexcept override { \ - Code \ - } \ - virtual char const *getName() const noexcept override { \ - return (#MessageName); \ - } \ - \ - private: \ - Type1 Param1; \ - Type2 Param2; \ - Type3 Param3; \ - Type4 Param4; \ - Type5 Param5; \ - Type6 Param6; \ - Type7 Param7; \ - Type8 Param8; \ - Type9 Param9; \ - }; \ - WRITE_MESSAGE(queue, MessageName, \ - (Value1, \ - Value2, \ - Value3, \ - Value4, \ - Value5, \ - Value6, \ - Value7, \ - Value8, \ - Value9)) \ +#define ENQUEUE_MESSAGE_9(queue, MessageName, \ + Param1, Value1, \ + Param2, Value2, \ + Param3, Value3, \ + Param4, Value4, \ + Param5, Value5, \ + Param6, Value6, \ + Param7, Value7, \ + Param8, Value8, \ + Param9, Value9, \ + Code) \ + { \ + using Type1 = std::decay::type; \ + using Type2 = std::decay::type; \ + using Type3 = std::decay::type; \ + using Type4 = std::decay::type; \ + using Type5 = std::decay::type; \ + using Type6 = std::decay::type; \ + using Type7 = std::decay::type; \ + using Type8 = std::decay::type; \ + using Type9 = std::decay::type; \ + \ + class MessageName : public Message { \ + public: \ + MessageName(Type1 In##Param1, \ + Type2 In##Param2, \ + Type3 In##Param3, \ + Type4 In##Param4, \ + Type5 In##Param5, \ + Type6 In##Param6, \ + Type7 In##Param7, \ + Type8 In##Param8, \ + Type9 In##Param9) \ + : Param1(std::move(In##Param1)), \ + Param2(std::move(In##Param2)), \ + Param3(std::move(In##Param3)), \ + Param4(std::move(In##Param4)), \ + Param5(std::move(In##Param5)), \ + Param6(std::move(In##Param6)), \ + Param7(std::move(In##Param7)), \ + Param8(std::move(In##Param8)), \ + Param9(std::move(In##Param9)) { \ + } \ + void execute() override { \ + Code \ + } \ + char const *getName() const noexcept override { \ + return (#MessageName); \ + } \ + \ + private: \ + Type1 Param1; \ + Type2 Param2; \ + Type3 Param3; \ + Type4 Param4; \ + Type5 Param5; \ + Type6 Param6; \ + Type7 Param7; \ + Type8 Param8; \ + Type9 Param9; \ + }; \ + WRITE_MESSAGE(queue, MessageName, \ + (Value1, \ + Value2, \ + Value3, \ + Value4, \ + Value5, \ + Value6, \ + Value7, \ + Value8, \ + Value9)) \ } } // namespace cc diff --git a/native/cocos/bindings/auto/jsb_audio_auto.cpp b/native/cocos/bindings/auto/jsb_audio_auto.cpp index 758dfb9d71..755ee714a5 100644 --- a/native/cocos/bindings/auto/jsb_audio_auto.cpp +++ b/native/cocos/bindings/auto/jsb_audio_auto.cpp @@ -714,7 +714,7 @@ static bool js_audio_AudioEngine_setFinishCallback(se::State& s) CC_UNUSED bool ok = true; if (argc == 2) { HolderType arg0 = {}; - HolderType, true> arg1 = {}; + HolderType, true> arg1 = {}; ok &= sevalue_to_native(args[0], &arg0, nullptr); do { if (args[1].isObject() && args[1].toObject()->isFunction()) @@ -722,7 +722,7 @@ static bool js_audio_AudioEngine_setFinishCallback(se::State& s) se::Value jsThis(s.thisObject()); se::Value jsFunc(args[1]); jsFunc.toObject()->root(); - auto lambda = [=](int larg0, const std::string& larg1) -> void { + auto lambda = [=](int larg0, const std::string larg1) -> void { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; diff --git a/native/cocos/bindings/auto/jsb_extension_auto.cpp b/native/cocos/bindings/auto/jsb_extension_auto.cpp index aca62a1b43..ff87b41e32 100644 --- a/native/cocos/bindings/auto/jsb_extension_auto.cpp +++ b/native/cocos/bindings/auto/jsb_extension_auto.cpp @@ -1032,14 +1032,14 @@ static bool js_extension_AssetsManagerEx_setVerifyCallback(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](const std::string& larg0, cc::extension::ManifestAsset larg1) -> bool { + auto lambda = [=](const std::string larg0, cc::extension::ManifestAsset larg1) -> bool { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; @@ -1085,14 +1085,14 @@ static bool js_extension_AssetsManagerEx_setVersionCompareHandle(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](const std::string& larg0, const std::string& larg1) -> int { + auto lambda = [=](const std::string larg0, const std::string larg1) -> int { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; @@ -1183,14 +1183,14 @@ static bool js_extension_AssetsManagerEx_constructor(se::State& s) // construct HolderType arg1 = {}; ok &= sevalue_to_native(args[1], &arg1, s.thisObject()); if (!ok) { ok = true; break; } - HolderType, true> arg2 = {}; + HolderType, true> arg2 = {}; do { if (args[2].isObject() && args[2].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[2]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](const std::string& larg0, const std::string& larg1) -> int { + auto lambda = [=](const std::string larg0, const std::string larg1) -> int { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.cpp b/native/cocos/bindings/auto/jsb_gfx_auto.cpp index e33567ecb9..17760fc9e9 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gfx_auto.cpp @@ -14898,7 +14898,7 @@ static bool js_gfx_GFXObject_getObjectType(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getObjectType(); + auto result = static_cast(cobj->getObjectType()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_GFXObject_getObjectType : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -15022,7 +15022,7 @@ static bool js_gfx_Buffer_getFlags(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getFlags(); + auto result = static_cast(cobj->getFlags()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getFlags : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -15041,7 +15041,7 @@ static bool js_gfx_Buffer_getMemUsage(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getMemUsage(); + auto result = static_cast(cobj->getMemUsage()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getMemUsage : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -15098,7 +15098,7 @@ static bool js_gfx_Buffer_getUsage(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getUsage(); + auto result = static_cast(cobj->getUsage()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getUsage : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -16101,7 +16101,7 @@ static bool js_gfx_CommandBuffer_getType(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getType(); + auto result = static_cast(cobj->getType()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_getType : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -16464,7 +16464,7 @@ static bool js_gfx_Context_getColorFormat(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getColorFormat(); + auto result = static_cast(cobj->getColorFormat()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Context_getColorFormat : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -16483,7 +16483,7 @@ static bool js_gfx_Context_getDepthStencilFormat(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getDepthStencilFormat(); + auto result = static_cast(cobj->getDepthStencilFormat()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Context_getDepthStencilFormat : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -16521,7 +16521,7 @@ static bool js_gfx_Context_getVsyncMode(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getVsyncMode(); + auto result = static_cast(cobj->getVsyncMode()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Context_getVsyncMode : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -17590,7 +17590,7 @@ static bool js_gfx_PipelineState_getBindPoint(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getBindPoint(); + auto result = static_cast(cobj->getBindPoint()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getBindPoint : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -17647,7 +17647,7 @@ static bool js_gfx_PipelineState_getDynamicStates(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getDynamicStates(); + auto result = static_cast(cobj->getDynamicStates()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDynamicStates : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -17704,7 +17704,7 @@ static bool js_gfx_PipelineState_getPrimitive(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getPrimitive(); + auto result = static_cast(cobj->getPrimitive()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getPrimitive : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -17870,7 +17870,7 @@ static bool js_gfx_Queue_getType(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getType(); + auto result = static_cast(cobj->getType()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Queue_getType : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18171,7 +18171,7 @@ static bool js_gfx_Sampler_getAddressU(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getAddressU(); + auto result = static_cast(cobj->getAddressU()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getAddressU : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18190,7 +18190,7 @@ static bool js_gfx_Sampler_getAddressV(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getAddressV(); + auto result = static_cast(cobj->getAddressV()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getAddressV : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18209,7 +18209,7 @@ static bool js_gfx_Sampler_getAddressW(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getAddressW(); + auto result = static_cast(cobj->getAddressW()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getAddressW : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18247,7 +18247,7 @@ static bool js_gfx_Sampler_getCmpFunc(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getCmpFunc(); + auto result = static_cast(cobj->getCmpFunc()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getCmpFunc : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18266,7 +18266,7 @@ static bool js_gfx_Sampler_getMagFilter(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getMagFilter(); + auto result = static_cast(cobj->getMagFilter()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getMagFilter : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18304,7 +18304,7 @@ static bool js_gfx_Sampler_getMinFilter(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getMinFilter(); + auto result = static_cast(cobj->getMinFilter()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getMinFilter : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18323,7 +18323,7 @@ static bool js_gfx_Sampler_getMipFilter(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getMipFilter(); + auto result = static_cast(cobj->getMipFilter()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_getMipFilter : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18750,7 +18750,7 @@ static bool js_gfx_Texture_getFlags(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getFlags(); + auto result = static_cast(cobj->getFlags()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getFlags : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18769,7 +18769,7 @@ static bool js_gfx_Texture_getFormat(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getFormat(); + auto result = static_cast(cobj->getFormat()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getFormat : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18845,7 +18845,7 @@ static bool js_gfx_Texture_getSamples(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getSamples(); + auto result = static_cast(cobj->getSamples()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getSamples : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18883,7 +18883,7 @@ static bool js_gfx_Texture_getType(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getType(); + auto result = static_cast(cobj->getType()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getType : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -18902,7 +18902,7 @@ static bool js_gfx_Texture_getUsage(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getUsage(); + auto result = static_cast(cobj->getUsage()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getUsage : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -19508,7 +19508,7 @@ static bool js_gfx_Device_getColorFormat(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getColorFormat(); + auto result = static_cast(cobj->getColorFormat()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Device_getColorFormat : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -19546,7 +19546,7 @@ static bool js_gfx_Device_getDepthStencilFormat(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getDepthStencilFormat(); + auto result = static_cast(cobj->getDepthStencilFormat()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Device_getDepthStencilFormat : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -19584,7 +19584,7 @@ static bool js_gfx_Device_getGfxAPI(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getGfxAPI(); + auto result = static_cast(cobj->getGfxAPI()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Device_getGfxAPI : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -19774,7 +19774,7 @@ static bool js_gfx_Device_getSurfaceTransform(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getSurfaceTransform(); + auto result = static_cast(cobj->getSurfaceTransform()); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_gfx_Device_getSurfaceTransform : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -19903,25 +19903,6 @@ static bool js_gfx_Device_resize(se::State& s) } SE_BIND_FUNC(js_gfx_Device_resize) -static bool js_gfx_Device_setMultithreaded(se::State& s) -{ - auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_setMultithreaded : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 1) { - HolderType arg0 = {}; - ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_setMultithreaded : Error processing arguments"); - cobj->setMultithreaded(arg0.value()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); - return false; -} -SE_BIND_FUNC(js_gfx_Device_setMultithreaded) - @@ -19967,7 +19948,6 @@ bool js_register_gfx_Device(se::Object* obj) cls->defineFunction("initialize", _SE(js_gfx_Device_initialize)); cls->defineFunction("present", _SE(js_gfx_Device_present)); cls->defineFunction("resize", _SE(js_gfx_Device_resize)); - cls->defineFunction("setMultithreaded", _SE(js_gfx_Device_setMultithreaded)); cls->install(); JSBClassType::registerClass(cls); diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.h b/native/cocos/bindings/auto/jsb_gfx_auto.h index 71d8e80ec8..ec83d280dc 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.h +++ b/native/cocos/bindings/auto/jsb_gfx_auto.h @@ -829,5 +829,4 @@ SE_DECLARE_FUNC(js_gfx_Device_hasFeature); SE_DECLARE_FUNC(js_gfx_Device_initialize); SE_DECLARE_FUNC(js_gfx_Device_present); SE_DECLARE_FUNC(js_gfx_Device_resize); -SE_DECLARE_FUNC(js_gfx_Device_setMultithreaded); diff --git a/native/cocos/bindings/auto/jsb_webview_auto.cpp b/native/cocos/bindings/auto/jsb_webview_auto.cpp index 7332603f49..f0e243a86d 100644 --- a/native/cocos/bindings/auto/jsb_webview_auto.cpp +++ b/native/cocos/bindings/auto/jsb_webview_auto.cpp @@ -161,7 +161,7 @@ static bool js_webview_WebView_getOnShouldStartLoading(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - std::function result = cobj->getOnShouldStartLoading(); + std::function result = cobj->getOnShouldStartLoading(); ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "js_webview_WebView_getOnShouldStartLoading : Error processing arguments"); SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); @@ -398,14 +398,14 @@ static bool js_webview_WebView_setOnDidFailLoading(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](cc::WebView* larg0, const std::string& larg1) -> void { + auto lambda = [=](cc::WebView* larg0, const std::string larg1) -> void { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; @@ -447,14 +447,14 @@ static bool js_webview_WebView_setOnDidFinishLoading(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](cc::WebView* larg0, const std::string& larg1) -> void { + auto lambda = [=](cc::WebView* larg0, const std::string larg1) -> void { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; @@ -496,14 +496,14 @@ static bool js_webview_WebView_setOnJSCallback(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](cc::WebView* larg0, const std::string& larg1) -> void { + auto lambda = [=](cc::WebView* larg0, const std::string larg1) -> void { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; @@ -545,14 +545,14 @@ static bool js_webview_WebView_setOnShouldStartLoading(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType, true> arg0 = {}; + HolderType, true> arg0 = {}; do { if (args[0].isObject() && args[0].toObject()->isFunction()) { se::Value jsThis(s.thisObject()); se::Value jsFunc(args[0]); jsThis.toObject()->attachObject(jsFunc.toObject()); - auto lambda = [=](cc::WebView* larg0, const std::string& larg1) -> bool { + auto lambda = [=](cc::WebView* larg0, const std::string larg1) -> bool { se::ScriptEngine::getInstance()->clearException(); se::AutoHandleScope hs; diff --git a/native/cocos/bindings/jswrapper/chakracore/Object.cpp b/native/cocos/bindings/jswrapper/chakracore/Object.cpp index 0156abd058..eac1534729 100644 --- a/native/cocos/bindings/jswrapper/chakracore/Object.cpp +++ b/native/cocos/bindings/jswrapper/chakracore/Object.cpp @@ -81,7 +81,7 @@ Object *Object::createArrayBufferObject(void *data, size_t byteLength) { return obj; } -Object *Object::createTypedArray(TypedArrayType type, void *data, size_t byteLength) { +Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t byteLength) { if (type == TypedArrayType::NONE) { SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!"); return nullptr; diff --git a/native/cocos/bindings/jswrapper/chakracore/Object.h b/native/cocos/bindings/jswrapper/chakracore/Object.h index efe8f91c07..06611f9fb9 100644 --- a/native/cocos/bindings/jswrapper/chakracore/Object.h +++ b/native/cocos/bindings/jswrapper/chakracore/Object.h @@ -89,7 +89,7 @@ public: * @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error. * @note The return value (non-null) has to be released manually. */ - static Object *createTypedArray(TypedArrayType type, void *data, size_t byteLength); + static Object *createTypedArray(TypedArrayType type, const void *data, size_t byteLength); /** * @brief Creates a JavaScript Array Buffer object from an existing pointer. @@ -294,12 +294,12 @@ public: * @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object, * which means `obj` may be garbage collected only after current object is garbage collected. * It's normally used in binding a native callback method. For example: - + ```javascript var self = this; someObject.setCallback(function(){}, self); ``` - + ```c++ static bool SomeObject_setCallback(se::State& s) { diff --git a/native/cocos/bindings/jswrapper/jsc/Object.h b/native/cocos/bindings/jswrapper/jsc/Object.h index 31e6a8533d..f2ad63b005 100644 --- a/native/cocos/bindings/jswrapper/jsc/Object.h +++ b/native/cocos/bindings/jswrapper/jsc/Object.h @@ -90,7 +90,7 @@ public: * @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error. * @note The return value (non-null) has to be released manually. */ - static Object *createTypedArray(TypedArrayType type, void *data, size_t byteLength); + static Object *createTypedArray(TypedArrayType type, const void *data, size_t byteLength); /** * @brief Creates a JavaScript Array Buffer object from an existing pointer. @@ -302,12 +302,12 @@ public: * @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object, * which means `obj` may be garbage collected only after current object is garbage collected. * It's normally used in binding a native callback method. For example: - + ```javascript var self = this; someObject.setCallback(function(){}, self); ``` - + ```c++ static bool SomeObject_setCallback(se::State& s) { diff --git a/native/cocos/bindings/jswrapper/jsc/Object.mm b/native/cocos/bindings/jswrapper/jsc/Object.mm index 8998a7bc81..500f9865b0 100644 --- a/native/cocos/bindings/jswrapper/jsc/Object.mm +++ b/native/cocos/bindings/jswrapper/jsc/Object.mm @@ -138,7 +138,7 @@ Object *Object::createArrayBufferObject(void *data, size_t byteLength) { return obj; } -Object *Object::createTypedArray(TypedArrayType type, void *data, size_t byteLength) { +Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t byteLength) { if (type == TypedArrayType::NONE) { SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!"); return nullptr; diff --git a/native/cocos/bindings/jswrapper/sm/Object.cpp b/native/cocos/bindings/jswrapper/sm/Object.cpp index 20c57e8031..142c439a2c 100644 --- a/native/cocos/bindings/jswrapper/sm/Object.cpp +++ b/native/cocos/bindings/jswrapper/sm/Object.cpp @@ -134,7 +134,7 @@ Object *Object::createArrayBufferObject(void *data, size_t byteLength) { return obj; } -Object *Object::createTypedArray(TypedArrayType type, void *data, size_t byteLength) { +Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t byteLength) { if (type == TypedArrayType::NONE) { SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!"); return nullptr; diff --git a/native/cocos/bindings/jswrapper/sm/Object.h b/native/cocos/bindings/jswrapper/sm/Object.h index 7815c144eb..92bee1afbc 100644 --- a/native/cocos/bindings/jswrapper/sm/Object.h +++ b/native/cocos/bindings/jswrapper/sm/Object.h @@ -90,7 +90,7 @@ public: * @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error. * @note The return value (non-null) has to be released manually. */ - static Object *createTypedArray(TypedArrayType type, void *data, size_t byteLength); + static Object *createTypedArray(TypedArrayType type, const void *data, size_t byteLength); /** * @brief Creates a JavaScript Array Buffer object from an existing pointer. @@ -295,12 +295,12 @@ public: * @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object, * which means `obj` may be garbage collected only after current object is garbage collected. * It's normally used in binding a native callback method. For example: - + ```javascript var self = this; someObject.setCallback(function(){}, self); ``` - + ```c++ static bool SomeObject_setCallback(se::State& s) { diff --git a/native/cocos/bindings/jswrapper/v8/HelperMacros.h b/native/cocos/bindings/jswrapper/v8/HelperMacros.h index 26513d8528..36593fa685 100644 --- a/native/cocos/bindings/jswrapper/v8/HelperMacros.h +++ b/native/cocos/bindings/jswrapper/v8/HelperMacros.h @@ -115,7 +115,6 @@ inline void printJSBInvoke() { bool ret = false; \ v8::Isolate * _isolate = _v8args.GetIsolate(); \ v8::HandleScope _hs(_isolate); \ - SE_UNUSED unsigned argc = (unsigned)_v8args.Length(); \ se::ValueArray args; \ args.reserve(10); \ se::internal::jsToSeArgs(_v8args, &args); \ diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 08f2199eb5..d333f2c79c 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -193,7 +193,7 @@ Object *Object::createArrayBufferObject(void *data, size_t byteLength) { return obj; } -Object *Object::createTypedArray(TypedArrayType type, void *data, size_t byteLength) { +Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t byteLength) { if (type == TypedArrayType::NONE) { SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!"); return nullptr; diff --git a/native/cocos/bindings/jswrapper/v8/Object.h b/native/cocos/bindings/jswrapper/v8/Object.h index d092459e07..d7782fe6d9 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.h +++ b/native/cocos/bindings/jswrapper/v8/Object.h @@ -98,7 +98,7 @@ public: * @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error. * @note The return value (non-null) has to be released manually. */ - static Object *createTypedArray(TypedArrayType type, void *data, size_t byteLength); + static Object *createTypedArray(TypedArrayType type, const void *data, size_t byteLength); /** * @brief Creates a JavaScript Array Buffer object from an existing pointer. @@ -318,12 +318,12 @@ public: * @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object, * which means `obj` may be garbage collected only after current object is garbage collected. * It's normally used in binding a native callback method. For example: - + ```javascript var self = this; someObject.setCallback(function(){}, self); ``` - + ```c++ static bool SomeObject_setCallback(se::State& s) { diff --git a/native/cocos/bindings/manual/jsb_classtype.cpp b/native/cocos/bindings/manual/jsb_classtype.cpp index 3392accf41..54c07a2371 100644 --- a/native/cocos/bindings/manual/jsb_classtype.cpp +++ b/native/cocos/bindings/manual/jsb_classtype.cpp @@ -25,22 +25,4 @@ #include "jsb_classtype.h" -JSBClassType::Map *JSBClassType::__jsbClassTypeMap = nullptr; - -bool JSBClassType::init() { - if (__jsbClassTypeMap == nullptr) - __jsbClassTypeMap = new (std::nothrow) Map(); - - return __jsbClassTypeMap != nullptr; -} - -void JSBClassType::destroy() { - if (__jsbClassTypeMap != nullptr) { - delete __jsbClassTypeMap; - __jsbClassTypeMap = nullptr; - } -} - -void JSBClassType::cleanup() { - __jsbClassTypeMap->clear(); -} +std::unordered_map JSBClassType::jsbClassTypeMap; diff --git a/native/cocos/bindings/manual/jsb_classtype.h b/native/cocos/bindings/manual/jsb_classtype.h index 7f9a9527ad..3a96b9c7c9 100644 --- a/native/cocos/bindings/manual/jsb_classtype.h +++ b/native/cocos/bindings/manual/jsb_classtype.h @@ -31,25 +31,22 @@ class JSBClassType { public: - static bool init(); - static void destroy(); - template static void registerClass(se::Class *cls) { const char *typeName = typeid(T).name(); - assert(__jsbClassTypeMap->find(typeName) == __jsbClassTypeMap->end()); - __jsbClassTypeMap->emplace(typeName, cls); + assert(jsbClassTypeMap.find(typeName) == jsbClassTypeMap.end()); + jsbClassTypeMap.emplace(typeName, cls); } template - static se::Class *findClass(const T *nativeObj) { - bool found = false; - std::string typeName = typeid(*nativeObj).name(); - auto iter = __jsbClassTypeMap->find(typeName); - if (iter == __jsbClassTypeMap->end()) { + static se::Class *findClass(const T * /*nativeObj*/) { + bool found = false; + std::string typeName = typeid(T).name(); + auto iter = jsbClassTypeMap.find(typeName); + if (iter == jsbClassTypeMap.end()) { typeName = typeid(T).name(); - iter = __jsbClassTypeMap->find(typeName); - if (iter != __jsbClassTypeMap->end()) { + iter = jsbClassTypeMap.find(typeName); + if (iter != jsbClassTypeMap.end()) { found = true; } } else { @@ -58,9 +55,10 @@ public: return found ? iter->second : nullptr; } - static void cleanup(); + static void cleanup() { + jsbClassTypeMap.clear(); + } private: - using Map = std::unordered_map; - static Map *__jsbClassTypeMap; + static std::unordered_map jsbClassTypeMap; }; diff --git a/native/cocos/bindings/manual/jsb_conversions.h b/native/cocos/bindings/manual/jsb_conversions.h index 4687e7106a..2497b42339 100644 --- a/native/cocos/bindings/manual/jsb_conversions.h +++ b/native/cocos/bindings/manual/jsb_conversions.h @@ -26,6 +26,7 @@ #pragma once #include +#include #include #include "bindings/jswrapper/SeApi.h" #include "bindings/manual/jsb_classtype.h" @@ -157,49 +158,49 @@ struct InputAssemblerInfo; #endif // se value -> native value -bool seval_to_int32(const se::Value &v, int32_t *ret); //NOLINT -bool seval_to_uint32(const se::Value &v, uint32_t *ret); //NOLINT -bool seval_to_uint(const se::Value &v, unsigned int *ret); //NOLINT -bool seval_to_int8(const se::Value &v, int8_t *ret); //NOLINT -bool seval_to_uint8(const se::Value &v, uint8_t *ret); //NOLINT -bool seval_to_int16(const se::Value &v, int16_t *ret); //NOLINT -bool seval_to_uint16(const se::Value &v, uint16_t *ret); //NOLINT -bool seval_to_boolean(const se::Value &v, bool *ret); //NOLINT -bool seval_to_float(const se::Value &v, float *ret); //NOLINT -bool seval_to_double(const se::Value &v, double *ret); //NOLINT -bool seval_to_long(const se::Value &v, long *ret); //NOLINT -bool seval_to_ulong(const se::Value &v, unsigned long *ret); //NOLINT -bool seval_to_longlong(const se::Value &v, long long *ret); //NOLINT -bool seval_to_size(const se::Value &v, size_t *ret); //NOLINT -bool seval_to_std_string(const se::Value &v, std::string *ret); //NOLINT -bool seval_to_Vec2(const se::Value &v, cc::Vec2 *pt); //NOLINT -bool seval_to_Vec3(const se::Value &v, cc::Vec3 *pt); //NOLINT -bool seval_to_Vec4(const se::Value &v, cc::Vec4 *pt); //NOLINT -bool seval_to_Mat4(const se::Value &v, cc::Mat4 *mat); //NOLINT -bool seval_to_Size(const se::Value &v, cc::Size *size); //NOLINT -bool seval_to_ccvalue(const se::Value &v, cc::Value *ret); //NOLINT -bool seval_to_ccvaluemap(const se::Value &v, cc::ValueMap *ret); //NOLINT -bool seval_to_ccvaluemapintkey(const se::Value &v, cc::ValueMapIntKey *ret); //NOLINT -bool seval_to_ccvaluevector(const se::Value &v, cc::ValueVector *ret); //NOLINT -bool sevals_variadic_to_ccvaluevector(const se::ValueArray &args, cc::ValueVector *ret); //NOLINT -bool seval_to_std_vector_string(const se::Value &v, std::vector *ret); //NOLINT -bool seval_to_std_vector_int(const se::Value &v, std::vector *ret); //NOLINT -bool seval_to_std_vector_uint16(const se::Value &v, std::vector *ret); //NOLINT -bool seval_to_std_vector_float(const se::Value &v, std::vector *ret); //NOLINT -bool seval_to_std_vector_Vec2(const se::Value &v, std::vector *ret); //NOLINT -bool seval_to_Uint8Array(const se::Value &v, uint8_t *ret); //NOLINT -bool seval_to_uintptr_t(const se::Value &v, uintptr_t *ret); //NOLINT +bool seval_to_int32(const se::Value &v, int32_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_uint32(const se::Value &v, uint32_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_uint(const se::Value &v, unsigned int *ret); // NOLINT(readability-identifier-naming) +bool seval_to_int8(const se::Value &v, int8_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_uint8(const se::Value &v, uint8_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_int16(const se::Value &v, int16_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_uint16(const se::Value &v, uint16_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_boolean(const se::Value &v, bool *ret); // NOLINT(readability-identifier-naming) +bool seval_to_float(const se::Value &v, float *ret); // NOLINT(readability-identifier-naming) +bool seval_to_double(const se::Value &v, double *ret); // NOLINT(readability-identifier-naming) +bool seval_to_long(const se::Value &v, long *ret); // NOLINT(readability-identifier-naming) +bool seval_to_ulong(const se::Value &v, unsigned long *ret); // NOLINT(readability-identifier-naming) +bool seval_to_longlong(const se::Value &v, long long *ret); // NOLINT(readability-identifier-naming) +bool seval_to_size(const se::Value &v, size_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_string(const se::Value &v, std::string *ret); // NOLINT(readability-identifier-naming) +bool seval_to_Vec2(const se::Value &v, cc::Vec2 *pt); // NOLINT(readability-identifier-naming) +bool seval_to_Vec3(const se::Value &v, cc::Vec3 *pt); // NOLINT(readability-identifier-naming) +bool seval_to_Vec4(const se::Value &v, cc::Vec4 *pt); // NOLINT(readability-identifier-naming) +bool seval_to_Mat4(const se::Value &v, cc::Mat4 *mat); // NOLINT(readability-identifier-naming) +bool seval_to_Size(const se::Value &v, cc::Size *size); // NOLINT(readability-identifier-naming) +bool seval_to_ccvalue(const se::Value &v, cc::Value *ret); // NOLINT(readability-identifier-naming) +bool seval_to_ccvaluemap(const se::Value &v, cc::ValueMap *ret); // NOLINT(readability-identifier-naming) +bool seval_to_ccvaluemapintkey(const se::Value &v, cc::ValueMapIntKey *ret); // NOLINT(readability-identifier-naming) +bool seval_to_ccvaluevector(const se::Value &v, cc::ValueVector *ret); // NOLINT(readability-identifier-naming) +bool sevals_variadic_to_ccvaluevector(const se::ValueArray &args, cc::ValueVector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_vector_string(const se::Value &v, std::vector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_vector_int(const se::Value &v, std::vector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_vector_uint16(const se::Value &v, std::vector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_vector_float(const se::Value &v, std::vector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_std_vector_Vec2(const se::Value &v, std::vector *ret); // NOLINT(readability-identifier-naming) +bool seval_to_Uint8Array(const se::Value &v, uint8_t *ret); // NOLINT(readability-identifier-naming) +bool seval_to_uintptr_t(const se::Value &v, uintptr_t *ret); // NOLINT(readability-identifier-naming) -bool seval_to_std_map_string_string(const se::Value &v, std::map *ret); //NOLINT -bool seval_to_Data(const se::Value &v, cc::Data *ret); //NOLINT -bool seval_to_DownloaderHints(const se::Value &v, cc::network::DownloaderHints *ret); //NOLINT +bool seval_to_std_map_string_string(const se::Value &v, std::map *ret); // NOLINT(readability-identifier-naming) +bool seval_to_Data(const se::Value &v, cc::Data *ret); // NOLINT(readability-identifier-naming) +bool seval_to_DownloaderHints(const se::Value &v, cc::network::DownloaderHints *ret); // NOLINT(readability-identifier-naming) template -bool seval_to_native_ptr(const se::Value &v, T *ret) { //NOLINT +bool seval_to_native_ptr(const se::Value &v, T *ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); if (v.isObject()) { - T ptr = (T)v.toObject()->getPrivateData(); + T ptr = static_cast(v.toObject()->getPrivateData()); if (ptr == nullptr) { // This should never happen, return 'false' to mark the conversion fails. *ret = nullptr; @@ -208,7 +209,8 @@ bool seval_to_native_ptr(const se::Value &v, T *ret) { //NOLINT *ret = ptr; return true; - } else if (v.isNullOrUndefined()) { + } + if (v.isNullOrUndefined()) { // If js value is null or undefined, the convertion should be successful. // So we should return 'true' to indicate the convertion succeeds and mark // the out value to 'nullptr'. @@ -223,18 +225,18 @@ bool seval_to_native_ptr(const se::Value &v, T *ret) { //NOLINT template typename std::enable_if::value && !std::is_same::value, T>::type -seval_to_type(const se::Value &v, bool &ok) { +seval_to_type(const se::Value &v, bool &ok) { // NOLINT(readability-identifier-naming) if (!v.isObject()) { ok = false; return T(); } - T *nativeObj = (T *)v.toObject()->getPrivateData(); + T *nativeObj = static_cast(v.toObject()->getPrivateData()); ok = true; return *nativeObj; } template typename std::enable_if::value, T>::type -seval_to_type(const se::Value &v, bool &ok) { +seval_to_type(const se::Value &v, bool &ok) { // NOLINT(readability-identifier-naming) if (!v.isNumber()) { ok = false; return 0; @@ -245,18 +247,18 @@ seval_to_type(const se::Value &v, bool &ok) { template typename std::enable_if::value, T>::type -seval_to_type(const se::Value &v, bool &ok) { +seval_to_type(const se::Value &v, bool &ok) { // NOLINT(readability-identifier-naming) if (!v.isNumber()) { ok = false; - return (T)0; + return static_cast(0); } ok = true; - return (T)v.toInt32(); + return static_cast(v.toInt32()); } template typename std::enable_if::value, T>::type -seval_to_type(const se::Value &v, bool &ok) { +seval_to_type(const se::Value &v, bool &ok) { // NOLINT(readability-identifier-naming) if (!v.isNumber()) { ok = false; return 0; @@ -267,7 +269,7 @@ seval_to_type(const se::Value &v, bool &ok) { template typename std::enable_if::value, T>::type -seval_to_type(const se::Value &v, bool &ok) { +seval_to_type(const se::Value &v, bool &ok) { // NOLINT(readability-identifier-naming) if (!v.isString()) { ok = false; return ""; @@ -278,7 +280,7 @@ seval_to_type(const se::Value &v, bool &ok) { template typename std::enable_if::value && std::is_class::type>::value, bool>::type -seval_to_std_vector(const se::Value &v, std::vector *ret) { +seval_to_std_vector(const se::Value &v, std::vector *ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); assert(v.isObject()); se::Object *obj = v.toObject(); @@ -303,7 +305,7 @@ seval_to_std_vector(const se::Value &v, std::vector *ret) { } if (tmp.isObject()) { - T nativeObj = (T)tmp.toObject()->getPrivateData(); + T nativeObj = static_cast(tmp.toObject()->getPrivateData()); (*ret)[i] = nativeObj; } else if (tmp.isNullOrUndefined()) { (*ret)[i] = nullptr; @@ -318,7 +320,7 @@ seval_to_std_vector(const se::Value &v, std::vector *ret) { template typename std::enable_if::value, bool>::type -seval_to_std_vector(const se::Value &v, std::vector *ret) { +seval_to_std_vector(const se::Value &v, std::vector *ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); assert(v.isObject()); se::Object *obj = v.toObject(); @@ -351,7 +353,7 @@ seval_to_std_vector(const se::Value &v, std::vector *ret) { } template -bool seval_to_Map_string_key(const se::Value &v, cc::Map *ret) { +bool seval_to_Map_string_key(const se::Value &v, cc::Map *ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); assert(v.isObject()); se::Object *obj = v.toObject(); @@ -371,7 +373,7 @@ bool seval_to_Map_string_key(const se::Value &v, cc::Map *ret) { return false; } - T nativeObj = (T)tmp.toObject()->getPrivateData(); + T nativeObj = static_cast(tmp.toObject()->getPrivateData()); ret->insert(key, nativeObj); } @@ -379,42 +381,43 @@ bool seval_to_Map_string_key(const se::Value &v, cc::Map *ret) { } // native value -> se value -bool int8_to_seval(int8_t v, se::Value *ret); //NOLINT -bool uint8_to_seval(uint8_t v, se::Value *ret); //NOLINT -bool int32_to_seval(int32_t v, se::Value *ret); //NOLINT -bool uint32_to_seval(uint32_t v, se::Value *ret); //NOLINT -bool int16_to_seval(uint16_t v, se::Value *ret); //NOLINT -bool uint16_to_seval(uint16_t v, se::Value *ret); //NOLINT -bool boolean_to_seval(bool v, se::Value *ret); //NOLINT -bool float_to_seval(float v, se::Value *ret); //NOLINT -bool double_to_seval(double v, se::Value *ret); //NOLINT -bool long_to_seval(long v, se::Value *ret); //NOLINT -bool ulong_to_seval(unsigned long v, se::Value *ret); //NOLINT -bool longlong_to_seval(long long v, se::Value *ret); //NOLINT -bool uintptr_t_to_seval(uintptr_t v, se::Value *ret); //NOLINT -bool size_to_seval(size_t v, se::Value *ret); //NOLINT -bool std_string_to_seval(const std::string &v, se::Value *ret); //NOLINT +bool int8_to_seval(int8_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool uint8_to_seval(uint8_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool int32_to_seval(int32_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool uint32_to_seval(uint32_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool int16_to_seval(uint16_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool uint16_to_seval(uint16_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool boolean_to_seval(bool v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool float_to_seval(float v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool double_to_seval(double v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool long_to_seval(long v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool ulong_to_seval(unsigned long v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool longlong_to_seval(long long v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool uintptr_t_to_seval(uintptr_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool size_to_seval(size_t v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_string_to_seval(const std::string &v, se::Value *ret); // NOLINT(readability-identifier-naming) -bool Vec2_to_seval(const cc::Vec2 &v, se::Value *ret); //NOLINT -bool Vec3_to_seval(const cc::Vec3 &v, se::Value *ret); //NOLINT -bool Vec4_to_seval(const cc::Vec4 &v, se::Value *ret); //NOLINT -bool Mat4_to_seval(const cc::Mat4 &v, se::Value *ret); //NOLINT -bool Size_to_seval(const cc::Size &v, se::Value *ret); //NOLINT -bool Rect_to_seval(const cc::Rect &v, se::Value *ret); //NOLINT -bool ccvalue_to_seval(const cc::Value &v, se::Value *ret); //NOLINT -bool ccvaluemap_to_seval(const cc::ValueMap &v, se::Value *ret); //NOLINT -bool ccvaluemapintkey_to_seval(const cc::ValueMapIntKey &v, se::Value *ret); //NOLINT -bool ccvaluevector_to_seval(const cc::ValueVector &v, se::Value *ret); //NOLINT -bool std_vector_string_to_seval(const std::vector &v, se::Value *ret); //NOLINT -bool std_vector_int_to_seval(const std::vector &v, se::Value *ret); //NOLINT -bool std_vector_uint16_to_seval(const std::vector &v, se::Value *ret); //NOLINT -bool std_vector_float_to_seval(const std::vector &v, se::Value *ret); //NOLINT -bool std_map_string_string_to_seval(const std::map &v, se::Value *ret); //NOLINT -bool ManifestAsset_to_seval(const cc::extension::ManifestAsset &v, se::Value *ret); //NOLINT -bool Data_to_seval(const cc::Data &v, se::Value *ret); //NOLINT -bool DownloadTask_to_seval(const cc::network::DownloadTask &v, se::Value *ret); //NOLINT +bool Vec2_to_seval(const cc::Vec2 &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Vec3_to_seval(const cc::Vec3 &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Vec4_to_seval(const cc::Vec4 &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Mat4_to_seval(const cc::Mat4 &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Size_to_seval(const cc::Size &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Rect_to_seval(const cc::Rect &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool ccvalue_to_seval(const cc::Value &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool ccvaluemap_to_seval(const cc::ValueMap &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool ccvaluemapintkey_to_seval(const cc::ValueMapIntKey &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool ccvaluevector_to_seval(const cc::ValueVector &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_vector_string_to_seval(const std::vector &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_vector_int_to_seval(const std::vector &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_vector_uint16_to_seval(const std::vector &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_vector_float_to_seval(const std::vector &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool std_map_string_string_to_seval(const std::map &v, se::Value *ret); // NOLINT(readability-identifier-naming) -// TODO: should add these functions if only bind gfx. +bool ManifestAsset_to_seval(const cc::extension::ManifestAsset &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool Data_to_seval(const cc::Data &v, se::Value *ret); // NOLINT(readability-identifier-naming) +bool DownloadTask_to_seval(const cc::network::DownloadTask &v, se::Value *ret); // NOLINT(readability-identifier-naming) + +// TODO(minggo): should add these functions if only bind gfx. // gfx_color_attachment_to_seval // gfx_depth_stecil_attachment_to_seval // sub_pass_info_to_seval @@ -424,9 +427,9 @@ bool DownloadTask_to_seval(const cc::network::DownloadTask &v, se::Value *ret); template typename std::enable_if::value, bool>::type -native_ptr_to_seval(T *v_c, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(v_c); +native_ptr_to_seval(T *v_c, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(v_c); assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -459,9 +462,9 @@ native_ptr_to_seval(T *v_c, se::Value *ret, bool *isReturnCachedValue = nullptr) //handle reference template typename std::enable_if::value && !std::is_pointer::value, bool>::type -native_ptr_to_seval(T &v_ref, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(&v_ref); +native_ptr_to_seval(T &v_ref, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(&v_ref); assert(ret != nullptr); if (v == nullptr) { @@ -493,7 +496,9 @@ native_ptr_to_seval(T &v_ref, se::Value *ret, bool *isReturnCachedValue = nullpt } template -bool native_ptr_to_rooted_seval(const typename std::enable_if::value, T>::type *v, se::Value *ret, bool *isReturnCachedValue = nullptr) { +bool native_ptr_to_rooted_seval( // NOLINT(readability-identifier-naming) + typename std::enable_if::value, T>::type *v, + se::Value *ret, bool *isReturnCachedValue = nullptr) { assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -501,13 +506,13 @@ bool native_ptr_to_rooted_seval(const typename std::enable_if(v)); if (iter == se::NativePtrToObjectMap::end()) { // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt se::Class *cls = JSBClassType::findClass(v); assert(cls != nullptr); obj = se::Object::createObjectWithClass(cls); obj->root(); - obj->setPrivateData((void *)v); + obj->setPrivateData(reinterpret_cast(v)); if (isReturnCachedValue != nullptr) { *isReturnCachedValue = false; @@ -528,9 +533,9 @@ bool native_ptr_to_rooted_seval(const typename std::enable_if typename std::enable_if::value, bool>::type -native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(vp); +native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(vp); assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -563,9 +568,9 @@ native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedV //handle ref template typename std::enable_if::value, bool>::type -native_ptr_to_seval(T &v_ref, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(&v_ref); +native_ptr_to_seval(T &v_ref, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(&v_ref); assert(ret != nullptr); if (v == nullptr) { @@ -597,7 +602,9 @@ native_ptr_to_seval(T &v_ref, se::Class *cls, se::Value *ret, bool *isReturnCach } template -bool native_ptr_to_rooted_seval(typename std::enable_if::value, T>::type *v, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { +bool native_ptr_to_rooted_seval( // NOLINT(readability-identifier-naming) + typename std::enable_if::value, T>::type *v, + se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -631,9 +638,9 @@ bool native_ptr_to_rooted_seval(typename std::enable_if typename std::enable_if::value, bool>::type -native_ptr_to_seval(T *vp, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(vp); +native_ptr_to_seval(T *vp, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(vp); assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -667,9 +674,9 @@ native_ptr_to_seval(T *vp, se::Value *ret, bool *isReturnCachedValue = nullptr) template typename std::enable_if::value, bool>::type -native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { - typedef typename std::decay::type>::type DecayT; - DecayT * v = const_cast(vp); +native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedValue = nullptr) { // NOLINT(readability-identifier-naming) + using DecayT = typename std::decay::type>::type; + auto *v = const_cast(vp); assert(ret != nullptr); if (v == nullptr) { ret->setNull(); @@ -700,7 +707,7 @@ native_ptr_to_seval(T *vp, se::Class *cls, se::Value *ret, bool *isReturnCachedV } template -bool std_vector_to_seval(const std::vector &v, se::Value *ret) { +bool std_vector_to_seval(const std::vector &v, se::Value *ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); bool ok = true; se::HandleObject obj(se::Object::createArrayObject(v.size())); @@ -719,10 +726,10 @@ bool std_vector_to_seval(const std::vector &v, se::Value *ret) { } template -bool seval_to_reference(const se::Value &v, T **ret) { +bool seval_to_reference(const se::Value &v, T **ret) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); assert(v.isObject()); - *ret = (T *)v.toObject()->getPrivateData(); + *ret = static_cast(v.toObject()->getPrivateData()); return true; } @@ -731,30 +738,30 @@ bool seval_to_reference(const se::Value &v, T **ret) { ////////////////////////// is jsb object /////////////////////////// template -struct _is_jsb_object : std::false_type {}; +struct is_jsb_object : std::false_type {}; // NOLINT(readability-identifier-naming) template -constexpr bool is_jsb_object_v = _is_jsb_object::type>::value; +constexpr bool is_jsb_object_v = is_jsb_object::type>::value; // NOLINT(readability-identifier-naming) #define JSB_REGISTER_OBJECT_TYPE(T) \ template <> \ - struct _is_jsb_object : std::true_type {} + struct is_jsb_object : std::true_type {} template constexpr inline typename std::enable_if::value, Out>::type & -holder_convert_to(In &input) { +holder_convert_to(In &input) { // NOLINT(readability-identifier-naming) return input; } template constexpr inline typename std::enable_if::value && std::is_same::type>::value, Out>::type & -holder_convert_to(In &input) { - return (Out)(&input); +holder_convert_to(In &input) { // NOLINT(readability-identifier-naming) + return static_cast(&input); } template constexpr inline typename std::enable_if::value && std::is_same::type>::value, Out>::type & -holder_convert_to(In &input) { +holder_convert_to(In &input) { // NOLINT(readability-identifier-naming) return *input; } @@ -779,7 +786,7 @@ struct HolderType { using local_type = std::string; local_type data; std::remove_const_t *ptr = nullptr; - inline type value() { return data.c_str(); } + inline type value() const { return data.c_str(); } }; template @@ -795,7 +802,7 @@ struct HolderType, true> { template inline typename std::enable_if_t::value && !std::is_pointer::value, bool> -sevalue_to_native(const se::Value &from, T *to, se::Object *) { +sevalue_to_native(const se::Value & /*from*/, T * /*to*/, se::Object * /*unused*/) { // NOLINT(readability-identifier-naming) // CC_STATIC_ASSERT(std::is_same::value, "sevalue_to_native not implemented for type"); SE_LOGE("Can not convert type ???\n - [[ %s ]]\n", typeid(T).name()); return false; @@ -803,7 +810,7 @@ sevalue_to_native(const se::Value &from, T *to, se::Object *) { template inline typename std::enable_if_t::value, bool> -sevalue_to_native(const se::Value &from, T *to, se::Object *ctx) { +sevalue_to_native(const se::Value &from, T *to, se::Object *ctx) { // NOLINT(readability-identifier-naming) typename std::underlying_type_t tmp; bool ret = sevalue_to_native(from, &tmp, ctx); if (ret) *to = static_cast(tmp); @@ -813,7 +820,7 @@ sevalue_to_native(const se::Value &from, T *to, se::Object *ctx) { //////////////// vector type template -bool sevalue_to_native(const se::Value &from, std::array *to, se::Object *ctx) { +bool sevalue_to_native(const se::Value &from, std::array *to, se::Object *ctx) { // NOLINT(readability-identifier-naming) assert(from.toObject()); se::Object *array = from.toObject(); assert(array->isArray()); @@ -829,7 +836,7 @@ bool sevalue_to_native(const se::Value &from, std::array *to, se::Object } template -bool sevalue_to_native(const se::Value &from, std::array *to, se::Object *ctx) { +bool sevalue_to_native(const se::Value &from, std::array *to, se::Object *ctx) { // NOLINT(readability-identifier-naming) assert(from.toObject()); se::Object *array = from.toObject(); assert(array->isArray() || array->isArrayBuffer() || array->isTypedArray()); @@ -853,7 +860,7 @@ bool sevalue_to_native(const se::Value &from, std::array *to, se:: se::Value tmp; assert(len >= CNT); for (size_t i = 0; i < CNT; i++) { - array->getArrayElement((uint)i, &tmp); + array->getArrayElement(static_cast(i), &tmp); sevalue_to_native(tmp, &(*to)[i], ctx); } } else { @@ -863,85 +870,85 @@ bool sevalue_to_native(const se::Value &from, std::array *to, se:: } template <> -inline bool sevalue_to_native(const se::Value &from, std::string *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, std::string *to, se::Object * /*ctx*/) { *to = from.toString(); return true; } ///// integers template <> -inline bool sevalue_to_native(const se::Value &from, bool *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, bool *to, se::Object * /*ctx*/) { *to = from.toBoolean(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, int32_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, int32_t *to, se::Object * /*ctx*/) { *to = from.toInt32(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, uint32_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, uint32_t *to, se::Object * /*ctx*/) { *to = from.toUint32(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, int16_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, int16_t *to, se::Object * /*ctx*/) { *to = from.toInt16(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, uint16_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, uint16_t *to, se::Object * /*ctx*/) { *to = from.toUint16(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, int8_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, int8_t *to, se::Object * /*ctx*/) { *to = from.toInt8(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, uint8_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, uint8_t *to, se::Object * /*ctx*/) { *to = from.toUint8(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, uint64_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, uint64_t *to, se::Object * /*ctx*/) { *to = from.toUIntptr_t(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, int64_t *to, se::Object *) { - *to = (int64_t)from.toNumber(); +inline bool sevalue_to_native(const se::Value &from, int64_t *to, se::Object * /*ctx*/) { + *to = static_cast(from.toNumber()); return true; } #if CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_MAC_OSX template <> -inline bool sevalue_to_native(const se::Value &from, uintptr_t *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, uintptr_t *to, se::Object *ctx) { *to = (uintptr_t)from.toNumber(); return true; } #endif template <> -inline bool sevalue_to_native(const se::Value &from, float *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, float *to, se::Object * /*ctx*/) { *to = from.toFloat(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, void *to, se::Object *) { +inline bool sevalue_to_native(const se::Value & /*from*/, void * /*to*/, se::Object * /*ctx*/) { assert(false); // void not supported return false; } template<> -inline bool sevalue_to_native(const se::Value &from, cc::Data *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, cc::Data *to, se::Object * /*ctx*/) { return seval_to_Data(from, to); } @@ -949,7 +956,7 @@ inline bool sevalue_to_native(const se::Value &from, cc::Data *to, se::Object *) template typename std::enable_if_t::value && !std::is_pointer::type>::value, bool> -sevalue_to_native(const se::Value &from, T to, se::Object *) { +sevalue_to_native(const se::Value &from, T to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) CC_STATIC_ASSERT(is_jsb_object_v>, "Only JSB object are accepted!"); if (from.isNullOrUndefined()) { //const std::string stack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); @@ -957,66 +964,89 @@ sevalue_to_native(const se::Value &from, T to, se::Object *) { *to = nullptr; return true; } - *to = (T)from.toObject()->getPrivateData(); + *to = static_cast(from.toObject()->getPrivateData()); return true; } template typename std::enable_if_t::value && std::is_pointer::type>::value, bool> -sevalue_to_native(const se::Value &from, T to, se::Object *) { - CC_STATIC_ASSERT(is_jsb_object_v::type>::type>, "Only JSB object are accepted!"); +sevalue_to_native(const se::Value &from, T to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) + using Value = typename std::remove_pointer::type>::type; + CC_STATIC_ASSERT(is_jsb_object_v || std::is_arithmetic::value, "Only JSB object or arithmetic types are supported"); + + if CC_CONSTEXPR (is_jsb_object_v) { + if (from.isNullOrUndefined()) { + //const std::string stack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); + //SE_LOGE("[ERROR] sevalue_to_native jsval is null/undefined: %s\nstack: %s", typeid(T).name(), stack.c_str()); + *to = nullptr; + return true; + } + *to = static_cast::type>(from.toObject()->getPrivateData()); + return true; + } else if CC_CONSTEXPR (std::is_arithmetic::value) { + se::Object *array = from.toObject(); + assert(array->isTypedArray()); + uint8_t *data = nullptr; + size_t dataLen = 0; + array->getTypedArrayData(&data, &dataLen); + *to = reinterpret_cast(data); + return true; + } +} + +template +typename std::enable_if_t::value && is_jsb_object_v, bool> +sevalue_to_native(const se::Value &from, T **to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) if (from.isNullOrUndefined()) { //const std::string stack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); //SE_LOGE("[ERROR] sevalue_to_native jsval is null/undefined: %s\nstack: %s", typeid(T).name(), stack.c_str()); *to = nullptr; return true; } - *to = (typename std::remove_pointer::type)from.toObject()->getPrivateData(); + *to = static_cast(from.toObject()->getPrivateData()); return true; } template typename std::enable_if_t::value && is_jsb_object_v, bool> -sevalue_to_native(const se::Value &from, T **to, se::Object *) { +sevalue_to_native(const se::Value &from, T ***to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) if (from.isNullOrUndefined()) { //const std::string stack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); //SE_LOGE("[ERROR] sevalue_to_native jsval is null/undefined: %s\nstack: %s", typeid(T).name(), stack.c_str()); *to = nullptr; return true; } - *to = (T *)from.toObject()->getPrivateData(); - return true; -} - -template -typename std::enable_if_t::value && is_jsb_object_v, bool> -sevalue_to_native(const se::Value &from, T ***to, se::Object *) { - if (from.isNullOrUndefined()) { - //const std::string stack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); - //SE_LOGE("[ERROR] sevalue_to_native jsval is null/undefined: %s\nstack: %s", typeid(T).name(), stack.c_str()); - *to = nullptr; - return true; - } - **to = (T *)from.toObject()->getPrivateData(); + **to = static_cast(from.toObject()->getPrivateData()); return true; } template -bool sevalue_to_native(const se::Value &from, std::vector *to, se::Object *ctx) { +bool sevalue_to_native(const se::Value &from, std::vector *to, se::Object *ctx) { // NOLINT(readability-identifier-naming) assert(from.toObject()); se::Object *array = from.toObject(); - assert(array->isArray()); - uint32_t len = 0; - array->getArrayLength(&len); - to->resize(len); - se::Value tmp; - for (uint32_t i = 0; i < len; i++) { - array->getArrayElement(i, &tmp); - if (!sevalue_to_native(tmp, to->data() + i, ctx)) { - SE_LOGE("vector %s convert error at %d\n", typeid(T).name(), i); + + if (array->isArray()) { + uint32_t len = 0; + array->getArrayLength(&len); + to->resize(len); + se::Value tmp; + for (uint32_t i = 0; i < len; i++) { + array->getArrayElement(i, &tmp); + if (!sevalue_to_native(tmp, to->data() + i, ctx)) { + SE_LOGE("vector %s convert error at %d\n", typeid(T).name(), i); + } } + return true; + } + + if (array->isTypedArray()) { + assert(std::is_arithmetic::value); + uint8_t *data = nullptr; + size_t dataLen = 0; + array->getTypedArrayData(&data, &dataLen); + to->assign(reinterpret_cast(data), reinterpret_cast(data + dataLen)); + return true; } - return true; } //template<> @@ -1027,27 +1057,28 @@ bool sevalue_to_native(const se::Value &from, std::vector *to, se: //} template <> -inline bool sevalue_to_native(const se::Value &from, void **to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, void **to, se::Object * /*ctx*/) { SE_LOGE("[warn] don't know how to convert to void *\n"); *to = from.toObject()->getPrivateData(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, std::string **to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, std::string **to, se::Object * /*ctx*/) { **to = from.toString(); return true; } template <> -inline bool sevalue_to_native(const se::Value &from, cc::ValueMap *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, cc::ValueMap *to, se::Object * /*ctx*/) { return seval_to_ccvaluemap(from, to); } template <> -inline bool sevalue_to_native(const se::Value &from, std::vector *to, se::Object *) { +inline bool sevalue_to_native(const se::Value &from, std::vector *to, se::Object * /*ctx*/) { assert(from.isObject()); se::Object *in = from.toObject(); + if (in->isTypedArray()) { uint8_t *data = nullptr; size_t dataLen = 0; @@ -1055,14 +1086,18 @@ inline bool sevalue_to_native(const se::Value &from, std::vector to->resize(dataLen); to->assign(data, data + dataLen); return true; - } else if (in->isArrayBuffer()) { + } + + if (in->isArrayBuffer()) { uint8_t *data = nullptr; size_t dataLen = 0; in->getArrayBufferData(&data, &dataLen); to->resize(dataLen); to->assign(data, data + dataLen); return true; - } else if (in->isArray()) { + } + + if (in->isArray()) { uint32_t len = 0; in->getArrayLength(&len); to->resize(len); @@ -1073,12 +1108,13 @@ inline bool sevalue_to_native(const se::Value &from, std::vector } return true; } + SE_LOGE("type error, ArrayBuffer/TypedArray/Array expected!"); return false; } template -inline bool sevalue_to_native(const se::Value &from, std::function *func, se::Object *self) { +inline bool sevalue_to_native(const se::Value &from, std::function *func, se::Object *self) { // NOLINT(readability-identifier-naming) if (from.isObject() && from.toObject()->isFunction()) { se::Object *callback = from.toObject(); self->attachObject(callback); @@ -1095,9 +1131,9 @@ inline bool sevalue_to_native(const se::Value &from, std::function * se::ScriptEngine::getInstance()->clearException(); } if CC_CONSTEXPR (!std::is_same::value) { - R raw_ret = {}; - sevalue_to_native(rval, &raw_ret, self); - return raw_ret; + R rawRet = {}; + sevalue_to_native(rval, &rawRet, self); + return rawRet; } }; } else { @@ -1108,24 +1144,24 @@ inline bool sevalue_to_native(const se::Value &from, std::function * #if HAS_CONSTEXPR template -inline bool sevalue_to_native(const se::Value &from, HolderType *holder, se::Object *ctx) { +inline bool sevalue_to_native(const se::Value &from, HolderType *holder, se::Object *ctx) { // NOLINT(readability-identifier-naming) if CC_CONSTEXPR (is_reference && is_jsb_object_v) { void *ptr = from.toObject()->getPrivateData(); if (ptr) { holder->data = static_cast(ptr); return true; - } else { - holder->ptr = new T; - return sevalue_to_native(from, holder->ptr, ctx); } + holder->ptr = new T; + return sevalue_to_native(from, holder->ptr, ctx); + } else if CC_CONSTEXPR (is_jsb_object_v) { void *ptr = from.toObject()->getPrivateData(); if (ptr) { holder->data = *static_cast(ptr); return true; - } else { - return sevalue_to_native(from, &(holder->data), ctx); } + return sevalue_to_native(from, &(holder->data), ctx); + } else { return sevalue_to_native(from, &(holder->data), ctx); } @@ -1169,12 +1205,12 @@ inline typename std::enable_if, bool>::type sevalue_to_nativ #if HAS_CONSTEXPR template -inline bool sevalue_to_native(const se::Value &from, HolderType, true> *holder, se::Object *ctx) { +inline bool sevalue_to_native(const se::Value &from, HolderType, true> *holder, se::Object *ctx) { // NOLINT(readability-identifier-naming) if CC_CONSTEXPR (is_jsb_object_v && std::is_pointer::value) { auto &vec = holder->data; return sevalue_to_native(from, &vec, ctx); } else if CC_CONSTEXPR (is_jsb_object_v) { - return sevalue_to_native(from, (std::vector *)/* clang/xcode needs this */ &(holder->data), ctx); + return sevalue_to_native(from, static_cast *>(&(holder->data)), ctx); } else { return sevalue_to_native(from, &(holder->data), ctx); } @@ -1206,7 +1242,7 @@ sevalue_to_native(const se::Value &from, HolderType, t #if HAS_CONSTEXPR template -inline bool nativevalue_to_se(const T &from, se::Value &to, se::Object *ctx) { +inline bool nativevalue_to_se(const T &from, se::Value &to, se::Object *ctx) { // NOLINT(readability-identifier-naming) if CC_CONSTEXPR (std::is_enum::value) { to.setInt32(static_cast(from)); return true; @@ -1214,16 +1250,12 @@ inline bool nativevalue_to_se(const T &from, se::Value &to, se::Object *ctx) { return native_ptr_to_seval(from, &to); } else if CC_CONSTEXPR (is_jsb_object_v) { return native_ptr_to_seval(from, &to); - } else if CC_CONSTEXPR (std::is_same::value) { - to.setNumber((double)static_cast>(from)); - return true; - } else if CC_CONSTEXPR (std::is_same::value) { - to.setNumber((double)static_cast>(from)); + } else if CC_CONSTEXPR (std::is_arithmetic::value) { + to.setNumber(static_cast(from)); return true; } else { return nativevalue_to_se::value, T, typename std::add_const::type>>(from, to, ctx); } - return false; } #else @@ -1256,12 +1288,12 @@ nativevalue_to_se(const T &from, se::Value &to, se::Object *ctx) { #endif // HAS_CONSTEXPR template -inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object *ctx) { +inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object *ctx) { // NOLINT(readability-identifier-naming) se::Object *array = se::Object::createArrayObject(from.size()); se::Value tmp; for (size_t i = 0; i < from.size(); i++) { nativevalue_to_se(from[i], tmp, ctx); - array->setArrayElement((uint32_t)i, tmp); + array->setArrayElement(static_cast(i), tmp); } to.setObject(array); array->decRef(); @@ -1269,28 +1301,28 @@ inline bool nativevalue_to_se(const std::vector &from, se::Value & } template <> -inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object *) { - se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::INT8, (void *)from.data(), from.size()); +inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object * /*ctx*/) { + se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::INT8, from.data(), from.size()); to.setObject(array); array->decRef(); return true; } template <> -inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object *) { - se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::UINT8, (void *)from.data(), from.size()); +inline bool nativevalue_to_se(const std::vector &from, se::Value &to, se::Object * /*ctx*/) { + se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::UINT8, from.data(), from.size()); to.setObject(array); array->decRef(); return true; } template -inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object *ctx) { +inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object *ctx) { // NOLINT(readability-identifier-naming) se::Object *array = se::Object::createArrayObject(N); se::Value tmp; for (size_t i = 0; i < N; i++) { nativevalue_to_se(from[i], tmp, ctx); - array->setArrayElement((uint32_t)i, tmp); + array->setArrayElement(static_cast(i), tmp); } to.setObject(array); array->decRef(); @@ -1298,7 +1330,7 @@ inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::O } template -inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::UINT8, from.data(), N); to.setObject(array); array->decRef(); @@ -1306,7 +1338,7 @@ inline bool nativevalue_to_se(const std::array &from, se::Value &to, } template -inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::INT16, from.data(), N * sizeof(uint16_t)); to.setObject(array); array->decRef(); @@ -1314,7 +1346,7 @@ inline bool nativevalue_to_se(const std::array &from, se::Value &to } template -inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const std::array &from, se::Value &to, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) se::Object *array = se::Object::createTypedArray(se::Object::TypedArrayType::FLOAT32, from.data(), N * sizeof(float)); to.setObject(array); array->decRef(); @@ -1322,53 +1354,54 @@ inline bool nativevalue_to_se(const std::array &from, se::Value &to, s } template <> -inline bool nativevalue_to_se(const int64_t &from, se::Value &to, se::Object *) { - to.setLong((long)from); +inline bool nativevalue_to_se(const int64_t &from, se::Value &to, se::Object * /*ctx*/) { + to.setLong(static_cast(from)); return true; } template <> -inline bool nativevalue_to_se(const uint64_t &from, se::Value &to, se::Object *) { - to.setUlong((unsigned long)from); +inline bool nativevalue_to_se(const uint64_t &from, se::Value &to, se::Object * /*ctx*/) { + to.setUlong(static_cast(from)); return true; } + template <> -inline bool nativevalue_to_se(const int32_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const int32_t &from, se::Value &to, se::Object * /*ctx*/) { to.setInt32(from); return true; } template <> -inline bool nativevalue_to_se(const uint32_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const uint32_t &from, se::Value &to, se::Object * /*ctx*/) { to.setUint32(from); return true; } template <> -inline bool nativevalue_to_se(const int16_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const int16_t &from, se::Value &to, se::Object * /*ctx*/) { to.setInt16(from); return true; } template <> -inline bool nativevalue_to_se(const uint16_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const uint16_t &from, se::Value &to, se::Object * /*ctx*/) { to.setUint16(from); return true; } template <> -inline bool nativevalue_to_se(const int8_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const int8_t &from, se::Value &to, se::Object * /*ctx*/) { to.setInt8(from); return true; } template <> -inline bool nativevalue_to_se(const uint8_t &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const uint8_t &from, se::Value &to, se::Object * /*ctx*/) { to.setUint8(from); return true; } #if CC_PLATFORM == CC_PLATFORM_WINDOWS template <> -inline bool nativevalue_to_se(const long &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const long &from, se::Value &to, se::Object *ctx) { if (sizeof(long) == 4) { to.setInt32(from); } else { @@ -1379,51 +1412,51 @@ inline bool nativevalue_to_se(const long &from, se::Value &to, se::Object *) { #endif template <> -inline bool nativevalue_to_se(const std::string &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const std::string &from, se::Value &to, se::Object * /*ctx*/) { to.setString(from); return true; } template <> -inline bool nativevalue_to_se(const float &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const float &from, se::Value &to, se::Object * /*ctx*/) { to.setFloat(from); return true; } template <> -inline bool nativevalue_to_se(const double &from, se::Value &to, se::Object *) { - to.setFloat((float)from); +inline bool nativevalue_to_se(const double &from, se::Value &to, se::Object * /*ctx*/) { + to.setFloat(static_cast(from)); return true; } template <> -inline bool nativevalue_to_se(const bool &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const bool &from, se::Value &to, se::Object * /*ctx*/) { to.setBoolean(from); return true; } template -inline bool nativevalue_to_se(std::function &from, se::Value &to, se::Object *) { - SE_LOGE("Can not convert C++ lambda to JS object"); // TODO +inline bool nativevalue_to_se(std::function & /*from*/, se::Value & /*to*/, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) + SE_LOGE("Can not convert C++ lambda to JS object"); // TODO(jiangzhan) return false; } template -inline bool nativevalue_to_se(const std::function &from, se::Value &to, se::Object *) { - SE_LOGE("Can not convert C++ const lambda to JS object"); // TODO +inline bool nativevalue_to_se(const std::function & /*from*/, se::Value & /*to*/, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) + SE_LOGE("Can not convert C++ const lambda to JS object"); // TODO(jiangzhan) return false; } ///////////////////////// function /////////////////////// template -bool nativevalue_to_se_args(se::ValueArray &array, T &x) { - return nativevalue_to_se(x, array[i], (se::Object *)nullptr); +bool nativevalue_to_se_args(se::ValueArray &array, T &x) { // NOLINT(readability-identifier-naming) + return nativevalue_to_se(x, array[i], nullptr); } template -bool nativevalue_to_se_args(se::ValueArray &array, T &x, Args &...args) { +bool nativevalue_to_se_args(se::ValueArray &array, T &x, Args &...args) { // NOLINT(readability-identifier-naming) return nativevalue_to_se_args(array, x) && nativevalue_to_se_args(array, args...); } template -bool nativevalue_to_se_args_v(se::ValueArray &array, Args &...args) { +bool nativevalue_to_se_args_v(se::ValueArray &array, Args &...args) { // NOLINT(readability-identifier-naming) return nativevalue_to_se_args<0, Args...>(array, args...); } @@ -1441,35 +1474,35 @@ class Size; // JSB_REGISTER_OBJECT_TYPE(cc::network::DownloaderHints); template <> -bool nativevalue_to_se(const cc::Data &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Data &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Value &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Value &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const std::unordered_map &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const std::unordered_map &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Vec2 &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Vec2 &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Vec3 &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Vec3 &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Vec4 &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Vec4 &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Size &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Size &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::extension::ManifestAsset &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::extension::ManifestAsset &from, se::Value &to, se::Object *ctx); template <> -bool nativevalue_to_se(const cc::Rect &from, se::Value &to, se::Object *); +bool nativevalue_to_se(const cc::Rect &from, se::Value &to, se::Object *ctx); template <> -inline bool nativevalue_to_se(const cc::network::DownloadTask &v, se::Value &ret, se::Object *) { - return DownloadTask_to_seval(v, &ret); +inline bool nativevalue_to_se(const cc::network::DownloadTask &from, se::Value &to, se::Object * /*ctx*/) { + return DownloadTask_to_seval(from, &to); } #if __clang__ @@ -1480,12 +1513,14 @@ inline bool nativevalue_to_se(const cc::network::DownloadTask &v, se::Value &ret #if USE_SPINE template -bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object *) { +bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) se::HandleObject obj(se::Object::createArrayObject(v.size())); bool ok = true; spine::Vector tmpv = v; - for (uint32_t i = 0, count = (uint32_t)tmpv.size(); i < count; i++) { + + auto size = static_cast(tmpv.size()); + for (uint32_t i = 0; i < size; ++i) { se::Value tmp; ok = nativevalue_to_se(tmpv[i], tmp, nullptr); if (!ok || !obj->setArrayElement(i, tmp)) { @@ -1495,19 +1530,22 @@ bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object *) } } - if (ok) + if (ok) { ret.setObject(obj); + } return ok; } template -bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object *) { +bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) se::HandleObject obj(se::Object::createArrayObject(v.size())); bool ok = true; spine::Vector tmpv = v; - for (uint32_t i = 0, count = (uint32_t)tmpv.size(); i < count; i++) { + + auto size = static_cast(tmpv.size()); + for (uint32_t i = 0; i < size; ++i) { se::Value tmp; ok = native_ptr_to_rooted_seval(tmpv[i], &tmp); if (!ok || !obj->setArrayElement(i, tmp)) { @@ -1522,7 +1560,7 @@ bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object * } template -bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object *) { +bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object * /*ctx*/) { // NOLINT(readability-identifier-naming) assert(ret != nullptr); assert(v.isObject()); se::Object *obj = v.toObject(); @@ -1544,7 +1582,7 @@ bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object * return false; } - T *nativeObj = (T *)tmp.toObject()->getPrivateData(); + T *nativeObj = static_cast(tmp.toObject()->getPrivateData()); ret->add(nativeObj); } @@ -1552,13 +1590,13 @@ bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object * } template <> -bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object *); +bool nativevalue_to_se(const spine::Vector &v, se::Value &ret, se::Object *ctx); template <> -bool nativevalue_to_se(const spine::String &obj, se::Value &val, se::Object *); +bool nativevalue_to_se(const spine::String &from, se::Value &to, se::Object *ctx); template <> -bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object *); +bool sevalue_to_native(const se::Value &v, spine::Vector *ret, se::Object *ctx); template <> bool seval_to_Map_string_key(const se::Value &v, cc::Map *ret); @@ -1566,7 +1604,7 @@ bool seval_to_Map_string_key(const se::Value &v, cc::Map -inline bool nativevalue_to_se(const se_object_ptr &from, se::Value &to, se::Object *) { +inline bool nativevalue_to_se(const se_object_ptr &from, se::Value &to, se::Object * /*ctx*/) { to.setObject(const_cast(from)); return true; } diff --git a/native/cocos/bindings/manual/jsb_module_register.cpp b/native/cocos/bindings/manual/jsb_module_register.cpp index 4678c4034b..a143e37360 100644 --- a/native/cocos/bindings/manual/jsb_module_register.cpp +++ b/native/cocos/bindings/manual/jsb_module_register.cpp @@ -96,20 +96,14 @@ #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(); + cc::PoolManager::getInstance()->getCurrentPool()->clear(); se->garbageCollect(); - PoolManager::getInstance()->getCurrentPool()->clear(); + cc::PoolManager::getInstance()->getCurrentPool()->clear(); }); se->addRegisterCallback(jsb_register_global_variables); @@ -180,8 +174,8 @@ bool jsb_register_all_modules() { se->addRegisterCallback(register_all_websocket_server); #endif se->addAfterCleanupHook([]() { - PoolManager::getInstance()->getCurrentPool()->clear(); - JSBClassType::destroy(); + cc::PoolManager::getInstance()->getCurrentPool()->clear(); + JSBClassType::cleanup(); }); return true; } diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index e592925ee0..6227a5eed1 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -55,6 +55,10 @@ namespace cc { namespace gfx { class CC_DLL DeviceManager final { + static constexpr bool DETACH_DEVICE_THREAD{true}; + static constexpr bool FORCE_DISABLE_VALIDATION{false}; + static constexpr bool FORCE_ENABLE_VALIDATION{false}; + public: static Device *create(const DeviceInfo &info) { if (Device::instance) return Device::instance; @@ -91,11 +95,12 @@ private: static bool tryCreate(const DeviceInfo &info, Device **pDevice) { Device *device = CC_NEW(DeviceCtor); - device = CC_NEW(gfx::DeviceAgent(device)); + if (DETACH_DEVICE_THREAD) { + device = CC_NEW(gfx::DeviceAgent(device)); + } if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) { device = CC_NEW(gfx::DeviceValidator(device)); - //((gfx::DeviceValidator *)device)->enableRecording(true); } if (!device->initialize(info)) { @@ -119,9 +124,6 @@ private: #ifndef CC_DEBUG static constexpr int CC_DEBUG{0}; #endif - - static constexpr bool FORCE_DISABLE_VALIDATION{false}; - static constexpr bool FORCE_ENABLE_VALIDATION{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/BufferAgent.cpp b/native/cocos/renderer/gfx-agent/BufferAgent.cpp index ee0992c458..f720e3c60c 100644 --- a/native/cocos/renderer/gfx-agent/BufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/BufferAgent.cpp @@ -24,11 +24,11 @@ ****************************************************************************/ #include "base/CoreStd.h" +#include "base/LinearAllocatorPool.h" #include "base/threading/MessageQueue.h" #include "BufferAgent.h" #include "DeviceAgent.h" -#include "LinearAllocatorPool.h" namespace cc { namespace gfx { diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp index 96426e939c..e63412afc0 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "base/CoreStd.h" +#include "base/LinearAllocatorPool.h" #include "base/job-system/JobSystem.h" #include "base/threading/MessageQueue.h" @@ -33,7 +34,6 @@ #include "DeviceAgent.h" #include "FramebufferAgent.h" #include "InputAssemblerAgent.h" -#include "LinearAllocatorPool.h" #include "PipelineStateAgent.h" #include "QueueAgent.h" #include "RenderPassAgent.h" diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h index a4c5009d9f..a3036c9ba5 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h @@ -31,11 +31,10 @@ namespace cc { class MessageQueue; +class LinearAllocatorPool; namespace gfx { -class LinearAllocatorPool; - class CC_DLL CommandBufferAgent final : public Agent { public: explicit CommandBufferAgent(CommandBuffer *actor); diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 944941ca60..9e116198ca 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "base/CoreStd.h" +#include "base/LinearAllocatorPool.h" #include "base/threading/MessageQueue.h" #include "BufferAgent.h" @@ -33,7 +34,6 @@ #include "DeviceAgent.h" #include "FramebufferAgent.h" #include "InputAssemblerAgent.h" -#include "LinearAllocatorPool.h" #include "PipelineLayoutAgent.h" #include "PipelineStateAgent.h" #include "QueueAgent.h" diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.h b/native/cocos/renderer/gfx-agent/DeviceAgent.h index 543e0e7f33..d6dff21527 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.h +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.h @@ -32,10 +32,10 @@ namespace cc { class MessageQueue; +class LinearAllocatorPool; namespace gfx { -class LinearAllocatorPool; class CommandBuffer; class CommandBufferAgent; constexpr uint MAX_CPU_FRAME_AHEAD = 1U; @@ -85,7 +85,6 @@ public: void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; void flushCommands(CommandBuffer *const *cmdBuffs, uint count) override; - void setMultithreaded(bool multithreaded) override; SurfaceTransform getSurfaceTransform() const override { return _actor->getSurfaceTransform(); } uint getWidth() const override { return _actor->getWidth(); } uint getHeight() const override { return _actor->getHeight(); } @@ -96,8 +95,10 @@ public: uint getNumInstances() const override { return _actor->getNumInstances(); } uint getNumTris() const override { return _actor->getNumTris(); } - MessageQueue * getMessageQueue() const { return _mainMessageQueue; } - LinearAllocatorPool *getMainAllocator() const { return _allocatorPools[_currentIndex]; } + void setMultithreaded(bool multithreaded); + + inline MessageQueue * getMessageQueue() const { return _mainMessageQueue; } + inline LinearAllocatorPool *getMainAllocator() const { return _allocatorPools[_currentIndex]; } protected: static DeviceAgent *instance; diff --git a/native/cocos/renderer/gfx-agent/QueueAgent.cpp b/native/cocos/renderer/gfx-agent/QueueAgent.cpp index 5d7c668393..8920ea5129 100644 --- a/native/cocos/renderer/gfx-agent/QueueAgent.cpp +++ b/native/cocos/renderer/gfx-agent/QueueAgent.cpp @@ -24,12 +24,12 @@ ****************************************************************************/ #include "base/CoreStd.h" +#include "base/LinearAllocatorPool.h" #include "base/job-system/JobSystem.h" #include "base/threading/MessageQueue.h" #include "CommandBufferAgent.h" #include "DeviceAgent.h" -#include "LinearAllocatorPool.h" #include "QueueAgent.h" namespace cc { diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index 75cfd3455e..58e9218b9a 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -654,10 +654,11 @@ CC_ENUM_OPERATORS(DynamicStateFlagBit); using DynamicStateList = vector; enum class StencilFace { - FRONT, - BACK, - ALL, + FRONT = 0x1, + BACK = 0x2, + ALL = 0x3, }; +CC_ENUM_OPERATORS(StencilFace); enum class DescriptorType : FlagBits { UNKNOWN = 0, @@ -872,7 +873,7 @@ struct DrawInfo { uint firstVertex = 0U; uint indexCount = 0U; uint firstIndex = 0U; - uint vertexOffset = 0U; + int vertexOffset = 0; uint instanceCount = 0U; uint firstInstance = 0U; }; @@ -1245,5 +1246,26 @@ struct MemoryStatus { uint textureSize = 0; }; +struct DynamicStencilStates { + uint writeMask = 0U; + uint compareMask = 0U; + uint reference = 0U; +}; + +struct DynamicStates { + Viewport viewport; + Rect scissor; + Color blendConstant; + float lineWidth = 1.F; + float depthBiasConstant = 0.F; + float depthBiasClamp = 0.F; + float depthBiasSlope = 0.F; + float depthMinBounds = 0.F; + float depthMaxBounds = 0.F; + + DynamicStencilStates stencilStatesFront; + DynamicStencilStates stencilStatesBack; +}; + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXDef.h b/native/cocos/renderer/gfx-base/GFXDef.h index c1bccbf1e0..707d2a4efc 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.h +++ b/native/cocos/renderer/gfx-base/GFXDef.h @@ -78,26 +78,6 @@ struct ContextInfo { Context* sharedCtx = nullptr; }; -struct DynamicStencilStates { - uint writeMask = 0U; - uint compareMask = 0U; - uint reference = 0U; -}; - -struct DynamicStates { - Viewport viewport; - Rect scissor; - Color blendConstant; - float lineWidth = 1.F; - float depthBiasConstant = 0.F; - float depthBiasClamp = 0.F; - float depthBiasSlope = 0.F; - float depthMinBounds = 0.F; - float depthMaxBounds = 0.F; - - DynamicStencilStates stencilStates[2]; -}; - constexpr TextureUsage TEXTURE_USAGE_TRANSIENT = static_cast( static_cast(TextureUsageBit::COLOR_ATTACHMENT) | static_cast(TextureUsageBit::DEPTH_STENCIL_ATTACHMENT) | diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index 013fdf6254..de877107af 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -59,7 +59,6 @@ public: virtual void present() = 0; virtual void flushCommands(CommandBuffer *const *cmdBuffs, uint count) {} - virtual void setMultithreaded(bool multithreaded) {} virtual SurfaceTransform getSurfaceTransform() const { return _transform; } virtual uint getWidth() const { return _width; } @@ -89,6 +88,8 @@ public: inline GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info); inline TextureBarrier * createTextureBarrier(const TextureBarrierInfo &info); + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0; + inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions); inline void flushCommands(const vector &cmdBuffs); inline void flushCommandsForJS(const vector &cmdBuffs); @@ -119,22 +120,21 @@ protected: virtual bool doInit(const DeviceInfo &info) = 0; virtual void doDestroy() = 0; - virtual CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) = 0; - virtual Queue * createQueue() = 0; - virtual Buffer * createBuffer() = 0; - virtual Texture * createTexture() = 0; - virtual Sampler * createSampler() = 0; - virtual Shader * createShader() = 0; - virtual InputAssembler * createInputAssembler() = 0; - virtual RenderPass * createRenderPass() = 0; - virtual Framebuffer * createFramebuffer() = 0; - virtual DescriptorSet * createDescriptorSet() = 0; - virtual DescriptorSetLayout *createDescriptorSetLayout() = 0; - virtual PipelineLayout * createPipelineLayout() = 0; - virtual PipelineState * createPipelineState() = 0; - virtual GlobalBarrier * createGlobalBarrier() = 0; - virtual TextureBarrier * createTextureBarrier() = 0; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0; + virtual CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) = 0; + virtual Queue * createQueue() = 0; + virtual Buffer * createBuffer() = 0; + virtual Texture * createTexture() = 0; + virtual Sampler * createSampler() = 0; + virtual Shader * createShader() = 0; + virtual InputAssembler * createInputAssembler() = 0; + virtual RenderPass * createRenderPass() = 0; + virtual Framebuffer * createFramebuffer() = 0; + virtual DescriptorSet * createDescriptorSet() = 0; + virtual DescriptorSetLayout *createDescriptorSetLayout() = 0; + virtual PipelineLayout * createPipelineLayout() = 0; + virtual PipelineState * createPipelineState() = 0; + virtual GlobalBarrier * createGlobalBarrier() = 0; + virtual TextureBarrier * createTextureBarrier() = 0; // On minimize virtual void releaseSurface(uintptr_t windowHandle) {} diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp index 58715b8d60..f315bcfc83 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -34,6 +34,7 @@ #include "GLES2PipelineState.h" #include "GLES2RenderPass.h" #include "GLES2Texture.h" +#include "gfx-base/GFXDef-common.h" namespace cc { namespace gfx { @@ -225,21 +226,27 @@ void GLES2CommandBuffer::setDepthBound(float minBounds, float maxBounds) { } void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { - auto &stencilState = _curDynamicStates.stencilStates[static_cast(face)]; - if (stencilState.writeMask != mask) { - stencilState.writeMask = mask; - _isStateInvalid = true; - } + auto update = [&](DynamicStencilStates &stencilState) { + if (stencilState.writeMask != mask) { + stencilState.writeMask = mask; + _isStateInvalid = true; + } + }; + if (hasFlag(face, StencilFace::FRONT)) update(_curDynamicStates.stencilStatesFront); + if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, uint ref, uint mask) { - auto &stencilState = _curDynamicStates.stencilStates[static_cast(face)]; - if ((stencilState.reference != ref) || - (stencilState.compareMask != mask)) { - stencilState.reference = ref; - stencilState.compareMask = mask; - _isStateInvalid = true; - } + auto update = [&](DynamicStencilStates &stencilState) { + if ((stencilState.reference != ref) || + (stencilState.compareMask != mask)) { + stencilState.reference = ref; + stencilState.compareMask = mask; + _isStateInvalid = true; + } + }; + if (hasFlag(face, StencilFace::FRONT)) update(_curDynamicStates.stencilStatesFront); + if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } void GLES2CommandBuffer::draw(const DrawInfo &info) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp index cd2ee6fa9a..93629debfd 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp @@ -1147,10 +1147,12 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { if (texUnitCacheMap.count(glSamplerTexture.name)) { uint cachedUnit = texUnitCacheMap[glSamplerTexture.name]; glSamplerTexture.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U, offset = 0U; t < glSamplerTexture.count; t++) { - while (usedTexUnits[cachedUnit + t + offset]) offset++; - glSamplerTexture.units.push_back(cachedUnit + t + offset); - usedTexUnits[cachedUnit + t + offset] = true; + for (uint t = 0U; t < glSamplerTexture.count; t++) { + while (usedTexUnits[cachedUnit]) { // the shader already compiles so we should be safe to do this here + cachedUnit = (cachedUnit + 1) % device->getCapabilities().maxTextureUnits; + } + glSamplerTexture.units.push_back(static_cast(cachedUnit)); + usedTexUnits[cachedUnit] = true; } } } @@ -1162,12 +1164,14 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { if (glSamplerTexture.glLoc < 0) { glSamplerTexture.glLoc = glActiveSamplerLocations[i]; for (uint t = 0U; t < glSamplerTexture.count; t++) { - while (usedTexUnits[unitIdx + t]) unitIdx++; - glSamplerTexture.units.push_back(unitIdx + t); - usedTexUnits[unitIdx + t] = true; - } - if (!texUnitCacheMap.count(glSamplerTexture.name)) { - texUnitCacheMap[glSamplerTexture.name] = unitIdx; + while (usedTexUnits[unitIdx]) { + unitIdx = (unitIdx + 1) % device->getCapabilities().maxTextureUnits; + } + if (!texUnitCacheMap.count(glSamplerTexture.name)) { + texUnitCacheMap[glSamplerTexture.name] = unitIdx; + } + glSamplerTexture.units.push_back(static_cast(unitIdx)); + usedTexUnits[unitIdx] = true; } } } @@ -1378,7 +1382,7 @@ void cmdFuncGLES2DestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gp } void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, - const Rect *renderArea, const Color *clearColors, float clearDepth, int clearStencil) { + const Rect *renderArea, const Color *clearColors, float clearDepth, uint clearStencil) { static uint attachmentLoadOpRecord = 0U; GLES2GPUStateCache *cache = device->stateCache(); @@ -2076,7 +2080,7 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli (isShaderChanged || gpuInputAssembler != gfxStateCache.gpuInputAssembler)) { gfxStateCache.gpuInputAssembler = gpuInputAssembler; if (device->extensionRegistry()->useVAO) { - GLuint hash = gpuPipelineState->gpuShader->glProgram ^ device->getThreadID(); + size_t hash = gpuPipelineState->gpuShader->glProgram ^ device->getThreadID(); GLuint glVAO = gpuInputAssembler->glVAOs[hash]; if (!glVAO) { GL_CHECK(glGenVertexArraysOES(1, &glVAO)); @@ -2092,8 +2096,8 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + GLuint glLoc = gpuInput.glLoc + c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; @@ -2143,8 +2147,8 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + GLuint glLoc = gpuInput.glLoc + c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; cache->glCurrentAttribLocs[glLoc] = true; @@ -2224,8 +2228,8 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } break; case DynamicStateFlagBit::STENCIL_WRITE_MASK: { - const auto &front = dynamicStates->stencilStates[static_cast(StencilFace::FRONT)]; - const auto &back = dynamicStates->stencilStates[static_cast(StencilFace::BACK)]; + const auto &front = dynamicStates->stencilStatesFront; + const auto &back = dynamicStates->stencilStatesBack; if (cache->dss.stencilWriteMaskFront != front.writeMask) { GL_CHECK(glStencilMaskSeparate(GL_FRONT, front.writeMask)); cache->dss.stencilWriteMaskFront = front.writeMask; @@ -2236,8 +2240,8 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } } break; case DynamicStateFlagBit::STENCIL_COMPARE_MASK: { - const auto &front = dynamicStates->stencilStates[static_cast(StencilFace::FRONT)]; - const auto &back = dynamicStates->stencilStates[static_cast(StencilFace::BACK)]; + const auto &front = dynamicStates->stencilStatesFront; + const auto &back = dynamicStates->stencilStatesBack; if ((cache->dss.stencilRefFront != front.reference) || (cache->dss.stencilReadMaskFront != front.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, @@ -2718,10 +2722,10 @@ void GLES2GPUBlitManager::draw(GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture * for (uint i = 0U; i < count; ++i) { const auto ®ion = regions[i]; - uint srcWidth = gpuTextureSrc ? gpuTextureSrc->width : device->getWidth(); - uint srcHeight = gpuTextureSrc ? gpuTextureSrc->height : device->getHeight(); - uint dstWidth = gpuTextureDst ? gpuTextureDst->width : device->getWidth(); - uint dstHeight = gpuTextureDst ? gpuTextureDst->height : device->getHeight(); + auto srcWidth = static_cast(gpuTextureSrc ? gpuTextureSrc->width : device->getWidth()); + auto srcHeight = static_cast(gpuTextureSrc ? gpuTextureSrc->height : device->getHeight()); + auto dstWidth = static_cast(gpuTextureDst ? gpuTextureDst->width : device->getWidth()); + auto dstHeight = static_cast(gpuTextureDst ? gpuTextureDst->height : device->getHeight()); _uniformBuffer[0] = static_cast(region.srcExtent.width) / srcWidth; _uniformBuffer[1] = static_cast(region.srcExtent.height) / srcHeight; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.h b/native/cocos/renderer/gfx-gles2/GLES2Commands.h index 815d89fc39..8b4381d39b 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -42,7 +42,7 @@ public: Rect renderArea; Color clearColors[MAX_ATTACHMENTS]; float clearDepth = 1.0F; - int clearStencil = 0; + uint clearStencil = 0; uint subpassIdx = 0U; GLES2CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} @@ -215,7 +215,7 @@ CC_GLES2_API void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassI const Rect * renderArea = nullptr, const Color * clearColors = nullptr, float clearDepth = 1.F, - int clearStencil = 0); + uint clearStencil = 0); CC_GLES2_API void cmdFuncGLES2EndRenderPass(GLES2Device *device); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 5941ed30d3..1bef468685 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -288,7 +288,7 @@ void GLES2Device::bindRenderContext(bool bound) { _context = bound ? _renderContext : nullptr; if (bound) { - _threadID = std::hash()(std::this_thread::get_id()); + _threadID = std::hash{}(std::this_thread::get_id()); _gpuStateCache->reset(); } } @@ -306,7 +306,7 @@ void GLES2Device::bindDeviceContext(bool bound) { _context = bound ? _deviceContext : nullptr; if (bound) { - _threadID = std::hash()(std::this_thread::get_id()); + _threadID = std::hash{}(std::this_thread::get_id()); _gpuStateCache->reset(); } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index c1fd93879b..63c1fd5b6b 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -86,7 +86,7 @@ public: }); } - inline uint getThreadID() const { return _threadID; } + inline size_t getThreadID() const { return _threadID; } protected: static GLES2Device *instance; @@ -133,7 +133,7 @@ protected: StringArray _extensions; - uint _threadID = 0U; + size_t _threadID = 0U; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index a40bf9fb58..545324f862 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -185,9 +185,9 @@ struct GLES2GPUUniformSamplerTexture final { Type type = Type::UNKNOWN; uint count = 0U; - vector units; - GLenum glType = 0; - GLint glLoc = -1; + vector units; + GLenum glType = 0; + GLint glLoc = -1; }; using GLES2GPUUniformSamplerTextureList = vector; @@ -227,13 +227,13 @@ using GLES2GPUAttributeList = vector; class GLES2GPUInputAssembler final : public Object { public: - AttributeList attributes; - GLES2GPUBufferList gpuVertexBuffers; - GLES2GPUBuffer * gpuIndexBuffer = nullptr; - GLES2GPUBuffer * gpuIndirectBuffer = nullptr; - GLES2GPUAttributeList glAttribs; - GLenum glIndexType = 0; - map glVAOs; + AttributeList attributes; + GLES2GPUBufferList gpuVertexBuffers; + GLES2GPUBuffer * gpuIndexBuffer = nullptr; + GLES2GPUBuffer * gpuIndirectBuffer = nullptr; + GLES2GPUAttributeList glAttribs; + GLenum glIndexType = 0; + unordered_map glVAOs; }; class GLES2GPURenderPass final : public Object { @@ -327,7 +327,7 @@ struct GLES2ObjectCache final { Rect renderArea; ColorList clearColors; float clearDepth = 1.F; - int clearStencil = 0; + uint clearStencil = 0U; }; class GLES2GPUStateCache final : public Object { diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index eb4c8c2f63..b966be5f2a 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -224,21 +224,27 @@ void GLES3CommandBuffer::setDepthBound(float minBounds, float maxBounds) { } void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { - auto &stencilState = _curDynamicStates.stencilStates[static_cast(face)]; - if (stencilState.writeMask != mask) { - stencilState.writeMask = mask; - _isStateInvalid = true; - } + auto update = [&](DynamicStencilStates &stencilState) { + if (stencilState.writeMask != mask) { + stencilState.writeMask = mask; + _isStateInvalid = true; + } + }; + if (hasFlag(face, StencilFace::FRONT)) update(_curDynamicStates.stencilStatesFront); + if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, uint ref, uint mask) { - auto &stencilState = _curDynamicStates.stencilStates[static_cast(face)]; - if ((stencilState.reference != ref) || - (stencilState.compareMask != mask)) { - stencilState.reference = ref; - stencilState.compareMask = mask; - _isStateInvalid = true; - } + auto update = [&](DynamicStencilStates &stencilState) { + if ((stencilState.reference != ref) || + (stencilState.compareMask != mask)) { + stencilState.reference = ref; + stencilState.compareMask = mask; + _isStateInvalid = true; + } + }; + if (hasFlag(face, StencilFace::FRONT)) update(_curDynamicStates.stencilStatesFront); + if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } void GLES3CommandBuffer::draw(const DrawInfo &info) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index bb39eca3ef..8581b575ad 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -1517,16 +1517,16 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { vector usedTexUnits(device->getCapabilities().maxTextureUnits, false); // try to reuse existing mappings first for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { - GLES3GPUUniformSamplerTexture &glSampler = glActiveSamplerTextures[i]; + GLES3GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; - if (texUnitCacheMap.count(glSampler.name) != 0U) { - uint cachedUnit = texUnitCacheMap[glSampler.name]; - glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSampler.count; t++) { + if (texUnitCacheMap.count(glSamplerTexture.name)) { + uint cachedUnit = texUnitCacheMap[glSamplerTexture.name]; + glSamplerTexture.glLoc = glActiveSamplerLocations[i]; + for (uint t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[cachedUnit]) { // the shader already compiles so we should be safe to do this here cachedUnit = (cachedUnit + 1) % device->getCapabilities().maxTextureUnits; } - glSampler.units.push_back(cachedUnit); + glSamplerTexture.units.push_back(static_cast(cachedUnit)); usedTexUnits[cachedUnit] = true; } } @@ -1534,18 +1534,18 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { // fill in the rest sequencially uint unitIdx = 0U; for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { - GLES3GPUUniformSamplerTexture &glSampler = glActiveSamplerTextures[i]; + GLES3GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; - if (glSampler.glLoc < 0) { - glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSampler.count; t++) { + if (glSamplerTexture.glLoc < 0) { + glSamplerTexture.glLoc = glActiveSamplerLocations[i]; + for (uint t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[unitIdx]) { unitIdx = (unitIdx + 1) % device->getCapabilities().maxTextureUnits; } - if (texUnitCacheMap.count(glSampler.name) == 0U) { - texUnitCacheMap[glSampler.name] = unitIdx; + if (!texUnitCacheMap.count(glSamplerTexture.name)) { + texUnitCacheMap[glSamplerTexture.name] = unitIdx; } - glSampler.units.push_back(unitIdx); + glSamplerTexture.units.push_back(static_cast(unitIdx)); usedTexUnits[unitIdx] = true; } } @@ -1556,7 +1556,7 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } for (GLES3GPUUniformSamplerTexture &gpuSamplerTexture : glActiveSamplerTextures) { - GL_CHECK(glUniform1iv(gpuSamplerTexture.glLoc, (GLsizei)gpuSamplerTexture.units.size(), gpuSamplerTexture.units.data())); + GL_CHECK(glUniform1iv(gpuSamplerTexture.glLoc, static_cast(gpuSamplerTexture.units.size()), gpuSamplerTexture.units.data())); } if (device->stateCache()->glProgram != gpuShader->glProgram) { @@ -1773,7 +1773,7 @@ void cmdFuncGLES3DestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gp void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect *renderArea, - const Color *clearColors, float clearDepth, int clearStencil) { + const Color *clearColors, float clearDepth, uint clearStencil) { static uint attachmentLoadOpRecord = 0U; GLES3GPUStateCache *cache = device->stateCache(); @@ -2380,7 +2380,7 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli (isShaderChanged || gpuInputAssembler != gfxStateCache.gpuInputAssembler)) { gfxStateCache.gpuInputAssembler = gpuInputAssembler; if (USE_VAO) { - GLuint hash = gpuPipelineState->gpuShader->glProgram ^ device->getThreadID(); + size_t hash = gpuPipelineState->gpuShader->glProgram ^ device->getThreadID(); GLuint glVAO = gpuInputAssembler->glVAOs[hash]; if (!glVAO) { GL_CHECK(glGenVertexArrays(1, &glVAO)); @@ -2396,8 +2396,8 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + GLuint glLoc = gpuInput.glLoc + c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; @@ -2440,8 +2440,8 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + GLuint glLoc = gpuInput.glLoc + c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glCurrentAttribLocs[glLoc] = true; cache->glEnabledAttribLocs[glLoc] = true; @@ -2513,8 +2513,8 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } break; case DynamicStateFlagBit::STENCIL_WRITE_MASK: { - const auto &front = dynamicStates->stencilStates[static_cast(StencilFace::FRONT)]; - const auto &back = dynamicStates->stencilStates[static_cast(StencilFace::BACK)]; + const auto &front = dynamicStates->stencilStatesFront; + const auto &back = dynamicStates->stencilStatesBack; if (cache->dss.stencilWriteMaskFront != front.writeMask) { GL_CHECK(glStencilMaskSeparate(GL_FRONT, front.writeMask)); cache->dss.stencilWriteMaskFront = front.writeMask; @@ -2525,8 +2525,8 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } } break; case DynamicStateFlagBit::STENCIL_COMPARE_MASK: { - const auto &front = dynamicStates->stencilStates[static_cast(StencilFace::FRONT)]; - const auto &back = dynamicStates->stencilStates[static_cast(StencilFace::BACK)]; + const auto &front = dynamicStates->stencilStatesFront; + const auto &back = dynamicStates->stencilStatesBack; if ((cache->dss.stencilRefFront != front.reference) || (cache->dss.stencilReadMaskFront != front.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index d659ab3472..989506d7b3 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -40,7 +40,7 @@ public: Rect renderArea; Color clearColors[MAX_ATTACHMENTS]; float clearDepth = 1.0F; - int clearStencil = 0; + uint clearStencil = 0U; uint subpassIdx = 0U; GLES3CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} @@ -248,7 +248,7 @@ CC_GLES3_API void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassI const Rect * renderArea = nullptr, const Color * clearColors = nullptr, float clearDepth = 1.F, - int clearStencil = 0); + uint clearStencil = 0); CC_GLES3_API void cmdFuncGLES3EndRenderPass(GLES3Device *device); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 4df8785240..25b90e8792 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -288,7 +288,7 @@ void GLES3Device::bindRenderContext(bool bound) { _context = bound ? _renderContext : nullptr; if (bound) { - _threadID = std::hash()(std::this_thread::get_id()); + _threadID = std::hash{}(std::this_thread::get_id()); _gpuStateCache->reset(); } } @@ -306,7 +306,7 @@ void GLES3Device::bindDeviceContext(bool bound) { _context = bound ? _deviceContext : nullptr; if (bound) { - _threadID = std::hash()(std::this_thread::get_id()); + _threadID = std::hash{}(std::this_thread::get_id()); _gpuStateCache->reset(); } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 33d119895e..6d927b2fda 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -75,7 +75,7 @@ public: }); } - inline uint getThreadID() const { return _threadID; } + inline size_t getThreadID() const { return _threadID; } uint getMinorVersion() const; @@ -121,7 +121,7 @@ protected: StringArray _extensions; - uint _threadID = 0U; + size_t _threadID = 0U; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index 8d38ac91ea..0346fc749a 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -152,9 +152,9 @@ struct GLES3GPUUniformSamplerTexture final { Type type = Type::UNKNOWN; uint count = 0U; - vector units; - GLenum glType = 0; - GLint glLoc = -1; + vector units; + GLenum glType = 0; + GLint glLoc = -1; }; using GLES3GPUUniformSamplerTextureList = vector; @@ -217,13 +217,13 @@ using GLES3GPUAttributeList = vector; class GLES3GPUInputAssembler final : public Object { public: - AttributeList attributes; - GLES3GPUBufferList gpuVertexBuffers; - GLES3GPUBuffer * gpuIndexBuffer = nullptr; - GLES3GPUBuffer * gpuIndirectBuffer = nullptr; - GLES3GPUAttributeList glAttribs; - GLenum glIndexType = 0; - map glVAOs; + AttributeList attributes; + GLES3GPUBufferList gpuVertexBuffers; + GLES3GPUBuffer * gpuIndexBuffer = nullptr; + GLES3GPUBuffer * gpuIndirectBuffer = nullptr; + GLES3GPUAttributeList glAttribs; + GLenum glIndexType = 0; + unordered_map glVAOs; }; class GLES3GPURenderPass final : public Object { @@ -329,7 +329,7 @@ struct GLES3ObjectCache final { Rect renderArea; ColorList clearColors; float clearDepth = 1.F; - int clearStencil = 0; + uint clearStencil = 0U; }; class GLES3GPUStateCache final : public Object { diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index 19d47339c0..7d93582afc 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -255,12 +255,11 @@ void CommandBufferValidator::setDepthBound(float minBounds, float maxBounds) { } void CommandBufferValidator::setStencilWriteMask(StencilFace face, uint mask) { - if (face == StencilFace::ALL) { - for (auto &stencilState : _curStates.stencilStates) { - stencilState.writeMask = mask; - } - } else { - _curStates.stencilStates[static_cast(face)].writeMask = mask; + if (hasFlag(face, StencilFace::FRONT)) { + _curStates.stencilStatesFront.writeMask = mask; + } + if (hasFlag(face, StencilFace::BACK)) { + _curStates.stencilStatesBack.writeMask = mask; } /////////// execute /////////// @@ -269,14 +268,13 @@ void CommandBufferValidator::setStencilWriteMask(StencilFace face, uint mask) { } void CommandBufferValidator::setStencilCompareMask(StencilFace face, uint ref, uint mask) { - if (face == StencilFace::ALL) { - for (auto &stencilState : _curStates.stencilStates) { - stencilState.reference = ref; - stencilState.compareMask = mask; - } - } else { - _curStates.stencilStates[static_cast(face)].reference = ref; - _curStates.stencilStates[static_cast(face)].compareMask = mask; + if (hasFlag(face, StencilFace::FRONT)) { + _curStates.stencilStatesFront.reference = ref; + _curStates.stencilStatesFront.compareMask = mask; + } + if (hasFlag(face, StencilFace::BACK)) { + _curStates.stencilStatesBack.reference = ref; + _curStates.stencilStatesBack.compareMask = mask; } /////////// execute /////////// diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index 58213d26bc..bc0b7dbf75 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -128,10 +128,6 @@ void DeviceValidator::present() { ++_currentFrame; } -void DeviceValidator::setMultithreaded(bool multithreaded) { - _actor->setMultithreaded(multithreaded); -} - CommandBuffer *DeviceValidator::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { CommandBuffer *actor = _actor->createCommandBuffer(info, hasAgent); CommandBuffer *result = CC_NEW(CommandBufferValidator(actor)); diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.h b/native/cocos/renderer/gfx-validator/DeviceValidator.h index cd0ae37aac..72dd92c8c3 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.h +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.h @@ -76,7 +76,6 @@ public: void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; void flushCommands(CommandBuffer *const *cmdBuffs, uint count) override; - void setMultithreaded(bool multithreaded) override; SurfaceTransform getSurfaceTransform() const override { return _actor->getSurfaceTransform(); } uint getWidth() const override { return _actor->getWidth(); } uint getHeight() const override { return _actor->getHeight(); } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 849e3eae09..d4632dfbb6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -39,6 +39,8 @@ #include "VKRenderPass.h" #include "VKTexture.h" #include "VKTextureBarrier.h" +#include "gfx-base/GFXDef-common.h" +#include "vulkan/vulkan_core.h" namespace cc { namespace gfx { @@ -308,24 +310,45 @@ void CCVKCommandBuffer::setDepthBound(float minBounds, float maxBounds) { } void CCVKCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { - DynamicStencilStates &state = _curDynamicStates.stencilStates[static_cast(face)]; - if (state.writeMask != mask) { - state.writeMask = mask; - - VkStencilFaceFlagBits vkFace = (face == StencilFace::FRONT ? VK_STENCIL_FACE_FRONT_BIT : VK_STENCIL_FACE_BACK_BIT); - vkCmdSetStencilWriteMask(_gpuCommandBuffer->vkCommandBuffer, vkFace, mask); + DynamicStencilStates &front = _curDynamicStates.stencilStatesFront; + DynamicStencilStates &back = _curDynamicStates.stencilStatesBack; + if (face == StencilFace::ALL) { + if (front.writeMask == mask && back.writeMask == mask) return; + front.writeMask = back.writeMask = mask; + vkCmdSetStencilWriteMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_AND_BACK, mask); + } else if (face == StencilFace::FRONT) { + if (front.writeMask == mask) return; + front.writeMask = mask; + vkCmdSetStencilWriteMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_BIT, mask); + } else if (face == StencilFace::BACK) { + if (back.writeMask == mask) return; + back.writeMask = mask; + vkCmdSetStencilWriteMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_BACK_BIT, mask); } } void CCVKCommandBuffer::setStencilCompareMask(StencilFace face, uint reference, uint mask) { - DynamicStencilStates &state = _curDynamicStates.stencilStates[static_cast(face)]; - if (state.reference != reference || state.compareMask != mask) { - state.reference = reference; - state.compareMask = mask; - - VkStencilFaceFlags vkFace = VK_STENCIL_FACE_FLAGS[static_cast(face)]; - vkCmdSetStencilReference(_gpuCommandBuffer->vkCommandBuffer, vkFace, reference); - vkCmdSetStencilCompareMask(_gpuCommandBuffer->vkCommandBuffer, vkFace, mask); + DynamicStencilStates &front = _curDynamicStates.stencilStatesFront; + DynamicStencilStates &back = _curDynamicStates.stencilStatesBack; + if (face == StencilFace::ALL) { + if (front.reference == reference && back.reference == reference && + front.compareMask == mask && back.compareMask == mask) return; + front.reference = back.reference = reference; + front.compareMask = back.compareMask = mask; + vkCmdSetStencilReference(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_AND_BACK, reference); + vkCmdSetStencilCompareMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_AND_BACK, mask); + } else if (face == StencilFace::FRONT) { + if (front.writeMask == mask && front.reference == reference) return; + front.writeMask = mask; + front.reference = reference; + vkCmdSetStencilReference(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_BIT, reference); + vkCmdSetStencilCompareMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_FRONT_BIT, mask); + } else if (face == StencilFace::BACK) { + if (back.writeMask == mask && back.reference == reference) return; + back.writeMask = mask; + back.reference = reference; + vkCmdSetStencilReference(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_BACK_BIT, reference); + vkCmdSetStencilCompareMask(_gpuCommandBuffer->vkCommandBuffer, VK_STENCIL_FACE_BACK_BIT, mask); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 9e7e5ec221..b737a43c6c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -42,7 +42,7 @@ constexpr bool ENABLE_LAZY_ALLOCATION = true; } CCVKGPUCommandBufferPool *CCVKGPUDevice::getCommandBufferPool() { - std::thread::id threadID = std::this_thread::get_id(); + static thread_local size_t threadID = std::hash{}(std::this_thread::get_id()); if (!_commandBufferPools.count(threadID)) { _commandBufferPools[threadID] = CC_NEW(CCVKGPUCommandBufferPool(this)); } @@ -553,7 +553,7 @@ void cmdFuncCCVKCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra void cmdFuncCCVKCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { - vector spirv = glsl2spirv(stage.type, "#version 450\n" + stage.source, device->gpuDevice()->minorVersion); + vector spirv = glsl2spirv(stage.type, "#version 450\n" + stage.source, static_cast(device->gpuDevice()->minorVersion)); VkShaderModuleCreateInfo createInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; createInfo.codeSize = spirv.size() * sizeof(unsigned int); createInfo.pCode = spirv.data(); @@ -993,8 +993,8 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; if (formatProperties.optimalTilingFeatures & mipmapFeatures) { - const int32_t width = gpuTexture->width; - const int32_t height = gpuTexture->height; + int width = static_cast(gpuTexture->width); + int height = static_cast(gpuTexture->height); VkImageBlit blitInfo{}; blitInfo.srcSubresource.aspectMask = gpuTexture->aspectMask; diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 4e1dde2b68..7750d17e12 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -369,10 +369,8 @@ public: private: friend class CCVKDevice; - using CommandBufferPools = tbb::concurrent_unordered_map< - std::thread::id, CCVKGPUCommandBufferPool *, std::hash>; - // cannot use thread_local here because we need explicit control over their destruction + using CommandBufferPools = tbb::concurrent_unordered_map>; CommandBufferPools _commandBufferPools; unordered_map _descriptorSetPools; @@ -875,14 +873,15 @@ public: } void update(const CCVKGPUBufferView *buffer) { - auto it = _buffers.find(buffer); - if (it == _buffers.end()) return; - auto &info = it->second; - for (uint i = 0U; i < info.descriptors.size(); i++) { - doUpdate(buffer, info.descriptors[i]); - } - for (const auto *set : info.sets) { - _descriptorSetHub->record(set); + for (const auto &it : _buffers) { + if (it.first->gpuBuffer != buffer->gpuBuffer) continue; + const auto &info = it.second; + for (uint i = 0U; i < info.descriptors.size(); i++) { + doUpdate(buffer, info.descriptors[i]); + } + for (const auto *set : info.sets) { + _descriptorSetHub->record(set); + } } } void update(const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor) { @@ -897,14 +896,15 @@ public: } } void update(const CCVKGPUTextureView *texture) { - auto it = _textures.find(texture); - if (it == _textures.end()) return; - auto &info = it->second; - for (uint i = 0U; i < info.descriptors.size(); i++) { - doUpdate(texture, info.descriptors[i]); - } - for (const auto *set : info.sets) { - _descriptorSetHub->record(set); + for (const auto &it : _textures) { + if (it.first->gpuTexture != texture->gpuTexture) continue; + const auto &info = it.second; + for (uint i = 0U; i < info.descriptors.size(); i++) { + doUpdate(texture, info.descriptors[i]); + } + for (const auto *set : info.sets) { + _descriptorSetHub->record(set); + } } } void update(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { diff --git a/native/docs/LINTER_AUTOFIX_GUIDE.md b/native/docs/LINTER_AUTOFIX_GUIDE.md index b7297274f8..e651d502da 100644 --- a/native/docs/LINTER_AUTOFIX_GUIDE.md +++ b/native/docs/LINTER_AUTOFIX_GUIDE.md @@ -113,6 +113,17 @@ utils/fix-tidy-format.sh HEAD~3..HEAD # run auto-fix on files changed in the las All the issues will be reported in the standard output. This can be used as local self-test runs for CI checks. +## Usage of `NOLINT` + +The general rule is: DO NOT USE IT. + +That being said, however, sometimes due to various reasons (clang-tidy false positives, fixing legacy codebase just requires too much work, etc.), when there is just no way around, you can use them with specific rule tags and reasons for why it has to be this way: +```cpp + // NOLINTNEXTLINE(google-explicit-constructor) false positive when involving __VA_ARGS__ + CC_VMATH_STRUCT(Model, transform, color, enabled) +``` +Never use `NOLINT` without any explanations or rule tags. + ## Other IDEs It is possible to use other IDEs as long as they [support clang-tidy](https://clang.llvm.org/extra/clang-tidy/Integrations.html). diff --git a/native/templates/common/Classes/Game.cpp b/native/templates/common/Classes/Game.cpp index fd6cb06a6b..a88bec052f 100644 --- a/native/templates/common/Classes/Game.cpp +++ b/native/templates/common/Classes/Game.cpp @@ -1,8 +1,8 @@ /**************************************************************************** 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 @@ -10,10 +10,10 @@ 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 @@ -62,10 +62,6 @@ bool Game::init() { jsb_run_script("jsb-adapter/jsb-builtin.js"); jsb_run_script("main.js"); - se->addAfterCleanupHook([]() { - JSBClassType::destroy(); - }); - #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) cc::Vec2 logicSize = getViewLogicalSize(); float pixelRatio = cc::Device::getDevicePixelRatio(); diff --git a/native/tools/simulator/frameworks/runtime-src/Classes/Game.cpp b/native/tools/simulator/frameworks/runtime-src/Classes/Game.cpp index 5f60205732..67463653c7 100755 --- a/native/tools/simulator/frameworks/runtime-src/Classes/Game.cpp +++ b/native/tools/simulator/frameworks/runtime-src/Classes/Game.cpp @@ -48,7 +48,7 @@ Game::~Game() bool Game::init() { - + cc::Application::init(); se::ScriptEngine *se = se::ScriptEngine::getInstance(); @@ -56,13 +56,13 @@ bool Game::init() Application::getInstance()->setPreferredFramesPerSecond(60); jsb_init_file_operation_delegate(); jsb_register_all_modules(); - + auto parser = ConfigParser::getInstance(); #if defined(CC_DEBUG) && (CC_DEBUG > 0) // Enable debugger here jsb_enable_debugger("0.0.0.0", 5086, parser->isWaitForConnect()); #endif - + se->start(); auto runtimeEngine = RuntimeEngine::getInstance(); @@ -74,11 +74,7 @@ bool Game::init() se::AutoHandleScope hs; jsb_run_script("jsb-adapter/jsb-builtin.js"); jsb_run_script("main.js"); - - se->addAfterCleanupHook([]() { - JSBClassType::destroy(); - }); - + // Runtime end CC_LOG_DEBUG("iShow!"); return true; diff --git a/native/tools/tojs/anysdk-appstore.ini b/native/tools/tojs/anysdk-appstore.ini index bd9a0467ac..1ec4d4162f 100644 --- a/native/tools/tojs/anysdk-appstore.ini +++ b/native/tools/tojs/anysdk-appstore.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/%(clang_include)s -clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(anysdk_appstore_dir)s cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/anysdk-common.ini b/native/tools/tojs/anysdk-common.ini index 45a410c644..298ef1be51 100644 --- a/native/tools/tojs/anysdk-common.ini +++ b/native/tools/tojs/anysdk-common.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/%(clang_include)s -clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(anysdk_common_dir)s diff --git a/native/tools/tojs/audio.ini b/native/tools/tojs/audio.ini index b8ebdbb59b..b95db6facf 100644 --- a/native/tools/tojs/audio.ini +++ b/native/tools/tojs/audio.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/cocos.ini b/native/tools/tojs/cocos.ini index e4e06f3b4f..9b59c87704 100644 --- a/native/tools/tojs/cocos.ini +++ b/native/tools/tojs/cocos.ini @@ -12,7 +12,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/dragonbones.ini b/native/tools/tojs/dragonbones.ini index fe0bc45ad0..1957a78294 100644 --- a/native/tools/tojs/dragonbones.ini +++ b/native/tools/tojs/dragonbones.ini @@ -10,7 +10,7 @@ macro_judgement = #if USE_DRAGONBONES > 0 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 -I%(cocosdir)s/external/android/arm64-v8a/include/v8 clang_headers = -clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/bindings/jswrapper -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/cocos/editor-support cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/editor_support.ini b/native/tools/tojs/editor_support.ini index f369901ebd..a0b748ef95 100644 --- a/native/tools/tojs/editor_support.ini +++ b/native/tools/tojs/editor_support.ini @@ -10,7 +10,7 @@ macro_judgement = 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 -I%(cocosdir)s/external/android/arm64-v8a/include/v8 clang_headers = -clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/bindings/jswrapper -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/cocos/editor-support cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/extension.ini b/native/tools/tojs/extension.ini index 6e87d43148..bc4b922985 100644 --- a/native/tools/tojs/extension.ini +++ b/native/tools/tojs/extension.ini @@ -11,7 +11,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources diff --git a/native/tools/tojs/genbindings.py b/native/tools/tojs/genbindings.py index b32cea12e9..b24e35d233 100755 --- a/native/tools/tojs/genbindings.py +++ b/native/tools/tojs/genbindings.py @@ -176,7 +176,7 @@ def main(): # tasks.append(_run_cmd(command)) _run_cmd(command).communicate() - if len(sys.argv) > 2 and sys.argv[1] == '--cfg': + if len(sys.argv) > 2 and sys.argv[1] == '--config': for path in sys.argv[2:]: generate(path.replace('\\', '/')) else: diff --git a/native/tools/tojs/gfx.ini b/native/tools/tojs/gfx.ini index e4fb6caca6..597dacfa29 100644 --- a/native/tools/tojs/gfx.ini +++ b/native/tools/tojs/gfx.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/renderer -I%(cocosdir)s/cocos/renderer/core-I%(cocosdir)s/cocos/math -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/network.ini b/native/tools/tojs/network.ini index dff444646e..26e7f6f95b 100644 --- a/native/tools/tojs/network.ini +++ b/native/tools/tojs/network.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/physics.ini b/native/tools/tojs/physics.ini index 0577c78f58..6f7d6a4019 100644 --- a/native/tools/tojs/physics.ini +++ b/native/tools/tojs/physics.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/external/android/armeabi-v7a/include/v8 cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/pipeline.ini b/native/tools/tojs/pipeline.ini index a1db1a481f..fa011904f2 100644 --- a/native/tools/tojs/pipeline.ini +++ b/native/tools/tojs/pipeline.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/renderer -I%(cocosdir)s -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/external/ios/include/v8 cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/spine.ini b/native/tools/tojs/spine.ini index 4985975523..f7f0421cf2 100644 --- a/native/tools/tojs/spine.ini +++ b/native/tools/tojs/spine.ini @@ -10,7 +10,7 @@ macro_judgement = 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 -I%(cocosdir)s/external/android/arm64-v8a/include/v8 clang_headers = -clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/bindings/jswrapper -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/cocos/editor-support cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 diff --git a/native/tools/tojs/video.ini b/native/tools/tojs/video.ini index 72a56ac7b4..18d4bd75bd 100644 --- a/native/tools/tojs/video.ini +++ b/native/tools/tojs/video.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources diff --git a/native/tools/tojs/webview.ini b/native/tools/tojs/webview.ini index c7de5375b7..cc941fcca2 100644 --- a/native/tools/tojs/webview.ini +++ b/native/tools/tojs/webview.ini @@ -14,7 +14,7 @@ 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++17 -fsigned-char -U__SSE__ -U__ARM_NEON +clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources