mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 15:42:39 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0a696cfe6 | |||
| 1b3ad36e4b | |||
| ff0f46ff81 | |||
| 0616a948ef | |||
| ee89a99a9b | |||
| f620989ce7 | |||
| 661de759ef | |||
| 0ab8246486 | |||
| 67642997f7 | |||
| 3be9ebc5b7 |
@@ -106,6 +106,13 @@ export class BakedSkinningModel extends MorphModel {
|
||||
UBOSkinningTexture.SIZE,
|
||||
));
|
||||
}
|
||||
|
||||
// The animation buffer belongs to the skinning root. Refresh its binding without
|
||||
// rebuilding the instanced attribute block, which would erase custom attribute values.
|
||||
for (let i = 0; i < this._subModels.length; i++) {
|
||||
this._updateLocalDescriptors(i, this._subModels[i].descriptorSet);
|
||||
}
|
||||
this.updateInstancedJointTextureInfo();
|
||||
}
|
||||
|
||||
// Override
|
||||
|
||||
@@ -142,6 +142,7 @@ export class SkinningModel extends MorphModel {
|
||||
}
|
||||
this._bufferIndices = null; this._joints.length = 0;
|
||||
if (!skeleton || !skinningRoot || !mesh) { return; }
|
||||
const prevRealTimeTextureMode = this._realTimeTextureMode;
|
||||
this._realTimeTextureMode = false;
|
||||
if (UBOSkinning.JOINT_UNIFORM_CAPACITY < skeleton.joints.length) { this._realTimeTextureMode = true; }
|
||||
this.transform = skinningRoot;
|
||||
@@ -161,6 +162,15 @@ export class SkinningModel extends MorphModel {
|
||||
if (!jointMaps) { indices.push(index); buffers.push(0); } else { getRelevantBuffers(indices, buffers, jointMaps, index); }
|
||||
this._joints.push({ indices, buffers, bound, target, bindpose, transform });
|
||||
}
|
||||
|
||||
// Rebind recreated joint resources without resetting user-provided instanced attributes.
|
||||
const subModelCount = Math.min(this._subModels.length, this._bufferIndices.length);
|
||||
if (subModelCount && prevRealTimeTextureMode !== this._realTimeTextureMode) {
|
||||
this.onMacroPatchesStateChanged();
|
||||
}
|
||||
for (let i = 0; i < subModelCount; i++) {
|
||||
this._updateLocalDescriptors(i, this._subModels[i].descriptorSet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -177,21 +177,21 @@ export class SkinnedMeshBatchRenderer extends SkinnedMeshRenderer {
|
||||
@override
|
||||
@visible(false)
|
||||
get mesh (): Mesh | null {
|
||||
return super.mesh;
|
||||
return Reflect.get(SkinnedMeshRenderer.prototype, 'mesh', this);
|
||||
}
|
||||
|
||||
set mesh (val) {
|
||||
super.mesh = val;
|
||||
Reflect.set(SkinnedMeshRenderer.prototype, 'mesh', val, this);
|
||||
}
|
||||
|
||||
@override
|
||||
@visible(false)
|
||||
get skeleton (): Skeleton | null {
|
||||
return super.skeleton;
|
||||
return Reflect.get(SkinnedMeshRenderer.prototype, 'skeleton', this);
|
||||
}
|
||||
|
||||
set skeleton (val) {
|
||||
super.skeleton = val;
|
||||
Reflect.set(SkinnedMeshRenderer.prototype, 'skeleton', val, this);
|
||||
}
|
||||
|
||||
public onLoad (): void {
|
||||
|
||||
@@ -42,7 +42,7 @@ import VelocityOvertimeModule from './animator/velocity-overtime';
|
||||
import Burst from './burst';
|
||||
import ShapeModule from './emitter/shape-module';
|
||||
import { ParticleCullingMode, ParticleSpace } from './enum';
|
||||
import { particleEmitZAxis } from './particle-general-function';
|
||||
import { isCurveTwoValues, particleEmitZAxis } from './particle-general-function';
|
||||
import ParticleSystemRenderer from './renderer/particle-system-renderer-data';
|
||||
import TrailModule from './renderer/trail';
|
||||
import { ParticleSystemRendererBase } from './renderer/particle-system-renderer-base';
|
||||
@@ -141,7 +141,7 @@ export class ParticleSystem extends ModelRenderer {
|
||||
@range([0, Number.POSITIVE_INFINITY])
|
||||
@displayOrder(10)
|
||||
@tooltip('i18n:particle_system.startSizeY')
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startSize3D; })
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startSize3D; }) // eslint-disable-line func-names, comma-dangle
|
||||
public startSizeY = new CurveRange();
|
||||
|
||||
/**
|
||||
@@ -153,7 +153,7 @@ export class ParticleSystem extends ModelRenderer {
|
||||
@range([0, Number.POSITIVE_INFINITY])
|
||||
@displayOrder(10)
|
||||
@tooltip('i18n:particle_system.startSizeZ')
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startSize3D; })
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startSize3D; }) // eslint-disable-line func-names, comma-dangle
|
||||
public startSizeZ = new CurveRange();
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ export class ParticleSystem extends ModelRenderer {
|
||||
@radian
|
||||
@displayOrder(12)
|
||||
@tooltip('i18n:particle_system.startRotationX')
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startRotation3D; })
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startRotation3D; }) // eslint-disable-line func-names, comma-dangle
|
||||
public startRotationX = new CurveRange();
|
||||
|
||||
/**
|
||||
@@ -196,7 +196,7 @@ export class ParticleSystem extends ModelRenderer {
|
||||
@radian
|
||||
@displayOrder(12)
|
||||
@tooltip('i18n:particle_system.startRotationY')
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startRotation3D; })
|
||||
@visible(function (this: ParticleSystem): boolean { return this.startRotation3D; }) // eslint-disable-line func-names, comma-dangle
|
||||
public startRotationY = new CurveRange();
|
||||
|
||||
/**
|
||||
@@ -1455,16 +1455,18 @@ export class ParticleSystem extends ModelRenderer {
|
||||
|
||||
if (!self._isEmitting) return;
|
||||
|
||||
const randTime = isCurveTwoValues(self.rateOverTime) ? pseudoRandom(randomRangeInt(0, bits.INT_MAX)) : 1;
|
||||
// emit by rateOverTime
|
||||
self._emitRateTimeCounter += self.rateOverTime.evaluate(self._time / self.duration, 1)! * dt;
|
||||
self._emitRateTimeCounter += self.rateOverTime.evaluate(self._time / self.duration, randTime)! * dt;
|
||||
if (self._emitRateTimeCounter > 1) {
|
||||
const emitNum = Math.floor(self._emitRateTimeCounter);
|
||||
self._emitRateTimeCounter -= emitNum;
|
||||
self.emit(emitNum, dt);
|
||||
}
|
||||
|
||||
const randDist = isCurveTwoValues(self.rateOverDistance) ? pseudoRandom(randomRangeInt(0, bits.INT_MAX)) : 1;
|
||||
// emit by rateOverDistance
|
||||
const rateOverDistance = self.rateOverDistance.evaluate(self._time / self.duration, 1)!;
|
||||
const rateOverDistance = self.rateOverDistance.evaluate(self._time / self.duration, randDist)!;
|
||||
if (rateOverDistance > 0) {
|
||||
Vec3.copy(self._oldWPos, self._curWPos);
|
||||
self.node.getWorldPosition(self._curWPos);
|
||||
|
||||
+54
-7
@@ -93,8 +93,8 @@ enum State {
|
||||
export enum ButtonEventType {
|
||||
/**
|
||||
* @event click
|
||||
* @param {Event.EventCustom} event
|
||||
* @param {Button} button - The Button component.
|
||||
* @param {EventTouch} event - The original touch event, undefined if the click is triggered by XR.
|
||||
*/
|
||||
CLICK = 'click',
|
||||
}
|
||||
@@ -156,16 +156,16 @@ export enum ButtonEventType {
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { log, Node } from 'cc';
|
||||
* import { log } from 'cc';
|
||||
* // Add an event to the button.
|
||||
* button.node.on(Node.EventType.TOUCH_START, (event) => {
|
||||
* log("This is a callback after the trigger event");
|
||||
* });
|
||||
* // You could also add a click event
|
||||
* // Note: In this way, you can't get the touch event info, so use it wisely.
|
||||
* button.node.on(Node.EventType.CLICK, (button) => {
|
||||
* //The event is a custom event, you could get the Button component via first argument
|
||||
* })
|
||||
* // The callback receives the Button component and the original touch event (if available).
|
||||
* button.on(Button.EventType.CLICK, (button, event) => {
|
||||
* log('button clicked');
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@ccclass('cc.Button')
|
||||
@@ -586,6 +586,53 @@ export class Button extends Component {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Register a Button event listener on the component. Button events are dispatched by the owner
|
||||
* node, and this method is a shorthand which forwards the registration to the node, so
|
||||
* `button.on(...)` and `button.node.on(...)` share the same listener registry.
|
||||
* @zh
|
||||
* 在组件上注册 Button 事件监听。Button 的事件由所属节点派发,此方法是 `this.node.on(type, ...)`
|
||||
* 的便捷封装,`button.on(...)` 与 `button.node.on(...)` 共用同一份监听器。
|
||||
* @param type @en Event type, e.g. [[ButtonEventType.CLICK]]. @zh 事件类型,如 [[ButtonEventType.CLICK]]。
|
||||
* @param callback @en The callback, receives the Button component and the original event. @zh 回调函数,参数为 Button 组件与原始事件。
|
||||
* @param target @en The target to be bound with. @zh 绑定的目标对象。
|
||||
* @example
|
||||
* ```ts
|
||||
* button.on(Button.EventType.CLICK, (button, event) => {
|
||||
* // clicked
|
||||
* }, this);
|
||||
* ```
|
||||
*/
|
||||
public on (type: ButtonEventType, callback: (button: Button, event?: EventTouch) => void, target?: unknown): void {
|
||||
this.node.on(type, callback, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Remove a Button event listener registered via [[on]] or `button.node.on`. To remove a listener,
|
||||
* the `type`, `callback` and `target` must match the registration.
|
||||
* @zh
|
||||
* 移除通过 [[on]] 或 `button.node.on` 注册的 Button 事件监听。`type`、`callback`、`target`
|
||||
* 需与注册时一致才能正确移除。
|
||||
*/
|
||||
public off (type: ButtonEventType, callback?: (button: Button, event?: EventTouch) => void, target?: unknown): void {
|
||||
this.node.off(type, callback, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Remove all Button event listeners registered with the given target.
|
||||
* Note: this forwards to `node.targetOff`, so listeners registered by other components
|
||||
* or by the engine internals on the same node with the same target are removed as well.
|
||||
* @zh
|
||||
* 移除指定 target 上注册的所有 Button 事件监听。注意:此方法会转发到 `node.targetOff`,
|
||||
* 同一节点上其他组件或引擎内部以相同 target 注册的监听也会被一并移除。
|
||||
*/
|
||||
public targetOff (target: unknown): void {
|
||||
this.node.targetOff(target);
|
||||
}
|
||||
|
||||
public __preload (): void {
|
||||
if (!this.target) {
|
||||
this.target = this.node;
|
||||
@@ -892,7 +939,7 @@ export class Button extends Component {
|
||||
|
||||
if (this._pressed) {
|
||||
ComponentEventHandler.emitEvents(this.clickEvents, event);
|
||||
this.node.emit(ButtonEventType.CLICK, this);
|
||||
this.node.emit(ButtonEventType.CLICK, this, event);
|
||||
}
|
||||
this._pressed = false;
|
||||
this._updateState();
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ void main() {
|
||||
color = packRGBE(color.rgb); // for reflection-map
|
||||
#else
|
||||
color = CCSurfacesDebugDisplayInvalidNumber(color);
|
||||
#if !CC_USE_FLOAT_OUTPUT || CC_IS_TRANSPARENCY_PASS
|
||||
#if !CC_USE_FLOAT_OUTPUT
|
||||
color.rgb = HDRToLDR(color.rgb);
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
#endif
|
||||
|
||||
@@ -86,6 +86,12 @@ void BakedSkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Me
|
||||
pipeline::UBOSkinning::size,
|
||||
});
|
||||
}
|
||||
|
||||
// JSB synchronizes the new root's animation buffer before calling bindSkeleton.
|
||||
for (index_t i = 0; i < _subModels.size(); ++i) {
|
||||
updateLocalDescriptors(i, _subModels[i]->getDescriptorSet());
|
||||
}
|
||||
updateInstancedJointTextureInfo();
|
||||
}
|
||||
|
||||
void BakedSkinningModel::updateTransform(uint32_t stamp) {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
****************************************************************************/
|
||||
#include "3d/models/SkinningModel.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "3d/assets/Mesh.h"
|
||||
@@ -80,6 +82,7 @@ void SkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Mesh *m
|
||||
_joints.clear();
|
||||
|
||||
if (!skeleton || !skinningRoot || !mesh) return;
|
||||
const bool prevRealTimeTextureMode = _realTimeTextureMode;
|
||||
auto jointCount = static_cast<uint32_t>(skeleton->getJoints().size());
|
||||
_realTimeTextureMode = pipeline::SkinningJointCapacity::jointUniformCapacity < jointCount;
|
||||
setTransform(skinningRoot);
|
||||
@@ -113,6 +116,15 @@ void SkinningModel::bindSkeleton(Skeleton *skeleton, Node *skinningRoot, Mesh *m
|
||||
jointInfo.indices = std::move(indices);
|
||||
_joints.emplace_back(std::move(jointInfo));
|
||||
}
|
||||
|
||||
// Rebind recreated resources without resetting custom instanced attributes.
|
||||
const auto subModelCount = std::min(_subModels.size(), _bufferIndices.size());
|
||||
if (subModelCount && prevRealTimeTextureMode != _realTimeTextureMode) {
|
||||
onMacroPatchesStateChanged();
|
||||
}
|
||||
for (index_t i = 0; i < subModelCount; ++i) {
|
||||
updateLocalDescriptors(i, _subModels[i]->getDescriptorSet());
|
||||
}
|
||||
}
|
||||
|
||||
void SkinningModel::updateTransform(uint32_t stamp) {
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include "application/ApplicationManager.h"
|
||||
#include "audio/include/AudioEngine.h"
|
||||
@@ -265,10 +266,11 @@ int AudioEngineImpl::play2d(const ccstd::string &filePath, bool loop, float volu
|
||||
|
||||
auto iter = _callbackMap.find(id);
|
||||
if (iter != _callbackMap.end()) {
|
||||
if (state == IAudioPlayer::State::OVER) {
|
||||
iter->second(id, filePath);
|
||||
}
|
||||
auto callback = std::move(iter->second);
|
||||
_callbackMap.erase(iter);
|
||||
if (state == IAudioPlayer::State::OVER) {
|
||||
callback(id, filePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
|
||||
#import <OpenAL/al.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "base/std/container/string.h"
|
||||
|
||||
@@ -40,6 +42,7 @@
|
||||
namespace cc {
|
||||
class AudioEngineImpl;
|
||||
class AudioPlayer;
|
||||
class Scheduler;
|
||||
|
||||
class AudioCache {
|
||||
public:
|
||||
@@ -96,13 +99,15 @@ protected:
|
||||
|
||||
std::mutex _readDataTaskMutex;
|
||||
|
||||
State _state{State::INITIAL};
|
||||
std::atomic<State> _state{State::INITIAL};
|
||||
|
||||
std::shared_ptr<bool> _isDestroyed;
|
||||
// Assigned before the read task is submitted; workers must not look up the current application.
|
||||
std::weak_ptr<Scheduler> _scheduler;
|
||||
std::shared_ptr<std::atomic_bool> _isDestroyed;
|
||||
ccstd::string _fileFullPath;
|
||||
unsigned int _id;
|
||||
bool _isLoadingFinished{false};
|
||||
bool _isSkipReadDataTask{false};
|
||||
std::atomic_bool _isLoadingFinished{false};
|
||||
std::atomic_bool _isSkipReadDataTask{false};
|
||||
|
||||
friend class AudioEngineImpl;
|
||||
friend class AudioPlayer;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <OpenAL/alc.h>
|
||||
#include <thread>
|
||||
#include "application/ApplicationManager.h"
|
||||
#include "base/Scheduler.h"
|
||||
#include "base/memory/Memory.h"
|
||||
|
||||
@@ -85,7 +84,7 @@ unsigned int __idIndex = 0;
|
||||
using namespace cc;
|
||||
|
||||
AudioCache::AudioCache()
|
||||
: _isDestroyed(std::make_shared<bool>(false)), _id(++__idIndex){
|
||||
: _isDestroyed(std::make_shared<std::atomic_bool>(false)), _id(++__idIndex){
|
||||
ALOGVV("AudioCache() %p, id=%u", this, _id);
|
||||
for (int i = 0; i < QUEUEBUFFER_NUM; ++i) {
|
||||
_queBuffers[i] = nullptr;
|
||||
@@ -114,7 +113,7 @@ AudioCache::~AudioCache() {
|
||||
_alBufferId = INVALID_AL_BUFFER_ID;
|
||||
}
|
||||
} else {
|
||||
ALOGW("AudioCache (%p), id=%u, buffer isn't ready, state=%d", this, _id, _state);
|
||||
ALOGW("AudioCache (%p), id=%u, buffer isn't ready, state=%d", this, _id, static_cast<int>(_state.load()));
|
||||
}
|
||||
|
||||
if (_queBufferFrames > 0) {
|
||||
@@ -267,7 +266,6 @@ void AudioCache::readDataTask(unsigned int selfId) {
|
||||
invokingPlayCallbacks();
|
||||
invokingLoadCallbacks();
|
||||
|
||||
_isLoadingFinished = true;
|
||||
if (_state != State::READY) {
|
||||
_state = State::FAILED;
|
||||
if (_alBufferId != INVALID_AL_BUFFER_ID && alIsBuffer(_alBufferId)) {
|
||||
@@ -277,12 +275,13 @@ void AudioCache::readDataTask(unsigned int selfId) {
|
||||
}
|
||||
}
|
||||
|
||||
_isLoadingFinished = true;
|
||||
_readDataTaskMutex.unlock();
|
||||
}
|
||||
|
||||
void AudioCache::addPlayCallback(const std::function<void()> &callback) {
|
||||
std::lock_guard<std::mutex> lk(_playCallbackMutex);
|
||||
switch (_state) {
|
||||
switch (_state.load()) {
|
||||
case State::INITIAL:
|
||||
case State::LOADING:
|
||||
_playCallbacks.push_back(callback);
|
||||
@@ -296,7 +295,7 @@ void AudioCache::addPlayCallback(const std::function<void()> &callback) {
|
||||
break;
|
||||
|
||||
default:
|
||||
ALOGE("Invalid state: %d", _state);
|
||||
ALOGE("Invalid state: %d", static_cast<int>(_state.load()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -312,7 +311,7 @@ void AudioCache::invokingPlayCallbacks() {
|
||||
}
|
||||
|
||||
void AudioCache::addLoadCallback(const std::function<void(bool)> &callback) {
|
||||
switch (_state) {
|
||||
switch (_state.load()) {
|
||||
case State::INITIAL:
|
||||
case State::LOADING:
|
||||
_loadCallbacks.push_back(callback);
|
||||
@@ -326,7 +325,7 @@ void AudioCache::addLoadCallback(const std::function<void(bool)> &callback) {
|
||||
break;
|
||||
|
||||
default:
|
||||
ALOGE("Invalid state: %d", _state);
|
||||
ALOGE("Invalid state: %d", static_cast<int>(_state.load()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -337,18 +336,27 @@ void AudioCache::invokingLoadCallbacks() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto scheduler = _scheduler.lock();
|
||||
if (!scheduler) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isDestroyed = _isDestroyed;
|
||||
auto scheduler = CC_CURRENT_ENGINE()->getScheduler();
|
||||
scheduler->performFunctionInCocosThread([&, isDestroyed]() {
|
||||
const bool isReady = _state.load() == State::READY;
|
||||
scheduler->performFunctionInCocosThread([this, isDestroyed, isReady]() {
|
||||
if (*isDestroyed) {
|
||||
ALOGV("invokingLoadCallbacks perform in cocos thread, AudioCache (%p) was destroyed!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &&cb : _loadCallbacks) {
|
||||
cb(_state == State::READY);
|
||||
// A callback may uncache this file or end the audio engine. Do not access the
|
||||
// cache again after invoking user code, and cancel any remaining callbacks.
|
||||
auto callbacks = std::move(_loadCallbacks);
|
||||
for (auto &&cb : callbacks) {
|
||||
if (*isDestroyed) {
|
||||
break;
|
||||
}
|
||||
cb(isReady);
|
||||
}
|
||||
|
||||
_loadCallbacks.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,6 +167,13 @@ AudioEngineImpl::~AudioEngineImpl() {
|
||||
sche->unschedule("AudioEngine", this);
|
||||
}
|
||||
|
||||
// AudioEngine::end() has joined the worker pool before deleting this backend.
|
||||
// Queued tasks are discarded by the pool, so their caches will never receive
|
||||
// a read/skip notification from a worker. Unblock those cache destructors.
|
||||
for (auto &entry : _audioCaches) {
|
||||
entry.second.setSkipReadDataTask(true);
|
||||
}
|
||||
|
||||
if (s_ALContext) {
|
||||
alDeleteSources(MAX_AUDIOINSTANCES, _alSources);
|
||||
|
||||
@@ -286,6 +293,7 @@ AudioCache *AudioEngineImpl::preload(const ccstd::string &filePath, std::functio
|
||||
auto it = _audioCaches.find(filePath);
|
||||
if (it == _audioCaches.end()) {
|
||||
audioCache = &_audioCaches[filePath];
|
||||
audioCache->_scheduler = _scheduler;
|
||||
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
unsigned int cacheId = audioCache->_id;
|
||||
auto isCacheDestroyed = audioCache->_isDestroyed;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include "audio/common/decoder/AudioDecoder.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/Utils.h"
|
||||
@@ -500,6 +501,7 @@ void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void(in
|
||||
}
|
||||
|
||||
void AudioEngineImpl::update(float /*dt*/) {
|
||||
ccstd::vector<std::function<void()>> finishCallbacks;
|
||||
ALint sourceState;
|
||||
int audioID;
|
||||
AudioPlayer *player;
|
||||
@@ -534,7 +536,9 @@ void AudioEngineImpl::update(float /*dt*/) {
|
||||
_threadMutex.unlock();
|
||||
|
||||
if (player->_finishCallbak) {
|
||||
player->_finishCallbak(audioID, filePath); //IDEA: callback will delay 50ms
|
||||
finishCallbacks.emplace_back([callback = std::move(player->_finishCallbak), audioID, filePath]() {
|
||||
callback(audioID, filePath);
|
||||
});
|
||||
}
|
||||
delete player;
|
||||
_alSourceUsed[alSource] = false;
|
||||
@@ -549,6 +553,12 @@ void AudioEngineImpl::update(float /*dt*/) {
|
||||
sche->unschedule("AudioEngine", this);
|
||||
}
|
||||
}
|
||||
|
||||
// Callbacks may play/stop audio or destroy the engine. Finish all access to
|
||||
// player state before invoking them, and keep the callbacks in local storage.
|
||||
for (const auto &callback : finishCallbacks) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::uncache(const ccstd::string &filePath) {
|
||||
|
||||
@@ -157,6 +157,7 @@ void Scheduler::schedule(const ccSchedulerFunc &callback, void *target, float in
|
||||
if (iter == _hashForTimers.end()) {
|
||||
element = ccnew HashTimerEntry();
|
||||
element->target = target;
|
||||
element->generation = ++_nextTimerGeneration;
|
||||
|
||||
_hashForTimers[target] = element;
|
||||
|
||||
@@ -368,10 +369,23 @@ void Scheduler::runFunctionsToBePerformedInCocosThread() {
|
||||
void Scheduler::update(float dt) {
|
||||
_updateHashLocked = true;
|
||||
|
||||
// Iterate over all the custom selectors
|
||||
HashTimerEntry *elt = nullptr;
|
||||
for (auto iter = _hashForTimers.begin(); iter != _hashForTimers.end();) {
|
||||
elt = iter->second;
|
||||
// Callbacks can rehash the map or remove and recreate a target. Snapshot
|
||||
// identities, not iterators or entry pointers; new entries start next frame.
|
||||
struct TimerIdentity {
|
||||
void *target;
|
||||
uint64_t generation;
|
||||
};
|
||||
ccstd::vector<TimerIdentity> targets;
|
||||
targets.reserve(_hashForTimers.size());
|
||||
for (const auto &entry : _hashForTimers) {
|
||||
targets.push_back({entry.first, entry.second->generation});
|
||||
}
|
||||
for (const auto &target : targets) {
|
||||
auto iter = _hashForTimers.find(target.target);
|
||||
if (iter == _hashForTimers.end() || iter->second->generation != target.generation) {
|
||||
continue;
|
||||
}
|
||||
auto *elt = iter->second;
|
||||
_currentTarget = elt;
|
||||
_currentTargetSalvaged = false;
|
||||
|
||||
@@ -396,14 +410,9 @@ void Scheduler::update(float dt) {
|
||||
|
||||
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
|
||||
if (_currentTargetSalvaged && _currentTarget->timers.empty()) {
|
||||
++iter;
|
||||
removeHashElement(_currentTarget);
|
||||
if (iter != _hashForTimers.end()) {
|
||||
++iter;
|
||||
}
|
||||
} else {
|
||||
++iter;
|
||||
}
|
||||
_currentTarget = nullptr;
|
||||
}
|
||||
|
||||
_updateHashLocked = false;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
@@ -278,6 +279,7 @@ private:
|
||||
struct HashTimerEntry {
|
||||
ccstd::vector<Timer *> timers;
|
||||
void *target;
|
||||
uint64_t generation;
|
||||
int timerIndex;
|
||||
Timer *currentTimer;
|
||||
bool currentTimerSalvaged;
|
||||
@@ -291,9 +293,10 @@ private:
|
||||
|
||||
// Used for "selectors with interval"
|
||||
ccstd::unordered_map<void *, HashTimerEntry *> _hashForTimers;
|
||||
uint64_t _nextTimerGeneration = 0;
|
||||
struct HashTimerEntry *_currentTarget = nullptr;
|
||||
bool _currentTargetSalvaged = false;
|
||||
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||
// True while timer entries are being updated.
|
||||
bool _updateHashLocked = false;
|
||||
|
||||
// Used for "perform Function"
|
||||
|
||||
@@ -1184,10 +1184,12 @@ void ScriptEngine::removeUnhandledPromise(v8::Local<v8::Promise> promise) {
|
||||
// Remove handled promises from the list
|
||||
SE_ASSERT(promise->GetIsolate() == _isolate, "Wrong isolate");
|
||||
auto *isolate = promise->GetIsolate();
|
||||
for (auto it = _unhandledPromises.begin(); it != _unhandledPromises.end(); ++it) {
|
||||
for (auto it = _unhandledPromises.begin(); it != _unhandledPromises.end();) {
|
||||
v8::Local<v8::Promise> const unhandledPromise = std::get<0>(*it).Get(isolate);
|
||||
if (unhandledPromise == promise) {
|
||||
_unhandledPromises.erase(it--);
|
||||
it = _unhandledPromises.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ THE SOFTWARE.
|
||||
#define COCOS_VERSION_DEFINED 1
|
||||
#define COCOS_VERSION 40000
|
||||
|
||||
// #define COCOS_PRE_RELEASE "alpha"
|
||||
// #define COCOS_PRE_RELEASE "beta"
|
||||
|
||||
@@ -1007,7 +1007,8 @@ public:
|
||||
for (auto *set : sets) {
|
||||
set->update(oldView, newView);
|
||||
}
|
||||
_gpuBufferViewSet.erase(iter);
|
||||
// Connecting the new view may have rehashed the map.
|
||||
_gpuBufferViewSet.erase(oldView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1018,7 +1019,8 @@ public:
|
||||
for (auto *set : sets) {
|
||||
set->update(oldView, newView);
|
||||
}
|
||||
_gpuTextureViewSet.erase(iter);
|
||||
// Connecting the new view may have rehashed the map.
|
||||
_gpuTextureViewSet.erase(oldView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1217,7 +1219,8 @@ public:
|
||||
ia->update(oldBuffer, newBuffer);
|
||||
_ias[newBuffer].insert(ia);
|
||||
}
|
||||
_ias.erase(iter);
|
||||
// Registering the new buffer may have rehashed the map.
|
||||
_ias.erase(oldBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-9
@@ -185,8 +185,9 @@ void GoogleBillingHelper::onBillingServiceDisconnected(JNIEnv* env, jclass clazz
|
||||
if (billingClient) {
|
||||
auto it = billingClient->_listeners.find(callbackId);
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
cc::callJSfunc(it->second.get(), "onBillingServiceDisconnected");
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onBillingServiceDisconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,8 +204,9 @@ void GoogleBillingHelper::onProductDetailsResponse(JNIEnv* env, jclass clazz,
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj);
|
||||
std::vector<cc::ProductDetails*> productDetailsList = cc::JniBilling::toProductDetailList(env, productDetailsListObj, tag, startID);
|
||||
cc::callJSfunc(it->second.get(), "onProductDetailsResponse", billingResult, productDetailsList);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onProductDetailsResponse", billingResult, productDetailsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,8 +241,9 @@ void GoogleBillingHelper::onConsumeResponse(JNIEnv* env, jclass clazz, jint tag,
|
||||
auto it = billingClient->_listeners.find(callbackId);
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj);
|
||||
cc::callJSfunc(it->second.get(), "onConsumeResponse", billingResult, cc::StringUtils::getStringUTFCharsJNI(env, static_cast<jstring>(purchaseToken)));
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onConsumeResponse", billingResult, cc::StringUtils::getStringUTFCharsJNI(env, static_cast<jstring>(purchaseToken)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,8 +259,9 @@ void GoogleBillingHelper::onQueryPurchasesResponse(JNIEnv* env, jclass clazz, ji
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj);
|
||||
std::vector<cc::Purchase*> purchasesList = cc::JniBilling::toPurchaseList(env, purchasesListObj, tag, startID);
|
||||
cc::callJSfunc(it->second.get(), "onQueryPurchasesResponse", billingResult, purchasesList);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onQueryPurchasesResponse", billingResult, purchasesList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,8 +276,9 @@ void GoogleBillingHelper::onBillingConfigResponse(JNIEnv* env, jclass clazz, jin
|
||||
if (billingConfigObj) {
|
||||
billingConfig = cc::JniBilling::toBillingConfig(env, billingConfigObj);
|
||||
}
|
||||
cc::callJSfunc(it->second.get(), "onBillingConfigResponse", billingResult, billingConfig);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onBillingConfigResponse", billingResult, billingConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,8 +293,9 @@ void GoogleBillingHelper::onAlternativeBillingOnlyTokenResponse(JNIEnv* env, jcl
|
||||
if (alternativeBillingOnlyReportingDetailsObj) {
|
||||
toAlternativeBillingOnlyReporting = cc::JniBilling::toAlternativeBillingOnlyReportingDetails(env, alternativeBillingOnlyReportingDetailsObj);
|
||||
}
|
||||
cc::callJSfunc(it->second.get(), "onAlternativeBillingOnlyTokenResponse", billingResult, toAlternativeBillingOnlyReporting);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onAlternativeBillingOnlyTokenResponse", billingResult, toAlternativeBillingOnlyReporting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,8 +310,9 @@ void GoogleBillingHelper::onExternalOfferReportingDetailsResponse(JNIEnv* env, j
|
||||
if (externalOfferReportingDetailsObj) {
|
||||
externalOfferReportingDetails = cc::JniBilling::toExternalOfferReportingDetails(env, externalOfferReportingDetailsObj);
|
||||
}
|
||||
cc::callJSfunc(it->second.get(), "onExternalOfferReportingDetailsResponse", billingResult, externalOfferReportingDetails);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onExternalOfferReportingDetailsResponse", billingResult, externalOfferReportingDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,8 +339,9 @@ void GoogleBillingHelper::onInAppMessageResponse(JNIEnv* env, jclass clazz, jint
|
||||
auto it = billingClient->_listeners.find(callbackId);
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
auto* inAppMessageResult = cc::JniBilling::toInAppMessageResult(env, inAppMessageResultObj);
|
||||
cc::callJSfunc(it->second.get(), "onInAppMessageResponse", inAppMessageResult);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), "onInAppMessageResponse", inAppMessageResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,8 +352,9 @@ void GoogleBillingHelper::responseOnlyWithBillingResult(const std::string& funct
|
||||
auto it = billingClient->_listeners.find(callbackId);
|
||||
if (it != billingClient->_listeners.end()) {
|
||||
auto* billingResult = cc::JniBilling::toBillingResult(env, billingResultObj);
|
||||
cc::callJSfunc(it->second.get(), functionName.c_str(), billingResult);
|
||||
scopedListener listener(it->second.get());
|
||||
billingClient->_listeners.erase(it);
|
||||
cc::callJSfunc(listener.get(), functionName.c_str(), billingResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ void PlayTask::onTaskSuccess(int listerId, void* obj) {
|
||||
// Therefore, it should be removed first.
|
||||
scopedListener listener(it->second.get());
|
||||
_listeners.erase(it);
|
||||
callJSfuncWithJObject(it->second.get(), "onSuccess", obj);
|
||||
callJSfuncWithJObject(listener.get(), "onSuccess", obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.35",
|
||||
"version": "4.0.0-beta.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.35",
|
||||
"version": "4.0.0-beta.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.35",
|
||||
"version": "4.0.0-beta.0",
|
||||
"description": "Cocos Creator is a cross-platform 2D & 3D game engine written in C++ and TypeScript, licensed under MIT.",
|
||||
"homepage": "http://www.cocos.com",
|
||||
"license": "MIT",
|
||||
|
||||
Reference in New Issue
Block a user