GUID

From owdev
(Redirected from Key)
Jump to: navigation, search

A GUID is a 16 bit consists out of several components.

  • 0xF000000000000000 – 4 bits reserved for engine usage
  • 0x0FFF000000000000 – 12 bits used as a type mask
  • 0x0000F00000000000 – 4 bits to indicate the platform the asset was authored for
  • 0x00000F8000000000 – 5 bits to indicate the region the asset was authored for
  • 0x0000001F00000000 – 5 bits to indicate the locale the asset was authored for
  • 0x00000000FFFFFFFF – 32 bits for a unique identifier

In other words:

byte rsvd_engine       = (byte)  (guid >> 60);
short type_mask        = (short) (guid >> 48 & 0xFFF);
byte platform          = (byte)  (guid >> 44 & 0xF);
byte region            = (byte)  (guid >> 39 & 0x1F);
byte locale            = (byte)  (guid >> 32 & 0x1F);
uint unique_identifier = (uint)  (guid       & 0xFFFFFFFF);

C# sample code for getting Type ID from a GUID.

short guidToTypeMask(ulong guid)
{
    short num = (key >> 48) & 0x0FFF;

    num = (((num >> 1 ) & 0x55555555) | ((num & 0x55555555) << 1 ));
    num = (((num >> 2 ) & 0x33333333) | ((num & 0x33333333) << 2 ));
    num = (((num >> 4 ) & 0x0F0F0F0F) | ((num & 0x0F0F0F0F) << 4 ));
    num = (((num >> 8 ) & 0x00FF00FF) | ((num & 0x00FF00FF) << 8 ));
    num = ( (num >> 16)               | ( num               << 16));

    num >>= 20;
    return num + 1;
}

This code essentially takes 12 highest bits from the key and reverts them.

GDC presentation

http://www.gdcvault.com/play/1024444/The-Data-Building-Pipeline-of