CScriptCooker: Make use of unsigned stream helpers
Same behavior, less sign conversion warnings.
This commit is contained in:
parent
d9046b4fd9
commit
7629f15f40
|
@ -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<CBoolProperty>(pProperty);
|
||||
auto* pBool = TPropCast<CBoolProperty>(pProperty);
|
||||
rOut.WriteBool( pBool->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Byte:
|
||||
{
|
||||
CByteProperty* pByte = TPropCast<CByteProperty>(pProperty);
|
||||
rOut.WriteByte( pByte->Value(pData) );
|
||||
auto* pByte = TPropCast<CByteProperty>(pProperty);
|
||||
rOut.WriteByte(pByte->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Short:
|
||||
{
|
||||
CShortProperty* pShort = TPropCast<CShortProperty>(pProperty);
|
||||
rOut.WriteShort( pShort->Value(pData) );
|
||||
auto* pShort = TPropCast<CShortProperty>(pProperty);
|
||||
rOut.WriteShort(pShort->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Int:
|
||||
{
|
||||
CIntProperty* pInt = TPropCast<CIntProperty>(pProperty);
|
||||
rOut.WriteLong( pInt->Value(pData) );
|
||||
auto* pInt = TPropCast<CIntProperty>(pProperty);
|
||||
rOut.WriteLong(pInt->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Float:
|
||||
{
|
||||
CFloatProperty* pFloat = TPropCast<CFloatProperty>(pProperty);
|
||||
rOut.WriteFloat( pFloat->Value(pData) );
|
||||
auto* pFloat = TPropCast<CFloatProperty>(pProperty);
|
||||
rOut.WriteFloat(pFloat->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Choice:
|
||||
{
|
||||
CChoiceProperty* pChoice = TPropCast<CChoiceProperty>(pProperty);
|
||||
rOut.WriteLong( pChoice->Value(pData) );
|
||||
auto* pChoice = TPropCast<CChoiceProperty>(pProperty);
|
||||
rOut.WriteLong(pChoice->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Enum:
|
||||
{
|
||||
CEnumProperty* pEnum = TPropCast<CEnumProperty>(pProperty);
|
||||
rOut.WriteLong( pEnum->Value(pData) );
|
||||
auto* pEnum = TPropCast<CEnumProperty>(pProperty);
|
||||
rOut.WriteLong(pEnum->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Flags:
|
||||
{
|
||||
CFlagsProperty* pFlags = TPropCast<CFlagsProperty>(pProperty);
|
||||
rOut.WriteLong( pFlags->Value(pData) );
|
||||
auto* pFlags = TPropCast<CFlagsProperty>(pProperty);
|
||||
rOut.WriteLong(pFlags->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::String:
|
||||
{
|
||||
CStringProperty* pString = TPropCast<CStringProperty>(pProperty);
|
||||
rOut.WriteString( pString->Value(pData) );
|
||||
auto* pString = TPropCast<CStringProperty>(pProperty);
|
||||
rOut.WriteString(pString->Value(pData));
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Vector:
|
||||
{
|
||||
CVectorProperty* pVector = TPropCast<CVectorProperty>(pProperty);
|
||||
auto* pVector = TPropCast<CVectorProperty>(pProperty);
|
||||
pVector->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Color:
|
||||
{
|
||||
CColorProperty* pColor = TPropCast<CColorProperty>(pProperty);
|
||||
auto* pColor = TPropCast<CColorProperty>(pProperty);
|
||||
pColor->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Asset:
|
||||
{
|
||||
CAssetProperty* pAsset = TPropCast<CAssetProperty>(pProperty);
|
||||
auto* pAsset = TPropCast<CAssetProperty>(pProperty);
|
||||
pAsset->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Sound:
|
||||
{
|
||||
CSoundProperty* pSound = TPropCast<CSoundProperty>(pProperty);
|
||||
auto* pSound = TPropCast<CSoundProperty>(pProperty);
|
||||
rOut.WriteLong( pSound->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::Animation:
|
||||
{
|
||||
CAnimationProperty* pAnim = TPropCast<CAnimationProperty>(pProperty);
|
||||
auto* pAnim = TPropCast<CAnimationProperty>(pProperty);
|
||||
rOut.WriteLong( pAnim->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyType::AnimationSet:
|
||||
{
|
||||
CAnimationSetProperty* pAnimSet = TPropCast<CAnimationSetProperty>(pProperty);
|
||||
auto* pAnimSet = TPropCast<CAnimationSetProperty>(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<CSplineProperty>(pProperty);
|
||||
auto* pSpline = TPropCast<CSplineProperty>(pProperty);
|
||||
std::vector<char>& 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<CGuidProperty>(pProperty);
|
||||
auto* pGuid = TPropCast<CGuidProperty>(pProperty);
|
||||
std::vector<char>& 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<CStructProperty>(pProperty);
|
||||
auto* pStruct = TPropCast<CStructProperty>(pProperty);
|
||||
std::vector<IProperty*> 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<uint32>(PropertiesToWrite.size()));
|
||||
else
|
||||
rOut.WriteShort((uint16) PropertiesToWrite.size());
|
||||
rOut.WriteUShort(static_cast<uint16>(PropertiesToWrite.size()));
|
||||
}
|
||||
|
||||
for (auto* property : PropertiesToWrite)
|
||||
|
@ -204,8 +205,8 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IProperty* pProperty, voi
|
|||
case EPropertyType::Array:
|
||||
{
|
||||
CArrayProperty* pArray = TPropCast<CArrayProperty>(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<uint16>(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<uint8>(ObjectType)) : rOut.WriteLong(ObjectType);
|
||||
IsPrime1 ? rOut.WriteUByte(static_cast<uint8>(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<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++)
|
||||
{
|
||||
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<uint16>(Size));
|
||||
IsPrime1 ? rOut.WriteULong(Size) : rOut.WriteUShort(static_cast<uint16>(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<uint32>(mGeneratedObjects.size()));
|
||||
|
||||
for (auto* object : mGeneratedObjects)
|
||||
WriteInstance(rOut, object);
|
||||
|
|
Loading…
Reference in New Issue