Refactor ExperimentFlags to FeatureFlags for consistency across the codebase

This commit is contained in:
scawful
2025-01-22 13:41:28 -05:00
parent b245b10963
commit de53ccae21
11 changed files with 157 additions and 136 deletions

View File

@@ -18,100 +18,6 @@ namespace yaze {
*/
namespace core {
/**
* @class ExperimentFlags
* @brief A class to manage experimental feature flags.
*/
class ExperimentFlags {
public:
struct Flags {
// Log instructions to the GUI debugger.
bool kLogInstructions = true;
// Flag to enable the saving of all palettes to the Rom.
bool kSaveAllPalettes = false;
// Flag to enable the saving of gfx groups to the rom.
bool kSaveGfxGroups = false;
// Flag to enable the change queue, which could have any anonymous
// save routine for the Rom. In practice, just the overworld tilemap
// and tile32 save.
bool kSaveWithChangeQueue = false;
// Attempt to run the dungeon room draw routine when opening a room.
bool kDrawDungeonRoomGraphics = true;
// Save dungeon map edits to the Rom.
bool kSaveDungeonMaps = false;
// Save graphics sheet to the Rom.
bool kSaveGraphicsSheet = false;
// Log to the console.
bool kLogToConsole = false;
// Overworld flags
struct Overworld {
// Load and render overworld sprites to the screen. Unstable.
bool kDrawOverworldSprites = false;
// Save overworld map edits to the Rom.
bool kSaveOverworldMaps = true;
// Save overworld entrances to the Rom.
bool kSaveOverworldEntrances = true;
// Save overworld exits to the Rom.
bool kSaveOverworldExits = true;
// Save overworld items to the Rom.
bool kSaveOverworldItems = true;
// Save overworld properties to the Rom.
bool kSaveOverworldProperties = true;
// Load custom overworld data from the ROM and enable UI.
bool kLoadCustomOverworld = false;
} overworld;
};
static Flags &get() {
static Flags instance;
return instance;
}
std::string Serialize() const {
std::string result;
result +=
"kLogInstructions: " + std::to_string(get().kLogInstructions) + "\n";
result +=
"kSaveAllPalettes: " + std::to_string(get().kSaveAllPalettes) + "\n";
result += "kSaveGfxGroups: " + std::to_string(get().kSaveGfxGroups) + "\n";
result +=
"kSaveWithChangeQueue: " + std::to_string(get().kSaveWithChangeQueue) +
"\n";
result += "kDrawDungeonRoomGraphics: " +
std::to_string(get().kDrawDungeonRoomGraphics) + "\n";
result +=
"kSaveDungeonMaps: " + std::to_string(get().kSaveDungeonMaps) + "\n";
result += "kLogToConsole: " + std::to_string(get().kLogToConsole) + "\n";
result += "kDrawOverworldSprites: " +
std::to_string(get().overworld.kDrawOverworldSprites) + "\n";
result += "kSaveOverworldMaps: " +
std::to_string(get().overworld.kSaveOverworldMaps) + "\n";
result += "kSaveOverworldEntrances: " +
std::to_string(get().overworld.kSaveOverworldEntrances) + "\n";
result += "kSaveOverworldExits: " +
std::to_string(get().overworld.kSaveOverworldExits) + "\n";
result += "kSaveOverworldItems: " +
std::to_string(get().overworld.kSaveOverworldItems) + "\n";
result += "kSaveOverworldProperties: " +
std::to_string(get().overworld.kSaveOverworldProperties) + "\n";
return result;
}
};
constexpr uint32_t kFastRomRegion = 0x808000;
inline uint32_t SnesToPc(uint32_t addr) noexcept {

106
src/app/core/features.h Normal file
View File

@@ -0,0 +1,106 @@
#ifndef YAZE_APP_CORE_FEATURES_H
#define YAZE_APP_CORE_FEATURES_H
#include <string>
namespace yaze {
namespace core {
/**
* @class FeatureFlags
* @brief A class to manage experimental feature flags.
*/
class FeatureFlags {
public:
struct Flags {
// Log instructions to the GUI debugger.
bool kLogInstructions = true;
// Flag to enable the saving of all palettes to the Rom.
bool kSaveAllPalettes = false;
// Flag to enable the saving of gfx groups to the rom.
bool kSaveGfxGroups = false;
// Flag to enable the change queue, which could have any anonymous
// save routine for the Rom. In practice, just the overworld tilemap
// and tile32 save.
bool kSaveWithChangeQueue = false;
// Attempt to run the dungeon room draw routine when opening a room.
bool kDrawDungeonRoomGraphics = true;
// Save dungeon map edits to the Rom.
bool kSaveDungeonMaps = false;
// Save graphics sheet to the Rom.
bool kSaveGraphicsSheet = false;
// Log to the console.
bool kLogToConsole = false;
// Overworld flags
struct Overworld {
// Load and render overworld sprites to the screen. Unstable.
bool kDrawOverworldSprites = false;
// Save overworld map edits to the Rom.
bool kSaveOverworldMaps = true;
// Save overworld entrances to the Rom.
bool kSaveOverworldEntrances = true;
// Save overworld exits to the Rom.
bool kSaveOverworldExits = true;
// Save overworld items to the Rom.
bool kSaveOverworldItems = true;
// Save overworld properties to the Rom.
bool kSaveOverworldProperties = true;
// Load custom overworld data from the ROM and enable UI.
bool kLoadCustomOverworld = false;
} overworld;
};
static Flags &get() {
static Flags instance;
return instance;
}
std::string Serialize() const {
std::string result;
result +=
"kLogInstructions: " + std::to_string(get().kLogInstructions) + "\n";
result +=
"kSaveAllPalettes: " + std::to_string(get().kSaveAllPalettes) + "\n";
result += "kSaveGfxGroups: " + std::to_string(get().kSaveGfxGroups) + "\n";
result +=
"kSaveWithChangeQueue: " + std::to_string(get().kSaveWithChangeQueue) +
"\n";
result += "kDrawDungeonRoomGraphics: " +
std::to_string(get().kDrawDungeonRoomGraphics) + "\n";
result +=
"kSaveDungeonMaps: " + std::to_string(get().kSaveDungeonMaps) + "\n";
result += "kLogToConsole: " + std::to_string(get().kLogToConsole) + "\n";
result += "kDrawOverworldSprites: " +
std::to_string(get().overworld.kDrawOverworldSprites) + "\n";
result += "kSaveOverworldMaps: " +
std::to_string(get().overworld.kSaveOverworldMaps) + "\n";
result += "kSaveOverworldEntrances: " +
std::to_string(get().overworld.kSaveOverworldEntrances) + "\n";
result += "kSaveOverworldExits: " +
std::to_string(get().overworld.kSaveOverworldExits) + "\n";
result += "kSaveOverworldItems: " +
std::to_string(get().overworld.kSaveOverworldItems) + "\n";
result += "kSaveOverworldProperties: " +
std::to_string(get().overworld.kSaveOverworldProperties) + "\n";
return result;
}
};
} // namespace core
} // namespace yaze
#endif // YAZE_APP_CORE_FEATURES_H

View File

@@ -1,6 +1,7 @@
#include "dungeon_editor.h"
#include "absl/container/flat_hash_map.h"
#include "app/core/features.h"
#include "app/core/platform/renderer.h"
#include "app/gfx/snes_palette.h"
#include "app/gui/canvas.h"
@@ -78,7 +79,7 @@ absl::Status DungeonEditor::Initialize() {
rooms_.emplace_back(zelda3::Room(/*room_id=*/i));
rooms_[i].LoadHeader();
rooms_[i].LoadRoomFromROM();
if (core::ExperimentFlags::get().kDrawDungeonRoomGraphics) {
if (core::FeatureFlags::get().kDrawDungeonRoomGraphics) {
rooms_[i].LoadRoomGraphics();
}

View File

@@ -2,6 +2,7 @@
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "app/core/features.h"
#include "app/core/platform/file_dialog.h"
#include "app/core/project.h"
#include "app/editor/code/assembly_editor.h"
@@ -732,7 +733,7 @@ void EditorManager::LoadRom() {
}
void EditorManager::SaveRom() {
if (core::ExperimentFlags::get().kSaveDungeonMaps) {
if (core::FeatureFlags::get().kSaveDungeonMaps) {
status_ = screen_editor_.SaveDungeonMaps();
RETURN_VOID_IF_ERROR(status_);
}
@@ -740,7 +741,7 @@ void EditorManager::SaveRom() {
status_ = overworld_editor_.Save();
RETURN_VOID_IF_ERROR(status_);
if (core::ExperimentFlags::get().kSaveGraphicsSheet)
if (core::FeatureFlags::get().kSaveGraphicsSheet)
PRINT_IF_ERROR(SaveAllGraphicsData(
*rom(), GraphicsSheetManager::GetInstance().gfx_sheets()));

View File

@@ -7,6 +7,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "app/core/features.h"
#include "app/core/platform/clipboard.h"
#include "app/core/platform/renderer.h"
#include "app/editor/graphics/palette_editor.h"
@@ -27,7 +28,6 @@
#include "util/log.h"
#include "util/macro.h"
namespace yaze {
namespace editor {
@@ -623,7 +623,7 @@ void OverworldEditor::CheckForMousePan() {
void OverworldEditor::DrawOverworldCanvas() {
if (all_gfx_loaded_) {
if (core::ExperimentFlags::get().overworld.kLoadCustomOverworld) {
if (core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
DrawCustomOverworldMapSettings();
} else {
DrawOverworldMapSettings();
@@ -967,7 +967,7 @@ void OverworldEditor::DrawOverworldSprites() {
current_sprite_ = sprite;
}
}
if (core::ExperimentFlags::get().overworld.kDrawOverworldSprites) {
if (core::FeatureFlags::get().overworld.kDrawOverworldSprites) {
if (sprite_previews_[sprite.id()].is_active()) {
ow_map_canvas_.DrawBitmap(sprite_previews_[sprite.id()], map_x, map_y,
2.0f);
@@ -999,22 +999,22 @@ void OverworldEditor::DrawOverworldSprites() {
}
absl::Status OverworldEditor::Save() {
if (core::ExperimentFlags::get().overworld.kSaveOverworldMaps) {
if (core::FeatureFlags::get().overworld.kSaveOverworldMaps) {
RETURN_IF_ERROR(overworld_.CreateTile32Tilemap());
RETURN_IF_ERROR(overworld_.SaveMap32Tiles());
RETURN_IF_ERROR(overworld_.SaveMap16Tiles());
RETURN_IF_ERROR(overworld_.SaveOverworldMaps());
}
if (core::ExperimentFlags::get().overworld.kSaveOverworldEntrances) {
if (core::FeatureFlags::get().overworld.kSaveOverworldEntrances) {
RETURN_IF_ERROR(overworld_.SaveEntrances());
}
if (core::ExperimentFlags::get().overworld.kSaveOverworldExits) {
if (core::FeatureFlags::get().overworld.kSaveOverworldExits) {
RETURN_IF_ERROR(overworld_.SaveExits());
}
if (core::ExperimentFlags::get().overworld.kSaveOverworldItems) {
if (core::FeatureFlags::get().overworld.kSaveOverworldItems) {
RETURN_IF_ERROR(overworld_.SaveItems());
}
if (core::ExperimentFlags::get().overworld.kSaveOverworldProperties) {
if (core::FeatureFlags::get().overworld.kSaveOverworldProperties) {
RETURN_IF_ERROR(overworld_.SaveMapProperties());
}
return absl::OkStatus();
@@ -1078,7 +1078,7 @@ absl::Status OverworldEditor::LoadGraphics() {
}
}
if (core::ExperimentFlags::get().overworld.kDrawOverworldSprites) {
if (core::FeatureFlags::get().overworld.kDrawOverworldSprites) {
RETURN_IF_ERROR(LoadSpriteGraphics());
}

View File

@@ -1,13 +1,14 @@
#ifndef YAZE_APP_EDITOR_UTILS_FLAGS_H
#define YAZE_APP_EDITOR_UTILS_FLAGS_H
#include "app/core/features.h"
#include "core/common.h"
#include "imgui/imgui.h"
namespace yaze {
namespace editor {
using core::ExperimentFlags;
using core::FeatureFlags;
using ImGui::BeginMenu;
using ImGui::Checkbox;
using ImGui::EndMenu;
@@ -17,40 +18,39 @@ using ImGui::Separator;
struct FlagsMenu {
void DrawOverworldFlags() {
Checkbox("Enable Overworld Sprites",
&ExperimentFlags::get().overworld.kDrawOverworldSprites);
&FeatureFlags::get().overworld.kDrawOverworldSprites);
Separator();
Checkbox("Save Overworld Maps",
&ExperimentFlags::get().overworld.kSaveOverworldMaps);
&FeatureFlags::get().overworld.kSaveOverworldMaps);
Checkbox("Save Overworld Entrances",
&ExperimentFlags::get().overworld.kSaveOverworldEntrances);
&FeatureFlags::get().overworld.kSaveOverworldEntrances);
Checkbox("Save Overworld Exits",
&ExperimentFlags::get().overworld.kSaveOverworldExits);
&FeatureFlags::get().overworld.kSaveOverworldExits);
Checkbox("Save Overworld Items",
&ExperimentFlags::get().overworld.kSaveOverworldItems);
&FeatureFlags::get().overworld.kSaveOverworldItems);
Checkbox("Save Overworld Properties",
&ExperimentFlags::get().overworld.kSaveOverworldProperties);
&FeatureFlags::get().overworld.kSaveOverworldProperties);
Checkbox("Load Custom Overworld",
&ExperimentFlags::get().overworld.kLoadCustomOverworld);
&FeatureFlags::get().overworld.kLoadCustomOverworld);
}
void DrawDungeonFlags() {
void DrawDungeonFlags() {
Checkbox("Draw Dungeon Room Graphics",
&ExperimentFlags::get().kDrawDungeonRoomGraphics);
&FeatureFlags::get().kDrawDungeonRoomGraphics);
Separator();
Checkbox("Save Dungeon Maps", &ExperimentFlags::get().kSaveDungeonMaps);
}
Checkbox("Save Dungeon Maps", &FeatureFlags::get().kSaveDungeonMaps);
}
void DrawResourceFlags() {
Checkbox("Save All Palettes", &ExperimentFlags::get().kSaveAllPalettes);
Checkbox("Save Gfx Groups", &ExperimentFlags::get().kSaveGfxGroups);
Checkbox("Save Graphics Sheets",
&ExperimentFlags::get().kSaveGraphicsSheet);
Checkbox("Save All Palettes", &FeatureFlags::get().kSaveAllPalettes);
Checkbox("Save Gfx Groups", &FeatureFlags::get().kSaveGfxGroups);
Checkbox("Save Graphics Sheets", &FeatureFlags::get().kSaveGraphicsSheet);
}
void DrawSystemFlags() {
Checkbox("Enable Console Logging", &ExperimentFlags::get().kLogToConsole);
Checkbox("Enable Console Logging", &FeatureFlags::get().kLogToConsole);
Checkbox("Log Instructions to Emulator Debugger",
&ExperimentFlags::get().kLogInstructions);
&FeatureFlags::get().kLogInstructions);
}
};

View File

@@ -7,6 +7,7 @@
#include <vector>
#include "app/core/common.h"
#include "app/core/features.h"
#include "app/emu/cpu/internal/opcodes.h"
namespace yaze {
@@ -1801,7 +1802,7 @@ void Cpu::ExecuteInstruction(uint8_t opcode) {
void Cpu::LogInstructions(uint16_t PC, uint8_t opcode, uint16_t operand,
bool immediate, bool accumulator_mode) {
if (core::ExperimentFlags::get().kLogInstructions) {
if (core::FeatureFlags::get().kLogInstructions) {
std::ostringstream oss;
oss << "$" << std::uppercase << std::setw(2) << std::setfill('0')
<< static_cast<int>(PB) << ":" << std::hex << PC << ": 0x"

View File

@@ -16,6 +16,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "app/core/features.h"
#include "app/core/platform/renderer.h"
#include "app/gfx/compression.h"
#include "app/gfx/snes_color.h"
@@ -442,9 +443,9 @@ absl::Status Rom::SaveToFile(bool backup, bool save_new, std::string filename) {
}
// Run the other save functions
if (core::ExperimentFlags::get().kSaveAllPalettes)
if (core::FeatureFlags::get().kSaveAllPalettes)
RETURN_IF_ERROR(SaveAllPalettes());
if (core::ExperimentFlags::get().kSaveGfxGroups)
if (core::FeatureFlags::get().kSaveGfxGroups)
RETURN_IF_ERROR(SaveGroupsToRom());
if (save_new) {

View File

@@ -6,6 +6,7 @@
#include <vector>
#include "absl/status/status.h"
#include "app/core/features.h"
#include "app/gfx/compression.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
@@ -113,7 +114,7 @@ absl::Status Overworld::AssembleMap32Tiles() {
rom_.version_constants().kMap32TileBL,
rom_.version_constants().kMap32TileBR};
if (rom()->data()[kMap32ExpandedFlagPos] != 0x04 &&
core::ExperimentFlags::get().overworld.kLoadCustomOverworld) {
core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
map32address[0] = rom_.version_constants().kMap32TileTL;
map32address[1] = kMap32TileTRExpanded;
map32address[2] = kMap32TileBLExpanded;
@@ -162,7 +163,7 @@ absl::Status Overworld::AssembleMap16Tiles() {
int tpos = kMap16Tiles;
int num_tile16 = kNumTile16Individual;
if (rom()->data()[kMap16ExpandedFlagPos] != 0x0F &&
core::ExperimentFlags::get().overworld.kLoadCustomOverworld) {
core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
tpos = kMap16TilesExpanded;
num_tile16 = NumberOfMap16Ex;
expanded_tile16_ = true;
@@ -306,7 +307,7 @@ absl::Status Overworld::LoadEntrances() {
int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
int num_entrances = 129;
if (rom()->data()[kOverworldEntranceExpandedFlagPos] != 0xB8 &&
core::ExperimentFlags::get().overworld.kLoadCustomOverworld) {
core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
ow_entrance_map_ptr = kOverworldEntranceMapExpanded;
ow_entrance_pos_ptr = kOverworldEntrancePosExpanded;
ow_entrance_id_ptr = kOverworldEntranceEntranceIdExpanded;
@@ -390,7 +391,7 @@ absl::Status Overworld::LoadExits() {
uint16_t px = (uint16_t)((rom_data[OWExitXPlayer + (i * 2) + 1] << 8) +
rom_data[OWExitXPlayer + (i * 2)]);
if (core::ExperimentFlags::get().kLogToConsole) {
if (core::FeatureFlags::get().kLogToConsole) {
std::cout << "Exit: " << i << " RoomID: " << exit_room_id
<< " MapID: " << exit_map_id << " VRAM: " << exit_vram
<< " YScroll: " << exit_y_scroll
@@ -1082,7 +1083,7 @@ absl::Status Overworld::CreateTile32Tilemap() {
unique_tiles.size(), LimitOfMap32));
}
if (core::ExperimentFlags::get().kLogToConsole) {
if (core::FeatureFlags::get().kLogToConsole) {
std::cout << "Number of unique Tiles32: " << tiles32_unique_.size()
<< " Saved:" << tiles32_unique_.size()
<< " Out of: " << LimitOfMap32 << std::endl;
@@ -1545,7 +1546,7 @@ absl::Status Overworld::SaveItems() {
return absl::AbortedError("Too many items");
}
if (core::ExperimentFlags::get().kLogToConsole) {
if (core::FeatureFlags::get().kLogToConsole) {
std::cout << "End of Items : " << data_pos << std::endl;
}

View File

@@ -5,6 +5,7 @@
#include <unordered_map>
#include <vector>
#include "app/core/features.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
@@ -18,7 +19,7 @@ OverworldMap::OverworldMap(int index, Rom &rom)
: index_(index), parent_(index), rom_(rom) {
LoadAreaInfo();
if (core::ExperimentFlags::get().overworld.kLoadCustomOverworld) {
if (core::FeatureFlags::get().overworld.kLoadCustomOverworld) {
// If the custom overworld ASM has NOT already been applied, manually set
// the vanilla values.
uint8_t asm_version = rom_[OverworldCustomASMHasBeenApplied];

View File

@@ -9,6 +9,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "app/core/features.h"
namespace yaze {
namespace util {
@@ -25,7 +26,7 @@ static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) {
message = absl::StrCat("[", tm.tm_hour, ":", tm.tm_min, ":", tm.tm_sec, "] ",
message, "\n");
if (ExperimentFlags::get().kLogToConsole) {
if (core::FeatureFlags::get().kLogToConsole) {
std::cout << message;
}
static std::ofstream fout(kLogFileOut, std::ios::out | std::ios::app);
@@ -33,4 +34,6 @@ static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) {
}
} // namespace util
} // namespace yaze
} // namespace yaze
#endif // YAZE_UTIL_LOG_H