ScummVM API documentation
game_volume.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_GAMEVOLUME_H_INCLUDED
28 #define ICB_GAMEVOLUME_H_INCLUDED
29 
30 #include "engines/icb/p4.h"
31 #include "engines/icb/common/px_3drealpoint.h"
32 #include "engines/icb/common/px_common.h"
33 #include "engines/icb/common/px_linkeddatafile.h"
34 #include "engines/icb/common/px_route_barriers.h"
35 
36 #include "math/utils.h"
37 
38 namespace ICB {
39 
40 // Set a limit on how many slices we can have (safe to increase this if we ever hit it).
41 #define MAX_SLICES 10
42 
43 // Simply pairs together a top and bottom for a slice.
44 struct _slice_limit {
45  PXreal fTop, fBottom;
46 
47  // Initialization.
48  _slice_limit() {
49  fTop = REAL_ZERO;
50  fBottom = REAL_ZERO;
51  }
52 };
53 
54 // This is used to store the actual size and position of one of the cubes in the game volume.
55 struct _bullet_cube {
56  PXreal fTop, fBottom;
57  PXreal fLeft, fRight;
58  PXreal fBack, fFront;
59 
60  // Initialization.
61  _bullet_cube() {
62  fTop = REAL_ZERO;
63  fBottom = REAL_ZERO;
64  fLeft = REAL_ZERO;
65  fRight = REAL_ZERO;
66  fBack = REAL_ZERO;
67  fFront = REAL_ZERO;
68  }
69 };
70 
71 // Holds a 3D index into the game space.
72 struct _XYZ_index {
73  int32 nX, nY, nZ;
74 
75  // Initialization.
76  _XYZ_index() {
77  nX = 0;
78  nY = 0;
79  nZ = 0;
80  }
81 };
82 
83 // Note that this class is abstract. Holds parameters about the space occupied by a game
84 // session for use by the line-of-sight code.
85 class _game_volume {
86 public:
87  // Default constructor and destructor.
88  inline _game_volume();
89  virtual inline ~_game_volume() = 0;
90 
91  // Copy constructor.
92  _game_volume(const _game_volume &oX) { CopyObject(oX); }
93 
94  // Operator '='.
95  inline const _game_volume &operator=(const _game_volume &oOpB);
96 
97  // This single function sets up all the parameters.
98  void SetUpParameters(LinkedDataFile *pyLOSData);
99 
100  // Gets and sets.
101  PXreal GetAbsoluteTop() const { return (m_fAbsoluteTop); }
102  PXreal GetAbsoluteBottom() const { return (m_fAbsoluteBottom); }
103  PXreal GetLeftEdge() const { return (m_fLeftEdge); }
104  PXreal GetRightEdge() const { return (m_fRightEdge); }
105  PXreal GetBackEdge() const { return (m_fBackEdge); }
106  PXreal GetFrontEdge() const { return (m_fFrontEdge); }
107 
108  uint32 GetNumSlices() const { return (m_nNumSlices); }
109  PXreal GetSliceTop(uint32 i) const { return (m_oSliceLimits[i].fTop); }
110  PXreal GetSliceBottom(uint32 i) const { return (m_oSliceLimits[i].fBottom); }
111 
112  uint32 GetXSize() const { return (m_nXSize); }
113  uint32 GetZSize() const { return (m_nZSize); }
114 
115  bool8 IsValid() const { return (m_bValid); }
116 
117  // This works out the indices for the cube a point is in.
118  bool8 GetCubeAndIndices(const px3DRealPoint &oPoint, _XYZ_index &oIndex, _bullet_cube &oCube) const;
119 
120 protected:
121  LinkedDataFile *m_pyLOSMemFile; // Pointer to the line-of-sight data file.
122 
123 private:
124  PXreal m_fAbsoluteTop; // The 'roof' of the cube.
125  PXreal m_fAbsoluteBottom; // The base of the cube.
126  PXreal m_fLeftEdge; // The leftmost edge of the cube.
127  PXreal m_fRightEdge; // The rightmost edge of the cube.
128  PXreal m_fBackEdge; // The backmost edge of the cube.
129  PXreal m_fFrontEdge; // The frontmost edge of the cube.
130  _slice_limit m_oSliceLimits[MAX_SLICES]; // Top and bottom of each slice.
131  uint32 m_nNumSlices; // The number of slices in the session.
132  uint32 m_nXSize; // Number of cubes along X dimension.
133  uint32 m_nZSize; // Number of cubes along Z dimension.
134  int32 m_nMinimumXIndex; // Minimum X index in the game space.
135  int32 m_nMinimumZIndex; // Ditto Z.
136  bool8 m_bValid; // TRUE when the object has been set up.
137  uint8 m_nPadding[3];
138 
139  // Private functions used only by this class.
140  inline void CopyObject(const _game_volume &oX);
141 };
142 
143 inline _game_volume::_game_volume() {
144  m_fAbsoluteTop = FLOAT_MAX;
145  m_fAbsoluteBottom = FLOAT_MIN;
146  m_fLeftEdge = REAL_ZERO;
147  m_fRightEdge = REAL_ZERO;
148  m_fBackEdge = REAL_ZERO;
149  m_fFrontEdge = REAL_ZERO;
150  m_nNumSlices = 0;
151  m_nXSize = 0;
152  m_nZSize = 0;
153  m_nMinimumXIndex = 0;
154  m_nMinimumZIndex = 0;
155  m_bValid = FALSE8;
156 }
157 
158 inline _game_volume::~_game_volume() {
159  // Doesn't actually need to do anything.
160 }
161 
162 inline const _game_volume &_game_volume::operator=(const _game_volume &oOpB) {
163  CopyObject(oOpB);
164 
165  return (*this);
166 }
167 
168 inline void _game_volume::CopyObject(const _game_volume &oX) {
169  uint32 i;
170 
171  m_fAbsoluteTop = oX.m_fAbsoluteTop;
172  m_fAbsoluteBottom = oX.m_fAbsoluteBottom;
173  m_fLeftEdge = oX.m_fLeftEdge;
174  m_fRightEdge = oX.m_fRightEdge;
175  m_fBackEdge = oX.m_fBackEdge;
176  m_fFrontEdge = oX.m_fFrontEdge;
177  m_nXSize = oX.m_nXSize;
178  m_nZSize = oX.m_nZSize;
179  m_bValid = oX.m_bValid;
180  m_nNumSlices = oX.m_nNumSlices;
181 
182  for (i = 0; i < oX.m_nNumSlices; ++i)
183  m_oSliceLimits[i] = oX.m_oSliceLimits[i];
184 }
185 
186 } // End of namespace ICB
187 
188 #endif // #if !defined( GAMEVOLUME_H_INCLUDED )
Definition: px_3drealpoint.h:45
Definition: game_volume.h:72
Definition: actor.h:32
Definition: px_linkeddatafile.h:53
Definition: game_volume.h:55
Definition: game_volume.h:44
Definition: game_volume.h:85