1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
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
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (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, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_PX_ANIMS_H_
29 #define ICB_PX_ANIMS_H_
30 
31 #include "engines/icb/common/px_common.h"
32 
33 namespace ICB {
34 
35 #define PSX_PXANIM_SCHEMA 5
36 #define PC_PXANIM_SCHEMA 5
37 
38 #define PXANIM_SCHEMA PC_PXANIM_SCHEMA
39 
40 #define PXANIM_TAG "Peas"
41 #define ORG_POS 0
42 #define ORG_STRING "ORG"
43 #define INT_POS 1
44 #define INT_STRING "INT"
45 #define OBJ_STRING "OBJ"
46 
47 #define ORG_TYPE 0
48 #define INT_TYPE 1
49 #define INT0_TYPE 2 // Forced export of INT marker on frame 0 of anim
50 
51 #define TRI_TYPE 3
52 #define OBJ_TYPE 4
53 
54 #if PXANIM_SCHEMA == 1
55 
56 #define TRI_POS 2
57 #define TRI_STRING "TRI"
58 
59 #undef INT_TYPE
60 #define INT_TYPE *(uint32 *)INT_STRING
61 
62 #undef TRI_TYPE
63 #define TRI_TYPE *(uint32 *)TRI_STRING
64 
65 #endif // #if PXANIM_SCHEMA == 1
66 
67 // PXmarker_PC : the PC version
68 class PXmarker_PC {
69 private:
70 	uint32 m_type;
71 	float m_x, m_y, m_z;
72 	float m_pan;
73 
74 #if PXANIM_SCHEMA == 1
75 	float dummy1, dummy2;
76 #endif
77 
78 public:
SetType(uint32 type)79 	void SetType(uint32 type) { m_type = type; }
SetPan(float pan)80 	void SetPan(float pan) { m_pan = pan; }
81 	void SetXYZ(float x, float y, float z);
82 
GetType(void)83 	uint32 GetType(void) { return m_type; }
GetPan(float * pan)84 	void GetPan(float *pan) { *pan = m_pan; }
85 	void GetXYZ(float *x, float *y, float *z);
86 };
87 
SetXYZ(float x,float y,float z)88 inline void PXmarker_PC::SetXYZ(float x, float y, float z) {
89 	m_x = x;
90 	m_y = y;
91 	m_z = z;
92 }
93 
GetXYZ(float * x,float * y,float * z)94 inline void PXmarker_PC::GetXYZ(float *x, float *y, float *z) {
95 	*x = m_x;
96 	*y = m_y;
97 	*z = m_z;
98 }
99 
100 // PXframe_PC : the PC version //
101 typedef struct {
102 	int16 left_foot_distance;
103 	int16 right_foot_distance;
104 	uint8 marker_qty;
105 	uint8 leftFootStep;
106 	uint8 rightFootStep;
107 	uint8 pad3;
108 	PXmarker_PC markers[1];
109 } PXframe_PC;
110 
111 // PXmarker_PSX : the PSX version
112 class PXmarker_PSX {
113 private:
114 	uint8 m_type;
115 	uint8 x8;
116 	uint16 x7y9;
117 	uint32 y6z15pan11;
118 
119 public:
SetType(uint8 type)120 	void SetType(uint8 type) { m_type = type; }
121 	void SetPackedXYZPan(uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11);
122 
GetType(void)123 	uint8 GetType(void) const { return m_type; }
124 
125 	void GetPan(float *pan) const;
126 	void GetXYZ(float *x, float *y, float *z) const;
127 };
128 
SetPackedXYZPan(uint8 _x8,uint16 _x7y9,uint32 _y6z15pan11)129 inline void PXmarker_PSX::SetPackedXYZPan(uint8 _x8, uint16 _x7y9, uint32 _y6z15pan11) {
130 	x8 = _x8;
131 	x7y9 = _x7y9;
132 	y6z15pan11 = _y6z15pan11;
133 }
134 
GetPan(float * pan)135 inline void PXmarker_PSX::GetPan(float *pan) const { *pan = (float)(((y6z15pan11 & 0x7FF) << 1)) / 4096.0f; }
136 
GetXYZ(float * x,float * y,float * z)137 inline void PXmarker_PSX::GetXYZ(float *x, float *y, float *z) const {
138 	int32 ix, iy, iz;
139 
140 	ix = ((x8 << 7) | (x7y9 >> 9));
141 	if (ix >= 16384)
142 		ix = ix - 32768;
143 
144 	iy = (((x7y9 & 0x1FF) << 6) | (y6z15pan11 >> 26));
145 	if (iy >= 16384)
146 		iy = iy - 32768;
147 
148 	iz = ((y6z15pan11 >> 11) & 0x7FFF);
149 	if (iz >= 16384)
150 		iz = iz - 32768;
151 
152 	*x = (float)ix;
153 	*y = (float)iy;
154 	*z = (float)iz;
155 }
156 
157 // PXframe_PSX : the PSX version //
158 typedef struct {
159 	int16 left_foot_distance;
160 	int16 right_foot_distance;
161 	uint8 marker_qty;
162 	uint8 leftFootStep;
163 	uint8 rightFootStep;
164 	uint8 pad3;
165 	PXmarker_PSX markers[1];
166 } PXframe_PSX;
167 
168 // PXanim //
169 typedef struct {
170 	char tag[4];
171 	int32 schema;
172 	uint8 frame_qty;
173 	uint8 speed;
174 	uint16 offsets[1];
175 } PXanim_PSX;
176 
177 typedef struct {
178 	char tag[4];
179 	int32 schema;
180 	uint8 frame_qty;
181 	uint8 speed;
182 	uint16 offsets[1];
183 } PXanim_PC;
184 
ConvertPXanim(PXanim_PSX * anim)185 inline void ConvertPXanim(PXanim_PSX *anim) {
186 	// Support old schema type files
187 	if (anim->schema == PSX_PXANIM_SCHEMA - 1) {
188 		int32 nFrames = anim->frame_qty;
189 		anim->frame_qty = (uint8)nFrames;
190 		anim->speed = 1;
191 		anim->schema = PSX_PXANIM_SCHEMA;
192 	}
193 }
194 
ConvertPXanim(PXanim_PC * anim)195 inline void ConvertPXanim(PXanim_PC *anim) {
196 	// Support old schema type files
197 	if (anim->schema == PC_PXANIM_SCHEMA - 1) {
198 		int32 nFrames = anim->frame_qty;
199 		anim->frame_qty = (uint8)nFrames;
200 		anim->speed = 1;
201 		anim->schema = PC_PXANIM_SCHEMA;
202 	}
203 }
204 
205 // The animation, frame, marker
206 typedef PXframe_PSX PXframe;
207 typedef PXmarker_PSX PXmarker;
208 
209 } // End of namespace ICB
210 
211 #endif //  _library__PX_ANIMS_H_
212