New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add worker for cocos native #16547
base: v3.8.2
Are you sure you want to change the base?
Add worker for cocos native #16547
Conversation
Interface Check ReportThis pull request does not change any public interfaces ! |
std::deque<std::string> messageQueue; | ||
/** | ||
* 发送信息到主线程 | ||
* type:0表示普通信息,1表示错误, 2 表示关闭 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to define a enum class {}
for the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
enum class MessageType {
NORMAL,
ERROR,
CLOSE
};
#include <cocos/base/Macros.h> | ||
#include <cocos/base/Log.h> | ||
#include <cocos/platform/FileUtils.h> | ||
#include <cocos/bindings/jswrapper/config.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use double quotes
to include files in engine. And cocos
prefix is not needed.
#include <cocos/bindings/jswrapper/config.h> | |
#include "bindings/jswrapper/config.h" |
function createTimeoutInfo(prevFuncArgs,isRepeat){let cb=prevFuncArgs[0];if(!cb){console.error("createTimeoutInfo doesn't pass a callback ...");return 0;} | ||
let delay=prevFuncArgs.length>1?prevFuncArgs[1]:0;let args;if(prevFuncArgs.length>2){args=Array.prototype.slice.call(prevFuncArgs,2);} | ||
let info=new TimeInfo(cb,delay,isRepeat,root,args);scheduleDataModel.timeoutInfos.set(info.id,info);return info.id;} | ||
root.setTimeout=function(cb){return createTimeoutInfo(arguments,false);};root.clearTimeout=function(id){scheduleDataModel.timeoutInfos.delete(id);};root.setInterval=function(cb){return createTimeoutInfo(arguments,true);};root.clearInterval=root.clearTimeout;root["$globalTick"]=function(nowMilliSeconds){handlerTimerInfos(nowMilliSeconds);}})(globalThis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this code come from?
If there is a bug in this code, how could we fix it since it was minified.
|
||
namespace ccex { | ||
namespace helper { | ||
std::unordered_map<uintptr_t, Worker*> workers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use v8::Isolate *
as the map's key?
)"; | ||
|
||
namespace { | ||
class WorkerImp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relationship between class Worker
and class WorkerImp
?
void setWeak(){ | ||
_weakCount.fetch_add(1); | ||
if (_weakCount == 3) { | ||
delete this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why delete this only when the weak count is 3?
} | ||
static void destroyAll(); | ||
public: | ||
std::deque<std::string> messageQueue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could messageQueue
variable be private ?
Re: #
Changelog
jsb_worker_maunal.cpp/jsb_worker_maunal.h
andWorker.cpp/Worker.h
jsb_module_register.cpp
简中说明
只支持v8引擎
支持特性
主线程Worker接口:
Worker内部接口:
不支持特性
PS: 根据我的测试,额外开启一个空Worker约增加10M内存
English
v8 engine only
Supported Features
Main Thread Worker Interface:
Worker Internal Interface:
Additional extended interfaces:
Unsupported Features
PS: According to my test, opening an empty Worker will increase the memory usage by about 10M.