From ee88e805b35f4087a126856f27264133bced1212 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 5 Feb 2019 22:51:44 +0000 Subject: [PATCH] Fix some errors and prevent some GCC warnings --- src/BossOhm.cpp | 2 ++ src/Bullet.cpp | 2 +- src/Caret.cpp | 2 +- src/Draw.cpp | 4 ++-- src/Font.cpp | 4 ++-- src/Frame.cpp | 5 +++-- src/Game.cpp | 6 +++--- src/NpcAct000.cpp | 2 +- src/NpcAct020.cpp | 2 +- src/NpcAct040.cpp | 2 ++ src/NpcAct060.cpp | 2 +- src/NpcAct140.cpp | 6 ++++++ src/NpcAct200.cpp | 4 ++-- src/NpcAct280.cpp | 2 ++ src/NpcTbl.cpp | 2 +- src/Organya.cpp | 2 +- src/Sound.cpp | 32 ++------------------------------ src/TextScr.cpp | 1 - src/ValueView.cpp | 2 +- 19 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/BossOhm.cpp b/src/BossOhm.cpp index f49ef44a..b5d792ad 100644 --- a/src/BossOhm.cpp +++ b/src/BossOhm.cpp @@ -51,6 +51,7 @@ void ActBoss01_34() { case 0: gBoss[i].act_no = 1; + // Fallthrough case 1: if (i == 3) gBoss[i].x = gBoss[0].x - 0x2000; @@ -150,6 +151,7 @@ void ActBossChar_Omega() gBoss[0].act_no = 30; gBoss[0].act_wait = 0; gBoss[0].ani_no = 0; + // Fallthrough case 30: SetQuake(2); gBoss[0].y -= 0x200; diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 7a4cf6bf..373374f7 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -915,7 +915,7 @@ void ActBullet_Bom(BULLET *bul, int level) } PlaySoundObject(44, 1); - + // Fallthrough case 1: if (level == 1) { diff --git a/src/Caret.cpp b/src/Caret.cpp index e56f9416..18c69d3d 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -17,7 +17,7 @@ void InitCaret() void ActCaret00(CARET *crt) { - ; + (void)crt; } void ActCaret01(CARET *crt) diff --git a/src/Draw.cpp b/src/Draw.cpp index 710a383e..af48ee60 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -145,9 +145,9 @@ static void FlushSurface(int surf_no) unsigned char (*src_pixels)[surf[surf_no].surface->pitch / 4][4] = (unsigned char (*)[surf[surf_no].surface->pitch/ 4][4])surf[surf_no].surface->pixels; unsigned char (*dst_pixels)[pitch / 4][4] = (unsigned char (*)[pitch/ 4][4])raw_pixels; - for (unsigned int h = 0; h < surf[surf_no].surface->h; ++h) + for (int h = 0; h < surf[surf_no].surface->h; ++h) { - for (unsigned int w = 0; w < surf[surf_no].surface->w; ++w) + for (int w = 0; w < surf[surf_no].surface->w; ++w) { dst_pixels[h][w][0] = src_pixels[h][w][0]; dst_pixels[h][w][1] = src_pixels[h][w][1]; diff --git a/src/Font.cpp b/src/Font.cpp index fb6961b2..8c3401b8 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -58,7 +58,7 @@ static unsigned long UTF8ToCode(const unsigned char *string, unsigned int *bytes case 3: case 4: length = zero_bit; - charcode = string[0] & (1 << (8 - zero_bit)) - 1; + charcode = (string[0] & (1 << (8 - zero_bit))) - 1; for (unsigned int i = 1; i < zero_bit; ++i) { @@ -230,7 +230,7 @@ void DrawText(FontObject *font_object, SDL_Surface *surface, int x, int y, unsig const int letter_x = x + pen_x + face->glyph->bitmap_left; const int letter_y = y + ((FT_MulFix(face->ascender, face->size->metrics.y_scale) - face->glyph->metrics.horiBearingY + (64 / 2)) / 64); - for (int iy = MAX(-letter_y, 0); letter_y + iy < MIN(letter_y + converted.rows, surface->h); ++iy) + for (int iy = MAX(-letter_y, 0); letter_y + iy < MIN(letter_y + converted.rows, (unsigned int)surface->h); ++iy) { if (face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) { diff --git a/src/Frame.cpp b/src/Frame.cpp index 7ab34df1..6f5938e2 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -6,6 +6,7 @@ #include "NpChar.h" #include "Game.h" #include "CommonDefines.h" +#include "Boss.h" FRAME gFrame; @@ -127,8 +128,8 @@ void SetFrameTargetNpChar(int event, int wait) void SetFrameTargetBoss(int no, int wait) { - //gFrame.tgt_x = &gBoss[no].x; - //gFrame.tgt_y = &gBoss[no].y; + gFrame.tgt_x = &gBoss[no].x; + gFrame.tgt_y = &gBoss[no].y; gFrame.wait = wait; } diff --git a/src/Game.cpp b/src/Game.cpp index 09213ed4..a81627ab 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -92,7 +92,7 @@ void PutNumber4(int x, int y, int value, bool bZero) } //Draw digit - if ( bZero && offset == 2 || sw != 0 || offset == 3 ) + if ((bZero && offset == 2) || sw != 0 || offset == 3 ) PutBitmap3(&rcClient, x + 8 * offset, y, &rect[a], SURFACE_ID_TEXT_BOX); //Go to next digit @@ -119,7 +119,7 @@ int ModeOpening() CutNoise(); - int wait = 0; + unsigned int wait = 0; while (wait < 500) { //Increase timer @@ -295,7 +295,7 @@ int ModeTitle() gMC.equip |= 0x100; //Start loop - int wait = 0; + unsigned int wait = 0; while (true) { diff --git a/src/NpcAct000.cpp b/src/NpcAct000.cpp index 6c0c603c..1f0ee050 100644 --- a/src/NpcAct000.cpp +++ b/src/NpcAct000.cpp @@ -414,7 +414,7 @@ void ActNpc005(NPCHAR *npc) case 0: //Init npc->y += 0x600; npc->act_no = 1; - + // Fallthrough case 1: //Waiting //Look at player if (npc->x <= gMC.x) diff --git a/src/NpcAct020.cpp b/src/NpcAct020.cpp index 0d33f377..bcbe5188 100644 --- a/src/NpcAct020.cpp +++ b/src/NpcAct020.cpp @@ -52,7 +52,7 @@ void ActNpc021(NPCHAR *npc) break; } - RECT rect[0]; + RECT rect[1]; rect[0] = {224, 40, 240, 48}; diff --git a/src/NpcAct040.cpp b/src/NpcAct040.cpp index 9fcf4ad2..84340e3c 100644 --- a/src/NpcAct040.cpp +++ b/src/NpcAct040.cpp @@ -39,6 +39,7 @@ void ActNpc040(NPCHAR *npc) npc->act_no = 1; npc->ani_no = 0; npc->ani_wait = 0; + // Fallthrough case 1: if (Random(0, 120) == 10) { @@ -65,6 +66,7 @@ void ActNpc040(NPCHAR *npc) npc->act_no = 4; npc->ani_no = 2; npc->ani_wait = 0; + // Fallthrough case 4: if (++npc->ani_wait > 4) { diff --git a/src/NpcAct060.cpp b/src/NpcAct060.cpp index a8cca143..0e352666 100644 --- a/src/NpcAct060.cpp +++ b/src/NpcAct060.cpp @@ -639,7 +639,7 @@ void ActNpc064(NPCHAR *npc) case 0: //Init npc->y += 0x600; npc->act_no = 1; - + // Fallthrough case 1: //Waiting //Look at player if (npc->x <= gMC.x) diff --git a/src/NpcAct140.cpp b/src/NpcAct140.cpp index d670e6de..3e773f36 100644 --- a/src/NpcAct140.cpp +++ b/src/NpcAct140.cpp @@ -793,6 +793,7 @@ void ActNpc150(NPCHAR *npc) for (int i = 0; i < 4; i++) SetNpChar(4, npc->x, npc->y, Random(-0x155, 0x155), Random(-0x600, 0), 0, 0, 0x100); PlaySoundObject(71, 1); + // Fallthrough case 11: npc->ani_no = 2; break; @@ -800,6 +801,7 @@ void ActNpc150(NPCHAR *npc) npc->act_no = 21; npc->act_wait = 64; PlaySoundObject(29, 1); + // Fallthrough case 21: if (!--npc->act_wait) npc->cond = 0; @@ -808,6 +810,7 @@ void ActNpc150(NPCHAR *npc) npc->act_no = 51; npc->ani_no = 3; npc->ani_wait = 0; + // Fallthrough case 51: if (++npc->ani_wait > 4) { @@ -827,6 +830,7 @@ void ActNpc150(NPCHAR *npc) npc->ani_no = 7; npc->tgt_x = npc->x; npc->tgt_y = npc->y; + // Fallthrough case 61: npc->tgt_y += 0x100; npc->x = npc->tgt_x + (Random(-1, 1) << 9); @@ -837,6 +841,7 @@ void ActNpc150(NPCHAR *npc) npc->act_wait = 0; npc->ani_no = 3; npc->ani_wait = 0; + // Fallthrough case 0x47: if ( npc->direct ) npc->x -= 0x100; @@ -859,6 +864,7 @@ void ActNpc150(NPCHAR *npc) npc->act_no = 101; npc->ani_no = 3; npc->ani_wait = 0; + // Fallthrough case 101: npc->ym += 0x40; if (npc->ym > 0x5FF) diff --git a/src/NpcAct200.cpp b/src/NpcAct200.cpp index b4a53a39..c2bcc3f6 100644 --- a/src/NpcAct200.cpp +++ b/src/NpcAct200.cpp @@ -34,5 +34,5 @@ void ActNpc219(NPCHAR *npc) else if (Random(0, 40) == 1) SetNpChar(4, npc->x + (Random(-20, 20) * 0x200), npc->y, 0, -0x200, 0, 0, 0x100); - npc->rect = rc[1]; -} \ No newline at end of file + npc->rect = rc[0]; +} diff --git a/src/NpcAct280.cpp b/src/NpcAct280.cpp index 8e7119bb..ed2bed7d 100644 --- a/src/NpcAct280.cpp +++ b/src/NpcAct280.cpp @@ -13,6 +13,8 @@ //Quake void ActNpc292(NPCHAR *npc) { + (void)npc; + SetQuake(10); } diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 2a4eadfe..88912139 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -19,7 +19,7 @@ bool LoadNpcTable(const char *path) const size_t tblSize = SDL_RWsize(fp); - const int npcCount = tblSize / 0x18; + const size_t npcCount = tblSize / 0x18; gNpcTable = (NPC_TABLE*)malloc(npcCount * sizeof(NPC_TABLE)); for (size_t i = 0; i < npcCount; i++) //bits diff --git a/src/Organya.cpp b/src/Organya.cpp index 3ce94914..29ae4323 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -123,7 +123,7 @@ bool MakeSoundObject8(int8_t *wavep, int8_t track, int8_t pipi) uint8_t *wp_sub = wp; size_t wav_tp = 0; - for (int i = 0; i < data_size; i++) + for (size_t i = 0; i < data_size; i++) { uint8_t work = *(wavep+wav_tp); work += 0x80; diff --git a/src/Sound.cpp b/src/Sound.cpp index 36be1577..c881e65f 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -76,18 +76,12 @@ SOUNDBUFFER::~SOUNDBUFFER() void SOUNDBUFFER::Release() { - if (this == NULL) - return; - //TODO: find a better and more stable(?) way to handle this function delete this; } void SOUNDBUFFER::Lock(uint8_t **outBuffer, size_t *outSize) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); if (outBuffer != nullptr) @@ -99,17 +93,11 @@ void SOUNDBUFFER::Lock(uint8_t **outBuffer, size_t *outSize) void SOUNDBUFFER::Unlock() { - if (this == NULL) - return; - SDL_UnlockAudioDevice(audioDevice); } void SOUNDBUFFER::SetCurrentPosition(uint32_t dwNewPosition) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); samplePosition = dwNewPosition; SDL_UnlockAudioDevice(audioDevice); @@ -117,9 +105,6 @@ void SOUNDBUFFER::SetCurrentPosition(uint32_t dwNewPosition) void SOUNDBUFFER::SetFrequency(uint32_t dwFrequency) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); frequency = (double)dwFrequency; SDL_UnlockAudioDevice(audioDevice); @@ -134,9 +119,6 @@ float MillibelToVolume(int32_t lVolume) void SOUNDBUFFER::SetVolume(int32_t lVolume) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); volume = MillibelToVolume(lVolume); SDL_UnlockAudioDevice(audioDevice); @@ -144,9 +126,6 @@ void SOUNDBUFFER::SetVolume(int32_t lVolume) void SOUNDBUFFER::SetPan(int32_t lPan) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); volume_l = MillibelToVolume(-lPan); volume_r = MillibelToVolume(lPan); @@ -155,9 +134,6 @@ void SOUNDBUFFER::SetPan(int32_t lPan) void SOUNDBUFFER::Play(bool bLooping) { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); playing = true; looping = bLooping; @@ -166,9 +142,6 @@ void SOUNDBUFFER::Play(bool bLooping) void SOUNDBUFFER::Stop() { - if (this == NULL) - return; - SDL_LockAudioDevice(audioDevice); playing = false; SDL_UnlockAudioDevice(audioDevice); @@ -176,9 +149,6 @@ void SOUNDBUFFER::Stop() void SOUNDBUFFER::Mix(float (*buffer)[2], size_t samples) { - if (this == NULL) - return; - if (!playing) //This sound buffer isn't playing return; @@ -225,6 +195,8 @@ void SOUNDBUFFER::Mix(float (*buffer)[2], size_t samples) //Sound mixer void AudioCallback(void *userdata, uint8_t *stream, int len) { + (void)userdata; + float (*buffer)[2] = (float(*)[2])stream; const size_t samples = len / (sizeof(float) * 2); diff --git a/src/TextScr.cpp b/src/TextScr.cpp index a7273654..4309a164 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -521,7 +521,6 @@ int TextScriptProc() else if (gTS.flags & 0x10) { //SAT/CAT/TUR printing - x; for (x = gTS.p_read; ; x++) { //Break if reaches command, or new-line diff --git a/src/ValueView.cpp b/src/ValueView.cpp index 455456ea..09c7fb3a 100644 --- a/src/ValueView.cpp +++ b/src/ValueView.cpp @@ -21,7 +21,7 @@ void SetValueView(int *px, int *py, int value) int i; //TODO: Boi I'm reaaaally boutta getcho pickle chin aah boi, egg head like collard greens head ass boi, ol' hell dat bell dirt aaah boi stank ah boi afro head ass, lip gloss chin ah boi ugly ahhh boi *snort* uglaaaa - for (i = 0; i < VALUEVIEW_MAX && (!gVV[i].flag || gVV[i].px != px || (gVV[i].value >= 0 || value >= 0) && (gVV[i].value <= 0 || value <= 0)); i++); + for (i = 0; i < VALUEVIEW_MAX && (!gVV[i].flag || gVV[i].px != px || ((gVV[i].value >= 0 || value >= 0) && (gVV[i].value <= 0 || value <= 0))); i++); int index; if (i == VALUEVIEW_MAX)