Skip to content

Commit

Permalink
Implement new axmol log system based on fmtlib (#1732)
Browse files Browse the repository at this point in the history
* Implement new log macros based on fmtlib

* Fix ci

* Fix ci

* Fix android ci

* Fix warnings

* Replace more ax::log by AXLOGX

* Fix ci

* Fix linux build

* Use stack memory for log prefix

* Fix linux build

* Fix warning

* Add ILogOutput support

* Replace old log calls with new log macros

* Fixup

* Fixup

* Fixup

* Update ci msvc to 14.39

* Update Console.h [skip ci]

* Pass log level to ILogOutput
  • Loading branch information
halx99 authored Mar 7, 2024
1 parent 8bf71b1 commit 5d2c42e
Show file tree
Hide file tree
Showing 98 changed files with 715 additions and 671 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
submodules: 'recursive'
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: '14.37'
toolset: '14.39'
arch: 'x64'
- name: Build
shell: pwsh
Expand All @@ -38,7 +38,7 @@ jobs:
submodules: 'recursive'
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: '14.37'
toolset: '14.39'
arch: 'x64'
- name: Build
shell: pwsh
Expand All @@ -52,7 +52,7 @@ jobs:
submodules: 'recursive'
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: '14.37'
toolset: '14.39'
arch: 'x64'
uwp: true
- name: Build
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Build
shell: pwsh
run: .\build.ps1 -p win32 -a 'x64' -cc clang -winsdk $env:WINSDK_VER
run: .\build.ps1 -p win32 -a 'x64' -cc clang -sdk $env:WINSDK_VER
linux:
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 5 additions & 3 deletions core/2d/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/
Expand Down Expand Up @@ -101,7 +102,7 @@ bool Speed::initWithAction(ActionInterval* action, float speed)
AXASSERT(action != nullptr, "action must not be NULL");
if (action == nullptr)
{
log("Speed::initWithAction error: action is nullptr!");
AXLOGE("Speed::initWithAction error: action is nullptr!");
return false;
}

Expand All @@ -128,7 +129,8 @@ void Speed::startWithTarget(Node* target)
_innerAction->startWithTarget(target);
}
else
log("Speed::startWithTarget error: target(%p) or _innerAction(%p) is nullptr!", target, _innerAction);
AXLOGE("Speed::startWithTarget error: target({}) or _innerAction({}) is nullptr!", fmt::ptr(target),
fmt::ptr(_innerAction));
}

void Speed::stop()
Expand Down Expand Up @@ -212,7 +214,7 @@ bool Follow::initWithTargetAndOffset(Node* followedNode, float xOffset, float yO
AXASSERT(followedNode != nullptr, "FollowedNode can't be NULL");
if (followedNode == nullptr)
{
log("Follow::initWithTarget error: followedNode is nullptr!");
AXLOGE("Follow::initWithTarget error: followedNode is nullptr!");
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion core/2d/ActionEase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2008-2009 Jason Booth
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
https://axmolengine.github.io/
Expand Down Expand Up @@ -78,7 +79,7 @@ void ActionEase::startWithTarget(Node* target)
}
else
{
ax::log("ActionEase::startWithTarget error: target or _inner is nullptr!");
AXLOGE("ActionEase::startWithTarget error: target or _inner is nullptr!");
}
}

Expand Down
24 changes: 12 additions & 12 deletions core/2d/ActionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool Sequence::initWithTwoActions(FiniteTimeAction* actionOne, FiniteTimeAction*
AXASSERT(actionTwo != nullptr, "actionTwo can't be nullptr!");
if (actionOne == nullptr || actionTwo == nullptr)
{
log("Sequence::initWithTwoActions error: action is nullptr!!");
AXLOGE("Sequence::initWithTwoActions error: action is nullptr!!");
return false;
}

Expand Down Expand Up @@ -295,12 +295,12 @@ void Sequence::startWithTarget(Node* target)
{
if (target == nullptr)
{
log("Sequence::startWithTarget error: target is nullptr!");
AXLOGE("Sequence::startWithTarget error: target is nullptr!");
return;
}
if (_actions[0] == nullptr || _actions[1] == nullptr)
{
log("Sequence::startWithTarget error: _actions[0] or _actions[1] is nullptr!");
AXLOGE("Sequence::startWithTarget error: _actions[0] or _actions[1] is nullptr!");
return;
}
if (_duration > FLT_EPSILON)
Expand Down Expand Up @@ -552,7 +552,7 @@ bool RepeatForever::initWithAction(ActionInterval* action)
AXASSERT(action != nullptr, "action can't be nullptr!");
if (action == nullptr)
{
log("RepeatForever::initWithAction error:action is nullptr!");
AXLOGE("RepeatForever::initWithAction error:action is nullptr!");
return false;
}

Expand Down Expand Up @@ -697,7 +697,7 @@ bool Spawn::initWithTwoActions(FiniteTimeAction* action1, FiniteTimeAction* acti
AXASSERT(action2 != nullptr, "action2 can't be nullptr!");
if (action1 == nullptr || action2 == nullptr)
{
log("Spawn::initWithTwoActions error: action is nullptr!");
AXLOGE("Spawn::initWithTwoActions error: action is nullptr!");
return false;
}

Expand Down Expand Up @@ -750,12 +750,12 @@ void Spawn::startWithTarget(Node* target)
{
if (target == nullptr)
{
log("Spawn::startWithTarget error: target is nullptr!");
AXLOGE("Spawn::startWithTarget error: target is nullptr!");
return;
}
if (_one == nullptr || _two == nullptr)
{
log("Spawn::startWithTarget error: _one or _two is nullptr!");
AXLOGE("Spawn::startWithTarget error: _one or _two is nullptr!");
return;
}

Expand Down Expand Up @@ -1545,7 +1545,7 @@ bool JumpBy::initWithDuration(float duration, const Vec2& position, float height
AXASSERT(jumps >= 0, "Number of jumps must be >= 0");
if (jumps < 0)
{
log("JumpBy::initWithDuration error: Number of jumps must be >= 0");
AXLOGE("JumpBy::initWithDuration error: Number of jumps must be >= 0");
return false;
}

Expand Down Expand Up @@ -1626,7 +1626,7 @@ bool JumpTo::initWithDuration(float duration, const Vec2& position, float height
AXASSERT(jumps >= 0, "Number of jumps must be >= 0");
if (jumps < 0)
{
log("JumpTo::initWithDuration error:Number of jumps must be >= 0");
AXLOGE("JumpTo::initWithDuration error:Number of jumps must be >= 0");
return false;
}

Expand Down Expand Up @@ -2002,7 +2002,7 @@ bool Blink::initWithDuration(float duration, int blinks)
AXASSERT(blinks >= 0, "blinks should be >= 0");
if (blinks < 0)
{
log("Blink::initWithDuration error:blinks should be >= 0");
AXLOGE("Blink::initWithDuration error:blinks should be >= 0");
return false;
}

Expand Down Expand Up @@ -2386,7 +2386,7 @@ bool ReverseTime::initWithAction(FiniteTimeAction* action)
AXASSERT(action != _other, "action doesn't equal to _other!");
if (action == nullptr || action == _other)
{
log("ReverseTime::initWithAction error: action is null or action equal to _other");
AXLOGE("ReverseTime::initWithAction error: action is null or action equal to _other");
return false;
}

Expand Down Expand Up @@ -2475,7 +2475,7 @@ bool Animate::initWithAnimation(Animation* animation)
AXASSERT(animation != nullptr, "Animate: argument Animation must be non-nullptr");
if (animation == nullptr)
{
log("Animate::initWithAnimation: argument Animation must be non-nullptr");
AXLOGE("Animate::initWithAnimation: argument Animation must be non-nullptr");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions core/2d/AnimationCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void AnimationCache::addAnimationsWithFile(std::string_view plist)
AXASSERT(!plist.empty(), "Invalid texture file name");
if (plist.empty())
{
log("%s error:file name is empty!", __FUNCTION__);
AXLOGE("{} error:file name is empty!", __FUNCTION__);
return;
}

Expand All @@ -260,7 +260,7 @@ void AnimationCache::addAnimationsWithFile(std::string_view plist)
AXASSERT(!dict.empty(), "CCAnimationCache: File could not be found");
if (dict.empty())
{
log("AnimationCache::addAnimationsWithFile error:%s not exist!", plist.data());
AXLOGE("AnimationCache::addAnimationsWithFile error:{} not exist!", plist);
}

addAnimationsWithDictionary(dict, plist);
Expand Down
8 changes: 4 additions & 4 deletions core/2d/AutoPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,14 @@ std::vector<Vec2> AutoPolygon::reduce(const std::vector<Vec2>& points, const Rec
// if there are less than 3 points, then we have nothing
if (size < 3)
{
log("AUTOPOLYGON: cannot reduce points for %s that has less than 3 points in input, e: %f", _filename.c_str(),
AXLOGE("AUTOPOLYGON: cannot reduce points for {} that has less than 3 points in input, e: {}", _filename,
epsilon);
return std::vector<Vec2>();
}
// if there are less than 9 points (but more than 3), then we don't need to reduce it
else if (size < 9)
{
log("AUTOPOLYGON: cannot reduce points for %s e: %f", _filename.c_str(), epsilon);
AXLOGE("AUTOPOLYGON: cannot reduce points for {} e: {}", _filename, epsilon);
return points;
}
float maxEp = MIN(rect.size.width, rect.size.height);
Expand All @@ -511,7 +511,7 @@ std::vector<Vec2> AutoPolygon::expand(const std::vector<Vec2>& points, const ax:
// if there are less than 3 points, then we have nothing
if (points.size() < 3)
{
log("AUTOPOLYGON: cannot expand points for %s with less than 3 points, e: %f", _filename.c_str(), epsilon);
AXLOGE("AUTOPOLYGON: cannot expand points for {} with less than 3 points, e: {}", _filename, epsilon);
return std::vector<Vec2>();
}

Expand Down Expand Up @@ -589,7 +589,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
// if there are less than 3 points, then we can't triangulate
if (points.size() < 3)
{
log("AUTOPOLYGON: cannot triangulate %s with less than 3 points", _filename.c_str());
AXLOGE("AUTOPOLYGON: cannot triangulate {} with less than 3 points", _filename);
return TrianglesCommand::Triangles();
}

Expand Down
21 changes: 10 additions & 11 deletions core/2d/FontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma
std::string_view type = settings["type"];
if (type != "fontatlas")
{
ax::print("Load fontatlas %s fail, invalid asset type: %s", fontatlasFile.data(), type.data());
AXLOGE("Load fontatlas {} fail, invalid asset type: {}", fontatlasFile, type);
return;
}

Expand All @@ -76,8 +76,8 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma
{
if (it->second->getReferenceCount() != 1)
{
ax::print("Load fontatlas %s fail, due to exist fontatlas with same key %s and in used",
fontatlasFile.data(), atlasName.data());
AXLOGE("Load fontatlas {} fail, due to exist fontatlas with same key {} and in used", fontatlasFile,
atlasName);
return;
}
else
Expand All @@ -90,8 +90,7 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma
auto font = FontFreeType::create(sourceFont, faceSize, GlyphCollection::DYNAMIC, ""sv, true, 0.0f);
if (!font)
{
ax::print("Load fontatils %s fail due to create source font %s fail", fontatlasFile.data(),
sourceFont.data());
AXLOGE("Load fontatils {} fail due to create source font {} fail", fontatlasFile, sourceFont);
return;
}

Expand Down Expand Up @@ -121,7 +120,7 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma
}
catch (std::exception& ex)
{
ax::print("Load fontatils %s fail due to exception occured: %s", fontatlasFile.data(), ex.what());
AXLOGE("Load fontatils {} fail due to exception occured: {}", fontatlasFile, ex.what());
}
}

Expand Down Expand Up @@ -225,8 +224,8 @@ void FontAtlas::initWithSettings(void* opaque /*simdjson::ondemand::document*/)
std::string strCharCode;
for (auto field : settings["letters"].get_object())
{
strCharCode = static_cast<std::string_view>(field.unescaped_key());
auto letterInfo = field.value();
strCharCode = static_cast<std::string_view>(field.unescaped_key());
auto letterInfo = field.value();
tempDef.U = static_cast<float>(letterInfo["U"].get_double());
tempDef.V = static_cast<float>(letterInfo["V"].get_double());
tempDef.xAdvance = static_cast<float>(letterInfo["advance"].get_double());
Expand Down Expand Up @@ -362,7 +361,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
for (auto&& charCode : charCodeSet)
{
auto bitmap = _fontFreeType->getGlyphBitmap(charCode, bitmapWidth, bitmapHeight, tempRect, tempDef.xAdvance);
if (bitmap && bitmapWidth > 0 && bitmapHeight > 0)
if (bitmap && bitmapWidth > 0 && bitmapHeight > 0)
{
tempDef.validDefinition = true;
tempDef.width = tempRect.size.width + _letterPadding + _letterEdgeExtend;
Expand Down Expand Up @@ -390,8 +389,8 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
_currLineHeight = glyphHeight;
}
_fontFreeType->renderCharAt(_currentPageData, (int)_currentPageOrigX + adjustForExtend,
(int)_currentPageOrigY + adjustForExtend, bitmap, bitmapWidth, bitmapHeight,
_width, _height);
(int)_currentPageOrigY + adjustForExtend, bitmap, bitmapWidth, bitmapHeight,
_width, _height);

tempDef.U = _currentPageOrigX;
tempDef.V = _currentPageOrigY;
Expand Down
5 changes: 2 additions & 3 deletions core/2d/FontFreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool FontFreeType::loadFontFace(std::string_view fontPath, int faceSize)

FT_Done_Face(face);

ax::log("Init font '%s' failed, only unicode ttf/ttc was supported.", fontPath.data());
AXLOGW("Init font '{}' failed, only unicode ttf/ttc was supported.", fontPath);
return false;
}

Expand Down Expand Up @@ -406,8 +406,7 @@ unsigned char* FontFreeType::getGlyphBitmap(char32_t charCode,

if (charUTF8 == "\n")
charUTF8 = "\\n";
ax::log("The font face: %s doesn't contains char: <%s>", _fontFace->charmap->face->family_name,
charUTF8.c_str());
AXLOGW("The font face: {} doesn't contains char: <{}>", _fontFace->charmap->face->family_name, charUTF8);

if (_mssingGlyphCharacter != 0)
{
Expand Down
10 changes: 5 additions & 5 deletions core/audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ AUDIO_ID AudioEngine::play2d(std::string_view filePath, const AudioPlayerSetting

if (_audioIDInfoMap.size() >= _maxInstances)
{
log("Fail to play %s cause by limited max instance of AudioEngine", filePath.data());
AXLOGE("Fail to play {} cause by limited max instance of AudioEngine", filePath);
break;
}
if (profileHelper)
{
if (profileHelper->profile.maxInstances != 0 &&
profileHelper->audioIDs.size() >= profileHelper->profile.maxInstances)
{
log("Fail to play %s cause by limited max instance of AudioProfile", filePath.data());
AXLOGE("Fail to play {} cause by limited max instance of AudioProfile", filePath);
break;
}
if (profileHelper->profile.minDelay > TIME_DELAY_PRECISION)
Expand All @@ -233,7 +233,7 @@ AUDIO_ID AudioEngine::play2d(std::string_view filePath, const AudioPlayerSetting
if (profileHelper->lastPlayTime > TIME_DELAY_PRECISION &&
currTime - profileHelper->lastPlayTime <= profileHelper->profile.minDelay)
{
log("Fail to play %s cause by limited minimum delay", filePath.data());
AXLOGE("Fail to play {} cause by limited minimum delay", filePath);
break;
}
}
Expand Down Expand Up @@ -505,7 +505,7 @@ bool AudioEngine::isLoop(AUDIO_ID audioID)
return tmpIterator->second.loop;
}

log("AudioEngine::isLoop-->The audio instance %d is non-existent", audioID);
AXLOGW("AudioEngine::isLoop-->The audio instance {} is non-existent", audioID);
return false;
}

Expand All @@ -517,7 +517,7 @@ float AudioEngine::getVolume(AUDIO_ID audioID)
return tmpIterator->second.volume;
}

log("AudioEngine::getVolume-->The audio instance %d is non-existent", audioID);
AXLOGW("AudioEngine::getVolume-->The audio instance {} is non-existent", audioID);
return 0.0f;
}

Expand Down
Loading

0 comments on commit 5d2c42e

Please sign in to comment.