ScummVM API documentation
rab_api.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_RAB_API_HH
28 #define ICB_RAB_API_HH
29 
30 #include "engines/icb/gfx/psx_pcdefines.h"
31 #include "engines/icb/gfx/rap_api.h"
32 
33 namespace ICB {
34 
35 // The output file format for the .rab file
36 #define RAB_API_SCHEMA 7
37 #define RAB_API_ID "RAB"
38 
39 // All the different animation frame types used during the
40 // compression process
41 #define ALL_ANGLES_32_BYTE_SIZE (4)
42 #define ALL_DELTAS_24_BYTE_SIZE (3)
43 #define ALL_DELTAS_16_BYTE_SIZE (2)
44 #define ALL_DELTAS_8_BYTE_SIZE (1)
45 
46 #define NONZERO_ANGLES_32_BYTE_SIZE (5)
47 #define NONZERO_DELTAS_24_BYTE_SIZE (4)
48 #define NONZERO_DELTAS_16_BYTE_SIZE (3)
49 #define NONZERO_DELTAS_8_BYTE_SIZE (2)
50 
51 #define ZERO_ANGLE (0)
52 
53 #define DELTA_24_NBITS (8)
54 #define DELTA_16_NBITS (5)
55 #define DELTA_8_NBITS (2)
56 
57 #define DELTA_24_ZERO (((1 << (DELTA_24_NBITS - 1)) << (DELTA_24_NBITS + DELTA_24_NBITS)) | ((1 << (DELTA_24_NBITS - 1)) << (DELTA_24_NBITS)) | (1 << (DELTA_24_NBITS - 1)))
58 #define DELTA_16_ZERO (((1 << (DELTA_16_NBITS - 1)) << (DELTA_16_NBITS + DELTA_16_NBITS)) | ((1 << (DELTA_16_NBITS - 1)) << (DELTA_16_NBITS)) | (1 << (DELTA_16_NBITS - 1)))
59 #define DELTA_8_ZERO (((1 << (DELTA_8_NBITS - 1)) << (DELTA_8_NBITS + DELTA_8_NBITS)) | ((1 << (DELTA_8_NBITS - 1)) << (DELTA_8_NBITS)) | (1 << (DELTA_8_NBITS - 1)))
60 
61 // Animation frame structures with max memory pre-allocated in them
62 // For use in the converter
63 //
64 // The animation frame structure is either:
65 //
66 // i) store ALL values OR store just non-zero values + bone ID
67 // ii) store orientations OR store deltas from the previous frame
68 // iii) use 8, 16, 24, 32-bits to store values
69 typedef struct FrameHeader {
70  BoneLink poseBone;
71  uint8 typeSize;
72  uint8 nThings;
73 } FrameHeader;
74 
75 // The typeSize bit masks
76 //
77 // DataTypeBit : 0 = Compressed Angle Triplet, 1 = Delta Triplet
78 // DataStoreZeroBit : 0 = don't store zero values, 1 = store zero values
79 // DataSizeBits 3 bits : size in bytes of the data value stored (1,2,3,4)
80 
81 // Most significant bit
82 #define DataTypeMask (1 << 7)
83 #define DataTypeDeltas (1 << 7)
84 #define DataTypeAngles (0)
85 
86 // Next one down
87 #define DataStoreZeroMask (1 << 6)
88 #define DataStoreZero (1 << 6)
89 #define DataDontStoreZero (0)
90 
91 // Lower nibble is DataSizeBits
92 #define DataSizeBitMask (0xF)
93 
94 #define ALL_ANGLES_32_TYPESIZE (DataTypeAngles | DataStoreZero | 4)
95 #define ALL_DELTAS_24_TYPESIZE (DataTypeDeltas | DataStoreZero | 3)
96 #define ALL_DELTAS_16_TYPESIZE (DataTypeDeltas | DataStoreZero | 2)
97 #define ALL_DELTAS_8_TYPESIZE (DataTypeDeltas | DataStoreZero | 1)
98 
99 #define NONZERO_ANGLES_32_TYPESIZE (DataTypeAngles | DataDontStoreZero | 4)
100 #define NONZERO_DELTAS_24_TYPESIZE (DataTypeDeltas | DataDontStoreZero | 3)
101 #define NONZERO_DELTAS_16_TYPESIZE (DataTypeDeltas | DataDontStoreZero | 2)
102 #define NONZERO_DELTAS_8_TYPESIZE (DataTypeDeltas | DataDontStoreZero | 1)
103 
104 // Basic angle triplet compression packs 3x12-bits into 3x10-bits
105 #define COMP_ANGLE_RANGE (1 << 10)
106 #define COMP_ANGLE_SHIFT (2)
107 #define COMP_VX_SHIFT (20)
108 #define COMP_VY_SHIFT (10)
109 #define COMP_VZ_SHIFT (0)
110 #define COMP_VX_MASK (0x3FF)
111 #define COMP_VY_MASK (0x3FF)
112 #define COMP_VZ_MASK (0x3FF)
113 
114 #define COMP_EXTRA_SHIFT (0)
115 #define COMP_DELTA_RANGE (COMP_ANGLE_RANGE)
116 
117 // Generic frame data structure
118 typedef struct FrameData {
119  BoneLink poseBone; // the animated bone for the pose object
120  uint8 typeSize; // FrameHeader but don't want compiler alignment bollocks
121  uint8 nThings;
122  int8 data[1]; // data[n] : n depends on compression used store frame
123 } FrameData;
124 
125 typedef struct MatrixHierarchy {
126  MATRIX matrix;
127  MatrixHierarchy *parent;
129 
130 typedef struct MatrixHierarchyPC {
131  MATRIXPC matrix;
132  MatrixHierarchyPC *parent;
134 
135 typedef uint32 CompTriplet;
136 
137 typedef struct LinkedMatrix {
138  CompTriplet crot; // compresseed angle triplet 10-bits per angle
139 } LinkedMatrix;
140 
141 typedef struct Bone_Frame {
142  BoneLink poseBone; // the animated bone for the pose object
143  LinkedMatrix bones[1]; // actually LinkedMatrix rot[nBones]
144 } Bone_Frame;
145 
146 typedef struct {
147  char id[4];
148  uint32 schema;
149  uint16 nFrames;
150  uint8 nBones; // nBones must match the RAP file nBones value
151  uint8 currentFrame; // the current frame of animation stored
152 
153  // byte offsets from start of the file
154  uint32 currentFrameOffset;
155 
156  // byte offsets from start of the file
157  uint32 frameOffsets[1]; // nFrames of them
158 } RabAPI;
159 
160 typedef struct _RabAPIObject {
161  static Bone_Frame *GetFrame(RabAPI *rab, const int32 f);
162 
163  static Bone_Frame *GetCurrentFrame(RabAPI *rab) { return (Bone_Frame *)((uint8 *)(rab->id + FROM_LE_32(rab->currentFrameOffset))); }
164 
165  static FrameData *GetFrameData(RabAPI *rab, const int32 f) { return (FrameData *)((uint8 *)(rab->id + FROM_LE_32(rab->frameOffsets[f]))); }
166 
167 } RabAPIObject;
168 
169 // Compress an SVECTOR ( uint16 vx,vy,vz, pad; ) -> uint32
170 // by dividing the angles (12-bits 0-4095) by four to make them 10-bits
171 int32 CompressSVECTOR(SVECTOR rotin, uint32 *rotout);
172 
173 // Uncompress an SVECTOR ( uint32 -> uint16 vx,vy,vz, pad; )
174 // by multiplying the angles (10-bits 0-1023) by four to make them 12-bits
175 inline void ExpandSVECTOR(CompTriplet rotin, SVECTOR *rotout) {
176  // Make the angles back up from the compressed 32-bit value
177  // x = ( upper 10-bits from part1 ) * 4
178  rotout->vx = (int16)(((int16)(rotin >> COMP_VX_SHIFT) & COMP_VX_MASK) << COMP_ANGLE_SHIFT);
179  // y = ( middle 10-bits from part1 ) * 4
180  rotout->vy = (int16)(((int16)(rotin >> COMP_VY_SHIFT) & COMP_VY_MASK) << COMP_ANGLE_SHIFT);
181  // z = ( lower 10-bits from part1 ) * 4
182  rotout->vz = (int16)(((int16)(rotin >> COMP_VZ_SHIFT) & COMP_VZ_MASK) << COMP_ANGLE_SHIFT);
183 }
184 
185 } // End of namespace ICB
186 
187 #endif // #ifndef RAB_API_HH
Definition: rab_api.h:160
Definition: px_capri_maths.h:53
Definition: rab_api.h:125
Definition: actor.h:32
Definition: rab_api.h:69
Definition: psx_pcdefines.h:41
Definition: rab_api.h:137
Definition: rab_api.h:141
Definition: rab_api.h:146
Definition: rab_api.h:130
Definition: rab_api.h:118
Definition: px_capri_maths.h:38