Merge branch 'v3.5.1-ds' into v3.6.0_merge_v3.5.1-ds

This commit is contained in:
minggo
2022-06-07 15:02:34 +08:00
18 changed files with 211 additions and 126 deletions
+4 -1
View File
@@ -23,6 +23,7 @@
THE SOFTWARE.
*/
import { JSB, SERVER_MODE } from 'internal:constants';
import { builtinResMgr } from './builtin';
import { Pool } from './memop';
import { RenderPipeline, createDefaultPipeline, DeferredPipeline } from './pipeline';
@@ -467,7 +468,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();
}
+2
View File
@@ -996,6 +996,7 @@ export class BaseNode extends CCObject implements ISchedulable {
EditorExtends.Component.add(component._id, component);
}
}
this.emit(NodeEventType.COMPONENT_ADDED, component);
if (this._activeInHierarchy) {
legacyCC.director._nodeActivator.activateComp(component);
}
@@ -1249,6 +1250,7 @@ export class BaseNode extends CCObject implements ISchedulable {
if (EDITOR && EditorExtends.Component) {
EditorExtends.Component.remove(component._id);
}
this.emit(NodeEventType.COMPONENT_REMOVED, component);
} else if (component.node !== (this as unknown as BaseNode)) {
errorID(3815);
}
+16
View File
@@ -222,4 +222,20 @@ export enum NodeEventType {
* 注意:此节点激活时,此事件仅从最顶部的节点发出。
*/
ACTIVE_IN_HIERARCHY_CHANGED = 'active-in-hierarchy-changed',
/**
* @en
* The event occur when node add a new component.
* @zh
* 当节点上增加组件时触发的事件
*/
COMPONENT_ADDED = 'component-added',
/**
* @en
* The event occur when node remove a component.
* @zh
* 当节点上移除组件时触发的事件
*/
COMPONENT_REMOVED = 'component-removed',
}
+3
View File
@@ -467,6 +467,9 @@ export class Node extends BaseNode implements CustomSerializable {
serializationOutput.writeProperty('_objFlags', this._objFlags);
serializationOutput.writeProperty('_parent', this._parent);
serializationOutput.writeProperty('_prefab', this._prefab);
if (context.customArguments.keepNodeUuid) {
serializationOutput.writeProperty('_id', this._id);
}
// TODO: editorExtrasTag may be a symbol in the future
serializationOutput.writeProperty(editorExtrasTag, this[editorExtrasTag]);
} else {
+15
View File
@@ -401,6 +401,7 @@ export function expandPrefabInstanceNode (node: Node, recursively = false) {
const prefabInstance = prefabInfo?.instance;
if (prefabInstance) {
createNodeWithPrefab(node);
applyNodeAndComponentId(node, node.uuid);
const targetMap: Record<string, any | Node | Component> = {};
prefabInstance.targetMap = targetMap;
@@ -431,3 +432,17 @@ export function expandNestedPrefabInstanceNode (node: BaseNode) {
});
}
}
export function applyNodeAndComponentId (node: Node, rootId: string) {
const { components, children } = node;
for (let i = 0; i < components.length; i++) {
const comp = components[i];
comp._id = `${rootId}${comp.__prefab?.fileId}`;
}
for (let i = 0; i < children.length; i++) {
const child = children[i];
// @ts-expect-error private member access
child._id = `${rootId}${child._prefab?.fileId}`;
applyNodeAndComponentId(child, rootId);
}
}
+49 -45
View File
@@ -368,12 +368,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
@@ -389,12 +383,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
@@ -489,40 +478,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
@@ -541,9 +524,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
@@ -563,17 +545,28 @@ elseif(MACOSX)
cocos/platform/mac/modules/Accelerometer.h
cocos/platform/mac/modules/Battery.mm
cocos/platform/mac/modules/Battery.h
NO_WERROR NO_UBUILD 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(
NO_WERROR NO_UBUILD 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(
NO_WERROR NO_UBUILD cocos/platform/ios/modules/Accelerometer.mm
@@ -597,17 +590,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
+2 -6
View File
@@ -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"
@@ -56,9 +54,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;
+2 -62
View File
@@ -25,10 +25,8 @@
#include "platform/empty/modules/System.h"
#include <string.h>
#include <sys/utsname.h>
namespace cc {
using OSType = System::OSType;
OSType System::getOSType() const {
@@ -40,31 +38,11 @@ ccstd::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;
}
ccstd::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";
}
ccstd::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
@@ -36,7 +36,7 @@ namespace {
} // namespace
namespace cc {
SystemWindow::SystemWindow() {
SystemWindow::SystemWindow(IEventDispatch* delegate) {
}
SystemWindow::~SystemWindow() {
@@ -53,8 +53,20 @@ void SystemWindow::copyTextToClipboard(const ccstd::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<float>(_width), static_cast<float>(_height)};
}
} // namespace cc
} // namespace cc
@@ -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};
@@ -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
+8 -2
View File
@@ -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 <AppKit/AppKit.h>
extern int cocos_main(int argc, const char **argv);
@@ -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 {
+2
View File
@@ -147,9 +147,11 @@ private:
device = ccnew gfx::DeviceAgent(device);
}
#if !defined(CC_SERVER_MODE)
if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) {
device = ccnew gfx::DeviceValidator(device);
}
#endif
if (!device->initialize(info)) {
CC_SAFE_DELETE(device);
@@ -35,7 +35,9 @@ Swapchain::Swapchain()
Swapchain::~Swapchain() = default;
void Swapchain::initialize(const SwapchainInfo &info) {
#if !defined(CC_SERVER_MODE)
CC_ASSERT(info.windowHandle);
#endif
_windowHandle = info.windowHandle;
_vsyncMode = info.vsyncMode;
@@ -73,7 +73,6 @@ bool EmptyDevice::doInit(const DeviceInfo & /*info*/) {
_formatFeatures.fill(static_cast<FormatFeature>(-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.");
+10 -1
View File
@@ -26,8 +26,17 @@
#include <iostream>
#include "platform/BasePlatform.h"
#if defined(CC_SERVER_MODE)
#include <windows.h>
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);
}
}
#endif
+62 -1
View File
@@ -1,8 +1,9 @@
import { Node, Scene } from "../../cocos/core/scene-graph"
import { Mat4, Quat, Vec3 } from "../../cocos/core/math"
import { director } from "../../cocos/core";
import { Component, director, game } from "../../cocos/core";
import { NodeEventType } from "../../cocos/core/scene-graph/node-event";
import { NodeUIProperties } from "../../cocos/core/scene-graph/node-ui-properties";
import { ccclass } from "../../cocos/core/data/decorators";
describe(`Node`, () => {
@@ -145,4 +146,64 @@ describe(`Node`, () => {
expect(node2.worldMatrix.equals(worldMat)).toBeFalsy();
expect(Mat4.determinant(node2.worldMatrix)).toBeCloseTo(0, 6);
});
test('component event', () => {
let onLoadCalled = false;
let onDestroyCalled = false;
@ccclass('TestComponent')
class TestComponent extends Component {
onLoad () {
onLoadCalled = true;
}
onDestroy () {
onDestroyCalled = true;
}
}
const scene = new Scene('');
director.runSceneImmediate(scene);
const node = new Node();
let compParam;
const addCb = jest.fn((tempComp) => { compParam = tempComp; expect(onLoadCalled).toBeFalsy(); });
const removeCb = jest.fn((tempComp) => {
compParam = tempComp;
if (onLoadCalled) {
expect(onDestroyCalled).toBeTruthy();
} else {
expect(onDestroyCalled).toBeFalsy();
}
});
node.on(NodeEventType.COMPONENT_ADDED, addCb);
node.on(NodeEventType.COMPONENT_REMOVED, removeCb)
let comp = node.addComponent(TestComponent);
expect(addCb).toBeCalledTimes(1);
expect(comp).toBe(compParam);
expect(onLoadCalled).toBeFalsy();
node.removeComponent(comp);
game.step();
expect(removeCb).toBeCalledTimes(1);
expect(comp).toBe(compParam);
expect(onDestroyCalled).toBeFalsy();
scene.addChild(node);
comp = node.addComponent(TestComponent);
expect(addCb).toBeCalledTimes(2);
expect(comp).toBe(compParam);
expect(onLoadCalled).toBeTruthy();
comp.destroy();
game.step();
expect(removeCb).toBeCalledTimes(2);
expect(comp).toBe(compParam);
expect(onDestroyCalled).toBeTruthy();
onLoadCalled = onDestroyCalled = false;
comp = node.addComponent(TestComponent);
expect(addCb).toBeCalledTimes(3);
expect(comp).toBe(compParam);
expect(onLoadCalled).toBeTruthy();
comp._destroyImmediate();
expect(removeCb).toBeCalledTimes(3);
expect(comp).toBe(compParam);
expect(onDestroyCalled).toBeTruthy();
});
});