Skip to content

Commit

Permalink
Fixed multiple warning issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsimo committed Jan 2, 2015
1 parent abc476e commit b7f46d3
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 42 deletions.
13 changes: 9 additions & 4 deletions src/Asteroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -26,15 +26,20 @@ namespace asteroids
for(int angle = 0; angle < 360; angle+=steps)
{
Vector2 p;
p.SetUnitLengthAndYawDegrees(angle);
p *= (m_radius - Random<int>(1, m_radius * 0.5f));
p.SetUnitLengthAndYawDegrees(static_cast<float>(angle));
int halfRadius = static_cast<int>(m_radius * 0.5f);
float displacement = static_cast<float>(m_radius - Random<int>(1, halfRadius));
p *= displacement;
m_points.push_back(p);
}

// Initialize the velocity
int positiveX = Random<int>(0, 1);
int positiveY = Random<int>(0, 1);
Vector2 dir = Vector2(Random<int>(1, 100), Random<int>(1, 100));
Vector2 dir = Vector2(
static_cast<float>(Random<int>(1, 100)),
static_cast<float>(Random<int>(1, 100))
);
if(!positiveX) dir.x = -dir.x;
if(!positiveY) dir.y = -dir.y;
dir.Normalize();
Expand Down
2 changes: 1 addition & 1 deletion src/Asteroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/AsteroidFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace asteroids

}

Asteroid *AsteroidFactory::Create(AsteroidSize size, int speed)
Asteroid *AsteroidFactory::Create(AsteroidSize size, float speed)
{
switch(size)
{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/AsteroidFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/AsteroidGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{

}
Expand Down
6 changes: 3 additions & 3 deletions src/BitmapFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ bool BitmapFont::LoadGlyphsFromXML(const std::string& filename)
xml_schema::flags::dont_validate));

m_family = static_cast<std::string>(font->family());
m_size = font->size();
m_height = font->height();
m_size = static_cast<int>(font->size());
m_height = static_cast<int>(font->height());
m_style = static_cast<std::string>(font->style());

Font::Char_sequence& cs(font->Char());
Expand All @@ -43,7 +43,7 @@ bool BitmapFont::LoadGlyphsFromXML(const std::string& filename)
std::string code = static_cast<std::string>(ch->code());
std::string offset = static_cast<std::string>(ch->offset());
std::string rect = static_cast<std::string>(ch->rect());
int width = ch->width();
int width = static_cast<int>(ch->width());

BitmapFontGlyph bitmapFontGlyph;
ParseGlyphRect(rect, bitmapFontGlyph.x, bitmapFontGlyph.y,
Expand Down
6 changes: 3 additions & 3 deletions src/Bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -34,7 +34,7 @@ namespace asteroids
for(int angle = 0; angle < 360; angle+=steps)
{
Vector2 p;
p.SetUnitLengthAndYawDegrees(angle);
p.SetUnitLengthAndYawDegrees(static_cast<float>(angle));
p *= BULLET_RADIUS;
m_points.push_back(p);
}
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/Drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void DrawCircle(
GLfloat x,
GLfloat y,
GLfloat radius,
GLfloat sides,
GLuint sides,
GLfloat lineWidth
)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void DrawCircle(
GLfloat x,
GLfloat y,
GLfloat radius = 5,
GLfloat sides = 20,
GLuint sides = 20,
GLfloat lineWidth = 1.f
);

Expand Down
2 changes: 1 addition & 1 deletion src/EnemyShip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace asteroids
}

float amplitude = 2.5f;
m_position.x += Random<int>(5, 10) / 10.0;
m_position.x += Random<int>(5, 10) / 10.f;
Vector2 dir;
dir.SetUnitLengthAndYawDegrees(m_position.x);
m_position.y += amplitude * dir.y;
Expand Down
4 changes: 2 additions & 2 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(m_width);
float bottom = static_cast<float>(m_height);
float top = 0;

glViewport(0, 0, m_width, m_height);
Expand Down
4 changes: 2 additions & 2 deletions src/MathUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/MathUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -622,7 +622,9 @@ namespace asteroids
if(!m_enemyShipRespawnWait)
{
m_enemyShip = new EnemyShip();
m_enemyShip->SetPosition(Vector2(0, Random<int>(0, m_height)));
m_enemyShip->SetPosition(
Vector2(0.f, (float) Random<int>(0, (int) m_height))
);
}
m_enemyShipRespawnWait = std::max(0, m_enemyShipRespawnWait - 1);
} else {
Expand Down Expand Up @@ -684,18 +686,18 @@ namespace asteroids
void World::RenderPlayerScore()
{
int score = m_player->GetScore();
DrawText(20, 20, std::to_string(static_cast<long long>(score)), m_bitmapFont, 0.8);
DrawText(20.f, 20.f, std::to_string(static_cast<long long>(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<int>(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;
}
}
Expand Down

0 comments on commit b7f46d3

Please sign in to comment.