CC_CALLBACK_0/2/3的使用.

本文详细介绍了Cocos2d-x中std::bind的使用方法,包括不同版本间的回调函数变化,以及如何通过宏定义和std::bind实现函数适配。同时,文章还解释了std::placeholders的含义及其在bind中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

重要的总结的话写在前面:

       1.直接看示例代码中//3.x版本代码的举例,别看乱了,头晕.

    2. CC_CALLBACK_0 对应 CallFunc 

     CC_CALLBACK_1 对应 CallFuncN

     其中重要的一句话是:CallFuncN:使用CC_CALLBACK_1。需要默认传入不定参数 placeholders::_1,其值为:调用该动作的对象(如sprite->runAction(callfun),那么默认的一个不定参数 _1 为 sprite)。

     注意:用宏的话还是跟bind有些不同的,有默认格式的.如果使用宏,

   3.参数类型和个数一定要匹配.HelloWorld::callback0, this) 前两个默认.>=1时候,默认传运行时候的节点为sender.

    ❤.!!!宏没有直接bind好用.直接格式std::bind(A函数,this,A函数参数列表绑定值[注意类型匹配]).

    如CallFunc::create(std::bind(&HelloWorld::callback2, this, sprite, 0.5));

    

    

    最终:用宏就用宏的例子思考问题,用bind就用bind例子思考问题.勿混杂.<bind比宏逻辑清晰点>

    猜测:从最基本的bind原型来看.传了this的话.使用这个绑定函数的时候,就能用这个this.

      


---------------------------------------------------------------------------------------------------- 


1、CC_CALLBACK_*

    cocos2dx总共使用了4个std::bind的宏定义,其重点就在于使用了std::bind进行函数适配

    > std::placeholders::_1 :不定参数。不事先指定,而是在调用的时候传入。

    > ##__VA_ARGS__         :可变参数列表。

1
2
3
4
5
6
7
//
// new callbacks based on C++11
#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__)
//


2、变更的回调函数

    > 动作函数  :CallFunc/CallFuncN

                  callfunc_selector / callfuncN_selector / callfuncND_selector

    > 菜单项回调menu_selector

    > 触摸事件  onTouchBegan / onTouchMoved / onTouchEnded


  2.1、动作函数CallFunc

    可以直接使用CC_CALLBACK_0、CC_CALLBACK_1,也可以直接使用std::bind。

    > CallFunc :使用CC_CALLBACK_0。不带任何不定参数。

    > CallFuncN:使用CC_CALLBACK_1。需要默认传入不定参数 placeholders::_1,其值为:调用该动作的对象(如sprite->runAction(callfun),那么默认的一个不定参数 _1 为 sprite)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
/**
 * 函数动作
 *     - CallFunc
 *     - CallFuncN
 *     - CallFuncND与CallFuncO已被遗弃,请使用CallFuncN替代
 */
//2.x版本
    CallFunc::create    (this, callfunc_selector  (HelloWorld::callback0) );
    CCCallFuncN::create (this, callfuncN_selector (HelloWorld::callback1) );
    CCCallFuncND::create(this, callfuncND_selector(HelloWorld::callback2), (void *)10 );
     
    //回调函数
    void HelloWorld::callback0() { }                     //CCCallFunc回调函数
    void HelloWorld::callback1(CCNode* node) { }         //CCCallFuncN回调函数
    void HelloWorld::callback2(CCNode* node,void* a) { } //CCCallFuncND回调函数,参数必须为void*
 
 
//3.x版本
    //使用 CC_CALLBACK_*
    CallFunc::create ( CC_CALLBACK_0(HelloWorld::callback0, this) );
    CallFuncN::create( CC_CALLBACK_1(HelloWorld::callback1, this) );
    CallFuncN::create( CC_CALLBACK_2(HelloWorld::callback2, this, 0.5));
     
    //使用 std::bind
    //其中sprite为执行动作的精灵
    CallFunc::create (std::bind(&HelloWorld::callback0, this ) );
    CallFuncN::create(std::bind(&HelloWorld::callback1, this, sprite);
    CallFuncN::create(std::bind(&HelloWorld::callback2, this, sprite, 0.5));
     
    //回调函数
    void HelloWorld::callback0() { }
    void HelloWorld::callback1(Node* node) { }
    void HelloWorld::callback2(Node* node, float a) { }   //可自定义参数类型float
     
//

原文转载自:http://blog.csdn.net/fanzhang1990/article/details/40984943

bind解说:转载自:http://www.jellythink.com/archives/773
#include <iostream>
#include <functional>
using namespace std;

int TestFunc(int a, char c, float f)
{
    cout << a << endl;
    cout << c << endl;
    cout << f << endl;

    return a;
}

int main()
{
    auto bindFunc1 = bind(TestFunc, std::placeholders::_1, 'A', 100.1);
    bindFunc1(10);

    cout << "=================================\n";

    auto bindFunc2 = bind(TestFunc, std::placeholders::_2, std::placeholders::_1, 100.1);
    bindFunc2('B', 10);

    cout << "=================================\n";

    auto bindFunc3 = bind(TestFunc, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1);
    bindFunc3(100.1, 30, 'C');

    return 0;
}

上面这段代码主要说的是bind中std::placeholders的使用。 std::placeholders是一个占位符。当使用bind生成一个新的可调用对象时,std::placeholders表示新的可调用对象的第 几个参数和原函数的第几个参数进行匹配,这么说有点绕。比如:

auto bindFunc3 = bind(TestFunc, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1);

bindFunc3(100.1, 30, 'C');

可以看到,在bind的时候,第一个位置是TestFunc,除了这个,参数的第一个位置为占位符std::placeholders::_2,这就表示,调用bindFunc3的时候,它的第二个参数和TestFunc的第一个参数匹配,以此类推。

以下是使用std::bind的一些需要注意的地方:

  • bind预先绑定的参数需要传具体的变量或值进去,对于预先绑定的参数,是pass-by-value的;
  • 对于不事先绑定的参数,需要传std::placeholders进去,从_1开始,依次递增。placeholder是pass-by-reference的;
  • bind的返回值是可调用实体,可以直接赋给std::function对象;
  • 对于绑定的指针、引用类型的参数,使用者需要保证在可调用实体调用之前,这些参数是可用的;
  • 类的this可以通过对象或者指针来绑定。
为什么要用std::bind

当我们厌倦了使用std::bind1ststd::bind2nd的时候,现在有了std::bind,你完全可以放弃使用std::bind1ststd::bind2nd了。std::bind绑定的参数的个数不受限制,绑定的具体哪些参数也不受限制,由用户指定,这个bind才是真正意义上的绑定。

在Cocos2d-x中,我们可以看到,使用std::bind生成一个可调用对象,这个对象可以直接赋值给std::function对象;在类中有一个std::function的变量,这个std::functionstd::bind来赋值,而std::bind绑定的可调用对象可以是Lambda表达式或者类成员函数等可调用对象,这个是Cocos2d-x中的一般用法。

以后遇到了“奇葩”用法再继续总结了,一次也总结不完的。


qwe@qwe-MS-Challenger-H610ITX-2LAN-V3:~/Desktop/catkin_ws$ catkin_make Base path: /home/qwe/Desktop/catkin_ws Source space: /home/qwe/Desktop/catkin_ws/src Build space: /home/qwe/Desktop/catkin_ws/build Devel space: /home/qwe/Desktop/catkin_ws/devel Install space: /home/qwe/Desktop/catkin_ws/install #### #### Running command: "make cmake_check_build_system" in "/home/qwe/Desktop/catkin_ws/build" #### #### #### Running command: "make -j12 -l12" in "/home/qwe/Desktop/catkin_ws/build" #### [ 4%] Generating ui_main_window.h Scanning dependencies of target _handmsg_generate_messages_check_deps_handtarget Scanning dependencies of target _handmsg_generate_messages_check_deps_handPosCaliData Scanning dependencies of target _handmsg_generate_messages_check_deps_igh Scanning dependencies of target std_msgs_generate_messages_py Scanning dependencies of target hand_igh_v2_node Scanning dependencies of target _handmsg_generate_messages_check_deps_handstatus [ 6%] Generating include/hand_gui_2/moc_qnode.cpp Scanning dependencies of target _handmsg_generate_messages_check_deps_HandPlanPoint [ 4%] Generating ui_lrhandform.h [ 4%] Generating qrc_images.cpp Scanning dependencies of target _handmsg_generate_messages_check_deps_tactile [ 7%] Built target std_msgs_generate_messages_py [ 7%] Generating include/hand_gui_2/moc_finger.cpp [ 9%] Generating include/hand_gui_2/moc_lrhandform.cpp [ 11%] Generating include/hand_gui_2/moc_main_window.cpp /home/qwe/Desktop/catkin_ws/src/qtros/include/hand_gui_2/finger.hpp:0: Note: No relevant classes found. No output generated. [ 12%] Building CXX object hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/main.cpp.o [ 12%] Built target _handmsg_generate_messages_check_deps_handstatus [ 14%] Building CXX object hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/pdos.cpp.o cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/build.make:76: hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/pdos.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: *** [hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/build.make:63: hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/main.cpp.o] Error 1 [ 14%] Built target _handmsg_generate_messages_check_deps_tactile [ 15%] Built target _handmsg_generate_messages_check_deps_handtarget [ 15%] Building CXX object hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/callback.cpp.o [ 15%] Built target _handmsg_generate_messages_check_deps_igh Scanning dependencies of target std_msgs_generate_messages_nodejs cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/build.make:89: hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/src/callback.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:940: hand_igh_v2/CMakeFiles/hand_igh_v2_node.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 15%] Built target _handmsg_generate_messages_check_deps_handPosCaliData Scanning dependencies of target std_msgs_generate_messages_eus Scanning dependencies of target std_msgs_generate_messages_cpp Scanning dependencies of target _demo_py_generate_messages_check_deps_nn [ 15%] Built target std_msgs_generate_messages_nodejs Scanning dependencies of target std_msgs_generate_messages_lisp [ 15%] Built target _handmsg_generate_messages_check_deps_HandPlanPoint [ 15%] Built target std_msgs_generate_messages_cpp [ 15%] Built target std_msgs_generate_messages_eus [ 15%] Built target std_msgs_generate_messages_lisp [ 15%] Built target _demo_py_generate_messages_check_deps_nn Scanning dependencies of target hand_gui_2 [ 17%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/src/lrhandform.cpp.o [ 19%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/src/finger.cpp.o [ 20%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/qrc_images.cpp.o [ 23%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/src/main.cpp.o [ 23%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/src/main_window.cpp.o [ 25%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/src/qnode.cpp.o [ 26%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_finger.cpp.o [ 28%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_lrhandform.cpp.o [ 31%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_qnode.cpp.o [ 31%] Building CXX object qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_main_window.cpp.o cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:119: qtros/CMakeFiles/hand_gui_2.dir/src/main.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:93: qtros/CMakeFiles/hand_gui_2.dir/src/finger.cpp.o] Error 1 make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:132: qtros/CMakeFiles/hand_gui_2.dir/src/main_window.cpp.o] Error 1 cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:106: qtros/CMakeFiles/hand_gui_2.dir/src/lrhandform.cpp.o] Error 1 make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:145: qtros/CMakeFiles/hand_gui_2.dir/src/qnode.cpp.o] Error 1 cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:171: qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_finger.cpp.o] Error 1 cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:197: qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_main_window.cpp.o] Error 1 cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:158: qtros/CMakeFiles/hand_gui_2.dir/qrc_images.cpp.o] Error 1 make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:210: qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_qnode.cpp.o] Error 1 make[2]: *** [qtros/CMakeFiles/hand_gui_2.dir/build.make:184: qtros/CMakeFiles/hand_gui_2.dir/include/hand_gui_2/moc_lrhandform.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:697: qtros/CMakeFiles/hand_gui_2.dir/all] Error 2 make: *** [Makefile:141: all] Error 2 Invoking "make -j12 -l12" failed
07-12
下面函数添加到chromium源码中用于获取cookie,函数: void FindSiteCookies(Profile* profile, const std::string& domain) { // 获取 CookieManager network::mojom::CookieManager* cookie_manager = profile->GetDefaultStoragePartition()->GetCookieManagerForBrowserProcess(); // 构建查询选项 net::CookieOptions options; options.set_include_httponly(); // 包含 HttpOnly Cookie options.set_same_site_cookie_context(net::CookieOptions::SameSiteCookieContext::MakeInclusive()); // 异步获取 Cookie 列表 cookie_manager->GetCookieList(GURL("https://" + domain), options, net::CookiePartitionKeyCollection(), base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { for (const auto& cookie : cookies) { LOG(INFO) << "Found cookie: " << cookie.cookie.Name() << "=" << cookie.cookie.Value() << " for domain: " << cookie.cookie.Domain(); } })); } 报错: ../../chrome/browser/ui/toolbar/app_menu_model.cc(1775,90): error: member access into incomplete type &#39;StoragePartition&#39; 1775 | network::mojom::CookieManager* cookie_manager = profile->GetDefaultStoragePartition()->GetCookieManagerForBrowserProcess(); | ^ ../..\content/public/browser/browser_context.h(106,7): note: forward declaration of &#39;content::StoragePartition&#39; 106 | class StoragePartition; | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1783,19): error: member access into incomplete type &#39;network::mojom::CookieManager&#39; 1783 | cookie_manager->GetCookieList(GURL("https://" + domain), options, net::CookiePartitionKeyCollection(), | ^ ../..\components/signin/public/base/signin_client.h(40,7): note: forward declaration of &#39;network::mojom::CookieManager&#39; 40 | class CookieManager; | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1783,76): error: no member named &#39;CookiePartitionKeyCollection&#39; in namespace &#39;net&#39; 1783 | cookie_manager->GetCookieList(GURL("https://" + domain), options, net::CookiePartitionKeyCollection(), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): error: variable &#39;__begin2&#39; cannot be implicitly captured in a lambda with no capture-default specified 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,124): note: while substituting into a lambda expression here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): note: &#39;__begin2&#39; declared here 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__begin2&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | __begin2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__begin2&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &__begin2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): error: variable &#39;__end2&#39; cannot be implicitly captured in a lambda with no capture-default specified 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): note: &#39;__end2&#39; declared here ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__end2&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | __end2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__end2&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &__end2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): error: variable &#39;__begin2&#39; cannot be implicitly captured in a lambda with no capture-default specified 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,37): note: &#39;__begin2&#39; declared here ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__begin2&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | __begin2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;__begin2&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &__begin2 ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1786,50): error: variable &#39;cookie&#39; cannot be implicitly captured in a lambda with no capture-default specified 1786 | LOG(INFO) << "Found cookie: " << cookie.cookie.Name() | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,30): note: &#39;cookie&#39; declared here 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1787,31): error: variable &#39;cookie&#39; cannot be implicitly captured in a lambda with no capture-default specified 1787 | << "=" << cookie.cookie.Value() | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,30): note: &#39;cookie&#39; declared here 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1788,43): error: variable &#39;cookie&#39; cannot be implicitly captured in a lambda with no capture-default specified 1788 | << " for domain: " << cookie.cookie.Domain(); | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1785,30): note: &#39;cookie&#39; declared here 1785 | for (const auto& cookie : cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: lambda expression begins here 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: capture &#39;cookie&#39; by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | &cookie ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by value 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | = ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,25): note: default capture by reference 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ | & ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): error: no viable conversion from &#39;(lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24)&#39; to &#39;(lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24)&#39; 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1785 | for (const auto& cookie : cookies) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1786 | LOG(INFO) << "Found cookie: " << cookie.cookie.Name() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1787 | << "=" << cookie.cookie.Value() | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1788 | << " for domain: " << cookie.cookie.Domain(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1789 | } | ~ 1790 | })); | ~ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: candidate constructor (the implicit copy constructor) not viable: no known conversion from &#39;(lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24)&#39; to &#39;const (lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24) &&#39; for 1st argument ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: candidate constructor (the implicit move constructor) not viable: no known conversion from &#39;(lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24)&#39; to &#39;(lambda at ../../chrome/browser/ui/toolbar/app_menu_model.cc:1784:24) &&&#39; for 1st argument 1784 | base::BindOnce([](const net::CookieAccessResultList& cookies, const net::CookieAccessResultList& excluded_cookies) { | ^ ../../chrome/browser/ui/toolbar/app_menu_model.cc(1784,24): note: candidate function ../..\base/functional/bind.h(58,32): note: passing argument to parameter &#39;functor&#39; here 58 | inline auto BindOnce(Functor&& functor, Args&&... args) { | ^ 10 error
最新发布
08-22
import { Component } from "cc"; import { oops } from "../../Oops"; import { AudioEffect } from "./AudioEffect"; import { AudioMusic } from "./AudioMusic"; import { OTimer } from "../../../../gamebase/timer/OTimer"; const LOCAL_STORE_KEY = "game_audio2"; /** * 音频管理器 * -@example 通过 oops.audio 调用 * -支持震动 * -获得音乐进度this._music.progress */ export class AudioManager extends Component { private _local_data: AudioLocalData = null; private _musicComp!: AudioMusic; //背景音乐 private _soundComp!: AudioEffect; //普通音效 private _battleSoundComp!: AudioEffect; //战斗音效 //#region 背景音乐 /** BGM播放进度 */ get progressMusic(): number { return this._musicComp.progress; } set progressMusic(value: number) { this._musicComp.progress = value; } /** BGM音量 */ get volumeMusic(): number { return this._local_data.volume_music; } set volumeMusic(value: number) { this._local_data.volume_music = value; this._musicComp.volume = value; } /** BGM开关 */ get switchMusic(): boolean { return this._local_data.switch_music; } set switchMusic(value: boolean) { this._local_data.switch_music = value; if (value) { this.resumeMusic(); } else { this.stopMusic(); } } /** 停止BGM */ stopMusic() { if (this._musicComp) { this._musicComp.stopAudio(); } } /** 恢复BGM */ resumeMusic() { if (this._musicComp && this.switchMusic) { this._musicComp.play(); } } /** 暂停BGM */ pauseMusic() { if (this._musicComp && this.switchMusic) { this._musicComp.pause(); } } /** 释放BGM */ releaseMusic() { this._musicComp?.release(); } /** * 设置BGM播放完成回调 * @param callback 回调 */ setMusicComplete(callback: Function | null = null) { this._musicComp.onComplete = callback; } /** * 播放BGM * @param url 资源地址 * @param callback 加载完成回调 */ playMusic(url: string, loop: boolean, callback?: Function) { if (this._local_data.switch_music) { this._musicComp.loop = loop; this._musicComp.load(url, callback); } } //#endregion //#region 音效 /** 音效音量 */ get volumeSound(): number { return this._local_data.volume_sound; } set volumeSound(value: number) { this._local_data.volume_sound = value; this._soundComp.volume = value; } /** 音效开关 */ get switchSound(): boolean { return this._local_data.switch_sound; } set switchSound(value: boolean) { this._local_data.switch_sound = value; if (value == false) this._soundComp.stop(); } /** 释放音效资源 */ public releaseSound() { this._soundComp?.release(); } /** * 播放音效 * @param url 地址 * @param vol 音量 * @param cd 冷却时间(冷却时间内无法重复播放)(>0生效) */ public playOneShoot(url: string, vol: number = 1, cd: number = 0.2) { if (this._local_data.switch_sound) { this._soundComp.load(url, vol, cd); } } /** * 停止当前音效 */ public stopEffect() { if (this._soundComp) { this._soundComp.stop(); } } //#endregion //#region 战斗音效 /** 战斗音效音量 */ get volumeBattleSound(): number { return this._local_data.volume_battleSound; } set volumeBattleSound(value: number) { this._local_data.volume_battleSound = value; this._battleSoundComp.volume = value; } /** 战斗音效开关 */ get switch_battleSound(): boolean { return this._local_data.switch_battleSound; } set switch_battleSound(value: boolean) { this._local_data.switch_battleSound = value; if (value == false) this._battleSoundComp.stop(); } /** 释放音效资源 */ public releaseBattleSound() { this._battleSoundComp?.release(); } /** * 播放音效 * @param url 地址 * @param vol 音量 * @param cd 冷却时间(冷却时间内无法重复播放)(>0生效) */ public playOneShootForBattle(url: string, vol: number = 1, cd: number = 0.2) { if (this._local_data.switch_sound) { if (this.switch_battleSound) { this._battleSoundComp.load(url, vol, cd, null); } } } /** 停止当前音效 */ public stopBattleEffect() { if (this._battleSoundComp) { this._battleSoundComp.stop(); } } //#endregion //#region 震动 /** 震动开关 */ get switch_vibrates(): boolean { return this._local_data.switch_vibrates; } set switch_vibrates(value: boolean) { this._local_data.switch_vibrates = value; } /** * 震动 * @param type 0轻1中2重 */ public vibrate(type: number = 0) { if (this.switch_vibrates) { } } /** * 长震动 */ public vibrateLong() { if (this.switch_vibrates) { } } //#endregion /** 释放所有 */ releaseAll() { this.releaseSound(); this.releaseMusic(); this.releaseBattleSound(); } /** * 恢复所有声音播放 */ public resumeAll() { if (this._musicComp && this.switchMusic) { this._musicComp.play(); } if (this._soundComp && this.switchSound) { this._soundComp.play(); } if (this._battleSoundComp && this.switch_battleSound) { this._battleSoundComp.play(); } } /** * 暂停所有声音播放 */ public pauseAll() { if (this._musicComp && this.switchMusic) { this._musicComp.pause(); } if (this._soundComp && this.switchSound) { this._soundComp.pause(); } if (this._battleSoundComp && this.switch_battleSound) { this._battleSoundComp.pause(); } } /** * 停止所有声音播放 */ public stopAll() { if (this._musicComp) { this._musicComp.stopAudio(); } if (this._soundComp) { this._soundComp.stop(); } if (this._battleSoundComp) { this._battleSoundComp.stop(); } } //#region 保存读取 /** 设置保存(延迟后自动保存) */ public save(delay: number = 0.2) { OTimer.instance.SetCd(`AudioManager_DelaySave`, delay, null, () => { this.save2(); }); } /** 保存配置 */ private save2() { if (this._local_data) { let jsonStr = JSON.stringify(this._local_data); oops.storage.set(LOCAL_STORE_KEY, jsonStr, false); console.log(`本地保存声音配置`, this._local_data); } else { console.error(`保存失败,配置数据为空 `); } } /** 读取配置 */ public load() { this._musicComp = this.getComponent(AudioMusic) || this.addComponent(AudioMusic)!; this._soundComp = this.getComponent(AudioEffect) || this.addComponent(AudioEffect)!; this._battleSoundComp = this.addComponent(AudioEffect); let jsonStr: string = oops.storage.get(LOCAL_STORE_KEY, null, false); if (!jsonStr || jsonStr == "") { let temp: AudioLocalData = { volume_music: 1, volume_sound: 1, volume_battleSound: 1, switch_music: true, switch_sound: true, switch_battleSound: true, switch_vibrates: true }; this._local_data = temp; console.log(`创建了新的声音配置文件`, this._local_data); } else { this._local_data = JSON.parse(jsonStr); console.log(`本地读取声音配置`, this._local_data); } if (this._musicComp) this._musicComp.volume = this._local_data.volume_music; if (this._soundComp) this._soundComp.volume = this._local_data.volume_sound; if (this._battleSoundComp) this._battleSoundComp.volume = this._local_data.volume_battleSound; } //#endregion } /** 封装 */ interface AudioLocalData { volume_music: number, volume_sound: number, volume_battleSound: number, switch_music: boolean, switch_sound: boolean, switch_battleSound: boolean, switch_vibrates: boolean } 这是游戏的export class AudioManager extends Component {
05-30
fs/btrfs/free-space-tree.o: warning: objtool: convert_free_space_to_bitmaps.cold.14()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: convert_free_space_to_extents.cold.15()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: remove_from_free_space_tree.cold.16()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: add_to_free_space_tree.cold.17()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: btrfs_create_free_space_tree.cold.18()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: btrfs_clear_free_space_tree.cold.19()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: add_block_group_free_space.cold.20()+0x0: frame pointer state mismatch fs/btrfs/free-space-tree.o: warning: objtool: remove_block_group_free_space.cold.21()+0x0: frame pointer state mismatch LD [M] fs/btrfs/btrfs.o CC kernel/delayacct.o kernel/relay.o: warning: objtool: relay_hotcpu_callback.cold.18()+0x0: frame pointer state mismatch kernel/relay.o: warning: objtool: relay_close.cold.19()+0x0: frame pointer state mismatch make: *** [fs] Error 2 CC kernel/taskstats.o CC kernel/tsacct.o kernel/rcutree.o: warning: objtool: rcu_check_callbacks.cold.59()+0x0: frame pointer state mismatch CC kernel/tracepoint.o CC kernel/elfcore.o CC kernel/irq_work.o CC kernel/user-return-notifier.o kernel/tracepoint.o: warning: objtool: tracepoint_add_probe.cold.12()+0x0: frame pointer state mismatch CC kernel/padata.o CC kernel/crash_dump.o CC kernel/jump_label.o CC kernel/iomem.o CC kernel/memremap.o LD kernel/built-in.o
07-04
Makefile:2: STATUS main.c Makefile:4: STATUS main.o ~/Balong5612V2/trunk/output/moses/cs_LF521430_user/modem_build/iot_ap-prefix/src/iot_ap-build/AP/MUSL/bin/musl-gcc -o app main.o /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.o: in function `websocket_callback&#39;: main.c:(.text+0x58): undefined reference to `lws_callback_on_writable&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x104): undefined reference to `lws_write&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x120): undefined reference to `_lws_log&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.o: in function `main&#39;: main.c:(.text+0x1b0): undefined reference to `lws_create_context&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x1d0): undefined reference to `_lws_log&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x1fc): undefined reference to `_lws_log&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x20c): undefined reference to `lws_service&#39; /opt/buildtools/toolchains/aarch64-none-linux-gnu-12.2.rel1/bin/../lib/gcc/aarch64-none-linux-gnu/12.2.1/../../../../aarch64-none-linux-gnu/bin/ld: main.c:(.text+0x228): undefined reference to `lws_context_destroy&#39; collect2: error: ld returned 1 exit status make: *** [Makefile:12: all] Error 1为什么会未定义
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值