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