jcobleigh wrote:
I call LittleToBig twice in each SetVar method (once to convert the input value and once to convert the value that will be returned).
This is a problem. We're using one variable to hold both the little-endian byte-ordered storage value and the machine-byte-ordered return value of GetVar() and SetVar(). To be honest, I think it is a design flaw of CDbPackedVars and will be a bit tough to deal with. So here is the gist of changes I would make to CDbPackedVars. Sorry, they aren't real cut and dry. Up to you, Jamie, if you want to try making them.
Suggested 1.6 Changes
The "
pValue"
member of UNPACKEDVAR always contains data in machine byte order, and the buffer returned from CDbPackedVars::GetPackedBuffer() will have reversals performed as needed. That buffer goes straight into the database, BTW, which is why it must be little-endian.
That part would be easy enough, but when you read the data back out in CDbPackedVars::UnpackBuffer(), you don't know which variables need byte reversal, because like a
big stupid dummy, I didn't store type info in the buffer. We could change this, but that would effectively invalidate the existing 1.6 data format and create a new one, which would be a large pain.
So I think we could instead make a kludgy function like this...
bool CDbPackedVar:: Does1_6VarNeedByteReversal(const char *pszVarName) const
{
return (strcmp(pszVarName, "somevar" ) ==0 || strcmp(pszVarName, "someothervar" ) ==0 || ... );
}
Hunt around for SetVar() calls and make a list of names and types passed in the second param. If variable name corresponds to a type that needs byte-ordering then it goes in the above strcmp code.
Suggested 2.0 Changes
The ugly function above should die with 1.6. For 2.0 we fix packed vars to store variable type.
-Erik
____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals |
twitch stream |
youtube archive (NSFW)