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_BARRIERS_H
29 #define ICB_BARRIERS_H
30 
31 #include "engines/icb/common/px_rcutypes.h"
32 #include "engines/icb/common/px_linkeddatafile.h"
33 #include "engines/icb/common/px_route_barriers.h"
34 
35 namespace ICB {
36 
37 #define MAX_slices 9
38 
39 //+1 for dummy top floor ceiling
40 #define MAX_heights (MAX_slices + 1)
41 
42 #define MAX_floors 48
43 
44 // this is the master number of objects -
45 // The +3 & ~3 - means it is rounded up to be a multiple of 4
46 #define MAX_props ((116 + 3) & ~3)
47 
48 #define MAX_parents_per_anim_slice 24
49 //#define   MAX_bars_per_parent 96
50 #define MAX_props_per_parent 16
51 
52 #define MAX_animating_props 24
53 #define MAX_bars_per_prop 60
54 
55 #define MAX_child_groups_per_parent 16
56 
57 #define MAX_prop_abars (MAX_animating_props * MAX_bars_per_prop)
58 
59 //--------------------------------------------------------------------------------------
60 class _animating_parent { // contains all of the abarriers that lie within this parent space - for each we record its associated prop and
61 	                  // state so we know when each is in scope
62 public:
63 	uint8 num_props;
64 	uint8 prop_number[MAX_props_per_parent];
65 };
66 
67 class _animating_barrier_slice { // contains a list of parents that lie within the slice
68 	                         // and a list of props within the slice
69 public:
70 	_animating_parent *anim_parents[MAX_parents_per_anim_slice];
71 
72 	uint8 num_props_in_slice;
73 	uint8 prop_list[MAX_props];
74 };
75 
76 class _anim_prop_info { // contains a list of all the abars for the prop
77 public:
78 	uint8 barriers_per_state;
79 	uint8 total_states;   // temp - could be removed
80 	uint16 *barrier_list; // pointer into 'prop_abar_table'
81 };
82 
83 class _barrier_handler {
84 
85 public:
86 	void ___init();
87 
88 	void Form_route_barrier_list(PXreal x, PXreal y, PXreal z, PXreal x2, PXreal z2);
89 	void Form_parent_barrier_list(PXreal x, PXreal y, PXreal z);
90 
91 	_parent_box *Fetch_parent_box_for_xyz(PXreal x, PXreal y, PXreal z, uint32 &par_num, uint32 &slice_num);
92 	_parent_box *Fetch_parent_num_on_slice_y(uint32 requested_parent, PXreal y);
93 	uint32 Fetch_number_of_child_boxes(_parent_box *parent);
94 	_child_group *Fetch_child_box(_parent_box *parent, uint32 child);
95 	_route_barrier *Fetch_barrier(uint32 num);
96 	uint32 Fetch_total_barriers();
Get_barrier_pointer()97 	_linked_data_file *Get_barrier_pointer() const { return raw_barriers; }
98 	void Prepare_animating_barriers();
99 	uint32 Get_anim_barriers(uint32 n, uint32 *oThisCubesBarriers, uint32 slice);
100 
101 	void Set_route_barrier_mask(int32 left, int32 right, int32 top, int32 bottom);
102 	void Clear_route_barrier_mask();
103 
104 	_animating_barrier_slice anim_slices[MAX_slices];
105 
106 	_anim_prop_info anim_prop_info[MAX_props];
107 
108 	uint16 prop_abar_table[MAX_animating_props * MAX_bars_per_prop];
109 
110 	uint8 parents_used;                              // count how many of table are used
111 	_animating_parent anim_parent_table[MAX_floors]; // storage
112 
113 	// raw barriers
114 	_linked_data_file *raw_barriers; // raw route barriers used for routing/line of sight and maybe shadow geometry
115 
116 	uint32 total_barriers;
117 
118 	// route barrier wrapper file
119 	_linked_data_file *route_wrapper;
120 
121 	uint32 total_slices; // useful out of file
122 
123 	bool8 barrier_mask;
124 	DXrect mask;
125 };
126 
Set_route_barrier_mask(int32 left,int32 right,int32 top,int32 bottom)127 inline void _barrier_handler::Set_route_barrier_mask(int32 left, int32 right, int32 top, int32 bottom) {
128 	// certain route building will provide an inner rect that barriers must lie within
129 	barrier_mask = TRUE8;
130 
131 	mask.left = left;
132 	mask.right = right;
133 	mask.top = top;
134 	mask.bottom = bottom;
135 }
136 
Clear_route_barrier_mask()137 inline void _barrier_handler::Clear_route_barrier_mask() {
138 	// cancel inner route barrier mask
139 
140 	barrier_mask = FALSE8;
141 }
142 
Fetch_number_of_child_boxes(_parent_box * parent)143 inline uint32 _barrier_handler::Fetch_number_of_child_boxes(_parent_box *parent) { return (parent->num_childgroups); }
144 
Fetch_child_box(_parent_box * parent,uint32 child)145 inline _child_group *_barrier_handler::Fetch_child_box(_parent_box *parent, uint32 child) { return ((_child_group *)(((uint8 *)parent) + parent->childgroups[child])); }
146 
Fetch_total_barriers()147 inline uint32 _barrier_handler::Fetch_total_barriers() { return (total_barriers); }
148 
149 } // End of namespace ICB
150 
151 #endif
152