forked from farbrausch/fr_public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opdata.cpp
74 lines (59 loc) · 1.42 KB
/
opdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// This code is in the public domain. See LICENSE for details.
#include "types.h"
#include "opdata.h"
#include "math3d_2.h"
sInt getSmallInt(const sU8*& strm)
{
sInt val = *strm++;
if (val & 128)
val = (val & 127) | ((*strm++) << 7);
return val;
}
sF32 getPackedFloat(const sU8*& strm)
{
sU8 firstByte = *strm++;
if (firstByte == 0x00)
return 0.0f;
else if (firstByte == 0x01)
return 1.0f;
else if (firstByte == 0xff)
return -1.0f;
sU16 secondWord = *((sU16 *) strm);
strm += 2;
sU32 fullVal = (sU32(firstByte) << 23) | ((sU32(secondWord) & 32768) << 16) | ((sU32(secondWord) & 32767) << 8);
return *((sF32 *) &fullVal);
}
sF32 getCodedFloat(const sU8* &ptr, sInt code)
{
static const sF32 vals[4] = { 0, 0, 1, -1 };
if((code & 3) == 0)
return getToterFloat(ptr);
else
return vals[code & 3];
}
void getPackedVec(fr::vector& vec, const sU8*& strm)
{
sInt code = *strm++;
vec.x = getCodedFloat(strm, code >> 0);
if(code & 64)
vec.y = vec.z = vec.x;
else
{
vec.y = getCodedFloat(strm, code >> 2);
vec.z = getCodedFloat(strm, code >> 4);
}
/*vec.x = getPackedFloat(strm);
vec.y = getPackedFloat(strm);
vec.z = getPackedFloat(strm);*/
}
sF32 getToterFloat(const sU8 *&ptr)
{
sU16 v;
sU32 vd;
v = *(const sU16 *) ptr;
vd = (v & 32768) << 16 // sign
| ((((v >> 10) & 31) + 128 - 16) << 23)
| ((v & 1023) << 13);
ptr += 2;
return *(sF32 *) &vd;
}