Skip to content

Commit

Permalink
Even more warning fixes (found by clang and in test cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Dec 23, 2024
1 parent 8ec85fb commit fd9708c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/audio_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class GenericAudio : public AudioInterface {
BgmChannel BGM_Channels[nr_of_bgm_channels];
SeChannel SE_Channels[nr_of_se_channels];
mutable bool BGM_PlayedOnceIndicator;
bool Muted;

std::vector<int16_t> sample_buffer = {};
std::vector<uint8_t> scrap_buffer = {};
Expand Down
3 changes: 0 additions & 3 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ Game_Character::Game_Character(Type type, lcf::rpg::SaveMapEventBase* d) :
{
}

Game_Character::~Game_Character() {
}

void Game_Character::SanitizeData(StringView name) {
SanitizeMoveRoute(name, data()->move_route, data()->move_route_index, "move_route_index");
}
Expand Down
8 changes: 4 additions & 4 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Game_Character {

static StringView TypeToStr(Type t);

/**
* Destructor.
*/
virtual ~Game_Character();
virtual ~Game_Character() = default;
Game_Character(Game_Character&&) = default;
Game_Character& operator=(const Game_Character&) = default;
Game_Character& operator=(Game_Character&&) = default;

/** @return the type of character this is */
Type GetType() const;
Expand Down
2 changes: 1 addition & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4567,7 +4567,7 @@ bool Game_Interpreter::CommandManiacRewriteMap(lcf::rpg::EventCommand const& com
}

int mode = com.parameters[0];
bool is_replace_range = com.parameters[1] != 0;
//bool is_replace_range = com.parameters[1] != 0; FIXME not implemented
bool is_upper_layer = com.parameters[2] != 0;

int tile_index = ValueOrVariableBitfield(mode, 0, com.parameters[3]);
Expand Down
4 changes: 1 addition & 3 deletions src/scene_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ void Scene_Debug::PushUiInterpreterView() {

Push(eUiInterpreterView);

auto& idx = prev[mode];

if (!was_range_list) {
SetupUiRangeList();
}
Expand Down Expand Up @@ -1249,7 +1247,7 @@ void Scene_Debug::UpdateInterpreterWindow(int index) {
state = Game_Interpreter::GetForegroundInterpreter().GetState();
first_line = Game_Battle::IsBattleRunning() ? "Foreground (Battle)" : "Foreground (Map)";
valid = true;
} else if (index <= state_interpreter.ev.size()) {
} else if (index <= static_cast<int>(state_interpreter.ev.size())) {
evt_id = state_interpreter.ev[index - 1];
state = state_interpreter.state_ev[index - 1];
first_line = fmt::format("EV{:04d}: {}", evt_id, Game_Map::GetEvent(evt_id)->GetName());
Expand Down
6 changes: 5 additions & 1 deletion src/window_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,15 @@ void Window_Settings::RefreshAudioSoundfont() {
#endif
}

#ifdef __clang__
// FIXME: Binding &cfg in the lambdas below is not needed and generates a warning in clang but MSVC requires it
#pragma clang diagnostic ignored "-Wunused-lambda-capture"
#endif

void Window_Settings::RefreshEngine() {
auto& cfg = Player::player_config;
cfg.Hide();

// FIXME: Binding &cfg is not needed and generates a warning but MSVC requires it
AddOption(cfg.font1, [this, &cfg]() {
font_size.Set(cfg.font1_size.Get());
Push(eEngineFont1);
Expand Down
1 change: 0 additions & 1 deletion tests/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

TEST_SUITE_BEGIN("Font");

constexpr char32_t escape = '\\';
constexpr int width = 240;
constexpr int height = 80;
constexpr int ch = 12;
Expand Down
68 changes: 41 additions & 27 deletions tests/move_route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
#include "game_switches.h"
#include <climits>
#include <initializer_list>
#include <lcf/rpg/movecommand.h>

#include "test_move_route.h"

TEST_SUITE_BEGIN("MoveRoute");

lcf::rpg::MoveRoute MakeRoute(int code, bool repeat = false, bool skip = false) {
lcf::rpg::MoveRoute mr;
lcf::rpg::MoveCommand mc;
mc.command_id = code;
mr.move_commands = { mc };
mr.repeat = repeat;
mr.skippable = skip;
return mr;
}

lcf::rpg::MoveRoute MakeRoute(std::initializer_list<lcf::rpg::MoveCommand> cmds, bool repeat = false, bool skip = false) {
lcf::rpg::MoveRoute mr;
mr.move_commands = cmds;
Expand Down Expand Up @@ -154,7 +165,7 @@ TEST_CASE("ForceMoveRouteDiffFreq") {

static void testInvalidCmd(bool repeat, bool skip) {
auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ -1 }}, repeat, skip);
auto mr = MakeRoute(-1, repeat, skip);

ch.ForceMoveRoute(mr, 3);
testMoveRoute(ch, false, 3, 0xFFFF, 64, 0, true, false, mr);
Expand Down Expand Up @@ -188,7 +199,7 @@ static void testMove(lcf::rpg::MoveCommand::Code code, int x, int y, int dir, in
ch.SetFacing(face);
ch.SetAllowMovement(success);

auto mr = MakeRoute({{ static_cast<int>(code) }}, repeat, skip);
auto mr = MakeRoute(static_cast<int>(code), repeat, skip);

CAPTURE(code);
CAPTURE(x);
Expand Down Expand Up @@ -444,7 +455,7 @@ static void testTurn(lcf::rpg::MoveCommand::Code code, int orig_dir, int dir, in
ch.SetY(y);
ch.SetDirection(orig_dir);
ch.SetFacing(orig_dir);
auto mr = MakeRoute({{ static_cast<int>(code) }});
auto mr = MakeRoute(static_cast<int>(code));

CAPTURE(code);
CAPTURE(orig_dir);
Expand Down Expand Up @@ -496,7 +507,7 @@ TEST_CASE("CommandTurnRandom") {

for (int i = 0; i < 10; ++i) {
auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::face_random_direction) }});
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::face_random_direction));

ch.ForceMoveRoute(mr, 3);
testMoveRouteDir(ch, Down, Down, false, 3, 0xFFFF, 64, 0, true, false, mr);
Expand All @@ -514,7 +525,7 @@ TEST_CASE("CommandWait") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::wait) }});
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::wait));

ch.ForceMoveRoute(mr, 2);
testMoveRouteDir(ch, Down, Down, false, 2, 0xFFFF, 0, 0, true, false, mr);
Expand All @@ -540,12 +551,16 @@ static void testJump(lcf::rpg::MoveCommand::Code code, int x, int y, int dir, in
ch.SetFacing(face);
ch.SetAllowMovement(success);

auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::begin_jump) }}, repeat, skip);
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::begin_jump), repeat, skip);
if (code != lcf::rpg::MoveCommand::Code::end_jump) {
mr.move_commands.push_back({ static_cast<int>(code) });
lcf::rpg::MoveCommand mc;
mc.command_id = static_cast<int>(code);
mr.move_commands.push_back(mc);
}
if (end) {
mr.move_commands.push_back({ static_cast<int>(lcf::rpg::MoveCommand::Code::end_jump) });
lcf::rpg::MoveCommand mc;
mc.command_id = static_cast<int>(lcf::rpg::MoveCommand::Code::end_jump);
mr.move_commands.push_back(mc);
}
auto num_cmds = static_cast<int>(mr.move_commands.size());

Expand Down Expand Up @@ -883,7 +898,7 @@ void testLockFacing(lcf::rpg::EventPage::AnimType at) {

auto ch = MoveRouteVehicle();
ch.SetAnimationType(at);
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::lock_facing) }});
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::lock_facing));

ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 0, 0, true, false, mr);
Expand All @@ -893,7 +908,7 @@ void testLockFacing(lcf::rpg::EventPage::AnimType at) {
testMoveRoute(ch, false, 2, 0xFFFF + 1, 128, 1, false, false, mr);
REQUIRE(ch.IsFacingLocked());

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::unlock_facing) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::unlock_facing));
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
REQUIRE(ch.IsFacingLocked());
Expand All @@ -913,8 +928,8 @@ TEST_CASE("CommandSpeedChange") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::increase_movement_speed) }});
const int n = 10;
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::increase_movement_speed));
//const int n = 10;

ch.SetMoveSpeed(1);
int prev = ch.GetMoveSpeed();
Expand All @@ -930,7 +945,7 @@ TEST_CASE("CommandSpeedChange") {
prev= ch.GetMoveSpeed();
}

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_movement_speed) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_movement_speed));
for (int i = 0; i < 10; ++i) {
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
Expand All @@ -948,16 +963,15 @@ TEST_CASE("CommandFreqChange") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::increase_movement_frequence) }});
const int n = 10;
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::increase_movement_frequence));

for (int i = 1; i < 10; ++i) {
const int freq = Utils::Clamp(i, 1, 8);

ch.ForceMoveRoute(mr, freq);
testMoveRoute(ch, false, freq, 0xFFFF, (i == 0 && freq == 2 ? 0 : Game_Character::GetMaxStopCountForStep(freq)), 0, true, false, mr);

const int next_freq = Utils::Clamp(freq + 1, 1, 8);
//const int next_freq = Utils::Clamp(freq + 1, 1, 8);
ForceUpdate(ch);
// FIXME: Need another command for the frequency to not get reset when move route is done.
//testMoveRoute(ch, false, next_freq, 0xFFFF + 1, Game_Character::GetMaxStopCountForStep(next_freq), 1, false, false, mr);
Expand All @@ -966,15 +980,15 @@ TEST_CASE("CommandFreqChange") {

}

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_movement_frequence) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_movement_frequence));

for (int i = 1; i < 10; ++i) {
const int freq = Utils::Clamp(i, 1, 8);

ch.ForceMoveRoute(mr, freq);
testMoveRoute(ch, false, freq, 0xFFFF, Game_Character::GetMaxStopCountForStep(freq), 0, true, false, mr);

const int next_freq = Utils::Clamp(freq - 1, 1, 8);
//const int next_freq = Utils::Clamp(freq - 1, 1, 8);
ForceUpdate(ch);
// FIXME: Need another command for the frequency to not get reset when move route is done.
//testMoveRoute(ch, false, next_freq, 0xFFFF + 1, Game_Character::GetMaxStopCountForStep(next_freq), 1, false, false, mr);
Expand All @@ -986,8 +1000,8 @@ TEST_CASE("CommandTranspChange") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::increase_transp) }});
const int n = 10;
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::increase_transp));
//const int n = 10;

ch.SetTransparency(0);
int prev = ch.GetTransparency();
Expand All @@ -1003,7 +1017,7 @@ TEST_CASE("CommandTranspChange") {
prev = ch.GetTransparency();
}

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_transp) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::decrease_transp));
for (int i = 0; i < 10; ++i) {
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
Expand All @@ -1021,7 +1035,7 @@ TEST_CASE("CommandThrough") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_on) }});
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_on));

auto testoff = [&]() {
REQUIRE(!ch.GetThrough());
Expand All @@ -1047,7 +1061,7 @@ TEST_CASE("CommandThrough") {
testMoveRoute(ch, false, 2, 0xFFFF + 1, 128, 1, false, false, mr);
teston();

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_off) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_off));
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
teston();
Expand All @@ -1058,7 +1072,7 @@ TEST_CASE("CommandThrough") {

ch.SetThrough(true);

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_off) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_off));
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
REQUIRE(ch.GetThrough());
Expand All @@ -1068,7 +1082,7 @@ TEST_CASE("CommandThrough") {
testoff();

ch.SetThrough(true);
mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_on) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::walk_everywhere_on));
ch.ForceMoveRoute(mr, 2);
REQUIRE(ch.GetThrough());

Expand All @@ -1081,7 +1095,7 @@ TEST_CASE("CommandStopAnimation") {
const MapGuard mg;

auto ch = MoveRouteVehicle();
auto mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::stop_animation) }});
auto mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::stop_animation));

ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 0, 0, true, false, mr);
Expand All @@ -1091,7 +1105,7 @@ TEST_CASE("CommandStopAnimation") {
testMoveRoute(ch, false, 2, 0xFFFF + 1, 128, 1, false, false, mr);
REQUIRE(ch.IsAnimPaused());

mr = MakeRoute({{ static_cast<int>(lcf::rpg::MoveCommand::Code::start_animation) }});
mr = MakeRoute(static_cast<int>(lcf::rpg::MoveCommand::Code::start_animation));
ch.ForceMoveRoute(mr, 2);
testMoveRoute(ch, false, 2, 0xFFFF, 128, 0, true, false, mr);
REQUIRE(ch.IsAnimPaused());
Expand Down
20 changes: 10 additions & 10 deletions tests/test_move_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,29 @@ struct MapGuard {
}
};

constexpr auto Up = Game_Character::Up;
constexpr auto Right = Game_Character::Right;
constexpr auto Down = Game_Character::Down;
constexpr auto Left = Game_Character::Left;
constexpr auto UpRight = Game_Character::UpRight;
constexpr auto DownRight = Game_Character::DownRight;
constexpr auto DownLeft = Game_Character::DownLeft;
constexpr auto UpLeft = Game_Character::UpLeft;
inline constexpr auto Up = Game_Character::Up;
inline constexpr auto Right = Game_Character::Right;
inline constexpr auto Down = Game_Character::Down;
inline constexpr auto Left = Game_Character::Left;
inline constexpr auto UpRight = Game_Character::UpRight;
inline constexpr auto DownRight = Game_Character::DownRight;
inline constexpr auto DownLeft = Game_Character::DownLeft;
inline constexpr auto UpLeft = Game_Character::UpLeft;
}

static void ForceUpdate(Game_Vehicle& ch) {
ch.SetProcessed(false);
ch.Update();
}

static void ForceUpdate(Game_Player& ch) {
/*static void ForceUpdate(Game_Player& ch) {
ch.SetProcessed(false);
ch.Update();
}
static void ForceUpdate(Game_Event& ch) {
ch.SetProcessed(false);
ch.Update(false);
}
}*/

#endif
1 change: 0 additions & 1 deletion tests/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

TEST_SUITE_BEGIN("Text");

constexpr char32_t escape = '\\';
constexpr int width = 240;
constexpr int height = 80;
constexpr int ch = 12;
Expand Down

0 comments on commit fd9708c

Please sign in to comment.