ScummVM API documentation
rlp_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_RLP_API_H
28 #define ICB_RLP_API_H
29 
30 namespace ICB {
31 
32 #define RLP_PROP_NAME_LENGTH 32
33 #define RLP_SHADE_NAME_LENGTH 8
34 #define RLP_LAMP_NAME_LENGTH 16
35 
36 #define MAX_NUMBER_SHADE_STATES 128
37 
38 #define RLP_API_SCHEMA 10
39 #define RLP_API_ID "RLP"
40 
41 #define EDGE_ONE 0x1
42 #define EDGE_TWO 0x2
43 #define EDGE_THREE 0x4
44 #define EDGE_FOUR 0x8
45 #define EDGE_ALL_VISIBLE (EDGE_ONE | EDGE_TWO | EDGE_THREE | EDGE_FOUR)
46 
47 // schema 2
48 // ========
49 // if (anu==0) then ans = ane = 0
50 // if (afu==0) then afs=afe=ATTEN_MAX_DISTANCE
51 
52 // schema 3
53 // ========
54 // ambient scaled down from 0-4096 to 0-255
55 
56 // schema 4
57 // ========
58 // m: multiplier scaled down from 0-4096 to 0-128
59 // illegal beam_angles OR illegal beam_softness
60 // disables beam_enable + WARNING should be an error,
61 // but then need artist to fix the model(s)
62 // An error will be enabled after big demo to Sony
63 // beam_angle & beam_softness converted to cos's of half angle
64 // ans, ane, afs, afe : pre-multiplied to be square distances
65 
66 // schema 5
67 // ========
68 // added ID "RPL" to the strucure
69 
70 // schema 6
71 // ========
72 // reduced ATTEN_MAX_DISTANCE to prevent integer overflow from (128*1024)->(128*128)
73 
74 // schema 7
75 // ========
76 // supported the bs & ba parameters for DIRECT lights
77 
78 // Lights are ignored beyond this distance
79 // Note, the square gets stored, so make it (1<<31)/2
80 #define ATTEN_MAX_DISTANCE (1 << 15)
81 
82 // 180 degrees is the maximum size for any kind of beam angles
83 #define MAX_BEAM_ANGLE (4096 / 2)
84 
85 // schema 9
86 // ========
87 // added the decay parameter
88 typedef struct PSXrgb { uint16 r, g, b, v; } PSXrgb;
89 
90 #define OMNI_LIGHT (0)
91 #define SPOT_LIGHT (1)
92 #define DIRECT_LIGHT (2)
93 
94 #define DECAY_NONE (0)
95 #define DECAY_INV (1)
96 #define DECAY_INV_SQR (2)
97 
98 // Trial and error has shown the 3DS MAX decay law constant is this
99 #define RLP_DECAY_CONSTANT (50)
100 // The decay law is:
101 // DECAY_NONE: m = 1.0;
102 // DECAY_INV: m = ( 1.0/ (distance/factor) )
103 // DECAY_INV_SQR: m = ( 1.0/ (distance/factor)^2 )
104 
105 typedef struct PSXLampState {
106  PSXrgb c; // colour not pre-multiplied
107  VECTOR pos; // world position of the lamp
108  int16 vx; // x-direction
109  int16 vy; // y-direction
110  int16 vz; // z-direction
111  uint16 m; // fixed-point int 128 = 1.0 (0=off)
112  uint32 ans2; // atten_near_start^2
113  uint32 ane2; // atten_near_end^2
114  uint32 afs2; // atten_far_start^2
115  uint32 afe2; // atten_far_end^2
116 } PSXLampState;
117 
118 typedef struct PSXLamp {
119  uint8 nStates;
120  uint8 type; // light_type (0=OMNI,1=SPOT,2=DIRECT)
121  uint8 anu; // atten_near_use
122  uint8 afu; // atten_far_use
123 
124  int32 ba; // cos(beam_angle/2) fixed-point int 4096 = 1.0
125  int32 bs; // cos(beam_softness/2) fixed-point int 4096 = 1.0
126 
127  uint32 decay; // decay parameter (0=none,1=inverse,2=inverse-squared)
128  uint16 w; // width in cm
129  uint16 b; // bounce factor : fixed-point int 128 = 1.0 (0=off)
130  char lamp_name[RLP_LAMP_NAME_LENGTH]; // for debugging purposes will go in final version
131  char prop_name[RLP_PROP_NAME_LENGTH];
132  PSXLampState states[1]; // actually PSXLampState states[nStates];
133 } PSXLamp;
134 
135 // A triangle
136 typedef struct ShadeTriangle {
137  uint32 vEdge; // bit-flag saying if edge 0,1,2 are visible
138  SVECTOR l01; // line vertex 0 -> vertex 1
139  SVECTOR l12; // line vertex 1 -> vertex 2
140  SVECTOR l20; // line vertex 2 -> vertex 0
141  SVECTOR n01; // normal to plane & line 01
142  SVECTOR n12; // normal to plane & line 12
143  SVECTOR n20; // normal to plane & line 20
144  SVECTOR pn; // plane normal
145  int32 d; // plane distance
146  int32 n01dots0; // n01 . vertex 0
147  int32 n12dots1; // n12 . vertex 1
148  int32 n20dots2; // n20 . vertex 2
149 } ShadeTriangle;
150 
151 // A quad
152 typedef struct ShadeQuad {
153  uint32 vEdge; // bit-flag saying if edge 0,1,2,3 are visible
154  SVECTOR l01; // line vertex 0 -> vertex 1
155  SVECTOR l12; // line vertex 1 -> vertex 2
156  SVECTOR l23; // line vertex 2 -> vertex 3
157  SVECTOR l30; // line vertex 3 -> vertex 0
158  SVECTOR n01; // normal to plane & line 01
159  SVECTOR n12; // normal to plane & line 12
160  SVECTOR n23; // normal to plane & line 23
161  SVECTOR n30; // normal to plane & line 30
162  SVECTOR pn; // plane normal
163  int32 d; // plane distance
164  int32 n01dots0; // n01 . vertex 0
165  int32 n12dots1; // n12 . vertex 1
166  int32 n23dots2; // n23 . vertex 2
167  int32 n30dots3; // n30 . vertex 3
168 } ShadeQuad;
169 
170 typedef struct PSXShade {
171  char shade_name[RLP_SHADE_NAME_LENGTH];
172  char prop_name[RLP_PROP_NAME_LENGTH];
173  uint32 nStates;
174  ShadeQuad states[1]; // ShadeQuad states[nStates]
175 } PSXShade;
176 
177 // For use with pre-processing converter
178 typedef struct ShadeInfo {
179  char shade_name[RLP_SHADE_NAME_LENGTH];
180  char prop_name[RLP_PROP_NAME_LENGTH];
181  uint32 nStates;
182  ShadeQuad states[MAX_NUMBER_SHADE_STATES];
183 } ShadeInfo;
184 
185 typedef struct rlp_API {
186  char id[4];
187  uint32 schema;
188  uint8 nLamps;
189  uint8 nShades;
190  uint16 shadeOffsetsOffset;
191  PSXrgb ambient;
192  // Byte offsets
193  uint32 lampOffsets[1]; // actually lampOffsets[nLamps]
194  inline PSXLamp *GetLamp(const int32 l);
195  inline uint32 *GetShadeOffsets(void);
196  inline PSXShade *GetShade(const int32 s);
197 } rlp_API;
198 
199 inline PSXLamp *rlp_API::GetLamp(const int32 l) { return (PSXLamp *)(id + lampOffsets[l]); }
200 
201 inline uint32 *rlp_API::GetShadeOffsets(void) { return (uint32 *)(id + shadeOffsetsOffset); }
202 
203 inline PSXShade *rlp_API::GetShade(const int32 s) {
204  uint32 *shadeOffsets = GetShadeOffsets();
205  return (PSXShade *)(id + shadeOffsets[s]);
206 }
207 
208 typedef struct rlp_API_9 {
209  char id[4];
210  uint32 schema;
211  uint32 nLamps;
212  PSXrgb ambient;
213  // Byte offsets
214  uint32 lampOffsets[1]; // actually lampOffsets[nLamps]
215  // PSXLamp lamps[nLamps]
216 } rlp_API_9;
217 
218 // Convert from API schema 9 to API schema 10
219 inline void ConvertRLP(rlp_API *rlp) {
220  if (rlp->schema == RLP_API_SCHEMA)
221  return;
222 }
223 
224 } // End of namespace ICB
225 
226 #endif // #ifndef RLP_API_H
Definition: rlp_api.h:208
Definition: rlp_api.h:118
Definition: rlp_api.h:185
Definition: px_capri_maths.h:53
Definition: rlp_api.h:178
Definition: rlp_api.h:170
Definition: actor.h:32
Definition: rlp_api.h:105
Definition: rlp_api.h:88
Definition: rlp_api.h:136
Definition: px_capri_maths.h:46
Definition: rlp_api.h:152