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_COMMON_H
29 #define ICB_PX_COMMON_H
30 
31 #include "common/scummsys.h"
32 
33 #include "engines/icb/common/px_rcutypes.h"
34 
35 namespace ICB {
36 
37 #define PXNULL (0xffffffff)
38 
39 // This defines the scale value for converting PC floats to PSX fixed-point representation.  Not
40 // sure if this is the right place for this.
41 #define PSX_FIXED_POINT_SCALE 4096
42 
43 #define PSX_FLOAT_POINT_SHIFT 12
44 #define PSX_FLOAT_POINT_SCALE (1 << PSX_FLOAT_POINT_SHIFT)
45 #define PSX_ANGLE_POINT_SCALE 4096
46 #define PSX_DOUBLE_POINT_SCALE 4096
47 
48 // Rather than using integer values beginning at 0 it would be more descriptive to use
49 // four ascii characters, so the type can be guessed from a hex dump.
50 // Use the FT macro to turn four characters into an enum _file_type
51 #define FT_MACRO(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
52 
53 enum _file_type {
54 	FT_UNDEFINED,
55 	unusedFT_COMPILED_GAME_OBJECT, // A compiled game object
56 	FT_FONT,                       // debug console & head-up font
57 	FT_VOX_ANIM,                   // voxel anim file (see voxel anim file format doc)
58 	FT_GAME_OBJECT,                // A game engine game object
59 	FT_BITMAP_ANIM,                // 2D anim file (from bitmap converter) (see 2D bitmaps doc)
60 	FT_BITMAP_FONT,                // font file (from bitmap converter) (see 2D bitmaps doc)
61 	unusedFT_FN_ROUTINES_DAT,      // fn routine data for the script compiler
62 	unusedFT_OBJECTS_SCRIPTS_DAT,  // Compiled scripts for a single object
63 	unusedFT_LINKED_SCRIPTS,       // File containing scripts linked together
64 	unusedFT_LINKED_OBJECTS,       // File containing objects in session linked together
65 	FT_PROP_LIST,                  // File containing a list of prop names and there program counters
66 	FT_PROP_ANIM_LIST,             // File containing prop animation lists
67 	FT_FLOOR_MAP,                  // File containing the floors for a session [PS 06/04/98].
68 	FT_BARRIERS,                   // File containing the index into the barriers file for the line-of-sight stuff [PS 06/04/98].
69 	FT_CAMERAS,                    // File containing the camera 'cubes' for a session [PS 06/04/98].
70 	FT_BARRIERLIST,                // File containing the actual raw walkgrid barriers for a session [PS 01/06/98].
71 	FT_OBJECT_POSITIONS,           // File listing props occurring on a given floor [PS 06/04/98].
72 	FT_PROP_ANIMATIONS,            // File containing information about prop animations [PS 11/08/98].
73 	FT_VOICE_OVER_TEXT,            // Compiled voice-over text file (for Remora etc.).
74 
75 	// add more here!
76 
77 	/***IMPORTANT***
78 		DO NOT DELETE ENTRIES FROM THIS LIST OR SUBSEQUENT RESOURCE TYPES WILL BE RENUMBERED
79 		RENAME ENTRIES NO LONGER IN USE AND REUSE THEM LATER
80 		*/
81 
82 	// The following entries can go in any order, but should not be changed
83 
84 	FT_COMPILED_SCRIPTS = FT_MACRO('C', 'S', 'C', 'R'),     // Compiled script object format (.scrobj)
85 	FT_LINKED_SCRIPTS = FT_MACRO('L', 'S', 'C', 'R'),       // File containing scripts linked together
86 	FT_LINKED_OBJECTS = FT_MACRO('L', 'O', 'B', 'J'),       // File containing objects in session linked together
87 	FT_COMPILED_GAME_OBJECT = FT_MACRO('C', 'O', 'B', 'J'), // A compiled game object
88 	FT_FN_ROUTINES_DAT = FT_MACRO('F', 'N', 'D', 'T'),      // fn routine data for the script compiler
89 	FT_COMBINED_OBJECT = FT_MACRO('C', 'M', 'B', 'O'),      // Combined object and script data
90 	FT_COMPILED_TEXT = FT_MACRO('C', 'M', 'P', 'T'),        // Compressed text
91 	FT_LINKED_TEXT = FT_MACRO('L', 'N', 'K', 'T'),          // Linked text
92 
93 	FT_COMPILED_SFX = FT_MACRO('S', 'F', 'X', ' '), // compiled SFX file
94 	FT_LINKED_SFX = FT_MACRO('S', 'F', 'X', 'L'),   // linked SFX files file
95 	FT_REMORA_MAP = FT_MACRO('R', 'M', 'A', 'P')    // Remora map file.
96 
97 };
98 
99 #define STANDARD_HEADER_NAME_LENGTH 32 // Max length of the header name
100 
101 class px_standard_header {
102 public:
103 	int32 version;                          // This is incremented every time the object is updated
104 	_file_type type;                        // enumerated value for every type of object in the game
105 	int32 owner;                            // Who is responsible for producing this object
106 	int32 unused;                           // For future expansion
107 	int32 unused2;                          // For future expansion
108 	char name[STANDARD_HEADER_NAME_LENGTH]; // 32 bytes worth of ascii name information
109 
110 	void SetData(int32 version, _file_type type, int32 owner, const char *name);
GetType()111 	_file_type GetType() { return (type); }
GetName()112 	const char *GetName() { return (name); }
GetVersion()113 	uint32 GetVersion() { return (version); }
114 };
115 
116 typedef struct {
117 	uint8 red;
118 	uint8 green;
119 	uint8 blue;
120 	uint8 alpha;
121 } _rgb;
122 
123 typedef float PXreal;
124 typedef float PXfloat;
125 typedef double PXdouble;
126 #define REAL_ZERO 0.0f
127 #define REAL_ONE 1.0f
128 #define REAL_TWO 2.0f
129 #define REAL_MIN FLT_MIN
130 #define REAL_MAX FLT_MAX
131 #define REAL_LARGE 100000.0f
132 
133 #define FLOAT_ZERO 0.0f
134 #define FLOAT_QUARTER 0.25f
135 #define FLOAT_HALF 0.5f
136 #define FLOAT_ONE 1.0f
137 #define FLOAT_TWO 2.0f
138 #define FLOAT_MIN FLT_MIN
139 #define FLOAT_MAX FLT_MAX
140 #define FLOAT_LARGE 100000.0f
141 
142 #define ZERO_TURN 0.0f
143 #define QUARTER_TURN 0.25f
144 #define HALF_TURN 0.5f
145 #define FULL_TURN 1.0f
146 
147 #define TWO_PI (2.0f * M_PI)
148 
149 // For converting pan values when the game is saved/loaded
150 // For PC this is equal to the PSX fixed point scaling used to represent angles
151 #define PAN_SCALE_FACTOR PSX_ANGLE_POINT_SCALE
152 
153 // #define DEGREES_TO_RADIANS 0.01745329f
154 #define DEGREES_TO_RADIANS(x) ((x * TWO_PI) / 360.0f)
155 #define RADIANS_TO_DEGREES(x) (x * (180.0f / PI))
156 
157 // How to make a PXdouble from a PXreal
158 #define PXreal2PXdouble(x) (double)(x)
159 // How to make a PXreal from a PXdouble
160 #define PXdouble2PXreal(x) (float)(x)
161 
162 // How to make a PXfloat from a PXreal
163 #define PXreal2PXfloat(x) (x)
164 // How to make a PXreal from a PXfloat
165 #define PXfloat2PXreal(x) (x)
166 
167 typedef struct PXsvector_PC {
168 	float x;
169 	float y;
170 	float z;
171 } PXsvector_PC;
172 
173 typedef struct PXvector_PC {
174 	float x;
175 	float y;
176 	float z;
177 } PXvector_PC;
178 
179 typedef struct PXsvector_PSX {
180 	int16 x;
181 	int16 y;
182 	int16 z;
183 	int16 pad;
184 } PXsvector_PSX;
185 
186 typedef struct PXvector_PSX {
187 	int32 x;
188 	int32 y;
189 	int32 z;
190 } PXvector_PSX;
191 
192 #ifdef _PSX_VECTOR
193 typedef PXvector_PSX PXvector;
194 typedef PXsvector_PSX PXsvector;
195 #else
196 typedef PXvector_PC PXvector;
197 typedef PXsvector_PC PXsvector;
198 #endif
199 
200 typedef struct PXorient_PSX {
201 	int16 pan;
202 	int16 tilt;
203 	int16 cant;
204 	int16 pad;
205 } PXorient_PSX;
206 
207 typedef struct PXorient_PC {
208 	float pan;
209 	float tilt;
210 	float cant;
211 } PXorient_PC;
212 
213 #ifdef _PSX_ORIENT
214 typedef PXorient_PSX PXorient;
215 #else
216 typedef PXorient_PC PXorient;
217 #endif
218 
219 // Endian safe read functions
READ_LE_U16(const void * p)220 inline uint16 READ_LE_U16(const void *p) {
221 	const uint8 *data = (const uint8 *)p;
222 	return (uint16)((data[1] << 8) | data[0]);
223 }
224 
READ_LE_U32(const void * p)225 inline uint32 READ_LE_U32(const void *p) {
226 	const uint8 *data = (const uint8 *)p;
227 	return (uint32)(((uint32)data[3] << 24) | ((uint32)data[2] << 16) | ((uint32)data[1] << 8) | (uint32)data[0]);
228 }
229 
230 #define MKTAG(a0, a1, a2, a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
231 
232 } // End of namespace ICB
233 
234 #endif // #ifndef _PX_INC_PROJECT_X_COMMON_H
235