From 277111a678528f36f06ea2ab293c21f647062ecf Mon Sep 17 00:00:00 2001 From: Tamir Atias Date: Fri, 30 Dec 2011 03:16:32 +0200 Subject: [PATCH] [FIX] Fixed warnings. --- Win32/Unuk/LibUnuk/LibUnuk.vcproj | 6 +-- Win32/Unuk/Unuk/Unuk.vcproj | 4 +- src/Unuk/Game.cpp | 2 +- src/Unuk/Player.cpp | 8 ++-- src/Unuk/main.cpp | 2 +- src/libUnuk/ApplySurface.cpp | 8 ++-- src/libUnuk/Character.cpp | 62 +++++++++++++++---------------- src/libUnuk/Debug.cpp | 2 +- src/libUnuk/Input.cpp | 2 +- src/libUnuk/MainMenu.cpp | 4 +- src/libUnuk/Map.cpp | 4 +- src/libUnuk/NPC.cpp | 2 +- src/libUnuk/ParticleEmitter.cpp | 18 ++++----- src/libUnuk/Rect.cpp | 20 +++++----- src/libUnuk/Texture.cpp | 2 +- 15 files changed, 74 insertions(+), 72 deletions(-) diff --git a/Win32/Unuk/LibUnuk/LibUnuk.vcproj b/Win32/Unuk/LibUnuk/LibUnuk.vcproj index 6150252..171c9e2 100644 --- a/Win32/Unuk/LibUnuk/LibUnuk.vcproj +++ b/Win32/Unuk/LibUnuk/LibUnuk.vcproj @@ -42,12 +42,12 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\..\..\src\Libs\;..\..\Dependencies\Include\" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" DebugInformationFormat="4" /> GetText()); // - _player->SetXY(playerX, playerY); + _player->SetXY((float)playerX, (float)playerY); // - Parse the map file. dataElem = dataElem->NextSiblingElement("map"); diff --git a/src/Unuk/Player.cpp b/src/Unuk/Player.cpp index 7ae1f12..c49b686 100644 --- a/src/Unuk/Player.cpp +++ b/src/Unuk/Player.cpp @@ -1,7 +1,7 @@ #include "Player.h" // Pixels * 60 / sec. -const float Player::PLAYER_SPEED = Character::CHARACTER_SPEED + 0.5; +const float Player::PLAYER_SPEED = Character::CHARACTER_SPEED + 0.5f; Player::Player(Map *mapArg) : Character(mapArg) { @@ -68,8 +68,8 @@ void Player::SetName(string nameArg) { } void Player::SetCamera(void) { - camera.x = (x + w / 2) - SCREEN_WIDTH / 2; - camera.y = (y + h / 2) - SCREEN_HEIGHT / 2; + camera.x = (Sint16)((x + w / 2) - SCREEN_WIDTH / 2); + camera.y = (Sint16)((y + h / 2) - SCREEN_HEIGHT / 2); if(camera.x < 0) camera.x = 0; @@ -85,7 +85,7 @@ void Player::SetCamera(void) { void Player::Move() { Character::Move(); if(map->GetMapTransitionName(tileX, tileY) != "null") { - SetXY(map->GetMapTransitionX(tileX, tileY), map->GetMapTransitionY(tileX, tileY)); + SetXY((float)map->GetMapTransitionX(tileX, tileY), (float)map->GetMapTransitionY(tileX, tileY)); map->Load(map->GetMapTransitionName(tileX, tileY)); } } diff --git a/src/Unuk/main.cpp b/src/Unuk/main.cpp index cadfee1..659f259 100644 --- a/src/Unuk/main.cpp +++ b/src/Unuk/main.cpp @@ -42,7 +42,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE); SDL_WM_SetCaption("fps - 00", NULL); - srand(time(NULL)); + srand((unsigned int)time(NULL)); camera.x = 0; camera.y = 0; diff --git a/src/libUnuk/ApplySurface.cpp b/src/libUnuk/ApplySurface.cpp index 626a538..b6b88c8 100644 --- a/src/libUnuk/ApplySurface.cpp +++ b/src/libUnuk/ApplySurface.cpp @@ -5,8 +5,8 @@ void ApplySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination, S SDL_Rect offset; - offset.x = x - camera.x; - offset.y = y - camera.y; + offset.x = (Sint16)(x - camera.x); + offset.y = (Sint16)(y - camera.y); SDL_BlitSurface(source, clip, destination, &offset); } @@ -16,8 +16,8 @@ void ApplySurfaceLiteral(int x, int y, SDL_Surface* source, SDL_Surface* destina SDL_Rect offset; - offset.x = x; - offset.y = y; + offset.x = (Sint16)x; + offset.y = (Sint16)y; SDL_BlitSurface(source, clip, destination, &offset); } diff --git a/src/libUnuk/Character.cpp b/src/libUnuk/Character.cpp index 9bc7f6b..f8bb9c2 100644 --- a/src/libUnuk/Character.cpp +++ b/src/libUnuk/Character.cpp @@ -39,15 +39,15 @@ void Character::LoadSprites(string filename, int wArg, int hArg) { _texture = LoadImageAlpha(filename.c_str()); - w = wArg; - h = hArg; + w = (float)wArg; + h = (float)hArg; for(int m_direction = 0; m_direction < 4; m_direction++) { for(int m_action = 0; m_action < 4; m_action++) { - _sprites[m_direction][m_action].x = w * m_action; - _sprites[m_direction][m_action].y = h * m_direction; - _sprites[m_direction][m_action].w = w; - _sprites[m_direction][m_action].h = h; + _sprites[m_direction][m_action].x = (Sint16)(w * m_action); + _sprites[m_direction][m_action].y = (Sint16)(h * m_direction); + _sprites[m_direction][m_action].w = (Sint16)w; + _sprites[m_direction][m_action].h = (Sint16)h; } } } @@ -65,33 +65,33 @@ void Character::Render(void) { // Draw some fancy speach bubbles. It is a bit of a mess, I am playing. if(_speachBubble.size() != 0) { if(_speachBubbleTimer.GetTicks() < SPEACH_BUBBLE_DISPLAY_LENGTH) { - roundedBoxRGBA(screen, (x + w / 2) - 100 - camera.x, - y - 100 - camera.y, - (x + w / 2) + 100 - camera.x, - y - 35 - camera.y, + roundedBoxRGBA(screen, (Sint16)((x + w / 2) - 100 - camera.x), + (Sint16)(y - 100 - camera.y), + (Sint16)((x + w / 2) + 100 - camera.x), + (Sint16)(y - 35 - camera.y), 5, 255, 255, 255, 255); - filledTrigonRGBA(screen, (x + w / 2) - 100 - camera.x, - y - 100 - camera.y, - (x + w / 2) - 10 - camera.x, - y - 40 - camera.y, - (x + w / 2) + 10 - camera.x, - y - 40 - camera.y, + filledTrigonRGBA(screen, (Sint16)((x + w / 2) - 100 - camera.x), + (Sint16)(y - 100 - camera.y), + (Sint16)((x + w / 2) - 10 - camera.x), + (Sint16)(y - 40 - camera.y), + (Sint16)((x + w / 2) + 10 - camera.x), + (Sint16)(y - 40 - camera.y), 255, 255, 255, 255); - _speachBubbleText.Render((x + w / 2) - 90, y - 90); + _speachBubbleText.Render((int)((x + w / 2) - 90), (int)y - 90); } } if(attacking && attackTimer.GetTicks() < ATTACKING_DISPLAY_LEN) { - ApplySurface(x, y, _texture, screen, &_sprites[directionFacing][ANIM_ATTACK]); + ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_ATTACK]); return; } else if(attacking) attacking = false; if(xVel == 0.0f && yVel == 0.0f) - ApplySurface(x, y, _texture, screen, &_sprites[directionFacing][ANIM_NO_FOOT]); + ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][ANIM_NO_FOOT]); else { if(_animationTimer.GetTicks() > ANIMATION_SPEED) { if(_animationStage == ANIM_NO_FOOT) { @@ -110,7 +110,7 @@ void Character::Render(void) { } _animationTimer.Start(); } - ApplySurface(x, y, _texture, screen, &_sprites[directionFacing][_animationStage]); + ApplySurface((int)x, (int)y, _texture, screen, &_sprites[directionFacing][_animationStage]); } } @@ -134,8 +134,8 @@ void Character::Update(void) { void Character::Move(void) { x += xVel; - tileX = ((x + (w / 2)) / TILE_WIDTH); - tileY = ((y + (h / 2)) / TILE_HEIGHT); + tileX = (int)(((x + (w / 2)) / TILE_WIDTH)); + tileY = (int)(((y + (h / 2)) / TILE_HEIGHT)); // Check collisions. if((x < 0) || (x + w) > levelWidth) x -= xVel; @@ -144,8 +144,8 @@ void Character::Move(void) { if(CheckCharacterCollisions()) x -= xVel; y += yVel; - tileX = ((x + (w / 2)) / TILE_WIDTH); - tileY = ((y + (h / 2)) / TILE_HEIGHT); + tileX = (int)(((x + (w / 2)) / TILE_WIDTH)); + tileY = (int)(((y + (h / 2)) / TILE_HEIGHT)); if((y < 0) || (y + h) > levelHeight) y -= yVel; if(CheckTileCollisions()) y -= yVel; @@ -162,7 +162,7 @@ bool Character::CheckTileCollisions(void) { for(int i = -1; i < 2; i++) { for(int j = -1; j < 2; j++) { if(map->GetTileSolidity(tileX + i, tileY + j)) - if(CheckCollisionXY(x, y, w, h, map->GetTileX(tileX + i, tileY + j), + if(CheckCollisionXY((int)x, (int)y, (int)w, (int)h, map->GetTileX(tileX + i, tileY + j), map->GetTileY(tileX + i, tileY + j), TILE_WIDTH, TILE_HEIGHT)) return true; } @@ -174,7 +174,7 @@ bool Character::CheckEntityCollisions(void) { for(int i = -1; i < 2; i++) { for(int j = -1; j < 2; j++) { if(map->GetEntitySolidity(tileX + i, tileY + j)) { - if(CheckCollisionXY(x, y, w, h, map->GetEntityX(tileX + i, tileY + j), + if(CheckCollisionXY((int)x, (int)y, (int)w, (int)h, map->GetEntityX(tileX + i, tileY + j), map->GetEntityY(tileX + i, tileY + j), map->GetEntityWidth(tileX + i, tileY + j), map->GetEntityHeight(tileX + i, tileY + j))) @@ -190,11 +190,11 @@ bool Character::CheckCharacterCollisions(void) { collisionIter != collisionList.end(); collisionIter++) { if((*collisionIter) != this) { - if(CheckCollisionXY(x, y, w, h, - (*collisionIter)->GetX(), - (*collisionIter)->GetY(), - (*collisionIter)->GetWidth(), - (*collisionIter)->GetHeight())) { + if(CheckCollisionXY((int)x, (int)y, (int)w, (int)h, + (int)(*collisionIter)->GetX(), + (int)(*collisionIter)->GetY(), + (int)(*collisionIter)->GetWidth(), + (int)(*collisionIter)->GetHeight())) { return true; } } diff --git a/src/libUnuk/Debug.cpp b/src/libUnuk/Debug.cpp index 04d5dd1..db6a8b6 100644 --- a/src/libUnuk/Debug.cpp +++ b/src/libUnuk/Debug.cpp @@ -63,7 +63,7 @@ void Debug::message(const char *msg, ...) { va_start(vargList, msg); #if defined WIN32 - outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList); + outLen = (unsigned short)_vsnprintf(outBuf, sizeof(outBuf), msg, vargList); #else outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList); #endif diff --git a/src/libUnuk/Input.cpp b/src/libUnuk/Input.cpp index 75ef423..a99b5d3 100644 --- a/src/libUnuk/Input.cpp +++ b/src/libUnuk/Input.cpp @@ -58,7 +58,7 @@ void UpdateInput(void) { char GetKey(void) { if(keyboard.lastChar != -1) - return keyboard.lastChar; + return (char)keyboard.lastChar; return 0; } diff --git a/src/libUnuk/MainMenu.cpp b/src/libUnuk/MainMenu.cpp index 954c9db..95f06d0 100644 --- a/src/libUnuk/MainMenu.cpp +++ b/src/libUnuk/MainMenu.cpp @@ -62,7 +62,8 @@ MainMenu::~MainMenu(void) { mainMenuNavVal_t MainMenu::Run(void) { FPS fpsLimiter(20); - while(1) { + bool running = true; + while(running) { Render(); SDL_Flip(screen); @@ -103,6 +104,7 @@ mainMenuNavVal_t MainMenu::Run(void) { fpsLimiter.LimitFPS(); } + return mainMenuExitGame; } void MainMenu::Render(void) { diff --git a/src/libUnuk/Map.cpp b/src/libUnuk/Map.cpp index d719516..5d760f5 100644 --- a/src/libUnuk/Map.cpp +++ b/src/libUnuk/Map.cpp @@ -104,13 +104,13 @@ void Map::Load(const string filename) { // dataElem = dataElem->NextSiblingElement("mapTransX"); assert(dataElem != NULL); - int mapTransX = atoi(dataElem->GetText()); + // int mapTransX = atoi(dataElem->GetText()); // not referenced // // dataElem = dataElem->NextSiblingElement("mapTransY"); assert(dataElem != NULL); - int mapTransY = atoi(dataElem->GetText()); + // int mapTransY = atoi(dataElem->GetText()); // not referenced // tileElem = tileElem->NextSiblingElement("tile"); diff --git a/src/libUnuk/NPC.cpp b/src/libUnuk/NPC.cpp index ed32ddf..37fa4d7 100644 --- a/src/libUnuk/NPC.cpp +++ b/src/libUnuk/NPC.cpp @@ -14,7 +14,7 @@ NPC::~NPC(void) { void NPC::Update(void) { // Store the NPC's health. - int health = GetHealth(); + // int health = GetHealth(); // not referenced Move(); diff --git a/src/libUnuk/ParticleEmitter.cpp b/src/libUnuk/ParticleEmitter.cpp index 6d1db9f..b029fab 100644 --- a/src/libUnuk/ParticleEmitter.cpp +++ b/src/libUnuk/ParticleEmitter.cpp @@ -15,8 +15,8 @@ void ParticleEmitter::SetXY(int xArg, int yArg) { void ParticleEmitter::ForceXY(int xArg, int yArg) { for(int i = 0; i < _particleCount; i++) { - m_particle[i].x = xArg; - m_particle[i].y = yArg; + m_particle[i].x = (float)xArg; + m_particle[i].y = (float)yArg; } } @@ -52,7 +52,7 @@ void ParticleEmitter::SetParticleLifetime(int lifetimeArg) { void ParticleEmitter::Render(void) { for(int i = 0; i < _particleCount; i++) { - ApplySurface(m_particle[i].x, m_particle[i].y, _particleTexture, screen); + ApplySurface((int)m_particle[i].x, (int)m_particle[i].y, _particleTexture, screen); } } @@ -60,16 +60,16 @@ void ParticleEmitter::Update(void) { for(int i = 0; i < _particleCount; i++) { if((int)SDL_GetTicks() - m_particle[i].startTime > m_particle[i].lifetime) { // Reset the x and y coords. - m_particle[i].x = x; - m_particle[i].y = y; + m_particle[i].x = (float)x; + m_particle[i].y = (float)y; - m_particle[i].xVel = rand() % 360; - m_particle[i].yVel = rand() % 360; + m_particle[i].xVel = (float)(rand() % 360); + m_particle[i].yVel = (float)(rand() % 360); if(rand() % 2) - m_particle[i].xVel = m_particle[i].xVel * -1; + m_particle[i].xVel = m_particle[i].xVel * -1.0f; if(rand() % 2) - m_particle[i].yVel = m_particle[i].yVel * -1; + m_particle[i].yVel = m_particle[i].yVel * -1.0f; m_particle[i].startTime = SDL_GetTicks(); } else { diff --git a/src/libUnuk/Rect.cpp b/src/libUnuk/Rect.cpp index 45bb779..818642d 100644 --- a/src/libUnuk/Rect.cpp +++ b/src/libUnuk/Rect.cpp @@ -7,13 +7,13 @@ Rect::~Rect(void) { } void Rect::SetXY(int xArg, int yArg) { - rect.x = xArg; - rect.y = yArg; + rect.x = (Sint16)xArg; + rect.y = (Sint16)yArg; } void Rect::SetWidthHeight(int wArg, int hArg) { - rect.w = wArg; - rect.h = hArg; + rect.w = (Uint16)wArg; + rect.h = (Uint16)hArg; } void Rect::SetRGB(Uint8 rArg, Uint8 gArg, Uint8 bArg) { @@ -42,10 +42,10 @@ void Rect::Draw(void) { void Rect::Draw(int xArg, int yArg) { SDL_Rect offset; - offset.x = xArg - camera.x; - offset.y = yArg - camera.y; - offset.w = rect.w; - offset.h = rect.h; + offset.x = (Sint16)(xArg - camera.x); + offset.y = (Sint16)(yArg - camera.y); + offset.w = (Sint16)rect.w; + offset.h = (Sint16)rect.h; } void Rect::DrawLiteral(void) { @@ -55,8 +55,8 @@ void Rect::DrawLiteral(void) { void Rect::DrawLiteral(int xArg, int yArg) { SDL_Rect offset; - offset.x = xArg; - offset.y = yArg; + offset.x = (Sint16)xArg; + offset.y = (Sint16)yArg; offset.w = rect.w; offset.h = rect.h; diff --git a/src/libUnuk/Texture.cpp b/src/libUnuk/Texture.cpp index f099af6..5a0a11c 100644 --- a/src/libUnuk/Texture.cpp +++ b/src/libUnuk/Texture.cpp @@ -49,5 +49,5 @@ void Texture::LoadAlpha(const char* filename) { } void Texture::SetAlpha(int alphaArg) { - SDL_SetAlpha(_texture, SDL_SRCALPHA, alphaArg); + SDL_SetAlpha(_texture, SDL_SRCALPHA, (Uint8)alphaArg); }