From 7629f15f408a78bd52e078cb476527980ed33d8e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 19 Jun 2020 20:20:59 -0400 Subject: [PATCH] CScriptCooker: Make use of unsigned stream helpers Same behavior, less sign conversion warnings. --- src/Core/Resource/Cooker/CScriptCooker.cpp | 93 +++++++++++----------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/src/Core/Resource/Cooker/CScriptCooker.cpp b/src/Core/Resource/Cooker/CScriptCooker.cpp index 941959fe..1cc7f238 100644 --- a/src/Core/Resource/Cooker/CScriptCooker.cpp +++ b/src/Core/Resource/Cooker/CScriptCooker.cpp @@ -7,13 +7,14 @@ 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) { - rOut.WriteLong(pProperty->ID()); + rOut.WriteULong(pProperty->ID()); SizeOffset = rOut.Tell(); - rOut.WriteShort(0x0); + rOut.WriteUShort(0x0); PropStart = rOut.Tell(); } @@ -22,105 +23,105 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi case EPropertyType::Bool: { - CBoolProperty* pBool = TPropCast(pProperty); + auto* pBool = TPropCast(pProperty); rOut.WriteBool( pBool->Value(pData) ); break; } case EPropertyType::Byte: { - CByteProperty* pByte = TPropCast(pProperty); - rOut.WriteByte( pByte->Value(pData) ); + auto* pByte = TPropCast(pProperty); + rOut.WriteByte(pByte->Value(pData)); break; } case EPropertyType::Short: { - CShortProperty* pShort = TPropCast(pProperty); - rOut.WriteShort( pShort->Value(pData) ); + auto* pShort = TPropCast(pProperty); + rOut.WriteShort(pShort->Value(pData)); break; } case EPropertyType::Int: { - CIntProperty* pInt = TPropCast(pProperty); - rOut.WriteLong( pInt->Value(pData) ); + auto* pInt = TPropCast(pProperty); + rOut.WriteLong(pInt->Value(pData)); break; } case EPropertyType::Float: { - CFloatProperty* pFloat = TPropCast(pProperty); - rOut.WriteFloat( pFloat->Value(pData) ); + auto* pFloat = TPropCast(pProperty); + rOut.WriteFloat(pFloat->Value(pData)); break; } case EPropertyType::Choice: { - CChoiceProperty* pChoice = TPropCast(pProperty); - rOut.WriteLong( pChoice->Value(pData) ); + auto* pChoice = TPropCast(pProperty); + rOut.WriteLong(pChoice->Value(pData)); break; } case EPropertyType::Enum: { - CEnumProperty* pEnum = TPropCast(pProperty); - rOut.WriteLong( pEnum->Value(pData) ); + auto* pEnum = TPropCast(pProperty); + rOut.WriteLong(pEnum->Value(pData)); break; } case EPropertyType::Flags: { - CFlagsProperty* pFlags = TPropCast(pProperty); - rOut.WriteLong( pFlags->Value(pData) ); + auto* pFlags = TPropCast(pProperty); + rOut.WriteLong(pFlags->Value(pData)); break; } case EPropertyType::String: { - CStringProperty* pString = TPropCast(pProperty); - rOut.WriteString( pString->Value(pData) ); + auto* pString = TPropCast(pProperty); + rOut.WriteString(pString->Value(pData)); break; } case EPropertyType::Vector: { - CVectorProperty* pVector = TPropCast(pProperty); + auto* pVector = TPropCast(pProperty); pVector->ValueRef(pData).Write(rOut); break; } case EPropertyType::Color: { - CColorProperty* pColor = TPropCast(pProperty); + auto* pColor = TPropCast(pProperty); pColor->ValueRef(pData).Write(rOut); break; } case EPropertyType::Asset: { - CAssetProperty* pAsset = TPropCast(pProperty); + auto* pAsset = TPropCast(pProperty); pAsset->ValueRef(pData).Write(rOut); break; } case EPropertyType::Sound: { - CSoundProperty* pSound = TPropCast(pProperty); + auto* pSound = TPropCast(pProperty); rOut.WriteLong( pSound->Value(pData) ); break; } case EPropertyType::Animation: { - CAnimationProperty* pAnim = TPropCast(pProperty); + auto* pAnim = TPropCast(pProperty); rOut.WriteLong( pAnim->Value(pData) ); break; } case EPropertyType::AnimationSet: { - CAnimationSetProperty* pAnimSet = TPropCast(pProperty); + auto* pAnimSet = TPropCast(pProperty); pAnimSet->ValueRef(pData).Write(rOut); break; } @@ -133,7 +134,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi case EPropertyType::Spline: { - CSplineProperty* pSpline = TPropCast(pProperty); + auto* pSpline = TPropCast(pProperty); std::vector& rBuffer = pSpline->ValueRef(pData); if (!rBuffer.empty()) @@ -164,7 +165,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi case EPropertyType::Guid: { - CGuidProperty* pGuid = TPropCast(pProperty); + auto* pGuid = TPropCast(pProperty); std::vector& rBuffer = pGuid->ValueRef(pData); if (rBuffer.empty()) @@ -176,7 +177,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi case EPropertyType::Struct: { - CStructProperty* pStruct = TPropCast(pProperty); + auto* pStruct = TPropCast(pProperty); std::vector PropertiesToWrite; for (uint32 ChildIdx = 0; ChildIdx < pStruct->NumChildren(); ChildIdx++) @@ -190,9 +191,9 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi if (!pStruct->IsAtomic()) { if (mGame <= EGame::Prime) - rOut.WriteLong(PropertiesToWrite.size()); + rOut.WriteULong(static_cast(PropertiesToWrite.size())); else - rOut.WriteShort((uint16) PropertiesToWrite.size()); + rOut.WriteUShort(static_cast(PropertiesToWrite.size())); } for (auto* property : PropertiesToWrite) @@ -204,8 +205,8 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi case EPropertyType::Array: { CArrayProperty* pArray = TPropCast(pProperty); - uint32 Count = pArray->ArrayCount(pData); - rOut.WriteLong(Count); + const uint32 Count = pArray->ArrayCount(pData); + rOut.WriteULong(Count); for (uint32 ElementIdx = 0; ElementIdx < pArray->ArrayCount(pData); ElementIdx++) { @@ -220,9 +221,9 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi if (SizeOffset != 0) { - uint32 PropEnd = rOut.Tell(); + const uint32 PropEnd = rOut.Tell(); rOut.Seek(SizeOffset, SEEK_SET); - rOut.WriteShort((uint16) (PropEnd - PropStart)); + rOut.WriteUShort(static_cast(PropEnd - PropStart)); rOut.Seek(PropEnd, SEEK_SET); } } @@ -236,24 +237,24 @@ void CScriptCooker::WriteInstance(IOutputStream& rOut, CScriptObject *pInstance) const bool IsPrime1 = mGame <= EGame::Prime; const uint32 ObjectType = pInstance->ObjectTypeID(); - IsPrime1 ? rOut.WriteByte(static_cast(ObjectType)) : rOut.WriteLong(ObjectType); + IsPrime1 ? rOut.WriteUByte(static_cast(ObjectType)) : rOut.WriteULong(ObjectType); const uint32 SizeOffset = rOut.Tell(); IsPrime1 ? rOut.WriteLong(0) : rOut.WriteShort(0); const uint32 InstanceStart = rOut.Tell(); const uint32 InstanceID = (pInstance->Layer()->AreaIndex() << 26) | pInstance->InstanceID(); - rOut.WriteLong(InstanceID); + rOut.WriteULong(InstanceID); const size_t NumLinks = pInstance->NumLinks(ELinkType::Outgoing); - IsPrime1 ? rOut.WriteLong(static_cast(NumLinks)) : rOut.WriteShort(static_cast(NumLinks)); + IsPrime1 ? rOut.WriteLong(static_cast(NumLinks)) : rOut.WriteUShort(static_cast(NumLinks)); for (size_t LinkIdx = 0; LinkIdx < NumLinks; LinkIdx++) { const CLink *pLink = pInstance->Link(ELinkType::Outgoing, LinkIdx); - rOut.WriteLong(pLink->State()); - rOut.WriteLong(pLink->Message()); - rOut.WriteLong(pLink->ReceiverID()); + rOut.WriteULong(pLink->State()); + rOut.WriteULong(pLink->Message()); + rOut.WriteULong(pLink->ReceiverID()); } WriteProperty(rOut, pInstance->Template()->Properties(), pInstance->PropertyData(), false); @@ -261,7 +262,7 @@ void CScriptCooker::WriteInstance(IOutputStream& rOut, CScriptObject *pInstance) rOut.Seek(SizeOffset, SEEK_SET); const uint32 Size = InstanceEnd - InstanceStart; - IsPrime1 ? rOut.WriteLong(Size) : rOut.WriteShort(static_cast(Size)); + IsPrime1 ? rOut.WriteULong(Size) : rOut.WriteUShort(static_cast(Size)); rOut.Seek(InstanceEnd, SEEK_SET); } @@ -271,7 +272,7 @@ void CScriptCooker::WriteLayer(IOutputStream& rOut, CScriptLayer *pLayer) rOut.WriteByte(mGame <= EGame::Prime ? 0 : 1); // Version - uint32 InstanceCountOffset = rOut.Tell(); + const uint32 InstanceCountOffset = rOut.Tell(); uint32 NumWrittenInstances = 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.WriteLong(NumWrittenInstances); + rOut.WriteULong(NumWrittenInstances); rOut.GoTo(LayerEnd); } void CScriptCooker::WriteGeneratedLayer(IOutputStream& rOut) { rOut.WriteByte(1); // Version - rOut.WriteLong(mGeneratedObjects.size()); + rOut.WriteULong(static_cast(mGeneratedObjects.size())); for (auto* object : mGeneratedObjects) WriteInstance(rOut, object);