CScriptCooker: Make use of unsigned stream helpers

Same behavior, less sign conversion warnings.
This commit is contained in:
Lioncash 2020-06-19 20:20:59 -04:00
parent d9046b4fd9
commit 7629f15f40
1 changed files with 47 additions and 46 deletions

View File

@ -7,13 +7,14 @@
void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, void* pData, bool InAtomicStruct) void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, void* pData, bool InAtomicStruct)
{ {
uint32 SizeOffset = 0, PropStart = 0; uint32 SizeOffset = 0;
uint32 PropStart = 0;
if (mGame >= EGame::EchoesDemo && !InAtomicStruct) if (mGame >= EGame::EchoesDemo && !InAtomicStruct)
{ {
rOut.WriteLong(pProperty->ID()); rOut.WriteULong(pProperty->ID());
SizeOffset = rOut.Tell(); SizeOffset = rOut.Tell();
rOut.WriteShort(0x0); rOut.WriteUShort(0x0);
PropStart = rOut.Tell(); PropStart = rOut.Tell();
} }
@ -22,105 +23,105 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
case EPropertyType::Bool: case EPropertyType::Bool:
{ {
CBoolProperty* pBool = TPropCast<CBoolProperty>(pProperty); auto* pBool = TPropCast<CBoolProperty>(pProperty);
rOut.WriteBool( pBool->Value(pData) ); rOut.WriteBool( pBool->Value(pData) );
break; break;
} }
case EPropertyType::Byte: case EPropertyType::Byte:
{ {
CByteProperty* pByte = TPropCast<CByteProperty>(pProperty); auto* pByte = TPropCast<CByteProperty>(pProperty);
rOut.WriteByte( pByte->Value(pData) ); rOut.WriteByte(pByte->Value(pData));
break; break;
} }
case EPropertyType::Short: case EPropertyType::Short:
{ {
CShortProperty* pShort = TPropCast<CShortProperty>(pProperty); auto* pShort = TPropCast<CShortProperty>(pProperty);
rOut.WriteShort( pShort->Value(pData) ); rOut.WriteShort(pShort->Value(pData));
break; break;
} }
case EPropertyType::Int: case EPropertyType::Int:
{ {
CIntProperty* pInt = TPropCast<CIntProperty>(pProperty); auto* pInt = TPropCast<CIntProperty>(pProperty);
rOut.WriteLong( pInt->Value(pData) ); rOut.WriteLong(pInt->Value(pData));
break; break;
} }
case EPropertyType::Float: case EPropertyType::Float:
{ {
CFloatProperty* pFloat = TPropCast<CFloatProperty>(pProperty); auto* pFloat = TPropCast<CFloatProperty>(pProperty);
rOut.WriteFloat( pFloat->Value(pData) ); rOut.WriteFloat(pFloat->Value(pData));
break; break;
} }
case EPropertyType::Choice: case EPropertyType::Choice:
{ {
CChoiceProperty* pChoice = TPropCast<CChoiceProperty>(pProperty); auto* pChoice = TPropCast<CChoiceProperty>(pProperty);
rOut.WriteLong( pChoice->Value(pData) ); rOut.WriteLong(pChoice->Value(pData));
break; break;
} }
case EPropertyType::Enum: case EPropertyType::Enum:
{ {
CEnumProperty* pEnum = TPropCast<CEnumProperty>(pProperty); auto* pEnum = TPropCast<CEnumProperty>(pProperty);
rOut.WriteLong( pEnum->Value(pData) ); rOut.WriteLong(pEnum->Value(pData));
break; break;
} }
case EPropertyType::Flags: case EPropertyType::Flags:
{ {
CFlagsProperty* pFlags = TPropCast<CFlagsProperty>(pProperty); auto* pFlags = TPropCast<CFlagsProperty>(pProperty);
rOut.WriteLong( pFlags->Value(pData) ); rOut.WriteLong(pFlags->Value(pData));
break; break;
} }
case EPropertyType::String: case EPropertyType::String:
{ {
CStringProperty* pString = TPropCast<CStringProperty>(pProperty); auto* pString = TPropCast<CStringProperty>(pProperty);
rOut.WriteString( pString->Value(pData) ); rOut.WriteString(pString->Value(pData));
break; break;
} }
case EPropertyType::Vector: case EPropertyType::Vector:
{ {
CVectorProperty* pVector = TPropCast<CVectorProperty>(pProperty); auto* pVector = TPropCast<CVectorProperty>(pProperty);
pVector->ValueRef(pData).Write(rOut); pVector->ValueRef(pData).Write(rOut);
break; break;
} }
case EPropertyType::Color: case EPropertyType::Color:
{ {
CColorProperty* pColor = TPropCast<CColorProperty>(pProperty); auto* pColor = TPropCast<CColorProperty>(pProperty);
pColor->ValueRef(pData).Write(rOut); pColor->ValueRef(pData).Write(rOut);
break; break;
} }
case EPropertyType::Asset: case EPropertyType::Asset:
{ {
CAssetProperty* pAsset = TPropCast<CAssetProperty>(pProperty); auto* pAsset = TPropCast<CAssetProperty>(pProperty);
pAsset->ValueRef(pData).Write(rOut); pAsset->ValueRef(pData).Write(rOut);
break; break;
} }
case EPropertyType::Sound: case EPropertyType::Sound:
{ {
CSoundProperty* pSound = TPropCast<CSoundProperty>(pProperty); auto* pSound = TPropCast<CSoundProperty>(pProperty);
rOut.WriteLong( pSound->Value(pData) ); rOut.WriteLong( pSound->Value(pData) );
break; break;
} }
case EPropertyType::Animation: case EPropertyType::Animation:
{ {
CAnimationProperty* pAnim = TPropCast<CAnimationProperty>(pProperty); auto* pAnim = TPropCast<CAnimationProperty>(pProperty);
rOut.WriteLong( pAnim->Value(pData) ); rOut.WriteLong( pAnim->Value(pData) );
break; break;
} }
case EPropertyType::AnimationSet: case EPropertyType::AnimationSet:
{ {
CAnimationSetProperty* pAnimSet = TPropCast<CAnimationSetProperty>(pProperty); auto* pAnimSet = TPropCast<CAnimationSetProperty>(pProperty);
pAnimSet->ValueRef(pData).Write(rOut); pAnimSet->ValueRef(pData).Write(rOut);
break; break;
} }
@ -133,7 +134,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
case EPropertyType::Spline: case EPropertyType::Spline:
{ {
CSplineProperty* pSpline = TPropCast<CSplineProperty>(pProperty); auto* pSpline = TPropCast<CSplineProperty>(pProperty);
std::vector<char>& rBuffer = pSpline->ValueRef(pData); std::vector<char>& rBuffer = pSpline->ValueRef(pData);
if (!rBuffer.empty()) if (!rBuffer.empty())
@ -164,7 +165,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
case EPropertyType::Guid: case EPropertyType::Guid:
{ {
CGuidProperty* pGuid = TPropCast<CGuidProperty>(pProperty); auto* pGuid = TPropCast<CGuidProperty>(pProperty);
std::vector<char>& rBuffer = pGuid->ValueRef(pData); std::vector<char>& rBuffer = pGuid->ValueRef(pData);
if (rBuffer.empty()) if (rBuffer.empty())
@ -176,7 +177,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
case EPropertyType::Struct: case EPropertyType::Struct:
{ {
CStructProperty* pStruct = TPropCast<CStructProperty>(pProperty); auto* pStruct = TPropCast<CStructProperty>(pProperty);
std::vector<IProperty*> PropertiesToWrite; std::vector<IProperty*> PropertiesToWrite;
for (uint32 ChildIdx = 0; ChildIdx < pStruct->NumChildren(); ChildIdx++) for (uint32 ChildIdx = 0; ChildIdx < pStruct->NumChildren(); ChildIdx++)
@ -190,9 +191,9 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
if (!pStruct->IsAtomic()) if (!pStruct->IsAtomic())
{ {
if (mGame <= EGame::Prime) if (mGame <= EGame::Prime)
rOut.WriteLong(PropertiesToWrite.size()); rOut.WriteULong(static_cast<uint32>(PropertiesToWrite.size()));
else else
rOut.WriteShort((uint16) PropertiesToWrite.size()); rOut.WriteUShort(static_cast<uint16>(PropertiesToWrite.size()));
} }
for (auto* property : PropertiesToWrite) for (auto* property : PropertiesToWrite)
@ -204,8 +205,8 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
case EPropertyType::Array: case EPropertyType::Array:
{ {
CArrayProperty* pArray = TPropCast<CArrayProperty>(pProperty); CArrayProperty* pArray = TPropCast<CArrayProperty>(pProperty);
uint32 Count = pArray->ArrayCount(pData); const uint32 Count = pArray->ArrayCount(pData);
rOut.WriteLong(Count); rOut.WriteULong(Count);
for (uint32 ElementIdx = 0; ElementIdx < pArray->ArrayCount(pData); ElementIdx++) for (uint32 ElementIdx = 0; ElementIdx < pArray->ArrayCount(pData); ElementIdx++)
{ {
@ -220,9 +221,9 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
if (SizeOffset != 0) if (SizeOffset != 0)
{ {
uint32 PropEnd = rOut.Tell(); const uint32 PropEnd = rOut.Tell();
rOut.Seek(SizeOffset, SEEK_SET); rOut.Seek(SizeOffset, SEEK_SET);
rOut.WriteShort((uint16) (PropEnd - PropStart)); rOut.WriteUShort(static_cast<uint16>(PropEnd - PropStart));
rOut.Seek(PropEnd, SEEK_SET); rOut.Seek(PropEnd, SEEK_SET);
} }
} }
@ -236,24 +237,24 @@ void CScriptCooker::WriteInstance(IOutputStream& rOut, CScriptObject *pInstance)
const bool IsPrime1 = mGame <= EGame::Prime; const bool IsPrime1 = mGame <= EGame::Prime;
const uint32 ObjectType = pInstance->ObjectTypeID(); const uint32 ObjectType = pInstance->ObjectTypeID();
IsPrime1 ? rOut.WriteByte(static_cast<uint8>(ObjectType)) : rOut.WriteLong(ObjectType); IsPrime1 ? rOut.WriteUByte(static_cast<uint8>(ObjectType)) : rOut.WriteULong(ObjectType);
const uint32 SizeOffset = rOut.Tell(); const uint32 SizeOffset = rOut.Tell();
IsPrime1 ? rOut.WriteLong(0) : rOut.WriteShort(0); IsPrime1 ? rOut.WriteLong(0) : rOut.WriteShort(0);
const uint32 InstanceStart = rOut.Tell(); const uint32 InstanceStart = rOut.Tell();
const uint32 InstanceID = (pInstance->Layer()->AreaIndex() << 26) | pInstance->InstanceID(); const uint32 InstanceID = (pInstance->Layer()->AreaIndex() << 26) | pInstance->InstanceID();
rOut.WriteLong(InstanceID); rOut.WriteULong(InstanceID);
const size_t NumLinks = pInstance->NumLinks(ELinkType::Outgoing); const size_t NumLinks = pInstance->NumLinks(ELinkType::Outgoing);
IsPrime1 ? rOut.WriteLong(static_cast<int32>(NumLinks)) : rOut.WriteShort(static_cast<uint16>(NumLinks)); IsPrime1 ? rOut.WriteLong(static_cast<int32>(NumLinks)) : rOut.WriteUShort(static_cast<uint16>(NumLinks));
for (size_t LinkIdx = 0; LinkIdx < NumLinks; LinkIdx++) for (size_t LinkIdx = 0; LinkIdx < NumLinks; LinkIdx++)
{ {
const CLink *pLink = pInstance->Link(ELinkType::Outgoing, LinkIdx); const CLink *pLink = pInstance->Link(ELinkType::Outgoing, LinkIdx);
rOut.WriteLong(pLink->State()); rOut.WriteULong(pLink->State());
rOut.WriteLong(pLink->Message()); rOut.WriteULong(pLink->Message());
rOut.WriteLong(pLink->ReceiverID()); rOut.WriteULong(pLink->ReceiverID());
} }
WriteProperty(rOut, pInstance->Template()->Properties(), pInstance->PropertyData(), false); WriteProperty(rOut, pInstance->Template()->Properties(), pInstance->PropertyData(), false);
@ -261,7 +262,7 @@ void CScriptCooker::WriteInstance(IOutputStream& rOut, CScriptObject *pInstance)
rOut.Seek(SizeOffset, SEEK_SET); rOut.Seek(SizeOffset, SEEK_SET);
const uint32 Size = InstanceEnd - InstanceStart; const uint32 Size = InstanceEnd - InstanceStart;
IsPrime1 ? rOut.WriteLong(Size) : rOut.WriteShort(static_cast<uint16>(Size)); IsPrime1 ? rOut.WriteULong(Size) : rOut.WriteUShort(static_cast<uint16>(Size));
rOut.Seek(InstanceEnd, SEEK_SET); rOut.Seek(InstanceEnd, SEEK_SET);
} }
@ -271,7 +272,7 @@ void CScriptCooker::WriteLayer(IOutputStream& rOut, CScriptLayer *pLayer)
rOut.WriteByte(mGame <= EGame::Prime ? 0 : 1); // Version rOut.WriteByte(mGame <= EGame::Prime ? 0 : 1); // Version
uint32 InstanceCountOffset = rOut.Tell(); const uint32 InstanceCountOffset = rOut.Tell();
uint32 NumWrittenInstances = 0; uint32 NumWrittenInstances = 0;
rOut.WriteLong(0); rOut.WriteLong(0);
@ -330,16 +331,16 @@ void CScriptCooker::WriteLayer(IOutputStream& rOut, CScriptLayer *pLayer)
} }
} }
uint32 LayerEnd = rOut.Tell(); const uint32 LayerEnd = rOut.Tell();
rOut.GoTo(InstanceCountOffset); rOut.GoTo(InstanceCountOffset);
rOut.WriteLong(NumWrittenInstances); rOut.WriteULong(NumWrittenInstances);
rOut.GoTo(LayerEnd); rOut.GoTo(LayerEnd);
} }
void CScriptCooker::WriteGeneratedLayer(IOutputStream& rOut) void CScriptCooker::WriteGeneratedLayer(IOutputStream& rOut)
{ {
rOut.WriteByte(1); // Version rOut.WriteByte(1); // Version
rOut.WriteLong(mGeneratedObjects.size()); rOut.WriteULong(static_cast<uint32>(mGeneratedObjects.size()));
for (auto* object : mGeneratedObjects) for (auto* object : mGeneratedObjects)
WriteInstance(rOut, object); WriteInstance(rOut, object);