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_TRACER_H_INCLUDED
29 #define ICB_TRACER_H_INCLUDED
30 
31 #include "engines/icb/game_volume.h"
32 #include "engines/icb/p4.h"
33 #include "engines/icb/p4_generic.h"
34 
35 #include "engines/icb/common/px_3drealpoint.h"
36 #include "engines/icb/common/px_2drealline.h"
37 
38 namespace ICB {
39 
40 class _floor_world;
41 
42 class _tracer : public _game_volume {
43 public:
44 	// Definitions used by this class.
45 	enum FaceID { NO_FACE, LEFT, RIGHT, FRONT, BACK, TOP, BOTTOM };
46 
47 	// Default constructor and destructor.
_tracer()48 	inline _tracer() { m_pyBarrierMemFile = NULL; m_nPadding[0] = 0; }
~_tracer()49 	virtual inline ~_tracer() { ; }
50 
51 	// This checks a line through game-world space and returns the point of its first impact.
52 	bool8 Trace(const px3DRealPoint &oFrom, const px3DRealPoint &oTo, _barrier_ray_type eRayType, px3DRealPoint &oImpact, _barrier_logic_value eImpactType);
53 
54 	// Call this before using the tracer, to point it at its barriers.
SetBarrierPointer(_linked_data_file * pyBarriers)55 	void SetBarrierPointer(_linked_data_file *pyBarriers) { m_pyBarrierMemFile = pyBarriers; }
56 
57 	// Call this to give the tracer access to the floor data.
SetFloorsPointer(_floor_world * pFloorWorld)58 	void SetFloorsPointer(_floor_world *pFloorWorld) { m_pFloorWorld = pFloorWorld; }
59 
60 private:
61 	_linked_data_file *m_pyBarrierMemFile; // The memory image of the barrier file.
62 	_floor_world *m_pFloorWorld;           // The floors data (loaded by the routing code).
63 	PXreal m_fXDiff, m_fYDiff, m_fZDiff;   // Delta x, y and z for the line we're tracing.
64 	PXreal m_fSqrLength;                   // Square length of the vector we're tracing.
65 	bool8 m_bXPositiveGoing;               // These 3 get set once for each
66 	bool8 m_bYPositiveGoing;               // call to the tracer, and indicate
67 	bool8 m_bZPositiveGoing;               // which way the line is going.
68 	uint8 m_nPadding[1];
69 
70 	// Here I block the use of the default '='.
_tracer(const _tracer & t)71 	_tracer(const _tracer &t) : _game_volume(t) { ; }
72 	void operator=(const _tracer &t) { ; }
73 
74 	// Private functions used only by this class.
75 	void GetBarriersForCube(const _XYZ_index &oCubeIndices, uint32 *oThisCubesBarriers, int32 &nNumBarriers, int32 nExtraSliceIndex) const;
76 
77 	px3DRealPoint CalculateEntryToNextCube(const px3DRealPoint &oCurrentPoint, const px3DRealPoint &oTo, const _bullet_cube &oThisCube, FaceID &eCubeLeavingFace) const;
78 
79 	bool8 CheckRayHeightAgainstBarrier(const px3DRealPoint &oFrom, const px3DRealPoint &oTo, const _route_barrier *pBarrier, px3DRealPoint &o3DImpactPoint) const;
80 
81 	uint32 FindClosest(const px3DRealPoint &oFrom, px3DRealPoint *oImpactList, uint32 nNumImpacts) const;
82 
83 	px3DRealPoint CalculateRayIntersectionWithCubeWall(const px3DRealPoint &oCurrentPoint, const px3DRealPoint &oTo, const _bullet_cube &oThisCube, FaceID eLeavingFace) const;
84 
85 	inline const _route_barrier *GetBarrier(uint32 i) const;
86 };
87 
GetBarrier(uint32 i)88 inline const _route_barrier *_tracer::GetBarrier(uint32 i) const {
89 	_route_barrier *pBarriers;
90 
91 	if (!m_pyBarrierMemFile)
92 		Fatal_error("No barrier file in _tracer::GetBarrier()");
93 
94 	pBarriers = (_route_barrier *)m_pyBarrierMemFile->Fetch_item_by_name("Data");
95 	return &(pBarriers[i]);
96 }
97 
98 extern _tracer *g_oTracer; // Object for doing the plotting of bullets and line-of-sight.
99 
100 } // End of namespace ICB
101 
102 #endif // #if !defined( TRACER_H_INCLUDED )
103