Browse Source

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.
master
Riyyi 4 years ago
parent
commit
0b57ee3a9f
  1. 14
      inferno/src/inferno/render/buffer.cpp
  2. 6
      inferno/src/inferno/render/buffer.h
  3. 4
      inferno/src/inferno/render/font.cpp
  4. 10
      inferno/src/inferno/render/font.h
  5. 4
      inferno/src/inferno/render/gltf.h
  6. 8
      inferno/src/inferno/render/renderer.cpp
  7. 2
      inferno/src/inferno/render/renderer.h
  8. 4
      inferno/src/inferno/render/shader.cpp
  9. 4
      inferno/src/inferno/render/shader.h
  10. 4
      inferno/src/inferno/render/texture.cpp
  11. 4
      inferno/src/inferno/render/texture.h
  12. 5
      inferno/src/inferno/system/camerasystem.h
  13. 2
      inferno/src/inferno/system/rendersystem.h
  14. 2
      inferno/src/inferno/system/transformsystem.h
  15. 2
      inferno/src/inferno/window.h

14
inferno/src/inferno/render/buffer.cpp

@ -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();

6
inferno/src/inferno/render/buffer.h

@ -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;

4
inferno/src/inferno/render/font.cpp

@ -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());

10
inferno/src/inferno/render/font.h

@ -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;

4
inferno/src/inferno/render/gltf.h

@ -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;

8
inferno/src/inferno/render/renderer.cpp

@ -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();

2
inferno/src/inferno/render/renderer.h

@ -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);

4
inferno/src/inferno/render/shader.cpp

@ -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());

4
inferno/src/inferno/render/shader.h

@ -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,

4
inferno/src/inferno/render/texture.cpp

@ -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());

4
inferno/src/inferno/render/texture.h

@ -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;

5
inferno/src/inferno/system/camerasystem.h

@ -3,7 +3,8 @@
#include <memory> //std::shared_ptr
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
#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);

2
inferno/src/inferno/system/rendersystem.h

@ -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;

2
inferno/src/inferno/system/transformsystem.h

@ -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;

2
inferno/src/inferno/window.h

@ -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; }

Loading…
Cancel
Save