From b7f46d3ca5d22659656f791156e44c1c7a892cdd Mon Sep 17 00:00:00 2001 From: Pavel Simo Date: Fri, 2 Jan 2015 22:50:44 +0800 Subject: [PATCH] Fixed multiple warning issues. --- src/Asteroid.cpp | 13 +++++++++---- src/Asteroid.h | 2 +- src/AsteroidFactory.cpp | 8 ++++---- src/AsteroidFactory.h | 8 ++++---- src/AsteroidGame.cpp | 2 +- src/BitmapFont.cpp | 6 +++--- src/Bullet.cpp | 6 +++--- src/Drawing.cpp | 8 ++++---- src/Drawing.h | 2 +- src/EnemyShip.cpp | 2 +- src/Game.cpp | 4 ++-- src/MathUtilities.cpp | 4 ++-- src/MathUtilities.h | 2 +- src/Player.cpp | 8 ++++---- src/SoundManager.cpp | 2 +- src/World.cpp | 14 ++++++++------ 16 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/Asteroid.cpp b/src/Asteroid.cpp index bbded4c..004ada2 100644 --- a/src/Asteroid.cpp +++ b/src/Asteroid.cpp @@ -5,7 +5,7 @@ namespace asteroids { const float ASTEROID_ROTATION_ANGLE = 1.f; - Asteroid::Asteroid(float radius, int numVertices, int speed) + Asteroid::Asteroid(float radius, int numVertices, float speed) : Actor(), m_radius(radius), m_numVertices(numVertices), @@ -26,15 +26,20 @@ namespace asteroids for(int angle = 0; angle < 360; angle+=steps) { Vector2 p; - p.SetUnitLengthAndYawDegrees(angle); - p *= (m_radius - Random(1, m_radius * 0.5f)); + p.SetUnitLengthAndYawDegrees(static_cast(angle)); + int halfRadius = static_cast(m_radius * 0.5f); + float displacement = static_cast(m_radius - Random(1, halfRadius)); + p *= displacement; m_points.push_back(p); } // Initialize the velocity int positiveX = Random(0, 1); int positiveY = Random(0, 1); - Vector2 dir = Vector2(Random(1, 100), Random(1, 100)); + Vector2 dir = Vector2( + static_cast(Random(1, 100)), + static_cast(Random(1, 100)) + ); if(!positiveX) dir.x = -dir.x; if(!positiveY) dir.y = -dir.y; dir.Normalize(); diff --git a/src/Asteroid.h b/src/Asteroid.h index 1f54b1c..0d72c65 100644 --- a/src/Asteroid.h +++ b/src/Asteroid.h @@ -19,7 +19,7 @@ namespace asteroids class Asteroid : public Actor { public: - Asteroid(float radius, int numVertices, int speed = 2); + Asteroid(float radius, int numVertices, float speed = 2.f); ~Asteroid(); virtual void OnRender() override; virtual void OnUpdate(World &world) override; diff --git a/src/AsteroidFactory.cpp b/src/AsteroidFactory.cpp index d02aaea..08e90e0 100644 --- a/src/AsteroidFactory.cpp +++ b/src/AsteroidFactory.cpp @@ -13,7 +13,7 @@ namespace asteroids } - Asteroid *AsteroidFactory::Create(AsteroidSize size, int speed) + Asteroid *AsteroidFactory::Create(AsteroidSize size, float speed) { switch(size) { @@ -27,7 +27,7 @@ namespace asteroids return nullptr; } - Asteroid *AsteroidFactory::CreateSmallAsteroid(int speed) + Asteroid *AsteroidFactory::CreateSmallAsteroid(float speed) { float radius = 15.0f; int numVertices = 15; @@ -36,7 +36,7 @@ namespace asteroids return asteroid; } - Asteroid *AsteroidFactory::CreateMediumAsteroid(int speed) + Asteroid *AsteroidFactory::CreateMediumAsteroid(float speed) { float radius = 30.0f; int numVertices = 15; @@ -45,7 +45,7 @@ namespace asteroids return asteroid; } - Asteroid *AsteroidFactory::CreateBigAsteroid(int speed) + Asteroid *AsteroidFactory::CreateBigAsteroid(float speed) { float radius = 60.0f; int numVertices = 15; diff --git a/src/AsteroidFactory.h b/src/AsteroidFactory.h index 9ca6634..e521804 100644 --- a/src/AsteroidFactory.h +++ b/src/AsteroidFactory.h @@ -11,10 +11,10 @@ namespace asteroids public: AsteroidFactory(); ~AsteroidFactory(); - Asteroid* Create(AsteroidSize size, int speed = 2); - Asteroid* CreateSmallAsteroid(int speed); - Asteroid* CreateMediumAsteroid(int speed); - Asteroid* CreateBigAsteroid(int speed); + Asteroid* Create(AsteroidSize size, float speed = 2.f); + Asteroid* CreateSmallAsteroid(float speed); + Asteroid* CreateMediumAsteroid(float speed); + Asteroid* CreateBigAsteroid(float speed); }; } diff --git a/src/AsteroidGame.cpp b/src/AsteroidGame.cpp index 0a5d4da..24db6bb 100644 --- a/src/AsteroidGame.cpp +++ b/src/AsteroidGame.cpp @@ -5,7 +5,7 @@ namespace asteroids AsteroidGame::AsteroidGame(const std::string &title, uint32_t width, uint32_t height, uint32_t framesPerSecond) : Game(title, width, height, framesPerSecond), - m_world(new World(width, height)) + m_world(new World((float)width, (float)height)) { } diff --git a/src/BitmapFont.cpp b/src/BitmapFont.cpp index 488c815..2ad6af2 100644 --- a/src/BitmapFont.cpp +++ b/src/BitmapFont.cpp @@ -32,8 +32,8 @@ bool BitmapFont::LoadGlyphsFromXML(const std::string& filename) xml_schema::flags::dont_validate)); m_family = static_cast(font->family()); - m_size = font->size(); - m_height = font->height(); + m_size = static_cast(font->size()); + m_height = static_cast(font->height()); m_style = static_cast(font->style()); Font::Char_sequence& cs(font->Char()); @@ -43,7 +43,7 @@ bool BitmapFont::LoadGlyphsFromXML(const std::string& filename) std::string code = static_cast(ch->code()); std::string offset = static_cast(ch->offset()); std::string rect = static_cast(ch->rect()); - int width = ch->width(); + int width = static_cast(ch->width()); BitmapFontGlyph bitmapFontGlyph; ParseGlyphRect(rect, bitmapFontGlyph.x, bitmapFontGlyph.y, diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 83e659d..50aeb04 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -4,7 +4,7 @@ namespace asteroids { const int BULLET_RADIUS = 3; const int BULLET_VERTEX = 8; - const int BULLET_LINE_WIDTH = 1; + const float BULLET_LINE_WIDTH = 1.f; const int BULLET_LIFE_SPAN = 40; Bullet::Bullet() @@ -34,7 +34,7 @@ namespace asteroids for(int angle = 0; angle < 360; angle+=steps) { Vector2 p; - p.SetUnitLengthAndYawDegrees(angle); + p.SetUnitLengthAndYawDegrees(static_cast(angle)); p *= BULLET_RADIUS; m_points.push_back(p); } @@ -48,6 +48,6 @@ namespace asteroids void Bullet::OnRender() { - DrawPolygon(m_points, m_position.x, m_position.y, 0, BULLET_LINE_WIDTH); + DrawPolygon(m_points, m_position.x, m_position.y, 0.f, BULLET_LINE_WIDTH); } } \ No newline at end of file diff --git a/src/Drawing.cpp b/src/Drawing.cpp index b764b1c..8ac02f4 100644 --- a/src/Drawing.cpp +++ b/src/Drawing.cpp @@ -88,7 +88,7 @@ void DrawCircle( GLfloat x, GLfloat y, GLfloat radius, - GLfloat sides, + GLuint sides, GLfloat lineWidth ) { @@ -125,8 +125,8 @@ void DrawTexture( GLfloat texBottom = (GLfloat)imgHeight / (GLfloat)texHeight; GLfloat texLeft = 0.f; GLfloat texRight = (GLfloat)imgWidth / (GLfloat)texWidth; - GLfloat quadWidth = imgWidth; - GLfloat quadHeight = imgHeight; + GLfloat quadWidth = (GLfloat) imgWidth; + GLfloat quadHeight = (GLfloat) imgHeight; if(clip != NULL) { @@ -182,7 +182,7 @@ void DrawText( GLfloat curX = x; GLfloat curY = y; - for(int i = 0; i < text.size(); ++i) + for(int i = 0; i < (int)text.size(); ++i) { if(text[i] == '\n' || text[i] == '\r') { diff --git a/src/Drawing.h b/src/Drawing.h index 95304df..5faa2a8 100644 --- a/src/Drawing.h +++ b/src/Drawing.h @@ -62,7 +62,7 @@ void DrawCircle( GLfloat x, GLfloat y, GLfloat radius = 5, - GLfloat sides = 20, + GLuint sides = 20, GLfloat lineWidth = 1.f ); diff --git a/src/EnemyShip.cpp b/src/EnemyShip.cpp index 9d5d07d..3f5b45a 100644 --- a/src/EnemyShip.cpp +++ b/src/EnemyShip.cpp @@ -28,7 +28,7 @@ namespace asteroids } float amplitude = 2.5f; - m_position.x += Random(5, 10) / 10.0; + m_position.x += Random(5, 10) / 10.f; Vector2 dir; dir.SetUnitLengthAndYawDegrees(m_position.x); m_position.y += amplitude * dir.y; diff --git a/src/Game.cpp b/src/Game.cpp index 25de649..2da8507 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -69,8 +69,8 @@ bool Game::Init() // GL ORTHOGRAPHIC PROJECTION // float left = 0; - float right = m_width; - float bottom = m_height; + float right = static_cast(m_width); + float bottom = static_cast(m_height); float top = 0; glViewport(0, 0, m_width, m_height); diff --git a/src/MathUtilities.cpp b/src/MathUtilities.cpp index f500165..9d543eb 100644 --- a/src/MathUtilities.cpp +++ b/src/MathUtilities.cpp @@ -7,12 +7,12 @@ int32 RoundToInt(real x) real Deg2Rad(real degrees) { - return degrees * (PI / 180.0); + return degrees * (PI / 180.f); } real Rad2Deg(real rad) { - return rad * (180.0 / PI); + return rad * (180.f / PI); } boolean IsPowerOf2(int32 x) diff --git a/src/MathUtilities.h b/src/MathUtilities.h index cecde23..4276323 100644 --- a/src/MathUtilities.h +++ b/src/MathUtilities.h @@ -9,7 +9,7 @@ typedef float real; typedef int32_t int32; typedef bool boolean; -const real EPS = 1e-6; +const real EPS = 0.000001f; const real PI = 3.14159265358979f; int32 RoundToInt(real x); diff --git a/src/Player.cpp b/src/Player.cpp index 69c966f..cb34660 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -5,8 +5,8 @@ namespace asteroids { const float PLAYER_ROTATION_ANGLE = 3.0f; // degrees const float PLAYER_MAX_SPEED = 6.f; - const float PLAYER_SHOOT_TIMEOUT = 20; - const float PLAYER_DRAG = 0.999; + const int PLAYER_SHOOT_TIMEOUT = 20; + const float PLAYER_DRAG = 0.999f; Player::Player() : m_score(0) @@ -23,8 +23,8 @@ namespace asteroids void Player::Initialize() { m_angle = 180; - m_vel = Vector2(0, 0); - m_accel = Vector2(0.04, 0.04); + m_vel = Vector2(0.f, 0.f); + m_accel = Vector2(0.04f, 0.04f); m_direction.SetUnitLengthAndYawDegrees(m_angle); m_upright.SetUnitLengthAndYawDegrees(m_angle + 90); m_state = 0; diff --git a/src/SoundManager.cpp b/src/SoundManager.cpp index 494bd4a..cbd699f 100644 --- a/src/SoundManager.cpp +++ b/src/SoundManager.cpp @@ -311,7 +311,7 @@ bool SoundManager::StopAll() alGetError(); - for(int i = 0; i < m_audioSourcesCount; ++i) + for(int i = 0; i < (int)m_audioSourcesCount; ++i) { Stop(i); } diff --git a/src/World.cpp b/src/World.cpp index 19a34cf..6e8886a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -447,7 +447,7 @@ namespace asteroids m_soundManager->Play(SOUND_BIG_ASTEROID_BANG, true); for(int i = 0; i < numAsteroids; ++i) { - Asteroid* mediumAsteroid = m_asteroidFactory.CreateMediumAsteroid(speed); + Asteroid* mediumAsteroid = m_asteroidFactory.CreateMediumAsteroid((float)speed); mediumAsteroid->SetPosition(asteroid.GetPosition()); m_asteroids.push_back(mediumAsteroid); } @@ -456,7 +456,7 @@ namespace asteroids m_soundManager->Play(SOUND_MEDIUM_ASTEROID_BANG, true); for(int i = 0; i < numAsteroids; ++i) { - Asteroid* smallAsteroid = m_asteroidFactory.CreateSmallAsteroid(speed); + Asteroid* smallAsteroid = m_asteroidFactory.CreateSmallAsteroid((float)speed); smallAsteroid->SetPosition(asteroid.GetPosition()); m_asteroids.push_back(smallAsteroid); } @@ -622,7 +622,9 @@ namespace asteroids if(!m_enemyShipRespawnWait) { m_enemyShip = new EnemyShip(); - m_enemyShip->SetPosition(Vector2(0, Random(0, m_height))); + m_enemyShip->SetPosition( + Vector2(0.f, (float) Random(0, (int) m_height)) + ); } m_enemyShipRespawnWait = std::max(0, m_enemyShipRespawnWait - 1); } else { @@ -684,18 +686,18 @@ namespace asteroids void World::RenderPlayerScore() { int score = m_player->GetScore(); - DrawText(20, 20, std::to_string(static_cast(score)), m_bitmapFont, 0.8); + DrawText(20.f, 20.f, std::to_string(static_cast(score)), m_bitmapFont, 0.8f); } void World::RenderPlayerLifes() { PointList pts = m_player->GetPoints(); int lifes = m_player->GetLifes(); - int x = m_width - 100; + int x = static_cast(m_width - 100); int y = 40; for(int i = 0; i < lifes; ++i) { - DrawPolygon(pts, x, y, 180); + DrawPolygon(pts, (float)x, (float)y, 180.f); x += 30; } }