Skip to content
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

Fix some compiling deprecated issues #2154

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/network/Downloader-curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class DownloadTaskCURL : public IDownloadTask
}
}

curl_easy_getinfo(_curl, CURLINFO_SPEED_DOWNLOAD, &_speed);
curl_easy_getinfo(_curl, CURLINFO_SPEED_DOWNLOAD_T, &_speed);

return ret;
}
Expand All @@ -309,7 +309,7 @@ class DownloadTaskCURL : public IDownloadTask
bool _acceptRanges;
int64_t _totalBytesExpected;

double _speed;
curl_off_t _speed;
CURL* _curl;
curl_socket_t _sockfd = -1; // store the sockfd to support cancel download manually
bool _cancelled = false;
Expand Down
2 changes: 1 addition & 1 deletion core/network/Downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AX_DLL DownloadTask final
int64_t bytesReceived = 0;
int64_t totalBytesReceived = 0;
// speed
double speedInBytes = 0;
int64_t speedInBytes = 0;
} mutable progressInfo;

DownloadTask();
Expand Down
10 changes: 3 additions & 7 deletions extensions/cocostudio/src/cocostudio/TriggerObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ void TriggerObj::serialize(const rapidjson::Value& val)
continue;
}

char buf[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);

std::string custom_event_name = fmt::to_string(event);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [this](EventCustom* /*evt*/) {
if (detect())
{
Expand Down Expand Up @@ -290,9 +287,8 @@ void TriggerObj::serialize(cocostudio::CocoLoader* pCocoLoader, cocostudio::stEx
{
continue;
}
char buf[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);

std::string custom_event_name = fmt::to_string(event);

EventListenerCustom* listener =
EventListenerCustom::create(custom_event_name, [this](EventCustom* /*evt*/) {
Expand Down
10 changes: 5 additions & 5 deletions extensions/fairygui/src/fairygui/event/InputProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void InputProcessor::onMouseDown(ax::EventMouse * event)
return;

auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
Expand Down Expand Up @@ -559,7 +559,7 @@ void InputProcessor::onMouseUp(ax::EventMouse * event)
return;

auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
Expand Down Expand Up @@ -620,13 +620,13 @@ void InputProcessor::onMouseUp(ax::EventMouse * event)
void InputProcessor::onMouseMove(ax::EventMouse * event)
{
TouchInfo* ti = getTouch(0);
Vec2 npos = UIRoot->worldToRoot(Vec2(event->getCursorX(), event->getCursorY()));
auto pt = event->getLocation();
Vec2 npos = UIRoot->worldToRoot(pt);
if (std::abs(ti->pos.x - npos.x) < 1
&& std::abs(ti->pos.y - npos.y) < 1)
return;

auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
Expand Down Expand Up @@ -669,7 +669,7 @@ void InputProcessor::onMouseMove(ax::EventMouse * event)
void InputProcessor::onMouseScroll(ax::EventMouse * event)
{
auto camera = Camera::getVisitingCamera();
Vec2 pt(event->getCursorX(), event->getCursorY());
Vec2 pt = event->getLocation();
GObject* target = _owner->hitTest(pt, camera);
if (!target)
target = _owner;
Expand Down
9 changes: 5 additions & 4 deletions tests/cpp-tests/Source/Box2DTestBed/Box2DTestBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ void Box2DTestBed::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
void Box2DTestBed::onMouseDown(Event* event)
{
EventMouse* e = (EventMouse*)event;
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
switch (e->getMouseButton())
{
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = false;
button[(int)EventMouse::MouseButton::BUTTON_RIGHT] = false;
button[(int)EventMouse::MouseButton::BUTTON_MIDDLE] = false;
case EventMouse::MouseButton::BUTTON_LEFT:
button[(int)EventMouse::MouseButton::BUTTON_LEFT] = true;
break;
Expand All @@ -217,7 +217,8 @@ void Box2DTestBed::onMouseUp(Event* event)
void Box2DTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
pos = {e->getCursorX() / g_debugDraw.mRatio, e->getCursorY() / g_debugDraw.mRatio};
auto pt = e->getLocation();
pos = {pt.x / g_debugDraw.mRatio, pt.y / g_debugDraw.mRatio};

if (button[(int)EventMouse::MouseButton::BUTTON_RIGHT])
{
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Source/Box2DTestBed/tests/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Bridge : public Test
prevBody = body;
}

b2Vec2 anchor(-15.0f + 1.0f * e_count, 5.0f);
b2Vec2 anchor(-15.0f + 1.0f * static_cast<float>(e_count), 5.0f);
jd.Initialize(prevBody, ground, anchor);
m_world->CreateJoint(&jd);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/cpp-tests/Source/ChipmunkTestBed/ChipmunkTestBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ void ChipmunkTestBed::onMouseUp(Event* event)
void ChipmunkTestBed::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;

ChipmunkDemoMouse.x = e->getCursorX() - physicsDebugNodeOffset.x;
ChipmunkDemoMouse.y = e->getCursorY() - physicsDebugNodeOffset.y;
auto pt = e->getLocation();
ChipmunkDemoMouse.x = pt.x - physicsDebugNodeOffset.x;
ChipmunkDemoMouse.y = pt.y - physicsDebugNodeOffset.y;

cpBodySetPosition(mouse_body, ChipmunkDemoMouse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ void ClippingNodePerformanceTest::setup()
countLabel->setPosition(Vec2(s.width / 2, s.height - 120));
addChild(countLabel, 1);

auto addClippingNode = [=] (int count) -> void {
auto addClippingNode = [this, s, countLabel] (int count) -> void {
for (int i = 0; i < count; i++) {
Vec2 pos = Vec2(random(0, (int) s.width), random(0, (int) s.height));
auto stencil = Sprite::create("Images/stars2.png");
Expand Down
9 changes: 4 additions & 5 deletions tests/cpp-tests/Source/InputTest/MouseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ void MouseEventTest::onMouseUp(Event* event)
void MouseEventTest::onMouseMove(Event* event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "MousePosition X:";
str = str + tostr(e->getCursorX()) + " Y:" + tostr(e->getCursorY());
_labelPosition->setString(str.c_str());
auto loc = e->getLocation();
std::string str = fmt::format("MousePosition:({},{})", loc.x, loc.y);
_labelPosition->setString(str);
}

void MouseEventTest::onMouseScroll(Event* event)
{
EventMouse* e = (EventMouse*)event;
std::string str = "Mouse Scroll detected, X: ";
str = str + tostr(e->getScrollX()) + " Y: " + tostr(e->getScrollY());
std::string str = fmt::format("Mouse Scroll detected, X:{} Y:{}", e->getScrollX(), e->getScrollY());
_labelAction->setString(str.c_str());
}

Expand Down
20 changes: 10 additions & 10 deletions tests/cpp-tests/Source/LabelTest/LabelTestNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ void LabelLayoutBaseTest::initWrapOption(const ax::Size& size)
checkBox->setSelected(true);
checkBox->setName("toggleWrap");

checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->enableWrap(true);
Expand Down Expand Up @@ -2354,7 +2354,7 @@ void LabelLayoutBaseTest::initToggleLabelTypeOption(const ax::Size& size)

auto stepper = (ControlStepper*)this->getChildByName("stepper");

checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this, stepper](Object* /*sender*/, CheckBox::EventType event) {
float fontSize = stepper->getValue();

if (event == CheckBox::EventType::SELECTED)
Expand Down Expand Up @@ -2419,7 +2419,7 @@ void LabelLayoutBaseTest::initSliders(const ax::Size& size)
addChild(slider2);
auto winSize = Director::getInstance()->getVisibleSize();

slider->addEventListener([=](Object* ref, Slider::EventType event) {
slider->addEventListener([this, slider, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider->getPercent();
auto labelSize = _label->getContentSize();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, labelSize.height);
Expand All @@ -2431,7 +2431,7 @@ void LabelLayoutBaseTest::initSliders(const ax::Size& size)
this->updateDrawNodeSize(drawNodeSize);
});

slider2->addEventListener([=](Object* ref, Slider::EventType event) {
slider2->addEventListener([this, slider2, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider2->getPercent();
auto labelSize = _label->getContentSize();
auto drawNodeSize = Size(labelSize.width, percent / 100.0 * winSize.height);
Expand Down Expand Up @@ -2663,7 +2663,7 @@ LabelResizeTest::LabelResizeTest()
slider2->setVisible(false);

auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
Expand All @@ -2690,7 +2690,7 @@ LabelResizeTest::LabelResizeTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");

checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);
Expand Down Expand Up @@ -2729,7 +2729,7 @@ LabelToggleTypeTest::LabelToggleTypeTest()
slider2->setVisible(false);

auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
Expand All @@ -2756,7 +2756,7 @@ LabelToggleTypeTest::LabelToggleTypeTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");

checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);
Expand Down Expand Up @@ -2875,7 +2875,7 @@ LabelSystemFontTest::LabelSystemFontTest()
auto slider1 = (ui::Slider*)this->getChildByTag(1);

auto winSize = Director::getInstance()->getVisibleSize();
slider1->addEventListener([=](Object* ref, Slider::EventType event) {
slider1->addEventListener([this, slider1, winSize](Object* /*sender*/, Slider::EventType event) {
float percent = slider1->getPercent();
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
if (drawNodeSize.height <= 0)
Expand All @@ -2899,7 +2899,7 @@ LabelSystemFontTest::LabelSystemFontTest()
checkBox->setSelected(false);
checkBox->setName("LineBreak");

checkBox->addEventListener([=](Object* ref, CheckBox::EventType event) {
checkBox->addEventListener([this](Object* /*sender*/, CheckBox::EventType event) {
if (event == CheckBox::EventType::SELECTED)
{
_label->setLineBreakWithoutSpace(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void Issue12226::onEnter()

const uint32_t length = (radius * 0.95);

std::function<void(float)> updateMotionStreak = [=](float dt) {
std::function<void(float)> updateMotionStreak = [outer, length, this](float dt) {
Vec2 position =
Vec2(outer->getPositionX() + length * cosf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)),
outer->getPositionY() + length * sinf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)));
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp-tests/Source/NavMeshTest/NavMeshTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ bool NavMeshBasicTestDemo::init()
TTFConfig ttfConfig("fonts/arial.ttf", 15);
_debugLabel = Label::createWithTTF(ttfConfig, "Debug Draw ON");
_debugLabel->retain();
auto menuItem1 = MenuItemLabel::create(_debugLabel, [=](Object*) {
auto menuItem1 = MenuItemLabel::create(_debugLabel, [this](Object*) {
bool enabledDebug = !getNavMesh()->isDebugDrawEnabled();
getNavMesh()->setDebugDrawEnable(enabledDebug);
if (enabledDebug)
Expand Down Expand Up @@ -355,7 +355,7 @@ bool NavMeshAdvanceTestDemo::init()
_debugLabel = Label::createWithTTF(ttfConfig, "Debug Draw ON");
_debugLabel->retain();

auto menuItem0 = MenuItemLabel::create(_obstacleLabel, [=](Object*) {
auto menuItem0 = MenuItemLabel::create(_obstacleLabel, [this](Object*) {
float x = ax::random(-50.0f, 50.0f);
float z = ax::random(-50.0f, 50.0f);
Physics3DWorld::HitResult result;
Expand All @@ -365,7 +365,7 @@ bool NavMeshAdvanceTestDemo::init()
menuItem0->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
menuItem0->setPosition(Vec2(VisibleRect::left().x, VisibleRect::top().y - 50));

auto menuItem1 = MenuItemLabel::create(_agentLabel, [=](Object*) {
auto menuItem1 = MenuItemLabel::create(_agentLabel, [this](Object*) {
float x = ax::random(-50.0f, 50.0f);
float z = ax::random(-50.0f, 50.0f);
Physics3DWorld::HitResult result;
Expand All @@ -375,7 +375,7 @@ bool NavMeshAdvanceTestDemo::init()
menuItem1->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
menuItem1->setPosition(Vec2(VisibleRect::left().x, VisibleRect::top().y - 100));

auto menuItem2 = MenuItemLabel::create(_debugLabel, [=](Object*) {
auto menuItem2 = MenuItemLabel::create(_debugLabel, [this](Object*) {
bool enabledDebug = !getNavMesh()->isDebugDrawEnabled();
getNavMesh()->setDebugDrawEnable(enabledDebug);
if (enabledDebug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ bool AudioWavTest::init()
_stateLabel->setPosition(layerSize.width / 2, layerSize.height * 0.7f);
addChild(_stateLabel);

auto playPrev = TextButton::create("Play Prev", [=](TextButton* button) {
auto playPrev = TextButton::create("Play Prev", [this](TextButton* button) {
if (_curIndex > 0)
{
AudioEngine::stop(_audioID);
Expand All @@ -490,7 +490,7 @@ bool AudioWavTest::init()
playPrev->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
addChild(playPrev);

auto playNext = TextButton::create("Play Next", [=](TextButton* button) {
auto playNext = TextButton::create("Play Next", [this](TextButton* button) {
if (_curIndex != -1 && _curIndex < (_wavFiles.size() - 1))
{
AudioEngine::stop(_audioID);
Expand Down Expand Up @@ -736,7 +736,7 @@ bool AudioIssue18597Test::init()

// test case for https://github.com/cocos2d/cocos2d-x/issues/18597
this->schedule(
[=](float dt) {
[this](float dt) {
AXLOGD("issues 18597 audio crash test");
for (int i = 0; i < 2; ++i)
{
Expand All @@ -754,7 +754,7 @@ bool AudioIssue18597Test::init()
this->addChild(labelTime);
// update label quickly
this->schedule(
[=](float dt) {
[this](float dt) {
_time += dt;
char timeString[20] = {0};
sprintf(timeString, "Time %2.2f", _time);
Expand Down
Loading