Modify some extensions for string_view

This commit is contained in:
halx99 2021-12-27 13:52:08 +08:00
parent 5ba5049146
commit b63f815488
60 changed files with 255 additions and 248 deletions

View File

@ -80,8 +80,7 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
auto tempAtlas = font->newFontAtlas(); auto tempAtlas = font->newFontAtlas();
if (tempAtlas) if (tempAtlas)
{ {
_atlasMap[atlasName] = tempAtlas; return _atlasMap.emplace(atlasName, tempAtlas).first->second;
return _atlasMap[atlasName];
} }
} }
} }

View File

@ -291,6 +291,13 @@ public:
return _data.erase(position); 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<K, V> container. * Removes an element with an iterator from the Map<K, V> container.
* *

View File

@ -22,7 +22,7 @@ struct string_hash
size_t operator()(const char* str) const { return hash_type{}(str); } 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_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 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); typename _Cont::iterator it = cont.find(key);
if (it != cont.end()) if (it != cont.end())
it.value() = std::move(_Val); it->second = std::move(_Val);
else else
it = cont.emplace(std::string{key}, std::forward<_Valty>(_Val)).first; it = cont.emplace(std::string{key}, std::forward<_Valty>(_Val)).first;
return it; return it;

View File

@ -638,7 +638,7 @@ std::string FileUtils::getPathForFilename(std::string_view filename,
std::string_view searchPath) const std::string_view searchPath) const
{ {
auto file = filename; auto file = filename;
std::string file_path = ""; std::string_view file_path = hlookup::empty_sv;
size_t pos = filename.find_last_of('/'); size_t pos = filename.find_last_of('/');
if (pos != std::string::npos) if (pos != std::string::npos)
{ {

View File

@ -84,17 +84,9 @@ static void _checkWorkingPath()
WCHAR utf16Path[CC_MAX_PATH] = {0}; WCHAR utf16Path[CC_MAX_PATH] = {0};
int nNum = GetCurrentDirectoryW(CC_MAX_PATH - 2, utf16Path); int nNum = GetCurrentDirectoryW(CC_MAX_PATH - 2, utf16Path);
s_workingPath.reserve(nNum + 1);
s_workingPath.assign(utf16Path, nNum); s_workingPath.assign(utf16Path, nNum);
s_workingPath.push_back('\\');
//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);
//}
} }
} }

View File

@ -581,7 +581,7 @@ std::string_view Animation::getLastAnimationName() const
return DEFAULT_NAME; return DEFAULT_NAME;
} }
void Animation::setAnimations(const std::map<std::string, AnimationData*>& value) void Animation::setAnimations(const hlookup::string_map<AnimationData*>& value)
{ {
if (_animations == value) if (_animations == value)
{ {

View File

@ -64,7 +64,7 @@ private:
float _inheritTimeScale; float _inheritTimeScale;
std::vector<std::string> _animationNames; std::vector<std::string> _animationNames;
std::vector<AnimationState*> _animationStates; std::vector<AnimationState*> _animationStates;
std::map<std::string, AnimationData*> _animations; hlookup::string_map<AnimationData*> _animations;
Armature* _armature; Armature* _armature;
AnimationConfig* _animationConfig; AnimationConfig* _animationConfig;
AnimationState* _lastAnimationState; AnimationState* _lastAnimationState;
@ -441,8 +441,8 @@ public:
* @version DragonBones 4.5 * @version DragonBones 4.5
* @language zh_CN * @language zh_CN
*/ */
inline const std::map<std::string, AnimationData*>& getAnimations() const { return _animations; } inline const hlookup::string_map<AnimationData*>& getAnimations() const { return _animations; }
void setAnimations(const std::map<std::string, AnimationData*>& value); void setAnimations(const hlookup::string_map<AnimationData*>& value);
/** /**
* - An AnimationConfig instance that can be used quickly. * - An AnimationConfig instance that can be used quickly.
* @see dragonBones.AnimationConfig * @see dragonBones.AnimationConfig

View File

@ -83,7 +83,7 @@ void AnimationState::_onClear()
void AnimationState::_updateTimelines() void AnimationState::_updateTimelines()
{ {
{ // Update constraint timelines. { // Update constraint timelines.
std::map<std::string, std::vector<ConstraintTimelineState*>> constraintTimelines; hlookup::string_map<std::vector<ConstraintTimelineState*>> constraintTimelines;
for (const auto timeline : _constraintTimelines) // Create constraint timelines map. for (const auto timeline : _constraintTimelines) // Create constraint timelines map.
{ {
constraintTimelines[timeline->constraint->getName()].push_back(timeline); constraintTimelines[timeline->constraint->getName()].push_back(timeline);
@ -137,7 +137,7 @@ void AnimationState::_updateTimelines()
void AnimationState::_updateBoneAndSlotTimelines() void AnimationState::_updateBoneAndSlotTimelines()
{ {
{ // Update bone timelines. { // Update bone timelines.
std::map<std::string, std::vector<BoneTimelineState*>> boneTimelines; hlookup::string_map<std::vector<BoneTimelineState*>> boneTimelines;
for (const auto timeline : _boneTimelines) // Create bone timelines map. for (const auto timeline : _boneTimelines) // Create bone timelines map.
{ {
boneTimelines[timeline->bone->getName()].push_back(timeline); boneTimelines[timeline->bone->getName()].push_back(timeline);
@ -238,7 +238,7 @@ void AnimationState::_updateBoneAndSlotTimelines()
} }
{ // Update slot timelines. { // Update slot timelines.
std::map<std::string, std::vector<SlotTimelineState*>> slotTimelines; hlookup::string_map<std::vector<SlotTimelineState*>> slotTimelines;
std::vector<unsigned> ffdFlags; std::vector<unsigned> ffdFlags;
for (const auto timeline : _slotTimelines) // Create slot timelines map. 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()) 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. 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() && if (std::find(_boneMask.cbegin(), _boneMask.cend(), bone->getName()) == _boneMask.cend() &&
currentBone->contains(bone)) 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)) if (!currentBone->contains(bone))
{ {
_boneMask.push_back(bone->getName()); _boneMask.push_back(std::string{bone->getName()});
} }
} }
} }

View File

@ -251,7 +251,7 @@ private:
std::vector<SlotTimelineState*> _slotTimelines; std::vector<SlotTimelineState*> _slotTimelines;
std::vector<ConstraintTimelineState*> _constraintTimelines; std::vector<ConstraintTimelineState*> _constraintTimelines;
std::vector<std::pair<TimelineState*, BaseTimelineType>> _poseTimelines; std::vector<std::pair<TimelineState*, BaseTimelineType>> _poseTimelines;
std::map<std::string, BonePose*> _bonePoses; hlookup::string_map<BonePose*> _bonePoses;
Armature* _armature; Armature* _armature;
ZOrderTimelineState* _zOrderTimeline; ZOrderTimelineState* _zOrderTimeline;

View File

@ -1,4 +1,4 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2012-2018 DragonBones team and other contributors * Copyright (c) 2012-2018 DragonBones team and other contributors
@ -33,6 +33,7 @@
#include <functional> #include <functional>
#include <sstream> #include <sstream>
#include <assert.h> #include <assert.h>
#include "base/hlookup.h"
// dragonBones assert // dragonBones assert
#define DRAGONBONES_ASSERT(cond, msg) \ #define DRAGONBONES_ASSERT(cond, msg) \
do \ do \
@ -359,15 +360,15 @@ inline int indexOf(const std::vector<T>& vector, const T& value)
return -1; return -1;
} }
template <class T> template <class Cont>
inline T* mapFind(const std::map<std::string, T*>& map, std::string_view key) inline auto mapFind(Cont& map, std::string_view key)
{ {
auto iterator = map.find(key); auto iterator = map.find(key);
return (iterator != map.end()) ? iterator->second : nullptr; return (iterator != map.end()) ? iterator->second : nullptr;
} }
template <class T> template <class Cont>
inline T* mapFindB(std::map<std::string, T>& map, std::string_view key) inline auto mapFindB(Cont& map, std::string_view key)
{ {
auto iterator = map.find(key); auto iterator = map.find(key);
return (iterator != map.end()) ? &iterator->second : nullptr; return (iterator != map.end()) ? &iterator->second : nullptr;

View File

@ -47,7 +47,7 @@ bool BaseFactory::_fillBuildArmaturePackage(BuildArmaturePackage& dataPackage,
std::string_view skinName, std::string_view skinName,
std::string_view textureAtlasName) const std::string_view textureAtlasName) const
{ {
std::string mapName = dragonBonesName; auto mapName = dragonBonesName;
DragonBonesData* dragonBonesData = nullptr; DragonBonesData* dragonBonesData = nullptr;
ArmatureData* armatureData = nullptr; ArmatureData* armatureData = nullptr;
@ -141,7 +141,7 @@ void BaseFactory::_buildSlots(const BuildArmaturePackage& dataPackage, Armature*
return; return;
} }
std::map<std::string, std::vector<DisplayData*>*> skinSlots; hlookup::string_map<std::vector<DisplayData*>*> skinSlots;
for (auto& pair : defaultSkin->displays) for (auto& pair : defaultSkin->displays)
{ {
auto& displays = pair.second; auto& displays = pair.second;

View File

@ -1,4 +1,4 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2012-2018 DragonBones team and other contributors * Copyright (c) 2012-2018 DragonBones team and other contributors
@ -68,8 +68,8 @@ public:
bool autoSearch; bool autoSearch;
protected: protected:
std::map<std::string, DragonBonesData*> _dragonBonesDataMap; hlookup::string_map<DragonBonesData*> _dragonBonesDataMap;
std::map<std::string, std::vector<TextureAtlasData*>> _textureAtlasDataMap; hlookup::string_map<std::vector<TextureAtlasData*>> _textureAtlasDataMap;
DragonBones* _dragonBones; DragonBones* _dragonBones;
DataParser* _dataParser; DataParser* _dataParser;
@ -550,14 +550,14 @@ public:
/** /**
* @private * @private
*/ */
inline const std::map<std::string, std::vector<TextureAtlasData*>>& getAllTextureAtlasData() const inline const hlookup::string_map<std::vector<TextureAtlasData*>>& getAllTextureAtlasData() const
{ {
return _textureAtlasDataMap; return _textureAtlasDataMap;
} }
/** /**
* @private * @private
*/ */
inline const std::map<std::string, DragonBonesData*>& getAllDragonBonesData() const { return _dragonBonesDataMap; } inline const hlookup::string_map<DragonBonesData*>& getAllDragonBonesData() const { return _dragonBonesDataMap; }
/** /**
* - An Worldclock instance updated by engine. * - An Worldclock instance updated by engine.
* @version DragonBones 5.7 * @version DragonBones 5.7

View File

@ -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 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. 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() && if (std::find(boneMask.cbegin(), boneMask.cend(), bone->getName()) == boneMask.cend() &&
currentBone->contains(bone)) 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)) if (!currentBone->contains(bone))
{ {
boneMask.push_back(bone->getName()); boneMask.push_back(std::string{bone->getName()});
} }
} }
} }

View File

@ -126,23 +126,23 @@ public:
/** /**
* @private * @private
*/ */
std::map<std::string, std::vector<TimelineData*>> boneTimelines; hlookup::string_map<std::vector<TimelineData*>> boneTimelines;
/** /**
* @private * @private
*/ */
std::map<std::string, std::vector<TimelineData*>> slotTimelines; hlookup::string_map<std::vector<TimelineData*>> slotTimelines;
/** /**
* @private * @private
*/ */
std::map<std::string, std::vector<TimelineData*>> constraintTimelines; hlookup::string_map<std::vector<TimelineData*>> constraintTimelines;
/** /**
* @private * @private
*/ */
std::map<std::string, std::vector<int>> boneCachedFrameIndices; hlookup::string_map<std::vector<int>> boneCachedFrameIndices;
/** /**
* @private * @private
*/ */
std::map<std::string, std::vector<int>> slotCachedFrameIndices; hlookup::string_map<std::vector<int>> slotCachedFrameIndices;
/** /**
* @private * @private
*/ */

View File

@ -113,23 +113,23 @@ public:
/** /**
* @private * @private
*/ */
std::map<std::string, BoneData*> bones; hlookup::string_map<BoneData*> bones;
/** /**
* @private * @private
*/ */
std::map<std::string, SlotData*> slots; hlookup::string_map<SlotData*> slots;
/** /**
* @private * @private
*/ */
std::map<std::string, ConstraintData*> constraints; hlookup::string_map<ConstraintData*> constraints;
/** /**
* @private * @private
*/ */
std::map<std::string, SkinData*> skins; hlookup::string_map<SkinData*> skins;
/** /**
* @private * @private
*/ */
std::map<std::string, AnimationData*> animations; hlookup::string_map<AnimationData*> animations;
/** /**
* - The default skin data. * - The default skin data.
* @version DragonBones 4.5 * @version DragonBones 4.5
@ -223,7 +223,7 @@ public:
* @version DragonBones 3.0 * @version DragonBones 3.0
* @language zh_CN * @language zh_CN
*/ */
inline BoneData* getBone(std::string_view boneName) const { return mapFind<BoneData>(bones, boneName); } inline BoneData* getBone(std::string_view boneName) const { return mapFind(bones, boneName); }
/** /**
* - Get a specific slot data. * - Get a specific slot data.
* @param slotName - The slot name. * @param slotName - The slot name.
@ -236,13 +236,13 @@ public:
* @version DragonBones 3.0 * @version DragonBones 3.0
* @language zh_CN * @language zh_CN
*/ */
inline SlotData* getSlot(std::string_view slotName) const { return mapFind<SlotData>(slots, slotName); } inline SlotData* getSlot(std::string_view slotName) const { return mapFind(slots, slotName); }
/** /**
* @private * @private
*/ */
inline ConstraintData* getConstraint(std::string_view constraintName) const inline ConstraintData* getConstraint(std::string_view constraintName) const
{ {
return mapFind<ConstraintData>(constraints, constraintName); return mapFind(constraints, constraintName);
} }
/** /**
* - Get a specific skin data. * - Get a specific skin data.

View File

@ -1,4 +1,4 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2012-2018 DragonBones team and other contributors * Copyright (c) 2012-2018 DragonBones team and other contributors
@ -107,7 +107,7 @@ public:
/** /**
* @private * @private
*/ */
std::map<std::string, ArmatureData*> armatures; hlookup::string_map<ArmatureData*> armatures;
/** /**
* @internal * @internal
*/ */
@ -160,7 +160,7 @@ public:
*/ */
inline ArmatureData* getArmature(std::string_view armatureName) const inline ArmatureData* getArmature(std::string_view armatureName) const
{ {
return mapFind<ArmatureData>(armatures, armatureName); return mapFind(armatures, armatureName);
} }
protected: protected:

View File

@ -80,7 +80,7 @@ public:
std::vector<DisplayData*>* getDisplays(std::string_view slotName) { return mapFindB(displays, slotName); } std::vector<DisplayData*>* getDisplays(std::string_view slotName) { return mapFindB(displays, slotName); }
public: // For WebAssembly. TODO parent public: // For WebAssembly. TODO parent
const std::map<std::string, std::vector<DisplayData*>>& getSlotDisplays() const { return displays; } const hlookup::string_map<std::vector<DisplayData*>>& getSlotDisplays() const { return displays; }
}; };
DRAGONBONES_NAMESPACE_END DRAGONBONES_NAMESPACE_END

View File

@ -1,4 +1,4 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2012-2018 DragonBones team and other contributors * Copyright (c) 2012-2018 DragonBones team and other contributors
@ -84,7 +84,7 @@ public:
/** /**
* @private * @private
*/ */
std::map<std::string, TextureData*> textures; hlookup::string_map<TextureData*> textures;
/** /**
* @private * @private
*/ */
@ -100,13 +100,16 @@ public:
/** /**
* @private * @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: protected:
virtual void _onClear() override; virtual void _onClear() override;
public: // For WebAssembly. public: // For WebAssembly.
const std::map<std::string, TextureData*>& getTextures() const { return textures; } const hlookup::string_map<TextureData*>& getTextures() const { return textures; }
}; };
/** /**
* @internal * @internal

View File

@ -127,7 +127,7 @@ const char* DataParser::DEFAULT_NAME = "default";
TextureFormat DataParser::_getTextureFormat(std::string_view value) TextureFormat DataParser::_getTextureFormat(std::string_view value)
{ {
auto lower = value; std::string lower{value};
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "rgba8888") if (lower == "rgba8888")
@ -160,7 +160,7 @@ TextureFormat DataParser::_getTextureFormat(std::string_view value)
ArmatureType DataParser::_getArmatureType(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); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "armature") if (lower == "armature")
@ -181,7 +181,7 @@ ArmatureType DataParser::_getArmatureType(std::string_view value)
DisplayType DataParser::_getDisplayType(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); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "image") if (lower == "image")
@ -206,7 +206,7 @@ DisplayType DataParser::_getDisplayType(std::string_view value)
BoundingBoxType DataParser::_getBoundingBoxType(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); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "rectangle") if (lower == "rectangle")
@ -227,7 +227,7 @@ BoundingBoxType DataParser::_getBoundingBoxType(std::string_view value)
ActionType DataParser::_getActionType(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); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "play") if (lower == "play")
@ -248,7 +248,7 @@ ActionType DataParser::_getActionType(std::string_view value)
BlendMode DataParser::_getBlendMode(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); std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
if (lower == "normal") if (lower == "normal")

View File

@ -93,7 +93,7 @@ protected:
return dragonBones::to_string(rawData[key].GetDouble()); 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) 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 rawData[(int)index].GetString();
} }
return defaultValue; return std::string{defaultValue};
} }
protected: protected:
@ -160,10 +160,10 @@ private:
std::vector<const rapidjson::Value*> _cacheRawMeshes; std::vector<const rapidjson::Value*> _cacheRawMeshes;
std::vector<MeshDisplayData*> _cacheMeshes; std::vector<MeshDisplayData*> _cacheMeshes;
std::vector<ActionFrame> _actionFrames; std::vector<ActionFrame> _actionFrames;
std::map<std::string, const rapidjson::Value*> _weightSlotPose; hlookup::string_map<const rapidjson::Value*> _weightSlotPose;
std::map<std::string, const rapidjson::Value*> _weightBonePoses; hlookup::string_map<const rapidjson::Value*> _weightBonePoses;
std::map<std::string, std::vector<BoneData*>> _cacheBones; hlookup::string_map<std::vector<BoneData*>> _cacheBones;
std::map<std::string, std::vector<ActionData*>> _slotChildActions; hlookup::string_map<std::vector<ActionData*>> _slotChildActions;
public: public:
JSONDataParser() JSONDataParser()

View File

@ -224,8 +224,8 @@ protected:
std::function<void(Frame*)> _frameEventListener; std::function<void(Frame*)> _frameEventListener;
std::function<void()> _lastFrameListener; std::function<void()> _lastFrameListener;
std::map<int, std::map<std::string, std::function<void()>>> _frameEndCallFuncs; std::map<int, hlookup::string_map<std::function<void()>>> _frameEndCallFuncs;
std::map<std::string, AnimationInfo> _animationInfos; hlookup::string_map<AnimationInfo> _animationInfos;
}; };
NS_TIMELINE_END NS_TIMELINE_END

View File

@ -136,9 +136,9 @@ void ActionTimelineCache::removeAction(std::string_view fileName)
ActionTimeline* ActionTimelineCache::createAction(std::string_view filename) ActionTimeline* ActionTimelineCache::createAction(std::string_view filename)
{ {
std::string path = filename; auto path = filename;
size_t pos = path.find_last_of('.'); size_t pos = path.find_last_of('.');
std::string suffix = path.substr(pos + 1, path.length()); auto suffix = path.substr(pos + 1, path.length());
ActionTimelineCache* cache = ActionTimelineCache::getInstance(); ActionTimelineCache* cache = ActionTimelineCache::getInstance();
@ -183,8 +183,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFile(std::string_vie
return loadAnimationActionWithContent(fileName, contentStr); return loadAnimationActionWithContent(fileName, contentStr);
} }
ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_view fileName, ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_view fileName, std::string_view content)
std::string_view content)
{ {
// if already exists an action with filename, then return this action // if already exists an action with filename, then return this action
ActionTimeline* action = _animationActions.at(fileName); ActionTimeline* action = _animationActions.at(fileName);
@ -192,7 +191,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_
return action; return action;
rapidjson::Document doc; rapidjson::Document doc;
doc.Parse<0>(content.c_str()); doc.Parse<0>(content.data(), content.length());
if (doc.HasParseError()) if (doc.HasParseError())
{ {
CCLOG("GetParseError %d\n", doc.GetParseError()); CCLOG("GetParseError %d\n", doc.GetParseError());
@ -442,7 +441,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(std:
if (action) if (action)
return action; return action;
std::string path = fileName; auto path = fileName;
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
@ -462,7 +461,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d::
if (action) if (action)
return action; return action;
std::string path = fileName; auto path = fileName;
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);

View File

@ -128,8 +128,8 @@ protected:
typedef std::function<Frame*(const rapidjson::Value& json)> FrameCreateFunc; typedef std::function<Frame*(const rapidjson::Value& json)> FrameCreateFunc;
typedef std::pair<std::string, FrameCreateFunc> Pair; typedef std::pair<std::string, FrameCreateFunc> Pair;
std::unordered_map<std::string, FrameCreateFunc> _funcs; hlookup::string_map<FrameCreateFunc> _funcs;
cocos2d::Map<std::string, ActionTimeline*> _animationActions; cocos2d::StringMap<ActionTimeline*> _animationActions;
}; };
NS_TIMELINE_END NS_TIMELINE_END

View File

@ -75,20 +75,20 @@ bool BoneNode::init()
setProgramState(new cocos2d::backend::ProgramState(program), false); setProgramState(new cocos2d::backend::ProgramState(program), false);
pipelineDescriptor.programState = _programState; pipelineDescriptor.programState = _programState;
_mvpLocation = _programState->getUniformLocation("u_MVPMatrix"); _mvpLocation = _programState->getUniformLocation("u_MVPMatrix"sv);
auto vertexLayout = _programState->getVertexLayout(); auto vertexLayout = _programState->getVertexLayout();
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes(); const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
auto iter = attributeInfo.find("a_position"); auto iter = attributeInfo.find("a_position"sv);
if (iter != attributeInfo.end()) 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); false);
} }
iter = attributeInfo.find("a_color"); iter = attributeInfo.find("a_color"sv);
if (iter != attributeInfo.end()) 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); 3 * sizeof(float), false);
} }
vertexLayout->setLayout(7 * sizeof(float)); vertexLayout->setLayout(7 * sizeof(float));
@ -152,7 +152,7 @@ void BoneNode::removeFromBoneList(BoneNode* bone)
{ {
auto subBones = bone->getAllSubBones(); auto subBones = bone->getAllSubBones();
subBones.pushBack(bone); subBones.pushBack(bone);
for (auto& subBone : subBones) for (auto subBone : subBones)
{ {
if (subBone->_rootSkeleton == nullptr) if (subBone->_rootSkeleton == nullptr)
continue; continue;
@ -186,7 +186,7 @@ void BoneNode::addToBoneList(BoneNode* bone)
{ {
auto subBones = bone->getAllSubBones(); auto subBones = bone->getAllSubBones();
subBones.pushBack(bone); subBones.pushBack(bone);
for (auto& subBone : subBones) for (auto subBone : subBones)
{ {
subBone->_rootSkeleton = _rootSkeleton; subBone->_rootSkeleton = _rootSkeleton;
auto bonename = subBone->getName(); auto bonename = subBone->getName();
@ -198,8 +198,8 @@ void BoneNode::addToBoneList(BoneNode* bone)
_rootSkeleton->_subBonesOrderDirty = true; _rootSkeleton->_subBonesOrderDirty = true;
} }
else else
CCLOG("already has a bone named %s in skeleton %s", bonename.c_str(), CCLOG("already has a bone named %s in skeleton %s", bonename.data(),
_rootSkeleton->getName().c_str()); _rootSkeleton->getName().data());
} }
} }
else else

View File

@ -298,7 +298,7 @@ void SkeletonNode::batchDrawAllSubBones()
#endif // CC_STUDIO_ENABLED_VIEW #endif // CC_STUDIO_ENABLED_VIEW
} }
void SkeletonNode::changeSkins(const std::map<std::string, std::string>& boneSkinNameMap) void SkeletonNode::changeSkins(const hlookup::string_map<std::string>& boneSkinNameMap)
{ {
for (auto& boneskin : boneSkinNameMap) for (auto& boneskin : boneSkinNameMap)
{ {
@ -327,14 +327,14 @@ BoneNode* SkeletonNode::getBoneNode(std::string_view boneName)
return nullptr; return nullptr;
} }
const cocos2d::Map<std::string, BoneNode*>& SkeletonNode::getAllSubBonesMap() const const cocos2d::StringMap<BoneNode*>& SkeletonNode::getAllSubBonesMap() const
{ {
return _subBonesMap; return _subBonesMap;
} }
void SkeletonNode::addSkinGroup(std::string groupName, std::map<std::string, std::string> boneSkinNameMap) void SkeletonNode::addSkinGroup(std::string groupName, hlookup::string_map<std::string> boneSkinNameMap)
{ {
_skinGroupMap.emplace(groupName, boneSkinNameMap); _skinGroupMap.emplace(groupName, std::move(boneSkinNameMap));
} }
void SkeletonNode::checkSubBonesDirty() void SkeletonNode::checkSubBonesDirty()

View File

@ -49,13 +49,13 @@ public:
/** /**
*get All bones in this skeleton, <bone's name, BoneNode> *get All bones in this skeleton, <bone's name, BoneNode>
*/ */
const cocos2d::Map<std::string, BoneNode*>& getAllSubBonesMap() const; const cocos2d::StringMap<BoneNode*>& getAllSubBonesMap() const;
/** /**
*@brief: change displays *@brief: change displays
*@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone> *@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
*/ */
void changeSkins(const std::map<std::string, std::string>& boneSkinNameMap); void changeSkins(const hlookup::string_map<std::string>& boneSkinNameMap);
/** /**
*@brief: change displays *@brief: change displays
@ -68,7 +68,7 @@ public:
*@param: groupName, key *@param: groupName, key
*@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone> *@param: boneSkinNameMap, map <name of bone, name of skin to display which added to bone>
*/ */
void addSkinGroup(std::string groupName, std::map<std::string, std::string> boneSkinNameMap); void addSkinGroup(std::string groupName, hlookup::string_map<std::string> boneSkinNameMap);
cocos2d::Rect getBoundingBox() const override; cocos2d::Rect getBoundingBox() const override;
@ -86,7 +86,7 @@ protected:
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override; virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
protected: protected:
cocos2d::Map<std::string, BoneNode*> _subBonesMap; cocos2d::StringMap<BoneNode*> _subBonesMap;
private: private:
struct VertexData struct VertexData
@ -98,7 +98,7 @@ private:
cocos2d::Vec2 _squareVertices[8]; cocos2d::Vec2 _squareVertices[8];
VertexData _vertexData[8]; VertexData _vertexData[8];
std::map<std::string, std::map<std::string, std::string>> hlookup::string_map<hlookup::string_map<std::string> >
_skinGroupMap; // map< suit name, map< bone name, skin name> > _skinGroupMap; // map< suit name, map< bone name, skin name> >
CC_DISALLOW_COPY_AND_ASSIGN(SkeletonNode); CC_DISALLOW_COPY_AND_ASSIGN(SkeletonNode);

View File

@ -282,9 +282,9 @@ void CSLoader::init()
Node* CSLoader::createNode(std::string_view filename) Node* CSLoader::createNode(std::string_view filename)
{ {
std::string path = filename; auto path = filename;
size_t pos = path.find_last_of('.'); 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(); 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) Node* CSLoader::createNode(std::string_view filename, const ccNodeLoadCallback& callback)
{ {
std::string path = filename; auto path = filename;
size_t pos = path.find_last_of('.'); 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(); CSLoader* load = CSLoader::getInstance();
@ -340,18 +340,18 @@ Node* CSLoader::createNodeWithVisibleSize(std::string_view filename, const ccNod
return node; 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('.'); 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; return result;
} }
ActionTimeline* CSLoader::createTimeline(std::string_view filename) ActionTimeline* CSLoader::createTimeline(std::string_view filename)
{ {
std::string suffix = getExtentionName(filename); auto suffix = getExtentionName(filename);
ActionTimelineCache* cache = ActionTimelineCache::getInstance(); 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) ActionTimeline* CSLoader::createTimeline(const Data& data, std::string_view filename)
{ {
std::string suffix = getExtentionName(filename); auto suffix = getExtentionName(filename);
ActionTimelineCache* cache = ActionTimelineCache::getInstance(); ActionTimelineCache* cache = ActionTimelineCache::getInstance();
@ -379,7 +379,7 @@ ActionTimeline* CSLoader::createTimeline(const Data& data, std::string_view file
} }
else if (suffix == "json" || suffix == "ExportJson") 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); return cache->createActionFromContent(filename, content);
} }
@ -417,7 +417,7 @@ Node* CSLoader::createNodeFromJson(std::string_view filename)
{ {
if (_recordJsonPath) 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); GUIReader::getInstance()->setFilePath(jsonPath);
_jsonPath = jsonPath; _jsonPath = jsonPath;
@ -448,7 +448,7 @@ Node* CSLoader::loadNodeWithFile(std::string_view fileName)
Node* CSLoader::loadNodeWithContent(std::string_view content) Node* CSLoader::loadNodeWithContent(std::string_view content)
{ {
rapidjson::Document doc; rapidjson::Document doc;
doc.Parse<0>(content.c_str()); doc.Parse<0>(content.data(), content.length());
if (doc.HasParseError()) if (doc.HasParseError())
{ {
CCLOG("GetParseError %d\n", doc.GetParseError()); CCLOG("GetParseError %d\n", doc.GetParseError());
@ -760,10 +760,10 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json)
if (isWidget(classname)) if (isWidget(classname))
{ {
std::string readerName = getGUIClassName(classname); std::string readerName{getGUIClassName(classname)};
readerName.append("Reader"); readerName.append("Reader");
std::string guiClassName = getGUIClassName(classname); std::string_view guiClassName = getGUIClassName(classname);
widget = dynamic_cast<Widget*>(ObjectFactory::getInstance()->createObject(guiClassName)); widget = dynamic_cast<Widget*>(ObjectFactory::getInstance()->createObject(guiClassName));
// fix memory leak for v3.3 // fix memory leak for v3.3
// widget->retain(); // 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 // 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 = WidgetReaderProtocol* reader =
dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName)); dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName));
if (reader && widget) if (reader && widget)
@ -990,7 +990,7 @@ inline void CSLoader::reconstructNestNode(cocos2d::Node* node)
else else
{ {
_rootNode = _callbackHandlers.back(); _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()) 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); CC_ASSERT(false);
return nullptr; return nullptr;
} }
@ -1144,7 +1144,7 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const
{ {
classname = customClassName; classname = customClassName;
} }
std::string readername = getGUIClassName(classname); std::string readername{getGUIClassName(classname)};
readername.append("Reader"); readername.append("Reader");
NodeReaderProtocol* reader = NodeReaderProtocol* reader =
@ -1178,8 +1178,8 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const
Widget* widget = dynamic_cast<Widget*>(node); Widget* widget = dynamic_cast<Widget*>(node);
if (widget) if (widget)
{ {
std::string callbackName = widget->getCallbackName(); auto callbackName = widget->getCallbackName();
std::string callbackType = widget->getCallbackType(); auto callbackType = widget->getCallbackType();
bindCallback(callbackName, callbackType, widget, _rootNode); 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; return false;
} }
@ -1315,40 +1315,42 @@ bool CSLoader::isCustomWidget(std::string_view type)
return false; 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") if (name == "Panel")
{ {
convertedClassName = "Layout"; convertedClassName = "Layout"sv;
} }
else if (name == "TextArea") else if (name == "TextArea")
{ {
convertedClassName = "Text"; convertedClassName = "Text"sv;
} }
else if (name == "TextButton") else if (name == "TextButton")
{ {
convertedClassName = "Button"; convertedClassName = "Button"sv;
} }
else if (name == "Label") else if (name == "Label")
{ {
convertedClassName = "Text"; convertedClassName = "Text"sv;
} }
else if (name == "LabelAtlas") else if (name == "LabelAtlas")
{ {
convertedClassName = "TextAtlas"; convertedClassName = "TextAtlas"sv;
} }
else if (name == "LabelBMFont") else if (name == "LabelBMFont")
{ {
convertedClassName = "TextBMFont"; convertedClassName = "TextBMFont"sv;
} }
else
convertedClassName = name;
return convertedClassName; 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 // 1st., custom widget parse properties of parent widget with parent widget reader
if (dynamic_cast<Button*>(widget)) if (dynamic_cast<Button*>(widget))
@ -1408,6 +1410,8 @@ std::string CSLoader::getWidgetReaderClassName(Widget* widget)
{ {
readerName = "WidgetReader"; readerName = "WidgetReader";
} }
else
readerName = hlookup::empty_sv;
return readerName; return readerName;
} }
@ -1495,7 +1499,7 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nod
} }
else else
{ {
std::string readername = getGUIClassName(classname); std::string readername{getGUIClassName(classname)};
readername.append("Reader"); readername.append("Reader");
NodeReaderProtocol* reader = NodeReaderProtocol* reader =
@ -1508,8 +1512,8 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nod
Widget* widget = dynamic_cast<Widget*>(node); Widget* widget = dynamic_cast<Widget*>(node);
if (widget) if (widget)
{ {
std::string callbackName = widget->getCallbackName(); auto callbackName = widget->getCallbackName();
std::string callbackType = widget->getCallbackType(); auto callbackType = widget->getCallbackType();
bindCallback(callbackName, callbackType, widget, _rootNode); bindCallback(callbackName, callbackType, widget, _rootNode);
} }

View File

@ -147,11 +147,11 @@ protected:
bool isWidget(std::string_view type); bool isWidget(std::string_view type);
bool isCustomWidget(std::string_view type); bool isCustomWidget(std::string_view type);
std::string getGUIClassName(std::string_view name); std::string_view getGUIClassName(std::string_view name);
std::string getWidgetReaderClassName(cocos2d::ui::Widget* widget); std::string_view getWidgetReaderClassName(cocos2d::ui::Widget* widget);
inline void reconstructNestNode(cocos2d::Node* node); 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<cocos2d::Node*(const rapidjson::Value& json)> NodeCreateFunc; typedef std::function<cocos2d::Node*(const rapidjson::Value& json)> NodeCreateFunc;
typedef std::pair<std::string, NodeCreateFunc> Pair; typedef std::pair<std::string, NodeCreateFunc> Pair;

View File

@ -190,7 +190,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
int ActionNode::valueToInt(std::string_view value) int ActionNode::valueToInt(std::string_view value)
{ {
return atoi(value.c_str()); return atoi(value.data());
} }
bool ActionNode::valueToBool(std::string_view value) 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) 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) void ActionNode::initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, cocos2d::Ref* root)

View File

@ -186,7 +186,7 @@ void ActionObject::initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNod
int ActionObject::valueToInt(std::string_view value) int ActionObject::valueToInt(std::string_view value)
{ {
return atoi(value.c_str()); return atoi(value.data());
} }
bool ActionObject::valueToBool(std::string_view value) 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) float ActionObject::valueToFloat(std::string_view value)
{ {
return utils::atof(value.c_str()); return utils::atof(value.data());
} }
void ActionObject::addActionNode(ActionNode* node) void ActionObject::addActionNode(ActionNode* node)

View File

@ -294,7 +294,7 @@ void Armature::changeBoneParent(Bone* bone, std::string_view parentName)
} }
} }
const cocos2d::Map<std::string, Bone*>& Armature::getBoneDic() const const cocos2d::StringMap<Bone*>& Armature::getBoneDic() const
{ {
return _boneDic; return _boneDic;
} }

View File

@ -144,7 +144,7 @@ public:
* Get Armature's bone dictionary * Get Armature's bone dictionary
* @return Armature's bone dictionary * @return Armature's bone dictionary
*/ */
const cocos2d::Map<std::string, Bone*>& getBoneDic() const; const cocos2d::StringMap<Bone*>& getBoneDic() const;
/** /**
* This boundingBox will calculate all bones' boundingBox every time * This boundingBox will calculate all bones' boundingBox every time
@ -258,7 +258,7 @@ protected:
mutable bool _armatureTransformDirty; mutable bool _armatureTransformDirty;
cocos2d::Map<std::string, Bone*> cocos2d::StringMap<Bone*>
_boneDic; //! The dictionary of the bones, include all bones in the armature, no matter it is the direct bone _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. //! or the indirect bone. It is different from m_pChindren.

View File

@ -138,7 +138,7 @@ void ArmatureAnimation::setSpeedScale(float speedScale)
_processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale; _processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale;
const Map<std::string, Bone*>& map = _armature->getBoneDic(); auto& map = _armature->getBoneDic();
for (auto& element : map) for (auto& element : map)
{ {
Bone* bone = element.second; Bone* bone = element.second;
@ -212,7 +212,7 @@ void ArmatureAnimation::play(std::string_view animationName, int durationTo, int
MovementBoneData* movementBoneData = nullptr; MovementBoneData* movementBoneData = nullptr;
_tweenList.clear(); _tweenList.clear();
const Map<std::string, Bone*>& map = _armature->getBoneDic(); auto& map = _armature->getBoneDic();
for (auto& element : map) for (auto& element : map)
{ {
Bone* bone = element.second; Bone* bone = element.second;

View File

@ -43,8 +43,8 @@ enum MovementEventType
class Armature; class Armature;
class Bone; class Bone;
typedef void (cocos2d::Ref::*SEL_MovementEventCallFunc)(Armature*, MovementEventType, const std::string&); typedef void (cocos2d::Ref::*SEL_MovementEventCallFunc)(Armature*, MovementEventType, std::string_view);
typedef void (cocos2d::Ref::*SEL_FrameEventCallFunc)(Bone*, const std::string&, int, int); typedef void (cocos2d::Ref::*SEL_FrameEventCallFunc)(Bone*, std::string_view, int, int);
#define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR) #define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR)
#define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR) #define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR)

View File

@ -122,7 +122,7 @@ void ArmatureDataManager::addArmatureData(std::string_view id,
{ {
if (RelativeData* data = getRelativeData(configFilePath)) if (RelativeData* data = getRelativeData(configFilePath))
{ {
data->armatures.push_back(id); data->armatures.push_back(std::string{id});
} }
_armarureDatas.insert(id, armatureData); _armarureDatas.insert(id, armatureData);
@ -144,7 +144,7 @@ void ArmatureDataManager::addAnimationData(std::string_view id,
{ {
if (RelativeData* data = getRelativeData(configFilePath)) if (RelativeData* data = getRelativeData(configFilePath))
{ {
data->animations.push_back(id); data->animations.push_back(std::string{id});
} }
_animationDatas.insert(id, animationData); _animationDatas.insert(id, animationData);
@ -166,7 +166,7 @@ void ArmatureDataManager::addTextureData(std::string_view id,
{ {
if (RelativeData* data = getRelativeData(configFilePath)) if (RelativeData* data = getRelativeData(configFilePath))
{ {
data->textures.push_back(id); data->textures.push_back(std::string{id});
} }
_textureDatas.insert(id, textureData); _textureDatas.insert(id, textureData);
@ -230,7 +230,7 @@ void ArmatureDataManager::addSpriteFrameFromFile(std::string_view plistPath,
{ {
if (RelativeData* data = getRelativeData(configFilePath)) if (RelativeData* data = getRelativeData(configFilePath))
{ {
data->plistFiles.push_back(plistPath); data->plistFiles.push_back(std::string{plistPath});
} }
SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath); SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath);
} }
@ -240,15 +240,15 @@ bool ArmatureDataManager::isAutoLoadSpriteFile()
return _autoLoadSpriteFile; return _autoLoadSpriteFile;
} }
const cocos2d::Map<std::string, ArmatureData*>& ArmatureDataManager::getArmatureDatas() const const cocos2d::StringMap<ArmatureData*>& ArmatureDataManager::getArmatureDatas() const
{ {
return _armarureDatas; return _armarureDatas;
} }
const cocos2d::Map<std::string, AnimationData*>& ArmatureDataManager::getAnimationDatas() const const cocos2d::StringMap<AnimationData*>& ArmatureDataManager::getAnimationDatas() const
{ {
return _animationDatas; return _animationDatas;
} }
const cocos2d::Map<std::string, TextureData*>& ArmatureDataManager::getTextureDatas() const const cocos2d::StringMap<TextureData*>& ArmatureDataManager::getTextureDatas() const
{ {
return _textureDatas; return _textureDatas;
} }

View File

@ -179,9 +179,9 @@ public:
*/ */
bool isAutoLoadSpriteFile(); bool isAutoLoadSpriteFile();
const cocos2d::Map<std::string, ArmatureData*>& getArmatureDatas() const; const cocos2d::StringMap<ArmatureData*>& getArmatureDatas() const;
const cocos2d::Map<std::string, AnimationData*>& getAnimationDatas() const; const cocos2d::StringMap<AnimationData*>& getAnimationDatas() const;
const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const; const cocos2d::StringMap<TextureData*>& getTextureDatas() const;
public: public:
void addRelativeData(std::string_view configFilePath); void addRelativeData(std::string_view configFilePath);
@ -193,25 +193,25 @@ private:
* @key std::string * @key std::string
* @value ArmatureData * * @value ArmatureData *
*/ */
cocos2d::Map<std::string, ArmatureData*> _armarureDatas; cocos2d::StringMap<ArmatureData*> _armarureDatas;
/** /**
* @brief save animation datas * @brief save animation datas
* @key std::string * @key std::string
* @value AnimationData * * @value AnimationData *
*/ */
cocos2d::Map<std::string, AnimationData*> _animationDatas; cocos2d::StringMap<AnimationData*> _animationDatas;
/** /**
* @brief save texture datas * @brief save texture datas
* @key std::string * @key std::string
* @value TextureData * * @value TextureData *
*/ */
cocos2d::Map<std::string, TextureData*> _textureDatas; cocos2d::StringMap<TextureData*> _textureDatas;
bool _autoLoadSpriteFile; bool _autoLoadSpriteFile;
std::unordered_map<std::string, RelativeData> _relativeDatas; hlookup::string_map<RelativeData> _relativeDatas;
}; };
} // namespace cocostudio } // namespace cocostudio

View File

@ -77,12 +77,12 @@ int ComAttribute::getInt(std::string_view key, int def) const
return v.asInt(); return v.asInt();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.data()))
{ {
return def; 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 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(); return v.asFloat();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.data()))
{ {
return def; 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 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(); return v.asBool();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.data()))
{ {
return def; 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 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(); 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() ComAttribute* ComAttribute::create()

View File

@ -276,19 +276,15 @@ void DataReaderHelper::addDataFromFile(std::string_view filePath)
return; return;
} }
} }
_configFileList.push_back(filePath); _configFileList.push_back(std::string{filePath});
//! find the base file path //! find the base file path
std::string basefilePath = filePath; std::string basefilePath;
size_t pos = basefilePath.find_last_of('/'); size_t pos = filePath.find_last_of('/');
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
basefilePath = basefilePath.substr(0, pos + 1); basefilePath = filePath.substr(0, pos + 1);
}
else
{
basefilePath = "";
} }
std::string fileExtension = cocos2d::FileUtils::getInstance()->getFileExtension(filePath); std::string fileExtension = cocos2d::FileUtils::getInstance()->getFileExtension(filePath);
@ -346,19 +342,15 @@ void DataReaderHelper::addDataFromFileAsync(std::string_view imagePath,
return; return;
} }
} }
_configFileList.push_back(filePath); _configFileList.push_back(std::string{filePath});
//! find the base file path //! find the base file path
std::string basefilePath = filePath; std::string basefilePath;
size_t pos = basefilePath.find_last_of('/'); size_t pos = filePath.find_last_of('/');
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
basefilePath = basefilePath.substr(0, pos + 1); basefilePath = filePath.substr(0, pos + 1);
}
else
{
basefilePath = "";
} }
// lazy init // lazy init
@ -506,7 +498,8 @@ void DataReaderHelper::removeConfigFile(std::string_view configFile)
void DataReaderHelper::addDataFromCache(std::string_view pFileContent, DataInfo* dataInfo) void DataReaderHelper::addDataFromCache(std::string_view pFileContent, DataInfo* dataInfo)
{ {
pugi::xml_document document; 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(); auto root = document.document_element();
dataInfo->flashToolVersion = root.attribute(VERSION).as_float(); 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) void DataReaderHelper::addDataFromJsonCache(std::string_view fileContent, DataInfo* dataInfo)
{ {
rapidjson::Document json; rapidjson::Document json;
rapidjson::StringStream stream(fileContent.c_str()); rapidjson::StringStream stream(fileContent.data());
if (fileContent.size() >= 3) if (fileContent.size() >= 3)
{ {
// Skip BOM if exists // 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); unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16);
if (bom == 0xBFBBEF) // UTF8 BOM if (bom == 0xBFBBEF) // UTF8 BOM

View File

@ -139,13 +139,15 @@ Color4B BaseData::getColor()
std::string DisplayData::changeDisplayToTexture(std::string_view displayName) std::string DisplayData::changeDisplayToTexture(std::string_view displayName)
{ {
// remove .xxx // remove .xxx
std::string textureName = displayName; std::string textureName;
size_t startPos = textureName.find_last_of("."); size_t startPos = displayName.find_last_of(".");
if (startPos != std::string::npos) if (startPos != std::string::npos)
{ {
textureName = textureName.erase(startPos); textureName.assign(displayName.data(), startPos); // textureName = textureName.erase(startPos);
} }
else
textureName = displayName;
return textureName; return textureName;
} }

View File

@ -286,7 +286,7 @@ public:
public: public:
std::string name; std::string name;
cocos2d::Map<std::string, BoneData*> boneDataDic; cocos2d::StringMap<BoneData*> boneDataDic;
float dataVersion; float dataVersion;
}; };
@ -446,7 +446,7 @@ public:
* @key std::string_view * @key std::string_view
* @value MovementBoneData * * @value MovementBoneData *
*/ */
cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic; cocos2d::StringMap<MovementBoneData*> movBoneDataDic;
}; };
/** /**
@ -477,7 +477,7 @@ public:
public: public:
std::string name; std::string name;
cocos2d::Map<std::string, MovementData*> movementDataDic; cocos2d::StringMap<MovementData*> movementDataDic;
std::vector<std::string> movementNames; std::vector<std::string> movementNames;
}; };

View File

@ -129,7 +129,7 @@ void DisplayManager::addDisplay(Node* display, int index)
skin->setBone(_bone); skin->setBone(_bone);
displayData = SpriteDisplayData::create(); 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()) if (SpriteDisplayData* spriteDisplayData = (SpriteDisplayData*)decoDisplay->getDisplayData())
{ {

View File

@ -311,7 +311,7 @@ std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget)
std::string WidgetPropertiesReader::getGUIClassName(std::string_view name) std::string WidgetPropertiesReader::getGUIClassName(std::string_view name)
{ {
std::string convertedClassName = name; std::string convertedClassName;
if (name == "Panel") if (name == "Panel")
{ {
convertedClassName = "Layout"; convertedClassName = "Layout";
@ -336,6 +336,8 @@ std::string WidgetPropertiesReader::getGUIClassName(std::string_view name)
{ {
convertedClassName = "TextBMFont"; convertedClassName = "TextBMFont";
} }
else
convertedClassName = name;
return convertedClassName; return convertedClassName;
} }
@ -429,7 +431,7 @@ Widget* GUIReader::widgetFromBinaryFile(const char* fileName)
std::string WidgetPropertiesReader::getWidgetReaderClassName(std::string_view classname) std::string WidgetPropertiesReader::getWidgetReaderClassName(std::string_view classname)
{ {
// create widget reader to parse properties of widget // create widget reader to parse properties of widget
std::string readerName = classname; std::string readerName;
if (readerName == "Panel") if (readerName == "Panel")
{ {
readerName = "Layout"; readerName = "Layout";
@ -454,6 +456,8 @@ std::string WidgetPropertiesReader::getWidgetReaderClassName(std::string_view cl
{ {
readerName = "TextBMFont"; readerName = "TextBMFont";
} }
else
readerName = classname;
readerName.append("Reader"); readerName.append("Reader");
return readerName; return readerName;
} }
@ -1643,10 +1647,10 @@ void WidgetPropertiesReader0300::setPropsForAllCustomWidgetFromJsonDictionary(st
{ {
GUIReader* guiReader = GUIReader::getInstance(); GUIReader* guiReader = GUIReader::getInstance();
std::map<std::string, Ref*>* object_map = guiReader->getParseObjectMap(); hlookup::string_map<Ref*>* object_map = guiReader->getParseObjectMap();
Ref* object = (*object_map)[classType]; Ref* object = (*object_map)[classType];
std::map<std::string, SEL_ParseEvent>* selector_map = guiReader->getParseCallBackMap(); hlookup::string_map<SEL_ParseEvent>* selector_map = guiReader->getParseCallBackMap();
SEL_ParseEvent selector = (*selector_map)[classType]; SEL_ParseEvent selector = (*selector_map)[classType];
if (object && selector) if (object && selector)

View File

@ -50,7 +50,7 @@ struct stExpCocoNode;
#define kCCSVersion 1.0 #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) #define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
class CCS_DLL GUIReader : public cocos2d::Ref class CCS_DLL GUIReader : public cocos2d::Ref
@ -96,9 +96,9 @@ protected:
std::string m_strFilePath; std::string m_strFilePath;
cocos2d::ValueMap _fileDesignSizes; cocos2d::ValueMap _fileDesignSizes;
typedef std::map<std::string, SEL_ParseEvent> ParseCallBackMap; typedef hlookup::string_map<SEL_ParseEvent> ParseCallBackMap;
ParseCallBackMap _mapParseSelector; ParseCallBackMap _mapParseSelector;
typedef std::map<std::string, Ref*> ParseObjectMap; typedef hlookup::string_map<Ref*> ParseObjectMap;
ParseObjectMap _mapObject; ParseObjectMap _mapObject;
public: public:

View File

@ -161,7 +161,7 @@ cocos2d::Node* SceneReader::createNodeWithSceneFile(
} }
else else
{ {
log("read file [%s] error!\n", fileName.c_str()); log("read file [%s] error!\n", fileName.data());
} }
return nullptr; return nullptr;
} }

View File

@ -94,7 +94,7 @@ bool Skin::initWithSpriteFrameName(std::string_view spriteFrameName)
} }
else 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; ret = false;
} }

View File

@ -70,7 +70,7 @@ private:
SpriteFrameCacheHelper(); SpriteFrameCacheHelper();
~SpriteFrameCacheHelper(); ~SpriteFrameCacheHelper();
std::map<std::string, std::vector<cocos2d::SpriteFrame*>> _usingSpriteFrames; hlookup::string_map<std::vector<cocos2d::SpriteFrame*>> _usingSpriteFrames;
static SpriteFrameCacheHelper* _spriteFrameCacheHelper; static SpriteFrameCacheHelper* _spriteFrameCacheHelper;
}; };

View File

@ -31,4 +31,6 @@
# define CCS_DLL # define CCS_DLL
#endif #endif
#include "base/hlookup.h"
#endif /* __CCEXTENSIONEXPORT_H__*/ #endif /* __CCEXTENSIONEXPORT_H__*/

View File

@ -453,7 +453,7 @@ int FlatBuffersSerialize::getResourceType(std::string key)
std::string FlatBuffersSerialize::getGUIClassName(std::string_view name) std::string FlatBuffersSerialize::getGUIClassName(std::string_view name)
{ {
std::string convertedClassName = name; std::string convertedClassName;
if (name == "Panel") if (name == "Panel")
{ {
convertedClassName = "Layout"; convertedClassName = "Layout";
@ -478,6 +478,8 @@ std::string FlatBuffersSerialize::getGUIClassName(std::string_view name)
{ {
convertedClassName = "TextBMFont"; convertedClassName = "TextBMFont";
} }
else
convertedClassName = name;
return convertedClassName; return convertedClassName;
} }
@ -1560,7 +1562,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFileForLanguageData
hasKeyReaded = true; hasKeyReaded = true;
} }
// Record corresponding text. // Record corresponding text.
else if (strcmp(languageName.c_str(), childElement.name()) == 0) else if (languageName == childElement.name())
{ {
const char* langText = childElement.text().as_string(); const char* langText = childElement.text().as_string();
if (langText && langText[0] != '\0') if (langText && langText[0] != '\0')

View File

@ -39,7 +39,7 @@ public:
void removeAllUnusedData(void); void removeAllUnusedData(void);
public: public:
std::map<std::string, SkeletonData*> _cacheTable; hlookup::string_map<SkeletonData*> _cacheTable;
void (*_reportError)(const char* pszFormat, ...); void (*_reportError)(const char* pszFormat, ...);
}; };
@ -76,7 +76,7 @@ public:
void removeAllUnusedData(void); void removeAllUnusedData(void);
public: public:
std::map<std::string, SkeletonData*> _cacheTable; hlookup::string_map<SkeletonData*> _cacheTable;
void (*_reportError)(const char* pszFormat, ...); void (*_reportError)(const char* pszFormat, ...);
}; };

View File

@ -4,15 +4,15 @@
namespace cocostudio namespace cocostudio
{ {
WidgetCallBackHandlerProtocol::~WidgetCallBackHandlerProtocol() {} WidgetCallBackHandlerProtocol::~WidgetCallBackHandlerProtocol() {}
cocos2d::ui::Widget::ccWidgetTouchCallback WidgetCallBackHandlerProtocol::onLocateTouchCallback(const std::string&) cocos2d::ui::Widget::ccWidgetTouchCallback WidgetCallBackHandlerProtocol::onLocateTouchCallback(std::string_view)
{ {
return nullptr; return nullptr;
} }
cocos2d::ui::Widget::ccWidgetClickCallback WidgetCallBackHandlerProtocol::onLocateClickCallback(const std::string&) cocos2d::ui::Widget::ccWidgetClickCallback WidgetCallBackHandlerProtocol::onLocateClickCallback(std::string_view)
{ {
return nullptr; return nullptr;
} }
cocos2d::ui::Widget::ccWidgetEventCallback WidgetCallBackHandlerProtocol::onLocateEventCallback(const std::string&) cocos2d::ui::Widget::ccWidgetEventCallback WidgetCallBackHandlerProtocol::onLocateEventCallback(std::string_view)
{ {
return nullptr; return nullptr;
} }

View File

@ -241,5 +241,5 @@ std::string ArmatureNodeReader::getArmatureName(std::string_view exporJsonPath)
if (start == -1) if (start == -1)
start = 0; start = 0;
return exporJsonPath.substr(start, end - start); return std::string{exporJsonPath.substr(start, end - start)};
} }

View File

@ -79,7 +79,7 @@ cocos2d::ui::Layout* (*aLayout)();
cocos2d::ui::ScrollView* (*aScrollView)(); cocos2d::ui::ScrollView* (*aScrollView)();
cocos2d::ui::ListView* (*aListView)(); cocos2d::ui::ListView* (*aListView)();
cocos2d::ui::PageView* (*aPageView)(); cocos2d::ui::PageView* (*aPageView)();
cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(const std::string&); cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(std::string_view);
cocos2d::Node* (*aArmatureNode)(); cocos2d::Node* (*aArmatureNode)();
cocostudio::timeline::SkeletonNode* (*aSkeletonNode)(); cocostudio::timeline::SkeletonNode* (*aSkeletonNode)();
cocostudio::timeline::BoneNode* (*aBoneNode)(); cocostudio::timeline::BoneNode* (*aBoneNode)();

View File

@ -168,7 +168,7 @@ CCS_DLL extern cocos2d::ui::PageView* (*aPageView)();
CCS_DLL extern cocos2d::Node* (*aArmatureNode)(); CCS_DLL extern cocos2d::Node* (*aArmatureNode)();
CCS_DLL extern cocostudio::timeline::SkeletonNode* (*aSkeletonNode)(); CCS_DLL extern cocostudio::timeline::SkeletonNode* (*aSkeletonNode)();
CCS_DLL extern cocostudio::timeline::BoneNode* (*aBoneNode)(); 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); CCS_DLL extern cocos2d::Node* (*aNestingNode)(std::string);
///// 3d objects ///// ///// 3d objects /////

View File

@ -97,7 +97,7 @@ void TextAtlasReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson
{ {
WidgetReader::setPropsFromJsonDictionary(widget, options); WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath(); std::string_view jsonPath = GUIReader::getInstance()->getFilePath();
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget); TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
// bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue); // bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue);
@ -112,7 +112,7 @@ void TextAtlasReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson
{ {
case 0: case 0:
{ {
std::string tp_c = jsonPath; std::string tp_c {jsonPath};
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str(); const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue, "12345678"), cmf_tp, labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue, "12345678"), cmf_tp,

View File

@ -82,7 +82,7 @@ void TextBMFontReader::setPropsFromJsonDictionary(Widget* widget, const rapidjso
{ {
WidgetReader::setPropsFromJsonDictionary(widget, options); WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath(); std::string_view jsonPath = GUIReader::getInstance()->getFilePath();
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget); TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
@ -92,7 +92,7 @@ void TextBMFontReader::setPropsFromJsonDictionary(Widget* widget, const rapidjso
{ {
case 0: case 0:
{ {
std::string tp_c = jsonPath; std::string tp_c { jsonPath };
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str(); const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelBMFont->setFntFile(cmf_tp); labelBMFont->setFntFile(cmf_tp);

View File

@ -101,9 +101,9 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson
textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20));
std::string jsonPath = GUIReader::getInstance()->getFilePath(); std::string fontFilePath{GUIReader::getInstance()->getFilePath()};
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)) if (FileUtils::getInstance()->isFileExist(fontFilePath))
textField->setFontName(fontFilePath); textField->setFontName(fontFilePath);
else else

View File

@ -57,7 +57,7 @@ void TextReader::setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* coc
Text* label = static_cast<Text*>(widget); Text* label = static_cast<Text*>(widget);
std::string binaryFilePath = GUIReader::getInstance()->getFilePath(); std::string binaryFilePath{GUIReader::getInstance()->getFilePath()};
for (int i = 0; i < cocoNode->GetChildNum(); ++i) for (int i = 0; i < cocoNode->GetChildNum(); ++i)
{ {
@ -96,7 +96,7 @@ void TextReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::Val
{ {
WidgetReader::setPropsFromJsonDictionary(widget, options); WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath(); std::string fontFilePath{GUIReader::getInstance()->getFilePath()};
Text* label = static_cast<Text*>(widget); Text* label = static_cast<Text*>(widget);
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, P_TouchScaleEnable); 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)); 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)) if (FileUtils::getInstance()->isFileExist(fontFilePath))
{ {
label->setFontName(fontFilePath); label->setFontName(fontFilePath);

View File

@ -98,7 +98,7 @@ WidgetReader::WidgetReader()
, _opacity(255) , _opacity(255)
, _isAdaptScreen(false) , _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 { valueToBool = [=](std::string_view str) -> bool {
int intValue = valueToInt(str); 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() {} WidgetReader::~WidgetReader() {}
@ -306,14 +306,14 @@ std::string WidgetReader::getResourcePath(const rapidjson::Value& dict,
std::string_view key, std::string_view key,
cocos2d::ui::Widget::TextureResType texType) cocos2d::ui::Widget::TextureResType texType)
{ {
std::string jsonPath = GUIReader::getInstance()->getFilePath(); std::string_view jsonPath = GUIReader::getInstance()->getFilePath();
const char* imageFileName = DICTOOL->getStringValue_json(dict, key.c_str()); const char* imageFileName = DICTOOL->getStringValue_json(dict, key.data());
std::string imageFileName_tp; std::string imageFileName_tp;
if (nullptr != imageFileName) if (nullptr != imageFileName)
{ {
if (texType == ui::Widget::TextureResType::LOCAL) if (texType == ui::Widget::TextureResType::LOCAL)
{ {
imageFileName_tp = jsonPath + imageFileName; imageFileName_tp.append(jsonPath).append(imageFileName);
} }
else if (texType == ui::Widget::TextureResType::PLIST) else if (texType == ui::Widget::TextureResType::PLIST)
{ {
@ -339,14 +339,14 @@ std::string WidgetReader::getResourcePath(CocoLoader* cocoLoader,
return ""; return "";
} }
std::string binaryPath = GUIReader::getInstance()->getFilePath(); std::string_view binaryPath = GUIReader::getInstance()->getFilePath();
std::string imageFileName_tp; std::string imageFileName_tp;
if (!backgroundValue.empty()) if (!backgroundValue.empty())
{ {
if (texType == ui::Widget::TextureResType::LOCAL) if (texType == ui::Widget::TextureResType::LOCAL)
{ {
imageFileName_tp = binaryPath + backgroundValue; imageFileName_tp.append(binaryPath).append(backgroundValue);
} }
else if (texType == ui::Widget::TextureResType::PLIST) 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 WidgetReader::getResourcePath(std::string_view path, cocos2d::ui::Widget::TextureResType texType)
{ {
std::string filePath = GUIReader::getInstance()->getFilePath(); std::string_view filePath = GUIReader::getInstance()->getFilePath();
const char* imageFileName = path.c_str();
std::string imageFileName_tp; std::string imageFileName_tp;
if (nullptr != imageFileName && 0 != strcmp("", imageFileName)) if (!path.empty())
{ {
if (texType == ui::Widget::TextureResType::LOCAL) if (texType == ui::Widget::TextureResType::LOCAL)
{ {
imageFileName_tp = filePath + imageFileName; imageFileName_tp.append(filePath).append(path);
} }
else if (texType == ui::Widget::TextureResType::PLIST) else if (texType == ui::Widget::TextureResType::PLIST)
{ {
imageFileName_tp = imageFileName; imageFileName_tp.assign(path);
} }
else else
{ {

View File

@ -79,9 +79,9 @@ protected:
void beginSetBasicProperties(cocos2d::ui::Widget* widget); void beginSetBasicProperties(cocos2d::ui::Widget* widget);
void endSetBasicProperties(cocos2d::ui::Widget* widget); void endSetBasicProperties(cocos2d::ui::Widget* widget);
std::function<int(const std::string&)> valueToInt; std::function<int(std::string_view)> valueToInt;
std::function<bool(const std::string&)> valueToBool; std::function<bool(std::string_view)> valueToBool;
std::function<float(const std::string&)> valueToFloat; std::function<float(std::string_view)> valueToFloat;
float _sizePercentX; float _sizePercentX;
float _sizePercentY; float _sizePercentY;

View File

@ -97,7 +97,7 @@ bool HelloWorld::init()
} }
// add "HelloWorld" splash screen" // add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png"); auto sprite = Sprite::create("HelloWorld.png"sv);
if (sprite == nullptr) if (sprite == nullptr)
{ {
problemLoading("'HelloWorld.png'"); problemLoading("'HelloWorld.png'");