1
0

Add a formatting function for Vector3 (#4282)

* Vector3: Add custom fmt compatible formatter.

* cLuaState: Add fmt version of ApiParamError

* Use vector formatting in manual bindings

* Always log vectors with FLOG
This commit is contained in:
peterbell10 2018-09-24 21:33:39 +01:00 committed by Alexander Harkness
parent 73689024f0
commit 4727ed2084
27 changed files with 192 additions and 181 deletions

View File

@ -2004,7 +2004,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
int cLuaState::ApiParamError(const char * a_MsgFormat, fmt::ArgList argp) int cLuaState::ApiParamError(fmt::StringRef a_Msg)
{ {
// Retrieve current function name // Retrieve current function name
lua_Debug entry; lua_Debug entry;
@ -2012,8 +2012,7 @@ int cLuaState::ApiParamError(const char * a_MsgFormat, fmt::ArgList argp)
VERIFY(lua_getinfo(m_LuaState, "n", &entry)); VERIFY(lua_getinfo(m_LuaState, "n", &entry));
// Compose the error message: // Compose the error message:
AString msg = Printf(a_MsgFormat, argp); AString errorMsg = fmt::format("{0}: {1}", (entry.name != nullptr) ? entry.name : "<unknown function>", a_Msg);
AString errorMsg = fmt::format("{0}: {1}", (entry.name != nullptr) ? entry.name : "<unknown function>", msg);
// Log everything into the console: // Log everything into the console:
LOGWARNING("%s", errorMsg.c_str()); LOGWARNING("%s", errorMsg.c_str());

View File

@ -820,11 +820,29 @@ public:
/** Logs all items in the current stack trace to the server console */ /** Logs all items in the current stack trace to the server console */
static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0); static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
/** Formats and prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error. /** Prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters. To be used for bindings when they detect bad parameters.
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */ Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
int ApiParamError(const char * a_MsgFormat, fmt::ArgList); int ApiParamError(fmt::StringRef a_Msg);
FMT_VARIADIC(int, ApiParamError, const char *)
/** Formats and prints the message using printf-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters.
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
template <typename... Args>
int ApiParamError(const char * a_MsgFormat, const Args & ... a_Args)
{
return ApiParamError(Printf(a_MsgFormat, a_Args...));
}
/** Formats and prints the message using python-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters.
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
template <typename... Args>
int FApiParamError(const char * a_MsgFormat, const Args & ... a_Args)
{
return ApiParamError(fmt::format(a_MsgFormat, a_Args...));
}
/** Returns the type of the item on the specified position in the stack */ /** Returns the type of the item on the specified position in the stack */
AString GetTypeText(int a_StackPos); AString GetTypeText(int a_StackPos);

View File

@ -288,17 +288,17 @@ public:
L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, FnRef); L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, FnRef);
if (Self == nullptr) if (Self == nullptr)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'"); return L.ApiParamError("Invalid 'self'");
} }
if (!FnRef.IsValid()) if (!FnRef.IsValid())
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #5"); return L.ApiParamError("Expected a valid callback function for parameter #5");
} }
if (!(Self->*CoordCheckFn)(BlockX, BlockY, BlockZ)) if (!(Self->*CoordCheckFn)(BlockX, BlockY, BlockZ))
{ {
return lua_do_error(tolua_S, Printf("Error in function call '#funcname#': The provided coordinates ({%d, %d, %d}) are not valid", return L.FApiParamError("The provided coordinates ({0}) are not valid",
BlockX, BlockY, BlockZ Vector3i{BlockX, BlockY, BlockZ}
).c_str()); );
} }
// Call the DoWith function: // Call the DoWith function:

View File

@ -129,7 +129,7 @@ static int tolua_cBlockArea_Create(lua_State * a_LuaState)
// Create the area: // Create the area:
if ((size.x <= 0) || (size.y <= 0) || (size.z <= 0)) if ((size.x <= 0) || (size.y <= 0) || (size.z <= 0))
{ {
return L.ApiParamError("Invalid sizes, must be greater than zero, got {%d, %d, %d}", size.x, size.y, size.z); return L.FApiParamError("Invalid sizes, must be greater than zero, got {0}", size);
} }
ASSERT(self != nullptr); ASSERT(self != nullptr);
self->Create(size, dataTypes); self->Create(size, dataTypes);
@ -216,10 +216,8 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords"); readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords)) if (!self->IsValidCoords(coords))
{ {
return L.ApiParamError("Coords ({%d, %d, %d}) out of range ({%d, %d, %d} - {%d, %d, %d}).", return L.FApiParamError("Coords ({0}) out of range ({1} - {2).",
coords.x, coords.y, coords.z, coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
); );
} }
BLOCKTYPE blockType; BLOCKTYPE blockType;
@ -368,9 +366,8 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords"); readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords)) if (!self->IsValidRelCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range (max {%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range (max {1}).",
coords.x, coords.y, coords.z, coords, self->GetSize() - Vector3i{1, 1, 1}
self->GetSizeX() - 1, self->GetSizeY() - 1, self->GetSizeZ() - 1
); );
} }
BLOCKTYPE blockType; BLOCKTYPE blockType;
@ -518,32 +515,32 @@ static int tolua_cBlockArea_Read(lua_State * a_LuaState)
bounds.Sort(); bounds.Sort();
if (bounds.p1.y < 0) if (bounds.p1.y < 0)
{ {
LOGWARNING("cBlockArea:Read(): MinBlockY less than zero, adjusting to zero. Coords: {%d, %d, %d} - {%d, %d, %d}", FLOGWARNING("cBlockArea:Read(): MinBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z bounds.p1, bounds.p2
); );
L.LogStackTrace(); L.LogStackTrace();
bounds.p1.y = 0; bounds.p1.y = 0;
} }
else if (bounds.p1.y >= cChunkDef::Height) else if (bounds.p1.y >= cChunkDef::Height)
{ {
LOGWARNING("cBlockArea:Read(): MinBlockY more than chunk height, adjusting to chunk height. Coords: {%d, %d, %d} - {%d, %d, %d}", FLOGWARNING("cBlockArea:Read(): MinBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z bounds.p1, bounds.p2
); );
L.LogStackTrace(); L.LogStackTrace();
bounds.p1.y = cChunkDef::Height - 1; bounds.p1.y = cChunkDef::Height - 1;
} }
if (bounds.p2.y < 0) if (bounds.p2.y < 0)
{ {
LOGWARNING("cBlockArea:Read(): MaxBlockY less than zero, adjusting to zero. Coords: {%d, %d, %d} - {%d, %d, %d}", FLOGWARNING("cBlockArea:Read(): MaxBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z bounds.p1, bounds.p2
); );
L.LogStackTrace(); L.LogStackTrace();
bounds.p2.y = 0; bounds.p2.y = 0;
} }
else if (bounds.p2.y > cChunkDef::Height) else if (bounds.p2.y > cChunkDef::Height)
{ {
LOGWARNING("cBlockArea:Read(): MaxBlockY more than chunk height, adjusting to chunk height. Coords: {%d, %d, %d} - {%d, %d, %d}", FLOGWARNING("cBlockArea:Read(): MaxBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z bounds.p1, bounds.p2
); );
L.LogStackTrace(); L.LogStackTrace();
bounds.p2.y = cChunkDef::Height; bounds.p2.y = cChunkDef::Height;
@ -789,10 +786,8 @@ static int GetBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords"); readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords)) if (!self->IsValidCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
coords.x, coords.y, coords.z, coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
); );
} }
@ -842,9 +837,8 @@ static int GetRelBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords"); readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords)) if (!self->IsValidRelCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).", return L.ApiParamError("The coords ({0}) are out of range ({1}).",
coords.x, coords.y, coords.z, coords, self->GetSize()
self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
); );
} }
@ -894,10 +888,8 @@ static int SetBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords)) if (!self->IsValidCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
coords.x, coords.y, coords.z, coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
); );
} }
DataType data; DataType data;
@ -949,9 +941,8 @@ static int SetRelBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords)) if (!self->IsValidRelCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range ({1}).",
coords.x, coords.y, coords.z, coords, self->GetSize()
self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
); );
} }
DataType data; DataType data;
@ -993,10 +984,8 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords)) if (!self->IsValidCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
coords.x, coords.y, coords.z, coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
); );
} }
@ -1043,9 +1032,8 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords"); auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords)) if (!self->IsValidRelCoords(coords))
{ {
return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).", return L.FApiParamError("The coords ({0}) are out of range ({1}).",
coords.x, coords.y, coords.z, coords, self->GetSize()
self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
); );
} }

View File

@ -334,7 +334,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
cBlockEntityWithItems * BlockEntity = static_cast<cBlockEntityWithItems *>(DestChunk->GetBlockEntity(OutX, OutY, OutZ)); cBlockEntityWithItems * BlockEntity = static_cast<cBlockEntityWithItems *>(DestChunk->GetBlockEntity(OutX, OutY, OutZ));
if (BlockEntity == nullptr) if (BlockEntity == nullptr)
{ {
LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ); FLOGWARNING("{0}: A block entity was not found where expected at {1}", __FUNCTION__, Vector3i{OutX, OutY, OutZ});
return false; return false;
} }
res = MoveItemsToGrid(*BlockEntity); res = MoveItemsToGrid(*BlockEntity);
@ -360,7 +360,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
cChestEntity * MainChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)); cChestEntity * MainChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (MainChest == nullptr) if (MainChest == nullptr)
{ {
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{0, 1, 0});
return false; return false;
} }
if (MoveItemsFromGrid(*MainChest)) if (MoveItemsFromGrid(*MainChest))
@ -401,7 +401,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
cChestEntity * SideChest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z)); cChestEntity * SideChest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z));
if (SideChest == nullptr) if (SideChest == nullptr)
{ {
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{Coords[i].x, 1, Coords[i].z});
} }
else else
{ {
@ -426,7 +426,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
cFurnaceEntity * Furnace = static_cast<cFurnaceEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)); cFurnaceEntity * Furnace = static_cast<cFurnaceEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (Furnace == nullptr) if (Furnace == nullptr)
{ {
LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); FLOGWARNING("{0}: A furnace entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{0, 1, 0});
return false; return false;
} }
@ -527,7 +527,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
cChestEntity * ConnectedChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)); cChestEntity * ConnectedChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ));
if (ConnectedChest == nullptr) if (ConnectedChest == nullptr)
{ {
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ); FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, Vector3i{a_BlockX, a_BlockY, a_BlockZ});
return false; return false;
} }
if (MoveItemsToGrid(*ConnectedChest)) if (MoveItemsToGrid(*ConnectedChest))
@ -570,7 +570,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
cChestEntity * Chest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)); cChestEntity * Chest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z));
if (Chest == nullptr) if (Chest == nullptr)
{ {
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z); FLOGWARNING("{0}: A chest entity was not found where expected, at {1} ({2}, {3}})", __FUNCTION__, Vector3i{a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z}, x, z);
continue; continue;
} }
if (MoveItemsToGrid(*Chest)) if (MoveItemsToGrid(*Chest))

View File

@ -64,7 +64,7 @@ bool cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
{ {
a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().RemoveOneEquippedItem();
} }
LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), cMonster::MobTypeToString(MonsterType).c_str()); FLOGD("Changed monster spawner at {0} to type {1}.", GetPos(), cMonster::MobTypeToString(MonsterType));
return true; return true;
} }
return false; return false;

View File

@ -638,7 +638,7 @@ void cChunk::SpawnMobs(cMobSpawner & a_MobSpawner)
double ActualX = WorldX + 0.5; double ActualX = WorldX + 0.5;
double ActualZ = WorldZ + 0.5; double ActualZ = WorldZ + 0.5;
newMob->SetPosition(ActualX, WorldY, ActualZ); newMob->SetPosition(ActualX, WorldY, ActualZ);
LOGD("Spawning %s #%i at {%d, %d, %d}", newMob->GetClass(), newMob->GetUniqueID(), WorldX, WorldY, WorldZ); FLOGD("Spawning {0} #{1} at {2}", newMob->GetClass(), newMob->GetUniqueID(), Vector3i{WorldX, WorldY, WorldZ});
NumberOfSuccess++; NumberOfSuccess++;
} // while (retry) } // while (retry)
} }
@ -1056,11 +1056,11 @@ bool cChunk::GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Bl
{ {
// Place a randomly-facing produce: // Place a randomly-facing produce:
NIBBLETYPE Meta = (ProduceType == E_BLOCK_MELON) ? 0 : static_cast<NIBBLETYPE>(Random.RandInt(4) % 4); NIBBLETYPE Meta = (ProduceType == E_BLOCK_MELON) ? 0 : static_cast<NIBBLETYPE>(Random.RandInt(4) % 4);
LOGD("Growing melon / pumpkin at {%d, %d, %d} (<%d, %d> from stem), overwriting %s, growing on top of %s, meta %d", FLOGD("Growing melon / pumpkin at {0} (<{1}, {2}> from stem), overwriting {3}, growing on top of {4}, meta {5}",
a_RelX + x + m_PosX * cChunkDef::Width, a_RelY, a_RelZ + z + m_PosZ * cChunkDef::Width, PositionToWorldPosition(a_RelX + x, a_RelY, a_RelZ + z),
x, z, x, z,
ItemTypeToString(BlockType[CheckType]).c_str(), ItemTypeToString(BlockType[CheckType]),
ItemTypeToString(Soil).c_str(), ItemTypeToString(Soil),
Meta Meta
); );
VERIFY(UnboundedRelFastSetBlock(a_RelX + x, a_RelY, a_RelZ + z, ProduceType, Meta)); VERIFY(UnboundedRelFastSetBlock(a_RelX + x, a_RelY, a_RelZ + z, ProduceType, Meta));

View File

@ -217,7 +217,7 @@ public:
{ {
return MakeIndexNoCheck(x, y, z); return MakeIndexNoCheck(x, y, z);
} }
LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); FLOGERROR("cChunkDef::MakeIndex(): coords out of range: {0}; returning fake index 0", Vector3i{x, y, z});
ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
return 0; return 0;
} }

View File

@ -1059,8 +1059,8 @@ void cClientHandle::HandleAnvilItemName(const AString & a_ItemName)
void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status) void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status)
{ {
LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", FLOGD("HandleLeftClick: {0}; Face: {1}; Stat: {2}",
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, a_Status
); );
m_NumBlockChangeInteractionsThisTick++; m_NumBlockChangeInteractionsThisTick++;
@ -1298,9 +1298,9 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
(m_LastDigBlockZ != a_BlockZ) (m_LastDigBlockZ != a_BlockZ)
) )
{ {
LOGD("Prevented a dig / aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)", FLOGD("Prevented a dig / aim bug in the client (finish {0} vs start {1}, HSD: {2})",
a_BlockX, a_BlockY, a_BlockZ, Vector3i{a_BlockX, a_BlockY, a_BlockZ},
m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ, Vector3i{m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ},
(m_HasStartedDigging ? "True" : "False") (m_HasStartedDigging ? "True" : "False")
); );
return; return;
@ -1424,8 +1424,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
// TODO: This distance should be calculated from the point that the cursor pointing at, instead of the center of the block // TODO: This distance should be calculated from the point that the cursor pointing at, instead of the center of the block
// Distance from the block's center to the player's eye height // Distance from the block's center to the player's eye height
double Dist = (Vector3d(a_BlockX, a_BlockY, a_BlockZ) + Vector3d(0.5, 0.5, 0.5) - m_Player->GetEyePosition()).Length(); double Dist = (Vector3d(a_BlockX, a_BlockY, a_BlockZ) + Vector3d(0.5, 0.5, 0.5) - m_Player->GetEyePosition()).Length();
LOGD("HandleRightClick: {%d, %d, %d}, face %d, Hand: %d, HeldItem: %s; Dist: %.02f", FLOGD("HandleRightClick: {0}, face {1}, Hand: {2}, HeldItem: {3}; Dist: {4:.02f}",
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Hand, ItemToFullString(HeldItem).c_str(), Dist Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, a_Hand, ItemToFullString(HeldItem), Dist
); );
// Check the reach distance: // Check the reach distance:
@ -2789,8 +2789,8 @@ void cClientHandle::SendPlayerMaxSpeed(void)
void cClientHandle::SendPlayerMoveLook(void) void cClientHandle::SendPlayerMoveLook(void)
{ {
/* /*
LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d", FLOGD("Sending PlayerMoveLook: {0:0.2f}, stance {1:0.2f}, OnGround: {2}",
m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0 m_Player->GetPosition(), m_Player->GetStance(), m_Player->IsOnGround()
); );
*/ */
m_Protocol->SendPlayerMoveLook(); m_Protocol->SendPlayerMoveLook();

View File

@ -25,9 +25,8 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
SetAirDrag(0.2f); SetAirDrag(0.2f);
SetYawFromSpeed(); SetYawFromSpeed();
SetPitchFromSpeed(); SetPitchFromSpeed();
LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", FLOGD("Created arrow {0} with speed {1:.02f} and rot {{{2:.02f}, {3:.02f}}}",
m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), m_UniqueID, GetSpeed(), GetYaw(), GetPitch()
GetYaw(), GetPitch()
); );
} }

View File

@ -88,11 +88,11 @@ cEntity::~cEntity()
/* /*
// DEBUG: // DEBUG:
LOGD("Deleting entity %d at pos {%.2f, %.2f, %.2f} ~ [%d, %d]; ptr %p", FLOGD("Deleting entity {0} at pos {1:.2f} ~ [{2}, {3}]; ptr {4}",
m_UniqueID, m_UniqueID,
m_Pos.x, m_Pos.y, m_Pos.z, m_Pos,
(int)(m_Pos.x / cChunkDef::Width), (int)(m_Pos.z / cChunkDef::Width), GetChunkX(), GetChunkZ(),
this static_cast<void *>(this)
); );
*/ */
@ -146,8 +146,8 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
/* /*
// DEBUG: // DEBUG:
LOGD("Initializing entity #%d (%s) at {%.02f, %.02f, %.02f}", FLOGD("Initializing entity #{0} ({1}) at {2:.02f}",
m_UniqueID, GetClass(), m_Pos.x, m_Pos.y, m_Pos.z m_UniqueID, GetClass(), m_Pos
); );
*/ */
@ -992,8 +992,8 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
/* /*
// DEBUG: // DEBUG:
LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", FLOGD("Entity #{0} ({1}) is inside a block at {{2}}",
m_UniqueID, GetClass(), BlockX, BlockY, BlockZ m_UniqueID, GetClass(), Vector3i{BlockX, BlockY, BlockZ}
); );
*/ */
} }

View File

@ -71,11 +71,11 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{ {
// Fallen onto a solid block // Fallen onto a solid block
/* /*
LOGD( FLOGD(
"Sand: Checked below at {%d, %d, %d} (rel {%d, %d, %d}), it's %s, finishing the fall.", "Sand: Checked below at {0} (rel {1}), it's {2}, finishing the fall.",
BlockX, BlockY, BlockZ, Vector3i{BlockX, BlockY, BlockZ},
BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width, cChunkDef::AbsoluteToRelative({BlockX, BlockY, BlockZ}, {a_Chunk.GetPosX(), a_Chunk.GetPosZ()}),
ItemTypeToString(BlockBelow).c_str() ItemTypeToString(BlockBelow)
); );
*/ */

View File

@ -150,8 +150,8 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
SetWorld(World); // Use default world SetWorld(World); // Use default world
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}", FLOGD("Player \"{0}\" is connecting for the first time, spawning at default world spawn {1:.2f}",
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ() a_PlayerName, GetPosition()
); );
} }
@ -2256,8 +2256,8 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetDataPath(), GetName(), GetUUID().ToLongString(), &m_Stats); cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetDataPath(), GetName(), GetUUID().ToLongString(), &m_Stats);
StatSerializer.Load(); StatSerializer.Load();
LOGD("Player %s was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"", FLOGD("Player {0} was read from file \"{1}\", spawning at {2:.2f} in world \"{3}\"",
GetName().c_str(), a_FileName.c_str(), GetPosX(), GetPosY(), GetPosZ(), a_World->GetName().c_str() GetName(), a_FileName, GetPosition(), a_World->GetName()
); );
return true; return true;

View File

@ -60,11 +60,11 @@ protected:
{ {
/* /*
// DEBUG: // DEBUG:
LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)", FLOGD("Hit block {0}:{1} at {2} face {3}, {4} ({5})",
a_BlockType, a_BlockMeta, a_BlockType, a_BlockMeta,
a_BlockX, a_BlockY, a_BlockZ, a_EntryFace, Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_EntryFace,
cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid", cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid",
ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str() ItemToString(cItem(a_BlockType, 1, a_BlockMeta))
); );
*/ */
@ -306,10 +306,8 @@ void cProjectileEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
SetSpeed(0, 0, 0); SetSpeed(0, 0, 0);
// DEBUG: // DEBUG:
LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, hit solid block at face %d", FLOGD("Projectile {0}: pos {1:.02f}, hit solid block at face {2}",
m_UniqueID, m_UniqueID, a_HitPos, a_HitFace
a_HitPos.x, a_HitPos.y, a_HitPos.z,
a_HitFace
); );
m_IsInGround = true; m_IsInGround = true;
@ -401,11 +399,11 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff(); Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff();
// DEBUG: // DEBUG:
LOGD("Projectile %d has hit an entity %d (%s) at {%.02f, %.02f, %.02f} (coeff %.03f)", FLOGD("Projectile {0} has hit an entity {1} ({2}) at {3:.02f} (coeff {4:.03f})",
m_UniqueID, m_UniqueID,
EntityCollisionCallback.GetHitEntity()->GetUniqueID(), EntityCollisionCallback.GetHitEntity()->GetUniqueID(),
EntityCollisionCallback.GetHitEntity()->GetClass(), EntityCollisionCallback.GetHitEntity()->GetClass(),
HitPos.x, HitPos.y, HitPos.z, HitPos,
EntityCollisionCallback.GetMinCoeff() EntityCollisionCallback.GetMinCoeff()
); );
@ -438,11 +436,8 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
SetPitchFromSpeed(); SetPitchFromSpeed();
/* /*
LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}", FLOGD("Projectile {0}: pos {1:.02f}, speed {2:.02f}, rot {{{3:.02f}, {4:.02f}}}",
m_UniqueID, m_UniqueID, GetPos(), GetSpeed(), GetYaw(), GetPitch()
GetPosX(), GetPosY(), GetPosZ(),
GetSpeedX(), GetSpeedY(), GetSpeedZ(),
GetYaw(), GetPitch()
); );
*/ */
} }

View File

@ -35,7 +35,7 @@ void cTNTEntity::Explode(void)
{ {
m_FuseTicks = 0; m_FuseTicks = 0;
Destroy(true); Destroy(true);
LOGD("BOOM at {%f, %f, %f}", GetPosX(), GetPosY(), GetPosZ()); FLOGD("BOOM at {0}", GetPosition());
m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this); m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
} }

View File

@ -1548,7 +1548,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
auto NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); auto NewMob = cMonster::NewMonsterFromType(AnimalToSpawn);
NewMob->SetHealth(NewMob->GetMaxHealth()); NewMob->SetHealth(NewMob->GetMaxHealth());
NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); NewMob->SetPosition(AnimalX, AnimalY, AnimalZ);
LOGD("Spawning %s #%i at {%.02f, %.02f, %.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); FLOGD("Spawning {0} #{1} at {2:.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), NewMob->GetPosition());
a_ChunkDesc.GetEntities().emplace_back(std::move(NewMob)); a_ChunkDesc.GetEntities().emplace_back(std::move(NewMob));
return true; return true;
@ -1988,7 +1988,7 @@ void cFinishGenOrePockets::imprintSphere(
(blockZ >= baseZ) && (blockZ < baseZ + cChunkDef::Width) (blockZ >= baseZ) && (blockZ < baseZ + cChunkDef::Width)
) )
{ {
// LOGD("Imprinting a sphere center at {%d, %d, %d}", blockX, blockY, blockZ); // FLOGD("Imprinting a sphere center at {0}", Vector3i{blockX, blockY, blockZ});
a_ChunkDesc.SetBlockTypeMeta(blockX - baseX, blockY, blockZ - baseZ, a_OreType, a_OreMeta); a_ChunkDesc.SetBlockTypeMeta(blockX - baseX, blockY, blockZ - baseZ, a_OreType, a_OreMeta);
} }
return; return;

View File

@ -235,12 +235,11 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe
/* /*
// DEBUG: // DEBUG:
printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ); FLOGD("Placed the starting piece at {0}", Vector3i{a_BlockX, a_BlockY, a_BlockZ});
cCuboid Hitbox = a_OutPieces[0]->GetHitBox(); cCuboid Hitbox = a_OutPieces[0]->GetHitBox();
Hitbox.Sort(); Hitbox.Sort();
printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", FLOGD(" Hitbox: {0} - {1} ({2} * {3} * {4})\n",
Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, Hitbox.p1, Hitbox.p2,
Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
); );
DebugConnectorPool(ConnectorPool, 0); DebugConnectorPool(ConnectorPool, 0);
@ -264,12 +263,11 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe
// DEBUG: // DEBUG:
const cPlacedPiece * NewPiece = a_OutPieces.back(); const cPlacedPiece * NewPiece = a_OutPieces.back();
const Vector3i & Coords = NewPiece->GetCoords(); const Vector3i & Coords = NewPiece->GetCoords();
printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations()); FLOGD("Placed a new piece at {0}, rotation {1}\n", Coords, NewPiece->GetNumCCWRotations());
cCuboid Hitbox = NewPiece->GetHitBox(); cCuboid Hitbox = NewPiece->GetHitBox();
Hitbox.Sort(); Hitbox.Sort();
printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", FLOGD(" Hitbox: {0} - {1} ({2} * {3} * {4})\n",
Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, Hitbox.p1, Hitbox.p2,
Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
); );
DebugConnectorPool(ConnectorPool, NumProcessed + 1); DebugConnectorPool(ConnectorPool, NumProcessed + 1);

View File

@ -498,9 +498,12 @@ bool cPrefabPiecePool::ReadConnectorsCubesetVer1(
!cPiece::cConnector::StringToDirection(DirectionStr, Direction) !cPiece::cConnector::StringToDirection(DirectionStr, Direction)
) )
{ {
CONDWARNING(a_LogWarnings, "Piece %s in file %s has a malformed Connector at index %d ({%d, %d, %d}, type %d, direction %s). Skipping the connector.", if (a_LogWarnings)
a_PieceName.c_str(), a_FileName.c_str(), idx, RelX, RelY, RelZ, Type, DirectionStr.c_str() {
FLOGWARNING("Piece {0} in file {1} has a malformed Connector at index {2} ({3}, type {4}, direction {5}). Skipping the connector.",
a_PieceName, a_FileName, idx, Vector3i{RelX, RelY, RelZ}, Type, DirectionStr
); );
}
res = false; res = false;
lua_pop(a_LuaState, 1); // stk: [Connectors] lua_pop(a_LuaState, 1); // stk: [Connectors]
idx += 1; idx += 1;

View File

@ -89,10 +89,10 @@ public:
BLOCKTYPE RightNeighborBlock = a_World.GetBlock(RightNeighborPos); BLOCKTYPE RightNeighborBlock = a_World.GetBlock(RightNeighborPos);
/* /*
// DEBUG: // DEBUG:
LOGD("Door being placed at {%d, %d, %d}", a_BlockX, a_BlockY, a_BlockZ); FLOGD("Door being placed at {0}", Vector3i{a_BlockX, a_BlockY, a_BlockZ});
LOGD("RelDirToOutside: {%d, %d, %d}", RelDirToOutside.x, RelDirToOutside.y, RelDirToOutside.z); FLOGD("RelDirToOutside: {0}", RelDirToOutside);
LOGD("Left neighbor at {%d, %d, %d}: %d (%s)", LeftNeighborPos.x, LeftNeighborPos.y, LeftNeighborPos.z, LeftNeighborBlock, ItemTypeToString(LeftNeighborBlock).c_str()); FLOGD("Left neighbor at {0}: {1} ({2})", LeftNeighborPos, LeftNeighborBlock, ItemTypeToString(LeftNeighborBlock));
LOGD("Right neighbor at {%d, %d, %d}: %d (%s)", RightNeighborPos.x, RightNeighborPos.y, RightNeighborPos.z, RightNeighborBlock, ItemTypeToString(RightNeighborBlock).c_str()); FLOGD("Right neighbor at {0}: {1} ({2})", RightNeighborPos, RightNeighborBlock, ItemTypeToString(RightNeighborBlock));
*/ */
if ( if (
cBlockDoorHandler::IsDoorBlockType(LeftNeighborBlock) || // The block to the left is a door block cBlockDoorHandler::IsDoorBlockType(LeftNeighborBlock) || // The block to the left is a door block

View File

@ -275,7 +275,7 @@ void cNetherPortalScanner::OnDisabled(void)
if (!m_FoundPortal) if (!m_FoundPortal)
{ {
// Build a new nether portal. // Build a new nether portal.
LOGD("Building nether portal at {%d, %d, %d}", m_PortalLoc.x, m_PortalLoc.y, m_PortalLoc.z); FLOGD("Building nether portal at {0}", m_PortalLoc);
BuildNetherPortal(m_PortalLoc, m_Dir, m_BuildPlatform); BuildNetherPortal(m_PortalLoc, m_Dir, m_BuildPlatform);
m_PortalLoc.x += 1; m_PortalLoc.x += 1;
m_PortalLoc.y += 2; m_PortalLoc.y += 2;
@ -295,7 +295,7 @@ void cNetherPortalScanner::OnDisabled(void)
Position.z += OutOffset; Position.z += OutOffset;
} }
LOGD("Placing player at {%f, %f, %f}", Position.x, Position.y, Position.z); FLOGD("Placing player at {0}", Position);
m_Entity->ScheduleMoveToWorld(m_World, Position, true); m_Entity->ScheduleMoveToWorld(m_World, Position, true);
delete this; delete this;
} }

View File

@ -137,10 +137,10 @@ void cSetChunkData::RemoveInvalidBlockEntities(void)
if (EntityBlockType != WorldBlockType) if (EntityBlockType != WorldBlockType)
{ {
// Bad blocktype, remove the block entity: // Bad blocktype, remove the block entity:
LOGD("Block entity blocktype mismatch at {%d, %d, %d}: entity for blocktype %s(%d) in block %s(%d). Deleting the block entity.", FLOGD("Block entity blocktype mismatch at {0}: entity for blocktype {1}({2}) in block {3}({4}). Deleting the block entity.",
BlockEntity->GetPosX(), BlockEntity->GetPosY(), BlockEntity->GetPosZ(), BlockEntity->GetPos(),
ItemTypeToString(EntityBlockType).c_str(), EntityBlockType, ItemTypeToString(EntityBlockType), EntityBlockType,
ItemTypeToString(WorldBlockType).c_str(), WorldBlockType ItemTypeToString(WorldBlockType), WorldBlockType
); );
delete BlockEntity; delete BlockEntity;
itr = m_BlockEntities.erase(itr); itr = m_BlockEntities.erase(itr);

View File

@ -14,9 +14,9 @@
// Easy switch for turning on debugging logging: // Easy switch for turning on debugging logging:
#if 0 #if 0
#define FIRE_LOG LOGD #define FIRE_FLOG FLOGD
#else #else
#define FIRE_LOG(...) #define FIRE_FLOG(...)
#endif #endif
@ -111,9 +111,7 @@ void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
if (!IsAllowedBlock(BlockType)) if (!IsAllowedBlock(BlockType))
{ {
// The block is no longer eligible (not a fire block anymore; a player probably placed a block over the fire) // The block is no longer eligible (not a fire block anymore; a player probably placed a block over the fire)
FIRE_LOG("FS: Removing block {%d, %d, %d}", FIRE_FLOG("FS: Removing block {0}", AbsPos);
AbsPos.x, AbsPos.y, AbsPos.z
);
itr = Data.erase(itr); itr = Data.erase(itr);
continue; continue;
} }
@ -148,16 +146,16 @@ void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
} }
/* /*
FIRE_LOG("FS: Fire at {%d, %d, %d} is stepping", FIRE_FLOG("FS: Fire at {0} is stepping",
itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width a_Chunk->PositionToWorldPosition(itr->x, itr->y, itr->z)
); );
*/ */
// Has the fire burnt out? // Has the fire burnt out?
if (BlockMeta == 0x0f) if (BlockMeta == 0x0f)
{ {
// The fire burnt out completely // The fire burnt out completely
FIRE_LOG("FS: Fire at {%d, %d, %d} burnt out, removing the fire block", FIRE_FLOG("FS: Fire at {0} burnt out, removing the fire block",
itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width a_Chunk->PositionToWorldPosition({itr->x, itr->y, itr->z})
); );
a_Chunk->SetBlock(x, y, z, E_BLOCK_AIR, 0); a_Chunk->SetBlock(x, y, z, E_BLOCK_AIR, 0);
RemoveFuelNeighbors(a_Chunk, x, y, z); RemoveFuelNeighbors(a_Chunk, x, y, z);
@ -272,7 +270,7 @@ void cFireSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
} }
} // for itr - ChunkData[] } // for itr - ChunkData[]
FIRE_LOG("FS: Adding block {%d, %d, %d}", a_Block.x, a_Block.y, a_Block.z); FIRE_FLOG("FS: Adding block {0}", a_Block);
ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ, 100)); ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ, 100));
} }
@ -352,8 +350,8 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
// Start the fire in the neighbor {x, y, z} // Start the fire in the neighbor {x, y, z}
/* /*
FIRE_LOG("FS: Trying to start fire at {%d, %d, %d}.", FIRE_LOG("FS: Trying to start fire at {0}.",
x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width a_Chunk->PositionToWorldPosition(x, y, z)
); );
*/ */
if (CanStartFireInBlock(a_Chunk, x, y, z)) if (CanStartFireInBlock(a_Chunk, x, y, z))
@ -366,7 +364,7 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
return; return;
} }
FIRE_LOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ); FIRE_FLOG("FS: Starting new fire at {0}.", Vector3i{a_PosX, y, a_PosZ});
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0); a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
} }
} // for y } // for y

View File

@ -20,9 +20,9 @@
// Enable or disable detailed logging // Enable or disable detailed logging
#if 0 #if 0
#define FLUID_LOG LOGD #define FLUID_FLOG FLOGD
#else #else
#define FLUID_LOG(...) #define FLUID_FLOG(...)
#endif #endif
@ -49,8 +49,8 @@ cFloodyFluidSimulator::cFloodyFluidSimulator(
void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{ {
FLUID_LOG("Simulating block {%d, %d, %d}: block %d, meta %d", FLUID_FLOG("Simulating block {0}: block {1}, meta {2}",
a_Chunk->GetPosX() * cChunkDef::Width + a_RelX, a_RelY, a_Chunk->GetPosZ() * cChunkDef::Width + a_RelZ, a_Chunk->PositionToWorldPosition(a_RelX, a_RelY, a_RelZ),
a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ), a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ),
a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ) a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ)
); );
@ -61,7 +61,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
if (!IsAnyFluidBlock(MyBlock)) if (!IsAnyFluidBlock(MyBlock))
{ {
// Can happen - if a block is scheduled for simulating and gets replaced in the meantime. // Can happen - if a block is scheduled for simulating and gets replaced in the meantime.
FLUID_LOG(" BadBlockType exit"); FLUID_FLOG(" BadBlockType exit");
return; return;
} }
@ -79,7 +79,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
{ {
// Has no tributary, has been decreased (in CheckTributaries()), // Has no tributary, has been decreased (in CheckTributaries()),
// no more processing needed (neighbors have been scheduled by the decrease) // no more processing needed (neighbors have been scheduled by the decrease)
FLUID_LOG(" CheckTributaries exit"); FLUID_FLOG(" CheckTributaries exit");
return; return;
} }
} }
@ -154,7 +154,7 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
if (IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ))) if (IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ)))
{ {
// This block is fed from above, no more processing needed // This block is fed from above, no more processing needed
FLUID_LOG(" Fed from above"); FLUID_FLOG(" Fed from above");
return false; return false;
} }
} }
@ -180,10 +180,8 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
if (IsAllowedBlock(BlockType) && IsHigherMeta(BlockMeta, a_MyMeta)) if (IsAllowedBlock(BlockType) && IsHigherMeta(BlockMeta, a_MyMeta))
{ {
// This block is fed, no more processing needed // This block is fed, no more processing needed
FLUID_LOG(" Fed from {%d, %d, %d}, type %d, meta %d", FLUID_FLOG(" Fed from {0}, type {1}, meta {2}",
a_Chunk->GetPosX() * cChunkDef::Width + a_RelX + Coords[i].x, a_Chunk->PositionToWorldPosition(a_RelX+ Coords[i].x, a_RelY, a_RelZ + Coords[i].z),
a_RelY,
a_Chunk->GetPosZ() * cChunkDef::Width + a_RelZ + Coords[i].z,
BlockType, BlockMeta BlockType, BlockMeta
); );
return false; return false;
@ -194,7 +192,7 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
// Block is not fed, decrease by m_Falloff levels: // Block is not fed, decrease by m_Falloff levels:
if (a_MyMeta >= 8) if (a_MyMeta >= 8)
{ {
FLUID_LOG(" Not fed and downwards, turning into non-downwards meta %d", m_Falloff); FLUID_FLOG(" Not fed and downwards, turning into non-downwards meta {0}", m_Falloff);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, m_Falloff); a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, m_Falloff);
} }
else else
@ -202,12 +200,12 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
a_MyMeta += m_Falloff; a_MyMeta += m_Falloff;
if (a_MyMeta < 8) if (a_MyMeta < 8)
{ {
FLUID_LOG(" Not fed, decreasing from %d to %d", a_MyMeta - m_Falloff, a_MyMeta); FLUID_FLOG(" Not fed, decreasing from {0} to {1}", a_MyMeta - m_Falloff, a_MyMeta);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, a_MyMeta); a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, a_MyMeta);
} }
else else
{ {
FLUID_LOG(" Not fed, meta %d, erasing altogether", a_MyMeta); FLUID_FLOG(" Not fed, meta {0}, erasing altogether", a_MyMeta);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0); a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
} }
} }
@ -253,9 +251,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
{ {
// Lava flowing into water, change to stone / cobblestone based on direction: // Lava flowing into water, change to stone / cobblestone based on direction:
BLOCKTYPE NewBlock = (a_NewMeta == 8) ? E_BLOCK_STONE : E_BLOCK_COBBLESTONE; BLOCKTYPE NewBlock = (a_NewMeta == 8) ? E_BLOCK_STONE : E_BLOCK_COBBLESTONE;
FLUID_LOG(" Lava flowing into water, turning water at rel {%d, %d, %d} into stone", FLUID_FLOG(" Lava flowing into water, turning water at rel {0} into {1}",
a_RelX, a_RelY, a_RelZ, Vector3i{a_RelX, a_RelY, a_RelZ}, ItemTypeToString(NewBlock)
ItemTypeToString(NewBlock).c_str()
); );
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0);
@ -274,8 +271,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
{ {
// Water flowing into lava, change to cobblestone / obsidian based on dest block: // Water flowing into lava, change to cobblestone / obsidian based on dest block:
BLOCKTYPE NewBlock = (BlockMeta == 0) ? E_BLOCK_OBSIDIAN : E_BLOCK_COBBLESTONE; BLOCKTYPE NewBlock = (BlockMeta == 0) ? E_BLOCK_OBSIDIAN : E_BLOCK_COBBLESTONE;
FLUID_LOG(" Water flowing into lava, turning lava at rel {%d, %d, %d} into %s", FLUID_FLOG(" Water flowing into lava, turning lava at rel {0} into {1}",
a_RelX, a_RelY, a_RelZ, ItemTypeToString(NewBlock).c_str() Vector3i{a_RelX, a_RelY, a_RelZ}, ItemTypeToString(NewBlock)
); );
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0);
@ -320,7 +317,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
} // if (CanWashAway) } // if (CanWashAway)
// Spread: // Spread:
FLUID_LOG(" Spreading to {%d, %d, %d} with meta %d", BlockX, a_RelY, BlockZ, a_NewMeta); FLUID_FLOG(" Spreading to {0} with meta {1}", Vector3i{BlockX, a_RelY, BlockZ}, a_NewMeta);
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
m_World.GetSimulatorManager()->WakeUp({BlockX, a_RelY, BlockZ}, a_NearChunk); m_World.GetSimulatorManager()->WakeUp({BlockX, a_RelY, BlockZ}, a_NearChunk);
@ -333,7 +330,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{ {
FLUID_LOG(" Checking neighbors for source creation"); FLUID_FLOG(" Checking neighbors for source creation");
static const Vector3i NeighborCoords[] = static const Vector3i NeighborCoords[] =
{ {
@ -356,21 +353,21 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX
// Neighbor not available, skip it // Neighbor not available, skip it
continue; continue;
} }
// FLUID_LOG(" Neighbor at {%d, %d, %d}: %s", x, y, z, ItemToFullString(cItem(BlockType, 1, BlockMeta)).c_str()); // FLUID_FLOG(" Neighbor at {0}: {1}", Vector3i{x, y, z}, ItemToFullString(cItem(BlockType, 1, BlockMeta)));
if ((BlockMeta == 0) && IsAnyFluidBlock(BlockType)) if ((BlockMeta == 0) && IsAnyFluidBlock(BlockType))
{ {
NumNeeded--; NumNeeded--;
// FLUID_LOG(" Found a neighbor source at {%d, %d, %d}, NumNeeded := %d", x, y, z, NumNeeded); // FLUID_FLOG(" Found a neighbor source at {0}, NumNeeded := {1}", Vector3i{x, y, z}, NumNeeded);
if (NumNeeded == 0) if (NumNeeded == 0)
{ {
// Found enough, turn into a source and bail out // Found enough, turn into a source and bail out
// FLUID_LOG(" Found enough neighbor sources, turning into a source"); // FLUID_FLOG(" Found enough neighbor sources, turning into a source");
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, 0); a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, 0);
return true; return true;
} }
} }
} }
// FLUID_LOG(" Not enough neighbors for turning into a source, NumNeeded = %d", NumNeeded); // FLUID_FLOG(" Not enough neighbors for turning into a source, NumNeeded = {0}", NumNeeded);
return false; return false;
} }

View File

@ -55,9 +55,9 @@ void cSandSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
Pos.y = itr->y; Pos.y = itr->y;
Pos.z = itr->z + BaseZ; Pos.z = itr->z + BaseZ;
/* /*
LOGD( FLOGD(
"Creating a falling block at {%d, %d, %d} of type %s, block below: %s", "Creating a falling block at {0} of type {1}, block below: {2}",
Pos.x, Pos.y, Pos.z, ItemTypeToString(BlockType).c_str(), ItemTypeToString(BlockBelow).c_str() Pos, ItemTypeToString(BlockType), ItemTypeToString(BlockBelow)
); );
*/ */

View File

@ -350,6 +350,22 @@ public:
z = -z; z = -z;
} }
// tolua_end
/** Allows formatting a Vector<T> using the same format specifiers as for T
e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */
template <typename ArgFormatter>
friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec)
{
std::array<T, 3> Data{{a_Vec.x, a_Vec.y, a_Vec.z}};
a_Formatter.writer() << '{';
fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", "));
a_Formatter.writer() << '}';
}
// tolua_begin
/** The max difference between two coords for which the coords are assumed equal. */ /** The max difference between two coords for which the coords are assumed equal. */
static const double EPS; static const double EPS;

View File

@ -605,7 +605,7 @@ bool cWorld::SetSpawn(double a_X, double a_Y, double a_Z)
m_SpawnX = a_X; m_SpawnX = a_X;
m_SpawnY = a_Y; m_SpawnY = a_Y;
m_SpawnZ = a_Z; m_SpawnZ = a_Z;
LOGD("Spawn set at {%f, %f, %f}", m_SpawnX, m_SpawnY, m_SpawnZ); FLOGD("Spawn set at {0}", Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return true; return true;
} }
else else
@ -695,7 +695,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
{ {
SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5); SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5);
LOGINFO("World \"%s\": Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ); FLOGINFO("World \"{0}\": Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return; return;
} }
@ -729,14 +729,14 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ); cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ);
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, a_MaxSpawnRadius); cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, a_MaxSpawnRadius);
LOGINFO("World \"%s\":Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ); FLOGINFO("World \"{0}\":Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return; return;
} }
} }
} }
m_SpawnY = GetHeight(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ)); m_SpawnY = GetHeight(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ));
LOGWARNING("World \"%s\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ); FLOGWARNING("World \"{0}\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
} }

View File

@ -727,10 +727,10 @@ cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a
{ {
TypeName.assign(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID))); TypeName.assign(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID)));
} }
LOGINFO("WorldLoader(%s): Block entity mismatch: block type %s (%d), type \"%s\", at {%d, %d, %d}; the entity will be lost.", LOGINFO("WorldLoader({0}): Block entity mismatch: block type {1} ({2}), type \"{3}\", at {4}; the entity will be lost.",
m_World->GetName().c_str(), m_World->GetName(),
ItemTypeToString(a_BlockType).c_str(), a_BlockType, TypeName.c_str(), ItemTypeToString(a_BlockType), a_BlockType, TypeName,
a_BlockX, a_BlockY, a_BlockZ Vector3i{a_BlockX, a_BlockY, a_BlockZ}
); );
return nullptr; return nullptr;
} }
@ -937,10 +937,10 @@ bool cWSSAnvil::CheckBlockEntityType(const cParsedNBT & a_NBT, int a_TagIdx, con
expectedTypes.append(et); expectedTypes.append(et);
expectedTypes.push_back('\"'); expectedTypes.push_back('\"');
} }
LOGWARNING("Block entity type mismatch: exp %s, got \"%s\". The block entity at {%d, %d, %d} will lose all its properties.", LOGWARNING("Block entity type mismatch: exp {0}, got \"{1}\". The block entity at {2} will lose all its properties.",
expectedTypes.c_str() + 2, // Skip the first ", " that is extra in the string expectedTypes.c_str() + 2, // Skip the first ", " that is extra in the string
AString(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID))).c_str(), AString(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID))),
a_BlockX, a_BlockY, a_BlockZ Vector3i{a_BlockX, a_BlockY, a_BlockZ}
); );
return false; return false;
} }