Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Idea for cutting down program size in games!!
#11
Quote:What you're saying sounds interesting, but I don't think I have enough experience to implement it. Could you give me some more information on how to do something like this?

I would like to have the text go a bit faster since it's being sent over a modem, using the EasyDoor library.

hmn , would you take a cpp example ? Tongue
Reply
#12
There is also something called an INDEX compression

The INDEX type is used as a way of reducing file size. It is a DWORD saved with as
less bytes as possible. The first byte tells if the number is positive or negative (bit 7, B
&& 0x80; 1 means negative). Any byte has a bit that means that there is another byte
following, in the first byte this is bit 6 (B && 0x40) and in the following is bit 7 (B &&
0x80). For example for number -12345:
0x00003039 (in positive, the sign is flagged at the end of the conversion)
00000000 00000000 00110000 00111001 (in binary)
0000001 1000000 111001 (grouping, 6 bits for the most significant byte, 7 bits for
others)
0x01 0x40 0x39 (in hex)
0x01 0xC0 0xF9 (added the bits for the sign and for the continuation flags)
Saved as 0xF9 0xC0 0x01, three bytes instead of four.


Compact indices exist so that small numbers can be stored efficiently.
An index named "Index" is stored as a series of 1-5 consecutive bytes.
Basically, the "Ar << B0" type code
serializes the byte stored in the variable B0. Serialize can mean
read or write, depending on the internal implementation of the archive
object Ar.

Code:
FArchive& operator<<( FArchive& Ar, FCompactIndex& I )
{
    INT Original = I.Value;
    DWORD V = Abs(I.Value);
    BYTE B0 =     ((I.Value>=0) ? 0 : 0x80) +
            ((V < 0x40) ? V : ((V & 0x3f)+0x40));
        I.Value = 0;
        Ar << B0;
        if( B0 & 0x40 ) {
            V >>= 6;
            BYTE B1 = (V < 0x80) ? V : ((V & 0x7f)+0x80);
            Ar << B1;
                if( B1 & 0x80 ) {
                    V >>= 7;
                    BYTE B2 = (V < 0x80) ? V : ((V & 0x7f)+0x80);
                    Ar << B2;
                    if( B2 & 0x80 ) {
                        V >>= 7;
                        BYTE B3 = (V < 0x80) ? V : ((V & 0x7f)+0x80);
                        Ar << B3;
                        if( B3 & 0x80 ) {
                            V >>= 7;
                            BYTE B4 = V;
                            Ar << B4;
                            I.Value = B4;
                        }
                        I.Value = (I.Value << 7) + (B3 & 0x7f);
                    }
                    I.Value = (I.Value << 7) + (B2 & 0x7f);
                }
            I.Value = (I.Value << 7) + (B1 & 0x7f);
        }
    I.Value = (I.Value << 6) + (B0 & 0x3f);
    if( B0 & 0x80 ) I.Value = -I.Value;
    if( Ar.IsSaving() && I.Value!=Original )
    appErrorf("Mismatch: %08X %08X",I.Value,Original);
    return Ar;
}


And here is a way to decode it:

Code:
int IndexParser()
{
    // INDEX PARSER,,
    int Actual=(Docptr[0]&0x3F);
    int to_add=1;
    if ((Docptr[0]&0x40)!=0)
    {
        Actual+=(Docptr[1]&0x7F)<<6;
        to_add++;
        for(int iIndexDec=2;(Docptr[iIndexDec-1]&0x80)!=0;iIndexDec++)
        {
            Actual+=(Docptr[iIndexDec]&0x7F)<<(6+7*(iIndexDec-1));
            to_add++;
        }
    }
    if ((Docptr[0]&0x80)!=0)
    {
        Actual=-Actual;    
    }
    Docptr+=to_add;
    return Actual;
}

I didn't have time to convert my last example to a real working format , but you need a mem alloc , and Docptr is a pointer to that mem alloc.

Tomorrow I'll be on a sort of holiday , so I'll give some more explanation when I get back.

hope you understand, its not the most easy thing I have made..

Scorp.
Reply
#13
i have no *idea* what you're talking about Smile

<------ so lost Smile

*peace*

Meg.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)