From 9a5d0ba123c2cae1ce2f7382144dea27a08c3858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Thu, 10 Nov 2022 21:53:29 +0800 Subject: [PATCH 01/19] Bug:native scene Winodws fix (cherry picked from commit 85424fa6878aac97cd29643d586203c6bba6d2e8) --- native/cocos/bindings/jswrapper/v8/Object.cpp | 2 +- native/cocos/bindings/jswrapper/v8/Utils.cpp | 6 +- .../platform/editor/EditorApplication.cpp | 178 ++++++++++++++++++ .../platform/editor/mac/EditorMacPlatform.cpp | 0 native/cocos/platform/editor/mac/Game.mm | 0 .../editor/windows/EditorWindowsPlatform.cpp | 131 +++++++++++++ native/cocos/platform/editor/windows/Game.cpp | 116 ++++++++++++ native/cocos/renderer/GFXDeviceManager.h | 2 +- 8 files changed, 430 insertions(+), 5 deletions(-) create mode 100644 native/cocos/platform/editor/EditorApplication.cpp create mode 100644 native/cocos/platform/editor/mac/EditorMacPlatform.cpp create mode 100644 native/cocos/platform/editor/mac/Game.mm create mode 100644 native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp create mode 100644 native/cocos/platform/editor/windows/Game.cpp diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 37a71861179..44c226b1c72 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -306,7 +306,7 @@ Object *Object::createTypedArrayWithBuffer(TypedArrayType type, const Object *ob Object *Object::createTypedArrayWithBuffer(TypedArrayType type, const Object *obj, size_t offset) { size_t byteLength{0}; uint8_t *skip{nullptr}; - obj->getTypedArrayData(&skip, &byteLength); + obj->getArrayBufferData(&skip, &byteLength); return Object::createTypedArrayWithBuffer(type, obj, offset, byteLength - offset); } diff --git a/native/cocos/bindings/jswrapper/v8/Utils.cpp b/native/cocos/bindings/jswrapper/v8/Utils.cpp index a3ae334c275..4079cedd3d2 100644 --- a/native/cocos/bindings/jswrapper/v8/Utils.cpp +++ b/native/cocos/bindings/jswrapper/v8/Utils.cpp @@ -204,7 +204,7 @@ void setPrivate(v8::Isolate *isolate, ObjectWrap &wrap, Object *thizObj) { v8::Local obj = wrap.handle(isolate); int c = obj->InternalFieldCount(); CC_ASSERT(c > 0); - if (c > 0) { + if (c == 1) { wrap.wrap(thizObj, 0); } } @@ -218,7 +218,7 @@ Object *getPrivate(v8::Isolate *isolate, v8::Local value) { v8::Local objChecked = obj.ToLocalChecked(); int c = objChecked->InternalFieldCount(); - if (c > 0) { + if (c == 1) { return static_cast(ObjectWrap::unwrap(objChecked, 0)); } @@ -228,7 +228,7 @@ Object *getPrivate(v8::Isolate *isolate, v8::Local value) { void clearPrivate(v8::Isolate *isolate, ObjectWrap &wrap) { v8::Local obj = wrap.handle(isolate); int c = obj->InternalFieldCount(); - if (c > 0) { + if (c == 1) { wrap.wrap(nullptr, 0); } } diff --git a/native/cocos/platform/editor/EditorApplication.cpp b/native/cocos/platform/editor/EditorApplication.cpp new file mode 100644 index 00000000000..fff29e4edb1 --- /dev/null +++ b/native/cocos/platform/editor/EditorApplication.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** + Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include "application/CocosApplication.h" + +#include "base/Macros.h" + +#include "cocos/application/ApplicationManager.h" +#include "cocos/bindings/event/EventDispatcher.h" +#include "cocos/bindings/jswrapper/SeApi.h" +#include "cocos/bindings/manual/jsb_classtype.h" +#include "cocos/bindings/manual/jsb_global.h" +#include "cocos/bindings/manual/jsb_module_register.h" +#include "cocos/engine/BaseEngine.h" +#include "cocos/platform/interfaces/modules/IScreen.h" +#include "cocos/platform/interfaces/modules/ISystemWindowManager.h" + +extern v8::Isolate* globalIsolate; +namespace cc { + + CocosApplication::CocosApplication() { + _engine = BaseEngine::createEngine(); + } + + CocosApplication::~CocosApplication() { + unregisterAllEngineEvents(); + } + + void CocosApplication::unregisterAllEngineEvents() { + if (_engine != nullptr) { + _engine->off(_engineEvents); + } + } + + int CocosApplication::init() { + if (_engine->init()) { + return -1; + } + unregisterAllEngineEvents(); + + _systemWindow = CC_GET_MAIN_SYSTEM_WINDOW(); + + _engineEvents = _engine->on([this](BaseEngine* /*emitter*/, BaseEngine::EngineStatus status) { + switch (status) { + case BaseEngine::ON_START: + this->onStart(); + break; + case BaseEngine::ON_RESUME: + this->onResume(); + break; + case BaseEngine::ON_PAUSE: + this->onPause(); + break; + case BaseEngine::ON_CLOSE: + this->onClose(); + break; + default: + CC_ASSERT(false); + } + }); + + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + + jsb_init_file_operation_delegate(); + + se->setExceptionCallback( + std::bind(&CocosApplication::handleException, this, // NOLINT(modernize-avoid-bind) + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + + jsb_register_all_modules(); + se->start(globalIsolate); + + +#if (CC_PLATFORM == CC_PLATFORM_IOS) + auto logicSize = _systemWindow->getViewSize(); + IScreen* screen = _engine->getInterface(); + float pixelRatio = screen->getDevicePixelRatio(); + uint32_t windowId = _systemWindow->getWindowId(); + events::Resize::broadcast(logicSize.x * pixelRatio, logicSize.y * pixelRatio, windowId); +#endif + return 0; + } + + int32_t CocosApplication::run(int argc, const char** argv) { + CC_UNUSED_PARAM(argc); + CC_UNUSED_PARAM(argv); + return _engine->run(); + } + + void CocosApplication::pause() { + _engine->pause(); + } + + void CocosApplication::resume() { + _engine->resume(); + } + + void CocosApplication::restart() { + _engine->restart(); + } + // IMPORTANT!!The method `onClose` is a function to be listen close event, while `close` is a jsb binding method mean to close the whole application. + void CocosApplication::close() { + _systemWindow->closeWindow(); + } + + BaseEngine::Ptr CocosApplication::getEngine() const { + return _engine; + } + + void CocosApplication::onStart() { + // TODO(cc): Handling engine start events + } + + void CocosApplication::onPause() { + // TODO(cc): Handling pause events + } + + void CocosApplication::onResume() { + // TODO(cc): Handling resume events + } + + void CocosApplication::onClose() { + _engine->close(); + } + + void CocosApplication::setDebugIpAndPort(const ccstd::string& serverAddr, uint32_t port, bool isWaitForConnect) { + // Enable debugger here + jsb_enable_debugger(serverAddr, port, isWaitForConnect); + } + + void CocosApplication::runScript(const ccstd::string& filePath) { + jsb_run_script(filePath); + } + + void CocosApplication::handleException(const char* location, const char* message, const char* stack) { + // Send exception information to server like Tencent Bugly. + CC_LOG_ERROR("\nUncaught Exception:\n - location : %s\n - msg : %s\n - detail : \n %s\n", location, message, stack); + } + + void CocosApplication::setXXTeaKey(const ccstd::string& key) { + jsb_set_xxtea_key(key); + } +#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS + void CocosApplication::createWindow(const char* title, int32_t w, + int32_t h, int32_t flags) { + _systemWindow->createWindow(title, w, h, flags); + } + + void CocosApplication::createWindow(const char* title, + int32_t x, int32_t y, int32_t w, + int32_t h, int32_t flags) { + _systemWindow->createWindow(title, x, y, w, h, flags); + } +#endif + +} // namespace cc diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.cpp b/native/cocos/platform/editor/mac/EditorMacPlatform.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/native/cocos/platform/editor/mac/Game.mm b/native/cocos/platform/editor/mac/Game.mm new file mode 100644 index 00000000000..e69de29bb2d diff --git a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp new file mode 100644 index 00000000000..25b86025949 --- /dev/null +++ b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include "platform/win32/WindowsPlatform.h" +#include "platform/win32/modules/SystemWindowManager.h" + +#include +#include +#include + +#include "cocos/platform/win32/modules/Accelerometer.h" +#include "cocos/platform/win32/modules/Battery.h" +#include "cocos/platform/win32/modules/Network.h" +#include "cocos/platform/win32/modules/System.h" +#if defined(CC_SERVER_MODE) +#include "platform/empty/modules/Screen.h" +#include "platform/empty/modules/SystemWindow.h" +#else +#include "cocos/platform/win32/modules/Screen.h" +#include "cocos/platform/win32/modules/SystemWindow.h" +#endif +#include "base/memory/Memory.h" +#include "cocos/platform/win32/modules/Vibrator.h" + +namespace { + /** + @brief This function changes the PVRFrame show/hide setting in register. + @param bEnable If true show the PVRFrame window, otherwise hide. + */ + void PVRFrameEnableControlWindow(bool bEnable) { + HKEY hKey = 0; + + // Open PVRFrame control key, if not exist create it. + if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, + L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", + 0, + 0, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + 0, + &hKey, + nullptr)) { + return; + } + + const WCHAR* wszValue = L"hide_gui"; + const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; + WCHAR wszOldData[256] = { 0 }; + DWORD dwSize = sizeof(wszOldData); + LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); + if (ERROR_FILE_NOT_FOUND == status // the key not exist + || (ERROR_SUCCESS == status // or the hide_gui value is exist + && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal + { + dwSize = static_cast(sizeof(WCHAR) * (wcslen(wszNewData) + 1)); + RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); + } + + RegCloseKey(hKey); + } + +} // namespace + +namespace cc { + WindowsPlatform::WindowsPlatform() { + } + WindowsPlatform::~WindowsPlatform() { +#ifdef USE_WIN32_CONSOLE + FreeConsole(); +#endif + } + + int32_t WindowsPlatform::init() { + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + _windowManager = std::make_shared(); + registerInterface(_windowManager); + registerInterface(std::make_shared()); + +#ifdef USE_WIN32_CONSOLE + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); +#endif + + PVRFrameEnableControlWindow(false); + + return _windowManager->init(); + } + + int32_t WindowsPlatform::loop() { + for (size_t i = 0; i < 5; i++) + { + _windowManager->processEvent(&_quit); + } + runTask(); + _window->swapWindow(); + return 0; + } + + ISystemWindow* WindowsPlatform::createNativeWindow(uint32_t windowId, void* externalHandle) { + return ccnew SystemWindow(windowId, externalHandle); + } + +} // namespace cc diff --git a/native/cocos/platform/editor/windows/Game.cpp b/native/cocos/platform/editor/windows/Game.cpp new file mode 100644 index 00000000000..e02de6ad146 --- /dev/null +++ b/native/cocos/platform/editor/windows/Game.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "cocos/application/BaseGame.h" +#include "cocos/application/ApplicationManager.h" +#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" +#include "cocos/platform/interfaces/modules/ISystemWindow.h" +#include "cocos/platform/interfaces/modules/ISystemWindowManager.h" + +#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) +#include "windows.h" +#endif + +extern "C" void cc_load_all_plugins(); // NOLINT + +using namespace std; +using namespace cc; + +class Game : public cc::BaseGame { +public: + Game(); + int init() override; + //bool init() override; + void onPause() override; + void onResume() override; + void onClose() override; +}; + +Game::Game() { +} + +int Game::init() { + cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); + + cc_load_all_plugins(); + +#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS + // override default value + //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; + //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; + _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; + _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; + _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | + ISystemWindow::CC_WINDOW_RESIZABLE | + ISystemWindow::CC_WINDOW_INPUT_FOCUS| + ISystemWindow::CC_WINDOW_HIDDEN + : _windowInfo.flags; + std::call_once(_windowCreateFlag, [&]() { + ISystemWindowInfo info; + info.title = _windowInfo.title; +#if CC_PLATFORM == CC_PLATFORM_WINDOWS + info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now + info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above +#else + info.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; + info.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; +#endif + info.width = _windowInfo.width; + info.height = _windowInfo.height; + info.flags = _windowInfo.flags; + + ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(ISystemWindowManager); + windowMgr->createWindow(info); + }); + +#endif + + if (_debuggerInfo.enabled) { + setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); + } + + int ret = cc::CocosApplication::init(); + if (ret != 0) { + return ret; + } + + setXXTeaKey(_xxteaKey); + return 0; +} + +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void Game::onPause() { + cc::CocosApplication::onPause(); +} + +void Game::onResume() { + cc::CocosApplication::onResume(); +} + +void Game::onClose() { + cc::CocosApplication::onClose(); +} + + +CC_REGISTER_APPLICATION(Game); diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index 8844f7484a1..45f28e1e864 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -62,7 +62,7 @@ namespace cc { namespace gfx { class CC_DLL DeviceManager final { - static constexpr bool DETACH_DEVICE_THREAD{true}; + static constexpr bool DETACH_DEVICE_THREAD{false}; static constexpr bool FORCE_DISABLE_VALIDATION{false}; static constexpr bool FORCE_ENABLE_VALIDATION{false}; From 6ab4f5a2b3a38e13411ee7713d857e5f78a3033c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Fri, 11 Nov 2022 22:05:20 +0800 Subject: [PATCH 02/19] =?UTF-8?q?feature:=E5=A2=9E=E5=8A=A0=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E7=BC=96=E8=BE=91=E5=99=A8platform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- native/CMakeLists.txt | 41 ++-- native/cocos/application/CocosApplication.cpp | 6 +- .../platform/editor/EditorApplication.cpp | 178 ------------------ .../platform/editor/mac/EditorMacPlatform.cpp | 0 .../platform/editor/mac/EditorMacPlatform.mm | 163 ++++++++++++++++ .../platform/editor/mac/EditorMacScene.mm | 56 ++++++ .../platform/editor/mac/EditorMacWindow.mm | 93 +++++++++ native/cocos/platform/editor/mac/Game.mm | 96 ++++++++++ .../editor/windows/EditorWindowsPlatform.cpp | 2 +- 9 files changed, 443 insertions(+), 192 deletions(-) delete mode 100644 native/cocos/platform/editor/EditorApplication.cpp delete mode 100644 native/cocos/platform/editor/mac/EditorMacPlatform.cpp create mode 100644 native/cocos/platform/editor/mac/EditorMacPlatform.mm create mode 100644 native/cocos/platform/editor/mac/EditorMacScene.mm create mode 100644 native/cocos/platform/editor/mac/EditorMacWindow.mm diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index c1a1f5d328d..e0d08e78317 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -506,10 +506,18 @@ cocos_source_files( cocos/platform/UniversalPlatform.h ) if(WINDOWS) - cocos_source_files( - cocos/platform/win32/WindowsPlatform.cpp - cocos/platform/win32/WindowsPlatform.h - ) + if(CC_EDITOR) + cocos_source_files( + cocos/platform/editor/windows/EditorWindowsPlatform.cpp + cocos/platform/win32/WindowsPlatform.h + cocos/platform/editor/windows/Game.cpp + ) + else() + cocos_source_files( + cocos/platform/win32/WindowsPlatform.cpp + cocos/platform/win32/WindowsPlatform.h + ) + endif() elseif(LINUX) cocos_source_files( cocos/platform/linux/LinuxPlatform.cpp @@ -526,14 +534,23 @@ elseif(OHOS) cocos/platform/ohos/OhosPlatform.h ) elseif(MACOSX) - cocos_source_files( - cocos/platform/mac/MacPlatform.mm - cocos/platform/mac/MacPlatform.h - cocos/platform/mac/ViewController.h - cocos/platform/mac/ViewController.mm - cocos/platform/mac/AppDelegate.h - cocos/platform/mac/AppDelegate.mm - ) + if(CC_EDITOR) + cocos_source_files( + cocos/platform/editor/mac/EditorMacPlatform.mm + cocos/platform/editor/mac/Game.mm + cocos/platform/editor/mac/EditorMacScene.mm + cocos/platform/editor/mac/EditorMacWindow.mm + ) + else() + cocos_source_files( + cocos/platform/mac/MacPlatform.mm + cocos/platform/mac/MacPlatform.h + cocos/platform/mac/ViewController.h + cocos/platform/mac/ViewController.mm + cocos/platform/mac/AppDelegate.h + cocos/platform/mac/AppDelegate.mm + ) + endif() elseif(IOS) cocos_source_files( cocos/platform/ios/IOSPlatform.mm diff --git a/native/cocos/application/CocosApplication.cpp b/native/cocos/application/CocosApplication.cpp index b542ca9b3ee..8e0bd142c08 100644 --- a/native/cocos/application/CocosApplication.cpp +++ b/native/cocos/application/CocosApplication.cpp @@ -89,8 +89,12 @@ int CocosApplication::init() { std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); jsb_register_all_modules(); - +#if CC_EDITOR + auto isolate = v8::Isolate::GetCurrent(); + se->start(isolate); +#else se->start(); +#endif #if (CC_PLATFORM == CC_PLATFORM_IOS) auto logicSize = _systemWindow->getViewSize(); diff --git a/native/cocos/platform/editor/EditorApplication.cpp b/native/cocos/platform/editor/EditorApplication.cpp deleted file mode 100644 index fff29e4edb1..00000000000 --- a/native/cocos/platform/editor/EditorApplication.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "application/CocosApplication.h" - -#include "base/Macros.h" - -#include "cocos/application/ApplicationManager.h" -#include "cocos/bindings/event/EventDispatcher.h" -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_classtype.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "cocos/bindings/manual/jsb_module_register.h" -#include "cocos/engine/BaseEngine.h" -#include "cocos/platform/interfaces/modules/IScreen.h" -#include "cocos/platform/interfaces/modules/ISystemWindowManager.h" - -extern v8::Isolate* globalIsolate; -namespace cc { - - CocosApplication::CocosApplication() { - _engine = BaseEngine::createEngine(); - } - - CocosApplication::~CocosApplication() { - unregisterAllEngineEvents(); - } - - void CocosApplication::unregisterAllEngineEvents() { - if (_engine != nullptr) { - _engine->off(_engineEvents); - } - } - - int CocosApplication::init() { - if (_engine->init()) { - return -1; - } - unregisterAllEngineEvents(); - - _systemWindow = CC_GET_MAIN_SYSTEM_WINDOW(); - - _engineEvents = _engine->on([this](BaseEngine* /*emitter*/, BaseEngine::EngineStatus status) { - switch (status) { - case BaseEngine::ON_START: - this->onStart(); - break; - case BaseEngine::ON_RESUME: - this->onResume(); - break; - case BaseEngine::ON_PAUSE: - this->onPause(); - break; - case BaseEngine::ON_CLOSE: - this->onClose(); - break; - default: - CC_ASSERT(false); - } - }); - - se::ScriptEngine* se = se::ScriptEngine::getInstance(); - - jsb_init_file_operation_delegate(); - - se->setExceptionCallback( - std::bind(&CocosApplication::handleException, this, // NOLINT(modernize-avoid-bind) - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - - jsb_register_all_modules(); - se->start(globalIsolate); - - -#if (CC_PLATFORM == CC_PLATFORM_IOS) - auto logicSize = _systemWindow->getViewSize(); - IScreen* screen = _engine->getInterface(); - float pixelRatio = screen->getDevicePixelRatio(); - uint32_t windowId = _systemWindow->getWindowId(); - events::Resize::broadcast(logicSize.x * pixelRatio, logicSize.y * pixelRatio, windowId); -#endif - return 0; - } - - int32_t CocosApplication::run(int argc, const char** argv) { - CC_UNUSED_PARAM(argc); - CC_UNUSED_PARAM(argv); - return _engine->run(); - } - - void CocosApplication::pause() { - _engine->pause(); - } - - void CocosApplication::resume() { - _engine->resume(); - } - - void CocosApplication::restart() { - _engine->restart(); - } - // IMPORTANT!!The method `onClose` is a function to be listen close event, while `close` is a jsb binding method mean to close the whole application. - void CocosApplication::close() { - _systemWindow->closeWindow(); - } - - BaseEngine::Ptr CocosApplication::getEngine() const { - return _engine; - } - - void CocosApplication::onStart() { - // TODO(cc): Handling engine start events - } - - void CocosApplication::onPause() { - // TODO(cc): Handling pause events - } - - void CocosApplication::onResume() { - // TODO(cc): Handling resume events - } - - void CocosApplication::onClose() { - _engine->close(); - } - - void CocosApplication::setDebugIpAndPort(const ccstd::string& serverAddr, uint32_t port, bool isWaitForConnect) { - // Enable debugger here - jsb_enable_debugger(serverAddr, port, isWaitForConnect); - } - - void CocosApplication::runScript(const ccstd::string& filePath) { - jsb_run_script(filePath); - } - - void CocosApplication::handleException(const char* location, const char* message, const char* stack) { - // Send exception information to server like Tencent Bugly. - CC_LOG_ERROR("\nUncaught Exception:\n - location : %s\n - msg : %s\n - detail : \n %s\n", location, message, stack); - } - - void CocosApplication::setXXTeaKey(const ccstd::string& key) { - jsb_set_xxtea_key(key); - } -#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS - void CocosApplication::createWindow(const char* title, int32_t w, - int32_t h, int32_t flags) { - _systemWindow->createWindow(title, w, h, flags); - } - - void CocosApplication::createWindow(const char* title, - int32_t x, int32_t y, int32_t w, - int32_t h, int32_t flags) { - _systemWindow->createWindow(title, x, y, w, h, flags); - } -#endif - -} // namespace cc diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.cpp b/native/cocos/platform/editor/mac/EditorMacPlatform.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.mm b/native/cocos/platform/editor/mac/EditorMacPlatform.mm new file mode 100644 index 00000000000..da66b3d5926 --- /dev/null +++ b/native/cocos/platform/editor/mac/EditorMacPlatform.mm @@ -0,0 +1,163 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include "platform/mac/MacPlatform.h" +#include "platform/interfaces/OSInterface.h" +#include "platform/mac/AppDelegate.h" + +#include "modules/Accelerometer.h" +#include "modules/Battery.h" +#include "modules/Network.h" +#include "modules/System.h" +#include "modules/Vibrator.h" + +#if defined(CC_SERVER_MODE) + #include "platform/empty/modules/Screen.h" + #include "platform/empty/modules/SystemWindow.h" +#else + #include "modules/Screen.h" + #include "modules/SystemWindow.h" + #include "modules/SystemWindowManager.h" +#endif + +#import +#include "base/memory/Memory.h" + +extern int cocos_main(int argc, const char **argv); + +@interface MyTimer : NSObject { + cc::MacPlatform *_platform; +// NSTimer *_timer; +} +- (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps; +- (void)start; +- (void)changeFPS; +- (void)pause; +- (void)resume; +@end + +@implementation MyTimer + +- (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps { + if (self = [super init]) { + _platform = platform; + } + return self; +} + +- (void)start { + int32_t fps = _platform->getFps(); +} + +- (void)pause { + +} + +- (void)resume { + [self start]; +} + +- (void)changeFPS { + [self pause]; + [self resume]; +} + +- (void)renderScene { + _platform->runTask(); +} + +@end + +namespace { +MyTimer *_timer; +} + +namespace cc { + +MacPlatform::~MacPlatform() { + +} + +int32_t MacPlatform::init() { + + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + return 0; +} + +int32_t MacPlatform::loop(void) { + runTask(); +} + +int32_t MacPlatform::run(int argc, const char **argv) { +#if defined(CC_SERVER_MODE) + cocos_main(argc, argv); + while (true) { + runTask(); + } + return 0; +#else + id delegate = [[AppDelegate alloc] init]; + NSApplication.sharedApplication.delegate = delegate; + return NSApplicationMain(argc, argv); +#endif +} + +void MacPlatform::setFps(int32_t fps) { + if(fps != getFps()) { + UniversalPlatform::setFps(fps); + } +} + +void MacPlatform::onPause() { + + cc::WindowEvent ev; + ev.type = cc::WindowEvent::Type::HIDDEN; + cc::events::WindowEvent::broadcast(ev); +} + +void MacPlatform::onResume() { + + cc::WindowEvent ev; + ev.type = cc::WindowEvent::Type::SHOW; + cc::events::WindowEvent::broadcast(ev); +} + +void MacPlatform::onClose() { + cc::WindowEvent ev; + ev.type = cc::WindowEvent::Type::CLOSE; + cc::events::WindowEvent::broadcast(ev); +} + +cc::ISystemWindow *MacPlatform::createNativeWindow(uint32_t windowId, void *externalHandle) { + return ccnew SystemWindow(windowId, externalHandle); +} + +} // namespace cc diff --git a/native/cocos/platform/editor/mac/EditorMacScene.mm b/native/cocos/platform/editor/mac/EditorMacScene.mm new file mode 100644 index 00000000000..556ce5744b3 --- /dev/null +++ b/native/cocos/platform/editor/mac/EditorMacScene.mm @@ -0,0 +1,56 @@ +/**************************************************************************** + 重写getDevicePixelRatio方法 +*/ + +#include "platform/mac/modules/Screen.h" + +#import +#include +#include + +#include "base/Macros.h" +#include "cocos/bindings/jswrapper/SeApi.h" + +namespace cc { + +int Screen::getDPI() const { + NSScreen * screen = [NSScreen mainScreen]; + NSDictionary *description = [screen deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + + return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f); +} + +float Screen::getDevicePixelRatio() const { + return 1; +} + +void Screen::setKeepScreenOn(bool value) { + CC_UNUSED_PARAM(value); +} + +Screen::Orientation Screen::getDeviceOrientation() const { + return Orientation::PORTRAIT; +} + +Vec4 Screen::getSafeAreaEdge() const { + return cc::Vec4(); +} + +bool Screen::isDisplayStats() { + se::AutoHandleScope hs; + se::Value ret; + char commandBuf[100] = "cc.debug.isDisplayStats();"; + se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); + return ret.toBoolean(); +} + +void Screen::setDisplayStats(bool isShow) { + se::AutoHandleScope hs; + char commandBuf[100] = {0}; + sprintf(commandBuf, "cc.debug.setDisplayStats(%s);", isShow ? "true" : "false"); + se::ScriptEngine::getInstance()->evalString(commandBuf); +} + +} // namespace cc diff --git a/native/cocos/platform/editor/mac/EditorMacWindow.mm b/native/cocos/platform/editor/mac/EditorMacWindow.mm new file mode 100644 index 00000000000..7a3e1a8c826 --- /dev/null +++ b/native/cocos/platform/editor/mac/EditorMacWindow.mm @@ -0,0 +1,93 @@ +/**************************************************************************** + Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ +#include "platform/mac/modules/SystemWindow.h" +#import +#import + +NSMutableDictionary *layerMap = [[NSMutableDictionary dictionary] retain]; +namespace cc { + + +SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle) + : _windowId(windowId) { + if (externalHandle) { + _windowHandle = reinterpret_cast(externalHandle); + } +} + +SystemWindow::~SystemWindow() = default; + +bool SystemWindow::createWindow(const char *title, + int w, int h, int flags) { + return createWindow(title, 0, 0, w, h, flags); +} + +bool SystemWindow::createWindow(const char *title, + int x, int y, int w, + int h, int flags) { + _width = w; + _height = h; + CAMetalLayer *layer = [[CAMetalLayer layer] retain]; + layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + layer.frame = CGRectMake(0, 0, w, h); + [layer setAnchorPoint:CGPointMake(0.f, 0.f)]; + NSString *key = [NSString stringWithFormat:@"%u",_windowId]; + [layerMap setValue:layer forKey:key]; + return true; +} + +void SystemWindow::closeWindow() { + //id window = [[[NSApplication sharedApplication] delegate] getWindow]; + if (_window) { + [_window close]; + _window = nullptr; + } +} + +void SystemWindow::setCursorEnabled(bool value) { +} + +void SystemWindow::copyTextToClipboard(const std::string &text) { + NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; + [pasteboard clearContents]; + NSString *tmp = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding]; + [pasteboard setString:tmp forType:NSPasteboardTypeString]; +} + +uintptr_t SystemWindow::getWindowHandle() const { + NSString *key = [NSString stringWithFormat:@"%u",_windowId]; + CAMetalLayer *layer = [layerMap valueForKey:key]; + return reinterpret_cast(layer); +} + +SystemWindow::Size SystemWindow::getViewSize() const { + return Size{static_cast(_width), static_cast(_height)}; +} + +uint32_t SystemWindow::getWindowId() const { + return _windowId; +} + +} diff --git a/native/cocos/platform/editor/mac/Game.mm b/native/cocos/platform/editor/mac/Game.mm index e69de29bb2d..9554a9cc8b6 100644 --- a/native/cocos/platform/editor/mac/Game.mm +++ b/native/cocos/platform/editor/mac/Game.mm @@ -0,0 +1,96 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "Game.h" +#include "FileUtils.h" +#include "renderer/pipeline/GlobalDescriptorSetManager.h" +#include "platform/interfaces/modules/ISystemWindowManager.h" +#include "cocos/application/ApplicationManager.h" + +#ifndef GAME_NAME +#define GAME_NAME "CocosGame"; +#endif +extern std::string SearchPath; +extern "C" void cc_load_all_plugins(); +Game::Game() = default; + +int Game::init() { + cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); + + cc_load_all_plugins(); + + #if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS + // override default value + //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; + //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; + _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; + _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; + _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | + cc::ISystemWindow::CC_WINDOW_RESIZABLE | + cc::ISystemWindow::CC_WINDOW_INPUT_FOCUS + : _windowInfo.flags; + std::call_once(_windowCreateFlag, [&]() { + cc::ISystemWindowInfo info; + info.title = _windowInfo.title; + info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now + info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above + info.width = _windowInfo.width; + info.height = _windowInfo.height; + info.flags = _windowInfo.flags; + + cc::ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(cc::ISystemWindowManager); + windowMgr->createWindow(info); + }); + + #endif + + if (_debuggerInfo.enabled) { + setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); + } + + int ret = cc::CocosApplication::init(); + if (ret != 0) { + return ret; + } + + setXXTeaKey(_xxteaKey); +// runScript("jsb-adapter/web-adapter.js"); +// runScript("main.js"); + + return 0; +} + +void Game::onPause() { + BaseGame::onPause(); +} + +void Game::onResume() { + BaseGame::onResume(); +} + +void Game::onClose() { + BaseGame::onClose(); +} + +CC_REGISTER_APPLICATION(Game); diff --git a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp index 25b86025949..8ea4eb5c50b 100644 --- a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp +++ b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp @@ -120,7 +120,7 @@ namespace cc { _windowManager->processEvent(&_quit); } runTask(); - _window->swapWindow(); + _windowManager->swapWindows(); return 0; } From 672efa1ea2a62952bbec113bddfc4c1cc4e967e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Tue, 15 Nov 2022 16:53:54 +0800 Subject: [PATCH 03/19] =?UTF-8?q?fix=EF=BC=9Afix=20gles3=20render=20error?= =?UTF-8?q?=20in=20edior=20on=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../renderer/gfx-gles3/GLES3Wrangler.cpp | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 46cc2ebce90..94b36f21a78 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -24,6 +24,8 @@ ****************************************************************************/ #include "GLES3Wrangler.h" +#include "base/Log.h" +#include #if defined(_WIN32) && !defined(ANDROID) #define WIN32_LEAN_AND_MEAN 1 @@ -34,8 +36,29 @@ static HMODULE libgles = NULL; static PFNGLES3WLOADPROC pfnGles3wLoad = NULL; bool gles3wOpen() { - libegl = LoadLibraryA("libEGL.dll"); - libgles = LoadLibraryA("libGLESv2.dll"); + std::string eglPath = "libEGL.dll"; + std::string glesPath = "libGLESv2.dll"; + +#if CC_EDITOR + // in editor,thers are same dlls,so we need to use abs path. + char dllPath[MAX_PATH]; + HMODULE engine = NULL; + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCWSTR)&gles3wOpen, &engine) != 0) { + GetModuleFileNameA(engine, dllPath, ARRAYSIZE(dllPath)); + std::string dir(dllPath); + dir = dir.substr(0, dir.rfind("\\") + 1); + eglPath = dir + eglPath; + glesPath = dir + glesPath; + } else { + int err = GetLastError(); + CC_LOG_WARNING("Failed to get abs path for editor,error code:%d", err); + } +#endif + + libegl = LoadLibraryA(eglPath.c_str()); + libgles = LoadLibraryA(glesPath.c_str()); return (libegl && libgles); } From d255c1c986da036c85ebf0a3b11e3bcc7a86ac9a Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Tue, 15 Nov 2022 17:39:46 +0800 Subject: [PATCH 04/19] feat: support editor mac platform --- .../platform/editor/mac/EditorMacPlatform.mm | 1 + .../platform/editor/mac/EditorMacScene.mm | 56 ----------- .../platform/editor/mac/EditorMacWindow.mm | 93 ------------------- native/cocos/platform/editor/mac/Game.h | 42 +++++++++ native/cocos/platform/editor/windows/Game.cpp | 34 +++---- native/cocos/platform/editor/windows/Game.h | 42 +++++++++ native/cocos/platform/mac/modules/Screen.mm | 8 ++ .../platform/mac/modules/SystemWindow.mm | 22 ++++- 8 files changed, 126 insertions(+), 172 deletions(-) delete mode 100644 native/cocos/platform/editor/mac/EditorMacScene.mm delete mode 100644 native/cocos/platform/editor/mac/EditorMacWindow.mm create mode 100644 native/cocos/platform/editor/mac/Game.h create mode 100644 native/cocos/platform/editor/windows/Game.h diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.mm b/native/cocos/platform/editor/mac/EditorMacPlatform.mm index da66b3d5926..5427e041dea 100644 --- a/native/cocos/platform/editor/mac/EditorMacPlatform.mm +++ b/native/cocos/platform/editor/mac/EditorMacPlatform.mm @@ -114,6 +114,7 @@ - (void)renderScene { int32_t MacPlatform::loop(void) { runTask(); + return 1; } int32_t MacPlatform::run(int argc, const char **argv) { diff --git a/native/cocos/platform/editor/mac/EditorMacScene.mm b/native/cocos/platform/editor/mac/EditorMacScene.mm deleted file mode 100644 index 556ce5744b3..00000000000 --- a/native/cocos/platform/editor/mac/EditorMacScene.mm +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - 重写getDevicePixelRatio方法 -*/ - -#include "platform/mac/modules/Screen.h" - -#import -#include -#include - -#include "base/Macros.h" -#include "cocos/bindings/jswrapper/SeApi.h" - -namespace cc { - -int Screen::getDPI() const { - NSScreen * screen = [NSScreen mainScreen]; - NSDictionary *description = [screen deviceDescription]; - NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; - CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); - - return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f); -} - -float Screen::getDevicePixelRatio() const { - return 1; -} - -void Screen::setKeepScreenOn(bool value) { - CC_UNUSED_PARAM(value); -} - -Screen::Orientation Screen::getDeviceOrientation() const { - return Orientation::PORTRAIT; -} - -Vec4 Screen::getSafeAreaEdge() const { - return cc::Vec4(); -} - -bool Screen::isDisplayStats() { - se::AutoHandleScope hs; - se::Value ret; - char commandBuf[100] = "cc.debug.isDisplayStats();"; - se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); - return ret.toBoolean(); -} - -void Screen::setDisplayStats(bool isShow) { - se::AutoHandleScope hs; - char commandBuf[100] = {0}; - sprintf(commandBuf, "cc.debug.setDisplayStats(%s);", isShow ? "true" : "false"); - se::ScriptEngine::getInstance()->evalString(commandBuf); -} - -} // namespace cc diff --git a/native/cocos/platform/editor/mac/EditorMacWindow.mm b/native/cocos/platform/editor/mac/EditorMacWindow.mm deleted file mode 100644 index 7a3e1a8c826..00000000000 --- a/native/cocos/platform/editor/mac/EditorMacWindow.mm +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ -#include "platform/mac/modules/SystemWindow.h" -#import -#import - -NSMutableDictionary *layerMap = [[NSMutableDictionary dictionary] retain]; -namespace cc { - - -SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle) - : _windowId(windowId) { - if (externalHandle) { - _windowHandle = reinterpret_cast(externalHandle); - } -} - -SystemWindow::~SystemWindow() = default; - -bool SystemWindow::createWindow(const char *title, - int w, int h, int flags) { - return createWindow(title, 0, 0, w, h, flags); -} - -bool SystemWindow::createWindow(const char *title, - int x, int y, int w, - int h, int flags) { - _width = w; - _height = h; - CAMetalLayer *layer = [[CAMetalLayer layer] retain]; - layer.pixelFormat = MTLPixelFormatBGRA8Unorm; - layer.frame = CGRectMake(0, 0, w, h); - [layer setAnchorPoint:CGPointMake(0.f, 0.f)]; - NSString *key = [NSString stringWithFormat:@"%u",_windowId]; - [layerMap setValue:layer forKey:key]; - return true; -} - -void SystemWindow::closeWindow() { - //id window = [[[NSApplication sharedApplication] delegate] getWindow]; - if (_window) { - [_window close]; - _window = nullptr; - } -} - -void SystemWindow::setCursorEnabled(bool value) { -} - -void SystemWindow::copyTextToClipboard(const std::string &text) { - NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; - [pasteboard clearContents]; - NSString *tmp = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding]; - [pasteboard setString:tmp forType:NSPasteboardTypeString]; -} - -uintptr_t SystemWindow::getWindowHandle() const { - NSString *key = [NSString stringWithFormat:@"%u",_windowId]; - CAMetalLayer *layer = [layerMap valueForKey:key]; - return reinterpret_cast(layer); -} - -SystemWindow::Size SystemWindow::getViewSize() const { - return Size{static_cast(_width), static_cast(_height)}; -} - -uint32_t SystemWindow::getWindowId() const { - return _windowId; -} - -} diff --git a/native/cocos/platform/editor/mac/Game.h b/native/cocos/platform/editor/mac/Game.h new file mode 100644 index 00000000000..efe80cfe2ae --- /dev/null +++ b/native/cocos/platform/editor/mac/Game.h @@ -0,0 +1,42 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#pragma once + +#include "cocos/cocos.h" + + /** + @brief The cocos2d Application. + + The reason for implement as private inheritance is to hide some interface call by Director. + */ +class Game : public cc::BaseGame { +public: + Game(); + int init() override; + //bool init() override; + void onPause() override; + void onResume() override; + void onClose() override; +}; diff --git a/native/cocos/platform/editor/windows/Game.cpp b/native/cocos/platform/editor/windows/Game.cpp index e02de6ad146..72ef2475dcf 100644 --- a/native/cocos/platform/editor/windows/Game.cpp +++ b/native/cocos/platform/editor/windows/Game.cpp @@ -22,14 +22,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "cocos/application/BaseGame.h" +#include "Game.h" #include "cocos/application/ApplicationManager.h" -#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" +#include "cocos/application/BaseGame.h" #include "cocos/platform/interfaces/modules/ISystemWindow.h" #include "cocos/platform/interfaces/modules/ISystemWindowManager.h" +#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) -#include "windows.h" + #include "windows.h" #endif extern "C" void cc_load_all_plugins(); // NOLINT @@ -37,16 +38,6 @@ extern "C" void cc_load_all_plugins(); // NOLINT using namespace std; using namespace cc; -class Game : public cc::BaseGame { -public: - Game(); - int init() override; - //bool init() override; - void onPause() override; - void onResume() override; - void onClose() override; -}; - Game::Game() { } @@ -62,27 +53,27 @@ int Game::init() { _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | - ISystemWindow::CC_WINDOW_RESIZABLE | - ISystemWindow::CC_WINDOW_INPUT_FOCUS| - ISystemWindow::CC_WINDOW_HIDDEN - : _windowInfo.flags; + ISystemWindow::CC_WINDOW_RESIZABLE | + ISystemWindow::CC_WINDOW_INPUT_FOCUS | + ISystemWindow::CC_WINDOW_HIDDEN + : _windowInfo.flags; std::call_once(_windowCreateFlag, [&]() { ISystemWindowInfo info; info.title = _windowInfo.title; -#if CC_PLATFORM == CC_PLATFORM_WINDOWS + #if CC_PLATFORM == CC_PLATFORM_WINDOWS info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above -#else + #else info.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; info.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; -#endif + #endif info.width = _windowInfo.width; info.height = _windowInfo.height; info.flags = _windowInfo.flags; ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(ISystemWindowManager); windowMgr->createWindow(info); - }); + }); #endif @@ -112,5 +103,4 @@ void Game::onClose() { cc::CocosApplication::onClose(); } - CC_REGISTER_APPLICATION(Game); diff --git a/native/cocos/platform/editor/windows/Game.h b/native/cocos/platform/editor/windows/Game.h new file mode 100644 index 00000000000..efe80cfe2ae --- /dev/null +++ b/native/cocos/platform/editor/windows/Game.h @@ -0,0 +1,42 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#pragma once + +#include "cocos/cocos.h" + + /** + @brief The cocos2d Application. + + The reason for implement as private inheritance is to hide some interface call by Director. + */ +class Game : public cc::BaseGame { +public: + Game(); + int init() override; + //bool init() override; + void onPause() override; + void onResume() override; + void onClose() override; +}; diff --git a/native/cocos/platform/mac/modules/Screen.mm b/native/cocos/platform/mac/modules/Screen.mm index fcedd5b18f8..c6736a492ef 100644 --- a/native/cocos/platform/mac/modules/Screen.mm +++ b/native/cocos/platform/mac/modules/Screen.mm @@ -44,7 +44,15 @@ of this software and associated engine source code (the "Software"), a limited, } float Screen::getDevicePixelRatio() const { +#if CC_EDITOR + se::AutoHandleScope hs; + se::Value ret; + char commandBuf[100] = "window.devicePixelRatio"; + se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); + return ret.isNumber() ? ret.toFloat() : 1; +#else return [[[[NSApplication sharedApplication] delegate] getWindow] backingScaleFactor]; +#endif } void Screen::setKeepScreenOn(bool value) { diff --git a/native/cocos/platform/mac/modules/SystemWindow.mm b/native/cocos/platform/mac/modules/SystemWindow.mm index d6dde3f50fe..7e94853cca4 100644 --- a/native/cocos/platform/mac/modules/SystemWindow.mm +++ b/native/cocos/platform/mac/modules/SystemWindow.mm @@ -25,10 +25,15 @@ of this software and associated engine source code (the "Software"), a limited, #include "platform/mac/modules/SystemWindow.h" #import -#include "platform/mac/AppDelegate.h" #include "platform/BasePlatform.h" #include "platform/interfaces/modules/IScreen.h" +#if CC_EDITOR +#import +#else +#include "platform/mac/AppDelegate.h" +#endif + namespace cc { SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle) @@ -42,6 +47,9 @@ of this software and associated engine source code (the "Software"), a limited, bool SystemWindow::createWindow(const char *title, int w, int h, int flags) { +#if CC_EDITOR + return createWindow(title, 0, 0, w, h, flags); +#else AppDelegate *delegate = [[NSApplication sharedApplication] delegate]; NSString *aString = [NSString stringWithUTF8String:title]; _window = [delegate createLeftBottomWindow:aString width:w height:h]; @@ -52,11 +60,22 @@ of this software and associated engine source code (the "Software"), a limited, _width = w * dpr; _height = h * dpr; return true; +#endif } bool SystemWindow::createWindow(const char *title, int x, int y, int w, int h, int flags) { +#if CC_EDITOR + _width = w; + _height = h; + CAMetalLayer *layer = [[CAMetalLayer layer] retain]; + layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + layer.frame = CGRectMake(x, y, w, h); + [layer setAnchorPoint:CGPointMake(0.f, 0.f)]; + _windowHandle = reinterpret_cast(layer); + return true; +#else AppDelegate *delegate = [[NSApplication sharedApplication] delegate]; NSString *aString = [NSString stringWithUTF8String:title]; _window = [delegate createWindow:aString xPos:x yPos:y width:w height:h]; @@ -67,6 +86,7 @@ of this software and associated engine source code (the "Software"), a limited, _width = w * dpr; _height = h * dpr; return true; +#endif } void SystemWindow::closeWindow() { From 598a5e2f7aba817a4fd8d2d8e41efb25b8645846 Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Tue, 15 Nov 2022 17:53:52 +0800 Subject: [PATCH 05/19] update cmakelist --- native/CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 9308f88d4cb..46b2945d9b7 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -511,6 +511,7 @@ if(WINDOWS) cocos/platform/editor/windows/EditorWindowsPlatform.cpp cocos/platform/win32/WindowsPlatform.h cocos/platform/editor/windows/Game.cpp + cocos/platform/editor/windows/Game.h ) else() cocos_source_files( @@ -538,19 +539,21 @@ elseif(MACOSX) cocos_source_files( cocos/platform/editor/mac/EditorMacPlatform.mm cocos/platform/editor/mac/Game.mm - cocos/platform/editor/mac/EditorMacScene.mm - cocos/platform/editor/mac/EditorMacWindow.mm + cocos/platform/editor/mac/Game.h ) else() cocos_source_files( cocos/platform/mac/MacPlatform.mm - cocos/platform/mac/MacPlatform.h - cocos/platform/mac/ViewController.h - cocos/platform/mac/ViewController.mm - cocos/platform/mac/AppDelegate.h - cocos/platform/mac/AppDelegate.mm ) endif() + cocos_source_files( + cocos/platform/mac/MacPlatform.h + cocos/platform/mac/ViewController.h + cocos/platform/mac/ViewController.mm + cocos/platform/mac/AppDelegate.h + cocos/platform/mac/AppDelegate.mm + ) + elseif(IOS) cocos_source_files( cocos/platform/ios/IOSPlatform.mm From 3481e6f74af3287e6dd04263bc6906c85e52f6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Tue, 15 Nov 2022 19:51:00 +0800 Subject: [PATCH 06/19] fix:adapter object.cpp for editor --- native/cocos/bindings/jswrapper/v8/Object.cpp | 61 ++++++++++++++++--- .../editor/windows/EditorWindowsPlatform.cpp | 6 +- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 7a6c0ace6ad..2db18e3b4a5 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -27,6 +27,10 @@ #include "Object.h" #include "v8/HelperMacros.h" +#if CC_EDITOR +#include +#endif + #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8 #include "../MappingUtils.h" #include "Class.h" @@ -217,11 +221,18 @@ Object *Object::createArrayObject(size_t length) { } Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { +#if CC_EDITOR + auto nsBuffer = node::Buffer::New(__isolate, byteLength); + char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); +#else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); + char *srcData = jsobj->GetBackingStore()->Data(); + #endif if (data) { - memcpy(jsobj->GetBackingStore()->Data(), data, byteLength); + memcpy(srcData, data, byteLength); } else { - memset(jsobj->GetBackingStore()->Data(), 0, byteLength); + memset(srcData, 0, byteLength); } Object *obj = Object::_createJSObject(nullptr, jsobj); return obj; @@ -229,9 +240,19 @@ Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { /* static */ Object *Object::createExternalArrayBufferObject(void *contents, size_t byteLength, BufferContentsFreeFunc freeFunc, void *freeUserData /* = nullptr*/) { - std::shared_ptr backingStore = v8::ArrayBuffer::NewBackingStore(contents, byteLength, freeFunc, freeUserData); + Object *obj = nullptr; +#if CC_EDITOR + auto nsBuffer = node::Buffer::New( + __isolate, (char *)contents, byteLength, [](char *data, void *hint) {}, nullptr) + .ToLocalChecked() + .As(); + v8::Local jsobj = nsBuffer.As()->Buffer(); +#else + std::shared_ptr backingStore = v8::ArrayBuffer::NewBackingStore(contents, byteLength, freeFunc, freeUserData); v8::Local jsobj = v8::ArrayBuffer::New(__isolate, backingStore); +#endif + if (!jsobj.IsEmpty()) { obj = Object::_createJSObject(nullptr, jsobj); } @@ -248,13 +269,20 @@ Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t b SE_LOGE("Doesn't support to create Uint8ClampedArray with Object::createTypedArray API!"); return nullptr; } - +#if CC_EDITOR + auto nsBuffer = node::Buffer::New(__isolate, byteLength); + char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); +#else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); + char *srcData = jsobj->GetBackingStore()->Data(); +#endif + // If data has content,then will copy data into buffer,or will only clear buffer. if (data) { - memcpy(jsobj->GetBackingStore()->Data(), data, byteLength); + memcpy(srcData, data, byteLength); } else { - memset(jsobj->GetBackingStore()->Data(), 0, byteLength); + memset(srcData, 0, byteLength); } v8::Local arr; @@ -555,12 +583,21 @@ Object::TypedArrayType Object::getTypedArrayType() const { bool Object::getTypedArrayData(uint8_t **ptr, size_t *length) const { CC_ASSERT(isTypedArray()); v8::Local obj = const_cast(this)->_obj.handle(__isolate); +#if CC_EDITOR + char *data = node::Buffer::Data(obj); + *ptr = reinterpret_cast(data); + if (length) { + *length = node::Buffer::Length(obj); + } + #else v8::Local arr = v8::Local::Cast(obj); const auto &backingStore = arr->Buffer()->GetBackingStore(); *ptr = static_cast(backingStore->Data()) + arr->ByteOffset(); if (length) { *length = arr->ByteLength(); } +#endif + return true; } @@ -571,6 +608,16 @@ bool Object::isArrayBuffer() const { bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { CC_ASSERT(isArrayBuffer()); +#if CC_EDITOR + v8::Local jsobj = _getJSObject().As(); + auto obj = v8::Int8Array::New(jsobj, 0, jsobj->ByteLength()); + char *data = node::Buffer::Data(obj.As()); + *ptr = reinterpret_cast(data); + if (length) { + //*length = backingStore->ByteLength(); + *length = node::Buffer::Length(obj.As()); + } +#else v8::Local obj = const_cast(this)->_obj.handle(__isolate); v8::Local arrBuf = v8::Local::Cast(obj); const auto &backingStore = arrBuf->GetBackingStore(); @@ -578,7 +625,7 @@ bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { if (length) { *length = backingStore->ByteLength(); } - +#endif return true; } diff --git a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp index 8ea4eb5c50b..b4f28a3967d 100644 --- a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp +++ b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp @@ -115,12 +115,8 @@ namespace cc { } int32_t WindowsPlatform::loop() { - for (size_t i = 0; i < 5; i++) - { - _windowManager->processEvent(&_quit); - } + _windowManager->processEvent(&_quit); runTask(); - _windowManager->swapWindows(); return 0; } From f360b29a0955dbe9af0a17553e9aebc51e80e5bc Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Tue, 15 Nov 2022 20:31:32 +0800 Subject: [PATCH 07/19] clang-format --- native/CMakeLists.txt | 4 +- native/cocos/bindings/jswrapper/v8/Object.cpp | 37 +++-- native/cocos/platform/editor/{mac => }/Game.h | 0 .../platform/editor/mac/EditorMacPlatform.mm | 11 +- native/cocos/platform/editor/mac/Game.mm | 87 +++++------ .../editor/windows/EditorWindowsPlatform.cpp | 136 +++++++++--------- native/cocos/platform/editor/windows/Game.cpp | 2 +- native/cocos/platform/editor/windows/Game.h | 42 ------ .../renderer/gfx-gles3/GLES3Wrangler.cpp | 8 +- 9 files changed, 140 insertions(+), 187 deletions(-) rename native/cocos/platform/editor/{mac => }/Game.h (100%) delete mode 100644 native/cocos/platform/editor/windows/Game.h diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 46b2945d9b7..7e9e2401c9a 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -511,7 +511,7 @@ if(WINDOWS) cocos/platform/editor/windows/EditorWindowsPlatform.cpp cocos/platform/win32/WindowsPlatform.h cocos/platform/editor/windows/Game.cpp - cocos/platform/editor/windows/Game.h + cocos/platform/editor/Game.h ) else() cocos_source_files( @@ -539,7 +539,7 @@ elseif(MACOSX) cocos_source_files( cocos/platform/editor/mac/EditorMacPlatform.mm cocos/platform/editor/mac/Game.mm - cocos/platform/editor/mac/Game.h + cocos/platform/editor/Game.h ) else() cocos_source_files( diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 2db18e3b4a5..2f2dfff6724 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -27,8 +27,8 @@ #include "Object.h" #include "v8/HelperMacros.h" -#if CC_EDITOR -#include +#if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS + #include #endif #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8 @@ -221,11 +221,11 @@ Object *Object::createArrayObject(size_t length) { } Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { -#if CC_EDITOR + #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); -#else + #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); char *srcData = jsobj->GetBackingStore()->Data(); #endif @@ -240,19 +240,18 @@ Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { /* static */ Object *Object::createExternalArrayBufferObject(void *contents, size_t byteLength, BufferContentsFreeFunc freeFunc, void *freeUserData /* = nullptr*/) { - Object *obj = nullptr; -#if CC_EDITOR + #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New( __isolate, (char *)contents, byteLength, [](char *data, void *hint) {}, nullptr) .ToLocalChecked() .As(); v8::Local jsobj = nsBuffer.As()->Buffer(); -#else + #else std::shared_ptr backingStore = v8::ArrayBuffer::NewBackingStore(contents, byteLength, freeFunc, freeUserData); v8::Local jsobj = v8::ArrayBuffer::New(__isolate, backingStore); -#endif - + #endif + if (!jsobj.IsEmpty()) { obj = Object::_createJSObject(nullptr, jsobj); } @@ -269,15 +268,15 @@ Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t b SE_LOGE("Doesn't support to create Uint8ClampedArray with Object::createTypedArray API!"); return nullptr; } -#if CC_EDITOR + #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); -#else + #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); char *srcData = jsobj->GetBackingStore()->Data(); -#endif - + #endif + // If data has content,then will copy data into buffer,or will only clear buffer. if (data) { memcpy(srcData, data, byteLength); @@ -583,20 +582,20 @@ Object::TypedArrayType Object::getTypedArrayType() const { bool Object::getTypedArrayData(uint8_t **ptr, size_t *length) const { CC_ASSERT(isTypedArray()); v8::Local obj = const_cast(this)->_obj.handle(__isolate); -#if CC_EDITOR + #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS char *data = node::Buffer::Data(obj); *ptr = reinterpret_cast(data); if (length) { *length = node::Buffer::Length(obj); } - #else + #else v8::Local arr = v8::Local::Cast(obj); const auto &backingStore = arr->Buffer()->GetBackingStore(); *ptr = static_cast(backingStore->Data()) + arr->ByteOffset(); if (length) { *length = arr->ByteLength(); } -#endif + #endif return true; } @@ -608,7 +607,7 @@ bool Object::isArrayBuffer() const { bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { CC_ASSERT(isArrayBuffer()); -#if CC_EDITOR + #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS v8::Local jsobj = _getJSObject().As(); auto obj = v8::Int8Array::New(jsobj, 0, jsobj->ByteLength()); char *data = node::Buffer::Data(obj.As()); @@ -617,7 +616,7 @@ bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { //*length = backingStore->ByteLength(); *length = node::Buffer::Length(obj.As()); } -#else + #else v8::Local obj = const_cast(this)->_obj.handle(__isolate); v8::Local arrBuf = v8::Local::Cast(obj); const auto &backingStore = arrBuf->GetBackingStore(); @@ -625,7 +624,7 @@ bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { if (length) { *length = backingStore->ByteLength(); } -#endif + #endif return true; } diff --git a/native/cocos/platform/editor/mac/Game.h b/native/cocos/platform/editor/Game.h similarity index 100% rename from native/cocos/platform/editor/mac/Game.h rename to native/cocos/platform/editor/Game.h diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.mm b/native/cocos/platform/editor/mac/EditorMacPlatform.mm index 5427e041dea..26813dbecb7 100644 --- a/native/cocos/platform/editor/mac/EditorMacPlatform.mm +++ b/native/cocos/platform/editor/mac/EditorMacPlatform.mm @@ -23,9 +23,9 @@ of this software and associated engine source code (the "Software"), a limited, THE SOFTWARE. ****************************************************************************/ -#include "platform/mac/MacPlatform.h" #include "platform/interfaces/OSInterface.h" #include "platform/mac/AppDelegate.h" +#include "platform/mac/MacPlatform.h" #include "modules/Accelerometer.h" #include "modules/Battery.h" @@ -49,7 +49,7 @@ of this software and associated engine source code (the "Software"), a limited, @interface MyTimer : NSObject { cc::MacPlatform *_platform; -// NSTimer *_timer; + // NSTimer *_timer; } - (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps; - (void)start; @@ -72,7 +72,6 @@ - (void)start { } - (void)pause { - } - (void)resume { @@ -97,11 +96,9 @@ - (void)renderScene { namespace cc { MacPlatform::~MacPlatform() { - } int32_t MacPlatform::init() { - registerInterface(std::make_shared()); registerInterface(std::make_shared()); registerInterface(std::make_shared()); @@ -132,20 +129,18 @@ - (void)renderScene { } void MacPlatform::setFps(int32_t fps) { - if(fps != getFps()) { + if (fps != getFps()) { UniversalPlatform::setFps(fps); } } void MacPlatform::onPause() { - cc::WindowEvent ev; ev.type = cc::WindowEvent::Type::HIDDEN; cc::events::WindowEvent::broadcast(ev); } void MacPlatform::onResume() { - cc::WindowEvent ev; ev.type = cc::WindowEvent::Type::SHOW; cc::events::WindowEvent::broadcast(ev); diff --git a/native/cocos/platform/editor/mac/Game.mm b/native/cocos/platform/editor/mac/Game.mm index 9554a9cc8b6..85269c8e675 100644 --- a/native/cocos/platform/editor/mac/Game.mm +++ b/native/cocos/platform/editor/mac/Game.mm @@ -22,14 +22,15 @@ of this software and associated engine source code (the "Software"), a limited, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "Game.h" +#include "../Game.h" #include "FileUtils.h" -#include "renderer/pipeline/GlobalDescriptorSetManager.h" -#include "platform/interfaces/modules/ISystemWindowManager.h" #include "cocos/application/ApplicationManager.h" +#include "platform/interfaces/modules/ISystemWindowManager.h" +#include "renderer/pipeline/GlobalDescriptorSetManager.h" + #ifndef GAME_NAME -#define GAME_NAME "CocosGame"; + #define GAME_NAME "CocosGame"; #endif extern std::string SearchPath; extern "C" void cc_load_all_plugins(); @@ -38,45 +39,45 @@ of this software and associated engine source code (the "Software"), a limited, int Game::init() { cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); - cc_load_all_plugins(); - - #if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS - // override default value - //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; - //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; - _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; - _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; - _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | - cc::ISystemWindow::CC_WINDOW_RESIZABLE | - cc::ISystemWindow::CC_WINDOW_INPUT_FOCUS - : _windowInfo.flags; - std::call_once(_windowCreateFlag, [&]() { - cc::ISystemWindowInfo info; - info.title = _windowInfo.title; - info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now - info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above - info.width = _windowInfo.width; - info.height = _windowInfo.height; - info.flags = _windowInfo.flags; - - cc::ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(cc::ISystemWindowManager); - windowMgr->createWindow(info); - }); - - #endif - - if (_debuggerInfo.enabled) { - setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); - } - - int ret = cc::CocosApplication::init(); - if (ret != 0) { - return ret; - } - - setXXTeaKey(_xxteaKey); -// runScript("jsb-adapter/web-adapter.js"); -// runScript("main.js"); + cc_load_all_plugins(); + +#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS + // override default value + //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; + //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; + _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; + _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; + _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | + cc::ISystemWindow::CC_WINDOW_RESIZABLE | + cc::ISystemWindow::CC_WINDOW_INPUT_FOCUS + : _windowInfo.flags; + std::call_once(_windowCreateFlag, [&]() { + cc::ISystemWindowInfo info; + info.title = _windowInfo.title; + info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now + info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above + info.width = _windowInfo.width; + info.height = _windowInfo.height; + info.flags = _windowInfo.flags; + + cc::ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(cc::ISystemWindowManager); + windowMgr->createWindow(info); + }); + +#endif + + if (_debuggerInfo.enabled) { + setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); + } + + int ret = cc::CocosApplication::init(); + if (ret != 0) { + return ret; + } + + setXXTeaKey(_xxteaKey); + // runScript("jsb-adapter/web-adapter.js"); + // runScript("main.js"); return 0; } diff --git a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp index b4f28a3967d..50d5deddb15 100644 --- a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp +++ b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp @@ -35,93 +35,93 @@ #include "cocos/platform/win32/modules/Network.h" #include "cocos/platform/win32/modules/System.h" #if defined(CC_SERVER_MODE) -#include "platform/empty/modules/Screen.h" -#include "platform/empty/modules/SystemWindow.h" + #include "platform/empty/modules/Screen.h" + #include "platform/empty/modules/SystemWindow.h" #else -#include "cocos/platform/win32/modules/Screen.h" -#include "cocos/platform/win32/modules/SystemWindow.h" + #include "cocos/platform/win32/modules/Screen.h" + #include "cocos/platform/win32/modules/SystemWindow.h" #endif #include "base/memory/Memory.h" #include "cocos/platform/win32/modules/Vibrator.h" namespace { - /** - @brief This function changes the PVRFrame show/hide setting in register. - @param bEnable If true show the PVRFrame window, otherwise hide. - */ - void PVRFrameEnableControlWindow(bool bEnable) { - HKEY hKey = 0; - - // Open PVRFrame control key, if not exist create it. - if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, - L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", - 0, - 0, - REG_OPTION_NON_VOLATILE, - KEY_ALL_ACCESS, - 0, - &hKey, - nullptr)) { - return; - } - - const WCHAR* wszValue = L"hide_gui"; - const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; - WCHAR wszOldData[256] = { 0 }; - DWORD dwSize = sizeof(wszOldData); - LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); - if (ERROR_FILE_NOT_FOUND == status // the key not exist - || (ERROR_SUCCESS == status // or the hide_gui value is exist - && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal - { - dwSize = static_cast(sizeof(WCHAR) * (wcslen(wszNewData) + 1)); - RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); - } - - RegCloseKey(hKey); +/** + @brief This function changes the PVRFrame show/hide setting in register. + @param bEnable If true show the PVRFrame window, otherwise hide. +*/ +void PVRFrameEnableControlWindow(bool bEnable) { + HKEY hKey = 0; + + // Open PVRFrame control key, if not exist create it. + if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, + L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", + 0, + 0, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + 0, + &hKey, + nullptr)) { + return; } + const WCHAR* wszValue = L"hide_gui"; + const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; + WCHAR wszOldData[256] = {0}; + DWORD dwSize = sizeof(wszOldData); + LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); + if (ERROR_FILE_NOT_FOUND == status // the key not exist + || (ERROR_SUCCESS == status // or the hide_gui value is exist + && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal + { + dwSize = static_cast(sizeof(WCHAR) * (wcslen(wszNewData) + 1)); + RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); + } + + RegCloseKey(hKey); +} + } // namespace namespace cc { - WindowsPlatform::WindowsPlatform() { - } - WindowsPlatform::~WindowsPlatform() { +WindowsPlatform::WindowsPlatform() { +} +WindowsPlatform::~WindowsPlatform() { #ifdef USE_WIN32_CONSOLE - FreeConsole(); + FreeConsole(); #endif - } - - int32_t WindowsPlatform::init() { - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - _windowManager = std::make_shared(); - registerInterface(_windowManager); - registerInterface(std::make_shared()); +} + +int32_t WindowsPlatform::init() { + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + registerInterface(std::make_shared()); + _windowManager = std::make_shared(); + registerInterface(_windowManager); + registerInterface(std::make_shared()); #ifdef USE_WIN32_CONSOLE - AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); #endif - PVRFrameEnableControlWindow(false); + PVRFrameEnableControlWindow(false); - return _windowManager->init(); - } + return _windowManager->init(); +} - int32_t WindowsPlatform::loop() { - _windowManager->processEvent(&_quit); - runTask(); - return 0; - } +int32_t WindowsPlatform::loop() { + _windowManager->processEvent(&_quit); + runTask(); + return 0; +} - ISystemWindow* WindowsPlatform::createNativeWindow(uint32_t windowId, void* externalHandle) { - return ccnew SystemWindow(windowId, externalHandle); - } +ISystemWindow* WindowsPlatform::createNativeWindow(uint32_t windowId, void* externalHandle) { + return ccnew SystemWindow(windowId, externalHandle); +} } // namespace cc diff --git a/native/cocos/platform/editor/windows/Game.cpp b/native/cocos/platform/editor/windows/Game.cpp index 72ef2475dcf..e522b2e9cb6 100644 --- a/native/cocos/platform/editor/windows/Game.cpp +++ b/native/cocos/platform/editor/windows/Game.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "Game.h" +#include "../Game.h" #include "cocos/application/ApplicationManager.h" #include "cocos/application/BaseGame.h" #include "cocos/platform/interfaces/modules/ISystemWindow.h" diff --git a/native/cocos/platform/editor/windows/Game.h b/native/cocos/platform/editor/windows/Game.h deleted file mode 100644 index efe80cfe2ae..00000000000 --- a/native/cocos/platform/editor/windows/Game.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#pragma once - -#include "cocos/cocos.h" - - /** - @brief The cocos2d Application. - - The reason for implement as private inheritance is to hide some interface call by Director. - */ -class Game : public cc::BaseGame { -public: - Game(); - int init() override; - //bool init() override; - void onPause() override; - void onResume() override; - void onClose() override; -}; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 94b36f21a78..7e8dbf460a2 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -24,8 +24,8 @@ ****************************************************************************/ #include "GLES3Wrangler.h" -#include "base/Log.h" #include +#include "base/Log.h" #if defined(_WIN32) && !defined(ANDROID) #define WIN32_LEAN_AND_MEAN 1 @@ -39,8 +39,8 @@ bool gles3wOpen() { std::string eglPath = "libEGL.dll"; std::string glesPath = "libGLESv2.dll"; -#if CC_EDITOR - // in editor,thers are same dlls,so we need to use abs path. + #if CC_EDITOR + // In editor,there are same library,so we need to use abs path to load them. char dllPath[MAX_PATH]; HMODULE engine = NULL; if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | @@ -55,7 +55,7 @@ bool gles3wOpen() { int err = GetLastError(); CC_LOG_WARNING("Failed to get abs path for editor,error code:%d", err); } -#endif + #endif libegl = LoadLibraryA(eglPath.c_str()); libgles = LoadLibraryA(glesPath.c_str()); From 62bb25659b827f6cb03dd4d6f9ecbe7d76700e97 Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Tue, 15 Nov 2022 20:56:10 +0800 Subject: [PATCH 08/19] fix type error --- native/cocos/bindings/jswrapper/v8/Object.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 2f2dfff6724..15b2bf1e1a1 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -223,11 +223,11 @@ Object *Object::createArrayObject(size_t length) { Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); - char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + auto srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); - char *srcData = jsobj->GetBackingStore()->Data(); + auto srcData = jsobj->GetBackingStore()->Data(); #endif if (data) { memcpy(srcData, data, byteLength); @@ -270,11 +270,11 @@ Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t b } #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); - char *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + auto srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); - char *srcData = jsobj->GetBackingStore()->Data(); + auto srcData = jsobj->GetBackingStore()->Data(); #endif // If data has content,then will copy data into buffer,or will only clear buffer. From dc4702e28da35353106baef6fba1feb71819aa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Tue, 15 Nov 2022 21:11:04 +0800 Subject: [PATCH 09/19] fix for pull request --- native/CMakeLists.txt | 3 +-- native/cocos/bindings/jswrapper/v8/Object.cpp | 1 + native/cocos/renderer/GFXDeviceManager.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 7e9e2401c9a..6a58ab0b083 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -552,8 +552,7 @@ elseif(MACOSX) cocos/platform/mac/ViewController.mm cocos/platform/mac/AppDelegate.h cocos/platform/mac/AppDelegate.mm - ) - + ) elseif(IOS) cocos_source_files( cocos/platform/ios/IOSPlatform.mm diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 15b2bf1e1a1..c5878dac680 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -27,6 +27,7 @@ #include "Object.h" #include "v8/HelperMacros.h" +// Use node::Buffer to replace v8 api,to avoid link err in editor platform. #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS #include #endif diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index 45f28e1e864..8844f7484a1 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -62,7 +62,7 @@ namespace cc { namespace gfx { class CC_DLL DeviceManager final { - static constexpr bool DETACH_DEVICE_THREAD{false}; + static constexpr bool DETACH_DEVICE_THREAD{true}; static constexpr bool FORCE_DISABLE_VALIDATION{false}; static constexpr bool FORCE_ENABLE_VALIDATION{false}; From 30b66af36c25874aaa166fb7eb1cc9f76d314b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 11:43:32 +0800 Subject: [PATCH 10/19] fix for pr:remove platform code,use cc_editor marco;fix clang tidy --- native/CMakeLists.txt | 25 +-- native/cocos/bindings/jswrapper/v8/Object.cpp | 8 +- .../editor/{Game.h => EditorApplication.h} | 6 +- .../mac/{Game.mm => EditorApplication.mm} | 14 +- .../platform/editor/mac/EditorMacPlatform.mm | 159 ------------------ .../{Game.cpp => EditorApplication.cpp} | 14 +- .../editor/windows/EditorWindowsPlatform.cpp | 127 -------------- native/cocos/platform/mac/MacPlatform.mm | 14 +- .../cocos/platform/win32/WindowsPlatform.cpp | 5 + 9 files changed, 47 insertions(+), 325 deletions(-) rename native/cocos/platform/editor/{Game.h => EditorApplication.h} (91%) rename native/cocos/platform/editor/mac/{Game.mm => EditorApplication.mm} (90%) delete mode 100644 native/cocos/platform/editor/mac/EditorMacPlatform.mm rename native/cocos/platform/editor/windows/{Game.cpp => EditorApplication.cpp} (91%) delete mode 100644 native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 6a58ab0b083..314e3630253 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -508,17 +508,14 @@ cocos_source_files( if(WINDOWS) if(CC_EDITOR) cocos_source_files( - cocos/platform/editor/windows/EditorWindowsPlatform.cpp - cocos/platform/win32/WindowsPlatform.h - cocos/platform/editor/windows/Game.cpp - cocos/platform/editor/Game.h - ) - else() - cocos_source_files( - cocos/platform/win32/WindowsPlatform.cpp - cocos/platform/win32/WindowsPlatform.h + cocos/platform/editor/windows/EditorApplication.cpp + cocos/platform/editor/EditorApplication.h ) endif() + cocos_source_files( + cocos/platform/win32/WindowsPlatform.cpp + cocos/platform/win32/WindowsPlatform.h + ) elseif(LINUX) cocos_source_files( cocos/platform/linux/LinuxPlatform.cpp @@ -537,16 +534,12 @@ elseif(OHOS) elseif(MACOSX) if(CC_EDITOR) cocos_source_files( - cocos/platform/editor/mac/EditorMacPlatform.mm - cocos/platform/editor/mac/Game.mm - cocos/platform/editor/Game.h - ) - else() - cocos_source_files( - cocos/platform/mac/MacPlatform.mm + cocos/platform/editor/mac/EditorApplication.mm + cocos/platform/editor/EditorApplication.h ) endif() cocos_source_files( + cocos/platform/mac/MacPlatform.mm cocos/platform/mac/MacPlatform.h cocos/platform/mac/ViewController.h cocos/platform/mac/ViewController.mm diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index c5878dac680..9aa92bb57c3 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -224,11 +224,11 @@ Object *Object::createArrayObject(size_t length) { Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); - auto srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + auto *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); - auto srcData = jsobj->GetBackingStore()->Data(); + auto *srcData = jsobj->GetBackingStore()->Data(); #endif if (data) { memcpy(srcData, data, byteLength); @@ -271,11 +271,11 @@ Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t b } #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS auto nsBuffer = node::Buffer::New(__isolate, byteLength); - auto srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); + auto *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); - auto srcData = jsobj->GetBackingStore()->Data(); + auto *srcData = jsobj->GetBackingStore()->Data(); #endif // If data has content,then will copy data into buffer,or will only clear buffer. diff --git a/native/cocos/platform/editor/Game.h b/native/cocos/platform/editor/EditorApplication.h similarity index 91% rename from native/cocos/platform/editor/Game.h rename to native/cocos/platform/editor/EditorApplication.h index efe80cfe2ae..8f56b482acb 100644 --- a/native/cocos/platform/editor/Game.h +++ b/native/cocos/platform/editor/EditorApplication.h @@ -24,16 +24,16 @@ ****************************************************************************/ #pragma once -#include "cocos/cocos.h" +#include "cocos/application/BaseGame.h" /** @brief The cocos2d Application. The reason for implement as private inheritance is to hide some interface call by Director. */ -class Game : public cc::BaseGame { +class EditorApplication : public cc::BaseGame { public: - Game(); + EditorApplication(); int init() override; //bool init() override; void onPause() override; diff --git a/native/cocos/platform/editor/mac/Game.mm b/native/cocos/platform/editor/mac/EditorApplication.mm similarity index 90% rename from native/cocos/platform/editor/mac/Game.mm rename to native/cocos/platform/editor/mac/EditorApplication.mm index 85269c8e675..ce856983ef3 100644 --- a/native/cocos/platform/editor/mac/Game.mm +++ b/native/cocos/platform/editor/mac/EditorApplication.mm @@ -22,7 +22,7 @@ of this software and associated engine source code (the "Software"), a limited, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "../Game.h" +#include "../EditorApplication.h" #include "FileUtils.h" #include "cocos/application/ApplicationManager.h" #include "platform/interfaces/modules/ISystemWindowManager.h" @@ -34,9 +34,9 @@ of this software and associated engine source code (the "Software"), a limited, #endif extern std::string SearchPath; extern "C" void cc_load_all_plugins(); -Game::Game() = default; +EditorApplication::EditorApplication() = default; -int Game::init() { +int EditorApplication::init() { cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); cc_load_all_plugins(); @@ -82,16 +82,16 @@ of this software and associated engine source code (the "Software"), a limited, return 0; } -void Game::onPause() { +void EditorApplication::onPause() { BaseGame::onPause(); } -void Game::onResume() { +void EditorApplication::onResume() { BaseGame::onResume(); } -void Game::onClose() { +void EditorApplication::onClose() { BaseGame::onClose(); } -CC_REGISTER_APPLICATION(Game); +CC_REGISTER_APPLICATION(EditorApplication); diff --git a/native/cocos/platform/editor/mac/EditorMacPlatform.mm b/native/cocos/platform/editor/mac/EditorMacPlatform.mm deleted file mode 100644 index 26813dbecb7..00000000000 --- a/native/cocos/platform/editor/mac/EditorMacPlatform.mm +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "platform/interfaces/OSInterface.h" -#include "platform/mac/AppDelegate.h" -#include "platform/mac/MacPlatform.h" - -#include "modules/Accelerometer.h" -#include "modules/Battery.h" -#include "modules/Network.h" -#include "modules/System.h" -#include "modules/Vibrator.h" - -#if defined(CC_SERVER_MODE) - #include "platform/empty/modules/Screen.h" - #include "platform/empty/modules/SystemWindow.h" -#else - #include "modules/Screen.h" - #include "modules/SystemWindow.h" - #include "modules/SystemWindowManager.h" -#endif - -#import -#include "base/memory/Memory.h" - -extern int cocos_main(int argc, const char **argv); - -@interface MyTimer : NSObject { - cc::MacPlatform *_platform; - // NSTimer *_timer; -} -- (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps; -- (void)start; -- (void)changeFPS; -- (void)pause; -- (void)resume; -@end - -@implementation MyTimer - -- (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps { - if (self = [super init]) { - _platform = platform; - } - return self; -} - -- (void)start { - int32_t fps = _platform->getFps(); -} - -- (void)pause { -} - -- (void)resume { - [self start]; -} - -- (void)changeFPS { - [self pause]; - [self resume]; -} - -- (void)renderScene { - _platform->runTask(); -} - -@end - -namespace { -MyTimer *_timer; -} - -namespace cc { - -MacPlatform::~MacPlatform() { -} - -int32_t MacPlatform::init() { - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - return 0; -} - -int32_t MacPlatform::loop(void) { - runTask(); - return 1; -} - -int32_t MacPlatform::run(int argc, const char **argv) { -#if defined(CC_SERVER_MODE) - cocos_main(argc, argv); - while (true) { - runTask(); - } - return 0; -#else - id delegate = [[AppDelegate alloc] init]; - NSApplication.sharedApplication.delegate = delegate; - return NSApplicationMain(argc, argv); -#endif -} - -void MacPlatform::setFps(int32_t fps) { - if (fps != getFps()) { - UniversalPlatform::setFps(fps); - } -} - -void MacPlatform::onPause() { - cc::WindowEvent ev; - ev.type = cc::WindowEvent::Type::HIDDEN; - cc::events::WindowEvent::broadcast(ev); -} - -void MacPlatform::onResume() { - cc::WindowEvent ev; - ev.type = cc::WindowEvent::Type::SHOW; - cc::events::WindowEvent::broadcast(ev); -} - -void MacPlatform::onClose() { - cc::WindowEvent ev; - ev.type = cc::WindowEvent::Type::CLOSE; - cc::events::WindowEvent::broadcast(ev); -} - -cc::ISystemWindow *MacPlatform::createNativeWindow(uint32_t windowId, void *externalHandle) { - return ccnew SystemWindow(windowId, externalHandle); -} - -} // namespace cc diff --git a/native/cocos/platform/editor/windows/Game.cpp b/native/cocos/platform/editor/windows/EditorApplication.cpp similarity index 91% rename from native/cocos/platform/editor/windows/Game.cpp rename to native/cocos/platform/editor/windows/EditorApplication.cpp index e522b2e9cb6..bd432c30097 100644 --- a/native/cocos/platform/editor/windows/Game.cpp +++ b/native/cocos/platform/editor/windows/EditorApplication.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "../Game.h" +#include "../EditorApplication.h" #include "cocos/application/ApplicationManager.h" #include "cocos/application/BaseGame.h" #include "cocos/platform/interfaces/modules/ISystemWindow.h" @@ -38,10 +38,10 @@ extern "C" void cc_load_all_plugins(); // NOLINT using namespace std; using namespace cc; -Game::Game() { +EditorApplication::EditorApplication() { } -int Game::init() { +int EditorApplication::init() { cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); cc_load_all_plugins(); @@ -91,16 +91,16 @@ int Game::init() { } // This function will be called when the app is inactive. When comes a phone call,it's be invoked too -void Game::onPause() { +void EditorApplication::onPause() { cc::CocosApplication::onPause(); } -void Game::onResume() { +void EditorApplication::onResume() { cc::CocosApplication::onResume(); } -void Game::onClose() { +void EditorApplication::onClose() { cc::CocosApplication::onClose(); } -CC_REGISTER_APPLICATION(Game); +CC_REGISTER_APPLICATION(EditorApplication); diff --git a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp b/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp deleted file mode 100644 index 50d5deddb15..00000000000 --- a/native/cocos/platform/editor/windows/EditorWindowsPlatform.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "platform/win32/WindowsPlatform.h" -#include "platform/win32/modules/SystemWindowManager.h" - -#include -#include -#include - -#include "cocos/platform/win32/modules/Accelerometer.h" -#include "cocos/platform/win32/modules/Battery.h" -#include "cocos/platform/win32/modules/Network.h" -#include "cocos/platform/win32/modules/System.h" -#if defined(CC_SERVER_MODE) - #include "platform/empty/modules/Screen.h" - #include "platform/empty/modules/SystemWindow.h" -#else - #include "cocos/platform/win32/modules/Screen.h" - #include "cocos/platform/win32/modules/SystemWindow.h" -#endif -#include "base/memory/Memory.h" -#include "cocos/platform/win32/modules/Vibrator.h" - -namespace { -/** - @brief This function changes the PVRFrame show/hide setting in register. - @param bEnable If true show the PVRFrame window, otherwise hide. -*/ -void PVRFrameEnableControlWindow(bool bEnable) { - HKEY hKey = 0; - - // Open PVRFrame control key, if not exist create it. - if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, - L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", - 0, - 0, - REG_OPTION_NON_VOLATILE, - KEY_ALL_ACCESS, - 0, - &hKey, - nullptr)) { - return; - } - - const WCHAR* wszValue = L"hide_gui"; - const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; - WCHAR wszOldData[256] = {0}; - DWORD dwSize = sizeof(wszOldData); - LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); - if (ERROR_FILE_NOT_FOUND == status // the key not exist - || (ERROR_SUCCESS == status // or the hide_gui value is exist - && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal - { - dwSize = static_cast(sizeof(WCHAR) * (wcslen(wszNewData) + 1)); - RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); - } - - RegCloseKey(hKey); -} - -} // namespace - -namespace cc { -WindowsPlatform::WindowsPlatform() { -} -WindowsPlatform::~WindowsPlatform() { -#ifdef USE_WIN32_CONSOLE - FreeConsole(); -#endif -} - -int32_t WindowsPlatform::init() { - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - registerInterface(std::make_shared()); - _windowManager = std::make_shared(); - registerInterface(_windowManager); - registerInterface(std::make_shared()); - -#ifdef USE_WIN32_CONSOLE - AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); -#endif - - PVRFrameEnableControlWindow(false); - - return _windowManager->init(); -} - -int32_t WindowsPlatform::loop() { - _windowManager->processEvent(&_quit); - runTask(); - return 0; -} - -ISystemWindow* WindowsPlatform::createNativeWindow(uint32_t windowId, void* externalHandle) { - return ccnew SystemWindow(windowId, externalHandle); -} - -} // namespace cc diff --git a/native/cocos/platform/mac/MacPlatform.mm b/native/cocos/platform/mac/MacPlatform.mm index d4eec5177aa..e4719f905f7 100644 --- a/native/cocos/platform/mac/MacPlatform.mm +++ b/native/cocos/platform/mac/MacPlatform.mm @@ -67,7 +67,12 @@ - (instancetype)initWithApp:(cc::MacPlatform *)platform fps:(int)fps { } return self; } - +#if CC_EDITOR + - (void)start { } + - (void)changeFPS { } + - (void)pause { } + - (void)resume { } +#else - (void)start { int32_t fps = _platform->getFps(); _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f / fps @@ -93,7 +98,7 @@ - (void)changeFPS { - (void)renderScene { _platform->runTask(); } - +#endif @end namespace { @@ -119,6 +124,10 @@ - (void)renderScene { } int32_t MacPlatform::loop(void) { +#if CC_EDITOR + runTask(); + return 1; +#else [_timer start]; NSArray *arguments = [[NSProcessInfo processInfo] arguments]; int argc = static_cast(arguments.count); @@ -129,6 +138,7 @@ - (void)renderScene { } return cocos_main(argc, argv.data()); +#endif } int32_t MacPlatform::run(int argc, const char **argv) { diff --git a/native/cocos/platform/win32/WindowsPlatform.cpp b/native/cocos/platform/win32/WindowsPlatform.cpp index 394fb4a7a9b..99e2fcfdcd1 100644 --- a/native/cocos/platform/win32/WindowsPlatform.cpp +++ b/native/cocos/platform/win32/WindowsPlatform.cpp @@ -115,6 +115,10 @@ int32_t WindowsPlatform::init() { } int32_t WindowsPlatform::loop() { +#if CC_EDITOR + _windowManager->processEvent(&_quit); + runTask(); +#else /////////////////////////////////////////////////////////////////////////// /////////////// changing timer resolution /////////////////////////////////////////////////////////////////////////// @@ -167,6 +171,7 @@ int32_t WindowsPlatform::loop() { timeEndPeriod(wTimerRes); onDestroy(); +#endif return 0; } From 2b50f7afbe6fc5427ab9183e0805f8661af601e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 11:52:01 +0800 Subject: [PATCH 11/19] Update native/cocos/platform/mac/modules/Screen.mm Co-authored-by: James Chen --- native/cocos/platform/mac/modules/Screen.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/native/cocos/platform/mac/modules/Screen.mm b/native/cocos/platform/mac/modules/Screen.mm index c6736a492ef..b1ea66b109a 100644 --- a/native/cocos/platform/mac/modules/Screen.mm +++ b/native/cocos/platform/mac/modules/Screen.mm @@ -48,7 +48,10 @@ of this software and associated engine source code (the "Software"), a limited, se::AutoHandleScope hs; se::Value ret; char commandBuf[100] = "window.devicePixelRatio"; - se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); +auto* global = se::ScriptEngine::getInstance()->getGlobalObject(); +se::Value devicePixelRatioVal; +global->getProperty("devicePixelRatio", &devicePixelRatioVal); +return devicePixelRatioVal.isNumber() ? devicePixelRatioVal.toFloat() : 1.F; return ret.isNumber() ? ret.toFloat() : 1; #else return [[[[NSApplication sharedApplication] delegate] getWindow] backingScaleFactor]; From 103ffb85b0467e1e3bff5deb55ee3ae4b053f509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 14:15:26 +0800 Subject: [PATCH 12/19] fix for pr: remove useless code,format code and handle path limit. --- native/cocos/bindings/jswrapper/v8/Object.cpp | 1 - native/cocos/platform/mac/modules/Screen.mm | 12 ++++-------- .../cocos/renderer/gfx-gles3/GLES3Wrangler.cpp | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 9aa92bb57c3..8695ab6fbf7 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -614,7 +614,6 @@ bool Object::getArrayBufferData(uint8_t **ptr, size_t *length) const { char *data = node::Buffer::Data(obj.As()); *ptr = reinterpret_cast(data); if (length) { - //*length = backingStore->ByteLength(); *length = node::Buffer::Length(obj.As()); } #else diff --git a/native/cocos/platform/mac/modules/Screen.mm b/native/cocos/platform/mac/modules/Screen.mm index b1ea66b109a..cad4ed26f44 100644 --- a/native/cocos/platform/mac/modules/Screen.mm +++ b/native/cocos/platform/mac/modules/Screen.mm @@ -45,14 +45,10 @@ of this software and associated engine source code (the "Software"), a limited, float Screen::getDevicePixelRatio() const { #if CC_EDITOR - se::AutoHandleScope hs; - se::Value ret; - char commandBuf[100] = "window.devicePixelRatio"; -auto* global = se::ScriptEngine::getInstance()->getGlobalObject(); -se::Value devicePixelRatioVal; -global->getProperty("devicePixelRatio", &devicePixelRatioVal); -return devicePixelRatioVal.isNumber() ? devicePixelRatioVal.toFloat() : 1.F; - return ret.isNumber() ? ret.toFloat() : 1; + auto* global = se::ScriptEngine::getInstance()->getGlobalObject(); + se::Value devicePixelRatioVal; + global->getProperty("devicePixelRatio", &devicePixelRatioVal); + return devicePixelRatioVal.isNumber() ? devicePixelRatioVal.toFloat() : 1.F; #else return [[[[NSApplication sharedApplication] delegate] getWindow] backingScaleFactor]; #endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 7e8dbf460a2..23d535f3130 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -26,6 +26,7 @@ #include "GLES3Wrangler.h" #include #include "base/Log.h" +#include "base/memory/Memory.h" #if defined(_WIN32) && !defined(ANDROID) #define WIN32_LEAN_AND_MEAN 1 @@ -41,13 +42,22 @@ bool gles3wOpen() { #if CC_EDITOR // In editor,there are same library,so we need to use abs path to load them. - char dllPath[MAX_PATH]; HMODULE engine = NULL; if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR)&gles3wOpen, &engine) != 0) { - GetModuleFileNameA(engine, dllPath, ARRAYSIZE(dllPath)); - std::string dir(dllPath); + std::string dir(""); + int times = 1; + do { + auto size = MAX_PATH * times++; + char *path = (char *)CC_MALLOC(size); + if (path) { + GetModuleFileNameA(engine, path, size); + dir = path; + } + CC_FREE(path); + } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER); + dir = dir.substr(0, dir.rfind("\\") + 1); eglPath = dir + eglPath; glesPath = dir + glesPath; From 7038fbb838b3b6f993f683537c57ba41a0d2f86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 14:17:02 +0800 Subject: [PATCH 13/19] add autoHandleScope back --- native/cocos/platform/mac/modules/Screen.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/platform/mac/modules/Screen.mm b/native/cocos/platform/mac/modules/Screen.mm index cad4ed26f44..6dab0eb254c 100644 --- a/native/cocos/platform/mac/modules/Screen.mm +++ b/native/cocos/platform/mac/modules/Screen.mm @@ -45,6 +45,7 @@ of this software and associated engine source code (the "Software"), a limited, float Screen::getDevicePixelRatio() const { #if CC_EDITOR + se::AutoHandleScope hs; auto* global = se::ScriptEngine::getInstance()->getGlobalObject(); se::Value devicePixelRatioVal; global->getProperty("devicePixelRatio", &devicePixelRatioVal); From effb0aa1b9506e3e5f56225d56b56b1a7c2bcf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 14:56:47 +0800 Subject: [PATCH 14/19] remove EditorApplication --- native/CMakeLists.txt | 12 -- .../cocos/platform/editor/EditorApplication.h | 42 ------- .../platform/editor/mac/EditorApplication.mm | 97 ---------------- .../editor/windows/EditorApplication.cpp | 106 ------------------ native/cocos/platform/mac/modules/Screen.mm | 1 - 5 files changed, 258 deletions(-) delete mode 100644 native/cocos/platform/editor/EditorApplication.h delete mode 100644 native/cocos/platform/editor/mac/EditorApplication.mm delete mode 100644 native/cocos/platform/editor/windows/EditorApplication.cpp diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 314e3630253..b7650cdd865 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -506,12 +506,6 @@ cocos_source_files( cocos/platform/UniversalPlatform.h ) if(WINDOWS) - if(CC_EDITOR) - cocos_source_files( - cocos/platform/editor/windows/EditorApplication.cpp - cocos/platform/editor/EditorApplication.h - ) - endif() cocos_source_files( cocos/platform/win32/WindowsPlatform.cpp cocos/platform/win32/WindowsPlatform.h @@ -532,12 +526,6 @@ elseif(OHOS) cocos/platform/ohos/OhosPlatform.h ) elseif(MACOSX) - if(CC_EDITOR) - cocos_source_files( - cocos/platform/editor/mac/EditorApplication.mm - cocos/platform/editor/EditorApplication.h - ) - endif() cocos_source_files( cocos/platform/mac/MacPlatform.mm cocos/platform/mac/MacPlatform.h diff --git a/native/cocos/platform/editor/EditorApplication.h b/native/cocos/platform/editor/EditorApplication.h deleted file mode 100644 index 8f56b482acb..00000000000 --- a/native/cocos/platform/editor/EditorApplication.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#pragma once - -#include "cocos/application/BaseGame.h" - - /** - @brief The cocos2d Application. - - The reason for implement as private inheritance is to hide some interface call by Director. - */ -class EditorApplication : public cc::BaseGame { -public: - EditorApplication(); - int init() override; - //bool init() override; - void onPause() override; - void onResume() override; - void onClose() override; -}; diff --git a/native/cocos/platform/editor/mac/EditorApplication.mm b/native/cocos/platform/editor/mac/EditorApplication.mm deleted file mode 100644 index ce856983ef3..00000000000 --- a/native/cocos/platform/editor/mac/EditorApplication.mm +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#include "../EditorApplication.h" -#include "FileUtils.h" -#include "cocos/application/ApplicationManager.h" -#include "platform/interfaces/modules/ISystemWindowManager.h" -#include "renderer/pipeline/GlobalDescriptorSetManager.h" - - -#ifndef GAME_NAME - #define GAME_NAME "CocosGame"; -#endif -extern std::string SearchPath; -extern "C" void cc_load_all_plugins(); -EditorApplication::EditorApplication() = default; - -int EditorApplication::init() { - cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); - - cc_load_all_plugins(); - -#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS - // override default value - //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; - //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; - _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; - _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; - _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | - cc::ISystemWindow::CC_WINDOW_RESIZABLE | - cc::ISystemWindow::CC_WINDOW_INPUT_FOCUS - : _windowInfo.flags; - std::call_once(_windowCreateFlag, [&]() { - cc::ISystemWindowInfo info; - info.title = _windowInfo.title; - info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now - info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above - info.width = _windowInfo.width; - info.height = _windowInfo.height; - info.flags = _windowInfo.flags; - - cc::ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(cc::ISystemWindowManager); - windowMgr->createWindow(info); - }); - -#endif - - if (_debuggerInfo.enabled) { - setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); - } - - int ret = cc::CocosApplication::init(); - if (ret != 0) { - return ret; - } - - setXXTeaKey(_xxteaKey); - // runScript("jsb-adapter/web-adapter.js"); - // runScript("main.js"); - - return 0; -} - -void EditorApplication::onPause() { - BaseGame::onPause(); -} - -void EditorApplication::onResume() { - BaseGame::onResume(); -} - -void EditorApplication::onClose() { - BaseGame::onClose(); -} - -CC_REGISTER_APPLICATION(EditorApplication); diff --git a/native/cocos/platform/editor/windows/EditorApplication.cpp b/native/cocos/platform/editor/windows/EditorApplication.cpp deleted file mode 100644 index bd432c30097..00000000000 --- a/native/cocos/platform/editor/windows/EditorApplication.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#include "../EditorApplication.h" -#include "cocos/application/ApplicationManager.h" -#include "cocos/application/BaseGame.h" -#include "cocos/platform/interfaces/modules/ISystemWindow.h" -#include "cocos/platform/interfaces/modules/ISystemWindowManager.h" -#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" - -#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) - #include "windows.h" -#endif - -extern "C" void cc_load_all_plugins(); // NOLINT - -using namespace std; -using namespace cc; - -EditorApplication::EditorApplication() { -} - -int EditorApplication::init() { - cc::pipeline::GlobalDSManager::setDescriptorSetLayout(); - - cc_load_all_plugins(); - -#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS - // override default value - //_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; - //_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; - _windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width; - _windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height; - _windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN | - ISystemWindow::CC_WINDOW_RESIZABLE | - ISystemWindow::CC_WINDOW_INPUT_FOCUS | - ISystemWindow::CC_WINDOW_HIDDEN - : _windowInfo.flags; - std::call_once(_windowCreateFlag, [&]() { - ISystemWindowInfo info; - info.title = _windowInfo.title; - #if CC_PLATFORM == CC_PLATFORM_WINDOWS - info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now - info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above - #else - info.x = _windowInfo.x == -1 ? 0 : _windowInfo.x; - info.y = _windowInfo.y == -1 ? 0 : _windowInfo.y; - #endif - info.width = _windowInfo.width; - info.height = _windowInfo.height; - info.flags = _windowInfo.flags; - - ISystemWindowManager* windowMgr = CC_GET_PLATFORM_INTERFACE(ISystemWindowManager); - windowMgr->createWindow(info); - }); - -#endif - - if (_debuggerInfo.enabled) { - setDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart); - } - - int ret = cc::CocosApplication::init(); - if (ret != 0) { - return ret; - } - - setXXTeaKey(_xxteaKey); - return 0; -} - -// This function will be called when the app is inactive. When comes a phone call,it's be invoked too -void EditorApplication::onPause() { - cc::CocosApplication::onPause(); -} - -void EditorApplication::onResume() { - cc::CocosApplication::onResume(); -} - -void EditorApplication::onClose() { - cc::CocosApplication::onClose(); -} - -CC_REGISTER_APPLICATION(EditorApplication); diff --git a/native/cocos/platform/mac/modules/Screen.mm b/native/cocos/platform/mac/modules/Screen.mm index 6dab0eb254c..cad4ed26f44 100644 --- a/native/cocos/platform/mac/modules/Screen.mm +++ b/native/cocos/platform/mac/modules/Screen.mm @@ -45,7 +45,6 @@ of this software and associated engine source code (the "Software"), a limited, float Screen::getDevicePixelRatio() const { #if CC_EDITOR - se::AutoHandleScope hs; auto* global = se::ScriptEngine::getInstance()->getGlobalObject(); se::Value devicePixelRatioVal; global->getProperty("devicePixelRatio", &devicePixelRatioVal); From ac8204050f800539035142d1a67b5fd2e479bd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 15:30:18 +0800 Subject: [PATCH 15/19] rename nsBuffer --- native/cocos/bindings/jswrapper/v8/Object.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 8695ab6fbf7..b4330722c25 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -223,9 +223,9 @@ Object *Object::createArrayObject(size_t length) { Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS - auto nsBuffer = node::Buffer::New(__isolate, byteLength); - auto *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); - v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); + auto nodeBuffer = node::Buffer::New(__isolate, byteLength); + auto *srcData = node::Buffer::Data(nodeBuffer.ToLocalChecked()); + v8::Local jsobj = nodeBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); auto *srcData = jsobj->GetBackingStore()->Data(); @@ -243,11 +243,11 @@ Object *Object::createArrayBufferObject(const void *data, size_t byteLength) { Object *Object::createExternalArrayBufferObject(void *contents, size_t byteLength, BufferContentsFreeFunc freeFunc, void *freeUserData /* = nullptr*/) { Object *obj = nullptr; #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS - auto nsBuffer = node::Buffer::New( + auto nodeBuffer = node::Buffer::New( __isolate, (char *)contents, byteLength, [](char *data, void *hint) {}, nullptr) .ToLocalChecked() .As(); - v8::Local jsobj = nsBuffer.As()->Buffer(); + v8::Local jsobj = nodeBuffer.As()->Buffer(); #else std::shared_ptr backingStore = v8::ArrayBuffer::NewBackingStore(contents, byteLength, freeFunc, freeUserData); v8::Local jsobj = v8::ArrayBuffer::New(__isolate, backingStore); @@ -270,9 +270,9 @@ Object *Object::createTypedArray(TypedArrayType type, const void *data, size_t b return nullptr; } #if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS - auto nsBuffer = node::Buffer::New(__isolate, byteLength); - auto *srcData = node::Buffer::Data(nsBuffer.ToLocalChecked()); - v8::Local jsobj = nsBuffer.ToLocalChecked().As()->Buffer(); + auto nodeBuffer = node::Buffer::New(__isolate, byteLength); + auto *srcData = node::Buffer::Data(nodeBuffer.ToLocalChecked()); + v8::Local jsobj = nodeBuffer.ToLocalChecked().As()->Buffer(); #else v8::Local jsobj = v8::ArrayBuffer::New(__isolate, byteLength); auto *srcData = jsobj->GetBackingStore()->Data(); From 207d3e780b51acc20e9aa1ef99e94f6dce356348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 15:31:40 +0800 Subject: [PATCH 16/19] fix spaces --- native/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index b7650cdd865..239b998cbb4 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -533,7 +533,7 @@ elseif(MACOSX) cocos/platform/mac/ViewController.mm cocos/platform/mac/AppDelegate.h cocos/platform/mac/AppDelegate.mm - ) + ) elseif(IOS) cocos_source_files( cocos/platform/ios/IOSPlatform.mm From 5ed6171dbfbe8a384a26d60a6c40ed59b249c859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 15:37:41 +0800 Subject: [PATCH 17/19] fix code style problem --- native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 23d535f3130..70683d5710b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -46,11 +46,11 @@ bool gles3wOpen() { if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR)&gles3wOpen, &engine) != 0) { - std::string dir(""); + std::string dir(); int times = 1; do { auto size = MAX_PATH * times++; - char *path = (char *)CC_MALLOC(size); + char *path = static_cast(CC_MALLOC(size)); if (path) { GetModuleFileNameA(engine, path, size); dir = path; From a5980f059a217ebcca37c9c79ac5bcf0fe580d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 15:38:37 +0800 Subject: [PATCH 18/19] fix error --- native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index 70683d5710b..e2ef64ab7dd 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -46,7 +46,7 @@ bool gles3wOpen() { if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR)&gles3wOpen, &engine) != 0) { - std::string dir(); + std::string dir; int times = 1; do { auto size = MAX_PATH * times++; From 0a4d5eed9adae02f2baca8ec905b16509f40b156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=87=AF=E9=B9=8F?= <609075410@qq.com> Date: Wed, 16 Nov 2022 16:00:03 +0800 Subject: [PATCH 19/19] fix type problem --- native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp index e2ef64ab7dd..10acafff8b4 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Wrangler.cpp @@ -62,8 +62,8 @@ bool gles3wOpen() { eglPath = dir + eglPath; glesPath = dir + glesPath; } else { - int err = GetLastError(); - CC_LOG_WARNING("Failed to get abs path for editor,error code:%d", err); + DWORD err = GetLastError(); + CC_LOG_WARNING("Failed to get abs path for editor,error code:%lu", err); } #endif