From bd1c1e0088cab9c8cbc4dbcbed030debcdf04ca9 Mon Sep 17 00:00:00 2001 From: yangchao <1162485779@qq.com> Date: Thu, 12 May 2022 09:43:46 +0800 Subject: [PATCH] V3.5.1 no window (#11016) --- cocos/core/root.ts | 6 +- native/CMakeLists.txt | 96 ++++++++++--------- native/cocos/platform/BasePlatform.cpp | 8 +- .../cocos/platform/empty/modules/System.cpp | 66 +------------ .../platform/empty/modules/SystemWindow.cpp | 16 +++- .../platform/empty/modules/SystemWindow.h | 6 +- native/cocos/platform/linux/LinuxPlatform.cpp | 10 +- native/cocos/platform/mac/MacPlatform.mm | 10 +- .../cocos/platform/win32/WindowsPlatform.cpp | 9 +- native/cocos/renderer/GFXDeviceManager.h | 2 + .../cocos/renderer/gfx-base/GFXSwapchain.cpp | 2 + .../cocos/renderer/gfx-empty/EmptyDevice.cpp | 1 - native/templates/windows/main.cpp | 11 ++- 13 files changed, 115 insertions(+), 128 deletions(-) diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 0fd196c256..0c6dac0d34 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -25,7 +25,7 @@ -import { JSB } from 'internal:constants'; +import { JSB, SERVER_MODE } from 'internal:constants'; import { builtinResMgr } from './builtin'; import { Pool } from './memop'; import { RenderPipeline, createDefaultPipeline, DeferredPipeline } from './pipeline'; @@ -450,7 +450,9 @@ export class Root { legacyCC.director.emit(legacyCC.Director.EVENT_BEFORE_COMMIT); cameraList.sort((a: Camera, b: Camera) => a.priority - b.priority); - this._pipeline.render(cameraList); + if (!SERVER_MODE) { + this._pipeline.render(cameraList); + } this._device.present(); } diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index d386255c73..985b75df0e 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -353,12 +353,6 @@ cocos_source_files( ) ############ main -if(USE_SERVER_MODE) - cocos_source_files( - cocos/main/EmptyMain.cpp - ) -endif() - if(NOT USE_SERVER_MODE AND (WINDOWS OR LINUX)) cocos_source_files( cocos/platform/SDLHelper.h @@ -374,12 +368,7 @@ cocos_source_files( cocos/platform/UniversalPlatform.cpp cocos/platform/UniversalPlatform.h ) -if(USE_SERVER_MODE) - cocos_source_files( - cocos/platform/empty/EmptyPlatform.cpp - cocos/platform/empty/EmptyPlatform.h - ) -elseif(WINDOWS) +if(WINDOWS) cocos_source_files( cocos/platform/win32/WindowsPlatform.cpp cocos/platform/win32/WindowsPlatform.h @@ -474,40 +463,34 @@ endif() ############ platform : Interface implementation of windows -if(USE_SERVER_MODE) - cocos_source_files( - cocos/platform/empty/modules/Accelerometer.cpp - cocos/platform/empty/modules/Accelerometer.h - cocos/platform/empty/modules/Battery.cpp - cocos/platform/empty/modules/Battery.h - cocos/platform/empty/modules/Screen.cpp - cocos/platform/empty/modules/Screen.h - cocos/platform/empty/modules/Network.cpp - cocos/platform/empty/modules/Network.h - cocos/platform/empty/modules/Vibrator.cpp - cocos/platform/empty/modules/Vibrator.h - cocos/platform/empty/modules/System.cpp - cocos/platform/empty/modules/System.h - cocos/platform/empty/modules/SystemWindow.cpp - cocos/platform/empty/modules/SystemWindow.h - ) -elseif(WINDOWS) +if(WINDOWS) cocos_source_files( cocos/platform/win32/modules/Accelerometer.cpp cocos/platform/win32/modules/Accelerometer.h cocos/platform/win32/modules/Battery.cpp cocos/platform/win32/modules/Battery.h - cocos/platform/win32/modules/Screen.cpp - cocos/platform/win32/modules/Screen.h cocos/platform/win32/modules/Network.cpp cocos/platform/win32/modules/Network.h cocos/platform/win32/modules/Vibrator.cpp cocos/platform/win32/modules/Vibrator.h cocos/platform/win32/modules/System.cpp cocos/platform/win32/modules/System.h - cocos/platform/win32/modules/SystemWindow.cpp - cocos/platform/win32/modules/SystemWindow.h ) + if(USE_SERVER_MODE) + cocos_source_files( + cocos/platform/empty/modules/Screen.cpp + cocos/platform/empty/modules/Screen.h + cocos/platform/empty/modules/SystemWindow.cpp + cocos/platform/empty/modules/SystemWindow.h + ) + else() + cocos_source_files( + cocos/platform/win32/modules/Screen.cpp + cocos/platform/win32/modules/Screen.h + cocos/platform/win32/modules/SystemWindow.cpp + cocos/platform/win32/modules/SystemWindow.h + ) + endif() elseif(ANDROID OR OHOS) cocos_source_files( cocos/platform/java/modules/Accelerometer.cpp @@ -526,9 +509,8 @@ elseif(ANDROID OR OHOS) cocos/platform/java/modules/SystemWindow.h ) endif() -if (USE_SERVER_MODE) -#nothing -elseif(ANDROID) + +if(ANDROID) cocos_source_files( cocos/platform/android/modules/Screen.cpp cocos/platform/android/modules/Screen.h @@ -548,17 +530,28 @@ elseif(MACOSX) cocos/platform/mac/modules/Accelerometer.h cocos/platform/mac/modules/Battery.mm cocos/platform/mac/modules/Battery.h - cocos/platform/mac/modules/Screen.mm - cocos/platform/mac/modules/Screen.h cocos/platform/mac/modules/Network.mm cocos/platform/mac/modules/Network.h cocos/platform/mac/modules/Vibrator.mm cocos/platform/mac/modules/Vibrator.h cocos/platform/mac/modules/System.mm cocos/platform/mac/modules/System.h - cocos/platform/mac/modules/SystemWindow.mm - cocos/platform/mac/modules/SystemWindow.h ) + if(USE_SERVER_MODE) + cocos_source_files( + cocos/platform/empty/modules/Screen.cpp + cocos/platform/empty/modules/Screen.h + cocos/platform/empty/modules/SystemWindow.cpp + cocos/platform/empty/modules/SystemWindow.h + ) + else() + cocos_source_files( + cocos/platform/mac/modules/Screen.mm + cocos/platform/mac/modules/Screen.h + cocos/platform/mac/modules/SystemWindow.mm + cocos/platform/mac/modules/SystemWindow.h + ) + endif() elseif(IOS) cocos_source_files( cocos/platform/ios/modules/Accelerometer.mm @@ -582,17 +575,28 @@ elseif(LINUX) cocos/platform/linux/modules/Accelerometer.h cocos/platform/linux/modules/Battery.cpp cocos/platform/linux/modules/Battery.h - cocos/platform/linux/modules/Screen.cpp - cocos/platform/linux/modules/Screen.h cocos/platform/linux/modules/Network.cpp cocos/platform/linux/modules/Network.h cocos/platform/linux/modules/Vibrator.cpp cocos/platform/linux/modules/Vibrator.h cocos/platform/linux/modules/System.cpp cocos/platform/linux/modules/System.h - cocos/platform/linux/modules/SystemWindow.cpp - cocos/platform/linux/modules/SystemWindow.h ) + if(USE_SERVER_MODE) + cocos_source_files( + cocos/platform/empty/modules/Screen.cpp + cocos/platform/empty/modules/Screen.h + cocos/platform/empty/modules/SystemWindow.cpp + cocos/platform/empty/modules/SystemWindow.h + ) + else() + cocos_source_files( + cocos/platform/linux/modules/Screen.cpp + cocos/platform/linux/modules/Screen.h + cocos/platform/linux/modules/SystemWindow.cpp + cocos/platform/linux/modules/SystemWindow.h + ) + endif() endif() ############ module log @@ -2481,4 +2485,4 @@ elseif(LINUX) ${LINUX_GRAPHIC_LIBS} ${CC_EXTERNAL_LIBS} ) -endif() \ No newline at end of file +endif() diff --git a/native/cocos/platform/BasePlatform.cpp b/native/cocos/platform/BasePlatform.cpp index 9b0003da91..a42a2a4c80 100644 --- a/native/cocos/platform/BasePlatform.cpp +++ b/native/cocos/platform/BasePlatform.cpp @@ -24,9 +24,7 @@ ****************************************************************************/ #include "platform/BasePlatform.h" -#if defined(CC_SERVER_MODE) - #include "platform/empty/EmptyPlatform.h" -#elif (CC_PLATFORM == CC_PLATFORM_WINDOWS) +#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) #include "platform/win32/WindowsPlatform.h" #elif (CC_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/AndroidPlatform.h" @@ -55,9 +53,7 @@ BasePlatform::~BasePlatform() { } BasePlatform* BasePlatform::createDefaultPlatform() { -#if defined(CC_SERVER_MODE) - static EmptyPlatform platform; -#elif (CC_PLATFORM == CC_PLATFORM_WINDOWS) +#if (CC_PLATFORM == CC_PLATFORM_WINDOWS) static WindowsPlatform platform; #elif (CC_PLATFORM == CC_PLATFORM_ANDROID) static AndroidPlatform platform; diff --git a/native/cocos/platform/empty/modules/System.cpp b/native/cocos/platform/empty/modules/System.cpp index b8e9f53f22..2516596cdb 100644 --- a/native/cocos/platform/empty/modules/System.cpp +++ b/native/cocos/platform/empty/modules/System.cpp @@ -25,10 +25,8 @@ #include "platform/empty/modules/System.h" #include -#include namespace cc { - using OSType = System::OSType; OSType System::getOSType() const { @@ -40,31 +38,11 @@ std::string System::getDeviceModel() const { } System::LanguageType System::getCurrentLanguage() const { - char* pLanguageName = getenv("LANG"); - if (!pLanguageName) { - return LanguageType::ENGLISH; - } - strtok(pLanguageName, "_"); - if (!pLanguageName) { - return LanguageType::ENGLISH; - } - - return getLanguageTypeByISO2(pLanguageName); + return LanguageType::ENGLISH; } std::string System::getCurrentLanguageCode() const { - static char code[3] = {0}; - char* pLanguageName = getenv("LANG"); - if (!pLanguageName) { - return "en"; - } - strtok(pLanguageName, "_"); - if (!pLanguageName) { - return "en"; - } - strncpy(code, pLanguageName, 2); - code[2] = '\0'; - return code; + return "en"; } std::string System::getSystemVersion() const { @@ -79,44 +57,6 @@ System::LanguageType System::getLanguageTypeByISO2(const char* code) const { // this function is used by all platforms to get system language // except windows: cocos/platform/win32/CCApplication-win32.cpp LanguageType ret = LanguageType::ENGLISH; - - if (strncmp(code, "zh", 2) == 0) { - ret = LanguageType::CHINESE; - } else if (strncmp(code, "ja", 2) == 0) { - ret = LanguageType::JAPANESE; - } else if (strncmp(code, "fr", 2) == 0) { - ret = LanguageType::FRENCH; - } else if (strncmp(code, "it", 2) == 0) { - ret = LanguageType::ITALIAN; - } else if (strncmp(code, "de", 2) == 0) { - ret = LanguageType::GERMAN; - } else if (strncmp(code, "es", 2) == 0) { - ret = LanguageType::SPANISH; - } else if (strncmp(code, "nl", 2) == 0) { - ret = LanguageType::DUTCH; - } else if (strncmp(code, "ru", 2) == 0) { - ret = LanguageType::RUSSIAN; - } else if (strncmp(code, "hu", 2) == 0) { - ret = LanguageType::HUNGARIAN; - } else if (strncmp(code, "pt", 2) == 0) { - ret = LanguageType::PORTUGUESE; - } else if (strncmp(code, "ko", 2) == 0) { - ret = LanguageType::KOREAN; - } else if (strncmp(code, "ar", 2) == 0) { - ret = LanguageType::ARABIC; - } else if (strncmp(code, "nb", 2) == 0) { - ret = LanguageType::NORWEGIAN; - } else if (strncmp(code, "pl", 2) == 0) { - ret = LanguageType::POLISH; - } else if (strncmp(code, "tr", 2) == 0) { - ret = LanguageType::TURKISH; - } else if (strncmp(code, "uk", 2) == 0) { - ret = LanguageType::UKRAINIAN; - } else if (strncmp(code, "ro", 2) == 0) { - ret = LanguageType::ROMANIAN; - } else if (strncmp(code, "bg", 2) == 0) { - ret = LanguageType::BULGARIAN; - } return ret; } -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/platform/empty/modules/SystemWindow.cpp b/native/cocos/platform/empty/modules/SystemWindow.cpp index 5c1c1dc8ea..7a1bc567df 100644 --- a/native/cocos/platform/empty/modules/SystemWindow.cpp +++ b/native/cocos/platform/empty/modules/SystemWindow.cpp @@ -39,7 +39,7 @@ namespace { } // namespace namespace cc { -SystemWindow::SystemWindow() { +SystemWindow::SystemWindow(IEventDispatch* delegate) { } SystemWindow::~SystemWindow() { @@ -56,8 +56,20 @@ void SystemWindow::copyTextToClipboard(const std::string &text) { //TODO } +int SystemWindow::init() { + return 0; +} + +void SystemWindow::pollEvent(bool* quit) { + return; +} + +void SystemWindow::swapWindow() { + return; +} + SystemWindow::Size SystemWindow::getViewSize() const { return Size{static_cast(_width), static_cast(_height)}; } -} // namespace cc \ No newline at end of file +} // namespace cc diff --git a/native/cocos/platform/empty/modules/SystemWindow.h b/native/cocos/platform/empty/modules/SystemWindow.h index 36b50e71a5..b86a4441a0 100644 --- a/native/cocos/platform/empty/modules/SystemWindow.h +++ b/native/cocos/platform/empty/modules/SystemWindow.h @@ -33,7 +33,7 @@ namespace cc { class CC_DLL SystemWindow : public ISystemWindow { public: - explicit SystemWindow(); + explicit SystemWindow(IEventDispatch* delegate); ~SystemWindow() override; uintptr_t getWindowHandler() const override; @@ -45,6 +45,10 @@ public: void setCursorEnabled(bool value) override; void copyTextToClipboard(const std::string& text) override; + int init(); + void pollEvent(bool* quit); + void swapWindow(); + private: int _width{0}; int _height{0}; diff --git a/native/cocos/platform/linux/LinuxPlatform.cpp b/native/cocos/platform/linux/LinuxPlatform.cpp index 246b031cb9..8d15ab5562 100644 --- a/native/cocos/platform/linux/LinuxPlatform.cpp +++ b/native/cocos/platform/linux/LinuxPlatform.cpp @@ -33,11 +33,17 @@ #include "modules/Accelerometer.h" #include "modules/Battery.h" #include "modules/Network.h" -#include "modules/Screen.h" #include "modules/System.h" -#include "modules/SystemWindow.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" +#endif + namespace { } // namespace diff --git a/native/cocos/platform/mac/MacPlatform.mm b/native/cocos/platform/mac/MacPlatform.mm index 586208b7c1..1d54c272b3 100644 --- a/native/cocos/platform/mac/MacPlatform.mm +++ b/native/cocos/platform/mac/MacPlatform.mm @@ -30,11 +30,17 @@ #include "modules/Accelerometer.h" #include "modules/Battery.h" #include "modules/Network.h" -#include "modules/Screen.h" #include "modules/System.h" -#include "modules/SystemWindow.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" +#endif + #import extern int cocos_main(int argc, const char** argv); diff --git a/native/cocos/platform/win32/WindowsPlatform.cpp b/native/cocos/platform/win32/WindowsPlatform.cpp index 4ffda82553..27ce9cbaf6 100644 --- a/native/cocos/platform/win32/WindowsPlatform.cpp +++ b/native/cocos/platform/win32/WindowsPlatform.cpp @@ -32,9 +32,14 @@ #include "modules/Accelerometer.h" #include "modules/Battery.h" #include "modules/Network.h" -#include "modules/Screen.h" #include "modules/System.h" -#include "modules/SystemWindow.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" +#endif #include "modules/Vibrator.h" namespace { diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index 8f2083d077..fdad07b981 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -122,9 +122,11 @@ private: device = CC_NEW(gfx::DeviceAgent(device)); } +#if !defined(CC_SERVER_MODE) if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) { device = CC_NEW(gfx::DeviceValidator(device)); } +#endif if (!device->initialize(info)) { CC_SAFE_DELETE(device); diff --git a/native/cocos/renderer/gfx-base/GFXSwapchain.cpp b/native/cocos/renderer/gfx-base/GFXSwapchain.cpp index 191ac3d118..fd8a5e9d5e 100644 --- a/native/cocos/renderer/gfx-base/GFXSwapchain.cpp +++ b/native/cocos/renderer/gfx-base/GFXSwapchain.cpp @@ -37,7 +37,9 @@ Swapchain::Swapchain() Swapchain::~Swapchain() = default; void Swapchain::initialize(const SwapchainInfo &info) { +#if !defined(CC_SERVER_MODE) CCASSERT(info.windowHandle, "Invalid window handle"); +#endif _windowHandle = info.windowHandle; _vsyncMode = info.vsyncMode; diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp index 7b9b4b67ba..2dd71f0170 100644 --- a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp @@ -73,7 +73,6 @@ bool EmptyDevice::doInit(const DeviceInfo & /*info*/) { _formatFeatures.fill(static_cast(-1)); // allow all usages for all formats _formatFeatures[toNumber(Format::UNKNOWN)] = FormatFeature::NONE; - _formatFeatures[toNumber(Format::COUNT)] = FormatFeature::NONE; CC_LOG_INFO("Empty device initialized."); diff --git a/native/templates/windows/main.cpp b/native/templates/windows/main.cpp index f16fa21df3..8b6dd66cbd 100644 --- a/native/templates/windows/main.cpp +++ b/native/templates/windows/main.cpp @@ -26,8 +26,17 @@ #include #include "platform/BasePlatform.h" + +#if defined(CC_SERVER_MODE) +#include +int WINAPI +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) { + START_PLATFORM(0, nullptr); +} +#else #include "sdl2/SDL_main.h" int SDL_main(int argc, char** argv) { START_PLATFORM(argc, (const char**)argv); -} \ No newline at end of file +} +#endif \ No newline at end of file