summaryrefslogtreecommitdiff
path: root/ZAPD/ZRoom/Commands/SetActorList.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-09-13 11:29:46 -0300
committerGitHub <noreply@github.com>2021-09-13 10:29:46 -0400
commit4d051c0fa036d245027a211bc7fd6a4afdce207f (patch)
treeeb1697990e40e60343971b777cbfe99c6eee548c /ZAPD/ZRoom/Commands/SetActorList.cpp
parent90662f3cbade844c8edc3943ab8252e334b6166a (diff)
ZRoom cleaning 3 (#140)
* Remove redundant scene member * altheaders clean * it is broken and I don't know why * fix VTXs * Fix the stuff I broke in SetRoomList * Add RoomAltHeader and SceneAltHeader * fix syotes again and set the size of each ZRoomCommand * Add SCENE_CMD_UNK_09 todo * Nuke HintSystem * run format * Remove `canHaveInner` from ZRoom since the HintSystem doesn't exists anymore * Remove sourceOutput member from ZResource * Update docs * run format * Add non 64-bits aligned textures warning * remove unused json library * Update SCENE_CMD_UNK_09 * Fix merge issues * run format * Clean up actorlist output * Fix merge conflicts * format * Fix actorlist extraction * Unify AltHeader * fix merge conflicts * Run formatter * minor style changes * fix using wrong symbols for extracted vtxs from overlays * format * fix makefile stuff * fix merge issue
Diffstat (limited to 'ZAPD/ZRoom/Commands/SetActorList.cpp')
-rw-r--r--ZAPD/ZRoom/Commands/SetActorList.cpp109
1 files changed, 70 insertions, 39 deletions
diff --git a/ZAPD/ZRoom/Commands/SetActorList.cpp b/ZAPD/ZRoom/Commands/SetActorList.cpp
index d93b2c9..64cea55 100644
--- a/ZAPD/ZRoom/Commands/SetActorList.cpp
+++ b/ZAPD/ZRoom/Commands/SetActorList.cpp
@@ -15,10 +15,26 @@ void SetActorList::ParseRawData()
{
ZRoomCommand::ParseRawData();
numActors = cmdArg1;
+}
+
+void SetActorList::DeclareReferences(const std::string& prefix)
+{
+ if (numActors != 0 && cmdArg2 != 0)
+ {
+ std::string varName =
+ StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset);
+ parent->AddDeclarationPlaceholder(segmentOffset, varName);
+ }
+}
+
+void SetActorList::ParseRawDataLate()
+{
+ ZRoomCommand::ParseRawDataLate();
+ size_t actorsAmount = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 0x10;
uint32_t currentPtr = segmentOffset;
- for (size_t i = 0; i < numActors; i++)
+ for (size_t i = 0; i < actorsAmount; i++)
{
ActorSpawnEntry entry(parent->GetRawData(), currentPtr);
@@ -27,50 +43,56 @@ void SetActorList::ParseRawData()
}
}
-void SetActorList::DeclareReferences(const std::string& prefix)
+void SetActorList::DeclareReferencesLate(const std::string& prefix)
{
- if (!actors.empty())
+ if (actors.empty())
+ return;
+
+ std::string declaration = "";
+
+ size_t largestlength = 0;
+ for (const auto& entry : actors)
{
- std::string declaration = "";
+ size_t actorNameLength = ZNames::GetActorName(entry.GetActorId()).size();
+ if (actorNameLength > largestlength)
+ largestlength = actorNameLength;
+ }
- size_t index = 0;
- for (const auto& entry : actors)
- {
- declaration +=
- StringHelper::Sprintf("\t{ %s }, // 0x%06X", entry.GetBodySourceCode().c_str(),
- segmentOffset + (index * 16));
+ size_t index = 0;
+ for (auto& entry : actors)
+ {
+ entry.SetLargestActorName(largestlength);
+ declaration += StringHelper::Sprintf("\t{ %s },", entry.GetBodySourceCode().c_str());
- if (index < actors.size() - 1)
- declaration += "\n";
+ if (index < actors.size() - 1)
+ declaration += "\n";
- index++;
- }
+ index++;
+ }
- const auto& entry = actors.front();
+ const auto& entry = actors.front();
- DeclarationPadding padding = DeclarationPadding::Pad16;
- if (Globals::Instance->game == ZGame::MM_RETAIL)
- padding = DeclarationPadding::None;
+ DeclarationPadding padding = DeclarationPadding::Pad16;
+ if (Globals::Instance->game == ZGame::MM_RETAIL)
+ padding = DeclarationPadding::None;
- parent->AddDeclarationArray(
- segmentOffset, DeclarationAlignment::Align4, padding,
- actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
- StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset),
- GetActorListArraySize(), declaration);
- }
+ std::string varName = StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset);
+ parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, padding,
+ actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
+ varName, GetActorListArraySize(), declaration);
}
std::string SetActorList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
+ if (numActors != actors.size())
+ {
+ printf("%s: numActors(%i) ~ actors(%li)\n", parent->GetName().c_str(), numActors,
+ actors.size());
+ }
return StringHelper::Sprintf("SCENE_CMD_ACTOR_LIST(%i, %s)", numActors, listName.c_str());
}
-size_t SetActorList::GetRawDataSize() const
-{
- return ZRoomCommand::GetRawDataSize() + ((int32_t)actors.size() * 16);
-}
-
size_t SetActorList::GetActorListArraySize() const
{
size_t actorCount = 0;
@@ -110,27 +132,31 @@ ActorSpawnEntry::ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t r
posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
- rotX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
- rotY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
- rotZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
+ rotX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 8);
+ rotY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 10);
+ rotZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12);
initVar = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
}
std::string ActorSpawnEntry::GetBodySourceCode() const
{
- std::string body = "\n";
+ std::string body = "";
+
+ std::string actorNameFmt = StringHelper::Sprintf("%%-%zus ", largestActorName + 1);
+ body =
+ StringHelper::Sprintf(actorNameFmt.c_str(), (ZNames::GetActorName(actorNum) + ",").c_str());
- body += "\t\t" + ZNames::GetActorName(actorNum) + ",\n";
- body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", posX, posY, posZ);
+ body += StringHelper::Sprintf("{ %6i, %6i, %6i }, ", posX, posY, posZ);
if (Globals::Instance->game == ZGame::MM_RETAIL)
- body += StringHelper::Sprintf("\t\t{ SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, "
- "0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X)},\n",
+ body += StringHelper::Sprintf("{ SPAWN_ROT_FLAGS(%#5hX, 0x%04X)"
+ ", SPAWN_ROT_FLAGS(%#5hX, 0x%04X)"
+ ", SPAWN_ROT_FLAGS(%#5hX, 0x%04X) }, ",
(rotX >> 7) & 0b111111111, rotX & 0b1111111,
(rotY >> 7) & 0b111111111, rotY & 0b1111111,
(rotZ >> 7) & 0b111111111, rotZ & 0b1111111);
else
- body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", rotX, rotY, rotZ);
- body += StringHelper::Sprintf("\t\t0x%04X\n ", initVar);
+ body += StringHelper::Sprintf("{ %#6hX, %#6hX, %#6hX }, ", rotX, rotY, rotZ);
+ body += StringHelper::Sprintf("0x%04X", initVar);
return body;
}
@@ -149,3 +175,8 @@ uint16_t ActorSpawnEntry::GetActorId() const
{
return actorNum;
}
+
+void ActorSpawnEntry::SetLargestActorName(size_t nameSize)
+{
+ largestActorName = nameSize;
+}