From b63f8154881c14680e483b903002dfcc7840b058 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 27 Dec 2021 13:52:08 +0800 Subject: [PATCH] Modify some extensions for string_view --- cocos/2d/CCFontAtlasCache.cpp | 3 +- cocos/base/CCMap.h | 7 ++ cocos/base/hlookup.h | 4 +- cocos/platform/CCFileUtils.cpp | 2 +- cocos/platform/win32/CCFileUtils-win32.cpp | 12 +--- .../DragonBones/animation/Animation.cpp | 2 +- extensions/DragonBones/animation/Animation.h | 6 +- .../DragonBones/animation/AnimationState.cpp | 12 ++-- .../DragonBones/animation/AnimationState.h | 2 +- extensions/DragonBones/core/DragonBones.h | 11 +-- .../DragonBones/factory/BaseFactory.cpp | 4 +- extensions/DragonBones/factory/BaseFactory.h | 10 +-- .../DragonBones/model/AnimationConfig.cpp | 6 +- extensions/DragonBones/model/AnimationData.h | 10 +-- extensions/DragonBones/model/ArmatureData.h | 16 ++--- .../DragonBones/model/DragonBonesData.h | 6 +- extensions/DragonBones/model/SkinData.h | 2 +- .../DragonBones/model/TextureAtlasData.h | 11 +-- extensions/DragonBones/parser/DataParser.cpp | 12 ++-- .../DragonBones/parser/JSONDataParser.h | 12 ++-- .../ActionTimeline/CCActionTimeline.h | 4 +- .../ActionTimeline/CCActionTimelineCache.cpp | 15 ++-- .../ActionTimeline/CCActionTimelineCache.h | 4 +- .../cocostudio/ActionTimeline/CCBoneNode.cpp | 18 ++--- .../ActionTimeline/CCSkeletonNode.cpp | 8 +-- .../ActionTimeline/CCSkeletonNode.h | 10 +-- .../cocostudio/ActionTimeline/CSLoader.cpp | 72 ++++++++++--------- .../cocostudio/ActionTimeline/CSLoader.h | 6 +- extensions/cocostudio/CCActionNode.cpp | 4 +- extensions/cocostudio/CCActionObject.cpp | 4 +- extensions/cocostudio/CCArmature.cpp | 2 +- extensions/cocostudio/CCArmature.h | 4 +- extensions/cocostudio/CCArmatureAnimation.cpp | 4 +- extensions/cocostudio/CCArmatureAnimation.h | 4 +- .../cocostudio/CCArmatureDataManager.cpp | 14 ++-- extensions/cocostudio/CCArmatureDataManager.h | 14 ++-- extensions/cocostudio/CCComAttribute.cpp | 18 ++--- extensions/cocostudio/CCDataReaderHelper.cpp | 31 ++++---- extensions/cocostudio/CCDatas.cpp | 8 ++- extensions/cocostudio/CCDatas.h | 6 +- extensions/cocostudio/CCDisplayManager.cpp | 2 +- extensions/cocostudio/CCSGUIReader.cpp | 12 ++-- extensions/cocostudio/CCSGUIReader.h | 6 +- extensions/cocostudio/CCSSceneReader.cpp | 2 +- extensions/cocostudio/CCSkin.cpp | 2 +- .../cocostudio/CCSpriteFrameCacheHelper.h | 2 +- extensions/cocostudio/CocosStudioExport.h | 2 + .../cocostudio/FlatBuffersSerialize.cpp | 6 +- .../cocostudio/SpineSkeletonDataCache.h | 4 +- .../WidgetCallBackHandlerProtocol.cpp | 6 +- .../ArmatureNodeReader/ArmatureNodeReader.cpp | 2 +- .../WidgetReader/NodeReaderProtocol.cpp | 2 +- .../WidgetReader/NodeReaderProtocol.h | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 4 +- .../TextBMFontReader/TextBMFontReader.cpp | 4 +- .../TextFieldReader/TextFieldReader.cpp | 6 +- .../WidgetReader/TextReader/TextReader.cpp | 8 +-- .../cocostudio/WidgetReader/WidgetReader.cpp | 23 +++--- .../cocostudio/WidgetReader/WidgetReader.h | 6 +- .../Classes/HelloWorldScene.cpp | 2 +- 60 files changed, 255 insertions(+), 248 deletions(-) diff --git a/cocos/2d/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp index 60a359c334..4ab9771720 100644 --- a/cocos/2d/CCFontAtlasCache.cpp +++ b/cocos/2d/CCFontAtlasCache.cpp @@ -80,8 +80,7 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config) auto tempAtlas = font->newFontAtlas(); if (tempAtlas) { - _atlasMap[atlasName] = tempAtlas; - return _atlasMap[atlasName]; + return _atlasMap.emplace(atlasName, tempAtlas).first->second; } } } diff --git a/cocos/base/CCMap.h b/cocos/base/CCMap.h index 0fd8b66f9f..9555a28bf2 100644 --- a/cocos/base/CCMap.h +++ b/cocos/base/CCMap.h @@ -291,6 +291,13 @@ public: return _data.erase(position); } + iterator erase(iterator position) + { + CCASSERT(position != _data.cend(), "Invalid iterator!"); + position->second->release(); + return _data.erase(position); + } + /** * Removes an element with an iterator from the Map container. * diff --git a/cocos/base/hlookup.h b/cocos/base/hlookup.h index 4a855cccff..f271224def 100644 --- a/cocos/base/hlookup.h +++ b/cocos/base/hlookup.h @@ -22,7 +22,7 @@ struct string_hash size_t operator()(const char* str) const { return hash_type{}(str); } size_t operator()(std::string_view str) const { return hash_type{}(str); } - size_t operator()(std::string const& str) const { return hash_type{}(str); } + size_t operator()(const std::string& str) const { return hash_type{}(str); } }; struct equal_to @@ -51,7 +51,7 @@ inline auto set_item(_Cont& cont, std::string_view key, _Valty&& _Val) { typename _Cont::iterator it = cont.find(key); if (it != cont.end()) - it.value() = std::move(_Val); + it->second = std::move(_Val); else it = cont.emplace(std::string{key}, std::forward<_Valty>(_Val)).first; return it; diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 588465d382..b86ec0fc8b 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -638,7 +638,7 @@ std::string FileUtils::getPathForFilename(std::string_view filename, std::string_view searchPath) const { auto file = filename; - std::string file_path = ""; + std::string_view file_path = hlookup::empty_sv; size_t pos = filename.find_last_of('/'); if (pos != std::string::npos) { diff --git a/cocos/platform/win32/CCFileUtils-win32.cpp b/cocos/platform/win32/CCFileUtils-win32.cpp index acc434b155..809a918852 100644 --- a/cocos/platform/win32/CCFileUtils-win32.cpp +++ b/cocos/platform/win32/CCFileUtils-win32.cpp @@ -84,17 +84,9 @@ static void _checkWorkingPath() WCHAR utf16Path[CC_MAX_PATH] = {0}; int nNum = GetCurrentDirectoryW(CC_MAX_PATH - 2, utf16Path); + s_workingPath.reserve(nNum + 1); s_workingPath.assign(utf16Path, nNum); - - //char utf8WorkingDir[CC_MAX_PATH] = {0}; - //nNum = - // WideCharToMultiByte(CP_UTF8, 0, utf16Path, nNum, utf8WorkingDir, sizeof(utf8WorkingDir), nullptr, nullptr); - //if (nNum < (CC_MAX_PATH - 2)) - //{ - // utf8WorkingDir[nNum] = '\\'; - // utf8WorkingDir[nNum + 1] = '\0'; - // s_workingPath = convertPathFormatToUnixStyle(utf8WorkingDir); - //} + s_workingPath.push_back('\\'); } } diff --git a/extensions/DragonBones/animation/Animation.cpp b/extensions/DragonBones/animation/Animation.cpp index 77ae02d80c..20dd91bafd 100644 --- a/extensions/DragonBones/animation/Animation.cpp +++ b/extensions/DragonBones/animation/Animation.cpp @@ -581,7 +581,7 @@ std::string_view Animation::getLastAnimationName() const return DEFAULT_NAME; } -void Animation::setAnimations(const std::map& value) +void Animation::setAnimations(const hlookup::string_map& value) { if (_animations == value) { diff --git a/extensions/DragonBones/animation/Animation.h b/extensions/DragonBones/animation/Animation.h index e5e2d74fa9..9faa7b2aeb 100644 --- a/extensions/DragonBones/animation/Animation.h +++ b/extensions/DragonBones/animation/Animation.h @@ -64,7 +64,7 @@ private: float _inheritTimeScale; std::vector _animationNames; std::vector _animationStates; - std::map _animations; + hlookup::string_map _animations; Armature* _armature; AnimationConfig* _animationConfig; AnimationState* _lastAnimationState; @@ -441,8 +441,8 @@ public: * @version DragonBones 4.5 * @language zh_CN */ - inline const std::map& getAnimations() const { return _animations; } - void setAnimations(const std::map& value); + inline const hlookup::string_map& getAnimations() const { return _animations; } + void setAnimations(const hlookup::string_map& value); /** * - An AnimationConfig instance that can be used quickly. * @see dragonBones.AnimationConfig diff --git a/extensions/DragonBones/animation/AnimationState.cpp b/extensions/DragonBones/animation/AnimationState.cpp index 2e9503f9a6..0540ce842f 100644 --- a/extensions/DragonBones/animation/AnimationState.cpp +++ b/extensions/DragonBones/animation/AnimationState.cpp @@ -83,7 +83,7 @@ void AnimationState::_onClear() void AnimationState::_updateTimelines() { { // Update constraint timelines. - std::map> constraintTimelines; + hlookup::string_map> constraintTimelines; for (const auto timeline : _constraintTimelines) // Create constraint timelines map. { constraintTimelines[timeline->constraint->getName()].push_back(timeline); @@ -137,7 +137,7 @@ void AnimationState::_updateTimelines() void AnimationState::_updateBoneAndSlotTimelines() { { // Update bone timelines. - std::map> boneTimelines; + hlookup::string_map> boneTimelines; for (const auto timeline : _boneTimelines) // Create bone timelines map. { boneTimelines[timeline->bone->getName()].push_back(timeline); @@ -238,7 +238,7 @@ void AnimationState::_updateBoneAndSlotTimelines() } { // Update slot timelines. - std::map> slotTimelines; + hlookup::string_map> slotTimelines; std::vector ffdFlags; for (const auto timeline : _slotTimelines) // Create slot timelines map. { @@ -760,7 +760,7 @@ void AnimationState::addBoneMask(std::string_view boneName, bool recursive) if (std::find(_boneMask.cbegin(), _boneMask.cend(), boneName) == _boneMask.cend()) { - _boneMask.push_back(boneName); + _boneMask.push_back(std::string{boneName}); } if (recursive) // Add recursive mixing. @@ -770,7 +770,7 @@ void AnimationState::addBoneMask(std::string_view boneName, bool recursive) if (std::find(_boneMask.cbegin(), _boneMask.cend(), bone->getName()) == _boneMask.cend() && currentBone->contains(bone)) { - _boneMask.push_back(bone->getName()); + _boneMask.push_back(std::string{bone->getName()}); } } } @@ -816,7 +816,7 @@ void AnimationState::removeBoneMask(std::string_view boneName, bool recursive) if (!currentBone->contains(bone)) { - _boneMask.push_back(bone->getName()); + _boneMask.push_back(std::string{bone->getName()}); } } } diff --git a/extensions/DragonBones/animation/AnimationState.h b/extensions/DragonBones/animation/AnimationState.h index 8536ad2577..faf9d3ab17 100644 --- a/extensions/DragonBones/animation/AnimationState.h +++ b/extensions/DragonBones/animation/AnimationState.h @@ -251,7 +251,7 @@ private: std::vector _slotTimelines; std::vector _constraintTimelines; std::vector> _poseTimelines; - std::map _bonePoses; + hlookup::string_map _bonePoses; Armature* _armature; ZOrderTimelineState* _zOrderTimeline; diff --git a/extensions/DragonBones/core/DragonBones.h b/extensions/DragonBones/core/DragonBones.h index 68d8d4abc6..336357fecf 100644 --- a/extensions/DragonBones/core/DragonBones.h +++ b/extensions/DragonBones/core/DragonBones.h @@ -1,4 +1,4 @@ -/** +/** * The MIT License (MIT) * * Copyright (c) 2012-2018 DragonBones team and other contributors @@ -33,6 +33,7 @@ #include #include #include +#include "base/hlookup.h" // dragonBones assert #define DRAGONBONES_ASSERT(cond, msg) \ do \ @@ -359,15 +360,15 @@ inline int indexOf(const std::vector& vector, const T& value) return -1; } -template -inline T* mapFind(const std::map& map, std::string_view key) +template +inline auto mapFind(Cont& map, std::string_view key) { auto iterator = map.find(key); return (iterator != map.end()) ? iterator->second : nullptr; } -template -inline T* mapFindB(std::map& map, std::string_view key) +template +inline auto mapFindB(Cont& map, std::string_view key) { auto iterator = map.find(key); return (iterator != map.end()) ? &iterator->second : nullptr; diff --git a/extensions/DragonBones/factory/BaseFactory.cpp b/extensions/DragonBones/factory/BaseFactory.cpp index a3f5f623ca..65c068596c 100644 --- a/extensions/DragonBones/factory/BaseFactory.cpp +++ b/extensions/DragonBones/factory/BaseFactory.cpp @@ -47,7 +47,7 @@ bool BaseFactory::_fillBuildArmaturePackage(BuildArmaturePackage& dataPackage, std::string_view skinName, std::string_view textureAtlasName) const { - std::string mapName = dragonBonesName; + auto mapName = dragonBonesName; DragonBonesData* dragonBonesData = nullptr; ArmatureData* armatureData = nullptr; @@ -141,7 +141,7 @@ void BaseFactory::_buildSlots(const BuildArmaturePackage& dataPackage, Armature* return; } - std::map*> skinSlots; + hlookup::string_map*> skinSlots; for (auto& pair : defaultSkin->displays) { auto& displays = pair.second; diff --git a/extensions/DragonBones/factory/BaseFactory.h b/extensions/DragonBones/factory/BaseFactory.h index 9142a316e2..61766b3fa4 100644 --- a/extensions/DragonBones/factory/BaseFactory.h +++ b/extensions/DragonBones/factory/BaseFactory.h @@ -1,4 +1,4 @@ -/** +/** * The MIT License (MIT) * * Copyright (c) 2012-2018 DragonBones team and other contributors @@ -68,8 +68,8 @@ public: bool autoSearch; protected: - std::map _dragonBonesDataMap; - std::map> _textureAtlasDataMap; + hlookup::string_map _dragonBonesDataMap; + hlookup::string_map> _textureAtlasDataMap; DragonBones* _dragonBones; DataParser* _dataParser; @@ -550,14 +550,14 @@ public: /** * @private */ - inline const std::map>& getAllTextureAtlasData() const + inline const hlookup::string_map>& getAllTextureAtlasData() const { return _textureAtlasDataMap; } /** * @private */ - inline const std::map& getAllDragonBonesData() const { return _dragonBonesDataMap; } + inline const hlookup::string_map& getAllDragonBonesData() const { return _dragonBonesDataMap; } /** * - An Worldclock instance updated by engine. * @version DragonBones 5.7 diff --git a/extensions/DragonBones/model/AnimationConfig.cpp b/extensions/DragonBones/model/AnimationConfig.cpp index 6e012bc6be..8ee7dac7d6 100644 --- a/extensions/DragonBones/model/AnimationConfig.cpp +++ b/extensions/DragonBones/model/AnimationConfig.cpp @@ -78,7 +78,7 @@ void AnimationConfig::addBoneMask(Armature* armature, std::string_view boneName, if (std::find(boneMask.cbegin(), boneMask.cend(), boneName) == boneMask.cend()) // Add mixing { - boneMask.push_back(boneName); + boneMask.push_back(std::string{boneName}); } if (recursive) // Add recursive mixing. @@ -88,7 +88,7 @@ void AnimationConfig::addBoneMask(Armature* armature, std::string_view boneName, if (std::find(boneMask.cbegin(), boneMask.cend(), bone->getName()) == boneMask.cend() && currentBone->contains(bone)) { - boneMask.push_back(bone->getName()); + boneMask.push_back(std::string{bone->getName()}); } } } @@ -131,7 +131,7 @@ void AnimationConfig::removeBoneMask(Armature* armature, std::string_view boneNa if (!currentBone->contains(bone)) { - boneMask.push_back(bone->getName()); + boneMask.push_back(std::string{bone->getName()}); } } } diff --git a/extensions/DragonBones/model/AnimationData.h b/extensions/DragonBones/model/AnimationData.h index 9a4879c068..64e7be54df 100644 --- a/extensions/DragonBones/model/AnimationData.h +++ b/extensions/DragonBones/model/AnimationData.h @@ -126,23 +126,23 @@ public: /** * @private */ - std::map> boneTimelines; + hlookup::string_map> boneTimelines; /** * @private */ - std::map> slotTimelines; + hlookup::string_map> slotTimelines; /** * @private */ - std::map> constraintTimelines; + hlookup::string_map> constraintTimelines; /** * @private */ - std::map> boneCachedFrameIndices; + hlookup::string_map> boneCachedFrameIndices; /** * @private */ - std::map> slotCachedFrameIndices; + hlookup::string_map> slotCachedFrameIndices; /** * @private */ diff --git a/extensions/DragonBones/model/ArmatureData.h b/extensions/DragonBones/model/ArmatureData.h index d8f24547d0..83210f4401 100644 --- a/extensions/DragonBones/model/ArmatureData.h +++ b/extensions/DragonBones/model/ArmatureData.h @@ -113,23 +113,23 @@ public: /** * @private */ - std::map bones; + hlookup::string_map bones; /** * @private */ - std::map slots; + hlookup::string_map slots; /** * @private */ - std::map constraints; + hlookup::string_map constraints; /** * @private */ - std::map skins; + hlookup::string_map skins; /** * @private */ - std::map animations; + hlookup::string_map animations; /** * - The default skin data. * @version DragonBones 4.5 @@ -223,7 +223,7 @@ public: * @version DragonBones 3.0 * @language zh_CN */ - inline BoneData* getBone(std::string_view boneName) const { return mapFind(bones, boneName); } + inline BoneData* getBone(std::string_view boneName) const { return mapFind(bones, boneName); } /** * - Get a specific slot data. * @param slotName - The slot name. @@ -236,13 +236,13 @@ public: * @version DragonBones 3.0 * @language zh_CN */ - inline SlotData* getSlot(std::string_view slotName) const { return mapFind(slots, slotName); } + inline SlotData* getSlot(std::string_view slotName) const { return mapFind(slots, slotName); } /** * @private */ inline ConstraintData* getConstraint(std::string_view constraintName) const { - return mapFind(constraints, constraintName); + return mapFind(constraints, constraintName); } /** * - Get a specific skin data. diff --git a/extensions/DragonBones/model/DragonBonesData.h b/extensions/DragonBones/model/DragonBonesData.h index 982f75c66d..5b20114fd9 100644 --- a/extensions/DragonBones/model/DragonBonesData.h +++ b/extensions/DragonBones/model/DragonBonesData.h @@ -1,4 +1,4 @@ -/** +/** * The MIT License (MIT) * * Copyright (c) 2012-2018 DragonBones team and other contributors @@ -107,7 +107,7 @@ public: /** * @private */ - std::map armatures; + hlookup::string_map armatures; /** * @internal */ @@ -160,7 +160,7 @@ public: */ inline ArmatureData* getArmature(std::string_view armatureName) const { - return mapFind(armatures, armatureName); + return mapFind(armatures, armatureName); } protected: diff --git a/extensions/DragonBones/model/SkinData.h b/extensions/DragonBones/model/SkinData.h index 7228dfd8fd..89e7abfc99 100644 --- a/extensions/DragonBones/model/SkinData.h +++ b/extensions/DragonBones/model/SkinData.h @@ -80,7 +80,7 @@ public: std::vector* getDisplays(std::string_view slotName) { return mapFindB(displays, slotName); } public: // For WebAssembly. TODO parent - const std::map>& getSlotDisplays() const { return displays; } + const hlookup::string_map>& getSlotDisplays() const { return displays; } }; DRAGONBONES_NAMESPACE_END diff --git a/extensions/DragonBones/model/TextureAtlasData.h b/extensions/DragonBones/model/TextureAtlasData.h index b10d5eeaf6..ae98fe39a7 100644 --- a/extensions/DragonBones/model/TextureAtlasData.h +++ b/extensions/DragonBones/model/TextureAtlasData.h @@ -1,4 +1,4 @@ -/** +/** * The MIT License (MIT) * * Copyright (c) 2012-2018 DragonBones team and other contributors @@ -84,7 +84,7 @@ public: /** * @private */ - std::map textures; + hlookup::string_map textures; /** * @private */ @@ -100,13 +100,16 @@ public: /** * @private */ - inline TextureData* getTexture(std::string_view textureName) const { return mapFind(textures, textureName); } + inline TextureData* getTexture(std::string_view textureName) const + { + return mapFind(textures, textureName); + } protected: virtual void _onClear() override; public: // For WebAssembly. - const std::map& getTextures() const { return textures; } + const hlookup::string_map& getTextures() const { return textures; } }; /** * @internal diff --git a/extensions/DragonBones/parser/DataParser.cpp b/extensions/DragonBones/parser/DataParser.cpp index 699628894e..3d0207d8d9 100644 --- a/extensions/DragonBones/parser/DataParser.cpp +++ b/extensions/DragonBones/parser/DataParser.cpp @@ -127,7 +127,7 @@ const char* DataParser::DEFAULT_NAME = "default"; TextureFormat DataParser::_getTextureFormat(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "rgba8888") @@ -160,7 +160,7 @@ TextureFormat DataParser::_getTextureFormat(std::string_view value) ArmatureType DataParser::_getArmatureType(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "armature") @@ -181,7 +181,7 @@ ArmatureType DataParser::_getArmatureType(std::string_view value) DisplayType DataParser::_getDisplayType(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "image") @@ -206,7 +206,7 @@ DisplayType DataParser::_getDisplayType(std::string_view value) BoundingBoxType DataParser::_getBoundingBoxType(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "rectangle") @@ -227,7 +227,7 @@ BoundingBoxType DataParser::_getBoundingBoxType(std::string_view value) ActionType DataParser::_getActionType(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "play") @@ -248,7 +248,7 @@ ActionType DataParser::_getActionType(std::string_view value) BlendMode DataParser::_getBlendMode(std::string_view value) { - auto lower = value; + std::string lower{value}; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); if (lower == "normal") diff --git a/extensions/DragonBones/parser/JSONDataParser.h b/extensions/DragonBones/parser/JSONDataParser.h index a80b510c37..21a437dac3 100644 --- a/extensions/DragonBones/parser/JSONDataParser.h +++ b/extensions/DragonBones/parser/JSONDataParser.h @@ -93,7 +93,7 @@ protected: return dragonBones::to_string(rawData[key].GetDouble()); } - return defaultValue; + return std::string{defaultValue}; } inline static int _getParameter(const rapidjson::Value& rawData, std::size_t index, int defaultValue) @@ -125,7 +125,7 @@ protected: return rawData[(int)index].GetString(); } - return defaultValue; + return std::string{defaultValue}; } protected: @@ -160,10 +160,10 @@ private: std::vector _cacheRawMeshes; std::vector _cacheMeshes; std::vector _actionFrames; - std::map _weightSlotPose; - std::map _weightBonePoses; - std::map> _cacheBones; - std::map> _slotChildActions; + hlookup::string_map _weightSlotPose; + hlookup::string_map _weightBonePoses; + hlookup::string_map> _cacheBones; + hlookup::string_map> _slotChildActions; public: JSONDataParser() diff --git a/extensions/cocostudio/ActionTimeline/CCActionTimeline.h b/extensions/cocostudio/ActionTimeline/CCActionTimeline.h index 5e9e1053c6..0d57dea4a1 100644 --- a/extensions/cocostudio/ActionTimeline/CCActionTimeline.h +++ b/extensions/cocostudio/ActionTimeline/CCActionTimeline.h @@ -224,8 +224,8 @@ protected: std::function _frameEventListener; std::function _lastFrameListener; - std::map>> _frameEndCallFuncs; - std::map _animationInfos; + std::map>> _frameEndCallFuncs; + hlookup::string_map _animationInfos; }; NS_TIMELINE_END diff --git a/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index 946ad6b2e3..40b966a829 100644 --- a/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -136,9 +136,9 @@ void ActionTimelineCache::removeAction(std::string_view fileName) ActionTimeline* ActionTimelineCache::createAction(std::string_view filename) { - std::string path = filename; - size_t pos = path.find_last_of('.'); - std::string suffix = path.substr(pos + 1, path.length()); + auto path = filename; + size_t pos = path.find_last_of('.'); + auto suffix = path.substr(pos + 1, path.length()); ActionTimelineCache* cache = ActionTimelineCache::getInstance(); @@ -183,8 +183,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFile(std::string_vie return loadAnimationActionWithContent(fileName, contentStr); } -ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_view fileName, - std::string_view content) +ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_view fileName, std::string_view content) { // if already exists an action with filename, then return this action ActionTimeline* action = _animationActions.at(fileName); @@ -192,7 +191,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_ return action; rapidjson::Document doc; - doc.Parse<0>(content.c_str()); + doc.Parse<0>(content.data(), content.length()); if (doc.HasParseError()) { CCLOG("GetParseError %d\n", doc.GetParseError()); @@ -442,7 +441,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(std: if (action) return action; - std::string path = fileName; + auto path = fileName; std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); @@ -462,7 +461,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d:: if (action) return action; - std::string path = fileName; + auto path = fileName; std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); diff --git a/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.h b/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.h index eb74ea3d58..ff3ecc26a0 100644 --- a/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.h +++ b/extensions/cocostudio/ActionTimeline/CCActionTimelineCache.h @@ -128,8 +128,8 @@ protected: typedef std::function FrameCreateFunc; typedef std::pair Pair; - std::unordered_map _funcs; - cocos2d::Map _animationActions; + hlookup::string_map _funcs; + cocos2d::StringMap _animationActions; }; NS_TIMELINE_END diff --git a/extensions/cocostudio/ActionTimeline/CCBoneNode.cpp b/extensions/cocostudio/ActionTimeline/CCBoneNode.cpp index 11b6ed2d4d..b812c36371 100644 --- a/extensions/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/extensions/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -75,20 +75,20 @@ bool BoneNode::init() setProgramState(new cocos2d::backend::ProgramState(program), false); pipelineDescriptor.programState = _programState; - _mvpLocation = _programState->getUniformLocation("u_MVPMatrix"); + _mvpLocation = _programState->getUniformLocation("u_MVPMatrix"sv); auto vertexLayout = _programState->getVertexLayout(); const auto& attributeInfo = _programState->getProgram()->getActiveAttributes(); - auto iter = attributeInfo.find("a_position"); + auto iter = attributeInfo.find("a_position"sv); if (iter != attributeInfo.end()) { - vertexLayout->setAttribute("a_position", iter->second.location, cocos2d::backend::VertexFormat::FLOAT3, 0, + vertexLayout->setAttribute("a_position"sv, iter->second.location, cocos2d::backend::VertexFormat::FLOAT3, 0, false); } - iter = attributeInfo.find("a_color"); + iter = attributeInfo.find("a_color"sv); if (iter != attributeInfo.end()) { - vertexLayout->setAttribute("a_color", iter->second.location, cocos2d::backend::VertexFormat::FLOAT4, + vertexLayout->setAttribute("a_color"sv, iter->second.location, cocos2d::backend::VertexFormat::FLOAT4, 3 * sizeof(float), false); } vertexLayout->setLayout(7 * sizeof(float)); @@ -152,7 +152,7 @@ void BoneNode::removeFromBoneList(BoneNode* bone) { auto subBones = bone->getAllSubBones(); subBones.pushBack(bone); - for (auto& subBone : subBones) + for (auto subBone : subBones) { if (subBone->_rootSkeleton == nullptr) continue; @@ -186,7 +186,7 @@ void BoneNode::addToBoneList(BoneNode* bone) { auto subBones = bone->getAllSubBones(); subBones.pushBack(bone); - for (auto& subBone : subBones) + for (auto subBone : subBones) { subBone->_rootSkeleton = _rootSkeleton; auto bonename = subBone->getName(); @@ -198,8 +198,8 @@ void BoneNode::addToBoneList(BoneNode* bone) _rootSkeleton->_subBonesOrderDirty = true; } else - CCLOG("already has a bone named %s in skeleton %s", bonename.c_str(), - _rootSkeleton->getName().c_str()); + CCLOG("already has a bone named %s in skeleton %s", bonename.data(), + _rootSkeleton->getName().data()); } } else diff --git a/extensions/cocostudio/ActionTimeline/CCSkeletonNode.cpp b/extensions/cocostudio/ActionTimeline/CCSkeletonNode.cpp index c2f8dbc7a1..d0a0749415 100644 --- a/extensions/cocostudio/ActionTimeline/CCSkeletonNode.cpp +++ b/extensions/cocostudio/ActionTimeline/CCSkeletonNode.cpp @@ -298,7 +298,7 @@ void SkeletonNode::batchDrawAllSubBones() #endif // CC_STUDIO_ENABLED_VIEW } -void SkeletonNode::changeSkins(const std::map& boneSkinNameMap) +void SkeletonNode::changeSkins(const hlookup::string_map& boneSkinNameMap) { for (auto& boneskin : boneSkinNameMap) { @@ -327,14 +327,14 @@ BoneNode* SkeletonNode::getBoneNode(std::string_view boneName) return nullptr; } -const cocos2d::Map& SkeletonNode::getAllSubBonesMap() const +const cocos2d::StringMap& SkeletonNode::getAllSubBonesMap() const { return _subBonesMap; } -void SkeletonNode::addSkinGroup(std::string groupName, std::map boneSkinNameMap) +void SkeletonNode::addSkinGroup(std::string groupName, hlookup::string_map boneSkinNameMap) { - _skinGroupMap.emplace(groupName, boneSkinNameMap); + _skinGroupMap.emplace(groupName, std::move(boneSkinNameMap)); } void SkeletonNode::checkSubBonesDirty() diff --git a/extensions/cocostudio/ActionTimeline/CCSkeletonNode.h b/extensions/cocostudio/ActionTimeline/CCSkeletonNode.h index 05d65bf973..e511c802b8 100644 --- a/extensions/cocostudio/ActionTimeline/CCSkeletonNode.h +++ b/extensions/cocostudio/ActionTimeline/CCSkeletonNode.h @@ -49,13 +49,13 @@ public: /** *get All bones in this skeleton, */ - const cocos2d::Map& getAllSubBonesMap() const; + const cocos2d::StringMap& getAllSubBonesMap() const; /** *@brief: change displays *@param: boneSkinNameMap, map */ - void changeSkins(const std::map& boneSkinNameMap); + void changeSkins(const hlookup::string_map& boneSkinNameMap); /** *@brief: change displays @@ -68,7 +68,7 @@ public: *@param: groupName, key *@param: boneSkinNameMap, map */ - void addSkinGroup(std::string groupName, std::map boneSkinNameMap); + void addSkinGroup(std::string groupName, hlookup::string_map boneSkinNameMap); cocos2d::Rect getBoundingBox() const override; @@ -86,7 +86,7 @@ protected: virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override; protected: - cocos2d::Map _subBonesMap; + cocos2d::StringMap _subBonesMap; private: struct VertexData @@ -98,7 +98,7 @@ private: cocos2d::Vec2 _squareVertices[8]; VertexData _vertexData[8]; - std::map> + hlookup::string_map > _skinGroupMap; // map< suit name, map< bone name, skin name> > CC_DISALLOW_COPY_AND_ASSIGN(SkeletonNode); diff --git a/extensions/cocostudio/ActionTimeline/CSLoader.cpp b/extensions/cocostudio/ActionTimeline/CSLoader.cpp index 61012e3c36..19652fb354 100644 --- a/extensions/cocostudio/ActionTimeline/CSLoader.cpp +++ b/extensions/cocostudio/ActionTimeline/CSLoader.cpp @@ -282,9 +282,9 @@ void CSLoader::init() Node* CSLoader::createNode(std::string_view filename) { - std::string path = filename; + auto path = filename; size_t pos = path.find_last_of('.'); - std::string suffix = path.substr(pos + 1, path.length()); + auto suffix = path.substr(pos + 1, path.length()); CSLoader* load = CSLoader::getInstance(); @@ -302,9 +302,9 @@ Node* CSLoader::createNode(std::string_view filename) Node* CSLoader::createNode(std::string_view filename, const ccNodeLoadCallback& callback) { - std::string path = filename; + auto path = filename; size_t pos = path.find_last_of('.'); - std::string suffix = path.substr(pos + 1, path.length()); + auto suffix = path.substr(pos + 1, path.length()); CSLoader* load = CSLoader::getInstance(); @@ -340,18 +340,18 @@ Node* CSLoader::createNodeWithVisibleSize(std::string_view filename, const ccNod return node; } -std::string CSLoader::getExtentionName(std::string_view name) +std::string_view CSLoader::getExtentionName(std::string_view name) { - std::string path = name; + auto path = name; size_t pos = path.find_last_of('.'); - std::string result = path.substr(pos + 1, path.length()); + auto result = path.substr(pos + 1, path.length()); return result; } ActionTimeline* CSLoader::createTimeline(std::string_view filename) { - std::string suffix = getExtentionName(filename); + auto suffix = getExtentionName(filename); ActionTimelineCache* cache = ActionTimelineCache::getInstance(); @@ -369,7 +369,7 @@ ActionTimeline* CSLoader::createTimeline(std::string_view filename) ActionTimeline* CSLoader::createTimeline(const Data& data, std::string_view filename) { - std::string suffix = getExtentionName(filename); + auto suffix = getExtentionName(filename); ActionTimelineCache* cache = ActionTimelineCache::getInstance(); @@ -379,7 +379,7 @@ ActionTimeline* CSLoader::createTimeline(const Data& data, std::string_view file } else if (suffix == "json" || suffix == "ExportJson") { - std::string content((char*)data.getBytes(), data.getSize()); + std::string_view content((char*)data.getBytes(), data.getSize()); return cache->createActionFromContent(filename, content); } @@ -417,7 +417,7 @@ Node* CSLoader::createNodeFromJson(std::string_view filename) { if (_recordJsonPath) { - std::string jsonPath = filename.substr(0, filename.find_last_of('/') + 1); + auto jsonPath = filename.substr(0, filename.find_last_of('/') + 1); GUIReader::getInstance()->setFilePath(jsonPath); _jsonPath = jsonPath; @@ -448,7 +448,7 @@ Node* CSLoader::loadNodeWithFile(std::string_view fileName) Node* CSLoader::loadNodeWithContent(std::string_view content) { rapidjson::Document doc; - doc.Parse<0>(content.c_str()); + doc.Parse<0>(content.data(), content.length()); if (doc.HasParseError()) { CCLOG("GetParseError %d\n", doc.GetParseError()); @@ -760,10 +760,10 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json) if (isWidget(classname)) { - std::string readerName = getGUIClassName(classname); + std::string readerName{getGUIClassName(classname)}; readerName.append("Reader"); - std::string guiClassName = getGUIClassName(classname); + std::string_view guiClassName = getGUIClassName(classname); widget = dynamic_cast(ObjectFactory::getInstance()->createObject(guiClassName)); // fix memory leak for v3.3 // widget->retain(); @@ -785,7 +785,7 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json) // // 1st., custom widget parse properties of parent widget with parent widget reader - std::string readerName = getWidgetReaderClassName(widget); + std::string_view readerName = getWidgetReaderClassName(widget); WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); if (reader && widget) @@ -990,7 +990,7 @@ inline void CSLoader::reconstructNestNode(cocos2d::Node* node) else { _rootNode = _callbackHandlers.back(); - CCLOG("after pop back _rootNode name = %s", _rootNode->getName().c_str()); + CCLOG("after pop back _rootNode name = %s", _rootNode->getName().data()); } } } @@ -1010,7 +1010,7 @@ Node* CSLoader::nodeWithFlatBuffersFile(std::string_view fileName, const ccNodeL if (buf.isNull()) { - CCLOG("CSLoader::nodeWithFlatBuffersFile - failed read file: %s", fileName.c_str()); + CCLOG("CSLoader::nodeWithFlatBuffersFile - failed read file: %s", fileName.data()); CC_ASSERT(false); return nullptr; } @@ -1144,7 +1144,7 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const { classname = customClassName; } - std::string readername = getGUIClassName(classname); + std::string readername{getGUIClassName(classname)}; readername.append("Reader"); NodeReaderProtocol* reader = @@ -1178,8 +1178,8 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const Widget* widget = dynamic_cast(node); if (widget) { - std::string callbackName = widget->getCallbackName(); - std::string callbackType = widget->getCallbackType(); + auto callbackName = widget->getCallbackName(); + auto callbackType = widget->getCallbackType(); bindCallback(callbackName, callbackType, widget, _rootNode); } @@ -1288,7 +1288,7 @@ bool CSLoader::bindCallback(std::string_view callbackName, } } - CCLOG("callBackName %s cannot be found", callbackName.c_str()); + CCLOG("callBackName %s cannot be found", callbackName.data()); return false; } @@ -1315,40 +1315,42 @@ bool CSLoader::isCustomWidget(std::string_view type) return false; } -std::string CSLoader::getGUIClassName(std::string_view name) +std::string_view CSLoader::getGUIClassName(std::string_view name) { - std::string convertedClassName = name; + std::string_view convertedClassName; if (name == "Panel") { - convertedClassName = "Layout"; + convertedClassName = "Layout"sv; } else if (name == "TextArea") { - convertedClassName = "Text"; + convertedClassName = "Text"sv; } else if (name == "TextButton") { - convertedClassName = "Button"; + convertedClassName = "Button"sv; } else if (name == "Label") { - convertedClassName = "Text"; + convertedClassName = "Text"sv; } else if (name == "LabelAtlas") { - convertedClassName = "TextAtlas"; + convertedClassName = "TextAtlas"sv; } else if (name == "LabelBMFont") { - convertedClassName = "TextBMFont"; + convertedClassName = "TextBMFont"sv; } + else + convertedClassName = name; return convertedClassName; } -std::string CSLoader::getWidgetReaderClassName(Widget* widget) +std::string_view CSLoader::getWidgetReaderClassName(Widget* widget) { - std::string readerName; + std::string_view readerName; // 1st., custom widget parse properties of parent widget with parent widget reader if (dynamic_cast(widget)) @@ -1408,6 +1410,8 @@ std::string CSLoader::getWidgetReaderClassName(Widget* widget) { readerName = "WidgetReader"; } + else + readerName = hlookup::empty_sv; return readerName; } @@ -1495,7 +1499,7 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nod } else { - std::string readername = getGUIClassName(classname); + std::string readername{getGUIClassName(classname)}; readername.append("Reader"); NodeReaderProtocol* reader = @@ -1508,8 +1512,8 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nod Widget* widget = dynamic_cast(node); if (widget) { - std::string callbackName = widget->getCallbackName(); - std::string callbackType = widget->getCallbackType(); + auto callbackName = widget->getCallbackName(); + auto callbackType = widget->getCallbackType(); bindCallback(callbackName, callbackType, widget, _rootNode); } diff --git a/extensions/cocostudio/ActionTimeline/CSLoader.h b/extensions/cocostudio/ActionTimeline/CSLoader.h index 903e7b31fa..3ba1e7fedc 100644 --- a/extensions/cocostudio/ActionTimeline/CSLoader.h +++ b/extensions/cocostudio/ActionTimeline/CSLoader.h @@ -147,11 +147,11 @@ protected: bool isWidget(std::string_view type); bool isCustomWidget(std::string_view type); - std::string getGUIClassName(std::string_view name); - std::string getWidgetReaderClassName(cocos2d::ui::Widget* widget); + std::string_view getGUIClassName(std::string_view name); + std::string_view getWidgetReaderClassName(cocos2d::ui::Widget* widget); inline void reconstructNestNode(cocos2d::Node* node); - static inline std::string getExtentionName(std::string_view name); + static inline std::string_view getExtentionName(std::string_view name); typedef std::function NodeCreateFunc; typedef std::pair Pair; diff --git a/extensions/cocostudio/CCActionNode.cpp b/extensions/cocostudio/CCActionNode.cpp index 7bb4b3b322..c1c454802a 100644 --- a/extensions/cocostudio/CCActionNode.cpp +++ b/extensions/cocostudio/CCActionNode.cpp @@ -190,7 +190,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) int ActionNode::valueToInt(std::string_view value) { - return atoi(value.c_str()); + return atoi(value.data()); } bool ActionNode::valueToBool(std::string_view value) { @@ -206,7 +206,7 @@ bool ActionNode::valueToBool(std::string_view value) } float ActionNode::valueToFloat(std::string_view value) { - return utils::atof(value.c_str()); + return utils::atof(value.data()); } void ActionNode::initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, cocos2d::Ref* root) diff --git a/extensions/cocostudio/CCActionObject.cpp b/extensions/cocostudio/CCActionObject.cpp index 8143324837..48c85bac15 100644 --- a/extensions/cocostudio/CCActionObject.cpp +++ b/extensions/cocostudio/CCActionObject.cpp @@ -186,7 +186,7 @@ void ActionObject::initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNod int ActionObject::valueToInt(std::string_view value) { - return atoi(value.c_str()); + return atoi(value.data()); } bool ActionObject::valueToBool(std::string_view value) { @@ -202,7 +202,7 @@ bool ActionObject::valueToBool(std::string_view value) } float ActionObject::valueToFloat(std::string_view value) { - return utils::atof(value.c_str()); + return utils::atof(value.data()); } void ActionObject::addActionNode(ActionNode* node) diff --git a/extensions/cocostudio/CCArmature.cpp b/extensions/cocostudio/CCArmature.cpp index 2a1f6402eb..ab518eda85 100644 --- a/extensions/cocostudio/CCArmature.cpp +++ b/extensions/cocostudio/CCArmature.cpp @@ -294,7 +294,7 @@ void Armature::changeBoneParent(Bone* bone, std::string_view parentName) } } -const cocos2d::Map& Armature::getBoneDic() const +const cocos2d::StringMap& Armature::getBoneDic() const { return _boneDic; } diff --git a/extensions/cocostudio/CCArmature.h b/extensions/cocostudio/CCArmature.h index 415018cd6e..66866ed2a8 100644 --- a/extensions/cocostudio/CCArmature.h +++ b/extensions/cocostudio/CCArmature.h @@ -144,7 +144,7 @@ public: * Get Armature's bone dictionary * @return Armature's bone dictionary */ - const cocos2d::Map& getBoneDic() const; + const cocos2d::StringMap& getBoneDic() const; /** * This boundingBox will calculate all bones' boundingBox every time @@ -258,7 +258,7 @@ protected: mutable bool _armatureTransformDirty; - cocos2d::Map + cocos2d::StringMap _boneDic; //! The dictionary of the bones, include all bones in the armature, no matter it is the direct bone //! or the indirect bone. It is different from m_pChindren. diff --git a/extensions/cocostudio/CCArmatureAnimation.cpp b/extensions/cocostudio/CCArmatureAnimation.cpp index 7b7258234a..3880ecabb3 100644 --- a/extensions/cocostudio/CCArmatureAnimation.cpp +++ b/extensions/cocostudio/CCArmatureAnimation.cpp @@ -138,7 +138,7 @@ void ArmatureAnimation::setSpeedScale(float speedScale) _processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale; - const Map& map = _armature->getBoneDic(); + auto& map = _armature->getBoneDic(); for (auto& element : map) { Bone* bone = element.second; @@ -212,7 +212,7 @@ void ArmatureAnimation::play(std::string_view animationName, int durationTo, int MovementBoneData* movementBoneData = nullptr; _tweenList.clear(); - const Map& map = _armature->getBoneDic(); + auto& map = _armature->getBoneDic(); for (auto& element : map) { Bone* bone = element.second; diff --git a/extensions/cocostudio/CCArmatureAnimation.h b/extensions/cocostudio/CCArmatureAnimation.h index c855e3b844..e1dce40f78 100644 --- a/extensions/cocostudio/CCArmatureAnimation.h +++ b/extensions/cocostudio/CCArmatureAnimation.h @@ -43,8 +43,8 @@ enum MovementEventType class Armature; class Bone; -typedef void (cocos2d::Ref::*SEL_MovementEventCallFunc)(Armature*, MovementEventType, const std::string&); -typedef void (cocos2d::Ref::*SEL_FrameEventCallFunc)(Bone*, const std::string&, int, int); +typedef void (cocos2d::Ref::*SEL_MovementEventCallFunc)(Armature*, MovementEventType, std::string_view); +typedef void (cocos2d::Ref::*SEL_FrameEventCallFunc)(Bone*, std::string_view, int, int); #define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR) #define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR) diff --git a/extensions/cocostudio/CCArmatureDataManager.cpp b/extensions/cocostudio/CCArmatureDataManager.cpp index c0e39d227b..de37f70e7c 100644 --- a/extensions/cocostudio/CCArmatureDataManager.cpp +++ b/extensions/cocostudio/CCArmatureDataManager.cpp @@ -122,7 +122,7 @@ void ArmatureDataManager::addArmatureData(std::string_view id, { if (RelativeData* data = getRelativeData(configFilePath)) { - data->armatures.push_back(id); + data->armatures.push_back(std::string{id}); } _armarureDatas.insert(id, armatureData); @@ -144,7 +144,7 @@ void ArmatureDataManager::addAnimationData(std::string_view id, { if (RelativeData* data = getRelativeData(configFilePath)) { - data->animations.push_back(id); + data->animations.push_back(std::string{id}); } _animationDatas.insert(id, animationData); @@ -166,7 +166,7 @@ void ArmatureDataManager::addTextureData(std::string_view id, { if (RelativeData* data = getRelativeData(configFilePath)) { - data->textures.push_back(id); + data->textures.push_back(std::string{id}); } _textureDatas.insert(id, textureData); @@ -230,7 +230,7 @@ void ArmatureDataManager::addSpriteFrameFromFile(std::string_view plistPath, { if (RelativeData* data = getRelativeData(configFilePath)) { - data->plistFiles.push_back(plistPath); + data->plistFiles.push_back(std::string{plistPath}); } SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath); } @@ -240,15 +240,15 @@ bool ArmatureDataManager::isAutoLoadSpriteFile() return _autoLoadSpriteFile; } -const cocos2d::Map& ArmatureDataManager::getArmatureDatas() const +const cocos2d::StringMap& ArmatureDataManager::getArmatureDatas() const { return _armarureDatas; } -const cocos2d::Map& ArmatureDataManager::getAnimationDatas() const +const cocos2d::StringMap& ArmatureDataManager::getAnimationDatas() const { return _animationDatas; } -const cocos2d::Map& ArmatureDataManager::getTextureDatas() const +const cocos2d::StringMap& ArmatureDataManager::getTextureDatas() const { return _textureDatas; } diff --git a/extensions/cocostudio/CCArmatureDataManager.h b/extensions/cocostudio/CCArmatureDataManager.h index 8b89ddb7a5..5862f01652 100644 --- a/extensions/cocostudio/CCArmatureDataManager.h +++ b/extensions/cocostudio/CCArmatureDataManager.h @@ -179,9 +179,9 @@ public: */ bool isAutoLoadSpriteFile(); - const cocos2d::Map& getArmatureDatas() const; - const cocos2d::Map& getAnimationDatas() const; - const cocos2d::Map& getTextureDatas() const; + const cocos2d::StringMap& getArmatureDatas() const; + const cocos2d::StringMap& getAnimationDatas() const; + const cocos2d::StringMap& getTextureDatas() const; public: void addRelativeData(std::string_view configFilePath); @@ -193,25 +193,25 @@ private: * @key std::string * @value ArmatureData * */ - cocos2d::Map _armarureDatas; + cocos2d::StringMap _armarureDatas; /** * @brief save animation datas * @key std::string * @value AnimationData * */ - cocos2d::Map _animationDatas; + cocos2d::StringMap _animationDatas; /** * @brief save texture datas * @key std::string * @value TextureData * */ - cocos2d::Map _textureDatas; + cocos2d::StringMap _textureDatas; bool _autoLoadSpriteFile; - std::unordered_map _relativeDatas; + hlookup::string_map _relativeDatas; }; } // namespace cocostudio diff --git a/extensions/cocostudio/CCComAttribute.cpp b/extensions/cocostudio/CCComAttribute.cpp index 2993266d56..f8c5381915 100644 --- a/extensions/cocostudio/CCComAttribute.cpp +++ b/extensions/cocostudio/CCComAttribute.cpp @@ -77,12 +77,12 @@ int ComAttribute::getInt(std::string_view key, int def) const return v.asInt(); } - if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) + if (!DICTOOL->checkObjectExist_json(_doc, key.data())) { return def; } - return DICTOOL->getIntValue_json(_doc, key.c_str()); + return DICTOOL->getIntValue_json(_doc, key.data()); } float ComAttribute::getFloat(std::string_view key, float def) const @@ -93,11 +93,11 @@ float ComAttribute::getFloat(std::string_view key, float def) const return v.asFloat(); } - if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) + if (!DICTOOL->checkObjectExist_json(_doc, key.data())) { return def; } - return DICTOOL->getFloatValue_json(_doc, key.c_str()); + return DICTOOL->getFloatValue_json(_doc, key.data()); } bool ComAttribute::getBool(std::string_view key, bool def) const @@ -108,12 +108,12 @@ bool ComAttribute::getBool(std::string_view key, bool def) const return v.asBool(); } - if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) + if (!DICTOOL->checkObjectExist_json(_doc, key.data())) { return def; } - return DICTOOL->getBooleanValue_json(_doc, key.c_str()); + return DICTOOL->getBooleanValue_json(_doc, key.data()); } std::string ComAttribute::getString(std::string_view key, std::string_view def) const @@ -124,12 +124,12 @@ std::string ComAttribute::getString(std::string_view key, std::string_view def) return v.asString(); } - if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) + if (!DICTOOL->checkObjectExist_json(_doc, key.data())) { - return def; + return std::string{def}; } - return DICTOOL->getStringValue_json(_doc, key.c_str()); + return DICTOOL->getStringValue_json(_doc, key.data()); } ComAttribute* ComAttribute::create() diff --git a/extensions/cocostudio/CCDataReaderHelper.cpp b/extensions/cocostudio/CCDataReaderHelper.cpp index 9dee7de590..0ee6d288ce 100644 --- a/extensions/cocostudio/CCDataReaderHelper.cpp +++ b/extensions/cocostudio/CCDataReaderHelper.cpp @@ -276,19 +276,15 @@ void DataReaderHelper::addDataFromFile(std::string_view filePath) return; } } - _configFileList.push_back(filePath); + _configFileList.push_back(std::string{filePath}); //! find the base file path - std::string basefilePath = filePath; - size_t pos = basefilePath.find_last_of('/'); + std::string basefilePath; + size_t pos = filePath.find_last_of('/'); if (pos != std::string::npos) { - basefilePath = basefilePath.substr(0, pos + 1); - } - else - { - basefilePath = ""; + basefilePath = filePath.substr(0, pos + 1); } std::string fileExtension = cocos2d::FileUtils::getInstance()->getFileExtension(filePath); @@ -346,19 +342,15 @@ void DataReaderHelper::addDataFromFileAsync(std::string_view imagePath, return; } } - _configFileList.push_back(filePath); + _configFileList.push_back(std::string{filePath}); //! find the base file path - std::string basefilePath = filePath; - size_t pos = basefilePath.find_last_of('/'); + std::string basefilePath; + size_t pos = filePath.find_last_of('/'); if (pos != std::string::npos) { - basefilePath = basefilePath.substr(0, pos + 1); - } - else - { - basefilePath = ""; + basefilePath = filePath.substr(0, pos + 1); } // lazy init @@ -506,7 +498,8 @@ void DataReaderHelper::removeConfigFile(std::string_view configFile) void DataReaderHelper::addDataFromCache(std::string_view pFileContent, DataInfo* dataInfo) { pugi::xml_document document; - document.load_string(pFileContent.c_str()); + pugi::xml_parse_result ret = document.load_buffer(pFileContent.data(), pFileContent.length()); + if(!ret) return; auto root = document.document_element(); dataInfo->flashToolVersion = root.attribute(VERSION).as_float(); @@ -1119,12 +1112,12 @@ ContourData* DataReaderHelper::decodeContour(pugi::xml_node& contourXML, DataInf void DataReaderHelper::addDataFromJsonCache(std::string_view fileContent, DataInfo* dataInfo) { rapidjson::Document json; - rapidjson::StringStream stream(fileContent.c_str()); + rapidjson::StringStream stream(fileContent.data()); if (fileContent.size() >= 3) { // Skip BOM if exists - const unsigned char* c = (const unsigned char*)fileContent.c_str(); + const unsigned char* c = (const unsigned char*)fileContent.data(); unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16); if (bom == 0xBFBBEF) // UTF8 BOM diff --git a/extensions/cocostudio/CCDatas.cpp b/extensions/cocostudio/CCDatas.cpp index 65b5cada2e..ef45d8bd45 100644 --- a/extensions/cocostudio/CCDatas.cpp +++ b/extensions/cocostudio/CCDatas.cpp @@ -139,13 +139,15 @@ Color4B BaseData::getColor() std::string DisplayData::changeDisplayToTexture(std::string_view displayName) { // remove .xxx - std::string textureName = displayName; - size_t startPos = textureName.find_last_of("."); + std::string textureName; + size_t startPos = displayName.find_last_of("."); if (startPos != std::string::npos) { - textureName = textureName.erase(startPos); + textureName.assign(displayName.data(), startPos); // textureName = textureName.erase(startPos); } + else + textureName = displayName; return textureName; } diff --git a/extensions/cocostudio/CCDatas.h b/extensions/cocostudio/CCDatas.h index e0ed53be05..dc2d767526 100644 --- a/extensions/cocostudio/CCDatas.h +++ b/extensions/cocostudio/CCDatas.h @@ -286,7 +286,7 @@ public: public: std::string name; - cocos2d::Map boneDataDic; + cocos2d::StringMap boneDataDic; float dataVersion; }; @@ -446,7 +446,7 @@ public: * @key std::string_view * @value MovementBoneData * */ - cocos2d::Map movBoneDataDic; + cocos2d::StringMap movBoneDataDic; }; /** @@ -477,7 +477,7 @@ public: public: std::string name; - cocos2d::Map movementDataDic; + cocos2d::StringMap movementDataDic; std::vector movementNames; }; diff --git a/extensions/cocostudio/CCDisplayManager.cpp b/extensions/cocostudio/CCDisplayManager.cpp index 7fdd2bc7ab..b6d07cc6fa 100644 --- a/extensions/cocostudio/CCDisplayManager.cpp +++ b/extensions/cocostudio/CCDisplayManager.cpp @@ -129,7 +129,7 @@ void DisplayManager::addDisplay(Node* display, int index) skin->setBone(_bone); displayData = SpriteDisplayData::create(); - DisplayFactory::initSpriteDisplay(_bone, decoDisplay, skin->getDisplayName().c_str(), skin); + DisplayFactory::initSpriteDisplay(_bone, decoDisplay, skin->getDisplayName().data(), skin); if (SpriteDisplayData* spriteDisplayData = (SpriteDisplayData*)decoDisplay->getDisplayData()) { diff --git a/extensions/cocostudio/CCSGUIReader.cpp b/extensions/cocostudio/CCSGUIReader.cpp index f2a0845df6..a3586e1e50 100644 --- a/extensions/cocostudio/CCSGUIReader.cpp +++ b/extensions/cocostudio/CCSGUIReader.cpp @@ -311,7 +311,7 @@ std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget) std::string WidgetPropertiesReader::getGUIClassName(std::string_view name) { - std::string convertedClassName = name; + std::string convertedClassName; if (name == "Panel") { convertedClassName = "Layout"; @@ -336,6 +336,8 @@ std::string WidgetPropertiesReader::getGUIClassName(std::string_view name) { convertedClassName = "TextBMFont"; } + else + convertedClassName = name; return convertedClassName; } @@ -429,7 +431,7 @@ Widget* GUIReader::widgetFromBinaryFile(const char* fileName) std::string WidgetPropertiesReader::getWidgetReaderClassName(std::string_view classname) { // create widget reader to parse properties of widget - std::string readerName = classname; + std::string readerName; if (readerName == "Panel") { readerName = "Layout"; @@ -454,6 +456,8 @@ std::string WidgetPropertiesReader::getWidgetReaderClassName(std::string_view cl { readerName = "TextBMFont"; } + else + readerName = classname; readerName.append("Reader"); return readerName; } @@ -1643,10 +1647,10 @@ void WidgetPropertiesReader0300::setPropsForAllCustomWidgetFromJsonDictionary(st { GUIReader* guiReader = GUIReader::getInstance(); - std::map* object_map = guiReader->getParseObjectMap(); + hlookup::string_map* object_map = guiReader->getParseObjectMap(); Ref* object = (*object_map)[classType]; - std::map* selector_map = guiReader->getParseCallBackMap(); + hlookup::string_map* selector_map = guiReader->getParseCallBackMap(); SEL_ParseEvent selector = (*selector_map)[classType]; if (object && selector) diff --git a/extensions/cocostudio/CCSGUIReader.h b/extensions/cocostudio/CCSGUIReader.h index 1de130dd4d..efec530634 100644 --- a/extensions/cocostudio/CCSGUIReader.h +++ b/extensions/cocostudio/CCSGUIReader.h @@ -50,7 +50,7 @@ struct stExpCocoNode; #define kCCSVersion 1.0 -typedef void (cocos2d::Ref::*SEL_ParseEvent)(const std::string&, cocos2d::Ref*, const rapidjson::Value&); +typedef void (cocos2d::Ref::*SEL_ParseEvent)(std::string_view, cocos2d::Ref*, const rapidjson::Value&); #define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR) class CCS_DLL GUIReader : public cocos2d::Ref @@ -96,9 +96,9 @@ protected: std::string m_strFilePath; cocos2d::ValueMap _fileDesignSizes; - typedef std::map ParseCallBackMap; + typedef hlookup::string_map ParseCallBackMap; ParseCallBackMap _mapParseSelector; - typedef std::map ParseObjectMap; + typedef hlookup::string_map ParseObjectMap; ParseObjectMap _mapObject; public: diff --git a/extensions/cocostudio/CCSSceneReader.cpp b/extensions/cocostudio/CCSSceneReader.cpp index f69c5e05dd..c93c80f393 100644 --- a/extensions/cocostudio/CCSSceneReader.cpp +++ b/extensions/cocostudio/CCSSceneReader.cpp @@ -161,7 +161,7 @@ cocos2d::Node* SceneReader::createNodeWithSceneFile( } else { - log("read file [%s] error!\n", fileName.c_str()); + log("read file [%s] error!\n", fileName.data()); } return nullptr; } diff --git a/extensions/cocostudio/CCSkin.cpp b/extensions/cocostudio/CCSkin.cpp index 8287a412bf..a532988362 100644 --- a/extensions/cocostudio/CCSkin.cpp +++ b/extensions/cocostudio/CCSkin.cpp @@ -94,7 +94,7 @@ bool Skin::initWithSpriteFrameName(std::string_view spriteFrameName) } else { - CCLOG("Can't find CCSpriteFrame with %s. Please check your .plist file", spriteFrameName.c_str()); + CCLOG("Can't find CCSpriteFrame with %s. Please check your .plist file", spriteFrameName.data()); ret = false; } diff --git a/extensions/cocostudio/CCSpriteFrameCacheHelper.h b/extensions/cocostudio/CCSpriteFrameCacheHelper.h index 0c84294e68..8f168b5452 100644 --- a/extensions/cocostudio/CCSpriteFrameCacheHelper.h +++ b/extensions/cocostudio/CCSpriteFrameCacheHelper.h @@ -70,7 +70,7 @@ private: SpriteFrameCacheHelper(); ~SpriteFrameCacheHelper(); - std::map> _usingSpriteFrames; + hlookup::string_map> _usingSpriteFrames; static SpriteFrameCacheHelper* _spriteFrameCacheHelper; }; diff --git a/extensions/cocostudio/CocosStudioExport.h b/extensions/cocostudio/CocosStudioExport.h index 89e1929c0d..dcc448bf40 100644 --- a/extensions/cocostudio/CocosStudioExport.h +++ b/extensions/cocostudio/CocosStudioExport.h @@ -31,4 +31,6 @@ # define CCS_DLL #endif +#include "base/hlookup.h" + #endif /* __CCEXTENSIONEXPORT_H__*/ \ No newline at end of file diff --git a/extensions/cocostudio/FlatBuffersSerialize.cpp b/extensions/cocostudio/FlatBuffersSerialize.cpp index 8d064ea849..bdd839b6e0 100644 --- a/extensions/cocostudio/FlatBuffersSerialize.cpp +++ b/extensions/cocostudio/FlatBuffersSerialize.cpp @@ -453,7 +453,7 @@ int FlatBuffersSerialize::getResourceType(std::string key) std::string FlatBuffersSerialize::getGUIClassName(std::string_view name) { - std::string convertedClassName = name; + std::string convertedClassName; if (name == "Panel") { convertedClassName = "Layout"; @@ -478,6 +478,8 @@ std::string FlatBuffersSerialize::getGUIClassName(std::string_view name) { convertedClassName = "TextBMFont"; } + else + convertedClassName = name; return convertedClassName; } @@ -1560,7 +1562,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFileForLanguageData hasKeyReaded = true; } // Record corresponding text. - else if (strcmp(languageName.c_str(), childElement.name()) == 0) + else if (languageName == childElement.name()) { const char* langText = childElement.text().as_string(); if (langText && langText[0] != '\0') diff --git a/extensions/cocostudio/SpineSkeletonDataCache.h b/extensions/cocostudio/SpineSkeletonDataCache.h index 317c64d06a..51a3e1de4a 100644 --- a/extensions/cocostudio/SpineSkeletonDataCache.h +++ b/extensions/cocostudio/SpineSkeletonDataCache.h @@ -39,7 +39,7 @@ public: void removeAllUnusedData(void); public: - std::map _cacheTable; + hlookup::string_map _cacheTable; void (*_reportError)(const char* pszFormat, ...); }; @@ -76,7 +76,7 @@ public: void removeAllUnusedData(void); public: - std::map _cacheTable; + hlookup::string_map _cacheTable; void (*_reportError)(const char* pszFormat, ...); }; diff --git a/extensions/cocostudio/WidgetCallBackHandlerProtocol.cpp b/extensions/cocostudio/WidgetCallBackHandlerProtocol.cpp index a8a6b59e7d..d51149ba9d 100644 --- a/extensions/cocostudio/WidgetCallBackHandlerProtocol.cpp +++ b/extensions/cocostudio/WidgetCallBackHandlerProtocol.cpp @@ -4,15 +4,15 @@ namespace cocostudio { WidgetCallBackHandlerProtocol::~WidgetCallBackHandlerProtocol() {} -cocos2d::ui::Widget::ccWidgetTouchCallback WidgetCallBackHandlerProtocol::onLocateTouchCallback(const std::string&) +cocos2d::ui::Widget::ccWidgetTouchCallback WidgetCallBackHandlerProtocol::onLocateTouchCallback(std::string_view) { return nullptr; } -cocos2d::ui::Widget::ccWidgetClickCallback WidgetCallBackHandlerProtocol::onLocateClickCallback(const std::string&) +cocos2d::ui::Widget::ccWidgetClickCallback WidgetCallBackHandlerProtocol::onLocateClickCallback(std::string_view) { return nullptr; } -cocos2d::ui::Widget::ccWidgetEventCallback WidgetCallBackHandlerProtocol::onLocateEventCallback(const std::string&) +cocos2d::ui::Widget::ccWidgetEventCallback WidgetCallBackHandlerProtocol::onLocateEventCallback(std::string_view) { return nullptr; } diff --git a/extensions/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp b/extensions/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp index 2a4a68060a..c78fc1aa16 100644 --- a/extensions/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp +++ b/extensions/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp @@ -241,5 +241,5 @@ std::string ArmatureNodeReader::getArmatureName(std::string_view exporJsonPath) if (start == -1) start = 0; - return exporJsonPath.substr(start, end - start); + return std::string{exporJsonPath.substr(start, end - start)}; } diff --git a/extensions/cocostudio/WidgetReader/NodeReaderProtocol.cpp b/extensions/cocostudio/WidgetReader/NodeReaderProtocol.cpp index 31bcc5732a..d64403d252 100644 --- a/extensions/cocostudio/WidgetReader/NodeReaderProtocol.cpp +++ b/extensions/cocostudio/WidgetReader/NodeReaderProtocol.cpp @@ -79,7 +79,7 @@ cocos2d::ui::Layout* (*aLayout)(); cocos2d::ui::ScrollView* (*aScrollView)(); cocos2d::ui::ListView* (*aListView)(); cocos2d::ui::PageView* (*aPageView)(); -cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(const std::string&); +cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(std::string_view); cocos2d::Node* (*aArmatureNode)(); cocostudio::timeline::SkeletonNode* (*aSkeletonNode)(); cocostudio::timeline::BoneNode* (*aBoneNode)(); diff --git a/extensions/cocostudio/WidgetReader/NodeReaderProtocol.h b/extensions/cocostudio/WidgetReader/NodeReaderProtocol.h index a92a24135f..ad10606f44 100644 --- a/extensions/cocostudio/WidgetReader/NodeReaderProtocol.h +++ b/extensions/cocostudio/WidgetReader/NodeReaderProtocol.h @@ -168,7 +168,7 @@ CCS_DLL extern cocos2d::ui::PageView* (*aPageView)(); CCS_DLL extern cocos2d::Node* (*aArmatureNode)(); CCS_DLL extern cocostudio::timeline::SkeletonNode* (*aSkeletonNode)(); CCS_DLL extern cocostudio::timeline::BoneNode* (*aBoneNode)(); -CCS_DLL extern cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(const std::string&); +CCS_DLL extern cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(std::string_view); CCS_DLL extern cocos2d::Node* (*aNestingNode)(std::string); ///// 3d objects ///// diff --git a/extensions/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/extensions/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index 161a86263c..e07405f1ab 100644 --- a/extensions/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/extensions/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -97,7 +97,7 @@ void TextAtlasReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson { WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); + std::string_view jsonPath = GUIReader::getInstance()->getFilePath(); TextAtlas* labelAtlas = static_cast(widget); // bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue); @@ -112,7 +112,7 @@ void TextAtlasReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson { case 0: { - std::string tp_c = jsonPath; + std::string tp_c {jsonPath}; const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); const char* cmf_tp = tp_c.append(cmfPath).c_str(); labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue, "12345678"), cmf_tp, diff --git a/extensions/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/extensions/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index fffff874b8..ae74e130cc 100644 --- a/extensions/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/extensions/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -82,7 +82,7 @@ void TextBMFontReader::setPropsFromJsonDictionary(Widget* widget, const rapidjso { WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); + std::string_view jsonPath = GUIReader::getInstance()->getFilePath(); TextBMFont* labelBMFont = static_cast(widget); @@ -92,7 +92,7 @@ void TextBMFontReader::setPropsFromJsonDictionary(Widget* widget, const rapidjso { case 0: { - std::string tp_c = jsonPath; + std::string tp_c { jsonPath }; const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); const char* cmf_tp = tp_c.append(cmfPath).c_str(); labelBMFont->setFntFile(cmf_tp); diff --git a/extensions/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 484dca151f..efbe1ae426 100644 --- a/extensions/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -101,9 +101,9 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - std::string fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); - std::string fontFilePath = jsonPath.append(fontName); + std::string fontFilePath{GUIReader::getInstance()->getFilePath()}; + auto fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); + fontFilePath.append(fontName); if (FileUtils::getInstance()->isFileExist(fontFilePath)) textField->setFontName(fontFilePath); else diff --git a/extensions/cocostudio/WidgetReader/TextReader/TextReader.cpp b/extensions/cocostudio/WidgetReader/TextReader/TextReader.cpp index a42748e5e2..05624cde11 100644 --- a/extensions/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/extensions/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -57,7 +57,7 @@ void TextReader::setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* coc Text* label = static_cast(widget); - std::string binaryFilePath = GUIReader::getInstance()->getFilePath(); + std::string binaryFilePath{GUIReader::getInstance()->getFilePath()}; for (int i = 0; i < cocoNode->GetChildNum(); ++i) { @@ -96,7 +96,7 @@ void TextReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::Val { WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); + std::string fontFilePath{GUIReader::getInstance()->getFilePath()}; Text* label = static_cast(widget); bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, P_TouchScaleEnable); @@ -106,9 +106,9 @@ void TextReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::Val label->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); - std::string fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); + auto fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); - std::string fontFilePath = jsonPath.append(fontName); + fontFilePath.append(fontName); if (FileUtils::getInstance()->isFileExist(fontFilePath)) { label->setFontName(fontFilePath); diff --git a/extensions/cocostudio/WidgetReader/WidgetReader.cpp b/extensions/cocostudio/WidgetReader/WidgetReader.cpp index c9cbce0976..46037d5856 100644 --- a/extensions/cocostudio/WidgetReader/WidgetReader.cpp +++ b/extensions/cocostudio/WidgetReader/WidgetReader.cpp @@ -98,7 +98,7 @@ WidgetReader::WidgetReader() , _opacity(255) , _isAdaptScreen(false) { - valueToInt = [=](std::string_view str) -> int { return atoi(str.c_str()); }; + valueToInt = [=](std::string_view str) -> int { return atoi(str.data()); }; valueToBool = [=](std::string_view str) -> bool { int intValue = valueToInt(str); @@ -112,7 +112,7 @@ WidgetReader::WidgetReader() } }; - valueToFloat = [=](std::string_view str) -> float { return utils::atof(str.c_str()); }; + valueToFloat = [=](std::string_view str) -> float { return utils::atof(str.data()); }; } WidgetReader::~WidgetReader() {} @@ -306,14 +306,14 @@ std::string WidgetReader::getResourcePath(const rapidjson::Value& dict, std::string_view key, cocos2d::ui::Widget::TextureResType texType) { - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - const char* imageFileName = DICTOOL->getStringValue_json(dict, key.c_str()); + std::string_view jsonPath = GUIReader::getInstance()->getFilePath(); + const char* imageFileName = DICTOOL->getStringValue_json(dict, key.data()); std::string imageFileName_tp; if (nullptr != imageFileName) { if (texType == ui::Widget::TextureResType::LOCAL) { - imageFileName_tp = jsonPath + imageFileName; + imageFileName_tp.append(jsonPath).append(imageFileName); } else if (texType == ui::Widget::TextureResType::PLIST) { @@ -339,14 +339,14 @@ std::string WidgetReader::getResourcePath(CocoLoader* cocoLoader, return ""; } - std::string binaryPath = GUIReader::getInstance()->getFilePath(); + std::string_view binaryPath = GUIReader::getInstance()->getFilePath(); std::string imageFileName_tp; if (!backgroundValue.empty()) { if (texType == ui::Widget::TextureResType::LOCAL) { - imageFileName_tp = binaryPath + backgroundValue; + imageFileName_tp.append(binaryPath).append(backgroundValue); } else if (texType == ui::Widget::TextureResType::PLIST) { @@ -942,18 +942,17 @@ Node* WidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table* widgetOp std::string WidgetReader::getResourcePath(std::string_view path, cocos2d::ui::Widget::TextureResType texType) { - std::string filePath = GUIReader::getInstance()->getFilePath(); - const char* imageFileName = path.c_str(); + std::string_view filePath = GUIReader::getInstance()->getFilePath(); std::string imageFileName_tp; - if (nullptr != imageFileName && 0 != strcmp("", imageFileName)) + if (!path.empty()) { if (texType == ui::Widget::TextureResType::LOCAL) { - imageFileName_tp = filePath + imageFileName; + imageFileName_tp.append(filePath).append(path); } else if (texType == ui::Widget::TextureResType::PLIST) { - imageFileName_tp = imageFileName; + imageFileName_tp.assign(path); } else { diff --git a/extensions/cocostudio/WidgetReader/WidgetReader.h b/extensions/cocostudio/WidgetReader/WidgetReader.h index e7641cdc39..0b9a86316b 100644 --- a/extensions/cocostudio/WidgetReader/WidgetReader.h +++ b/extensions/cocostudio/WidgetReader/WidgetReader.h @@ -79,9 +79,9 @@ protected: void beginSetBasicProperties(cocos2d::ui::Widget* widget); void endSetBasicProperties(cocos2d::ui::Widget* widget); - std::function valueToInt; - std::function valueToBool; - std::function valueToFloat; + std::function valueToInt; + std::function valueToBool; + std::function valueToFloat; float _sizePercentX; float _sizePercentY; diff --git a/templates/cpp-template-default/Classes/HelloWorldScene.cpp b/templates/cpp-template-default/Classes/HelloWorldScene.cpp index 620e41e866..60b791bbde 100644 --- a/templates/cpp-template-default/Classes/HelloWorldScene.cpp +++ b/templates/cpp-template-default/Classes/HelloWorldScene.cpp @@ -97,7 +97,7 @@ bool HelloWorld::init() } // add "HelloWorld" splash screen" - auto sprite = Sprite::create("HelloWorld.png"); + auto sprite = Sprite::create("HelloWorld.png"sv); if (sprite == nullptr) { problemLoading("'HelloWorld.png'");