From bfc679d02e1d1c9597a8aca814bf1579c6fdffc5 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Wed, 22 Mar 2023 22:18:32 +0100
Subject: [PATCH] Fix several compiler warnings

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/fire_works/src/main.cpp              | 12 +++----
 projects/particle_simulation/src/Particle.cpp | 16 +++++-----
 projects/particle_simulation/src/Particle.hpp | 32 +++++++++++--------
 projects/sph/src/Particle.hpp                 |  2 +-
 projects/sph/src/main.cpp                     | 19 ++++++-----
 src/vkcv/AccelerationStructureManager.hpp     |  1 +
 src/vkcv/DescriptorSetManager.hpp             |  3 +-
 src/vkcv/ImageManager.hpp                     |  1 +
 8 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/projects/fire_works/src/main.cpp b/projects/fire_works/src/main.cpp
index aa23f74a..ef1a66bf 100644
--- a/projects/fire_works/src/main.cpp
+++ b/projects/fire_works/src/main.cpp
@@ -85,18 +85,16 @@ struct draw_smoke_t {
 #define POINT_COUNT (2048 * 256)
 
 void InitializeParticles(std::vector<particle_t> &particles) {
-	for (size_t i = 0; i < particles.size(); i++) {
-		particle_t particle;
-		particle.position = glm::vec3(2.0f * (std::rand() % RAND_MAX) / RAND_MAX - 1.0f,
-									  2.0f * (std::rand() % RAND_MAX) / RAND_MAX - 1.0f,
-									  2.0f * (std::rand() % RAND_MAX) / RAND_MAX - 1.0f);
+	const auto rand_max = static_cast<float>(RAND_MAX);
+	for (auto& particle : particles) {
+		particle.position = glm::vec3(2.0f * (std::rand() % RAND_MAX) / rand_max - 1.0f,
+									  2.0f * (std::rand() % RAND_MAX) / rand_max - 1.0f,
+									  2.0f * (std::rand() % RAND_MAX) / rand_max - 1.0f);
 
 		particle.lifetime = 0.0f;
 		particle.velocity = glm::vec3(0.0f);
 		particle.size = 0.01f;
 		particle.color = glm::vec3(1.0f, 0.0f, 0.0f);
-
-		particles [i] = particle;
 	}
 }
 
diff --git a/projects/particle_simulation/src/Particle.cpp b/projects/particle_simulation/src/Particle.cpp
index b80d063d..5e726cee 100644
--- a/projects/particle_simulation/src/Particle.cpp
+++ b/projects/particle_simulation/src/Particle.cpp
@@ -9,34 +9,34 @@ Particle::Particle(glm::vec3 position, glm::vec3 velocity, float lifeTime)
   m_reset_velocity(velocity)
 {}
 
-const glm::vec3& Particle::getPosition()const{
+const glm::vec3& Particle::getPosition() const {
     return m_position;
 }
 
-bool Particle::isAlive()const{
+bool Particle::isAlive() const {
     return m_lifeTime > 0.f;
 }
 
-void Particle::setPosition( const glm::vec3 pos ){
+void Particle::setPosition(const glm::vec3& pos) {
     m_position = pos;
 }
 
-const glm::vec3& Particle::getVelocity()const{
+const glm::vec3& Particle::getVelocity() const {
     return m_velocity;
 }
 
-void Particle::setVelocity( const glm::vec3 vel ){
+void Particle::setVelocity(const glm::vec3& vel) {
     m_velocity = vel;
 }
 
-void Particle::update( const float delta ){
+void Particle::update(float delta) {
     m_position += m_velocity * delta;
 }
 
-void Particle::setLifeTime( const float lifeTime ){
+void Particle::setLifeTime(float lifeTime) {
     m_lifeTime = lifeTime;
 }
 
-const float& Particle::getLifeTime()const{
+float Particle::getLifeTime() const {
     return m_lifeTime;
 }
\ No newline at end of file
diff --git a/projects/particle_simulation/src/Particle.hpp b/projects/particle_simulation/src/Particle.hpp
index 73e7cbf5..35d39dac 100644
--- a/projects/particle_simulation/src/Particle.hpp
+++ b/projects/particle_simulation/src/Particle.hpp
@@ -6,29 +6,33 @@ class Particle {
 
 public:
     Particle(glm::vec3 position, glm::vec3 velocity, float lifeTime = 1.f);
+	
+	[[nodiscard]]
+    const glm::vec3& getPosition() const;
 
-    const glm::vec3& getPosition()const;
+    void setPosition(const glm::vec3& pos);
+	
+	[[nodiscard]]
+    const glm::vec3& getVelocity() const;
 
-    void setPosition( const glm::vec3 pos );
+    void setVelocity(const glm::vec3& vel);
 
-    const glm::vec3& getVelocity()const;
+    void update(float delta);
 
-    void setVelocity( const glm::vec3 vel );
+    [[nodiscard]]
+	bool isAlive() const;
 
-    void update( const float delta );
-
-    bool isAlive()const;
-
-    void setLifeTime( const float lifeTime );
-
-    const float& getLifeTime()const;
+    void setLifeTime(float lifeTime);
+	
+	[[nodiscard]]
+	float getLifeTime() const;
 
 private:
     // all properties of the Particle
     glm::vec3 m_position;
     float m_lifeTime;
     glm::vec3 m_velocity;
-    float m_mass;
-    glm::vec3 m_reset_velocity;
-    float padding_3;
+	[[maybe_unused]] float m_mass;
+	[[maybe_unused]] glm::vec3 m_reset_velocity;
+	[[maybe_unused]] float m_padding;
 };
diff --git a/projects/sph/src/Particle.hpp b/projects/sph/src/Particle.hpp
index 6c4ab50b..c94f484b 100644
--- a/projects/sph/src/Particle.hpp
+++ b/projects/sph/src/Particle.hpp
@@ -26,7 +26,7 @@ public:
 private:
     // all properties of the Particle
     glm::vec3 m_position;
-    float m_padding1;
+	[[maybe_unused]] [[maybe_unused]] float m_padding;
     glm::vec3 m_velocity;
     float m_density;
     glm::vec3 m_force;
diff --git a/projects/sph/src/main.cpp b/projects/sph/src/main.cpp
index dff31b8a..3d8cf078 100644
--- a/projects/sph/src/main.cpp
+++ b/projects/sph/src/main.cpp
@@ -136,25 +136,28 @@ int main(int argc, const char **argv) {
             vkcv::BufferType::UNIFORM,
             1
     );
+	
+	const float rand_max = static_cast<float>(RAND_MAX);
 
     // generating particles
     int numberParticles = 20000;
     std::vector<Particle> particles;
+	particles.reserve(numberParticles);
+	
     for (int i = 0; i < numberParticles; i++) {
         const float lo = 0.6;
         const float hi = 0.9;
         const float vlo = 0;
         const float vhi = 70;
-        float x = lo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(hi-lo)));
-        float y = lo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(hi-lo)));
-        float z = lo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(hi-lo)));
-        float vx = vlo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(vhi-vlo)));
-        float vy = vlo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(vhi-vlo)));
-        float vz = vlo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(vhi-vlo)));
+        float x = lo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(hi-lo)));
+        float y = lo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(hi-lo)));
+        float z = lo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(hi-lo)));
+        float vx = vlo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(vhi-vlo)));
+        float vy = vlo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(vhi-vlo)));
+        float vz = vlo + static_cast <float> (rand()) /( static_cast <float> (rand_max/(vhi-vlo)));
         glm::vec3 pos = glm::vec3(x,y,z);
         glm::vec3 vel = glm::vec3(vx,vy,vz);
-        //glm::vec3 vel = glm::vec3(0.0,0.0,0.0);
-        particles.push_back(Particle(pos, vel));
+        particles.emplace_back(pos, vel);
     }
 
     // creating and filling particle buffer
diff --git a/src/vkcv/AccelerationStructureManager.hpp b/src/vkcv/AccelerationStructureManager.hpp
index 2a8a6901..062a1bcf 100644
--- a/src/vkcv/AccelerationStructureManager.hpp
+++ b/src/vkcv/AccelerationStructureManager.hpp
@@ -37,6 +37,7 @@ namespace vkcv {
 	private:
 		BufferManager* m_bufferManager;
 		
+		using HandleManager<AccelerationStructureEntry, AccelerationStructureHandle>::init;
 		bool init(Core &core, BufferManager &bufferManager);
 		
 		[[nodiscard]] uint64_t getIdFrom(const AccelerationStructureHandle &handle) const override;
diff --git a/src/vkcv/DescriptorSetManager.hpp b/src/vkcv/DescriptorSetManager.hpp
index 5dbdc954..4b0d307b 100644
--- a/src/vkcv/DescriptorSetManager.hpp
+++ b/src/vkcv/DescriptorSetManager.hpp
@@ -38,7 +38,8 @@ namespace vkcv {
 		Vector<vk::DescriptorPool> m_Pools;
 		Vector<vk::DescriptorPoolSize> m_PoolSizes;
 		vk::DescriptorPoolCreateInfo m_PoolInfo;
-
+		
+		using HandleManager<DescriptorSetEntry, DescriptorSetHandle>::init;
 		bool init(Core &core, DescriptorSetLayoutManager &descriptorSetLayoutManager);
 
 		[[nodiscard]] uint64_t getIdFrom(const DescriptorSetHandle &handle) const override;
diff --git a/src/vkcv/ImageManager.hpp b/src/vkcv/ImageManager.hpp
index d334c59b..123c972a 100644
--- a/src/vkcv/ImageManager.hpp
+++ b/src/vkcv/ImageManager.hpp
@@ -54,6 +54,7 @@ namespace vkcv {
 		Vector<ImageEntry> m_swapchainImages;
 		int m_currentSwapchainInputImage;
 
+		using HandleManager<ImageEntry, ImageHandle>::init;
 		bool init(Core &core, BufferManager &bufferManager);
 
 		[[nodiscard]] uint64_t getIdFrom(const ImageHandle &handle) const override;
-- 
GitLab