ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:packing

Value packing

All ACS integers are 32-bit. Value packing functions let you store four 8-bit integers or two 16-bit integers in one 32-bit int variable. This can be useful, for example, to store RGBA colors in a single variable. Or to store big arrays using less memory.

Packing 8-bit integers (bytes)

int PackBytes(int b1, int b2, int b3, int b4) returns a 32-bit integer containing 4 bytes. Byte values must be in [0, 255] range.

  • int UnpackByte1(int packed) – returns the first packed byte.
  • int UnpackByte2(int packed) – returns the second packed byte.
  • int UnpackByte3(int packed) – returns the third packed byte.
  • int UnpackByte4(int packed) – returns the fourth packed byte.

Example:

int color = PackBytes(255, 128, 0, 255); // Orange

int r = UnpackByte1(color); // 255
int g = UnpackByte2(color); // 128
int b = UnpackByte3(color); // 0
int alpha = UnpackByte4(color); // 255

Packing 16-bit integers (shorts)

int PackShorts(int short1, int short2) returns a 32-bit integer containing two 16-bit integers (shorts). Short values must be in [-32678. 32767] range.

  • int UnpackShort1(int packed) – returns the first packed short.
  • int UnpackShort2(int packed) – returns the second packed short.

Other packing options

Other packing options are not supported. If you need some other way of packing values, it is recommended to implement it yourself. Only the most generally useful value packing functions are included.

new/packing.txt · Last modified: 2018/02/17 21:25 by korshun