mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge branch 'v3.8.8' into v4.0.0
This commit is contained in:
@@ -22,7 +22,7 @@ jobs:
|
||||
id: cache-oh-sdk
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: cache-oh-sdk-15
|
||||
cache-name: cache-oh-sdk-21
|
||||
with:
|
||||
path: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}
|
||||
@@ -33,11 +33,11 @@ jobs:
|
||||
run: |
|
||||
if [ ! -d "$HOME/openharmony" ]; then
|
||||
mkdir -p $HOME/openharmony
|
||||
echo "Download commandline-tools-linux-x64-5.0.13.200.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-15/commandline-tools-linux-x64-5.0.13.200.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-15/commandline-tools-linux-x64-5.0.13.200.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-5.0.13.200.zip ..."
|
||||
7z x commandline-tools-linux-x64-5.0.13.200.zip.001 -o$HOME/openharmony > /dev/null
|
||||
echo "Download commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
7z x commandline-tools-linux-x64-6.0.1.246.zip.001 -o$HOME/openharmony > /dev/null
|
||||
cd $HOME/openharmony
|
||||
ls -l
|
||||
cd command-line-tools
|
||||
|
||||
@@ -296,6 +296,7 @@ jobs:
|
||||
|
||||
- name: Install libgl1
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libgl1
|
||||
|
||||
- name: Checking libGL.so.1
|
||||
@@ -328,7 +329,7 @@ jobs:
|
||||
id: cache-oh-sdk
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: cache-oh-sdk-13
|
||||
cache-name: cache-oh-sdk-21
|
||||
with:
|
||||
path: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}
|
||||
@@ -347,11 +348,11 @@ jobs:
|
||||
run: |
|
||||
if [ ! -d "$HOME/openharmony" ]; then
|
||||
mkdir -p $HOME/openharmony
|
||||
echo "Download commandline-tools-linux-x64-5.0.13.200.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-15/commandline-tools-linux-x64-5.0.13.200.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-15/commandline-tools-linux-x64-5.0.13.200.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-5.0.13.200.zip ..."
|
||||
7z x commandline-tools-linux-x64-5.0.13.200.zip.001 -o$HOME/openharmony > /dev/null
|
||||
echo "Download commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.001
|
||||
wget -q https://github.com/cocos/oh-sdk-for-ci/releases/download/api-21/commandline-tools-linux-x64-6.0.1.246.zip.002
|
||||
echo "Unzip commandline-tools-linux-x64-6.0.1.246.zip ..."
|
||||
7z x commandline-tools-linux-x64-6.0.1.246.zip.001 -o$HOME/openharmony > /dev/null
|
||||
cd $HOME/openharmony
|
||||
ls -l
|
||||
cd command-line-tools
|
||||
|
||||
@@ -1027,7 +1027,7 @@ export class Label extends UIRenderer {
|
||||
if (!this.renderData) {
|
||||
if (this._assembler && this._assembler.createData) {
|
||||
this._renderData = this._assembler.createData(this) as RenderData;
|
||||
this.renderData!.material = this.material;
|
||||
this.renderData!.material = this.getRenderMaterial(0);
|
||||
this._updateColor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable, visible } from 'cc.decorator';
|
||||
import { BUILD, EDITOR } from 'internal:constants';
|
||||
import { BUILD, JSB, EDITOR } from 'internal:constants';
|
||||
import { SpriteAtlas } from '../assets/sprite-atlas';
|
||||
import { SpriteFrame, SpriteFrameEvent } from '../assets/sprite-frame';
|
||||
import { builtinResMgr } from '../../asset/asset-manager/builtin-res-mgr';
|
||||
@@ -703,6 +703,7 @@ export class Sprite extends UIRenderer {
|
||||
}
|
||||
if (textureChanged) {
|
||||
if (self.renderData) self.renderData.textureDirty = true;
|
||||
if (JSB) this._colorDirty();
|
||||
// texture type changed, set this._instanceMaterialType to default value
|
||||
const oldIsRT = oldFrame ? oldFrame.texture instanceof RenderTexture : false;
|
||||
const newIsRT = spriteFrame.texture instanceof RenderTexture;
|
||||
|
||||
@@ -398,9 +398,7 @@ export class UIRenderer extends Renderer {
|
||||
this.node.off(NodeEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
|
||||
this.node.off(NodeEventType.SIZE_CHANGED, this._nodeStateChange, this);
|
||||
this.node.off(NodeEventType.PARENT_CHANGED, this._colorDirty, this);
|
||||
// When disabling, it is necessary to free up idle space to fully utilize chunks
|
||||
// and avoid breaking batch processing.
|
||||
this._destroyData();
|
||||
this.destroyRenderData();
|
||||
uiRendererManager.removeRenderer(this);
|
||||
this._renderFlag = false;
|
||||
this._renderEntity.enabled = false;
|
||||
@@ -544,10 +542,8 @@ export class UIRenderer extends Renderer {
|
||||
}
|
||||
|
||||
protected _updateColor (): void {
|
||||
this.node._uiProps.colorDirty = true;
|
||||
this.setEntityColorDirty(true);
|
||||
this._colorDirty();
|
||||
this.setEntityColor(this._color);
|
||||
|
||||
const assembler = this._assembler;
|
||||
if (assembler) {
|
||||
if (assembler.updateColor) {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo } from '../../gfx';
|
||||
import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo, Feature, API } from '../../gfx';
|
||||
import { getAttributeStride } from './vertex-format';
|
||||
import { sys, getError, warnID, assertIsTrue } from '../../core';
|
||||
import { NativeUIMeshBuffer } from './native-2d';
|
||||
@@ -251,7 +251,12 @@ export class MeshBuffer {
|
||||
|
||||
this.floatsPerVertex = getAttributeStride(attrs) >> 2;
|
||||
|
||||
assertIsTrue(this._initVDataCount / this._floatsPerVertex < 65536, getError(9005));
|
||||
var vDataCountLimit = 65536; // 2^16 - 1
|
||||
const glApi = device.gfxAPI;
|
||||
if (glApi === API.WEBGPU || glApi === API.WEBGL2 || glApi === API.WEBGL && device.hasFeature(Feature.ELEMENT_INDEX_UINT)) {
|
||||
vDataCountLimit = 4294967295; // 2^32 - 1
|
||||
}
|
||||
assertIsTrue(this._initVDataCount / this._floatsPerVertex < vDataCountLimit, getError(9005));
|
||||
|
||||
if (!this.vData || !this.iData) {
|
||||
this.vData = new Float32Array(this._initVDataCount);
|
||||
|
||||
@@ -125,10 +125,8 @@ imageAssetProto._setRawAsset = function (filename: string, inLibrary = true) {
|
||||
imageAssetProto.reset = function (data: any) {
|
||||
this._nativeData = data;
|
||||
|
||||
if (!(data instanceof jsbWindow.HTMLElement)) {
|
||||
if(data.format !== undefined) {
|
||||
this.format = (data as any).format;
|
||||
}
|
||||
if (data.format !== undefined && !this.isFormatFixed()) {
|
||||
this.format = (data as any).format;
|
||||
}
|
||||
this._syncDataToNative();
|
||||
};
|
||||
@@ -267,8 +265,7 @@ imageAssetProto._deserialize = function (data: any) {
|
||||
|
||||
if (ext) {
|
||||
this._setRawAsset(ext);
|
||||
this.format = format;
|
||||
// this._format = format;
|
||||
this.setFixedFormat(format);
|
||||
} else {
|
||||
warnID(3121);
|
||||
}
|
||||
|
||||
@@ -1066,17 +1066,25 @@ interface Macro {
|
||||
ENABLE_WEBGL_HIGHP_STRUCT_VALUES: boolean;
|
||||
|
||||
/**
|
||||
* @zh Batcher2D 中内存增量的大小(KB)
|
||||
* 这个值决定了当场景中存在的 2d 渲染组件的顶点数量超过当前 batcher2D 中可容纳的顶点数量时,内存扩充的增加量
|
||||
* 这个值越大,共用同一个 meshBuffer 的 2d 渲染组件数量会更多,但每次扩充所占用的内存也会更大
|
||||
* 默认值在标准格式([[VertexFormat.vfmtPosUvColor]])下可容纳 4096 个顶点(4096*9*4/1024),你可以增加容量来提升每个批次可容纳的元素数量
|
||||
* @en The MeshBuffer chunk size in Batcher2D (KB)
|
||||
* This value determines the increase in memory expansion,
|
||||
* when the number of vertices of 2d rendering components present in the scene exceeds the number of vertices,
|
||||
* that can be accommodated in the current batcher2D.
|
||||
* The larger this value is, the more 2d rendering components will share the same meshBuffer, but the more memory will be used for each expansion
|
||||
* The default size can contain 4096 standard vertex ([[VertexFormat.vfmtPosUvColor]]) in one buffer,
|
||||
* you can user larger buffer size to increase the elements count per 2d draw batch.
|
||||
* @zh Batcher2D 中每个渲染批次的内存增量(KB)
|
||||
* 增大此值能使参与渲染合批的 2d 渲染组件数量增加,但是每次增加渲染批次的内存增量也会变大。
|
||||
* 这个值决定每个 2D 渲染批次的顶点数量,计算公式为 vCount = Math.floor(macro.BATCHER2D_MEM_INCREMENT * 1024 / 9 * 4);
|
||||
* WebGL2 & WebGPU 等渲染后端的最大顶点数量通常是 2^32 - 1,即 4294967295。
|
||||
* WebGL1 渲染后端的最大顶点数量通常是 2^16 - 1,即 65535。引擎使用拓展 OES_element_index_uint 突破了这个限制,最大顶点数量也可达到 2^32 - 1。
|
||||
* 所以 macro.BATCHER2D_MEM_INCREMENT 的理论最大值为 150994943,但是因为所运行平台的 js 引擎对 Float32Array|Uint16Array 的最大长度有限制,实际最大值往往会小于 2^32 - 1。
|
||||
* 建议最大值不超过 1048576 kb (1GB),否则会因为 js 引擎的限制而导致 buffer 创建失败。
|
||||
* @en Memory increment (KB) for each rendering batch in Batcher2D
|
||||
* Increasing this value can increase the number of 2D rendering components involved in rendering batching, but the memory increment for each additional rendering batch will also become larger.
|
||||
* This value determines the number of vertices in each 2D rendering batch, calculated as vCount = Math.floor(macro.BATCHER2D_MEM_INCREMENT * 1024 / 9 * 4);
|
||||
* The maximum number of vertices for rendering backends such as WebGL2 & WebGPU is usually 2^32 - 1, which is 4294967295.
|
||||
* The maximum number of vertices for the WebGL1 rendering backend is usually 2^16 - 1, which is 65535. The engine uses the extension OES_element_index_uint to break this limit, and the maximum number of vertices can also reach 2^32 - 1.
|
||||
* Therefore, the theoretical maximum value of macro.BATCHER2D_MEM_INCREMENT is 150994943. However, due to the limitations of the JS engine on the maximum length of Float32Array|Uint16Array on the running platform, the actual maximum value is often less than 2^32 - 1.
|
||||
* It is recommended that the maximum value does not exceed 1048576 kb (1GB); otherwise, buffer creation will fail due to JS engine limitations.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { macro } from 'cc';
|
||||
* macro.BATCHER2D_MEM_INCREMENT = 4096; //4096 KB
|
||||
* ```
|
||||
* @default 144 KB
|
||||
*/
|
||||
BATCHER2D_MEM_INCREMENT: number;
|
||||
|
||||
@@ -155,7 +155,7 @@ class MotionStreakAssembler implements IAssembler {
|
||||
|
||||
renderData.resize(vertexCount, indexCount); // resize
|
||||
|
||||
if (JSB) {
|
||||
if (JSB && comp.texture) {
|
||||
const indexCount = renderData.indexCount;
|
||||
this.createQuadIndices(comp, indexCount);
|
||||
renderData.chunk.setIndexBuffer(QUAD_INDICES!);
|
||||
@@ -163,7 +163,7 @@ class MotionStreakAssembler implements IAssembler {
|
||||
// Fill all dataList to vData
|
||||
this.updateWorldVertexAllData(comp);
|
||||
|
||||
renderData.updateRenderData(comp, comp.texture!);
|
||||
renderData.updateRenderData(comp, comp.texture);
|
||||
comp._markForUpdateRenderData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1443,7 +1443,8 @@ export class ParticleSystem extends ModelRenderer {
|
||||
// emit particles.
|
||||
const startDelay = self.startDelay.evaluate(0, 1)!;
|
||||
if (self._time > startDelay) {
|
||||
if (self._time > (self.duration + startDelay)) {
|
||||
const timeLeft = self._time - (self.duration + startDelay);
|
||||
if (timeLeft > dt) {
|
||||
// self._time = startDelay; // delay will not be applied from the second loop.(Unity)
|
||||
// self._emitRateTimeCounter = 0.0;
|
||||
// self._emitRateDistanceCounter = 0.0;
|
||||
@@ -1478,8 +1479,10 @@ export class ParticleSystem extends ModelRenderer {
|
||||
}
|
||||
|
||||
// bursts
|
||||
for (const burst of self.bursts) {
|
||||
burst.update(self, dt);
|
||||
if (timeLeft <= 0 || self.loop) {
|
||||
for (const burst of self.bursts) {
|
||||
burst.update(self, dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +373,8 @@ export class Skeleton extends UIRenderer {
|
||||
this.defaultAnimation = '';
|
||||
this._animationName = '';
|
||||
this._skinName = '';
|
||||
this._animCache = null;
|
||||
this._destroySkeletonInfo(this._skeletonCache);
|
||||
this._updateSkeletonData();
|
||||
this._updateUITransform();
|
||||
}
|
||||
|
||||
+26
-12
@@ -55,6 +55,7 @@ cc_set_if_undefined(USE_REMOTE_LOG OFF)
|
||||
cc_set_if_undefined(USE_ADPF OFF)
|
||||
cc_set_if_undefined(USE_GOOGLE_BILLING OFF)
|
||||
cc_set_if_undefined(USE_GOOGLE_PLAY_GAMES OFF)
|
||||
cc_set_if_undefined(USE_GAMEPAD ON)
|
||||
|
||||
if(ANDROID AND NOT DEFINED USE_CCACHE)
|
||||
if("$ENV{COCOS_USE_CCACHE}" STREQUAL "1")
|
||||
@@ -368,7 +369,7 @@ NO_WERROR cocos/audio/common/utils/primitives.cpp
|
||||
cocos/audio/android/utils/Utils.cpp
|
||||
cocos/audio/android/utils/Utils.h
|
||||
)
|
||||
if(ANDROID)
|
||||
if(ANDROID)
|
||||
cocos_source_files(
|
||||
cocos/audio/android/PcmAudioService.cpp
|
||||
cocos/audio/android/PcmAudioService.h
|
||||
@@ -376,7 +377,7 @@ NO_WERROR cocos/audio/common/utils/primitives.cpp
|
||||
cocos/audio/android/UrlAudioPlayer.h
|
||||
)
|
||||
elseif(OPENHARMONY)
|
||||
cocos_source_files(
|
||||
cocos_source_files(
|
||||
cocos/audio/openharmony/PcmAudioService.cpp
|
||||
cocos/audio/openharmony/PcmAudioService.h
|
||||
cocos/audio/openharmony/UrlAudioPlayer.cpp
|
||||
@@ -590,6 +591,13 @@ elseif(OPENHARMONY)
|
||||
cocos/platform/openharmony/OpenHarmonyPlatform.cpp
|
||||
cocos/platform/openharmony/OpenHarmonyPlatform.h
|
||||
)
|
||||
if(USE_GAMEPAD)
|
||||
cocos_source_files(
|
||||
cocos/platform/openharmony/OpenHarmonyGamepad.cpp
|
||||
cocos/platform/openharmony/OpenHarmonyGamepad.h
|
||||
)
|
||||
endif()
|
||||
|
||||
elseif(OHOS)
|
||||
cocos_source_files(
|
||||
cocos/platform/ohos/OhosPlatform.cpp
|
||||
@@ -611,7 +619,7 @@ elseif(IOS)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USE_ADPF)
|
||||
if(USE_ADPF)
|
||||
cocos_source_files(
|
||||
cocos/platform/android/adpf_manager.h
|
||||
cocos/platform/android/adpf_manager.cpp
|
||||
@@ -801,7 +809,7 @@ if(USE_GOOGLE_BILLING)
|
||||
vendor/google/billing/build-params/PendingPurchasesParams.h
|
||||
vendor/google/billing/build-params/QueryProductDetailsParams.h
|
||||
vendor/google/billing/build-params/QueryPurchasesParams.h
|
||||
|
||||
|
||||
vendor/google/billing/result-values/AccountIdentifiers.h
|
||||
vendor/google/billing/result-values/AlternativeBillingOnlyReportingDetails.h
|
||||
vendor/google/billing/result-values/BillingConfig.h
|
||||
@@ -1140,7 +1148,7 @@ set(SWIG_OUTPUT_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated)
|
||||
set(SWIG_OUTPUT ${SWIG_OUTPUT_ROOT}/cocos/bindings/auto)
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config ${SWIG_OUTPUT})
|
||||
|
||||
if(USE_GOOGLE_BILLING)
|
||||
if(USE_GOOGLE_BILLING)
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config/android/google/billing ${SWIG_OUTPUT})
|
||||
endif()
|
||||
|
||||
@@ -3040,7 +3048,7 @@ if(USE_SE_JSVM)
|
||||
|
||||
if (NOT OPENHARMONY)
|
||||
include_directories(${CWD}/cocos/bindings/jswrapper/jsvm-v8-backend)
|
||||
cocos_source_files(MODULE ccbindings
|
||||
cocos_source_files(MODULE ccbindings
|
||||
cocos/bindings/jswrapper/jsvm-v8-backend/js_native_api_v8.cc
|
||||
cocos/bindings/jswrapper/jsvm-v8-backend/js_native_api_v8.h
|
||||
cocos/bindings/jswrapper/jsvm-v8-backend/js_native_api_v8_internals.h
|
||||
@@ -3441,7 +3449,7 @@ function(cc_apply_definations target)
|
||||
$<IF:$<BOOL:${USE_GOOGLE_BILLING}>,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0>
|
||||
$<IF:$<BOOL:${USE_GOOGLE_PLAY_GAMES}>,CC_USE_GOOGLE_PLAY_GAMES=1,CC_USE_GOOGLE_PLAY_GAMES=0>
|
||||
$<IF:$<BOOL:${USE_BOX2D_JSB}>,CC_USE_BOX2D_JSB=1,CC_USE_BOX2D_JSB=0>
|
||||
|
||||
$<IF:$<BOOL:${USE_GAMEPAD}>,CC_USE_GAMEPAD=1,CC_USE_GAMEPAD=0>
|
||||
)
|
||||
endfunction()
|
||||
|
||||
@@ -3634,7 +3642,7 @@ if(OPENHARMONY)
|
||||
|
||||
find_library( hilog-lib
|
||||
hilog_ndk.z )
|
||||
|
||||
|
||||
find_library( # Sets the name of the path variable.
|
||||
libace-lib
|
||||
# Specifies the name of the NDK library that
|
||||
@@ -3671,13 +3679,19 @@ if(OPENHARMONY)
|
||||
libnative_window.so
|
||||
libnative_buffer.so
|
||||
libbundle_ndk.z.so
|
||||
libace_napi.z.so
|
||||
libace_ndk.z.so
|
||||
libz.so
|
||||
libace_napi.z.so
|
||||
libace_ndk.z.so
|
||||
libz.so
|
||||
librawfile.z.so
|
||||
libdeviceinfo_ndk.z.so
|
||||
libohsensor.so
|
||||
${CC_EXTERNAL_LIBS}
|
||||
)
|
||||
|
||||
if(USE_GAMEPAD)
|
||||
list(APPEND LIBS libohgame_controller.z.so)
|
||||
endif()
|
||||
|
||||
if(USE_SE_JSVM)
|
||||
list(APPEND LIBS libjsvm.so)
|
||||
endif()
|
||||
@@ -3768,7 +3782,7 @@ set(COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${COCOS_SOURCE_LIST})
|
||||
set(COCOS_GENERATED_LIST)
|
||||
foreach(src IN LISTS COCOS_SOURCE_LIST_EXCLUDE_GENRATED)
|
||||
get_source_file_property(IS_GENERATED ${src} GENERATED)
|
||||
if(IS_GENERATED)
|
||||
if(IS_GENERATED)
|
||||
list(REMOVE_ITEM COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${src})
|
||||
list(APPEND COCOS_GENERATED_LIST ${src})
|
||||
endif()
|
||||
|
||||
@@ -28,6 +28,7 @@ THE SOFTWARE.
|
||||
#include "audio/openharmony/PcmAudioService.h"
|
||||
#include "audio/android/AudioMixerController.h"
|
||||
#include "audio/android/cutils/log.h"
|
||||
#include <deviceinfo.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -104,7 +105,12 @@ bool PcmAudioService::init(AudioMixerController *controller, int numChannels, in
|
||||
OH_AudioStreamBuilder_SetRendererInfo(_builder, AUDIOSTREAM_USAGE_GAME);
|
||||
|
||||
OH_AudioRenderer_Callbacks callbacks;
|
||||
callbacks.OH_AudioRenderer_OnWriteData = nullptr;
|
||||
static int sdkApi = OH_GetSdkApiVersion();
|
||||
if(sdkApi >= 21) {
|
||||
callbacks.OH_AudioRenderer_OnWriteData = nullptr;
|
||||
} else {
|
||||
callbacks.OH_AudioRenderer_OnWriteData = reinterpret_cast<int32_t (*)(OH_AudioRenderer*,void* ,void* ,int32_t)>(AudioRendererOnWriteData);
|
||||
}
|
||||
callbacks.OH_AudioRenderer_OnInterruptEvent = AudioRendererOnInterrupt;
|
||||
callbacks.OH_AudioRenderer_OnError = nullptr;
|
||||
callbacks.OH_AudioRenderer_OnStreamEvent = nullptr;
|
||||
@@ -112,10 +118,12 @@ bool PcmAudioService::init(AudioMixerController *controller, int numChannels, in
|
||||
if (ret != AUDIOSTREAM_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = OH_AudioStreamBuilder_SetRendererWriteDataCallback(_builder, AudioRendererOnWriteData, this);
|
||||
if (ret != AUDIOSTREAM_SUCCESS) {
|
||||
return false;
|
||||
|
||||
if(sdkApi >= 21) {
|
||||
ret = OH_AudioStreamBuilder_SetRendererWriteDataCallback(_builder, AudioRendererOnWriteData, this);
|
||||
if (ret != AUDIOSTREAM_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ret = OH_AudioStreamBuilder_GenerateRenderer(_builder, &_audioRenderer);
|
||||
|
||||
@@ -541,7 +541,15 @@ void ScriptEngine::handlePromiseExceptions() {
|
||||
}
|
||||
|
||||
void ScriptEngine::mainLoopUpdate() {
|
||||
// empty implementation
|
||||
// Run all tasks
|
||||
JSVM_Status status{};
|
||||
for (bool runTasks = true; runTasks;) {
|
||||
// Execute one foreground task (if one exists), then microtasks.
|
||||
NODE_API_CALL(status, _env, OH_JSVM_PumpMessageLoop(_vm, &runTasks));
|
||||
if (runTasks) {
|
||||
NODE_API_CALL(status, _env, OH_JSVM_PerformMicrotaskCheckpoint(_vm));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::throwException(const std::string &errorMessage) {
|
||||
|
||||
@@ -572,6 +572,7 @@ struct ImageInfo *createImageInfo(Image *img) {
|
||||
|
||||
if (dst != imgInfo->data) free(imgInfo->data);
|
||||
imgInfo->data = dst;
|
||||
imgInfo->format = cc::gfx::Format::RGBA8;
|
||||
imgInfo->hasAlpha = true;
|
||||
}
|
||||
|
||||
@@ -629,6 +630,7 @@ bool jsb_global_load_image(const ccstd::string &path, const se::Value &callbackV
|
||||
retObj->setProperty("data", se::Value(obj));
|
||||
retObj->setProperty("width", se::Value(imgInfo->width));
|
||||
retObj->setProperty("height", se::Value(imgInfo->height));
|
||||
retObj->setProperty("format", se::Value(static_cast<int>(imgInfo->format)));
|
||||
|
||||
se::Value mipmapLevelDataSizeArr;
|
||||
nativevalue_to_se(imgInfo->mipmapLevelDataSize, mipmapLevelDataSizeArr, nullptr);
|
||||
|
||||
@@ -112,7 +112,12 @@ public:
|
||||
inline void setNeedFreeData(bool v) { _needFreeData = v; }
|
||||
inline void setUrl(const ccstd::string &url) { _url = url; }
|
||||
inline void setMipmapLevelDataSize(const ccstd::vector<uint32_t> &mipmapLevelDataSize) { _mipmapLevelDataSize = mipmapLevelDataSize; }
|
||||
|
||||
inline void setFixedFormat(PixelFormat format) {
|
||||
setFormat(format);
|
||||
_isFormatFixed = true;
|
||||
}
|
||||
inline bool isFormatFixed() const { return _isFormatFixed; }
|
||||
|
||||
// Functions for Utils.
|
||||
IntrusivePtr<ImageAsset> extractMipmap0();
|
||||
std::vector<IntrusivePtr<ImageAsset>> extractMipmaps();
|
||||
@@ -123,7 +128,12 @@ private:
|
||||
PixelFormat _format{PixelFormat::RGBA8888};
|
||||
uint32_t _width{0};
|
||||
uint32_t _height{0};
|
||||
|
||||
/*
|
||||
* A fixed image format will not be altered by the parsed data format. In iOS, the declared format may not necessarily reflect the true format of the data.
|
||||
* For example, the format might be labeled as RGB_A_PVRTC_4BPPV1, but the actual data format is RGB_PVRTC_4BPPV1. RGB_A_PVRTC_4BPPV1 is a custom format,
|
||||
* and in such cases, it must be explicitly set as a fixed format. Otherwise, it will be replaced by the true format of the data.
|
||||
*/
|
||||
bool _isFormatFixed{false};
|
||||
bool _needFreeData{false}; // Should free data if the data is assigned in C++.
|
||||
|
||||
ArrayBuffer::Ptr _arrayBuffer; //minggo: hold the data from ImageSource.
|
||||
|
||||
@@ -265,7 +265,7 @@ enum class KeyCode {
|
||||
DPAD_LEFT = 1000,
|
||||
DPAD_DOWN = 1004,
|
||||
DPAD_RIGHT = 1001,
|
||||
DPAD_CENTER = 1005
|
||||
DPAD_CENTER = 1005,
|
||||
};
|
||||
|
||||
class KeyboardEvent {
|
||||
|
||||
@@ -47,6 +47,11 @@
|
||||
#include "tinydir/tinydir.h"
|
||||
#include "tinyxml2/tinyxml2.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// Implement DictMaker
|
||||
@@ -1059,15 +1064,35 @@ int unlinkCb(const char *fpath, const struct stat * /*sb*/, int /*typeflag*/, st
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
bool FileUtils::removeDirectory(const ccstd::string &path) {
|
||||
bool FileUtils::removeDirectory(const ccstd::string &path) { // NOLINT(misc-no-recursion)
|
||||
#if (CC_PLATFORM != CC_PLATFORM_ANDROID)
|
||||
return nftw(path.c_str(), unlinkCb, 64, FTW_DEPTH | FTW_PHYS) != -1;
|
||||
#else
|
||||
ccstd::string command = "rm -r ";
|
||||
// Path may include space.
|
||||
command += "\"" + path + "\"";
|
||||
DIR* dir = opendir(path.c_str());
|
||||
if (!dir) return false;
|
||||
|
||||
return (system(command.c_str()) >= 0);
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != nullptr) {
|
||||
// 跳过 . 和 ..
|
||||
if (strcmp(entry->d_name, ".") == 0 ||
|
||||
strcmp(entry->d_name, "..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string fullPath = path + "/" + entry->d_name;
|
||||
|
||||
if (entry->d_type == DT_DIR) {
|
||||
// remove sub directory
|
||||
removeDirectory(fullPath);
|
||||
} else {
|
||||
// remove file
|
||||
unlink(fullPath.c_str());
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
// remove empty directory
|
||||
return rmdir(path.c_str()) == 0;
|
||||
#endif // (CC_PLATFORM != CC_PLATFORM_ANDROID)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
namespace {
|
||||
std::unordered_map<int, cc::KeyCode> gKeyMap = {
|
||||
{SDLK_LGUI, cc::KeyCode::META_LEFT},
|
||||
{SDLK_RGUI, cc::KeyCode::META_RIGHT},
|
||||
{SDLK_APPLICATION, cc::KeyCode::CONTEXT_MENU},
|
||||
{SDLK_SCROLLLOCK, cc::KeyCode::SCROLLLOCK},
|
||||
{SDLK_PAUSE, cc::KeyCode::PAUSE},
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 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/platform/openharmony/OpenHarmonyGamepad.h"
|
||||
#include "cocos/base/Log.h"
|
||||
#include "cocos/engine/EngineEvents.h"
|
||||
#include "cocos/platform/openharmony/OpenHarmonyPlatform.h"
|
||||
#include "cocos/platform/openharmony/WorkerMessageQueue.h"
|
||||
|
||||
#include "GameControllerKit/game_device.h"
|
||||
#include "GameControllerKit/game_device_event.h"
|
||||
#include "GameControllerKit/game_pad.h"
|
||||
|
||||
namespace cc {
|
||||
static char gGameControllerIds{0};
|
||||
static std::unordered_map<std::string, char> gControllers;
|
||||
static constexpr char kMaxControllers = sizeof(gGameControllerIds) * 8;
|
||||
#define CALL_OH_GAMEPAD(the_call) \
|
||||
do { \
|
||||
GameController_ErrorCode errorCode = (the_call); \
|
||||
if (errorCode != GameController_ErrorCode::GAME_CONTROLLER_SUCCESS) { \
|
||||
CC_LOG_ERROR("%s failed: %d", #the_call, errorCode); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
enum ButtonCode {
|
||||
OH_LeftShoulder = 2307,
|
||||
OH_RightShoulder = 2308,
|
||||
OH_LeftTrigger = 2309,
|
||||
OH_RightTrigger = 2310,
|
||||
OH_LeftThumbstick = 2314,
|
||||
OH_RightThumbstick = 2315,
|
||||
OH_ButtonHome = 2311,
|
||||
OH_ButtonMenu = 2312,
|
||||
OH_ButtonA = 2301,
|
||||
OH_ButtonB = 2302,
|
||||
OH_ButtonC = 2303,
|
||||
OH_ButtonX = 2304,
|
||||
OH_ButtonY = 2305,
|
||||
OH_Dpad_UpButton = 2012,
|
||||
OH_Dpad_DownButton = 2013,
|
||||
OH_Dpad_LeftButton = 2014,
|
||||
OH_Dpad_RightButton = 2015,
|
||||
};
|
||||
|
||||
StickKeyCode ohButtonCode2StickKeyCode(int32_t code) {
|
||||
switch (code) {
|
||||
case OH_LeftShoulder: return StickKeyCode::L1;
|
||||
case OH_RightShoulder: return StickKeyCode::R1;
|
||||
case OH_LeftThumbstick: return StickKeyCode::L3;
|
||||
case OH_RightThumbstick: return StickKeyCode::R3;
|
||||
|
||||
case OH_ButtonA: return StickKeyCode::B;
|
||||
case OH_ButtonB: return StickKeyCode::A;
|
||||
case OH_ButtonX: return StickKeyCode::Y;
|
||||
case OH_ButtonY: return StickKeyCode::X;
|
||||
|
||||
case OH_ButtonHome: return StickKeyCode::MINUS;
|
||||
case OH_ButtonMenu:
|
||||
return StickKeyCode::PLUS;
|
||||
// case OH_ButtonC: return StickAxisCode::HOME;
|
||||
}
|
||||
return StickKeyCode::UNDEFINE;
|
||||
}
|
||||
|
||||
void SendAxisEvent(const char* deviceId, double result, StickAxisCode stickAxisCode) {
|
||||
auto it = gControllers.find(deviceId);
|
||||
if (it == gControllers.end()) {
|
||||
CC_LOG_ERROR("Controller not found");
|
||||
return;
|
||||
}
|
||||
cc::ControllerInfo info;
|
||||
info.napdId = it->second;
|
||||
info.axisInfos.emplace_back(stickAxisCode, result);
|
||||
|
||||
ControllerEvent* ev = new ControllerEvent;
|
||||
ev->type = ControllerEvent::Type::GAMEPAD;
|
||||
ev->controllerInfos.emplace_back(std::make_unique<ControllerInfo>(std::move(info)));
|
||||
OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_GAMEPAD_CONTROLLER_INPUT, reinterpret_cast<void*>(ev), nullptr);
|
||||
}
|
||||
|
||||
void SendAxisEvent(const char* deviceId, double result_x, double result_y, StickAxisCode stickAxisCodeX, StickAxisCode stickAxisCodeY) {
|
||||
auto it = gControllers.find(deviceId);
|
||||
if (it == gControllers.end()) {
|
||||
CC_LOG_ERROR("Controller not found");
|
||||
return;
|
||||
}
|
||||
cc::ControllerInfo info;
|
||||
info.napdId = it->second;
|
||||
info.axisInfos.emplace_back(stickAxisCodeX, result_x);
|
||||
info.axisInfos.emplace_back(stickAxisCodeY, result_y);
|
||||
|
||||
ControllerEvent* ev = new ControllerEvent;
|
||||
ev->type = ControllerEvent::Type::GAMEPAD;
|
||||
ev->controllerInfos.emplace_back(std::make_unique<ControllerInfo>(std::move(info)));
|
||||
OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_GAMEPAD_CONTROLLER_INPUT, reinterpret_cast<void*>(ev), nullptr);
|
||||
}
|
||||
|
||||
void OnLeftThumbstickAxisEventCallback(const struct GamePad_AxisEvent* axisEvent) {
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetDeviceId(axisEvent, &deviceId));
|
||||
double result_x;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetXAxisValue(axisEvent, &result_x));
|
||||
double result_y;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetYAxisValue(axisEvent, &result_y));
|
||||
|
||||
SendAxisEvent(deviceId, result_x, -result_y, StickAxisCode::LEFT_STICK_X, StickAxisCode::LEFT_STICK_Y);
|
||||
free(deviceId);
|
||||
}
|
||||
|
||||
void OnRightThumbstickAxisEventCallback(const struct GamePad_AxisEvent* axisEvent) {
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetDeviceId(axisEvent, &deviceId));
|
||||
double result_x;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetZAxisValue(axisEvent, &result_x));
|
||||
double result_y;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetRZAxisValue(axisEvent, &result_y));
|
||||
SendAxisEvent(deviceId, result_x, -result_y, StickAxisCode::RIGHT_STICK_X, StickAxisCode::RIGHT_STICK_Y);
|
||||
free(deviceId);
|
||||
}
|
||||
|
||||
void OnDpadAxisEventCallback(const struct GamePad_AxisEvent* axisEvent) {
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetDeviceId(axisEvent, &deviceId));
|
||||
double result_x;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetHatXAxisValue(axisEvent, &result_x));
|
||||
double result_y;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetHatYAxisValue(axisEvent, &result_y));
|
||||
SendAxisEvent(deviceId, result_x, -result_y, StickAxisCode::X, StickAxisCode::Y);
|
||||
free(deviceId);
|
||||
}
|
||||
|
||||
void OnLeftTriggerAxisEventCallback(const struct GamePad_AxisEvent* axisEvent) {
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetDeviceId(axisEvent, &deviceId));
|
||||
double result;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetBrakeAxisValue(axisEvent, &result));
|
||||
SendAxisEvent(deviceId, result, cc::StickAxisCode::L2);
|
||||
free(deviceId);
|
||||
}
|
||||
|
||||
void OnRightTriggerAxisEventCallback(const struct GamePad_AxisEvent* axisEvent) {
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetDeviceId(axisEvent, &deviceId));
|
||||
double result;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_AxisEvent_GetGasAxisValue(axisEvent, &result));
|
||||
SendAxisEvent(deviceId, result, cc::StickAxisCode::R2);
|
||||
free(deviceId);
|
||||
}
|
||||
|
||||
void OnDeviceChanged(const struct GameDevice_DeviceEvent* deviceEvent) {
|
||||
GameDevice_StatusChangedType status;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceEvent_GetChangedType(deviceEvent, &status));
|
||||
GameDevice_DeviceInfo* deviceInfo;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceEvent_GetDeviceInfo(deviceEvent, &deviceInfo));
|
||||
char* deviceId = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetDeviceId(deviceInfo, &deviceId));
|
||||
char* name = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetName(deviceInfo, &name));
|
||||
|
||||
int product;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetProduct(deviceInfo, &product));
|
||||
int version;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetVersion(deviceInfo, &version));
|
||||
char* physicalAddress = nullptr;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetPhysicalAddress(deviceInfo, &physicalAddress));
|
||||
GameDevice_DeviceType type;
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DeviceInfo_GetDeviceType(deviceInfo, &type));
|
||||
|
||||
// TODO: This is a hack because some system components in HarmonyOS also receive this message, making it impossible
|
||||
// to distinguish between a game controller and system components. This could cause the game to misinterpret
|
||||
// the presence of multiple controllers, leading to anomalies. Therefore, a filter condition has been added here.
|
||||
// Theoretically, the distinction should be made using the "type" field, but in the system, game controllers are also identified as "unknown".
|
||||
// product == 480 && version == 256 : hid-over-i2c 27C6:01E0 Touchpad
|
||||
// product == 5120 && version == 256 : uart_hid 14F3:1400 System Control
|
||||
if((product == 480 && version == 256) || (product == 5120 && version == 256)) {
|
||||
return;
|
||||
}
|
||||
// if(type != GameDevice_DeviceType::GAME_PAD) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
do {
|
||||
if (status == GameDevice_StatusChangedType::ONLINE) {
|
||||
int id = 0;
|
||||
do {
|
||||
if ((gGameControllerIds & (1 << id)) == 0) {
|
||||
break;
|
||||
}
|
||||
id++;
|
||||
} while (id < kMaxControllers);
|
||||
if (id >= kMaxControllers) {
|
||||
CC_LOG_ERROR("The number of controllers should not exceed %d", kMaxControllers);
|
||||
break;
|
||||
}
|
||||
gGameControllerIds |= (1 << id);
|
||||
gControllers.insert(std::make_pair(std::string(deviceId), id));
|
||||
} else {
|
||||
auto it = gControllers.find(deviceId);
|
||||
if (it == gControllers.end()) {
|
||||
CC_LOG_ERROR("Controller not found: %s, %s", name, deviceId);
|
||||
break;
|
||||
}
|
||||
gGameControllerIds &= ~(1 << it->second);
|
||||
gControllers.erase(it);
|
||||
}
|
||||
ControllerChangeEvent* ev = new ControllerChangeEvent;
|
||||
// Send an online controllers.
|
||||
for (auto controller : gControllers) {
|
||||
ev->controllerIds.emplace_back(controller.second);
|
||||
}
|
||||
OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_GAMEPAD_CONTROLLER_CHANGE, reinterpret_cast<void*>(ev), nullptr);
|
||||
} while (0);
|
||||
|
||||
free(deviceId);
|
||||
free(physicalAddress);
|
||||
free(name);
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_DestroyDeviceInfo(&deviceInfo));
|
||||
}
|
||||
|
||||
void OnButtonEvent(const struct GamePad_ButtonEvent* buttonEvent) {
|
||||
char* deviceId;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonEvent_GetDeviceId(buttonEvent, &deviceId));
|
||||
GamePad_Button_ActionType action;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonEvent_GetButtonAction(buttonEvent, &action));
|
||||
std::int32_t buttonCode;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonEvent_GetButtonCode(buttonEvent, &buttonCode));
|
||||
char* buttonCodeName;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonEvent_GetButtonCodeName(buttonEvent, &buttonCodeName));
|
||||
std::int64_t actionTime;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonEvent_GetActionTime(buttonEvent, &actionTime));
|
||||
std::int32_t count;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_PressedButtons_GetCount(buttonEvent, &count));
|
||||
for (std::int32_t idx = 0; idx < count; idx++) {
|
||||
GamePad_PressedButton* pressedButton;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_PressedButtons_GetButtonInfo(buttonEvent, idx, &pressedButton));
|
||||
int code;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_PressedButton_GetButtonCode(pressedButton, &code));
|
||||
char* name;
|
||||
CALL_OH_GAMEPAD(OH_GamePad_PressedButton_GetButtonCodeName(pressedButton, &name));
|
||||
free(name);
|
||||
}
|
||||
auto it = gControllers.find(deviceId);
|
||||
if (it == gControllers.end()) {
|
||||
CC_LOG_ERROR("Controller not found");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isPressed = (action == GamePad_Button_ActionType::DOWN);
|
||||
cc::ControllerInfo info;
|
||||
cc::ControllerInfo::ButtonInfo buttonInfo{ohButtonCode2StickKeyCode(buttonCode), isPressed};
|
||||
info.buttonInfos.emplace_back(buttonInfo);
|
||||
info.napdId = it->second;
|
||||
ControllerEvent* ev = new ControllerEvent;
|
||||
ev->type = ControllerEvent::Type::GAMEPAD;
|
||||
ev->controllerInfos.emplace_back(std::make_unique<ControllerInfo>(std::move(info)));
|
||||
OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_GAMEPAD_CONTROLLER_INPUT, reinterpret_cast<void*>(ev), nullptr);
|
||||
}
|
||||
|
||||
OpenHarmonyGamePad::OpenHarmonyGamePad() {
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_RegisterDeviceMonitor(OnDeviceChanged));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftShoulder_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightShoulder_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonMenu_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonHome_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonC_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonA_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonB_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonX_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonY_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_RegisterButtonInputMonitor(OnButtonEvent));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftTrigger_RegisterAxisInputMonitor(OnLeftTriggerAxisEventCallback));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightTrigger_RegisterAxisInputMonitor(OnRightTriggerAxisEventCallback));
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_Dpad_RegisterAxisInputMonitor(OnDpadAxisEventCallback));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_RegisterAxisInputMonitor(OnLeftThumbstickAxisEventCallback));
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_RegisterAxisInputMonitor(OnRightThumbstickAxisEventCallback));
|
||||
}
|
||||
|
||||
OpenHarmonyGamePad::~OpenHarmonyGamePad() {
|
||||
CALL_OH_GAMEPAD(OH_GameDevice_UnregisterDeviceMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftShoulder_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightShoulder_UnregisterButtonInputMonitor());
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonMenu_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonHome_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonC_UnregisterButtonInputMonitor());
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonA_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonB_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonX_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_ButtonY_UnregisterButtonInputMonitor());
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_UnregisterButtonInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_UnregisterButtonInputMonitor());
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftTrigger_UnregisterAxisInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightTrigger_UnregisterAxisInputMonitor());
|
||||
|
||||
CALL_OH_GAMEPAD(OH_GamePad_Dpad_UnregisterAxisInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_UnregisterAxisInputMonitor());
|
||||
CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_UnregisterAxisInputMonitor());
|
||||
}
|
||||
} // namespace cc
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 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 "base/Macros.h"
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL OpenHarmonyGamePad {
|
||||
public:
|
||||
OpenHarmonyGamePad();
|
||||
virtual ~OpenHarmonyGamePad();
|
||||
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
@@ -42,6 +42,12 @@
|
||||
#include "platform/empty/modules/Vibrator.h"
|
||||
#include "platform/openharmony/modules/System.h"
|
||||
|
||||
#if CC_USE_GAMEPAD
|
||||
#include "platform/openharmony/OpenHarmonyGamepad.h"
|
||||
#endif
|
||||
|
||||
#include "cocos/engine/EngineEvents.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
@@ -53,29 +59,29 @@ private:
|
||||
uv_cond_t _cond{};
|
||||
uv_mutex_t _mutex{};
|
||||
bool _completed{false};
|
||||
|
||||
public:
|
||||
|
||||
enum class WAIT_RET_CODE {
|
||||
SUCCEED = 0,
|
||||
TIMEOUT,
|
||||
};
|
||||
|
||||
|
||||
SyncContext() {
|
||||
CC_LOG_INFO("Create SyncContext: %p", this);
|
||||
uv_mutex_init(&_mutex);
|
||||
uv_cond_init(&_cond);
|
||||
}
|
||||
|
||||
|
||||
~SyncContext() {
|
||||
CC_LOG_INFO("Destroy SyncContext: %p", this);
|
||||
uv_mutex_destroy(&_mutex);
|
||||
uv_cond_destroy(&_cond);
|
||||
}
|
||||
|
||||
|
||||
WAIT_RET_CODE wait_for(uint64_t nanoSeconds) {
|
||||
WAIT_RET_CODE ret = WAIT_RET_CODE::SUCCEED;
|
||||
uv_mutex_lock(&_mutex);
|
||||
|
||||
|
||||
// Use a while loop to check the completed flag to avoid spurious wakeup.
|
||||
while (!_completed) {
|
||||
int r = uv_cond_timedwait(&_cond, &_mutex, nanoSeconds);
|
||||
@@ -87,18 +93,18 @@ public:
|
||||
uv_mutex_unlock(&_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void notify() {
|
||||
uv_mutex_lock(&_mutex);
|
||||
_completed = true;
|
||||
uv_cond_signal(&_cond);
|
||||
uv_mutex_unlock(&_mutex);
|
||||
}
|
||||
|
||||
|
||||
void addRef() {
|
||||
++_refCount;
|
||||
}
|
||||
|
||||
|
||||
void release() {
|
||||
--_refCount;
|
||||
int ref = _refCount;
|
||||
@@ -106,27 +112,12 @@ public:
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void sendMsgToWorker(const cc::MessageType& type, void* data, void* window) {
|
||||
cc::OpenHarmonyPlatform* platform = dynamic_cast<cc::OpenHarmonyPlatform*>(cc::BasePlatform::getPlatform());
|
||||
CC_ASSERT(platform != nullptr);
|
||||
cc::WorkerMessageData msg{type, static_cast<void*>(data), window};
|
||||
platform->enqueue(msg);
|
||||
}
|
||||
|
||||
void sendMsgToWorkerAndWait(const cc::MessageType& type, void* data, void* window) {
|
||||
cc::OpenHarmonyPlatform* platform = dynamic_cast<cc::OpenHarmonyPlatform*>(cc::BasePlatform::getPlatform());
|
||||
CC_ASSERT(platform != nullptr);
|
||||
cc::WorkerMessageData msg{type, static_cast<void*>(data), window};
|
||||
platform->enqueueAndWait(msg);
|
||||
}
|
||||
|
||||
void onSurfaceCreatedCB(OH_NativeXComponent* component, void* window) {
|
||||
CC_LOG_INFO("onSurfaceCreatedCB, component: %p, window: %p");
|
||||
// It is possible that when the message is sent, the worker thread has not yet started.
|
||||
//sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_CREATED, component, window);
|
||||
// sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_CREATED, component, window);
|
||||
cc::ISystemWindowInfo info;
|
||||
info.title = "";
|
||||
info.x = 0;
|
||||
@@ -146,12 +137,12 @@ void onSurfaceHideCB(OH_NativeXComponent* component, void* window) {
|
||||
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
|
||||
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
|
||||
ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
|
||||
if(ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
|
||||
if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
|
||||
CC_LOG_ERROR("onSurfaceHideCB, OH_NativeXComponent_GetXComponentId failed: %d", ret);
|
||||
return;
|
||||
}
|
||||
sendMsgToWorkerAndWait(cc::MessageType::WM_XCOMPONENT_SURFACE_HIDE, component, window);
|
||||
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorkerAndWait(cc::MessageType::WM_XCOMPONENT_SURFACE_HIDE, component, window);
|
||||
|
||||
CC_LOG_INFO("onSurfaceHideCB end, component: %p, window: %p");
|
||||
}
|
||||
|
||||
@@ -161,13 +152,13 @@ void onSurfaceShowCB(OH_NativeXComponent* component, void* window) {
|
||||
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
|
||||
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
|
||||
ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
|
||||
if(ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
|
||||
if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_SHOW, component, window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_SHOW, component, window);
|
||||
}
|
||||
|
||||
int ohKeyCodeToCocosKeyCode(OH_NativeXComponent_KeyCode ohKeyCode){
|
||||
int ohKeyCodeToCocosKeyCode(OH_NativeXComponent_KeyCode ohKeyCode) {
|
||||
static const int keyZeroInCocos = 48;
|
||||
static const int keyF1InCocos = 112;
|
||||
static const int keyAInCocos = 65;
|
||||
@@ -195,24 +186,60 @@ int ohKeyCodeToCocosKeyCode(OH_NativeXComponent_KeyCode ohKeyCode){
|
||||
{KEY_SPACE, cc::KeyCode::SPACE},
|
||||
{KEY_ALT_RIGHT, cc::KeyCode::ALT_RIGHT},
|
||||
{KEY_CTRL_RIGHT, cc::KeyCode::CONTROL_RIGHT},
|
||||
|
||||
{KEY_DPAD_LEFT, cc::KeyCode::ARROW_LEFT},
|
||||
{KEY_DPAD_RIGHT, cc::KeyCode::ARROW_RIGHT},
|
||||
{KEY_DPAD_DOWN, cc::KeyCode::ARROW_DOWN},
|
||||
{KEY_DPAD_UP, cc::KeyCode::ARROW_UP},
|
||||
{KEY_DPAD_CENTER, cc::KeyCode::DPAD_CENTER},
|
||||
|
||||
{KEY_MOVE_HOME, cc::KeyCode::HOME},
|
||||
{KEY_MOVE_END, cc::KeyCode::END},
|
||||
{KEY_FORWARD_DEL, cc::KeyCode::DELETE_KEY},
|
||||
{KEY_INSERT, cc::KeyCode::INSERT},
|
||||
{KEY_PAGE_UP, cc::KeyCode::PAGE_UP},
|
||||
{KEY_PAGE_DOWN, cc::KeyCode::PAGE_DOWN},
|
||||
{KEY_SCROLL_LOCK, cc::KeyCode::SCROLLLOCK},
|
||||
{KEY_BREAK, cc::KeyCode::PAUSE},
|
||||
// numpad
|
||||
{KEY_NUM_LOCK, cc::KeyCode::NUM_LOCK},
|
||||
{KEY_NUMPAD_DIVIDE, cc::KeyCode::NUMPAD_DIVIDE},
|
||||
{KEY_NUMPAD_MULTIPLY, cc::KeyCode::NUMPAD_MULTIPLY},
|
||||
{KEY_NUMPAD_SUBTRACT, cc::KeyCode::NUMPAD_MINUS},
|
||||
{KEY_NUMPAD_ADD, cc::KeyCode::NUMPAD_PLUS},
|
||||
{KEY_NUMPAD_ENTER, cc::KeyCode::NUMPAD_ENTER},
|
||||
{KEY_NUMPAD_DOT, cc::KeyCode::NUMPAD_DECIMAL},
|
||||
{KEY_NUMPAD_COMMA, cc::KeyCode::COMMA},
|
||||
{KEY_NUMPAD_EQUALS, cc::KeyCode::EQUAL},
|
||||
|
||||
{KEY_NUMPAD_0, cc::KeyCode::NUMPAD_0},
|
||||
{KEY_NUMPAD_1, cc::KeyCode::NUMPAD_1},
|
||||
{KEY_NUMPAD_2, cc::KeyCode::NUMPAD_2},
|
||||
{KEY_NUMPAD_3, cc::KeyCode::NUMPAD_3},
|
||||
{KEY_NUMPAD_4, cc::KeyCode::NUMPAD_4},
|
||||
{KEY_NUMPAD_5, cc::KeyCode::NUMPAD_5},
|
||||
{KEY_NUMPAD_6, cc::KeyCode::NUMPAD_6},
|
||||
{KEY_NUMPAD_7, cc::KeyCode::NUMPAD_7},
|
||||
{KEY_NUMPAD_8, cc::KeyCode::NUMPAD_8},
|
||||
{KEY_NUMPAD_9, cc::KeyCode::NUMPAD_9},
|
||||
|
||||
{KEY_MENU, cc::KeyCode::CONTEXT_MENU},
|
||||
{KEY_SYSRQ, cc::KeyCode::PRINT_SCREEN},
|
||||
{KEY_META_LEFT, cc::KeyCode::META_LEFT},
|
||||
{KEY_META_RIGHT, cc::KeyCode::META_RIGHT},
|
||||
};
|
||||
if(keyCodeMap.find(ohKeyCode) != keyCodeMap.end()){
|
||||
if (keyCodeMap.find(ohKeyCode) != keyCodeMap.end()) {
|
||||
return int(keyCodeMap[ohKeyCode]);
|
||||
}
|
||||
if(ohKeyCode >= KEY_0 && ohKeyCode <= KEY_9){
|
||||
if (ohKeyCode >= KEY_0 && ohKeyCode <= KEY_9) {
|
||||
return keyZeroInCocos + ohKeyCode - KEY_0;
|
||||
}
|
||||
if(ohKeyCode >= KEY_A && ohKeyCode <= KEY_Z){
|
||||
if (ohKeyCode >= KEY_A && ohKeyCode <= KEY_Z) {
|
||||
return keyAInCocos + ohKeyCode - KEY_A;
|
||||
}
|
||||
if(ohKeyCode >= KEY_F1 && ohKeyCode <= KEY_F12){
|
||||
}
|
||||
if (ohKeyCode >= KEY_F1 && ohKeyCode <= KEY_F12) {
|
||||
return keyF1InCocos + ohKeyCode - KEY_F1;
|
||||
}
|
||||
}
|
||||
return ohKeyCode;
|
||||
}
|
||||
|
||||
@@ -234,13 +261,12 @@ void dispatchKeyEventCB(OH_NativeXComponent* component, void* window) {
|
||||
ev->action = 0 == action ? cc::KeyboardEvent::Action::PRESS : cc::KeyboardEvent::Action::RELEASE;
|
||||
|
||||
ev->key = ohKeyCodeToCocosKeyCode(code);
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_KEY_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_KEY_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
} else {
|
||||
CC_LOG_ERROR("OpenHarmonyPlatform::getKeyEventError");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dispatchMouseEventCB(OH_NativeXComponent* component, void* window) {
|
||||
OH_NativeXComponent_MouseEvent mouseEvent;
|
||||
int32_t ret = OH_NativeXComponent_GetMouseEvent(component, window, &mouseEvent);
|
||||
@@ -260,7 +286,7 @@ void dispatchMouseEventCB(OH_NativeXComponent* component, void* window) {
|
||||
break;
|
||||
case OH_NativeXComponent_MouseEventAction::OH_NATIVEXCOMPONENT_MOUSE_MOVE:
|
||||
ev->type = cc::MouseEvent::Type::MOVE;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
ev->type = cc::MouseEvent::Type::UNKNOWN;
|
||||
break;
|
||||
@@ -285,13 +311,13 @@ void dispatchMouseEventCB(OH_NativeXComponent* component, void* window) {
|
||||
ev->button = -1;
|
||||
break;
|
||||
}
|
||||
if(mouseEvent.action == 1 && mouseEvent.button == 1) {
|
||||
if (mouseEvent.action == 1 && mouseEvent.button == 1) {
|
||||
cc::OpenHarmonyPlatform::getInstance()->isMouseLeftActive = true;
|
||||
}
|
||||
if(mouseEvent.action == 2 && mouseEvent.button == 1) {
|
||||
if (mouseEvent.action == 2 && mouseEvent.button == 1) {
|
||||
cc::OpenHarmonyPlatform::getInstance()->isMouseLeftActive = false;
|
||||
}
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_MOUSE_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_MOUSE_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
} else {
|
||||
CC_LOG_ERROR("OpenHarmonyPlatform::getMouseEventError");
|
||||
}
|
||||
@@ -343,15 +369,15 @@ void dispatchTouchEventCB(OH_NativeXComponent* component, void* window) {
|
||||
ev->touches.emplace_back(touchEvent.touchPoints[i].x, touchEvent.touchPoints[i].y, id);
|
||||
}
|
||||
}
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_TOUCH_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_TOUCH_EVENT, reinterpret_cast<void*>(ev), window);
|
||||
}
|
||||
|
||||
void onSurfaceChangedCB(OH_NativeXComponent* component, void* window) {
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_CHANGED, reinterpret_cast<void*>(component), window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_CHANGED, reinterpret_cast<void*>(component), window);
|
||||
}
|
||||
|
||||
void onSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) {
|
||||
sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_DESTROY, reinterpret_cast<void*>(component), window);
|
||||
cc::OpenHarmonyPlatform::sendMsgToWorker(cc::MessageType::WM_XCOMPONENT_SURFACE_DESTROY, reinterpret_cast<void*>(component), window);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -371,6 +397,13 @@ OpenHarmonyPlatform::OpenHarmonyPlatform() {
|
||||
_callback.OnSurfaceChanged = onSurfaceChangedCB;
|
||||
_callback.OnSurfaceDestroyed = onSurfaceDestroyedCB;
|
||||
_callback.DispatchTouchEvent = dispatchTouchEventCB;
|
||||
#if CC_USE_GAMEPAD
|
||||
_gamePad = std::make_unique<OpenHarmonyGamePad>();
|
||||
#endif
|
||||
}
|
||||
|
||||
OpenHarmonyPlatform::~OpenHarmonyPlatform() {
|
||||
|
||||
}
|
||||
|
||||
int32_t OpenHarmonyPlatform::init() {
|
||||
@@ -400,7 +433,7 @@ void OpenHarmonyPlatform::setNativeXComponent(OH_NativeXComponent* component) {
|
||||
OH_NativeXComponent_RegisterCallback(_component, &_callback);
|
||||
OH_NativeXComponent_RegisterSurfaceHideCallback(_component, onSurfaceHideCB);
|
||||
OH_NativeXComponent_RegisterSurfaceShowCallback(_component, onSurfaceShowCB);
|
||||
// register KeyEvent
|
||||
// register KeyEvent
|
||||
OH_NativeXComponent_RegisterKeyEventCallback(_component, dispatchKeyEventCB);
|
||||
// register mouseEvent
|
||||
_mouseCallback.DispatchMouseEvent = dispatchMouseEventCB;
|
||||
@@ -415,10 +448,10 @@ void OpenHarmonyPlatform::enqueue(const WorkerMessageData& msg) {
|
||||
|
||||
void OpenHarmonyPlatform::enqueueAndWait(WorkerMessageData& msg) {
|
||||
SyncContext* syncContext = new SyncContext(); // ref -> 1
|
||||
syncContext->addRef(); // ref -> 2
|
||||
syncContext->addRef(); // ref -> 2
|
||||
msg.syncContext = syncContext;
|
||||
_messageQueue.enqueue(msg);
|
||||
auto *oldWorkerLoop = _workerLoop;
|
||||
auto* oldWorkerLoop = _workerLoop;
|
||||
triggerMessageSignal();
|
||||
|
||||
auto oldTime = std::chrono::steady_clock::now();
|
||||
@@ -464,7 +497,7 @@ void OpenHarmonyPlatform::onMessageCallback(const uv_async_t* /* req */) {
|
||||
WorkerMessageData msgData;
|
||||
OpenHarmonyPlatform* platform = OpenHarmonyPlatform::getInstance();
|
||||
while (true) {
|
||||
//loop until all msg dispatch
|
||||
// loop until all msg dispatch
|
||||
if (!platform->dequeue(reinterpret_cast<WorkerMessageData*>(&msgData))) {
|
||||
// Queue has no data
|
||||
break;
|
||||
@@ -483,7 +516,7 @@ void OpenHarmonyPlatform::onMessageCallback(const uv_async_t* /* req */) {
|
||||
events::Keyboard::broadcast(*ev);
|
||||
delete ev;
|
||||
ev = nullptr;
|
||||
} else if (msgData.type == MessageType::WM_XCOMPONENT_MOUSE_EVENT || msgData.type == MessageType::WM_XCOMPONENT_MOUSE_WHEEL_EVENT ) {
|
||||
} else if (msgData.type == MessageType::WM_XCOMPONENT_MOUSE_EVENT || msgData.type == MessageType::WM_XCOMPONENT_MOUSE_WHEEL_EVENT) {
|
||||
MouseEvent* ev = reinterpret_cast<MouseEvent*>(msgData.data);
|
||||
CC_ASSERT(ev != nullptr);
|
||||
events::Mouse::broadcast(*ev);
|
||||
@@ -501,14 +534,14 @@ void OpenHarmonyPlatform::onMessageCallback(const uv_async_t* /* req */) {
|
||||
platform->onSurfaceChanged(nativexcomponet, msgData.window);
|
||||
} else if (msgData.type == MessageType::WM_XCOMPONENT_SURFACE_SHOW) {
|
||||
OH_NativeXComponent* nativexcomponet = reinterpret_cast<OH_NativeXComponent*>(msgData.data);
|
||||
CC_ASSERT(nativexcomponet != nullptr);
|
||||
CC_ASSERT(nativexcomponet != nullptr);
|
||||
platform->onSurfaceShow(msgData.window);
|
||||
} else if (msgData.type == MessageType::WM_XCOMPONENT_SURFACE_HIDE) {
|
||||
OH_NativeXComponent* nativexcomponet = reinterpret_cast<OH_NativeXComponent*>(msgData.data);
|
||||
CC_ASSERT(nativexcomponet != nullptr);
|
||||
CC_ASSERT(nativexcomponet != nullptr);
|
||||
platform->onSurfaceHide();
|
||||
|
||||
auto *ctx = reinterpret_cast<SyncContext*>(msgData.syncContext);
|
||||
|
||||
auto* ctx = reinterpret_cast<SyncContext*>(msgData.syncContext);
|
||||
if (ctx) {
|
||||
ctx->notify();
|
||||
ctx->release();
|
||||
@@ -522,6 +555,20 @@ void OpenHarmonyPlatform::onMessageCallback(const uv_async_t* /* req */) {
|
||||
CC_ASSERT(false);
|
||||
}
|
||||
continue;
|
||||
} else if (msgData.type == MessageType::WM_GAMEPAD_CONTROLLER_INPUT) {
|
||||
CC_LOG_INFO("onMessageCallback GamePad ...");
|
||||
ControllerEvent* ev = reinterpret_cast<ControllerEvent*>(msgData.data);
|
||||
CC_ASSERT(ev != nullptr);
|
||||
events::Controller::broadcast(*ev);
|
||||
delete ev;
|
||||
ev = nullptr;
|
||||
} else if (msgData.type == MessageType::WM_GAMEPAD_CONTROLLER_CHANGE) {
|
||||
CC_LOG_INFO("onMessageCallback GamePad ...");
|
||||
ControllerChangeEvent* ev = reinterpret_cast<ControllerChangeEvent*>(msgData.data);
|
||||
CC_ASSERT(ev != nullptr);
|
||||
events::ControllerChange::broadcast(*ev);
|
||||
delete ev;
|
||||
ev = nullptr;
|
||||
}
|
||||
|
||||
if (msgData.type == MessageType::WM_APP_SHOW) {
|
||||
@@ -567,7 +614,7 @@ void OpenHarmonyPlatform::onHideNative() {
|
||||
void OpenHarmonyPlatform::onDestroyNative() {
|
||||
CC_LOG_INFO("OpenHarmonyPlatform::onDestroyNative");
|
||||
onDestroy();
|
||||
if (_timerInited) {
|
||||
if (_timerInited) {
|
||||
uv_timer_stop(&_timerHandle);
|
||||
}
|
||||
}
|
||||
@@ -586,13 +633,13 @@ void OpenHarmonyPlatform::workerInit(uv_loop_t* loop) {
|
||||
if (_workerLoop) {
|
||||
uv_timer_init(_workerLoop, &_timerHandle);
|
||||
_timerInited = true;
|
||||
|
||||
|
||||
uv_async_init(_workerLoop, &_messageSignal, reinterpret_cast<uv_async_cb>(OpenHarmonyPlatform::onMessageCallback));
|
||||
|
||||
|
||||
if (!_messageQueue.empty()) {
|
||||
triggerMessageSignal(); // trigger the signal to handle the pending message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::requestVSync() {
|
||||
@@ -616,6 +663,13 @@ void OpenHarmonyPlatform::onSurfaceChanged(OH_NativeXComponent* component, void*
|
||||
ev.width = width;
|
||||
ev.height = height;
|
||||
events::WindowEvent::broadcast(ev);
|
||||
// Hack:On the PC platform, a resize message is sent, but this message occurs before initialization is complete, resulting in unprocessed messages.
|
||||
// Therefore, an additional handling of the resize message is required here.
|
||||
cc::SystemWindowManager* windowMgr = this->getInterface<cc::SystemWindowManager>();
|
||||
CC_ASSERT_NOT_NULL(windowMgr);
|
||||
auto systemWindow = windowMgr->getWindow(cc::ISystemWindow::mainWindowId);
|
||||
CC_ASSERT_NOT_NULL(systemWindow);
|
||||
systemWindow->setViewSize(width, height);
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::onSurfaceDestroyed(OH_NativeXComponent* component, void* window) {
|
||||
@@ -635,10 +689,10 @@ void OpenHarmonyPlatform::onSurfaceShow(void* window) {
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::dispatchMouseWheelCB(std::string eventType, float offsetY) {
|
||||
if(isMouseLeftActive) {
|
||||
if (isMouseLeftActive) {
|
||||
return;
|
||||
}
|
||||
if(eventType == "actionUpdate") {
|
||||
if (eventType == "actionUpdate") {
|
||||
float moveScrollY = offsetY - scrollDistance;
|
||||
scrollDistance = offsetY;
|
||||
cc::MouseEvent* ev = new cc::MouseEvent;
|
||||
@@ -663,4 +717,18 @@ ISystemWindow* OpenHarmonyPlatform::createNativeWindow(uint32_t windowId, void*
|
||||
return window;
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::sendMsgToWorker(const cc::MessageType& type, void* data, void* window) {
|
||||
cc::OpenHarmonyPlatform* platform = dynamic_cast<cc::OpenHarmonyPlatform*>(cc::BasePlatform::getPlatform());
|
||||
CC_ASSERT(platform != nullptr);
|
||||
cc::WorkerMessageData msg{type, static_cast<void*>(data), window};
|
||||
platform->enqueue(msg);
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::sendMsgToWorkerAndWait(const cc::MessageType& type, void* data, void* window) {
|
||||
cc::OpenHarmonyPlatform* platform = dynamic_cast<cc::OpenHarmonyPlatform*>(cc::BasePlatform::getPlatform());
|
||||
CC_ASSERT(platform != nullptr);
|
||||
cc::WorkerMessageData msg{type, static_cast<void*>(data), window};
|
||||
platform->enqueueAndWait(msg);
|
||||
}
|
||||
|
||||
}; // namespace cc
|
||||
|
||||
@@ -29,17 +29,22 @@
|
||||
|
||||
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||
|
||||
#include <napi/native_api.h>
|
||||
#include <uv.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <napi/native_api.h>
|
||||
|
||||
#include "platform/openharmony/WorkerMessageQueue.h"
|
||||
|
||||
namespace cc {
|
||||
#if CC_USE_GAMEPAD
|
||||
class OpenHarmonyGamePad;
|
||||
#endif
|
||||
|
||||
class OpenHarmonyPlatform : public UniversalPlatform {
|
||||
public:
|
||||
OpenHarmonyPlatform();
|
||||
~OpenHarmonyPlatform() override;
|
||||
int32_t init() override;
|
||||
static OpenHarmonyPlatform* getInstance();
|
||||
|
||||
@@ -65,7 +70,10 @@ public:
|
||||
bool dequeue(WorkerMessageData* data);
|
||||
|
||||
void triggerMessageSignal();
|
||||
ISystemWindow *createNativeWindow(uint32_t windowId, void *externalHandle) override;
|
||||
ISystemWindow* createNativeWindow(uint32_t windowId, void* externalHandle) override;
|
||||
static void sendMsgToWorker(const cc::MessageType& type, void* data, void* window);
|
||||
static void sendMsgToWorkerAndWait(const cc::MessageType& type, void* data, void* window);
|
||||
|
||||
public:
|
||||
// Callback, called by ACE XComponent
|
||||
void onSurfaceCreated(OH_NativeXComponent* component, void* window);
|
||||
@@ -86,7 +94,10 @@ public:
|
||||
uv_async_t _messageSignal{};
|
||||
bool _timerInited{false};
|
||||
WorkerMessageQueue _messageQueue;
|
||||
//game started
|
||||
#if CC_USE_GAMEPAD
|
||||
std::unique_ptr<OpenHarmonyGamePad> _gamePad;
|
||||
#endif
|
||||
// game started
|
||||
bool g_started{false};
|
||||
bool isMouseLeftActive{false};
|
||||
float scrollDistance{0};
|
||||
|
||||
@@ -47,6 +47,8 @@ enum class MessageType {
|
||||
WM_APP_HIDE,
|
||||
WM_APP_DESTROY,
|
||||
WM_VSYNC,
|
||||
WM_GAMEPAD_CONTROLLER_INPUT,
|
||||
WM_GAMEPAD_CONTROLLER_CHANGE,
|
||||
};
|
||||
|
||||
struct WorkerMessageData {
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
"type": "github",
|
||||
"owner": "cocos",
|
||||
"name": "cocos-engine-external",
|
||||
"checkout": "v3.8.8-1"
|
||||
"checkout": "v3.8.8-2"
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { OPEN_HARMONY } from 'internal:constants';
|
||||
import { OPEN_HARMONY, IOS } from 'internal:constants';
|
||||
import { EventTarget } from '../../../cocos/core/event';
|
||||
import { checkPalIntegrity, withImpl } from '../../integrity-check';
|
||||
import { BrowserType, NetworkType, OS, Platform, Language, Feature } from '../enum-type';
|
||||
@@ -134,7 +134,8 @@ class SystemInfo extends EventTarget {
|
||||
[Feature.EVENT_HANDLE]: this.isXR,
|
||||
[Feature.EVENT_HMD]: this.isXR,
|
||||
[Feature.EVENT_HANDHELD]: (typeof xr !== 'undefined' && typeof xr.ARModule !== 'undefined'),
|
||||
[Feature.WASM]: !OPEN_HARMONY,
|
||||
// Although the iOS OS supports WASM, the engine does not yet support loading WASM on this platform.
|
||||
[Feature.WASM]: !OPEN_HARMONY && !IOS,
|
||||
};
|
||||
|
||||
this._registerEvent();
|
||||
|
||||
@@ -37,6 +37,7 @@ class HTMLImageElement extends HTMLElement {
|
||||
this.width = this.naturalWidth = info.width;
|
||||
this.height = this.naturalHeight = info.height;
|
||||
this._data = info.data;
|
||||
this.format = info.format;
|
||||
this.complete = true;
|
||||
this._mipmapLevelDataSize = info.mipmapLevelDataSize;
|
||||
|
||||
|
||||
@@ -698,11 +698,6 @@ const cacheManager = require('./jsb-cache-manager');
|
||||
this.skeletonData.init();
|
||||
this.setSkeletonData(this.skeletonData);
|
||||
|
||||
this._indexBoneSockets();
|
||||
this._updateSocketBindings();
|
||||
this.attachUtil.init(this);
|
||||
this._preCacheMode = this._cacheMode;
|
||||
|
||||
if (this.defaultSkin && this.defaultSkin !== '') {
|
||||
this.setSkin(this.defaultSkin);
|
||||
} else if (this._skinName && this._skinName !== '') {
|
||||
@@ -720,6 +715,11 @@ const cacheManager = require('./jsb-cache-manager');
|
||||
this._nativeSkeleton._comp = null;
|
||||
this._nativeSkeleton = null;
|
||||
}
|
||||
|
||||
this._indexBoneSockets();
|
||||
this._updateSocketBindings();
|
||||
this.attachUtil.init(this);
|
||||
this._preCacheMode = this._cacheMode;
|
||||
};
|
||||
|
||||
const _onDestroy = skeleton.onDestroy;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.18",
|
||||
"@ohos/hamock": "1.0.0"
|
||||
modelVersion: '5.0.0',
|
||||
devDependencies: {
|
||||
'@ohos/hypium': '1.0.21',
|
||||
'@ohos/hamock': '1.0.0',
|
||||
},
|
||||
"author": "",
|
||||
"name": "test-cases",
|
||||
"description": "example description",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
author: '',
|
||||
name: 'test-cases',
|
||||
description: 'example description',
|
||||
main: '',
|
||||
version: '1.0.0',
|
||||
dependencies: {}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ export * from './exports/profiler';
|
||||
export * from './exports/rich-text';
|
||||
export * from './exports/skeletal-animation';
|
||||
export * from './exports/sorting';
|
||||
export * from './exports/sorting-2d';
|
||||
export * from './exports/spine';
|
||||
export * from './exports/terrain';
|
||||
export * from './exports/tiled-map';
|
||||
|
||||
Reference in New Issue
Block a user