Optimize out a lot of std::string construction and allocations (#415)
Update CommandLineParameters.hpp Update CommandLineParametersTests.cpp Update WebContext.hpp xmake check-files -f Fix MaterialPassRegistry
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Nz
|
||||
Animation(Animation&&) noexcept;
|
||||
~Animation();
|
||||
|
||||
bool AddSequence(const Sequence& sequence);
|
||||
bool AddSequence(Sequence sequence);
|
||||
void AnimateSkeleton(Skeleton* targetSkeleton, std::size_t frameA, std::size_t frameB, float interpolation) const;
|
||||
|
||||
bool CreateSkeletal(std::size_t frameCount, std::size_t jointCount);
|
||||
@@ -74,23 +74,23 @@ namespace Nz
|
||||
|
||||
std::size_t GetFrameCount() const;
|
||||
std::size_t GetJointCount() const;
|
||||
Sequence* GetSequence(const std::string& sequenceName);
|
||||
Sequence* GetSequence(std::string_view sequenceName);
|
||||
Sequence* GetSequence(std::size_t index);
|
||||
const Sequence* GetSequence(const std::string& sequenceName) const;
|
||||
const Sequence* GetSequence(std::string_view sequenceName) const;
|
||||
const Sequence* GetSequence(std::size_t index) const;
|
||||
std::size_t GetSequenceCount() const;
|
||||
std::size_t GetSequenceIndex(const std::string& sequenceName) const;
|
||||
std::size_t GetSequenceIndex(std::string_view sequenceName) const;
|
||||
SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0);
|
||||
const SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0) const;
|
||||
AnimationType GetType() const;
|
||||
|
||||
bool HasSequence(const std::string& sequenceName) const;
|
||||
bool HasSequence(std::string_view sequenceName) const;
|
||||
bool HasSequence(std::size_t index = 0) const;
|
||||
|
||||
bool IsLoopPointInterpolationEnabled() const;
|
||||
bool IsValid() const;
|
||||
|
||||
void RemoveSequence(const std::string& sequenceName);
|
||||
void RemoveSequence(std::string_view sequenceName);
|
||||
void RemoveSequence(std::size_t index);
|
||||
|
||||
Animation& operator=(const Animation&) = delete;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
||||
@@ -57,12 +57,12 @@ namespace Nz
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(const std::string& message);
|
||||
void Error(std::string_view message);
|
||||
bool ParseBaseframe();
|
||||
bool ParseBounds();
|
||||
bool ParseFrame();
|
||||
bool ParseHierarchy();
|
||||
void Warning(const std::string& message);
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<float> m_animatedComponents;
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace Nz
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(const std::string& message);
|
||||
void Error(std::string_view message);
|
||||
bool ParseJoints();
|
||||
bool ParseMesh();
|
||||
void Warning(const std::string& message);
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Joint> m_joints;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
@@ -22,12 +23,12 @@ namespace Nz
|
||||
MTLParser() = default;
|
||||
~MTLParser() = default;
|
||||
|
||||
inline Material* AddMaterial(const std::string& matName);
|
||||
inline Material* AddMaterial(std::string matName);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline const Material* GetMaterial(const std::string& materialName) const;
|
||||
inline const std::unordered_map<std::string, Material>& GetMaterials() const;
|
||||
inline const Material* GetMaterial(std::string_view materialName) const;
|
||||
inline const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>& GetMaterials() const;
|
||||
|
||||
bool Parse(Stream& stream);
|
||||
|
||||
@@ -60,12 +61,12 @@ namespace Nz
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(const std::string& message);
|
||||
inline void Error(std::string_view message);
|
||||
inline void Flush() const;
|
||||
inline void Warning(const std::string& message);
|
||||
inline void Warning(std::string_view message);
|
||||
inline void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::unordered_map<std::string, Material> m_materials;
|
||||
std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>> m_materials;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline MTLParser::Material* MTLParser::AddMaterial(const std::string& matName)
|
||||
inline MTLParser::Material* MTLParser::AddMaterial(std::string matName)
|
||||
{
|
||||
return &m_materials[matName];
|
||||
return &m_materials[std::move(matName)];
|
||||
}
|
||||
|
||||
inline void MTLParser::Clear()
|
||||
@@ -17,7 +17,7 @@ namespace Nz
|
||||
m_materials.clear();
|
||||
}
|
||||
|
||||
inline const MTLParser::Material* MTLParser::GetMaterial(const std::string& materialName) const
|
||||
inline const MTLParser::Material* MTLParser::GetMaterial(std::string_view materialName) const
|
||||
{
|
||||
auto it = m_materials.find(materialName);
|
||||
if (it != m_materials.end())
|
||||
@@ -26,7 +26,7 @@ namespace Nz
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline const std::unordered_map<std::string, MTLParser::Material>& MTLParser::GetMaterials() const
|
||||
inline auto MTLParser::GetMaterials() const -> const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>&
|
||||
{
|
||||
return m_materials;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace Nz
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void MTLParser::Error(const std::string& message)
|
||||
inline void MTLParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace Nz
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void MTLParser::Warning(const std::string& message)
|
||||
inline void MTLParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ namespace Nz
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(const std::string& message);
|
||||
inline void Error(std::string_view message);
|
||||
inline void Flush() const;
|
||||
inline void Warning(const std::string& message);
|
||||
inline void Warning(std::string_view message);
|
||||
inline bool UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Mesh> m_meshes;
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace Nz
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void OBJParser::Error(const std::string& message)
|
||||
inline void OBJParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace Nz
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void OBJParser::Warning(const std::string& message)
|
||||
inline void OBJParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Nz
|
||||
|
||||
// Save
|
||||
bool SaveToFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
|
||||
bool SaveToStream(Stream& stream, const std::string& format, const ImageParams& params = ImageParams());
|
||||
bool SaveToStream(Stream& stream, std::string_view format, const ImageParams& params = ImageParams());
|
||||
|
||||
//TODO: SaveArray, SaveCubemap, SaveFace
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Nz
|
||||
~Mesh() = default;
|
||||
|
||||
void AddSubMesh(std::shared_ptr<SubMesh> subMesh);
|
||||
void AddSubMesh(const std::string& identifier, std::shared_ptr<SubMesh> subMesh);
|
||||
void AddSubMesh(std::string identifier, std::shared_ptr<SubMesh> subMesh);
|
||||
|
||||
std::shared_ptr<SubMesh> BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
|
||||
void BuildSubMeshes(const PrimitiveList& primitiveList, const MeshParams& params = MeshParams());
|
||||
@@ -123,14 +123,14 @@ namespace Nz
|
||||
std::size_t GetMaterialCount() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
const std::shared_ptr<SubMesh>& GetSubMesh(const std::string& identifier) const;
|
||||
const std::shared_ptr<SubMesh>& GetSubMesh(std::string_view identifier) const;
|
||||
const std::shared_ptr<SubMesh>& GetSubMesh(std::size_t index) const;
|
||||
std::size_t GetSubMeshCount() const;
|
||||
std::size_t GetSubMeshIndex(const std::string& identifier) const;
|
||||
std::size_t GetSubMeshIndex(std::string_view identifier) const;
|
||||
UInt32 GetTriangleCount() const;
|
||||
UInt32 GetVertexCount() const;
|
||||
|
||||
bool HasSubMesh(const std::string& identifier) const;
|
||||
bool HasSubMesh(std::string_view identifier) const;
|
||||
bool HasSubMesh(std::size_t index = 0) const;
|
||||
|
||||
void InvalidateAABB() const;
|
||||
@@ -140,11 +140,11 @@ namespace Nz
|
||||
|
||||
void Recenter();
|
||||
|
||||
void RemoveSubMesh(const std::string& identifier);
|
||||
void RemoveSubMesh(std::string_view identifier);
|
||||
void RemoveSubMesh(std::size_t index);
|
||||
|
||||
bool SaveToFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
|
||||
bool SaveToStream(Stream& stream, const std::string& format, const MeshParams& params = MeshParams());
|
||||
bool SaveToStream(Stream& stream, std::string_view format, const MeshParams& params = MeshParams());
|
||||
|
||||
void SetAnimation(const std::filesystem::path& animationPath);
|
||||
void SetMaterialCount(std::size_t matCount);
|
||||
@@ -175,7 +175,7 @@ namespace Nz
|
||||
};
|
||||
|
||||
std::size_t m_jointCount; // Only used by skeletal meshes
|
||||
std::unordered_map<std::string, std::size_t> m_subMeshMap;
|
||||
std::unordered_map<std::string, std::size_t, StringHash<>, std::equal_to<>> m_subMeshMap;
|
||||
std::vector<ParameterList> m_materialData;
|
||||
std::vector<SubMeshData> m_subMeshes;
|
||||
AnimationType m_animationType;
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace Nz
|
||||
void Destroy();
|
||||
|
||||
const Boxf& GetAABB() const;
|
||||
Joint* GetJoint(const std::string& jointName);
|
||||
Joint* GetJoint(std::string_view jointName);
|
||||
Joint* GetJoint(std::size_t index);
|
||||
const Joint* GetJoint(const std::string& jointName) const;
|
||||
const Joint* GetJoint(std::string_view jointName) const;
|
||||
const Joint* GetJoint(std::size_t index) const;
|
||||
Joint* GetJoints();
|
||||
const Joint* GetJoints() const;
|
||||
std::size_t GetJointCount() const;
|
||||
std::size_t GetJointIndex(const std::string& jointName) const;
|
||||
std::size_t GetJointIndex(std::string_view jointName) const;
|
||||
Joint* GetRootJoint();
|
||||
const Joint* GetRootJoint() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user