Refactor logging to use util::logf and add log utility header

This commit is contained in:
scawful
2025-01-22 13:36:37 -05:00
parent a5b94ab173
commit b245b10963
9 changed files with 75 additions and 50 deletions

View File

@@ -10,6 +10,7 @@
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "util/hex.h"
#include "util/log.h"
#include "util/macro.h"
namespace yaze {
@@ -532,7 +533,7 @@ absl::Status Overworld::Save(Rom &rom) {
}
absl::Status Overworld::SaveOverworldMaps() {
core::logf("Saving Overworld Maps");
util::logf("Saving Overworld Maps");
// Initialize map pointers
std::fill(map_pointers1_id.begin(), map_pointers1_id.end(), -1);
@@ -572,7 +573,7 @@ absl::Status Overworld::SaveOverworldMaps() {
}
if ((pos + size_a) >= 0x6411F && (pos + size_a) <= 0x70000) {
core::logf("Pos set to overflow region for map %s at %s",
util::logf("Pos set to overflow region for map %s at %s",
std::to_string(i), util::HexLong(pos));
pos = kOverworldMapDataOverflow; // 0x0F8780;
}
@@ -609,7 +610,7 @@ absl::Status Overworld::SaveOverworldMaps() {
std::copy(a.begin(), a.end(), map_data_p1[i].begin());
int snes_pos = core::PcToSnes(pos);
map_pointers1[i] = snes_pos;
core::logf("Saving map pointers1 and compressed data for map %s at %s",
util::logf("Saving map pointers1 and compressed data for map %s at %s",
util::HexByte(i), util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
@@ -619,7 +620,7 @@ absl::Status Overworld::SaveOverworldMaps() {
} else {
// Save pointer for map1
int snes_pos = map_pointers1[map_pointers1_id[i]];
core::logf("Saving map pointers1 for map %s at %s", util::HexByte(i),
util::logf("Saving map pointers1 for map %s at %s", util::HexByte(i),
util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
@@ -631,7 +632,7 @@ absl::Status Overworld::SaveOverworldMaps() {
}
if ((pos + b.size()) >= 0x6411F && (pos + b.size()) <= 0x70000) {
core::logf("Pos set to overflow region for map %s at %s",
util::logf("Pos set to overflow region for map %s at %s",
util::HexByte(i), util::HexLong(pos));
pos = kOverworldMapDataOverflow;
}
@@ -641,7 +642,7 @@ absl::Status Overworld::SaveOverworldMaps() {
std::copy(b.begin(), b.end(), map_data_p2[i].begin());
int snes_pos = core::PcToSnes(pos);
map_pointers2[i] = snes_pos;
core::logf("Saving map pointers2 and compressed data for map %s at %s",
util::logf("Saving map pointers2 and compressed data for map %s at %s",
util::HexByte(i), util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
@@ -651,7 +652,7 @@ absl::Status Overworld::SaveOverworldMaps() {
} else {
// Save pointer for map2
int snes_pos = map_pointers2[map_pointers2_id[i]];
core::logf("Saving map pointers2 for map %s at %s", util::HexByte(i),
util::logf("Saving map pointers2 for map %s at %s", util::HexByte(i),
util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
@@ -661,7 +662,7 @@ absl::Status Overworld::SaveOverworldMaps() {
// Check if too many maps data
if (pos > kOverworldCompressedOverflowPos) {
core::logf("Too many maps data %s", util::HexLong(pos));
util::logf("Too many maps data %s", util::HexLong(pos));
return absl::AbortedError("Too many maps data " + std::to_string(pos));
}
@@ -670,7 +671,7 @@ absl::Status Overworld::SaveOverworldMaps() {
}
absl::Status Overworld::SaveLargeMaps() {
core::logf("Saving Large Maps");
util::logf("Saving Large Maps");
std::vector<uint8_t> checked_map;
for (int i = 0; i < 0x40; i++) {
@@ -1148,7 +1149,7 @@ absl::Status Overworld::SaveMap32Expanded() {
}
absl::Status Overworld::SaveMap32Tiles() {
core::logf("Saving Map32 Tiles");
util::logf("Saving Map32 Tiles");
constexpr int kMaxUniqueTiles = 0x4540;
constexpr int kTilesPer32x32Tile = 6;
@@ -1355,7 +1356,7 @@ absl::Status Overworld::SaveMap16Expanded() {
}
absl::Status Overworld::SaveMap16Tiles() {
core::logf("Saving Map16 Tiles");
util::logf("Saving Map16 Tiles");
int tpos = kMap16Tiles;
// 3760
for (int i = 0; i < NumberOfMap16; i += 1) {
@@ -1376,7 +1377,7 @@ absl::Status Overworld::SaveMap16Tiles() {
}
absl::Status Overworld::SaveEntrances() {
core::logf("Saving Entrances");
util::logf("Saving Entrances");
int ow_entrance_map_ptr = kOverworldEntranceMap;
int ow_entrance_pos_ptr = kOverworldEntrancePos;
int ow_entrance_id_ptr = kOverworldEntranceEntranceId;
@@ -1410,7 +1411,7 @@ absl::Status Overworld::SaveEntrances() {
}
absl::Status Overworld::SaveExits() {
core::logf("Saving Exits");
util::logf("Saving Exits");
for (int i = 0; i < kNumOverworldExits; i++) {
RETURN_IF_ERROR(
rom()->WriteShort(OWExitRoomId + (i * 2), all_exits_[i].room_id_));
@@ -1552,7 +1553,7 @@ absl::Status Overworld::SaveItems() {
}
absl::Status Overworld::SaveMapProperties() {
core::logf("Saving Map Properties");
util::logf("Saving Map Properties");
for (int i = 0; i < kDarkWorldMapIdStart; i++) {
RETURN_IF_ERROR(rom()->WriteByte(kAreaGfxIdPtr + i,
overworld_maps_[i].area_graphics()));

View File

@@ -9,6 +9,7 @@
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "util/hex.h"
#include "util/log.h"
namespace yaze {
namespace zelda3 {
@@ -77,7 +78,7 @@ void OverworldMap::LoadAreaInfo() {
message_id_ = message_id.value();
} else {
message_id_ = 0;
core::logf("Error reading message id for map %d", parent_);
util::logf("Error reading message id for map %d", parent_);
}
if (index_ < kDarkWorldMapIdStart) {