Merge the code of v3.3.1 platform adaptation layer into the development branch (#3958)

* 1、Merge platform adaptation layer code into the development branch
2、It passed the test in windows and ohos system

* 1、Merge platform adaptation layer code into the development branch
2、It passed the test in windows and ohos system

* 1、Fix github compile windows error

* 1、Fix github compile windows error

* 1. Adjust the code format;
2. Fix js automatic generation binding
3. Adjust github CI compilation

* 1. Adjust the code format;
2. Fix js automatic generation binding
3. Adjust github CI compilation

* Solve mac and ios compilation failure

* Fix the problem of compilation of Windows-side simulator

* 1. Adapt the simulator to a new adaptation layer;
2. Fix the compilation warning of ios, and the implicit conversion failed;
3. Fix the mac compilation error, due to the problem of adding the link identification -all_load;

* 1.Add the isDisplayStats and setDisplayStats method to the screen interface

* Fix clang-tidy compilation warning

* Fix clang-tidy compilation warning

* Repair the emulator, compatible with mac and win

* 1、Repair detailed errors, including name modification and calling method modification
2、Delete redundant files in the template directory
3、Change the vibrate interface to vibrator
4、Fix word spelling errors

* Rename interfaces to modules

* Replace CC_ASSERT with CCASSERT

* Replace CC_ASSERT with CCASSERT

Co-authored-by: qiuguohua <>
This commit is contained in:
qiuguohua
2021-10-27 10:51:02 +08:00
committed by GitHub
parent 606dd0f2f0
commit eeb9d5c689
249 changed files with 12109 additions and 7683 deletions
@@ -28,24 +28,22 @@ THE SOFTWARE.
namespace cc {
AsyncTaskPool *AsyncTaskPool::s_asyncTaskPool = nullptr;
AsyncTaskPool *AsyncTaskPool::sAsyncTaskPool = nullptr;
AsyncTaskPool *AsyncTaskPool::getInstance() {
if (s_asyncTaskPool == nullptr) {
s_asyncTaskPool = new (std::nothrow) AsyncTaskPool();
if (sAsyncTaskPool == nullptr) {
sAsyncTaskPool = new (std::nothrow) AsyncTaskPool();
}
return s_asyncTaskPool;
return sAsyncTaskPool;
}
void AsyncTaskPool::destroyInstance() {
delete s_asyncTaskPool;
s_asyncTaskPool = nullptr;
delete sAsyncTaskPool;
sAsyncTaskPool = nullptr;
}
AsyncTaskPool::AsyncTaskPool() {
}
AsyncTaskPool::AsyncTaskPool() = default;
AsyncTaskPool::~AsyncTaskPool() {
}
AsyncTaskPool::~AsyncTaskPool() = default;
} // namespace cc
@@ -23,20 +23,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCSYNC_TASK_POOL_H_
#define __CCSYNC_TASK_POOL_H_
#pragma once
#include "application/ApplicationManager.h"
#include "platform/Application.h"
#include "base/Scheduler.h"
#include <vector>
#include <queue>
#include <memory>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <future>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>
#include <stdexcept>
#include <thread>
#include <vector>
/**
* @addtogroup base
@@ -51,7 +51,7 @@ namespace cc {
*/
class CC_DLL AsyncTaskPool {
public:
typedef std::function<void(void *)> TaskCallBack;
using TaskCallBack = std::function<void(void *)>;
enum class TaskType {
TASK_IO,
@@ -97,31 +97,31 @@ protected:
class ThreadTasks {
struct AsyncTaskCallBack {
TaskCallBack callback;
void *callbackParam;
void * callbackParam;
};
public:
ThreadTasks()
: _stop(false) {
ThreadTasks() {
_thread = std::thread(
[this] {
for (;;) {
std::function<void()> task;
AsyncTaskCallBack callback;
AsyncTaskCallBack callback;
{
std::unique_lock<std::mutex> lock(this->_queueMutex);
this->_condition.wait(lock,
[this] { return this->_stop || !this->_tasks.empty(); });
if (this->_stop && this->_tasks.empty())
if (this->_stop && this->_tasks.empty()) {
return;
task = std::move(this->_tasks.front());
}
task = std::move(this->_tasks.front());
callback = std::move(this->_taskCallBacks.front());
this->_tasks.pop();
this->_taskCallBacks.pop();
}
task();
Application::getInstance()->getScheduler()->performFunctionInCocosThread([&, callback] { callback.callback(callback.callbackParam); });
CC_CURRENT_ENGINE()->getScheduler()->performFunctionInCocosThread([&, callback] { callback.callback(callback.callbackParam); });
}
});
}
@@ -130,20 +130,24 @@ protected:
std::unique_lock<std::mutex> lock(_queueMutex);
_stop = true;
while (_tasks.size())
while (!_tasks.empty()) {
_tasks.pop();
while (_taskCallBacks.size())
}
while (!_taskCallBacks.empty()) {
_taskCallBacks.pop();
}
}
_condition.notify_all();
_thread.join();
}
void clear() {
std::unique_lock<std::mutex> lock(_queueMutex);
while (_tasks.size())
while (!_tasks.empty()) {
_tasks.pop();
while (_taskCallBacks.size())
}
while (!_taskCallBacks.empty()) {
_taskCallBacks.pop();
}
}
template <class F>
void enqueue(const TaskCallBack &callback, void *callbackParam, F &&f) {
@@ -159,7 +163,7 @@ protected:
}
AsyncTaskCallBack taskCallBack;
taskCallBack.callback = callback;
taskCallBack.callback = callback;
taskCallBack.callbackParam = callbackParam;
_tasks.emplace([task]() { task(); });
_taskCallBacks.emplace(taskCallBack);
@@ -172,28 +176,28 @@ protected:
std::thread _thread;
// the task queue
std::queue<std::function<void()>> _tasks;
std::queue<AsyncTaskCallBack> _taskCallBacks;
std::queue<AsyncTaskCallBack> _taskCallBacks;
// synchronization
std::mutex _queueMutex;
std::mutex _queueMutex;
std::condition_variable _condition;
bool _stop;
bool _stop{false};
};
//tasks
ThreadTasks _threadTasks[int(TaskType::TASK_MAX_TYPE)];
ThreadTasks _threadTasks[static_cast<int>(TaskType::TASK_MAX_TYPE)];
static AsyncTaskPool *s_asyncTaskPool;
static AsyncTaskPool *sAsyncTaskPool;
};
inline void AsyncTaskPool::stopTasks(TaskType type) {
auto &threadTask = _threadTasks[(int)type];
auto &threadTask = _threadTasks[static_cast<int>(type)];
threadTask.clear();
}
template <class F>
inline void AsyncTaskPool::enqueue(AsyncTaskPool::TaskType type, const TaskCallBack &callback, void *callbackParam, F &&f) {
auto &threadTask = _threadTasks[(int)type];
auto &threadTask = _threadTasks[static_cast<int>(type)];
threadTask.enqueue(callback, callbackParam, f);
}
@@ -201,4 +205,3 @@ inline void AsyncTaskPool::enqueue(AsyncTaskPool::TaskType type, const TaskCallB
} // namespace cc
// end group
/// @}
#endif //__CCSYNC_TASK_POOL_H_