1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 /*
20  * $Header: n:/project/lib/src/edms/RCS/edms_int.h 1.4 1993/05/13 15:46:06 roadkill Exp $
21  */
22 
23 //	This header file contains the codes for the object types and functions in Soliton.
24 //	=====================================================================
25 
26 #ifndef __EDMS_INT_H
27 #define __EDMS_INT_H
28 
29 //	Are we building a shipping version?
30 //	===================================
31 //#define EDMS_SHIPPABLE	1
32 
33 //	Things like Getch()
34 //	-------------------
35 ////#include <conio.h>
36 
37 //#pragma INLINE_DEPTH 255
38 //#pragma INLINE_RECURSION ON
39 
40 //	Cool math universe...
41 //	---------------------
42 #include "fixpp.h"
43 
44 // Physics handle typedef
45 // ======================
46 #include "physhand.h"
47 
48 #include "ss_flet.h"
49 
50 //	Actual object types...
51 //	======================
52 extern Q VACUUM, MARBLE, ROBOT, FIELD_POINT, BIPED, PELVIS, DEATH, D_FRAME;
53 
54 //	Commands for soliton from the state stream (in the Global.cc file)...
55 //	=====================================================================
56 extern Q END;
57 
58 //	Max and Minima...
59 //	=================
60 #define MAX_OBJ 96
61 //#define DOF_MAX 96
62 #define DOF_MAX 40
63 #define EDMS_DATA_SIZE 100
64 
65 #define DOF 7        // degrees of freedom
66 #define DOF_DERIVS 4 // d/dt each dof this-1 times
67 
68 // Dan, these are model specific, so we need more general names than below.  I suggest
69 //#define DOF_X         0
70 //#define DOF_Y         1
71 //#define DOF_Z         2
72 //#define DOF_ORIENT_0  3
73 //#define DOF_ORIENT_1  4
74 //#define DOF_ORIENT_2  5
75 //#define DOF_ORIENT_3  6
76 // But I can't spend time right now changing the references in your code ;^) ...
77 
78 #define DOF_X 0
79 #define DOF_Y 1
80 #define DOF_Z 2
81 #define DOF_ALPHA 3
82 #define DOF_BETA 4
83 #define DOF_GAMMA 5
84 #define DOF_DIRAC 6
85 
86 //	Memory conserving stuff...
87 //	==========================
88 typedef Q EDMS_Argument_Block[MAX_OBJ][DOF][DOF_DERIVS];
89 typedef Q (*EDMS_Argblock_Pointer)[DOF][DOF_DERIVS];
90 
91 //	Have some functions...
92 //	======================
93 
94 //	General functions...
95 //	--------------------
96 typedef struct {
97     fix playfield_size;
98     int32_t min_physics_handle;
99     void (*collision_callback)(physics_handle caller, physics_handle victim, int32_t badness, int32_t DATA1,
100                                int32_t DATA2, fix location[3]),
101         (*autodestruct_callback)(physics_handle caller), (*awol_callback)(physics_handle caller),
102         (*snooz_callback)(physics_handle caller);
103     void *argblock_pointer;
104 } EDMS_data;
105 
106 //	Structs...
107 //	==========
108 typedef struct {
109     fix X, Y, Z, alpha, beta, gamma;
110     fix X_dot, Y_dot, Z_dot, alpha_dot, beta_dot, gamma_dot;
111 } State;
112 
113 //	Stuff that used to be in physhand.h....
114 //	=======================================
115 typedef int32_t object_number;
116 
117 #define physics_handle_to_object_number(ph) (ph2on[ph])
118 #define object_number_to_physics_handle(on) (on2ph[on])
119 
120 extern "C" {
121 
122 void EDMS_init_handles(void);
123 physics_handle EDMS_bind_object_number(object_number on);
124 void EDMS_remap_object_number(object_number old, object_number nu);
125 physics_handle EDMS_get_free_ph(void);
126 void EDMS_release_object(physics_handle ph);
127 
128 }
129 
130 //	Terrain
131 //	=======
132 Q terrain(Q X, Q Y, int32_t deriv);                         // This calls Terrain()
133 TerrainHit indoor_terrain(Q X, Q Y, Q Z, Q R, physics_handle ph, TFType type); // Indoor for Citadel, FBO, etc...
134 
135 extern "C" {
136 
137 fix Terrain(fix X, fix Y, int32_t deriv);                           // This is provided by the user...
138 TerrainHit Indoor_Terrain(fix X, fix Y, fix Z, fix R, physics_handle ph, TFType type); // As is this...
139 
140 //	Here's the actual indoor guy we ask for...
141 //	------------------------------------------
142 typedef struct {
143     // Filled by user when Indoor_Terrain is called...
144     fix cx, cy, cz;
145     fix fx, fy, fz;
146     fix wx, wy, wz;
147 } TerrainData;
148 
149 extern TerrainData terrain_info; // Struct name EDMS expects...
150 
151 // Freefall terrain data structures...
152 // -----------------------------------
153 typedef struct {
154     // The ground...
155     fix g_height, g_dx, g_dy, g_dz;
156     // Any walls...
157     fix w_x, w_y, w_z;
158     // Squishiness, friction, et cetera...
159     fix terrain_information;
160     // For terrain return information...
161     int32_t DATA1, DATA2;
162     // Only needed for "fast" terrain calls
163     fix my_size;
164     // Who's responsible...
165     physics_handle caller;
166 } terrain_ff;
167 
168 bool FF_terrain(fix X, fix Y, fix Z, uchar fast, terrain_ff *TFF); // From Freefall...
169 bool FF_raycast(fix x, fix y, fix z, fix *vec, fix range, fix *where_hit, terrain_ff *tff);
170 }
171 
172 bool ff_terrain(Q X, Q Y, Q Z, uchar fast, terrain_ff *TFF); // For the refined...
173 bool ff_raycast(Q x, Q y, Q z, Fixpoint *vec, Q range, Fixpoint *where_hit, terrain_ff *FFT);
174 
175 //		Motion package functions...
176 //		===========================
177 
178 //		Marble...
179 //		---------
180 void marble_X(int32_t object);
181 void marble_Y(int32_t object);
182 void marble_Z(int32_t object);
183 
184 //		Robot...
185 //		--------
186 void robot_X(int32_t object);
187 void robot_Y(int32_t object);
188 void robot_Z(int32_t object);
189 
190 //		Deformable objects...
191 //		---------------------
192 void field_point_X(int32_t object);
193 void field_point_Y(int32_t object);
194 void field_point_Z(int32_t object);
195 
196 // Have some arrays...
197 // ===================
198 
199 // binary database (collision) operators...
200 // ========================================
201 
202 // Playfield information and scaling...
203 // ------------------------------------
204 //#define COLLISION_SIZE 100
205 #define DELTA_BY_TWO .5
206 
207 #define NUM_OBJECT_BITS 32
208 
209 #define object_bit(n) (1 << (n & 31))
210 
211 // To turn on an element...
212 // ------------------------
213 #define write_object_bit(X, Y, obit) (data[X][Y] |= obit)
214 
215 // Turn it off...
216 // --------------
217 #define delete_object_bit(X, Y, obit) (data[X][Y] &= ~(obit))
218 
219 // Test a bit...
220 // -------------
221 #define test_object_bit(X, Y, object) (data[X][Y] & object_bit(object))
222 
223 // Check for a given collision...
224 // ------------------------------
225 #define check_object(caller, looker)                                                                  \
226     (data[(hash_scale * A[caller][DOF_X][0]).to_int()][(hash_scale * A[caller][DOF_Y][0]).to_int()] & \
227      object_bit(looker))
228 
229 // This used to be a function in collide.cc
230 // I had to change the name because Seamus had some files locked out.
231 #define check_for_hit(other_object) (test_bitmask & object_bit(other_object))
232 
233 //	Ta Daa.
234 //	=======
235 
236 #include "externs.h"
237 #endif // __EDMS_INT_H
238