Skip to content

Commit

Permalink
optimize Constants in engine (cocos#11464)
Browse files Browse the repository at this point in the history
* publish build-engine 4.3.5

* update build-engine deps

* remove default-constants.ts

ds

remove de

* delete consts.d.ts

* support build-const workflow

* remove EXPORT_TO_GLOBAL

* update comment

* fix interface-check

* update comment
  • Loading branch information
PPpro authored Jun 14, 2022
1 parent e551182 commit 1c737b9
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 303 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ native/external/

scripts/typedoc-plugin/lib/
!templates/**/*

@types/consts.d.ts
124 changes: 0 additions & 124 deletions @types/consts.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,19 @@
"internal": false
},
"BYTEDANCE": {
"comment": "Running in the ByteDance's quick game.",
"comment": "Running in the ByteDance's mini game.",
"value": false,
"ccGlobal": true,
"internal": false
},
"OPPO": {
"comment": "Running in the oppo's mini game.",
"comment": "Running in the oppo's quick game.",
"value": false,
"ccGlobal": true,
"internal": false
},
"VIVO": {
"comment": "Running in the vivo's mini game.",
"comment": "Running in the vivo's quick game.",
"value": false,
"ccGlobal": true,
"internal": false
Expand Down Expand Up @@ -314,7 +314,7 @@
"dynamic": true
},
"JSB": {
"comment": "Running in native platform (mobile app, desktop app, or simulator).",
"comment": "Running in environment where using JSB as the JavaScript interface binding scheme.",
"value": "$NATIVE",
"ccGlobal": true,
"internal": false,
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/skeletal-animation/skeletal-animation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
THE SOFTWARE.
*/

import { JSB } from 'internal:constants';
import { Mat4, Quat, Vec3 } from '../../core/math';
import { IAnimInfo, JointAnimationInfo } from './skeletal-animation-utils';
import { Node } from '../../core/scene-graph/node';
Expand All @@ -31,7 +32,6 @@ import { AnimationState } from '../../core/animation/animation-state';
import { SkeletalAnimation, Socket } from './skeletal-animation';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { legacyCC } from '../../core/global-exports';
import { JSB } from '../../core/default-constants';

const m4_1 = new Mat4();
const m4_2 = new Mat4();
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/assets/render-texture.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
THE SOFTWARE.
*/
import { ccclass, rangeMax, rangeMin, serializable } from 'cc.decorator';
import { EDITOR, TEST } from 'internal:constants';
import {
_applyDecoratedDescriptor,
_assertThisInitialized,
_initializerDefineProperty,
} from '../data/utils/decorator-jsb-utils';
import { legacyCC } from '../global-exports';
import { Filter, PixelFormat, WrapMode } from './asset-enum';
import { EDITOR, TEST } from '../default-constants';

declare const jsb: any;
const renderTextureProto: any = jsb.RenderTexture.prototype;
Expand Down
3 changes: 1 addition & 2 deletions cocos/core/data/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
THE SOFTWARE.
*/

import { DEV } from 'internal:constants';
import { DEV, JSB } from 'internal:constants';
import { isDomNode } from '../utils/misc';
import { ValueType } from '../value-types';
import { CCObject, isCCObject } from './object';
Expand All @@ -33,7 +33,6 @@ import { getError, warn } from '../platform/debug';
import { legacyCC } from '../global-exports';
import { Prefab } from '../assets/prefab';
import { Node } from '../scene-graph/node';
import { JSB } from '../default-constants';
import { updateChildrenForDeserialize } from '../utils/jsb-utils';
import { isCCClassOrFastDefined } from './class';

Expand Down
123 changes: 1 addition & 122 deletions cocos/core/global-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,7 @@
THE SOFTWARE.
*/

import {
ALIPAY,
BAIDU,
BUILD,
COCOSPLAY,
DEBUG,
DEV,
EDITOR,
JSB,
MINIGAME,
PREVIEW,
RUNTIME_BASED,
SUPPORT_JIT,
TEST,
BYTEDANCE,
WECHAT,
XIAOMI,
HUAWEI,
OPPO,
VIVO,
EXPORT_TO_GLOBAL,
} from 'internal:constants';
import { DEV } from 'internal:constants';

const _global = typeof window === 'undefined' ? global : window;

Expand All @@ -64,106 +43,6 @@ export const legacyCC: Record<string, any> & {
// For internal usage
legacyCC.internal = {};

if (EXPORT_TO_GLOBAL) {
// Supports dynamically access from external scripts such as adapters and debugger.
// So macros should still defined in global even if inlined in engine.
/**
* @en The pre-compilation constant for code tree shaking: CC_BUILD (Available for built package)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_BUILD(在构建后生效)
*/
_global.CC_BUILD = BUILD;
/**
* @en The pre-compilation constant for code tree shaking: CC_TEST (Available for ci test environment)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_TEST(在 CI 测试环境下生效)
*/
_global.CC_TEST = TEST;
/**
* @en The pre-compilation constant for code tree shaking: CC_EDITOR (Available for editor environment)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_EDITOR(在编辑器环境下生效)
*/
_global.CC_EDITOR = EDITOR;
/**
* @en The pre-compilation constant for code tree shaking: CC_PREVIEW (Available for preview)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_PREVIEW(预览时生效)
*/
_global.CC_PREVIEW = PREVIEW;
/**
* @en The pre-compilation constant for code tree shaking: CC_DEV (Internal)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_DEV(内部使用)
*/
_global.CC_DEV = DEV;
/**
* @en The pre-compilation constant for code tree shaking: CC_DEBUG (Available for debug environment)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_DEBUG(在调试模式下生效)
*/
_global.CC_DEBUG = DEBUG;
/**
* @en The pre-compilation constant for code tree shaking: CC_JSB (Available for native application environment)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_JSB(在原生应用环境下生效)
*/
_global.CC_JSB = JSB;
/**
* @en The pre-compilation constant for code tree shaking: CC_BYTEDANCE (Available for Bytedance platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_BYTEDANCE(在字节平台上生效)
*/
_global.CC_BYTEDANCE = BYTEDANCE;
/**
* @en The pre-compilation constant for code tree shaking: CC_WECHAT (Available for Wechat mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_WECHAT(在微信小游戏平台上生效)
*/
_global.CC_WECHAT = WECHAT;
/**
* @en The pre-compilation constant for code tree shaking: CC_ALIPAY (Available for Alipay mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_ALIPAY(在支付宝小游戏平台上生效)
*/
_global.CC_ALIPAY = ALIPAY;
/**
* @en The pre-compilation constant for code tree shaking: CC_XIAOMI (Available for MI mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_XIAOMI(在小米小游戏平台上生效)
*/
_global.CC_XIAOMI = XIAOMI;
/**
* @en The pre-compilation constant for code tree shaking: CC_BAIDU (Available for Baidu mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_BAIDU(在百度小游戏平台上生效)
*/
_global.CC_BAIDU = BAIDU;
/**
* @en The pre-compilation constant for code tree shaking: CC_COCOSPLAY (Available for Cocos Play platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_COCOSPLAY(在 CocosPlay 小游戏平台上生效)
*/
_global.CC_COCOSPLAY = COCOSPLAY;
/**
* @en The pre-compilation constant for code tree shaking: CC_HUAWEI (Available for Huawei mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_HUAWEI(在华为快游戏平台上生效)
*/
_global.CC_HUAWEI = HUAWEI;
/**
* @en The pre-compilation constant for code tree shaking: CC_OPPO (Available for OPPO mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_OPPO(在 OPPO 小游戏平台上生效)
*/
_global.CC_OPPO = OPPO;
/**
* @en The pre-compilation constant for code tree shaking: CC_VIVO (Available for Vivo mini game platform)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_VIVO(在 Vivo 小游戏平台上生效)
*/
_global.CC_VIVO = VIVO;
/**
* @en The pre-compilation constant for code tree shaking: CC_MINIGAME (Available for general mini game platforms)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_MINIGAME(在各个小游戏平台上生效)
*/
_global.CC_MINIGAME = MINIGAME;
/**
* @en The pre-compilation constant for code tree shaking: CC_RUNTIME_BASED (Available for Huawei, OPPO, Vivo and Cocos Play)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_RUNTIME_BASED(在华为、OPPO、Vivo 和 CocosPlay 平台上生效)
*/
_global.CC_RUNTIME_BASED = RUNTIME_BASED;
/**
* @en The pre-compilation constant for code tree shaking: CC_SUPPORT_JIT (Available for platforms support JIT)
* @zh 预编译宏变量,通常用来做平台或环境相关自动代码剔除:CC_SUPPORT_JIT(在支持 JIT 的平台上生效)
*/
_global.CC_SUPPORT_JIT = SUPPORT_JIT;
}

if (DEV) {
legacyCC._Test = {};
}
Expand Down
1 change: 0 additions & 1 deletion cocos/core/math/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { IColorLike } from './type-define';
import { clamp, EPSILON } from './utils';
import { legacyCC } from '../global-exports';
import { mixin } from '../utils/js-typed';
import { JSB } from '../default-constants';

const toFloat = 1 / 255;

Expand Down
3 changes: 1 addition & 2 deletions cocos/core/scene-graph/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
THE SOFTWARE.
*/

import { EDITOR } from 'internal:constants';
import { EDITOR, JSB } from 'internal:constants';
import { ccclass } from 'cc.decorator';
import { BaseNode } from './base-node';
import { replaceProperty, removeProperty } from '../utils/x-deprecated';
Expand All @@ -35,7 +35,6 @@ import { legacyCC } from '../global-exports';
import { CCObject } from '../data/object';
import { warnID } from '../platform/debug';
import { SceneGlobals, ShadowsInfo } from './scene-globals';
import { JSB } from '../default-constants';
import { SystemEventType } from '../../input/types';
import { SystemEvent } from '../../input';
import { NodeUIProperties } from './node-ui-properties';
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
THE SOFTWARE.
*/

import { EDITOR } from 'internal:constants';
import { ccclass, editable, serializable, type } from 'cc.decorator';
import {
_applyDecoratedDescriptor,
Expand All @@ -37,7 +38,6 @@ import { Mat4, Quat, Vec3 } from '../math';
import { NodeEventProcessor } from './node-event-processor';
import { Layers } from './layers';
import { SerializationContext, SerializationOutput, serializeTag } from '../data';
import { EDITOR } from '../default-constants';
import { _tempFloatArray } from './utils.jsb';

import {
Expand Down
Loading

0 comments on commit 1c737b9

Please sign in to comment.