Remove const ref std::shared_ptr
Taking a const std::shared_ptr& doesnt make sense, as it doesnt increase the reference count and the object inside the pointer is still modifiable. Return std::shared_ptr by value, returning by reference wont increase the reference count and RVO (return value optimization) makes the const concern moot.
This commit is contained in:
@@ -143,10 +143,10 @@ namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements) :
|
||||
m_elements(elements), m_stride(0)
|
||||
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements)
|
||||
: m_elements(elements), m_stride(0)
|
||||
{
|
||||
this->calculateOffsetsAndStride();
|
||||
calculateOffsetsAndStride();
|
||||
}
|
||||
|
||||
void BufferLayout::calculateOffsetsAndStride()
|
||||
@@ -258,7 +258,7 @@ namespace Inferno {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void VertexArray::addVertexBuffer(const std::shared_ptr<VertexBuffer>& vertexBuffer)
|
||||
void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer)
|
||||
{
|
||||
const auto& layout = vertexBuffer->getLayout();
|
||||
ASSERT(layout.getElements().size(), "VertexBuffer has no layout");
|
||||
@@ -279,18 +279,18 @@ namespace Inferno {
|
||||
|
||||
index++;
|
||||
}
|
||||
m_vertexBuffers.push_back(vertexBuffer);
|
||||
m_vertexBuffers.push_back(std::move(vertexBuffer));
|
||||
|
||||
unbind();
|
||||
vertexBuffer->unbind();
|
||||
}
|
||||
|
||||
void VertexArray::setIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer)
|
||||
void VertexArray::setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer)
|
||||
{
|
||||
bind();
|
||||
indexBuffer->bind();
|
||||
|
||||
m_indexBuffer = indexBuffer;
|
||||
m_indexBuffer = std::move(indexBuffer);
|
||||
|
||||
unbind();
|
||||
indexBuffer->unbind();
|
||||
|
||||
@@ -132,11 +132,11 @@ namespace Inferno {
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
void addVertexBuffer(const std::shared_ptr<VertexBuffer>& vertexBuffer);
|
||||
void setIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer);
|
||||
void addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer);
|
||||
void setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
|
||||
|
||||
inline const std::vector<std::shared_ptr<VertexBuffer>>& getVertexBuffers() const { return m_vertexBuffers; }
|
||||
inline const std::shared_ptr<IndexBuffer>& getIndexBuffer() const { return m_indexBuffer; }
|
||||
inline std::shared_ptr<IndexBuffer> getIndexBuffer() const { return m_indexBuffer; }
|
||||
|
||||
private:
|
||||
uint32_t m_id;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Inferno {
|
||||
{
|
||||
}
|
||||
|
||||
void FontManager::add(const std::string& name, const std::shared_ptr<Font>& font)
|
||||
void FontManager::add(const std::string& name, std::shared_ptr<Font> font)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_fontList.emplace(std::move(name), std::move(font));
|
||||
@@ -146,7 +146,7 @@ namespace Inferno {
|
||||
}
|
||||
}
|
||||
|
||||
void FontManager::remove(const std::shared_ptr<Font>& font)
|
||||
void FontManager::remove(std::shared_ptr<Font> font)
|
||||
{
|
||||
if (exists(font->name())) {
|
||||
m_fontList.erase(font->name());
|
||||
|
||||
@@ -33,10 +33,10 @@ class Texture;
|
||||
|
||||
inline std::string name() const { return m_name; }
|
||||
inline uint32_t size() const { return m_size; }
|
||||
inline const std::shared_ptr<Texture>& texture() const { return m_texture; }
|
||||
inline std::shared_ptr<Texture> texture() const { return m_texture; }
|
||||
|
||||
inline const std::shared_ptr<Character>& get(unsigned char c) const { return m_characterList.at(c); }
|
||||
inline const std::shared_ptr<Character>& operator[](unsigned char c) const { return m_characterList.at(c); }
|
||||
inline std::shared_ptr<Character> get(unsigned char c) const { return m_characterList.at(c); }
|
||||
inline std::shared_ptr<Character> operator[](unsigned char c) const { return m_characterList.at(c); }
|
||||
|
||||
private:
|
||||
void parseFont(const std::string& font);
|
||||
@@ -57,13 +57,13 @@ class Texture;
|
||||
FontManager(s);
|
||||
virtual ~FontManager();
|
||||
|
||||
void add(const std::string& name, const std::shared_ptr<Font>& font);
|
||||
void add(const std::string& name, std::shared_ptr<Font> font);
|
||||
std::shared_ptr<Font> load(const std::string& name);
|
||||
std::shared_ptr<Font> get(const std::string& name);
|
||||
bool exists(const std::string& name);
|
||||
|
||||
void remove(const std::string& name);
|
||||
void remove(const std::shared_ptr<Font>& font);
|
||||
void remove(std::shared_ptr<Font> font);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Font>> m_fontList;
|
||||
|
||||
@@ -134,13 +134,13 @@ namespace Inferno {
|
||||
GltfManager(s) {}
|
||||
virtual ~GltfManager() {}
|
||||
|
||||
void add(const std::string& path, const std::shared_ptr<Gltf>& gltf);
|
||||
void add(const std::string& path, std::shared_ptr<Gltf> gltf);
|
||||
std::shared_ptr<Gltf> load(const std::string& path);
|
||||
std::shared_ptr<Gltf> get(const std::string& path);
|
||||
bool exists(const std::string& path);
|
||||
|
||||
void remove(const std::string& path);
|
||||
void remove(const std::shared_ptr<Gltf>& gltf);
|
||||
void remove(std::shared_ptr<Gltf> gltf);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Gltf>> m_gltfList;
|
||||
|
||||
@@ -36,9 +36,9 @@ namespace Inferno {
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void RenderCommand::drawIndexed(const std::shared_ptr<VertexArray>& vertexArray, uint32_t indexCount)
|
||||
void RenderCommand::drawIndexed(const VertexArray& vertexArray, uint32_t indexCount)
|
||||
{
|
||||
uint32_t count = indexCount ? indexCount : vertexArray->getIndexBuffer()->getCount();
|
||||
uint32_t count = indexCount ? indexCount : vertexArray.getIndexBuffer()->getCount();
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace Inferno {
|
||||
bind();
|
||||
|
||||
// Render
|
||||
RenderCommand::drawIndexed(m_vertexArray, m_quadIndex * indexPerQuad);
|
||||
RenderCommand::drawIndexed(*m_vertexArray, m_quadIndex * indexPerQuad);
|
||||
|
||||
unbind();
|
||||
}
|
||||
@@ -420,7 +420,7 @@ namespace Inferno {
|
||||
// Render
|
||||
bool depthTest = RenderCommand::depthTest();
|
||||
RenderCommand::setDepthTest(false);
|
||||
RenderCommand::drawIndexed(m_vertexArray, m_quadIndex * indexPerQuad);
|
||||
RenderCommand::drawIndexed(*m_vertexArray, m_quadIndex * indexPerQuad);
|
||||
RenderCommand::setDepthTest(depthTest);
|
||||
|
||||
unbind();
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Inferno {
|
||||
|
||||
static void clear();
|
||||
static void clearColor(const glm::vec4& color);
|
||||
static void drawIndexed(const std::shared_ptr<VertexArray>& vertexArray, uint32_t indexCount = 0);
|
||||
static void drawIndexed(const VertexArray& vertexArray, uint32_t indexCount = 0);
|
||||
|
||||
static void setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||
static void setDepthTest(bool enabled);
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Inferno {
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderManager::add(const std::string& name, const std::shared_ptr<Shader>& shader)
|
||||
void ShaderManager::add(const std::string& name, std::shared_ptr<Shader> shader)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_shaderList.emplace(std::move(name), std::move(shader));
|
||||
@@ -243,7 +243,7 @@ namespace Inferno {
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderManager::remove(const std::shared_ptr<Shader>& shader)
|
||||
void ShaderManager::remove(std::shared_ptr<Shader> shader)
|
||||
{
|
||||
if (exists(shader->name())) {
|
||||
m_shaderList.erase(shader->name());
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Inferno {
|
||||
ShaderManager(s);
|
||||
virtual ~ShaderManager();
|
||||
|
||||
void add(const std::string& name, const std::shared_ptr<Shader>& shader);
|
||||
void add(const std::string& name, std::shared_ptr<Shader> shader);
|
||||
std::shared_ptr<Shader> load(const std::string& name);
|
||||
std::shared_ptr<Shader> load(const std::string& vertexSource,
|
||||
const std::string& fragmentSource);
|
||||
@@ -60,7 +60,7 @@ namespace Inferno {
|
||||
bool exists(const std::string& name);
|
||||
|
||||
void remove(const std::string& name);
|
||||
void remove(const std::shared_ptr<Shader>& shader);
|
||||
void remove(std::shared_ptr<Shader> shader);
|
||||
|
||||
protected:
|
||||
std::string computeName(const std::string& vertexSource,
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Inferno {
|
||||
{
|
||||
}
|
||||
|
||||
void TextureManager::add(const std::string& path, const std::shared_ptr<Texture>& texture)
|
||||
void TextureManager::add(const std::string& path, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// Construct (key, value) pair and insert it into the unordered_map
|
||||
m_textureList.emplace(std::move(path), std::move(texture));
|
||||
@@ -146,7 +146,7 @@ namespace Inferno {
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::remove(const std::shared_ptr<Texture>& texture)
|
||||
void TextureManager::remove(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
if (exists(texture->path())) {
|
||||
m_textureList.erase(texture->path());
|
||||
|
||||
@@ -44,13 +44,13 @@ namespace Inferno {
|
||||
TextureManager(s);
|
||||
virtual ~TextureManager();
|
||||
|
||||
void add(const std::string& path, const std::shared_ptr<Texture>& texture);
|
||||
void add(const std::string& path, std::shared_ptr<Texture> texture);
|
||||
std::shared_ptr<Texture> load(const std::string& path);
|
||||
std::shared_ptr<Texture> get(const std::string& path);
|
||||
bool exists(const std::string& path);
|
||||
|
||||
void remove(const std::string& path);
|
||||
void remove(const std::shared_ptr<Texture>& texture);
|
||||
void remove(std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Texture>> m_textureList;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <memory> //std::shared_ptr
|
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
|
||||
@@ -24,7 +25,7 @@ namespace Inferno {
|
||||
|
||||
glm::mat4 projectionView();
|
||||
|
||||
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
void updateOrthographic(TransformComponent& transform, CameraComponent& camera);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Inferno {
|
||||
|
||||
void render();
|
||||
|
||||
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Inferno {
|
||||
|
||||
void update();
|
||||
|
||||
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
|
||||
void setRegistry(std::shared_ptr<entt::registry> registry) { m_registry = registry; };
|
||||
|
||||
private:
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Inferno {
|
||||
inline uint32_t getHeight() const { return m_properties.height; }
|
||||
|
||||
inline GLFWwindow* getWindow() const { return m_window; }
|
||||
inline const std::shared_ptr<Context>& getContext() const { return m_context; }
|
||||
inline std::shared_ptr<Context> getContext() const { return m_context; }
|
||||
|
||||
inline void setEventCallback(const std::function<void(Event&)>& callback) { m_eventCallback = callback; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user